@valu/block-components 0.1.1 → 0.2.1
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/LICENSE +359 -0
- package/README.md +7 -0
- package/dist/components/matrix/index.cjs +741 -0
- package/dist/components/matrix/index.cjs.map +1 -0
- package/dist/components/matrix/index.d.cts +208 -0
- package/dist/components/matrix/index.d.ts +208 -0
- package/dist/components/matrix/index.js +731 -0
- package/dist/components/matrix/index.js.map +1 -0
- package/dist/index.cjs +723 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +721 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, useId, useState, useCallback, useRef, useMemo, useEffect } from 'react';
|
|
2
2
|
import { QueryClientProvider, QueryClient, useInfiniteQuery, keepPreviousData } from '@tanstack/react-query';
|
|
3
|
-
import { VisuallyHidden, Icon, Popover, Spinner, Button } from '@wordpress/components';
|
|
3
|
+
import { VisuallyHidden, Icon, Popover, ToggleControl, Spinner, Button, CheckboxControl } from '@wordpress/components';
|
|
4
4
|
import { __, sprintf, _n } from '@wordpress/i18n';
|
|
5
5
|
import { search, closeSmall, dragHandle, caution, chevronUp, chevronDown, people } from '@wordpress/icons';
|
|
6
6
|
import styled from '@emotion/styled';
|
|
@@ -2021,6 +2021,725 @@ var ContentPicker = ({
|
|
|
2021
2021
|
] }) }) });
|
|
2022
2022
|
};
|
|
2023
2023
|
|
|
2024
|
-
|
|
2024
|
+
// components/matrix/styles/tokens.ts
|
|
2025
|
+
var tokens2 = {
|
|
2026
|
+
accent: "var(--wp-admin-theme-color, #3858e9)",
|
|
2027
|
+
accentHover: "color-mix(in srgb, var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9)) 4%, transparent)",
|
|
2028
|
+
bg: "var(--wp-components-color-background, #ffffff)",
|
|
2029
|
+
bgMuted: "var(--wp-components-color-gray-100, #f0f0f0)",
|
|
2030
|
+
fg: "var(--wp-components-color-foreground, #1e1e1e)",
|
|
2031
|
+
gray200: "var(--wp-components-color-gray-200, #ebebeb)",
|
|
2032
|
+
gray300: "var(--wp-components-color-gray-300, #dcdcde)",
|
|
2033
|
+
gray600: "var(--wp-components-color-gray-600, #757575)",
|
|
2034
|
+
gray900: "var(--wp-components-color-gray-900, #1e1e1e)",
|
|
2035
|
+
radiusSm: "2px",
|
|
2036
|
+
radiusMd: "4px",
|
|
2037
|
+
rowMinHeight: "44px",
|
|
2038
|
+
shadowStickyTop: "inset 0 -1px 0 rgba(0, 0, 0, 0.08)",
|
|
2039
|
+
shadowStickyLeft: "inset -1px 0 0 rgba(0, 0, 0, 0.08)",
|
|
2040
|
+
spaceXs: "4px",
|
|
2041
|
+
spaceSm: "8px",
|
|
2042
|
+
spaceMd: "12px",
|
|
2043
|
+
transitionFast: "120ms ease-out",
|
|
2044
|
+
fontSizeBody: "13px",
|
|
2045
|
+
fontSizeSmall: "11px",
|
|
2046
|
+
fontWeightRegular: 400,
|
|
2047
|
+
fontWeightMedium: 500,
|
|
2048
|
+
fontWeightBold: 600,
|
|
2049
|
+
/** Sticky z-index layering. Row-header > master > top headers > leaf cells. */
|
|
2050
|
+
zRowHeader: 4,
|
|
2051
|
+
zMaster: 3,
|
|
2052
|
+
zHeader: 3};
|
|
2053
|
+
|
|
2054
|
+
// components/matrix/styles/index.ts
|
|
2055
|
+
var visuallyHiddenCss2 = css`
|
|
2056
|
+
position: absolute !important;
|
|
2057
|
+
clip: rect(1px, 1px, 1px, 1px);
|
|
2058
|
+
width: 1px;
|
|
2059
|
+
height: 1px;
|
|
2060
|
+
overflow: hidden;
|
|
2061
|
+
white-space: nowrap;
|
|
2062
|
+
`;
|
|
2063
|
+
var Root2 = styled.div`
|
|
2064
|
+
color: ${tokens2.fg};
|
|
2065
|
+
font-size: ${tokens2.fontSizeBody};
|
|
2066
|
+
|
|
2067
|
+
* {
|
|
2068
|
+
box-sizing: border-box;
|
|
2069
|
+
}
|
|
2070
|
+
`;
|
|
2071
|
+
var Viewport = styled.div`
|
|
2072
|
+
position: relative;
|
|
2073
|
+
overflow: auto;
|
|
2074
|
+
max-height: ${(p) => p.$maxHeight};
|
|
2075
|
+
border: 1px solid ${tokens2.gray300};
|
|
2076
|
+
border-radius: ${tokens2.radiusMd};
|
|
2077
|
+
background: ${tokens2.bg};
|
|
2078
|
+
`;
|
|
2079
|
+
var Table = styled.table`
|
|
2080
|
+
border-collapse: separate;
|
|
2081
|
+
border-spacing: 0;
|
|
2082
|
+
width: 100%;
|
|
2083
|
+
min-width: max-content;
|
|
2084
|
+
|
|
2085
|
+
caption {
|
|
2086
|
+
${visuallyHiddenCss2};
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
th,
|
|
2090
|
+
td {
|
|
2091
|
+
text-align: left;
|
|
2092
|
+
padding: ${tokens2.spaceSm} ${tokens2.spaceMd};
|
|
2093
|
+
border-bottom: 1px solid ${tokens2.gray200};
|
|
2094
|
+
font-weight: ${tokens2.fontWeightRegular};
|
|
2095
|
+
vertical-align: middle;
|
|
2096
|
+
background: ${tokens2.bg};
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
tbody tr:last-of-type th,
|
|
2100
|
+
tbody tr:last-of-type td {
|
|
2101
|
+
border-bottom: none;
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
tbody tr:hover th,
|
|
2105
|
+
tbody tr:hover td {
|
|
2106
|
+
background: ${tokens2.bgMuted};
|
|
2107
|
+
}
|
|
2108
|
+
`;
|
|
2109
|
+
var HeaderCell = styled.th`
|
|
2110
|
+
font-weight: ${tokens2.fontWeightBold};
|
|
2111
|
+
font-size: ${tokens2.fontSizeSmall};
|
|
2112
|
+
text-transform: uppercase;
|
|
2113
|
+
letter-spacing: 0.02em;
|
|
2114
|
+
color: ${tokens2.gray900};
|
|
2115
|
+
white-space: nowrap;
|
|
2116
|
+
text-align: ${(p) => p.$align ?? "left"};
|
|
2117
|
+
|
|
2118
|
+
${(p) => p.$sticky && css`
|
|
2119
|
+
position: sticky;
|
|
2120
|
+
top: ${p.$top ?? "0"};
|
|
2121
|
+
z-index: ${p.$z ?? tokens2.zHeader};
|
|
2122
|
+
box-shadow: ${tokens2.shadowStickyTop};
|
|
2123
|
+
`};
|
|
2124
|
+
|
|
2125
|
+
${(p) => p.$leftSticky && css`
|
|
2126
|
+
position: sticky;
|
|
2127
|
+
left: ${p.$leftOffset ?? "0"};
|
|
2128
|
+
z-index: ${(p.$z ?? tokens2.zHeader) + 1};
|
|
2129
|
+
box-shadow: ${tokens2.shadowStickyLeft}, ${tokens2.shadowStickyTop};
|
|
2130
|
+
`};
|
|
2131
|
+
`;
|
|
2132
|
+
var GroupHeaderButton = styled.button`
|
|
2133
|
+
display: inline-flex;
|
|
2134
|
+
align-items: center;
|
|
2135
|
+
gap: ${tokens2.spaceXs};
|
|
2136
|
+
background: transparent;
|
|
2137
|
+
border: 1px solid transparent;
|
|
2138
|
+
border-radius: ${tokens2.radiusSm};
|
|
2139
|
+
padding: 2px ${tokens2.spaceXs};
|
|
2140
|
+
font: inherit;
|
|
2141
|
+
color: inherit;
|
|
2142
|
+
cursor: pointer;
|
|
2143
|
+
text-transform: inherit;
|
|
2144
|
+
letter-spacing: inherit;
|
|
2145
|
+
|
|
2146
|
+
&:hover {
|
|
2147
|
+
background: ${tokens2.accentHover};
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
&:focus-visible {
|
|
2151
|
+
outline: 2px solid ${tokens2.accent};
|
|
2152
|
+
outline-offset: 1px;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
&[disabled] {
|
|
2156
|
+
cursor: default;
|
|
2157
|
+
&:hover {
|
|
2158
|
+
background: transparent;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
`;
|
|
2162
|
+
var Caret = styled.span`
|
|
2163
|
+
display: inline-block;
|
|
2164
|
+
width: 0;
|
|
2165
|
+
height: 0;
|
|
2166
|
+
border-left: 4px solid transparent;
|
|
2167
|
+
border-right: 4px solid transparent;
|
|
2168
|
+
border-top: 5px solid currentColor;
|
|
2169
|
+
transition: transform ${tokens2.transitionFast};
|
|
2170
|
+
transform: ${(p) => p.$open ? "rotate(0deg)" : "rotate(-90deg)"};
|
|
2171
|
+
`;
|
|
2172
|
+
var RowHeaderCell = styled.th`
|
|
2173
|
+
min-width: 220px;
|
|
2174
|
+
max-width: 320px;
|
|
2175
|
+
${(p) => p.$leftSticky && css`
|
|
2176
|
+
position: sticky;
|
|
2177
|
+
left: 0;
|
|
2178
|
+
z-index: ${tokens2.zRowHeader};
|
|
2179
|
+
box-shadow: ${tokens2.shadowStickyLeft};
|
|
2180
|
+
`};
|
|
2181
|
+
`;
|
|
2182
|
+
var RowHeaderInner = styled.div`
|
|
2183
|
+
display: flex;
|
|
2184
|
+
align-items: center;
|
|
2185
|
+
gap: ${tokens2.spaceMd};
|
|
2186
|
+
min-height: ${tokens2.rowMinHeight};
|
|
2187
|
+
`;
|
|
2188
|
+
var RowHeaderText = styled.div`
|
|
2189
|
+
display: flex;
|
|
2190
|
+
flex-direction: column;
|
|
2191
|
+
gap: 2px;
|
|
2192
|
+
min-width: 0;
|
|
2193
|
+
`;
|
|
2194
|
+
var RowLabel = styled.div`
|
|
2195
|
+
font-weight: ${tokens2.fontWeightMedium};
|
|
2196
|
+
color: ${tokens2.gray900};
|
|
2197
|
+
overflow: hidden;
|
|
2198
|
+
text-overflow: ellipsis;
|
|
2199
|
+
`;
|
|
2200
|
+
var RowSublabel = styled.div`
|
|
2201
|
+
color: ${tokens2.gray600};
|
|
2202
|
+
font-size: ${tokens2.fontSizeSmall};
|
|
2203
|
+
overflow: hidden;
|
|
2204
|
+
text-overflow: ellipsis;
|
|
2205
|
+
`;
|
|
2206
|
+
var RowMeta = styled.div`
|
|
2207
|
+
display: flex;
|
|
2208
|
+
flex-wrap: wrap;
|
|
2209
|
+
gap: ${tokens2.spaceXs};
|
|
2210
|
+
margin-left: auto;
|
|
2211
|
+
`;
|
|
2212
|
+
var MasterCell = styled.td`
|
|
2213
|
+
min-width: 96px;
|
|
2214
|
+
text-align: center;
|
|
2215
|
+
${(p) => p.$leftSticky && css`
|
|
2216
|
+
position: sticky;
|
|
2217
|
+
left: ${p.$leftOffset};
|
|
2218
|
+
z-index: ${tokens2.zMaster};
|
|
2219
|
+
box-shadow: ${tokens2.shadowStickyLeft};
|
|
2220
|
+
`};
|
|
2221
|
+
`;
|
|
2222
|
+
var LeafCell = styled.td`
|
|
2223
|
+
min-width: 88px;
|
|
2224
|
+
text-align: center;
|
|
2225
|
+
|
|
2226
|
+
&[data-disabled='true'] {
|
|
2227
|
+
opacity: 0.45;
|
|
2228
|
+
}
|
|
2229
|
+
`;
|
|
2230
|
+
var SummaryCell = styled.td`
|
|
2231
|
+
min-width: 88px;
|
|
2232
|
+
text-align: center;
|
|
2233
|
+
color: ${tokens2.gray600};
|
|
2234
|
+
font-variant-numeric: tabular-nums;
|
|
2235
|
+
`;
|
|
2236
|
+
var FillerCell = styled.td`
|
|
2237
|
+
width: 100%;
|
|
2238
|
+
padding: 0;
|
|
2239
|
+
`;
|
|
2240
|
+
var FillerHeaderCell = styled.th`
|
|
2241
|
+
width: 100%;
|
|
2242
|
+
padding: 0;
|
|
2243
|
+
|
|
2244
|
+
${(p) => p.$sticky && css`
|
|
2245
|
+
position: sticky;
|
|
2246
|
+
top: 0;
|
|
2247
|
+
z-index: ${tokens2.zHeader};
|
|
2248
|
+
background: ${tokens2.bg};
|
|
2249
|
+
box-shadow: ${tokens2.shadowStickyTop};
|
|
2250
|
+
`};
|
|
2251
|
+
`;
|
|
2252
|
+
var CellControlWrap = styled.div`
|
|
2253
|
+
display: inline-flex;
|
|
2254
|
+
align-items: center;
|
|
2255
|
+
justify-content: center;
|
|
2256
|
+
|
|
2257
|
+
/* Trim @wordpress/components default vertical margins inside table cells. */
|
|
2258
|
+
.components-checkbox-control,
|
|
2259
|
+
.components-toggle-control,
|
|
2260
|
+
.components-base-control,
|
|
2261
|
+
.components-base-control__field {
|
|
2262
|
+
margin: 0;
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
.components-checkbox-control__input-container {
|
|
2266
|
+
margin: 0;
|
|
2267
|
+
}
|
|
2268
|
+
`;
|
|
2269
|
+
var Caption = styled.caption`
|
|
2270
|
+
${visuallyHiddenCss2};
|
|
2271
|
+
`;
|
|
2272
|
+
var isExpanded = (group, expanded) => group.collapsible === false ? true : expanded.has(group.id);
|
|
2273
|
+
var MatrixHeader = ({
|
|
2274
|
+
groups,
|
|
2275
|
+
master,
|
|
2276
|
+
flat,
|
|
2277
|
+
stickyHeader,
|
|
2278
|
+
stickyFirstColumn,
|
|
2279
|
+
masterLeftOffset,
|
|
2280
|
+
expandedGroups,
|
|
2281
|
+
onToggleGroup,
|
|
2282
|
+
labels,
|
|
2283
|
+
renderHeader,
|
|
2284
|
+
rowHeaderLabel
|
|
2285
|
+
}) => {
|
|
2286
|
+
if (flat) {
|
|
2287
|
+
const cols = groups[0]?.columns ?? [];
|
|
2288
|
+
return /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
2289
|
+
/* @__PURE__ */ jsx(
|
|
2290
|
+
HeaderCell,
|
|
2291
|
+
{
|
|
2292
|
+
scope: "col",
|
|
2293
|
+
$sticky: stickyHeader,
|
|
2294
|
+
$leftSticky: stickyFirstColumn,
|
|
2295
|
+
$leftOffset: "0",
|
|
2296
|
+
children: rowHeaderLabel ?? ""
|
|
2297
|
+
}
|
|
2298
|
+
),
|
|
2299
|
+
master && /* @__PURE__ */ jsx(
|
|
2300
|
+
HeaderCell,
|
|
2301
|
+
{
|
|
2302
|
+
scope: "col",
|
|
2303
|
+
$sticky: stickyHeader,
|
|
2304
|
+
$leftSticky: stickyFirstColumn,
|
|
2305
|
+
$leftOffset: masterLeftOffset,
|
|
2306
|
+
$align: "center",
|
|
2307
|
+
children: master.label
|
|
2308
|
+
}
|
|
2309
|
+
),
|
|
2310
|
+
cols.map((col) => /* @__PURE__ */ jsx(
|
|
2311
|
+
HeaderCell,
|
|
2312
|
+
{
|
|
2313
|
+
scope: "col",
|
|
2314
|
+
$sticky: stickyHeader,
|
|
2315
|
+
$align: "center",
|
|
2316
|
+
"aria-description": col.description,
|
|
2317
|
+
children: renderHeader ? renderHeader(col) : col.label
|
|
2318
|
+
},
|
|
2319
|
+
col.id
|
|
2320
|
+
)),
|
|
2321
|
+
/* @__PURE__ */ jsx(FillerHeaderCell, { "aria-hidden": true, $sticky: stickyHeader })
|
|
2322
|
+
] }) });
|
|
2323
|
+
}
|
|
2324
|
+
const TOP_ROW_HEIGHT = "36px";
|
|
2325
|
+
return /* @__PURE__ */ jsxs("thead", { children: [
|
|
2326
|
+
/* @__PURE__ */ jsxs("tr", { children: [
|
|
2327
|
+
/* @__PURE__ */ jsx(
|
|
2328
|
+
HeaderCell,
|
|
2329
|
+
{
|
|
2330
|
+
scope: "col",
|
|
2331
|
+
rowSpan: 2,
|
|
2332
|
+
$sticky: stickyHeader,
|
|
2333
|
+
$leftSticky: stickyFirstColumn,
|
|
2334
|
+
$leftOffset: "0",
|
|
2335
|
+
children: rowHeaderLabel ?? ""
|
|
2336
|
+
}
|
|
2337
|
+
),
|
|
2338
|
+
master && /* @__PURE__ */ jsx(
|
|
2339
|
+
HeaderCell,
|
|
2340
|
+
{
|
|
2341
|
+
scope: "col",
|
|
2342
|
+
rowSpan: 2,
|
|
2343
|
+
$sticky: stickyHeader,
|
|
2344
|
+
$leftSticky: stickyFirstColumn,
|
|
2345
|
+
$leftOffset: masterLeftOffset,
|
|
2346
|
+
$align: "center",
|
|
2347
|
+
children: master.label
|
|
2348
|
+
}
|
|
2349
|
+
),
|
|
2350
|
+
groups.map((group) => {
|
|
2351
|
+
const open = isExpanded(group, expandedGroups);
|
|
2352
|
+
const span = open ? group.columns.length : 1;
|
|
2353
|
+
const collapsible = group.collapsible !== false;
|
|
2354
|
+
return /* @__PURE__ */ jsx(
|
|
2355
|
+
HeaderCell,
|
|
2356
|
+
{
|
|
2357
|
+
scope: "colgroup",
|
|
2358
|
+
colSpan: span,
|
|
2359
|
+
rowSpan: open ? 1 : 2,
|
|
2360
|
+
$sticky: stickyHeader,
|
|
2361
|
+
$align: "center",
|
|
2362
|
+
children: collapsible ? /* @__PURE__ */ jsxs(
|
|
2363
|
+
GroupHeaderButton,
|
|
2364
|
+
{
|
|
2365
|
+
type: "button",
|
|
2366
|
+
"aria-expanded": open,
|
|
2367
|
+
"aria-label": open ? labels.collapseGroup : labels.expandGroup,
|
|
2368
|
+
onClick: () => onToggleGroup(group.id),
|
|
2369
|
+
children: [
|
|
2370
|
+
/* @__PURE__ */ jsx(Caret, { $open: open, "aria-hidden": true }),
|
|
2371
|
+
group.label
|
|
2372
|
+
]
|
|
2373
|
+
}
|
|
2374
|
+
) : /* @__PURE__ */ jsx("span", { children: group.label })
|
|
2375
|
+
},
|
|
2376
|
+
group.id
|
|
2377
|
+
);
|
|
2378
|
+
}),
|
|
2379
|
+
/* @__PURE__ */ jsx(FillerHeaderCell, { "aria-hidden": true, rowSpan: 2, $sticky: stickyHeader })
|
|
2380
|
+
] }),
|
|
2381
|
+
/* @__PURE__ */ jsx("tr", { children: groups.map((group) => {
|
|
2382
|
+
const open = isExpanded(group, expandedGroups);
|
|
2383
|
+
if (!open) return null;
|
|
2384
|
+
return group.columns.map((col) => /* @__PURE__ */ jsx(
|
|
2385
|
+
HeaderCell,
|
|
2386
|
+
{
|
|
2387
|
+
scope: "col",
|
|
2388
|
+
$sticky: stickyHeader,
|
|
2389
|
+
$top: TOP_ROW_HEIGHT,
|
|
2390
|
+
$align: "center",
|
|
2391
|
+
"aria-description": col.description,
|
|
2392
|
+
children: renderHeader ? renderHeader(col) : col.label
|
|
2393
|
+
},
|
|
2394
|
+
`${group.id}::${col.id}`
|
|
2395
|
+
));
|
|
2396
|
+
}) })
|
|
2397
|
+
] });
|
|
2398
|
+
};
|
|
2399
|
+
|
|
2400
|
+
// components/matrix/utils.ts
|
|
2401
|
+
var cellKey = (rowId, colId) => `${rowId}::${colId}`;
|
|
2402
|
+
var selectionByRow = (value, rowId) => {
|
|
2403
|
+
const prefix = `${rowId}::`;
|
|
2404
|
+
const out = [];
|
|
2405
|
+
for (const key of value) {
|
|
2406
|
+
if (key.startsWith(prefix)) out.push(key.slice(prefix.length));
|
|
2407
|
+
}
|
|
2408
|
+
return out;
|
|
2409
|
+
};
|
|
2410
|
+
var toggleCell = (value, rowId, colId, checked) => {
|
|
2411
|
+
const next = new Set(value);
|
|
2412
|
+
if (checked) next.add(cellKey(rowId, colId));
|
|
2413
|
+
else next.delete(cellKey(rowId, colId));
|
|
2414
|
+
return next;
|
|
2415
|
+
};
|
|
2416
|
+
var normalizeGroups = (input) => {
|
|
2417
|
+
if (input.groups) return { groups: input.groups, flat: false };
|
|
2418
|
+
return {
|
|
2419
|
+
groups: [
|
|
2420
|
+
{
|
|
2421
|
+
id: "__flat__",
|
|
2422
|
+
label: "",
|
|
2423
|
+
columns: input.columns ?? [],
|
|
2424
|
+
collapsible: false,
|
|
2425
|
+
defaultExpanded: true
|
|
2426
|
+
}
|
|
2427
|
+
],
|
|
2428
|
+
flat: true
|
|
2429
|
+
};
|
|
2430
|
+
};
|
|
2431
|
+
var defaultLabels = (overrides = {}) => ({
|
|
2432
|
+
expandGroup: overrides.expandGroup ?? "Expand group",
|
|
2433
|
+
collapseGroup: overrides.collapseGroup ?? "Collapse group",
|
|
2434
|
+
groupSummary: overrides.groupSummary ?? ((selected, total) => `${selected} / ${total}`),
|
|
2435
|
+
cellToggled: overrides.cellToggled ?? ((rowLabel, colLabel, checked) => checked ? `${colLabel} added to ${rowLabel}` : `${colLabel} removed from ${rowLabel}`)
|
|
2436
|
+
});
|
|
2437
|
+
var toPlainText = (node) => {
|
|
2438
|
+
if (node === null || node === void 0 || node === false || node === true) return "";
|
|
2439
|
+
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
2440
|
+
if (Array.isArray(node)) return node.map(toPlainText).join(" ");
|
|
2441
|
+
if (typeof node === "object" && "props" in node) {
|
|
2442
|
+
const props = node.props;
|
|
2443
|
+
if (props && "children" in props) return toPlainText(props.children);
|
|
2444
|
+
}
|
|
2445
|
+
return "";
|
|
2446
|
+
};
|
|
2447
|
+
var MatrixCell = ({
|
|
2448
|
+
row,
|
|
2449
|
+
column,
|
|
2450
|
+
value,
|
|
2451
|
+
disabled,
|
|
2452
|
+
variant,
|
|
2453
|
+
onChange,
|
|
2454
|
+
renderCell
|
|
2455
|
+
}) => {
|
|
2456
|
+
const key = cellKey(row.id, column.id);
|
|
2457
|
+
const checked = value.has(key);
|
|
2458
|
+
const toggle = useCallback(
|
|
2459
|
+
(nextChecked) => {
|
|
2460
|
+
if (disabled) return;
|
|
2461
|
+
const next = toggleCell(value, row.id, column.id, nextChecked);
|
|
2462
|
+
onChange(next, { rowId: row.id, colId: column.id, checked: nextChecked });
|
|
2463
|
+
},
|
|
2464
|
+
[column.id, disabled, onChange, row.id, value]
|
|
2465
|
+
);
|
|
2466
|
+
const ariaLabel = `${toPlainText(row.label)} \u2014 ${toPlainText(column.label)}`;
|
|
2467
|
+
const content = renderCell ? renderCell({ row, column, checked, disabled, toggle, selectionKey: key }) : variant === "toggle" ? /* @__PURE__ */ jsx(
|
|
2468
|
+
ToggleControl,
|
|
2469
|
+
{
|
|
2470
|
+
__nextHasNoMarginBottom: true,
|
|
2471
|
+
label: "",
|
|
2472
|
+
checked,
|
|
2473
|
+
disabled,
|
|
2474
|
+
"aria-label": ariaLabel,
|
|
2475
|
+
onChange: toggle
|
|
2476
|
+
}
|
|
2477
|
+
) : /* @__PURE__ */ jsx(
|
|
2478
|
+
CheckboxControl,
|
|
2479
|
+
{
|
|
2480
|
+
__nextHasNoMarginBottom: true,
|
|
2481
|
+
label: "",
|
|
2482
|
+
checked,
|
|
2483
|
+
disabled,
|
|
2484
|
+
"aria-label": ariaLabel,
|
|
2485
|
+
onChange: toggle
|
|
2486
|
+
}
|
|
2487
|
+
);
|
|
2488
|
+
return /* @__PURE__ */ jsx(LeafCell, { "data-disabled": disabled || void 0, children: /* @__PURE__ */ jsx(CellControlWrap, { children: content }) });
|
|
2489
|
+
};
|
|
2490
|
+
var MatrixGroupSummary = ({ ctx, labels, render }) => {
|
|
2491
|
+
if (render) return /* @__PURE__ */ jsx(SummaryCell, { children: render(ctx) });
|
|
2492
|
+
return /* @__PURE__ */ jsx(SummaryCell, { children: labels.groupSummary(ctx.selectedCount, ctx.totalCount) });
|
|
2493
|
+
};
|
|
2494
|
+
var isGroupExpanded = (group, expanded) => group.collapsible === false ? true : expanded.has(group.id);
|
|
2495
|
+
var countSelected = (value, rowId, cols) => {
|
|
2496
|
+
let n = 0;
|
|
2497
|
+
for (const c of cols) if (value.has(cellKey(rowId, c.id))) n += 1;
|
|
2498
|
+
return n;
|
|
2499
|
+
};
|
|
2500
|
+
var MatrixRowView = ({
|
|
2501
|
+
row,
|
|
2502
|
+
groups,
|
|
2503
|
+
master,
|
|
2504
|
+
flat,
|
|
2505
|
+
value,
|
|
2506
|
+
expandedGroups,
|
|
2507
|
+
stickyFirstColumn,
|
|
2508
|
+
masterLeftOffset,
|
|
2509
|
+
variant,
|
|
2510
|
+
onChange,
|
|
2511
|
+
labels,
|
|
2512
|
+
renderCell,
|
|
2513
|
+
renderRowHeader,
|
|
2514
|
+
renderGroupSummary
|
|
2515
|
+
}) => {
|
|
2516
|
+
const masterChecked = master ? value.has(cellKey(row.id, master.id)) : true;
|
|
2517
|
+
const masterDisablesRow = master ? master.disablesRow !== false : false;
|
|
2518
|
+
const rowDisabled = master ? masterDisablesRow && !masterChecked : false;
|
|
2519
|
+
const toggleMaster = useCallback(
|
|
2520
|
+
(checked) => {
|
|
2521
|
+
if (!master) return;
|
|
2522
|
+
const next = toggleCell(value, row.id, master.id, checked);
|
|
2523
|
+
onChange(next, { rowId: row.id, colId: master.id, checked });
|
|
2524
|
+
},
|
|
2525
|
+
[master, onChange, row.id, value]
|
|
2526
|
+
);
|
|
2527
|
+
return /* @__PURE__ */ jsxs("tr", { children: [
|
|
2528
|
+
/* @__PURE__ */ jsx(RowHeaderCell, { scope: "row", $leftSticky: stickyFirstColumn, children: renderRowHeader ? renderRowHeader(row) : /* @__PURE__ */ jsxs(RowHeaderInner, { children: [
|
|
2529
|
+
row.avatar,
|
|
2530
|
+
/* @__PURE__ */ jsxs(RowHeaderText, { children: [
|
|
2531
|
+
/* @__PURE__ */ jsx(RowLabel, { children: row.label }),
|
|
2532
|
+
row.sublabel && /* @__PURE__ */ jsx(RowSublabel, { children: row.sublabel })
|
|
2533
|
+
] }),
|
|
2534
|
+
row.meta && /* @__PURE__ */ jsx(RowMeta, { children: row.meta })
|
|
2535
|
+
] }) }),
|
|
2536
|
+
master && /* @__PURE__ */ jsx(MasterCell, { $leftSticky: stickyFirstColumn, $leftOffset: masterLeftOffset, children: /* @__PURE__ */ jsx(CellControlWrap, { children: /* @__PURE__ */ jsx(
|
|
2537
|
+
ToggleControl,
|
|
2538
|
+
{
|
|
2539
|
+
__nextHasNoMarginBottom: true,
|
|
2540
|
+
label: "",
|
|
2541
|
+
checked: masterChecked,
|
|
2542
|
+
"aria-label": `${toPlainText(master.label)} \u2014 ${toPlainText(row.label)}`,
|
|
2543
|
+
onChange: toggleMaster
|
|
2544
|
+
}
|
|
2545
|
+
) }) }),
|
|
2546
|
+
flat ? groups[0].columns.map((col) => /* @__PURE__ */ jsx(
|
|
2547
|
+
MatrixCell,
|
|
2548
|
+
{
|
|
2549
|
+
row,
|
|
2550
|
+
column: col,
|
|
2551
|
+
value,
|
|
2552
|
+
disabled: rowDisabled,
|
|
2553
|
+
variant,
|
|
2554
|
+
onChange,
|
|
2555
|
+
renderCell
|
|
2556
|
+
},
|
|
2557
|
+
col.id
|
|
2558
|
+
)) : groups.flatMap((group) => {
|
|
2559
|
+
const open = isGroupExpanded(group, expandedGroups);
|
|
2560
|
+
if (!open) {
|
|
2561
|
+
return [
|
|
2562
|
+
/* @__PURE__ */ jsx(
|
|
2563
|
+
MatrixGroupSummary,
|
|
2564
|
+
{
|
|
2565
|
+
ctx: {
|
|
2566
|
+
row,
|
|
2567
|
+
group,
|
|
2568
|
+
selectedCount: countSelected(value, row.id, group.columns),
|
|
2569
|
+
totalCount: group.columns.length
|
|
2570
|
+
},
|
|
2571
|
+
labels,
|
|
2572
|
+
render: renderGroupSummary
|
|
2573
|
+
},
|
|
2574
|
+
group.id
|
|
2575
|
+
)
|
|
2576
|
+
];
|
|
2577
|
+
}
|
|
2578
|
+
return group.columns.map((col) => /* @__PURE__ */ jsx(
|
|
2579
|
+
MatrixCell,
|
|
2580
|
+
{
|
|
2581
|
+
row,
|
|
2582
|
+
column: col,
|
|
2583
|
+
value,
|
|
2584
|
+
disabled: rowDisabled,
|
|
2585
|
+
variant,
|
|
2586
|
+
onChange,
|
|
2587
|
+
renderCell
|
|
2588
|
+
},
|
|
2589
|
+
`${group.id}::${col.id}`
|
|
2590
|
+
));
|
|
2591
|
+
}),
|
|
2592
|
+
/* @__PURE__ */ jsx(FillerCell, { "aria-hidden": true })
|
|
2593
|
+
] });
|
|
2594
|
+
};
|
|
2595
|
+
var EmotionCacheProvider2 = ({ children }) => {
|
|
2596
|
+
const [head, setHead] = useState(null);
|
|
2597
|
+
const captureDocument = useCallback((node) => {
|
|
2598
|
+
if (!node) return;
|
|
2599
|
+
const owner = node.ownerDocument ?? document;
|
|
2600
|
+
setHead((prev) => prev === owner.head ? prev : owner.head);
|
|
2601
|
+
}, []);
|
|
2602
|
+
const cache = useMemo(() => {
|
|
2603
|
+
if (!head) return null;
|
|
2604
|
+
return createCache({ key: "valu-mx", container: head, prepend: true });
|
|
2605
|
+
}, [head]);
|
|
2606
|
+
if (!cache) {
|
|
2607
|
+
return /* @__PURE__ */ jsx("div", { ref: captureDocument, style: { display: "contents" } });
|
|
2608
|
+
}
|
|
2609
|
+
return /* @__PURE__ */ jsx(CacheProvider, { value: cache, children: /* @__PURE__ */ jsx("div", { ref: captureDocument, style: { display: "contents" }, children }) });
|
|
2610
|
+
};
|
|
2611
|
+
var useExpandedGroups = ({
|
|
2612
|
+
expanded: controlled,
|
|
2613
|
+
defaultExpanded,
|
|
2614
|
+
onChange
|
|
2615
|
+
}) => {
|
|
2616
|
+
const [uncontrolled, setUncontrolled] = useState(
|
|
2617
|
+
() => defaultExpanded ?? /* @__PURE__ */ new Set()
|
|
2618
|
+
);
|
|
2619
|
+
const isControlled = controlled !== void 0;
|
|
2620
|
+
const expanded = isControlled ? controlled : uncontrolled;
|
|
2621
|
+
const apply = useCallback(
|
|
2622
|
+
(next) => {
|
|
2623
|
+
if (!isControlled) setUncontrolled(next);
|
|
2624
|
+
onChange?.(next);
|
|
2625
|
+
},
|
|
2626
|
+
[isControlled, onChange]
|
|
2627
|
+
);
|
|
2628
|
+
const isExpanded2 = useCallback((groupId) => expanded.has(groupId), [expanded]);
|
|
2629
|
+
const toggle = useCallback(
|
|
2630
|
+
(groupId) => {
|
|
2631
|
+
const next = new Set(expanded);
|
|
2632
|
+
if (next.has(groupId)) next.delete(groupId);
|
|
2633
|
+
else next.add(groupId);
|
|
2634
|
+
apply(next);
|
|
2635
|
+
},
|
|
2636
|
+
[apply, expanded]
|
|
2637
|
+
);
|
|
2638
|
+
const expand = useCallback(
|
|
2639
|
+
(groupId) => {
|
|
2640
|
+
if (expanded.has(groupId)) return;
|
|
2641
|
+
const next = new Set(expanded);
|
|
2642
|
+
next.add(groupId);
|
|
2643
|
+
apply(next);
|
|
2644
|
+
},
|
|
2645
|
+
[apply, expanded]
|
|
2646
|
+
);
|
|
2647
|
+
const collapse = useCallback(
|
|
2648
|
+
(groupId) => {
|
|
2649
|
+
if (!expanded.has(groupId)) return;
|
|
2650
|
+
const next = new Set(expanded);
|
|
2651
|
+
next.delete(groupId);
|
|
2652
|
+
apply(next);
|
|
2653
|
+
},
|
|
2654
|
+
[apply, expanded]
|
|
2655
|
+
);
|
|
2656
|
+
return { expanded, isExpanded: isExpanded2, toggle, expand, collapse };
|
|
2657
|
+
};
|
|
2658
|
+
var DEFAULT_MAX_HEIGHT = "calc(100vh - 260px)";
|
|
2659
|
+
var Matrix = (props) => {
|
|
2660
|
+
const {
|
|
2661
|
+
rows,
|
|
2662
|
+
master,
|
|
2663
|
+
value,
|
|
2664
|
+
onChange,
|
|
2665
|
+
expanded,
|
|
2666
|
+
defaultExpanded,
|
|
2667
|
+
onExpandedChange,
|
|
2668
|
+
variant = "checkbox",
|
|
2669
|
+
renderCell,
|
|
2670
|
+
renderRowHeader,
|
|
2671
|
+
renderGroupSummary,
|
|
2672
|
+
renderHeader,
|
|
2673
|
+
stickyHeader = true,
|
|
2674
|
+
stickyFirstColumn = true,
|
|
2675
|
+
rowHeaderWidth = 220,
|
|
2676
|
+
maxHeight = DEFAULT_MAX_HEIGHT,
|
|
2677
|
+
caption,
|
|
2678
|
+
labels,
|
|
2679
|
+
className,
|
|
2680
|
+
id
|
|
2681
|
+
} = props;
|
|
2682
|
+
const reactId = useId();
|
|
2683
|
+
const rootId = id ?? `valu-mx-${reactId.replace(/:/g, "")}`;
|
|
2684
|
+
const { groups, flat } = useMemo(
|
|
2685
|
+
() => normalizeGroups({ columns: props.columns, groups: props.groups }),
|
|
2686
|
+
[props.columns, props.groups]
|
|
2687
|
+
);
|
|
2688
|
+
const resolvedLabels = useMemo(() => defaultLabels(labels), [labels]);
|
|
2689
|
+
const { expanded: expandedGroups, toggle: toggleGroup } = useExpandedGroups({
|
|
2690
|
+
expanded,
|
|
2691
|
+
defaultExpanded,
|
|
2692
|
+
onChange: onExpandedChange
|
|
2693
|
+
});
|
|
2694
|
+
const maxHeightCss = typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight;
|
|
2695
|
+
const cssLength = (v) => typeof v === "number" ? `${v}px` : v;
|
|
2696
|
+
const rowHeaderWidthCss = cssLength(rowHeaderWidth);
|
|
2697
|
+
const masterWidthCss = master ? cssLength(master.width ?? 96) : "0";
|
|
2698
|
+
const masterLeftOffset = rowHeaderWidthCss;
|
|
2699
|
+
return /* @__PURE__ */ jsx(EmotionCacheProvider2, { children: /* @__PURE__ */ jsx(Root2, { id: rootId, className, children: /* @__PURE__ */ jsx(Viewport, { $maxHeight: maxHeightCss, children: /* @__PURE__ */ jsxs(Table, { children: [
|
|
2700
|
+
caption && /* @__PURE__ */ jsx(Caption, { children: caption }),
|
|
2701
|
+
/* @__PURE__ */ jsxs("colgroup", { children: [
|
|
2702
|
+
/* @__PURE__ */ jsx("col", { style: { width: rowHeaderWidthCss } }),
|
|
2703
|
+
master && /* @__PURE__ */ jsx("col", { style: { width: masterWidthCss } })
|
|
2704
|
+
] }),
|
|
2705
|
+
/* @__PURE__ */ jsx(
|
|
2706
|
+
MatrixHeader,
|
|
2707
|
+
{
|
|
2708
|
+
groups,
|
|
2709
|
+
master,
|
|
2710
|
+
flat,
|
|
2711
|
+
stickyHeader,
|
|
2712
|
+
stickyFirstColumn,
|
|
2713
|
+
masterLeftOffset,
|
|
2714
|
+
expandedGroups,
|
|
2715
|
+
onToggleGroup: toggleGroup,
|
|
2716
|
+
labels: resolvedLabels,
|
|
2717
|
+
renderHeader
|
|
2718
|
+
}
|
|
2719
|
+
),
|
|
2720
|
+
/* @__PURE__ */ jsx("tbody", { children: rows.map((row) => /* @__PURE__ */ jsx(
|
|
2721
|
+
MatrixRowView,
|
|
2722
|
+
{
|
|
2723
|
+
row,
|
|
2724
|
+
groups,
|
|
2725
|
+
master,
|
|
2726
|
+
flat,
|
|
2727
|
+
value,
|
|
2728
|
+
expandedGroups,
|
|
2729
|
+
stickyFirstColumn,
|
|
2730
|
+
masterLeftOffset,
|
|
2731
|
+
variant,
|
|
2732
|
+
onChange,
|
|
2733
|
+
labels: resolvedLabels,
|
|
2734
|
+
renderCell,
|
|
2735
|
+
renderRowHeader,
|
|
2736
|
+
renderGroupSummary
|
|
2737
|
+
},
|
|
2738
|
+
row.id
|
|
2739
|
+
)) })
|
|
2740
|
+
] }) }) }) });
|
|
2741
|
+
};
|
|
2742
|
+
|
|
2743
|
+
export { ContentPicker, Matrix, cellKey, selectionByRow, toggleCell };
|
|
2025
2744
|
//# sourceMappingURL=index.js.map
|
|
2026
2745
|
//# sourceMappingURL=index.js.map
|