Skip to content

Commit a306a2c

Browse files
committed
NextGen Editor: Added support for multiple editor instances
1 parent 3e3b8d1 commit a306a2c

File tree

7 files changed

+387
-297
lines changed

7 files changed

+387
-297
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
1. [](#improved)
55
* Added the ability to enable/disable built-in notice CSS
6+
* NextGen Editor: Added support for multiple editor instances
67

78
# v5.0.5
89
## 03/12/2021

nextgen-editor/dist/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nextgen-editor/dist/js/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nextgen-editor/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
"lint": "vue-cli-service lint"
1010
},
1111
"devDependencies": {
12-
"@vue/cli-plugin-babel": "~4.5.10",
13-
"@vue/cli-plugin-eslint": "~4.5.10",
14-
"@vue/cli-service": "~4.5.10",
12+
"@vue/cli-plugin-babel": "~4.5.12",
13+
"@vue/cli-plugin-eslint": "~4.5.12",
14+
"@vue/cli-service": "~4.5.12",
1515
"@vue/eslint-config-airbnb": "^5.3.0",
1616
"babel-eslint": "^10.1.0",
1717
"directory-named-webpack-plugin": "^4.0.1",
18-
"eslint": "^7.17.0",
18+
"eslint": "^7.25.0",
1919
"eslint-plugin-import": "^2.22.1",
20-
"eslint-plugin-vue": "^7.4.1",
20+
"eslint-plugin-vue": "^7.9.0",
2121
"node-sass": "^5.0.0",
22-
"sass-loader": "^10.1.0"
22+
"sass-loader": "^11.0.1"
2323
}
2424
}

nextgen-editor/src/events.js

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,78 @@ window.scDisplaySettings = function scDisplaySettings() {
99
};
1010

1111
window.scBlockAddChildFromParent = function scBlockAddChildFromParent() {
12-
const { editor } = window.nextgenEditor;
12+
const { editors } = window.nextgenEditor;
1313

1414
const domShortcode = this.parentNode;
15+
const editor = (editors.filter((instance) => instance.ui.view.element.contains(domShortcode)) || []).shift();
16+
1517
const name = domShortcode.getAttribute('name');
1618
const shortcode = window.nextgenEditor.shortcodes[name];
17-
const viewShortcode = editor.editing.view.domConverter.mapDomToView(domShortcode);
18-
const modelShortcode = editor.editing.mapper.toModelElement(viewShortcode);
1919

20-
const domShortcodeBlockReadOnly = domShortcode.querySelector('shortcode-block-readonly');
21-
const viewShortcodeBlockReadOnly = editor.editing.view.domConverter.mapDomToView(domShortcodeBlockReadOnly);
22-
const modelShortcodeBlockReadOnly = editor.editing.mapper.toModelElement(viewShortcodeBlockReadOnly);
20+
if (editor) {
21+
const viewShortcode = editor.editing.view.domConverter.mapDomToView(domShortcode);
22+
const modelShortcode = editor.editing.mapper.toModelElement(viewShortcode);
23+
24+
const domShortcodeBlockReadOnly = domShortcode.querySelector('shortcode-block-readonly');
25+
const viewShortcodeBlockReadOnly = editor.editing.view.domConverter.mapDomToView(domShortcodeBlockReadOnly);
26+
const modelShortcodeBlockReadOnly = editor.editing.mapper.toModelElement(viewShortcodeBlockReadOnly);
2327

24-
editor.model.change((modelWriter) => {
25-
const insertPosition = modelWriter.createPositionAt(modelShortcodeBlockReadOnly, 0);
26-
editor.execute(`shortcode_${shortcode.child.name}`, { insertPosition, modelParentShortcode: modelShortcode });
28+
editor.model.change((modelWriter) => {
29+
const insertPosition = modelWriter.createPositionAt(modelShortcodeBlockReadOnly, 0);
30+
editor.execute(`shortcode_${shortcode.child.name}`, { insertPosition, modelParentShortcode: modelShortcode });
2731

28-
domShortcode.querySelector('.sc-add-child').classList.remove('sc-visible');
29-
});
32+
domShortcode.querySelector('.sc-add-child').classList.remove('sc-visible');
33+
});
34+
}
3035
};
3136

