@haklex/rich-static-renderer 0.0.42 → 0.0.43

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RichRenderer.d.ts","sourceRoot":"","sources":["../src/RichRenderer.tsx"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AA+JhD,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,OAAmB,EACnB,KAAe,EACf,SAAS,EACT,KAAK,EACL,EAAE,EAAE,SAAiB,EACrB,cAAc,EACd,UAAU,GACX,EAAE,iBAAiB,2CAmCnB"}
1
+ {"version":3,"file":"RichRenderer.d.ts","sourceRoot":"","sources":["../src/RichRenderer.tsx"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAyMhD,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,OAAmB,EACnB,KAAe,EACf,SAAS,EACT,KAAK,EACL,EAAE,EAAE,SAAiB,EACrB,cAAc,EACd,UAAU,GACX,EAAE,iBAAiB,2CAwCnB"}
package/dist/index.mjs CHANGED
@@ -270,14 +270,33 @@ function wrapDecoration(serialized, key, decoration) {
270
270
  return decoration;
271
271
  }
272
272
  }
273
- function renderTree(node, editor, editorConfig, headingSlugs, key) {
273
+ function applyBlockId(element, blockId, nodeKey) {
274
+ if (!blockId) return element;
275
+ if (isValidElement(element) && typeof element.type === "string") {
276
+ return cloneElement(element, { "data-block-id": blockId });
277
+ }
278
+ return /* @__PURE__ */ jsx(
279
+ "div",
280
+ {
281
+ className: "rich-block-anchor",
282
+ "data-block-id": blockId,
283
+ children: element
284
+ },
285
+ `${nodeKey}-block-anchor`
286
+ );
287
+ }
288
+ function renderTree(node, editor, editorConfig, headingSlugs, key, blockId) {
274
289
  const nodeKey = node.getKey ? node.getKey() : key;
275
290
  if (typeof node.decorate === "function") {
276
291
  try {
277
292
  const decoration = node.decorate(editor, editorConfig);
278
293
  if (decoration != null) {
279
294
  const serialized2 = node.exportJSON ? node.exportJSON() : {};
280
- return wrapDecoration(serialized2, nodeKey, decoration);
295
+ return applyBlockId(
296
+ wrapDecoration(serialized2, nodeKey, decoration),
297
+ blockId,
298
+ nodeKey
299
+ );
281
300
  }
282
301
  } catch {
283
302
  }
@@ -301,7 +320,11 @@ function renderTree(node, editor, editorConfig, headingSlugs, key) {
301
320
  );
302
321
  }
303
322
  }
304
- return renderBuiltinNode(serialized, nodeKey, children, headingSlugs);
323
+ return applyBlockId(
324
+ renderBuiltinNode(serialized, nodeKey, children, headingSlugs),
325
+ blockId,
326
+ nodeKey
327
+ );
305
328
  }
306
329
  function renderEditorToReact(value, nodes) {
307
330
  const editor = createHeadlessEditor({
@@ -316,12 +339,20 @@ function renderEditorToReact(value, nodes) {
316
339
  const editorState = editor.parseEditorState(value);
317
340
  editor.setEditorState(editorState);
318
341
  const footnoteData = preprocessFootnotes(value);
342
+ const rawRootChildren = value.root?.children;
319
343
  let content = null;
320
344
  editorState.read(() => {
321
345
  const root = $getRoot();
322
346
  const headingSlugs = /* @__PURE__ */ new Map();
323
347
  const children = root.getChildren().map(
324
- (child, i) => renderTree(child, editor, editorConfig, headingSlugs, `ssr-${i}`)
348
+ (child, i) => renderTree(
349
+ child,
350
+ editor,
351
+ editorConfig,
352
+ headingSlugs,
353
+ `ssr-${i}`,
354
+ rawRootChildren?.[i]?.$?.blockId
355
+ )
325
356
  );
326
357
  content = /* @__PURE__ */ jsx(Fragment, { children });
327
358
  });
@@ -341,6 +372,7 @@ function renderEditorToReact(value, nodes) {
341
372
  const nestedState = nestedEditor.parseEditorState(state);
342
373
  nestedEditor.setEditorState(nestedState);
343
374
  let nested = null;
375
+ const nestedRawChildren = state.root?.children;
344
376
  nestedState.read(() => {
345
377
  const root = $getRoot();
346
378
  const headingSlugs = /* @__PURE__ */ new Map();
@@ -350,7 +382,8 @@ function renderEditorToReact(value, nodes) {
350
382
  nestedEditor,
351
383
  nestedEditorConfig,
352
384
  headingSlugs,
353
- `nested-${i}`
385
+ `nested-${i}`,
386
+ nestedRawChildren?.[i]?.$?.blockId
354
387
  )
355
388
  );
356
389
  nested = /* @__PURE__ */ jsx(Fragment, { children: ch });
@@ -387,7 +420,16 @@ function RichRenderer({
387
420
  {
388
421
  definitions: footnoteData.definitions,
389
422
  displayNumberMap: footnoteData.displayNumberMap,
390
- children: /* @__PURE__ */ jsx(NestedContentRendererProvider, { value: renderNestedContent, children: /* @__PURE__ */ jsx(Component, { className: classes, style, "data-theme": theme, children: content }) })
423
+ children: /* @__PURE__ */ jsx(NestedContentRendererProvider, { value: renderNestedContent, children: /* @__PURE__ */ jsx(
424
+ Component,
425
+ {
426
+ className: classes,
427
+ style,
428
+ "data-theme": theme,
429
+ suppressHydrationWarning: true,
430
+ children: content
431
+ }
432
+ ) })
391
433
  }
392
434
  )
393
435
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-static-renderer",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "description": "Headless SSR engine for Lexical rich content",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@lexical/headless": "^0.41.0",
19
- "@haklex/rich-editor": "0.0.42",
20
- "@haklex/rich-style-token": "0.0.42"
19
+ "@haklex/rich-editor": "0.0.43",
20
+ "@haklex/rich-style-token": "0.0.43"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@lexical/code": "^0.41.0",