@qkix/better-blocks-react-renderer 0.18.0 → 0.18.2
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/README.md +51 -14
- package/dist/index.d.mts +39 -5
- package/dist/index.d.ts +39 -5
- package/dist/index.js +58 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -98,17 +98,17 @@ function CodeBlock({
|
|
|
98
98
|
}) {
|
|
99
99
|
const [html, setHtml] = useState(null);
|
|
100
100
|
useEffect(() => {
|
|
101
|
-
let
|
|
101
|
+
let canceled = false;
|
|
102
102
|
setHtml(null);
|
|
103
103
|
if (!plainText) return;
|
|
104
104
|
const lang = normalizeCodeLang(language);
|
|
105
105
|
loadHighlighter(theme, lang).then((highlighter) => highlighter.codeToHtml(plainText, { lang, theme })).then((highlighted) => {
|
|
106
|
-
if (!
|
|
106
|
+
if (!canceled) setHtml(highlighted);
|
|
107
107
|
}).catch(() => {
|
|
108
|
-
if (!
|
|
108
|
+
if (!canceled) setHtml(null);
|
|
109
109
|
});
|
|
110
110
|
return () => {
|
|
111
|
-
|
|
111
|
+
canceled = true;
|
|
112
112
|
};
|
|
113
113
|
}, [plainText, language, theme]);
|
|
114
114
|
return /* @__PURE__ */ jsxs("div", { className: "bb-code", children: [
|
|
@@ -135,16 +135,16 @@ var renderCount = 0;
|
|
|
135
135
|
function MermaidDiagram({ value }) {
|
|
136
136
|
const [svg, setSvg] = useState2(null);
|
|
137
137
|
useEffect2(() => {
|
|
138
|
-
let
|
|
138
|
+
let canceled = false;
|
|
139
139
|
setSvg(null);
|
|
140
140
|
if (!value) return;
|
|
141
141
|
loadMermaid().then((mermaid) => mermaid.render(`bb-mermaid-${renderCount++}`, value)).then(({ svg: svg2 }) => {
|
|
142
|
-
if (!
|
|
142
|
+
if (!canceled) setSvg(svg2);
|
|
143
143
|
}).catch(() => {
|
|
144
|
-
if (!
|
|
144
|
+
if (!canceled) setSvg(null);
|
|
145
145
|
});
|
|
146
146
|
return () => {
|
|
147
|
-
|
|
147
|
+
canceled = true;
|
|
148
148
|
};
|
|
149
149
|
}, [value]);
|
|
150
150
|
if (svg) {
|
|
@@ -326,14 +326,14 @@ function SocialEmbed({
|
|
|
326
326
|
});
|
|
327
327
|
const widget = WIDGET_SCRIPTS[platform];
|
|
328
328
|
if (!widget) return;
|
|
329
|
-
let
|
|
329
|
+
let canceled = false;
|
|
330
330
|
void loadWidgetScript(widget.src, platform).then(() => {
|
|
331
331
|
const container = containerRef.current;
|
|
332
|
-
if (
|
|
332
|
+
if (canceled || !container) return;
|
|
333
333
|
if (!widget.process(container)) reinjectWidgetScript(widget.src, platform);
|
|
334
334
|
});
|
|
335
335
|
return () => {
|
|
336
|
-
|
|
336
|
+
canceled = true;
|
|
337
337
|
};
|
|
338
338
|
}, [platform, html]);
|
|
339
339
|
const providerName = (_a = oembed == null ? void 0 : oembed.providerName) != null ? _a : PLATFORM_LABELS[platform];
|
|
@@ -397,12 +397,12 @@ function Video({
|
|
|
397
397
|
setMuxDefined(true);
|
|
398
398
|
return;
|
|
399
399
|
}
|
|
400
|
-
let
|
|
400
|
+
let canceled = false;
|
|
401
401
|
void window.customElements.whenDefined("mux-player").then(() => {
|
|
402
|
-
if (!
|
|
402
|
+
if (!canceled) setMuxDefined(true);
|
|
403
403
|
});
|
|
404
404
|
return () => {
|
|
405
|
-
|
|
405
|
+
canceled = true;
|
|
406
406
|
};
|
|
407
407
|
}, [wantsMux]);
|
|
408
408
|
const isHls = HLS_MANIFEST.test(url);
|
|
@@ -624,44 +624,63 @@ function renderTable(block, key, blocks, modifiers) {
|
|
|
624
624
|
function isHeaderRow(row) {
|
|
625
625
|
return !!row && row.children.length > 0 && row.children.every((c) => c.type === "table-header-cell");
|
|
626
626
|
}
|
|
627
|
+
function renderCustomBlock(plugin, block, key, blocks, modifiers, options) {
|
|
628
|
+
const { component: Component, content = "void" } = plugin;
|
|
629
|
+
const children = Array.isArray(block.children) ? block.children : [];
|
|
630
|
+
if (content === "blocks") {
|
|
631
|
+
return /* @__PURE__ */ jsx5(Component, { node: block, children: children.map(
|
|
632
|
+
(child, index) => renderBlock(child, index, blocks, modifiers, options)
|
|
633
|
+
) }, key);
|
|
634
|
+
}
|
|
635
|
+
if (content === "inline") {
|
|
636
|
+
return /* @__PURE__ */ jsx5(Component, { node: block, children: renderInlineContent(children, blocks, modifiers) }, key);
|
|
637
|
+
}
|
|
638
|
+
return /* @__PURE__ */ jsx5(Component, { node: block }, key);
|
|
639
|
+
}
|
|
627
640
|
function renderBlock(block, key, blocks, modifiers, options) {
|
|
628
|
-
|
|
641
|
+
var _a;
|
|
642
|
+
const plugin = (_a = options == null ? void 0 : options.plugins) == null ? void 0 : _a.get(block.type);
|
|
643
|
+
if (plugin) {
|
|
644
|
+
return renderCustomBlock(plugin, block, key, blocks, modifiers, options);
|
|
645
|
+
}
|
|
646
|
+
const builtIn = block;
|
|
647
|
+
switch (builtIn.type) {
|
|
629
648
|
case "paragraph":
|
|
630
|
-
return renderParagraph(
|
|
649
|
+
return renderParagraph(builtIn, key, blocks, modifiers);
|
|
631
650
|
case "heading":
|
|
632
|
-
return renderHeading(
|
|
651
|
+
return renderHeading(builtIn, key, blocks, modifiers);
|
|
633
652
|
case "list":
|
|
634
|
-
return renderList(
|
|
653
|
+
return renderList(builtIn, key, blocks, modifiers);
|
|
635
654
|
case "quote":
|
|
636
|
-
return renderQuote(
|
|
655
|
+
return renderQuote(builtIn, key, blocks, modifiers);
|
|
637
656
|
case "code":
|
|
638
|
-
return renderCode(
|
|
657
|
+
return renderCode(builtIn, key, blocks, options);
|
|
639
658
|
case "image":
|
|
640
|
-
return renderImage(
|
|
659
|
+
return renderImage(builtIn, key, blocks);
|
|
641
660
|
case "horizontal-line":
|
|
642
|
-
return renderHorizontalLine(
|
|
661
|
+
return renderHorizontalLine(builtIn, key, blocks);
|
|
643
662
|
case "table":
|
|
644
|
-
return renderTable(
|
|
663
|
+
return renderTable(builtIn, key, blocks, modifiers);
|
|
645
664
|
case "media-embed":
|
|
646
|
-
return renderMediaEmbed(
|
|
665
|
+
return renderMediaEmbed(builtIn, key, blocks);
|
|
647
666
|
case "embed":
|
|
648
|
-
return renderEmbed(
|
|
667
|
+
return renderEmbed(builtIn, key, blocks);
|
|
649
668
|
case "video":
|
|
650
|
-
return renderVideo(
|
|
669
|
+
return renderVideo(builtIn, key, blocks);
|
|
651
670
|
case "math":
|
|
652
|
-
return renderMath(
|
|
671
|
+
return renderMath(builtIn, key, blocks);
|
|
653
672
|
case "diagram":
|
|
654
|
-
return renderDiagram(
|
|
673
|
+
return renderDiagram(builtIn, key, blocks);
|
|
655
674
|
case "callout":
|
|
656
|
-
return renderCallout(
|
|
675
|
+
return renderCallout(builtIn, key, blocks, modifiers, options);
|
|
657
676
|
case "details":
|
|
658
|
-
return renderDetails(
|
|
677
|
+
return renderDetails(builtIn, key, blocks, modifiers, options);
|
|
659
678
|
case "button":
|
|
660
|
-
return renderButton(
|
|
679
|
+
return renderButton(builtIn, key, blocks);
|
|
661
680
|
case "social-embed":
|
|
662
|
-
return renderSocialEmbed(
|
|
681
|
+
return renderSocialEmbed(builtIn, key, blocks);
|
|
663
682
|
case "audio":
|
|
664
|
-
return renderAudio(
|
|
683
|
+
return renderAudio(builtIn, key, blocks);
|
|
665
684
|
default:
|
|
666
685
|
return null;
|
|
667
686
|
}
|
|
@@ -1242,6 +1261,7 @@ function BlocksRenderer({
|
|
|
1242
1261
|
content,
|
|
1243
1262
|
blocks,
|
|
1244
1263
|
modifiers,
|
|
1264
|
+
blockPlugins,
|
|
1245
1265
|
codeTheme = DEFAULT_CODE_THEME,
|
|
1246
1266
|
codeCopyButton = false
|
|
1247
1267
|
}) {
|
|
@@ -1253,7 +1273,11 @@ function BlocksRenderer({
|
|
|
1253
1273
|
const needsTableCss = !(blocks == null ? void 0 : blocks.table) && contentHasBlock(content, "table");
|
|
1254
1274
|
const needsQuoteCss = !(blocks == null ? void 0 : blocks.quote) && contentHasBlock(content, "quote");
|
|
1255
1275
|
const needsCodeCss = !(blocks == null ? void 0 : blocks.code) && contentHasBlock(content, "code");
|
|
1256
|
-
const options = {
|
|
1276
|
+
const options = {
|
|
1277
|
+
codeTheme,
|
|
1278
|
+
codeCopyButton,
|
|
1279
|
+
plugins: (blockPlugins == null ? void 0 : blockPlugins.length) ? new Map(blockPlugins.map((plugin) => [plugin.type, plugin])) : void 0
|
|
1280
|
+
};
|
|
1257
1281
|
return /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
1258
1282
|
needsButtonCss && /* @__PURE__ */ jsx5("style", { children: BUTTON_HOVER_CSS }),
|
|
1259
1283
|
needsEmbedCss && /* @__PURE__ */ jsx5("style", { children: EMBED_FRAME_CSS }),
|