-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmanifest.js
More file actions
215 lines (210 loc) · 7.22 KB
/
manifest.js
File metadata and controls
215 lines (210 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import React, { PureComponent, useState } from "react";
import ReactDOM from "react-dom";
import manifest from "@neos-project/neos-ui-extensibility";
import { selectors } from "@neos-project/neos-ui-redux-store";
import { DropDown, Icon } from "@neos-project/react-ui-components";
import { connect } from "react-redux";
import { $transform, $get } from "plow-js";
import { Provider } from "react-redux";
import { DndProvider } from "react-dnd";
import HTML5Backend from "react-dnd-html5-backend";
import { EditorEnvelope } from "@neos-project/neos-ui-editors";
import { NeosContext } from "@neos-project/neos-ui-decorators";
import SecondaryInspector from "./SecondaryInspector/index";
let renderSecondaryInspector = () => {};
const InlineSecondaryInspector = () => {
const [state, setState] = useState({
secondaryInspectorName: undefined,
secondaryInspectorComponent: undefined,
});
const closeSecondaryInspector = () => {
setState({
secondaryInspectorName: undefined,
secondaryInspectorComponent: undefined,
});
};
renderSecondaryInspector = (
secondaryInspectorName,
secondaryInspectorComponentFactory
) => {
if (state.secondaryInspectorName === secondaryInspectorName) {
// We toggle the secondary inspector if it is rendered a second time; so that's why we hide it here.
closeSecondaryInspector();
} else {
let secondaryInspectorComponent = null;
if (secondaryInspectorComponentFactory) {
// Hint: we directly resolve the factory function here, to ensure the object is not re-created on every render but stays the same for its whole lifetime.
secondaryInspectorComponent = secondaryInspectorComponentFactory();
}
setState({
secondaryInspectorName,
secondaryInspectorComponent,
});
}
};
return state.secondaryInspectorComponent ? (
<SecondaryInspector onClose={closeSecondaryInspector}>
{state.secondaryInspectorComponent}
</SecondaryInspector>
) : null;
};
@connect(
$transform({
currentlyEditedPropertyName:
selectors.UI.ContentCanvas.currentlyEditedPropertyName,
getNodeByContextPath: selectors.CR.Nodes.nodeByContextPath,
focusedNodePath: selectors.CR.Nodes.focusedNodePathSelector,
})
)
class InlineEditorEnvelope extends PureComponent {
state = {
isOpen: false,
};
handleToggle = () => {
this.setState({ isOpen: !this.state.isOpen });
};
render() {
const {
contextPath,
fusionPath,
propertyName,
persistChange,
editorOptions,
getNodeByContextPath,
} = this.props;
const node = getNodeByContextPath(contextPath);
const nodeTypeName = $get("nodeType", node);
const nodeType = this.props.nodeTypesRegistry.getNodeType(nodeTypeName);
const icon = $get("icon", editorOptions) || "pencil";
const value = $get(["properties", propertyName], node);
return (
<div style={{ display: "inline-block" }}>
<DropDown.Stateless
isOpen={this.state.isOpen}
padded={true}
onToggle={this.handleToggle}
onClose={() => null}
>
<DropDown.Header className="enveloper_dropdown_header">
<style>
{
"\
.enveloper_dropdown_header{\
position: relative;\
width: 30px;\
height: 30px;\
padding: 0;\
}\
.enveloper_dropdown_icon{\
position: absolute;\
top: 8px;\
left: 8px;\
}\
.enveloper_dropdown_contents{\
width: 320px;\
background-color: #272727;\
}\
.enveloper_dropdown_header svg:nth-child(3) {\
display: none;\
}\
"
}
</style>
<Icon className="enveloper_dropdown_icon" icon={icon} />
</DropDown.Header>
<DropDown.Contents
className="enveloper_dropdown_contents"
scrollable={false}
>
<div>
<EditorEnvelope
identifier={propertyName}
label={
$get("label", editorOptions) ||
$get(["properties", propertyName, "ui", "label"], nodeType) ||
""
}
editor={$get("editor", editorOptions)}
value={value && value.toJS ? value.toJS() : value}
hooks={null}
options={editorOptions}
commit={(value) => {
persistChange({
type: "Neos.Neos.Ui:Property",
subject: contextPath,
payload: {
propertyName,
value,
nodeDomAddress: {
contextPath,
fusionPath,
},
},
});
}}
renderSecondaryInspector={renderSecondaryInspector}
/>
</div>
</DropDown.Contents>
</DropDown.Stateless>
</div>
);
}
}
const findParentFusionPath = (node, contextPath) => {
if (node) {
const fusionPath = node.getAttribute("data-__neos-fusion-path");
if (
fusionPath &&
node.getAttribute("data-__neos-node-contextpath") === contextPath
) {
return fusionPath;
}
return findParentFusionPath(node.parentNode, contextPath);
}
return null;
};
manifest(
"Flowpack.StructuredEditing:EditorEnvelope",
{},
(globalRegistry, { routes, configuration, store }) => {
const containerRegistry = globalRegistry.get("containers");
containerRegistry.set(
"Modals/InlineSecondaryInspector",
InlineSecondaryInspector
);
const inlineEditorRegistry = globalRegistry.get("inlineEditors");
const nodeTypesRegistry = globalRegistry.get(
"@neos-project/neos-ui-contentrepository"
);
inlineEditorRegistry.set("Flowpack.StructuredEditing/EditorEnvelope", {
bootstrap: () => null,
createInlineEditor: (config) => {
const domNode = config.propertyDomNode;
const guestWindow = domNode.ownerDocument.defaultView;
const fusionPath = findParentFusionPath(domNode, config.contextPath);
ReactDOM.render(
<Provider store={store}>
<NeosContext.Provider
value={{ configuration, globalRegistry, routes }}
>
<DndProvider backend={HTML5Backend} context={guestWindow}>
<InlineEditorEnvelope
globalRegistry={globalRegistry}
routes={routes}
configuration={configuration}
store={store}
fusionPath={fusionPath}
nodeTypesRegistry={nodeTypesRegistry}
{...config}
/>
</DndProvider>
</NeosContext.Provider>
</Provider>,
domNode
);
},
ToolbarComponent: () => null,
});
}
);