@dxos/react-ui-table 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe
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-63UUF4IG.mjs → chunk-2PFAPQL4.mjs} +7 -7
- package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GPZSXPSA.mjs → chunk-GS2UNGJK.mjs} +444 -491
- package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +161 -303
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +9 -7
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-K734DJB7.mjs → chunk-6POOFFYF.mjs} +7 -7
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-XUD6W42C.mjs → chunk-TRR3C5NX.mjs} +444 -491
- package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +161 -303
- 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 +9 -7
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +1 -1
- 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 +3 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +70 -7
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +5 -2
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +5 -6
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +7 -5
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -3
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +1 -2
- 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/TableToolbar/TableToolbar.d.ts +2 -2
- package/dist/types/src/components/TableToolbar/TableToolbar.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 +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +3 -3
- 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 +4 -4
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +2 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +3 -3
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +6 -6
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +5 -6
- package/dist/types/src/util/dynamic-table.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +52 -51
- package/src/components/Table/DynamicTable.stories.tsx +11 -10
- package/src/components/Table/DynamicTable.tsx +4 -7
- package/src/components/Table/Relations.stories.tsx +127 -18
- package/src/components/Table/RowActionsMenu.tsx +21 -13
- package/src/components/Table/Table.stories.tsx +44 -43
- package/src/components/Table/Table.tsx +13 -9
- package/src/components/TableCellEditor/FormCellEditor.tsx +51 -41
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +19 -46
- package/src/components/TableCellEditor/TableCellEditor.tsx +7 -94
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +32 -22
- package/src/components/testing.ts +2 -2
- package/src/hooks/useAddRow.ts +1 -1
- package/src/hooks/useTableModel.ts +5 -5
- package/src/model/modal-controller.ts +0 -28
- package/src/model/table-model.test.ts +17 -7
- package/src/model/table-model.ts +12 -8
- package/src/model/table-presentation.test.ts +20 -18
- package/src/model/table-presentation.ts +4 -5
- package/src/model/table-sorting.ts +9 -9
- package/src/playwright/TableManager.ts +1 -1
- package/src/playwright/smoke.spec.ts +7 -5
- package/src/testing/useTestTableModel.ts +7 -5
- package/src/types/schema.ts +8 -8
- package/src/util/dynamic-table.ts +10 -12
- package/src/util/schema.ts +4 -4
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
- package/dist/lib/browser/chunk-GPZSXPSA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XUD6W42C.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/src/components/Table/CreateRefPanel.tsx +0 -103
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
schema_exports
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6POOFFYF.mjs";
|
|
5
5
|
|
|
6
6
|
// src/util/dynamic-table.ts
|
|
7
|
-
import { Obj } from "@dxos/echo";
|
|
8
|
-
import { getTypename, toJsonSchema } from "@dxos/echo
|
|
9
|
-
import { ProjectionModel,
|
|
7
|
+
import { Filter, Obj, Query } from "@dxos/echo";
|
|
8
|
+
import { getTypename, toJsonSchema } from "@dxos/echo/internal";
|
|
9
|
+
import { ProjectionModel, View, getSchemaFromPropertyDefinitions } from "@dxos/schema";
|
|
10
10
|
var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
11
11
|
if (typename && properties) {
|
|
12
12
|
const schema2 = getSchemaFromPropertyDefinitions(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 = ({
|
|
31
|
+
var makeDynamicTable = ({ jsonSchema, properties }) => {
|
|
32
32
|
const table = Obj.make(schema_exports.Table, {
|
|
33
33
|
sizes: {}
|
|
34
34
|
});
|
|
35
|
-
const view =
|
|
36
|
-
|
|
35
|
+
const view = View.make({
|
|
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
|
}
|
|
@@ -256,14 +257,14 @@ var tableControls = {
|
|
|
256
257
|
};
|
|
257
258
|
|
|
258
259
|
// src/util/schema.ts
|
|
259
|
-
import
|
|
260
|
-
import
|
|
260
|
+
import * as Schema from "effect/Schema";
|
|
261
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
261
262
|
var narrowSchema = (schema, paths) => {
|
|
262
263
|
const ast = schema?.ast;
|
|
263
|
-
if (isTypeLiteral(ast)) {
|
|
264
|
+
if (SchemaAST.isTypeLiteral(ast)) {
|
|
264
265
|
const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
|
|
265
266
|
if (propertySignatures.length > 0) {
|
|
266
|
-
const narrowType = new TypeLiteral(propertySignatures, []);
|
|
267
|
+
const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
|
|
267
268
|
return Schema.make(narrowType);
|
|
268
269
|
}
|
|
269
270
|
}
|
|
@@ -274,11 +275,10 @@ var narrowSchema = (schema, paths) => {
|
|
|
274
275
|
import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
|
|
275
276
|
import { Resource as Resource2 } from "@dxos/context";
|
|
276
277
|
import { Obj as Obj2, Ref } from "@dxos/echo";
|
|
277
|
-
import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo
|
|
278
|
+
import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
|
|
278
279
|
import { invariant } from "@dxos/invariant";
|
|
279
280
|
import { ObjectId } from "@dxos/keys";
|
|
280
281
|
import { getSnapshot, isLiveObject } from "@dxos/live-object";
|
|
281
|
-
import { fullyQualifiedId } from "@dxos/react-client/echo";
|
|
282
282
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
283
283
|
import { ProjectionModel as ProjectionModel2, validateSchema } from "@dxos/schema";
|
|
284
284
|
|
|
@@ -301,20 +301,34 @@ var extractTagIds = (value) => {
|
|
|
301
301
|
// src/model/selection-model.ts
|
|
302
302
|
import { computed, effect, signal } from "@preact/signals-core";
|
|
303
303
|
import { Resource } from "@dxos/context";
|
|
304
|
-
function _define_property(obj, key, value) {
|
|
305
|
-
if (key in obj) {
|
|
306
|
-
Object.defineProperty(obj, key, {
|
|
307
|
-
value,
|
|
308
|
-
enumerable: true,
|
|
309
|
-
configurable: true,
|
|
310
|
-
writable: true
|
|
311
|
-
});
|
|
312
|
-
} else {
|
|
313
|
-
obj[key] = value;
|
|
314
|
-
}
|
|
315
|
-
return obj;
|
|
316
|
-
}
|
|
317
304
|
var SelectionModel = class extends Resource {
|
|
305
|
+
_rows;
|
|
306
|
+
_selectionMode;
|
|
307
|
+
_initialSelection;
|
|
308
|
+
_onSelectionChanged;
|
|
309
|
+
_selection;
|
|
310
|
+
_validSelectedIds = computed(() => {
|
|
311
|
+
const rows = this._rows.value;
|
|
312
|
+
if (!rows) {
|
|
313
|
+
return /* @__PURE__ */ new Set();
|
|
314
|
+
}
|
|
315
|
+
const validIds = new Set(rows.map((row) => row.id));
|
|
316
|
+
return new Set([
|
|
317
|
+
...this._selection.value
|
|
318
|
+
].filter((id) => validIds.has(id)));
|
|
319
|
+
});
|
|
320
|
+
_hasSelection = computed(() => this._validSelectedIds.value.size > 0);
|
|
321
|
+
_allSelected = computed(() => {
|
|
322
|
+
const rows = this._rows.value;
|
|
323
|
+
if (rows.length === 0) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return rows.every((row) => this._selection.value.has(row.id));
|
|
327
|
+
});
|
|
328
|
+
constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
|
|
329
|
+
super(), this._rows = _rows, this._selectionMode = _selectionMode, this._initialSelection = _initialSelection, this._onSelectionChanged = _onSelectionChanged;
|
|
330
|
+
this._selection = signal(new Set(this._initialSelection));
|
|
331
|
+
}
|
|
318
332
|
async _open() {
|
|
319
333
|
const selectionWatcher = effect(() => {
|
|
320
334
|
touch(this._selection.value);
|
|
@@ -337,80 +351,80 @@ var SelectionModel = class extends Resource {
|
|
|
337
351
|
get selectionMode() {
|
|
338
352
|
return this._selectionMode;
|
|
339
353
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
getSelectedRows = () => {
|
|
355
|
+
const selectedIds = this._validSelectedIds.value;
|
|
356
|
+
return this._rows.value.filter((row) => selectedIds.has(row.id));
|
|
357
|
+
};
|
|
358
|
+
isRowIndexSelected = (rowIndex) => {
|
|
359
|
+
const row = this._rows.value[rowIndex];
|
|
360
|
+
return this._selection.value.has(row.id);
|
|
361
|
+
};
|
|
362
|
+
isObjectSelected = (object) => {
|
|
363
|
+
return this._selection.value.has(object.id);
|
|
364
|
+
};
|
|
365
|
+
//
|
|
366
|
+
// Manipulation
|
|
367
|
+
//
|
|
368
|
+
toggleSelectionForRowIndex = (rowIndex) => {
|
|
369
|
+
const row = this._rows.value[rowIndex];
|
|
370
|
+
const newSelection = new Set(this._selection.value);
|
|
371
|
+
if (newSelection.has(row.id)) {
|
|
372
|
+
newSelection.delete(row.id);
|
|
373
|
+
} else {
|
|
374
|
+
if (this._selectionMode === "single") {
|
|
375
|
+
newSelection.clear();
|
|
357
376
|
}
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}, this.toggleSelectionForRowIndex = (rowIndex) => {
|
|
368
|
-
const row = this._rows.value[rowIndex];
|
|
369
|
-
const newSelection = new Set(this._selection.value);
|
|
370
|
-
if (newSelection.has(row.id)) {
|
|
371
|
-
newSelection.delete(row.id);
|
|
372
|
-
} else {
|
|
373
|
-
if (this._selectionMode === "single") {
|
|
374
|
-
newSelection.clear();
|
|
375
|
-
}
|
|
376
|
-
newSelection.add(row.id);
|
|
377
|
+
newSelection.add(row.id);
|
|
378
|
+
}
|
|
379
|
+
this._selection.value = newSelection;
|
|
380
|
+
};
|
|
381
|
+
setSelection = (mode) => {
|
|
382
|
+
switch (mode) {
|
|
383
|
+
case "all": {
|
|
384
|
+
this._selection.value = new Set(this._rows.value.map((row) => row.id));
|
|
385
|
+
break;
|
|
377
386
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
case "all": {
|
|
382
|
-
this._selection.value = new Set(this._rows.value.map((row) => row.id));
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
case "none": {
|
|
386
|
-
this._selection.value = /* @__PURE__ */ new Set();
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
387
|
+
case "none": {
|
|
388
|
+
this._selection.value = /* @__PURE__ */ new Set();
|
|
389
|
+
break;
|
|
389
390
|
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
393
|
};
|
|
394
394
|
|
|
395
395
|
// src/model/table-sorting.ts
|
|
396
396
|
import { computed as computed2, signal as signal2 } from "@preact/signals-core";
|
|
397
397
|
import orderBy from "lodash.orderby";
|
|
398
|
-
import { FormatEnum, TypeEnum, getValue } from "@dxos/echo
|
|
398
|
+
import { FormatEnum, TypeEnum, getValue } from "@dxos/echo/internal";
|
|
399
399
|
import { formatForDisplay } from "@dxos/react-ui-form";
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
400
|
+
var TableSorting = class {
|
|
401
|
+
_view;
|
|
402
|
+
_projection;
|
|
403
|
+
_displayToDataIndex = /* @__PURE__ */ new Map();
|
|
404
|
+
_rows;
|
|
405
|
+
_localSort = signal2(void 0);
|
|
406
|
+
_isDirty;
|
|
407
|
+
sortedRows;
|
|
408
|
+
constructor(rows, _view, _projection) {
|
|
409
|
+
this._view = _view;
|
|
410
|
+
this._projection = _projection;
|
|
411
|
+
this._rows = rows;
|
|
412
|
+
this._isDirty = computed2(() => {
|
|
413
|
+
const local = this._localSort.value;
|
|
414
|
+
const viewSort = this._view.sort?.[0];
|
|
415
|
+
if (local?.type === "cleared") {
|
|
416
|
+
return viewSort !== void 0;
|
|
417
|
+
}
|
|
418
|
+
if (local?.type === "active") {
|
|
419
|
+
if (!viewSort) {
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
|
|
423
|
+
}
|
|
424
|
+
return false;
|
|
407
425
|
});
|
|
408
|
-
|
|
409
|
-
obj[key] = value;
|
|
426
|
+
this.sortedRows = this.initialiseSortedRows();
|
|
410
427
|
}
|
|
411
|
-
return obj;
|
|
412
|
-
}
|
|
413
|
-
var TableSorting = class {
|
|
414
428
|
/**
|
|
415
429
|
* @reactive
|
|
416
430
|
* @returns Local sort if present, falls back to view sort.
|
|
@@ -546,51 +560,9 @@ var TableSorting = class {
|
|
|
546
560
|
value
|
|
547
561
|
});
|
|
548
562
|
}
|
|
549
|
-
constructor(rows, _view, _projection) {
|
|
550
|
-
_define_property2(this, "_view", void 0);
|
|
551
|
-
_define_property2(this, "_projection", void 0);
|
|
552
|
-
_define_property2(this, "_displayToDataIndex", void 0);
|
|
553
|
-
_define_property2(this, "_rows", void 0);
|
|
554
|
-
_define_property2(this, "_localSort", void 0);
|
|
555
|
-
_define_property2(this, "_isDirty", void 0);
|
|
556
|
-
_define_property2(this, "sortedRows", void 0);
|
|
557
|
-
this._view = _view;
|
|
558
|
-
this._projection = _projection;
|
|
559
|
-
this._displayToDataIndex = /* @__PURE__ */ new Map();
|
|
560
|
-
this._localSort = signal2(void 0);
|
|
561
|
-
this._rows = rows;
|
|
562
|
-
this._isDirty = computed2(() => {
|
|
563
|
-
const local = this._localSort.value;
|
|
564
|
-
const viewSort = this._view.sort?.[0];
|
|
565
|
-
if (local?.type === "cleared") {
|
|
566
|
-
return viewSort !== void 0;
|
|
567
|
-
}
|
|
568
|
-
if (local?.type === "active") {
|
|
569
|
-
if (!viewSort) {
|
|
570
|
-
return true;
|
|
571
|
-
}
|
|
572
|
-
return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
|
|
573
|
-
}
|
|
574
|
-
return false;
|
|
575
|
-
});
|
|
576
|
-
this.sortedRows = this.initialiseSortedRows();
|
|
577
|
-
}
|
|
578
563
|
};
|
|
579
564
|
|
|
580
565
|
// src/model/table-model.ts
|
|
581
|
-
function _define_property3(obj, key, value) {
|
|
582
|
-
if (key in obj) {
|
|
583
|
-
Object.defineProperty(obj, key, {
|
|
584
|
-
value,
|
|
585
|
-
enumerable: true,
|
|
586
|
-
configurable: true,
|
|
587
|
-
writable: true
|
|
588
|
-
});
|
|
589
|
-
} else {
|
|
590
|
-
obj[key] = value;
|
|
591
|
-
}
|
|
592
|
-
return obj;
|
|
593
|
-
}
|
|
594
566
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
595
567
|
var defaultFeatures = {
|
|
596
568
|
selection: {
|
|
@@ -601,8 +573,71 @@ var defaultFeatures = {
|
|
|
601
573
|
schemaEditable: false
|
|
602
574
|
};
|
|
603
575
|
var TableModel = class extends Resource2 {
|
|
576
|
+
_view;
|
|
577
|
+
_projection;
|
|
578
|
+
_table;
|
|
579
|
+
_visibleRange = signal3({
|
|
580
|
+
start: {
|
|
581
|
+
row: 0,
|
|
582
|
+
col: 0
|
|
583
|
+
},
|
|
584
|
+
end: {
|
|
585
|
+
row: 0,
|
|
586
|
+
col: 0
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
_onInsertRow;
|
|
590
|
+
_onDeleteRows;
|
|
591
|
+
_onDeleteColumn;
|
|
592
|
+
_onCellUpdate;
|
|
593
|
+
_onRowOrderChange;
|
|
594
|
+
_onRowAction;
|
|
595
|
+
_rowActions;
|
|
596
|
+
_features;
|
|
597
|
+
_rows = signal3([]);
|
|
598
|
+
_draftRows = signal3([]);
|
|
599
|
+
_sorting;
|
|
600
|
+
_pinnedRows;
|
|
601
|
+
_selection;
|
|
602
|
+
_columnMeta;
|
|
603
|
+
constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
604
|
+
top: [],
|
|
605
|
+
bottom: []
|
|
606
|
+
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
607
|
+
super();
|
|
608
|
+
this._view = view;
|
|
609
|
+
this._projection = projection ?? new ProjectionModel2(schema, view.projection);
|
|
610
|
+
this._projection.normalizeView();
|
|
611
|
+
this._features = {
|
|
612
|
+
...defaultFeatures,
|
|
613
|
+
...features
|
|
614
|
+
};
|
|
615
|
+
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
616
|
+
F: __dxlog_file,
|
|
617
|
+
L: 148,
|
|
618
|
+
S: this,
|
|
619
|
+
A: [
|
|
620
|
+
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
621
|
+
"'Single selection is not compatible with editable tables.'"
|
|
622
|
+
]
|
|
623
|
+
});
|
|
624
|
+
this._sorting = new TableSorting(this._rows, this._view, this._projection);
|
|
625
|
+
if (sorting.length > 0) {
|
|
626
|
+
const [sort] = sorting;
|
|
627
|
+
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
628
|
+
}
|
|
629
|
+
this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
|
|
630
|
+
this._pinnedRows = pinnedRows;
|
|
631
|
+
this._rowActions = rowActions;
|
|
632
|
+
this._onInsertRow = onInsertRow;
|
|
633
|
+
this._onDeleteRows = onDeleteRows;
|
|
634
|
+
this._onDeleteColumn = onDeleteColumn;
|
|
635
|
+
this._onCellUpdate = onCellUpdate;
|
|
636
|
+
this._onRowOrderChange = onRowOrderChange;
|
|
637
|
+
this._onRowAction = onRowAction;
|
|
638
|
+
}
|
|
604
639
|
get id() {
|
|
605
|
-
return
|
|
640
|
+
return Obj2.getDXN(this._view).toString();
|
|
606
641
|
}
|
|
607
642
|
get view() {
|
|
608
643
|
return this._view;
|
|
@@ -743,6 +778,17 @@ var TableModel = class extends Resource2 {
|
|
|
743
778
|
});
|
|
744
779
|
this._ctx.onDispose(draftRowsWatcher);
|
|
745
780
|
}
|
|
781
|
+
//
|
|
782
|
+
// Data
|
|
783
|
+
//
|
|
784
|
+
setRows = (obj) => {
|
|
785
|
+
this._rows.value = obj;
|
|
786
|
+
};
|
|
787
|
+
getRowCount = () => this._rows.value.length;
|
|
788
|
+
/**
|
|
789
|
+
* @reactive
|
|
790
|
+
*/
|
|
791
|
+
getDraftRowCount = () => this._draftRows.value.length;
|
|
746
792
|
// TODO(ZaymonFC): Return .value instead of exposing the signal.
|
|
747
793
|
get draftRows() {
|
|
748
794
|
return this._draftRows;
|
|
@@ -761,6 +807,14 @@ var TableModel = class extends Resource2 {
|
|
|
761
807
|
const validationErrors = draftRow.validationErrors || [];
|
|
762
808
|
return validationErrors.some((error) => error.path === fieldPath);
|
|
763
809
|
}
|
|
810
|
+
getColumnCount = () => this._projection?.fields.length ?? 0;
|
|
811
|
+
insertRow = () => {
|
|
812
|
+
const result = this._onInsertRow?.();
|
|
813
|
+
if (result === "draft" && this._draftRows.value.length === 0) {
|
|
814
|
+
this.createDraftRow();
|
|
815
|
+
}
|
|
816
|
+
return result ?? "final";
|
|
817
|
+
};
|
|
764
818
|
createDraftRow() {
|
|
765
819
|
if (!this._projection) {
|
|
766
820
|
return;
|
|
@@ -800,6 +854,187 @@ var TableModel = class extends Resource2 {
|
|
|
800
854
|
const schema = toEffectSchema(this._projection.baseSchema);
|
|
801
855
|
return validateSchema(schema, data) || [];
|
|
802
856
|
}
|
|
857
|
+
commitDraftRow = (draftRowIndex) => {
|
|
858
|
+
if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
const draftRow = this._draftRows.value[draftRowIndex];
|
|
862
|
+
if (!draftRow.valid) {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
const insertRowResult = this._onInsertRow?.(draftRow.data);
|
|
866
|
+
if (insertRowResult === "final") {
|
|
867
|
+
const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
|
|
868
|
+
this._draftRows.value = newDraftRows;
|
|
869
|
+
}
|
|
870
|
+
return insertRowResult === "final";
|
|
871
|
+
};
|
|
872
|
+
deleteRow = (rowIndex) => {
|
|
873
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
874
|
+
const obj = this._rows.value[row];
|
|
875
|
+
const objectsToDelete = [];
|
|
876
|
+
if (this.features.selection.enabled && this._selection.hasSelection.value) {
|
|
877
|
+
const selectedRows = this._selection.getSelectedRows();
|
|
878
|
+
objectsToDelete.push(...selectedRows);
|
|
879
|
+
} else {
|
|
880
|
+
objectsToDelete.push(obj);
|
|
881
|
+
}
|
|
882
|
+
this._onDeleteRows?.(row, objectsToDelete);
|
|
883
|
+
};
|
|
884
|
+
handleRowAction = (actionId, rowIndex) => {
|
|
885
|
+
if (!this._onRowAction) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
889
|
+
const data = this._rows.value[row];
|
|
890
|
+
if (data) {
|
|
891
|
+
this._onRowAction(actionId, data);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
getCellData = (cell) => {
|
|
895
|
+
const { col, row, plane } = cell;
|
|
896
|
+
const fields = this._projection?.fields ?? [];
|
|
897
|
+
if (col < 0 || col >= fields.length) {
|
|
898
|
+
return void 0;
|
|
899
|
+
}
|
|
900
|
+
const field = fields[col];
|
|
901
|
+
let value;
|
|
902
|
+
if (plane === "frozenRowsEnd") {
|
|
903
|
+
if (row >= 0 && row < this._draftRows.value.length) {
|
|
904
|
+
value = getValue2(this._draftRows.value[row].data, field.path);
|
|
905
|
+
} else {
|
|
906
|
+
return void 0;
|
|
907
|
+
}
|
|
908
|
+
} else {
|
|
909
|
+
const dataIndex = this._sorting.getDataIndex(row);
|
|
910
|
+
value = getValue2(this._rows.value[dataIndex], field.path);
|
|
911
|
+
}
|
|
912
|
+
if (value == null) {
|
|
913
|
+
return "";
|
|
914
|
+
}
|
|
915
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
916
|
+
switch (props.format) {
|
|
917
|
+
case FormatEnum2.Ref: {
|
|
918
|
+
if (!field.referencePath) {
|
|
919
|
+
return "";
|
|
920
|
+
}
|
|
921
|
+
return getValue2(value.target, field.referencePath);
|
|
922
|
+
}
|
|
923
|
+
default: {
|
|
924
|
+
return formatForEditing({
|
|
925
|
+
type: props.type,
|
|
926
|
+
format: props.format,
|
|
927
|
+
value
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
validateCellData = async ({ col, row, plane }, value) => {
|
|
933
|
+
const fields = this._projection?.fields ?? [];
|
|
934
|
+
if (col < 0 || col >= fields.length) {
|
|
935
|
+
return {
|
|
936
|
+
valid: false,
|
|
937
|
+
error: "Invalid column index"
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
const field = fields[col];
|
|
941
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
942
|
+
const transformedValue = editorTextToCellValue(props, value);
|
|
943
|
+
const isDraftRow = plane === "frozenRowsEnd";
|
|
944
|
+
if (isDraftRow) {
|
|
945
|
+
const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
|
|
946
|
+
if (isInvalidDraftRowIndex) {
|
|
947
|
+
return {
|
|
948
|
+
valid: false,
|
|
949
|
+
error: "Invalid draft row index"
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
const draftRow = this._draftRows.value[row];
|
|
953
|
+
const snapshot = {
|
|
954
|
+
...draftRow.data
|
|
955
|
+
};
|
|
956
|
+
setValue(snapshot, field.path, transformedValue);
|
|
957
|
+
const validationErrors = this.validateDraftRowData(snapshot);
|
|
958
|
+
if (validationErrors.length > 0) {
|
|
959
|
+
const error = validationErrors.find((err) => err.path === field.path);
|
|
960
|
+
if (error) {
|
|
961
|
+
return {
|
|
962
|
+
valid: false,
|
|
963
|
+
error: error.message
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return {
|
|
968
|
+
valid: true
|
|
969
|
+
};
|
|
970
|
+
} else {
|
|
971
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
972
|
+
const currentRow = this._rows.value[rowIdx];
|
|
973
|
+
invariant(currentRow, "Invalid row index", {
|
|
974
|
+
F: __dxlog_file,
|
|
975
|
+
L: 525,
|
|
976
|
+
S: this,
|
|
977
|
+
A: [
|
|
978
|
+
"currentRow",
|
|
979
|
+
"'Invalid row index'"
|
|
980
|
+
]
|
|
981
|
+
});
|
|
982
|
+
const snapshot = getSnapshot(currentRow);
|
|
983
|
+
setValue(snapshot, field.path, transformedValue);
|
|
984
|
+
const schema = getSchema(currentRow);
|
|
985
|
+
invariant(schema, void 0, {
|
|
986
|
+
F: __dxlog_file,
|
|
987
|
+
L: 531,
|
|
988
|
+
S: this,
|
|
989
|
+
A: [
|
|
990
|
+
"schema",
|
|
991
|
+
""
|
|
992
|
+
]
|
|
993
|
+
});
|
|
994
|
+
const validationResult = validateSchema(schema, snapshot);
|
|
995
|
+
if (validationResult && validationResult.length > 0) {
|
|
996
|
+
const error = validationResult[0];
|
|
997
|
+
invariant(error.path === field.path, void 0, {
|
|
998
|
+
F: __dxlog_file,
|
|
999
|
+
L: 536,
|
|
1000
|
+
S: this,
|
|
1001
|
+
A: [
|
|
1002
|
+
"error.path === field.path",
|
|
1003
|
+
""
|
|
1004
|
+
]
|
|
1005
|
+
});
|
|
1006
|
+
return {
|
|
1007
|
+
valid: false,
|
|
1008
|
+
error: error.message
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
return {
|
|
1012
|
+
valid: true
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
setCellData = (cell, value) => {
|
|
1017
|
+
const { col, row, plane } = cell;
|
|
1018
|
+
const fields = this._projection?.fields ?? [];
|
|
1019
|
+
if (col < 0 || col >= fields.length) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
const field = fields[col];
|
|
1023
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
1024
|
+
const transformedValue = editorTextToCellValue(props, value);
|
|
1025
|
+
if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (plane === "frozenRowsEnd") {
|
|
1029
|
+
if (row >= 0 && row < this._draftRows.value.length) {
|
|
1030
|
+
setValue(this._draftRows.value[row].data, field.path, transformedValue);
|
|
1031
|
+
this.validateDraftRow(row);
|
|
1032
|
+
}
|
|
1033
|
+
} else {
|
|
1034
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
1035
|
+
setValue(this._rows.value[rowIdx], field.path, transformedValue);
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
803
1038
|
/**
|
|
804
1039
|
* Updates a cell's value using a transform function.
|
|
805
1040
|
* @param {DxGridPlanePosition} position - The position of the cell to update.
|
|
@@ -880,239 +1115,6 @@ var TableModel = class extends Resource2 {
|
|
|
880
1115
|
saveView() {
|
|
881
1116
|
this._sorting.save();
|
|
882
1117
|
}
|
|
883
|
-
constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
884
|
-
top: [],
|
|
885
|
-
bottom: []
|
|
886
|
-
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
887
|
-
super(), _define_property3(this, "_view", void 0), _define_property3(this, "_projection", void 0), _define_property3(this, "_table", void 0), _define_property3(this, "_visibleRange", signal3({
|
|
888
|
-
start: {
|
|
889
|
-
row: 0,
|
|
890
|
-
col: 0
|
|
891
|
-
},
|
|
892
|
-
end: {
|
|
893
|
-
row: 0,
|
|
894
|
-
col: 0
|
|
895
|
-
}
|
|
896
|
-
})), _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), //
|
|
897
|
-
// Data
|
|
898
|
-
//
|
|
899
|
-
_define_property3(this, "setRows", (obj) => {
|
|
900
|
-
this._rows.value = obj;
|
|
901
|
-
}), _define_property3(this, "getRowCount", () => this._rows.value.length), /**
|
|
902
|
-
* @reactive
|
|
903
|
-
*/
|
|
904
|
-
_define_property3(this, "getDraftRowCount", () => this._draftRows.value.length), _define_property3(this, "getColumnCount", () => this._projection?.fields.length ?? 0), _define_property3(this, "insertRow", () => {
|
|
905
|
-
const result = this._onInsertRow?.();
|
|
906
|
-
if (result === "draft" && this._draftRows.value.length === 0) {
|
|
907
|
-
this.createDraftRow();
|
|
908
|
-
}
|
|
909
|
-
return result ?? "final";
|
|
910
|
-
}), _define_property3(this, "commitDraftRow", (draftRowIndex) => {
|
|
911
|
-
if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
|
|
912
|
-
return false;
|
|
913
|
-
}
|
|
914
|
-
const draftRow = this._draftRows.value[draftRowIndex];
|
|
915
|
-
if (!draftRow.valid) {
|
|
916
|
-
return false;
|
|
917
|
-
}
|
|
918
|
-
const insertRowResult = this._onInsertRow?.(draftRow.data);
|
|
919
|
-
if (insertRowResult === "final") {
|
|
920
|
-
const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
|
|
921
|
-
this._draftRows.value = newDraftRows;
|
|
922
|
-
}
|
|
923
|
-
return insertRowResult === "final";
|
|
924
|
-
}), _define_property3(this, "deleteRow", (rowIndex) => {
|
|
925
|
-
const row = this._sorting.getDataIndex(rowIndex);
|
|
926
|
-
const obj = this._rows.value[row];
|
|
927
|
-
const objectsToDelete = [];
|
|
928
|
-
if (this.features.selection.enabled && this._selection.hasSelection.value) {
|
|
929
|
-
const selectedRows = this._selection.getSelectedRows();
|
|
930
|
-
objectsToDelete.push(...selectedRows);
|
|
931
|
-
} else {
|
|
932
|
-
objectsToDelete.push(obj);
|
|
933
|
-
}
|
|
934
|
-
this._onDeleteRows?.(row, objectsToDelete);
|
|
935
|
-
}), _define_property3(this, "handleRowAction", (actionId, rowIndex) => {
|
|
936
|
-
if (!this._onRowAction) {
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
const row = this._sorting.getDataIndex(rowIndex);
|
|
940
|
-
const data = this._rows.value[row];
|
|
941
|
-
if (data) {
|
|
942
|
-
this._onRowAction(actionId, data);
|
|
943
|
-
}
|
|
944
|
-
}), _define_property3(this, "getCellData", (cell) => {
|
|
945
|
-
const { col, row, plane } = cell;
|
|
946
|
-
const fields = this._projection?.fields ?? [];
|
|
947
|
-
if (col < 0 || col >= fields.length) {
|
|
948
|
-
return void 0;
|
|
949
|
-
}
|
|
950
|
-
const field = fields[col];
|
|
951
|
-
let value;
|
|
952
|
-
if (plane === "frozenRowsEnd") {
|
|
953
|
-
if (row >= 0 && row < this._draftRows.value.length) {
|
|
954
|
-
value = getValue2(this._draftRows.value[row].data, field.path);
|
|
955
|
-
} else {
|
|
956
|
-
return void 0;
|
|
957
|
-
}
|
|
958
|
-
} else {
|
|
959
|
-
const dataIndex = this._sorting.getDataIndex(row);
|
|
960
|
-
value = getValue2(this._rows.value[dataIndex], field.path);
|
|
961
|
-
}
|
|
962
|
-
if (value == null) {
|
|
963
|
-
return "";
|
|
964
|
-
}
|
|
965
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
966
|
-
switch (props.format) {
|
|
967
|
-
case FormatEnum2.Ref: {
|
|
968
|
-
if (!field.referencePath) {
|
|
969
|
-
return "";
|
|
970
|
-
}
|
|
971
|
-
return getValue2(value.target, field.referencePath);
|
|
972
|
-
}
|
|
973
|
-
default: {
|
|
974
|
-
return formatForEditing({
|
|
975
|
-
type: props.type,
|
|
976
|
-
format: props.format,
|
|
977
|
-
value
|
|
978
|
-
});
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
}), _define_property3(this, "validateCellData", async ({ col, row, plane }, value) => {
|
|
982
|
-
const fields = this._projection?.fields ?? [];
|
|
983
|
-
if (col < 0 || col >= fields.length) {
|
|
984
|
-
return {
|
|
985
|
-
valid: false,
|
|
986
|
-
error: "Invalid column index"
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
const field = fields[col];
|
|
990
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
991
|
-
const transformedValue = editorTextToCellValue(props, value);
|
|
992
|
-
const isDraftRow = plane === "frozenRowsEnd";
|
|
993
|
-
if (isDraftRow) {
|
|
994
|
-
const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
|
|
995
|
-
if (isInvalidDraftRowIndex) {
|
|
996
|
-
return {
|
|
997
|
-
valid: false,
|
|
998
|
-
error: "Invalid draft row index"
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
const draftRow = this._draftRows.value[row];
|
|
1002
|
-
const snapshot = {
|
|
1003
|
-
...draftRow.data
|
|
1004
|
-
};
|
|
1005
|
-
setValue(snapshot, field.path, transformedValue);
|
|
1006
|
-
const validationErrors = this.validateDraftRowData(snapshot);
|
|
1007
|
-
if (validationErrors.length > 0) {
|
|
1008
|
-
const error = validationErrors.find((err) => err.path === field.path);
|
|
1009
|
-
if (error) {
|
|
1010
|
-
return {
|
|
1011
|
-
valid: false,
|
|
1012
|
-
error: error.message
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
return {
|
|
1017
|
-
valid: true
|
|
1018
|
-
};
|
|
1019
|
-
} else {
|
|
1020
|
-
const rowIdx = this._sorting.getDataIndex(row);
|
|
1021
|
-
const currentRow = this._rows.value[rowIdx];
|
|
1022
|
-
invariant(currentRow, "Invalid row index", {
|
|
1023
|
-
F: __dxlog_file,
|
|
1024
|
-
L: 521,
|
|
1025
|
-
S: this,
|
|
1026
|
-
A: [
|
|
1027
|
-
"currentRow",
|
|
1028
|
-
"'Invalid row index'"
|
|
1029
|
-
]
|
|
1030
|
-
});
|
|
1031
|
-
const snapshot = getSnapshot(currentRow);
|
|
1032
|
-
setValue(snapshot, field.path, transformedValue);
|
|
1033
|
-
const schema2 = getSchema(currentRow);
|
|
1034
|
-
invariant(schema2, void 0, {
|
|
1035
|
-
F: __dxlog_file,
|
|
1036
|
-
L: 527,
|
|
1037
|
-
S: this,
|
|
1038
|
-
A: [
|
|
1039
|
-
"schema",
|
|
1040
|
-
""
|
|
1041
|
-
]
|
|
1042
|
-
});
|
|
1043
|
-
const validationResult = validateSchema(schema2, snapshot);
|
|
1044
|
-
if (validationResult && validationResult.length > 0) {
|
|
1045
|
-
const error = validationResult[0];
|
|
1046
|
-
invariant(error.path === field.path, void 0, {
|
|
1047
|
-
F: __dxlog_file,
|
|
1048
|
-
L: 532,
|
|
1049
|
-
S: this,
|
|
1050
|
-
A: [
|
|
1051
|
-
"error.path === field.path",
|
|
1052
|
-
""
|
|
1053
|
-
]
|
|
1054
|
-
});
|
|
1055
|
-
return {
|
|
1056
|
-
valid: false,
|
|
1057
|
-
error: error.message
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
return {
|
|
1061
|
-
valid: true
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
}), _define_property3(this, "setCellData", (cell, value) => {
|
|
1065
|
-
const { col, row, plane } = cell;
|
|
1066
|
-
const fields = this._projection?.fields ?? [];
|
|
1067
|
-
if (col < 0 || col >= fields.length) {
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
const field = fields[col];
|
|
1071
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
1072
|
-
const transformedValue = editorTextToCellValue(props, value);
|
|
1073
|
-
if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
if (plane === "frozenRowsEnd") {
|
|
1077
|
-
if (row >= 0 && row < this._draftRows.value.length) {
|
|
1078
|
-
setValue(this._draftRows.value[row].data, field.path, transformedValue);
|
|
1079
|
-
this.validateDraftRow(row);
|
|
1080
|
-
}
|
|
1081
|
-
} else {
|
|
1082
|
-
const rowIdx = this._sorting.getDataIndex(row);
|
|
1083
|
-
setValue(this._rows.value[rowIdx], field.path, transformedValue);
|
|
1084
|
-
}
|
|
1085
|
-
});
|
|
1086
|
-
this._view = view;
|
|
1087
|
-
this._projection = projection ?? new ProjectionModel2(schema, view.projection);
|
|
1088
|
-
this._features = {
|
|
1089
|
-
...defaultFeatures,
|
|
1090
|
-
...features
|
|
1091
|
-
};
|
|
1092
|
-
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
1093
|
-
F: __dxlog_file,
|
|
1094
|
-
L: 148,
|
|
1095
|
-
S: this,
|
|
1096
|
-
A: [
|
|
1097
|
-
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
1098
|
-
"'Single selection is not compatible with editable tables.'"
|
|
1099
|
-
]
|
|
1100
|
-
});
|
|
1101
|
-
this._sorting = new TableSorting(this._rows, this._view, this._projection);
|
|
1102
|
-
if (sorting.length > 0) {
|
|
1103
|
-
const [sort] = sorting;
|
|
1104
|
-
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
1105
|
-
}
|
|
1106
|
-
this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
|
|
1107
|
-
this._pinnedRows = pinnedRows;
|
|
1108
|
-
this._rowActions = rowActions;
|
|
1109
|
-
this._onInsertRow = onInsertRow;
|
|
1110
|
-
this._onDeleteRows = onDeleteRows;
|
|
1111
|
-
this._onDeleteColumn = onDeleteColumn;
|
|
1112
|
-
this._onCellUpdate = onCellUpdate;
|
|
1113
|
-
this._onRowOrderChange = onRowOrderChange;
|
|
1114
|
-
this._onRowAction = onRowAction;
|
|
1115
|
-
}
|
|
1116
1118
|
};
|
|
1117
1119
|
var editorTextToCellValue = (props, value) => {
|
|
1118
1120
|
switch (props.format) {
|
|
@@ -1147,128 +1149,96 @@ var editorTextToCellValue = (props, value) => {
|
|
|
1147
1149
|
|
|
1148
1150
|
// src/model/modal-controller.ts
|
|
1149
1151
|
import { signal as signal4 } from "@preact/signals-core";
|
|
1150
|
-
import { log } from "@dxos/log";
|
|
1151
|
-
function _define_property4(obj, key, value) {
|
|
1152
|
-
if (key in obj) {
|
|
1153
|
-
Object.defineProperty(obj, key, {
|
|
1154
|
-
value,
|
|
1155
|
-
enumerable: true,
|
|
1156
|
-
configurable: true,
|
|
1157
|
-
writable: true
|
|
1158
|
-
});
|
|
1159
|
-
} else {
|
|
1160
|
-
obj[key] = value;
|
|
1161
|
-
}
|
|
1162
|
-
return obj;
|
|
1163
|
-
}
|
|
1164
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/modal-controller.ts";
|
|
1165
1152
|
var ModalController = class {
|
|
1153
|
+
_state = signal4({
|
|
1154
|
+
type: "closed"
|
|
1155
|
+
});
|
|
1156
|
+
_triggerRef = {
|
|
1157
|
+
current: null
|
|
1158
|
+
};
|
|
1166
1159
|
get state() {
|
|
1167
1160
|
return this._state;
|
|
1168
1161
|
}
|
|
1169
1162
|
get trigger() {
|
|
1170
1163
|
return this._triggerRef;
|
|
1171
1164
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
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
|
-
});
|
|
1165
|
+
setTrigger = (trigger) => {
|
|
1166
|
+
this._triggerRef.current = trigger;
|
|
1167
|
+
};
|
|
1168
|
+
showRowMenu = (rowIndex) => {
|
|
1169
|
+
this._state.value = {
|
|
1170
|
+
type: "row",
|
|
1171
|
+
rowIndex
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1174
|
+
showColumnMenu = (fieldId) => {
|
|
1175
|
+
this._state.value = {
|
|
1176
|
+
type: "column",
|
|
1177
|
+
fieldId
|
|
1178
|
+
};
|
|
1179
|
+
};
|
|
1180
|
+
showColumnCreator = () => {
|
|
1181
|
+
this._state.value = {
|
|
1182
|
+
type: "columnSettings",
|
|
1183
|
+
mode: {
|
|
1184
|
+
type: "create"
|
|
1221
1185
|
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1186
|
+
};
|
|
1187
|
+
};
|
|
1188
|
+
showReferencePanel = (targetId, schemaId) => {
|
|
1189
|
+
this._state.value = {
|
|
1190
|
+
type: "refPanel",
|
|
1191
|
+
targetId,
|
|
1192
|
+
typename: schemaId
|
|
1193
|
+
};
|
|
1194
|
+
};
|
|
1195
|
+
openColumnSettings = () => {
|
|
1196
|
+
if (this._state.value.type === "column") {
|
|
1197
|
+
const fieldId = this._state.value.fieldId;
|
|
1198
|
+
requestAnimationFrame(() => {
|
|
1226
1199
|
this._state.value = {
|
|
1227
|
-
type: "
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1200
|
+
type: "columnSettings",
|
|
1201
|
+
mode: {
|
|
1202
|
+
type: "edit",
|
|
1203
|
+
fieldId
|
|
1204
|
+
}
|
|
1231
1205
|
};
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
});
|
|
1241
|
-
_define_property4(this, "close", () => {
|
|
1242
|
-
this._state.value = {
|
|
1243
|
-
type: "closed"
|
|
1244
|
-
};
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
close = () => {
|
|
1210
|
+
this._state.value = {
|
|
1211
|
+
type: "closed"
|
|
1212
|
+
};
|
|
1213
|
+
};
|
|
1247
1214
|
};
|
|
1248
1215
|
|
|
1249
1216
|
// src/model/table-presentation.ts
|
|
1250
1217
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1251
|
-
import
|
|
1218
|
+
import * as Predicate from "effect/Predicate";
|
|
1252
1219
|
import { Obj as Obj3 } from "@dxos/echo";
|
|
1253
|
-
import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo
|
|
1220
|
+
import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
|
|
1254
1221
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1255
1222
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1256
1223
|
import { mx } from "@dxos/react-ui-theme";
|
|
1257
1224
|
import { VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1258
|
-
function _define_property5(obj, key, value) {
|
|
1259
|
-
if (key in obj) {
|
|
1260
|
-
Object.defineProperty(obj, key, {
|
|
1261
|
-
value,
|
|
1262
|
-
enumerable: true,
|
|
1263
|
-
configurable: true,
|
|
1264
|
-
writable: true
|
|
1265
|
-
});
|
|
1266
|
-
} else {
|
|
1267
|
-
obj[key] = value;
|
|
1268
|
-
}
|
|
1269
|
-
return obj;
|
|
1270
|
-
}
|
|
1271
1225
|
var TablePresentation = class {
|
|
1226
|
+
model;
|
|
1227
|
+
_visibleRange;
|
|
1228
|
+
fieldProjectionCache = /* @__PURE__ */ new Map();
|
|
1229
|
+
constructor(model, _visibleRange = signal5({
|
|
1230
|
+
start: {
|
|
1231
|
+
row: 0,
|
|
1232
|
+
col: 0
|
|
1233
|
+
},
|
|
1234
|
+
end: {
|
|
1235
|
+
row: 0,
|
|
1236
|
+
col: 0
|
|
1237
|
+
}
|
|
1238
|
+
})) {
|
|
1239
|
+
this.model = model;
|
|
1240
|
+
this._visibleRange = _visibleRange;
|
|
1241
|
+
}
|
|
1272
1242
|
getCells(range, plane) {
|
|
1273
1243
|
this.fieldProjectionCache.clear();
|
|
1274
1244
|
let cells;
|
|
@@ -1386,7 +1356,7 @@ var TablePresentation = class {
|
|
|
1386
1356
|
}
|
|
1387
1357
|
return "Object";
|
|
1388
1358
|
};
|
|
1389
|
-
const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
|
|
1359
|
+
const tags = targetArray.map(getLabel).filter(Predicate.isNotNullable).map((title) => {
|
|
1390
1360
|
return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
|
|
1391
1361
|
}).join("");
|
|
1392
1362
|
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
@@ -1396,7 +1366,7 @@ var TablePresentation = class {
|
|
|
1396
1366
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1397
1367
|
if (targetObj) {
|
|
1398
1368
|
const dxn = Obj3.getDXN(targetObj)?.toString();
|
|
1399
|
-
cell.accessoryHtml = `<dx-anchor refId=${dxn} class="dx-button is-6
|
|
1369
|
+
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>`;
|
|
1400
1370
|
}
|
|
1401
1371
|
}
|
|
1402
1372
|
if (props.format === FormatEnum3.Boolean) {
|
|
@@ -1654,23 +1624,6 @@ var TablePresentation = class {
|
|
|
1654
1624
|
}
|
|
1655
1625
|
return cells;
|
|
1656
1626
|
}
|
|
1657
|
-
constructor(model, _visibleRange = signal5({
|
|
1658
|
-
start: {
|
|
1659
|
-
row: 0,
|
|
1660
|
-
col: 0
|
|
1661
|
-
},
|
|
1662
|
-
end: {
|
|
1663
|
-
row: 0,
|
|
1664
|
-
col: 0
|
|
1665
|
-
}
|
|
1666
|
-
})) {
|
|
1667
|
-
_define_property5(this, "model", void 0);
|
|
1668
|
-
_define_property5(this, "_visibleRange", void 0);
|
|
1669
|
-
_define_property5(this, "fieldProjectionCache", void 0);
|
|
1670
|
-
this.model = model;
|
|
1671
|
-
this._visibleRange = _visibleRange;
|
|
1672
|
-
this.fieldProjectionCache = /* @__PURE__ */ new Map();
|
|
1673
|
-
}
|
|
1674
1627
|
};
|
|
1675
1628
|
var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
1676
1629
|
if (!selected) {
|
|
@@ -1699,13 +1652,13 @@ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
|
1699
1652
|
import { effect as effect3 } from "@preact/signals-core";
|
|
1700
1653
|
import orderBy2 from "lodash.orderby";
|
|
1701
1654
|
import { useEffect, useMemo, useState } from "react";
|
|
1702
|
-
import {
|
|
1655
|
+
import { Obj as Obj4 } from "@dxos/echo";
|
|
1703
1656
|
import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
|
|
1704
1657
|
import { isNonNullable } from "@dxos/util";
|
|
1705
1658
|
var useTableModel = ({ view, schema, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
1706
1659
|
var _effect = _useSignals();
|
|
1707
1660
|
try {
|
|
1708
|
-
const selected = useSelected(view &&
|
|
1661
|
+
const selected = useSelected(view && Obj4.getDXN(view).toString(), "multi");
|
|
1709
1662
|
const initialSelection = useMemo(() => selected, [
|
|
1710
1663
|
view
|
|
1711
1664
|
]);
|
|
@@ -1784,12 +1737,12 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
|
|
|
1784
1737
|
|
|
1785
1738
|
// src/hooks/useAddRow.ts
|
|
1786
1739
|
import { useCallback } from "react";
|
|
1787
|
-
import { Obj as
|
|
1740
|
+
import { Obj as Obj5 } from "@dxos/echo";
|
|
1788
1741
|
var useAddRow = ({ space, schema }) => {
|
|
1789
1742
|
return useCallback((data) => {
|
|
1790
1743
|
if (space && schema) {
|
|
1791
1744
|
try {
|
|
1792
|
-
space.db.add(
|
|
1745
|
+
space.db.add(Obj5.make(schema, data ?? {}));
|
|
1793
1746
|
return "final";
|
|
1794
1747
|
} catch (error) {
|
|
1795
1748
|
return "draft";
|
|
@@ -1820,4 +1773,4 @@ export {
|
|
|
1820
1773
|
useTableModel,
|
|
1821
1774
|
useAddRow
|
|
1822
1775
|
};
|
|
1823
|
-
//# sourceMappingURL=chunk-
|
|
1776
|
+
//# sourceMappingURL=chunk-TRR3C5NX.mjs.map
|