@seanyeh77/ui 0.43.1 → 0.44.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 +14 -14
- package/dist/bundle.js.map +1 -1
- package/dist/components/Alert/Alert.d.ts +1 -1
- package/dist/components/Alert/Alert.js +2 -1
- package/dist/components/Alert/Alert.js.map +1 -1
- package/dist/components/DangerZone/DangerZone.d.ts +1 -1
- package/dist/components/DangerZone/DangerZone.js +2 -1
- package/dist/components/DangerZone/DangerZone.js.map +1 -1
- package/dist/components/DataTable/DataTable.d.ts +8 -3
- package/dist/components/DataTable/DataTable.js +155 -63
- package/dist/components/DataTable/DataTable.js.map +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +2 -2
- package/dist/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +1 -1
- package/dist/components/Dialog/Dialog.js +2 -1
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/Drawer/Drawer.d.ts +1 -0
- package/dist/components/Drawer/Drawer.js +2 -1
- package/dist/components/Drawer/Drawer.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.d.ts +2 -2
- package/dist/components/EmptyState/EmptyState.js +3 -2
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/ErrorPage/ErrorPage.d.ts +1 -0
- package/dist/components/ErrorPage/ErrorPage.js +2 -1
- package/dist/components/ErrorPage/ErrorPage.js.map +1 -1
- package/dist/components/EventTimeline/EventTimeline.d.ts +1 -1
- package/dist/components/EventTimeline/EventTimeline.js +2 -1
- package/dist/components/EventTimeline/EventTimeline.js.map +1 -1
- package/dist/components/FileUpload/FileUpload.d.ts +1 -1
- package/dist/components/FileUpload/FileUpload.js +2 -1
- package/dist/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/components/InlineCode/InlineCode.js +10 -6
- package/dist/components/InlineCode/InlineCode.js.map +1 -1
- package/dist/components/KpiCard/KpiCard.d.ts +2 -2
- package/dist/components/KpiCard/KpiCard.js +5 -4
- package/dist/components/KpiCard/KpiCard.js.map +1 -1
- package/dist/components/LayerGraph/LayerGraph.js +19 -9
- package/dist/components/LayerGraph/LayerGraph.js.map +1 -1
- package/dist/components/LoginCard/LoginCard.d.ts +1 -1
- package/dist/components/LoginCard/LoginCard.js.map +1 -1
- package/dist/components/Markdown/Markdown.js +19 -1
- package/dist/components/Markdown/Markdown.js.map +1 -1
- package/dist/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/components/NotificationBell/NotificationBell.d.ts +1 -0
- package/dist/components/NotificationBell/NotificationBell.js +2 -1
- package/dist/components/NotificationBell/NotificationBell.js.map +1 -1
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/SettingsLayout/SettingsLayout.d.ts +1 -1
- package/dist/components/SettingsLayout/SettingsLayout.js +2 -1
- package/dist/components/SettingsLayout/SettingsLayout.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +4 -1
- package/dist/components/Tabs/Tabs.js +5 -2
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TextArea/TextArea.d.ts +2 -1
- package/dist/components/TextArea/TextArea.js +3 -2
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +2 -2
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/Toast/Toast.d.ts +1 -1
- package/dist/components/Toast/Toast.js +2 -1
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/css/Alert.css +1 -0
- package/dist/css/Button.css +1 -0
- package/dist/css/Checkbox.css +1 -0
- package/dist/css/CodeView.css +1 -1
- package/dist/css/DangerZone.css +1 -0
- package/dist/css/DataTable.css +177 -38
- package/dist/css/DatePicker.css +1 -0
- package/dist/css/DateRangePicker.css +1 -0
- package/dist/css/Drawer.css +1 -0
- package/dist/css/EmptyState.css +1 -0
- package/dist/css/ErrorPage.css +1 -0
- package/dist/css/EventTimeline.css +1 -0
- package/dist/css/FileUpload.css +1 -0
- package/dist/css/KpiCard.css +1 -0
- package/dist/css/LoginCard.css +1 -0
- package/dist/css/Markdown.css +29 -1
- package/dist/css/MultiSelect.css +1 -0
- package/dist/css/NotificationBell.css +1 -0
- package/dist/css/ProjectSwitcher.css +6 -1
- package/dist/css/Select.css +1 -0
- package/dist/css/SettingsLayout.css +1 -0
- package/dist/css/Suggestion.css +1 -1
- package/dist/css/Tabs.css +6 -6
- package/dist/css/Term.css +1 -1
- package/dist/css/TextArea.css +1 -0
- package/dist/css/TextField.css +1 -0
- package/dist/css/Toast.css +1 -0
- package/dist/css/Tour.css +1 -1
- package/dist/css/TreeList.css +1 -0
- package/dist/css/Workbench.css +12 -0
- package/dist/format.js +3 -1
- package/dist/format.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/internal/Field.js +3 -2
- package/dist/internal/Field.js.map +1 -1
- package/dist/internal/codeSpans.js +20 -0
- package/dist/internal/codeSpans.js.map +1 -0
- package/dist/styles.css +316 -133
- package/docs/Alert.md +1 -0
- package/docs/Card.md +3 -3
- package/docs/DangerZone.md +1 -0
- package/docs/DataTable.md +29 -19
- package/docs/DatePicker.md +1 -0
- package/docs/Dialog.md +1 -0
- package/docs/Drawer.md +1 -0
- package/docs/EmptyState.md +1 -0
- package/docs/ErrorPage.md +1 -0
- package/docs/EventTimeline.md +1 -0
- package/docs/FileUpload.md +1 -0
- package/docs/Format.md +1 -1
- package/docs/KpiCard.md +1 -0
- package/docs/LoginCard.md +1 -0
- package/docs/Markdown.md +3 -0
- package/docs/MultiSelect.md +1 -0
- package/docs/NotificationBell.md +1 -0
- package/docs/Select.md +1 -0
- package/docs/SettingsLayout.md +1 -0
- package/docs/Tabs.md +2 -2
- package/docs/Term.md +1 -0
- package/docs/TextArea.md +1 -0
- package/docs/TextField.md +1 -0
- package/docs/Toast.md +1 -0
- package/docs/data.md +4 -3
- package/docs/guidelines.md +4 -4
- package/docs/layout.md +1 -1
- package/package.json +2 -2
package/dist/css/ErrorPage.css
CHANGED
package/dist/css/FileUpload.css
CHANGED
package/dist/css/KpiCard.css
CHANGED
package/dist/css/LoginCard.css
CHANGED
package/dist/css/Markdown.css
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
@layer theme, base, ui, components, utilities;
|
|
2
2
|
@layer ui.tokens, ui.components;
|
|
3
|
+
@import './InlineCode.css';
|
|
3
4
|
@import './Dialog.css';
|
|
4
5
|
@import './Alert.css';
|
|
5
6
|
@import './IconButton.css';
|
|
6
|
-
@import './InlineCode.css';
|
|
7
7
|
@import './AiMark.css';
|
|
8
8
|
@import './Term.css';
|
|
9
9
|
@import './CodeView.css';
|
|
@@ -87,6 +87,34 @@
|
|
|
87
87
|
text-underline-offset: 2px;
|
|
88
88
|
cursor: pointer;
|
|
89
89
|
}
|
|
90
|
+
/* A list item that is one link (a reference list): the link fills the row, so the whole row is clickable, with the
|
|
91
|
+
hover ground of other rows. 32 px with a mouse, 48 px on touch screens. The marker stays outside the row, where the
|
|
92
|
+
other items' markers are; the text starts where theirs does and the ground reaches 6 px to its left. */
|
|
93
|
+
.ui-md li.ui-md-rowitem + li.ui-md-rowitem {
|
|
94
|
+
margin-top: 2px;
|
|
95
|
+
}
|
|
96
|
+
.ui-md-link.is-row {
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
box-sizing: border-box;
|
|
100
|
+
min-height: 32px;
|
|
101
|
+
margin-left: -6px;
|
|
102
|
+
padding: 3px 8px 3px 6px;
|
|
103
|
+
border-radius: var(--radius-sm);
|
|
104
|
+
text-align: left;
|
|
105
|
+
transition: background-color var(--dur-hover) ease;
|
|
106
|
+
}
|
|
107
|
+
.ui-md-link.is-row:hover {
|
|
108
|
+
background: var(--surface-sub);
|
|
109
|
+
}
|
|
110
|
+
button.ui-md-link.is-row {
|
|
111
|
+
width: calc(100% + 6px);
|
|
112
|
+
}
|
|
113
|
+
@media (pointer: coarse) {
|
|
114
|
+
.ui-md-link.is-row {
|
|
115
|
+
min-height: var(--touch-target);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
90
118
|
.ui-md-table-wrap {
|
|
91
119
|
max-width: 100%;
|
|
92
120
|
overflow-x: auto;
|
package/dist/css/MultiSelect.css
CHANGED
|
@@ -57,16 +57,21 @@
|
|
|
57
57
|
min-width: 0;
|
|
58
58
|
white-space: nowrap;
|
|
59
59
|
}
|
|
60
|
-
/* The name keeps its room; the status gives way first, then the name is cut with
|
|
60
|
+
/* The name keeps its room; the status gives way first, then the name is cut with 「…」, never below 3em. A name shorter
|
|
61
|
+
than 3em keeps its own width: a 3em box would leave a gap before 「·」 (「web · production」). Browsers without
|
|
62
|
+
calc-size() keep the 3em box. */
|
|
61
63
|
.ui-projsw-name {
|
|
62
64
|
flex: 0 1 auto;
|
|
63
65
|
min-width: 3em;
|
|
66
|
+
min-width: calc-size(max-content, min(size, 3em));
|
|
64
67
|
overflow: hidden;
|
|
65
68
|
text-overflow: ellipsis;
|
|
66
69
|
}
|
|
70
|
+
/* pre: the status starts with 「 · 」, and a flex item drops its leading space otherwise (「web· production」). */
|
|
67
71
|
.ui-projsw-status {
|
|
68
72
|
flex: 0 1000 auto;
|
|
69
73
|
min-width: 0;
|
|
74
|
+
white-space: pre;
|
|
70
75
|
overflow: hidden;
|
|
71
76
|
text-overflow: ellipsis;
|
|
72
77
|
}
|
package/dist/css/Select.css
CHANGED
package/dist/css/Suggestion.css
CHANGED
package/dist/css/Tabs.css
CHANGED
|
@@ -79,13 +79,13 @@
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
.ui-tab-count {
|
|
82
|
-
/* With the space before it: about 6 px from the name.
|
|
82
|
+
/* With the space before it: about 6 px from the name. A quiet number: the text font with figures of one width,
|
|
83
|
+
muted and regular weight on every tab, so the names lead and the counts line up. */
|
|
83
84
|
margin-left: 2px;
|
|
84
|
-
font-family: var(--font-
|
|
85
|
-
font-
|
|
85
|
+
font-family: var(--font-sans);
|
|
86
|
+
font-variant-numeric: tabular-nums;
|
|
87
|
+
font-size: var(--text-compact);
|
|
88
|
+
font-weight: 400;
|
|
86
89
|
color: var(--ink-muted);
|
|
87
90
|
}
|
|
88
|
-
.ui-tab.is-selected .ui-tab-count {
|
|
89
|
-
color: var(--ink);
|
|
90
|
-
}
|
|
91
91
|
}
|
package/dist/css/Term.css
CHANGED
package/dist/css/TextArea.css
CHANGED
package/dist/css/TextField.css
CHANGED
package/dist/css/Toast.css
CHANGED
package/dist/css/Tour.css
CHANGED
package/dist/css/TreeList.css
CHANGED
package/dist/css/Workbench.css
CHANGED
|
@@ -595,6 +595,18 @@
|
|
|
595
595
|
.ui-wb-sheet > .ui-wb-split .ui-wb-split-line {
|
|
596
596
|
display: none;
|
|
597
597
|
}
|
|
598
|
+
/* On touch screens the grip's touch area is 48 px tall: the 20 px grip plus a transparent area above it, over the
|
|
599
|
+
bottom of the main view, so it never covers the panel's tab row below. */
|
|
600
|
+
@media (pointer: coarse) {
|
|
601
|
+
.ui-wb-sheet > .ui-wb-split.is-h::after {
|
|
602
|
+
content: '';
|
|
603
|
+
position: absolute;
|
|
604
|
+
left: 0;
|
|
605
|
+
right: 0;
|
|
606
|
+
bottom: 0;
|
|
607
|
+
height: var(--touch-target);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
598
610
|
.ui-wb-grab {
|
|
599
611
|
flex: 0 0 20px;
|
|
600
612
|
display: flex;
|
package/dist/format.js
CHANGED
|
@@ -41,7 +41,9 @@ function time(d) {
|
|
|
41
41
|
}).format(d);
|
|
42
42
|
}
|
|
43
43
|
function dateTime(d, o) {
|
|
44
|
-
|
|
44
|
+
if (!d) return "";
|
|
45
|
+
const day = date(d, o);
|
|
46
|
+
return isZhTW() && day.endsWith(")") ? day + time(d) : `${day} ${time(d)}`;
|
|
45
47
|
}
|
|
46
48
|
/** Within 7 days: 「2 小時前」、「昨天」. Older: full date and time. Pass now to test. */
|
|
47
49
|
function relative(d, now = /* @__PURE__ */ new Date()) {
|
package/dist/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { I18N, isZhTW, tr } from './i18n';\n\n/* Dates and numbers for the current locale (setLocale). zh-TW follows the design system's rules\n (2026/11/04(三), 24-hour clock, NT$ 1,280, 萬 and 億 in KPI cards); other locales use Intl's conventions. */\n\nexport type Decimals = number | 'money' | 'percent' | 'size' | 'count';\n\nconst DECIMALS = { money: 0, percent: 1, size: 1, count: 0 } as const;\n\nconst pad2 = (n: number): string => String(n).padStart(2, '0');\n\nfunction locale(): string {\n return I18N.locale;\n}\n\n/** zh-TW: 2026/11/04(三). Other locales: their short date with weekday. */\nfunction date(d: Date | null | undefined, o: { weekday?: boolean; long?: boolean } = {}): string {\n if (!d) return '';\n const wd = o.weekday !== false;\n if (o.long) return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long', day: 'numeric', weekday: wd ? 'long' : undefined }).format(d);\n if (isZhTW()) return fmtDate(d) + (wd ? `(${new Intl.DateTimeFormat('zh-TW', { weekday: 'narrow' }).format(d)})` : '');\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: '2-digit', day: '2-digit', weekday: wd ? 'short' : undefined }).format(d);\n}\n\n/** zh-TW: 24-hour 15:57. Other locales: their own clock. */\nfunction time(d: Date | null | undefined): string {\n if (!d) return '';\n return new Intl.DateTimeFormat(\n I18N.locale,\n isZhTW() ? { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' } : { hour: 'numeric', minute: '2-digit' },\n ).format(d);\n}\n\nfunction dateTime(d: Date | null | undefined, o?: { weekday?: boolean }): string {\n return d ? `${date(d, o)} ${time(d)}` : '';\n}\n\n/** Within 7 days: 「2 小時前」、「昨天」. Older: full date and time. Pass now to test. */\nfunction relative(d: Date | null | undefined, now: Date = new Date()): string {\n if (!d) return '';\n const s = (now.getTime() - d.getTime()) / 1000;\n if (s < 0 || s >= 604800) return dateTime(d);\n const rt = new Intl.RelativeTimeFormat(I18N.locale, { numeric: 'auto' });\n if (s < 60) return rt.format(0, 'second');\n if (s < 3600) return rt.format(-Math.floor(s / 60), 'minute');\n if (s < 86400) return rt.format(-Math.floor(s / 3600), 'hour');\n return rt.format(-Math.floor(s / 86400), 'day');\n}\n\nfunction month(d: Date): string {\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long' }).format(d);\n}\n\n/** Week starts on Sunday for zh-TW; other locales use Intl's week info when the browser has it. */\nfunction firstDay(): number {\n if (isZhTW()) return 0;\n try {\n const l = new Intl.Locale(I18N.locale) as Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } };\n const w = l.getWeekInfo ? l.getWeekInfo() : l.weekInfo;\n if (w?.firstDay) return w.firstDay % 7;\n } catch {\n /* older browsers have no week info */\n }\n return 0;\n}\n\n/** Narrow weekday names, starting from firstDay(). */\nfunction weekdays(): string[] {\n const fd = firstDay();\n const f = new Intl.DateTimeFormat(I18N.locale, { weekday: 'narrow' });\n // 2026/11/01 is a Sunday.\n return Array.from({ length: 7 }, (_, i) => f.format(new Date(2026, 10, 1 + ((fd + i) % 7))));\n}\n\n/** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */\nfunction number(v: number, dec?: Decimals): string {\n const dd = typeof dec === 'number' ? dec : dec ? DECIMALS[dec] : 0;\n return new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dd, maximumFractionDigits: dd }).format(v);\n}\n\nfunction percent(v: number, dec = 1): string {\n return new Intl.NumberFormat(I18N.locale, { style: 'percent', minimumFractionDigits: dec, maximumFractionDigits: dec }).format(v / 100);\n}\n\n/** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.\n * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */\nfunction compact(v: number, like?: number): string {\n const ref = like ?? v;\n if (Math.abs(ref) < 1e4) return number(v);\n if (/^zh/i.test(I18N.locale)) {\n const a = Math.abs(ref);\n // 99,999,999 rounds to 10,000.0 萬: write it as 1 億.\n const [unit, div, maxDec] = Math.round(a / 1e3) >= 1e5 ? (['億', 1e8, 2] as const) : (['萬', 1e4, 1] as const);\n const finalStr = new Intl.NumberFormat(I18N.locale, { maximumFractionDigits: maxDec }).format(a / div);\n const sign = v < 0 ? '-' : '';\n if (like === undefined) return `${sign}${finalStr} ${unit}`;\n const digits = (finalStr.split('.')[1] || '').length;\n return `${sign}${new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Math.abs(v) / div)} ${unit}`;\n }\n const nf = new Intl.NumberFormat(I18N.locale, { notation: 'compact', maximumFractionDigits: 1 });\n if (like === undefined) return nf.format(v);\n const parts = nf.formatToParts(ref);\n let num = '';\n let dec = '';\n for (const pt of parts) {\n if (pt.type === 'integer') num += pt.value;\n if (pt.type === 'fraction') {\n num += '.' + pt.value;\n dec = pt.value;\n }\n }\n const mant = parseFloat(num) || 1;\n const scale = 10 ** Math.round(Math.log10(Math.abs(ref) / mant));\n const inner = new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dec.length, maximumFractionDigits: dec.length }).format(Math.abs(v) / scale);\n let done = false;\n const body = parts\n .map((pt) => {\n if (pt.type === 'integer' || pt.type === 'group' || pt.type === 'decimal' || pt.type === 'fraction') {\n if (done) return '';\n done = true;\n return inner;\n }\n return pt.value;\n })\n .join('');\n return (v < 0 && ref >= 0 ? '-' : '') + body;\n}\n\n/** zh-TW with TWD: NT$ 1,280, negatives -NT$ 1,280. Other locales and currencies: Intl's own symbol and order. */\nfunction money(v: number, o: { currency?: string; compact?: boolean; like?: number } = {}): string {\n const cur = o.currency || I18N.currency;\n const body = o.compact ? compact(Math.abs(v), o.like !== undefined ? Math.abs(o.like) : undefined) : number(Math.abs(v), 'money');\n if (isZhTW() && cur === 'TWD') return `${v < 0 ? '-' : ''}NT$ ${body}`;\n if (o.compact) return `${v < 0 ? '-' : ''}${body} ${cur}`;\n return new Intl.NumberFormat(I18N.locale, {\n style: 'currency',\n currency: cur,\n // narrowSymbol writes TWD as a bare 「$」, which reads as dollars: keep 「NT$」 (docs: 英文介面顯示 NT$486,000).\n currencyDisplay: cur === 'TWD' ? 'symbol' : 'narrowSymbol',\n minimumFractionDigits: 0,\n maximumFractionDigits: cur === 'TWD' || cur === 'JPY' ? 0 : 2,\n }).format(v);\n}\n\n/** Bytes to 「186 KB」「54.9 MB」「1.2 GB」. */\nexport function fileSize(b: number | null | undefined): string {\n if (b == null || Number.isNaN(b)) return '';\n // An empty file is 0 KB; anything else at least 1 KB.\n // Compare after rounding: 1,048,500 bytes rounds to 1,024 KB, so it is written 「1.0 MB」.\n if (Math.round(b / 1024) < 1024) return number(b === 0 ? 0 : Math.max(1, Math.round(b / 1024))) + ' KB';\n if (Math.round((b / 1048576) * 10) < 10240) return number(b / 1048576, 1) + ' MB';\n return number(b / 1073741824, 1) + ' GB';\n}\n\n/** Seconds as a clock-style length: under 1 h 「46:42」「1:30」 (minutes not zero-padded), 1 h or more 「1:54:49」.\n * Rounded to the second. Negative, NaN or missing: 「—」. */\nfunction duration(seconds: number | null | undefined): string {\n if (seconds == null || Number.isNaN(seconds) || seconds < 0 || !Number.isFinite(seconds)) return '—';\n const t = Math.round(seconds);\n const h = Math.floor(t / 3600);\n const m = Math.floor((t % 3600) / 60);\n const s = t % 60;\n return h ? `${h}:${pad2(m)}:${pad2(s)}` : `${m}:${pad2(s)}`;\n}\n\n/** Shortens a path: keeps the first segment and the last two, 「src/…/hooks/ops.c:58」. */\nfunction path(p: string | null | undefined, o: { head?: number; tail?: number } = {}): string {\n const head = o.head ?? 1;\n const tail = o.tail ?? 2;\n const parts = String(p ?? '').split('/');\n return parts.length > head + tail ? `${parts.slice(0, head).join('/')}/…/${parts.slice(-tail).join('/')}` : String(p ?? '');\n}\n\n/** A part of a whole, as shown: 「1 / 1 個」「6 / 6 筆」, or 「1 / 5」 without a unit. Give screen readers\n * `fractionLabel` with it: they read the slash as 「斜線」. */\nfunction fraction(n: number, total: number, unit?: string): string {\n return tr(unit ? '{n} / {total} {unit}' : '{n} / {total}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** The same fraction as read aloud: 「1 個中的 1 個」「6 筆中的 6 筆」, or 「5 中的 1」 without a unit (English:\n * 「1 of 1」). For `aria-label`, or for visually hidden text beside the shown fraction. */\nfunction fractionLabel(n: number, total: number, unit?: string): string {\n return tr(unit ? '{total} {unit}中的 {n} {unit}' : '{total} 中的 {n}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** Every date, number, amount, size and path shown in the UI goes through these. */\nexport const format = {\n locale,\n date,\n time,\n dateTime,\n relative,\n month,\n weekdays,\n firstDay,\n number,\n percent,\n compact,\n money,\n fileSize,\n duration,\n path,\n fraction,\n fractionLabel,\n};\n\n/* Calendar helpers (local dates, no time). */\nexport const fmtDate = (d: Date | null | undefined): string => (d ? `${d.getFullYear()}/${pad2(d.getMonth() + 1)}/${pad2(d.getDate())}` : '');\n\nexport function parseDate(s: string | null | undefined): Date | null {\n const m = /^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})$/.exec(s || '');\n if (!m) return null;\n const d = new Date(+m[1], +m[2] - 1, +m[3]);\n return d.getMonth() === +m[2] - 1 ? d : null;\n}\n\nexport const sameDay = (a: Date | null | undefined, b: Date | null | undefined): boolean =>\n !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n\nexport const dayAdd = (d: Date, n: number): Date => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);\n"],"mappings":";;AAOA,MAAM,WAAW;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;CAAG,OAAO;AAAE;AAE3D,MAAM,QAAQ,MAAsB,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;AAE7D,SAAS,SAAiB;CACxB,OAAO,KAAK;AACd;;AAGA,SAAS,KAAK,GAA4B,IAA2C,CAA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AK;EAAG,MAAM,QAAQ;CAAG,CAAC;AAC7H;;AAGA,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,WAAW,MAAwC,IAAI,GAAG,EAAE,YAAY,EAAE,GAAG,KAAK,EAAE,SAAS,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,CAAC,MAAM;AAE1I,SAAgB,UAAU,GAA2C;CACnE,MAAM,IAAI,kCAAkC,KAAK,KAAK,EAAE;CACxD,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;CAC1C,OAAO,EAAE,SAAS,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI;AAC1C;AAEA,MAAa,WAAW,GAA4B,MAClD,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,MAAM,EAAE,YAAY,KAAK,EAAE,SAAS,MAAM,EAAE,SAAS,KAAK,EAAE,QAAQ,MAAM,EAAE,QAAQ;AAElH,MAAa,UAAU,GAAS,MAAoB,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { I18N, isZhTW, tr } from './i18n';\n\n/* Dates and numbers for the current locale (setLocale). zh-TW follows the design system's rules\n (2026/11/04(三), 24-hour clock, NT$ 1,280, 萬 and 億 in KPI cards); other locales use Intl's conventions. */\n\nexport type Decimals = number | 'money' | 'percent' | 'size' | 'count';\n\nconst DECIMALS = { money: 0, percent: 1, size: 1, count: 0 } as const;\n\nconst pad2 = (n: number): string => String(n).padStart(2, '0');\n\nfunction locale(): string {\n return I18N.locale;\n}\n\n/** zh-TW: 2026/11/04(三). Other locales: their short date with weekday. */\nfunction date(d: Date | null | undefined, o: { weekday?: boolean; long?: boolean } = {}): string {\n if (!d) return '';\n const wd = o.weekday !== false;\n if (o.long) return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long', day: 'numeric', weekday: wd ? 'long' : undefined }).format(d);\n if (isZhTW()) return fmtDate(d) + (wd ? `(${new Intl.DateTimeFormat('zh-TW', { weekday: 'narrow' }).format(d)})` : '');\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: '2-digit', day: '2-digit', weekday: wd ? 'short' : undefined }).format(d);\n}\n\n/** zh-TW: 24-hour 15:57. Other locales: their own clock. */\nfunction time(d: Date | null | undefined): string {\n if (!d) return '';\n return new Intl.DateTimeFormat(\n I18N.locale,\n isZhTW() ? { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' } : { hour: 'numeric', minute: '2-digit' },\n ).format(d);\n}\n\nfunction dateTime(d: Date | null | undefined, o?: { weekday?: boolean }): string {\n if (!d) return '';\n // zh-TW: the full-width 「)」 already leaves half a character of room, so no space after it: 2026/11/04(三)13:00.\n const day = date(d, o);\n return isZhTW() && day.endsWith(')') ? day + time(d) : `${day} ${time(d)}`;\n}\n\n/** Within 7 days: 「2 小時前」、「昨天」. Older: full date and time. Pass now to test. */\nfunction relative(d: Date | null | undefined, now: Date = new Date()): string {\n if (!d) return '';\n const s = (now.getTime() - d.getTime()) / 1000;\n if (s < 0 || s >= 604800) return dateTime(d);\n const rt = new Intl.RelativeTimeFormat(I18N.locale, { numeric: 'auto' });\n if (s < 60) return rt.format(0, 'second');\n if (s < 3600) return rt.format(-Math.floor(s / 60), 'minute');\n if (s < 86400) return rt.format(-Math.floor(s / 3600), 'hour');\n return rt.format(-Math.floor(s / 86400), 'day');\n}\n\nfunction month(d: Date): string {\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long' }).format(d);\n}\n\n/** Week starts on Sunday for zh-TW; other locales use Intl's week info when the browser has it. */\nfunction firstDay(): number {\n if (isZhTW()) return 0;\n try {\n const l = new Intl.Locale(I18N.locale) as Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } };\n const w = l.getWeekInfo ? l.getWeekInfo() : l.weekInfo;\n if (w?.firstDay) return w.firstDay % 7;\n } catch {\n /* older browsers have no week info */\n }\n return 0;\n}\n\n/** Narrow weekday names, starting from firstDay(). */\nfunction weekdays(): string[] {\n const fd = firstDay();\n const f = new Intl.DateTimeFormat(I18N.locale, { weekday: 'narrow' });\n // 2026/11/01 is a Sunday.\n return Array.from({ length: 7 }, (_, i) => f.format(new Date(2026, 10, 1 + ((fd + i) % 7))));\n}\n\n/** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */\nfunction number(v: number, dec?: Decimals): string {\n const dd = typeof dec === 'number' ? dec : dec ? DECIMALS[dec] : 0;\n return new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dd, maximumFractionDigits: dd }).format(v);\n}\n\nfunction percent(v: number, dec = 1): string {\n return new Intl.NumberFormat(I18N.locale, { style: 'percent', minimumFractionDigits: dec, maximumFractionDigits: dec }).format(v / 100);\n}\n\n/** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.\n * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */\nfunction compact(v: number, like?: number): string {\n const ref = like ?? v;\n if (Math.abs(ref) < 1e4) return number(v);\n if (/^zh/i.test(I18N.locale)) {\n const a = Math.abs(ref);\n // 99,999,999 rounds to 10,000.0 萬: write it as 1 億.\n const [unit, div, maxDec] = Math.round(a / 1e3) >= 1e5 ? (['億', 1e8, 2] as const) : (['萬', 1e4, 1] as const);\n const finalStr = new Intl.NumberFormat(I18N.locale, { maximumFractionDigits: maxDec }).format(a / div);\n const sign = v < 0 ? '-' : '';\n if (like === undefined) return `${sign}${finalStr} ${unit}`;\n const digits = (finalStr.split('.')[1] || '').length;\n return `${sign}${new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Math.abs(v) / div)} ${unit}`;\n }\n const nf = new Intl.NumberFormat(I18N.locale, { notation: 'compact', maximumFractionDigits: 1 });\n if (like === undefined) return nf.format(v);\n const parts = nf.formatToParts(ref);\n let num = '';\n let dec = '';\n for (const pt of parts) {\n if (pt.type === 'integer') num += pt.value;\n if (pt.type === 'fraction') {\n num += '.' + pt.value;\n dec = pt.value;\n }\n }\n const mant = parseFloat(num) || 1;\n const scale = 10 ** Math.round(Math.log10(Math.abs(ref) / mant));\n const inner = new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dec.length, maximumFractionDigits: dec.length }).format(Math.abs(v) / scale);\n let done = false;\n const body = parts\n .map((pt) => {\n if (pt.type === 'integer' || pt.type === 'group' || pt.type === 'decimal' || pt.type === 'fraction') {\n if (done) return '';\n done = true;\n return inner;\n }\n return pt.value;\n })\n .join('');\n return (v < 0 && ref >= 0 ? '-' : '') + body;\n}\n\n/** zh-TW with TWD: NT$ 1,280, negatives -NT$ 1,280. Other locales and currencies: Intl's own symbol and order. */\nfunction money(v: number, o: { currency?: string; compact?: boolean; like?: number } = {}): string {\n const cur = o.currency || I18N.currency;\n const body = o.compact ? compact(Math.abs(v), o.like !== undefined ? Math.abs(o.like) : undefined) : number(Math.abs(v), 'money');\n if (isZhTW() && cur === 'TWD') return `${v < 0 ? '-' : ''}NT$ ${body}`;\n if (o.compact) return `${v < 0 ? '-' : ''}${body} ${cur}`;\n return new Intl.NumberFormat(I18N.locale, {\n style: 'currency',\n currency: cur,\n // narrowSymbol writes TWD as a bare 「$」, which reads as dollars: keep 「NT$」 (docs: 英文介面顯示 NT$486,000).\n currencyDisplay: cur === 'TWD' ? 'symbol' : 'narrowSymbol',\n minimumFractionDigits: 0,\n maximumFractionDigits: cur === 'TWD' || cur === 'JPY' ? 0 : 2,\n }).format(v);\n}\n\n/** Bytes to 「186 KB」「54.9 MB」「1.2 GB」. */\nexport function fileSize(b: number | null | undefined): string {\n if (b == null || Number.isNaN(b)) return '';\n // An empty file is 0 KB; anything else at least 1 KB.\n // Compare after rounding: 1,048,500 bytes rounds to 1,024 KB, so it is written 「1.0 MB」.\n if (Math.round(b / 1024) < 1024) return number(b === 0 ? 0 : Math.max(1, Math.round(b / 1024))) + ' KB';\n if (Math.round((b / 1048576) * 10) < 10240) return number(b / 1048576, 1) + ' MB';\n return number(b / 1073741824, 1) + ' GB';\n}\n\n/** Seconds as a clock-style length: under 1 h 「46:42」「1:30」 (minutes not zero-padded), 1 h or more 「1:54:49」.\n * Rounded to the second. Negative, NaN or missing: 「—」. */\nfunction duration(seconds: number | null | undefined): string {\n if (seconds == null || Number.isNaN(seconds) || seconds < 0 || !Number.isFinite(seconds)) return '—';\n const t = Math.round(seconds);\n const h = Math.floor(t / 3600);\n const m = Math.floor((t % 3600) / 60);\n const s = t % 60;\n return h ? `${h}:${pad2(m)}:${pad2(s)}` : `${m}:${pad2(s)}`;\n}\n\n/** Shortens a path: keeps the first segment and the last two, 「src/…/hooks/ops.c:58」. */\nfunction path(p: string | null | undefined, o: { head?: number; tail?: number } = {}): string {\n const head = o.head ?? 1;\n const tail = o.tail ?? 2;\n const parts = String(p ?? '').split('/');\n return parts.length > head + tail ? `${parts.slice(0, head).join('/')}/…/${parts.slice(-tail).join('/')}` : String(p ?? '');\n}\n\n/** A part of a whole, as shown: 「1 / 1 個」「6 / 6 筆」, or 「1 / 5」 without a unit. Give screen readers\n * `fractionLabel` with it: they read the slash as 「斜線」. */\nfunction fraction(n: number, total: number, unit?: string): string {\n return tr(unit ? '{n} / {total} {unit}' : '{n} / {total}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** The same fraction as read aloud: 「1 個中的 1 個」「6 筆中的 6 筆」, or 「5 中的 1」 without a unit (English:\n * 「1 of 1」). For `aria-label`, or for visually hidden text beside the shown fraction. */\nfunction fractionLabel(n: number, total: number, unit?: string): string {\n return tr(unit ? '{total} {unit}中的 {n} {unit}' : '{total} 中的 {n}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** Every date, number, amount, size and path shown in the UI goes through these. */\nexport const format = {\n locale,\n date,\n time,\n dateTime,\n relative,\n month,\n weekdays,\n firstDay,\n number,\n percent,\n compact,\n money,\n fileSize,\n duration,\n path,\n fraction,\n fractionLabel,\n};\n\n/* Calendar helpers (local dates, no time). */\nexport const fmtDate = (d: Date | null | undefined): string => (d ? `${d.getFullYear()}/${pad2(d.getMonth() + 1)}/${pad2(d.getDate())}` : '');\n\nexport function parseDate(s: string | null | undefined): Date | null {\n const m = /^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})$/.exec(s || '');\n if (!m) return null;\n const d = new Date(+m[1], +m[2] - 1, +m[3]);\n return d.getMonth() === +m[2] - 1 ? d : null;\n}\n\nexport const sameDay = (a: Date | null | undefined, b: Date | null | undefined): boolean =>\n !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n\nexport const dayAdd = (d: Date, n: number): Date => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);\n"],"mappings":";;AAOA,MAAM,WAAW;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;CAAG,OAAO;AAAE;AAE3D,MAAM,QAAQ,MAAsB,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;AAE7D,SAAS,SAAiB;CACxB,OAAO,KAAK;AACd;;AAGA,SAAS,KAAK,GAA4B,IAA2C,CAAC,GAAW;CAC/F,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,KAAK,EAAE,YAAY;CACzB,IAAI,EAAE,MAAM,OAAO,IAAI,KAAK,eAAe,KAAK,QAAQ;EAAE,MAAM;EAAW,OAAO;EAAQ,KAAK;EAAW,SAAS,KAAK,SAAS,KAAA;CAAU,CAAC,CAAC,CAAC,OAAO,CAAC;CACtJ,IAAI,OAAO,GAAG,OAAO,QAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,eAAe,SAAS,EAAE,SAAS,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAA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;AAE1I,SAAgB,UAAU,GAA2C;CACnE,MAAM,IAAI,kCAAkC,KAAK,KAAK,EAAE;CACxD,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;CAC1C,OAAO,EAAE,SAAS,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI;AAC1C;AAEA,MAAa,WAAW,GAA4B,MAClD,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,MAAM,EAAE,YAAY,KAAK,EAAE,SAAS,MAAM,EAAE,SAAS,KAAK,EAAE,QAAQ,MAAM,EAAE,QAAQ;AAElH,MAAa,UAAU,GAAS,MAAoB,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,IAAI,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,8 +13,8 @@ import { Calendar } from "./components/Calendar/Calendar.js";
|
|
|
13
13
|
import { Card } from "./components/Card/Card.js";
|
|
14
14
|
import { Checkbox } from "./components/Checkbox/Checkbox.js";
|
|
15
15
|
import { CodeView } from "./components/CodeView/CodeView.js";
|
|
16
|
-
import { focusMain } from "./internal/focusMain.js";
|
|
17
16
|
import { CommandPalette } from "./components/CommandPalette/CommandPalette.js";
|
|
17
|
+
import { focusMain } from "./internal/focusMain.js";
|
|
18
18
|
import { DangerZone } from "./components/DangerZone/DangerZone.js";
|
|
19
19
|
import { DataTable } from "./components/DataTable/DataTable.js";
|
|
20
20
|
import { DatePicker } from "./components/DatePicker/DatePicker.js";
|
|
@@ -22,8 +22,8 @@ import { DateRangePicker } from "./components/DateRangePicker/DateRangePicker.js
|
|
|
22
22
|
import { DetailList } from "./components/DetailList/DetailList.js";
|
|
23
23
|
import { Dialog } from "./components/Dialog/Dialog.js";
|
|
24
24
|
import { SplitPane } from "./components/SplitPane/SplitPane.js";
|
|
25
|
-
import { format } from "./format.js";
|
|
26
25
|
import { Drawer } from "./components/Drawer/Drawer.js";
|
|
26
|
+
import { format } from "./format.js";
|
|
27
27
|
import { EmptyState } from "./components/EmptyState/EmptyState.js";
|
|
28
28
|
import { ErrorPage } from "./components/ErrorPage/ErrorPage.js";
|
|
29
29
|
import { FileUpload } from "./components/FileUpload/FileUpload.js";
|
package/dist/internal/Field.js
CHANGED
|
@@ -3,6 +3,7 @@ import { CHECK, Icon } from "../icons/Icon.js";
|
|
|
3
3
|
import { cx } from "./util.js";
|
|
4
4
|
import { includeIcons } from "../icons/store.js";
|
|
5
5
|
import warning_circle_default from "../icons/ph/warning-circle.js";
|
|
6
|
+
import { codeText } from "../components/InlineCode/InlineCode.js";
|
|
6
7
|
import * as React from "react";
|
|
7
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
// src/internal/Field.tsx
|
|
@@ -61,12 +62,12 @@ function FieldMessage({ id, error, hint, className }) {
|
|
|
61
62
|
id,
|
|
62
63
|
className: cx("ui-field-error", className),
|
|
63
64
|
role: "alert",
|
|
64
|
-
children: error
|
|
65
|
+
children: codeText(error)
|
|
65
66
|
}, error);
|
|
66
67
|
return hint ? /* @__PURE__ */ jsx("div", {
|
|
67
68
|
id,
|
|
68
69
|
className: cx("ui-field-hint", className),
|
|
69
|
-
children: hint
|
|
70
|
+
children: codeText(hint)
|
|
70
71
|
}) : null;
|
|
71
72
|
}
|
|
72
73
|
export { CheckMark, FieldErrorIcon, FieldLabel, FieldMessage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","names":["phWarningCircle"],"sources":["../../src/internal/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { CHECK, Icon } from '../icons/Icon';\nimport { cx } from './util';\nimport { includeIcons } from '../icons/store';\nimport phWarningCircle from '../icons/ph/warning-circle';\n\nincludeIcons(phWarningCircle);\n\n/** A field's label above it, with the red asterisk when required. A <label> when it names one input, otherwise a <span>. */\nexport function FieldLabel({ htmlFor, id, required, children }: { htmlFor?: string; id?: string; required?: boolean; children: React.ReactNode }) {\n const Tag = htmlFor ? 'label' : 'span';\n return (\n <Tag htmlFor={htmlFor} id={id} className=\"ui-field-label\">\n {children}\n {required ? (\n <span className=\"ui-req\" aria-hidden=\"true\">\n {' *'}\n </span>\n ) : null}\n </Tag>\n );\n}\n\n/** The mark inside a check box: a drawn check, a dash for 'mixed', or nothing. The check draws itself only when it\n * turns on after mount, never when a list or menu opens with it already on. */\nexport function CheckMark({ v }: { v: boolean | 'mixed' }) {\n const [prev, setPrev] = React.useState(v);\n const [draw, setDraw] = React.useState(false);\n if (prev !== v) {\n setPrev(v);\n setDraw(v === true);\n }\n if (v === 'mixed') return <span className=\"ui-check-dash\" />;\n if (!v) return null;\n return (\n <svg\n className={cx(draw && 'ui-draw')}\n width={14}\n height={14}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={3.5}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d={CHECK} />\n </svg>\n );\n}\n\n/** The error mark inside a field with an error: a red warning circle at the field's right end (TextField and every other\n * field type, so an error always shows the red border and this icon). `inline` sits in a flex row before the field's\n * own trailing button (show password, calendar, caret) instead of over the input. */\nexport function FieldErrorIcon({ inline }: { inline?: boolean }) {\n return <Icon name=\"warning-circle\" className={cx('ui-field-icon', inline && 'is-inline')} />;\n}\n\n/** The line under a field: the error (cause and fix) when there is one, otherwise the hint. The error is inserted only\n * while there is one, keyed by its text: a new error is a new alert node, announced once; the hint never announces. */\nexport function FieldMessage({ id, error, hint, className }: { id: string; error?: string; hint?: React.ReactNode; className?: string }) {\n if (error)\n return (\n <div key={error} id={id} className={cx('ui-field-error', className)} role=\"alert\">\n {error}\n </div>\n );\n return hint ? (\n <div id={id} className={cx('ui-field-hint', className)}>\n {hint}\n </div>\n ) : null;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Field.js","names":["phWarningCircle"],"sources":["../../src/internal/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { CHECK, Icon } from '../icons/Icon';\nimport { cx } from './util';\nimport { includeIcons } from '../icons/store';\nimport phWarningCircle from '../icons/ph/warning-circle';\nimport { codeText } from '../components/InlineCode/InlineCode';\n\nincludeIcons(phWarningCircle);\n\n/** A field's label above it, with the red asterisk when required. A <label> when it names one input, otherwise a <span>. */\nexport function FieldLabel({ htmlFor, id, required, children }: { htmlFor?: string; id?: string; required?: boolean; children: React.ReactNode }) {\n const Tag = htmlFor ? 'label' : 'span';\n return (\n <Tag htmlFor={htmlFor} id={id} className=\"ui-field-label\">\n {children}\n {required ? (\n <span className=\"ui-req\" aria-hidden=\"true\">\n {' *'}\n </span>\n ) : null}\n </Tag>\n );\n}\n\n/** The mark inside a check box: a drawn check, a dash for 'mixed', or nothing. The check draws itself only when it\n * turns on after mount, never when a list or menu opens with it already on. */\nexport function CheckMark({ v }: { v: boolean | 'mixed' }) {\n const [prev, setPrev] = React.useState(v);\n const [draw, setDraw] = React.useState(false);\n if (prev !== v) {\n setPrev(v);\n setDraw(v === true);\n }\n if (v === 'mixed') return <span className=\"ui-check-dash\" />;\n if (!v) return null;\n return (\n <svg\n className={cx(draw && 'ui-draw')}\n width={14}\n height={14}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={3.5}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d={CHECK} />\n </svg>\n );\n}\n\n/** The error mark inside a field with an error: a red warning circle at the field's right end (TextField and every other\n * field type, so an error always shows the red border and this icon). `inline` sits in a flex row before the field's\n * own trailing button (show password, calendar, caret) instead of over the input. */\nexport function FieldErrorIcon({ inline }: { inline?: boolean }) {\n return <Icon name=\"warning-circle\" className={cx('ui-field-icon', inline && 'is-inline')} />;\n}\n\n/** The line under a field: the error (cause and fix) when there is one, otherwise the hint. The error is inserted only\n * while there is one, keyed by its text: a new error is a new alert node, announced once; the hint never announces. */\nexport function FieldMessage({ id, error, hint, className }: { id: string; error?: string; hint?: React.ReactNode; className?: string }) {\n if (error)\n return (\n <div key={error} id={id} className={cx('ui-field-error', className)} role=\"alert\">\n {codeText(error)}\n </div>\n );\n return hint ? (\n <div id={id} className={cx('ui-field-hint', className)}>\n {codeText(hint)}\n </div>\n ) : null;\n}\n"],"mappings":";;;;;;;;;AAOA,aAAaA,sBAAe;;AAG5B,SAAgB,WAAW,EAAE,SAAS,IAAI,UAAU,YAA8F;CAEhJ,OACE,qBAFU,UAAU,UAAU,QAE9B;EAAc;EAAa;EAAI,WAAU;EAAzC,UAAA,CACG,UACA,WACC,oBAAC,QAAD;GAAM,WAAU;GAAS,eAAY;GAClC,UAAA;EACG,CAAA,IACJ,IACD;;AAET;;;AAIA,SAAgB,UAAU,EAAE,KAA+B;CACzD,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,CAAC;CACxC,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,IAAI,SAAS,GAAG;EACd,QAAQ,CAAC;EACT,QAAQ,MAAM,IAAI;CACpB;CACA,IAAI,MAAM,SAAS,OAAO,oBAAC,QAAD,EAAM,WAAU,gBAAiB,CAAA;CAC3D,IAAI,CAAC,GAAG,OAAO;CACf,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,QAAQ,SAAS;EAC/B,OAAO;EACP,QAAQ;EACR,SAAQ;EACR,MAAK;EACL,QAAO;EACP,aAAa;EACb,eAAc;EACd,gBAAe;EACf,eAAY;EAEZ,UAAA,oBAAC,QAAD,EAAM,GAAG,MAAQ,CAAA;CACd,CAAA;AAET;;;;AAKA,SAAgB,eAAe,EAAE,UAAgC;CAC/D,OAAO,oBAAC,MAAD;EAAM,MAAK;EAAiB,WAAW,GAAG,iBAAiB,UAAU,WAAW;CAAI,CAAA;AAC7F;;;AAIA,SAAgB,aAAa,EAAE,IAAI,OAAO,MAAM,aAAyF;CACvI,IAAI,OACF,OACE,oBAAC,OAAD;EAAqB;EAAI,WAAW,GAAG,kBAAkB,SAAS;EAAG,MAAK;EACvE,UAAA,SAAS,KAAK;CACZ,GAFK,KAEL;CAET,OAAO,OACL,oBAAC,OAAD;EAAS;EAAI,WAAW,GAAG,iBAAiB,SAAS;EAClD,UAAA,SAAS,IAAI;CACX,CAAA,IACH;AACN"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/internal/codeSpans.ts
|
|
3
|
+
const PAIR = /(`[^`]+`)/;
|
|
4
|
+
/** Cuts a text written as in Markdown into plain and code pieces. Only a pair of backticks around at least one character
|
|
5
|
+
* is code; a lone backtick stays in the text. Shared by CodeText, the sentence props that take a string and LayerGraph
|
|
6
|
+
* labels, so every component reads backticks the same way. */
|
|
7
|
+
function codeSpans(text) {
|
|
8
|
+
return String(text ?? "").split(PAIR).map((t, i) => i % 2 ? {
|
|
9
|
+
code: true,
|
|
10
|
+
text: t.slice(1, -1)
|
|
11
|
+
} : {
|
|
12
|
+
code: false,
|
|
13
|
+
text: t
|
|
14
|
+
}).filter((s) => s.text !== "");
|
|
15
|
+
}
|
|
16
|
+
/** True when the text has at least one `code` span. */
|
|
17
|
+
const hasCodeSpan = (text) => !!text && PAIR.test(text);
|
|
18
|
+
export { codeSpans, hasCodeSpan };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=codeSpans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeSpans.js","names":[],"sources":["../../src/internal/codeSpans.ts"],"sourcesContent":["/** One piece of a text with `backtick` spans: plain text, or the code between a pair of backticks (without them). */\nexport interface CodeSpan {\n code: boolean;\n text: string;\n}\n\nconst PAIR = /(`[^`]+`)/;\n\n/** Cuts a text written as in Markdown into plain and code pieces. Only a pair of backticks around at least one character\n * is code; a lone backtick stays in the text. Shared by CodeText, the sentence props that take a string and LayerGraph\n * labels, so every component reads backticks the same way. */\nexport function codeSpans(text: string | null | undefined): CodeSpan[] {\n // split with a capture group: the pieces at odd indexes are the matched pairs.\n return String(text ?? '')\n .split(PAIR)\n .map((t, i) => (i % 2 ? { code: true, text: t.slice(1, -1) } : { code: false, text: t }))\n .filter((s) => s.text !== '');\n}\n\n/** True when the text has at least one `code` span. */\nexport const hasCodeSpan = (text: string | null | undefined): boolean => !!text && PAIR.test(text);\n"],"mappings":";;AAMA,MAAM,OAAO;;;;AAKb,SAAgB,UAAU,MAA6C;CAErE,OAAO,OAAO,QAAQ,EAAE,CAAC,CACtB,MAAM,IAAI,CAAC,CACX,KAAK,GAAG,MAAO,IAAI,IAAI;EAAE,MAAM;EAAM,MAAM,EAAE,MAAM,GAAG,EAAE;CAAE,IAAI;EAAE,MAAM;EAAO,MAAM;CAAE,CAAE,CAAC,CACxF,QAAQ,MAAM,EAAE,SAAS,EAAE;AAChC;;AAGA,MAAa,eAAe,SAA6C,CAAC,CAAC,QAAQ,KAAK,KAAK,IAAI"}
|