Skip to content

Commit 0c416cd

Browse files
committed
first public commit
Hi
0 parents  commit 0c416cd

File tree

14 files changed

+9902
-0
lines changed

14 files changed

+9902
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Configuration/Settings.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Neos:
2+
Neos:
3+
Ui:
4+
resources:
5+
javascript:
6+
'MhsDesign.LiveInspectorJsEvents:JsEvents':
7+
resource: resource://MhsDesign.LiveInspectorJsEvents/Public/JsEvents/Plugin.js

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# MhsDesign.LiveInspectorJsEvents
2+
3+
## Neos Ui Plugin for Inspector change events in the iframe.
4+
5+
### Usage
6+
7+
listen to the events (in the iframe):
8+
9+
```js
10+
document.addEventListener("MhsDesign.LiveInspectorJsEvents", (event) => {
11+
const crNode = event.detail.node
12+
13+
// fresh properties as key value object
14+
15+
// on discard all properties will be in this object.
16+
// except the ones starting with an underscore (private)
17+
const properties = event.detail.properties
18+
19+
// COMMIT or DISCARD
20+
const typeOfUserAction = event.detail.message
21+
})
22+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"description": "MhsDesign.LiveInspectorJsEvents",
3+
"scripts": {
4+
"build": "neos-react-scripts build",
5+
"watch": "neos-react-scripts watch"
6+
},
7+
"devDependencies": {
8+
"@neos-project/neos-ui-extensibility": "^7.1"
9+
},
10+
"neos": {
11+
"buildTargetDirectory": "../../Public/JsEvents"
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const filterObject = (obj, callback) => {
2+
return Object.fromEntries(Object.entries(obj)
3+
.filter(([key, val]) => callback(key, val)))
4+
}
5+
6+
export const filterOutPropertiesWithUnderscore = (obj) => {
7+
return filterObject(obj, (key, value) => key.startsWith("_") === false)
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./manifest');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import manifest from '@neos-project/neos-ui-extensibility';
2+
import onNodeChangeSendEvent from './onNodeChangeSendEvent'
3+
4+
manifest('MhsDesign.LiveInspectorJsEvents:JsEvents', {}, globalRegistry => {
5+
const sagasRegistry = globalRegistry.get('sagas');
6+
sagasRegistry.set('MhsDesign.LiveInspectorJsEvents/JsEvents', {saga: onNodeChangeSendEvent});
7+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
same functions as in '@neos-project/neos-ui-guest-frame/src/dom' but these files are not yet exposed
3+
but will be soon: https://github.com/neos/neos-ui/pull/2945
4+
*/
5+
6+
const getGuestFrameDocument = () => {
7+
const guestFrame = document.getElementsByName('neos-content-main')[0];
8+
return guestFrame && guestFrame.contentDocument;
9+
};
10+
11+
export const dispatchCustomEvent = (eventName, eventDescription, eventDetail = {}) => {
12+
const detail = {
13+
message: eventDescription,
14+
...eventDetail
15+
};
16+
const event = new CustomEvent(
17+
eventName,
18+
{
19+
detail,
20+
bubbles: true,
21+
cancelable: true
22+
}
23+
);
24+
getGuestFrameDocument().dispatchEvent(event);
25+
};
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {takeLatest, select} from 'redux-saga/effects'
2+
import {actionTypes, selectors} from '@neos-project/neos-ui-redux-store'
3+
4+
import {filterOutPropertiesWithUnderscore} from './helpers'
5+
// TODO: use consumer api soon: https://github.com/neos/neos-ui/pull/2945
6+
import {dispatchCustomEvent} from './neos-ui-guest-frame'
7+
8+
export default function* onNodeChangeSendEvent() {
9+
10+
// COMMIT happens on every subtle change in the inspector.
11+
yield takeLatest(actionTypes.UI.Inspector.COMMIT, function* (action) {
12+
13+
// alternative
14+
// const state = yield select();
15+
// const node = selectors.CR.Nodes.focusedSelector(state)
16+
17+
const node = action.payload.focusedNode
18+
19+
const changedNodeProperty = {}
20+
changedNodeProperty[action.payload.propertyId] = action.payload.value
21+
22+
dispatchCustomEvent('MhsDesign.LiveInspectorJsEvents', 'COMMIT', {
23+
node: node,
24+
properties: changedNodeProperty
25+
})
26+
})
27+
28+
// DISCARD happens when you dont apply the changes.
29+
yield takeLatest(actionTypes.UI.Inspector.DISCARD, function* (action) {
30+
31+
const state = yield select();
32+
const node = selectors.CR.Nodes.nodeByContextPath(state)(action.payload.focusedNodeContextPath)
33+
34+
dispatchCustomEvent('MhsDesign.LiveInspectorJsEvents', 'DISCARD', {
35+
node: node,
36+
properties: filterOutPropertiesWithUnderscore(node.properties)
37+
})
38+
})
39+
}
40+
41+
42+
/*
43+
44+
make sure you have the Redux DevTools installed:
45+
https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=de
46+
47+
The API from Neos.
48+
49+
node = {
50+
"identifier": "99257f0c-70f0-405b-a82b-fa8e375c23fb",
51+
...
52+
"properties": {
53+
"_creationDateTime": "2021-08-22T18:58:21+00:00",
54+
"_path": "/sites/root/main/node-l461lxh2i1a77",
55+
"_name": "node-l461lxh2i1a77",
56+
"_nodeType": "Vendor.Site:Content.Heading",
57+
...
58+
"title": "my String old"
59+
}
60+
61+
commitAction = {
62+
"type": "@neos/neos-ui/UI/Inspector/COMMIT",
63+
"payload": {
64+
"propertyId": "title",
65+
"value": "my String",
66+
...
67+
"focusedNode": node, // we get something like in the node above
68+
}
69+
}
70+
}
71+
72+
discardAction = {
73+
"type": "@neos/neos-ui/UI/Inspector/DISCARD",
74+
"payload": {
75+
"focusedNodeContextPath": "/sites/root/main/node-l461lxh2i1a77@user-mhs"
76+
// we can get all the node details from the CR via:
77+
// selectors.CR.Nodes.nodeByContextPath(state)(focusedNodeContextPath)
78+
}
79+
}
80+
81+
*/

0 commit comments

Comments
 (0)