Browse Source

Update Asset Manager modal and do not rerender it

pull/281/head
Artur Arseniev 9 years ago
parent
commit
c7a2c8599e
  1. 4
      dist/grapes.min.js
  2. 2
      package.json
  3. 11
      src/asset_manager/config/config.js
  4. 5
      src/asset_manager/index.js
  5. 10
      src/asset_manager/model/AssetImage.js
  6. 2
      src/asset_manager/view/AssetImageView.js
  7. 8
      src/asset_manager/view/AssetView.js
  8. 22
      src/asset_manager/view/AssetsView.js
  9. 29
      src/commands/view/OpenAssets.js
  10. 2
      src/style_manager/view/PropertyFileView.js

4
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Free and Open Source Web Builder Framework", "description": "Free and Open Source Web Builder Framework",
"version": "0.9.37", "version": "0.9.38",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

11
src/asset_manager/config/config.js

@ -1,10 +1,16 @@
module.exports = { module.exports = {
// Default assets // Default assets
// eg. [
// 'https://...image1.png',
// 'https://...image2.png',
// {type: 'image', src: 'https://...image3.png', someOtherCustomProp: 1},
// ..
// ]
assets: [], assets: [],
// Content to add where there is no assets to show // Content to add where there is no assets to show
// eg. 'No <b>assets</b> here, drag to upload' // eg. 'No <b>assets</b> here, drag to upload'
noAssets: 'No assets', noAssets: '',
// Style prefix // Style prefix
stylePrefix: 'am-', stylePrefix: 'am-',
@ -67,4 +73,7 @@ module.exports = {
// Any dropzone content to append inside dropzone element // Any dropzone content to append inside dropzone element
dropzoneContent: '', dropzoneContent: '',
// Default title for the asset manager modal
modalTitle: 'Select Image',
}; };

5
src/asset_manager/index.js

@ -255,6 +255,11 @@ module.exports = () => {
*/ */
render(assets) { render(assets) {
const toRender = assets || this.getAll().models; const toRender = assets || this.getAll().models;
if (!am.rendered) {
am.render();
}
am.collection.reset(toRender); am.collection.reset(toRender);
return this.getContainer(); return this.getContainer();
}, },

10
src/asset_manager/model/AssetImage.js

@ -2,11 +2,11 @@ const Asset = require('./Asset');
module.exports = Asset.extend({ module.exports = Asset.extend({
defaults: _.extend({}, Asset.prototype.defaults, { defaults: Object.assign({}, Asset.prototype.defaults, {
type: 'image', type: 'image',
unitDim: 'px', unitDim: 'px',
height: 0, height: 0,
width: 0, width: 0,
}), }),
}); });

2
src/asset_manager/view/AssetImageView.js

@ -57,6 +57,7 @@ module.exports = require('./AssetView').extend({
* @private * @private
* */ * */
handleDblClick() { handleDblClick() {
const em = this.em;
var onDblClick = this.config.onDblClick; var onDblClick = this.config.onDblClick;
var model = this.model; var model = this.model;
@ -64,6 +65,7 @@ module.exports = require('./AssetView').extend({
onDblClick(model); onDblClick(model);
} else { } else {
this.updateTarget(model.get('src')); this.updateTarget(model.get('src'));
em && em.get('Modal').close();
} }
var onSelect = this.collection.onSelect; var onSelect = this.collection.onSelect;

8
src/asset_manager/view/AssetView.js

@ -3,9 +3,11 @@ module.exports = Backbone.View.extend({
initialize(o = {}) { initialize(o = {}) {
this.options = o; this.options = o;
this.collection = o.collection; this.collection = o.collection;
this.config = o.config || {}; const config = o.config || {};
this.pfx = this.config.stylePrefix || ''; this.config = config;
this.ppfx = this.config.pStylePrefix || ''; this.pfx = config.stylePrefix || '';
this.ppfx = config.pStylePrefix || '';
this.em = config.em;
this.className = this.pfx + 'asset'; this.className = this.pfx + 'asset';
this.listenTo(this.model, 'destroy remove', this.remove); this.listenTo(this.model, 'destroy remove', this.remove);
const init = this.init && this.init.bind(this); const init = this.init && this.init.bind(this);

22
src/asset_manager/view/AssetsView.js

@ -38,7 +38,7 @@ module.exports = Backbone.View.extend({
this.pfx = this.config.stylePrefix || ''; this.pfx = this.config.stylePrefix || '';
this.ppfx = this.config.pStylePrefix || ''; this.ppfx = this.config.pStylePrefix || '';
const coll = this.collection; const coll = this.collection;
this.listenTo(coll, 'reset', this.render); this.listenTo(coll, 'reset', this.renderAssets);
this.listenTo(coll, 'add', this.addToAsset); this.listenTo(coll, 'add', this.addToAsset);
this.listenTo(coll, 'remove', this.removedAsset); this.listenTo(coll, 'remove', this.removedAsset);
this.listenTo(coll, 'deselectAll', this.deselectAll); this.listenTo(coll, 'deselectAll', this.deselectAll);
@ -166,18 +166,22 @@ module.exports = Backbone.View.extend({
this.$el.find(`.${pfx}highlight`).removeClass(`${pfx}highlight`); this.$el.find(`.${pfx}highlight`).removeClass(`${pfx}highlight`);
}, },
renderAssets() {
const fragment = document.createDocumentFragment();
const assets = this.$el.find(`.${this.pfx}assets`);
assets.empty();
this.toggleNoAssets(this.collection.length);
this.collection.each((model) => this.addAsset(model, fragment));
assets.append(fragment);
},
render() { render() {
const pfx = this.pfx;
const ppfx = this.ppfx;
//const noAssets = this.config.noAssets;
const fuRendered = this.options.fu.render().el; const fuRendered = this.options.fu.render().el;
const fragment = document.createDocumentFragment();
this.$el.empty(); this.$el.empty();
this.collection.each((model) => this.addAsset(model, fragment));
this.$el.append(fuRendered).append(this.template(this)); this.$el.append(fuRendered).append(this.template(this));
this.el.className = `${ppfx}asset-manager`; this.el.className = `${this.ppfx}asset-manager`;
this.toggleNoAssets(this.collection.length); this.renderAssets();
this.$el.find(`.${pfx}assets`).append(fragment); this.rendered = 1;
return this; return this;
} }
}); });

29
src/commands/view/OpenAssets.js

@ -1,21 +1,24 @@
module.exports = { module.exports = {
run(editor, sender, opts) { run(editor, sender, opts = {}) {
var opt = opts || {}; const modal = editor.Modal;
var config = editor.getConfig(); const am = editor.AssetManager;
var modal = editor.Modal; const config = am.getConfig();
var assetManager = editor.AssetManager; const title = opts.modalTitle || config.modalTitle || '';
assetManager.onClick(opt.onClick); am.setTarget(opts.target);
assetManager.onDblClick(opt.onDblClick); am.onClick(opts.onClick);
am.onDblClick(opts.onDblClick);
am.onSelect(opts.onSelect);
// old API if (!this.rendered) {
assetManager.setTarget(opt.target); console.log('render now');
assetManager.onSelect(opt.onSelect); am.render();
assetManager.render(); this.rendered = 1;
}
modal.setTitle(opt.modalTitle || 'Select image'); modal.setTitle(title);
modal.setContent(assetManager.getContainer()); modal.setContent(am.getContainer());
modal.open(); modal.open();
}, },

2
src/style_manager/view/PropertyFileView.js

@ -125,7 +125,7 @@ module.exports = PropertyView.extend({
if(editor) { if(editor) {
this.modal.setTitle('Select image'); this.modal.setTitle('Select image');
this.modal.setContent(this.am.render()); this.modal.setContent(this.am.getContainer());
this.am.setTarget(null); this.am.setTarget(null);
editor.runCommand('open-assets', { editor.runCommand('open-assets', {
target: this.model, target: this.model,

Loading…
Cancel
Save