Skip to content

Commit

Permalink
Merge branch 'release/1.4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Apr 27, 2021
2 parents b86040d + 03b9989 commit 6a7fad0
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 84 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v1.4.5
## 04/27/2021

1. [](#improved)
* NextGen Editor: Added toolbar icon
* NextGen Editor: Added support for multiple editor instances
1. [](#bugfix)
* Fixed permissions to only require `pages.read` for `taskPageInject` [premium-issues#43](https://github.com/getgrav/grav-premium-issues/issues/43)

# v1.4.4
## 01/29/2021

Expand All @@ -10,7 +19,7 @@

1. [](#improved)
* NextGen Editor: Updated upcast/downcast syntax to support latest version

# v1.4.2
## 12/20/2020

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Page Inject
type: plugin
slug: page-inject
version: 1.4.4
version: 1.4.5
description: "**Page Inject** is a powerful plugin that lets you inject entire pages or page content into other pages using simple markdown syntax"
icon: trello
author:
Expand Down
171 changes: 90 additions & 81 deletions nextgen-editor/plugins/page-inject/page-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const itemTypes = {
window.nextgenEditor.addHook('hookInit', () => {
window.nextgenEditor.addButtonGroup('page-inject', {
label: 'Page Inject',
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>`
});

window.nextgenEditor.addButton('page-inject-page', {
Expand Down Expand Up @@ -216,99 +217,107 @@ window.nextgenEditor.addPlugin('GravPageInject', {
});

window.pageInjectRouteSettings = function pageInjectRouteSettings() {
const { editor } = window.nextgenEditor;
const { editors } = window.nextgenEditor;

const domPageInject = this.closest('page-inject');
const viewPageInject = editor.editing.view.domConverter.mapDomToView(domPageInject);
const modelPageInject = editor.editing.mapper.toModelElement(viewPageInject);
const route = modelPageInject.getAttribute('route');

showPagePicker(route, (page) => {
if (page.value === route) {
return;
}

editor.model.change((modelWriter) => {
const attributes = [...modelPageInject.getAttributes()]
.reduce((acc, pair) => ({ ...acc, [pair.shift()]: pair.pop() }), {});

const dataNewPageInject = uncollapse(`<page-inject type="${attributes.type}" title="${page.name}" route="${page.value}" template="${attributes.template}"></page-inject>`);
const viewNewPageInject = editor.data.processor.toView(dataNewPageInject).getChild(0);
const modelNewPageInject = editor.data.toModel(viewNewPageInject, '$block').getChild(0);
const insertPosition = modelWriter.createPositionBefore(modelPageInject);

modelWriter.remove(modelPageInject);
modelWriter.insert(modelNewPageInject, insertPosition);
modelWriter.setSelection(modelNewPageInject, 'on');
const editor = (editors.filter((instance) => instance.ui.view.element.contains(domPageInject)) || []).shift();

if (editor) {
const viewPageInject = editor.editing.view.domConverter.mapDomToView(domPageInject);
const modelPageInject = editor.editing.mapper.toModelElement(viewPageInject);
const route = modelPageInject.getAttribute('route');

showPagePicker(route, (page) => {
if (page.value === route) {
return;
}

editor.model.change((modelWriter) => {
const attributes = [...modelPageInject.getAttributes()]
.reduce((acc, pair) => ({ ...acc, [pair.shift()]: pair.pop() }), {});

const dataNewPageInject = uncollapse(`<page-inject type="${attributes.type}" title="${page.name}" route="${page.value}" template="${attributes.template}"></page-inject>`);
const viewNewPageInject = editor.data.processor.toView(dataNewPageInject).getChild(0);
const modelNewPageInject = editor.data.toModel(viewNewPageInject, '$block').getChild(0);
const insertPosition = modelWriter.createPositionBefore(modelPageInject);

modelWriter.remove(modelPageInject);
modelWriter.insert(modelNewPageInject, insertPosition);
modelWriter.setSelection(modelNewPageInject, 'on');
});
});
});
}
};

window.pageInjectSettings = function pageInjectSettings() {
const { editor } = window.nextgenEditor;
const { editors } = window.nextgenEditor;

const domPageInject = this.closest('page-inject');
const viewPageInject = editor.editing.view.domConverter.mapDomToView(domPageInject);
let modelPageInject = editor.editing.mapper.toModelElement(viewPageInject);

const currentAttributes = [...modelPageInject.getAttributes()]
.reduce((acc, pair) => ({ ...acc, [pair.shift()]: pair.pop() }), {});

const attributes = {
type: {
title: 'Type',
widget: {
type: 'select',
values: Object.keys(itemTypes).map((value) => ({ value, label: itemTypes[value] })),
const editor = (editors.filter((instance) => instance.ui.view.element.contains(domPageInject)) || []).shift();

if (editor) {
const viewPageInject = editor.editing.view.domConverter.mapDomToView(domPageInject);
let modelPageInject = editor.editing.mapper.toModelElement(viewPageInject);

const currentAttributes = [...modelPageInject.getAttributes()]
.reduce((acc, pair) => ({...acc, [pair.shift()]: pair.pop()}), {});

const attributes = {
type: {
title: 'Type',
widget: {
type: 'select',
values: Object.keys(itemTypes).map((value) => ({value, label: itemTypes[value]})),
},
},
},
template: {
title: 'Template',
widget: {
type: 'input-text',
// type: 'select',
// values: [
// { value: '', label: '' },
// ...Object.keys(availableTemplates).map((value) => ({ value, label: availableTemplates[value] })),
// ],
visible: ({ attributes }) => attributes.type === 'page',
template: {
title: 'Template',
widget: {
type: 'input-text',
// type: 'select',
// values: [
// { value: '', label: '' },
// ...Object.keys(availableTemplates).map((value) => ({ value, label: availableTemplates[value] })),
// ],
visible: ({attributes}) => attributes.type === 'page',
},
},
},
};

const argsForPopup = {
title: 'Page Inject',
domDisplayPoint: this,
debounceDelay: 1000,
attributes,
currentAttributes,
};

argsForPopup.deleteItem = () => {
editor.model.change((modelWriter) => modelWriter.remove(modelPageInject));
};

argsForPopup.changeAttributes = (changeCallback) => {
editor.model.change((modelWriter) => {
const dataNewPageInject = uncollapse(`<page-inject type="${currentAttributes.type}" title="${currentAttributes.title}" route="${currentAttributes.route}" template="${currentAttributes.template}"></page-inject>`);
const viewNewPageInject = editor.data.processor.toView(dataNewPageInject).getChild(0);
const modelNewPageInject = editor.data.toModel(viewNewPageInject, '$block').getChild(0);
const insertPosition = modelWriter.createPositionBefore(modelPageInject);

modelWriter.remove(modelPageInject);
modelWriter.insert(modelNewPageInject, insertPosition);
modelWriter.setSelection(modelNewPageInject, 'on');

modelPageInject = modelNewPageInject;
});
};

const argsForPopup = {
title: 'Page Inject',
domDisplayPoint: this,
debounceDelay: 1000,
attributes,
currentAttributes,
};

argsForPopup.deleteItem = () => {
editor.model.change((modelWriter) => modelWriter.remove(modelPageInject));
};

argsForPopup.changeAttributes = (changeCallback) => {
editor.model.change((modelWriter) => {
const dataNewPageInject = uncollapse(`<page-inject type="${currentAttributes.type}" title="${currentAttributes.title}" route="${currentAttributes.route}" template="${currentAttributes.template}"></page-inject>`);
const viewNewPageInject = editor.data.processor.toView(dataNewPageInject).getChild(0);
const modelNewPageInject = editor.data.toModel(viewNewPageInject, '$block').getChild(0);
const insertPosition = modelWriter.createPositionBefore(modelPageInject);

modelWriter.remove(modelPageInject);
modelWriter.insert(modelNewPageInject, insertPosition);
modelWriter.setSelection(modelNewPageInject, 'on');

modelPageInject = modelNewPageInject;
});

if (currentAttributes.type !== 'page' && currentAttributes.template) {
currentAttributes.template = '';
changeCallback();
}
};
if (currentAttributes.type !== 'page' && currentAttributes.template) {
currentAttributes.template = '';
changeCallback();
}
};

showSettingsPopup(argsForPopup);
showSettingsPopup(argsForPopup);
}
};

})();
2 changes: 1 addition & 1 deletion page-inject.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function onAdminTaskExecute(Event $e): void
header('Cache-Control: no-cache, no-store, must-revalidate');
$controller = $e['controller'];

if (!$controller->authorizeTask('pageInject', ['admin.pages', 'admin.super'])) {
if (!$controller->authorizeTask('pageInject', ['admin.pages.read', 'admin.super'])) {
http_response_code(401);
$json_response = [
'status' => 'error',
Expand Down

0 comments on commit 6a7fad0

Please sign in to comment.