@haklex/rich-static-renderer 0.0.42 → 0.0.44

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"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderBuiltinNode.d.ts","sourceRoot":"","sources":["../../src/engine/renderBuiltinNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAmBtC,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,GAAG,EACT,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAC5B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,SAAS,CAwLX"}
1
+ {"version":3,"file":"renderBuiltinNode.d.ts","sourceRoot":"","sources":["../../src/engine/renderBuiltinNode.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAmBrD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,GAAG,EACT,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAC5B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,SAAS,CAkMX"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { getVariantClass, allNodes, ColorSchemeProvider, RendererConfigProvider, FootnoteDefinitionsProvider, NestedContentRendererProvider, editorTheme } from "@haklex/rich-editor/static";
2
+ import { RendererWrapper, RubyRenderer, getVariantClass, allNodes, ColorSchemeProvider, RendererConfigProvider, FootnoteDefinitionsProvider, NestedContentRendererProvider, editorTheme } from "@haklex/rich-editor/static";
3
3
  import { PortalThemeProvider } from "@haklex/rich-style-token";
4
4
  import { createHeadlessEditor } from "@lexical/headless";
5
5
  import { $getRoot } from "lexical";
6
- import { isValidElement, cloneElement, createElement } from "react";
6
+ import { createElement, isValidElement, cloneElement } from "react";
7
7
  var tableWrapper = "_1v9yxw30";
8
8
  var table = "_1v9yxw31";
9
9
  var tableHead = "_1v9yxw32";
@@ -155,6 +155,16 @@ function renderBuiltinNode(node, key, children, headingSlugs) {
155
155
  }
156
156
  case "spoiler":
157
157
  return /* @__PURE__ */ jsx("span", { className: "rich-spoiler", role: "button", tabIndex: 0, children }, key);
158
+ case "ruby":
159
+ return createElement(RendererWrapper, {
160
+ key,
161
+ rendererKey: "Ruby",
162
+ defaultRenderer: RubyRenderer,
163
+ props: {
164
+ reading: node.reading ?? "",
165
+ children
166
+ }
167
+ });
158
168
  case "code":
159
169
  return /* @__PURE__ */ jsx("pre", { className: "rich-code-block", children: /* @__PURE__ */ jsx("code", { children }) }, key);
160
170
  case "code-highlight":
@@ -270,14 +280,33 @@ function wrapDecoration(serialized, key, decoration) {
270
280
  return decoration;
271
281
  }
272
282
  }
273
- function renderTree(node, editor, editorConfig, headingSlugs, key) {
283
+ function applyBlockId(element, blockId, nodeKey) {
284
+ if (!blockId) return element;
285
+ if (isValidElement(element) && typeof element.type === "string") {
286
+ return cloneElement(element, { "data-block-id": blockId });
287
+ }
288
+ return /* @__PURE__ */ jsx(
289
+ "div",
290
+ {
291
+ className: "rich-block-anchor",
292
+ "data-block-id": blockId,
293
+ children: element
294
+ },
295
+ `${nodeKey}-block-anchor`
296
+ );
297
+ }
298
+ function renderTree(node, editor, editorConfig, headingSlugs, key, blockId) {
274
299
  const nodeKey = node.getKey ? node.getKey() : key;
275
300
  if (typeof node.decorate === "function") {
276
301
  try {
277
302
  const decoration = node.decorate(editor, editorConfig);
278
303
  if (decoration != null) {
279
304
  const serialized2 = node.exportJSON ? node.exportJSON() : {};
280
- return wrapDecoration(serialized2, nodeKey, decoration);
305
+ return applyBlockId(
306
+ wrapDecoration(serialized2, nodeKey, decoration),
307
+ blockId,
308
+ nodeKey
309
+ );
281
310
  }
282
311
  } catch {
283
312
  }
@@ -301,7 +330,11 @@ function renderTree(node, editor, editorConfig, headingSlugs, key) {
301
330
  );
302
331
  }
303
332
  }
304
- return renderBuiltinNode(serialized, nodeKey, children, headingSlugs);
333
+ return applyBlockId(
334
+ renderBuiltinNode(serialized, nodeKey, children, headingSlugs),
335
+ blockId,
336
+ nodeKey
337
+ );
305
338
  }
306
339
  function renderEditorToReact(value, nodes) {
307
340
  const editor = createHeadlessEditor({
@@ -316,12 +349,20 @@ function renderEditorToReact(value, nodes) {
316
349
  const editorState = editor.parseEditorState(value);
317
350
  editor.setEditorState(editorState);
318
351
  const footnoteData = preprocessFootnotes(value);
352
+ const rawRootChildren = value.root?.children;
319
353
  let content = null;
320
354
  editorState.read(() => {
321
355
  const root = $getRoot();
322
356
  const headingSlugs = /* @__PURE__ */ new Map();
323
357
  const children = root.getChildren().map(
324
- (child, i) => renderTree(child, editor, editorConfig, headingSlugs, `ssr-${i}`)
358
+ (child, i) => renderTree(
359
+ child,
360
+ editor,
361
+ editorConfig,
362
+ headingSlugs,
363
+ `ssr-${i}`,
364
+ rawRootChildren?.[i]?.$?.blockId
365
+ )
325
366
  );
326
367
  content = /* @__PURE__ */ jsx(Fragment, { children });
327
368
  });
@@ -341,6 +382,7 @@ function renderEditorToReact(value, nodes) {
341
382
  const nestedState = nestedEditor.parseEditorState(state);
342
383
  nestedEditor.setEditorState(nestedState);
343
384
  let nested = null;
385
+ const nestedRawChildren = state.root?.children;
344
386
  nestedState.read(() => {
345
387
  const root = $getRoot();
346
388
  const headingSlugs = /* @__PURE__ */ new Map();
@@ -350,7 +392,8 @@ function renderEditorToReact(value, nodes) {
350
392
  nestedEditor,
351
393
  nestedEditorConfig,
352
394
  headingSlugs,
353
- `nested-${i}`
395
+ `nested-${i}`,
396
+ nestedRawChildren?.[i]?.$?.blockId
354
397
  )
355
398
  );
356
399
  nested = /* @__PURE__ */ jsx(Fragment, { children: ch });
@@ -387,7 +430,16 @@ function RichRenderer({
387
430
  {
388
431
  definitions: footnoteData.definitions,
389
432
  displayNumberMap: footnoteData.displayNumberMap,
390
- children: /* @__PURE__ */ jsx(NestedContentRendererProvider, { value: renderNestedContent, children: /* @__PURE__ */ jsx(Component, { className: classes, style, "data-theme": theme, children: content }) })
433
+ children: /* @__PURE__ */ jsx(NestedContentRendererProvider, { value: renderNestedContent, children: /* @__PURE__ */ jsx(
434
+ Component,
435
+ {
436
+ className: classes,
437
+ style,
438
+ "data-theme": theme,
439
+ suppressHydrationWarning: true,
440
+ children: content
441
+ }
442
+ ) })
391
443
  }
392
444
  )
393
445
  }
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.44",
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.44",
20
+ "@haklex/rich-style-token": "0.0.44"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@lexical/code": "^0.41.0",