@revisium/schema-toolkit-ui 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6920,6 +6920,88 @@ const SYSTEM_FIELD_IDS = new Set([
6920
6920
  "schemaHash"
6921
6921
  ]);
6922
6922
 
6923
+ //#endregion
6924
+ //#region src/table-editor/TableEditor/model/SchemaContext.ts
6925
+ const DATA_FIELD = "data";
6926
+ function stripDataFieldPrefix(field) {
6927
+ const prefix = `${DATA_FIELD}.`;
6928
+ if (field.startsWith(prefix)) return field.slice(prefix.length);
6929
+ if (field === DATA_FIELD) return "";
6930
+ return field;
6931
+ }
6932
+ const SYSTEM_REF_SCHEMAS = {
6933
+ [_revisium_schema_toolkit.SystemSchemaIds.File]: _revisium_schema_toolkit.fileSchema,
6934
+ [_revisium_schema_toolkit.SystemSchemaIds.RowId]: _revisium_schema_toolkit.rowIdSchema,
6935
+ [_revisium_schema_toolkit.SystemSchemaIds.RowCreatedAt]: _revisium_schema_toolkit.rowCreatedAtSchema,
6936
+ [_revisium_schema_toolkit.SystemSchemaIds.RowCreatedId]: _revisium_schema_toolkit.rowCreatedIdSchema,
6937
+ [_revisium_schema_toolkit.SystemSchemaIds.RowVersionId]: _revisium_schema_toolkit.rowVersionIdSchema,
6938
+ [_revisium_schema_toolkit.SystemSchemaIds.RowPublishedAt]: _revisium_schema_toolkit.rowPublishedAtSchema,
6939
+ [_revisium_schema_toolkit.SystemSchemaIds.RowUpdatedAt]: _revisium_schema_toolkit.rowUpdatedAtSchema,
6940
+ [_revisium_schema_toolkit.SystemSchemaIds.RowHash]: _revisium_schema_toolkit.rowHashSchema,
6941
+ [_revisium_schema_toolkit.SystemSchemaIds.RowSchemaHash]: _revisium_schema_toolkit.rowSchemaHashSchema
6942
+ };
6943
+ function wrapDataSchema(dataSchema) {
6944
+ return {
6945
+ type: "object",
6946
+ properties: { [DATA_FIELD]: dataSchema },
6947
+ additionalProperties: false,
6948
+ required: [DATA_FIELD]
6949
+ };
6950
+ }
6951
+ function buildRowSchema(wrappedDataSchema) {
6952
+ const systemProperties = {};
6953
+ for (const sf of SYSTEM_FIELDS) systemProperties[sf.id] = { $ref: sf.ref };
6954
+ return {
6955
+ type: "object",
6956
+ properties: {
6957
+ ...systemProperties,
6958
+ ...wrappedDataSchema.properties
6959
+ },
6960
+ additionalProperties: false,
6961
+ required: [...Object.keys(systemProperties), ...wrappedDataSchema.required]
6962
+ };
6963
+ }
6964
+ var SchemaContext = class {
6965
+ _allColumns = [];
6966
+ _dataSchema = null;
6967
+ _wrappedDataSchema = null;
6968
+ _fullRefSchemas = {};
6969
+ _rootNode = null;
6970
+ get allColumns() {
6971
+ return this._allColumns;
6972
+ }
6973
+ get sortableFields() {
6974
+ return this._allColumns.filter((col) => !col.isDeprecated && col.fieldType !== FilterFieldType.File);
6975
+ }
6976
+ get filterableFields() {
6977
+ return this.sortableFields;
6978
+ }
6979
+ get dataSchema() {
6980
+ return this._dataSchema;
6981
+ }
6982
+ get wrappedDataSchema() {
6983
+ return this._wrappedDataSchema;
6984
+ }
6985
+ get fullRefSchemas() {
6986
+ return this._fullRefSchemas;
6987
+ }
6988
+ get rootNode() {
6989
+ return this._rootNode;
6990
+ }
6991
+ init(dataSchema, refSchemas) {
6992
+ this._dataSchema = dataSchema;
6993
+ this._fullRefSchemas = {
6994
+ ...SYSTEM_REF_SCHEMAS,
6995
+ ...refSchemas
6996
+ };
6997
+ const wrapped = wrapDataSchema(dataSchema);
6998
+ this._wrappedDataSchema = wrapped;
6999
+ const rowSchema = buildRowSchema(wrapped);
7000
+ this._rootNode = new _revisium_schema_toolkit.SchemaParser().parse(rowSchema, this._fullRefSchemas);
7001
+ this._allColumns = extractColumns(this._rootNode);
7002
+ }
7003
+ };
7004
+
6923
7005
  //#endregion
