@@ -9,64 +9,78 @@ window.scDisplaySettings = function scDisplaySettings() {
99} ;
1010
1111window . 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
3237window . 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
5565window . 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