Browse Source
Firefox resize fix + skip loading keymaps in headless mode (#6435)
* Fix error when resizing components in Firefox
* Avoid loading keymaps for headless editor
* Fix other possible issues
up-docs
Artur Arseniev
11 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
15 additions and
4 deletions
-
packages/core/src/canvas/index.ts
-
packages/core/src/commands/view/SelectComponent.ts
-
packages/core/src/editor/model/Editor.ts
-
packages/core/src/keymaps/index.ts
-
packages/core/src/utils/sorter/ComponentSorter.ts
|
|
|
@ -486,7 +486,9 @@ export default class CanvasModule extends Module<CanvasConfig> { |
|
|
|
*/ |
|
|
|
getMouseRelativePos(e: any, opts: any = {}) { |
|
|
|
const subWinOffset = opts.subWinOffset; |
|
|
|
const doc = e.target.ownerDocument; |
|
|
|
const { target } = e; |
|
|
|
// In Firefox, pointing outside the window, will return the HTMLDocument.
|
|
|
|
const doc = target.nodeType === Node.DOCUMENT_NODE ? target : target.ownerDocument; |
|
|
|
const win = doc.defaultView || doc.parentWindow; |
|
|
|
const frame = win.frameElement; |
|
|
|
const yOffset = subWinOffset ? win.pageYOffset : 0; |
|
|
|
|
|
|
|
@ -496,7 +496,7 @@ export default { |
|
|
|
const style: any = {}; |
|
|
|
|
|
|
|
if (!onlyHeight) { |
|
|
|
const bodyw = canvas.getBody().offsetWidth; |
|
|
|
const bodyw = canvas.getBody()?.offsetWidth || 0; |
|
|
|
const width = rect.w < bodyw ? rect.w : bodyw; |
|
|
|
style[keyWidth!] = autoWidth ? 'auto' : `${width}${unitWidth}`; |
|
|
|
} |
|
|
|
|
|
|
|
@ -314,6 +314,14 @@ export default class EditorModel extends Model { |
|
|
|
return this.config.grapesjs?.version || ''; |
|
|
|
} |
|
|
|
|
|
|
|
get isHeadless() { |
|
|
|
return !!this.config.headless; |
|
|
|
} |
|
|
|
|
|
|
|
get isShallow() { |
|
|
|
return !!this.get('isShallow'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get configurations |
|
|
|
* @param {string} [prop] Property name |
|
|
|
|
|
|
|
@ -64,6 +64,7 @@ export default class KeymapsModule extends Module<KeymapsConfig & { name?: strin |
|
|
|
} |
|
|
|
|
|
|
|
onLoad() { |
|
|
|
if (this.em.isHeadless) return; |
|
|
|
const defKeys = this.config.defaults; |
|
|
|
|
|
|
|
for (let id in defKeys) { |
|
|
|
@ -121,7 +122,7 @@ export default class KeymapsModule extends Module<KeymapsConfig & { name?: strin |
|
|
|
const handlerRes = isString(handler) ? cmd.get(handler) : handler; |
|
|
|
const ableTorun = !em.isEditing() && !editor.Canvas.isInputFocused(); |
|
|
|
if (ableTorun || opts.force) { |
|
|
|
opts.prevent && canvas.getCanvasView().preventDefault(e); |
|
|
|
opts.prevent && canvas.getCanvasView()?.preventDefault(e); |
|
|
|
isFunction(handlerRes) ? handlerRes(editor, 0, opt) : cmd.runCommand(handlerRes, opt); |
|
|
|
const args = [id, h.shortcut, e]; |
|
|
|
em.trigger('keymap:emit', ...args); |
|
|
|
|
|
|
|
@ -182,7 +182,7 @@ export default class ComponentSorter<NodeType extends BaseComponentNode> extends |
|
|
|
} |
|
|
|
} |
|
|
|
const addedNode = targetNode.addChildAt(sourceNode, index, { action: 'move-component' }) as NodeType; |
|
|
|
this.triggerEndMoveEvent(addedNode); |
|
|
|
addedNode && this.triggerEndMoveEvent(addedNode); |
|
|
|
|
|
|
|
return { addedNode, index }; |
|
|
|
} |
|
|
|
|