Skip to content

Commit 6a7fad0

Browse files
committed
Merge branch 'release/1.4.5'
2 parents b86040d + 03b9989 commit 6a7fad0

File tree

4 files changed

+102
-84
lines changed

4 files changed

+102
-84
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v1.4.5
2+
## 04/27/2021
3+
4+
1. [](#improved)
5+
* NextGen Editor: Added toolbar icon
6+
* NextGen Editor: Added support for multiple editor instances
7+
1. [](#bugfix)
8+
* Fixed permissions to only require `pages.read` for `taskPageInject` [premium-issues#43](https://github.com/getgrav/grav-premium-issues/issues/43)
9+
110
# v1.4.4
211
## 01/29/2021
312

@@ -10,7 +19,7 @@
1019

1120
1. [](#improved)
1221
* NextGen Editor: Updated upcast/downcast syntax to support latest version
13-
22+
1423
# v1.4.2
1524
## 12/20/2020
1625

blueprints.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Page Inject
22
type: plugin
33
slug: page-inject
4-
version: 1.4.4
4+
version: 1.4.5
55
description: "**Page Inject** is a powerful plugin that lets you inject entire pages or page content into other pages using simple markdown syntax"
66
icon: trello
77
author:

nextgen-editor/plugins/page-inject/page-inject.js

Lines changed: 90 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const itemTypes = {
1515
window.nextgenEditor.addHook('hookInit', () => {
1616
window.nextgenEditor.addButtonGroup('page-inject', {
1717
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>`
1819
});
1920

2021
window.nextgenEditor.addButton('page-inject-page', {
@@ -216,99 +217,107 @@ window.nextgenEditor.addPlugin('GravPageInject', {
216217
});
217218

218219
window.pageInjectRouteSettings = function pageInjectRouteSettings() {
219-
const { editor } = window.nextgenEditor;
220+
const { editors } = window.nextgenEditor;
220221

221222
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+
});
243248
});
244-
});
249+
}
245250
};
246251

247252
window.pageInjectSettings = function pageInjectSettings() {
248-
const { editor } = window.nextgenEditor;
253+
const { editors } = window.nextgenEditor;
249254

250255
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+
},
263272
},
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+
},
275284
},
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+
});
304312

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+
};
310318

311-
showSettingsPopup(argsForPopup);
319+
showSettingsPopup(argsForPopup);
320+
}
312321
};
313322

314323
})();

page-inject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function onAdminTaskExecute(Event $e): void
6767
header('Cache-Control: no-cache, no-store, must-revalidate');
6868
$controller = $e['controller'];
6969

70-
if (!$controller->authorizeTask('pageInject', ['admin.pages', 'admin.super'])) {
70+
if (!$controller->authorizeTask('pageInject', ['admin.pages.read', 'admin.super'])) {
7171
http_response_code(401);
7272
$json_response = [
7373
'status' => 'error',

0 commit comments

Comments
 (0)