@vuu-ui/vuu-data-editing 3.3.1 → 3.3.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.3.1",
2
+ "version": "3.3.2",
3
3
  "description": "Shared data editing APIs and React components for VUU UI",
4
4
  "main": "./src/index.js",
5
5
  "author": "heswell",
@@ -12,13 +12,13 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@salt-ds/core": "1.54.1",
15
- "@vuu-ui/vuu-ui-controls": "3.3.1",
16
- "@vuu-ui/vuu-utils": "3.3.1"
15
+ "@vuu-ui/vuu-ui-controls": "3.3.2",
16
+ "@vuu-ui/vuu-utils": "3.3.2"
17
17
  },
18
18
  "devDependencies": {
19
- "@vuu-ui/vuu-data-types": "3.3.1",
20
- "@vuu-ui/vuu-protocol-types": "3.3.1",
21
- "@vuu-ui/vuu-table-types": "3.3.1"
19
+ "@vuu-ui/vuu-data-types": "3.3.2",
20
+ "@vuu-ui/vuu-protocol-types": "3.3.2",
21
+ "@vuu-ui/vuu-table-types": "3.3.2"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "^19.2.3"
@@ -363,17 +363,7 @@ class EditSession extends EventEmitter {
363
363
  status: "active",
364
364
  sessionDataSource
365
365
  });
366
- if (Object.keys(this.#rowDefaults).length > 0) {
367
- const schema = sessionDataSource.tableSchema;
368
- if (schema) {
369
- const columnNames = new Set(schema.columns.map((c)=>c.name));
370
- const unknown = Object.keys(this.#rowDefaults).filter((key)=>!columnNames.has(key));
371
- if (unknown.length > 0) {
372
- console.warn(`[EditSession] rowDefaults contains columns not in table schema, removing: ${unknown.join(", ")}`);
373
- for (const key of unknown)delete this.#rowDefaults[key];
374
- }
375
- }
376
- }
366
+ this.reconcileWithSessionSchema();
377
367
  return sessionDataSource;
378
368
  } catch (cause) {
379
369
  const error = cause instanceof Error ? cause : new Error(String(cause));
@@ -386,6 +376,21 @@ class EditSession extends EventEmitter {
386
376
  }
387
377
  });
388
378
  }
379
+ reconcileWithSessionSchema() {
380
+ const sessionSchema = this.#sessionDataSource?.tableSchema;
381
+ if (void 0 === sessionSchema) return;
382
+ const columnNames = new Set(sessionSchema.columns.map((c)=>c.name));
383
+ const unknown = Object.keys(this.#rowDefaults).filter((key)=>!columnNames.has(key));
384
+ if (unknown.length > 0) {
385
+ console.warn(`[EditSession] rowDefaults contains columns not in table schema, removing: ${unknown.join(", ")}`);
386
+ for (const key of unknown)delete this.#rowDefaults[key];
387
+ }
388
+ const sourceKey = this.#sourceTableDataSource?.tableSchema?.key;
389
+ if (void 0 !== sourceKey && sourceKey !== sessionSchema.key) {
390
+ console.warn(`[EditSession] source table key '${sourceKey}' differs from session table key '${sessionSchema.key}', discarding pending edits`);
391
+ this.#clearEdits();
392
+ }
393
+ }
389
394
  get dataSource() {
390
395
  return this.#sessionDataSource ?? this.#sourceTableDataSource;
391
396
  }
@@ -85,12 +85,16 @@ const useEditableTable = ({ columns, dataSource: dataSourceProp, deleteMode = "s
85
85
  ]);
86
86
  useEffect(()=>{
87
87
  if (!sessionDataSource) return void setSubscribedSessionDataSource(void 0);
88
- const handleSubscribed = ()=>setSubscribedSessionDataSource(sessionDataSource);
88
+ const handleSubscribed = ()=>{
89
+ editSession.reconcileWithSessionSchema();
90
+ setSubscribedSessionDataSource(sessionDataSource);
91
+ };
89
92
  setSubscribedSessionDataSource(void 0);
90
93
  sessionDataSource.on("subscribed", handleSubscribed);
91
94
  if ("subscribed" === sessionDataSource.status && sessionDataSource.tableSchema) handleSubscribed();
92
95
  return ()=>sessionDataSource.removeListener("subscribed", handleSubscribed);
93
96
  }, [
97
+ editSession,
94
98
  sessionDataSource
95
99
  ]);
96
100
  useEffect(()=>{
@@ -127,10 +131,15 @@ const useEditableTable = ({ columns, dataSource: dataSourceProp, deleteMode = "s
127
131
  const canCancel = "active" === lifecycle.status || "error" === lifecycle.status && "end" === lifecycle.operation;
128
132
  const canSave = canCancel && ("dirty" === editState || "stale" === editState) && 0 === editSession.invalidCount;
129
133
  const isEditSessionReady = isEditMode && void 0 !== sessionDataSource && sessionDataSource === editSession.sessionDataSource && subscribedSessionDataSource === sessionDataSource && "subscribed" === sessionDataSource.status && void 0 !== sessionDataSource.tableSchema;
134
+ const editSchema = subscribedSessionDataSource?.tableSchema;
135
+ const viewSchema = sourceDataSource.tableSchema;
136
+ const columnsDiverge = void 0 !== editSchema && void 0 !== viewSchema && (editSchema.columns.length !== viewSchema.columns.length || editSchema.columns.some((column, index)=>column.name !== viewSchema.columns[index]?.name));
130
137
  return {
131
138
  canCancel,
132
139
  canSave,
140
+ columnsDiverge,
133
141
  dataSource,
142
+ editSchema,
134
143
  editSession,
135
144
  lifecycle,
136
145
  hasSelection: selectionCount > 0,
@@ -74,6 +74,11 @@ export declare class EditSession extends EventEmitter<EditSessionEvents> {
74
74
  isCellEdited(key: string, columnName: string): boolean;
75
75
  undoRowChange(key: string): Promise<void>;
76
76
  begin(copyOption?: CopyOption, sessionType?: SessionType): Promise<DataSource>;
77
+ /**
78
+ * Safe to call repeatedly - schema of a remote session table typically arrives
79
+ * after begin() resolves, so callers re-invoke this once 'subscribed' fires.
80
+ */
81
+ reconcileWithSessionSchema(): void;
77
82
  get dataSource(): EditApi<import("@vuu-ui/vuu-data-types").DataSourceRow<VuuRowDataItemType>> | undefined;
78
83
  get sessionDataSource(): DataSource | undefined;
79
84
  end(saveChanges?: boolean, force?: boolean): Promise<void>;
@@ -27,7 +27,9 @@ export interface EditableTableHookProps {
27
27
  export declare const useEditableTable: ({ columns, dataSource: dataSourceProp, deleteMode, editSessionApi, copyOption, isEditMode, onCancel, onSave, rowDefaults, table, }: EditableTableHookProps) => {
28
28
  canCancel: boolean;
29
29
  canSave: boolean;
30
+ columnsDiverge: boolean;
30
31
  dataSource: DataSource;
32
+ editSchema: import("@vuu-ui/vuu-data-types").TableSchema | undefined;
31
33
  editSession: EditSession;
32
34
  lifecycle: EditLifecycle;
33
35
  hasSelection: boolean;