@vonaffenfels/slate-editor 1.0.78 → 1.0.81

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.78",
3
+ "version": "1.0.81",
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": "d9a15e949b3c97d57e927366ab4063e3f83618ef",
74
+ "gitHead": "a8759bb4528cbe15162eea2db425d570110eaaf7",
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  }
@@ -31,6 +31,7 @@ export default function BlockEditor({
31
31
  storybookStories,
32
32
  onSaveClick,
33
33
  isLoading,
34
+ activeConfig,
34
35
  }) {
35
36
  const scrollContainer = useRef(null);
36
37
  const [selectedStorybookElement, setSelectedStorybookElement] = useState(null);
@@ -319,6 +320,8 @@ export default function BlockEditor({
319
320
  setSelectedStorybookElement(null);
320
321
  };
321
322
 
323
+ const slug = contentfulSdk?.entry?.fields?.slug?.getValue();
324
+
322
325
  return (
323
326
  <div className={classNames({"block-editor-wrapper h-full": true})}>
324
327
  <Resizable
@@ -336,7 +339,12 @@ export default function BlockEditor({
336
339
  isLoadingStories={isLoadingStories}
337
340
  editor={editor}
338
341
  sdk={contentfulSdk}
339
- lastSelection={lastSelection}/>
342
+ lastSelection={lastSelection}
343
+ buttons={activeConfig?.domain && slug && (
344
+ <a href={`${activeConfig.domain}/${slug}`} target="_blank" rel="noreferrer">
345
+ <button className='button button--secondary'>Live-Seite öffnen</button>
346
+ </a>
347
+ )}/>
340
348
  </div>
341
349
  <div className="relative h-full max-h-full overflow-scroll px-8 py-4" ref={scrollContainer}>
342
350
  {isLoading && (
@@ -161,7 +161,8 @@ export function Serializer({
161
161
  [typeProps.classNameArticle + " article-width"]: !isInSlot && (props.attributes?.width === "article" || !props.attributes?.width),
162
162
  })}
163
163
  >
164
- {props.children.map((v, i) => <Fragment key={"layout-pos-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>)}
164
+ {props.children.map((v, i) => <Fragment
165
+ key={"layout-pos-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>)}
165
166
  </div>
166
167
  </Wrapper>;
167
168
  }
@@ -176,7 +177,8 @@ export function Serializer({
176
177
  "md:ml-4": props.attributes?.margin?.left,
177
178
  })}
178
179
  >
179
- {props.children.map((v, i) => <Fragment key={"layout-slot-" + i}>{serializeNode(v, i, props.attributes.name)}</Fragment>)}
180
+ {props.children.map((v, i) => <Fragment
181
+ key={"layout-slot-" + i}>{serializeNode(v, i, props.attributes.name)}</Fragment>)}
180
182
  </div>
181
183
  </Wrapper>;
182
184
  default: {
@@ -189,7 +191,8 @@ export function Serializer({
189
191
  type: props.type,
190
192
  },
191
193
  attributes: props.htmlAttributes || {},
192
- children: props.children.map((v, i) => <Fragment key={props.type + "-pos-item-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>),
194
+ children: props.children.map((v, i) => <Fragment
195
+ key={props.type + "-pos-item-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>),
193
196
  };
194
197
 
195
198
  return <Default
@@ -217,6 +220,19 @@ export function Serializer({
217
220
  return serializeLeaf(node);
218
221
  }
219
222
 
223
+ // unwrap elements that are inside of a paragraph (that has no text content) so they have been inserted "inline" by mistake
224
+ // this helps preventing a lot of hydration errors!
225
+ if (node?.type === "paragraph") {
226
+ const textContent = node.children.find(v => !v?.type && v?.text);
227
+ if (!textContent) {
228
+ const storybookNodes = node.children.filter(v => v?.type === "storybook");
229
+ if (storybookNodes.length === 1) {
230
+ // only unwrap if we only have exactly 1 node
231
+ return renderElement(storybookNodes.at(0), isInSlot);
232
+ }
233
+ }
234
+ }
235
+
220
236
  return renderElement(node, isInSlot);
221
237
  }
222
238
 
@@ -39,6 +39,7 @@ export const Toolbar = ({
39
39
  editor,
40
40
  sdk,
41
41
  lastSelection,
42
+ buttons,
42
43
  }) => {
43
44
  const ref = useRef();
44
45
 
@@ -166,6 +167,9 @@ export const Toolbar = ({
166
167
  {!!onSaveClick && <button
167
168
  className="!w-auto !border-0 !bg-green-600 !text-xs font-bold text-white hover:!bg-green-700"
168
169
  onClick={onSaveClick}>Änderungen speichern</button>}
170
+ {buttons && (
171
+ <div>{buttons}</div>
172
+ )}
169
173
  </div>
170
174
  </Menu>;
171
175
  }