@seanyeh77/ui 0.30.1 → 0.32.0
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/bundle.js +17 -17
- package/dist/bundle.js.map +1 -1
- package/dist/{format-entry-ePskyytj.js → format-entry-B9oxzJvw.js} +6 -1
- package/dist/format-entry-B9oxzJvw.js.map +1 -0
- package/dist/format.js +1 -1
- package/dist/index.d.ts +61 -6
- package/dist/index.js +456 -193
- package/dist/index.js.map +1 -1
- package/dist/styles.css +151 -11
- package/docs/CodeView.md +39 -2
- package/docs/Markdown.md +18 -0
- package/docs/Term.md +27 -0
- package/docs/Workbench.md +9 -5
- package/docs/guidelines.md +6 -3
- package/package.json +2 -2
- package/dist/format-entry-ePskyytj.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-
|
|
2
|
+
import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-B9oxzJvw.js";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
|
|
6
6
|
import { Dialog as Dialog$1 } from "@base-ui/react/dialog";
|
|
7
7
|
import { Menu as Menu$1 } from "@base-ui/react/menu";
|
|
8
8
|
import { PreviewCard } from "@base-ui/react/preview-card";
|
|
9
|
-
import { createPortal } from "react-dom";
|
|
10
9
|
import { Popover as Popover$1 } from "@base-ui/react/popover";
|
|
10
|
+
import { createPortal } from "react-dom";
|
|
11
11
|
import { Combobox } from "@base-ui/react/combobox";
|
|
12
12
|
import { Select as Select$1 } from "@base-ui/react/select";
|
|
13
13
|
// src/icons/data.ts
|
|
@@ -108,7 +108,8 @@ const PH = {
|
|
|
108
108
|
tag: "<path d=\"M243.31,136,144,36.69A15.86,15.86,0,0,0,132.69,32H40a8,8,0,0,0-8,8v92.69A15.86,15.86,0,0,0,36.69,144L136,243.31a16,16,0,0,0,22.63,0l84.68-84.68a16,16,0,0,0,0-22.63Zm-96,96L48,132.69V48h84.69L232,147.31ZM96,84A12,12,0,1,1,84,72,12,12,0,0,1,96,84Z\"/>",
|
|
109
109
|
"sort-ascending": "<path d=\"M128,128a8,8,0,0,1-8,8H48a8,8,0,0,1,0-16h72A8,8,0,0,1,128,128ZM48,72H184a8,8,0,0,0,0-16H48a8,8,0,0,0,0,16Zm56,112H48a8,8,0,0,0,0,16h56a8,8,0,0,0,0-16Zm125.66-21.66a8,8,0,0,0-11.32,0L192,188.69V112a8,8,0,0,0-16,0v76.69l-26.34-26.35a8,8,0,0,0-11.32,11.32l40,40a8,8,0,0,0,11.32,0l40-40A8,8,0,0,0,229.66,162.34Z\"/>",
|
|
110
110
|
"dots-six-vertical": "<path d=\"M104,60A12,12,0,1,1,92,48,12,12,0,0,1,104,60Zm60,12a12,12,0,1,0-12-12A12,12,0,0,0,164,72ZM92,116a12,12,0,1,0,12,12A12,12,0,0,0,92,116Zm72,0a12,12,0,1,0,12,12A12,12,0,0,0,164,116ZM92,184a12,12,0,1,0,12,12A12,12,0,0,0,92,184Zm72,0a12,12,0,1,0,12,12A12,12,0,0,0,164,184Z\"/>",
|
|
111
|
-
"push-pin": "<path d=\"M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z\"/>"
|
|
111
|
+
"push-pin": "<path d=\"M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z\"/>",
|
|
112
|
+
keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,144H32V64H224V192Zm-16-64a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,128Zm0-32a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,96ZM72,160a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16h8A8,8,0,0,1,72,160Zm96,0a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,160Zm40,0a8,8,0,0,1-8,8h-8a8,8,0,0,1,0-16h8A8,8,0,0,1,208,160Z\"/>"
|
|
112
113
|
};
|
|
113
114
|
const PH_FILL = {
|
|
114
115
|
archive: "<path d=\"M224,48H32A16,16,0,0,0,16,64V88a16,16,0,0,0,16,16v88a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm-72,96H104a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm72-56H32V64H224V88Z\"/>",
|
|
@@ -207,7 +208,8 @@ const PH_FILL = {
|
|
|
207
208
|
tag: "<path d=\"M243.31,136,144,36.69A15.86,15.86,0,0,0,132.69,32H40a8,8,0,0,0-8,8v92.69A15.86,15.86,0,0,0,36.69,144L136,243.31a16,16,0,0,0,22.63,0l84.68-84.68a16,16,0,0,0,0-22.63ZM84,96A12,12,0,1,1,96,84,12,12,0,0,1,84,96Z\"/>",
|
|
208
209
|
"sort-ascending": "<path d=\"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM72,72h96a8,8,0,0,1,0,16H72a8,8,0,0,1,0-16Zm40,112H72a8,8,0,0,1,0-16h40a8,8,0,0,1,0,16Zm8-48H72a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm77.66,29.66-24,24a8,8,0,0,1-11.32,0l-24-24a8,8,0,0,1,11.32-11.32L160,164.69V120a8,8,0,0,1,16,0v44.69l10.34-10.35a8,8,0,0,1,11.32,11.32Z\"/>",
|
|
209
210
|
"dots-six-vertical": "<path d=\"M192,16H64A16,16,0,0,0,48,32V224a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V32A16,16,0,0,0,192,16ZM100,200a12,12,0,1,1,12-12A12,12,0,0,1,100,200Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,100,140Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,100,80Zm56,120a12,12,0,1,1,12-12A12,12,0,0,1,156,200Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,156,140Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,156,80Z\"/>",
|
|
210
|
-
"push-pin": "<path d=\"M235.33,104l-53.47,53.65c4.56,12.67,6.45,33.89-13.19,60A15.93,15.93,0,0,1,157,224c-.38,0-.75,0-1.13,0a16,16,0,0,1-11.32-4.69L96.29,171,53.66,213.66a8,8,0,0,1-11.32-11.32L85,159.71l-48.3-48.3A16,16,0,0,1,38,87.63c25.42-20.51,49.75-16.48,60.4-13.14L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.33,104Z\"/>"
|
|
211
|
+
"push-pin": "<path d=\"M235.33,104l-53.47,53.65c4.56,12.67,6.45,33.89-13.19,60A15.93,15.93,0,0,1,157,224c-.38,0-.75,0-1.13,0a16,16,0,0,1-11.32-4.69L96.29,171,53.66,213.66a8,8,0,0,1-11.32-11.32L85,159.71l-48.3-48.3A16,16,0,0,1,38,87.63c25.42-20.51,49.75-16.48,60.4-13.14L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.33,104Z\"/>",
|
|
212
|
+
keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48ZM64,168H48a8,8,0,0,1,0-16H64a8,8,0,0,1,0,16Zm96,0H96a8,8,0,0,1,0-16h64a8,8,0,0,1,0,16Zm48,0H192a8,8,0,0,1,0-16h16a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Z\"/>"
|
|
211
213
|
};
|
|
212
214
|
/** Lucide names that map to a Phosphor icon. */
|
|
213
215
|
const PH_ALIAS = {
|
|
@@ -2263,6 +2265,222 @@ function CodeText({ text, refHref, onRef, isRef = isCodeRef, as: Tag = "span", c
|
|
|
2263
2265
|
})
|
|
2264
2266
|
});
|
|
2265
2267
|
}
|
|
2268
|
+
// src/internal/FloatingPanel.tsx
|
|
2269
|
+
/** A positioned panel next to its trigger: flips when there is no room, closes on Esc and outside press, returns focus. */
|
|
2270
|
+
function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, delay = 0, id, focusOnOpen = true, children, ...aria }) {
|
|
2271
|
+
const within = boundary?.current ?? void 0;
|
|
2272
|
+
return /* @__PURE__ */ jsxs(Popover$1.Root, {
|
|
2273
|
+
open,
|
|
2274
|
+
onOpenChange,
|
|
2275
|
+
children: [/* @__PURE__ */ jsx(Popover$1.Trigger, {
|
|
2276
|
+
render: trigger,
|
|
2277
|
+
openOnHover,
|
|
2278
|
+
delay,
|
|
2279
|
+
closeDelay: 150
|
|
2280
|
+
}), /* @__PURE__ */ jsx(Popover$1.Portal, { children: /* @__PURE__ */ jsx(Popover$1.Positioner, {
|
|
2281
|
+
className: "ui-float",
|
|
2282
|
+
side,
|
|
2283
|
+
align,
|
|
2284
|
+
sideOffset,
|
|
2285
|
+
anchor,
|
|
2286
|
+
collisionBoundary: within,
|
|
2287
|
+
collisionPadding: within ? 0 : void 0,
|
|
2288
|
+
collisionAvoidance: within ? {
|
|
2289
|
+
side: "flip",
|
|
2290
|
+
align: "shift"
|
|
2291
|
+
} : void 0,
|
|
2292
|
+
children: /* @__PURE__ */ jsx(Popover$1.Popup, {
|
|
2293
|
+
id,
|
|
2294
|
+
className,
|
|
2295
|
+
"aria-label": aria["aria-label"],
|
|
2296
|
+
initialFocus: focusOnOpen ? void 0 : false,
|
|
2297
|
+
children
|
|
2298
|
+
})
|
|
2299
|
+
}) })]
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
/** A word that opens its explanation: a floating card from 600 px, a sheet from the bottom on phones. `icon` adds a small
|
|
2303
|
+
* question mark; `inline` marks the word with a dashed underline and opens on hover or keyboard focus. */
|
|
2304
|
+
function Term({ children, title, text, content, code, action, refHref, onRef, isRef, variant = "icon", openOnFocus = true, tabIndex, className }) {
|
|
2305
|
+
const [open, setOpen] = React.useState(false);
|
|
2306
|
+
const narrow = useNarrow();
|
|
2307
|
+
const inlineV = variant === "inline";
|
|
2308
|
+
const cardId = React.useId();
|
|
2309
|
+
const ref = React.useRef(null);
|
|
2310
|
+
const [inline, setInline] = React.useState(false);
|
|
2311
|
+
React.useLayoutEffect(() => {
|
|
2312
|
+
const par = ref.current?.parentNode;
|
|
2313
|
+
const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
|
|
2314
|
+
setInline(txt);
|
|
2315
|
+
}, [children]);
|
|
2316
|
+
const block = React.useRef(null);
|
|
2317
|
+
const toggle = (next) => {
|
|
2318
|
+
if (next) {
|
|
2319
|
+
const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
|
|
2320
|
+
block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
|
|
2321
|
+
}
|
|
2322
|
+
setOpen(next);
|
|
2323
|
+
};
|
|
2324
|
+
const heading = title || (typeof children === "string" ? children : "");
|
|
2325
|
+
const onFocus = (e) => {
|
|
2326
|
+
if (openOnFocus && !narrow && e.currentTarget.matches(":focus-visible")) toggle(true);
|
|
2327
|
+
};
|
|
2328
|
+
const onBlur = (e) => {
|
|
2329
|
+
const to = e.relatedTarget;
|
|
2330
|
+
if (to && (ref.current?.contains(to) || document.getElementById(cardId)?.contains(to))) return;
|
|
2331
|
+
if (!narrow) setOpen(false);
|
|
2332
|
+
};
|
|
2333
|
+
const trigger = inlineV ? /* @__PURE__ */ jsxs("button", {
|
|
2334
|
+
type: "button",
|
|
2335
|
+
ref,
|
|
2336
|
+
className: cx("ui-term", "is-word", open && "is-open", className),
|
|
2337
|
+
tabIndex,
|
|
2338
|
+
"aria-describedby": open && !narrow ? cardId : void 0,
|
|
2339
|
+
onFocus,
|
|
2340
|
+
onBlur,
|
|
2341
|
+
children: [children, /* @__PURE__ */ jsx("span", {
|
|
2342
|
+
className: "ui-visually-hidden",
|
|
2343
|
+
children: tr(",有說明")
|
|
2344
|
+
})]
|
|
2345
|
+
}) : /* @__PURE__ */ jsxs("button", {
|
|
2346
|
+
type: "button",
|
|
2347
|
+
ref,
|
|
2348
|
+
className: cx("ui-term", inline && "is-inline", open && "is-open", className),
|
|
2349
|
+
children: [
|
|
2350
|
+
/* @__PURE__ */ jsx("span", {
|
|
2351
|
+
className: "ui-visually-hidden",
|
|
2352
|
+
children: tr("說明") + " "
|
|
2353
|
+
}),
|
|
2354
|
+
children,
|
|
2355
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
2356
|
+
name: "question",
|
|
2357
|
+
size: 14,
|
|
2358
|
+
className: "ui-term-q"
|
|
2359
|
+
})
|
|
2360
|
+
]
|
|
2361
|
+
});
|
|
2362
|
+
const body = (Title, Close) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2363
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2364
|
+
className: "ui-term-head",
|
|
2365
|
+
children: [/* @__PURE__ */ jsx(Title, {
|
|
2366
|
+
className: "ui-term-title",
|
|
2367
|
+
children: heading
|
|
2368
|
+
}), /* @__PURE__ */ jsx(Close, {
|
|
2369
|
+
className: "ui-dialog-close ui-term-close",
|
|
2370
|
+
"aria-label": tr("關閉說明"),
|
|
2371
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "x" })
|
|
2372
|
+
})]
|
|
2373
|
+
}),
|
|
2374
|
+
text ? /* @__PURE__ */ jsx(CodeText, {
|
|
2375
|
+
as: "div",
|
|
2376
|
+
className: "ui-term-body",
|
|
2377
|
+
text,
|
|
2378
|
+
refHref,
|
|
2379
|
+
onRef,
|
|
2380
|
+
isRef
|
|
2381
|
+
}) : null,
|
|
2382
|
+
content ? /* @__PURE__ */ jsx("div", {
|
|
2383
|
+
className: "ui-term-body",
|
|
2384
|
+
children: content
|
|
2385
|
+
}) : null,
|
|
2386
|
+
code ? /* @__PURE__ */ jsx("pre", {
|
|
2387
|
+
className: "ui-term-code",
|
|
2388
|
+
children: code
|
|
2389
|
+
}) : null,
|
|
2390
|
+
action ? /* @__PURE__ */ jsx("button", {
|
|
2391
|
+
type: "button",
|
|
2392
|
+
className: "ui-link-btn ui-term-action",
|
|
2393
|
+
onClick: () => {
|
|
2394
|
+
setOpen(false);
|
|
2395
|
+
action.onClick?.();
|
|
2396
|
+
},
|
|
2397
|
+
children: action.label
|
|
2398
|
+
}) : null
|
|
2399
|
+
] });
|
|
2400
|
+
if (narrow) return /* @__PURE__ */ jsxs(Dialog$1.Root, {
|
|
2401
|
+
open,
|
|
2402
|
+
onOpenChange: setOpen,
|
|
2403
|
+
children: [/* @__PURE__ */ jsx(Dialog$1.Trigger, { render: trigger }), /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(Dialog$1.Backdrop, { className: "ui-term-backdrop" }), /* @__PURE__ */ jsx(Dialog$1.Popup, {
|
|
2404
|
+
className: "ui-term-sheet",
|
|
2405
|
+
children: body(Dialog$1.Title, Dialog$1.Close)
|
|
2406
|
+
})] })]
|
|
2407
|
+
});
|
|
2408
|
+
return /* @__PURE__ */ jsx(FloatingPanel, {
|
|
2409
|
+
open,
|
|
2410
|
+
onOpenChange: toggle,
|
|
2411
|
+
sideOffset: 8,
|
|
2412
|
+
className: "ui-term-pop",
|
|
2413
|
+
trigger,
|
|
2414
|
+
boundary: block,
|
|
2415
|
+
...inlineV ? {
|
|
2416
|
+
openOnHover: true,
|
|
2417
|
+
delay: 500,
|
|
2418
|
+
id: cardId,
|
|
2419
|
+
focusOnOpen: false
|
|
2420
|
+
} : {},
|
|
2421
|
+
children: inlineV ? /* @__PURE__ */ jsx("div", {
|
|
2422
|
+
onBlur,
|
|
2423
|
+
children: body(Popover$1.Title, Popover$1.Close)
|
|
2424
|
+
}) : body(Popover$1.Title, Popover$1.Close)
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2427
|
+
// src/internal/terms.tsx
|
|
2428
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2429
|
+
const WORDY = /^[\p{Script=Latin}\p{N}_]$/u;
|
|
2430
|
+
/** One pattern for all the words, longest first, so 「cookie jar」 wins over 「cookie」. */
|
|
2431
|
+
function termPattern(terms) {
|
|
2432
|
+
const list = (terms ?? []).filter((t) => t.term);
|
|
2433
|
+
if (!list.length) return null;
|
|
2434
|
+
const alts = [...list].sort((a, b) => b.term.length - a.term.length).map((t) => {
|
|
2435
|
+
const w = [...t.term];
|
|
2436
|
+
const pre = WORDY.test(w[0]) ? "(?<![\\p{Script=Latin}\\p{N}_])" : "";
|
|
2437
|
+
const post = WORDY.test(w[w.length - 1]) ? "(?![\\p{Script=Latin}\\p{N}_])" : "";
|
|
2438
|
+
return pre + esc(t.term) + post;
|
|
2439
|
+
});
|
|
2440
|
+
return new RegExp(alts.join("|"), "gu");
|
|
2441
|
+
}
|
|
2442
|
+
/** The words in a piece of text. `seen` holds the words already marked in this block; with `first` they are skipped
|
|
2443
|
+
* and the new ones added. */
|
|
2444
|
+
function findTerms(text, terms, re, mark, seen) {
|
|
2445
|
+
const out = [];
|
|
2446
|
+
for (const m of text.matchAll(re)) {
|
|
2447
|
+
const i = terms.findIndex((t) => t.term === m[0]);
|
|
2448
|
+
if (i < 0) continue;
|
|
2449
|
+
if (mark === "first") {
|
|
2450
|
+
if (seen.has(m[0])) continue;
|
|
2451
|
+
seen.add(m[0]);
|
|
2452
|
+
}
|
|
2453
|
+
out.push({
|
|
2454
|
+
from: m.index,
|
|
2455
|
+
to: m.index + m[0].length,
|
|
2456
|
+
i
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
return out;
|
|
2460
|
+
}
|
|
2461
|
+
/** The word as an inline Term. */
|
|
2462
|
+
function termNode(t, key, children, extra) {
|
|
2463
|
+
return /* @__PURE__ */ jsx(Term, {
|
|
2464
|
+
variant: "inline",
|
|
2465
|
+
title: t.title,
|
|
2466
|
+
text: t.text,
|
|
2467
|
+
action: t.action,
|
|
2468
|
+
...extra,
|
|
2469
|
+
children: children ?? t.term
|
|
2470
|
+
}, key);
|
|
2471
|
+
}
|
|
2472
|
+
/** Text with its words as inline Terms; `rest` renders the text between them. */
|
|
2473
|
+
function withTerms(text, hits, terms, key, rest = (s) => s, extra) {
|
|
2474
|
+
const out = [];
|
|
2475
|
+
let at = 0;
|
|
2476
|
+
for (const h of hits) {
|
|
2477
|
+
if (h.from > at) out.push(/* @__PURE__ */ jsx(React.Fragment, { children: rest(text.slice(at, h.from)) }, key()));
|
|
2478
|
+
out.push(termNode(terms[h.i], key(), text.slice(h.from, h.to), extra));
|
|
2479
|
+
at = h.to;
|
|
2480
|
+
}
|
|
2481
|
+
if (at < text.length) out.push(/* @__PURE__ */ jsx(React.Fragment, { children: rest(text.slice(at)) }, key()));
|
|
2482
|
+
return out;
|
|
2483
|
+
}
|
|
2266
2484
|
// src/components/CodeView/tokens.ts
|
|
2267
2485
|
const KEYWORDS = {
|
|
2268
2486
|
c: new Set("auto break case char const continue default do double else enum extern float for goto if inline int long register restrict return short signed sizeof static struct switch typedef union unsigned void volatile while bool true false NULL nullptr class namespace template typename public private protected virtual new delete".split(" ")),
|
|
@@ -2453,8 +2671,60 @@ function matchLinks(lines, start, links) {
|
|
|
2453
2671
|
for (const list of out.values()) list.sort((a, b) => a.from - b.from);
|
|
2454
2672
|
return out;
|
|
2455
2673
|
}
|
|
2674
|
+
/** Each line's words from `terms`: only in comments and strings, never where a name link or a path is. With 'first',
|
|
2675
|
+
* each word once per file, at its first place. */
|
|
2676
|
+
function matchTerms(toks, start, links, terms, mark) {
|
|
2677
|
+
const out = /* @__PURE__ */ new Map();
|
|
2678
|
+
const re = termPattern(terms);
|
|
2679
|
+
if (!re || !terms) return out;
|
|
2680
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2681
|
+
toks.forEach((line, i) => {
|
|
2682
|
+
const n = start + i;
|
|
2683
|
+
const taken = links.get(n) ?? [];
|
|
2684
|
+
let at = 0;
|
|
2685
|
+
for (const [cls, text] of line) {
|
|
2686
|
+
if (cls === "is-comment" || cls === "is-string") {
|
|
2687
|
+
const paths = [...text.matchAll(PATH_IN_CODE)].map((m) => ({
|
|
2688
|
+
from: at + m.index,
|
|
2689
|
+
to: at + m.index + m[0].length
|
|
2690
|
+
}));
|
|
2691
|
+
const free = (from, to) => ![...taken, ...paths].some((h) => h.from < to && from < h.to);
|
|
2692
|
+
const found = findTerms(text, terms, re, "all", /* @__PURE__ */ new Set()).map((w) => ({
|
|
2693
|
+
...w,
|
|
2694
|
+
from: w.from + at,
|
|
2695
|
+
to: w.to + at
|
|
2696
|
+
})).filter((w) => free(w.from, w.to)).filter((w) => {
|
|
2697
|
+
if (mark === "all") return true;
|
|
2698
|
+
const t = terms[w.i].term;
|
|
2699
|
+
if (seen.has(t)) return false;
|
|
2700
|
+
seen.add(t);
|
|
2701
|
+
return true;
|
|
2702
|
+
});
|
|
2703
|
+
if (found.length) out.set(n, [...out.get(n) ?? [], ...found]);
|
|
2704
|
+
}
|
|
2705
|
+
at += text.length;
|
|
2706
|
+
}
|
|
2707
|
+
});
|
|
2708
|
+
return out;
|
|
2709
|
+
}
|
|
2710
|
+
/** What the keys do: a small panel opened from the keyboard button or with ?; nothing on screen until asked. */
|
|
2711
|
+
function KeysPanel(p) {
|
|
2712
|
+
return /* @__PURE__ */ jsx(FloatingPanel, {
|
|
2713
|
+
open: p.open,
|
|
2714
|
+
onOpenChange: p.onOpenChange,
|
|
2715
|
+
trigger: p.trigger,
|
|
2716
|
+
side: "bottom",
|
|
2717
|
+
align: "end",
|
|
2718
|
+
className: "ui-popover ui-cv-keys",
|
|
2719
|
+
"aria-label": tr("鍵盤操作"),
|
|
2720
|
+
children: /* @__PURE__ */ jsxs("dl", {
|
|
2721
|
+
className: "ui-cv-keylist",
|
|
2722
|
+
children: [p.keys.map((k) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: /* @__PURE__ */ jsx("kbd", { children: k.label }) }), /* @__PURE__ */ jsx("dd", { children: k.what })] }, k.k)), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: /* @__PURE__ */ jsx("kbd", { children: "?" }) }), /* @__PURE__ */ jsx("dd", { children: tr("顯示或關閉這份說明") })] })]
|
|
2723
|
+
})
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2456
2726
|
/** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
|
|
2457
|
-
function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, links, onLink, preview, maxHeight, sections, copy, lineNumbers = true, onCopy, onCopyError, className, ref }) {
|
|
2727
|
+
function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, links, onLink, preview, terms, termsMark = "first", maxHeight, sections, copy, header = true, lineNumbers = true, onCopy, onCopyError, className, ref }) {
|
|
2458
2728
|
const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
|
|
2459
2729
|
const lang = language || languageOf(file);
|
|
2460
2730
|
const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
|
|
@@ -2468,7 +2738,14 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2468
2738
|
start,
|
|
2469
2739
|
links
|
|
2470
2740
|
]);
|
|
2471
|
-
const
|
|
2741
|
+
const termHits = React.useMemo(() => matchTerms(toks, start, hits, terms, termsMark), [
|
|
2742
|
+
toks,
|
|
2743
|
+
start,
|
|
2744
|
+
hits,
|
|
2745
|
+
terms,
|
|
2746
|
+
termsMark
|
|
2747
|
+
]);
|
|
2748
|
+
const nav = hits.size > 0 || termHits.size > 0;
|
|
2472
2749
|
const [armed, setArmed] = React.useState(false);
|
|
2473
2750
|
const inside = React.useRef(false);
|
|
2474
2751
|
React.useEffect(() => {
|
|
@@ -2556,10 +2833,24 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2556
2833
|
if (b && el && b.scrollHeight > b.clientHeight) b.scrollTop += el.getBoundingClientRect().top - b.getBoundingClientRect().top - b.clientHeight / 2 + el.offsetHeight / 2;
|
|
2557
2834
|
}, [ta, code]);
|
|
2558
2835
|
const digits = String(start + lines.length - 1).length;
|
|
2559
|
-
const
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2836
|
+
const prose = (cls, text, inLink) => !inLink && (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef, nav ? -1 : void 0) : breakable(text);
|
|
2837
|
+
const piece = (cls, text, key, inLink, at = 0, words) => {
|
|
2838
|
+
const mine = !inLink && terms && words ? words.filter((w) => w.from >= at && w.to <= at + text.length) : [];
|
|
2839
|
+
let k = 0;
|
|
2840
|
+
const kids = mine.length && terms ? withTerms(text, mine.map((w) => ({
|
|
2841
|
+
...w,
|
|
2842
|
+
from: w.from - at,
|
|
2843
|
+
to: w.to - at
|
|
2844
|
+
})), terms, () => key + "t" + k++, (t) => prose(cls, t, false), {
|
|
2845
|
+
className: "ui-cv-term",
|
|
2846
|
+
tabIndex: -1,
|
|
2847
|
+
openOnFocus: false
|
|
2848
|
+
}) : prose(cls, text, inLink);
|
|
2849
|
+
return cls ? /* @__PURE__ */ jsx("span", {
|
|
2850
|
+
className: cls,
|
|
2851
|
+
children: kids
|
|
2852
|
+
}, key) : /* @__PURE__ */ jsx(React.Fragment, { children: kids }, key);
|
|
2853
|
+
};
|
|
2563
2854
|
const nameLink = (hit, kids) => {
|
|
2564
2855
|
const link = links?.[hit.i];
|
|
2565
2856
|
if (!link) return null;
|
|
@@ -2576,8 +2867,15 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2576
2867
|
children: kids
|
|
2577
2868
|
}, "n" + hit.i);
|
|
2578
2869
|
};
|
|
2579
|
-
const lineContent = (line, lineHits) => {
|
|
2580
|
-
if (!lineHits)
|
|
2870
|
+
const lineContent = (line, lineHits, words) => {
|
|
2871
|
+
if (!lineHits) {
|
|
2872
|
+
let at = 0;
|
|
2873
|
+
return line.map(([cls, text], j) => {
|
|
2874
|
+
const el = piece(cls, text, String(j), false, at, words);
|
|
2875
|
+
at += text.length;
|
|
2876
|
+
return el;
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2581
2879
|
const out = [];
|
|
2582
2880
|
let group = [];
|
|
2583
2881
|
let open = null;
|
|
@@ -2605,7 +2903,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2605
2903
|
group.push(piece(cls, text.slice(k, end - pos), key, true));
|
|
2606
2904
|
} else {
|
|
2607
2905
|
flush();
|
|
2608
|
-
out.push(piece(cls, text.slice(k, end - pos), key, false));
|
|
2906
|
+
out.push(piece(cls, text.slice(k, end - pos), key, false, at, words));
|
|
2609
2907
|
}
|
|
2610
2908
|
k = end - pos;
|
|
2611
2909
|
}
|
|
@@ -2634,7 +2932,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2634
2932
|
children: [/* @__PURE__ */ jsx("span", {
|
|
2635
2933
|
className: "ui-visually-hidden ui-cv-sr",
|
|
2636
2934
|
children: tr("第 {n} 行", { n }) + indentText(lines[i]) + tr(":")
|
|
2637
|
-
}), lineContent(toks[i], hits.get(n))]
|
|
2935
|
+
}), lineContent(toks[i], hits.get(n), termHits.get(n))]
|
|
2638
2936
|
})]
|
|
2639
2937
|
}, i));
|
|
2640
2938
|
}
|
|
@@ -2648,7 +2946,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2648
2946
|
{
|
|
2649
2947
|
k: "ArrowLeft ArrowRight",
|
|
2650
2948
|
label: "←→",
|
|
2651
|
-
what: tr("上一個/下一個連結")
|
|
2949
|
+
what: tr(!termHits.size ? "上一個/下一個連結" : hits.size ? "上一個/下一個連結或名詞" : "上一個/下一個名詞")
|
|
2652
2950
|
},
|
|
2653
2951
|
{
|
|
2654
2952
|
k: "Enter",
|
|
@@ -2693,6 +2991,12 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2693
2991
|
];
|
|
2694
2992
|
const onMove = (e) => {
|
|
2695
2993
|
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
|
2994
|
+
if (e.key === "?") {
|
|
2995
|
+
e.preventDefault();
|
|
2996
|
+
byKey.current = true;
|
|
2997
|
+
setKeysOpen((o) => !o);
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
2696
3000
|
const pre = e.currentTarget;
|
|
2697
3001
|
const items = [...pre.querySelectorAll("[role=\"listitem\"]")];
|
|
2698
3002
|
if (!items.length) return;
|
|
@@ -2707,9 +3011,10 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2707
3011
|
el.focus();
|
|
2708
3012
|
};
|
|
2709
3013
|
if (nav) {
|
|
2710
|
-
const stops = [...pre.querySelectorAll(".ui-cv-name, .ui-cv-ref")];
|
|
3014
|
+
const stops = [...pre.querySelectorAll(".ui-cv-name, .ui-cv-ref, .ui-cv-term")];
|
|
2711
3015
|
const onStop = act ? stops.indexOf(act) : -1;
|
|
2712
3016
|
if (e.key === "Escape") {
|
|
3017
|
+
if (act?.classList.contains("ui-cv-term") && act.getAttribute("aria-expanded") === "true") return;
|
|
2713
3018
|
if (pv) setPv(null);
|
|
2714
3019
|
else if (onStop >= 0) focusLine(curLine ?? void 0);
|
|
2715
3020
|
else if (curLine) pre.focus();
|
|
@@ -2768,6 +3073,8 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2768
3073
|
}));
|
|
2769
3074
|
};
|
|
2770
3075
|
const [copied, setCopied] = React.useState(false);
|
|
3076
|
+
const [keysOpen, setKeysOpen] = React.useState(false);
|
|
3077
|
+
const byKey = React.useRef(false);
|
|
2771
3078
|
const copyTimer = React.useRef(void 0);
|
|
2772
3079
|
React.useEffect(() => () => clearTimeout(copyTimer.current), []);
|
|
2773
3080
|
const doCopy = () => {
|
|
@@ -2779,7 +3086,50 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2779
3086
|
onCopy?.(code);
|
|
2780
3087
|
}, () => onCopyError?.());
|
|
2781
3088
|
};
|
|
2782
|
-
const
|
|
3089
|
+
const langText = languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
|
|
3090
|
+
className: "ui-cv-lang",
|
|
3091
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3092
|
+
className: "ui-visually-hidden",
|
|
3093
|
+
children: tr("程式語言") + tr(":")
|
|
3094
|
+
}), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
|
|
3095
|
+
}) : null;
|
|
3096
|
+
const copyBtn = copy ? /* @__PURE__ */ jsx(IconButton, {
|
|
3097
|
+
className: cx("ui-cv-copy", copied && "is-copied"),
|
|
3098
|
+
variant: header === "float" ? "quiet" : void 0,
|
|
3099
|
+
label: copied ? tr("已複製") : tr("複製程式碼"),
|
|
3100
|
+
icon: copied ? CHECK : "copy",
|
|
3101
|
+
onClick: doCopy
|
|
3102
|
+
}) : null;
|
|
3103
|
+
const onKeysChange = (o) => {
|
|
3104
|
+
setKeysOpen(o);
|
|
3105
|
+
if (!o && byKey.current) {
|
|
3106
|
+
byKey.current = false;
|
|
3107
|
+
requestAnimationFrame(() => body.current?.focus());
|
|
3108
|
+
}
|
|
3109
|
+
};
|
|
3110
|
+
const keysPanel = (trigger) => /* @__PURE__ */ jsx(KeysPanel, {
|
|
3111
|
+
open: keysOpen,
|
|
3112
|
+
onOpenChange: onKeysChange,
|
|
3113
|
+
trigger,
|
|
3114
|
+
keys
|
|
3115
|
+
});
|
|
3116
|
+
const keysBtn = keysPanel(/* @__PURE__ */ jsx(IconButton, {
|
|
3117
|
+
variant: "quiet",
|
|
3118
|
+
icon: "keyboard",
|
|
3119
|
+
label: tr("鍵盤操作"),
|
|
3120
|
+
onClick: () => byKey.current = false
|
|
3121
|
+
}));
|
|
3122
|
+
const head = header === "float" ? /* @__PURE__ */ jsxs("div", {
|
|
3123
|
+
className: "ui-cv-tools",
|
|
3124
|
+
children: [
|
|
3125
|
+
langText,
|
|
3126
|
+
copyBtn,
|
|
3127
|
+
keysBtn
|
|
3128
|
+
]
|
|
3129
|
+
}) : header === false ? keysPanel(/* @__PURE__ */ jsx("span", {
|
|
3130
|
+
className: "ui-cv-keyanchor",
|
|
3131
|
+
"aria-hidden": "true"
|
|
3132
|
+
})) : file || title || copy ? /* @__PURE__ */ jsxs("div", {
|
|
2783
3133
|
className: "ui-cv-head",
|
|
2784
3134
|
children: [
|
|
2785
3135
|
file ? fileHref || onFile ? /* @__PURE__ */ jsx(InlineCode, {
|
|
@@ -2794,23 +3144,16 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2794
3144
|
className: "ui-cv-title",
|
|
2795
3145
|
children: title
|
|
2796
3146
|
}) : null,
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
className: "ui-visually-hidden",
|
|
2801
|
-
children: tr("程式語言") + tr(":")
|
|
2802
|
-
}), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
|
|
2803
|
-
}) : null,
|
|
2804
|
-
copy ? /* @__PURE__ */ jsx(IconButton, {
|
|
2805
|
-
className: cx("ui-cv-copy", copied && "is-copied"),
|
|
2806
|
-
label: copied ? tr("已複製") : tr("複製程式碼"),
|
|
2807
|
-
icon: copied ? CHECK : "copy",
|
|
2808
|
-
onClick: doCopy
|
|
2809
|
-
}) : null
|
|
3147
|
+
langText,
|
|
3148
|
+
copyBtn,
|
|
3149
|
+
keysBtn
|
|
2810
3150
|
]
|
|
2811
|
-
}) :
|
|
3151
|
+
}) : keysPanel(/* @__PURE__ */ jsx("span", {
|
|
3152
|
+
className: "ui-cv-keyanchor",
|
|
3153
|
+
"aria-hidden": "true"
|
|
3154
|
+
}));
|
|
2812
3155
|
return /* @__PURE__ */ jsxs("div", {
|
|
2813
|
-
className: cx("ui-cv", !lineNumbers && "no-nums", className),
|
|
3156
|
+
className: cx("ui-cv", !lineNumbers && "no-nums", header === "float" && "is-float", className),
|
|
2814
3157
|
role: "region",
|
|
2815
3158
|
"aria-label": file || title || tr("原始碼"),
|
|
2816
3159
|
children: [
|
|
@@ -2820,7 +3163,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2820
3163
|
style: maxHeight ? { maxHeight } : void 0,
|
|
2821
3164
|
tabIndex: 0,
|
|
2822
3165
|
"aria-label": tr("程式碼"),
|
|
2823
|
-
"aria-keyshortcuts": keys.map((k) => k.k).join(" "),
|
|
3166
|
+
"aria-keyshortcuts": [...keys.map((k) => k.k), "?"].join(" "),
|
|
2824
3167
|
onKeyDown: onMove,
|
|
2825
3168
|
...nav ? {
|
|
2826
3169
|
onClick: onLinkClick,
|
|
@@ -2873,11 +3216,6 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2873
3216
|
})
|
|
2874
3217
|
}) })
|
|
2875
3218
|
}) : null,
|
|
2876
|
-
/* @__PURE__ */ jsx("div", {
|
|
2877
|
-
className: "ui-cv-keys",
|
|
2878
|
-
"aria-hidden": "true",
|
|
2879
|
-
children: keys.map((k) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("kbd", { children: k.label }), k.what] }, k.k))
|
|
2880
|
-
}),
|
|
2881
3219
|
narrow && canWindow ? /* @__PURE__ */ jsx("button", {
|
|
2882
3220
|
type: "button",
|
|
2883
3221
|
className: "ui-link-btn ui-cv-more",
|
|
@@ -3578,38 +3916,6 @@ function writeSort(prefix, levels, initial) {
|
|
|
3578
3916
|
const s = sp.toString();
|
|
3579
3917
|
history.replaceState(history.state, "", location.pathname + (s ? "?" + s : "") + location.hash);
|
|
3580
3918
|
}
|
|
3581
|
-
// src/internal/FloatingPanel.tsx
|
|
3582
|
-
/** A positioned panel next to its trigger: flips when there is no room, closes on Esc and outside press, returns focus. */
|
|
3583
|
-
function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, children, ...aria }) {
|
|
3584
|
-
const within = boundary?.current ?? void 0;
|
|
3585
|
-
return /* @__PURE__ */ jsxs(Popover$1.Root, {
|
|
3586
|
-
open,
|
|
3587
|
-
onOpenChange,
|
|
3588
|
-
children: [/* @__PURE__ */ jsx(Popover$1.Trigger, {
|
|
3589
|
-
render: trigger,
|
|
3590
|
-
openOnHover,
|
|
3591
|
-
delay: 0,
|
|
3592
|
-
closeDelay: 150
|
|
3593
|
-
}), /* @__PURE__ */ jsx(Popover$1.Portal, { children: /* @__PURE__ */ jsx(Popover$1.Positioner, {
|
|
3594
|
-
className: "ui-float",
|
|
3595
|
-
side,
|
|
3596
|
-
align,
|
|
3597
|
-
sideOffset,
|
|
3598
|
-
anchor,
|
|
3599
|
-
collisionBoundary: within,
|
|
3600
|
-
collisionPadding: within ? 0 : void 0,
|
|
3601
|
-
collisionAvoidance: within ? {
|
|
3602
|
-
side: "flip",
|
|
3603
|
-
align: "shift"
|
|
3604
|
-
} : void 0,
|
|
3605
|
-
children: /* @__PURE__ */ jsx(Popover$1.Popup, {
|
|
3606
|
-
className,
|
|
3607
|
-
"aria-label": aria["aria-label"],
|
|
3608
|
-
children
|
|
3609
|
-
})
|
|
3610
|
-
}) })]
|
|
3611
|
-
});
|
|
3612
|
-
}
|
|
3613
3919
|
// src/components/DataTable/parts.tsx
|
|
3614
3920
|
/** Marks the first match of q in text. */
|
|
3615
3921
|
function markMatch(text, q) {
|
|
@@ -5505,100 +5811,6 @@ function FormGrid({ children, className }) {
|
|
|
5505
5811
|
children
|
|
5506
5812
|
});
|
|
5507
5813
|
}
|
|
5508
|
-
// src/components/Term/Term.tsx
|
|
5509
|
-
/** A word followed by a small question mark that opens its explanation: a floating card from 600 px, a sheet from the bottom on phones. */
|
|
5510
|
-
function Term({ children, title, text, content, code, action, refHref, onRef, isRef, className }) {
|
|
5511
|
-
const [open, setOpen] = React.useState(false);
|
|
5512
|
-
const narrow = useNarrow();
|
|
5513
|
-
const ref = React.useRef(null);
|
|
5514
|
-
const [inline, setInline] = React.useState(false);
|
|
5515
|
-
React.useLayoutEffect(() => {
|
|
5516
|
-
const par = ref.current?.parentNode;
|
|
5517
|
-
const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
|
|
5518
|
-
setInline(txt);
|
|
5519
|
-
}, [children]);
|
|
5520
|
-
const block = React.useRef(null);
|
|
5521
|
-
const toggle = (next) => {
|
|
5522
|
-
if (next) {
|
|
5523
|
-
const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
|
|
5524
|
-
block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
|
|
5525
|
-
}
|
|
5526
|
-
setOpen(next);
|
|
5527
|
-
};
|
|
5528
|
-
const heading = title || (typeof children === "string" ? children : "");
|
|
5529
|
-
const trigger = /* @__PURE__ */ jsxs("button", {
|
|
5530
|
-
type: "button",
|
|
5531
|
-
ref,
|
|
5532
|
-
className: cx("ui-term", inline && "is-inline", open && "is-open", className),
|
|
5533
|
-
children: [
|
|
5534
|
-
/* @__PURE__ */ jsx("span", {
|
|
5535
|
-
className: "ui-visually-hidden",
|
|
5536
|
-
children: tr("說明") + " "
|
|
5537
|
-
}),
|
|
5538
|
-
children,
|
|
5539
|
-
/* @__PURE__ */ jsx(Icon, {
|
|
5540
|
-
name: "question",
|
|
5541
|
-
size: 14,
|
|
5542
|
-
className: "ui-term-q"
|
|
5543
|
-
})
|
|
5544
|
-
]
|
|
5545
|
-
});
|
|
5546
|
-
const body = (Title, Close) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5547
|
-
/* @__PURE__ */ jsxs("div", {
|
|
5548
|
-
className: "ui-term-head",
|
|
5549
|
-
children: [/* @__PURE__ */ jsx(Title, {
|
|
5550
|
-
className: "ui-term-title",
|
|
5551
|
-
children: heading
|
|
5552
|
-
}), /* @__PURE__ */ jsx(Close, {
|
|
5553
|
-
className: "ui-dialog-close ui-term-close",
|
|
5554
|
-
"aria-label": tr("關閉說明"),
|
|
5555
|
-
children: /* @__PURE__ */ jsx(Icon, { name: "x" })
|
|
5556
|
-
})]
|
|
5557
|
-
}),
|
|
5558
|
-
text ? /* @__PURE__ */ jsx(CodeText, {
|
|
5559
|
-
as: "div",
|
|
5560
|
-
className: "ui-term-body",
|
|
5561
|
-
text,
|
|
5562
|
-
refHref,
|
|
5563
|
-
onRef,
|
|
5564
|
-
isRef
|
|
5565
|
-
}) : null,
|
|
5566
|
-
content ? /* @__PURE__ */ jsx("div", {
|
|
5567
|
-
className: "ui-term-body",
|
|
5568
|
-
children: content
|
|
5569
|
-
}) : null,
|
|
5570
|
-
code ? /* @__PURE__ */ jsx("pre", {
|
|
5571
|
-
className: "ui-term-code",
|
|
5572
|
-
children: code
|
|
5573
|
-
}) : null,
|
|
5574
|
-
action ? /* @__PURE__ */ jsx("button", {
|
|
5575
|
-
type: "button",
|
|
5576
|
-
className: "ui-link-btn ui-term-action",
|
|
5577
|
-
onClick: () => {
|
|
5578
|
-
setOpen(false);
|
|
5579
|
-
action.onClick?.();
|
|
5580
|
-
},
|
|
5581
|
-
children: action.label
|
|
5582
|
-
}) : null
|
|
5583
|
-
] });
|
|
5584
|
-
if (narrow) return /* @__PURE__ */ jsxs(Dialog$1.Root, {
|
|
5585
|
-
open,
|
|
5586
|
-
onOpenChange: setOpen,
|
|
5587
|
-
children: [/* @__PURE__ */ jsx(Dialog$1.Trigger, { render: trigger }), /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(Dialog$1.Backdrop, { className: "ui-term-backdrop" }), /* @__PURE__ */ jsx(Dialog$1.Popup, {
|
|
5588
|
-
className: "ui-term-sheet",
|
|
5589
|
-
children: body(Dialog$1.Title, Dialog$1.Close)
|
|
5590
|
-
})] })]
|
|
5591
|
-
});
|
|
5592
|
-
return /* @__PURE__ */ jsx(FloatingPanel, {
|
|
5593
|
-
open,
|
|
5594
|
-
onOpenChange: toggle,
|
|
5595
|
-
sideOffset: 8,
|
|
5596
|
-
className: "ui-term-pop",
|
|
5597
|
-
trigger,
|
|
5598
|
-
boundary: block,
|
|
5599
|
-
children: body(Popover$1.Title, Popover$1.Close)
|
|
5600
|
-
});
|
|
5601
|
-
}
|
|
5602
5814
|
// src/components/Graph/Graph.tsx
|
|
5603
5815
|
/** <defs> with the arrowheads #ui-arrow and #ui-arrow-accent; put it first inside your diagram's <svg>. */
|
|
5604
5816
|
function GraphDefs() {
|
|
@@ -5913,13 +6125,24 @@ const BLOCKED = [
|
|
|
5913
6125
|
"data",
|
|
5914
6126
|
"vbscript"
|
|
5915
6127
|
];
|
|
6128
|
+
/** A new block: its own count of marked words. */
|
|
6129
|
+
const block = (c) => ({
|
|
6130
|
+
...c,
|
|
6131
|
+
seen: /* @__PURE__ */ new Set()
|
|
6132
|
+
});
|
|
6133
|
+
/** No words marked inside (headings, link text, a summary button). */
|
|
6134
|
+
const noTerms = (c) => ({
|
|
6135
|
+
...c,
|
|
6136
|
+
seen: void 0
|
|
6137
|
+
});
|
|
5916
6138
|
const CJK = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\u3000-\u303f\uff00-\uffef]/u;
|
|
5917
6139
|
/** Inline Markdown: code spans, links, autolinks, bold, italic, hard breaks; HTML tags dropped, their text kept. */
|
|
5918
6140
|
function inline(src, c) {
|
|
5919
6141
|
const out = [];
|
|
5920
6142
|
let text = "";
|
|
5921
6143
|
const flush = () => {
|
|
5922
|
-
if (text) out.push(text);
|
|
6144
|
+
if (text && c.termRe && c.terms && c.seen) out.push(...withTerms(text, findTerms(text, c.terms, c.termRe, c.termsMark, c.seen), c.terms, c.k));
|
|
6145
|
+
else if (text) out.push(text);
|
|
5923
6146
|
text = "";
|
|
5924
6147
|
};
|
|
5925
6148
|
let i = 0;
|
|
@@ -5997,8 +6220,21 @@ function inline(src, c) {
|
|
|
5997
6220
|
continue;
|
|
5998
6221
|
}
|
|
5999
6222
|
flush();
|
|
6223
|
+
const termId = /^term:(.*)$/i.exec(m.href.trim())?.[1];
|
|
6224
|
+
if (termId !== void 0) {
|
|
6225
|
+
let id = termId;
|
|
6226
|
+
try {
|
|
6227
|
+
id = decodeURIComponent(termId);
|
|
6228
|
+
} catch {}
|
|
6229
|
+
const t = c.terms?.find((x) => x.term === id);
|
|
6230
|
+
devWarn(!t, "Markdown", `[${m.text}](term:${termId}) 找不到 terms 裡 term 為「${id}」的項目,只顯示文字。把它加進 terms,或改 term: 後面的字。`);
|
|
6231
|
+
c.seen?.add(id);
|
|
6232
|
+
out.push(t ? termNode(t, c.k(), inline(m.text, noTerms(c))) : /* @__PURE__ */ jsx(React.Fragment, { children: inline(m.text, noTerms(c)) }, c.k()));
|
|
6233
|
+
i = m.end;
|
|
6234
|
+
continue;
|
|
6235
|
+
}
|
|
6000
6236
|
const name = /^\s*`([^`]+)`\s*$/.exec(m.text)?.[1];
|
|
6001
|
-
out.push(link(m.href, inline(m.text, c), c, name));
|
|
6237
|
+
out.push(link(m.href, inline(m.text, noTerms(c)), c, name));
|
|
6002
6238
|
i = m.end;
|
|
6003
6239
|
continue;
|
|
6004
6240
|
}
|
|
@@ -6154,19 +6390,24 @@ const NUM = /^[-+]?(?:NT\$\s?)?[\d,]+(?:\.\d+)?\s?(?:%|[A-Za-z]{1,3}|\p{Script=H
|
|
|
6154
6390
|
* tags are dropped and their text kept; links only to http, https, mailto and relative addresses. */
|
|
6155
6391
|
function Markdown(p) {
|
|
6156
6392
|
let n = 0;
|
|
6393
|
+
const termsMark = p.termsMark ?? "first";
|
|
6394
|
+
const termRe = React.useMemo(() => termPattern(p.terms), [p.terms]);
|
|
6157
6395
|
const c = {
|
|
6158
6396
|
k: () => "m" + n++,
|
|
6159
6397
|
schemes: p.schemes,
|
|
6160
6398
|
linkHref: p.linkHref,
|
|
6161
6399
|
onLink: p.onLink,
|
|
6162
6400
|
refHref: p.refHref,
|
|
6163
|
-
onRef: p.onRef
|
|
6401
|
+
onRef: p.onRef,
|
|
6402
|
+
terms: p.terms,
|
|
6403
|
+
termsMark,
|
|
6404
|
+
termRe
|
|
6164
6405
|
};
|
|
6165
6406
|
const src = String(p.children ?? "").replace(/\r\n?/g, "\n");
|
|
6166
6407
|
const cls = cx("ui-md", p.size === "small" && "is-small", p.className);
|
|
6167
6408
|
if (p.inline) return /* @__PURE__ */ jsx("span", {
|
|
6168
6409
|
className: cx(cls, "is-inline"),
|
|
6169
|
-
children: inline(src.trim().replace(/\n\s*\n/g, "\n"), c)
|
|
6410
|
+
children: inline(src.trim().replace(/\n\s*\n/g, "\n"), block(c))
|
|
6170
6411
|
});
|
|
6171
6412
|
const top = p.topLevel ?? 4;
|
|
6172
6413
|
const render = (blocks) => blocks.map((b) => {
|
|
@@ -6175,13 +6416,13 @@ function Markdown(p) {
|
|
|
6175
6416
|
const H = `h${Math.min(6, top + b.level - 1)}`;
|
|
6176
6417
|
return /* @__PURE__ */ jsx(H, {
|
|
6177
6418
|
className: "ui-md-h",
|
|
6178
|
-
children: inline(b.text, c)
|
|
6419
|
+
children: inline(b.text, noTerms(c))
|
|
6179
6420
|
}, c.k());
|
|
6180
6421
|
}
|
|
6181
|
-
case "p": return /* @__PURE__ */ jsx("p", { children: inline(b.text, c) }, c.k());
|
|
6422
|
+
case "p": return /* @__PURE__ */ jsx("p", { children: inline(b.text, block(c)) }, c.k());
|
|
6182
6423
|
case "hr": return /* @__PURE__ */ jsx("hr", {}, c.k());
|
|
6183
6424
|
case "details": return /* @__PURE__ */ jsx(MdDetails, {
|
|
6184
|
-
summary: inline(b.summary, c),
|
|
6425
|
+
summary: inline(b.summary, noTerms(c)),
|
|
6185
6426
|
children: render(b.blocks)
|
|
6186
6427
|
}, c.k());
|
|
6187
6428
|
case "alert": return /* @__PURE__ */ jsx(Alert, {
|
|
@@ -6191,7 +6432,7 @@ function Markdown(p) {
|
|
|
6191
6432
|
}, c.k());
|
|
6192
6433
|
case "quote": return /* @__PURE__ */ jsx("blockquote", { children: render(b.blocks) }, c.k());
|
|
6193
6434
|
case "list": {
|
|
6194
|
-
const items = b.items.map((it) => /* @__PURE__ */ jsx("li", { children: it.length === 1 && it[0].t === "p" ? inline(it[0].text, c) : render(it) }, c.k()));
|
|
6435
|
+
const items = b.items.map((it) => /* @__PURE__ */ jsx("li", { children: it.length === 1 && it[0].t === "p" ? inline(it[0].text, block(c)) : render(it) }, c.k()));
|
|
6195
6436
|
return b.ordered ? /* @__PURE__ */ jsx("ol", {
|
|
6196
6437
|
start: b.start === 1 ? void 0 : b.start,
|
|
6197
6438
|
children: items
|
|
@@ -6205,7 +6446,9 @@ function Markdown(p) {
|
|
|
6205
6446
|
copy: true,
|
|
6206
6447
|
lineNumbers: false,
|
|
6207
6448
|
refHref: p.refHref,
|
|
6208
|
-
onRef: p.onRef
|
|
6449
|
+
onRef: p.onRef,
|
|
6450
|
+
terms: p.terms,
|
|
6451
|
+
termsMark
|
|
6209
6452
|
}, c.k());
|
|
6210
6453
|
case "table": {
|
|
6211
6454
|
const n = b.head.length;
|
|
@@ -6216,9 +6459,9 @@ function Markdown(p) {
|
|
|
6216
6459
|
};
|
|
6217
6460
|
return /* @__PURE__ */ jsx(MdTable, {
|
|
6218
6461
|
label: b.head.map(plain).join("、"),
|
|
6219
|
-
heads: b.head.map((h) => inline(h, c)),
|
|
6462
|
+
heads: b.head.map((h) => inline(h, noTerms(c))),
|
|
6220
6463
|
headText: b.head.map(plain),
|
|
6221
|
-
rows: b.rows.map((r) => Array.from({ length: n }, (_, j) => inline(r[j] ?? "", c))),
|
|
6464
|
+
rows: b.rows.map((r) => Array.from({ length: n }, (_, j) => inline(r[j] ?? "", block(c)))),
|
|
6222
6465
|
numeric,
|
|
6223
6466
|
align
|
|
6224
6467
|
}, c.k());
|
|
@@ -10445,6 +10688,7 @@ function useWorkbench() {
|
|
|
10445
10688
|
return api;
|
|
10446
10689
|
}
|
|
10447
10690
|
const TOP = 48;
|
|
10691
|
+
const BAR = 36;
|
|
10448
10692
|
const LIM = {
|
|
10449
10693
|
explorer: [180, 480],
|
|
10450
10694
|
side: [240, 560],
|
|
@@ -11211,6 +11455,8 @@ function Workbench({ ref, ...p }) {
|
|
|
11211
11455
|
] });
|
|
11212
11456
|
};
|
|
11213
11457
|
const brand = p.brand;
|
|
11458
|
+
const hasBar = !!(p.crumbs?.length || p.mainBar);
|
|
11459
|
+
const filter = p.explorerFilter;
|
|
11214
11460
|
const brandInner = brand ? /* @__PURE__ */ jsxs(Fragment, { children: [brand.mark ? /* @__PURE__ */ jsx("span", {
|
|
11215
11461
|
className: "ui-wb-mark",
|
|
11216
11462
|
"aria-hidden": "true",
|
|
@@ -11264,22 +11510,15 @@ function Workbench({ ref, ...p }) {
|
|
|
11264
11510
|
className: "ui-wb-top",
|
|
11265
11511
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
11266
11512
|
className: "ui-wb-top-l",
|
|
11267
|
-
children: [
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
|
|
11275
|
-
|
|
11276
|
-
children: brandInner
|
|
11277
|
-
}) : null,
|
|
11278
|
-
p.crumbs?.length ? /* @__PURE__ */ jsx(Breadcrumb, {
|
|
11279
|
-
className: "ui-wb-crumbs",
|
|
11280
|
-
items: phone ? p.crumbs.slice(-1) : p.crumbs
|
|
11281
|
-
}) : null
|
|
11282
|
-
]
|
|
11513
|
+
children: [toggleBtn("explorer", exOpen, false), brand ? brand.href ? /* @__PURE__ */ jsx("a", {
|
|
11514
|
+
className: "ui-wb-brand",
|
|
11515
|
+
href: brand.href,
|
|
11516
|
+
"aria-label": phone ? brand.name : void 0,
|
|
11517
|
+
children: brandInner
|
|
11518
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
11519
|
+
className: "ui-wb-brand",
|
|
11520
|
+
children: brandInner
|
|
11521
|
+
}) : null]
|
|
11283
11522
|
}), /* @__PURE__ */ jsxs("div", {
|
|
11284
11523
|
className: "ui-wb-top-r",
|
|
11285
11524
|
children: [
|
|
@@ -11295,16 +11534,31 @@ function Workbench({ ref, ...p }) {
|
|
|
11295
11534
|
}), /* @__PURE__ */ jsxs("div", {
|
|
11296
11535
|
className: "ui-wb-body",
|
|
11297
11536
|
children: [
|
|
11537
|
+
hasBar ? /* @__PURE__ */ jsxs("div", {
|
|
11538
|
+
className: "ui-wb-mainbar",
|
|
11539
|
+
style: {
|
|
11540
|
+
left: mainL,
|
|
11541
|
+
right: mainR
|
|
11542
|
+
},
|
|
11543
|
+
children: [p.crumbs?.length ? /* @__PURE__ */ jsx(Breadcrumb, {
|
|
11544
|
+
className: "ui-wb-crumbs",
|
|
11545
|
+
items: p.crumbs
|
|
11546
|
+
}) : /* @__PURE__ */ jsx("span", { className: "ui-wb-mainbar-fill" }), p.mainBar ? /* @__PURE__ */ jsx("div", {
|
|
11547
|
+
className: "ui-wb-mainbar-btns",
|
|
11548
|
+
children: p.mainBar
|
|
11549
|
+
}) : null]
|
|
11550
|
+
}) : null,
|
|
11298
11551
|
/* @__PURE__ */ jsx("main", {
|
|
11299
11552
|
className: "ui-wb-main",
|
|
11300
11553
|
style: {
|
|
11301
11554
|
left: mainL,
|
|
11302
11555
|
right: mainR,
|
|
11303
|
-
bottom: mainB
|
|
11556
|
+
bottom: mainB,
|
|
11557
|
+
top: hasBar ? BAR : 0
|
|
11304
11558
|
},
|
|
11305
11559
|
children: p.children
|
|
11306
11560
|
}),
|
|
11307
|
-
p.explorer || p.explorerHead || p.explorerFoot ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
11561
|
+
p.explorer || p.explorerHead || p.explorerFoot || filter ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
11308
11562
|
exOverlay ? /* @__PURE__ */ jsx("button", {
|
|
11309
11563
|
type: "button",
|
|
11310
11564
|
tabIndex: -1,
|
|
@@ -11321,6 +11575,15 @@ function Workbench({ ref, ...p }) {
|
|
|
11321
11575
|
"aria-label": regionName.explorer,
|
|
11322
11576
|
inert: !exOpen,
|
|
11323
11577
|
children: [
|
|
11578
|
+
filter ? /* @__PURE__ */ jsx("div", {
|
|
11579
|
+
className: "ui-wb-exfilter",
|
|
11580
|
+
children: /* @__PURE__ */ jsx(SearchField, {
|
|
11581
|
+
value: filter.value,
|
|
11582
|
+
onChange: filter.onChange,
|
|
11583
|
+
label: filter.label ?? tr("篩選"),
|
|
11584
|
+
placeholder: filter.label ?? tr("篩選")
|
|
11585
|
+
})
|
|
11586
|
+
}) : null,
|
|
11324
11587
|
p.explorerHead ? /* @__PURE__ */ jsx("div", {
|
|
11325
11588
|
className: "ui-wb-exhead",
|
|
11326
11589
|
children: p.explorerHead
|