@seanyeh77/ui 0.18.0 → 0.19.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 +10 -7
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +171 -58
- package/dist/index.js.map +1 -1
- package/dist/styles.css +132 -0
- package/docs/DetailList.md +3 -3
- package/docs/LayerGraph.md +1 -0
- package/docs/Markdown.md +69 -3
- package/docs/Section.md +14 -14
- package/docs/guidelines.md +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -901,7 +901,10 @@ interface MarkdownProps {
|
|
|
901
901
|
/** small: 13 px, for notes. Default: the same 16 px as the text around it. */
|
|
902
902
|
size?: 'body' | 'small';
|
|
903
903
|
/** The heading level `#` becomes. Default 4: # is an h4 (20 px), ## an h5, ### and deeper h6 (both 16 px bold). */
|
|
904
|
-
topLevel?: 3 | 4 | 5 | 6;
|
|
904
|
+
topLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
905
|
+
/** Link schemes of your own, such as ['fn', 'file']: [_sync_as](fn:harness/controller.py:VirtualRouter._sync_as)
|
|
906
|
+
* goes to linkHref and onLink as written, which decide what it opens. javascript:, data: and vbscript: never link. */
|
|
907
|
+
schemes?: string[];
|
|
905
908
|
/** The address of a link (after the http, https, mailto or relative check); return undefined for no link. */
|
|
906
909
|
linkHref?: (href: string) => string | undefined | null;
|
|
907
910
|
/** A plain click on a link (the default navigation is prevented; Ctrl, ⌘ or Shift still open linkHref). */
|
|
@@ -935,6 +938,9 @@ interface SectionProps {
|
|
|
935
938
|
lazy?: boolean;
|
|
936
939
|
/** Remembers open or closed in localStorage under this key. If storage fails it works the same, without remembering. */
|
|
937
940
|
storageKey?: string;
|
|
941
|
+
/** Controls right of the summary, such as a copy IconButton. Outside the title button: clicking them does not open
|
|
942
|
+
* or close the section. */
|
|
943
|
+
actions?: React.ReactNode;
|
|
938
944
|
/** Heading level of the title. Default 3. The size stays 20 px whatever the level. */
|
|
939
945
|
level?: 2 | 3 | 4 | 5 | 6;
|
|
940
946
|
children?: React.ReactNode;
|
|
@@ -1070,6 +1076,9 @@ interface LayerGraphProps {
|
|
|
1070
1076
|
/** The 「圖/清單」 switch above the diagram; the list shows every box and line as text, also for screen readers.
|
|
1071
1077
|
* false hides the switch. */
|
|
1072
1078
|
listView?: boolean;
|
|
1079
|
+
/** Controls of the page on the same row as 「圖/清單」, at its left, such as the page's own 「依元件/依檔案」 Tabs,
|
|
1080
|
+
* so two switches do not sit on two rows. */
|
|
1081
|
+
toolbar?: React.ReactNode;
|
|
1073
1082
|
/** Headings of the list: { nodes, edges }. Default 「項目」 and 「關係」. */
|
|
1074
1083
|
listLabels?: {
|
|
1075
1084
|
nodes?: string;
|
package/dist/index.js
CHANGED
|
@@ -4687,6 +4687,17 @@ function GraphLegend({ items = LEGEND_DEFAULT, className }) {
|
|
|
4687
4687
|
});
|
|
4688
4688
|
}
|
|
4689
4689
|
// src/components/Markdown/Markdown.tsx
|
|
4690
|
+
const DETAILS_OPEN = /^\s*<details\b[^>]*>/i;
|
|
4691
|
+
const DETAILS_TAG = /<(\/?)details\b[^>]*>/gi;
|
|
4692
|
+
const SUMMARY = /<summary\b[^>]*>([\s\S]*?)<\/summary>/i;
|
|
4693
|
+
const ALERT = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/i;
|
|
4694
|
+
const ALERT_TONE = {
|
|
4695
|
+
NOTE: "info",
|
|
4696
|
+
TIP: "success",
|
|
4697
|
+
IMPORTANT: "info",
|
|
4698
|
+
WARNING: "warning",
|
|
4699
|
+
CAUTION: "danger"
|
|
4700
|
+
};
|
|
4690
4701
|
const FENCE = /^ {0,3}(`{3,}|~{3,})\s*([\w+#.-]*)/;
|
|
4691
4702
|
const HEADING = /^ {0,3}(#{1,6})(?:\s+(.*?))?\s*#*\s*$/;
|
|
4692
4703
|
const HR = /^ {0,3}([-*_])(?:\s*\1){2,}\s*$/;
|
|
@@ -4727,6 +4738,30 @@ function parse(lines) {
|
|
|
4727
4738
|
i++;
|
|
4728
4739
|
continue;
|
|
4729
4740
|
}
|
|
4741
|
+
if (DETAILS_OPEN.test(line)) {
|
|
4742
|
+
const rest = lines.slice(i).join("\n");
|
|
4743
|
+
DETAILS_TAG.lastIndex = 0;
|
|
4744
|
+
let depth = 0;
|
|
4745
|
+
let open = -1;
|
|
4746
|
+
let close = rest.length;
|
|
4747
|
+
let after = rest.length;
|
|
4748
|
+
for (let m = DETAILS_TAG.exec(rest); m; m = DETAILS_TAG.exec(rest)) if (!m[1]) {
|
|
4749
|
+
if (depth++ === 0) open = m.index + m[0].length;
|
|
4750
|
+
} else if (--depth === 0) {
|
|
4751
|
+
close = m.index;
|
|
4752
|
+
after = m.index + m[0].length;
|
|
4753
|
+
break;
|
|
4754
|
+
}
|
|
4755
|
+
let inner = rest.slice(open, close);
|
|
4756
|
+
const sum = SUMMARY.exec(inner);
|
|
4757
|
+
if (sum) inner = inner.slice(0, sum.index) + inner.slice(sum.index + sum[0].length);
|
|
4758
|
+
out.push({
|
|
4759
|
+
t: "details",
|
|
4760
|
+
summary: (sum?.[1] ?? "").trim(),
|
|
4761
|
+
blocks: parse(inner.split("\n"))
|
|
4762
|
+
});
|
|
4763
|
+
return out.concat(parse(rest.slice(after).split("\n")));
|
|
4764
|
+
}
|
|
4730
4765
|
const fence = FENCE.exec(line);
|
|
4731
4766
|
if (fence) {
|
|
4732
4767
|
const mark = fence[1];
|
|
@@ -4762,7 +4797,13 @@ function parse(lines) {
|
|
|
4762
4797
|
body.push(QUOTE.exec(lines[i])?.[1] ?? lines[i]);
|
|
4763
4798
|
i++;
|
|
4764
4799
|
}
|
|
4765
|
-
|
|
4800
|
+
const alert = body.length > 0 ? ALERT.exec(body[0]) : null;
|
|
4801
|
+
if (alert) out.push({
|
|
4802
|
+
t: "alert",
|
|
4803
|
+
tone: ALERT_TONE[alert[1].toUpperCase()],
|
|
4804
|
+
blocks: parse(body.slice(1))
|
|
4805
|
+
});
|
|
4806
|
+
else out.push({
|
|
4766
4807
|
t: "quote",
|
|
4767
4808
|
blocks: parse(body)
|
|
4768
4809
|
});
|
|
@@ -4852,6 +4893,11 @@ function safeHref(href) {
|
|
|
4852
4893
|
}
|
|
4853
4894
|
const PATH = /^(?:\.{1,2}\/)?(?:[\w.-]+\/)*[\w.-]+\.[A-Za-z0-9]+(?::\d+(?:-\d+)?)?$/;
|
|
4854
4895
|
const isPath = (s) => PATH.test(s) && (s.includes("/") || /:\d/.test(s));
|
|
4896
|
+
const BLOCKED = [
|
|
4897
|
+
"javascript",
|
|
4898
|
+
"data",
|
|
4899
|
+
"vbscript"
|
|
4900
|
+
];
|
|
4855
4901
|
const CJK = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\u3000-\u303f\uff00-\uffef]/u;
|
|
4856
4902
|
/** Inline Markdown: code spans, links, autolinks, bold, italic, hard breaks; HTML tags dropped, their text kept. */
|
|
4857
4903
|
function inline(src, c) {
|
|
@@ -5016,9 +5062,11 @@ function findClose(src, from, run) {
|
|
|
5016
5062
|
return -1;
|
|
5017
5063
|
}
|
|
5018
5064
|
function link(raw, children, c) {
|
|
5019
|
-
const
|
|
5065
|
+
const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(raw.trim())?.[1].toLowerCase();
|
|
5066
|
+
const own = !!scheme && !BLOCKED.includes(scheme) && !!c.schemes?.some((x) => x.toLowerCase() === scheme);
|
|
5067
|
+
const safe = own ? raw.trim() : safeHref(raw);
|
|
5020
5068
|
if (safe === void 0) return /* @__PURE__ */ jsx(React.Fragment, { children }, c.k());
|
|
5021
|
-
const href = c.linkHref ? c.linkHref(safe) || void 0 : safe;
|
|
5069
|
+
const href = c.linkHref ? c.linkHref(safe) || void 0 : own ? void 0 : safe;
|
|
5022
5070
|
if (!href && !c.onLink) return /* @__PURE__ */ jsx(React.Fragment, { children }, c.k());
|
|
5023
5071
|
const outside = !!href && /^https?:/i.test(href);
|
|
5024
5072
|
const onLink = c.onLink;
|
|
@@ -5064,6 +5112,7 @@ function Markdown(p) {
|
|
|
5064
5112
|
let n = 0;
|
|
5065
5113
|
const c = {
|
|
5066
5114
|
k: () => "m" + n++,
|
|
5115
|
+
schemes: p.schemes,
|
|
5067
5116
|
linkHref: p.linkHref,
|
|
5068
5117
|
onLink: p.onLink,
|
|
5069
5118
|
refHref: p.refHref,
|
|
@@ -5087,6 +5136,15 @@ function Markdown(p) {
|
|
|
5087
5136
|
}
|
|
5088
5137
|
case "p": return /* @__PURE__ */ jsx("p", { children: inline(b.text, c) }, c.k());
|
|
5089
5138
|
case "hr": return /* @__PURE__ */ jsx("hr", {}, c.k());
|
|
5139
|
+
case "details": return /* @__PURE__ */ jsx(MdDetails, {
|
|
5140
|
+
summary: inline(b.summary, c),
|
|
5141
|
+
children: render(b.blocks)
|
|
5142
|
+
}, c.k());
|
|
5143
|
+
case "alert": return /* @__PURE__ */ jsx(Alert, {
|
|
5144
|
+
tone: b.tone,
|
|
5145
|
+
className: "ui-md-alert",
|
|
5146
|
+
children: render(b.blocks)
|
|
5147
|
+
}, c.k());
|
|
5090
5148
|
case "quote": return /* @__PURE__ */ jsx("blockquote", { children: render(b.blocks) }, c.k());
|
|
5091
5149
|
case "list": {
|
|
5092
5150
|
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()));
|
|
@@ -5125,6 +5183,7 @@ function Markdown(p) {
|
|
|
5125
5183
|
}, j)) }) }), /* @__PURE__ */ jsx("tbody", { children: b.rows.map((r, ri) => /* @__PURE__ */ jsx("tr", { children: Array.from({ length: n }, (_, j) => /* @__PURE__ */ jsx("td", {
|
|
5126
5184
|
className: numeric[j] ? "is-num" : void 0,
|
|
5127
5185
|
style: align(j),
|
|
5186
|
+
"data-label": plain(b.head[j] ?? ""),
|
|
5128
5187
|
children: inline(r[j] ?? "", c)
|
|
5129
5188
|
}, j)) }, ri)) })]
|
|
5130
5189
|
})
|
|
@@ -5137,6 +5196,47 @@ function Markdown(p) {
|
|
|
5137
5196
|
children: render(parse(src.split("\n")))
|
|
5138
5197
|
});
|
|
5139
5198
|
}
|
|
5199
|
+
/** A header cell as plain text, for the label above each value when a narrow table turns into cards. */
|
|
5200
|
+
const plain = (md) => md.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[`*_]/g, "").trim();
|
|
5201
|
+
/** DA: a <details> block: a button with the summary, closed at first. The closed content stays in the page
|
|
5202
|
+
* (hidden="until-found"), so the browser's find opens it, as in Section. */
|
|
5203
|
+
function MdDetails({ summary, children }) {
|
|
5204
|
+
const [open, setOpen] = React.useState(false);
|
|
5205
|
+
const id = React.useId();
|
|
5206
|
+
const body = React.useRef(null);
|
|
5207
|
+
React.useLayoutEffect(() => {
|
|
5208
|
+
const el = body.current;
|
|
5209
|
+
if (!el) return;
|
|
5210
|
+
if (open) {
|
|
5211
|
+
el.removeAttribute("hidden");
|
|
5212
|
+
return;
|
|
5213
|
+
}
|
|
5214
|
+
el.setAttribute("hidden", "until-found");
|
|
5215
|
+
const found = () => setOpen(true);
|
|
5216
|
+
el.addEventListener("beforematch", found);
|
|
5217
|
+
return () => el.removeEventListener("beforematch", found);
|
|
5218
|
+
}, [open]);
|
|
5219
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
5220
|
+
className: cx("ui-md-details", open && "is-open"),
|
|
5221
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
5222
|
+
type: "button",
|
|
5223
|
+
className: "ui-md-summary",
|
|
5224
|
+
"aria-expanded": open,
|
|
5225
|
+
"aria-controls": id,
|
|
5226
|
+
onClick: () => setOpen(!open),
|
|
5227
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
5228
|
+
name: "caret-right",
|
|
5229
|
+
size: 16,
|
|
5230
|
+
className: "ui-md-caret"
|
|
5231
|
+
}), /* @__PURE__ */ jsx("span", { children: summary })]
|
|
5232
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
5233
|
+
id,
|
|
5234
|
+
ref: body,
|
|
5235
|
+
className: "ui-md-details-body",
|
|
5236
|
+
children
|
|
5237
|
+
})]
|
|
5238
|
+
});
|
|
5239
|
+
}
|
|
5140
5240
|
// src/components/Section/Section.tsx
|
|
5141
5241
|
const Group = React.createContext(null);
|
|
5142
5242
|
const MOVE_MS = 260;
|
|
@@ -5245,31 +5345,37 @@ function Section(p) {
|
|
|
5245
5345
|
return /* @__PURE__ */ jsxs("section", {
|
|
5246
5346
|
id: p.id,
|
|
5247
5347
|
className: cx("ui-sec", open && "is-open", p.className),
|
|
5248
|
-
children: [/* @__PURE__ */
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5348
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
5349
|
+
className: "ui-sec-row",
|
|
5350
|
+
children: [/* @__PURE__ */ jsx(H, {
|
|
5351
|
+
ref: head,
|
|
5352
|
+
className: "ui-sec-h",
|
|
5353
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
5354
|
+
type: "button",
|
|
5355
|
+
className: "ui-sec-btn",
|
|
5356
|
+
"aria-expanded": open,
|
|
5357
|
+
"aria-controls": body,
|
|
5358
|
+
onClick: () => set(!open),
|
|
5359
|
+
children: [
|
|
5360
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
5361
|
+
name: "caret-right",
|
|
5362
|
+
size: 18,
|
|
5363
|
+
className: "ui-sec-caret"
|
|
5364
|
+
}),
|
|
5365
|
+
/* @__PURE__ */ jsx("span", {
|
|
5366
|
+
className: "ui-sec-title",
|
|
5367
|
+
children: p.title
|
|
5368
|
+
}),
|
|
5369
|
+
p.summary != null && p.summary !== false ? /* @__PURE__ */ jsx("span", {
|
|
5370
|
+
className: "ui-sec-sum",
|
|
5371
|
+
children: p.summary
|
|
5372
|
+
}) : null
|
|
5373
|
+
]
|
|
5374
|
+
})
|
|
5375
|
+
}), p.actions ? /* @__PURE__ */ jsx("div", {
|
|
5376
|
+
className: "ui-sec-actions",
|
|
5377
|
+
children: p.actions
|
|
5378
|
+
}) : null]
|
|
5273
5379
|
}), /* @__PURE__ */ jsx("div", {
|
|
5274
5380
|
id: body,
|
|
5275
5381
|
className: "ui-sec-body",
|
|
@@ -6855,37 +6961,44 @@ function LayerGraph(p) {
|
|
|
6855
6961
|
return /* @__PURE__ */ jsxs("div", {
|
|
6856
6962
|
className: cx("ui-graph ui-lg", p.className),
|
|
6857
6963
|
children: [
|
|
6858
|
-
p.listView === false && !toggleShown ? null : /* @__PURE__ */ jsxs("div", {
|
|
6964
|
+
p.listView === false && !toggleShown && !p.toolbar ? null : /* @__PURE__ */ jsxs("div", {
|
|
6859
6965
|
className: "ui-lg-bar",
|
|
6860
|
-
children: [
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
"
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6966
|
+
children: [
|
|
6967
|
+
p.toolbar ? /* @__PURE__ */ jsx("div", {
|
|
6968
|
+
className: "ui-lg-toolbar",
|
|
6969
|
+
children: p.toolbar
|
|
6970
|
+
}) : null,
|
|
6971
|
+
toggleShown && p.labelToggle === "icon" ? /* @__PURE__ */ jsx(IconButton, {
|
|
6972
|
+
className: "ui-lg-labels-btn",
|
|
6973
|
+
icon: "tag",
|
|
6974
|
+
filled: labelsOn,
|
|
6975
|
+
label: tr("顯示線上文字"),
|
|
6976
|
+
"aria-pressed": labelsOn,
|
|
6977
|
+
onClick: switchLabels
|
|
6978
|
+
}) : toggleShown ? /* @__PURE__ */ jsxs("label", {
|
|
6979
|
+
className: "ui-lg-labels-switch",
|
|
6980
|
+
children: [/* @__PURE__ */ jsx(Switch, {
|
|
6981
|
+
checked: labelsOn,
|
|
6982
|
+
onChange: switchLabels,
|
|
6983
|
+
label: tr("線上文字")
|
|
6984
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
6985
|
+
"aria-hidden": "true",
|
|
6986
|
+
children: tr("線上文字")
|
|
6987
|
+
})]
|
|
6988
|
+
}) : null,
|
|
6989
|
+
p.listView === false ? null : /* @__PURE__ */ jsx(Tabs, {
|
|
6990
|
+
label: tr("顯示方式"),
|
|
6991
|
+
value: view,
|
|
6992
|
+
onChange: setView,
|
|
6993
|
+
items: [{
|
|
6994
|
+
id: "graph",
|
|
6995
|
+
label: tr("圖")
|
|
6996
|
+
}, {
|
|
6997
|
+
id: "list",
|
|
6998
|
+
label: tr("清單")
|
|
6999
|
+
}]
|
|
7000
|
+
})
|
|
7001
|
+
]
|
|
6889
7002
|
}),
|
|
6890
7003
|
showList ? list : null,
|
|
6891
7004
|
/* @__PURE__ */ jsx("div", {
|