@kjun-ui/react 0.5.0 → 0.6.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/index.cjs +118 -99
- package/dist/index.js +118 -99
- package/dist/styles.css +2 -2581
- package/dist/types/packages/react/src/controls.d.cts +3 -2
- package/dist/types/packages/react/src/controls.d.ts +3 -2
- package/dist/types/packages/react/src/typography.d.cts +1 -19
- package/dist/types/packages/react/src/typography.d.ts +1 -19
- package/dist/types/shared/package-runtime/group-keyboard.d.cts +7 -0
- package/dist/types/shared/package-runtime/group-keyboard.d.ts +7 -0
- package/dist/types/shared/package-runtime/selection-indicator.d.cts +4 -0
- package/dist/types/shared/package-runtime/selection-indicator.d.ts +4 -0
- package/dist/types/shared/package-runtime/table-model.d.cts +15 -0
- package/dist/types/shared/package-runtime/table-model.d.ts +15 -0
- package/dist/types/shared/package-runtime/table-presentation.d.cts +1 -1
- package/dist/types/shared/package-runtime/table-presentation.d.ts +1 -1
- package/dist/types/shared/package-runtime/table.d.cts +1 -1
- package/dist/types/shared/package-runtime/table.d.ts +1 -1
- package/dist/types/shared/package-runtime/typography.d.cts +19 -0
- package/dist/types/shared/package-runtime/typography.d.ts +19 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -563,7 +563,7 @@ function KjunProvider({
|
|
|
563
563
|
] }) }) }) });
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
-
//
|
|
566
|
+
// shared/package-runtime/typography.ts
|
|
567
567
|
var import_tokens4 = require("@kjun-ui/tokens");
|
|
568
568
|
function typeStyle(role2) {
|
|
569
569
|
const t = typeof role2 === "string" ? import_tokens4.tokens.typography[role2] : role2;
|
|
@@ -2045,89 +2045,111 @@ var import_react22 = require("react");
|
|
|
2045
2045
|
var import_react_aria_components2 = require("react-aria-components");
|
|
2046
2046
|
|
|
2047
2047
|
// packages/react/src/use-selection-indicator.ts
|
|
2048
|
-
var import_tokens15 = require("@kjun-ui/tokens");
|
|
2049
2048
|
var import_react21 = require("react");
|
|
2049
|
+
|
|
2050
|
+
// shared/package-runtime/selection-indicator.ts
|
|
2051
|
+
var import_tokens15 = require("@kjun-ui/tokens");
|
|
2052
|
+
function selectionIndicator(root, marker, tabs = false) {
|
|
2053
|
+
var _a;
|
|
2054
|
+
let selected = null, bounds = "", disposed = false;
|
|
2055
|
+
const observed = /* @__PURE__ */ new Set();
|
|
2056
|
+
const observer = new ResizeObserver(() => update());
|
|
2057
|
+
const visibility = new MutationObserver(() => update());
|
|
2058
|
+
for (let ancestor = root; ancestor; ancestor = ancestor.parentElement) {
|
|
2059
|
+
visibility.observe(ancestor, { attributes: true, attributeFilter: ["style", "class", "hidden", "data-variant", "data-density"] });
|
|
2060
|
+
}
|
|
2061
|
+
function edges() {
|
|
2062
|
+
const start = root.scrollLeft > 1, end = root.scrollLeft + root.clientWidth < root.scrollWidth - 1;
|
|
2063
|
+
const next = start && end ? "both" : start ? "start" : end ? "end" : "";
|
|
2064
|
+
if (next) root.dataset.overflow = next;
|
|
2065
|
+
else root.removeAttribute("data-overflow");
|
|
2066
|
+
}
|
|
2067
|
+
function update() {
|
|
2068
|
+
if (disposed) return;
|
|
2069
|
+
if (!tabs) edges();
|
|
2070
|
+
const buttons = [...root.querySelectorAll(tabs ? '[role="tab"]' : "button")];
|
|
2071
|
+
for (const node of observed) if (!buttons.includes(node) && node !== root) {
|
|
2072
|
+
observer.unobserve(node);
|
|
2073
|
+
observed.delete(node);
|
|
2074
|
+
}
|
|
2075
|
+
for (const node of [root, ...buttons]) if (!observed.has(node)) {
|
|
2076
|
+
observer.observe(node, { box: "border-box" });
|
|
2077
|
+
observed.add(node);
|
|
2078
|
+
}
|
|
2079
|
+
const next = buttons.find((button) => button.getAttribute(tabs ? "aria-selected" : "aria-pressed") === "true") || null;
|
|
2080
|
+
if (!next || !next.offsetWidth || !next.offsetHeight) {
|
|
2081
|
+
root.removeAttribute("data-indicator");
|
|
2082
|
+
marker.hidden = true;
|
|
2083
|
+
selected = null;
|
|
2084
|
+
bounds = "";
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
const underline = tabs && root.closest('[data-variant="underline"]');
|
|
2088
|
+
const style = getComputedStyle(next);
|
|
2089
|
+
const left = underline ? parseFloat(style.paddingLeft) : 0;
|
|
2090
|
+
const right = underline ? parseFloat(style.paddingRight) : 0;
|
|
2091
|
+
const height = underline ? import_tokens15.tokens.extensions.tabs.indicatorHeight : next.offsetHeight;
|
|
2092
|
+
const key = [!!underline, left, right, next.offsetLeft, next.offsetTop, next.offsetWidth, next.offsetHeight].join(",");
|
|
2093
|
+
if (key !== bounds) {
|
|
2094
|
+
marker.dataset.animate = String(!!selected && selected !== next);
|
|
2095
|
+
marker.style.transform = `translateX(${next.offsetLeft + left}px)`;
|
|
2096
|
+
marker.style.top = (underline ? next.offsetTop + next.offsetHeight - height : next.offsetTop) + "px";
|
|
2097
|
+
marker.style.width = Math.max(0, next.offsetWidth - left - right) + "px";
|
|
2098
|
+
marker.style.height = height + "px";
|
|
2099
|
+
}
|
|
2100
|
+
marker.hidden = false;
|
|
2101
|
+
root.dataset.indicator = "true";
|
|
2102
|
+
selected = next;
|
|
2103
|
+
bounds = key;
|
|
2104
|
+
}
|
|
2105
|
+
update();
|
|
2106
|
+
if (!tabs) root.addEventListener("scroll", edges, { passive: true });
|
|
2107
|
+
(_a = document.fonts) == null ? void 0 : _a.addEventListener("loadingdone", update);
|
|
2108
|
+
return { update, destroy() {
|
|
2109
|
+
var _a2;
|
|
2110
|
+
disposed = true;
|
|
2111
|
+
observer.disconnect();
|
|
2112
|
+
visibility.disconnect();
|
|
2113
|
+
root.removeEventListener("scroll", edges);
|
|
2114
|
+
(_a2 = document.fonts) == null ? void 0 : _a2.removeEventListener("loadingdone", update);
|
|
2115
|
+
} };
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
// packages/react/src/use-selection-indicator.ts
|
|
2050
2119
|
function useSelectionIndicator(tabs = false) {
|
|
2051
2120
|
const group = (0, import_react21.useRef)(null);
|
|
2052
2121
|
const indicator = (0, import_react21.useRef)(null);
|
|
2053
2122
|
const sync = (0, import_react21.useRef)(() => {
|
|
2054
2123
|
});
|
|
2055
2124
|
(0, import_react21.useLayoutEffect)(() => {
|
|
2056
|
-
var _a;
|
|
2057
2125
|
const root = group.current, marker = indicator.current;
|
|
2058
2126
|
if (!root || !marker) return;
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
let disposed = false;
|
|
2062
|
-
const observer = new ResizeObserver(() => update());
|
|
2063
|
-
const visibility = new MutationObserver(() => update());
|
|
2064
|
-
for (let ancestor = root; ancestor; ancestor = ancestor.parentElement) {
|
|
2065
|
-
visibility.observe(ancestor, { attributes: true, attributeFilter: ["style", "class", "hidden", "data-variant", "data-density"] });
|
|
2066
|
-
}
|
|
2067
|
-
const observed = /* @__PURE__ */ new Set();
|
|
2068
|
-
function edges() {
|
|
2069
|
-
const start = root.scrollLeft > 1, end = root.scrollLeft + root.clientWidth < root.scrollWidth - 1;
|
|
2070
|
-
const next = start && end ? "both" : start ? "start" : end ? "end" : "";
|
|
2071
|
-
if (next) root.dataset.overflow = next;
|
|
2072
|
-
else root.removeAttribute("data-overflow");
|
|
2073
|
-
}
|
|
2074
|
-
function update() {
|
|
2075
|
-
if (disposed) return;
|
|
2076
|
-
if (!tabs) edges();
|
|
2077
|
-
const buttons = [...root.querySelectorAll(tabs ? '[role="tab"]' : "button")];
|
|
2078
|
-
for (const node of observed) if (!buttons.includes(node) && node !== root) {
|
|
2079
|
-
observer.unobserve(node);
|
|
2080
|
-
observed.delete(node);
|
|
2081
|
-
}
|
|
2082
|
-
for (const node of [root, ...buttons]) if (!observed.has(node)) {
|
|
2083
|
-
observer.observe(node, { box: "border-box" });
|
|
2084
|
-
observed.add(node);
|
|
2085
|
-
}
|
|
2086
|
-
const next = buttons.find((button) => button.getAttribute(tabs ? "aria-selected" : "aria-pressed") === "true") || null;
|
|
2087
|
-
if (!next || !next.offsetWidth || !next.offsetHeight) {
|
|
2088
|
-
root.removeAttribute("data-indicator");
|
|
2089
|
-
marker.hidden = true;
|
|
2090
|
-
selected = null;
|
|
2091
|
-
bounds = "";
|
|
2092
|
-
return;
|
|
2093
|
-
}
|
|
2094
|
-
const underline = tabs && root.closest('[data-variant="underline"]');
|
|
2095
|
-
const style = getComputedStyle(next);
|
|
2096
|
-
const left = underline ? parseFloat(style.paddingLeft) : 0;
|
|
2097
|
-
const right = underline ? parseFloat(style.paddingRight) : 0;
|
|
2098
|
-
const height = underline ? import_tokens15.tokens.extensions.tabs.indicatorHeight : next.offsetHeight;
|
|
2099
|
-
const key = [!!underline, left, right, next.offsetLeft, next.offsetTop, next.offsetWidth, next.offsetHeight].join(",");
|
|
2100
|
-
if (key !== bounds) {
|
|
2101
|
-
marker.dataset.animate = String(!!selected && selected !== next);
|
|
2102
|
-
marker.style.transform = `translateX(${next.offsetLeft + left}px)`;
|
|
2103
|
-
marker.style.top = (underline ? next.offsetTop + next.offsetHeight - height : next.offsetTop) + "px";
|
|
2104
|
-
marker.style.width = Math.max(0, next.offsetWidth - left - right) + "px";
|
|
2105
|
-
marker.style.height = height + "px";
|
|
2106
|
-
}
|
|
2107
|
-
marker.hidden = false;
|
|
2108
|
-
root.dataset.indicator = "true";
|
|
2109
|
-
selected = next;
|
|
2110
|
-
bounds = key;
|
|
2111
|
-
}
|
|
2112
|
-
sync.current = update;
|
|
2113
|
-
update();
|
|
2114
|
-
if (!tabs) root.addEventListener("scroll", edges, { passive: true });
|
|
2115
|
-
(_a = document.fonts) == null ? void 0 : _a.addEventListener("loadingdone", update);
|
|
2127
|
+
const handle = selectionIndicator(root, marker, tabs);
|
|
2128
|
+
sync.current = handle.update;
|
|
2116
2129
|
return () => {
|
|
2117
|
-
|
|
2118
|
-
disposed = true;
|
|
2119
|
-
observer.disconnect();
|
|
2120
|
-
visibility.disconnect();
|
|
2130
|
+
handle.destroy();
|
|
2121
2131
|
sync.current = () => {
|
|
2122
2132
|
};
|
|
2123
|
-
root.removeEventListener("scroll", edges);
|
|
2124
|
-
(_a2 = document.fonts) == null ? void 0 : _a2.removeEventListener("loadingdone", update);
|
|
2125
2133
|
};
|
|
2126
2134
|
}, [tabs]);
|
|
2127
2135
|
(0, import_react21.useLayoutEffect)(() => sync.current());
|
|
2128
2136
|
return { group, indicator };
|
|
2129
2137
|
}
|
|
2130
2138
|
|
|
2139
|
+
// shared/package-runtime/group-keyboard.ts
|
|
2140
|
+
function groupKeydown(event) {
|
|
2141
|
+
var _a;
|
|
2142
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
2143
|
+
const group = event.currentTarget;
|
|
2144
|
+
const buttons = Array.from(group.querySelectorAll("button:not(:disabled)"));
|
|
2145
|
+
const current = buttons.indexOf(event.target);
|
|
2146
|
+
if (current < 0) return;
|
|
2147
|
+
event.preventDefault();
|
|
2148
|
+
const direction = getComputedStyle(group).direction === "rtl" ? -1 : 1;
|
|
2149
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (current + (event.key === "ArrowRight" ? direction : -direction) + buttons.length) % buttons.length;
|
|
2150
|
+
(_a = buttons[next]) == null ? void 0 : _a.focus();
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2131
2153
|
// packages/react/src/controls.tsx
|
|
2132
2154
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2133
2155
|
function KjunCheckbox({
|
|
@@ -2337,21 +2359,6 @@ var KjunTextarea = (0, import_react22.forwardRef)(
|
|
|
2337
2359
|
);
|
|
2338
2360
|
}
|
|
2339
2361
|
);
|
|
2340
|
-
function groupKeydown(event) {
|
|
2341
|
-
var _a;
|
|
2342
|
-
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
2343
|
-
const buttons = Array.from(
|
|
2344
|
-
event.currentTarget.querySelectorAll(
|
|
2345
|
-
"button:not(:disabled)"
|
|
2346
|
-
)
|
|
2347
|
-
);
|
|
2348
|
-
const current = buttons.indexOf(event.target);
|
|
2349
|
-
if (current < 0) return;
|
|
2350
|
-
event.preventDefault();
|
|
2351
|
-
const direction = getComputedStyle(event.currentTarget).direction === "rtl" ? -1 : 1;
|
|
2352
|
-
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (current + (event.key === "ArrowRight" ? direction : -direction) + buttons.length) % buttons.length;
|
|
2353
|
-
(_a = buttons[next]) == null ? void 0 : _a.focus();
|
|
2354
|
-
}
|
|
2355
2362
|
function KjunButtonGroup({
|
|
2356
2363
|
value,
|
|
2357
2364
|
options,
|
|
@@ -5216,12 +5223,36 @@ function KjunSparkline({
|
|
|
5216
5223
|
// shared/package-runtime/table.ts
|
|
5217
5224
|
var import_tokens33 = require("@kjun-ui/tokens");
|
|
5218
5225
|
var import_react42 = require("react");
|
|
5226
|
+
|
|
5227
|
+
// shared/package-runtime/table-model.ts
|
|
5219
5228
|
function getValue(row, key) {
|
|
5220
5229
|
return key.split(".").reduce(
|
|
5221
5230
|
(value, part) => value != null && typeof value === "object" ? value[part] : void 0,
|
|
5222
5231
|
row
|
|
5223
5232
|
);
|
|
5224
5233
|
}
|
|
5234
|
+
function sortTableRows(data, sort, { sortable = true, sortMode = "client" }) {
|
|
5235
|
+
if (!sortable || sortMode === "server" || !sort.key) return data;
|
|
5236
|
+
return [...data].sort((a, b) => {
|
|
5237
|
+
const x = getValue(a, sort.key), y = getValue(b, sort.key);
|
|
5238
|
+
const order = x === y ? 0 : typeof x === "number" && typeof y === "number" ? x > y ? 1 : -1 : String(x) > String(y) ? 1 : -1;
|
|
5239
|
+
return sort.order === "asc" ? order : -order;
|
|
5240
|
+
});
|
|
5241
|
+
}
|
|
5242
|
+
var tableRowKey = (row, rowKey, index = 0) => {
|
|
5243
|
+
var _a;
|
|
5244
|
+
return (_a = getValue(row, rowKey)) != null ? _a : index;
|
|
5245
|
+
};
|
|
5246
|
+
function tableSelection(rows, selected, rowKey) {
|
|
5247
|
+
const isSelected = (row) => selected.some((r) => getValue(r, rowKey) === getValue(row, rowKey));
|
|
5248
|
+
const all = rows.length > 0 && rows.every(isSelected);
|
|
5249
|
+
return { isSelected, all, some: rows.some(isSelected) && !all };
|
|
5250
|
+
}
|
|
5251
|
+
var toggleSelectedRow = (selected, row, rowKey) => selected.some((r) => getValue(r, rowKey) === getValue(row, rowKey)) ? selected.filter((r) => getValue(r, rowKey) !== getValue(row, rowKey)) : [...selected, row];
|
|
5252
|
+
var toggleAllRows = (rows, all) => all ? [] : [...rows];
|
|
5253
|
+
var toggleExpandedRow = (expanded, id, single) => expanded.includes(id) ? expanded.filter((v) => v !== id) : [...single ? [] : expanded, id];
|
|
5254
|
+
|
|
5255
|
+
// shared/package-runtime/table.ts
|
|
5225
5256
|
function useTableModel(props) {
|
|
5226
5257
|
var _a;
|
|
5227
5258
|
const {
|
|
@@ -5241,17 +5272,9 @@ function useTableModel(props) {
|
|
|
5241
5272
|
}), [internalExpanded, setExpanded] = (0, import_react42.useState)([]), [search, setSearch] = (0, import_react42.useState)(""), timer = (0, import_react42.useRef)(void 0);
|
|
5242
5273
|
(0, import_react42.useEffect)(() => () => clearTimeout(timer.current), []);
|
|
5243
5274
|
const sort = props.sort === void 0 ? internalSort : (_a = props.sort) != null ? _a : { key: "", order: "asc" };
|
|
5244
|
-
const rows =
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
return sort.order === "asc" ? order : -order;
|
|
5248
|
-
}) : data;
|
|
5249
|
-
const key = (row, index = 0) => {
|
|
5250
|
-
var _a2;
|
|
5251
|
-
return (_a2 = getValue(row, rowKey)) != null ? _a2 : index;
|
|
5252
|
-
};
|
|
5253
|
-
const selectedRow = (row) => selected.some((r) => getValue(r, rowKey) === getValue(row, rowKey));
|
|
5254
|
-
const all = rows.length > 0 && rows.every(selectedRow), some = rows.some(selectedRow) && !all, expanded = expandedRows != null ? expandedRows : internalExpanded;
|
|
5275
|
+
const rows = sortTableRows(data, sort, { sortable, sortMode });
|
|
5276
|
+
const key = (row, index = 0) => tableRowKey(row, rowKey, index);
|
|
5277
|
+
const { isSelected: selectedRow, all, some } = tableSelection(rows, selected, rowKey), expanded = expandedRows != null ? expandedRows : internalExpanded;
|
|
5255
5278
|
return {
|
|
5256
5279
|
rows,
|
|
5257
5280
|
key,
|
|
@@ -5276,14 +5299,10 @@ function useTableModel(props) {
|
|
|
5276
5299
|
if (props.sort === void 0) setSort(next);
|
|
5277
5300
|
(_a2 = props.onSortChange) == null ? void 0 : _a2.call(props, next);
|
|
5278
5301
|
},
|
|
5279
|
-
toggleRow: (row) => onSelectionChange == null ? void 0 : onSelectionChange(
|
|
5280
|
-
|
|
5281
|
-
(r) => getValue(r, rowKey) !== getValue(row, rowKey)
|
|
5282
|
-
) : [...selected, row]
|
|
5283
|
-
),
|
|
5284
|
-
toggleAll: () => onSelectionChange == null ? void 0 : onSelectionChange(all ? [] : [...rows]),
|
|
5302
|
+
toggleRow: (row) => onSelectionChange == null ? void 0 : onSelectionChange(toggleSelectedRow(selected, row, rowKey)),
|
|
5303
|
+
toggleAll: () => onSelectionChange == null ? void 0 : onSelectionChange(toggleAllRows(rows, all)),
|
|
5285
5304
|
toggleExpand: (row, index) => {
|
|
5286
|
-
const
|
|
5305
|
+
const next = toggleExpandedRow(expanded, key(row, index), expandSingle);
|
|
5287
5306
|
setExpanded(next);
|
|
5288
5307
|
onExpandedRowsChange == null ? void 0 : onExpandedRowsChange(next);
|
|
5289
5308
|
}
|
package/dist/index.js
CHANGED
|
@@ -455,7 +455,7 @@ function KjunProvider({
|
|
|
455
455
|
] }) }) }) });
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
//
|
|
458
|
+
// shared/package-runtime/typography.ts
|
|
459
459
|
import { tokens as tokens2 } from "@kjun-ui/tokens";
|
|
460
460
|
function typeStyle(role2) {
|
|
461
461
|
const t = typeof role2 === "string" ? tokens2.typography[role2] : role2;
|
|
@@ -1976,89 +1976,111 @@ import {
|
|
|
1976
1976
|
} from "react-aria-components";
|
|
1977
1977
|
|
|
1978
1978
|
// packages/react/src/use-selection-indicator.ts
|
|
1979
|
-
import { tokens as tokens11 } from "@kjun-ui/tokens";
|
|
1980
1979
|
import { useLayoutEffect as useLayoutEffect9, useRef as useRef12 } from "react";
|
|
1980
|
+
|
|
1981
|
+
// shared/package-runtime/selection-indicator.ts
|
|
1982
|
+
import { tokens as tokens11 } from "@kjun-ui/tokens";
|
|
1983
|
+
function selectionIndicator(root, marker, tabs = false) {
|
|
1984
|
+
var _a;
|
|
1985
|
+
let selected = null, bounds = "", disposed = false;
|
|
1986
|
+
const observed = /* @__PURE__ */ new Set();
|
|
1987
|
+
const observer = new ResizeObserver(() => update());
|
|
1988
|
+
const visibility = new MutationObserver(() => update());
|
|
1989
|
+
for (let ancestor = root; ancestor; ancestor = ancestor.parentElement) {
|
|
1990
|
+
visibility.observe(ancestor, { attributes: true, attributeFilter: ["style", "class", "hidden", "data-variant", "data-density"] });
|
|
1991
|
+
}
|
|
1992
|
+
function edges() {
|
|
1993
|
+
const start = root.scrollLeft > 1, end = root.scrollLeft + root.clientWidth < root.scrollWidth - 1;
|
|
1994
|
+
const next = start && end ? "both" : start ? "start" : end ? "end" : "";
|
|
1995
|
+
if (next) root.dataset.overflow = next;
|
|
1996
|
+
else root.removeAttribute("data-overflow");
|
|
1997
|
+
}
|
|
1998
|
+
function update() {
|
|
1999
|
+
if (disposed) return;
|
|
2000
|
+
if (!tabs) edges();
|
|
2001
|
+
const buttons = [...root.querySelectorAll(tabs ? '[role="tab"]' : "button")];
|
|
2002
|
+
for (const node of observed) if (!buttons.includes(node) && node !== root) {
|
|
2003
|
+
observer.unobserve(node);
|
|
2004
|
+
observed.delete(node);
|
|
2005
|
+
}
|
|
2006
|
+
for (const node of [root, ...buttons]) if (!observed.has(node)) {
|
|
2007
|
+
observer.observe(node, { box: "border-box" });
|
|
2008
|
+
observed.add(node);
|
|
2009
|
+
}
|
|
2010
|
+
const next = buttons.find((button) => button.getAttribute(tabs ? "aria-selected" : "aria-pressed") === "true") || null;
|
|
2011
|
+
if (!next || !next.offsetWidth || !next.offsetHeight) {
|
|
2012
|
+
root.removeAttribute("data-indicator");
|
|
2013
|
+
marker.hidden = true;
|
|
2014
|
+
selected = null;
|
|
2015
|
+
bounds = "";
|
|
2016
|
+
return;
|
|
2017
|
+
}
|
|
2018
|
+
const underline = tabs && root.closest('[data-variant="underline"]');
|
|
2019
|
+
const style = getComputedStyle(next);
|
|
2020
|
+
const left = underline ? parseFloat(style.paddingLeft) : 0;
|
|
2021
|
+
const right = underline ? parseFloat(style.paddingRight) : 0;
|
|
2022
|
+
const height = underline ? tokens11.extensions.tabs.indicatorHeight : next.offsetHeight;
|
|
2023
|
+
const key = [!!underline, left, right, next.offsetLeft, next.offsetTop, next.offsetWidth, next.offsetHeight].join(",");
|
|
2024
|
+
if (key !== bounds) {
|
|
2025
|
+
marker.dataset.animate = String(!!selected && selected !== next);
|
|
2026
|
+
marker.style.transform = `translateX(${next.offsetLeft + left}px)`;
|
|
2027
|
+
marker.style.top = (underline ? next.offsetTop + next.offsetHeight - height : next.offsetTop) + "px";
|
|
2028
|
+
marker.style.width = Math.max(0, next.offsetWidth - left - right) + "px";
|
|
2029
|
+
marker.style.height = height + "px";
|
|
2030
|
+
}
|
|
2031
|
+
marker.hidden = false;
|
|
2032
|
+
root.dataset.indicator = "true";
|
|
2033
|
+
selected = next;
|
|
2034
|
+
bounds = key;
|
|
2035
|
+
}
|
|
2036
|
+
update();
|
|
2037
|
+
if (!tabs) root.addEventListener("scroll", edges, { passive: true });
|
|
2038
|
+
(_a = document.fonts) == null ? void 0 : _a.addEventListener("loadingdone", update);
|
|
2039
|
+
return { update, destroy() {
|
|
2040
|
+
var _a2;
|
|
2041
|
+
disposed = true;
|
|
2042
|
+
observer.disconnect();
|
|
2043
|
+
visibility.disconnect();
|
|
2044
|
+
root.removeEventListener("scroll", edges);
|
|
2045
|
+
(_a2 = document.fonts) == null ? void 0 : _a2.removeEventListener("loadingdone", update);
|
|
2046
|
+
} };
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
// packages/react/src/use-selection-indicator.ts
|
|
1981
2050
|
function useSelectionIndicator(tabs = false) {
|
|
1982
2051
|
const group = useRef12(null);
|
|
1983
2052
|
const indicator = useRef12(null);
|
|
1984
2053
|
const sync = useRef12(() => {
|
|
1985
2054
|
});
|
|
1986
2055
|
useLayoutEffect9(() => {
|
|
1987
|
-
var _a;
|
|
1988
2056
|
const root = group.current, marker = indicator.current;
|
|
1989
2057
|
if (!root || !marker) return;
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
let disposed = false;
|
|
1993
|
-
const observer = new ResizeObserver(() => update());
|
|
1994
|
-
const visibility = new MutationObserver(() => update());
|
|
1995
|
-
for (let ancestor = root; ancestor; ancestor = ancestor.parentElement) {
|
|
1996
|
-
visibility.observe(ancestor, { attributes: true, attributeFilter: ["style", "class", "hidden", "data-variant", "data-density"] });
|
|
1997
|
-
}
|
|
1998
|
-
const observed = /* @__PURE__ */ new Set();
|
|
1999
|
-
function edges() {
|
|
2000
|
-
const start = root.scrollLeft > 1, end = root.scrollLeft + root.clientWidth < root.scrollWidth - 1;
|
|
2001
|
-
const next = start && end ? "both" : start ? "start" : end ? "end" : "";
|
|
2002
|
-
if (next) root.dataset.overflow = next;
|
|
2003
|
-
else root.removeAttribute("data-overflow");
|
|
2004
|
-
}
|
|
2005
|
-
function update() {
|
|
2006
|
-
if (disposed) return;
|
|
2007
|
-
if (!tabs) edges();
|
|
2008
|
-
const buttons = [...root.querySelectorAll(tabs ? '[role="tab"]' : "button")];
|
|
2009
|
-
for (const node of observed) if (!buttons.includes(node) && node !== root) {
|
|
2010
|
-
observer.unobserve(node);
|
|
2011
|
-
observed.delete(node);
|
|
2012
|
-
}
|
|
2013
|
-
for (const node of [root, ...buttons]) if (!observed.has(node)) {
|
|
2014
|
-
observer.observe(node, { box: "border-box" });
|
|
2015
|
-
observed.add(node);
|
|
2016
|
-
}
|
|
2017
|
-
const next = buttons.find((button) => button.getAttribute(tabs ? "aria-selected" : "aria-pressed") === "true") || null;
|
|
2018
|
-
if (!next || !next.offsetWidth || !next.offsetHeight) {
|
|
2019
|
-
root.removeAttribute("data-indicator");
|
|
2020
|
-
marker.hidden = true;
|
|
2021
|
-
selected = null;
|
|
2022
|
-
bounds = "";
|
|
2023
|
-
return;
|
|
2024
|
-
}
|
|
2025
|
-
const underline = tabs && root.closest('[data-variant="underline"]');
|
|
2026
|
-
const style = getComputedStyle(next);
|
|
2027
|
-
const left = underline ? parseFloat(style.paddingLeft) : 0;
|
|
2028
|
-
const right = underline ? parseFloat(style.paddingRight) : 0;
|
|
2029
|
-
const height = underline ? tokens11.extensions.tabs.indicatorHeight : next.offsetHeight;
|
|
2030
|
-
const key = [!!underline, left, right, next.offsetLeft, next.offsetTop, next.offsetWidth, next.offsetHeight].join(",");
|
|
2031
|
-
if (key !== bounds) {
|
|
2032
|
-
marker.dataset.animate = String(!!selected && selected !== next);
|
|
2033
|
-
marker.style.transform = `translateX(${next.offsetLeft + left}px)`;
|
|
2034
|
-
marker.style.top = (underline ? next.offsetTop + next.offsetHeight - height : next.offsetTop) + "px";
|
|
2035
|
-
marker.style.width = Math.max(0, next.offsetWidth - left - right) + "px";
|
|
2036
|
-
marker.style.height = height + "px";
|
|
2037
|
-
}
|
|
2038
|
-
marker.hidden = false;
|
|
2039
|
-
root.dataset.indicator = "true";
|
|
2040
|
-
selected = next;
|
|
2041
|
-
bounds = key;
|
|
2042
|
-
}
|
|
2043
|
-
sync.current = update;
|
|
2044
|
-
update();
|
|
2045
|
-
if (!tabs) root.addEventListener("scroll", edges, { passive: true });
|
|
2046
|
-
(_a = document.fonts) == null ? void 0 : _a.addEventListener("loadingdone", update);
|
|
2058
|
+
const handle = selectionIndicator(root, marker, tabs);
|
|
2059
|
+
sync.current = handle.update;
|
|
2047
2060
|
return () => {
|
|
2048
|
-
|
|
2049
|
-
disposed = true;
|
|
2050
|
-
observer.disconnect();
|
|
2051
|
-
visibility.disconnect();
|
|
2061
|
+
handle.destroy();
|
|
2052
2062
|
sync.current = () => {
|
|
2053
2063
|
};
|
|
2054
|
-
root.removeEventListener("scroll", edges);
|
|
2055
|
-
(_a2 = document.fonts) == null ? void 0 : _a2.removeEventListener("loadingdone", update);
|
|
2056
2064
|
};
|
|
2057
2065
|
}, [tabs]);
|
|
2058
2066
|
useLayoutEffect9(() => sync.current());
|
|
2059
2067
|
return { group, indicator };
|
|
2060
2068
|
}
|
|
2061
2069
|
|
|
2070
|
+
// shared/package-runtime/group-keyboard.ts
|
|
2071
|
+
function groupKeydown(event) {
|
|
2072
|
+
var _a;
|
|
2073
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
2074
|
+
const group = event.currentTarget;
|
|
2075
|
+
const buttons = Array.from(group.querySelectorAll("button:not(:disabled)"));
|
|
2076
|
+
const current = buttons.indexOf(event.target);
|
|
2077
|
+
if (current < 0) return;
|
|
2078
|
+
event.preventDefault();
|
|
2079
|
+
const direction = getComputedStyle(group).direction === "rtl" ? -1 : 1;
|
|
2080
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (current + (event.key === "ArrowRight" ? direction : -direction) + buttons.length) % buttons.length;
|
|
2081
|
+
(_a = buttons[next]) == null ? void 0 : _a.focus();
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2062
2084
|
// packages/react/src/controls.tsx
|
|
2063
2085
|
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2064
2086
|
function KjunCheckbox({
|
|
@@ -2268,21 +2290,6 @@ var KjunTextarea = forwardRef3(
|
|
|
2268
2290
|
);
|
|
2269
2291
|
}
|
|
2270
2292
|
);
|
|
2271
|
-
function groupKeydown(event) {
|
|
2272
|
-
var _a;
|
|
2273
|
-
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
2274
|
-
const buttons = Array.from(
|
|
2275
|
-
event.currentTarget.querySelectorAll(
|
|
2276
|
-
"button:not(:disabled)"
|
|
2277
|
-
)
|
|
2278
|
-
);
|
|
2279
|
-
const current = buttons.indexOf(event.target);
|
|
2280
|
-
if (current < 0) return;
|
|
2281
|
-
event.preventDefault();
|
|
2282
|
-
const direction = getComputedStyle(event.currentTarget).direction === "rtl" ? -1 : 1;
|
|
2283
|
-
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (current + (event.key === "ArrowRight" ? direction : -direction) + buttons.length) % buttons.length;
|
|
2284
|
-
(_a = buttons[next]) == null ? void 0 : _a.focus();
|
|
2285
|
-
}
|
|
2286
2293
|
function KjunButtonGroup({
|
|
2287
2294
|
value,
|
|
2288
2295
|
options,
|
|
@@ -5182,12 +5189,36 @@ function KjunSparkline({
|
|
|
5182
5189
|
// shared/package-runtime/table.ts
|
|
5183
5190
|
import { nextTableSort } from "@kjun-ui/tokens";
|
|
5184
5191
|
import { useEffect as useEffect15, useRef as useRef25, useState as useState24 } from "react";
|
|
5192
|
+
|
|
5193
|
+
// shared/package-runtime/table-model.ts
|
|
5185
5194
|
function getValue(row, key) {
|
|
5186
5195
|
return key.split(".").reduce(
|
|
5187
5196
|
(value, part) => value != null && typeof value === "object" ? value[part] : void 0,
|
|
5188
5197
|
row
|
|
5189
5198
|
);
|
|
5190
5199
|
}
|
|
5200
|
+
function sortTableRows(data, sort, { sortable = true, sortMode = "client" }) {
|
|
5201
|
+
if (!sortable || sortMode === "server" || !sort.key) return data;
|
|
5202
|
+
return [...data].sort((a, b) => {
|
|
5203
|
+
const x = getValue(a, sort.key), y = getValue(b, sort.key);
|
|
5204
|
+
const order = x === y ? 0 : typeof x === "number" && typeof y === "number" ? x > y ? 1 : -1 : String(x) > String(y) ? 1 : -1;
|
|
5205
|
+
return sort.order === "asc" ? order : -order;
|
|
5206
|
+
});
|
|
5207
|
+
}
|
|
5208
|
+
var tableRowKey = (row, rowKey, index = 0) => {
|
|
5209
|
+
var _a;
|
|
5210
|
+
return (_a = getValue(row, rowKey)) != null ? _a : index;
|
|
5211
|
+
};
|
|
5212
|
+
function tableSelection(rows, selected, rowKey) {
|
|
5213
|
+
const isSelected = (row) => selected.some((r) => getValue(r, rowKey) === getValue(row, rowKey));
|
|
5214
|
+
const all = rows.length > 0 && rows.every(isSelected);
|
|
5215
|
+
return { isSelected, all, some: rows.some(isSelected) && !all };
|
|
5216
|
+
}
|
|
5217
|
+
var toggleSelectedRow = (selected, row, rowKey) => selected.some((r) => getValue(r, rowKey) === getValue(row, rowKey)) ? selected.filter((r) => getValue(r, rowKey) !== getValue(row, rowKey)) : [...selected, row];
|
|
5218
|
+
var toggleAllRows = (rows, all) => all ? [] : [...rows];
|
|
5219
|
+
var toggleExpandedRow = (expanded, id, single) => expanded.includes(id) ? expanded.filter((v) => v !== id) : [...single ? [] : expanded, id];
|
|
5220
|
+
|
|
5221
|
+
// shared/package-runtime/table.ts
|
|
5191
5222
|
function useTableModel(props) {
|
|
5192
5223
|
var _a;
|
|
5193
5224
|
const {
|
|
@@ -5207,17 +5238,9 @@ function useTableModel(props) {
|
|
|
5207
5238
|
}), [internalExpanded, setExpanded] = useState24([]), [search, setSearch] = useState24(""), timer = useRef25(void 0);
|
|
5208
5239
|
useEffect15(() => () => clearTimeout(timer.current), []);
|
|
5209
5240
|
const sort = props.sort === void 0 ? internalSort : (_a = props.sort) != null ? _a : { key: "", order: "asc" };
|
|
5210
|
-
const rows =
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
return sort.order === "asc" ? order : -order;
|
|
5214
|
-
}) : data;
|
|
5215
|
-
const key = (row, index = 0) => {
|
|
5216
|
-
var _a2;
|
|
5217
|
-
return (_a2 = getValue(row, rowKey)) != null ? _a2 : index;
|
|
5218
|
-
};
|
|
5219
|
-
const selectedRow = (row) => selected.some((r) => getValue(r, rowKey) === getValue(row, rowKey));
|
|
5220
|
-
const all = rows.length > 0 && rows.every(selectedRow), some = rows.some(selectedRow) && !all, expanded = expandedRows != null ? expandedRows : internalExpanded;
|
|
5241
|
+
const rows = sortTableRows(data, sort, { sortable, sortMode });
|
|
5242
|
+
const key = (row, index = 0) => tableRowKey(row, rowKey, index);
|
|
5243
|
+
const { isSelected: selectedRow, all, some } = tableSelection(rows, selected, rowKey), expanded = expandedRows != null ? expandedRows : internalExpanded;
|
|
5221
5244
|
return {
|
|
5222
5245
|
rows,
|
|
5223
5246
|
key,
|
|
@@ -5242,14 +5265,10 @@ function useTableModel(props) {
|
|
|
5242
5265
|
if (props.sort === void 0) setSort(next);
|
|
5243
5266
|
(_a2 = props.onSortChange) == null ? void 0 : _a2.call(props, next);
|
|
5244
5267
|
},
|
|
5245
|
-
toggleRow: (row) => onSelectionChange == null ? void 0 : onSelectionChange(
|
|
5246
|
-
|
|
5247
|
-
(r) => getValue(r, rowKey) !== getValue(row, rowKey)
|
|
5248
|
-
) : [...selected, row]
|
|
5249
|
-
),
|
|
5250
|
-
toggleAll: () => onSelectionChange == null ? void 0 : onSelectionChange(all ? [] : [...rows]),
|
|
5268
|
+
toggleRow: (row) => onSelectionChange == null ? void 0 : onSelectionChange(toggleSelectedRow(selected, row, rowKey)),
|
|
5269
|
+
toggleAll: () => onSelectionChange == null ? void 0 : onSelectionChange(toggleAllRows(rows, all)),
|
|
5251
5270
|
toggleExpand: (row, index) => {
|
|
5252
|
-
const
|
|
5271
|
+
const next = toggleExpandedRow(expanded, key(row, index), expandSingle);
|
|
5253
5272
|
setExpanded(next);
|
|
5254
5273
|
onExpandedRowsChange == null ? void 0 : onExpandedRowsChange(next);
|
|
5255
5274
|
}
|