@vonaffenfels/slate-editor 1.0.59 → 1.0.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonaffenfels/slate-editor",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -71,7 +71,7 @@
71
71
  "cssnano": "^5.0.1",
72
72
  "escape-html": "^1.0.3"
73
73
  },
74
- "gitHead": "45e9d0390c7c19fbfa54c8bf9c3cef5a076e4198",
74
+ "gitHead": "82ea53774b0e6a0f904cfaaca038bf0eda00af8e",
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  }
package/scss/editor.scss CHANGED
@@ -259,8 +259,8 @@
259
259
 
260
260
  .layout-slot-option-padding {
261
261
  position: relative;
262
- width: 1.5em;
263
- height: 1.5em;
262
+ width: 26px;
263
+ height: 26px;
264
264
  display: inline-block;
265
265
 
266
266
  .layout-slot-option-padding-item {
@@ -77,6 +77,7 @@ export default function BlockEditor({
77
77
 
78
78
  const [loadedStorybookStories, setLoadedStorybookStories] = useState([]);
79
79
  const [isLoadingStories, setIsLoadingStories] = useState(false);
80
+ const [lastSelection, setLastSelection] = useState(null);
80
81
 
81
82
  const loadStories = async () => {
82
83
  setIsLoadingStories(true);
@@ -99,6 +100,10 @@ export default function BlockEditor({
99
100
  };
100
101
 
101
102
  const onSlateChange = (newValue) => {
103
+ if (editor.selection) {
104
+ setLastSelection(editor.selection);
105
+ }
106
+
102
107
  if (newValue.length > 0) {
103
108
  onChange(newValue);
104
109
  } else {
@@ -286,7 +291,8 @@ export default function BlockEditor({
286
291
  storybookStories={loadedStorybookStories}
287
292
  isLoadingStories={isLoadingStories}
288
293
  editor={editor}
289
- sdk={contentfulSdk}/>
294
+ sdk={contentfulSdk}
295
+ lastSelection={lastSelection}/>
290
296
  </div>
291
297
  <div className="relative h-full max-h-full overflow-scroll px-8 py-4" ref={scrollContainer}>
292
298
  {isLoading && (
@@ -55,7 +55,7 @@ export const SidebarEditorField = ({
55
55
  ));
56
56
  } else {
57
57
  return Object.keys(field.control.options).map(key => (
58
- <option key={`select-option-${key}`} value={field.control.options[key]}>{field.control.options[key]}</option>
58
+ <option key={`select-option-${key}`} value={field.control.options[key]}>{key}</option>
59
59
  ));
60
60
  }
61
61
  };
@@ -181,6 +181,11 @@ const SidebarEditor = ({
181
181
  <div className="grow">
182
182
  {storybookElement?.block && (
183
183
  <div className="flex items-center">
184
+ <div className="mr-1 flex items-center">
185
+ <ToolMargin
186
+ margin={storybookElement.attributes.margin}
187
+ onChange={value => handleFieldValueChange("margin", value)} />
188
+ </div>
184
189
  <div className="icon-button-group mr-1">
185
190
  <IconButton title="Rückgängig" onClick={undo} disabled={currentVersion <= 1}>↺</IconButton>
186
191
  <IconButton title="Wiederherstellen" onClick={redo} disabled={currentVersion >= versionCount || versionCount === 0}>↻</IconButton>
@@ -196,15 +201,10 @@ const SidebarEditor = ({
196
201
  <IconButton title="Löschen" onClick={() => onDelete && onDelete(storybookElement)}>
197
202
  🗑
198
203
  </IconButton>
199
- <div className="ml-1 flex items-center">
200
- <ToolMargin
201
- margin={storybookElement.attributes.margin}
202
- onChange={value => handleFieldValueChange("margin", value)} />
203
- </div>
204
204
  </div>
205
205
  )}
206
206
  </div>
207
- {!!onClose && <IconButton onClick={onClose} title="Schließen">⨯</IconButton>}
207
+ {!!onClose && <IconButton size="big" onClick={onClose} title="Schließen">⨯</IconButton>}
208
208
  </div>
209
209
  <hr className="mt-2" style={{borderColor: "#cfd9e0"}}/>
210
210
  </div>
@@ -299,11 +299,14 @@ export const IconButton = ({
299
299
 
300
300
  switch (size) {
301
301
  case "small":
302
- classNames += " !text-xs min-w-[28px]";
302
+ classNames += " !text-xs min-w-[28px] max-h-[28px]";
303
+ break;
304
+ case "big":
305
+ classNames += " !text-xl min-w-[32px] max-h-[28px] !leading-[18px]";
303
306
  break;
304
307
  case "medium":
305
308
  default:
306
- classNames += " !text-sm min-w-[32px]";
309
+ classNames += " !text-sm min-w-[32px] max-h-[28px]";
307
310
  }
308
311
 
309
312
  return (
@@ -39,9 +39,12 @@ export const Toolbar = ({
39
39
  isLoadingStories,
40
40
  editor,
41
41
  sdk,
42
+ lastSelection,
42
43
  }) => {
43
44
  const ref = useRef();
44
45
 
46
+ const portal = sdk?.entry?.fields?.portal.getValue();
47
+
45
48
  useEffect(() => {
46
49
  if (!hover) {
47
50
  return;
@@ -144,6 +147,8 @@ export const Toolbar = ({
144
147
  storybookStories={storybookStories}
145
148
  editor={editor}
146
149
  storyContext={sdk.parameters.instance.storyContext}
150
+ portal={portal}
151
+ lastSelection={lastSelection}
147
152
  />
148
153
  </div>
149
154
  </div>
@@ -170,6 +175,8 @@ const ElementAutocomplete = ({
170
175
  isLoading,
171
176
  editor,
172
177
  storyContext = "",
178
+ portal,
179
+ lastSelection,
173
180
  }) => {
174
181
  const items = (storybookStories || []).map(story => {
175
182
  let storyTitleSplit = String(story.title || "").split("/");
@@ -179,11 +186,12 @@ const ElementAutocomplete = ({
179
186
  }
180
187
 
181
188
  let splitStoryContext = String(storyContext || "").split(",");
182
- let isItemInContext = splitStoryContext.find(context => {
189
+ let isItemInStoryContext = splitStoryContext.find(context => {
183
190
  return Array.isArray(story.storyContext) ? story.storyContext.includes(context) : context === story.storyContext;
184
191
  });
192
+ let isItemInPortalContext = !story.portalContext || story.portalContext.includes(portal);
185
193
 
186
- if (!devMode && !isItemInContext) {
194
+ if (!devMode && (!isItemInStoryContext || !isItemInPortalContext)) {
187
195
  return;
188
196
  }
189
197
 
@@ -212,7 +220,7 @@ const ElementAutocomplete = ({
212
220
  attributes: {...(item?.stories?.[0]?.args || item?.stories?.[1]?.args || {})},
213
221
  };
214
222
 
215
- Transforms.insertNodes(editor, [element]);
223
+ Transforms.insertNodes(editor, [element], {at: [lastSelection?.anchor?.path?.[0]]});
216
224
  };
217
225
 
218
226
  useEffect(() => {
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
  {