vira 28.19.6 → 28.19.7
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/elements/define-vira-element.d.ts +18 -0
- package/dist/elements/define-vira-element.js +19 -0
- package/dist/elements/form/vira-form-fields.d.ts +100 -0
- package/dist/elements/form/vira-form-fields.js +60 -0
- package/dist/elements/form/vira-form.element.d.ts +35 -0
- package/dist/elements/form/vira-form.element.js +151 -0
- package/dist/elements/index.js +25 -0
- package/dist/elements/pop-up/pop-up-helpers.d.ts +33 -0
- package/dist/elements/pop-up/pop-up-helpers.js +58 -0
- package/{src/elements/pop-up/pop-up-menu-item.ts → dist/elements/pop-up/pop-up-menu-item.d.ts} +3 -4
- package/dist/elements/pop-up/pop-up-menu-item.js +1 -0
- package/dist/elements/pop-up/vira-menu-item.element.d.ts +19 -0
- package/{src/elements/pop-up/vira-menu-item.element.ts → dist/elements/pop-up/vira-menu-item.element.js} +11 -28
- package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +41 -0
- package/dist/elements/pop-up/vira-menu-trigger.element.js +121 -0
- package/dist/elements/pop-up/vira-menu.element.d.ts +38 -0
- package/{src/elements/pop-up/vira-menu.element.ts → dist/elements/pop-up/vira-menu.element.js} +49 -76
- package/dist/elements/pop-up/vira-pop-up-menu.element.d.ts +35 -0
- package/{src/elements/pop-up/vira-pop-up-menu.element.ts → dist/elements/pop-up/vira-pop-up-menu.element.js} +22 -34
- package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +105 -0
- package/{src/elements/pop-up/vira-pop-up-trigger.element.ts → dist/elements/pop-up/vira-pop-up-trigger.element.js} +104 -199
- package/dist/elements/shared-text-input-logic.d.ts +63 -0
- package/dist/elements/shared-text-input-logic.js +101 -0
- package/dist/elements/vira-bold-text.element.d.ts +9 -0
- package/{src/elements/vira-bold-text.element.ts → dist/elements/vira-bold-text.element.js} +7 -8
- package/dist/elements/vira-button.element.d.ts +31 -0
- package/{src/elements/vira-button.element.ts → dist/elements/vira-button.element.js} +35 -66
- package/dist/elements/vira-card.element.d.ts +18 -0
- package/{src/elements/vira-card.element.ts → dist/elements/vira-card.element.js} +13 -16
- package/dist/elements/vira-checkbox.element.d.ts +34 -0
- package/{src/elements/vira-checkbox.element.ts → dist/elements/vira-checkbox.element.js} +28 -71
- package/dist/elements/vira-collapsible-wrapper.element.d.ts +14 -0
- package/{src/elements/vira-collapsible-wrapper.element.ts → dist/elements/vira-collapsible-wrapper.element.js} +16 -18
- package/dist/elements/vira-dropdown.element.d.ts +46 -0
- package/{src/elements/vira-dropdown.element.ts → dist/elements/vira-dropdown.element.js} +48 -94
- package/dist/elements/vira-error.element.d.ts +7 -0
- package/{src/elements/vira-error.element.ts → dist/elements/vira-error.element.js} +5 -6
- package/dist/elements/vira-icon.element.d.ts +13 -0
- package/{src/elements/vira-icon.element.ts → dist/elements/vira-icon.element.js} +6 -13
- package/dist/elements/vira-image.element.d.ts +45 -0
- package/{src/elements/vira-image.element.ts → dist/elements/vira-image.element.js} +43 -63
- package/dist/elements/vira-input.element.d.ts +62 -0
- package/{src/elements/vira-input.element.ts → dist/elements/vira-input.element.js} +85 -151
- package/dist/elements/vira-link.element.d.ts +73 -0
- package/{src/elements/vira-link.element.ts → dist/elements/vira-link.element.js} +11 -62
- package/dist/elements/vira-modal.element.d.ts +39 -0
- package/{src/elements/vira-modal.element.ts → dist/elements/vira-modal.element.js} +50 -89
- package/dist/elements/vira-overflow-switch.element.d.ts +21 -0
- package/dist/elements/vira-overflow-switch.element.js +110 -0
- package/dist/elements/vira-progress.element.d.ts +18 -0
- package/{src/elements/vira-progress.element.ts → dist/elements/vira-progress.element.js} +11 -26
- package/dist/elements/vira-select.element.d.ts +48 -0
- package/{src/elements/vira-select.element.ts → dist/elements/vira-select.element.js} +41 -96
- package/dist/icons/icon-color.test-helper.d.ts +6 -0
- package/dist/icons/icon-color.test-helper.js +9 -0
- package/dist/icons/icon-css-vars.d.ts +14 -0
- package/{src/icons/icon-css-vars.ts → dist/icons/icon-css-vars.js} +1 -2
- package/dist/icons/icon-svg.d.ts +27 -0
- package/dist/icons/icon-svg.js +48 -0
- package/dist/icons/icon-svgs/bell-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/bell-24.icon.ts → dist/icons/icon-svgs/bell-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/chat-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/chat-24.icon.ts → dist/icons/icon-svgs/chat-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/check-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/check-24.icon.ts → dist/icons/icon-svgs/check-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/chevron-down-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/chevron-down-24.icon.ts → dist/icons/icon-svgs/chevron-down-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/chevron-up-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/chevron-up-24.icon.ts → dist/icons/icon-svgs/chevron-up-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/close-x-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/close-x-24.icon.ts → dist/icons/icon-svgs/close-x-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/commit-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/commit-24.icon.ts → dist/icons/icon-svgs/commit-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/copy-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/copy-24.icon.ts → dist/icons/icon-svgs/copy-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/document-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/document-24.icon.ts → dist/icons/icon-svgs/document-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/document-search-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/document-search-24.icon.ts → dist/icons/icon-svgs/document-search-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/double-chevron-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/double-chevron-24.icon.ts → dist/icons/icon-svgs/double-chevron-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/element-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/element-16.icon.ts → dist/icons/icon-svgs/element-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/element-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/element-24.icon.ts → dist/icons/icon-svgs/element-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/external-link-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/external-link-24.icon.ts → dist/icons/icon-svgs/external-link-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/eye-closed-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/eye-closed-24.icon.ts → dist/icons/icon-svgs/eye-closed-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/eye-open-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/eye-open-24.icon.ts → dist/icons/icon-svgs/eye-open-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/filter-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/filter-24.icon.ts → dist/icons/icon-svgs/filter-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/link-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/link-24.icon.ts → dist/icons/icon-svgs/link-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/loader-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/loader-24.icon.ts → dist/icons/icon-svgs/loader-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/loader-animated-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/loader-animated-24.icon.ts → dist/icons/icon-svgs/loader-animated-24.icon.js} +6 -8
- package/dist/icons/icon-svgs/lock-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/lock-24.icon.ts → dist/icons/icon-svgs/lock-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/options-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/options-24.icon.ts → dist/icons/icon-svgs/options-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/pencil-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/pencil-24.icon.ts → dist/icons/icon-svgs/pencil-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/shield-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/shield-24.icon.ts → dist/icons/icon-svgs/shield-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/sort-ascending-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/sort-ascending-24.icon.ts → dist/icons/icon-svgs/sort-ascending-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/sort-descending-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/sort-descending-24.icon.ts → dist/icons/icon-svgs/sort-descending-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-loud-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-loud-24.icon.ts → dist/icons/icon-svgs/speaker-loud-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-medium-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-medium-24.icon.ts → dist/icons/icon-svgs/speaker-medium-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-muted-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-muted-24.icon.ts → dist/icons/icon-svgs/speaker-muted-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-quiet-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-quiet-24.icon.ts → dist/icons/icon-svgs/speaker-quiet-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/star-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/star-24.icon.ts → dist/icons/icon-svgs/star-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-failure-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-failure-24.icon.ts → dist/icons/icon-svgs/status-failure-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-in-progress-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-in-progress-24.icon.ts → dist/icons/icon-svgs/status-in-progress-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-success-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-success-24.icon.ts → dist/icons/icon-svgs/status-success-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-unknown-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-unknown-24.icon.ts → dist/icons/icon-svgs/status-unknown-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-warning-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-warning-24.icon.ts → dist/icons/icon-svgs/status-warning-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/upload-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/upload-24.icon.ts → dist/icons/icon-svgs/upload-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/x-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/x-24.icon.ts → dist/icons/icon-svgs/x-24.icon.js} +4 -5
- package/dist/icons/index.d.ts +86 -0
- package/{src/icons/index.ts → dist/icons/index.js} +39 -43
- package/dist/index.js +4 -0
- package/dist/styles/border.d.ts +9 -0
- package/{src/styles/border.ts → dist/styles/border.js} +1 -2
- package/dist/styles/disabled.d.ts +6 -0
- package/{src/styles/disabled.ts → dist/styles/disabled.js} +2 -3
- package/dist/styles/durations.d.ts +22 -0
- package/{src/styles/durations.ts → dist/styles/durations.js} +1 -2
- package/dist/styles/focus.d.ts +34 -0
- package/{src/styles/focus.ts → dist/styles/focus.js} +8 -29
- package/dist/styles/font.d.ts +9 -0
- package/{src/styles/font.ts → dist/styles/font.js} +1 -2
- package/dist/styles/form-styles.d.ts +20 -0
- package/{src/styles/form-styles.ts → dist/styles/form-styles.js} +1 -6
- package/{src/styles/index.ts → dist/styles/index.d.ts} +0 -1
- package/dist/styles/index.js +13 -0
- package/dist/styles/native-styles.d.ts +13 -0
- package/{src/styles/native-styles.ts → dist/styles/native-styles.js} +3 -5
- package/dist/styles/scrollbar.d.ts +6 -0
- package/{src/styles/scrollbar.ts → dist/styles/scrollbar.js} +3 -4
- package/dist/styles/shadows.d.ts +20 -0
- package/{src/styles/shadows.ts → dist/styles/shadows.js} +6 -8
- package/dist/styles/user-select.d.ts +6 -0
- package/{src/styles/user-select.ts → dist/styles/user-select.js} +2 -3
- package/dist/styles/vira-color-palette.d.ts +95 -0
- package/{src/styles/vira-color-palette.ts → dist/styles/vira-color-palette.js} +1 -11
- package/dist/styles/vira-color-theme.d.ts +1184 -0
- package/dist/styles/vira-color-theme.js +1138 -0
- package/dist/util/define-table.d.ts +110 -0
- package/dist/util/define-table.js +115 -0
- package/dist/util/dynamic-element.d.ts +63 -0
- package/dist/util/dynamic-element.js +61 -0
- package/dist/util/index.js +3 -0
- package/dist/util/pop-up-manager.d.ts +186 -0
- package/dist/util/pop-up-manager.js +214 -0
- package/package.json +6 -6
- package/src/elements/define-vira-element.ts +0 -29
- package/src/elements/form/vira-form-fields.ts +0 -140
- package/src/elements/form/vira-form.element.ts +0 -204
- package/src/elements/pop-up/pop-up-helpers.ts +0 -85
- package/src/elements/pop-up/vira-menu-trigger.element.ts +0 -158
- package/src/elements/shared-text-input-logic.ts +0 -173
- package/src/elements/vira-overflow-switch.element.ts +0 -137
- package/src/icons/icon-color.test-helper.ts +0 -9
- package/src/icons/icon-svg.ts +0 -71
- package/src/styles/vira-color-theme.ts +0 -1142
- package/src/util/define-table.ts +0 -279
- package/src/util/dynamic-element.ts +0 -129
- package/src/util/pop-up-manager.ts +0 -380
- /package/{src/elements/index.ts → dist/elements/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/util/index.ts → dist/util/index.d.ts} +0 -0
package/src/util/define-table.ts
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import {check} from '@augment-vir/assert';
|
|
2
|
-
import {filterMap, type ArrayElement, type PartialWithUndefined} from '@augment-vir/common';
|
|
3
|
-
import {type HtmlInterpolation} from 'element-vir';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An individual key definition in {@link ViraTableHeaders}.
|
|
7
|
-
*
|
|
8
|
-
* @category Internal
|
|
9
|
-
*/
|
|
10
|
-
export type ViraTableKey = Readonly<
|
|
11
|
-
{
|
|
12
|
-
/** The key that cells must set a value to. */
|
|
13
|
-
key: string | number;
|
|
14
|
-
} & PartialWithUndefined<{
|
|
15
|
-
/** If this is not provided, `key` will be used directly. */
|
|
16
|
-
content: HtmlInterpolation;
|
|
17
|
-
/** If set to `true`, this header (and it's column) won't be rendered. */
|
|
18
|
-
disabled: boolean;
|
|
19
|
-
}>
|
|
20
|
-
>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* All header definitions for a {@link ViraTable} instance.
|
|
24
|
-
*
|
|
25
|
-
* @category Internal
|
|
26
|
-
*/
|
|
27
|
-
export type ViraTableHeaders = ReadonlyArray<ViraTableKey>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* An individual entry in {@link ViraTable}. In default table orientation, this will be a row. In
|
|
31
|
-
* horizontal orientation, this will be a column.
|
|
32
|
-
*
|
|
33
|
-
* @category Internal
|
|
34
|
-
*/
|
|
35
|
-
export type ViraTableEntry<Headers extends ViraTableHeaders | undefined = undefined> = Record<
|
|
36
|
-
HeaderKey<Headers>,
|
|
37
|
-
HtmlInterpolation
|
|
38
|
-
>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* An individual cell in {@link ViraTableRow}.
|
|
42
|
-
*
|
|
43
|
-
* @category Internal
|
|
44
|
-
*/
|
|
45
|
-
export type ViraTableCell<
|
|
46
|
-
Headers extends ViraTableHeaders | undefined = undefined,
|
|
47
|
-
CellData = any,
|
|
48
|
-
> = {
|
|
49
|
-
content: HtmlInterpolation;
|
|
50
|
-
key: HeaderKey<Headers>;
|
|
51
|
-
/**
|
|
52
|
-
* The original entry that created this row (in default or vertical table orientation) or column
|
|
53
|
-
* (in horizontal table orientation). This is `undefined` in header cells.
|
|
54
|
-
*/
|
|
55
|
-
data: CellData;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* An individual row in {@link ViraTable}.
|
|
60
|
-
*
|
|
61
|
-
* @category Internal
|
|
62
|
-
*/
|
|
63
|
-
export type ViraTableRow<
|
|
64
|
-
Headers extends ViraTableHeaders | undefined = undefined,
|
|
65
|
-
CellData = any,
|
|
66
|
-
RowData = CellData,
|
|
67
|
-
> = {
|
|
68
|
-
cells: ViraTableCell<Headers, CellData>[];
|
|
69
|
-
data: RowData;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* All keys for the given headers.
|
|
74
|
-
*
|
|
75
|
-
* @category Internal
|
|
76
|
-
*/
|
|
77
|
-
export type HeaderKey<Headers extends ViraTableHeaders | undefined = undefined> =
|
|
78
|
-
undefined extends Headers ? string | number : ArrayElement<Exclude<Headers, undefined>>['key'];
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Table information that can easily be mapped into a `<table>` element.
|
|
82
|
-
*
|
|
83
|
-
* @category Internal
|
|
84
|
-
*/
|
|
85
|
-
export type ViraTable<
|
|
86
|
-
Headers extends ViraTableHeaders | undefined = undefined,
|
|
87
|
-
Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical,
|
|
88
|
-
OriginalData extends ReadonlyArray<any> = any[],
|
|
89
|
-
> = Orientation extends ViraTableOrientation.Horizontal
|
|
90
|
-
? {
|
|
91
|
-
headerRow: undefined;
|
|
92
|
-
orientation: Orientation;
|
|
93
|
-
rows: ViraTableRow<Headers, ArrayElement<OriginalData> | undefined, undefined>[];
|
|
94
|
-
}
|
|
95
|
-
: {
|
|
96
|
-
headerRow: ViraTableCell<Headers, undefined>[];
|
|
97
|
-
orientation: Orientation;
|
|
98
|
-
rows: ViraTableRow<Headers, ArrayElement<OriginalData>>[];
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Orientation options for {@link ViraTable}.
|
|
103
|
-
*
|
|
104
|
-
* @category Internal
|
|
105
|
-
*/
|
|
106
|
-
export enum ViraTableOrientation {
|
|
107
|
-
/**
|
|
108
|
-
* This corresponds to a _vertical_ entry sequence (as you move from entry to entry, you move
|
|
109
|
-
* across the table vertically). This is the default table layout. Each entry becomes a new row.
|
|
110
|
-
* Headers are in a separate row.
|
|
111
|
-
*/
|
|
112
|
-
Vertical = 'vertical',
|
|
113
|
-
/**
|
|
114
|
-
* This corresponds to a _horizontal_ entry sequence (as you move from entry to entry, you move
|
|
115
|
-
* across the table horizontally). Each entry becomes a column. Headers are the left most
|
|
116
|
-
* column.
|
|
117
|
-
*/
|
|
118
|
-
Horizontal = 'horizontal',
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Options for {@link defineTable}.
|
|
123
|
-
*
|
|
124
|
-
* @category Internal
|
|
125
|
-
*/
|
|
126
|
-
export type ViraTableOptions<Orientation extends ViraTableOrientation = ViraTableOrientation> =
|
|
127
|
-
PartialWithUndefined<{
|
|
128
|
-
orientation: Orientation;
|
|
129
|
-
hideHeaders: boolean;
|
|
130
|
-
}>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Accepts headers and entries and lays them out into rows according to the given
|
|
134
|
-
* `options.orientation` (defaulting to vertical). This does not itself create a `<table>` element,
|
|
135
|
-
* but makes it easy to loop over rows to (with `.map()`) to generate rows in a table.
|
|
136
|
-
*
|
|
137
|
-
* @category Table
|
|
138
|
-
*/
|
|
139
|
-
export function defineTable<
|
|
140
|
-
const Headers extends ViraTableHeaders,
|
|
141
|
-
OriginalData extends ReadonlyArray<any>,
|
|
142
|
-
const Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical,
|
|
143
|
-
>(
|
|
144
|
-
/** The order of these keys determines the order that they render in. */
|
|
145
|
-
headers: Readonly<Headers>,
|
|
146
|
-
originalData: OriginalData,
|
|
147
|
-
dataMap: (
|
|
148
|
-
entry: ArrayElement<OriginalData>,
|
|
149
|
-
entryIndex: number,
|
|
150
|
-
) => ViraTableEntry<Headers> | undefined,
|
|
151
|
-
options: ViraTableOptions<Orientation> = {},
|
|
152
|
-
): ViraTable<Headers, Orientation, OriginalData> {
|
|
153
|
-
const mappedData = originalData.map((dataRow, rowIndex) => {
|
|
154
|
-
return {
|
|
155
|
-
cells: dataMap(dataRow, rowIndex) as ViraTableEntry | undefined,
|
|
156
|
-
data: dataRow,
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (options.orientation === ViraTableOrientation.Horizontal) {
|
|
161
|
-
const rows: ViraTableRow<Headers, ArrayElement<OriginalData> | undefined, undefined>[] =
|
|
162
|
-
filterMap(
|
|
163
|
-
headers,
|
|
164
|
-
(
|
|
165
|
-
header,
|
|
166
|
-
):
|
|
167
|
-
| ViraTableRow<Headers, ArrayElement<OriginalData> | undefined, undefined>
|
|
168
|
-
| undefined => {
|
|
169
|
-
if (header.disabled) {
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const headerCellArray: ViraTableCell<Headers>[] = options.hideHeaders
|
|
174
|
-
? []
|
|
175
|
-
: [
|
|
176
|
-
{
|
|
177
|
-
content: header.content ?? header.key,
|
|
178
|
-
key: header.key,
|
|
179
|
-
data: undefined,
|
|
180
|
-
},
|
|
181
|
-
];
|
|
182
|
-
|
|
183
|
-
const cells: ViraTableCell<Headers, ArrayElement<OriginalData>>[] = filterMap(
|
|
184
|
-
mappedData,
|
|
185
|
-
({
|
|
186
|
-
data,
|
|
187
|
-
cells,
|
|
188
|
-
}): ViraTableCell<Headers, ArrayElement<OriginalData>> | undefined => {
|
|
189
|
-
if (!cells) {
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
content: cells[header.key],
|
|
195
|
-
key: header.key,
|
|
196
|
-
data,
|
|
197
|
-
};
|
|
198
|
-
},
|
|
199
|
-
check.isTruthy,
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const allCells = [
|
|
203
|
-
...headerCellArray,
|
|
204
|
-
...cells,
|
|
205
|
-
];
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
cells: allCells,
|
|
209
|
-
data: undefined,
|
|
210
|
-
};
|
|
211
|
-
},
|
|
212
|
-
check.isTruthy,
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
headerRow: undefined,
|
|
217
|
-
rows,
|
|
218
|
-
orientation: ViraTableOrientation.Horizontal,
|
|
219
|
-
} satisfies ViraTable<Headers, ViraTableOrientation.Horizontal> as ViraTable<
|
|
220
|
-
Headers,
|
|
221
|
-
Orientation
|
|
222
|
-
>;
|
|
223
|
-
} else {
|
|
224
|
-
const headerRow: ViraTableCell<Headers>[] = options.hideHeaders
|
|
225
|
-
? []
|
|
226
|
-
: filterMap(
|
|
227
|
-
headers,
|
|
228
|
-
(header): ViraTableCell<Headers> | undefined => {
|
|
229
|
-
if (header.disabled) {
|
|
230
|
-
return undefined;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return {
|
|
234
|
-
content: header.content ?? header.key,
|
|
235
|
-
key: header.key,
|
|
236
|
-
data: undefined,
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
check.isTruthy,
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const rows: ViraTableRow<Headers, ArrayElement<OriginalData>>[] = filterMap(
|
|
243
|
-
mappedData,
|
|
244
|
-
({cells, data}): ViraTableRow<Headers, ArrayElement<OriginalData>> | undefined => {
|
|
245
|
-
if (!cells) {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
cells: filterMap(
|
|
251
|
-
headers,
|
|
252
|
-
(
|
|
253
|
-
header,
|
|
254
|
-
): ViraTableCell<Headers, ArrayElement<OriginalData>> | undefined => {
|
|
255
|
-
if (header.disabled) {
|
|
256
|
-
return undefined;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
content: cells[header.key],
|
|
261
|
-
key: header.key,
|
|
262
|
-
data,
|
|
263
|
-
};
|
|
264
|
-
},
|
|
265
|
-
check.isTruthy,
|
|
266
|
-
),
|
|
267
|
-
data,
|
|
268
|
-
};
|
|
269
|
-
},
|
|
270
|
-
check.isTruthy,
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
headerRow,
|
|
275
|
-
rows,
|
|
276
|
-
orientation: ViraTableOrientation.Vertical,
|
|
277
|
-
} satisfies ViraTable<Headers> as ViraTable<Headers, Orientation>;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import {type Values} from '@augment-vir/common';
|
|
2
|
-
import {type AsyncProp, asyncProp, type DeclarativeElementDefinition} from 'element-vir';
|
|
3
|
-
import {type RequireExactlyOne} from 'type-fest';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Base type for loaders passed to {@link createDynamicElementLoader}.
|
|
7
|
-
*
|
|
8
|
-
* @category Internal
|
|
9
|
-
*/
|
|
10
|
-
export type BaseDynamicElementLoaders = Record<string, () => Promise<DeclarativeElementDefinition>>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create a dynamic element loader. This should go in your element state. This makes deferring
|
|
14
|
-
* element importing convenient and allows parts of your app to be placed in separate bundles. Make
|
|
15
|
-
* sure to also use {@link renderDynamicElement} to use the output of this loader.
|
|
16
|
-
*
|
|
17
|
-
* @category Util
|
|
18
|
-
* @see {@link renderDynamicElement}
|
|
19
|
-
* @see [example usage](https://github.com/electrovir/vira/blob/dev/packages/vira-book/src/element-book/entries/dynamic-elements.book.ts)
|
|
20
|
-
*/
|
|
21
|
-
export function createDynamicElementLoader<
|
|
22
|
-
const Loaders extends Readonly<BaseDynamicElementLoaders>,
|
|
23
|
-
>(loaders: Readonly<Loaders>): DynamicElementAsyncProp<Loaders> {
|
|
24
|
-
return asyncProp<DynamicElementValue<NoInfer<Loaders>>, keyof NoInfer<Loaders>>({
|
|
25
|
-
async updateCallback(elementKey, previousResolvedValue) {
|
|
26
|
-
if (previousResolvedValue && elementKey in previousResolvedValue.cache) {
|
|
27
|
-
return {
|
|
28
|
-
cache: previousResolvedValue.cache,
|
|
29
|
-
element: previousResolvedValue.cache[elementKey],
|
|
30
|
-
key: elementKey,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const imported = await loaders[elementKey]();
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
cache: {
|
|
38
|
-
...previousResolvedValue?.cache,
|
|
39
|
-
[elementKey]: imported,
|
|
40
|
-
},
|
|
41
|
-
element: imported,
|
|
42
|
-
key: elementKey,
|
|
43
|
-
} as any;
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The value for the async prop {@link DynamicElementAsyncProp}.
|
|
50
|
-
*
|
|
51
|
-
* @category Internal
|
|
52
|
-
*/
|
|
53
|
-
export type DynamicElementValue<Loaders extends BaseDynamicElementLoaders> = {
|
|
54
|
-
cache: Partial<Record<keyof Loaders, DeclarativeElementDefinition>>;
|
|
55
|
-
element: Awaited<ReturnType<Values<Loaders>>>;
|
|
56
|
-
key: keyof Loaders;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* An async prop for dynamic loading elements. This is the output from
|
|
60
|
-
* {@link createDynamicElementLoader}.
|
|
61
|
-
*
|
|
62
|
-
* @category Internal
|
|
63
|
-
*/
|
|
64
|
-
export type DynamicElementAsyncProp<Loaders extends BaseDynamicElementLoaders> = AsyncProp<
|
|
65
|
-
DynamicElementValue<Loaders>,
|
|
66
|
-
keyof Loaders
|
|
67
|
-
>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Params for the `ready` callback in {@link renderDynamicElement}.
|
|
71
|
-
*
|
|
72
|
-
* @category Internal
|
|
73
|
-
*/
|
|
74
|
-
export type ReadyParams<Loaders extends Readonly<BaseDynamicElementLoaders>> = RequireExactlyOne<{
|
|
75
|
-
[Key in keyof Loaders]: Awaited<ReturnType<Loaders[Key]>>;
|
|
76
|
-
}>;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Renders the current state of a dynamic element loader. This should go in your render function.
|
|
80
|
-
* Make sure to also use {@link createDynamicElementLoader} to create a dynamic loader in your
|
|
81
|
-
* element's state.
|
|
82
|
-
*
|
|
83
|
-
* @category Util
|
|
84
|
-
* @see {@link createDynamicElementLoader}
|
|
85
|
-
* @see [example usage](https://github.com/electrovir/vira/blob/dev/packages/vira-book/src/element-book/entries/dynamic-elements.book.ts)
|
|
86
|
-
*/
|
|
87
|
-
export function renderDynamicElement<
|
|
88
|
-
const Loaders extends BaseDynamicElementLoaders,
|
|
89
|
-
const LoadingReturnValue,
|
|
90
|
-
const ReadyReturnValue,
|
|
91
|
-
const ErrorReturnValue,
|
|
92
|
-
>(
|
|
93
|
-
asyncProp: DynamicElementAsyncProp<Loaders>,
|
|
94
|
-
{
|
|
95
|
-
ready,
|
|
96
|
-
loading,
|
|
97
|
-
error,
|
|
98
|
-
key,
|
|
99
|
-
}: {
|
|
100
|
-
/**
|
|
101
|
-
* If this is left undefined (or falsy), the current key will not be set, whatever the
|
|
102
|
-
* existing key is will continue to be used.
|
|
103
|
-
*/
|
|
104
|
-
key?: keyof NoInfer<Loaders> | undefined;
|
|
105
|
-
loading(this: void, params: Promise<ReadyParams<NoInfer<Loaders>>>): LoadingReturnValue;
|
|
106
|
-
ready(this: void, params: ReadyParams<NoInfer<Loaders>>): ReadyReturnValue;
|
|
107
|
-
error(this: void, error: Error): ErrorReturnValue;
|
|
108
|
-
},
|
|
109
|
-
): ReadyReturnValue | LoadingReturnValue | ErrorReturnValue {
|
|
110
|
-
if (key) {
|
|
111
|
-
(asyncProp.update as (key: keyof Loaders) => boolean)(key);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (asyncProp.value instanceof Error) {
|
|
115
|
-
return error(asyncProp.value);
|
|
116
|
-
} else if (asyncProp.value instanceof Promise) {
|
|
117
|
-
return loading(
|
|
118
|
-
asyncProp.value.then((value) => {
|
|
119
|
-
return {
|
|
120
|
-
[value.key]: value.element,
|
|
121
|
-
} as ReadyParams<Loaders>;
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
} else {
|
|
125
|
-
return ready({
|
|
126
|
-
[asyncProp.value.key]: asyncProp.value.element,
|
|
127
|
-
} as ReadyParams<Loaders>);
|
|
128
|
-
}
|
|
129
|
-
}
|