Browse Source

Merge branch 'fix-resizer-helpers' into dev. Fixes #976

pull/1069/head
Artur Arseniev 9 years ago
parent
commit
5bedf06816
  1. 1
      src/commands/view/Resize.js
  2. 36
      src/commands/view/SelectComponent.js
  3. 1
      src/editor/index.js
  4. 11
      src/editor/model/Editor.js

1
src/commands/view/Resize.js

@ -19,6 +19,7 @@ module.exports = {
} }
canvasResizer.setOptions(options); canvasResizer.setOptions(options);
canvasResizer.blur();
canvasResizer.focus(el); canvasResizer.focus(el);
return canvasResizer; return canvasResizer;
}, },

36
src/commands/view/SelectComponent.js

@ -1,4 +1,4 @@
import { bindAll } from 'underscore'; import { bindAll, isElement } from 'underscore';
import { on, off, getUnitFromValue } from 'utils/mixins'; import { on, off, getUnitFromValue } from 'utils/mixins';
const ToolbarView = require('dom_components/view/ToolbarView'); const ToolbarView = require('dom_components/view/ToolbarView');
@ -186,6 +186,7 @@ module.exports = {
if (model) { if (model) {
if (model.get('selectable')) { if (model.get('selectable')) {
editor.select(model); editor.select(model);
this.initResize(model);
} else { } else {
let parent = model.parent(); let parent = model.parent();
while (parent && !parent.get('selectable')) parent = parent.parent(); while (parent && !parent.get('selectable')) parent = parent.parent();
@ -262,7 +263,8 @@ module.exports = {
* @private * @private
* */ * */
onSelect() { 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(); const model = this.em.getSelected();
this.updateToolbar(model); this.updateToolbar(model);
@ -273,26 +275,27 @@ module.exports = {
this.hideHighlighter(); this.hideHighlighter();
this.initResize(el); this.initResize(el);
} else { } else {
editor.stopCommand('resize'); this.editor.stopCommand('resize');
} }
}, },
/** /**
* Init resizer on the element if possible * Init resizer on the element if possible
* @param {HTMLElement} el * @param {HTMLElement|Component} elem
* @private * @private
*/ */
initResize(el) { initResize(elem) {
var em = this.em; const em = this.em;
var editor = em ? em.get('Editor') : ''; const editor = em ? em.get('Editor') : '';
var config = em ? em.get('Config') : ''; const config = em ? em.get('Config') : '';
var pfx = config.stylePrefix || ''; const pfx = config.stylePrefix || '';
var attrName = `data-${pfx}handler`; const attrName = `data-${pfx}handler`;
var resizeClass = `${pfx}resizing`; const resizeClass = `${pfx}resizing`;
var model = em.get('selectedComponent'); const model = !isElement(elem) ? elem : em.getSelected();
var resizable = model.get('resizable'); const resizable = model.get('resizable');
var options = {}; const el = isElement(elem) ? elem : model.getEl();
var modelToStyle; let options = {};
let modelToStyle;
var toggleBodyClass = (method, e, opts) => { var toggleBodyClass = (method, e, opts) => {
const docs = opts.docs; const docs = opts.docs;
@ -376,11 +379,12 @@ module.exports = {
if (typeof resizable == 'object') { if (typeof resizable == 'object') {
options = { ...options, ...resizable }; options = { ...options, ...resizable };
} }
editor.runCommand('resize', { el, options }); editor.runCommand('resize', { el, options });
// On undo/redo the resizer rect is not updating, need somehow to call // On undo/redo the resizer rect is not updating, need somehow to call
// this.updateRect on undo/redo action // this.updateRect on undo/redo action
} else {
editor.stopCommand('resize');
} }
}, },

1
src/editor/index.js

@ -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` - 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: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: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 * ## Blocks
* * `block:add` - New block added * * `block:add` - New block added
* * `block:remove` - Block removed * * `block:remove` - Block removed

11
src/editor/model/Editor.js

@ -197,13 +197,10 @@ module.exports = Backbone.Model.extend({
* @param {Object} Options * @param {Object} Options
* @private * @private
* */ * */
componentSelected(model, val, options) { componentSelected(editor, selected, options) {
if (!this.get('selectedComponent')) { const prev = this.previous('selectedComponent');
this.trigger('deselect-comp'); prev && this.trigger('component:deselected', prev, options);
} else { selected && this.trigger('component:selected', selected, options);
this.trigger('select-comp', [model, val, options]);
this.trigger('component:selected', arguments);
}
}, },
/** /**

Loading…
Cancel
Save