Skip to content

Commit

Permalink
first public commit
Browse files Browse the repository at this point in the history
Hi
  • Loading branch information
mhsdesign committed Sep 5, 2021
0 parents commit 0c416cd
Show file tree
Hide file tree
Showing 14 changed files with 9,902 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Neos:
Neos:
Ui:
resources:
javascript:
'MhsDesign.LiveInspectorJsEvents:JsEvents':
resource: resource://MhsDesign.LiveInspectorJsEvents/Public/JsEvents/Plugin.js
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# MhsDesign.LiveInspectorJsEvents

## Neos Ui Plugin for Inspector change events in the iframe.

### Usage

listen to the events (in the iframe):

```js
document.addEventListener("MhsDesign.LiveInspectorJsEvents", (event) => {
const crNode = event.detail.node

// fresh properties as key value object

// on discard all properties will be in this object.
// except the ones starting with an underscore (private)
const properties = event.detail.properties

// COMMIT or DISCARD
const typeOfUserAction = event.detail.message
})
```
13 changes: 13 additions & 0 deletions Resources/Private/JsEvents/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "MhsDesign.LiveInspectorJsEvents",
"scripts": {
"build": "neos-react-scripts build",
"watch": "neos-react-scripts watch"
},
"devDependencies": {
"@neos-project/neos-ui-extensibility": "^7.1"
},
"neos": {
"buildTargetDirectory": "../../Public/JsEvents"
}
}
8 changes: 8 additions & 0 deletions Resources/Private/JsEvents/src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const filterObject = (obj, callback) => {
return Object.fromEntries(Object.entries(obj)
.filter(([key, val]) => callback(key, val)))
}

export const filterOutPropertiesWithUnderscore = (obj) => {
return filterObject(obj, (key, value) => key.startsWith("_") === false)
}
1 change: 1 addition & 0 deletions Resources/Private/JsEvents/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./manifest');
7 changes: 7 additions & 0 deletions Resources/Private/JsEvents/src/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import manifest from '@neos-project/neos-ui-extensibility';
import onNodeChangeSendEvent from './onNodeChangeSendEvent'

manifest('MhsDesign.LiveInspectorJsEvents:JsEvents', {}, globalRegistry => {
const sagasRegistry = globalRegistry.get('sagas');
sagasRegistry.set('MhsDesign.LiveInspectorJsEvents/JsEvents', {saga: onNodeChangeSendEvent});
});
25 changes: 25 additions & 0 deletions Resources/Private/JsEvents/src/neos-ui-guest-frame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
same functions as in '@neos-project/neos-ui-guest-frame/src/dom' but these files are not yet exposed
but will be soon: https://github.com/neos/neos-ui/pull/2945
*/

const getGuestFrameDocument = () => {
const guestFrame = document.getElementsByName('neos-content-main')[0];
return guestFrame && guestFrame.contentDocument;
};

export const dispatchCustomEvent = (eventName, eventDescription, eventDetail = {}) => {
const detail = {
message: eventDescription,
...eventDetail
};
const event = new CustomEvent(
eventName,
{
detail,
bubbles: true,
cancelable: true
}
);
getGuestFrameDocument().dispatchEvent(event);
};
81 changes: 81 additions & 0 deletions Resources/Private/JsEvents/src/onNodeChangeSendEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {takeLatest, select} from 'redux-saga/effects'
import {actionTypes, selectors} from '@neos-project/neos-ui-redux-store'

import {filterOutPropertiesWithUnderscore} from './helpers'
// TODO: use consumer api soon: https://github.com/neos/neos-ui/pull/2945
import {dispatchCustomEvent} from './neos-ui-guest-frame'

export default function* onNodeChangeSendEvent() {

// COMMIT happens on every subtle change in the inspector.
yield takeLatest(actionTypes.UI.Inspector.COMMIT, function* (action) {

// alternative
// const state = yield select();
// const node = selectors.CR.Nodes.focusedSelector(state)

const node = action.payload.focusedNode

const changedNodeProperty = {}
changedNodeProperty[action.payload.propertyId] = action.payload.value

dispatchCustomEvent('MhsDesign.LiveInspectorJsEvents', 'COMMIT', {
node: node,
properties: changedNodeProperty
})
})

// DISCARD happens when you dont apply the changes.
yield takeLatest(actionTypes.UI.Inspector.DISCARD, function* (action) {

const state = yield select();
const node = selectors.CR.Nodes.nodeByContextPath(state)(action.payload.focusedNodeContextPath)

dispatchCustomEvent('MhsDesign.LiveInspectorJsEvents', 'DISCARD', {
node: node,
properties: filterOutPropertiesWithUnderscore(node.properties)
})
})
}


/*
make sure you have the Redux DevTools installed:
https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=de
The API from Neos.
node = {
"identifier": "99257f0c-70f0-405b-a82b-fa8e375c23fb",
...
"properties": {
"_creationDateTime": "2021-08-22T18:58:21+00:00",
"_path": "/sites/root/main/node-l461lxh2i1a77",
"_name": "node-l461lxh2i1a77",
"_nodeType": "Vendor.Site:Content.Heading",
...
"title": "my String old"
}
commitAction = {
"type": "@neos/neos-ui/UI/Inspector/COMMIT",
"payload": {
"propertyId": "title",
"value": "my String",
...
"focusedNode": node, // we get something like in the node above
}
}
}
discardAction = {
"type": "@neos/neos-ui/UI/Inspector/DISCARD",
"payload": {
"focusedNodeContextPath": "/sites/root/main/node-l461lxh2i1a77@user-mhs"
// we can get all the node details from the CR via:
// selectors.CR.Nodes.nodeByContextPath(state)(focusedNodeContextPath)
}
}
*/
Loading

0 comments on commit 0c416cd

Please sign in to comment.