Skip to content

Commit

Permalink
Merge branch 'fix-resizer-helpers' into dev. Fixes GrapesJS#976
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Apr 25, 2018
2 parents 94a844f + 9f0ed07 commit 5bedf06
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/commands/view/Resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
}

canvasResizer.setOptions(options);
canvasResizer.blur();
canvasResizer.focus(el);
return canvasResizer;
},
Expand Down
36 changes: 20 additions & 16 deletions src/commands/view/SelectComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bindAll } from 'underscore';
import { bindAll, isElement } from 'underscore';
import { on, off, getUnitFromValue } from 'utils/mixins';

const ToolbarView = require('dom_components/view/ToolbarView');
Expand Down Expand Up @@ -186,6 +186,7 @@ module.exports = {
if (model) {
if (model.get('selectable')) {
editor.select(model);
this.initResize(model);
} else {
let parent = model.parent();
while (parent && !parent.get('selectable')) parent = parent.parent();
Expand Down Expand Up @@ -262,7 +263,8 @@ module.exports = {
* @private
* */
onSelect() {
const editor = this.editor;
// Get the selected model directly from the Editor as the event might
// be triggered manually without the model
const model = this.em.getSelected();
this.updateToolbar(model);

Expand All @@ -273,26 +275,27 @@ module.exports = {
this.hideHighlighter();
this.initResize(el);
} else {
editor.stopCommand('resize');
this.editor.stopCommand('resize');
}
},

/**
* Init resizer on the element if possible
* @param {HTMLElement} el
* @param {HTMLElement|Component} elem
* @private
*/
initResize(el) {
var em = this.em;
var editor = em ? em.get('Editor') : '';
var config = em ? em.get('Config') : '';
var pfx = config.stylePrefix || '';
var attrName = `data-${pfx}handler`;
var resizeClass = `${pfx}resizing`;
var model = em.get('selectedComponent');
var resizable = model.get('resizable');
var options = {};
var modelToStyle;
initResize(elem) {
const em = this.em;
const editor = em ? em.get('Editor') : '';
const config = em ? em.get('Config') : '';
const pfx = config.stylePrefix || '';
const attrName = `data-${pfx}handler`;
const resizeClass = `${pfx}resizing`;
const model = !isElement(elem) ? elem : em.getSelected();
const resizable = model.get('resizable');
const el = isElement(elem) ? elem : model.getEl();
let options = {};
let modelToStyle;

var toggleBodyClass = (method, e, opts) => {
const docs = opts.docs;
Expand Down Expand Up @@ -376,11 +379,12 @@ module.exports = {
if (typeof resizable == 'object') {
options = { ...options, ...resizable };
}

editor.runCommand('resize', { el, options });

// On undo/redo the resizer rect is not updating, need somehow to call
// this.updateRect on undo/redo action
} else {
editor.stopCommand('resize');
}
},

Expand Down
1 change: 1 addition & 0 deletions src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* * `component:styleUpdate` - Triggered when the style of the component is updated, the model is passed as an argument to the callback
* * `component:styleUpdate:{propertyName}` - Listen for a specific style property change, the model is passed as an argument to the callback
* * `component:selected` - New component selected, the selected model is passed as an argument to the callback
* * `component:deselected` - Component deselected, the deselected model is passed as an argument to the callback
* ## Blocks
* * `block:add` - New block added
* * `block:remove` - Block removed
Expand Down
11 changes: 4 additions & 7 deletions src/editor/model/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,10 @@ module.exports = Backbone.Model.extend({
* @param {Object} Options
* @private
* */
componentSelected(model, val, options) {
if (!this.get('selectedComponent')) {
this.trigger('deselect-comp');
} else {
this.trigger('select-comp', [model, val, options]);
this.trigger('component:selected', arguments);
}
componentSelected(editor, selected, options) {
const prev = this.previous('selectedComponent');
prev && this.trigger('component:deselected', prev, options);
selected && this.trigger('component:selected', selected, options);
},

/**
Expand Down

0 comments on commit 5bedf06

Please sign in to comment.