@seanyeh77/ui 0.23.0 → 0.25.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 -10
- package/dist/bundle.js.map +1 -1
- package/dist/index.js +103 -74
- package/dist/index.js.map +1 -1
- package/dist/styles.css +108 -18
- package/dist/tokens.css +7 -7
- package/docs/DataTable.md +10 -3
- package/docs/guidelines.md +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ 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";
|
|
9
10
|
import { Popover as Popover$1 } from "@base-ui/react/popover";
|
|
10
11
|
import { Combobox } from "@base-ui/react/combobox";
|
|
11
12
|
import { Select as Select$1 } from "@base-ui/react/select";
|
|
@@ -1264,9 +1265,9 @@ const SWATCHES = [
|
|
|
1264
1265
|
["紫", "#8a4fd6"],
|
|
1265
1266
|
["桃紅", "#c2407a"],
|
|
1266
1267
|
["紅", "#cd3a2f"],
|
|
1267
|
-
["橘", "#
|
|
1268
|
-
["綠", "#
|
|
1269
|
-
["青", "#
|
|
1268
|
+
["橘", "#b85a0e"],
|
|
1269
|
+
["綠", "#1a844a"],
|
|
1270
|
+
["青", "#0e827d"]
|
|
1270
1271
|
];
|
|
1271
1272
|
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
1272
1273
|
/** 8 swatches plus a hex field for any color. */
|
|
@@ -3211,10 +3212,11 @@ function ColResize(p) {
|
|
|
3211
3212
|
}
|
|
3212
3213
|
});
|
|
3213
3214
|
}
|
|
3214
|
-
/** The 「放大表格」 icon: 32 px, no border, at
|
|
3215
|
-
|
|
3215
|
+
/** The 「放大表格」 icon: 32 px, no border, at a Markdown table's top right; in a DataTable's toolbar (inToolbar) it is a
|
|
3216
|
+
* toolbar button like 「複製成 Markdown」. */
|
|
3217
|
+
function ZoomButton({ onClick, inToolbar }) {
|
|
3216
3218
|
return /* @__PURE__ */ jsx(IconButton, {
|
|
3217
|
-
className: "ui-table-zoom",
|
|
3219
|
+
className: inToolbar ? "ui-dt-zoombtn" : "ui-table-zoom",
|
|
3218
3220
|
icon: "corners-out",
|
|
3219
3221
|
label: tr("放大表格"),
|
|
3220
3222
|
onClick
|
|
@@ -3451,10 +3453,14 @@ function ColumnMenu({ cols, hidden, onToggle }) {
|
|
|
3451
3453
|
trigger: /* @__PURE__ */ jsxs("button", {
|
|
3452
3454
|
type: "button",
|
|
3453
3455
|
className: cx("ui-btn", "ui-btn-secondary", "ui-dt-colbtn", open && "is-open"),
|
|
3456
|
+
"aria-label": tr("欄位"),
|
|
3454
3457
|
children: [/* @__PURE__ */ jsx(Icon, {
|
|
3455
3458
|
name: "columns",
|
|
3456
3459
|
size: 18
|
|
3457
|
-
}),
|
|
3460
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
3461
|
+
className: "ui-dt-btntext",
|
|
3462
|
+
children: tr("欄位")
|
|
3463
|
+
})]
|
|
3458
3464
|
}),
|
|
3459
3465
|
children: [/* @__PURE__ */ jsx("div", {
|
|
3460
3466
|
className: "ui-noti-group",
|
|
@@ -3497,7 +3503,10 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear,
|
|
|
3497
3503
|
name: "funnel",
|
|
3498
3504
|
size: 18
|
|
3499
3505
|
}),
|
|
3500
|
-
|
|
3506
|
+
/* @__PURE__ */ jsx("span", {
|
|
3507
|
+
className: "ui-dt-btntext",
|
|
3508
|
+
children: tr("篩選")
|
|
3509
|
+
}),
|
|
3501
3510
|
activeCount ? /* @__PURE__ */ jsx("span", {
|
|
3502
3511
|
className: "ui-pop-count",
|
|
3503
3512
|
children: activeCount
|
|
@@ -3679,7 +3688,7 @@ function sortSentence(levels, cols) {
|
|
|
3679
3688
|
return tr("依 {list} 排序", { list: levels.map((l) => name(l.key) + " " + dirWord(l.dir)).join(tr(",再依 ")) });
|
|
3680
3689
|
}
|
|
3681
3690
|
/** The toolbar's 「排序」 button: it shows the current sort and opens a panel to add, order, flip and remove levels. */
|
|
3682
|
-
function SortButton({ cols, levels, max, onChange, boundary
|
|
3691
|
+
function SortButton({ cols, levels, max, onChange, boundary }) {
|
|
3683
3692
|
const [open, setOpen] = React.useState(false);
|
|
3684
3693
|
const [adding, setAdding] = React.useState(false);
|
|
3685
3694
|
const [drag, setDrag] = React.useState(null);
|
|
@@ -3721,11 +3730,17 @@ function SortButton({ cols, levels, max, onChange, boundary, short }) {
|
|
|
3721
3730
|
}),
|
|
3722
3731
|
/* @__PURE__ */ jsx("span", {
|
|
3723
3732
|
className: "ui-dt-sortbtn-text",
|
|
3724
|
-
children:
|
|
3733
|
+
children: levels.length ? tr("排序:{list}", { list: shown }) : tr("排序")
|
|
3725
3734
|
}),
|
|
3726
|
-
|
|
3727
|
-
className: "ui-
|
|
3728
|
-
children:
|
|
3735
|
+
levels.length ? /* @__PURE__ */ jsxs("span", {
|
|
3736
|
+
className: "ui-dt-sortbtn-short",
|
|
3737
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3738
|
+
className: "ui-dt-btntext",
|
|
3739
|
+
children: tr("排序")
|
|
3740
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
3741
|
+
className: "ui-pop-count",
|
|
3742
|
+
children: levels.length
|
|
3743
|
+
})]
|
|
3729
3744
|
}) : null
|
|
3730
3745
|
]
|
|
3731
3746
|
}),
|
|
@@ -3965,6 +3980,12 @@ function DataTable(p) {
|
|
|
3965
3980
|
const [zoomed, setZoomed] = React.useState(false);
|
|
3966
3981
|
const [zoomWidths, setZoomWidths] = React.useState(null);
|
|
3967
3982
|
const zoomRef = React.useRef(null);
|
|
3983
|
+
const [headSlot, setHeadSlot] = React.useState(null);
|
|
3984
|
+
const noSearch = search === false && !p.caption;
|
|
3985
|
+
React.useLayoutEffect(() => {
|
|
3986
|
+
const prev = noSearch ? rootRef.current?.previousElementSibling : null;
|
|
3987
|
+
setHeadSlot(prev instanceof HTMLElement && prev.classList.contains("ui-card-head") && prev.parentElement?.classList.contains("ui-card") ? prev : null);
|
|
3988
|
+
}, [noSearch]);
|
|
3968
3989
|
const [resetKey, setResetKey] = React.useState(p.resetKey);
|
|
3969
3990
|
const resetting = resetKey !== p.resetKey;
|
|
3970
3991
|
if (resetting) {
|
|
@@ -4432,9 +4453,13 @@ function DataTable(p) {
|
|
|
4432
4453
|
if (p.copyText) return p.copyText(all);
|
|
4433
4454
|
return markdownTable(shownCols.map((c) => c.label), all.map((r) => shownCols.map((c) => String(c.fullText?.(r) ?? c.searchText?.(r) ?? cellText(c, get(r, c.key)) ?? ""))));
|
|
4434
4455
|
};
|
|
4435
|
-
const toolsView = (inZoom) => /* @__PURE__ */ jsxs("div", {
|
|
4436
|
-
className: "ui-dt-tools",
|
|
4456
|
+
const toolsView = (inZoom, inHead = false) => /* @__PURE__ */ jsxs("div", {
|
|
4457
|
+
className: cx("ui-dt-tools", inHead && "is-inhead"),
|
|
4437
4458
|
children: [
|
|
4459
|
+
search === false && p.caption && !inZoom && !inHead ? /* @__PURE__ */ jsx("div", {
|
|
4460
|
+
className: "ui-dt-caption",
|
|
4461
|
+
children: p.caption
|
|
4462
|
+
}) : null,
|
|
4438
4463
|
search !== false ? /* @__PURE__ */ jsx(SearchField, {
|
|
4439
4464
|
value: q,
|
|
4440
4465
|
onChange: (v) => {
|
|
@@ -4445,57 +4470,65 @@ function DataTable(p) {
|
|
|
4445
4470
|
label: search.placeholder || tr("搜尋"),
|
|
4446
4471
|
className: "ui-dt-search"
|
|
4447
4472
|
}) : null,
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4473
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4474
|
+
className: "ui-dt-actions",
|
|
4475
|
+
children: [
|
|
4476
|
+
filters.length ? /* @__PURE__ */ jsx(FilterButton, {
|
|
4477
|
+
boundary: inZoom ? zoomRef : rootRef,
|
|
4478
|
+
filters,
|
|
4479
|
+
values,
|
|
4480
|
+
activeCount: activeN,
|
|
4481
|
+
count: (f, v) => all.filter((x) => passes(x.r, f.key) && matches(f, x.r, f.type === "list" ? [v] : void 0)).length,
|
|
4482
|
+
onChange: (key, v) => {
|
|
4483
|
+
setValues({
|
|
4484
|
+
...values,
|
|
4485
|
+
[key]: v
|
|
4486
|
+
});
|
|
4487
|
+
setPage(0);
|
|
4488
|
+
},
|
|
4489
|
+
onClear: () => {
|
|
4490
|
+
setValues({});
|
|
4491
|
+
setPage(0);
|
|
4492
|
+
}
|
|
4493
|
+
}) : null,
|
|
4494
|
+
/* @__PURE__ */ jsxs("span", {
|
|
4495
|
+
className: "ui-dt-result",
|
|
4496
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4497
|
+
"aria-hidden": "true",
|
|
4498
|
+
children: seenOnly(tr("{n} / {total} 筆", {
|
|
4499
|
+
n: "",
|
|
4500
|
+
total: ""
|
|
4501
|
+
}), [format.number(list.length), format.number(baseCount)])
|
|
4502
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4503
|
+
className: "ui-visually-hidden",
|
|
4504
|
+
children: format.fractionLabel(list.length, baseCount, tr("筆"))
|
|
4505
|
+
})]
|
|
4506
|
+
}),
|
|
4507
|
+
p.copy !== false && !narrow ? /* @__PURE__ */ jsx(CopyMarkdownButton, {
|
|
4508
|
+
text: copyMarkdown,
|
|
4509
|
+
onCopyError: p.onCopyError
|
|
4510
|
+
}) : null,
|
|
4511
|
+
sortCols.length ? /* @__PURE__ */ jsx(SortButton, {
|
|
4512
|
+
cols: sortCols,
|
|
4513
|
+
levels: sort,
|
|
4514
|
+
max: maxSort,
|
|
4515
|
+
onChange: changeSort,
|
|
4516
|
+
boundary: inZoom ? zoomRef : rootRef
|
|
4517
|
+
}) : null,
|
|
4518
|
+
p.columnMenu !== false && cols.length > 2 ? /* @__PURE__ */ jsx(ColumnMenu, {
|
|
4519
|
+
cols,
|
|
4520
|
+
hidden,
|
|
4521
|
+
onToggle: (k) => setToggled({
|
|
4522
|
+
...toggled,
|
|
4523
|
+
[k]: !hidden[k]
|
|
4524
|
+
})
|
|
4525
|
+
}) : null,
|
|
4526
|
+
p.zoom !== false && !narrow && !inZoom ? /* @__PURE__ */ jsx(ZoomButton, {
|
|
4527
|
+
inToolbar: true,
|
|
4528
|
+
onClick: () => setZoomed(true)
|
|
4529
|
+
}) : null
|
|
4530
|
+
]
|
|
4531
|
+
})
|
|
4499
4532
|
]
|
|
4500
4533
|
});
|
|
4501
4534
|
const tableView = (inZoom) => {
|
|
@@ -4504,7 +4537,7 @@ function DataTable(p) {
|
|
|
4504
4537
|
return /* @__PURE__ */ jsx("div", {
|
|
4505
4538
|
className: cx("ui-dt-scroller", scrollMore && !inZoom && "has-more"),
|
|
4506
4539
|
children: /* @__PURE__ */ jsx("div", {
|
|
4507
|
-
className: "ui-dt-scroll",
|
|
4540
|
+
className: cx("ui-dt-scroll", pages > 1 && "is-paged"),
|
|
4508
4541
|
ref: inZoom ? void 0 : scrollRef,
|
|
4509
4542
|
onScroll: inZoom ? void 0 : onScroll,
|
|
4510
4543
|
children: /* @__PURE__ */ jsxs("div", {
|
|
@@ -4690,9 +4723,9 @@ function DataTable(p) {
|
|
|
4690
4723
|
}) : null });
|
|
4691
4724
|
return /* @__PURE__ */ jsxs("div", {
|
|
4692
4725
|
ref: rootRef,
|
|
4693
|
-
className: cx("ui-dt", selIds.length && "has-sel", p.className),
|
|
4726
|
+
className: cx("ui-dt", search === false && "is-nosearch", selIds.length && "has-sel", p.className),
|
|
4694
4727
|
children: [
|
|
4695
|
-
p.caption ? /* @__PURE__ */ jsx("div", {
|
|
4728
|
+
p.caption && search !== false ? /* @__PURE__ */ jsx("div", {
|
|
4696
4729
|
className: "ui-dt-caption",
|
|
4697
4730
|
children: p.caption
|
|
4698
4731
|
}) : null,
|
|
@@ -4746,11 +4779,7 @@ function DataTable(p) {
|
|
|
4746
4779
|
count: sumAll.filter((x) => String(get(x.r, summary.key)) === String(it.value)).length
|
|
4747
4780
|
}))]
|
|
4748
4781
|
}) : null,
|
|
4749
|
-
toolsView(false),
|
|
4750
|
-
p.zoom !== false && !narrow ? /* @__PURE__ */ jsx("div", {
|
|
4751
|
-
className: "ui-dt-zoom",
|
|
4752
|
-
children: /* @__PURE__ */ jsx(ZoomButton, { onClick: () => setZoomed(true) })
|
|
4753
|
-
}) : null,
|
|
4782
|
+
headSlot ? createPortal(toolsView(false, true), headSlot) : toolsView(false),
|
|
4754
4783
|
tableView(false),
|
|
4755
4784
|
/* @__PURE__ */ jsx(ScrollHint, {
|
|
4756
4785
|
show: overflows,
|