@affino/datagrid-vue-app 0.1.1 → 0.1.2

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.
Files changed (110) hide show
  1. package/dist/DataGrid.d.ts +9 -9
  2. package/dist/DataGridTableStage.vue.d.ts +112 -0
  3. package/dist/chunks/useDataGridAppRowModel-CcTL-h8L.js +11251 -0
  4. package/dist/gantt/DataGridGanttStage.vue.d.ts +21 -0
  5. package/dist/host/DataGridDefaultRenderer.d.ts +3 -3
  6. package/dist/host/DataGridRuntimeHost.d.ts +1 -1
  7. package/dist/index.js +1125 -4
  8. package/dist/internal.js +37 -14
  9. package/dist/overlays/DataGridAdvancedFilterPopover.vue.d.ts +62 -0
  10. package/dist/overlays/DataGridAggregationsPopover.vue.d.ts +62 -0
  11. package/dist/overlays/DataGridCellComboboxEditor.vue.d.ts +29 -0
  12. package/dist/overlays/DataGridColumnLayoutPopover.vue.d.ts +51 -0
  13. package/dist/overlays/DataGridColumnMenu.vue.d.ts +65 -0
  14. package/dist/overlays/DataGridFilterableCombobox.vue.d.ts +76 -0
  15. package/dist/stage/DataGridTableStage.vue.d.ts +115 -0
  16. package/dist/stage/DataGridTableStageCenterPane.vue.d.ts +121 -0
  17. package/dist/stage/DataGridTableStageFillActionMenu.vue.d.ts +30 -0
  18. package/dist/stage/DataGridTableStageHeader.vue.d.ts +84 -0
  19. package/dist/stage/DataGridTableStageOverlayLayer.vue.d.ts +34 -0
  20. package/dist/stage/DataGridTableStagePinnedPane.vue.d.ts +43 -0
  21. package/package.json +8 -5
  22. package/dist/DataGrid.js +0 -565
  23. package/dist/DataGridDefaultRenderer.js +0 -2
  24. package/dist/DataGridModuleHost.js +0 -2
  25. package/dist/DataGridRuntimeHost.js +0 -1
  26. package/dist/config/dataGridAdvancedFilter.js +0 -21
  27. package/dist/config/dataGridAggregations.js +0 -21
  28. package/dist/config/dataGridColumnLayout.js +0 -21
  29. package/dist/config/dataGridFormulaOptions.js +0 -137
  30. package/dist/config/dataGridPublicProps.js +0 -58
  31. package/dist/config/dataGridSavedView.js +0 -73
  32. package/dist/config/dataGridVirtualization.js +0 -32
  33. package/dist/dataGridAdvancedFilter.js +0 -1
  34. package/dist/dataGridAggregations.js +0 -1
  35. package/dist/dataGridAppContext.js +0 -1
  36. package/dist/dataGridCellComboboxState.d.ts +0 -10
  37. package/dist/dataGridCellComboboxState.js +0 -67
  38. package/dist/dataGridColumnLayout.js +0 -1
  39. package/dist/dataGridColumnMenu.d.ts +0 -9
  40. package/dist/dataGridColumnMenu.js +0 -21
  41. package/dist/dataGridEditability.js +0 -1
  42. package/dist/dataGridFilterableCombobox.js +0 -1
  43. package/dist/dataGridFormulaOptions.js +0 -1
  44. package/dist/dataGridGantt.d.ts +0 -3
  45. package/dist/dataGridGantt.js +0 -1
  46. package/dist/dataGridGanttDependencySelection.d.ts +0 -7
  47. package/dist/dataGridGanttDependencySelection.js +0 -46
  48. package/dist/dataGridGanttLabel.d.ts +0 -2
  49. package/dist/dataGridGanttLabel.js +0 -30
  50. package/dist/dataGridGanttSplit.d.ts +0 -20
  51. package/dist/dataGridGanttSplit.js +0 -31
  52. package/dist/dataGridGanttWheel.d.ts +0 -10
  53. package/dist/dataGridGanttWheel.js +0 -30
  54. package/dist/dataGridOverlayThemeVars.d.ts +0 -1
  55. package/dist/dataGridOverlayThemeVars.js +0 -32
  56. package/dist/dataGridPublicProps.js +0 -1
  57. package/dist/dataGridTableStage.types.js +0 -1
  58. package/dist/dataGridTableStageBody.types.js +0 -1
  59. package/dist/dataGridTableStageContext.js +0 -1
  60. package/dist/dataGridTheme.js +0 -1
  61. package/dist/dataGridVirtualization.js +0 -1
  62. package/dist/ensureDataGridAppStyles.js +0 -1
  63. package/dist/gantt/dataGridGantt.js +0 -1
  64. package/dist/gantt/dataGridGanttDependencySelection.js +0 -46
  65. package/dist/gantt/dataGridGanttLabel.js +0 -30
  66. package/dist/gantt/dataGridGanttSplit.js +0 -31
  67. package/dist/gantt/dataGridGanttWheel.js +0 -30
  68. package/dist/host/DataGridDefaultRenderer.js +0 -1847
  69. package/dist/host/DataGridModuleHost.js +0 -23
  70. package/dist/host/DataGridRuntimeHost.js +0 -174
  71. package/dist/overlays/dataGridCellComboboxState.js +0 -67
  72. package/dist/overlays/dataGridColumnMenu.js +0 -190
  73. package/dist/overlays/dataGridContextMenu.js +0 -218
  74. package/dist/overlays/dataGridFilterableCombobox.js +0 -74
  75. package/dist/overlays/dataGridOverlayThemeVars.js +0 -32
  76. package/dist/stage/dataGridTableStage.types.js +0 -1
  77. package/dist/stage/dataGridTableStageBody.types.js +0 -1
  78. package/dist/stage/dataGridTableStageContext.js +0 -88
  79. package/dist/stage/useDataGridTableStageBindings.js +0 -162
  80. package/dist/stage/useDataGridTableStageCellIo.js +0 -62
  81. package/dist/stage/useDataGridTableStageColumns.js +0 -124
  82. package/dist/stage/useDataGridTableStageFillAction.js +0 -28
  83. package/dist/stage/useDataGridTableStageHistory.js +0 -46
  84. package/dist/stage/useDataGridTableStageRowSelection.js +0 -107
  85. package/dist/stage/useDataGridTableStageRuntime.js +0 -526
  86. package/dist/stage/useDataGridTableStageScrollSync.js +0 -49
  87. package/dist/stage/useDataGridTableStageViewportKeyboard.js +0 -58
  88. package/dist/stage/useDataGridTableStageVisualSelection.js +0 -83
  89. package/dist/theme/dataGridTheme.js +0 -84
  90. package/dist/theme/ensureDataGridAppStyles.js +0 -2656
  91. package/dist/useDataGridAppControlledState.js +0 -390
  92. package/dist/useDataGridAppRowModel.js +0 -85
  93. package/dist/useDataGridTableStageBindings.js +0 -1
  94. package/dist/useDataGridTableStageCellIo.d.ts +0 -28
  95. package/dist/useDataGridTableStageCellIo.js +0 -62
  96. package/dist/useDataGridTableStageColumns.d.ts +0 -21
  97. package/dist/useDataGridTableStageColumns.js +0 -122
  98. package/dist/useDataGridTableStageFillAction.d.ts +0 -19
  99. package/dist/useDataGridTableStageFillAction.js +0 -28
  100. package/dist/useDataGridTableStageHistory.d.ts +0 -31
  101. package/dist/useDataGridTableStageHistory.js +0 -46
  102. package/dist/useDataGridTableStageRowSelection.d.ts +0 -28
  103. package/dist/useDataGridTableStageRowSelection.js +0 -103
  104. package/dist/useDataGridTableStageRuntime.js +0 -1
  105. package/dist/useDataGridTableStageScrollSync.d.ts +0 -17
  106. package/dist/useDataGridTableStageScrollSync.js +0 -49
  107. package/dist/useDataGridTableStageViewportKeyboard.d.ts +0 -20
  108. package/dist/useDataGridTableStageViewportKeyboard.js +0 -58
  109. package/dist/useDataGridTableStageVisualSelection.d.ts +0 -24
  110. package/dist/useDataGridTableStageVisualSelection.js +0 -70