6924
7006
  //#region src/table-editor/Columns/model/extractColumns.ts
6925
7007
  const NODE_TYPE_TO_FIELD_TYPE = {
@@ -6963,15 +7045,20 @@ function resolveRefColumn(child, fieldPath) {
6963
7045
  const refValue = child.ref();
6964
7046
  if (!refValue) return null;
6965
7047
  const systemDef = SYSTEM_FIELD_BY_REF.get(refValue);
6966
- if (systemDef) return {
6967
- field: systemDef.id,
6968
- label: systemDef.label,
6969
- fieldType: systemDef.fieldType,
6970
- isSystem: true,
6971
- systemFieldId: systemDef.id,
6972
- isDeprecated: child.metadata().deprecated ?? false,
6973
- hasFormula: child.hasFormula()
6974
- };
7048
+ if (systemDef) {
7049
+ const isDeprecated = child.metadata().deprecated ?? false;
7050
+ const hasFormula = child.hasFormula();
7051
+ return {
7052
+ field: systemDef.id,
7053
+ label: systemDef.label,
7054
+ fieldType: systemDef.fieldType,
7055
+ isSystem: true,
7056
+ systemFieldId: systemDef.id,
7057
+ isDeprecated,
7058
+ hasFormula,
7059
+ isSortable: !isDeprecated && !hasFormula
7060
+ };
7061
+ }
6975
7062
  if (refValue === _revisium_schema_toolkit.SystemSchemaIds.File) return resolveFileRefColumns(child, fieldPath);
6976
7063
  return null;
6977
7064
  }
@@ -6984,14 +7071,22 @@ function resolveFileRefColumns(child, fieldPath) {
6984
7071
  }
6985
7072
  return result;
6986
7073
  }
7074
+ function stripDataPrefix(fieldPath) {
7075
+ if (fieldPath === DATA_FIELD) return DATA_FIELD;
7076
+ if (fieldPath.startsWith(`${DATA_FIELD}.`)) return fieldPath.slice(DATA_FIELD.length + 1);
7077
+ return fieldPath;
7078
+ }
6987
7079
  function createColumn(fieldPath, child, fieldType) {
7080
+ const isDeprecated = child.metadata().deprecated ?? false;
7081
+ const hasFormula = child.hasFormula();
6988
7082
  return {
6989
7083
  field: fieldPath,
6990
- label: fieldPath,
7084
+ label: stripDataPrefix(fieldPath),
6991
7085
  fieldType,
6992
7086
  isSystem: false,
6993
- isDeprecated: child.metadata().deprecated ?? false,
6994
- hasFormula: child.hasFormula()
7087
+ isDeprecated,
7088
+ hasFormula,
7089
+ isSortable: !isDeprecated && !hasFormula && fieldType !== FilterFieldType.File
6995
7090
  };
6996
7091
  }
6997
7092
 
@@ -7078,6 +7173,10 @@ var ColumnsModel = class {
7078
7173
  const visible = this._visibleFieldSet;
7079
7174
  return this._allColumns.filter((col) => !visible.has(col.field) && !col.isSystem);
7080
7175
  }
