mirror of https://github.com/artf/grapesjs.git
committed by
GitHub
64 changed files with 18943 additions and 18041 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,9 +1,15 @@ |
|||
module.exports = { |
|||
|
|||
run(editor) { |
|||
const comp = editor.getSelected(); |
|||
const coll = comp && comp.collection; |
|||
coll && coll.parent && editor.select(coll.parent); |
|||
const sel = editor.getSelected(); |
|||
let comp = sel && sel.parent(); |
|||
|
|||
// Recurse through the parent() chain until a selectable parent is found
|
|||
while (comp && !comp.get("selectable")) { |
|||
comp = comp.parent(); |
|||
} |
|||
|
|||
comp && editor.select(comp); |
|||
} |
|||
|
|||
}; |
|||
|
|||
@ -0,0 +1,58 @@ |
|||
const Component = require('./Component'); |
|||
|
|||
module.exports = Component.extend({ |
|||
|
|||
defaults: { ...Component.prototype.defaults, |
|||
type: 'tbody', |
|||
tagName: 'tbody', |
|||
draggable: ['table'], |
|||
droppable: ['tr'], |
|||
columns: 1, |
|||
rows: 1, |
|||
}, |
|||
|
|||
initialize(o, opt) { |
|||
Component.prototype.initialize.apply(this, arguments); |
|||
const components = this.get('components'); |
|||
let columns = this.get('columns'); |
|||
let rows = this.get('rows'); |
|||
|
|||
// Init components if empty
|
|||
if (!components.length) { |
|||
const rowsToAdd = []; |
|||
|
|||
while (rows--) { |
|||
const columnsToAdd = []; |
|||
let clm = columns; |
|||
|
|||
while (clm--) { |
|||
columnsToAdd.push({ |
|||
type: 'cell', |
|||
classes: ['cell'] |
|||
}); |
|||
} |
|||
|
|||
rowsToAdd.push({ |
|||
type: 'row', |
|||
classes: ['row'], |
|||
components: columnsToAdd |
|||
}); |
|||
} |
|||
|
|||
components.add(rowsToAdd); |
|||
} |
|||
}, |
|||
|
|||
},{ |
|||
|
|||
isComponent(el) { |
|||
let result = ''; |
|||
|
|||
if (el.tagName == 'TBODY') { |
|||
result = { type: 'tbody' }; |
|||
} |
|||
|
|||
return result; |
|||
}, |
|||
|
|||
}); |
|||
@ -0,0 +1,21 @@ |
|||
const ComponentTableBody = require('./ComponentTableBody'); |
|||
|
|||
module.exports = ComponentTableBody.extend({ |
|||
|
|||
defaults: { ...ComponentTableBody.prototype.defaults, |
|||
type: 'tfoot', |
|||
tagName: 'tfoot', |
|||
}, |
|||
|
|||
},{ |
|||
isComponent(el) { |
|||
let result = ''; |
|||
|
|||
if (el.tagName == 'TFOOT') { |
|||
result = { type: 'tfoot' }; |
|||
} |
|||
|
|||
return result; |
|||
}, |
|||
|
|||
}); |
|||
@ -0,0 +1,21 @@ |
|||
const ComponentTableBody = require('./ComponentTableBody'); |
|||
|
|||
module.exports = ComponentTableBody.extend({ |
|||
|
|||
defaults: { ...ComponentTableBody.prototype.defaults, |
|||
type: 'thead', |
|||
tagName: 'thead' |
|||
}, |
|||
|
|||
}, { |
|||
isComponent(el) { |
|||
let result = ''; |
|||
|
|||
if (el.tagName == 'THEAD') { |
|||
result = { type: 'thead' }; |
|||
} |
|||
|
|||
return result; |
|||
}, |
|||
|
|||
}); |
|||
@ -0,0 +1,4 @@ |
|||
var Backbone = require('backbone'); |
|||
var ComponentView = require('./ComponentView'); |
|||
|
|||
module.exports = ComponentView.extend({}); |
|||
@ -0,0 +1,4 @@ |
|||
var Backbone = require('backbone'); |
|||
var ComponentView = require('./ComponentView'); |
|||
|
|||
module.exports = ComponentView.extend({}); |
|||
@ -0,0 +1,4 @@ |
|||
var Backbone = require('backbone'); |
|||
var ComponentView = require('./ComponentView'); |
|||
|
|||
module.exports = ComponentView.extend({}); |
|||
@ -1,21 +1,22 @@ |
|||
var Backbone = require('backbone'); |
|||
var Selector = require('./Selector'); |
|||
import { filter } from 'underscore'; |
|||
const Selector = require('./Selector'); |
|||
|
|||
module.exports = Backbone.Collection.extend({ |
|||
module.exports = require('backbone').Collection.extend({ |
|||
model: Selector, |
|||
|
|||
getStyleable() { |
|||
return _.filter(this.models, item => |
|||
return filter(this.models, item => |
|||
item.get('active') && !item.get('private')); |
|||
}, |
|||
|
|||
getValid() { |
|||
return _.filter(this.models, item => !item.get('private')); |
|||
return filter(this.models, item => !item.get('private')); |
|||
}, |
|||
|
|||
getFullString() { |
|||
getFullString(collection) { |
|||
const result = []; |
|||
this.each(selector => result.push(selector.getFullName())); |
|||
const coll = collection || this; |
|||
coll.forEach(selector => result.push(selector.getFullName())); |
|||
return result.join('').trim(); |
|||
} |
|||
}); |
|||
|
|||
@ -0,0 +1,242 @@ |
|||
/** |
|||
* This module allows to manage the stack of changes applied in canvas |
|||
* |
|||
* You can access the module in this way |
|||
* ```js
|
|||
* const um = editor.UndoManager; |
|||
* ``` |
|||
* |
|||
*/ |
|||
import UndoManager from 'backbone-undo'; |
|||
|
|||
module.exports = () => { |
|||
let em; |
|||
let um; |
|||
let config; |
|||
let beforeCache; |
|||
const configDef = {}; |
|||
|
|||
return { |
|||
|
|||
name: 'UndoManager', |
|||
|
|||
|
|||
/** |
|||
* Initialize module |
|||
* @param {Object} config Configurations |
|||
* @private |
|||
*/ |
|||
init(opts = {}) { |
|||
config = { ...opts, ...configDef }; |
|||
em = config.em; |
|||
this.em = em; |
|||
um = new UndoManager({ track: true, register: [] }); |
|||
um.changeUndoType('change', { condition: false }); |
|||
const customUndoType = { |
|||
on(object, value, opt = {}) { |
|||
!beforeCache && (beforeCache = object.previousAttributes()); |
|||
|
|||
if (opt.avoidStore) { |
|||
return; |
|||
} else { |
|||
const result = { |
|||
object, |
|||
before: beforeCache, |
|||
after: object.toJSON() |
|||
}; |
|||
beforeCache = null; |
|||
return result; |
|||
} |
|||
}, |
|||
|
|||
undo(model, bf, af, opt) { |
|||
model.set(bf); |
|||
}, |
|||
|
|||
redo(model, bf, af, opt) { |
|||
model.set(af); |
|||
} |
|||
}; |
|||
|
|||
const events = ['style', 'attributes', 'content', 'src']; |
|||
events.forEach(ev => um.addUndoType(`change:${ev}`, customUndoType)); |
|||
um.on('undo redo', () => em.trigger('change:selectedComponent change:canvasOffset')); |
|||
['undo', 'redo'].forEach(ev => um.on(ev, () => em.trigger(ev))); |
|||
|
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Get module configurations |
|||
* @return {Object} Configuration object |
|||
* @example |
|||
* const config = um.getConfig(); |
|||
* // { ... }
|
|||
*/ |
|||
getConfig() { |
|||
return config; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Add an entity (Model/Collection) to track |
|||
* Note: New Components and CSSRules will be added automatically |
|||
* @param {Model|Collection} entity Entity to track |
|||
* @return {this} |
|||
* @example |
|||
* um.add(someModelOrCollection); |
|||
*/ |
|||
add(entity) { |
|||
um.register(entity); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Remove and stop tracking the entity (Model/Collection) |
|||
* @param {Model|Collection} entity Entity to remove |
|||
* @return {this} |
|||
* @example |
|||
* um.remove(someModelOrCollection); |
|||
*/ |
|||
remove(entity) { |
|||
um.unregister(entity); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Remove all entities |
|||
* @return {this} |
|||
* @example |
|||
* um.removeAll(); |
|||
*/ |
|||
removeAll() { |
|||
um.unregisterAll(); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Start/resume tracking changes |
|||
* @return {this} |
|||
* @example |
|||
* um.start(); |
|||
*/ |
|||
start() { |
|||
um.startTracking(); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Stop tracking changes |
|||
* @return {this} |
|||
* @example |
|||
* um.stop(); |
|||
*/ |
|||
stop() { |
|||
um.stopTracking(); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Undo last change |
|||
* @return {this} |
|||
* @example |
|||
* um.undo(); |
|||
*/ |
|||
undo() { |
|||
if (!em.get('Canvas').isInputFocused()) um.undo(1); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Undo all changes |
|||
* @return {this} |
|||
* @example |
|||
* um.undoAll(); |
|||
*/ |
|||
undoAll() { |
|||
um.undoAll(); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Redo last change |
|||
* @return {this} |
|||
* @example |
|||
* um.redo(); |
|||
*/ |
|||
redo() { |
|||
if (!em.get('Canvas').isInputFocused()) um.redo(1); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Redo all changes |
|||
* @return {this} |
|||
* @example |
|||
* um.redoAll(); |
|||
*/ |
|||
redoAll() { |
|||
um.redoAll(); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Checks if exists an available undo |
|||
* @return {Boolean} |
|||
* @example |
|||
* um.hasUndo(); |
|||
*/ |
|||
hasUndo() { |
|||
return um.isAvailable('undo'); |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Checks if exists an available redo |
|||
* @return {Boolean} |
|||
* @example |
|||
* um.hasRedo(); |
|||
*/ |
|||
hasRedo() { |
|||
return um.isAvailable('redo'); |
|||
}, |
|||
|
|||
|
|||
/** |
|||
* Get stack of changes |
|||
* @return {Collection} |
|||
* @example |
|||
* const stack = um.getStack(); |
|||
* stack.each(item => ...); |
|||
*/ |
|||
getStack() { |
|||
return um.stack; |
|||
}, |
|||
|
|||
/** |
|||
* Clear the stack |
|||
* @return {this} |
|||
* @example |
|||
* um.clear(); |
|||
*/ |
|||
clear() { |
|||
um.clear(); |
|||
return this; |
|||
}, |
|||
|
|||
|
|||
getInstance() { |
|||
return um; |
|||
} |
|||
}; |
|||
}; |
|||
@ -0,0 +1,38 @@ |
|||
/** |
|||
* File made for IE/Edge support |
|||
* https://github.com/artf/grapesjs/issues/214
|
|||
*/ |
|||
|
|||
export default () => { |
|||
|
|||
/** |
|||
* Check if IE/Edge |
|||
* @return {Boolean} |
|||
*/ |
|||
const isIE = () => { |
|||
let match; |
|||
const agent = window.navigator.userAgent; |
|||
const rules = [ |
|||
[ 'edge', /Edge\/([0-9\._]+)/ ], |
|||
[ 'ie', /MSIE\s(7\.0)/ ], |
|||
[ 'ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ ], |
|||
[ 'ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ ], |
|||
]; |
|||
|
|||
for (let i = 0; i < rules.length; i++) { |
|||
const rule = rules[i]; |
|||
match = rule[1].exec(agent); |
|||
if (match) break; |
|||
} |
|||
|
|||
return !!match; |
|||
} |
|||
|
|||
if (isIE()) { |
|||
const originalCreateHTMLDocument = DOMImplementation.prototype.createHTMLDocument |
|||
DOMImplementation.prototype.createHTMLDocument = (title) => { |
|||
if (!title) title = ''; |
|||
return originalCreateHTMLDocument.apply(document.implementation, [title]); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue