@svgrid/grid 3.0.4 → 3.0.6
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/README.md +32 -11
- package/dist/GridMenus.svelte +34 -4
- package/dist/SvGrid.controller.svelte.d.ts +33 -5
- package/dist/SvGrid.controller.svelte.js +397 -58
- package/dist/SvGrid.css +200 -2
- package/dist/SvGrid.svelte +350 -40
- package/dist/SvGrid.types.d.ts +433 -7
- package/dist/SvGridDropdown.svelte +20 -0
- package/dist/SvGridDropdown.svelte.d.ts +12 -0
- package/dist/SvModal.svelte +22 -0
- package/dist/SvModal.svelte.d.ts +7 -0
- package/dist/a11y/dismissable.d.ts +10 -0
- package/dist/a11y/dismissable.js +24 -2
- package/dist/build-api.js +92 -37
- package/dist/cdn/{GridMenus-BL7ZgQvU.js → GridMenus-C-NtjlrJ.js} +155 -146
- package/dist/cdn/GridMenus-TssHej3q.js +644 -0
- package/dist/cdn/{SvChartMenu-FBSMINA6.js → SvChartMenu-BFSTpvB-.js} +1 -1
- package/dist/cdn/{SvChartMenu-Bl6PBbkT.js → SvChartMenu-BZ1Iwv0y.js} +1 -1
- package/dist/cdn/{SvDateTimePicker-DQwt4UAs.js → SvDateTimePicker-D9u_cOf8.js} +1 -1
- package/dist/cdn/{SvDateTimePicker-vNU6bZ-q.js → SvDateTimePicker-s_6IUpI7.js} +1 -1
- package/dist/cdn/{SvGridCellEditor-B1p-vCK5.js → SvGridCellEditor-BlyCSp0q.js} +1 -1
- package/dist/cdn/{SvGridCellEditor-D_0q4xAu.js → SvGridCellEditor-ClRRA9lW.js} +1 -1
- package/dist/cdn/{SvGridChart-DzLkSwCH.js → SvGridChart-B4EV8U6t.js} +4 -4
- package/dist/cdn/{SvGridChart-C3EWAZaM.js → SvGridChart-DsmwTyZF.js} +4 -4
- package/dist/cdn/{SvGridChartBuilder-CfII62sZ.js → SvGridChartBuilder-cHloHobN.js} +4 -4
- package/dist/cdn/{SvGridChartBuilder-BE2T1ykB.js → SvGridChartBuilder-vOl7C0Za.js} +4 -4
- package/dist/cdn/{SvGridChartPanel-xf4sWVTo.js → SvGridChartPanel-AcqF-Ll5.js} +5 -5
- package/dist/cdn/{SvGridChartPanel-CCX5_Wgd.js → SvGridChartPanel-biMtSBPA.js} +5 -5
- package/dist/cdn/{SvGridChartView-DYwabQWj.js → SvGridChartView-Dx_GmZuL.js} +2 -2
- package/dist/cdn/{SvGridChartView-CfuXmY5I.js → SvGridChartView-I3rDHXAq.js} +2 -2
- package/dist/cdn/{SvGridDropdown-D0VdjeR8.js → SvGridDropdown-BWeM3lMe.js} +46 -46
- package/dist/cdn/{SvGridDropdown-D13MtJ2j.js → SvGridDropdown-CJ6QqTxu.js} +67 -67
- package/dist/cdn/{SvModal-CIZWCcad.js → SvModal-ClxGmpAc.js} +187 -186
- package/dist/cdn/{SvModal-BAE-pjZX.js → SvModal-DhB_VMFR.js} +148 -147
- package/dist/cdn/{cell-formatting-C2Hf5gqd.js → cell-formatting-DVVKOSI9.js} +1 -1
- package/dist/cdn/{chart-Dz7SqMXH.js → chart-DEZxwC0i.js} +1 -1
- package/dist/cdn/{chart-panel-messages-CUbf2R4i.js → chart-panel-messages-D12XcTZJ.js} +1 -1
- package/dist/cdn/{chart-panel-messages-CmNrMdsr.js → chart-panel-messages-DguS7gC5.js} +1 -1
- package/dist/cdn/{chart-summary-BJW_tg_X.js → chart-summary-CMAXBGY-.js} +1 -1
- package/dist/cdn/{chart-trend-CaN9mDEV.js → chart-trend-BkEp61Gj.js} +1 -1
- package/dist/cdn/{dismissable-DAHetSNk.js → dismissable-Brc4EZU1.js} +5 -1
- package/dist/cdn/{export-format-CUDLy2yn.js → export-format-YzdwBww2.js} +1 -1
- package/dist/cdn/{row-resize-niQCp040.js → row-resize-DtOS1KG6.js} +41 -32
- package/dist/cdn/server-block-cache-DIqb3VZn.js +241 -0
- package/dist/cdn/{src-V1uu8iE9.js → src-CgoeSM8k.js} +5339 -4753
- package/dist/cdn/{src-BKhZ6eXd.js → src-DfwxB1TH.js} +9817 -9231
- package/dist/cdn/svgrid.js +28 -27
- package/dist/cdn/svgrid.svelte-external.js +28 -27
- package/dist/cdn/validate-AZoD8BoR.js +80 -0
- package/dist/cell-formatting.js +18 -1
- package/dist/cell-render.js +25 -6
- package/dist/clipboard.d.ts +2 -2
- package/dist/clipboard.js +72 -23
- package/dist/columns.js +7 -2
- package/dist/conditional-formatting.d.ts +2 -0
- package/dist/conditional-formatting.js +2 -0
- package/dist/core.d.ts +22 -6
- package/dist/core.js +401 -38
- package/dist/editing.js +34 -0
- package/dist/gantt-view.svelte.d.ts +24 -0
- package/dist/gantt-view.svelte.js +13 -0
- package/dist/grid-icons.d.ts +2 -2
- package/dist/grid-icons.js +2 -2
- package/dist/grid-messages.d.ts +10 -0
- package/dist/grid-messages.js +9 -0
- package/dist/headless.d.ts +5 -0
- package/dist/headless.js +12 -0
- package/dist/history.d.ts +21 -0
- package/dist/history.js +34 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -3
- package/dist/keyboard-handlers.js +24 -1
- package/dist/keyboard.js +4 -0
- package/dist/row-drag-touch.d.ts +1 -1
- package/dist/row-drag.js +35 -1
- package/dist/row-model.d.ts +139 -0
- package/dist/row-model.js +16 -0
- package/dist/row-resize.js +22 -1
- package/dist/selection.d.ts +2 -1
- package/dist/selection.js +31 -3
- package/dist/server-block-cache.d.ts +219 -0
- package/dist/server-block-cache.js +539 -0
- package/dist/server-data-source.d.ts +274 -8
- package/dist/server-data-source.js +229 -20
- package/dist/server.d.ts +13 -0
- package/dist/server.js +13 -0
- package/dist/sparkline.js +7 -5
- package/dist/svgrid-wrapper.types.d.ts +33 -0
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +29 -3
- package/package.json +11 -1
- package/src/GridMenus.svelte +34 -4
- package/src/SvGrid.controller.svelte.ts +397 -61
- package/src/SvGrid.css +200 -2
- package/src/SvGrid.svelte +350 -40
- package/src/SvGrid.types.ts +453 -7
- package/src/SvGridDropdown.svelte +20 -0
- package/src/SvModal.svelte +22 -0
- package/src/SvModal.test.ts +30 -1
- package/src/a11y/dismissable.test.ts +10 -1
- package/src/a11y/dismissable.ts +22 -2
- package/src/build-api.ts +96 -31
- package/src/cell-formatting.test.ts +17 -0
- package/src/cell-formatting.ts +18 -1
- package/src/cell-render.test.ts +24 -2
- package/src/cell-render.ts +24 -8
- package/src/clipboard.test.ts +107 -0
- package/src/clipboard.ts +62 -23
- package/src/columns.test.ts +4 -4
- package/src/columns.ts +7 -2
- package/src/conditional-formatting.test.ts +8 -0
- package/src/conditional-formatting.ts +3 -0
- package/src/core.rowmodel-cache.test.ts +51 -0
- package/src/core.tick-repair.test.ts +287 -0
- package/src/core.ts +407 -38
- package/src/editing.test.ts +52 -0
- package/src/editing.ts +33 -0
- package/src/gantt-stub.test.svelte +38 -0
- package/src/gantt-view.svelte.ts +35 -0
- package/src/grid-icons.ts +2 -2
- package/src/grid-messages.test.ts +7 -0
- package/src/grid-messages.ts +22 -0
- package/src/headless.ts +24 -0
- package/src/history.test.ts +49 -1
- package/src/history.ts +48 -2
- package/src/icon-seam.test.ts +2 -4
- package/src/index.ts +38 -10
- package/src/keyboard-handlers.coverage.test.ts +65 -0
- package/src/keyboard-handlers.ts +26 -1
- package/src/keyboard.ts +3 -0
- package/src/row-drag-touch.ts +2 -2
- package/src/row-drag.test.ts +51 -0
- package/src/row-drag.ts +35 -2
- package/src/row-model.ts +152 -0
- package/src/row-resize.ts +24 -1
- package/src/selection.test.ts +3 -0
- package/src/selection.ts +33 -3
- package/src/server-block-cache.test.ts +672 -0
- package/src/server-block-cache.ts +690 -0
- package/src/server-data-source.infinite.test.ts +405 -0
- package/src/server-data-source.test.ts +19 -0
- package/src/server-data-source.ts +496 -29
- package/src/server.ts +49 -0
- package/src/sparkline.test.ts +7 -0
- package/src/sparkline.ts +6 -4
- package/src/svgrid-wrapper.types.ts +32 -0
- package/src/svgrid.api.test.ts +21 -0
- package/src/svgrid.charting.test.ts +12 -4
- package/src/svgrid.context-menu.test.ts +12 -0
- package/src/svgrid.detail-rows.svelte.test.ts +187 -0
- package/src/svgrid.filter-menu-scroll.test.ts +9 -0
- package/src/svgrid.gantt-seam.test.ts +199 -0
- package/src/svgrid.live-update-paths.svelte.test.ts +184 -0
- package/src/svgrid.menu-scroll-close.test.ts +10 -0
- package/src/svgrid.row-model-prop.svelte.test.ts +352 -0
- package/src/svgrid.row-model-seam.svelte.test.ts +305 -0
- package/src/svgrid.row-pinning.test.ts +15 -1
- package/src/svgrid.selection-bar-seam.test.ts +1 -1
- package/src/svgrid.sticky-groups.svelte.test.ts +145 -0
- package/src/svgrid.upsell-license.test.ts +8 -5
- package/src/test-setup.ts +12 -0
- package/src/transaction.test.ts +58 -0
- package/src/validate.test.ts +29 -0
- package/src/validate.ts +34 -3
- package/dist/SvGroupCell.svelte +0 -141
- package/dist/SvGroupCell.svelte.d.ts +0 -49
- package/dist/SvRowGroupPanel.svelte +0 -186
- package/dist/SvRowGroupPanel.svelte.d.ts +0 -25
- package/dist/cdn/GridMenus-7kbpnnBW.js +0 -635
- package/dist/cdn/validate-_CDJzgIo.js +0 -75
- package/dist/server-group-model.d.ts +0 -98
- package/dist/server-group-model.js +0 -263
- package/src/SvGroupCell.svelte +0 -141
- package/src/SvRowGroupPanel.svelte +0 -186
- package/src/server-group-model.test.ts +0 -294
- package/src/server-group-model.ts +0 -370
package/src/SvGrid.types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Type definitions extracted from SvGrid.svelte. These are compile-time
|
|
2
2
|
// only - moving them out keeps the component's <script> focused on logic.
|
|
3
3
|
import type { Snippet } from "svelte";
|
|
4
|
+
import type { GridRowModel } from "./row-model";
|
|
4
5
|
import type {
|
|
5
6
|
CellEditorType,
|
|
6
7
|
ColumnDef,
|
|
@@ -1112,8 +1113,276 @@ export type SchedulerConfig<
|
|
|
1112
1113
|
searchPlaceholder?: string;
|
|
1113
1114
|
};
|
|
1114
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* The Gantt axis presets: which unit is a tick and which is the coarser row
|
|
1118
|
+
* grouping them. `week` (day ticks under month majors) is the default.
|
|
1119
|
+
*/
|
|
1120
|
+
export type GanttZoom = "day" | "week" | "month" | "quarter" | "year";
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* The four classic dependency kinds. `FS` (finish-to-start) is the default:
|
|
1124
|
+
* the successor may not start before the predecessor finishes.
|
|
1125
|
+
*/
|
|
1126
|
+
export type GanttDependencyType = "FS" | "SS" | "FF" | "SF";
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* A link from a predecessor task (`from`) to a successor (`to`). Both are row
|
|
1130
|
+
* ids (the grid's `getRowId`). `lag` is in DAYS - negative for a lead, so
|
|
1131
|
+
* `{ type: 'FS', lag: -1 }` lets the successor start a day before the
|
|
1132
|
+
* predecessor finishes.
|
|
1133
|
+
*/
|
|
1134
|
+
export type GanttDependency = {
|
|
1135
|
+
id: string;
|
|
1136
|
+
from: string;
|
|
1137
|
+
to: string;
|
|
1138
|
+
type?: GanttDependencyType;
|
|
1139
|
+
lag?: number;
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
/** Fired when a task bar is dragged to new dates. {@link GanttConfig.onTaskMove}. */
|
|
1143
|
+
export type GanttTaskMoveEvent<TData extends RowData = RowData> = {
|
|
1144
|
+
row: TData;
|
|
1145
|
+
start: Date;
|
|
1146
|
+
end: Date;
|
|
1147
|
+
/**
|
|
1148
|
+
* The moved row's descendants, shifted by the same delta - present only when
|
|
1149
|
+
* a summary (parent) bar was dragged. Cascaded successors are NOT here; they
|
|
1150
|
+
* arrive through {@link GanttConfig.onDependenciesChange}.
|
|
1151
|
+
*/
|
|
1152
|
+
subtree?: Array<{ row: TData; start: Date; end: Date }>;
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
/** Fired when a task bar's edge is dragged. {@link GanttConfig.onTaskResize}. */
|
|
1156
|
+
export type GanttTaskResizeEvent<TData extends RowData = RowData> = {
|
|
1157
|
+
row: TData;
|
|
1158
|
+
start: Date;
|
|
1159
|
+
end: Date;
|
|
1160
|
+
/** Which edge the user dragged. */
|
|
1161
|
+
edge: "start" | "end";
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1164
|
+
/** Fired when a bar's progress grip is dragged. {@link GanttConfig.onProgressChange}. */
|
|
1165
|
+
export type GanttProgressChangeEvent<TData extends RowData = RowData> = {
|
|
1166
|
+
row: TData;
|
|
1167
|
+
/** 0-100, in whole percent. */
|
|
1168
|
+
progress: number;
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1171
|
+
/** Fired when the Gantt's detail drawer is saved. {@link GanttConfig.onTaskCommit}. */
|
|
1172
|
+
export type GanttTaskCommitEvent<TData extends RowData = RowData> = {
|
|
1173
|
+
row: TData;
|
|
1174
|
+
values: Partial<TData>;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* The Gantt's built-in task drawer. Same shape as the scheduler's - a field
|
|
1179
|
+
* list, a title and a width - so one drawer config type covers both views.
|
|
1180
|
+
*/
|
|
1181
|
+
export type GanttDrawerConfig<TData extends RowData = RowData> =
|
|
1182
|
+
SchedulerDrawerConfig<TData>;
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Turns the grid into a Gantt chart. Set `gantt` and the grid renders its rows
|
|
1186
|
+
* as a task table beside a time chart: one bar per row positioned by start /
|
|
1187
|
+
* end, nested into a work-breakdown tree by `parentField`, with dependency
|
|
1188
|
+
* arrows between linked tasks.
|
|
1189
|
+
*
|
|
1190
|
+
* Like the Kanban board and the scheduler it is a pure *view of the grid*: it
|
|
1191
|
+
* renders the grid's filtered + sorted rows and writes back only through
|
|
1192
|
+
* callbacks, never mutating your data. Dragging a bar fires
|
|
1193
|
+
* {@link GanttConfig.onTaskMove} where you reassign the dates on your own rows.
|
|
1194
|
+
*
|
|
1195
|
+
* Dates are local calendar days and `end` is EXCLUSIVE, except that a date-only
|
|
1196
|
+
* string (`'2026-09-14'`, no time part) is read as the end OF that day - the
|
|
1197
|
+
* inclusive convention planning tools use. So
|
|
1198
|
+
* `{ start: '2026-09-14', end: '2026-09-16' }` draws a three-day bar.
|
|
1199
|
+
*/
|
|
1200
|
+
export type GanttConfig<
|
|
1201
|
+
TFeatures extends TableFeatures = TableFeatures,
|
|
1202
|
+
TData extends RowData = RowData,
|
|
1203
|
+
> = {
|
|
1204
|
+
/** Field holding each task's start (`Date` | epoch-ms | ISO string). Required. */
|
|
1205
|
+
startField: keyof TData & string;
|
|
1206
|
+
/** Field holding the end. Omit to use `durationField`, else the task is a milestone. */
|
|
1207
|
+
endField?: keyof TData & string;
|
|
1208
|
+
/** Field holding the length in WORKING days, used when `endField` is absent. */
|
|
1209
|
+
durationField?: keyof TData & string;
|
|
1210
|
+
/** Field for the task name. Defaults to the first column's field. */
|
|
1211
|
+
titleField?: keyof TData & string;
|
|
1212
|
+
/** Field holding percent complete (0-100). Drives the bar's inner fill. */
|
|
1213
|
+
progressField?: keyof TData & string;
|
|
1214
|
+
/**
|
|
1215
|
+
* Field holding each row's PARENT task id, nesting the flat rows into a
|
|
1216
|
+
* work-breakdown tree. Parents render a rolled-up summary bar and a collapse
|
|
1217
|
+
* chevron. Rows whose parent is missing become roots rather than vanishing.
|
|
1218
|
+
*
|
|
1219
|
+
* This is the Gantt's own tree - do NOT also set the grid's `treeData` prop.
|
|
1220
|
+
* `treeData` hides collapsed children from the view entirely, which would
|
|
1221
|
+
* drop them out of their phase's summary bar.
|
|
1222
|
+
*/
|
|
1223
|
+
parentField?: keyof TData & string;
|
|
1224
|
+
/**
|
|
1225
|
+
* Boolean field marking a task as a milestone (a diamond, no length). A task
|
|
1226
|
+
* whose end equals its start renders as one regardless.
|
|
1227
|
+
*/
|
|
1228
|
+
milestoneField?: keyof TData & string;
|
|
1229
|
+
/** Field holding a per-task accent color (any CSS color). Else `color`. */
|
|
1230
|
+
colorField?: keyof TData & string;
|
|
1231
|
+
/** Fallback accent color for every bar. */
|
|
1232
|
+
color?: string;
|
|
1233
|
+
|
|
1234
|
+
// --- dependencies ---------------------------------------------------------
|
|
1235
|
+
/**
|
|
1236
|
+
* Predecessor -> successor links, drawn as arrows between bars. `from` / `to`
|
|
1237
|
+
* are row ids (your `getRowId`). See {@link GanttDependency}.
|
|
1238
|
+
*/
|
|
1239
|
+
dependencies?: ReadonlyArray<GanttDependency>;
|
|
1240
|
+
/**
|
|
1241
|
+
* Per-row field holding that row's links (as `GanttDependency[]` or a plain
|
|
1242
|
+
* list of successor ids). An alternative to the flat `dependencies` array.
|
|
1243
|
+
*/
|
|
1244
|
+
dependencyField?: keyof TData & string;
|
|
1245
|
+
/**
|
|
1246
|
+
* Cascade successors forward on move / resize so every link stays legal,
|
|
1247
|
+
* preserving each task's duration. Defaults to `true` when any dependency is
|
|
1248
|
+
* present. Cascading never pulls a task earlier.
|
|
1249
|
+
*/
|
|
1250
|
+
autoReschedule?: boolean;
|
|
1251
|
+
/**
|
|
1252
|
+
* Schedule in working time (see `nonWorkingDays` / `holidays`): a moved
|
|
1253
|
+
* or cascaded task lands on a working day and keeps its WORKING length, so
|
|
1254
|
+
* a five-day task dragged over a weekend stays five days of work, and the
|
|
1255
|
+
* critical path measures slack in working days. `false` schedules in
|
|
1256
|
+
* calendar time. Default `true`.
|
|
1257
|
+
*/
|
|
1258
|
+
respectWorkingTime?: boolean;
|
|
1259
|
+
/** Fired with the cascaded shifts after a move / resize (never mutates rows). */
|
|
1260
|
+
onDependenciesChange?: (
|
|
1261
|
+
moves: Array<{ id: string; start: Date; end: Date }>,
|
|
1262
|
+
) => void;
|
|
1263
|
+
/** Fired when the user draws a new link (drag from one bar's edge to another). */
|
|
1264
|
+
onDependencyAdd?: (dep: GanttDependency) => void;
|
|
1265
|
+
/** Fired when the user removes a link (arrow context menu). */
|
|
1266
|
+
onDependencyRemove?: (id: string) => void;
|
|
1267
|
+
|
|
1268
|
+
// --- axis -----------------------------------------------------------------
|
|
1269
|
+
/** The axis preset the chart opens on. Default `'week'`. */
|
|
1270
|
+
zoom?: GanttZoom;
|
|
1271
|
+
/**
|
|
1272
|
+
* The presets the toolbar's zoom stepper offers. Default all five; a single
|
|
1273
|
+
* entry hides the stepper.
|
|
1274
|
+
*/
|
|
1275
|
+
zoomLevels?: ReadonlyArray<GanttZoom>;
|
|
1276
|
+
/** Fired when the zoom preset changes (stepper or Ctrl+wheel). */
|
|
1277
|
+
onZoomChange?: (zoom: GanttZoom) => void;
|
|
1278
|
+
/** First day of the week, 0-6 (0 = Sunday). Default 0. */
|
|
1279
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
1280
|
+
/**
|
|
1281
|
+
* Weekday numbers (0 = Sun ... 6 = Sat) that are non-working: shaded in the
|
|
1282
|
+
* chart and skipped by duration + cascade arithmetic. Default `[0, 6]`.
|
|
1283
|
+
*/
|
|
1284
|
+
nonWorkingDays?: ReadonlyArray<number>;
|
|
1285
|
+
/** Specific dates that are non-working (holidays, closures). */
|
|
1286
|
+
holidays?: ReadonlyArray<Date | number | string>;
|
|
1287
|
+
/** Shade the non-working columns. Default `true`. */
|
|
1288
|
+
showNonWorking?: boolean;
|
|
1289
|
+
/** Draw the dashed "today" line across the chart. Default `true`. */
|
|
1290
|
+
todayLine?: boolean;
|
|
1291
|
+
/** Earliest date the axis shows and a drag may reach. */
|
|
1292
|
+
minDate?: Date | number | string;
|
|
1293
|
+
/** Latest date the axis shows and a drag may reach. */
|
|
1294
|
+
maxDate?: Date | number | string;
|
|
1295
|
+
/** Calendar days of slack around the first start / last end. Default 7. */
|
|
1296
|
+
rangePaddingDays?: number;
|
|
1297
|
+
|
|
1298
|
+
// --- layout ---------------------------------------------------------------
|
|
1299
|
+
/**
|
|
1300
|
+
* Column ids shown in the task table, in order. Defaults to every leaf
|
|
1301
|
+
* column. Two built-ins need no column definition: `'__duration'` (working
|
|
1302
|
+
* days) and `'__progress'` (a small bar).
|
|
1303
|
+
*/
|
|
1304
|
+
tableColumns?: ReadonlyArray<string>;
|
|
1305
|
+
/** Width (px) of the task table pane. Default 360; a splitter resizes it. */
|
|
1306
|
+
tableWidth?: number;
|
|
1307
|
+
/** Height (px) of one task row. Default 32. */
|
|
1308
|
+
rowHeight?: number;
|
|
1309
|
+
/** Parents draw a rolled-up summary bar spanning their children. Default `true`. */
|
|
1310
|
+
summaryBars?: boolean;
|
|
1311
|
+
/**
|
|
1312
|
+
* Where a bar's label sits: `'inside'` (default, falling back to the right
|
|
1313
|
+
* when the bar is too narrow), always `'right'`, or `'none'`.
|
|
1314
|
+
*/
|
|
1315
|
+
labelPosition?: "inside" | "right" | "none";
|
|
1316
|
+
|
|
1317
|
+
// --- work-breakdown collapse ------------------------------------------------
|
|
1318
|
+
/**
|
|
1319
|
+
* Controlled collapse: the ids of the parent rows whose children are hidden.
|
|
1320
|
+
* Omit to let the Gantt own its own collapse state.
|
|
1321
|
+
*/
|
|
1322
|
+
collapsed?: ReadonlyArray<string>;
|
|
1323
|
+
/** Fired when a chevron (or Expand / Collapse all) changes the collapsed set. */
|
|
1324
|
+
onCollapseChange?: (collapsed: string[]) => void;
|
|
1325
|
+
|
|
1326
|
+
// --- editing ----------------------------------------------------------------
|
|
1327
|
+
/**
|
|
1328
|
+
* Enable drag-to-move, edge resize, the progress grip and link drawing.
|
|
1329
|
+
* Without it the chart is read-only.
|
|
1330
|
+
*/
|
|
1331
|
+
editable?: boolean;
|
|
1332
|
+
/**
|
|
1333
|
+
* Enable undo / redo of move, resize and progress edits with `Ctrl/Cmd+Z` and
|
|
1334
|
+
* `Ctrl/Cmd+Shift+Z` (or `Ctrl+Y`). The callbacks re-fire with the reversed
|
|
1335
|
+
* values, so your data follows.
|
|
1336
|
+
*/
|
|
1337
|
+
history?: boolean;
|
|
1338
|
+
/** Fired when a bar is dragged to new dates. */
|
|
1339
|
+
onTaskMove?: (event: GanttTaskMoveEvent<TData>) => void;
|
|
1340
|
+
/** Fired when a bar's edge is dragged. */
|
|
1341
|
+
onTaskResize?: (event: GanttTaskResizeEvent<TData>) => void;
|
|
1342
|
+
/** Fired when the progress grip is dragged. */
|
|
1343
|
+
onProgressChange?: (event: GanttProgressChangeEvent<TData>) => void;
|
|
1344
|
+
/** Fired when empty chart space is double-clicked - create a task there. */
|
|
1345
|
+
onTaskAdd?: (start: Date, end: Date, parentId?: string) => void;
|
|
1346
|
+
/**
|
|
1347
|
+
* Fired from the bar's Delete action. Setting this shows Delete in the
|
|
1348
|
+
* drawer and the context menu. Remove the row from your data in the handler.
|
|
1349
|
+
*/
|
|
1350
|
+
onTaskDelete?: (row: TData) => void;
|
|
1351
|
+
|
|
1352
|
+
// --- chrome -----------------------------------------------------------------
|
|
1353
|
+
/**
|
|
1354
|
+
* Custom body for a TASK bar. Receives the row. Omit for the built-in label.
|
|
1355
|
+
* A phase's summary bar is a thin spine with no room for a body, so it keeps
|
|
1356
|
+
* its plain label; a milestone has no body at all.
|
|
1357
|
+
*/
|
|
1358
|
+
task?: Snippet<[TData]>;
|
|
1359
|
+
/**
|
|
1360
|
+
* Hover tooltip for a bar. A `Snippet<[TData]>` for custom content, or `true`
|
|
1361
|
+
* for the built-in one (title, dates, duration, percent). Omit to disable.
|
|
1362
|
+
*/
|
|
1363
|
+
tooltip?: boolean | Snippet<[TData]>;
|
|
1364
|
+
/** Delay (ms) before the hover tooltip opens. Default 400. */
|
|
1365
|
+
tooltipDelay?: number;
|
|
1366
|
+
/** Built-in task drawer: `true` for all fields, or a config object. */
|
|
1367
|
+
drawer?: boolean | GanttDrawerConfig<TData>;
|
|
1368
|
+
/** Fired when the drawer is saved. */
|
|
1369
|
+
onTaskCommit?: (event: GanttTaskCommitEvent<TData>) => void;
|
|
1370
|
+
/** Right-click menu for a bar. Return items or `undefined` to suppress. */
|
|
1371
|
+
taskMenu?: (row: TData) => MenuItem[] | undefined;
|
|
1372
|
+
|
|
1373
|
+
/** Show the search box (binds to the grid's global filter). Default `true`. */
|
|
1374
|
+
searchable?: boolean;
|
|
1375
|
+
searchPlaceholder?: string;
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1115
1378
|
export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData> = {
|
|
1116
|
-
|
|
1379
|
+
/**
|
|
1380
|
+
* The rows to render.
|
|
1381
|
+
*
|
|
1382
|
+
* Optional only because `rowModel` can supply them instead; a grid with
|
|
1383
|
+
* neither renders empty. When both are present `data` wins.
|
|
1384
|
+
*/
|
|
1385
|
+
data?: ReadonlyArray<TData>;
|
|
1117
1386
|
columns: Array<ColumnDef<TFeatures, TData>>;
|
|
1118
1387
|
/**
|
|
1119
1388
|
* Kanban board mode. When set, the grid renders its rows as cards in
|
|
@@ -1127,6 +1396,15 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
1127
1396
|
* {@link SchedulerConfig}.
|
|
1128
1397
|
*/
|
|
1129
1398
|
scheduler?: SchedulerConfig<TFeatures, TData>;
|
|
1399
|
+
/**
|
|
1400
|
+
* Gantt mode. When set, the grid renders its rows as a task table beside a
|
|
1401
|
+
* time chart: one bar per row by start / end, a work-breakdown tree from
|
|
1402
|
+
* `parentField`, and dependency arrows. See {@link GanttConfig}.
|
|
1403
|
+
*
|
|
1404
|
+
* A view of the grid like the board and scheduler; the renderer ships in
|
|
1405
|
+
* `@svgrid/enterprise` (call `enableGanttView()`).
|
|
1406
|
+
*/
|
|
1407
|
+
gantt?: GanttConfig<TFeatures, TData>;
|
|
1130
1408
|
/**
|
|
1131
1409
|
* Chart view. When set, the grid renders its FILTERED + SORTED rows as a chart
|
|
1132
1410
|
* instead of a table (search / filters / sort flow through). Unlike board and
|
|
@@ -1721,6 +1999,15 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
1721
1999
|
rowIndex: number;
|
|
1722
2000
|
columnId: string;
|
|
1723
2001
|
}) => unknown;
|
|
2002
|
+
/**
|
|
2003
|
+
* Whether a collapsed row still takes part in a copy or a fill that
|
|
2004
|
+
* spans it. Left out, both skip every collapsed row, which is what
|
|
2005
|
+
* "filter, copy, paste" needs and what a fill dragged over a filtered
|
|
2006
|
+
* list expects: the series runs over the rows that show. A spreadsheet
|
|
2007
|
+
* answers per row: a row hidden by hand is copied and filled, as Excel
|
|
2008
|
+
* does, while a row a filter folded away is not.
|
|
2009
|
+
*/
|
|
2010
|
+
includeCollapsedRows?: (rowIndex: number) => boolean;
|
|
1724
2011
|
/**
|
|
1725
2012
|
* An HTML rendering of what Ctrl+C copies, written to the clipboard as
|
|
1726
2013
|
* `text/html` beside the TSV. Excel and Google Sheets read the HTML
|
|
@@ -1886,10 +2173,11 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
1886
2173
|
rows: TData[],
|
|
1887
2174
|
) => void;
|
|
1888
2175
|
/**
|
|
1889
|
-
* Fires whenever the cell
|
|
1890
|
-
*
|
|
1891
|
-
* `
|
|
1892
|
-
*
|
|
2176
|
+
* Fires whenever the cell selection changes (mouse, keyboard, or
|
|
2177
|
+
* `api.selectCells()`). `ranges` is every selected rectangle, matching
|
|
2178
|
+
* `api.getSelected()`: the ones a Ctrl+click committed and the active one
|
|
2179
|
+
* last, each `[rowStart, colStart, rowEnd, colEnd]` in grid coords. Empty
|
|
2180
|
+
* array when the user clears the selection.
|
|
1893
2181
|
*/
|
|
1894
2182
|
onCellSelectionChange?: (
|
|
1895
2183
|
ranges: Array<[number, number, number, number]>,
|
|
@@ -2099,6 +2387,99 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
2099
2387
|
scrollHeight: number;
|
|
2100
2388
|
clientHeight: number;
|
|
2101
2389
|
}) => void;
|
|
2390
|
+
/**
|
|
2391
|
+
* Fires when the range of rows on screen changes, with the first and last
|
|
2392
|
+
* row INDEX (not pixels). Coalesced to one call per frame, so it is cheap
|
|
2393
|
+
* to wire to something that fetches.
|
|
2394
|
+
*
|
|
2395
|
+
* This is the hook a block-loading data source needs and
|
|
2396
|
+
* `onScrollBottomReached` cannot give it: "the user is looking at rows
|
|
2397
|
+
* 4,000-4,020" answers which block to fetch and which to keep, while
|
|
2398
|
+
* "they hit the bottom" only ever means "append more". Both are free; use
|
|
2399
|
+
* this one with `createServerDataSource({ mode: 'infinite' })`, or let
|
|
2400
|
+
* `rowModel` wire it for you.
|
|
2401
|
+
*
|
|
2402
|
+
* Reports `0, data.length - 1` when virtualization is off, since every row
|
|
2403
|
+
* really is rendered.
|
|
2404
|
+
*/
|
|
2405
|
+
onVisibleRangeChange?: (range: {
|
|
2406
|
+
startIndex: number;
|
|
2407
|
+
endIndex: number;
|
|
2408
|
+
}) => void;
|
|
2409
|
+
/**
|
|
2410
|
+
* Marks a row as one whose data has not arrived: `"loading"` draws a
|
|
2411
|
+
* shimmer in every cell, `"failed"` draws a full-width "could not load"
|
|
2412
|
+
* row with a Retry button, and `null` (the default for every row) renders
|
|
2413
|
+
* normally.
|
|
2414
|
+
*
|
|
2415
|
+
* Placeholder rows are inert - not selectable, not editable, and skipped
|
|
2416
|
+
* by cell navigation - because there is nothing there to act on yet.
|
|
2417
|
+
*
|
|
2418
|
+
* `createServerDataSource` in `infinite` mode fills the gaps with rows this
|
|
2419
|
+
* recognises, so the usual wiring is `rowPlaceholder={rowPlaceholderState}`
|
|
2420
|
+
* (or nothing at all, via `rowModel`).
|
|
2421
|
+
*/
|
|
2422
|
+
rowPlaceholder?: (row: TData, rowIndex: number) => "loading" | "failed" | null;
|
|
2423
|
+
/** Called by the Retry button on a `"failed"` placeholder row. */
|
|
2424
|
+
onRetryRow?: (row: TData, rowIndex: number) => void;
|
|
2425
|
+
/**
|
|
2426
|
+
* Hand selection over to an external model.
|
|
2427
|
+
*
|
|
2428
|
+
* The grid normally tracks selection as a record of the row ids it has
|
|
2429
|
+
* seen, which is right until the rows it has seen are a window onto a
|
|
2430
|
+
* million on a server: "select all" then means 20 ticked checkboxes rather
|
|
2431
|
+
* than a million, and the header checkbox cannot honestly say `all`. A
|
|
2432
|
+
* model that stores the RULE ("everything except these three") can answer
|
|
2433
|
+
* both, so when this is set the header checkbox, the row checkboxes and
|
|
2434
|
+
* `api.selectAllRows()` all route through it instead.
|
|
2435
|
+
*
|
|
2436
|
+
* `@svgrid/enterprise` ships one for the server-side row model; this is the
|
|
2437
|
+
* seam it plugs into.
|
|
2438
|
+
*/
|
|
2439
|
+
/**
|
|
2440
|
+
* Drive the grid from a row model instead of wiring a dozen props.
|
|
2441
|
+
*
|
|
2442
|
+
* `createServerDataSource` returns one, and so does the Enterprise
|
|
2443
|
+
* server-side row model, so server-backed grids become:
|
|
2444
|
+
*
|
|
2445
|
+
* ```svelte
|
|
2446
|
+
* <SvGrid rowModel={ctl} {columns} />
|
|
2447
|
+
* ```
|
|
2448
|
+
*
|
|
2449
|
+
* The model supplies `data`, `loading`, `getRowId`, the external sort
|
|
2450
|
+
* and filter wiring, the visible range, placeholder rows, group
|
|
2451
|
+
* accessors, selection and paging - each one only if it implements that
|
|
2452
|
+
* part. A prop written explicitly on the grid always wins, so you can
|
|
2453
|
+
* adopt it and still override one piece.
|
|
2454
|
+
*/
|
|
2455
|
+
rowModel?: GridRowModel<TData>;
|
|
2456
|
+
/**
|
|
2457
|
+
* Columns that REPLACE `columns` while set. The server-side row model
|
|
2458
|
+
* supplies them in pivot mode - one column per pivoted value, grouped
|
|
2459
|
+
* under a header per pivot key - and clears them when pivot mode ends,
|
|
2460
|
+
* so `columns` stays the app's own list. Rarely set by hand.
|
|
2461
|
+
*/
|
|
2462
|
+
pivotResultColumns?: Array<ColumnDef<TFeatures, TData>> | null;
|
|
2463
|
+
rowSelectionModel?: {
|
|
2464
|
+
isSelected: (rowId: string, row: TData) => boolean;
|
|
2465
|
+
/** Whether the header checkbox shows empty, indeterminate, or ticked. */
|
|
2466
|
+
headerState: () => "none" | "some" | "all";
|
|
2467
|
+
toggle: (rowId: string, row: TData, next: boolean) => void;
|
|
2468
|
+
/** The header checkbox: select or clear everything, loaded or not. */
|
|
2469
|
+
toggleAll: (next: boolean) => void;
|
|
2470
|
+
/**
|
|
2471
|
+
* How many rows the rule selects, counting the ones the grid never
|
|
2472
|
+
* loaded; `null` when it cannot say. The selection bar shows this
|
|
2473
|
+
* instead of counting ticked rows on screen.
|
|
2474
|
+
*/
|
|
2475
|
+
selectedCount?: () => number | null;
|
|
2476
|
+
/**
|
|
2477
|
+
* Apply one patch to every selected row, loaded or not. When present,
|
|
2478
|
+
* the bulk-edit drawer sends its edits here instead of writing the
|
|
2479
|
+
* loaded cells. Resolves with how many rows changed.
|
|
2480
|
+
*/
|
|
2481
|
+
bulkUpdate?: (patch: Record<string, unknown>) => Promise<number>;
|
|
2482
|
+
};
|
|
2102
2483
|
/**
|
|
2103
2484
|
* Marks a row as an expandable "detail row". When this returns true the
|
|
2104
2485
|
* grid renders that row as a SINGLE full-width cell (colspan across every
|
|
@@ -2115,12 +2496,43 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
2115
2496
|
* `isDetailRow` is true. Receives the row's data and its index.
|
|
2116
2497
|
*/
|
|
2117
2498
|
renderDetailRow?: Snippet<[{ row: TData; rowIndex: number }]>;
|
|
2499
|
+
/**
|
|
2500
|
+
* The height of a detail row, in px, or a function of its data. With it
|
|
2501
|
+
* the virtualizer can size detail rows, so master-detail works with
|
|
2502
|
+
* `virtualization` on (the panel scrolls inside its cell when taller).
|
|
2503
|
+
* Without it a detail row is auto height, which needs
|
|
2504
|
+
* `virtualization={false}`.
|
|
2505
|
+
*/
|
|
2506
|
+
detailRowHeight?: number | ((row: TData) => number);
|
|
2507
|
+
/**
|
|
2508
|
+
* A row-header column of chevrons that open and close detail rows. It
|
|
2509
|
+
* sits with the row-number and selection columns: sticky at the left,
|
|
2510
|
+
* no column menu, not resizable, not reorderable, outside the active
|
|
2511
|
+
* cell and the selection. The chevron calls `onDetailToggle` (or, on a
|
|
2512
|
+
* server row model, the model's own toggle) and reads `isDetailOpen`
|
|
2513
|
+
* for its direction; `hasDetail` hides it on rows that have nothing to
|
|
2514
|
+
* open. Detail rows themselves get an empty cell.
|
|
2515
|
+
*/
|
|
2516
|
+
showDetailToggle?: boolean;
|
|
2517
|
+
/**
|
|
2518
|
+
* Open or close the detail under a row. The chevron of `showDetailToggle`
|
|
2519
|
+
* and Ctrl+Enter on a row call it; you keep the open set and insert or
|
|
2520
|
+
* remove the detail row in `data`. A server row model supplies its own
|
|
2521
|
+
* (the `rowModel` prop wires `toggleDetail`), so this is the client side.
|
|
2522
|
+
*/
|
|
2523
|
+
onDetailToggle?: (row: TData, rowIndex: number) => void;
|
|
2524
|
+
/** Whether the detail under a row is open: the chevron's direction and `aria-expanded`. */
|
|
2525
|
+
isDetailOpen?: (row: TData) => boolean;
|
|
2526
|
+
/** Whether a row has a detail to open; the chevron is left out where this returns false. */
|
|
2527
|
+
hasDetail?: (row: TData) => boolean;
|
|
2118
2528
|
/**
|
|
2119
2529
|
* Server-side group / tree keyboard + accessibility, built into the grid. When
|
|
2120
2530
|
* set, the grid uses the treegrid role and marks matching rows with
|
|
2121
2531
|
* `aria-level` / `aria-expanded`, and ArrowRight / ArrowLeft expand / collapse
|
|
2122
|
-
* the focused group row (no app-level key handling). Pair with
|
|
2123
|
-
* + `SvGroupCell` for the visual
|
|
2532
|
+
* the focused group row (no app-level key handling). Pair with
|
|
2533
|
+
* `serverGroupRows` + `SvGroupCell` from `@svgrid/enterprise` for the visual
|
|
2534
|
+
* expander, or drive it from your own tree state. Every accessor receives the
|
|
2535
|
+
* row data.
|
|
2124
2536
|
*/
|
|
2125
2537
|
serverGroup?: {
|
|
2126
2538
|
/** Whether a row is an expandable group / branch. */
|
|
@@ -2131,6 +2543,12 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
2131
2543
|
expanded?: (row: TData) => boolean;
|
|
2132
2544
|
/** Expand / collapse a group row. Called on ArrowRight / ArrowLeft. */
|
|
2133
2545
|
onToggle: (row: TData) => void;
|
|
2546
|
+
/** Open / close the detail panel under a leaf. Called on Ctrl+Enter when `renderDetailRow` is set, and by the `showDetailToggle` chevron. */
|
|
2547
|
+
toggleDetail?: (row: TData) => void;
|
|
2548
|
+
/** Whether the detail under a leaf is open (the chevron's direction). */
|
|
2549
|
+
detailOpen?: (row: TData) => boolean;
|
|
2550
|
+
/** Whether a row can open a detail at all; a group, a placeholder or a detail row cannot. */
|
|
2551
|
+
hasDetail?: (row: TData) => boolean;
|
|
2134
2552
|
};
|
|
2135
2553
|
/**
|
|
2136
2554
|
* Server-side set-filter values. When set, a column's filter checklist is
|
|
@@ -2158,6 +2576,17 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
2158
2576
|
* skips them.
|
|
2159
2577
|
*/
|
|
2160
2578
|
frozenRows?: number;
|
|
2579
|
+
/**
|
|
2580
|
+
* Keep the group a row belongs to in view: while the rows of an open
|
|
2581
|
+
* group scroll past, the group's row (and its parents' rows) stay under
|
|
2582
|
+
* the header, the way a section heading stays put in a long list, so a
|
|
2583
|
+
* screen deep inside a 60,000-row group still says which group it is.
|
|
2584
|
+
* Works for server-side groups (`rowModel` / `serverGroup`), client
|
|
2585
|
+
* grouping and tree data. Under `virtualization` the band shows a copy
|
|
2586
|
+
* of each ancestor row; without it the rows themselves stick. Off by
|
|
2587
|
+
* default.
|
|
2588
|
+
*/
|
|
2589
|
+
stickyGroupRows?: boolean;
|
|
2161
2590
|
/**
|
|
2162
2591
|
* Merged cells: rectangles drawn as one cell, a spreadsheet's Merge &
|
|
2163
2592
|
* Center. Each entry is the top-left cell (display indices) and how many
|
|
@@ -2234,6 +2663,23 @@ export type Props<TFeatures extends TableFeatures = TableFeatures, TData extends
|
|
|
2234
2663
|
fromGridId: number;
|
|
2235
2664
|
toGridId: number;
|
|
2236
2665
|
}) => void;
|
|
2666
|
+
/**
|
|
2667
|
+
* Take the drop yourself. With this set the grid keeps the drag
|
|
2668
|
+
* affordance and the drop indicator but does not touch its data: the
|
|
2669
|
+
* handler gets the dragged row, the row it landed on (null for the
|
|
2670
|
+
* empty space below the rows) and the side - `before` / `after`, or
|
|
2671
|
+
* `into` when it landed on the middle of a group or tree row, which
|
|
2672
|
+
* makes it that row's child. The path for a `rowModel`, whose rows the
|
|
2673
|
+
* grid does not own: hand the move to the model (`moveRow`) or to your
|
|
2674
|
+
* server. Only fires within one grid; a drop from another grid stays
|
|
2675
|
+
* managed.
|
|
2676
|
+
*/
|
|
2677
|
+
onRowDrop?: (event: {
|
|
2678
|
+
row: TData;
|
|
2679
|
+
target: TData | null;
|
|
2680
|
+
targetIndex: number | null;
|
|
2681
|
+
side: "before" | "after" | "into";
|
|
2682
|
+
}) => void;
|
|
2237
2683
|
/**
|
|
2238
2684
|
* Align this grid with others that share the same non-empty
|
|
2239
2685
|
* `alignedGridGroup` string: horizontal scroll and column-resize widths are
|
|
@@ -45,6 +45,18 @@
|
|
|
45
45
|
* loading line instead of "No options", which would read as "nothing to
|
|
46
46
|
* pick" when the truth is "not here yet". */
|
|
47
47
|
loading?: boolean
|
|
48
|
+
/**
|
|
49
|
+
* The trigger's element id, so a form's `<label for>` reaches it and
|
|
50
|
+
* clicking the label focuses it. Without one a select in a form was a
|
|
51
|
+
* button with no name.
|
|
52
|
+
*/
|
|
53
|
+
id?: string
|
|
54
|
+
/** Accessible name for the trigger when no label points at `id`. */
|
|
55
|
+
ariaLabel?: string
|
|
56
|
+
/** Marks the trigger `aria-invalid`, the way an input in the same form is. */
|
|
57
|
+
invalid?: boolean
|
|
58
|
+
/** `aria-describedby` for the trigger: the error or help text of the field. */
|
|
59
|
+
describedBy?: string
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
let {
|
|
@@ -59,6 +71,10 @@
|
|
|
59
71
|
onCommit,
|
|
60
72
|
onCancel,
|
|
61
73
|
loading = false,
|
|
74
|
+
id,
|
|
75
|
+
ariaLabel,
|
|
76
|
+
invalid = false,
|
|
77
|
+
describedBy,
|
|
62
78
|
}: Props = $props()
|
|
63
79
|
|
|
64
80
|
/** Stable per-instance id used to build option ids for
|
|
@@ -348,10 +364,14 @@
|
|
|
348
364
|
<!-- svelte-ignore a11y_role_supports_aria_props_implicit -->
|
|
349
365
|
<button
|
|
350
366
|
type="button"
|
|
367
|
+
{id}
|
|
351
368
|
class="sv-grid-dropdown-trigger"
|
|
352
369
|
class:sv-grid-dropdown-trigger-chips={renderChipsInTrigger && selectedArr.length > 0}
|
|
353
370
|
aria-haspopup="listbox"
|
|
354
371
|
aria-expanded={open}
|
|
372
|
+
aria-label={ariaLabel}
|
|
373
|
+
aria-invalid={invalid || undefined}
|
|
374
|
+
aria-describedby={describedBy}
|
|
355
375
|
aria-activedescendant={open ? optionId(highlighted) : undefined}
|
|
356
376
|
bind:this={triggerEl}
|
|
357
377
|
use:focusTrigger
|
package/src/SvModal.svelte
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { portalToBody } from './popover'
|
|
17
17
|
import { nextEditorId } from './editor-contract'
|
|
18
18
|
import { createOverlay } from './createOverlay.svelte'
|
|
19
|
+
import { getFocusable } from './a11y/focus-trap'
|
|
19
20
|
|
|
20
21
|
type Props = {
|
|
21
22
|
open?: boolean
|
|
@@ -33,6 +34,13 @@
|
|
|
33
34
|
closeOnEsc?: boolean
|
|
34
35
|
/** Hide the header close (x) button. */
|
|
35
36
|
hideClose?: boolean
|
|
37
|
+
/**
|
|
38
|
+
* The element to focus when the dialog opens. Defaults to the first
|
|
39
|
+
* focusable control in the body or footer - never the header Close (x),
|
|
40
|
+
* so opening a dialog lands on its content and Enter does not dismiss it.
|
|
41
|
+
* Pass a getter to target a specific field (e.g. a search input).
|
|
42
|
+
*/
|
|
43
|
+
initialFocus?: () => HTMLElement | null
|
|
36
44
|
children?: Snippet
|
|
37
45
|
footer?: Snippet
|
|
38
46
|
}
|
|
@@ -48,6 +56,7 @@
|
|
|
48
56
|
closeOnBackdrop = true,
|
|
49
57
|
closeOnEsc = true,
|
|
50
58
|
hideClose = false,
|
|
59
|
+
initialFocus,
|
|
51
60
|
children,
|
|
52
61
|
footer,
|
|
53
62
|
}: Props = $props()
|
|
@@ -69,6 +78,19 @@
|
|
|
69
78
|
closeOnEsc: () => closeOnEsc,
|
|
70
79
|
closeOnBackdrop: () => closeOnBackdrop,
|
|
71
80
|
onOpen: () => { drag = { x: 0, y: 0 }; box = null },
|
|
81
|
+
// Land focus on the dialog's content, not the header Close (x). The x is
|
|
82
|
+
// the first focusable in DOM order, so the trap's "first focusable"
|
|
83
|
+
// default sent focus there - where Enter immediately dismissed the
|
|
84
|
+
// dialog and the loud focus ring pointed at "close" over the primary
|
|
85
|
+
// action. Prefer the first focusable outside the header; fall back to the
|
|
86
|
+
// panel itself when the body has no control of its own.
|
|
87
|
+
initialFocus: () => {
|
|
88
|
+
const explicit = initialFocus?.()
|
|
89
|
+
if (explicit) return explicit
|
|
90
|
+
if (!dialogEl) return null
|
|
91
|
+
const first = getFocusable(dialogEl).find((el) => !el.closest('.sv-modal__header'))
|
|
92
|
+
return first ?? dialogEl
|
|
93
|
+
},
|
|
72
94
|
})
|
|
73
95
|
|
|
74
96
|
// --- Drag (header) ---------------------------------------------------------
|
package/src/SvModal.test.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SvDrawer shares), plus the modal's title wiring and closeOnEsc opt-out.
|
|
5
5
|
*/
|
|
6
6
|
import { describe, expect, it } from 'vitest'
|
|
7
|
-
import { mount, unmount, flushSync } from 'svelte'
|
|
7
|
+
import { mount, unmount, flushSync, createRawSnippet } from 'svelte'
|
|
8
8
|
import SvModal from './SvModal.svelte'
|
|
9
9
|
|
|
10
10
|
function mountModal(props: Record<string, unknown>) {
|
|
@@ -79,6 +79,35 @@ describe('SvModal', () => {
|
|
|
79
79
|
} finally { destroy() }
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
+
it('focuses the first body control on open, not the header Close (x)', async () => {
|
|
83
|
+
// The close x is the first focusable in DOM order; the trap's plain "first
|
|
84
|
+
// focusable" sent focus there, so Enter dismissed the dialog at once and
|
|
85
|
+
// the focus ring pointed at "close". Focus must land on the content.
|
|
86
|
+
// (The trap focuses on the next microtask, so let it run.)
|
|
87
|
+
const body = createRawSnippet(() => ({
|
|
88
|
+
render: () => `<button type="button" class="probe-ok">OK</button>`,
|
|
89
|
+
}))
|
|
90
|
+
const { destroy } = mountModal({ open: true, title: 'Edit row', children: body })
|
|
91
|
+
try {
|
|
92
|
+
flushSync()
|
|
93
|
+
await new Promise((r) => setTimeout(r, 0))
|
|
94
|
+
const active = document.activeElement as HTMLElement
|
|
95
|
+
expect(active?.classList.contains('sv-modal__x')).toBe(false)
|
|
96
|
+
expect(active?.classList.contains('probe-ok')).toBe(true)
|
|
97
|
+
} finally { destroy() }
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('falls back to the panel, still not the Close (x), when the body has no control', async () => {
|
|
101
|
+
const { destroy } = mountModal({ open: true, title: 'Empty' })
|
|
102
|
+
try {
|
|
103
|
+
flushSync()
|
|
104
|
+
await new Promise((r) => setTimeout(r, 0))
|
|
105
|
+
const active = document.activeElement as HTMLElement
|
|
106
|
+
expect(active?.classList.contains('sv-modal__x')).toBe(false)
|
|
107
|
+
expect(active?.classList.contains('sv-modal')).toBe(true)
|
|
108
|
+
} finally { destroy() }
|
|
109
|
+
})
|
|
110
|
+
|
|
82
111
|
it('dismisses on outside (backdrop) pointerdown', () => {
|
|
83
112
|
const { destroy } = mountModal({ open: true })
|
|
84
113
|
try {
|