@@ -1,23 +0,0 @@
1
- import { defineComponent, h } from "vue";
2
- export default defineComponent({
3
- name: "DataGridModuleHost",
4
- props: {
5
- modules: {
6
- type: Array,
7
- default: () => [],
8
- },
9
- },
10
- setup(props) {
11
- return () => {
12
- if (props.modules.length === 0) {
13
- return null;
14
- }
15
- return h("div", { class: "datagrid-app-toolbar" }, [
16
- h("div", { class: "datagrid-app-toolbar__group" }, props.modules.map(module => (h(module.component, {
17
- key: module.key,
18
- ...(module.props ?? {}),
19
- })))),
20
- ]);
21
- };
22
- },
23
- });
@@ -1,174 +0,0 @@
1
- import { computed, defineComponent, h, mergeProps, onBeforeUnmount, provide, ref, watch, } from "vue";
2
- import { useDataGridRuntime } from "@affino/datagrid-vue";
3
- import { applyDataGridTheme, } from "../theme/dataGridTheme";
4
- import { dataGridAppRootElementKey } from "../dataGridAppContext";
5
- export default defineComponent({
6
- name: "DataGridRuntimeHost",
7
- inheritAttrs: false,
8
- props: {
9
- rows: {
10
- type: Array,
11
- default: () => [],
12
- },
13
- rowModel: {
14
- type: Object,
15
- default: undefined,
16
- },
17
- columns: {
18
- type: Array,
19
- default: () => [],
20
- },
21
- theme: {
22
- type: [String, Object],
23
- default: undefined,
24
- },
25
- plugins: {
26
- type: Array,
27
- default: () => [],
28
- },
29
- services: {
30
- type: Object,
31
- default: undefined,
32
- },
33
- startupOrder: {
34
- type: Array,
35
- default: undefined,
36
- },
37
- autoStart: {
38
- type: Boolean,
39
- default: true,
40
- },
41
- renderMode: {
42
- type: String,
43
- default: "virtualization",
44
- },
45
- pagination: {
46
- type: Object,
47
- default: null,
48
- },
49
- },
50
- emits: ["cell-change", "selection-change"],
51
- setup(props, { attrs, slots, emit, expose }) {
52
- const rootElementRef = ref(null);
53
- provide(dataGridAppRootElementKey, rootElementRef);
54
- let themeObserver = null;
55
- const runtime = useDataGridRuntime({
56
- rows: computed(() => props.rows),
57
- rowModel: props.rowModel,
58
- columns: computed(() => props.columns),
59
- plugins: props.plugins,
60
- services: props.services,
61
- startupOrder: props.startupOrder,
62
- autoStart: props.autoStart,
63
- });
64
- const bodyRuntime = runtime;
65
- const publicRuntime = {
66
- api: runtime.api,
67
- syncBodyRowsInRange: runtime.syncBodyRowsInRange,
68
- rowPartition: runtime.rowPartition,
69
- virtualWindow: runtime.virtualWindow,
70
- columnSnapshot: runtime.columnSnapshot,
71
- getBodyRowAtIndex: bodyRuntime.getBodyRowAtIndex,
72
- resolveBodyRowIndexById: bodyRuntime.resolveBodyRowIndexById,
73
- };
74
- const syncPaginationState = () => {
75
- if (props.renderMode === "pagination") {
76
- const pagination = props.pagination ?? { pageSize: 100, currentPage: 0 };
77
- runtime.api.rows.setPagination({
78
- pageSize: Math.max(1, Math.trunc(pagination.pageSize)),
79
- currentPage: Math.max(0, Math.trunc(pagination.currentPage)),
80
- });
81
- return;
82
- }
83
- runtime.api.rows.setPagination(null);
84
- };
85
- watch(() => props.renderMode, () => {
86
- syncPaginationState();
87
- }, { immediate: true });
88
- watch(() => props.pagination, () => {
89
- syncPaginationState();
90
- }, { immediate: true, deep: true });
91
- if (typeof document !== "undefined") {
92
- themeObserver = new MutationObserver(() => {
93
- const rootElement = rootElementRef.value;
94
- if (!rootElement) {
95
- return;
96
- }
97
- applyDataGridTheme(rootElement, props.theme);
98
- });
99
- themeObserver.observe(document.documentElement, {
100
- attributes: true,
101
- attributeFilter: ["class", "data-theme"],
102
- });
103
- }
104
- watch([() => props.theme, rootElementRef], () => {
105
- const rootElement = rootElementRef.value;
106
- if (!rootElement) {
107
- return;
108
- }
109
- applyDataGridTheme(rootElement, props.theme);
110
- }, { immediate: true, deep: true });
111
- const unsubscribeRowsChanged = runtime.api.events.on("rows:changed", payload => {
112
- emit("cell-change", payload);
113
- });
114
- const unsubscribeSelectionChanged = runtime.api.events.on("selection:changed", payload => {
115
- emit("selection-change", payload);
116
- });
117
- onBeforeUnmount(() => {
118
- unsubscribeRowsChanged();
119
- unsubscribeSelectionChanged();
120
- themeObserver?.disconnect();
121
- themeObserver = null;
122
- });
123
- const slotVirtualWindow = computed(() => {
124
- const window = runtime.virtualWindow.value;
125
- return {
126
- ...(window ?? {}),
127
- rowTotal: window?.rowTotal ?? runtime.rowPartition.value.bodyRowCount,
128
- colTotal: runtime.columnSnapshot.value.visibleColumns.length,
129
- };
130
- });
131
- expose({
132
- api: runtime.api,
133
- core: runtime.core,
134
- runtime: publicRuntime,
135
- rowModel: runtime.rowModel,
136
- columnModel: runtime.columnModel,
137
- columnSnapshot: runtime.columnSnapshot,
138
- rowPartition: runtime.rowPartition,
139
- setRows: runtime.setRows,
140
- syncBodyRowsInRange: runtime.syncBodyRowsInRange,
141
- getBodyRowAtIndex: bodyRuntime.getBodyRowAtIndex,
142
- resolveBodyRowIndexById: bodyRuntime.resolveBodyRowIndexById,
143
- virtualWindow: runtime.virtualWindow,
144
- start: runtime.start,
145
- stop: runtime.stop,
146
- });
147
- return () => h("div", mergeProps(attrs, {
148
- ref: rootElementRef,
149
- class: "affino-datagrid-app-root",
150
- style: {
151
- display: "flex",
152
- flex: "1 1 auto",
153
- width: "100%",
154
- height: "100%",
155
- minHeight: "0",
156
- minWidth: "0",
157
- },
158
- }), slots.default?.({
159
- api: runtime.api,
160
- core: runtime.core,
161
- runtime: publicRuntime,
162
- grid: publicRuntime,
163
- rowModel: runtime.rowModel,
164
- columnModel: runtime.columnModel,
165
- columnSnapshot: runtime.columnSnapshot.value,
166
- rowPartition: runtime.rowPartition.value,
167
- setRows: runtime.setRows,
168
- syncBodyRowsInRange: runtime.syncBodyRowsInRange,
169
- getBodyRowAtIndex: bodyRuntime.getBodyRowAtIndex,
170
- resolveBodyRowIndexById: bodyRuntime.resolveBodyRowIndexById,
171
- virtualWindow: slotVirtualWindow.value,
172
- }) ?? []);
173
- },
174
- });
@@ -1,67 +0,0 @@
1
- export function createDataGridCellComboboxState(initial = {}) {
2
- return {
3
- open: initial.open ?? false,
4
- filter: initial.filter ?? "",
5
- activeIndex: initial.activeIndex ?? -1,
6
- };
7
- }
8
- export function setDataGridCellComboboxOpen(state, open) {
9
- if (state.open === open) {
10
- return state;
11
- }
12
- return {
13
- ...state,
14
- open,
15
- };
16
- }
17
- export function setDataGridCellComboboxFilter(state, filter) {
18
- if (state.filter === filter) {
19
- return state;
20
- }
21
- return {
22
- ...state,
23
- filter,
24
- };
25
- }
26
- export function activateDataGridCellComboboxIndex(state, index, optionCount) {
27
- const nextIndex = clampIndex(index, optionCount);
28
- if (nextIndex === state.activeIndex) {
29
- return state;
30
- }
31
- return {
32
- ...state,
33
- activeIndex: nextIndex,
34
- };
35
- }
36
- export function moveDataGridCellComboboxFocus(state, delta, optionCount, loop = true) {
37
- if (optionCount <= 0 || delta === 0) {
38
- return state;
39
- }
40
- if (state.activeIndex < 0) {
41
- return activateDataGridCellComboboxIndex(state, delta > 0 ? 0 : optionCount - 1, optionCount);
42
- }
43
- const rawTarget = state.activeIndex + Math.trunc(delta);
44
- if (loop) {
45
- return activateDataGridCellComboboxIndex(state, modulo(rawTarget, optionCount), optionCount);
46
- }
47
- return activateDataGridCellComboboxIndex(state, rawTarget, optionCount);
48
- }
49
- function clampIndex(index, optionCount) {
50
- if (optionCount <= 0) {
51
- return -1;
52
- }
53
- if (!Number.isFinite(index)) {
54
- return 0;
55
- }
56
- const normalized = Math.trunc(index);
57
- if (normalized < 0) {
58
- return 0;
59
- }
60
- if (normalized >= optionCount) {
61
- return optionCount - 1;
62
- }
63
- return normalized;
64
- }
65
- function modulo(value, divisor) {
66
- return ((value % divisor) + divisor) % divisor;
67
- }
@@ -1,190 +0,0 @@
1
- export const DATAGRID_COLUMN_MENU_ITEM_KEYS = ["sort", "group", "pin", "filter"];
2
- export const DATAGRID_COLUMN_MENU_ACTION_KEYS = [
3
- "sortAsc",
4
- "sortDesc",
5
- "clearSort",
6
- "toggleGroup",
7
- "pinMenu",
8
- "pinLeft",
9
- "pinRight",
10
- "unpin",
11
- "clearFilter",
12
- "addCurrentSelectionToFilter",
13
- "selectAllValues",
14
- "clearAllValues",
15
- "applyFilter",
16
- "cancelFilter",
17
- ];
18
- const DEFAULT_MAX_FILTER_VALUES = 120;
19
- function normalizeItems(input) {
20
- const allowed = new Set(DATAGRID_COLUMN_MENU_ITEM_KEYS);
21
- const source = Array.isArray(input) ? input : DATAGRID_COLUMN_MENU_ITEM_KEYS;
22
- const normalized = [];
23
- for (const item of source) {
24
- if (!allowed.has(item) || normalized.includes(item)) {
25
- continue;
26
- }
27
- normalized.push(item);
28
- }
29
- return normalized.length > 0 ? normalized : [...DATAGRID_COLUMN_MENU_ITEM_KEYS];
30
- }
31
- function normalizeItemSubset(input) {
32
- if (!Array.isArray(input)) {
33
- return [];
34
- }
35
- const allowed = new Set(DATAGRID_COLUMN_MENU_ITEM_KEYS);
36
- const normalized = [];
37
- for (const item of input) {
38
- if (!allowed.has(item) || normalized.includes(item)) {
39
- continue;
40
- }
41
- normalized.push(item);
42
- }
43
- return normalized;
44
- }
45
- function normalizeLabels(input) {
46
- if (!input) {
47
- return Object.freeze({});
48
- }
49
- const entries = Object.entries(input)
50
- .filter(([key, value]) => DATAGRID_COLUMN_MENU_ITEM_KEYS.includes(key) && typeof value === "string")
51
- .map(([key, value]) => [key, value.trim()])
52
- .filter(([, value]) => value.length > 0);
53
- return Object.freeze(Object.fromEntries(entries));
54
- }
55
- function normalizeDisabledReasons(input) {
56
- if (!input) {
57
- return Object.freeze({});
58
- }
59
- const entries = Object.entries(input)
60
- .filter(([key, value]) => DATAGRID_COLUMN_MENU_ITEM_KEYS.includes(key) && typeof value === "string")
61
- .map(([key, value]) => [key, value.trim()])
62
- .filter(([, value]) => value.length > 0);
63
- return Object.freeze(Object.fromEntries(entries));
64
- }
65
- function normalizeActionOptions(input) {
66
- if (!input) {
67
- return Object.freeze({});
68
- }
69
- const entries = Object.entries(input)
70
- .filter(([key, value]) => DATAGRID_COLUMN_MENU_ACTION_KEYS.includes(key) && Boolean(value))
71
- .map(([key, value]) => {
72
- const option = value;
73
- const normalized = {
74
- ...(option.hidden === true ? { hidden: true } : {}),
75
- ...(option.disabled === true ? { disabled: true } : {}),
76
- ...(typeof option.disabledReason === "string" && option.disabledReason.trim().length > 0
77
- ? { disabledReason: option.disabledReason.trim() }
78
- : {}),
79
- ...(typeof option.label === "string" && option.label.trim().length > 0
80
- ? { label: option.label.trim() }
81
- : {}),
82
- };
83
- return [key, Object.freeze(normalized)];
84
- })
85
- .filter(([, value]) => Object.keys(value).length > 0);
86
- return Object.freeze(Object.fromEntries(entries));
87
- }
88
- function normalizeColumns(input) {
89
- if (!input) {
90
- return {};
91
- }
92
- const normalizedEntries = Object.entries(input)
93
- .filter(([key]) => key.trim().length > 0)
94
- .map(([key, value]) => {
95
- const items = value?.items ? normalizeItems(value.items) : undefined;
96
- const hide = normalizeItemSubset(value?.hide);
97
- const disabled = normalizeItemSubset(value?.disabled);
98
- const disabledReasons = normalizeDisabledReasons(value?.disabledReasons);
99
- const labels = normalizeLabels(value?.labels);
100
- const actions = normalizeActionOptions(value?.actions);
101
- return [
102
- key,
103
- {
104
- ...(items ? { items } : {}),
105
- ...(hide.length > 0 ? { hide } : {}),
106
- ...(disabled.length > 0 ? { disabled } : {}),
107
- ...(Object.keys(disabledReasons).length > 0 ? { disabledReasons } : {}),
108
- ...(Object.keys(labels).length > 0 ? { labels } : {}),
109
- ...(Object.keys(actions).length > 0 ? { actions } : {}),
110
- },
111
- ];
112
- });
113
- return Object.fromEntries(normalizedEntries);
114
- }
115
- export function resolveDataGridColumnMenu(input) {
116
- if (typeof input === "boolean") {
117
- return {
118
- enabled: input,
119
- maxFilterValues: DEFAULT_MAX_FILTER_VALUES,
120
- items: [...DATAGRID_COLUMN_MENU_ITEM_KEYS],
121
- disabled: [],
122
- disabledReasons: Object.freeze({}),
123
- labels: Object.freeze({}),
124
- actions: Object.freeze({}),
125
- columns: {},
126
- };
127
- }
128
- if (!input) {
129
- return {
130
- enabled: false,
131
- maxFilterValues: DEFAULT_MAX_FILTER_VALUES,
132
- items: [...DATAGRID_COLUMN_MENU_ITEM_KEYS],
133
- disabled: [],
134
- disabledReasons: Object.freeze({}),
135
- labels: Object.freeze({}),
136
- actions: Object.freeze({}),
137
- columns: {},
138
- };
139
- }
140
- return {
141
- enabled: input.enabled ?? true,
142
- maxFilterValues: Number.isFinite(input.maxFilterValues)
143
- ? Math.max(20, Math.trunc(input.maxFilterValues))
144
- : DEFAULT_MAX_FILTER_VALUES,
145
- items: normalizeItems(input.items),
146
- disabled: normalizeItemSubset(input.disabled),
147
- disabledReasons: normalizeDisabledReasons(input.disabledReasons),
148
- labels: normalizeLabels(input.labels),
149
- actions: normalizeActionOptions(input.actions),
150
- columns: normalizeColumns(input.columns),
151
- };
152
- }
153
- export function resolveDataGridColumnMenuItems(options, columnKey) {
154
- const columnOptions = options.columns[columnKey];
155
- const baseItems = columnOptions?.items ? normalizeItems(columnOptions.items) : options.items;
156
- const hidden = new Set(columnOptions?.hide ?? []);
157
- const filtered = baseItems.filter(item => !hidden.has(item));
158
- return filtered.length > 0 ? filtered : [];
159
- }
160
- export function resolveDataGridColumnMenuDisabledItems(options, columnKey) {
161
- const visibleItems = resolveDataGridColumnMenuItems(options, columnKey);
162
- const columnDisabled = new Set(options.columns[columnKey]?.disabled ?? []);
163
- const globallyDisabled = new Set(options.disabled);
164
- return visibleItems.filter(item => globallyDisabled.has(item) || columnDisabled.has(item));
165
- }
166
- export function resolveDataGridColumnMenuLabels(options, columnKey) {
167
- return Object.freeze({
168
- ...options.labels,
169
- ...(options.columns[columnKey]?.labels ?? {}),
170
- });
171
- }
172
- export function resolveDataGridColumnMenuDisabledReasons(options, columnKey) {
173
- return Object.freeze({
174
- ...options.disabledReasons,
175
- ...(options.columns[columnKey]?.disabledReasons ?? {}),
176
- });
177
- }
178
- export function resolveDataGridColumnMenuActionOptions(options, columnKey) {
179
- const columnActions = options.columns[columnKey]?.actions ?? {};
180
- const entries = DATAGRID_COLUMN_MENU_ACTION_KEYS
181
- .map(actionKey => {
182
- const merged = {
183
- ...(options.actions[actionKey] ?? {}),
184
- ...(columnActions[actionKey] ?? {}),
185
- };
186
- return [actionKey, Object.freeze(merged)];
187
- })
188
- .filter(([, value]) => Object.keys(value).length > 0);
189
- return Object.freeze(Object.fromEntries(entries));
190
- }
@@ -1,218 +0,0 @@
1
- export const DATAGRID_CELL_MENU_ITEM_KEYS = ["clipboard", "edit"];
2
- export const DATAGRID_CELL_MENU_ACTION_KEYS = ["cut", "copy", "paste", "clear"];
3
- export const DATAGRID_ROW_INDEX_MENU_ITEM_KEYS = ["insert", "clipboard", "selection"];
4
- export const DATAGRID_ROW_INDEX_MENU_ACTION_KEYS = [
5
- "insertAbove",
6
- "insertBelow",
7
- "cut",
8
- "copy",
9
- "paste",
10
- "deleteSelected",
11
- ];
12
- function normalizeItems(input, allowedKeys) {
13
- const allowed = new Set(allowedKeys);
14
- const source = Array.isArray(input) ? input : allowedKeys;
15
- const normalized = [];
16
- for (const item of source) {
17
- if (!allowed.has(item) || normalized.includes(item)) {
18
- continue;
19
- }
20
- normalized.push(item);
21
- }
22
- return normalized.length > 0 ? normalized : [...allowedKeys];
23
- }
24
- function normalizeItemSubset(input, allowedKeys) {
25
- if (!Array.isArray(input)) {
26
- return [];
27
- }
28
- const allowed = new Set(allowedKeys);
29
- const normalized = [];
30
- for (const item of input) {
31
- if (!allowed.has(item) || normalized.includes(item)) {
32
- continue;
33
- }
34
- normalized.push(item);
35
- }
36
- return normalized;
37
- }
38
- function normalizeLabels(input, allowedKeys) {
39
- if (!input) {
40
- return Object.freeze({});
41
- }
42
- const entries = Object.entries(input)
43
- .filter((entry) => allowedKeys.includes(entry[0]) && typeof entry[1] === "string")
44
- .map(([key, value]) => [key, value.trim()])
45
- .filter(([, value]) => value.length > 0);
46
- return Object.freeze(Object.fromEntries(entries));
47
- }
48
- function normalizeActionOptions(input, allowedKeys) {
49
- if (!input) {
50
- return Object.freeze({});
51
- }
52
- const entries = Object.entries(input)
53
- .filter(([key, value]) => allowedKeys.includes(key) && Boolean(value))
54
- .map(([key, value]) => {
55
- const option = value;
56
- const normalized = {
57
- ...(option.hidden === true ? { hidden: true } : {}),
58
- ...(option.disabled === true ? { disabled: true } : {}),
59
- ...(typeof option.disabledReason === "string" && option.disabledReason.trim().length > 0
60
- ? { disabledReason: option.disabledReason.trim() }
61
- : {}),
62
- ...(typeof option.label === "string" && option.label.trim().length > 0
63
- ? { label: option.label.trim() }
64
- : {}),
65
- };
66
- return [key, Object.freeze(normalized)];
67
- })
68
- .filter(([, value]) => Object.keys(value).length > 0);
69
- return Object.freeze(Object.fromEntries(entries));
70
- }
71
- function normalizeCellColumns(input) {
72
- if (!input) {
73
- return {};
74
- }
75
- const normalizedEntries = Object.entries(input)
76
- .filter(([key]) => key.trim().length > 0)
77
- .map(([key, value]) => {
78
- const items = value?.items ? normalizeItems(value.items, DATAGRID_CELL_MENU_ITEM_KEYS) : undefined;
79
- const hide = normalizeItemSubset(value?.hide, DATAGRID_CELL_MENU_ITEM_KEYS);
80
- const disabled = normalizeItemSubset(value?.disabled, DATAGRID_CELL_MENU_ITEM_KEYS);
81
- const disabledReasons = normalizeLabels(value?.disabledReasons, DATAGRID_CELL_MENU_ITEM_KEYS);
82
- const labels = normalizeLabels(value?.labels, DATAGRID_CELL_MENU_ITEM_KEYS);
83
- const actions = normalizeActionOptions(value?.actions, DATAGRID_CELL_MENU_ACTION_KEYS);
84
- return [
85
- key,
86
- {
87
- ...(items ? { items } : {}),
88
- ...(hide.length > 0 ? { hide } : {}),
89
- ...(disabled.length > 0 ? { disabled } : {}),
90
- ...(Object.keys(disabledReasons).length > 0 ? { disabledReasons } : {}),
91
- ...(Object.keys(labels).length > 0 ? { labels } : {}),
92
- ...(Object.keys(actions).length > 0 ? { actions } : {}),
93
- },
94
- ];
95
- });
96
- return Object.freeze(Object.fromEntries(normalizedEntries));
97
- }
98
- export function resolveDataGridCellMenu(input) {
99
- if (typeof input === "boolean") {
100
- return {
101
- enabled: input,
102
- items: [...DATAGRID_CELL_MENU_ITEM_KEYS],
103
- disabled: [],
104
- disabledReasons: Object.freeze({}),
105
- labels: Object.freeze({}),
106
- actions: Object.freeze({}),
107
- columns: {},
108
- };
109
- }
110
- if (!input) {
111
- return {
112
- enabled: false,
113
- items: [...DATAGRID_CELL_MENU_ITEM_KEYS],
114
- disabled: [],
115
- disabledReasons: Object.freeze({}),
116
- labels: Object.freeze({}),
117
- actions: Object.freeze({}),
118
- columns: {},
119
- };
120
- }
121
- return {
122
- enabled: input.enabled ?? true,
123
- items: normalizeItems(input.items, DATAGRID_CELL_MENU_ITEM_KEYS),
124
- disabled: normalizeItemSubset(input.disabled, DATAGRID_CELL_MENU_ITEM_KEYS),
125
- disabledReasons: normalizeLabels(input.disabledReasons, DATAGRID_CELL_MENU_ITEM_KEYS),
126
- labels: normalizeLabels(input.labels, DATAGRID_CELL_MENU_ITEM_KEYS),
127
- actions: normalizeActionOptions(input.actions, DATAGRID_CELL_MENU_ACTION_KEYS),
128
- columns: normalizeCellColumns(input.columns),
129
- };
130
- }
131
- export function resolveDataGridCellMenuItems(options, columnKey) {
132
- const columnOptions = options.columns[columnKey];
133
- const baseItems = columnOptions?.items
134
- ? normalizeItems(columnOptions.items, DATAGRID_CELL_MENU_ITEM_KEYS)
135
- : options.items;
136
- const hidden = new Set(columnOptions?.hide ?? []);
137
- const filtered = baseItems.filter(item => !hidden.has(item));
138
- return filtered.length > 0 ? filtered : [];
139
- }
140
- export function resolveDataGridCellMenuDisabledItems(options, columnKey) {
141
- const visibleItems = resolveDataGridCellMenuItems(options, columnKey);
142
- const columnDisabled = new Set(options.columns[columnKey]?.disabled ?? []);
143
- const globallyDisabled = new Set(options.disabled);
144
- return visibleItems.filter(item => globallyDisabled.has(item) || columnDisabled.has(item));
145
- }
146
- export function resolveDataGridCellMenuLabels(options, columnKey) {
147
- return Object.freeze({
148
- ...options.labels,
149
- ...(options.columns[columnKey]?.labels ?? {}),
150
- });
151
- }
152
- export function resolveDataGridCellMenuDisabledReasons(options, columnKey) {
153
- return Object.freeze({
154
- ...options.disabledReasons,
155
- ...(options.columns[columnKey]?.disabledReasons ?? {}),
156
- });
157
- }
158
- export function resolveDataGridCellMenuActionOptions(options, columnKey) {
159
- const columnActions = options.columns[columnKey]?.actions ?? {};
160
- const entries = DATAGRID_CELL_MENU_ACTION_KEYS
161
- .map(actionKey => {
162
- const merged = {
163
- ...(options.actions[actionKey] ?? {}),
164
- ...(columnActions[actionKey] ?? {}),
165
- };
166
- return [actionKey, Object.freeze(merged)];
167
- })
168
- .filter(([, value]) => Object.keys(value).length > 0);
169
- return Object.freeze(Object.fromEntries(entries));
170
- }
171
- export function resolveDataGridRowIndexMenu(input) {
172
- if (typeof input === "boolean") {
173
- return {
174
- enabled: input,
175
- items: [...DATAGRID_ROW_INDEX_MENU_ITEM_KEYS],
176
- disabled: [],
177
- disabledReasons: Object.freeze({}),
178
- labels: Object.freeze({}),
179
- actions: Object.freeze({}),
180
- };
181
- }
182
- if (!input) {
183
- return {
184
- enabled: false,
185
- items: [...DATAGRID_ROW_INDEX_MENU_ITEM_KEYS],
186
- disabled: [],
187
- disabledReasons: Object.freeze({}),
188
- labels: Object.freeze({}),
189
- actions: Object.freeze({}),
190
- };
191
- }
192
- return {
193
- enabled: input.enabled ?? true,
194
- items: normalizeItems(input.items, DATAGRID_ROW_INDEX_MENU_ITEM_KEYS),
195
- disabled: normalizeItemSubset(input.disabled, DATAGRID_ROW_INDEX_MENU_ITEM_KEYS),
196
- disabledReasons: normalizeLabels(input.disabledReasons, DATAGRID_ROW_INDEX_MENU_ITEM_KEYS),
197
- labels: normalizeLabels(input.labels, DATAGRID_ROW_INDEX_MENU_ITEM_KEYS),
198
- actions: normalizeActionOptions(input.actions, DATAGRID_ROW_INDEX_MENU_ACTION_KEYS),
199
- };
200
- }
201
- export function resolveDataGridRowIndexMenuItems(options) {
202
- return options.items;
203
- }
204
- export function resolveDataGridRowIndexMenuDisabledItems(options) {
205
- return options.disabled;
206
- }
207
- export function resolveDataGridRowIndexMenuLabels(options) {
208
- return options.labels;
209
- }
210
- export function resolveDataGridRowIndexMenuDisabledReasons(options) {
211
- return options.disabledReasons;
212
- }
213
- export function resolveDataGridRowIndexMenuActionOptions(options) {
214
- const entries = DATAGRID_ROW_INDEX_MENU_ACTION_KEYS
215
- .map(actionKey => [actionKey, Object.freeze({ ...(options.actions[actionKey] ?? {}) })])
216
- .filter(([, value]) => Object.keys(value).length > 0);
217
- return Object.freeze(Object.fromEntries(entries));
218
- }