@fusion.dev/helix-headless 0.239.0 → 0.240.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/api.json +1 -1
- package/custom-elements.json +1 -1
- package/dist/column-manager/index.d.ts +1 -0
- package/dist/column-manager/index.js +1 -0
- package/dist/column-manager/root/column-manager-root.d.ts +137 -0
- package/dist/column-manager/root/column-manager-root.js +253 -0
- package/dist/data-table/binding.d.ts +85 -0
- package/dist/data-table/binding.js +58 -0
- package/dist/data-table/edit.d.ts +47 -0
- package/dist/data-table/edit.js +60 -0
- package/dist/data-table/events/before-cell-commit.d.ts +16 -0
- package/dist/data-table/events/before-cell-commit.js +11 -0
- package/dist/data-table/events/before-cell-edit.d.ts +13 -0
- package/dist/data-table/events/before-cell-edit.js +11 -0
- package/dist/data-table/events/before-export.d.ts +15 -0
- package/dist/data-table/events/before-export.js +11 -0
- package/dist/data-table/events/before-view-change.d.ts +16 -0
- package/dist/data-table/events/before-view-change.js +11 -0
- package/dist/data-table/events/cell-commit.d.ts +12 -0
- package/dist/data-table/events/cell-commit.js +11 -0
- package/dist/data-table/events/cell-edit.d.ts +11 -0
- package/dist/data-table/events/cell-edit.js +11 -0
- package/dist/data-table/events/details.d.ts +47 -0
- package/dist/data-table/events/export.d.ts +11 -0
- package/dist/data-table/events/export.js +11 -0
- package/dist/data-table/events/index.d.ts +18 -2
- package/dist/data-table/events/index.js +17 -1
- package/dist/data-table/events/view-change.d.ts +12 -0
- package/dist/data-table/events/view-change.js +11 -0
- package/dist/data-table/export.d.ts +43 -0
- package/dist/data-table/export.js +26 -0
- package/dist/data-table/index.d.ts +2 -0
- package/dist/data-table/index.js +2 -0
- package/dist/data-table/root/data-table-root.d.ts +406 -26
- package/dist/data-table/root/data-table-root.js +959 -30
- package/dist/data-table/view.d.ts +124 -0
- package/dist/data-table/view.js +249 -0
- package/dist/data-table/xlsx/index.d.ts +27 -0
- package/dist/data-table/xlsx/index.js +119 -0
- package/dist/date-input/root/date-input-root.d.ts +7 -0
- package/dist/date-input/root/date-input-root.js +9 -1
- package/dist/element-events.generated.js +9 -0
- package/dist/filter-input/root/filter-input-root.d.ts +31 -0
- package/dist/filter-input/root/filter-input-root.js +94 -12
- package/dist/filter-input/table.d.ts +64 -0
- package/dist/filter-input/table.js +76 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/input/root/input-root.d.ts +7 -0
- package/dist/input/root/input-root.js +9 -1
- package/dist/number-input/root/number-input-root.d.ts +7 -0
- package/dist/number-input/root/number-input-root.js +9 -1
- package/dist/quick-filters/events/before-view-save.d.ts +14 -0
- package/dist/quick-filters/events/before-view-save.js +11 -0
- package/dist/quick-filters/events/details.d.ts +10 -0
- package/dist/quick-filters/events/details.js +1 -0
- package/dist/quick-filters/events/index.d.ts +16 -0
- package/dist/quick-filters/events/index.js +9 -0
- package/dist/quick-filters/events/view-save.d.ts +11 -0
- package/dist/quick-filters/events/view-save.js +11 -0
- package/dist/quick-filters/filter/quick-filter.d.ts +48 -0
- package/dist/quick-filters/filter/quick-filter.js +33 -0
- package/dist/quick-filters/index.d.ts +3 -0
- package/dist/quick-filters/index.js +3 -0
- package/dist/quick-filters/root/quick-filters-root.d.ts +118 -0
- package/dist/quick-filters/root/quick-filters-root.js +183 -0
- package/dist/selection-bar/index.d.ts +1 -0
- package/dist/selection-bar/index.js +1 -0
- package/dist/selection-bar/root/selection-bar-root.d.ts +65 -0
- package/dist/selection-bar/root/selection-bar-root.js +44 -0
- package/dist/table/column/table-column.d.ts +82 -0
- package/dist/table/column/table-column.js +54 -0
- package/dist/table/column-type.d.ts +7 -0
- package/dist/table/column-type.js +1 -0
- package/dist/table-export/index.d.ts +1 -0
- package/dist/table-export/index.js +1 -0
- package/dist/table-export/root/table-export-root.d.ts +132 -0
- package/dist/table-export/root/table-export-root.js +233 -0
- package/dist/view-panel/index.d.ts +1 -0
- package/dist/view-panel/index.js +1 -0
- package/dist/view-panel/root/view-panel-root.d.ts +132 -0
- package/dist/view-panel/root/view-panel-root.js +209 -0
- package/examples.json +1 -1
- package/lint.json +1 -1
- package/package.json +5 -5
- package/types/jsx.d.ts +1231 -9
- package/types/svelte.d.ts +6 -0
- package/types/vue.d.ts +605 -6
- package/types/words.d.ts +305 -5
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Data Table's view: everything a reader can change about how the rows are
|
|
3
|
+
* shown, as one value that round-trips through JSON.
|
|
4
|
+
*
|
|
5
|
+
* **One value, so a view can be stored.** A URL, a saved view, a preset and a
|
|
6
|
+
* server request each need the query, the filters, the sort, the columns and
|
|
7
|
+
* the page size together, and five properties read one at a time can be caught
|
|
8
|
+
* half changed. The table still keeps `sort`, `filter`, `order`, `hidden` and
|
|
9
|
+
* `page-size`; each is a window on this value.
|
|
10
|
+
*
|
|
11
|
+
* String handling and comparisons with no DOM in them, so the pure spec covers
|
|
12
|
+
* it directly.
|
|
13
|
+
*/
|
|
14
|
+
import type { ColumnType } from '../table/column-type.js';
|
|
15
|
+
export type { ColumnType };
|
|
16
|
+
/** Which end of the row a pinned column stays at while the table scrolls. */
|
|
17
|
+
export type PinEdge = 'end' | 'start';
|
|
18
|
+
/** One filter on one column. */
|
|
19
|
+
export interface ViewFilter {
|
|
20
|
+
/** The column's `field`. */
|
|
21
|
+
field: string;
|
|
22
|
+
/** The comparison, one of the names `operatorsFor` gives for the column's type. */
|
|
23
|
+
operator: string;
|
|
24
|
+
/** What the field is compared to. A filter on one column matches any of them. */
|
|
25
|
+
values: string[];
|
|
26
|
+
}
|
|
27
|
+
/** The columns' arrangement. */
|
|
28
|
+
export interface ViewColumns {
|
|
29
|
+
/** The fields that are hidden. */
|
|
30
|
+
hidden: string[];
|
|
31
|
+
/** Every field in the order shown. An empty list keeps the written order. */
|
|
32
|
+
order: string[];
|
|
33
|
+
/** The fields pinned to an end of the row. */
|
|
34
|
+
pinned: Record<string, PinEdge>;
|
|
35
|
+
/** The widths a reader set, as CSS lengths, by field. */
|
|
36
|
+
widths: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
/** Everything a reader can change about how a Data Table shows its rows. */
|
|
39
|
+
export interface DataTableView {
|
|
40
|
+
/** The arrangement of the columns. */
|
|
41
|
+
columns: ViewColumns;
|
|
42
|
+
/** The column filters. Filters on different columns all have to match. */
|
|
43
|
+
filters: ViewFilter[];
|
|
44
|
+
/** The rows on a page, `0` for every row. */
|
|
45
|
+
pageSize: number;
|
|
46
|
+
/** The search text. */
|
|
47
|
+
query: string;
|
|
48
|
+
/** The sort order, as `field:direction`, or empty for the order the rows arrived in. */
|
|
49
|
+
sort: string;
|
|
50
|
+
}
|
|
51
|
+
/** A view with only some of its parts, such as a preset or a saved view. */
|
|
52
|
+
export type PartialView = {
|
|
53
|
+
[K in Exclude<keyof DataTableView, 'columns'>]?: DataTableView[K] | undefined;
|
|
54
|
+
} & {
|
|
55
|
+
columns?: {
|
|
56
|
+
[K in keyof ViewColumns]?: ViewColumns[K] | undefined;
|
|
57
|
+
} | undefined;
|
|
58
|
+
};
|
|
59
|
+
/** A view with nothing changed. */
|
|
60
|
+
export declare const emptyView: () => DataTableView;
|
|
61
|
+
/**
|
|
62
|
+
* Reads a view from a value that may have come from anywhere, such as JSON a
|
|
63
|
+
* reader saved. Anything that is not part of a view is left out, so a stored
|
|
64
|
+
* view from an older page still reads.
|
|
65
|
+
*/
|
|
66
|
+
export declare const readView: (value: unknown) => DataTableView;
|
|
67
|
+
/**
|
|
68
|
+
* Reads a partial view from a value that may have come from anywhere, keeping
|
|
69
|
+
* only the parts it names, so a preset that names its filters leaves the sort
|
|
70
|
+
* alone.
|
|
71
|
+
*/
|
|
72
|
+
export declare const readPartialView: (value: unknown) => PartialView;
|
|
73
|
+
/** Reads a view from JSON. Text that is not JSON reads as a view with nothing changed. */
|
|
74
|
+
export declare const parseView: (json: string) => DataTableView;
|
|
75
|
+
/** Writes a view as JSON, with its keys in a fixed order so two equal views write the same text. */
|
|
76
|
+
export declare const viewJson: (view: DataTableView) => string;
|
|
77
|
+
/** Whether two views show the rows the same way. */
|
|
78
|
+
export declare const sameView: (a: DataTableView, b: DataTableView) => boolean;
|
|
79
|
+
/**
|
|
80
|
+
* A view with the parts of another laid over it. A part the other names
|
|
81
|
+
* replaces the whole of that part, so a preset with `filters` clears every
|
|
82
|
+
* other filter, and one without leaves them alone.
|
|
83
|
+
*/
|
|
84
|
+
export declare const mergeView: (base: DataTableView, over: PartialView) => DataTableView;
|
|
85
|
+
/**
|
|
86
|
+
* Whether a view already holds everything a partial view names, which is how
|
|
87
|
+
* a preset knows it is the one in force.
|
|
88
|
+
*/
|
|
89
|
+
export declare const holdsView: (view: DataTableView, part: PartialView) => boolean;
|
|
90
|
+
/** One comparison a column's filter offers. */
|
|
91
|
+
export interface FilterOperatorInfo {
|
|
92
|
+
/** How many values it takes. */
|
|
93
|
+
arity: 'many' | 'none' | 'one' | 'two';
|
|
94
|
+
/** The words a reader is shown, in English. */
|
|
95
|
+
label: string;
|
|
96
|
+
/** Its name in a view. */
|
|
97
|
+
name: string;
|
|
98
|
+
}
|
|
99
|
+
/** The comparisons a column of a type offers, its default first. */
|
|
100
|
+
export declare const operatorsFor: (type: ColumnType) => readonly FilterOperatorInfo[];
|
|
101
|
+
/** The text a value is compared as, for text and enum columns. */
|
|
102
|
+
export declare const textOf: (value: unknown) => string;
|
|
103
|
+
/** Whether one value passes one filter, compared as its column's type. */
|
|
104
|
+
export declare const passes: (value: unknown, type: ColumnType, filter: ViewFilter) => boolean;
|
|
105
|
+
/** What the filters need of a column: how to read a row and what it holds. */
|
|
106
|
+
export interface FilterColumn {
|
|
107
|
+
field: string;
|
|
108
|
+
type: ColumnType;
|
|
109
|
+
value: (row: Readonly<Record<string, unknown>>) => unknown;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Whether a row passes every filter. Filters on different columns all have to
|
|
113
|
+
* match, and a filter's own values are any of, so `status: open, pending` and
|
|
114
|
+
* `owner: ada` is open or pending, and Ada's. A filter on a field no column
|
|
115
|
+
* declares is left out, so a stored view outlives a removed column.
|
|
116
|
+
*/
|
|
117
|
+
export declare const passesAll: (row: Readonly<Record<string, unknown>>, filters: readonly ViewFilter[], columns: ReadonlyMap<string, FilterColumn>) => boolean;
|
|
118
|
+
/** One value an enum column holds, and how many rows hold it. */
|
|
119
|
+
export interface Facet {
|
|
120
|
+
count: number;
|
|
121
|
+
value: string;
|
|
122
|
+
}
|
|
123
|
+
/** Every value a column holds across the rows, with how many rows hold each, most first. */
|
|
124
|
+
export declare const facetsOf: (rows: readonly Readonly<Record<string, unknown>>[], value: (row: Readonly<Record<string, unknown>>) => unknown) => Facet[];
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
export const emptyView = () => ({
|
|
2
|
+
columns: { hidden: [], order: [], pinned: {}, widths: {} },
|
|
3
|
+
filters: [],
|
|
4
|
+
pageSize: 0,
|
|
5
|
+
query: '',
|
|
6
|
+
sort: '',
|
|
7
|
+
});
|
|
8
|
+
const strings = (value) => Array.isArray(value) ? value.filter((one) => typeof one === 'string') : [];
|
|
9
|
+
const record = (value, allowed) => {
|
|
10
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const [key, one] of Object.entries(value)) {
|
|
15
|
+
if (typeof one === 'string' && (!allowed || allowed.includes(one))) {
|
|
16
|
+
out[key] = one;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
};
|
|
21
|
+
export const readView = (value) => {
|
|
22
|
+
const view = emptyView();
|
|
23
|
+
if (!value || typeof value !== 'object') {
|
|
24
|
+
return view;
|
|
25
|
+
}
|
|
26
|
+
const given = value;
|
|
27
|
+
return mergeView(view, {
|
|
28
|
+
columns: given.columns && typeof given.columns === 'object'
|
|
29
|
+
? (() => {
|
|
30
|
+
const columns = given.columns;
|
|
31
|
+
return {
|
|
32
|
+
hidden: strings(columns.hidden),
|
|
33
|
+
order: strings(columns.order),
|
|
34
|
+
pinned: record(columns.pinned, ['end', 'start']),
|
|
35
|
+
widths: record(columns.widths),
|
|
36
|
+
};
|
|
37
|
+
})()
|
|
38
|
+
: undefined,
|
|
39
|
+
filters: Array.isArray(given.filters)
|
|
40
|
+
? given.filters.flatMap((one) => {
|
|
41
|
+
if (!one || typeof one !== 'object') {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const { field, operator, values } = one;
|
|
45
|
+
return typeof field === 'string' && field !== ''
|
|
46
|
+
? [
|
|
47
|
+
{
|
|
48
|
+
field,
|
|
49
|
+
operator: typeof operator === 'string' ? operator : '',
|
|
50
|
+
values: strings(values),
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
: [];
|
|
54
|
+
})
|
|
55
|
+
: undefined,
|
|
56
|
+
pageSize: typeof given.pageSize === 'number' && given.pageSize >= 0
|
|
57
|
+
? Math.floor(given.pageSize)
|
|
58
|
+
: undefined,
|
|
59
|
+
query: typeof given.query === 'string' ? given.query : undefined,
|
|
60
|
+
sort: typeof given.sort === 'string' ? given.sort : undefined,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
export const readPartialView = (value) => {
|
|
64
|
+
if (!value || typeof value !== 'object') {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
const whole = readView(value);
|
|
68
|
+
const named = value;
|
|
69
|
+
const columns = named.columns;
|
|
70
|
+
return {
|
|
71
|
+
...('filters' in named ? { filters: whole.filters } : {}),
|
|
72
|
+
...('pageSize' in named ? { pageSize: whole.pageSize } : {}),
|
|
73
|
+
...('query' in named ? { query: whole.query } : {}),
|
|
74
|
+
...('sort' in named ? { sort: whole.sort } : {}),
|
|
75
|
+
...(columns && typeof columns === 'object'
|
|
76
|
+
? {
|
|
77
|
+
columns: Object.fromEntries(['hidden', 'order', 'pinned', 'widths']
|
|
78
|
+
.filter((key) => key in columns)
|
|
79
|
+
.map((key) => [key, whole.columns[key]])),
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export const parseView = (json) => {
|
|
85
|
+
try {
|
|
86
|
+
return readView(JSON.parse(json));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return emptyView();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export const viewJson = (view) => {
|
|
93
|
+
const sorted = (of) => Object.fromEntries(Object.entries(of).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
94
|
+
return JSON.stringify({
|
|
95
|
+
columns: {
|
|
96
|
+
hidden: [...view.columns.hidden].sort(),
|
|
97
|
+
order: view.columns.order,
|
|
98
|
+
pinned: sorted(view.columns.pinned),
|
|
99
|
+
widths: sorted(view.columns.widths),
|
|
100
|
+
},
|
|
101
|
+
filters: view.filters.map(({ field, operator, values }) => ({ field, operator, values })),
|
|
102
|
+
pageSize: view.pageSize,
|
|
103
|
+
query: view.query,
|
|
104
|
+
sort: view.sort,
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
export const sameView = (a, b) => viewJson(a) === viewJson(b);
|
|
108
|
+
export const mergeView = (base, over) => ({
|
|
109
|
+
columns: {
|
|
110
|
+
hidden: over.columns?.hidden ?? base.columns.hidden,
|
|
111
|
+
order: over.columns?.order ?? base.columns.order,
|
|
112
|
+
pinned: over.columns?.pinned ?? base.columns.pinned,
|
|
113
|
+
widths: over.columns?.widths ?? base.columns.widths,
|
|
114
|
+
},
|
|
115
|
+
filters: over.filters ?? base.filters,
|
|
116
|
+
pageSize: over.pageSize ?? base.pageSize,
|
|
117
|
+
query: over.query ?? base.query,
|
|
118
|
+
sort: over.sort ?? base.sort,
|
|
119
|
+
});
|
|
120
|
+
export const holdsView = (view, part) => sameView(mergeView(view, part), view);
|
|
121
|
+
const OPERATORS = {
|
|
122
|
+
boolean: [{ arity: 'one', label: 'is', name: 'is' }],
|
|
123
|
+
date: [
|
|
124
|
+
{ arity: 'one', label: 'on', name: 'on' },
|
|
125
|
+
{ arity: 'one', label: 'before', name: 'before' },
|
|
126
|
+
{ arity: 'one', label: 'after', name: 'after' },
|
|
127
|
+
{ arity: 'two', label: 'between', name: 'between' },
|
|
128
|
+
{ arity: 'none', label: 'is empty', name: 'empty' },
|
|
129
|
+
],
|
|
130
|
+
enum: [
|
|
131
|
+
{ arity: 'many', label: 'is any of', name: 'any' },
|
|
132
|
+
{ arity: 'many', label: 'is none of', name: 'none' },
|
|
133
|
+
{ arity: 'none', label: 'is empty', name: 'empty' },
|
|
134
|
+
],
|
|
135
|
+
number: [
|
|
136
|
+
{ arity: 'one', label: '=', name: 'eq' },
|
|
137
|
+
{ arity: 'one', label: '≠', name: 'ne' },
|
|
138
|
+
{ arity: 'one', label: '<', name: 'lt' },
|
|
139
|
+
{ arity: 'one', label: '≤', name: 'le' },
|
|
140
|
+
{ arity: 'one', label: '>', name: 'gt' },
|
|
141
|
+
{ arity: 'one', label: '≥', name: 'ge' },
|
|
142
|
+
{ arity: 'two', label: 'between', name: 'between' },
|
|
143
|
+
{ arity: 'none', label: 'is empty', name: 'empty' },
|
|
144
|
+
],
|
|
145
|
+
text: [
|
|
146
|
+
{ arity: 'many', label: 'contains', name: 'contains' },
|
|
147
|
+
{ arity: 'many', label: 'is', name: 'is' },
|
|
148
|
+
{ arity: 'many', label: 'is not', name: 'not' },
|
|
149
|
+
{ arity: 'none', label: 'is empty', name: 'empty' },
|
|
150
|
+
],
|
|
151
|
+
};
|
|
152
|
+
export const operatorsFor = (type) => OPERATORS[type];
|
|
153
|
+
const empty = (value) => value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
|
|
154
|
+
const dayOf = (value) => {
|
|
155
|
+
if (empty(value)) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
const time = value instanceof Date
|
|
159
|
+
? value.getTime()
|
|
160
|
+
: typeof value === 'number'
|
|
161
|
+
? value
|
|
162
|
+
: Date.parse(String(value));
|
|
163
|
+
return Number.isNaN(time) ? undefined : Math.floor(time / 86_400_000);
|
|
164
|
+
};
|
|
165
|
+
const numberOf = (value) => {
|
|
166
|
+
if (empty(value)) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
const number = typeof value === 'number' ? value : Number(String(value).replaceAll(',', ''));
|
|
170
|
+
return Number.isNaN(number) ? undefined : number;
|
|
171
|
+
};
|
|
172
|
+
export const textOf = (value) => value === undefined || value === null
|
|
173
|
+
? ''
|
|
174
|
+
: value instanceof Date
|
|
175
|
+
? value.toISOString()
|
|
176
|
+
: String(value);
|
|
177
|
+
const fold = (text) => text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
|
|
178
|
+
export const passes = (value, type, filter) => {
|
|
179
|
+
const { operator, values } = filter;
|
|
180
|
+
if (operator === 'empty') {
|
|
181
|
+
return empty(value);
|
|
182
|
+
}
|
|
183
|
+
if (type === 'number' || type === 'date') {
|
|
184
|
+
const read = type === 'number' ? numberOf : dayOf;
|
|
185
|
+
const it = read(value);
|
|
186
|
+
const [a, b] = values.map(read);
|
|
187
|
+
if (a === undefined || (operator === 'between' && b === undefined)) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (it === undefined) {
|
|
191
|
+
return operator === 'ne';
|
|
192
|
+
}
|
|
193
|
+
switch (operator) {
|
|
194
|
+
case 'eq':
|
|
195
|
+
case 'on':
|
|
196
|
+
return it === a;
|
|
197
|
+
case 'ne':
|
|
198
|
+
return it !== a;
|
|
199
|
+
case 'lt':
|
|
200
|
+
case 'before':
|
|
201
|
+
return it < a;
|
|
202
|
+
case 'le':
|
|
203
|
+
return it <= a;
|
|
204
|
+
case 'gt':
|
|
205
|
+
case 'after':
|
|
206
|
+
return it > a;
|
|
207
|
+
case 'ge':
|
|
208
|
+
return it >= a;
|
|
209
|
+
case 'between':
|
|
210
|
+
return it >= Math.min(a, b) && it <= Math.max(a, b);
|
|
211
|
+
default:
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (type === 'boolean') {
|
|
216
|
+
const [wanted] = values;
|
|
217
|
+
return wanted === undefined || String(Boolean(value) && value !== 'false') === wanted;
|
|
218
|
+
}
|
|
219
|
+
if (values.length === 0) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
const text = fold(textOf(value));
|
|
223
|
+
const folded = values.map(fold);
|
|
224
|
+
switch (operator) {
|
|
225
|
+
case 'contains':
|
|
226
|
+
return folded.some((one) => text.includes(one));
|
|
227
|
+
case 'none':
|
|
228
|
+
case 'not':
|
|
229
|
+
return !folded.includes(text);
|
|
230
|
+
default:
|
|
231
|
+
return folded.includes(text);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
export const passesAll = (row, filters, columns) => filters.every((filter) => {
|
|
235
|
+
const column = columns.get(filter.field);
|
|
236
|
+
return !column || passes(column.value(row), column.type, filter);
|
|
237
|
+
});
|
|
238
|
+
export const facetsOf = (rows, value) => {
|
|
239
|
+
const counts = new Map();
|
|
240
|
+
for (const row of rows) {
|
|
241
|
+
const text = textOf(value(row));
|
|
242
|
+
if (text !== '') {
|
|
243
|
+
counts.set(text, (counts.get(text) ?? 0) + 1);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return [...counts]
|
|
247
|
+
.map(([one, count]) => ({ count, value: one }))
|
|
248
|
+
.sort((a, b) => b.count - a.count || (a.value < b.value ? -1 : a.value > b.value ? 1 : 0));
|
|
249
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes a Data Table's export as an XLSX workbook, one sheet with the
|
|
3
|
+
* headings in its first row.
|
|
4
|
+
*
|
|
5
|
+
* Its own entry, `@fusion.dev/helix/data-table/xlsx`, so a table that never
|
|
6
|
+
* writes a spreadsheet does not carry it. Hand it to the table:
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { toXlsx } from '@fusion.dev/helix/data-table/xlsx'
|
|
10
|
+
* table.xlsx = toXlsx
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* The workbook is the smallest a spreadsheet opens: the parts the format
|
|
14
|
+
* requires, stored in a ZIP without compression, with text written in place
|
|
15
|
+
* and numbers kept as numbers. Text a spreadsheet would run as a formula is
|
|
16
|
+
* kept as text, the way the CSV writer keeps it.
|
|
17
|
+
*/
|
|
18
|
+
import type { ExportData } from '../export.js';
|
|
19
|
+
/** The CRC-32 a ZIP entry carries. */
|
|
20
|
+
export declare const crc32: (bytes: Uint8Array) => number;
|
|
21
|
+
/** Files stored in a ZIP, without compression, which every reader opens. */
|
|
22
|
+
export declare const zip: (files: readonly {
|
|
23
|
+
name: string;
|
|
24
|
+
text: string;
|
|
25
|
+
}[]) => Uint8Array;
|
|
26
|
+
/** Writes an export as an XLSX workbook. */
|
|
27
|
+
export declare const toXlsx: (data: ExportData) => Uint8Array;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const CRC_TABLE = (() => {
|
|
2
|
+
const table = new Uint32Array(256);
|
|
3
|
+
for (let n = 0; n < 256; n += 1) {
|
|
4
|
+
let c = n;
|
|
5
|
+
for (let k = 0; k < 8; k += 1) {
|
|
6
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
7
|
+
}
|
|
8
|
+
table[n] = c >>> 0;
|
|
9
|
+
}
|
|
10
|
+
return table;
|
|
11
|
+
})();
|
|
12
|
+
export const crc32 = (bytes) => {
|
|
13
|
+
let crc = 0xffffffff;
|
|
14
|
+
for (const byte of bytes) {
|
|
15
|
+
crc = CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
16
|
+
}
|
|
17
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
18
|
+
};
|
|
19
|
+
export const zip = (files) => {
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
const local = [];
|
|
22
|
+
const central = [];
|
|
23
|
+
let offset = 0;
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
const name = encoder.encode(file.name);
|
|
26
|
+
const data = encoder.encode(file.text);
|
|
27
|
+
const crc = crc32(data);
|
|
28
|
+
const head = new DataView(new ArrayBuffer(30));
|
|
29
|
+
head.setUint32(0, 0x04034b50, true);
|
|
30
|
+
head.setUint16(4, 20, true);
|
|
31
|
+
head.setUint16(6, 0x0800, true);
|
|
32
|
+
head.setUint32(14, crc, true);
|
|
33
|
+
head.setUint32(18, data.length, true);
|
|
34
|
+
head.setUint32(22, data.length, true);
|
|
35
|
+
head.setUint16(26, name.length, true);
|
|
36
|
+
local.push(new Uint8Array(head.buffer), name, data);
|
|
37
|
+
const entry = new DataView(new ArrayBuffer(46));
|
|
38
|
+
entry.setUint32(0, 0x02014b50, true);
|
|
39
|
+
entry.setUint16(4, 20, true);
|
|
40
|
+
entry.setUint16(6, 20, true);
|
|
41
|
+
entry.setUint16(8, 0x0800, true);
|
|
42
|
+
entry.setUint32(16, crc, true);
|
|
43
|
+
entry.setUint32(20, data.length, true);
|
|
44
|
+
entry.setUint32(24, data.length, true);
|
|
45
|
+
entry.setUint16(28, name.length, true);
|
|
46
|
+
entry.setUint32(42, offset, true);
|
|
47
|
+
central.push(new Uint8Array(entry.buffer), name);
|
|
48
|
+
offset += 30 + name.length + data.length;
|
|
49
|
+
}
|
|
50
|
+
const size = central.reduce((sum, part) => sum + part.length, 0);
|
|
51
|
+
const end = new DataView(new ArrayBuffer(22));
|
|
52
|
+
end.setUint32(0, 0x06054b50, true);
|
|
53
|
+
end.setUint16(8, files.length, true);
|
|
54
|
+
end.setUint16(10, files.length, true);
|
|
55
|
+
end.setUint32(12, size, true);
|
|
56
|
+
end.setUint32(16, offset, true);
|
|
57
|
+
const parts = [...local, ...central, new Uint8Array(end.buffer)];
|
|
58
|
+
const out = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
|
|
59
|
+
let at = 0;
|
|
60
|
+
for (const part of parts) {
|
|
61
|
+
out.set(part, at);
|
|
62
|
+
at += part.length;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
};
|
|
66
|
+
const xmlText = (text) => text
|
|
67
|
+
.replaceAll('&', '&')
|
|
68
|
+
.replaceAll('<', '<')
|
|
69
|
+
.replaceAll('>', '>')
|
|
70
|
+
.replaceAll('"', '"')
|
|
71
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, '');
|
|
72
|
+
const columnName = (index) => {
|
|
73
|
+
let name = '';
|
|
74
|
+
for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26)) {
|
|
75
|
+
name = String.fromCharCode(65 + ((n - 1) % 26)) + name;
|
|
76
|
+
}
|
|
77
|
+
return name;
|
|
78
|
+
};
|
|
79
|
+
const cell = (value, ref) => {
|
|
80
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
81
|
+
return `<c r="${ref}"><v>${value}</v></c>`;
|
|
82
|
+
}
|
|
83
|
+
if (typeof value === 'boolean') {
|
|
84
|
+
return `<c r="${ref}" t="b"><v>${value ? 1 : 0}</v></c>`;
|
|
85
|
+
}
|
|
86
|
+
if (value === undefined || value === null || value === '') {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
const text = value instanceof Date ? value.toISOString() : String(value);
|
|
90
|
+
return `<c r="${ref}" t="inlineStr"><is><t xml:space="preserve">${xmlText(text)}</t></is></c>`;
|
|
91
|
+
};
|
|
92
|
+
export const toXlsx = (data) => {
|
|
93
|
+
const lines = [data.headings, ...data.rows].map((values, row) => `<row r="${row + 1}">${values.map((value, column) => cell(value, `${columnName(column)}${row + 1}`)).join('')}</row>`);
|
|
94
|
+
const xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
95
|
+
const main = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';
|
|
96
|
+
const relations = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
97
|
+
return zip([
|
|
98
|
+
{
|
|
99
|
+
name: '[Content_Types].xml',
|
|
100
|
+
text: `${xml}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>`,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: '_rels/.rels',
|
|
104
|
+
text: `${xml}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="${relations}/officeDocument" Target="xl/workbook.xml"/></Relationships>`,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'xl/workbook.xml',
|
|
108
|
+
text: `${xml}<workbook xmlns="${main}" xmlns:r="${relations}"><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets></workbook>`,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'xl/_rels/workbook.xml.rels',
|
|
112
|
+
text: `${xml}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="${relations}/worksheet" Target="worksheets/sheet1.xml"/></Relationships>`,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'xl/worksheets/sheet1.xml',
|
|
116
|
+
text: `${xml}<worksheet xmlns="${main}"><sheetData>${lines.join('')}</sheetData></worksheet>`,
|
|
117
|
+
},
|
|
118
|
+
]);
|
|
119
|
+
};
|
|
@@ -583,6 +583,13 @@ export declare class HelixHeadlessDateInput extends HelixHeadlessDateInput_base
|
|
|
583
583
|
protected renderClearIcon(): TemplateResult;
|
|
584
584
|
/** The line of text the dates are typed into, where the field shows no segments. */
|
|
585
585
|
private renderControl;
|
|
586
|
+
/**
|
|
587
|
+
* A press on the field's own box, beside the text, puts focus in the text,
|
|
588
|
+
* as a press on a native field's padding does. Without it a field drawn
|
|
589
|
+
* narrower than its box, as a field sized to its value is, took no focus
|
|
590
|
+
* from most of its box.
|
|
591
|
+
*/
|
|
592
|
+
private readonly handleFieldPress;
|
|
586
593
|
protected render(): TemplateResult;
|
|
587
594
|
/**
|
|
588
595
|
* The value as a `Date`, at midnight UTC, or `null` while there is no date.
|
|
@@ -134,6 +134,14 @@ let HelixHeadlessDateInput = class HelixHeadlessDateInput extends MixinSegmented
|
|
|
134
134
|
}
|
|
135
135
|
void this.updateComplete.then(() => this.returnFocus());
|
|
136
136
|
};
|
|
137
|
+
this.handleFieldPress = (event) => {
|
|
138
|
+
const control = this.partNamed('control');
|
|
139
|
+
if (event.composedPath()[0] !== event.currentTarget || !control || this.disabled) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
control.focus();
|
|
144
|
+
};
|
|
137
145
|
}
|
|
138
146
|
static { this.words = 'helix-date-input'; }
|
|
139
147
|
get language() {
|
|
@@ -398,7 +406,7 @@ let HelixHeadlessDateInput = class HelixHeadlessDateInput extends MixinSegmented
|
|
|
398
406
|
}
|
|
399
407
|
render() {
|
|
400
408
|
return html `${this.renderLabel()}
|
|
401
|
-
<div part="field" @keydown=${this.handleKeydown}>
|
|
409
|
+
<div part="field" @keydown=${this.handleKeydown} @mousedown=${this.handleFieldPress}>
|
|
402
410
|
<slot name="start"></slot>
|
|
403
411
|
${this.mode === 'multiple'
|
|
404
412
|
? this.renderTokenRow(this.shownDates.map((date) => this.renderTag(date)), this.restCount)
|
|
@@ -103,15 +103,22 @@ registerElementEvents({
|
|
|
103
103
|
],
|
|
104
104
|
'helix-headless-copy-button': ['helix-copy', 'helix-copy-error', 'helix-press'],
|
|
105
105
|
'helix-headless-data-table': [
|
|
106
|
+
'helix-before-cell-commit',
|
|
107
|
+
'helix-before-cell-edit',
|
|
106
108
|
'helix-before-column-toggle',
|
|
109
|
+
'helix-before-export',
|
|
107
110
|
'helix-before-filter',
|
|
108
111
|
'helix-before-follow',
|
|
109
112
|
'helix-before-navigate',
|
|
110
113
|
'helix-before-reorder',
|
|
111
114
|
'helix-before-select',
|
|
112
115
|
'helix-before-sort',
|
|
116
|
+
'helix-before-view-change',
|
|
117
|
+
'helix-cell-commit',
|
|
118
|
+
'helix-cell-edit',
|
|
113
119
|
'helix-column-toggle',
|
|
114
120
|
'helix-expand',
|
|
121
|
+
'helix-export',
|
|
115
122
|
'helix-filter',
|
|
116
123
|
'helix-follow',
|
|
117
124
|
'helix-load-more',
|
|
@@ -119,6 +126,7 @@ registerElementEvents({
|
|
|
119
126
|
'helix-reorder',
|
|
120
127
|
'helix-select',
|
|
121
128
|
'helix-sort',
|
|
129
|
+
'helix-view-change',
|
|
122
130
|
],
|
|
123
131
|
'helix-headless-date-input': [
|
|
124
132
|
'change',
|
|
@@ -310,6 +318,7 @@ registerElementEvents({
|
|
|
310
318
|
'helix-headless-popover': ['helix-before-close', 'helix-before-open', 'toggle'],
|
|
311
319
|
'helix-headless-progress': ['helix-complete'],
|
|
312
320
|
'helix-headless-qr-code': ['error'],
|
|
321
|
+
'helix-headless-quick-filters': ['helix-before-view-save', 'helix-view-save'],
|
|
313
322
|
'helix-headless-radio': ['helix-before-select'],
|
|
314
323
|
'helix-headless-radio-group': ['change', 'helix-before-change', 'helix-before-select', 'input'],
|
|
315
324
|
'helix-headless-rating': [
|
|
@@ -253,6 +253,19 @@ export declare class HelixHeadlessFilterInput extends HelixHeadlessFilterInput_b
|
|
|
253
253
|
* what you slot and you narrow it.
|
|
254
254
|
*/
|
|
255
255
|
filterSuggestions: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* The id of a `DataTable` the field filters, in the same document or
|
|
258
|
+
* shadow root.
|
|
259
|
+
*
|
|
260
|
+
* Bound, the field searches the table as you type and offers each
|
|
261
|
+
* `filterable` column as a filter. Typing `status:open` makes a chip, and
|
|
262
|
+
* the suggestions list the columns and then a column's values, each with how
|
|
263
|
+
* many rows hold it. Every chip is a filter in the table's `view`, and a
|
|
264
|
+
* change to the view from anywhere else redraws the chips. Filters on
|
|
265
|
+
* different columns all have to match, and the values in one chip are any
|
|
266
|
+
* of. A `source` you set wins over the table's suggestions.
|
|
267
|
+
*/
|
|
268
|
+
for: string;
|
|
256
269
|
/**
|
|
257
270
|
* Whether the suggestions are still loading, such as while a request for the
|
|
258
271
|
* values of a typed key is out.
|
|
@@ -466,6 +479,24 @@ export declare class HelixHeadlessFilterInput extends HelixHeadlessFilterInput_b
|
|
|
466
479
|
* notification, which is sent only for a filter that stood.
|
|
467
480
|
*/
|
|
468
481
|
private readonly handleFacet;
|
|
482
|
+
/** The fields the grammar reads: the ones declared, then a bound table's. */
|
|
483
|
+
private get vocabularies();
|
|
484
|
+
/** The table named by `for`, once it is defined. */
|
|
485
|
+
private get boundTable();
|
|
486
|
+
/** The table this field listens to, so it can stop. */
|
|
487
|
+
private listened;
|
|
488
|
+
/** Listens to the table named by `for`, and to no other. */
|
|
489
|
+
private bindTable;
|
|
490
|
+
/** The table's view changed, from this field or from anywhere else. */
|
|
491
|
+
private readonly handleTableView;
|
|
492
|
+
/** Draws a chip for each filter in the bound table's view, and takes away the rest. */
|
|
493
|
+
private drawTableChips;
|
|
494
|
+
/** Searches a bound table by the text left once the filters are read out. */
|
|
495
|
+
private searchTable;
|
|
496
|
+
/** The suggestions: yours where you set `source`, and a bound table's otherwise. */
|
|
497
|
+
private get suggestionSource();
|
|
498
|
+
/** The table's suggestions, made once so the field does not ask again for a new function. */
|
|
499
|
+
private tableSuggestions;
|
|
469
500
|
/** Adds, updates or removes the chip for one filter. See `chips`. */
|
|
470
501
|
private drawChip;
|
|
471
502
|
/**
|