@dxos/react-ui-table 0.8.4-main.28f8d3d → 0.8.4-main.406dc2a
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/lib/browser/chunk-4K7JPALT.mjs +66 -0
- package/dist/lib/browser/chunk-4K7JPALT.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ZAOSIG3L.mjs → chunk-OZTXLZGM.mjs} +526 -536
- package/dist/lib/browser/chunk-OZTXLZGM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +373 -481
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +11 -8
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/chunk-MK6OVUF6.mjs +67 -0
- package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZOFFI3JJ.mjs → chunk-S56Z4V4X.mjs} +526 -536
- package/dist/lib/node-esm/chunk-S56Z4V4X.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +373 -481
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +11 -8
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/DynamicTable.d.ts +2 -2
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +51 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +104 -5
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +8 -5
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +41 -3
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +12 -6
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +8 -13
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +3 -2
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +0 -7
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +7 -6
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +1 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +3 -22
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +25 -5
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +4 -5
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +51 -50
- package/src/components/Table/DynamicTable.stories.tsx +12 -9
- package/src/components/Table/DynamicTable.tsx +4 -7
- package/src/components/Table/Relations.stories.tsx +162 -38
- package/src/components/Table/Table.stories.tsx +59 -52
- package/src/components/Table/Table.tsx +109 -90
- package/src/components/TableCellEditor/FormCellEditor.tsx +153 -42
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +22 -63
- package/src/components/TableCellEditor/TableCellEditor.tsx +62 -208
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/testing.ts +2 -2
- package/src/hooks/useAddRow.ts +7 -5
- package/src/hooks/useTableModel.ts +1 -1
- package/src/model/modal-controller.ts +0 -28
- package/src/model/table-model.test.ts +18 -10
- package/src/model/table-model.ts +26 -17
- package/src/model/table-presentation.test.ts +21 -20
- package/src/model/table-presentation.ts +58 -39
- package/src/model/table-sorting.ts +15 -6
- package/src/playwright/smoke.spec.ts +46 -46
- package/src/testing/useTestTableModel.ts +9 -6
- package/src/types/index.ts +1 -1
- package/src/types/schema.ts +63 -6
- package/src/util/dynamic-table.ts +11 -11
- package/src/util/index.ts +0 -1
- package/src/util/schema.ts +4 -4
- package/src/util/table-buttons.ts +3 -3
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZAOSIG3L.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -12
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -86
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/util/table.ts +0 -53
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
schema_exports
|
|
4
|
+
} from "./chunk-MK6OVUF6.mjs";
|
|
5
5
|
|
|
6
6
|
// src/util/dynamic-table.ts
|
|
7
|
-
import { Obj } from "@dxos/echo";
|
|
8
|
-
import { getTypename, toJsonSchema } from "@dxos/echo
|
|
7
|
+
import { Filter, Obj, Query } from "@dxos/echo";
|
|
8
|
+
import { getTypename, toJsonSchema } from "@dxos/echo/internal";
|
|
9
9
|
import { ProjectionModel, createView, getSchemaFromPropertyDefinitions } from "@dxos/schema";
|
|
10
10
|
var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
11
11
|
if (typename && properties) {
|
|
@@ -28,12 +28,12 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
28
28
|
throw new Error("invalid properties");
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
var makeDynamicTable = ({
|
|
32
|
-
const table = Obj.make(
|
|
31
|
+
var makeDynamicTable = ({ jsonSchema, properties }) => {
|
|
32
|
+
const table = Obj.make(schema_exports.Table, {
|
|
33
33
|
sizes: {}
|
|
34
34
|
});
|
|
35
35
|
const view = createView({
|
|
36
|
-
|
|
36
|
+
query: Query.select(Filter.everything()),
|
|
37
37
|
jsonSchema,
|
|
38
38
|
presentation: table,
|
|
39
39
|
...properties && {
|
|
@@ -41,6 +41,7 @@ var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
|
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
const projection = new ProjectionModel(jsonSchema, view.projection);
|
|
44
|
+
projection.normalizeView();
|
|
44
45
|
if (properties && projection.fields) {
|
|
45
46
|
setProperties(view, projection, table, properties);
|
|
46
47
|
}
|
|
@@ -68,7 +69,7 @@ var setProperties = (view, projection, table, properties) => {
|
|
|
68
69
|
}
|
|
69
70
|
if (property.sort) {
|
|
70
71
|
const fieldId = field.id;
|
|
71
|
-
view.
|
|
72
|
+
view.sort = [
|
|
72
73
|
{
|
|
73
74
|
fieldId,
|
|
74
75
|
direction: property.sort
|
|
@@ -82,41 +83,6 @@ var setProperties = (view, projection, table, properties) => {
|
|
|
82
83
|
// src/util/signals.ts
|
|
83
84
|
var touch = (value) => value;
|
|
84
85
|
|
|
85
|
-
// src/util/table.ts
|
|
86
|
-
import { Match } from "effect";
|
|
87
|
-
import { Obj as Obj2 } from "@dxos/echo";
|
|
88
|
-
import { toEffectSchema } from "@dxos/echo-schema";
|
|
89
|
-
import { createViewFromSpace, getSchemaProperties } from "@dxos/schema";
|
|
90
|
-
var createTable = async ({ sizes, ...props }) => {
|
|
91
|
-
const table = Obj2.make(TableView, {
|
|
92
|
-
sizes: {}
|
|
93
|
-
});
|
|
94
|
-
const { jsonSchema, view } = await createViewFromSpace({
|
|
95
|
-
...props,
|
|
96
|
-
presentation: table
|
|
97
|
-
});
|
|
98
|
-
const schema = toEffectSchema(jsonSchema);
|
|
99
|
-
const shouldIncludeId = props.fields?.find((field) => field === "id") !== void 0;
|
|
100
|
-
const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
|
|
101
|
-
for (const property of properties) {
|
|
102
|
-
if (sizes?.[property.name]) {
|
|
103
|
-
table.sizes[property.name] = sizes[property.name];
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
Match.type().pipe(Match.when("boolean", () => {
|
|
107
|
-
table.sizes[property.name] = 100;
|
|
108
|
-
}), Match.when("number", () => {
|
|
109
|
-
table.sizes[property.name] = 100;
|
|
110
|
-
}), Match.orElse(() => {
|
|
111
|
-
}))(property.type);
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
jsonSchema,
|
|
115
|
-
schema,
|
|
116
|
-
view
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
86
|
// src/util/table-buttons.ts
|
|
121
87
|
var BUTTON_IDENTIFIERS = {
|
|
122
88
|
columnSettings: "data-table-column-settings-button",
|
|
@@ -126,10 +92,9 @@ var BUTTON_IDENTIFIERS = {
|
|
|
126
92
|
saveDraftRow: "data-table-save-draft-row-button",
|
|
127
93
|
sort: "data-table-sort-button"
|
|
128
94
|
};
|
|
129
|
-
var createButton = ({ attr, data, disabled = false, icon, testId, type = "primary" }) => {
|
|
95
|
+
var createButton = ({ attr, data, disabled = false, icon, testId, type: _type = "primary" }) => {
|
|
130
96
|
const dataAttrs = Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
|
|
131
|
-
|
|
132
|
-
return `<button ${attr} data-testid="${testId}" class="dx-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? "disabled" : ""} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
|
|
97
|
+
return `<button ${attr} data-testid="${testId}" class="dx-button is-6 aspect-square pli-0.5 min-bs-0" ${dataAttrs} ${disabled ? "disabled" : ""} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
|
|
133
98
|
};
|
|
134
99
|
var addColumnButton = {
|
|
135
100
|
attr: BUTTON_IDENTIFIERS.newColumn,
|
|
@@ -155,7 +120,8 @@ var columnSettingsButton = {
|
|
|
155
120
|
attr: BUTTON_IDENTIFIERS.columnSettings,
|
|
156
121
|
icon: columnSettingsButton.icon,
|
|
157
122
|
data: {
|
|
158
|
-
"data-field-id": fieldId
|
|
123
|
+
"data-field-id": fieldId,
|
|
124
|
+
"data-variant": "ghost"
|
|
159
125
|
},
|
|
160
126
|
testId: "table-column-settings-button"
|
|
161
127
|
});
|
|
@@ -291,14 +257,14 @@ var tableControls = {
|
|
|
291
257
|
};
|
|
292
258
|
|
|
293
259
|
// src/util/schema.ts
|
|
294
|
-
import
|
|
295
|
-
import
|
|
260
|
+
import * as Schema from "effect/Schema";
|
|
261
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
296
262
|
var narrowSchema = (schema, paths) => {
|
|
297
263
|
const ast = schema?.ast;
|
|
298
|
-
if (isTypeLiteral(ast)) {
|
|
264
|
+
if (SchemaAST.isTypeLiteral(ast)) {
|
|
299
265
|
const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
|
|
300
266
|
if (propertySignatures.length > 0) {
|
|
301
|
-
const narrowType = new TypeLiteral(propertySignatures, []);
|
|
267
|
+
const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
|
|
302
268
|
return Schema.make(narrowType);
|
|
303
269
|
}
|
|
304
270
|
}
|
|
@@ -308,11 +274,11 @@ var narrowSchema = (schema, paths) => {
|
|
|
308
274
|
// src/model/table-model.ts
|
|
309
275
|
import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
|
|
310
276
|
import { Resource as Resource2 } from "@dxos/context";
|
|
311
|
-
import { Obj as
|
|
312
|
-
import { FormatEnum as FormatEnum2, getSchema,
|
|
277
|
+
import { Obj as Obj2, Ref } from "@dxos/echo";
|
|
278
|
+
import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
|
|
313
279
|
import { invariant } from "@dxos/invariant";
|
|
314
280
|
import { ObjectId } from "@dxos/keys";
|
|
315
|
-
import { isLiveObject } from "@dxos/live-object";
|
|
281
|
+
import { getSnapshot, isLiveObject } from "@dxos/live-object";
|
|
316
282
|
import { fullyQualifiedId } from "@dxos/react-client/echo";
|
|
317
283
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
318
284
|
import { ProjectionModel as ProjectionModel2, validateSchema } from "@dxos/schema";
|
|
@@ -336,17 +302,47 @@ var extractTagIds = (value) => {
|
|
|
336
302
|
// src/model/selection-model.ts
|
|
337
303
|
import { computed, effect, signal } from "@preact/signals-core";
|
|
338
304
|
import { Resource } from "@dxos/context";
|
|
305
|
+
function _define_property(obj, key, value) {
|
|
306
|
+
if (key in obj) {
|
|
307
|
+
Object.defineProperty(obj, key, {
|
|
308
|
+
value,
|
|
309
|
+
enumerable: true,
|
|
310
|
+
configurable: true,
|
|
311
|
+
writable: true
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
obj[key] = value;
|
|
315
|
+
}
|
|
316
|
+
return obj;
|
|
317
|
+
}
|
|
339
318
|
var SelectionModel = class extends Resource {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
319
|
+
async _open() {
|
|
320
|
+
const selectionWatcher = effect(() => {
|
|
321
|
+
touch(this._selection.value);
|
|
322
|
+
this._onSelectionChanged?.();
|
|
323
|
+
});
|
|
324
|
+
this._ctx.onDispose(selectionWatcher);
|
|
325
|
+
}
|
|
326
|
+
//
|
|
327
|
+
// Getters
|
|
328
|
+
//
|
|
329
|
+
get selection() {
|
|
330
|
+
return this._selection;
|
|
331
|
+
}
|
|
332
|
+
get hasSelection() {
|
|
333
|
+
return this._hasSelection;
|
|
334
|
+
}
|
|
335
|
+
get allRowsSeleted() {
|
|
336
|
+
return this._allSelected;
|
|
337
|
+
}
|
|
338
|
+
get selectionMode() {
|
|
339
|
+
return this._selectionMode;
|
|
340
|
+
}
|
|
348
341
|
constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
|
|
349
|
-
super(), this
|
|
342
|
+
super(), _define_property(this, "_rows", void 0), _define_property(this, "_selectionMode", void 0), _define_property(this, "_initialSelection", void 0), _define_property(this, "_onSelectionChanged", void 0), _define_property(this, "_selection", void 0), _define_property(this, "_validSelectedIds", void 0), _define_property(this, "_hasSelection", void 0), _define_property(this, "_allSelected", void 0), _define_property(this, "getSelectedRows", void 0), _define_property(this, "isRowIndexSelected", void 0), _define_property(this, "isObjectSelected", void 0), //
|
|
343
|
+
// Manipulation
|
|
344
|
+
//
|
|
345
|
+
_define_property(this, "toggleSelectionForRowIndex", void 0), _define_property(this, "setSelection", void 0), this._rows = _rows, this._selectionMode = _selectionMode, this._initialSelection = _initialSelection, this._onSelectionChanged = _onSelectionChanged, this._validSelectedIds = computed(() => {
|
|
350
346
|
const rows = this._rows.value;
|
|
351
347
|
if (!rows) {
|
|
352
348
|
return /* @__PURE__ */ new Set();
|
|
@@ -395,73 +391,27 @@ var SelectionModel = class extends Resource {
|
|
|
395
391
|
};
|
|
396
392
|
this._selection = signal(new Set(this._initialSelection));
|
|
397
393
|
}
|
|
398
|
-
async _open() {
|
|
399
|
-
const selectionWatcher = effect(() => {
|
|
400
|
-
touch(this._selection.value);
|
|
401
|
-
this._onSelectionChanged?.();
|
|
402
|
-
});
|
|
403
|
-
this._ctx.onDispose(selectionWatcher);
|
|
404
|
-
}
|
|
405
|
-
//
|
|
406
|
-
// Getters
|
|
407
|
-
//
|
|
408
|
-
get selection() {
|
|
409
|
-
return this._selection;
|
|
410
|
-
}
|
|
411
|
-
get hasSelection() {
|
|
412
|
-
return this._hasSelection;
|
|
413
|
-
}
|
|
414
|
-
get allRowsSeleted() {
|
|
415
|
-
return this._allSelected;
|
|
416
|
-
}
|
|
417
|
-
get selectionMode() {
|
|
418
|
-
return this._selectionMode;
|
|
419
|
-
}
|
|
420
|
-
getSelectedRows;
|
|
421
|
-
isRowIndexSelected;
|
|
422
|
-
isObjectSelected;
|
|
423
|
-
//
|
|
424
|
-
// Manipulation
|
|
425
|
-
//
|
|
426
|
-
toggleSelectionForRowIndex;
|
|
427
|
-
setSelection;
|
|
428
394
|
};
|
|
429
395
|
|
|
430
396
|
// src/model/table-sorting.ts
|
|
431
397
|
import { computed as computed2, signal as signal2 } from "@preact/signals-core";
|
|
432
398
|
import orderBy from "lodash.orderby";
|
|
433
|
-
import { FormatEnum, TypeEnum, getValue } from "@dxos/echo
|
|
399
|
+
import { FormatEnum, TypeEnum, getValue } from "@dxos/echo/internal";
|
|
434
400
|
import { formatForDisplay } from "@dxos/react-ui-form";
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
sortedRows;
|
|
443
|
-
constructor(rows, _view, _projection) {
|
|
444
|
-
this._view = _view;
|
|
445
|
-
this._projection = _projection;
|
|
446
|
-
this._displayToDataIndex = /* @__PURE__ */ new Map();
|
|
447
|
-
this._localSort = signal2(void 0);
|
|
448
|
-
this._rows = rows;
|
|
449
|
-
this._isDirty = computed2(() => {
|
|
450
|
-
const local = this._localSort.value;
|
|
451
|
-
const viewSort = this._view.query.sort?.[0];
|
|
452
|
-
if (local?.type === "cleared") {
|
|
453
|
-
return viewSort !== void 0;
|
|
454
|
-
}
|
|
455
|
-
if (local?.type === "active") {
|
|
456
|
-
if (!viewSort) {
|
|
457
|
-
return true;
|
|
458
|
-
}
|
|
459
|
-
return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
|
|
460
|
-
}
|
|
461
|
-
return false;
|
|
401
|
+
function _define_property2(obj, key, value) {
|
|
402
|
+
if (key in obj) {
|
|
403
|
+
Object.defineProperty(obj, key, {
|
|
404
|
+
value,
|
|
405
|
+
enumerable: true,
|
|
406
|
+
configurable: true,
|
|
407
|
+
writable: true
|
|
462
408
|
});
|
|
463
|
-
|
|
409
|
+
} else {
|
|
410
|
+
obj[key] = value;
|
|
464
411
|
}
|
|
412
|
+
return obj;
|
|
413
|
+
}
|
|
414
|
+
var TableSorting = class {
|
|
465
415
|
/**
|
|
466
416
|
* @reactive
|
|
467
417
|
* @returns Local sort if present, falls back to view sort.
|
|
@@ -474,7 +424,7 @@ var TableSorting = class {
|
|
|
474
424
|
if (local?.type === "active") {
|
|
475
425
|
return local.sort;
|
|
476
426
|
}
|
|
477
|
-
return this._view.
|
|
427
|
+
return this._view.sort?.[0];
|
|
478
428
|
}
|
|
479
429
|
/**
|
|
480
430
|
* @reactive
|
|
@@ -518,11 +468,11 @@ var TableSorting = class {
|
|
|
518
468
|
save() {
|
|
519
469
|
if (this._localSort.value !== void 0) {
|
|
520
470
|
if (this._localSort.value.type === "active") {
|
|
521
|
-
this._view.
|
|
471
|
+
this._view.sort = [
|
|
522
472
|
this._localSort.value.sort
|
|
523
473
|
];
|
|
524
474
|
} else {
|
|
525
|
-
this._view.
|
|
475
|
+
this._view.sort = [];
|
|
526
476
|
}
|
|
527
477
|
this._localSort.value = void 0;
|
|
528
478
|
}
|
|
@@ -597,9 +547,51 @@ var TableSorting = class {
|
|
|
597
547
|
value
|
|
598
548
|
});
|
|
599
549
|
}
|
|
550
|
+
constructor(rows, _view, _projection) {
|
|
551
|
+
_define_property2(this, "_view", void 0);
|
|
552
|
+
_define_property2(this, "_projection", void 0);
|
|
553
|
+
_define_property2(this, "_displayToDataIndex", void 0);
|
|
554
|
+
_define_property2(this, "_rows", void 0);
|
|
555
|
+
_define_property2(this, "_localSort", void 0);
|
|
556
|
+
_define_property2(this, "_isDirty", void 0);
|
|
557
|
+
_define_property2(this, "sortedRows", void 0);
|
|
558
|
+
this._view = _view;
|
|
559
|
+
this._projection = _projection;
|
|
560
|
+
this._displayToDataIndex = /* @__PURE__ */ new Map();
|
|
561
|
+
this._localSort = signal2(void 0);
|
|
562
|
+
this._rows = rows;
|
|
563
|
+
this._isDirty = computed2(() => {
|
|
564
|
+
const local = this._localSort.value;
|
|
565
|
+
const viewSort = this._view.sort?.[0];
|
|
566
|
+
if (local?.type === "cleared") {
|
|
567
|
+
return viewSort !== void 0;
|
|
568
|
+
}
|
|
569
|
+
if (local?.type === "active") {
|
|
570
|
+
if (!viewSort) {
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
|
|
574
|
+
}
|
|
575
|
+
return false;
|
|
576
|
+
});
|
|
577
|
+
this.sortedRows = this.initialiseSortedRows();
|
|
578
|
+
}
|
|
600
579
|
};
|
|
601
580
|
|
|
602
581
|
// src/model/table-model.ts
|
|
582
|
+
function _define_property3(obj, key, value) {
|
|
583
|
+
if (key in obj) {
|
|
584
|
+
Object.defineProperty(obj, key, {
|
|
585
|
+
value,
|
|
586
|
+
enumerable: true,
|
|
587
|
+
configurable: true,
|
|
588
|
+
writable: true
|
|
589
|
+
});
|
|
590
|
+
} else {
|
|
591
|
+
obj[key] = value;
|
|
592
|
+
}
|
|
593
|
+
return obj;
|
|
594
|
+
}
|
|
603
595
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
604
596
|
var defaultFeatures = {
|
|
605
597
|
selection: {
|
|
@@ -610,68 +602,6 @@ var defaultFeatures = {
|
|
|
610
602
|
schemaEditable: false
|
|
611
603
|
};
|
|
612
604
|
var TableModel = class extends Resource2 {
|
|
613
|
-
_view;
|
|
614
|
-
_projection;
|
|
615
|
-
_table;
|
|
616
|
-
_visibleRange = signal3({
|
|
617
|
-
start: {
|
|
618
|
-
row: 0,
|
|
619
|
-
col: 0
|
|
620
|
-
},
|
|
621
|
-
end: {
|
|
622
|
-
row: 0,
|
|
623
|
-
col: 0
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
_onInsertRow;
|
|
627
|
-
_onDeleteRows;
|
|
628
|
-
_onDeleteColumn;
|
|
629
|
-
_onCellUpdate;
|
|
630
|
-
_onRowOrderChange;
|
|
631
|
-
_onRowAction;
|
|
632
|
-
_rowActions;
|
|
633
|
-
_features;
|
|
634
|
-
_rows = signal3([]);
|
|
635
|
-
_draftRows = signal3([]);
|
|
636
|
-
_sorting;
|
|
637
|
-
_pinnedRows;
|
|
638
|
-
_selection;
|
|
639
|
-
_columnMeta;
|
|
640
|
-
constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
641
|
-
top: [],
|
|
642
|
-
bottom: []
|
|
643
|
-
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
644
|
-
super();
|
|
645
|
-
this._view = view;
|
|
646
|
-
this._projection = projection ?? new ProjectionModel2(schema, view.projection);
|
|
647
|
-
this._features = {
|
|
648
|
-
...defaultFeatures,
|
|
649
|
-
...features
|
|
650
|
-
};
|
|
651
|
-
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
652
|
-
F: __dxlog_file,
|
|
653
|
-
L: 141,
|
|
654
|
-
S: this,
|
|
655
|
-
A: [
|
|
656
|
-
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
657
|
-
"'Single selection is not compatible with editable tables.'"
|
|
658
|
-
]
|
|
659
|
-
});
|
|
660
|
-
this._sorting = new TableSorting(this._rows, this._view, this._projection);
|
|
661
|
-
if (sorting.length > 0) {
|
|
662
|
-
const [sort] = sorting;
|
|
663
|
-
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
664
|
-
}
|
|
665
|
-
this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
|
|
666
|
-
this._pinnedRows = pinnedRows;
|
|
667
|
-
this._rowActions = rowActions;
|
|
668
|
-
this._onInsertRow = onInsertRow;
|
|
669
|
-
this._onDeleteRows = onDeleteRows;
|
|
670
|
-
this._onDeleteColumn = onDeleteColumn;
|
|
671
|
-
this._onCellUpdate = onCellUpdate;
|
|
672
|
-
this._onRowOrderChange = onRowOrderChange;
|
|
673
|
-
this._onRowAction = onRowAction;
|
|
674
|
-
}
|
|
675
605
|
get id() {
|
|
676
606
|
return fullyQualifiedId(this._view);
|
|
677
607
|
}
|
|
@@ -681,7 +611,7 @@ var TableModel = class extends Resource2 {
|
|
|
681
611
|
get table() {
|
|
682
612
|
invariant(this._table, "Model not initialized", {
|
|
683
613
|
F: __dxlog_file,
|
|
684
|
-
L:
|
|
614
|
+
L: 187,
|
|
685
615
|
S: this,
|
|
686
616
|
A: [
|
|
687
617
|
"this._table",
|
|
@@ -720,7 +650,7 @@ var TableModel = class extends Resource2 {
|
|
|
720
650
|
get columnMeta() {
|
|
721
651
|
invariant(this._columnMeta, void 0, {
|
|
722
652
|
F: __dxlog_file,
|
|
723
|
-
L:
|
|
653
|
+
L: 226,
|
|
724
654
|
S: this,
|
|
725
655
|
A: [
|
|
726
656
|
"this._columnMeta",
|
|
@@ -744,12 +674,12 @@ var TableModel = class extends Resource2 {
|
|
|
744
674
|
//
|
|
745
675
|
async _open() {
|
|
746
676
|
const presentation = this._view.presentation.target ?? await this._view.presentation.load();
|
|
747
|
-
invariant(
|
|
677
|
+
invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
|
|
748
678
|
F: __dxlog_file,
|
|
749
|
-
L:
|
|
679
|
+
L: 249,
|
|
750
680
|
S: this,
|
|
751
681
|
A: [
|
|
752
|
-
"Obj.instanceOf(
|
|
682
|
+
"Obj.instanceOf(Table.Table, presentation)",
|
|
753
683
|
""
|
|
754
684
|
]
|
|
755
685
|
});
|
|
@@ -778,7 +708,7 @@ var TableModel = class extends Resource2 {
|
|
|
778
708
|
},
|
|
779
709
|
frozenColsEnd: {
|
|
780
710
|
0: {
|
|
781
|
-
size:
|
|
711
|
+
size: 32,
|
|
782
712
|
resizeable: false
|
|
783
713
|
}
|
|
784
714
|
}
|
|
@@ -814,17 +744,6 @@ var TableModel = class extends Resource2 {
|
|
|
814
744
|
});
|
|
815
745
|
this._ctx.onDispose(draftRowsWatcher);
|
|
816
746
|
}
|
|
817
|
-
//
|
|
818
|
-
// Data
|
|
819
|
-
//
|
|
820
|
-
setRows = (obj) => {
|
|
821
|
-
this._rows.value = obj;
|
|
822
|
-
};
|
|
823
|
-
getRowCount = () => this._rows.value.length;
|
|
824
|
-
/**
|
|
825
|
-
* @reactive
|
|
826
|
-
*/
|
|
827
|
-
getDraftRowCount = () => this._draftRows.value.length;
|
|
828
747
|
// TODO(ZaymonFC): Return .value instead of exposing the signal.
|
|
829
748
|
get draftRows() {
|
|
830
749
|
return this._draftRows;
|
|
@@ -843,13 +762,6 @@ var TableModel = class extends Resource2 {
|
|
|
843
762
|
const validationErrors = draftRow.validationErrors || [];
|
|
844
763
|
return validationErrors.some((error) => error.path === fieldPath);
|
|
845
764
|
}
|
|
846
|
-
getColumnCount = () => this._projection?.fields.length ?? 0;
|
|
847
|
-
insertRow = () => {
|
|
848
|
-
const result = this._onInsertRow?.();
|
|
849
|
-
if (result === false && this._draftRows.value.length === 0) {
|
|
850
|
-
this.createDraftRow();
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
765
|
createDraftRow() {
|
|
854
766
|
if (!this._projection) {
|
|
855
767
|
return;
|
|
@@ -886,190 +798,9 @@ var TableModel = class extends Resource2 {
|
|
|
886
798
|
this._draftRows.value = newDraftRows;
|
|
887
799
|
}
|
|
888
800
|
validateDraftRowData(data) {
|
|
889
|
-
const schema =
|
|
801
|
+
const schema = toEffectSchema(this._projection.baseSchema);
|
|
890
802
|
return validateSchema(schema, data) || [];
|
|
891
803
|
}
|
|
892
|
-
commitDraftRow = (draftRowIndex) => {
|
|
893
|
-
if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
|
|
894
|
-
return false;
|
|
895
|
-
}
|
|
896
|
-
const draftRow = this._draftRows.value[draftRowIndex];
|
|
897
|
-
if (!draftRow.valid) {
|
|
898
|
-
return false;
|
|
899
|
-
}
|
|
900
|
-
const success = this._onInsertRow?.(draftRow.data);
|
|
901
|
-
if (success) {
|
|
902
|
-
const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
|
|
903
|
-
this._draftRows.value = newDraftRows;
|
|
904
|
-
}
|
|
905
|
-
return success ?? false;
|
|
906
|
-
};
|
|
907
|
-
deleteRow = (rowIndex) => {
|
|
908
|
-
const row = this._sorting.getDataIndex(rowIndex);
|
|
909
|
-
const obj = this._rows.value[row];
|
|
910
|
-
const objectsToDelete = [];
|
|
911
|
-
if (this.features.selection.enabled && this._selection.hasSelection.value) {
|
|
912
|
-
const selectedRows = this._selection.getSelectedRows();
|
|
913
|
-
objectsToDelete.push(...selectedRows);
|
|
914
|
-
} else {
|
|
915
|
-
objectsToDelete.push(obj);
|
|
916
|
-
}
|
|
917
|
-
this._onDeleteRows?.(row, objectsToDelete);
|
|
918
|
-
};
|
|
919
|
-
handleRowAction = (actionId, rowIndex) => {
|
|
920
|
-
if (!this._onRowAction) {
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
const row = this._sorting.getDataIndex(rowIndex);
|
|
924
|
-
const data = this._rows.value[row];
|
|
925
|
-
if (data) {
|
|
926
|
-
this._onRowAction(actionId, data);
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
getCellData = (cell) => {
|
|
930
|
-
const { col, row, plane } = cell;
|
|
931
|
-
const fields = this._projection?.fields ?? [];
|
|
932
|
-
if (col < 0 || col >= fields.length) {
|
|
933
|
-
return void 0;
|
|
934
|
-
}
|
|
935
|
-
const field = fields[col];
|
|
936
|
-
let value;
|
|
937
|
-
if (plane === "frozenRowsEnd") {
|
|
938
|
-
if (row >= 0 && row < this._draftRows.value.length) {
|
|
939
|
-
value = getValue2(this._draftRows.value[row].data, field.path);
|
|
940
|
-
} else {
|
|
941
|
-
return void 0;
|
|
942
|
-
}
|
|
943
|
-
} else {
|
|
944
|
-
const dataIndex = this._sorting.getDataIndex(row);
|
|
945
|
-
value = getValue2(this._rows.value[dataIndex], field.path);
|
|
946
|
-
}
|
|
947
|
-
if (value == null) {
|
|
948
|
-
return "";
|
|
949
|
-
}
|
|
950
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
951
|
-
switch (props.format) {
|
|
952
|
-
case FormatEnum2.Ref: {
|
|
953
|
-
if (!field.referencePath) {
|
|
954
|
-
return "";
|
|
955
|
-
}
|
|
956
|
-
return getValue2(value.target, field.referencePath);
|
|
957
|
-
}
|
|
958
|
-
default: {
|
|
959
|
-
return formatForEditing({
|
|
960
|
-
type: props.type,
|
|
961
|
-
format: props.format,
|
|
962
|
-
value
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
};
|
|
967
|
-
validateCellData = async ({ col, row, plane }, value) => {
|
|
968
|
-
const fields = this._projection?.fields ?? [];
|
|
969
|
-
if (col < 0 || col >= fields.length) {
|
|
970
|
-
return {
|
|
971
|
-
valid: false,
|
|
972
|
-
error: "Invalid column index"
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
const field = fields[col];
|
|
976
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
977
|
-
const transformedValue = editorTextToCellValue(props, value);
|
|
978
|
-
const isDraftRow = plane === "frozenRowsEnd";
|
|
979
|
-
if (isDraftRow) {
|
|
980
|
-
const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
|
|
981
|
-
if (isInvalidDraftRowIndex) {
|
|
982
|
-
return {
|
|
983
|
-
valid: false,
|
|
984
|
-
error: "Invalid draft row index"
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
const draftRow = this._draftRows.value[row];
|
|
988
|
-
const snapshot = {
|
|
989
|
-
...draftRow.data
|
|
990
|
-
};
|
|
991
|
-
setValue(snapshot, field.path, transformedValue);
|
|
992
|
-
const validationErrors = this.validateDraftRowData(snapshot);
|
|
993
|
-
if (validationErrors.length > 0) {
|
|
994
|
-
const error = validationErrors.find((err) => err.path === field.path);
|
|
995
|
-
if (error) {
|
|
996
|
-
return {
|
|
997
|
-
valid: false,
|
|
998
|
-
error: error.message
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
return {
|
|
1003
|
-
valid: true
|
|
1004
|
-
};
|
|
1005
|
-
} else {
|
|
1006
|
-
const rowIdx = this._sorting.getDataIndex(row);
|
|
1007
|
-
const currentRow = this._rows.value[rowIdx];
|
|
1008
|
-
invariant(currentRow, "Invalid row index", {
|
|
1009
|
-
F: __dxlog_file,
|
|
1010
|
-
L: 513,
|
|
1011
|
-
S: this,
|
|
1012
|
-
A: [
|
|
1013
|
-
"currentRow",
|
|
1014
|
-
"'Invalid row index'"
|
|
1015
|
-
]
|
|
1016
|
-
});
|
|
1017
|
-
const snapshot = getSnapshot(currentRow);
|
|
1018
|
-
setValue(snapshot, field.path, transformedValue);
|
|
1019
|
-
const schema = getSchema(currentRow);
|
|
1020
|
-
invariant(schema, void 0, {
|
|
1021
|
-
F: __dxlog_file,
|
|
1022
|
-
L: 519,
|
|
1023
|
-
S: this,
|
|
1024
|
-
A: [
|
|
1025
|
-
"schema",
|
|
1026
|
-
""
|
|
1027
|
-
]
|
|
1028
|
-
});
|
|
1029
|
-
const validationResult = validateSchema(schema, snapshot);
|
|
1030
|
-
if (validationResult && validationResult.length > 0) {
|
|
1031
|
-
const error = validationResult[0];
|
|
1032
|
-
invariant(error.path === field.path, void 0, {
|
|
1033
|
-
F: __dxlog_file,
|
|
1034
|
-
L: 524,
|
|
1035
|
-
S: this,
|
|
1036
|
-
A: [
|
|
1037
|
-
"error.path === field.path",
|
|
1038
|
-
""
|
|
1039
|
-
]
|
|
1040
|
-
});
|
|
1041
|
-
return {
|
|
1042
|
-
valid: false,
|
|
1043
|
-
error: error.message
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
return {
|
|
1047
|
-
valid: true
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
setCellData = (cell, value) => {
|
|
1052
|
-
const { col, row, plane } = cell;
|
|
1053
|
-
const fields = this._projection?.fields ?? [];
|
|
1054
|
-
if (col < 0 || col >= fields.length) {
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
const field = fields[col];
|
|
1058
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
1059
|
-
const transformedValue = editorTextToCellValue(props, value);
|
|
1060
|
-
if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
if (plane === "frozenRowsEnd") {
|
|
1064
|
-
if (row >= 0 && row < this._draftRows.value.length) {
|
|
1065
|
-
setValue(this._draftRows.value[row].data, field.path, transformedValue);
|
|
1066
|
-
this.validateDraftRow(row);
|
|
1067
|
-
}
|
|
1068
|
-
} else {
|
|
1069
|
-
const rowIdx = this._sorting.getDataIndex(row);
|
|
1070
|
-
setValue(this._rows.value[rowIdx], field.path, transformedValue);
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
804
|
/**
|
|
1074
805
|
* Updates a cell's value using a transform function.
|
|
1075
806
|
* @param {DxGridPlanePosition} position - The position of the cell to update.
|
|
@@ -1150,6 +881,240 @@ var TableModel = class extends Resource2 {
|
|
|
1150
881
|
saveView() {
|
|
1151
882
|
this._sorting.save();
|
|
1152
883
|
}
|
|
884
|
+
constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
885
|
+
top: [],
|
|
886
|
+
bottom: []
|
|
887
|
+
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
888
|
+
super(), _define_property3(this, "_view", void 0), _define_property3(this, "_projection", void 0), _define_property3(this, "_table", void 0), _define_property3(this, "_visibleRange", signal3({
|
|
889
|
+
start: {
|
|
890
|
+
row: 0,
|
|
891
|
+
col: 0
|
|
892
|
+
},
|
|
893
|
+
end: {
|
|
894
|
+
row: 0,
|
|
895
|
+
col: 0
|
|
896
|
+
}
|
|
897
|
+
})), _define_property3(this, "_onInsertRow", void 0), _define_property3(this, "_onDeleteRows", void 0), _define_property3(this, "_onDeleteColumn", void 0), _define_property3(this, "_onCellUpdate", void 0), _define_property3(this, "_onRowOrderChange", void 0), _define_property3(this, "_onRowAction", void 0), _define_property3(this, "_rowActions", void 0), _define_property3(this, "_features", void 0), _define_property3(this, "_rows", signal3([])), _define_property3(this, "_draftRows", signal3([])), _define_property3(this, "_sorting", void 0), _define_property3(this, "_pinnedRows", void 0), _define_property3(this, "_selection", void 0), _define_property3(this, "_columnMeta", void 0), //
|
|
898
|
+
// Data
|
|
899
|
+
//
|
|
900
|
+
_define_property3(this, "setRows", (obj) => {
|
|
901
|
+
this._rows.value = obj;
|
|
902
|
+
}), _define_property3(this, "getRowCount", () => this._rows.value.length), /**
|
|
903
|
+
* @reactive
|
|
904
|
+
*/
|
|
905
|
+
_define_property3(this, "getDraftRowCount", () => this._draftRows.value.length), _define_property3(this, "getColumnCount", () => this._projection?.fields.length ?? 0), _define_property3(this, "insertRow", () => {
|
|
906
|
+
const result = this._onInsertRow?.();
|
|
907
|
+
if (result === "draft" && this._draftRows.value.length === 0) {
|
|
908
|
+
this.createDraftRow();
|
|
909
|
+
}
|
|
910
|
+
return result ?? "final";
|
|
911
|
+
}), _define_property3(this, "commitDraftRow", (draftRowIndex) => {
|
|
912
|
+
if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
const draftRow = this._draftRows.value[draftRowIndex];
|
|
916
|
+
if (!draftRow.valid) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
const insertRowResult = this._onInsertRow?.(draftRow.data);
|
|
920
|
+
if (insertRowResult === "final") {
|
|
921
|
+
const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
|
|
922
|
+
this._draftRows.value = newDraftRows;
|
|
923
|
+
}
|
|
924
|
+
return insertRowResult === "final";
|
|
925
|
+
}), _define_property3(this, "deleteRow", (rowIndex) => {
|
|
926
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
927
|
+
const obj = this._rows.value[row];
|
|
928
|
+
const objectsToDelete = [];
|
|
929
|
+
if (this.features.selection.enabled && this._selection.hasSelection.value) {
|
|
930
|
+
const selectedRows = this._selection.getSelectedRows();
|
|
931
|
+
objectsToDelete.push(...selectedRows);
|
|
932
|
+
} else {
|
|
933
|
+
objectsToDelete.push(obj);
|
|
934
|
+
}
|
|
935
|
+
this._onDeleteRows?.(row, objectsToDelete);
|
|
936
|
+
}), _define_property3(this, "handleRowAction", (actionId, rowIndex) => {
|
|
937
|
+
if (!this._onRowAction) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
941
|
+
const data = this._rows.value[row];
|
|
942
|
+
if (data) {
|
|
943
|
+
this._onRowAction(actionId, data);
|
|
944
|
+
}
|
|
945
|
+
}), _define_property3(this, "getCellData", (cell) => {
|
|
946
|
+
const { col, row, plane } = cell;
|
|
947
|
+
const fields = this._projection?.fields ?? [];
|
|
948
|
+
if (col < 0 || col >= fields.length) {
|
|
949
|
+
return void 0;
|
|
950
|
+
}
|
|
951
|
+
const field = fields[col];
|
|
952
|
+
let value;
|
|
953
|
+
if (plane === "frozenRowsEnd") {
|
|
954
|
+
if (row >= 0 && row < this._draftRows.value.length) {
|
|
955
|
+
value = getValue2(this._draftRows.value[row].data, field.path);
|
|
956
|
+
} else {
|
|
957
|
+
return void 0;
|
|
958
|
+
}
|
|
959
|
+
} else {
|
|
960
|
+
const dataIndex = this._sorting.getDataIndex(row);
|
|
961
|
+
value = getValue2(this._rows.value[dataIndex], field.path);
|
|
962
|
+
}
|
|
963
|
+
if (value == null) {
|
|
964
|
+
return "";
|
|
965
|
+
}
|
|
966
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
967
|
+
switch (props.format) {
|
|
968
|
+
case FormatEnum2.Ref: {
|
|
969
|
+
if (!field.referencePath) {
|
|
970
|
+
return "";
|
|
971
|
+
}
|
|
972
|
+
return getValue2(value.target, field.referencePath);
|
|
973
|
+
}
|
|
974
|
+
default: {
|
|
975
|
+
return formatForEditing({
|
|
976
|
+
type: props.type,
|
|
977
|
+
format: props.format,
|
|
978
|
+
value
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}), _define_property3(this, "validateCellData", async ({ col, row, plane }, value) => {
|
|
983
|
+
const fields = this._projection?.fields ?? [];
|
|
984
|
+
if (col < 0 || col >= fields.length) {
|
|
985
|
+
return {
|
|
986
|
+
valid: false,
|
|
987
|
+
error: "Invalid column index"
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
const field = fields[col];
|
|
991
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
992
|
+
const transformedValue = editorTextToCellValue(props, value);
|
|
993
|
+
const isDraftRow = plane === "frozenRowsEnd";
|
|
994
|
+
if (isDraftRow) {
|
|
995
|
+
const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
|
|
996
|
+
if (isInvalidDraftRowIndex) {
|
|
997
|
+
return {
|
|
998
|
+
valid: false,
|
|
999
|
+
error: "Invalid draft row index"
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
const draftRow = this._draftRows.value[row];
|
|
1003
|
+
const snapshot = {
|
|
1004
|
+
...draftRow.data
|
|
1005
|
+
};
|
|
1006
|
+
setValue(snapshot, field.path, transformedValue);
|
|
1007
|
+
const validationErrors = this.validateDraftRowData(snapshot);
|
|
1008
|
+
if (validationErrors.length > 0) {
|
|
1009
|
+
const error = validationErrors.find((err) => err.path === field.path);
|
|
1010
|
+
if (error) {
|
|
1011
|
+
return {
|
|
1012
|
+
valid: false,
|
|
1013
|
+
error: error.message
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return {
|
|
1018
|
+
valid: true
|
|
1019
|
+
};
|
|
1020
|
+
} else {
|
|
1021
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
1022
|
+
const currentRow = this._rows.value[rowIdx];
|
|
1023
|
+
invariant(currentRow, "Invalid row index", {
|
|
1024
|
+
F: __dxlog_file,
|
|
1025
|
+
L: 522,
|
|
1026
|
+
S: this,
|
|
1027
|
+
A: [
|
|
1028
|
+
"currentRow",
|
|
1029
|
+
"'Invalid row index'"
|
|
1030
|
+
]
|
|
1031
|
+
});
|
|
1032
|
+
const snapshot = getSnapshot(currentRow);
|
|
1033
|
+
setValue(snapshot, field.path, transformedValue);
|
|
1034
|
+
const schema2 = getSchema(currentRow);
|
|
1035
|
+
invariant(schema2, void 0, {
|
|
1036
|
+
F: __dxlog_file,
|
|
1037
|
+
L: 528,
|
|
1038
|
+
S: this,
|
|
1039
|
+
A: [
|
|
1040
|
+
"schema",
|
|
1041
|
+
""
|
|
1042
|
+
]
|
|
1043
|
+
});
|
|
1044
|
+
const validationResult = validateSchema(schema2, snapshot);
|
|
1045
|
+
if (validationResult && validationResult.length > 0) {
|
|
1046
|
+
const error = validationResult[0];
|
|
1047
|
+
invariant(error.path === field.path, void 0, {
|
|
1048
|
+
F: __dxlog_file,
|
|
1049
|
+
L: 533,
|
|
1050
|
+
S: this,
|
|
1051
|
+
A: [
|
|
1052
|
+
"error.path === field.path",
|
|
1053
|
+
""
|
|
1054
|
+
]
|
|
1055
|
+
});
|
|
1056
|
+
return {
|
|
1057
|
+
valid: false,
|
|
1058
|
+
error: error.message
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
valid: true
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
}), _define_property3(this, "setCellData", (cell, value) => {
|
|
1066
|
+
const { col, row, plane } = cell;
|
|
1067
|
+
const fields = this._projection?.fields ?? [];
|
|
1068
|
+
if (col < 0 || col >= fields.length) {
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
const field = fields[col];
|
|
1072
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
1073
|
+
const transformedValue = editorTextToCellValue(props, value);
|
|
1074
|
+
if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if (plane === "frozenRowsEnd") {
|
|
1078
|
+
if (row >= 0 && row < this._draftRows.value.length) {
|
|
1079
|
+
setValue(this._draftRows.value[row].data, field.path, transformedValue);
|
|
1080
|
+
this.validateDraftRow(row);
|
|
1081
|
+
}
|
|
1082
|
+
} else {
|
|
1083
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
1084
|
+
setValue(this._rows.value[rowIdx], field.path, transformedValue);
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
this._view = view;
|
|
1088
|
+
this._projection = projection ?? new ProjectionModel2(schema, view.projection);
|
|
1089
|
+
this._projection.normalizeView();
|
|
1090
|
+
this._features = {
|
|
1091
|
+
...defaultFeatures,
|
|
1092
|
+
...features
|
|
1093
|
+
};
|
|
1094
|
+
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
1095
|
+
F: __dxlog_file,
|
|
1096
|
+
L: 149,
|
|
1097
|
+
S: this,
|
|
1098
|
+
A: [
|
|
1099
|
+
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
1100
|
+
"'Single selection is not compatible with editable tables.'"
|
|
1101
|
+
]
|
|
1102
|
+
});
|
|
1103
|
+
this._sorting = new TableSorting(this._rows, this._view, this._projection);
|
|
1104
|
+
if (sorting.length > 0) {
|
|
1105
|
+
const [sort] = sorting;
|
|
1106
|
+
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
1107
|
+
}
|
|
1108
|
+
this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
|
|
1109
|
+
this._pinnedRows = pinnedRows;
|
|
1110
|
+
this._rowActions = rowActions;
|
|
1111
|
+
this._onInsertRow = onInsertRow;
|
|
1112
|
+
this._onDeleteRows = onDeleteRows;
|
|
1113
|
+
this._onDeleteColumn = onDeleteColumn;
|
|
1114
|
+
this._onCellUpdate = onCellUpdate;
|
|
1115
|
+
this._onRowOrderChange = onRowOrderChange;
|
|
1116
|
+
this._onRowAction = onRowAction;
|
|
1117
|
+
}
|
|
1153
1118
|
};
|
|
1154
1119
|
var editorTextToCellValue = (props, value) => {
|
|
1155
1120
|
switch (props.format) {
|
|
@@ -1184,117 +1149,108 @@ var editorTextToCellValue = (props, value) => {
|
|
|
1184
1149
|
|
|
1185
1150
|
// src/model/modal-controller.ts
|
|
1186
1151
|
import { signal as signal4 } from "@preact/signals-core";
|
|
1187
|
-
|
|
1188
|
-
|
|
1152
|
+
function _define_property4(obj, key, value) {
|
|
1153
|
+
if (key in obj) {
|
|
1154
|
+
Object.defineProperty(obj, key, {
|
|
1155
|
+
value,
|
|
1156
|
+
enumerable: true,
|
|
1157
|
+
configurable: true,
|
|
1158
|
+
writable: true
|
|
1159
|
+
});
|
|
1160
|
+
} else {
|
|
1161
|
+
obj[key] = value;
|
|
1162
|
+
}
|
|
1163
|
+
return obj;
|
|
1164
|
+
}
|
|
1189
1165
|
var ModalController = class {
|
|
1190
|
-
_state = signal4({
|
|
1191
|
-
type: "closed"
|
|
1192
|
-
});
|
|
1193
|
-
_triggerRef = {
|
|
1194
|
-
current: null
|
|
1195
|
-
};
|
|
1196
1166
|
get state() {
|
|
1197
1167
|
return this._state;
|
|
1198
1168
|
}
|
|
1199
1169
|
get trigger() {
|
|
1200
1170
|
return this._triggerRef;
|
|
1201
1171
|
}
|
|
1202
|
-
|
|
1203
|
-
this
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
this
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
this
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
this
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1172
|
+
constructor() {
|
|
1173
|
+
_define_property4(this, "_state", signal4({
|
|
1174
|
+
type: "closed"
|
|
1175
|
+
}));
|
|
1176
|
+
_define_property4(this, "_triggerRef", {
|
|
1177
|
+
current: null
|
|
1178
|
+
});
|
|
1179
|
+
_define_property4(this, "setTrigger", (trigger) => {
|
|
1180
|
+
this._triggerRef.current = trigger;
|
|
1181
|
+
});
|
|
1182
|
+
_define_property4(this, "showRowMenu", (rowIndex) => {
|
|
1183
|
+
this._state.value = {
|
|
1184
|
+
type: "row",
|
|
1185
|
+
rowIndex
|
|
1186
|
+
};
|
|
1187
|
+
});
|
|
1188
|
+
_define_property4(this, "showColumnMenu", (fieldId) => {
|
|
1189
|
+
this._state.value = {
|
|
1190
|
+
type: "column",
|
|
1191
|
+
fieldId
|
|
1192
|
+
};
|
|
1193
|
+
});
|
|
1194
|
+
_define_property4(this, "showColumnCreator", () => {
|
|
1195
|
+
this._state.value = {
|
|
1196
|
+
type: "columnSettings",
|
|
1197
|
+
mode: {
|
|
1198
|
+
type: "create"
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
});
|
|
1202
|
+
_define_property4(this, "showReferencePanel", (targetId, schemaId) => {
|
|
1203
|
+
this._state.value = {
|
|
1204
|
+
type: "refPanel",
|
|
1205
|
+
targetId,
|
|
1206
|
+
typename: schemaId
|
|
1207
|
+
};
|
|
1208
|
+
});
|
|
1209
|
+
_define_property4(this, "openColumnSettings", () => {
|
|
1210
|
+
if (this._state.value.type === "column") {
|
|
1211
|
+
const fieldId = this._state.value.fieldId;
|
|
1212
|
+
requestAnimationFrame(() => {
|
|
1213
|
+
this._state.value = {
|
|
1214
|
+
type: "columnSettings",
|
|
1215
|
+
mode: {
|
|
1216
|
+
type: "edit",
|
|
1217
|
+
fieldId
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
});
|
|
1222
1221
|
}
|
|
1223
|
-
};
|
|
1224
|
-
|
|
1225
|
-
showReferencePanel = (targetId, schemaId) => {
|
|
1226
|
-
this._state.value = {
|
|
1227
|
-
type: "refPanel",
|
|
1228
|
-
targetId,
|
|
1229
|
-
typename: schemaId
|
|
1230
|
-
};
|
|
1231
|
-
};
|
|
1232
|
-
openColumnSettings = () => {
|
|
1233
|
-
if (this._state.value.type === "column") {
|
|
1234
|
-
const fieldId = this._state.value.fieldId;
|
|
1235
|
-
requestAnimationFrame(() => {
|
|
1236
|
-
this._state.value = {
|
|
1237
|
-
type: "columnSettings",
|
|
1238
|
-
mode: {
|
|
1239
|
-
type: "edit",
|
|
1240
|
-
fieldId
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
};
|
|
1246
|
-
openCreateRef = (typename, anchorCell, initialValues, onCreate) => {
|
|
1247
|
-
if (anchorCell) {
|
|
1248
|
-
this._triggerRef.current = anchorCell;
|
|
1222
|
+
});
|
|
1223
|
+
_define_property4(this, "close", () => {
|
|
1249
1224
|
this._state.value = {
|
|
1250
|
-
type: "
|
|
1251
|
-
typename,
|
|
1252
|
-
initialValues,
|
|
1253
|
-
onCreate
|
|
1225
|
+
type: "closed"
|
|
1254
1226
|
};
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
F: __dxlog_file2,
|
|
1258
|
-
L: 86,
|
|
1259
|
-
S: this,
|
|
1260
|
-
C: (f, a) => f(...a)
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
close = () => {
|
|
1265
|
-
this._state.value = {
|
|
1266
|
-
type: "closed"
|
|
1267
|
-
};
|
|
1268
|
-
};
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1269
1229
|
};
|
|
1270
1230
|
|
|
1271
1231
|
// src/model/table-presentation.ts
|
|
1272
1232
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1273
|
-
import
|
|
1274
|
-
import { Obj as
|
|
1275
|
-
import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo
|
|
1233
|
+
import * as Predicate from "effect/Predicate";
|
|
1234
|
+
import { Obj as Obj3 } from "@dxos/echo";
|
|
1235
|
+
import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
|
|
1276
1236
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1277
1237
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1278
1238
|
import { mx } from "@dxos/react-ui-theme";
|
|
1279
1239
|
import { VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
row: 0,
|
|
1291
|
-
col: 0
|
|
1292
|
-
}
|
|
1293
|
-
})) {
|
|
1294
|
-
this.model = model;
|
|
1295
|
-
this._visibleRange = _visibleRange;
|
|
1296
|
-
this.fieldProjectionCache = /* @__PURE__ */ new Map();
|
|
1240
|
+
function _define_property5(obj, key, value) {
|
|
1241
|
+
if (key in obj) {
|
|
1242
|
+
Object.defineProperty(obj, key, {
|
|
1243
|
+
value,
|
|
1244
|
+
enumerable: true,
|
|
1245
|
+
configurable: true,
|
|
1246
|
+
writable: true
|
|
1247
|
+
});
|
|
1248
|
+
} else {
|
|
1249
|
+
obj[key] = value;
|
|
1297
1250
|
}
|
|
1251
|
+
return obj;
|
|
1252
|
+
}
|
|
1253
|
+
var TablePresentation = class {
|
|
1298
1254
|
getCells(range, plane) {
|
|
1299
1255
|
this.fieldProjectionCache.clear();
|
|
1300
1256
|
let cells;
|
|
@@ -1322,7 +1278,7 @@ var TablePresentation = class {
|
|
|
1322
1278
|
cells = this.getDraftRowCells(range);
|
|
1323
1279
|
break;
|
|
1324
1280
|
case "fixedEndStart":
|
|
1325
|
-
cells = this.
|
|
1281
|
+
cells = this.getDraftIconCells(range);
|
|
1326
1282
|
break;
|
|
1327
1283
|
case "fixedEndEnd":
|
|
1328
1284
|
cells = this.getDraftActionCells(range);
|
|
@@ -1382,10 +1338,7 @@ var TablePresentation = class {
|
|
|
1382
1338
|
}
|
|
1383
1339
|
};
|
|
1384
1340
|
const classes = [];
|
|
1385
|
-
const formatClasses = cellClassesForFieldType(
|
|
1386
|
-
type: props.type,
|
|
1387
|
-
format: props.format
|
|
1388
|
-
});
|
|
1341
|
+
const formatClasses = cellClassesForFieldType(props);
|
|
1389
1342
|
if (formatClasses) {
|
|
1390
1343
|
classes.push(formatClasses);
|
|
1391
1344
|
}
|
|
@@ -1393,9 +1346,7 @@ var TablePresentation = class {
|
|
|
1393
1346
|
if (rowSelectionClasses) {
|
|
1394
1347
|
classes.push(rowSelectionClasses);
|
|
1395
1348
|
}
|
|
1396
|
-
|
|
1397
|
-
cell.className = mx(classes.flat());
|
|
1398
|
-
}
|
|
1349
|
+
cell.className = mx(classes);
|
|
1399
1350
|
if (props.type === TypeEnum2.Array) {
|
|
1400
1351
|
const targetArray = getValue3(obj, field.path);
|
|
1401
1352
|
if (targetArray && Array.isArray(targetArray)) {
|
|
@@ -1417,7 +1368,7 @@ var TablePresentation = class {
|
|
|
1417
1368
|
}
|
|
1418
1369
|
return "Object";
|
|
1419
1370
|
};
|
|
1420
|
-
const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
|
|
1371
|
+
const tags = targetArray.map(getLabel).filter(Predicate.isNotNullable).map((title) => {
|
|
1421
1372
|
return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
|
|
1422
1373
|
}).join("");
|
|
1423
1374
|
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
@@ -1426,8 +1377,8 @@ var TablePresentation = class {
|
|
|
1426
1377
|
if (props.format === FormatEnum3.Ref && props.referenceSchema) {
|
|
1427
1378
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1428
1379
|
if (targetObj) {
|
|
1429
|
-
const dxn =
|
|
1430
|
-
cell.accessoryHtml = `<dx-
|
|
1380
|
+
const dxn = Obj3.getDXN(targetObj)?.toString();
|
|
1381
|
+
cell.accessoryHtml = `<div role="none" class="absolute inline-end-0 inset-block-0 p-[--dx-grid-cell-content-padding-block]"><dx-anchor refId=${dxn} class="dx-button is-6 aspect-square min-bs-0" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-anchor></div>`;
|
|
1431
1382
|
}
|
|
1432
1383
|
}
|
|
1433
1384
|
if (props.format === FormatEnum3.Boolean) {
|
|
@@ -1489,27 +1440,39 @@ var TablePresentation = class {
|
|
|
1489
1440
|
const cells = {};
|
|
1490
1441
|
const fields = this.model.projection?.fields ?? [];
|
|
1491
1442
|
const draftRows = this.model.draftRows.value;
|
|
1492
|
-
|
|
1493
|
-
const draftRow = draftRows[row];
|
|
1443
|
+
if (draftRows.length === 0) {
|
|
1494
1444
|
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
1495
|
-
|
|
1445
|
+
cells[toPlaneCellIndex({
|
|
1496
1446
|
col,
|
|
1497
|
-
row
|
|
1498
|
-
})
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1447
|
+
row: 0
|
|
1448
|
+
})] = {
|
|
1449
|
+
value: "",
|
|
1450
|
+
readonly: true,
|
|
1451
|
+
className: "dx-grid__row--cta__cell"
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
} else {
|
|
1455
|
+
for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
|
|
1456
|
+
const draftRow = draftRows[row];
|
|
1457
|
+
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
1458
|
+
const cellIndex = toPlaneCellIndex({
|
|
1459
|
+
col,
|
|
1460
|
+
row
|
|
1461
|
+
});
|
|
1462
|
+
const field = fields[col];
|
|
1463
|
+
if (!field) {
|
|
1464
|
+
continue;
|
|
1465
|
+
}
|
|
1466
|
+
this.createDataCell(cells, draftRow.data, field, col, row);
|
|
1467
|
+
if (this.model.hasDraftRowValidationError(row, field.path)) {
|
|
1468
|
+
const cellValue = cells[cellIndex];
|
|
1469
|
+
if (cellValue) {
|
|
1470
|
+
const existingClasses = cellValue.className || "";
|
|
1471
|
+
const draftClasses = "dx-grid__cell--flagged";
|
|
1472
|
+
cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
|
|
1473
|
+
}
|
|
1510
1474
|
}
|
|
1511
1475
|
}
|
|
1512
|
-
cells[cellIndex].className += " !bg-toolbarSurface";
|
|
1513
1476
|
}
|
|
1514
1477
|
}
|
|
1515
1478
|
return cells;
|
|
@@ -1526,10 +1489,10 @@ var TablePresentation = class {
|
|
|
1526
1489
|
row: 0
|
|
1527
1490
|
})] = {
|
|
1528
1491
|
// TODO(burdon): Use same logic as form for fallback title.
|
|
1529
|
-
value:
|
|
1530
|
-
readonly: true,
|
|
1492
|
+
value: "",
|
|
1531
1493
|
resizeHandle: "col",
|
|
1532
1494
|
accessoryHtml: `
|
|
1495
|
+
<span class="grow min-is-0 truncate">${props.title ?? field.path}</span>
|
|
1533
1496
|
${direction !== void 0 ? tableButtons.sort.render({
|
|
1534
1497
|
fieldId: field.id,
|
|
1535
1498
|
direction
|
|
@@ -1538,7 +1501,7 @@ var TablePresentation = class {
|
|
|
1538
1501
|
fieldId: field.id
|
|
1539
1502
|
})}
|
|
1540
1503
|
`,
|
|
1541
|
-
className: "!bg-toolbarSurface"
|
|
1504
|
+
className: "!bg-toolbarSurface !text-description [&>div]:flex [&>div]:items-stretch"
|
|
1542
1505
|
};
|
|
1543
1506
|
}
|
|
1544
1507
|
return cells;
|
|
@@ -1629,39 +1592,67 @@ var TablePresentation = class {
|
|
|
1629
1592
|
getDraftActionCells(range) {
|
|
1630
1593
|
const cells = {};
|
|
1631
1594
|
const draftRows = this.model.draftRows.value;
|
|
1632
|
-
|
|
1633
|
-
const draftRow = draftRows[row];
|
|
1634
|
-
const disabled = !draftRow.valid;
|
|
1595
|
+
if (draftRows.length === 0) {
|
|
1635
1596
|
cells[toPlaneCellIndex({
|
|
1636
1597
|
col: 0,
|
|
1637
|
-
row
|
|
1598
|
+
row: 0
|
|
1638
1599
|
})] = {
|
|
1639
1600
|
value: "",
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
rowIndex: row,
|
|
1643
|
-
disabled
|
|
1644
|
-
}),
|
|
1645
|
-
className: "!bg-toolbarSurface"
|
|
1601
|
+
className: "dx-grid__row--cta__cell",
|
|
1602
|
+
readonly: true
|
|
1646
1603
|
};
|
|
1604
|
+
} else {
|
|
1605
|
+
for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
|
|
1606
|
+
const draftRow = draftRows[row];
|
|
1607
|
+
const disabled = !draftRow.valid;
|
|
1608
|
+
cells[toPlaneCellIndex({
|
|
1609
|
+
col: 0,
|
|
1610
|
+
row
|
|
1611
|
+
})] = {
|
|
1612
|
+
value: "",
|
|
1613
|
+
readonly: true,
|
|
1614
|
+
accessoryHtml: tableButtons.saveDraftRow.render({
|
|
1615
|
+
rowIndex: row,
|
|
1616
|
+
disabled
|
|
1617
|
+
})
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1647
1620
|
}
|
|
1648
1621
|
return cells;
|
|
1649
1622
|
}
|
|
1650
|
-
|
|
1623
|
+
getDraftIconCells(range) {
|
|
1651
1624
|
const cells = {};
|
|
1652
1625
|
const draftRows = this.model.draftRows.value;
|
|
1653
|
-
for (let row = range.start.row; row <= range.end.row
|
|
1626
|
+
for (let row = range.start.row; row <= range.end.row; row++) {
|
|
1654
1627
|
cells[toPlaneCellIndex({
|
|
1655
1628
|
col: 0,
|
|
1656
1629
|
row
|
|
1657
1630
|
})] = {
|
|
1658
1631
|
value: "",
|
|
1659
1632
|
readonly: true,
|
|
1660
|
-
|
|
1633
|
+
accessoryHtml: '<dx-icon icon="ph--plus--regular" class="contents"></dx-icon>',
|
|
1634
|
+
className: mx("[&>div]:grid [&>div]:place-content-center", draftRows.length < 1 && "dx-grid__row--cta__cell")
|
|
1661
1635
|
};
|
|
1662
1636
|
}
|
|
1663
1637
|
return cells;
|
|
1664
1638
|
}
|
|
1639
|
+
constructor(model, _visibleRange = signal5({
|
|
1640
|
+
start: {
|
|
1641
|
+
row: 0,
|
|
1642
|
+
col: 0
|
|
1643
|
+
},
|
|
1644
|
+
end: {
|
|
1645
|
+
row: 0,
|
|
1646
|
+
col: 0
|
|
1647
|
+
}
|
|
1648
|
+
})) {
|
|
1649
|
+
_define_property5(this, "model", void 0);
|
|
1650
|
+
_define_property5(this, "_visibleRange", void 0);
|
|
1651
|
+
_define_property5(this, "fieldProjectionCache", void 0);
|
|
1652
|
+
this.model = model;
|
|
1653
|
+
this._visibleRange = _visibleRange;
|
|
1654
|
+
this.fieldProjectionCache = /* @__PURE__ */ new Map();
|
|
1655
|
+
}
|
|
1665
1656
|
};
|
|
1666
1657
|
var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
1667
1658
|
if (!selected) {
|
|
@@ -1775,18 +1766,18 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
|
|
|
1775
1766
|
|
|
1776
1767
|
// src/hooks/useAddRow.ts
|
|
1777
1768
|
import { useCallback } from "react";
|
|
1778
|
-
import { Obj as
|
|
1769
|
+
import { Obj as Obj4 } from "@dxos/echo";
|
|
1779
1770
|
var useAddRow = ({ space, schema }) => {
|
|
1780
1771
|
return useCallback((data) => {
|
|
1781
1772
|
if (space && schema) {
|
|
1782
1773
|
try {
|
|
1783
|
-
space.db.add(
|
|
1784
|
-
return
|
|
1774
|
+
space.db.add(Obj4.make(schema, data ?? {}));
|
|
1775
|
+
return "final";
|
|
1785
1776
|
} catch (error) {
|
|
1786
|
-
return
|
|
1777
|
+
return "draft";
|
|
1787
1778
|
}
|
|
1788
1779
|
}
|
|
1789
|
-
return
|
|
1780
|
+
return "final";
|
|
1790
1781
|
}, [
|
|
1791
1782
|
space,
|
|
1792
1783
|
schema
|
|
@@ -1797,7 +1788,6 @@ export {
|
|
|
1797
1788
|
getBaseSchema,
|
|
1798
1789
|
makeDynamicTable,
|
|
1799
1790
|
touch,
|
|
1800
|
-
createTable,
|
|
1801
1791
|
BUTTON_IDENTIFIERS,
|
|
1802
1792
|
tableButtons,
|
|
1803
1793
|
CONTROL_IDENTIFIERS,
|
|
@@ -1812,4 +1802,4 @@ export {
|
|
|
1812
1802
|
useTableModel,
|
|
1813
1803
|
useAddRow
|
|
1814
1804
|
};
|
|
1815
|
-
//# sourceMappingURL=chunk-
|
|
1805
|
+
//# sourceMappingURL=chunk-S56Z4V4X.mjs.map
|