@@ -15,6 +15,7 @@ const itemTypes = {
15
15
window . nextgenEditor . addHook ( 'hookInit' , ( ) => {
16
16
window . nextgenEditor . addButtonGroup ( 'page-inject' , {
17
17
label : 'Page Inject' ,
18
+ icon : `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z" /></svg>`
18
19
} ) ;
19
20
20
21
window . nextgenEditor . addButton ( 'page-inject-page' , {
@@ -216,99 +217,107 @@ window.nextgenEditor.addPlugin('GravPageInject', {
216
217
} ) ;
217
218
218
219
window . pageInjectRouteSettings = function pageInjectRouteSettings ( ) {
219
- const { editor } = window . nextgenEditor ;
220
+ const { editors } = window . nextgenEditor ;
220
221
221
222
const domPageInject = this . closest ( 'page-inject' ) ;
222
- const viewPageInject = editor . editing . view . domConverter . mapDomToView ( domPageInject ) ;
223
- const modelPageInject = editor . editing . mapper . toModelElement ( viewPageInject ) ;
224
- const route = modelPageInject . getAttribute ( 'route' ) ;
225
-
226
- showPagePicker ( route , ( page ) => {
227
- if ( page . value === route ) {
228
- return ;
229
- }
230
-
231
- editor . model . change ( ( modelWriter ) => {
232
- const attributes = [ ...modelPageInject . getAttributes ( ) ]
233
- . reduce ( ( acc , pair ) => ( { ...acc , [ pair . shift ( ) ] : pair . pop ( ) } ) , { } ) ;
234
-
235
- const dataNewPageInject = uncollapse ( `<page-inject type="${ attributes . type } " title="${ page . name } " route="${ page . value } " template="${ attributes . template } "></page-inject>` ) ;
236
- const viewNewPageInject = editor . data . processor . toView ( dataNewPageInject ) . getChild ( 0 ) ;
237
- const modelNewPageInject = editor . data . toModel ( viewNewPageInject , '$block' ) . getChild ( 0 ) ;
238
- const insertPosition = modelWriter . createPositionBefore ( modelPageInject ) ;
239
-
240
- modelWriter . remove ( modelPageInject ) ;
241
- modelWriter . insert ( modelNewPageInject , insertPosition ) ;
242
- modelWriter . setSelection ( modelNewPageInject , 'on' ) ;
223
+ const editor = ( editors . filter ( ( instance ) => instance . ui . view . element . contains ( domPageInject ) ) || [ ] ) . shift ( ) ;
224
+
225
+ if ( editor ) {
226
+ const viewPageInject = editor . editing . view . domConverter . mapDomToView ( domPageInject ) ;
227
+ const modelPageInject = editor . editing . mapper . toModelElement ( viewPageInject ) ;
228
+ const route = modelPageInject . getAttribute ( 'route' ) ;
229
+
230
+ showPagePicker ( route , ( page ) => {
231
+ if ( page . value === route ) {
232
+ return ;
233
+ }
234
+
235
+ editor . model . change ( ( modelWriter ) => {
236
+ const attributes = [ ...modelPageInject . getAttributes ( ) ]
237
+ . reduce ( ( acc , pair ) => ( { ...acc , [ pair . shift ( ) ] : pair . pop ( ) } ) , { } ) ;
238
+
239
+ const dataNewPageInject = uncollapse ( `<page-inject type="${ attributes . type } " title="${ page . name } " route="${ page . value } " template="${ attributes . template } "></page-inject>` ) ;
240
+ const viewNewPageInject = editor . data . processor . toView ( dataNewPageInject ) . getChild ( 0 ) ;
241
+ const modelNewPageInject = editor . data . toModel ( viewNewPageInject , '$block' ) . getChild ( 0 ) ;
242
+ const insertPosition = modelWriter . createPositionBefore ( modelPageInject ) ;
243
+
244
+ modelWriter . remove ( modelPageInject ) ;
245
+ modelWriter . insert ( modelNewPageInject , insertPosition ) ;
246
+ modelWriter . setSelection ( modelNewPageInject , 'on' ) ;
247
+ } ) ;
243
248
} ) ;
244
- } ) ;
249
+ }
245
250
} ;
246
251
247
252
window . pageInjectSettings = function pageInjectSettings ( ) {
248
- const { editor } = window . nextgenEditor ;
253
+ const { editors } = window . nextgenEditor ;
249
254
250
255
const domPageInject = this . closest ( 'page-inject' ) ;
251
- const viewPageInject = editor . editing . view . domConverter . mapDomToView ( domPageInject ) ;
252
- let modelPageInject = editor . editing . mapper . toModelElement ( viewPageInject ) ;
253
-
254
- const currentAttributes = [ ...modelPageInject . getAttributes ( ) ]
255
- . reduce ( ( acc , pair ) => ( { ...acc , [ pair . shift ( ) ] : pair . pop ( ) } ) , { } ) ;
256
-
257
- const attributes = {
258
- type : {
259
- title : 'Type' ,
260
- widget : {
261
- type : 'select' ,
262
- values : Object . keys ( itemTypes ) . map ( ( value ) => ( { value, label : itemTypes [ value ] } ) ) ,
256
+ const editor = ( editors . filter ( ( instance ) => instance . ui . view . element . contains ( domPageInject ) ) || [ ] ) . shift ( ) ;
257
+
258
+ if ( editor ) {
259
+ const viewPageInject = editor . editing . view . domConverter . mapDomToView ( domPageInject ) ;
260
+ let modelPageInject = editor . editing . mapper . toModelElement ( viewPageInject ) ;
261
+
262
+ const currentAttributes = [ ...modelPageInject . getAttributes ( ) ]
263
+ . reduce ( ( acc , pair ) => ( { ...acc , [ pair . shift ( ) ] : pair . pop ( ) } ) , { } ) ;
264
+
265
+ const attributes = {
266
+ type : {
267
+ title : 'Type' ,
268
+ widget : {
269
+ type : 'select' ,
270
+ values : Object . keys ( itemTypes ) . map ( ( value ) => ( { value, label : itemTypes [ value ] } ) ) ,
271
+ } ,
263
272
} ,
264
- } ,
265
- template : {
266
- title : 'Template' ,
267
- widget : {
268
- type : 'input-text ' ,
269
- // type: 'select',
270
- // values: [
271
- // { value: '' , label: '' } ,
272
- // ...Object.keys(availableTemplates).map((value) => ({ value, label: availableTemplates[value] })) ,
273
- // ] ,
274
- visible : ( { attributes } ) => attributes . type === 'page' ,
273
+ template : {
274
+ title : 'Template' ,
275
+ widget : {
276
+ type : 'input-text' ,
277
+ // type: 'select ',
278
+ // values: [
279
+ // { value: '', label: '' },
280
+ // ...Object.keys(availableTemplates).map((value) => ( { value, label: availableTemplates[value] })) ,
281
+ // ] ,
282
+ visible : ( { attributes } ) => attributes . type === 'page' ,
283
+ } ,
275
284
} ,
276
- } ,
277
- } ;
278
-
279
- const argsForPopup = {
280
- title : 'Page Inject' ,
281
- domDisplayPoint : this ,
282
- debounceDelay : 1000 ,
283
- attributes,
284
- currentAttributes,
285
- } ;
286
-
287
- argsForPopup . deleteItem = ( ) => {
288
- editor . model . change ( ( modelWriter ) => modelWriter . remove ( modelPageInject ) ) ;
289
- } ;
290
-
291
- argsForPopup . changeAttributes = ( changeCallback ) => {
292
- editor . model . change ( ( modelWriter ) => {
293
- const dataNewPageInject = uncollapse ( `<page-inject type="${ currentAttributes . type } " title="${ currentAttributes . title } " route="${ currentAttributes . route } " template="${ currentAttributes . template } "></page-inject>` ) ;
294
- const viewNewPageInject = editor . data . processor . toView ( dataNewPageInject ) . getChild ( 0 ) ;
295
- const modelNewPageInject = editor . data . toModel ( viewNewPageInject , '$block' ) . getChild ( 0 ) ;
296
- const insertPosition = modelWriter . createPositionBefore ( modelPageInject ) ;
297
-
298
- modelWriter . remove ( modelPageInject ) ;
299
- modelWriter . insert ( modelNewPageInject , insertPosition ) ;
300
- modelWriter . setSelection ( modelNewPageInject , 'on' ) ;
301
-
302
- modelPageInject = modelNewPageInject ;
303
- } ) ;
285
+ } ;
286
+
287
+ const argsForPopup = {
288
+ title : 'Page Inject' ,
289
+ domDisplayPoint : this ,
290
+ debounceDelay : 1000 ,
291
+ attributes,
292
+ currentAttributes,
293
+ } ;
294
+
295
+ argsForPopup . deleteItem = ( ) => {
296
+ editor . model . change ( ( modelWriter ) => modelWriter . remove ( modelPageInject ) ) ;
297
+ } ;
298
+
299
+ argsForPopup . changeAttributes = ( changeCallback ) => {
300
+ editor . model . change ( ( modelWriter ) => {
301
+ const dataNewPageInject = uncollapse ( `<page-inject type="${ currentAttributes . type } " title="${ currentAttributes . title } " route="${ currentAttributes . route } " template="${ currentAttributes . template } "></page-inject>` ) ;
302
+ const viewNewPageInject = editor . data . processor . toView ( dataNewPageInject ) . getChild ( 0 ) ;
303
+ const modelNewPageInject = editor . data . toModel ( viewNewPageInject , '$block' ) . getChild ( 0 ) ;
304
+ const insertPosition = modelWriter . createPositionBefore ( modelPageInject ) ;
305
+
306
+ modelWriter . remove ( modelPageInject ) ;
307
+ modelWriter . insert ( modelNewPageInject , insertPosition ) ;
308
+ modelWriter . setSelection ( modelNewPageInject , 'on' ) ;
309
+
310
+ modelPageInject = modelNewPageInject ;
311
+ } ) ;
304
312
305
- if ( currentAttributes . type !== 'page' && currentAttributes . template ) {
306
- currentAttributes . template = '' ;
307
- changeCallback ( ) ;
308
- }
309
- } ;
313
+ if ( currentAttributes . type !== 'page' && currentAttributes . template ) {
314
+ currentAttributes . template = '' ;
315
+ changeCallback ( ) ;
316
+ }
317
+ } ;
310
318
311
- showSettingsPopup ( argsForPopup ) ;
319
+ showSettingsPopup ( argsForPopup ) ;
320
+ }
312
321
} ;
313
322
314
323
} ) ( ) ;
0 commit comments