@vonaffenfels/slate-editor 1.0.59 → 1.0.62
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 +1 -1
- package/dist/BlockEditor.js +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/scss/editor.scss +16 -8
- package/src/BlockEditor.js +82 -3
- package/src/ElementAutocomplete.js +84 -0
- package/src/SidebarEditor/Resizable.js +18 -13
- package/src/SidebarEditor/SidebarEditorField.js +1 -1
- package/src/SidebarEditor.js +63 -117
- package/src/Toolbar/Toolbar.js +18 -80
- package/storyLoader.js +1 -0
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);
|
|
@@ -39,9 +38,12 @@ export const Toolbar = ({
|
|
|
39
38
|
isLoadingStories,
|
|
40
39
|
editor,
|
|
41
40
|
sdk,
|
|
41
|
+
lastSelection,
|
|
42
42
|
}) => {
|
|
43
43
|
const ref = useRef();
|
|
44
44
|
|
|
45
|
+
const portal = sdk?.entry?.fields?.portal.getValue();
|
|
46
|
+
|
|
45
47
|
useEffect(() => {
|
|
46
48
|
if (!hover) {
|
|
47
49
|
return;
|
|
@@ -92,6 +94,17 @@ export const Toolbar = ({
|
|
|
92
94
|
}
|
|
93
95
|
}, [hover, ref, editor]);
|
|
94
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
|
+
|
|
95
108
|
function renderMenu() {
|
|
96
109
|
return <Menu
|
|
97
110
|
ref={ref}
|
|
@@ -144,6 +157,9 @@ export const Toolbar = ({
|
|
|
144
157
|
storybookStories={storybookStories}
|
|
145
158
|
editor={editor}
|
|
146
159
|
storyContext={sdk.parameters.instance.storyContext}
|
|
160
|
+
portal={portal}
|
|
161
|
+
lastSelection={lastSelection}
|
|
162
|
+
onChange={handleAutocompleteChange}
|
|
147
163
|
/>
|
|
148
164
|
</div>
|
|
149
165
|
</div>
|
|
@@ -165,84 +181,6 @@ export const Toolbar = ({
|
|
|
165
181
|
}
|
|
166
182
|
};
|
|
167
183
|
|
|
168
|
-
const ElementAutocomplete = ({
|
|
169
|
-
storybookStories,
|
|
170
|
-
isLoading,
|
|
171
|
-
editor,
|
|
172
|
-
storyContext = "",
|
|
173
|
-
}) => {
|
|
174
|
-
const items = (storybookStories || []).map(story => {
|
|
175
|
-
let storyTitleSplit = String(story.title || "").split("/");
|
|
176
|
-
|
|
177
|
-
if (!story.id) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
let splitStoryContext = String(storyContext || "").split(",");
|
|
182
|
-
let isItemInContext = splitStoryContext.find(context => {
|
|
183
|
-
return Array.isArray(story.storyContext) ? story.storyContext.includes(context) : context === story.storyContext;
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
if (!devMode && !isItemInContext) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
value: story.id.toLowerCase(),
|
|
192
|
-
label: storyTitleSplit[storyTitleSplit.length - 1],
|
|
193
|
-
stories: story.stories,
|
|
194
|
-
};
|
|
195
|
-
}).filter(Boolean);
|
|
196
|
-
|
|
197
|
-
const [filteredItems, setFilteredItems] = useState(items);
|
|
198
|
-
|
|
199
|
-
useEffect(() => {
|
|
200
|
-
setFilteredItems(items);
|
|
201
|
-
}, [storybookStories]);
|
|
202
|
-
|
|
203
|
-
const handleQueryChange = (query) => {
|
|
204
|
-
setFilteredItems(query ? items.filter((item) => item.label.toLowerCase().includes(query.toLowerCase())) : items);
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const handleOnChange = (item) => {
|
|
208
|
-
let element = {
|
|
209
|
-
children: [{text: ''}],
|
|
210
|
-
type: "storybook",
|
|
211
|
-
block: item.value,
|
|
212
|
-
attributes: {...(item?.stories?.[0]?.args || item?.stories?.[1]?.args || {})},
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
Transforms.insertNodes(editor, [element]);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
let autoCompleteElement = document.getElementsByClassName("element-autocomplete")[0];
|
|
220
|
-
|
|
221
|
-
if (autoCompleteElement) {
|
|
222
|
-
autoCompleteElement.value = "";
|
|
223
|
-
}
|
|
224
|
-
}, []);
|
|
225
|
-
|
|
226
|
-
return (
|
|
227
|
-
<Autocomplete
|
|
228
|
-
items={filteredItems}
|
|
229
|
-
onQueryChange={handleQueryChange}
|
|
230
|
-
isLoading={isLoading}
|
|
231
|
-
placeholder={'Element hinzufügen'}
|
|
232
|
-
emptyListMessage={'Keine Komponenten gefunden'}
|
|
233
|
-
noMatchesMessage={'Keine Ergebnisse gefunden'}
|
|
234
|
-
dropdownProps={{isFullWidth: true}}
|
|
235
|
-
maxHeight={300}
|
|
236
|
-
onChange={handleOnChange}
|
|
237
|
-
width="medium"
|
|
238
|
-
>
|
|
239
|
-
{(options) =>
|
|
240
|
-
options.map((option) => <span key={option.value}>{option.label}</span>)
|
|
241
|
-
}
|
|
242
|
-
</Autocomplete>
|
|
243
|
-
);
|
|
244
|
-
};
|
|
245
|
-
|
|
246
184
|
export const ToobarHoverExpandButton = ({children}) => {
|
|
247
185
|
return <span
|
|
248
186
|
className={
|
package/storyLoader.js
CHANGED
|
@@ -19,6 +19,7 @@ module.exports = async function storiesLoader() {
|
|
|
19
19
|
story.id = baseStory.id;
|
|
20
20
|
story.argTypes = baseStory.argTypes;
|
|
21
21
|
story.storyContext = baseStory.storyContext;
|
|
22
|
+
story.portalContext = baseStory.portalContext;
|
|
22
23
|
story.title = baseStory.title;
|
|
23
24
|
story.stories = [
|
|
24
25
|
{
|