@nuucognition/ncm-ui 0.1.1-beta.0 → 0.1.1-beta.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/dist/blocks/admonition/index.js +118 -46
- package/dist/blocks/aside/index.js +118 -46
- package/dist/blocks/blockquote/index.d.ts +7 -5
- package/dist/blocks/blockquote/index.js +1218 -36
- package/dist/blocks/chart/index.js +2 -1
- package/dist/blocks/container/index.js +72 -31
- package/dist/blocks/custom-code/index.js +1 -1
- package/dist/blocks/dataview/index.js +2 -1
- package/dist/blocks/definition/index.js +117 -45
- package/dist/blocks/embedding/index.js +72 -31
- package/dist/blocks/figure/index.js +72 -31
- package/dist/blocks/footnote/index.js +118 -46
- package/dist/blocks/header/index.js +72 -31
- package/dist/blocks/html/index.js +2 -1
- package/dist/blocks/index.js +118 -46
- package/dist/blocks/latex/index.js +2 -2
- package/dist/blocks/list/index.js +72 -31
- package/dist/blocks/math/index.js +3 -2
- package/dist/blocks/mermaid/index.js +2 -1
- package/dist/blocks/paragraph/index.js +72 -31
- package/dist/blocks/spoiler/index.js +118 -46
- package/dist/blocks/table/index.js +73 -32
- package/dist/blocks/task-list/index.js +72 -31
- package/dist/components/index.js +157 -65
- package/dist/components/ncm-block.js +118 -46
- package/dist/components/ncm-document.js +157 -65
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +119 -44
- package/dist/hooks/index.js +118 -46
- package/dist/hooks/use-block-renderer.js +118 -46
- package/dist/index.d.ts +1 -1
- package/dist/index.js +164 -58
- package/dist/inline/index.d.ts +2 -3
- package/dist/inline/index.js +72 -31
- package/dist/lib/defaults.js +118 -46
- package/dist/references-BM-lvGrq.d.ts +99 -0
- package/dist/styles/nuu.css +39 -16
- package/package.json +3 -4
- package/dist/references-BYW5pnj_.d.ts +0 -63
|
@@ -18,7 +18,8 @@ function ChartBlock({ block, className }) {
|
|
|
18
18
|
"data-ncm-chart": "",
|
|
19
19
|
"data-ncm-chart-type": block.chartType ?? "unknown",
|
|
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 })
|
|
@@ -51,6 +51,52 @@ function tryParseInlineRef(input) {
|
|
|
51
51
|
}
|
|
52
52
|
return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
|
|
53
53
|
}
|
|
54
|
+
function runLength(input, index, char) {
|
|
55
|
+
let end = index;
|
|
56
|
+
while (end < input.length && input[end] === char) end++;
|
|
57
|
+
return end - index;
|
|
58
|
+
}
|
|
59
|
+
function tryParseEmphasis(input) {
|
|
60
|
+
const char = input[0];
|
|
61
|
+
if (char !== "*" && char !== "_") return null;
|
|
62
|
+
const open = Math.min(3, runLength(input, 0, char));
|
|
63
|
+
const need = open;
|
|
64
|
+
let i = open;
|
|
65
|
+
while (i < input.length) {
|
|
66
|
+
const ch = input[i];
|
|
67
|
+
if (ch === "`") {
|
|
68
|
+
const close = input.indexOf("`", i + 1);
|
|
69
|
+
if (close === -1) break;
|
|
70
|
+
i = close + 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (ch !== char) {
|
|
74
|
+
i++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const run = runLength(input, i, char);
|
|
78
|
+
const closes = need === 1 ? run % 2 === 1 : run >= need;
|
|
79
|
+
if (!closes) {
|
|
80
|
+
i += run;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const extra = run - need;
|
|
84
|
+
const inner = input.slice(open, i + extra);
|
|
85
|
+
if (inner.length === 0) return null;
|
|
86
|
+
const length = i + run;
|
|
87
|
+
const children = parseInline(inner);
|
|
88
|
+
let token;
|
|
89
|
+
if (need === 3) {
|
|
90
|
+
token = { type: "bold", children: [{ type: "italic", children }] };
|
|
91
|
+
} else if (need === 2) {
|
|
92
|
+
token = { type: "bold", children };
|
|
93
|
+
} else {
|
|
94
|
+
token = { type: "italic", children };
|
|
95
|
+
}
|
|
96
|
+
return { token, length };
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
54
100
|
function parseInline(content) {
|
|
55
101
|
if (!content) return [];
|
|
56
102
|
const tokens = [];
|
|
@@ -122,17 +168,11 @@ function parseInline(content) {
|
|
|
122
168
|
remaining = remaining.slice(linkMatch[0].length);
|
|
123
169
|
continue;
|
|
124
170
|
}
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
type: "bold",
|
|
131
|
-
children: parseInline(innerContent)
|
|
132
|
-
});
|
|
133
|
-
remaining = remaining.slice(boldMatch[0].length);
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
171
|
+
const emphasis = tryParseEmphasis(remaining);
|
|
172
|
+
if (emphasis) {
|
|
173
|
+
tokens.push(emphasis.token);
|
|
174
|
+
remaining = remaining.slice(emphasis.length);
|
|
175
|
+
continue;
|
|
136
176
|
}
|
|
137
177
|
const strikeMatch = remaining.match(/^~~(.+?)~~/);
|
|
138
178
|
if (strikeMatch && strikeMatch[1] !== void 0) {
|
|
@@ -143,18 +183,6 @@ function parseInline(content) {
|
|
|
143
183
|
remaining = remaining.slice(strikeMatch[0].length);
|
|
144
184
|
continue;
|
|
145
185
|
}
|
|
146
|
-
const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
|
|
147
|
-
if (italicMatch) {
|
|
148
|
-
const innerContent = italicMatch[1] ?? italicMatch[2];
|
|
149
|
-
if (innerContent !== void 0) {
|
|
150
|
-
tokens.push({
|
|
151
|
-
type: "italic",
|
|
152
|
-
children: parseInline(innerContent)
|
|
153
|
-
});
|
|
154
|
-
remaining = remaining.slice(italicMatch[0].length);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
186
|
const nextSpecial = findNextSpecialChar(remaining);
|
|
159
187
|
if (nextSpecial > 0) {
|
|
160
188
|
tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
|
|
@@ -265,17 +293,30 @@ function ReferenceMarker({ kind, number, children }) {
|
|
|
265
293
|
}
|
|
266
294
|
);
|
|
267
295
|
}
|
|
268
|
-
|
|
296
|
+
function normalizeReferenceContent(content) {
|
|
297
|
+
return content.replace(/\s+/g, " ").trim().toLowerCase();
|
|
298
|
+
}
|
|
299
|
+
var ReferenceNumberingContext = createContext(null);
|
|
269
300
|
var BlockReferenceScopeContext = createContext(null);
|
|
270
|
-
function BlockReferenceScope({
|
|
271
|
-
const
|
|
272
|
-
const
|
|
301
|
+
function BlockReferenceScope({ children }) {
|
|
302
|
+
const numbering = useContext(ReferenceNumberingContext);
|
|
303
|
+
const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
|
|
273
304
|
const counter = useRef({ ref: 0, footnote: 0 });
|
|
274
|
-
counter.current = { ref: 0, footnote: 0 };
|
|
275
305
|
const value = {
|
|
306
|
+
numberFor(kind, content) {
|
|
307
|
+
const key = normalizeReferenceContent(content);
|
|
308
|
+
const fromDocument = numbering?.[kind].get(key);
|
|
309
|
+
if (fromDocument !== void 0) return fromDocument;
|
|
310
|
+
const map = local.current[kind];
|
|
311
|
+
const existing = map.get(key);
|
|
312
|
+
if (existing !== void 0) return existing;
|
|
313
|
+
counter.current[kind] += 1;
|
|
314
|
+
map.set(key, counter.current[kind]);
|
|
315
|
+
return counter.current[kind];
|
|
316
|
+
},
|
|
276
317
|
next(kind) {
|
|
277
318
|
counter.current[kind] += 1;
|
|
278
|
-
return
|
|
319
|
+
return counter.current[kind];
|
|
279
320
|
}
|
|
280
321
|
};
|
|
281
322
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
|
|
@@ -283,7 +324,7 @@ function BlockReferenceScope({ blockId, children }) {
|
|
|
283
324
|
function useBlockReferenceScope() {
|
|
284
325
|
return useContext(BlockReferenceScopeContext);
|
|
285
326
|
}
|
|
286
|
-
var INERT_SCOPE = { next: () => 0 };
|
|
327
|
+
var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
|
|
287
328
|
function InertReferenceScope({ children }) {
|
|
288
329
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
|
|
289
330
|
}
|
|
@@ -574,7 +615,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
574
615
|
);
|
|
575
616
|
}
|
|
576
617
|
case "inline_ref": {
|
|
577
|
-
const number = refScope?.
|
|
618
|
+
const number = refScope?.numberFor(token.kind, token.content) ?? 0;
|
|
578
619
|
return /* @__PURE__ */ jsx(ReferenceMarker, { kind: token.kind, number, children: token.content ? /* @__PURE__ */ jsx(InertReferenceScope, { children: /* @__PURE__ */ jsx(InlineContent, { content: token.content, disableBionic: true, disableBeeline: true }) }) : null });
|
|
579
620
|
}
|
|
580
621
|
default:
|
|
@@ -19,7 +19,7 @@ function CustomCodeBlock({ block, className }) {
|
|
|
19
19
|
"data-block-id": block.id,
|
|
20
20
|
"data-ncm-custom-code": "",
|
|
21
21
|
"data-ncm-language": block.language,
|
|
22
|
-
className: cn("overflow-x-auto", className),
|
|
22
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
23
23
|
children: [
|
|
24
24
|
/* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
|
|
25
25
|
/* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
|
|
@@ -18,7 +18,8 @@ function DataviewBlock({ block, className }) {
|
|
|
18
18
|
"data-ncm-dataview": "",
|
|
19
19
|
"data-ncm-query-type": block.queryType,
|
|
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.query })
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { serializeInlineContent, isTypedNestedList } from '@nuucognition/ncm';
|
|
2
|
+
import { serializeInlineContent, isTypedNestedList, parseNcm } from '@nuucognition/ncm';
|
|
3
3
|
import { createContext, createElement, useMemo, useContext, useRef, useState, useEffect, useId, useCallback, Component } from 'react';
|
|
4
4
|
import { extractExtension, embedTypeFromExtension } from '@nuucognition/mesh-core';
|
|
5
5
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -48,6 +48,52 @@ function tryParseInlineRef(input) {
|
|
|
48
48
|
}
|
|
49
49
|
return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
|
|
50
50
|
}
|
|
51
|
+
function runLength(input, index, char) {
|
|
52
|
+
let end = index;
|
|
53
|
+
while (end < input.length && input[end] === char) end++;
|
|
54
|
+
return end - index;
|
|
55
|
+
}
|
|
56
|
+
function tryParseEmphasis(input) {
|
|
57
|
+
const char = input[0];
|
|
58
|
+
if (char !== "*" && char !== "_") return null;
|
|
59
|
+
const open = Math.min(3, runLength(input, 0, char));
|
|
60
|
+
const need = open;
|
|
61
|
+
let i = open;
|
|
62
|
+
while (i < input.length) {
|
|
63
|
+
const ch = input[i];
|
|
64
|
+
if (ch === "`") {
|
|
65
|
+
const close = input.indexOf("`", i + 1);
|
|
66
|
+
if (close === -1) break;
|
|
67
|
+
i = close + 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (ch !== char) {
|
|
71
|
+
i++;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const run = runLength(input, i, char);
|
|
75
|
+
const closes = need === 1 ? run % 2 === 1 : run >= need;
|
|
76
|
+
if (!closes) {
|
|
77
|
+
i += run;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const extra = run - need;
|
|
81
|
+
const inner = input.slice(open, i + extra);
|
|
82
|
+
if (inner.length === 0) return null;
|
|
83
|
+
const length = i + run;
|
|
84
|
+
const children = parseInline(inner);
|
|
85
|
+
let token;
|
|
86
|
+
if (need === 3) {
|
|
87
|
+
token = { type: "bold", children: [{ type: "italic", children }] };
|
|
88
|
+
} else if (need === 2) {
|
|
89
|
+
token = { type: "bold", children };
|
|
90
|
+
} else {
|
|
91
|
+
token = { type: "italic", children };
|
|
92
|
+
}
|
|
93
|
+
return { token, length };
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
51
97
|
function parseInline(content) {
|
|
52
98
|
if (!content) return [];
|
|
53
99
|
const tokens = [];
|
|
@@ -119,17 +165,11 @@ function parseInline(content) {
|
|
|
119
165
|
remaining = remaining.slice(linkMatch[0].length);
|
|
120
166
|
continue;
|
|
121
167
|
}
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
type: "bold",
|
|
128
|
-
children: parseInline(innerContent)
|
|
129
|
-
});
|
|
130
|
-
remaining = remaining.slice(boldMatch[0].length);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
168
|
+
const emphasis = tryParseEmphasis(remaining);
|
|
169
|
+
if (emphasis) {
|
|
170
|
+
tokens.push(emphasis.token);
|
|
171
|
+
remaining = remaining.slice(emphasis.length);
|
|
172
|
+
continue;
|
|
133
173
|
}
|
|
134
174
|
const strikeMatch = remaining.match(/^~~(.+?)~~/);
|
|
135
175
|
if (strikeMatch && strikeMatch[1] !== void 0) {
|
|
@@ -140,18 +180,6 @@ function parseInline(content) {
|
|
|
140
180
|
remaining = remaining.slice(strikeMatch[0].length);
|
|
141
181
|
continue;
|
|
142
182
|
}
|
|
143
|
-
const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
|
|
144
|
-
if (italicMatch) {
|
|
145
|
-
const innerContent = italicMatch[1] ?? italicMatch[2];
|
|
146
|
-
if (innerContent !== void 0) {
|
|
147
|
-
tokens.push({
|
|
148
|
-
type: "italic",
|
|
149
|
-
children: parseInline(innerContent)
|
|
150
|
-
});
|
|
151
|
-
remaining = remaining.slice(italicMatch[0].length);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
183
|
const nextSpecial = findNextSpecialChar(remaining);
|
|
156
184
|
if (nextSpecial > 0) {
|
|
157
185
|
tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
|
|
@@ -262,17 +290,30 @@ function ReferenceMarker({ kind, number, children }) {
|
|
|
262
290
|
}
|
|
263
291
|
);
|
|
264
292
|
}
|
|
265
|
-
|
|
293
|
+
function normalizeReferenceContent(content) {
|
|
294
|
+
return content.replace(/\s+/g, " ").trim().toLowerCase();
|
|
295
|
+
}
|
|
296
|
+
var ReferenceNumberingContext = createContext(null);
|
|
266
297
|
var BlockReferenceScopeContext = createContext(null);
|
|
267
|
-
function BlockReferenceScope({
|
|
268
|
-
const
|
|
269
|
-
const
|
|
298
|
+
function BlockReferenceScope({ children }) {
|
|
299
|
+
const numbering = useContext(ReferenceNumberingContext);
|
|
300
|
+
const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
|
|
270
301
|
const counter = useRef({ ref: 0, footnote: 0 });
|
|
271
|
-
counter.current = { ref: 0, footnote: 0 };
|
|
272
302
|
const value = {
|
|
303
|
+
numberFor(kind, content) {
|
|
304
|
+
const key = normalizeReferenceContent(content);
|
|
305
|
+
const fromDocument = numbering?.[kind].get(key);
|
|
306
|
+
if (fromDocument !== void 0) return fromDocument;
|
|
307
|
+
const map = local.current[kind];
|
|
308
|
+
const existing = map.get(key);
|
|
309
|
+
if (existing !== void 0) return existing;
|
|
310
|
+
counter.current[kind] += 1;
|
|
311
|
+
map.set(key, counter.current[kind]);
|
|
312
|
+
return counter.current[kind];
|
|
313
|
+
},
|
|
273
314
|
next(kind) {
|
|
274
315
|
counter.current[kind] += 1;
|
|
275
|
-
return
|
|
316
|
+
return counter.current[kind];
|
|
276
317
|
}
|
|
277
318
|
};
|
|
278
319
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
|
|
@@ -280,7 +321,7 @@ function BlockReferenceScope({ blockId, children }) {
|
|
|
280
321
|
function useBlockReferenceScope() {
|
|
281
322
|
return useContext(BlockReferenceScopeContext);
|
|
282
323
|
}
|
|
283
|
-
var INERT_SCOPE = { next: () => 0 };
|
|
324
|
+
var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
|
|
284
325
|
function InertReferenceScope({ children }) {
|
|
285
326
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
|
|
286
327
|
}
|
|
@@ -571,7 +612,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
571
612
|
);
|
|
572
613
|
}
|
|
573
614
|
case "inline_ref": {
|
|
574
|
-
const number = refScope?.
|
|
615
|
+
const number = refScope?.numberFor(token.kind, token.content) ?? 0;
|
|
575
616
|
return /* @__PURE__ */ jsx(ReferenceMarker, { kind: token.kind, number, children: token.content ? /* @__PURE__ */ jsx(InertReferenceScope, { children: /* @__PURE__ */ jsx(InlineContent, { content: token.content, disableBionic: true, disableBeeline: true }) }) : null });
|
|
576
617
|
}
|
|
577
618
|
default:
|
|
@@ -710,8 +751,32 @@ function AttributionBlock({ block, className }) {
|
|
|
710
751
|
}
|
|
711
752
|
);
|
|
712
753
|
}
|
|
754
|
+
function quoteBlocks(block) {
|
|
755
|
+
try {
|
|
756
|
+
const doc = parseNcm(block.content, {
|
|
757
|
+
preset: "ncm-full",
|
|
758
|
+
allowMissingFrontmatter: true,
|
|
759
|
+
// Attribution off, as the NUU Editor's bridge keeps it: the promoter's
|
|
760
|
+
// trigger is any last quote line starting with `-`, so a nested quote
|
|
761
|
+
// ending in a list item would lose that item to a `— Author` line.
|
|
762
|
+
blockOptions: { extensions: { attribution: false } }
|
|
763
|
+
});
|
|
764
|
+
const blocks = doc.blocks ?? [];
|
|
765
|
+
if (blocks.length === 0 || blocks.some((child) => child.type === "frontmatter")) {
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
768
|
+
return blocks.map((child, index) => ({ ...child, id: `${block.id}.${index + 1}`, stableId: void 0 }));
|
|
769
|
+
} catch {
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function QuotedLines({ content }) {
|
|
774
|
+
const lines = content.split("\n");
|
|
775
|
+
return /* @__PURE__ */ jsx(Fragment, { children: 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)) });
|
|
776
|
+
}
|
|
713
777
|
function BlockquoteBlock({ block, className }) {
|
|
714
|
-
const
|
|
778
|
+
const multiline = block.content.includes("\n");
|
|
779
|
+
const blocks = useMemo(() => multiline ? quoteBlocks(block) : null, [block, multiline]);
|
|
715
780
|
return /* @__PURE__ */ jsx(
|
|
716
781
|
"blockquote",
|
|
717
782
|
{
|
|
@@ -721,7 +786,9 @@ function BlockquoteBlock({ block, className }) {
|
|
|
721
786
|
"data-block-id": block.id,
|
|
722
787
|
"data-ncm-blockquote": "",
|
|
723
788
|
className,
|
|
724
|
-
children:
|
|
789
|
+
children: !multiline ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : blocks === null ? /* @__PURE__ */ jsx(QuotedLines, { content: block.content }) : blocks.map(
|
|
790
|
+
(child) => child.type === "paragraph" ? /* @__PURE__ */ jsx(QuotedLines, { content: child.content ?? "" }, blockKey(child)) : /* @__PURE__ */ jsx(NcmBlock, { block: child }, blockKey(child))
|
|
791
|
+
)
|
|
725
792
|
}
|
|
726
793
|
);
|
|
727
794
|
}
|
|
@@ -736,7 +803,8 @@ function ChartBlock({ block, className }) {
|
|
|
736
803
|
"data-ncm-chart": "",
|
|
737
804
|
"data-ncm-chart-type": block.chartType ?? "unknown",
|
|
738
805
|
className: cn(
|
|
739
|
-
|
|
806
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
807
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
740
808
|
className
|
|
741
809
|
),
|
|
742
810
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -916,7 +984,8 @@ function DataviewBlock({ block, className }) {
|
|
|
916
984
|
"data-ncm-dataview": "",
|
|
917
985
|
"data-ncm-query-type": block.queryType,
|
|
918
986
|
className: cn(
|
|
919
|
-
|
|
987
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
988
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
920
989
|
className
|
|
921
990
|
),
|
|
922
991
|
children: /* @__PURE__ */ jsx("code", { children: block.query })
|
|
@@ -1240,7 +1309,8 @@ function HtmlBlock({ block, className }) {
|
|
|
1240
1309
|
"data-block-id": block.id,
|
|
1241
1310
|
"data-ncm-html": "",
|
|
1242
1311
|
className: cn(
|
|
1243
|
-
|
|
1312
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1313
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1244
1314
|
className
|
|
1245
1315
|
),
|
|
1246
1316
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1278,7 +1348,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1278
1348
|
"data-ncm-type": block.type,
|
|
1279
1349
|
"data-block-id": block.id,
|
|
1280
1350
|
"data-ncm-latex-display": "",
|
|
1281
|
-
className: cn("overflow-x-auto", className),
|
|
1351
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1282
1352
|
dangerouslySetInnerHTML: { __html: html }
|
|
1283
1353
|
}
|
|
1284
1354
|
);
|
|
@@ -1293,7 +1363,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1293
1363
|
"data-ncm-type": block.type,
|
|
1294
1364
|
"data-block-id": block.id,
|
|
1295
1365
|
"data-ncm-latex-display": "",
|
|
1296
|
-
className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1366
|
+
className: cn("overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1297
1367
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
1298
1368
|
}
|
|
1299
1369
|
);
|
|
@@ -1413,7 +1483,7 @@ function MathBlock({ block, className }) {
|
|
|
1413
1483
|
"data-ncm-type": block.type,
|
|
1414
1484
|
"data-block-id": block.id,
|
|
1415
1485
|
"data-ncm-math": "",
|
|
1416
|
-
className: cn("overflow-x-auto", className),
|
|
1486
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1417
1487
|
dangerouslySetInnerHTML: { __html: html }
|
|
1418
1488
|
}
|
|
1419
1489
|
);
|
|
@@ -1429,7 +1499,8 @@ function MathBlock({ block, className }) {
|
|
|
1429
1499
|
"data-block-id": block.id,
|
|
1430
1500
|
"data-ncm-math": "",
|
|
1431
1501
|
className: cn(
|
|
1432
|
-
|
|
1502
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1503
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1433
1504
|
className
|
|
1434
1505
|
),
|
|
1435
1506
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1447,7 +1518,8 @@ function MermaidBlock({ block, className }) {
|
|
|
1447
1518
|
"data-ncm-mermaid": "",
|
|
1448
1519
|
"data-ncm-diagram-type": block.diagramType,
|
|
1449
1520
|
className: cn(
|
|
1450
|
-
|
|
1521
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1522
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1451
1523
|
className
|
|
1452
1524
|
),
|
|
1453
1525
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1508,7 +1580,7 @@ function TableBlock({ block, className }) {
|
|
|
1508
1580
|
"data-ncm-type": block.type,
|
|
1509
1581
|
"data-block-id": block.id,
|
|
1510
1582
|
"data-ncm-table": "",
|
|
1511
|
-
className: cn("w-full overflow-x-auto", className),
|
|
1583
|
+
className: cn("w-full overflow-x-auto overflow-y-hidden", className),
|
|
1512
1584
|
children: /* @__PURE__ */ jsxs("table", { role: "table", "data-ncm-table-element": "", children: [
|
|
1513
1585
|
/* @__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)) }) }),
|
|
1514
1586
|
/* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, rowIndex) => {
|
|
@@ -1594,7 +1666,7 @@ function FallbackBlock({ block, className }) {
|
|
|
1594
1666
|
"data-block-id": block.id,
|
|
1595
1667
|
"data-ncm-fallback": "",
|
|
1596
1668
|
className: cn(
|
|
1597
|
-
"overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1669
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1598
1670
|
className
|
|
1599
1671
|
)
|
|
1600
1672
|
},
|
|
@@ -1650,7 +1722,7 @@ function CustomCodeBlock({ block, className }) {
|
|
|
1650
1722
|
"data-block-id": block.id,
|
|
1651
1723
|
"data-ncm-custom-code": "",
|
|
1652
1724
|
"data-ncm-language": block.language,
|
|
1653
|
-
className: cn("overflow-x-auto", className),
|
|
1725
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1654
1726
|
children: [
|
|
1655
1727
|
/* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
|
|
1656
1728
|
/* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
|
|
@@ -52,6 +52,52 @@ function tryParseInlineRef(input) {
|
|
|
52
52
|
}
|
|
53
53
|
return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
|
|
54
54
|
}
|
|
55
|
+
function runLength(input, index, char) {
|
|
56
|
+
let end = index;
|
|
57
|
+
while (end < input.length && input[end] === char) end++;
|
|
58
|
+
return end - index;
|
|
59
|
+
}
|
|
60
|
+
function tryParseEmphasis(input) {
|
|
61
|
+
const char = input[0];
|
|
62
|
+
if (char !== "*" && char !== "_") return null;
|
|
63
|
+
const open = Math.min(3, runLength(input, 0, char));
|
|
64
|
+
const need = open;
|
|
65
|
+
let i = open;
|
|
66
|
+
while (i < input.length) {
|
|
67
|
+
const ch = input[i];
|
|
68
|
+
if (ch === "`") {
|
|
69
|
+
const close = input.indexOf("`", i + 1);
|
|
70
|
+
if (close === -1) break;
|
|
71
|
+
i = close + 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (ch !== char) {
|
|
75
|
+
i++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const run = runLength(input, i, char);
|
|
79
|
+
const closes = need === 1 ? run % 2 === 1 : run >= need;
|
|
80
|
+
if (!closes) {
|
|
81
|
+
i += run;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const extra = run - need;
|
|
85
|
+
const inner = input.slice(open, i + extra);
|
|
86
|
+
if (inner.length === 0) return null;
|
|
87
|
+
const length = i + run;
|
|
88
|
+
const children = parseInline(inner);
|
|
89
|
+
let token;
|
|
90
|
+
if (need === 3) {
|
|
91
|
+
token = { type: "bold", children: [{ type: "italic", children }] };
|
|
92
|
+
} else if (need === 2) {
|
|
93
|
+
token = { type: "bold", children };
|
|
94
|
+
} else {
|
|
95
|
+
token = { type: "italic", children };
|
|
96
|
+
}
|
|
97
|
+
return { token, length };
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
55
101
|
function parseInline(content) {
|
|
56
102
|
if (!content) return [];
|
|
57
103
|
const tokens = [];
|
|
@@ -123,17 +169,11 @@ function parseInline(content) {
|
|
|
123
169
|
remaining = remaining.slice(linkMatch[0].length);
|
|
124
170
|
continue;
|
|
125
171
|
}
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
type: "bold",
|
|
132
|
-
children: parseInline(innerContent)
|
|
133
|
-
});
|
|
134
|
-
remaining = remaining.slice(boldMatch[0].length);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
172
|
+
const emphasis = tryParseEmphasis(remaining);
|
|
173
|
+
if (emphasis) {
|
|
174
|
+
tokens.push(emphasis.token);
|
|
175
|
+
remaining = remaining.slice(emphasis.length);
|
|
176
|
+
continue;
|
|
137
177
|
}
|
|
138
178
|
const strikeMatch = remaining.match(/^~~(.+?)~~/);
|
|
139
179
|
if (strikeMatch && strikeMatch[1] !== void 0) {
|
|
@@ -144,18 +184,6 @@ function parseInline(content) {
|
|
|
144
184
|
remaining = remaining.slice(strikeMatch[0].length);
|
|
145
185
|
continue;
|
|
146
186
|
}
|
|
147
|
-
const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
|
|
148
|
-
if (italicMatch) {
|
|
149
|
-
const innerContent = italicMatch[1] ?? italicMatch[2];
|
|
150
|
-
if (innerContent !== void 0) {
|
|
151
|
-
tokens.push({
|
|
152
|
-
type: "italic",
|
|
153
|
-
children: parseInline(innerContent)
|
|
154
|
-
});
|
|
155
|
-
remaining = remaining.slice(italicMatch[0].length);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
187
|
const nextSpecial = findNextSpecialChar(remaining);
|
|
160
188
|
if (nextSpecial > 0) {
|
|
161
189
|
tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
|
|
@@ -262,17 +290,30 @@ function ReferenceMarker({ kind, number, children }) {
|
|
|
262
290
|
}
|
|
263
291
|
);
|
|
264
292
|
}
|
|
265
|
-
|
|
293
|
+
function normalizeReferenceContent(content) {
|
|
294
|
+
return content.replace(/\s+/g, " ").trim().toLowerCase();
|
|
295
|
+
}
|
|
296
|
+
var ReferenceNumberingContext = createContext(null);
|
|
266
297
|
var BlockReferenceScopeContext = createContext(null);
|
|
267
|
-
function BlockReferenceScope({
|
|
268
|
-
const
|
|
269
|
-
const
|
|
298
|
+
function BlockReferenceScope({ children }) {
|
|
299
|
+
const numbering = useContext(ReferenceNumberingContext);
|
|
300
|
+
const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
|
|
270
301
|
const counter = useRef({ ref: 0, footnote: 0 });
|
|
271
|
-
counter.current = { ref: 0, footnote: 0 };
|
|
272
302
|
const value = {
|
|
303
|
+
numberFor(kind, content) {
|
|
304
|
+
const key = normalizeReferenceContent(content);
|
|
305
|
+
const fromDocument = numbering?.[kind].get(key);
|
|
306
|
+
if (fromDocument !== void 0) return fromDocument;
|
|
307
|
+
const map = local.current[kind];
|
|
308
|
+
const existing = map.get(key);
|
|
309
|
+
if (existing !== void 0) return existing;
|
|
310
|
+
counter.current[kind] += 1;
|
|
311
|
+
map.set(key, counter.current[kind]);
|
|
312
|
+
return counter.current[kind];
|
|
313
|
+
},
|
|
273
314
|
next(kind) {
|
|
274
315
|
counter.current[kind] += 1;
|
|
275
|
-
return
|
|
316
|
+
return counter.current[kind];
|
|
276
317
|
}
|
|
277
318
|
};
|
|
278
319
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
|
|
@@ -280,7 +321,7 @@ function BlockReferenceScope({ blockId, children }) {
|
|
|
280
321
|
function useBlockReferenceScope() {
|
|
281
322
|
return useContext(BlockReferenceScopeContext);
|
|
282
323
|
}
|
|
283
|
-
var INERT_SCOPE = { next: () => 0 };
|
|
324
|
+
var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
|
|
284
325
|
function InertReferenceScope({ children }) {
|
|
285
326
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
|
|
286
327
|
}
|
|
@@ -571,7 +612,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
571
612
|
);
|
|
572
613
|
}
|
|
573
614
|
case "inline_ref": {
|
|
574
|
-
const number = refScope?.
|
|
615
|
+
const number = refScope?.numberFor(token.kind, token.content) ?? 0;
|
|
575
616
|
return /* @__PURE__ */ jsx(ReferenceMarker, { kind: token.kind, number, children: token.content ? /* @__PURE__ */ jsx(InertReferenceScope, { children: /* @__PURE__ */ jsx(InlineContent, { content: token.content, disableBionic: true, disableBeeline: true }) }) : null });
|
|
576
617
|
}
|
|
577
618
|
default:
|