3237
window.scBlockAddChild = function scBlockAddChild(event, where) {
33-
const { editor } = window.nextgenEditor;
38+
const { editors } = window.nextgenEditor;
3439

3540
const domShortcode = this.parentNode;
41+
const editor = (editors.filter((instance) => instance.ui.view.element.contains(domShortcode)) || []).shift();
42+
3643
const name = domShortcode.getAttribute('name');
3744
const shortcode = window.nextgenEditor.shortcodes[name];
38-
const viewShortcode = editor.editing.view.domConverter.mapDomToView(domShortcode);
39-
const modelShortcode = editor.editing.mapper.toModelElement(viewShortcode);
4045

41-
editor.model.change((modelWriter) => {
42-
let modelParentShortcode = modelShortcode.parent;
43-
const insertPosition = modelWriter.createPositionAt(modelShortcode, where);
46+
if (editor) {
47+
const viewShortcode = editor.editing.view.domConverter.mapDomToView(domShortcode);
48+
const modelShortcode = editor.editing.mapper.toModelElement(viewShortcode);
4449

45-
while (modelParentShortcode && modelParentShortcode.name !== 'shortcode-block') {
46-
modelParentShortcode = modelParentShortcode.parent;
47-
}
50+
editor.model.change((modelWriter) => {
51+
let modelParentShortcode = modelShortcode.parent;
52+
const insertPosition = modelWriter.createPositionAt(modelShortcode, where);
4853

49-
if (modelParentShortcode) {
50-
editor.execute(`shortcode_${shortcode.name}`, { insertPosition, modelParentShortcode });
51-
}
52-
});
54+
while (modelParentShortcode && modelParentShortcode.name !== 'shortcode-block') {
55+
modelParentShortcode = modelParentShortcode.parent;
56+
}
57+
58+
if (modelParentShortcode) {
59+
editor.execute(`shortcode_${shortcode.name}`, { insertPosition, modelParentShortcode });
60+
}
61+
});
62+
}
5363
};
5464

5565
window.scBlockMoveChild = function scBlockMove(event, where) {
56-
const { editor } = window.nextgenEditor;
66+
const { editors } = window.nextgenEditor;
5767

5868
const domShortcode = this.parentNode;
59-
const viewShortcode = editor.editing.view.domConverter.mapDomToView(domShortcode);
60-
const modelShortcode = editor.editing.mapper.toModelElement(viewShortcode);
69+
const editor = (editors.filter((instance) => instance.ui.view.element.contains(domShortcode)) || []).shift();
6170

62-
const domSiblingShortcode = where === 'up'
63-
? domShortcode.previousSibling
64-
: domShortcode.nextSibling;
71+
if (editor) {
72+
const viewShortcode = editor.editing.view.domConverter.mapDomToView(domShortcode);
73+
const modelShortcode = editor.editing.mapper.toModelElement(viewShortcode);
6574

66-
const viewSiblingShortcode = editor.editing.view.domConverter.mapDomToView(domSiblingShortcode);
67-
const modelSiblingShortcode = editor.editing.mapper.toModelElement(viewSiblingShortcode);
75+
const domSiblingShortcode = where === 'up'
76+
? domShortcode.previousSibling
77+
: domShortcode.nextSibling;
6878

69-
editor.model.change((modelWriter) => {
70-
modelWriter.move(modelWriter.createRangeOn(modelShortcode), modelSiblingShortcode, where === 'up' ? 'before' : 'after');
71-
});
79+
const viewSiblingShortcode = editor.editing.view.domConverter.mapDomToView(domSiblingShortcode);
80+
const modelSiblingShortcode = editor.editing.mapper.toModelElement(viewSiblingShortcode);
81+
82+
editor.model.change((modelWriter) => {
83+
modelWriter.move(modelWriter.createRangeOn(modelShortcode), modelSiblingShortcode, where === 'up' ? 'before' : 'after');
84+
});
85+
}
7286
};

0 commit comments

Comments
 (0)