@nuucognition/ncm-ui 0.1.0-dev.1 → 0.1.1-beta.1
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 +90 -0
- package/dist/blocks/admonition/index.d.ts +2 -3
- package/dist/blocks/admonition/index.js +79 -23
- package/dist/blocks/aside/index.d.ts +2 -3
- package/dist/blocks/aside/index.js +79 -23
- package/dist/blocks/attribution/index.d.ts +2 -3
- package/dist/blocks/blockquote/index.d.ts +5 -4
- package/dist/blocks/blockquote/index.js +52 -7
- package/dist/blocks/chart/index.d.ts +2 -3
- package/dist/blocks/chart/index.js +2 -1
- package/dist/blocks/code/index.d.ts +2 -3
- package/dist/blocks/code/index.js +2 -2
- package/dist/blocks/container/index.d.ts +2 -3
- package/dist/blocks/container/index.js +50 -5
- package/dist/blocks/custom-code/index.d.ts +2 -3
- package/dist/blocks/custom-code/index.js +1 -1
- package/dist/blocks/dataview/index.d.ts +2 -3
- package/dist/blocks/dataview/index.js +2 -1
- package/dist/blocks/definition/index.d.ts +2 -3
- package/dist/blocks/definition/index.js +79 -23
- package/dist/blocks/embed/index.d.ts +2 -3
- package/dist/blocks/embedding/index.d.ts +2 -3
- package/dist/blocks/embedding/index.js +50 -5
- package/dist/blocks/figure/index.d.ts +2 -3
- package/dist/blocks/figure/index.js +50 -5
- package/dist/blocks/footnote/index.d.ts +2 -3
- package/dist/blocks/footnote/index.js +79 -23
- package/dist/blocks/frontmatter/index.d.ts +2 -3
- package/dist/blocks/header/index.d.ts +2 -3
- package/dist/blocks/header/index.js +50 -5
- package/dist/blocks/horizontal-rule/index.d.ts +2 -3
- package/dist/blocks/html/index.d.ts +3 -4
- package/dist/blocks/html/index.js +2 -1
- package/dist/blocks/index.d.ts +1 -2
- package/dist/blocks/index.js +79 -23
- package/dist/blocks/latex/index.d.ts +2 -3
- package/dist/blocks/latex/index.js +2 -2
- package/dist/blocks/link/index.d.ts +2 -3
- package/dist/blocks/list/index.d.ts +2 -3
- package/dist/blocks/list/index.js +57 -7
- package/dist/blocks/math/index.d.ts +2 -3
- package/dist/blocks/math/index.js +3 -2
- package/dist/blocks/mermaid/index.d.ts +2 -3
- package/dist/blocks/mermaid/index.js +2 -1
- package/dist/blocks/page-breaker/index.d.ts +2 -3
- package/dist/blocks/paragraph/index.d.ts +2 -3
- package/dist/blocks/paragraph/index.js +50 -5
- package/dist/blocks/spoiler/index.d.ts +2 -3
- package/dist/blocks/spoiler/index.js +79 -23
- package/dist/blocks/table/index.d.ts +2 -3
- package/dist/blocks/table/index.js +51 -6
- package/dist/blocks/task-list/index.d.ts +2 -3
- package/dist/blocks/task-list/index.js +52 -6
- package/dist/components/index.d.ts +34 -4
- package/dist/components/index.js +117 -25
- package/dist/components/ncm-block.d.ts +2 -3
- package/dist/components/ncm-block.js +79 -23
- package/dist/components/ncm-document.d.ts +4 -4
- package/dist/components/ncm-document.js +79 -23
- package/dist/context/index.d.ts +2 -3
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +79 -23
- package/dist/hooks/use-block-renderer.js +79 -23
- package/dist/hooks/use-ncm-config.d.ts +1 -2
- package/dist/index.d.ts +3 -4
- package/dist/index.js +118 -26
- package/dist/inline/index.d.ts +4 -4
- package/dist/inline/index.js +51 -6
- package/dist/lib/defaults.js +79 -23
- package/dist/{references-Bs5wJybr.d.ts → references-BYW5pnj_.d.ts} +4 -4
- package/dist/styles/nuu.css +329 -44
- package/dist/styles/paper.css +62 -1
- package/dist/{use-ncm-config-D0doMYTH.d.ts → use-ncm-config-CnntcShj.d.ts} +55 -4
- package/package.json +5 -5
|
@@ -543,9 +543,10 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
543
543
|
case "image": {
|
|
544
544
|
const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
|
|
545
545
|
return /* @__PURE__ */ jsx(
|
|
546
|
-
|
|
546
|
+
EmbedImage,
|
|
547
547
|
{
|
|
548
|
-
"data-ncm-token": "image",
|
|
548
|
+
attrs: { "data-ncm-token": "image" },
|
|
549
|
+
target: token.src,
|
|
549
550
|
src,
|
|
550
551
|
alt: token.alt,
|
|
551
552
|
title: token.title
|
|
@@ -579,10 +580,13 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
579
580
|
}
|
|
580
581
|
if (embedType === "image") {
|
|
581
582
|
return /* @__PURE__ */ jsx(
|
|
582
|
-
|
|
583
|
+
EmbedImage,
|
|
583
584
|
{
|
|
584
|
-
|
|
585
|
-
|
|
585
|
+
attrs: {
|
|
586
|
+
"data-ncm-token": "wiki_embed",
|
|
587
|
+
"data-ncm-wikiembed-type": embedType
|
|
588
|
+
},
|
|
589
|
+
target: token.target,
|
|
586
590
|
src: url,
|
|
587
591
|
alt: token.display ?? token.target,
|
|
588
592
|
className: config.embeddings?.imageClassName
|
|
@@ -613,6 +617,22 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
613
617
|
}
|
|
614
618
|
);
|
|
615
619
|
}
|
|
620
|
+
const onEmbedClick = config.embeddings?.onEmbedClick;
|
|
621
|
+
if (onEmbedClick) {
|
|
622
|
+
const handleClick = (e) => {
|
|
623
|
+
onEmbedClick(token.target, result, e);
|
|
624
|
+
};
|
|
625
|
+
return /* @__PURE__ */ jsx(
|
|
626
|
+
"button",
|
|
627
|
+
{
|
|
628
|
+
type: "button",
|
|
629
|
+
"data-ncm-token": "wiki_embed",
|
|
630
|
+
"data-ncm-wikiembed-type": embedType,
|
|
631
|
+
onClick: handleClick,
|
|
632
|
+
children: token.display ?? token.target
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
}
|
|
616
636
|
return /* @__PURE__ */ jsx(
|
|
617
637
|
"a",
|
|
618
638
|
{
|
|
@@ -631,6 +651,31 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
631
651
|
return null;
|
|
632
652
|
}
|
|
633
653
|
}
|
|
654
|
+
function EmbedImage({ attrs, target, src, alt, title, className }) {
|
|
655
|
+
const config = useNcmConfig();
|
|
656
|
+
const Fallback = config.embeddings?.renderImageError;
|
|
657
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
658
|
+
useEffect(() => {
|
|
659
|
+
setFailedSrc(null);
|
|
660
|
+
}, [src]);
|
|
661
|
+
if (!Fallback) {
|
|
662
|
+
return /* @__PURE__ */ jsx("img", { ...attrs, src, alt, title, className });
|
|
663
|
+
}
|
|
664
|
+
if (failedSrc === src) {
|
|
665
|
+
return /* @__PURE__ */ jsx(Fallback, { target, src, alt, retry: () => setFailedSrc(null) });
|
|
666
|
+
}
|
|
667
|
+
return /* @__PURE__ */ jsx(
|
|
668
|
+
"img",
|
|
669
|
+
{
|
|
670
|
+
...attrs,
|
|
671
|
+
src,
|
|
672
|
+
alt,
|
|
673
|
+
title,
|
|
674
|
+
className,
|
|
675
|
+
onError: () => setFailedSrc(src)
|
|
676
|
+
}
|
|
677
|
+
);
|
|
678
|
+
}
|
|
634
679
|
function renderReadingText(content, opts) {
|
|
635
680
|
if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
636
681
|
const { bionic = false, beeline = false } = opts;
|
|
@@ -666,7 +711,7 @@ function renderReadingText(content, opts) {
|
|
|
666
711
|
return /* @__PURE__ */ jsx(Fragment, { children: pieces });
|
|
667
712
|
}
|
|
668
713
|
function BlockquoteBlock({ block, className }) {
|
|
669
|
-
const lines = block.content.split("\n")
|
|
714
|
+
const lines = block.content.split("\n");
|
|
670
715
|
return /* @__PURE__ */ jsx(
|
|
671
716
|
"blockquote",
|
|
672
717
|
{
|
|
@@ -676,7 +721,7 @@ function BlockquoteBlock({ block, className }) {
|
|
|
676
721
|
"data-block-id": block.id,
|
|
677
722
|
"data-ncm-blockquote": "",
|
|
678
723
|
className,
|
|
679
|
-
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(InlineContent, { content: line }) }, index))
|
|
724
|
+
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index))
|
|
680
725
|
}
|
|
681
726
|
);
|
|
682
727
|
}
|
|
@@ -691,7 +736,8 @@ function ChartBlock({ block, className }) {
|
|
|
691
736
|
"data-ncm-chart": "",
|
|
692
737
|
"data-ncm-chart-type": block.chartType ?? "unknown",
|
|
693
738
|
className: cn(
|
|
694
|
-
|
|
739
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
740
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
695
741
|
className
|
|
696
742
|
),
|
|
697
743
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -816,7 +862,7 @@ function CodeBlock({ block, className }) {
|
|
|
816
862
|
"data-ncm-language": block.language,
|
|
817
863
|
className: cn("relative", className),
|
|
818
864
|
children: [
|
|
819
|
-
codeConfig.copyButton
|
|
865
|
+
codeConfig.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
820
866
|
/* @__PURE__ */ jsx(CustomRenderer, { code: block.content, language: block.language }),
|
|
821
867
|
languageLabel
|
|
822
868
|
]
|
|
@@ -835,7 +881,7 @@ function CodeBlock({ block, className }) {
|
|
|
835
881
|
"data-ncm-language": block.language,
|
|
836
882
|
className: cn("relative", className),
|
|
837
883
|
children: [
|
|
838
|
-
codeConfig?.copyButton
|
|
884
|
+
codeConfig?.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
839
885
|
/* @__PURE__ */ jsx("pre", { "data-ncm-code-pre": "", children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
|
|
840
886
|
codeConfig?.lineNumbers && /* @__PURE__ */ jsx(LineNumbers, { count: lineCount }),
|
|
841
887
|
/* @__PURE__ */ jsx("code", { "data-ncm-code": "", className: "flex-1", children: /* @__PURE__ */ jsx(DefaultShikiRenderer, { code: block.content, language: block.language }) })
|
|
@@ -871,7 +917,8 @@ function DataviewBlock({ block, className }) {
|
|
|
871
917
|
"data-ncm-dataview": "",
|
|
872
918
|
"data-ncm-query-type": block.queryType,
|
|
873
919
|
className: cn(
|
|
874
|
-
|
|
920
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
921
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
875
922
|
className
|
|
876
923
|
),
|
|
877
924
|
children: /* @__PURE__ */ jsx("code", { children: block.query })
|
|
@@ -1191,7 +1238,8 @@ function HtmlBlock({ block, className }) {
|
|
|
1191
1238
|
"data-block-id": block.id,
|
|
1192
1239
|
"data-ncm-html": "",
|
|
1193
1240
|
className: cn(
|
|
1194
|
-
|
|
1241
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1242
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1195
1243
|
className
|
|
1196
1244
|
),
|
|
1197
1245
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1229,7 +1277,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1229
1277
|
"data-ncm-type": block.type,
|
|
1230
1278
|
"data-block-id": block.id,
|
|
1231
1279
|
"data-ncm-latex-display": "",
|
|
1232
|
-
className: cn("overflow-x-auto", className),
|
|
1280
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1233
1281
|
dangerouslySetInnerHTML: { __html: html }
|
|
1234
1282
|
}
|
|
1235
1283
|
);
|
|
@@ -1244,7 +1292,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1244
1292
|
"data-ncm-type": block.type,
|
|
1245
1293
|
"data-block-id": block.id,
|
|
1246
1294
|
"data-ncm-latex-display": "",
|
|
1247
|
-
className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1295
|
+
className: cn("overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1248
1296
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
1249
1297
|
}
|
|
1250
1298
|
);
|
|
@@ -1268,10 +1316,12 @@ function LinkBlock({ block, className }) {
|
|
|
1268
1316
|
function ListBlock({ block, className }) {
|
|
1269
1317
|
const isOrdered = block.type === "list_ordered";
|
|
1270
1318
|
const Tag = isOrdered ? "ol" : "ul";
|
|
1319
|
+
const start = isOrdered && typeof block.marker === "number" && block.marker !== 1 ? block.marker : void 0;
|
|
1271
1320
|
return /* @__PURE__ */ jsx(
|
|
1272
1321
|
Tag,
|
|
1273
1322
|
{
|
|
1274
1323
|
role: "list",
|
|
1324
|
+
start,
|
|
1275
1325
|
"data-ncm-block": block.id,
|
|
1276
1326
|
"data-ncm-stable": block.stableId,
|
|
1277
1327
|
"data-ncm-type": block.type,
|
|
@@ -1283,6 +1333,9 @@ function ListBlock({ block, className }) {
|
|
|
1283
1333
|
}
|
|
1284
1334
|
);
|
|
1285
1335
|
}
|
|
1336
|
+
function ItemContent({ content }) {
|
|
1337
|
+
return content.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" });
|
|
1338
|
+
}
|
|
1286
1339
|
function nestedItemIdKey(id) {
|
|
1287
1340
|
if (!id) {
|
|
1288
1341
|
return void 0;
|
|
@@ -1299,7 +1352,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1299
1352
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
|
|
1300
1353
|
const key = nestedItemIdKey(itemIds?.[index]) ?? `item-${index}`;
|
|
1301
1354
|
if (typeof item === "string") {
|
|
1302
|
-
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(
|
|
1355
|
+
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(ItemContent, { content: item }) }, key);
|
|
1303
1356
|
}
|
|
1304
1357
|
if (isTypedNestedList(item)) {
|
|
1305
1358
|
return /* @__PURE__ */ jsx(NestedTypedList, { list: item }, key);
|
|
@@ -1309,7 +1362,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1309
1362
|
const content = typeof first === "string" ? first : "";
|
|
1310
1363
|
const nestedContent = processNestedItems(rest, ordered);
|
|
1311
1364
|
return /* @__PURE__ */ jsxs("li", { "data-ncm-list-item": "", children: [
|
|
1312
|
-
/* @__PURE__ */ jsx(
|
|
1365
|
+
/* @__PURE__ */ jsx(ItemContent, { content }),
|
|
1313
1366
|
nestedContent
|
|
1314
1367
|
] }, key);
|
|
1315
1368
|
}
|
|
@@ -1359,7 +1412,7 @@ function MathBlock({ block, className }) {
|
|
|
1359
1412
|
"data-ncm-type": block.type,
|
|
1360
1413
|
"data-block-id": block.id,
|
|
1361
1414
|
"data-ncm-math": "",
|
|
1362
|
-
className: cn("overflow-x-auto", className),
|
|
1415
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1363
1416
|
dangerouslySetInnerHTML: { __html: html }
|
|
1364
1417
|
}
|
|
1365
1418
|
);
|
|
@@ -1375,7 +1428,8 @@ function MathBlock({ block, className }) {
|
|
|
1375
1428
|
"data-block-id": block.id,
|
|
1376
1429
|
"data-ncm-math": "",
|
|
1377
1430
|
className: cn(
|
|
1378
|
-
|
|
1431
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1432
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1379
1433
|
className
|
|
1380
1434
|
),
|
|
1381
1435
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1393,7 +1447,8 @@ function MermaidBlock({ block, className }) {
|
|
|
1393
1447
|
"data-ncm-mermaid": "",
|
|
1394
1448
|
"data-ncm-diagram-type": block.diagramType,
|
|
1395
1449
|
className: cn(
|
|
1396
|
-
|
|
1450
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1451
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1397
1452
|
className
|
|
1398
1453
|
),
|
|
1399
1454
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1454,7 +1509,7 @@ function TableBlock({ block, className }) {
|
|
|
1454
1509
|
"data-ncm-type": block.type,
|
|
1455
1510
|
"data-block-id": block.id,
|
|
1456
1511
|
"data-ncm-table": "",
|
|
1457
|
-
className: cn("w-full overflow-x-auto", className),
|
|
1512
|
+
className: cn("w-full overflow-x-auto overflow-y-hidden", className),
|
|
1458
1513
|
children: /* @__PURE__ */ jsxs("table", { role: "table", "data-ncm-table-element": "", children: [
|
|
1459
1514
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { "data-ncm-table-row": "", children: block.headers.map((header, index) => /* @__PURE__ */ jsx("th", { "data-ncm-table-header": "", children: /* @__PURE__ */ jsx(InlineContent, { content: header }) }, index)) }) }),
|
|
1460
1515
|
/* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, rowIndex) => {
|
|
@@ -1468,6 +1523,7 @@ function TableBlock({ block, className }) {
|
|
|
1468
1523
|
function TaskItems({ items }) {
|
|
1469
1524
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item) => {
|
|
1470
1525
|
const status = item.checked ? "Completed" : "Incomplete";
|
|
1526
|
+
const text = serializeInlineContent(item.content);
|
|
1471
1527
|
return /* @__PURE__ */ jsxs(
|
|
1472
1528
|
"li",
|
|
1473
1529
|
{
|
|
@@ -1494,7 +1550,7 @@ function TaskItems({ items }) {
|
|
|
1494
1550
|
":",
|
|
1495
1551
|
" "
|
|
1496
1552
|
] }),
|
|
1497
|
-
/* @__PURE__ */ jsx(InlineContent, { content:
|
|
1553
|
+
text.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: text }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" })
|
|
1498
1554
|
] })
|
|
1499
1555
|
] }),
|
|
1500
1556
|
item.children ? /* @__PURE__ */ jsx("ul", { role: "list", "data-ncm-list-nested": "", className: "ml-6 list-none", children: /* @__PURE__ */ jsx(TaskItems, { items: item.children.items }) }) : null
|
|
@@ -1539,7 +1595,7 @@ function FallbackBlock({ block, className }) {
|
|
|
1539
1595
|
"data-block-id": block.id,
|
|
1540
1596
|
"data-ncm-fallback": "",
|
|
1541
1597
|
className: cn(
|
|
1542
|
-
"overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1598
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1543
1599
|
className
|
|
1544
1600
|
)
|
|
1545
1601
|
},
|
|
@@ -1595,7 +1651,7 @@ function CustomCodeBlock({ block, className }) {
|
|
|
1595
1651
|
"data-block-id": block.id,
|
|
1596
1652
|
"data-ncm-custom-code": "",
|
|
1597
1653
|
"data-ncm-language": block.language,
|
|
1598
|
-
className: cn("overflow-x-auto", className),
|
|
1654
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1599
1655
|
children: [
|
|
1600
1656
|
/* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
|
|
1601
1657
|
/* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { FrontmatterBlock as FrontmatterBlock$1 } from '@nuucognition/ncm';
|
|
3
3
|
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
-
import 'react';
|
|
5
4
|
|
|
6
5
|
type FrontmatterBlockProps = BlockRendererProps<FrontmatterBlock$1>;
|
|
7
6
|
/**
|
|
@@ -11,6 +10,6 @@ type FrontmatterBlockProps = BlockRendererProps<FrontmatterBlock$1>;
|
|
|
11
10
|
* is a neutral default so the block is never silently dropped. Override the
|
|
12
11
|
* `frontmatter` renderer key to hide it or render a richer header.
|
|
13
12
|
*/
|
|
14
|
-
declare function FrontmatterBlock({ block, className }: FrontmatterBlockProps):
|
|
13
|
+
declare function FrontmatterBlock({ block, className }: FrontmatterBlockProps): react.JSX.Element;
|
|
15
14
|
|
|
16
15
|
export { FrontmatterBlock, type FrontmatterBlockProps };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { HeaderBlock as HeaderBlock$1 } from '@nuucognition/ncm';
|
|
3
3
|
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
-
import 'react';
|
|
5
4
|
|
|
6
5
|
type HeaderBlockProps = BlockRendererProps<HeaderBlock$1>;
|
|
7
|
-
declare function HeaderBlock({ block, className }: HeaderBlockProps):
|
|
6
|
+
declare function HeaderBlock({ block, className }: HeaderBlockProps): react.JSX.Element;
|
|
8
7
|
|
|
9
8
|
export { HeaderBlock, type HeaderBlockProps };
|
|
@@ -468,9 +468,10 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
468
468
|
case "image": {
|
|
469
469
|
const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
|
|
470
470
|
return /* @__PURE__ */ jsx(
|
|
471
|
-
|
|
471
|
+
EmbedImage,
|
|
472
472
|
{
|
|
473
|
-
"data-ncm-token": "image",
|
|
473
|
+
attrs: { "data-ncm-token": "image" },
|
|
474
|
+
target: token.src,
|
|
474
475
|
src,
|
|
475
476
|
alt: token.alt,
|
|
476
477
|
title: token.title
|
|
@@ -504,10 +505,13 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
504
505
|
}
|
|
505
506
|
if (embedType === "image") {
|
|
506
507
|
return /* @__PURE__ */ jsx(
|
|
507
|
-
|
|
508
|
+
EmbedImage,
|
|
508
509
|
{
|
|
509
|
-
|
|
510
|
-
|
|
510
|
+
attrs: {
|
|
511
|
+
"data-ncm-token": "wiki_embed",
|
|
512
|
+
"data-ncm-wikiembed-type": embedType
|
|
513
|
+
},
|
|
514
|
+
target: token.target,
|
|
511
515
|
src: url,
|
|
512
516
|
alt: token.display ?? token.target,
|
|
513
517
|
className: config.embeddings?.imageClassName
|
|
@@ -538,6 +542,22 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
538
542
|
}
|
|
539
543
|
);
|
|
540
544
|
}
|
|
545
|
+
const onEmbedClick = config.embeddings?.onEmbedClick;
|
|
546
|
+
if (onEmbedClick) {
|
|
547
|
+
const handleClick = (e) => {
|
|
548
|
+
onEmbedClick(token.target, result, e);
|
|
549
|
+
};
|
|
550
|
+
return /* @__PURE__ */ jsx(
|
|
551
|
+
"button",
|
|
552
|
+
{
|
|
553
|
+
type: "button",
|
|
554
|
+
"data-ncm-token": "wiki_embed",
|
|
555
|
+
"data-ncm-wikiembed-type": embedType,
|
|
556
|
+
onClick: handleClick,
|
|
557
|
+
children: token.display ?? token.target
|
|
558
|
+
}
|
|
559
|
+
);
|
|
560
|
+
}
|
|
541
561
|
return /* @__PURE__ */ jsx(
|
|
542
562
|
"a",
|
|
543
563
|
{
|
|
@@ -556,6 +576,31 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
556
576
|
return null;
|
|
557
577
|
}
|
|
558
578
|
}
|
|
579
|
+
function EmbedImage({ attrs, target, src, alt, title, className }) {
|
|
580
|
+
const config = useNcmConfig();
|
|
581
|
+
const Fallback = config.embeddings?.renderImageError;
|
|
582
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
583
|
+
useEffect(() => {
|
|
584
|
+
setFailedSrc(null);
|
|
585
|
+
}, [src]);
|
|
586
|
+
if (!Fallback) {
|
|
587
|
+
return /* @__PURE__ */ jsx("img", { ...attrs, src, alt, title, className });
|
|
588
|
+
}
|
|
589
|
+
if (failedSrc === src) {
|
|
590
|
+
return /* @__PURE__ */ jsx(Fallback, { target, src, alt, retry: () => setFailedSrc(null) });
|
|
591
|
+
}
|
|
592
|
+
return /* @__PURE__ */ jsx(
|
|
593
|
+
"img",
|
|
594
|
+
{
|
|
595
|
+
...attrs,
|
|
596
|
+
src,
|
|
597
|
+
alt,
|
|
598
|
+
title,
|
|
599
|
+
className,
|
|
600
|
+
onError: () => setFailedSrc(src)
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
}
|
|
559
604
|
function renderReadingText(content, opts) {
|
|
560
605
|
if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
561
606
|
const { bionic = false, beeline = false } = opts;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { HorizontalRuleBlock as HorizontalRuleBlock$1 } from '@nuucognition/ncm';
|
|
3
3
|
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
-
import 'react';
|
|
5
4
|
|
|
6
5
|
type HorizontalRuleBlockProps = BlockRendererProps<HorizontalRuleBlock$1>;
|
|
7
|
-
declare function HorizontalRuleBlock({ block, className }: HorizontalRuleBlockProps):
|
|
6
|
+
declare function HorizontalRuleBlock({ block, className }: HorizontalRuleBlockProps): react.JSX.Element;
|
|
8
7
|
|
|
9
8
|
export { HorizontalRuleBlock, type HorizontalRuleBlockProps };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { HtmlBlock as HtmlBlock$1 } from '@nuucognition/ncm';
|
|
3
3
|
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
-
import 'react';
|
|
5
4
|
|
|
6
5
|
type HtmlBlockProps = BlockRendererProps<HtmlBlock$1>;
|
|
7
6
|
interface SanitizedHtmlBlockProps extends HtmlBlockProps {
|
|
@@ -19,13 +18,13 @@ interface SanitizedHtmlBlockProps extends HtmlBlockProps {
|
|
|
19
18
|
* a sanitization step override the `html` renderer key to inject trusted
|
|
20
19
|
* markup.
|
|
21
20
|
*/
|
|
22
|
-
declare function HtmlBlock({ block, className }: HtmlBlockProps):
|
|
21
|
+
declare function HtmlBlock({ block, className }: HtmlBlockProps): react.JSX.Element;
|
|
23
22
|
/**
|
|
24
23
|
* Opt-in HTML renderer for consumers that want sanitized HTML injection.
|
|
25
24
|
*
|
|
26
25
|
* `HtmlBlock` remains the safe default and renders source as text. Use this
|
|
27
26
|
* renderer as an explicit `html` override when your surface supports HTML.
|
|
28
27
|
*/
|
|
29
|
-
declare function SanitizedHtmlBlock({ block, className, rawHtml, allowDataImages, }: SanitizedHtmlBlockProps):
|
|
28
|
+
declare function SanitizedHtmlBlock({ block, className, rawHtml, allowDataImages, }: SanitizedHtmlBlockProps): react.JSX.Element;
|
|
30
29
|
|
|
31
30
|
export { HtmlBlock, type HtmlBlockProps, SanitizedHtmlBlock, type SanitizedHtmlBlockProps };
|
|
@@ -18,7 +18,8 @@ function HtmlBlock({ block, className }) {
|
|
|
18
18
|
"data-block-id": block.id,
|
|
19
19
|
"data-ncm-html": "",
|
|
20
20
|
className: cn(
|
|
21
|
-
|
|
21
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
22
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
22
23
|
className
|
|
23
24
|
),
|
|
24
25
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export { ParagraphBlock, ParagraphBlockProps } from './paragraph/index.js';
|
|
|
26
26
|
export { SpoilerBlock, SpoilerBlockProps } from './spoiler/index.js';
|
|
27
27
|
export { TableBlock, TableBlockProps } from './table/index.js';
|
|
28
28
|
export { TaskListBlock, TaskListBlockProps } from './task-list/index.js';
|
|
29
|
-
import 'react
|
|
29
|
+
import 'react';
|
|
30
30
|
import '@nuucognition/ncm';
|
|
31
31
|
import '../renderers-C5f41FCy.js';
|
|
32
|
-
import 'react';
|