diff --git a/src/dom_components/index.ts b/src/dom_components/index.ts
index 6876afdfc..2cda40037 100644
--- a/src/dom_components/index.ts
+++ b/src/dom_components/index.ts
@@ -440,21 +440,24 @@ export default class ComponentManager extends ItemManagerModule {
return res;
}, {});
+ var tempModel = new modelToExt();
// If the model/view is a simple object I need to extend it
if (typeof model === 'object') {
methods.model = modelToExt.extend(
{
...model,
...getExtendedObj(extendFn, model, modelToExt),
- defaults: {
- ...(result(modelToExt.prototype, 'defaults') || {}),
- ...(result(model, 'defaults') || {}),
- },
},
{
isComponent: compType && !extendType && !isComponent ? modelToExt.isComponent : isComponent || (() => 0),
}
);
+ Object.defineProperty(methods.model.prototype, 'defaults', {
+ value: {
+ ...(result(modelToExt.prototype, 'defaults') || {}),
+ ...(result(model, 'defaults') || {}),
+ },
+ });
}
if (typeof view === 'object') {
diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js
index e656ad413..e7c067201 100644
--- a/src/dom_components/model/Component.js
+++ b/src/dom_components/model/Component.js
@@ -94,6 +94,51 @@ export const keyUpdateInside = `${keyUpdate}-inside`;
* @module docsjs.Component
*/
export default class Component extends StyleableModel {
+ get defaults() {
+ return {
+ tagName: 'div',
+ type: '',
+ name: '',
+ removable: true,
+ draggable: true,
+ droppable: true,
+ badgable: true,
+ stylable: true,
+ 'stylable-require': '',
+ 'style-signature': '',
+ unstylable: '',
+ highlightable: true,
+ copyable: true,
+ resizable: false,
+ editable: false,
+ layerable: true,
+ selectable: true,
+ hoverable: true,
+ locked: false,
+ void: false,
+ state: '', // Indicates if the component is in some CSS state like ':hover', ':active', etc.
+ status: '', // State, eg. 'selected'
+ content: '',
+ icon: '',
+ style: '',
+ styles: '', // Component related styles
+ classes: '', // Array of classes
+ script: '',
+ 'script-props': '',
+ 'script-export': '',
+ attributes: '',
+ traits: ['id', 'title'],
+ propagate: '',
+ dmode: '',
+ toolbar: null,
+ [keySymbol]: 0,
+ [keySymbols]: 0,
+ [keySymbolOvrd]: 0,
+ _undo: true,
+ _undoexc: ['status', 'open'],
+ };
+ }
+
/**
* Hook method, called once the model is created
*/
@@ -1962,50 +2007,3 @@ Component.checkId = (components, styles = [], list = {}, opts = {}) => {
components && Component.checkId(components, styles, list, opts);
});
};
-
-Component.getDefaults = function () {
- return result(this.prototype, 'defaults');
-};
-
-Component.prototype.defaults = {
- tagName: 'div',
- type: '',
- name: '',
- removable: true,
- draggable: true,
- droppable: true,
- badgable: true,
- stylable: true,
- 'stylable-require': '',
- 'style-signature': '',
- unstylable: '',
- highlightable: true,
- copyable: true,
- resizable: false,
- editable: false,
- layerable: true,
- selectable: true,
- hoverable: true,
- locked: false,
- void: false,
- state: '', // Indicates if the component is in some CSS state like ':hover', ':active', etc.
- status: '', // State, eg. 'selected'
- content: '',
- icon: '',
- style: '',
- styles: '', // Component related styles
- classes: '', // Array of classes
- script: '',
- 'script-props': '',
- 'script-export': '',
- attributes: '',
- traits: ['id', 'title'],
- propagate: '',
- dmode: '',
- toolbar: null,
- [keySymbol]: 0,
- [keySymbols]: 0,
- [keySymbolOvrd]: 0,
- _undo: true,
- _undoexc: ['status', 'open'],
-};
diff --git a/src/dom_components/model/ComponentComment.js b/src/dom_components/model/ComponentComment.js
index 020e86b92..15bfb1a05 100644
--- a/src/dom_components/model/ComponentComment.js
+++ b/src/dom_components/model/ComponentComment.js
@@ -1,24 +1,21 @@
-import Component from './ComponentTextNode';
+import ComponentTextNode from './ComponentTextNode';
-export default Component.extend(
- {
- defaults: {
- ...Component.prototype.defaults,
- },
+export default class ComponentComment extends ComponentTextNode {
+ get defaults() {
+ return { ...super.defaults };
+ }
+
+ toHTML() {
+ return ``;
+ }
+}
- toHTML() {
- return ``;
- },
- },
- {
- isComponent(el) {
- if (el.nodeType == 8) {
- return {
- tagName: 'NULL',
- type: 'comment',
- content: el.textContent,
- };
- }
- },
+ComponentComment.isComponent = el => {
+ if (el.nodeType == 8) {
+ return {
+ tagName: 'NULL',
+ type: 'comment',
+ content: el.textContent,
+ };
}
-);
+};
diff --git a/src/dom_components/model/ComponentFrame.js b/src/dom_components/model/ComponentFrame.js
index 82bb0cc9f..35e445200 100644
--- a/src/dom_components/model/ComponentFrame.js
+++ b/src/dom_components/model/ComponentFrame.js
@@ -3,21 +3,18 @@ import { toLowerCase } from 'utils/mixins';
const type = 'iframe';
-export default Component.extend(
- {
- defaults() {
- return {
- ...Component.prototype.defaults,
- type,
- tagName: type,
- droppable: false,
- resizable: true,
- traits: ['id', 'title', 'src'],
- attributes: { frameborder: '0' },
- };
- },
- },
- {
- isComponent: el => toLowerCase(el.tagName) === type,
+export default class ComponentFrame extends Component {
+ get defaults() {
+ return {
+ ...super.defaults,
+ type,
+ tagName: type,
+ droppable: false,
+ resizable: true,
+ traits: ['id', 'title', 'src'],
+ attributes: { frameborder: '0' },
+ };
}
-);
+}
+
+ComponentFrame.isComponent = el => toLowerCase(el.tagName) === type;
diff --git a/src/dom_components/model/ComponentImage.js b/src/dom_components/model/ComponentImage.js
index 185ec4d2e..6d3f638cd 100644
--- a/src/dom_components/model/ComponentImage.js
+++ b/src/dom_components/model/ComponentImage.js
@@ -5,10 +5,10 @@ import { toLowerCase, buildBase64UrlFromSvg } from 'utils/mixins';
const svgAttrs =
'xmlns="http://www.w3.org/2000/svg" width="100" viewBox="0 0 24 24" style="fill: rgba(0,0,0,0.15); transform: scale(0.75)"';
-export default Component.extend(
- {
- defaults: {
- ...Component.prototype.defaults,
+export default class ComponentImage extends Component {
+ get defaults() {
+ return {
+ ...super.defaults,
type: 'image',
tagName: 'img',
void: true,
@@ -19,130 +19,129 @@ export default Component.extend(
traits: ['alt'],
src: ``,
+
+ `,
// Fallback image in case the src can't be loaded
// If you use SVG, xmlns="http://www.w3.org/2000/svg" is required
fallback: ``,
+
+ `,
// File to load asynchronously once the model is rendered
file: '',
- },
+ };
+ }
- initialize(o, opt) {
- Component.prototype.initialize.apply(this, arguments);
- const { src } = this.get('attributes');
- if (src && buildBase64UrlFromSvg(result(this, 'defaults').src) !== src) {
- this.set('src', src, { silent: 1 });
- }
- },
-
- initToolbar(...args) {
- Component.prototype.initToolbar.apply(this, args);
- const em = this.em;
-
- if (em) {
- var cmd = em.get('Commands');
- var cmdName = 'image-editor';
-
- // Add Image Editor button only if the default command exists
- if (cmd.has(cmdName)) {
- let hasButtonBool = false;
- var tb = this.get('toolbar');
-
- for (let i = 0; i < tb.length; i++) {
- if (tb[i].command === 'image-editor') {
- hasButtonBool = true;
- break;
- }
- }
+ initialize(o, opt) {
+ Component.prototype.initialize.apply(this, arguments);
+ const { src } = this.get('attributes');
+ if (src && buildBase64UrlFromSvg(result(this, 'defaults').src) !== src) {
+ this.set('src', src, { silent: 1 });
+ }
+ }
+
+ initToolbar(...args) {
+ Component.prototype.initToolbar.apply(this, args);
+ const em = this.em;
+
+ if (em) {
+ var cmd = em.get('Commands');
+ var cmdName = 'image-editor';
- if (!hasButtonBool) {
- tb.push({
- attributes: { class: 'fa fa-pencil' },
- command: cmdName,
- });
- this.set('toolbar', tb);
+ // Add Image Editor button only if the default command exists
+ if (cmd.has(cmdName)) {
+ let hasButtonBool = false;
+ var tb = this.get('toolbar');
+
+ for (let i = 0; i < tb.length; i++) {
+ if (tb[i].command === 'image-editor') {
+ hasButtonBool = true;
+ break;
}
}
- }
- },
-
- /**
- * Returns object of attributes for HTML
- * @return {Object}
- * @private
- */
- getAttrToHTML(...args) {
- const attr = Component.prototype.getAttrToHTML.apply(this, args);
- const src = this.getSrcResult();
- if (src) attr.src = src;
- return attr;
- },
-
- getSrcResult(opt = {}) {
- const src = this.get(opt.fallback ? 'fallback' : 'src') || '';
- let result = src;
-
- if (src && src.substr(0, 4) === '