@vonaffenfels/slate-editor 1.0.60 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockEditor.css +2 -2
- package/dist/BlockEditor.js +1 -1
- package/dist/index.css +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/scss/editor.scss +14 -6
- package/scss/sidebarEditor.scss +20 -0
- package/src/BlockEditor.js +49 -2
- package/src/CollapsableMenu/CollapsableMenu.js +46 -0
- package/src/ElementAutocomplete.js +84 -0
- package/src/SidebarEditor/Resizable.js +18 -13
- package/src/SidebarEditor.js +58 -115
- package/src/Toolbar/Toolbar.js +13 -83
package/src/Toolbar/Toolbar.js
CHANGED
|
@@ -25,8 +25,7 @@ import {
|
|
|
25
25
|
Autocomplete, Spinner,
|
|
26
26
|
} from "@contentful/forma-36-react-components";
|
|
27
27
|
import {Transforms} from "slate";
|
|
28
|
-
|
|
29
|
-
const devMode = localStorage.getItem("dev-mode") === "true";
|
|
28
|
+
import {ElementAutocomplete} from "../ElementAutocomplete";
|
|
30
29
|
|
|
31
30
|
export const Portal = ({children}) => {
|
|
32
31
|
return ReactDOM.createPortal(children, window.document.body);
|
|
@@ -95,6 +94,17 @@ export const Toolbar = ({
|
|
|
95
94
|
}
|
|
96
95
|
}, [hover, ref, editor]);
|
|
97
96
|
|
|
97
|
+
const handleAutocompleteChange = item => {
|
|
98
|
+
let element = {
|
|
99
|
+
children: [{text: ''}],
|
|
100
|
+
type: "storybook",
|
|
101
|
+
block: item.value,
|
|
102
|
+
attributes: {...(item?.stories?.[0]?.args || item?.stories?.[1]?.args || {})},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
Transforms.insertNodes(editor, [element], {at: [lastSelection?.anchor?.path?.[0]]});
|
|
106
|
+
};
|
|
107
|
+
|
|
98
108
|
function renderMenu() {
|
|
99
109
|
return <Menu
|
|
100
110
|
ref={ref}
|
|
@@ -149,6 +159,7 @@ export const Toolbar = ({
|
|
|
149
159
|
storyContext={sdk.parameters.instance.storyContext}
|
|
150
160
|
portal={portal}
|
|
151
161
|
lastSelection={lastSelection}
|
|
162
|
+
onChange={handleAutocompleteChange}
|
|
152
163
|
/>
|
|
153
164
|
</div>
|
|
154
165
|
</div>
|
|
@@ -170,87 +181,6 @@ export const Toolbar = ({
|
|
|
170
181
|
}
|
|
171
182
|
};
|
|
172
183
|
|
|
173
|
-
const ElementAutocomplete = ({
|
|
174
|
-
storybookStories,
|
|
175
|
-
isLoading,
|
|
176
|
-
editor,
|
|
177
|
-
storyContext = "",
|
|
178
|
-
portal,
|
|
179
|
-
lastSelection,
|
|
180
|
-
}) => {
|
|
181
|
-
const items = (storybookStories || []).map(story => {
|
|
182
|
-
let storyTitleSplit = String(story.title || "").split("/");
|
|
183
|
-
|
|
184
|
-
if (!story.id) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let splitStoryContext = String(storyContext || "").split(",");
|
|
189
|
-
let isItemInStoryContext = splitStoryContext.find(context => {
|
|
190
|
-
return Array.isArray(story.storyContext) ? story.storyContext.includes(context) : context === story.storyContext;
|
|
191
|
-
});
|
|
192
|
-
let isItemInPortalContext = !story.portalContext || story.portalContext.includes(portal);
|
|
193
|
-
|
|
194
|
-
if (!devMode && (!isItemInStoryContext || !isItemInPortalContext)) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return {
|
|
199
|
-
value: story.id.toLowerCase(),
|
|
200
|
-
label: storyTitleSplit[storyTitleSplit.length - 1],
|
|
201
|
-
stories: story.stories,
|
|
202
|
-
};
|
|
203
|
-
}).filter(Boolean);
|
|
204
|
-
|
|
205
|
-
const [filteredItems, setFilteredItems] = useState(items);
|
|
206
|
-
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
setFilteredItems(items);
|
|
209
|
-
}, [storybookStories]);
|
|
210
|
-
|
|
211
|
-
const handleQueryChange = (query) => {
|
|
212
|
-
setFilteredItems(query ? items.filter((item) => item.label.toLowerCase().includes(query.toLowerCase())) : items);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const handleOnChange = (item) => {
|
|
216
|
-
let element = {
|
|
217
|
-
children: [{text: ''}],
|
|
218
|
-
type: "storybook",
|
|
219
|
-
block: item.value,
|
|
220
|
-
attributes: {...(item?.stories?.[0]?.args || item?.stories?.[1]?.args || {})},
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
Transforms.insertNodes(editor, [element], {at: [lastSelection?.anchor?.path?.[0]]});
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
useEffect(() => {
|
|
227
|
-
let autoCompleteElement = document.getElementsByClassName("element-autocomplete")[0];
|
|
228
|
-
|
|
229
|
-
if (autoCompleteElement) {
|
|
230
|
-
autoCompleteElement.value = "";
|
|
231
|
-
}
|
|
232
|
-
}, []);
|
|
233
|
-
|
|
234
|
-
return (
|
|
235
|
-
<Autocomplete
|
|
236
|
-
items={filteredItems}
|
|
237
|
-
onQueryChange={handleQueryChange}
|
|
238
|
-
isLoading={isLoading}
|
|
239
|
-
placeholder={'Element hinzufügen'}
|
|
240
|
-
emptyListMessage={'Keine Komponenten gefunden'}
|
|
241
|
-
noMatchesMessage={'Keine Ergebnisse gefunden'}
|
|
242
|
-
dropdownProps={{isFullWidth: true}}
|
|
243
|
-
maxHeight={300}
|
|
244
|
-
onChange={handleOnChange}
|
|
245
|
-
width="medium"
|
|
246
|
-
>
|
|
247
|
-
{(options) =>
|
|
248
|
-
options.map((option) => <span key={option.value}>{option.label}</span>)
|
|
249
|
-
}
|
|
250
|
-
</Autocomplete>
|
|
251
|
-
);
|
|
252
|
-
};
|
|
253
|
-
|
|
254
184
|
export const ToobarHoverExpandButton = ({children}) => {
|
|
255
185
|
return <span
|
|
256
186
|
className={
|