@septkit/ui 0.0.95 → 0.0.96
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/README.md +68 -0
- package/dist/bulk-edit/bulk-edit-field.js +5 -0
- package/dist/bulk-edit/bulk-edit-field.vue_vue_type_script_setup_true_lang.js +40 -0
- package/dist/bulk-edit/bulk-edit-panel.js +5 -0
- package/dist/bulk-edit/bulk-edit-panel.vue_vue_type_script_setup_true_lang.js +56 -0
- package/dist/bulk-edit/index.js +5 -0
- package/dist/bulk-edit/summarize-values.js +15 -0
- package/dist/bulk-edit/use-bulk-edit-form.js +41 -0
- package/dist/index.d.ts +254 -68
- package/dist/index.js +26 -18
- package/dist/table/filterable-column-header.js +1 -1
- package/dist/table/filterable-column-header.vue_vue_type_script_setup_true_lang.js +17 -4
- package/dist/table/index.js +6 -2
- package/dist/table/selection/index.js +4 -0
- package/dist/table/selection/selection-checkbox.js +5 -0
- package/dist/table/selection/selection-checkbox.vue_vue_type_script_setup_true_lang.js +40 -0
- package/dist/table/selection/selection-toolbar.js +5 -0
- package/dist/table/selection/selection-toolbar.vue_vue_type_script_setup_true_lang.js +59 -0
- package/dist/table/selection/use-row-selection.js +48 -0
- package/dist/ui.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# SET ui library
|
|
2
2
|
|
|
3
|
+
## Shared table: column filter and sort
|
|
4
|
+
|
|
5
|
+
Filter and sort mechanics for TanStack-based tables, extracted from Label Manager and Network
|
|
6
|
+
([ADR-0026](../../doc/adr/0026-shared-table-filter-and-sort-components.md)). Lives in
|
|
7
|
+
`lib/table/`. It renders the filter popover and the sort button; rows, columns and matching rules
|
|
8
|
+
stay with the extension.
|
|
9
|
+
|
|
10
|
+
- **Option builders** (`lib/table/filters/build-filter-options.ts`): framework-free
|
|
11
|
+
`buildTreeOptions`, `buildFlatOptions`, `buildMultiValueOptions`, `collectLeafKeys`,
|
|
12
|
+
`collectParentKeys`, `filterTree` and the `KEY_SEPARATOR` / `NO_VALUE_KEY` sentinels.
|
|
13
|
+
- `useColumnFilters({ columns, rows, strategies })`: per-column selection state, AND-combined
|
|
14
|
+
across columns (`predicate(row)`), plus `apply`, `reset`, `resetAll`, `isColumnActive`,
|
|
15
|
+
`getSelection`, `getAllKeys`. Each column supplies a `ColumnFilterStrategy` (`keyUniverse`,
|
|
16
|
+
`openWithAllSelected`, `matches`, optional `isExtraActive` and `onReset`). `openWithAllSelected`
|
|
17
|
+
`true` opens a column fully checked and collapses a full selection back to inactive;
|
|
18
|
+
`false` opens it empty and activates on the first tick.
|
|
19
|
+
- `useRowSort({ sortAccessors })`: explicit sort, ascending, descending, off (original order).
|
|
20
|
+
A column is sortable only when it has an accessor; `apply(rows)` returns the sorted copy.
|
|
21
|
+
- `FilterableColumnHeader` (`columnId`, `title`): header cell with funnel and optional sort
|
|
22
|
+
button; the popover is teleported, viewport-aware and focus-trapped.
|
|
23
|
+
- **Adapters**: the header reads two injected models, not a concrete controller. Provide
|
|
24
|
+
`provideColumnFilterHeader(model: ColumnFilterHeaderModel)` (required) and
|
|
25
|
+
`provideRowSortHeader(model: RowSortHeaderModel)` (optional; without it no sort button is
|
|
26
|
+
shown) in the table's parent, mapping the extension's own controller onto them.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const filters = useColumnFilters(allRows) // extension controller
|
|
30
|
+
provideColumnFilterHeader(createColumnFilterHeaderModel(filters)) // adapter
|
|
31
|
+
provideRowSortHeader(createRowSortHeaderModel(sort)) // optional
|
|
32
|
+
const rows = computed(() => sort.apply(allRows.value.filter(filters.predicate)))
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```vue
|
|
36
|
+
<FilterableColumnHeader column-id="ip" title="IP" />
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Reference adapters: `packages/extensions/network/src/network-table/filters/` (flat columns with
|
|
40
|
+
`(empty)` and sorting) and `packages/extensions/label-manager/src/label-manager-table/filters/`
|
|
41
|
+
(tree, flat and value variants, label language).
|
|
42
|
+
|
|
43
|
+
Because extensions consume the published package (ADR-0007), a change here needs an `@septkit/ui`
|
|
44
|
+
release and a dependency bump before extensions build against it.
|
|
45
|
+
|
|
46
|
+
## Row selection and bulk edit
|
|
47
|
+
|
|
48
|
+
Domain-free building blocks for tables that edit several rows at once. The consuming extension
|
|
49
|
+
supplies rows, rules and the write; nothing here knows about SCL.
|
|
50
|
+
|
|
51
|
+
- `useRowSelection({ allKeys, visibleKeys })` (`lib/table/selection/`): selected keys, counts,
|
|
52
|
+
header state (`none` / `some` / `all`), `toggle`, `toggleAllVisible`, `selectAllVisible`,
|
|
53
|
+
`clear`. Header and select-all act on visible rows only; a selected row hidden by a filter stays
|
|
54
|
+
selected; keys that leave `allKeys` are dropped at once.
|
|
55
|
+
- `SelectionCheckbox` (row and header checkbox with `indeterminate`) and `SelectionToolbar`
|
|
56
|
+
(hint, "N selected of M", select all, clear, locked text, `notice` slot, "Bulk edit" button).
|
|
57
|
+
- `summarizeValues(values)` (`lib/bulk-edit/`): `{ kind: 'same', value }` shown as "Same for all N",
|
|
58
|
+
or `{ kind: 'mixed', distinct }` shown as "N different values".
|
|
59
|
+
- `useBulkEditForm({ rows, read, validate })`: field values, `changedFields`, `edit`, `errors`,
|
|
60
|
+
`canApply`, `reset`. A shared value pre-fills its field; a differing one starts empty and, left
|
|
61
|
+
empty, is not part of the edit. `validate(edit, rows)` runs only for changed fields and returns
|
|
62
|
+
`{ fieldErrors, rowErrors }` (`rowErrors`: fields in error per row key, for marking cells).
|
|
63
|
+
`rows` is read reactively: when the rows change, a field whose shared value changed takes the new
|
|
64
|
+
value; typed edits on other fields are kept. A new instance per selection is not required.
|
|
65
|
+
- `BulkEditPanel` (title, footer with "Fix N errors to apply", Cancel, Apply) and `BulkEditField`
|
|
66
|
+
(label, hint or error, changed dot) render the form; the controls go in the slots.
|
|
67
|
+
|
|
68
|
+
Locking the table while editing is up to the consumer. Used by the network extension; meant to be
|
|
69
|
+
reused by the Label Manager update table (#2376).
|
|
70
|
+
|
|
3
71
|
## Package name
|
|
4
72
|
|
|
5
73
|
> [!IMPORTANT]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createCommentVNode as e, createElementBlock as t, createElementVNode as n, createTextVNode as r, defineComponent as i, openBlock as a, renderSlot as o, toDisplayString as s } from "vue";
|
|
2
|
+
//#region lib/bulk-edit/bulk-edit-field.vue?vue&type=script&setup=true&lang.ts
|
|
3
|
+
var c = {
|
|
4
|
+
class: "flex min-w-36 flex-col gap-1",
|
|
5
|
+
"data-testid": "bulk-edit-field"
|
|
6
|
+
}, l = { class: "flex items-center gap-1 font-medium" }, u = {
|
|
7
|
+
key: 0,
|
|
8
|
+
class: "bg-primary inline-block size-1.5 rounded-full",
|
|
9
|
+
title: "Changed",
|
|
10
|
+
"data-testid": "bulk-edit-field-changed"
|
|
11
|
+
}, d = {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "text-error",
|
|
14
|
+
role: "alert",
|
|
15
|
+
"data-testid": "bulk-edit-field-error"
|
|
16
|
+
}, f = {
|
|
17
|
+
key: 1,
|
|
18
|
+
class: "text-base-content/60",
|
|
19
|
+
"data-testid": "bulk-edit-field-hint"
|
|
20
|
+
}, p = /*@__PURE__*/ i({
|
|
21
|
+
__name: "bulk-edit-field",
|
|
22
|
+
props: {
|
|
23
|
+
label: {},
|
|
24
|
+
hint: { default: void 0 },
|
|
25
|
+
error: { default: void 0 },
|
|
26
|
+
changed: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
default: !1
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
setup(i) {
|
|
32
|
+
return (p, m) => (a(), t("div", c, [
|
|
33
|
+
n("span", l, [r(s(i.label) + " ", 1), i.changed ? (a(), t("span", u)) : e("", !0)]),
|
|
34
|
+
o(p.$slots, "default"),
|
|
35
|
+
i.error ? (a(), t("span", d, s(i.error), 1)) : i.hint ? (a(), t("span", f, s(i.hint), 1)) : e("", !0)
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
export { p as default };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import e from "../external/.pnpm/@lucide_vue@1.23.0_vue@3.5.39_typescript@5.8.3_/node_modules/@lucide/vue/dist/esm/icons/x.js";
|
|
2
|
+
import { createCommentVNode as t, createElementBlock as n, createElementVNode as r, createVNode as i, defineComponent as a, openBlock as o, renderSlot as s, toDisplayString as c, unref as l } from "vue";
|
|
3
|
+
//#region lib/bulk-edit/bulk-edit-panel.vue?vue&type=script&setup=true&lang.ts
|
|
4
|
+
var u = {
|
|
5
|
+
class: "border-base-300 bg-base-100 flex flex-col gap-3 border-b px-3 py-3 text-xs",
|
|
6
|
+
"aria-label": "Bulk edit",
|
|
7
|
+
"data-testid": "bulk-edit-panel"
|
|
8
|
+
}, d = { class: "flex items-start justify-between gap-3" }, f = {
|
|
9
|
+
key: 0,
|
|
10
|
+
class: "text-base-content/60 ml-2"
|
|
11
|
+
}, p = { class: "flex flex-wrap items-start gap-4" }, m = { class: "ml-auto flex items-center gap-3 self-end" }, h = {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "text-error",
|
|
14
|
+
role: "status",
|
|
15
|
+
"data-testid": "bulk-edit-error-summary"
|
|
16
|
+
}, g = {
|
|
17
|
+
key: 1,
|
|
18
|
+
class: "text-base-content/60",
|
|
19
|
+
"data-testid": "bulk-edit-no-change"
|
|
20
|
+
}, _ = ["disabled"], v = /*@__PURE__*/ a({
|
|
21
|
+
__name: "bulk-edit-panel",
|
|
22
|
+
props: {
|
|
23
|
+
title: {},
|
|
24
|
+
description: { default: void 0 },
|
|
25
|
+
canApply: { type: Boolean },
|
|
26
|
+
errorCount: {}
|
|
27
|
+
},
|
|
28
|
+
emits: ["apply", "cancel"],
|
|
29
|
+
setup(a, { emit: v }) {
|
|
30
|
+
let y = v;
|
|
31
|
+
return (v, b) => (o(), n("section", u, [r("header", d, [r("p", null, [r("strong", null, c(a.title), 1), a.description ? (o(), n("span", f, c(a.description), 1)) : t("", !0)]), r("button", {
|
|
32
|
+
type: "button",
|
|
33
|
+
class: "btn btn-ghost btn-xs btn-square",
|
|
34
|
+
"aria-label": "Close bulk edit",
|
|
35
|
+
"data-testid": "bulk-edit-close",
|
|
36
|
+
onClick: b[0] ||= (e) => y("cancel")
|
|
37
|
+
}, [i(l(e), { class: "size-3.5" })])]), r("div", p, [s(v.$slots, "default"), r("div", m, [
|
|
38
|
+
a.errorCount > 0 ? (o(), n("span", h, " Fix " + c(a.errorCount) + " " + c(a.errorCount === 1 ? "error" : "errors") + " to apply ", 1)) : a.canApply ? t("", !0) : (o(), n("span", g, " Change a field to apply ")),
|
|
39
|
+
r("button", {
|
|
40
|
+
type: "button",
|
|
41
|
+
class: "btn btn-ghost btn-sm",
|
|
42
|
+
"data-testid": "bulk-edit-cancel",
|
|
43
|
+
onClick: b[1] ||= (e) => y("cancel")
|
|
44
|
+
}, " Cancel "),
|
|
45
|
+
r("button", {
|
|
46
|
+
type: "button",
|
|
47
|
+
class: "btn btn-primary btn-sm",
|
|
48
|
+
disabled: !a.canApply,
|
|
49
|
+
"data-testid": "bulk-edit-apply",
|
|
50
|
+
onClick: b[2] ||= (e) => y("apply")
|
|
51
|
+
}, " Apply ", 8, _)
|
|
52
|
+
])])]));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
//#endregion
|
|
56
|
+
export { v as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import e from "./bulk-edit-panel.js";
|
|
2
|
+
import t from "./bulk-edit-field.js";
|
|
3
|
+
import { summarizeValues as n } from "./summarize-values.js";
|
|
4
|
+
import { useBulkEditForm as r } from "./use-bulk-edit-form.js";
|
|
5
|
+
export { t as BulkEditField, e as BulkEditPanel, n as summarizeValues, r as useBulkEditForm };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region lib/bulk-edit/summarize-values.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = new Set(e);
|
|
4
|
+
return t.size > 1 ? {
|
|
5
|
+
kind: "mixed",
|
|
6
|
+
distinct: t.size,
|
|
7
|
+
hint: `${t.size} different values`
|
|
8
|
+
} : {
|
|
9
|
+
kind: "same",
|
|
10
|
+
value: e[0] ?? "",
|
|
11
|
+
hint: `Same for all ${e.length}`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { e as summarizeValues };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { summarizeValues as e } from "./summarize-values.js";
|
|
2
|
+
import { computed as t, reactive as n, watch as r } from "vue";
|
|
3
|
+
//#region lib/bulk-edit/use-bulk-edit-form.ts
|
|
4
|
+
function i(i) {
|
|
5
|
+
let { rows: a, read: o, validate: s } = i, c = t(() => {
|
|
6
|
+
let [e] = a();
|
|
7
|
+
return e ? Object.keys(o(e)) : [];
|
|
8
|
+
}), l = t(() => {
|
|
9
|
+
let t = a().map(o);
|
|
10
|
+
return Object.fromEntries(c.value.map((n) => [n, e(t.map((e) => e[n]))]));
|
|
11
|
+
}), u = t(() => Object.fromEntries(c.value.map((e) => {
|
|
12
|
+
let t = l.value[e];
|
|
13
|
+
return [e, t.kind === "same" ? t.value : ""];
|
|
14
|
+
}))), d = n({ ...u.value });
|
|
15
|
+
r(u, (e, t) => {
|
|
16
|
+
for (let n of Object.keys(e)) e[n] !== t[n] && (d[n] = e[n]);
|
|
17
|
+
}, { flush: "sync" });
|
|
18
|
+
let f = t(() => c.value.filter((e) => d[e] !== u.value[e])), p = t(() => Object.fromEntries(f.value.map((e) => [e, d[e]]))), m = t(() => f.value.length === 0 ? {
|
|
19
|
+
fieldErrors: {},
|
|
20
|
+
rowErrors: {}
|
|
21
|
+
} : s(p.value, a())), h = t(() => Object.keys(m.value.fieldErrors).length), g = t(() => f.value.length > 0 && h.value === 0);
|
|
22
|
+
function _(e, t) {
|
|
23
|
+
d[e] = t;
|
|
24
|
+
}
|
|
25
|
+
function v() {
|
|
26
|
+
Object.assign(d, u.value);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
values: d,
|
|
30
|
+
summaries: l,
|
|
31
|
+
setValue: _,
|
|
32
|
+
changedFields: f,
|
|
33
|
+
edit: p,
|
|
34
|
+
errors: m,
|
|
35
|
+
errorCount: h,
|
|
36
|
+
canApply: g,
|
|
37
|
+
reset: v
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { i as useBulkEditForm };
|