7176
+ get availableFieldsToInsert() {
7177
+ const visible = this._visibleFieldSet;
7178
+ return this._allColumns.filter((col) => !visible.has(col.field));
7179
+ }
7081
7180
  get availableSystemFieldsToAdd() {
7082
7181
  const visible = this._visibleFieldSet;
7083
7182
  return this._allColumns.filter((col) => !visible.has(col.field) && col.isSystem);
@@ -7458,11 +7557,9 @@ var ColumnsModel = class {
7458
7557
  return this._pinnedColumns.get(neighbor) === pin;
7459
7558
  }
7460
7559
  _toViewField(field) {
7461
- if (this._columnLookup.get(field)?.isSystem) return field;
7462
- return `data.${field}`;
7560
+ return field;
7463
7561
  }
7464
7562
  _fromViewField(viewField) {
7465
- if (viewField.startsWith("data.")) return viewField.slice(5);
7466
7563
  return viewField;
7467
7564
  }
7468
7565
  _resolveWidthUntracked(field) {
@@ -7981,7 +8078,7 @@ function buildConditionClause(condition) {
7981
8078
  searchType: condition.searchType || "plain"
7982
8079
  } };
7983
8080
  return { data: {
7984
- path: condition.field,
8081
+ path: stripDataFieldPrefix(condition.field),
7985
8082
  search: condition.value,
7986
8083
  searchLanguage: condition.searchLanguage || "simple",
7987
8084
  searchType: condition.searchType || "plain"
@@ -7990,7 +8087,7 @@ function buildConditionClause(condition) {
7990
8087
  const opClause = buildOperatorClause(condition.operator, condition.value, condition.fieldType);
7991
8088
  if (SYSTEM_FIELD_IDS.has(condition.field)) return { [condition.field]: opClause };
7992
8089
  return { data: {
7993
- path: condition.field,
8090
+ path: stripDataFieldPrefix(condition.field),
7994
8091
  ...opClause
7995
8092
  } };
7996
8093
  }
@@ -9316,22 +9413,18 @@ var SortModel = class {
9316
9413
  if (firstAvailable) this.addSort(firstAvailable.field);
9317
9414
  }
9318
9415
  serializeToViewSorts() {
9319
- const lookup = this._fieldLookup;
9320
- return this.sorts.map((sort) => {
9321
- return {
9322
- field: lookup.get(sort.field)?.isSystem ? sort.field : `data.${sort.field}`,
9323
- direction: sort.direction
9324
- };
9325
- });
9416
+ return this.sorts.map((sort) => ({
9417
+ field: sort.field,
9418
+ direction: sort.direction
9419
+ }));
9326
9420
  }
9327
9421
  applyViewSorts(viewSorts) {
9328
9422
  const lookup = this._fieldLookup;
9329
9423
  const sorts = [];
9330
9424
  for (const vs of viewSorts) {
9331
- const field = vs.field.startsWith("data.") ? vs.field.slice(5) : vs.field;
9332
9425
  const direction = vs.direction === "desc" ? "desc" : "asc";
9333
- if (lookup.has(field)) sorts.push({
9334
- field,
9426
+ if (lookup.has(vs.field)) sorts.push({
9427
+ field: vs.field,
9335
9428
  direction
9336
9429
  });
9337
9430
  }
@@ -12188,8 +12281,8 @@ const InsertColumnSubmenu = ({ label, valuePrefix, availableFields, onSelect })
12188
12281
  //#region src/table-editor/Table/ui/Header/ColumnHeaderMenu.tsx
12189
12282
  const ColumnHeaderMenu = (0, mobx_react_lite.observer)(({ column, columnsModel, sortModel, filterModel, onCopyPath, onClose }) => {
12190
12283
  const canRemove = columnsModel.canRemoveColumn;
12191
- const availableFields = columnsModel.availableFieldsToAdd;
12192
- const hasAvailableFields = availableFields.length > 0;
12284
+ const insertableFields = columnsModel.availableFieldsToInsert;
12285
+ const hasInsertableFields = insertableFields.length > 0;
12193
12286
  const canMove = columnsModel.canMoveLeft(column.field) || columnsModel.canMoveRight(column.field);
12194
12287
  const isPinned = columnsModel.isPinned(column.field);
12195
12288
  const canPinLeft = columnsModel.canPinLeft(column.field);
@@ -12227,11 +12320,11 @@ const ColumnHeaderMenu = (0, mobx_react_lite.observer)(({ column, columnsModel,
12227
12320
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_chakra_ui_react.Menu.Content, {
12228
12321
  minW: "180px",
12229
12322
  children: [
12230
- sortModel && !column.hasFormula && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortSubmenu, {
12323
+ sortModel && column.isSortable && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortSubmenu, {
12231
12324
  field: column.field,
12232
12325
  sortModel
12233
12326
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_chakra_ui_react.Menu.Separator, {})] }),
12234
- filterModel && !column.hasFormula && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_chakra_ui_react.Menu.Item, {
12327
+ filterModel && column.isSortable && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_chakra_ui_react.Menu.Item, {
12235
12328
  value: "add-filter",
12236
12329
  onClick: handleAddFilter,
12237
12330
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_icons_lu.LuFilter, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_chakra_ui_react.Text, { children: "Add filter" })]
@@ -12257,17 +12350,17 @@ const ColumnHeaderMenu = (0, mobx_react_lite.observer)(({ column, columnsModel,
12257
12350
  }),
12258
12351
  (canPinLeft || canPinRight) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_chakra_ui_react.Menu.Separator, {})
12259
12352
  ] }),
12260
- hasAvailableFields && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
12353
+ hasInsertableFields && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
12261
12354
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InsertColumnSubmenu, {
12262
12355
  label: "Insert before",
12263
12356
  valuePrefix: "before",
12264
- availableFields,
12357
+ availableFields: insertableFields,
12265
12358
  onSelect: handleInsertBefore
12266
12359
  }),
12267
12360
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InsertColumnSubmenu, {
12268
12361
  label: "Insert after",
12269
12362
  valuePrefix: "after",
12270
- availableFields,
12363
+ availableFields: insertableFields,
12271
12364
  onSelect: handleInsertAfter
12272
12365
  }),
12273
12366
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_chakra_ui_react.Menu.Separator, {})
@@ -12385,11 +12478,11 @@ const ColumnHeader = (0, mobx_react_lite.observer)(({ column, columnsModel, sort
12385
12478
  field: column.field,
12386
12479
  columnsModel
12387
12480
  }),
12388
- filterModel && !column.hasFormula && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FilterIndicator, {
12481
+ filterModel && column.isSortable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FilterIndicator, {
12389
12482
  field: column.field,
12390
12483
  filterModel
12391
12484
  }),
12392
- sortModel && !column.hasFormula && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortIndicator, {
12485
+ sortModel && column.isSortable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortIndicator, {
12393
12486
  field: column.field,
12394
12487
  sortModel
12395
12488
  })
@@ -13505,67 +13598,6 @@ var ViewSettingsBadgeModel = class {
13505
13598
  }
13506
13599
  };
13507
13600
 
13508
- //#endregion
13509
- //#region src/table-editor/TableEditor/model/SchemaContext.ts
13510
- const SYSTEM_REF_SCHEMAS = {
13511
- [_revisium_schema_toolkit.SystemSchemaIds.File]: _revisium_schema_toolkit.fileSchema,
13512
- [_revisium_schema_toolkit.SystemSchemaIds.RowId]: _revisium_schema_toolkit.rowIdSchema,
13513
- [_revisium_schema_toolkit.SystemSchemaIds.RowCreatedAt]: _revisium_schema_toolkit.rowCreatedAtSchema,
13514
- [_revisium_schema_toolkit.SystemSchemaIds.RowCreatedId]: _revisium_schema_toolkit.rowCreatedIdSchema,
13515
- [_revisium_schema_toolkit.SystemSchemaIds.RowVersionId]: _revisium_schema_toolkit.rowVersionIdSchema,
13516
- [_revisium_schema_toolkit.SystemSchemaIds.RowPublishedAt]: _revisium_schema_toolkit.rowPublishedAtSchema,
13517
- [_revisium_schema_toolkit.SystemSchemaIds.RowUpdatedAt]: _revisium_schema_toolkit.rowUpdatedAtSchema,
13518
- [_revisium_schema_toolkit.SystemSchemaIds.RowHash]: _revisium_schema_toolkit.rowHashSchema,
13519
- [_revisium_schema_toolkit.SystemSchemaIds.RowSchemaHash]: _revisium_schema_toolkit.rowSchemaHashSchema
13520
- };
13521
- function buildRowSchema(dataSchema) {
13522
- const systemProperties = {};
13523
- for (const sf of SYSTEM_FIELDS) systemProperties[sf.id] = { $ref: sf.ref };
13524
- return {
13525
- type: "object",
13526
- properties: {
13527
- ...systemProperties,
13528
- ...dataSchema.properties
13529
- },
13530
- additionalProperties: false,
13531
- required: [...Object.keys(systemProperties), ...dataSchema.required ?? []]
13532
- };
13533
- }
13534
- var SchemaContext = class {
13535
- _allColumns = [];
13536
- _dataSchema = null;
13537
- _fullRefSchemas = {};
13538
- _rootNode = null;
13539
- get allColumns() {
13540
- return this._allColumns;
13541
- }
13542
- get sortableFields() {
13543
- return this._allColumns.filter((col) => !col.isDeprecated && col.fieldType !== FilterFieldType.File);
13544
- }
13545
- get filterableFields() {
13546
- return this.sortableFields;
13547
- }
13548
- get dataSchema() {
13549
- return this._dataSchema;
13550
- }
13551
- get fullRefSchemas() {
13552
- return this._fullRefSchemas;
13553
- }
13554
- get rootNode() {
13555
- return this._rootNode;
13556
- }
13557
- init(dataSchema, refSchemas) {
13558
- this._dataSchema = dataSchema;
13559
- this._fullRefSchemas = {
13560
- ...SYSTEM_REF_SCHEMAS,
13561
- ...refSchemas
13562
- };
13563
- const rowSchema = buildRowSchema(dataSchema);
13564
- this._rootNode = new _revisium_schema_toolkit.SchemaParser().parse(rowSchema, this._fullRefSchemas);
13565
- this._allColumns = extractColumns(this._rootNode);
13566
- }
13567
- };
13568
-
13569
13601
  //#endregion
13570
13602
  //#region src/table-editor/TableEditor/model/TableEditorCore.ts
13571
13603
  const DEFAULT_PAGE_SIZE = 50;
@@ -13712,7 +13744,10 @@ var TableEditorCore = class {
13712
13744
  _buildQuery(after = null) {
13713
13745
  return {
13714
13746
  where: this.filters.hasActiveFilters ? this.filters.buildCurrentWhereClause() : null,
13715
- orderBy: this.sorts.serializeToViewSorts(),
13747
+ orderBy: this.sorts.serializeToViewSorts().map((s) => ({
13748
+ field: stripDataFieldPrefix(s.field),
13749
+ direction: s.direction
13750
+ })),
13716
13751
  search: this.search.debouncedQuery,
13717
13752
  first: this._pageSize,
13718
13753
  after
@@ -13747,14 +13782,14 @@ var TableEditorCore = class {
13747
13782
  this._updateNavigationContext();
13748
13783
  }
13749
13784
  _createRowVMs(rawRows) {
13750
- const dataSchema = this._schemaContext.dataSchema;
13751
- if (!dataSchema) return [];
13785
+ const wrappedSchema = this._schemaContext.wrappedDataSchema;
13786
+ if (!wrappedSchema) return [];
13752
13787
  const tableModel = (0, _revisium_schema_toolkit.createTableModel)({
13753
13788
  tableId: this._tableId,
13754
- schema: dataSchema,
13789
+ schema: wrappedSchema,
13755
13790
  rows: rawRows.map((r) => ({
13756
13791
  rowId: r.rowId,
13757
- data: r.data
13792
+ data: { data: r.data }
13758
13793
  })),
13759
13794
  refSchemas: this._schemaContext.fullRefSchemas
13760
13795
  });
@@ -13768,10 +13803,14 @@ var TableEditorCore = class {
13768
13803
  id: rawRow.rowId
13769
13804
  };
13770
13805
  }
13806
+ _toPatchField(field) {
13807
+ return stripDataFieldPrefix(field);
13808
+ }
13771
13809
  async _commitCell(rowId, field, value, previousValue) {
13810
+ const patchField = this._toPatchField(field);
13772
13811
  const result = (await this._dataSource.patchCells([{
13773
13812
  rowId,
13774
- field,
13813
+ field: patchField,
13775
13814
  value
13776
13815
  }]))[0];
13777
13816
  if (result && !result.ok) (0, mobx.runInAction)(() => {
@@ -13851,7 +13890,7 @@ var MockDataSource = class {
13851
13890
  static createRow(rowId, data, systemFields) {
13852
13891
  const row = {
13853
13892
  rowId,
13854
- data: { ...data }
13893
+ data: data && typeof data === "object" && !Array.isArray(data) ? { ...data } : data
13855
13894
  };
13856
13895
  if (systemFields) row.systemFields = systemFields;
13857
13896
  return row;
@@ -13870,16 +13909,23 @@ var MockDataSource = class {
13870
13909
  let rows = [...this._allRows];
13871
13910
  if (query.search) {
13872
13911
  const lower = query.search.toLowerCase();
13873
- rows = rows.filter((row) => Object.values(row.data).some((val) => typeof val === "string" && val.toLowerCase().includes(lower)));
13912
+ rows = rows.filter((row) => {
13913
+ const data = row.data;
13914
+ if (data && typeof data === "object") return Object.values(data).some((val) => typeof val === "string" && val.toLowerCase().includes(lower));
13915
+ if (typeof data === "string") return data.toLowerCase().includes(lower);
13916
+ return false;
13917
+ });
13874
13918
  }
13875
13919
  if (query.orderBy.length > 0) {
13876
13920
  const firstOrder = query.orderBy[0];
13877
13921
  if (firstOrder) {
13878
- const field = firstOrder.field.startsWith("data.") ? firstOrder.field.slice(5) : firstOrder.field;
13922
+ const field = firstOrder.field;
13879
13923
  const dir = firstOrder.direction === "desc" ? -1 : 1;
13880
13924
  rows.sort((a, b) => {
13881
- const aVal = a.data[field];
13882
- const bVal = b.data[field];
13925
+ const aData = a.data;
13926
+ const bData = b.data;
13927
+ const aVal = aData?.[field];
13928
+ const bVal = bData?.[field];
13883
13929
  if (aVal === bVal) return 0;
13884
13930
  if (aVal == null) return 1;
13885
13931
  if (bVal == null) return -1;
@@ -13915,7 +13961,7 @@ var MockDataSource = class {
13915
13961
  error: "Mock failure"
13916
13962
  };
13917
13963
  const row = this._allRows.find((r) => r.rowId === patch.rowId);
13918
- if (row) row.data[patch.field] = patch.value;
13964
+ if (row?.data && typeof row.data === "object" && !Array.isArray(row.data)) row.data[patch.field] = patch.value;
13919
13965
  return {
13920
13966
  rowId: patch.rowId,
13921
13967
  field: patch.field,