@dxos/react-ui-table 0.8.4-main.5ea62a8 → 0.8.4-main.ae835ea
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-4K7JPALT.mjs} +5 -5
- package/dist/lib/browser/chunk-4K7JPALT.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RQYXNWWN.mjs → chunk-G7MGPBSR.mjs} +444 -490
- package/dist/lib/browser/chunk-G7MGPBSR.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +132 -283
- 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 -6
- 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-QNDUGIS7.mjs → chunk-LD5JEBA6.mjs} +444 -490
- package/dist/lib/node-esm/chunk-LD5JEBA6.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-K734DJB7.mjs → chunk-MK6OVUF6.mjs} +5 -5
- package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +132 -283
- 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 -6
- 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 +71 -7
- package/dist/types/src/components/Table/Relations.stories.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.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 +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 +2 -2
- 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 +1 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +3 -17
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +3 -3
- 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/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 +51 -51
- package/src/components/Table/DynamicTable.stories.tsx +8 -7
- package/src/components/Table/DynamicTable.tsx +4 -7
- package/src/components/Table/Relations.stories.tsx +119 -11
- package/src/components/Table/Table.stories.tsx +36 -35
- package/src/components/Table/Table.tsx +13 -9
- package/src/components/TableCellEditor/FormCellEditor.tsx +51 -41
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +17 -45
- package/src/components/TableCellEditor/TableCellEditor.tsx +17 -112
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +3 -0
- package/src/components/testing.ts +2 -2
- package/src/hooks/useAddRow.ts +1 -1
- package/src/hooks/useTableModel.ts +1 -1
- package/src/model/modal-controller.ts +0 -28
- package/src/model/table-model.test.ts +16 -6
- package/src/model/table-model.ts +10 -3
- package/src/model/table-presentation.test.ts +19 -17
- package/src/model/table-presentation.ts +4 -5
- package/src/model/table-sorting.ts +15 -6
- package/src/playwright/smoke.spec.ts +3 -3
- package/src/testing/useTestTableModel.ts +7 -4
- package/src/types/schema.ts +4 -4
- package/src/util/dynamic-table.ts +8 -8
- package/src/util/schema.ts +4 -4
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
- package/dist/lib/browser/chunk-RQYXNWWN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QNDUGIS7.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,11 +1,11 @@
|
|
|
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-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 = ({
|
|
31
|
+
var makeDynamicTable = ({ jsonSchema, properties }) => {
|
|
32
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
|
|
@@ -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,7 +275,7 @@ 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";
|
|
@@ -301,20 +302,34 @@ var extractTagIds = (value) => {
|
|
|
301
302
|
// src/model/selection-model.ts
|
|
302
303
|
import { computed, effect, signal } from "@preact/signals-core";
|
|
303
304
|
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
305
|
var SelectionModel = class extends Resource {
|
|
306
|
+
_rows;
|
|
307
|
+
_selectionMode;
|
|
308
|
+
_initialSelection;
|
|
309
|
+
_onSelectionChanged;
|
|
310
|
+
_selection;
|
|
311
|
+
_validSelectedIds = computed(() => {
|
|
312
|
+
const rows = this._rows.value;
|
|
313
|
+
if (!rows) {
|
|
314
|
+
return /* @__PURE__ */ new Set();
|
|
315
|
+
}
|
|
316
|
+
const validIds = new Set(rows.map((row) => row.id));
|
|
317
|
+
return new Set([
|
|
318
|
+
...this._selection.value
|
|
319
|
+
].filter((id) => validIds.has(id)));
|
|
320
|
+
});
|
|
321
|
+
_hasSelection = computed(() => this._validSelectedIds.value.size > 0);
|
|
322
|
+
_allSelected = computed(() => {
|
|
323
|
+
const rows = this._rows.value;
|
|
324
|
+
if (rows.length === 0) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
return rows.every((row) => this._selection.value.has(row.id));
|
|
328
|
+
});
|
|
329
|
+
constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
|
|
330
|
+
super(), this._rows = _rows, this._selectionMode = _selectionMode, this._initialSelection = _initialSelection, this._onSelectionChanged = _onSelectionChanged;
|
|
331
|
+
this._selection = signal(new Set(this._initialSelection));
|
|
332
|
+
}
|
|
318
333
|
async _open() {
|
|
319
334
|
const selectionWatcher = effect(() => {
|
|
320
335
|
touch(this._selection.value);
|
|
@@ -337,80 +352,80 @@ var SelectionModel = class extends Resource {
|
|
|
337
352
|
get selectionMode() {
|
|
338
353
|
return this._selectionMode;
|
|
339
354
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
getSelectedRows = () => {
|
|
356
|
+
const selectedIds = this._validSelectedIds.value;
|
|
357
|
+
return this._rows.value.filter((row) => selectedIds.has(row.id));
|
|
358
|
+
};
|
|
359
|
+
isRowIndexSelected = (rowIndex) => {
|
|
360
|
+
const row = this._rows.value[rowIndex];
|
|
361
|
+
return this._selection.value.has(row.id);
|
|
362
|
+
};
|
|
363
|
+
isObjectSelected = (object) => {
|
|
364
|
+
return this._selection.value.has(object.id);
|
|
365
|
+
};
|
|
366
|
+
//
|
|
367
|
+
// Manipulation
|
|
368
|
+
//
|
|
369
|
+
toggleSelectionForRowIndex = (rowIndex) => {
|
|
370
|
+
const row = this._rows.value[rowIndex];
|
|
371
|
+
const newSelection = new Set(this._selection.value);
|
|
372
|
+
if (newSelection.has(row.id)) {
|
|
373
|
+
newSelection.delete(row.id);
|
|
374
|
+
} else {
|
|
375
|
+
if (this._selectionMode === "single") {
|
|
376
|
+
newSelection.clear();
|
|
357
377
|
}
|
|
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);
|
|
378
|
+
newSelection.add(row.id);
|
|
379
|
+
}
|
|
380
|
+
this._selection.value = newSelection;
|
|
381
|
+
};
|
|
382
|
+
setSelection = (mode) => {
|
|
383
|
+
switch (mode) {
|
|
384
|
+
case "all": {
|
|
385
|
+
this._selection.value = new Set(this._rows.value.map((row) => row.id));
|
|
386
|
+
break;
|
|
377
387
|
}
|
|
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
|
-
}
|
|
388
|
+
case "none": {
|
|
389
|
+
this._selection.value = /* @__PURE__ */ new Set();
|
|
390
|
+
break;
|
|
389
391
|
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
}
|
|
392
|
+
}
|
|
393
|
+
};
|
|
393
394
|
};
|
|
394
395
|
|
|
395
396
|
// src/model/table-sorting.ts
|
|
396
397
|
import { computed as computed2, signal as signal2 } from "@preact/signals-core";
|
|
397
398
|
import orderBy from "lodash.orderby";
|
|
398
|
-
import { FormatEnum, TypeEnum, getValue } from "@dxos/echo
|
|
399
|
+
import { FormatEnum, TypeEnum, getValue } from "@dxos/echo/internal";
|
|
399
400
|
import { formatForDisplay } from "@dxos/react-ui-form";
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
401
|
+
var TableSorting = class {
|
|
402
|
+
_view;
|
|
403
|
+
_projection;
|
|
404
|
+
_displayToDataIndex = /* @__PURE__ */ new Map();
|
|
405
|
+
_rows;
|
|
406
|
+
_localSort = signal2(void 0);
|
|
407
|
+
_isDirty;
|
|
408
|
+
sortedRows;
|
|
409
|
+
constructor(rows, _view, _projection) {
|
|
410
|
+
this._view = _view;
|
|
411
|
+
this._projection = _projection;
|
|
412
|
+
this._rows = rows;
|
|
413
|
+
this._isDirty = computed2(() => {
|
|
414
|
+
const local = this._localSort.value;
|
|
415
|
+
const viewSort = this._view.sort?.[0];
|
|
416
|
+
if (local?.type === "cleared") {
|
|
417
|
+
return viewSort !== void 0;
|
|
418
|
+
}
|
|
419
|
+
if (local?.type === "active") {
|
|
420
|
+
if (!viewSort) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
407
426
|
});
|
|
408
|
-
|
|
409
|
-
obj[key] = value;
|
|
427
|
+
this.sortedRows = this.initialiseSortedRows();
|
|
410
428
|
}
|
|
411
|
-
return obj;
|
|
412
|
-
}
|
|
413
|
-
var TableSorting = class {
|
|
414
429
|
/**
|
|
415
430
|
* @reactive
|
|
416
431
|
* @returns Local sort if present, falls back to view sort.
|
|
@@ -423,7 +438,7 @@ var TableSorting = class {
|
|
|
423
438
|
if (local?.type === "active") {
|
|
424
439
|
return local.sort;
|
|
425
440
|
}
|
|
426
|
-
return this._view.
|
|
441
|
+
return this._view.sort?.[0];
|
|
427
442
|
}
|
|
428
443
|
/**
|
|
429
444
|
* @reactive
|
|
@@ -467,11 +482,11 @@ var TableSorting = class {
|
|
|
467
482
|
save() {
|
|
468
483
|
if (this._localSort.value !== void 0) {
|
|
469
484
|
if (this._localSort.value.type === "active") {
|
|
470
|
-
this._view.
|
|
485
|
+
this._view.sort = [
|
|
471
486
|
this._localSort.value.sort
|
|
472
487
|
];
|
|
473
488
|
} else {
|
|
474
|
-
this._view.
|
|
489
|
+
this._view.sort = [];
|
|
475
490
|
}
|
|
476
491
|
this._localSort.value = void 0;
|
|
477
492
|
}
|
|
@@ -546,51 +561,9 @@ var TableSorting = class {
|
|
|
546
561
|
value
|
|
547
562
|
});
|
|
548
563
|
}
|
|
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.query.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
564
|
};
|
|
579
565
|
|
|
580
566
|
// 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
567
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
595
568
|
var defaultFeatures = {
|
|
596
569
|
selection: {
|
|
@@ -601,6 +574,69 @@ var defaultFeatures = {
|
|
|
601
574
|
schemaEditable: false
|
|
602
575
|
};
|
|
603
576
|
var TableModel = class extends Resource2 {
|
|
577
|
+
_view;
|
|
578
|
+
_projection;
|
|
579
|
+
_table;
|
|
580
|
+
_visibleRange = signal3({
|
|
581
|
+
start: {
|
|
582
|
+
row: 0,
|
|
583
|
+
col: 0
|
|
584
|
+
},
|
|
585
|
+
end: {
|
|
586
|
+
row: 0,
|
|
587
|
+
col: 0
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
_onInsertRow;
|
|
591
|
+
_onDeleteRows;
|
|
592
|
+
_onDeleteColumn;
|
|
593
|
+
_onCellUpdate;
|
|
594
|
+
_onRowOrderChange;
|
|
595
|
+
_onRowAction;
|
|
596
|
+
_rowActions;
|
|
597
|
+
_features;
|
|
598
|
+
_rows = signal3([]);
|
|
599
|
+
_draftRows = signal3([]);
|
|
600
|
+
_sorting;
|
|
601
|
+
_pinnedRows;
|
|
602
|
+
_selection;
|
|
603
|
+
_columnMeta;
|
|
604
|
+
constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
605
|
+
top: [],
|
|
606
|
+
bottom: []
|
|
607
|
+
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
608
|
+
super();
|
|
609
|
+
this._view = view;
|
|
610
|
+
this._projection = projection ?? new ProjectionModel2(schema, view.projection);
|
|
611
|
+
this._projection.normalizeView();
|
|
612
|
+
this._features = {
|
|
613
|
+
...defaultFeatures,
|
|
614
|
+
...features
|
|
615
|
+
};
|
|
616
|
+
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
617
|
+
F: __dxlog_file,
|
|
618
|
+
L: 149,
|
|
619
|
+
S: this,
|
|
620
|
+
A: [
|
|
621
|
+
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
622
|
+
"'Single selection is not compatible with editable tables.'"
|
|
623
|
+
]
|
|
624
|
+
});
|
|
625
|
+
this._sorting = new TableSorting(this._rows, this._view, this._projection);
|
|
626
|
+
if (sorting.length > 0) {
|
|
627
|
+
const [sort] = sorting;
|
|
628
|
+
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
629
|
+
}
|
|
630
|
+
this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
|
|
631
|
+
this._pinnedRows = pinnedRows;
|
|
632
|
+
this._rowActions = rowActions;
|
|
633
|
+
this._onInsertRow = onInsertRow;
|
|
634
|
+
this._onDeleteRows = onDeleteRows;
|
|
635
|
+
this._onDeleteColumn = onDeleteColumn;
|
|
636
|
+
this._onCellUpdate = onCellUpdate;
|
|
637
|
+
this._onRowOrderChange = onRowOrderChange;
|
|
638
|
+
this._onRowAction = onRowAction;
|
|
639
|
+
}
|
|
604
640
|
get id() {
|
|
605
641
|
return fullyQualifiedId(this._view);
|
|
606
642
|
}
|
|
@@ -610,7 +646,7 @@ var TableModel = class extends Resource2 {
|
|
|
610
646
|
get table() {
|
|
611
647
|
invariant(this._table, "Model not initialized", {
|
|
612
648
|
F: __dxlog_file,
|
|
613
|
-
L:
|
|
649
|
+
L: 187,
|
|
614
650
|
S: this,
|
|
615
651
|
A: [
|
|
616
652
|
"this._table",
|
|
@@ -649,7 +685,7 @@ var TableModel = class extends Resource2 {
|
|
|
649
685
|
get columnMeta() {
|
|
650
686
|
invariant(this._columnMeta, void 0, {
|
|
651
687
|
F: __dxlog_file,
|
|
652
|
-
L:
|
|
688
|
+
L: 226,
|
|
653
689
|
S: this,
|
|
654
690
|
A: [
|
|
655
691
|
"this._columnMeta",
|
|
@@ -675,7 +711,7 @@ var TableModel = class extends Resource2 {
|
|
|
675
711
|
const presentation = this._view.presentation.target ?? await this._view.presentation.load();
|
|
676
712
|
invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
|
|
677
713
|
F: __dxlog_file,
|
|
678
|
-
L:
|
|
714
|
+
L: 249,
|
|
679
715
|
S: this,
|
|
680
716
|
A: [
|
|
681
717
|
"Obj.instanceOf(Table.Table, presentation)",
|
|
@@ -743,6 +779,17 @@ var TableModel = class extends Resource2 {
|
|
|
743
779
|
});
|
|
744
780
|
this._ctx.onDispose(draftRowsWatcher);
|
|
745
781
|
}
|
|
782
|
+
//
|
|
783
|
+
// Data
|
|
784
|
+
//
|
|
785
|
+
setRows = (obj) => {
|
|
786
|
+
this._rows.value = obj;
|
|
787
|
+
};
|
|
788
|
+
getRowCount = () => this._rows.value.length;
|
|
789
|
+
/**
|
|
790
|
+
* @reactive
|
|
791
|
+
*/
|
|
792
|
+
getDraftRowCount = () => this._draftRows.value.length;
|
|
746
793
|
// TODO(ZaymonFC): Return .value instead of exposing the signal.
|
|
747
794
|
get draftRows() {
|
|
748
795
|
return this._draftRows;
|
|
@@ -761,6 +808,14 @@ var TableModel = class extends Resource2 {
|
|
|
761
808
|
const validationErrors = draftRow.validationErrors || [];
|
|
762
809
|
return validationErrors.some((error) => error.path === fieldPath);
|
|
763
810
|
}
|
|
811
|
+
getColumnCount = () => this._projection?.fields.length ?? 0;
|
|
812
|
+
insertRow = () => {
|
|
813
|
+
const result = this._onInsertRow?.();
|
|
814
|
+
if (result === "draft" && this._draftRows.value.length === 0) {
|
|
815
|
+
this.createDraftRow();
|
|
816
|
+
}
|
|
817
|
+
return result ?? "final";
|
|
818
|
+
};
|
|
764
819
|
createDraftRow() {
|
|
765
820
|
if (!this._projection) {
|
|
766
821
|
return;
|
|
@@ -800,6 +855,187 @@ var TableModel = class extends Resource2 {
|
|
|
800
855
|
const schema = toEffectSchema(this._projection.baseSchema);
|
|
801
856
|
return validateSchema(schema, data) || [];
|
|
802
857
|
}
|
|
858
|
+
commitDraftRow = (draftRowIndex) => {
|
|
859
|
+
if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
const draftRow = this._draftRows.value[draftRowIndex];
|
|
863
|
+
if (!draftRow.valid) {
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
const insertRowResult = this._onInsertRow?.(draftRow.data);
|
|
867
|
+
if (insertRowResult === "final") {
|
|
868
|
+
const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
|
|
869
|
+
this._draftRows.value = newDraftRows;
|
|
870
|
+
}
|
|
871
|
+
return insertRowResult === "final";
|
|
872
|
+
};
|
|
873
|
+
deleteRow = (rowIndex) => {
|
|
874
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
875
|
+
const obj = this._rows.value[row];
|
|
876
|
+
const objectsToDelete = [];
|
|
877
|
+
if (this.features.selection.enabled && this._selection.hasSelection.value) {
|
|
878
|
+
const selectedRows = this._selection.getSelectedRows();
|
|
879
|
+
objectsToDelete.push(...selectedRows);
|
|
880
|
+
} else {
|
|
881
|
+
objectsToDelete.push(obj);
|
|
882
|
+
}
|
|
883
|
+
this._onDeleteRows?.(row, objectsToDelete);
|
|
884
|
+
};
|
|
885
|
+
handleRowAction = (actionId, rowIndex) => {
|
|
886
|
+
if (!this._onRowAction) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
890
|
+
const data = this._rows.value[row];
|
|
891
|
+
if (data) {
|
|
892
|
+
this._onRowAction(actionId, data);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
getCellData = (cell) => {
|
|
896
|
+
const { col, row, plane } = cell;
|
|
897
|
+
const fields = this._projection?.fields ?? [];
|
|
898
|
+
if (col < 0 || col >= fields.length) {
|
|
899
|
+
return void 0;
|
|
900
|
+
}
|
|
901
|
+
const field = fields[col];
|
|
902
|
+
let value;
|
|
903
|
+
if (plane === "frozenRowsEnd") {
|
|
904
|
+
if (row >= 0 && row < this._draftRows.value.length) {
|
|
905
|
+
value = getValue2(this._draftRows.value[row].data, field.path);
|
|
906
|
+
} else {
|
|
907
|
+
return void 0;
|
|
908
|
+
}
|
|
909
|
+
} else {
|
|
910
|
+
const dataIndex = this._sorting.getDataIndex(row);
|
|
911
|
+
value = getValue2(this._rows.value[dataIndex], field.path);
|
|
912
|
+
}
|
|
913
|
+
if (value == null) {
|
|
914
|
+
return "";
|
|
915
|
+
}
|
|
916
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
917
|
+
switch (props.format) {
|
|
918
|
+
case FormatEnum2.Ref: {
|
|
919
|
+
if (!field.referencePath) {
|
|
920
|
+
return "";
|
|
921
|
+
}
|
|
922
|
+
return getValue2(value.target, field.referencePath);
|
|
923
|
+
}
|
|
924
|
+
default: {
|
|
925
|
+
return formatForEditing({
|
|
926
|
+
type: props.type,
|
|
927
|
+
format: props.format,
|
|
928
|
+
value
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
validateCellData = async ({ col, row, plane }, value) => {
|
|
934
|
+
const fields = this._projection?.fields ?? [];
|
|
935
|
+
if (col < 0 || col >= fields.length) {
|
|
936
|
+
return {
|
|
937
|
+
valid: false,
|
|
938
|
+
error: "Invalid column index"
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
const field = fields[col];
|
|
942
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
943
|
+
const transformedValue = editorTextToCellValue(props, value);
|
|
944
|
+
const isDraftRow = plane === "frozenRowsEnd";
|
|
945
|
+
if (isDraftRow) {
|
|
946
|
+
const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
|
|
947
|
+
if (isInvalidDraftRowIndex) {
|
|
948
|
+
return {
|
|
949
|
+
valid: false,
|
|
950
|
+
error: "Invalid draft row index"
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
const draftRow = this._draftRows.value[row];
|
|
954
|
+
const snapshot = {
|
|
955
|
+
...draftRow.data
|
|
956
|
+
};
|
|
957
|
+
setValue(snapshot, field.path, transformedValue);
|
|
958
|
+
const validationErrors = this.validateDraftRowData(snapshot);
|
|
959
|
+
if (validationErrors.length > 0) {
|
|
960
|
+
const error = validationErrors.find((err) => err.path === field.path);
|
|
961
|
+
if (error) {
|
|
962
|
+
return {
|
|
963
|
+
valid: false,
|
|
964
|
+
error: error.message
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
valid: true
|
|
970
|
+
};
|
|
971
|
+
} else {
|
|
972
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
973
|
+
const currentRow = this._rows.value[rowIdx];
|
|
974
|
+
invariant(currentRow, "Invalid row index", {
|
|
975
|
+
F: __dxlog_file,
|
|
976
|
+
L: 522,
|
|
977
|
+
S: this,
|
|
978
|
+
A: [
|
|
979
|
+
"currentRow",
|
|
980
|
+
"'Invalid row index'"
|
|
981
|
+
]
|
|
982
|
+
});
|
|
983
|
+
const snapshot = getSnapshot(currentRow);
|
|
984
|
+
setValue(snapshot, field.path, transformedValue);
|
|
985
|
+
const schema = getSchema(currentRow);
|
|
986
|
+
invariant(schema, void 0, {
|
|
987
|
+
F: __dxlog_file,
|
|
988
|
+
L: 528,
|
|
989
|
+
S: this,
|
|
990
|
+
A: [
|
|
991
|
+
"schema",
|
|
992
|
+
""
|
|
993
|
+
]
|
|
994
|
+
});
|
|
995
|
+
const validationResult = validateSchema(schema, snapshot);
|
|
996
|
+
if (validationResult && validationResult.length > 0) {
|
|
997
|
+
const error = validationResult[0];
|
|
998
|
+
invariant(error.path === field.path, void 0, {
|
|
999
|
+
F: __dxlog_file,
|
|
1000
|
+
L: 533,
|
|
1001
|
+
S: this,
|
|
1002
|
+
A: [
|
|
1003
|
+
"error.path === field.path",
|
|
1004
|
+
""
|
|
1005
|
+
]
|
|
1006
|
+
});
|
|
1007
|
+
return {
|
|
1008
|
+
valid: false,
|
|
1009
|
+
error: error.message
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
return {
|
|
1013
|
+
valid: true
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
setCellData = (cell, value) => {
|
|
1018
|
+
const { col, row, plane } = cell;
|
|
1019
|
+
const fields = this._projection?.fields ?? [];
|
|
1020
|
+
if (col < 0 || col >= fields.length) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
const field = fields[col];
|
|
1024
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
1025
|
+
const transformedValue = editorTextToCellValue(props, value);
|
|
1026
|
+
if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
if (plane === "frozenRowsEnd") {
|
|
1030
|
+
if (row >= 0 && row < this._draftRows.value.length) {
|
|
1031
|
+
setValue(this._draftRows.value[row].data, field.path, transformedValue);
|
|
1032
|
+
this.validateDraftRow(row);
|
|
1033
|
+
}
|
|
1034
|
+
} else {
|
|
1035
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
1036
|
+
setValue(this._rows.value[rowIdx], field.path, transformedValue);
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
803
1039
|
/**
|
|
804
1040
|
* Updates a cell's value using a transform function.
|
|
805
1041
|
* @param {DxGridPlanePosition} position - The position of the cell to update.
|
|
@@ -880,239 +1116,6 @@ var TableModel = class extends Resource2 {
|
|
|
880
1116
|
saveView() {
|
|
881
1117
|
this._sorting.save();
|
|
882
1118
|
}
|
|
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: 515,
|
|
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: 521,
|
|
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: 526,
|
|
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: 142,
|
|
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
1119
|
};
|
|
1117
1120
|
var editorTextToCellValue = (props, value) => {
|
|
1118
1121
|
switch (props.format) {
|
|
@@ -1147,128 +1150,96 @@ var editorTextToCellValue = (props, value) => {
|
|
|
1147
1150
|
|
|
1148
1151
|
// src/model/modal-controller.ts
|
|
1149
1152
|
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
1153
|
var ModalController = class {
|
|
1154
|
+
_state = signal4({
|
|
1155
|
+
type: "closed"
|
|
1156
|
+
});
|
|
1157
|
+
_triggerRef = {
|
|
1158
|
+
current: null
|
|
1159
|
+
};
|
|
1166
1160
|
get state() {
|
|
1167
1161
|
return this._state;
|
|
1168
1162
|
}
|
|
1169
1163
|
get trigger() {
|
|
1170
1164
|
return this._triggerRef;
|
|
1171
1165
|
}
|
|
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
|
-
});
|
|
1166
|
+
setTrigger = (trigger) => {
|
|
1167
|
+
this._triggerRef.current = trigger;
|
|
1168
|
+
};
|
|
1169
|
+
showRowMenu = (rowIndex) => {
|
|
1170
|
+
this._state.value = {
|
|
1171
|
+
type: "row",
|
|
1172
|
+
rowIndex
|
|
1173
|
+
};
|
|
1174
|
+
};
|
|
1175
|
+
showColumnMenu = (fieldId) => {
|
|
1176
|
+
this._state.value = {
|
|
1177
|
+
type: "column",
|
|
1178
|
+
fieldId
|
|
1179
|
+
};
|
|
1180
|
+
};
|
|
1181
|
+
showColumnCreator = () => {
|
|
1182
|
+
this._state.value = {
|
|
1183
|
+
type: "columnSettings",
|
|
1184
|
+
mode: {
|
|
1185
|
+
type: "create"
|
|
1221
1186
|
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1187
|
+
};
|
|
1188
|
+
};
|
|
1189
|
+
showReferencePanel = (targetId, schemaId) => {
|
|
1190
|
+
this._state.value = {
|
|
1191
|
+
type: "refPanel",
|
|
1192
|
+
targetId,
|
|
1193
|
+
typename: schemaId
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
openColumnSettings = () => {
|
|
1197
|
+
if (this._state.value.type === "column") {
|
|
1198
|
+
const fieldId = this._state.value.fieldId;
|
|
1199
|
+
requestAnimationFrame(() => {
|
|
1226
1200
|
this._state.value = {
|
|
1227
|
-
type: "
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1201
|
+
type: "columnSettings",
|
|
1202
|
+
mode: {
|
|
1203
|
+
type: "edit",
|
|
1204
|
+
fieldId
|
|
1205
|
+
}
|
|
1231
1206
|
};
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
});
|
|
1241
|
-
_define_property4(this, "close", () => {
|
|
1242
|
-
this._state.value = {
|
|
1243
|
-
type: "closed"
|
|
1244
|
-
};
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
close = () => {
|
|
1211
|
+
this._state.value = {
|
|
1212
|
+
type: "closed"
|
|
1213
|
+
};
|
|
1214
|
+
};
|
|
1247
1215
|
};
|
|
1248
1216
|
|
|
1249
1217
|
// src/model/table-presentation.ts
|
|
1250
1218
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1251
|
-
import
|
|
1219
|
+
import * as Predicate from "effect/Predicate";
|
|
1252
1220
|
import { Obj as Obj3 } from "@dxos/echo";
|
|
1253
|
-
import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo
|
|
1221
|
+
import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
|
|
1254
1222
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1255
1223
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1256
1224
|
import { mx } from "@dxos/react-ui-theme";
|
|
1257
1225
|
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
1226
|
var TablePresentation = class {
|
|
1227
|
+
model;
|
|
1228
|
+
_visibleRange;
|
|
1229
|
+
fieldProjectionCache = /* @__PURE__ */ new Map();
|
|
1230
|
+
constructor(model, _visibleRange = signal5({
|
|
1231
|
+
start: {
|
|
1232
|
+
row: 0,
|
|
1233
|
+
col: 0
|
|
1234
|
+
},
|
|
1235
|
+
end: {
|
|
1236
|
+
row: 0,
|
|
1237
|
+
col: 0
|
|
1238
|
+
}
|
|
1239
|
+
})) {
|
|
1240
|
+
this.model = model;
|
|
1241
|
+
this._visibleRange = _visibleRange;
|
|
1242
|
+
}
|
|
1272
1243
|
getCells(range, plane) {
|
|
1273
1244
|
this.fieldProjectionCache.clear();
|
|
1274
1245
|
let cells;
|
|
@@ -1386,7 +1357,7 @@ var TablePresentation = class {
|
|
|
1386
1357
|
}
|
|
1387
1358
|
return "Object";
|
|
1388
1359
|
};
|
|
1389
|
-
const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
|
|
1360
|
+
const tags = targetArray.map(getLabel).filter(Predicate.isNotNullable).map((title) => {
|
|
1390
1361
|
return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
|
|
1391
1362
|
}).join("");
|
|
1392
1363
|
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
@@ -1396,7 +1367,7 @@ var TablePresentation = class {
|
|
|
1396
1367
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1397
1368
|
if (targetObj) {
|
|
1398
1369
|
const dxn = Obj3.getDXN(targetObj)?.toString();
|
|
1399
|
-
cell.accessoryHtml = `<dx-
|
|
1370
|
+
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
1371
|
}
|
|
1401
1372
|
}
|
|
1402
1373
|
if (props.format === FormatEnum3.Boolean) {
|
|
@@ -1654,23 +1625,6 @@ var TablePresentation = class {
|
|
|
1654
1625
|
}
|
|
1655
1626
|
return cells;
|
|
1656
1627
|
}
|
|
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
1628
|
};
|
|
1675
1629
|
var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
1676
1630
|
if (!selected) {
|
|
@@ -1820,4 +1774,4 @@ export {
|
|
|
1820
1774
|
useTableModel,
|
|
1821
1775
|
useAddRow
|
|
1822
1776
|
};
|
|
1823
|
-
//# sourceMappingURL=chunk-
|
|
1777
|
+
//# sourceMappingURL=chunk-LD5JEBA6.mjs.map
|