Browse Source

Added `listenToEl` option to refresh editor on scrollable elements. Fixes #2722

pull/2997/head
Artur Arseniev 6 years ago
parent
commit
c68996279b
  1. 11
      src/commands/view/SelectComponent.js
  2. 8
      src/editor/config/config.js

11
src/commands/view/SelectComponent.js

@ -41,7 +41,8 @@ export default {
'onOut', 'onOut',
'onClick', 'onClick',
'onFrameScroll', 'onFrameScroll',
'onFrameUpdated' 'onFrameUpdated',
'onContainerChange'
); );
}, },
@ -74,8 +75,11 @@ export default {
* */ * */
toggleSelectComponent(enable) { toggleSelectComponent(enable) {
const { em } = this; const { em } = this;
const listenToEl = em.getConfig('listenToEl');
const { parentNode } = em.getContainer();
const method = enable ? 'on' : 'off'; const method = enable ? 'on' : 'off';
const methods = { on, off }; const methods = { on, off };
!listenToEl.length && parentNode && listenToEl.push(parentNode);
const trigger = (win, body) => { const trigger = (win, body) => {
methods[method](body, 'mouseover', this.onHover); methods[method](body, 'mouseover', this.onHover);
methods[method](body, 'mouseleave', this.onOut); methods[method](body, 'mouseleave', this.onOut);
@ -83,6 +87,7 @@ export default {
methods[method](win, 'scroll', this.onFrameScroll); methods[method](win, 'scroll', this.onFrameScroll);
}; };
methods[method](window, 'resize', this.onFrameUpdated); methods[method](window, 'resize', this.onFrameUpdated);
methods[method](listenToEl, 'scroll', this.onContainerChange);
em[method]('component:toggled', this.onSelect, this); em[method]('component:toggled', this.onSelect, this);
em[method]('change:componentHovered', this.onHovered, this); em[method]('change:componentHovered', this.onHovered, this);
em[method]( em[method](
@ -721,6 +726,10 @@ export default {
this.updateGlobalPos(); this.updateGlobalPos();
}), }),
onContainerChange: debounce(function() {
this.em.refreshCanvas();
}, 150),
/** /**
* Returns element's data info * Returns element's data info
* @param {HTMLElement} el * @param {HTMLElement} el

8
src/editor/config/config.js

@ -148,6 +148,14 @@ export default {
// To get more about this feature read: https://github.com/artf/grapesjs/issues/1936 // To get more about this feature read: https://github.com/artf/grapesjs/issues/1936
dragMode: 0, dragMode: 0,
// When the editor is placed in a scrollable container (eg. modals) this might
// cause elements inside the canvas (eg. floating toolbars) to be misaligned.
// To avoid that, you can specify an array of DOM elements on which their scroll will
// trigger the canvas update.
// Be default, if the array is empty, the first parent element will be appended.
// listenToEl: [document.querySelector('#scrollable-el')],
listenToEl: [],
// Import asynchronously CSS to use as icons // Import asynchronously CSS to use as icons
cssIcons: cssIcons:
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css',

Loading…
Cancel
Save