@agile-team/mach-table 0.36.0 → 0.38.0
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/README.md +23 -18
- package/dist/adapter.cjs +1 -1
- package/dist/adapter.d.cts +6 -2
- package/dist/adapter.d.ts +6 -2
- package/dist/adapter.js +1 -1
- package/dist/analysis.cjs +1 -1
- package/dist/analysis.d.cts +2 -2
- package/dist/analysis.d.ts +2 -2
- package/dist/analysis.js +1 -1
- package/dist/{api-Di5SQHAP.d.cts → api-Bgcy7aRd.d.cts} +7 -2
- package/dist/{api-Di5SQHAP.d.ts → api-Bgcy7aRd.d.ts} +7 -2
- package/dist/business.cjs +1 -1
- package/dist/business.d.cts +1 -26
- package/dist/business.d.ts +1 -26
- package/dist/business.js +1 -1
- package/dist/{configuration-nh5lvWDe.d.ts → configuration-B5dSDN9d.d.ts} +1 -1
- package/dist/{configuration-DlRW86iR.d.cts → configuration-BVWcsdGm.d.cts} +1 -1
- package/dist/import.cjs +1 -1
- package/dist/import.d.cts +1 -1
- package/dist/import.d.ts +1 -1
- package/dist/import.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +4 -13
- package/dist/index.d.ts +4 -13
- package/dist/index.js +5 -5
- package/dist/mach-table.css +1 -1
- package/dist/multi-range.d.cts +1 -1
- package/dist/multi-range.d.ts +1 -1
- package/dist/ordering.cjs +1 -1
- package/dist/ordering.d.cts +1 -1
- package/dist/ordering.d.ts +1 -1
- package/dist/ordering.js +1 -1
- package/dist/preferences.d.cts +1 -1
- package/dist/preferences.d.ts +1 -1
- package/dist/server-side.cjs +1 -1
- package/dist/server-side.d.cts +1 -1
- package/dist/server-side.d.ts +1 -1
- package/dist/server-side.js +1 -1
- package/dist/{shared-BusgJSf4.d.ts → shared-CLEc9O2p.d.ts} +1 -1
- package/dist/{shared-O6pPO8H8.d.cts → shared-DfLrRGYY.d.cts} +1 -1
- package/dist/workbench.cjs +1 -1
- package/dist/workbench.css +1 -1
- package/dist/workbench.d.cts +3 -3
- package/dist/workbench.d.ts +3 -3
- package/dist/workbench.js +1 -1
- package/dist/worker.d.cts +2 -2
- package/dist/worker.d.ts +2 -2
- package/package.json +2 -2
- package/dist/cachedDictionary-C26hMT22.d.cts +0 -30
- package/dist/cachedDictionary-C26hMT22.d.ts +0 -30
|
@@ -28,6 +28,8 @@ declare class Column<TData = any> {
|
|
|
28
28
|
parentGroup: ColumnGroup<TData> | null;
|
|
29
29
|
level: number;
|
|
30
30
|
isDetailToggle: boolean;
|
|
31
|
+
/** Generated UI column excluded from the business export schema. */
|
|
32
|
+
isAutoRowNumber?: true;
|
|
31
33
|
constructor(id: string, colDef: ColDef<TData>);
|
|
32
34
|
get sortable(): boolean;
|
|
33
35
|
get resizable(): boolean;
|
|
@@ -219,7 +221,7 @@ interface SelectEditorOption {
|
|
|
219
221
|
interface SelectEditorParams {
|
|
220
222
|
/** Primitive options kept for concise same-label/same-value selects. */
|
|
221
223
|
values?: readonly (string | number)[];
|
|
222
|
-
/** Label/value options
|
|
224
|
+
/** Label/value options when the stored value differs from its display text. */
|
|
223
225
|
options?: readonly SelectEditorOption[];
|
|
224
226
|
}
|
|
225
227
|
interface SetFilterParams {
|
|
@@ -932,6 +934,8 @@ interface GridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
932
934
|
loadTreeChildren?: (params: TreeDataLoadParams<TData>) => Promise<readonly TData[]>;
|
|
933
935
|
autoCheckedChildren?: boolean;
|
|
934
936
|
defaultExpandAll?: boolean;
|
|
937
|
+
/** Add a row-number column when no index column is declared. Enabled by default by the Vue and React components. */
|
|
938
|
+
rowNumber?: boolean;
|
|
935
939
|
indexOffset?: number;
|
|
936
940
|
/** Apply flat local row moves automatically (default true). False emits intent for server-controlled ordering. */
|
|
937
941
|
applyRowDrag?: boolean;
|
|
@@ -1051,6 +1055,7 @@ interface ResolvedGridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
1051
1055
|
loadTreeChildren?: (params: TreeDataLoadParams<TData>) => Promise<readonly TData[]>;
|
|
1052
1056
|
autoCheckedChildren: boolean;
|
|
1053
1057
|
defaultExpandAll: boolean;
|
|
1058
|
+
rowNumber: boolean;
|
|
1054
1059
|
indexOffset: number;
|
|
1055
1060
|
applyRowDrag: boolean;
|
|
1056
1061
|
rowDragPolicy?: RowDragPolicy<TData>;
|
|
@@ -1435,4 +1440,4 @@ interface GridApi<TData = any> {
|
|
|
1435
1440
|
isDestroyed(): boolean;
|
|
1436
1441
|
}
|
|
1437
1442
|
|
|
1438
|
-
export { type
|
|
1443
|
+
export { type ContextMenuItem as $, type AdvancedFilterModel as A, type ApplyGridStateOptions as B, type ColDef as C, type CellAlign as D, type CellClassParams as E, type FilterType as F, type GridFeature as G, type CellClassRule as H, type ImportMatrixOptions as I, type CellClickEvent as J, type CellContextMenuEvent as K, type CellDoubleClickEvent as L, type CellEditingStartedEvent as M, type CellEditingStoppedEvent as N, type CellEditorFactory as O, type CellEditorParams as P, type CellRendererOutput as Q, type CellStyleRule as R, type SortModel as S, type CellValueChangedEvent as T, type ColDefOrGroup as U, type ColumnLayoutMode as V, type ColumnMovedEvent as W, type ColumnResizedEvent as X, type ColumnStatus as Y, type ColumnVisibilityChangedEvent as Z, type ColumnWorkbenchItem as _, type GridCellRange as a, type PaginationChangedEvent as a$, type ContextMenuParams as a0, type CsvExportParams as a1, DEFAULT_LOCALE as a2, type DatasourceMode as a3, type DateFilterCondition as a4, type DateFilterMatch as a5, type DetailRowRendererParams as a6, type DetailToggledEvent as a7, type DirtyStateChangedEvent as a8, type DomLayoutMode as a9, type GridHierarchyApi as aA, type GridIoApi as aB, type GridPaginationApi as aC, type GridPerformanceSnapshot as aD, type GridPersistenceOptions as aE, type GridReadyEvent as aF, type GridRowsApi as aG, type GridSelectionApi as aH, type GridSortingApi as aI, type GridStateApi as aJ, type GridStateSection as aK, type GridUpdateSchedulerSnapshot as aL, type GridViewApi as aM, type HeaderComponentParams as aN, type ICellEditor as aO, type ICellRendererResult as aP, type ImportCsvOptions as aQ, type InfiniteGetRowsParams as aR, LOCALE_EN as aS, type MachTableLocale as aT, type MachTableLocaleKey as aU, type MatrixExportParams as aV, type ModelUpdatedEvent as aW, type NumberFilterCondition as aX, type NumberFilterMatch as aY, type OverlayContent as aZ, type OverlayTemplate as a_, EVENT_TYPES as aa, type EditableIndicator as ab, type EditableParams as ac, type EventHandlers as ad, type FilterChangedEvent as ae, type GetRowHeightParams as af, type GridAsyncOptions as ag, type GridBatchSaveResult as ah, type GridCellChange as ai, type GridColumnsApi as aj, type GridDataProcessorColumn as ak, type GridDataProcessorRequest as al, type GridDataProcessorResult as am, type GridDataProcessorRow as an, type GridDatasource as ao, type GridDiagnosticError as ap, type GridDiagnostics as aq, type GridDiagnosticsApi as ar, type GridEditType as as, type GridEditingApi as at, type GridErrorCode as au, type GridErrorEvent as av, type GridEventBase as aw, type GridEventMap as ax, type GridFeatureContext as ay, type GridFilteringApi as az, type GridApi as b, type PaginationConfig as b0, type PinnedDirection as b1, type PrintOptions as b2, type RangeSelectionChangedEvent as b3, type RefreshCellsParams as b4, type RemoteBlockCacheSnapshot as b5, type ResolvedGridOptions as b6, type RowClickEvent as b7, type RowDragEndEvent as b8, type RowDragIntent as b9, type ThemeMode as bA, type TooltipParams as bB, type TreeChildrenLoadFailedEvent as bC, type TreeChildrenLoadedEvent as bD, type TreeDataLoadParams as bE, type ValueFormatterParams as bF, type ValueGetterParams as bG, type ValueInputSource as bH, type ValueOutputTarget as bI, type ValueParserParams as bJ, type ValueSerializerParams as bK, type ValueSetterParams as bL, type WatermarkConfig as bM, formatText as bN, formatTwo as bO, isColDefGroup as bP, matchLocaleKey as bQ, type RowDragPolicy as ba, type RowEditChange as bb, type RowEditValidationParams as bc, type RowEditValidationResult as bd, type RowEditingStartedEvent as be, type RowEditingStoppedEvent as bf, type RowNode as bg, type RowSelectionMode as bh, type RowStyleParams as bi, type RowStyleRule as bj, type RowTone as bk, type RowTransaction as bl, type SaveChangeIssue as bm, type SaveChangesResult as bn, type SelectEditorOption as bo, type SelectEditorParams as bp, type SelectionChangedEvent as bq, type SetFilterCondition as br, type SetFilterParams as bs, type SortChangedEvent as bt, type SortDirection as bu, type SortModelItem as bv, type StatusBarConfig as bw, type StatusBarPanel as bx, type TextFilterCondition as by, type TextFilterMatch as bz, type GridOptions as c, type GridDataProcessor as d, type GridComponents as e, type GridState as f, type GridStateStore as g, type FilterModel as h, type FieldPath as i, type GridEventType as j, type SaveChangesHandler as k, type ColumnFilter as l, type AdvancedFilterCondition as m, type AdvancedFilterNode as n, type AdvancedFilterGroup as o, type ColDefGroup as p, type GridStateInput as q, type GridSize as r, type CellRendererParams as s, type GridChange as t, type CellRendererFn as u, type FieldPathValue as v, type SaveChangeConflict as w, type ColumnState as x, type ActionPolicy as y, type ActionPolicyContext as z };
|
package/dist/business.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var f=(r,e)=>{for(var u in e)c(r,u,{get:e[u],enumerable:!0})},p=(r,e,u,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of y(e))!S.call(r,t)&&t!==u&&c(r,t,{get:()=>e[t],enumerable:!(a=T(e,t))||a.enumerable});return r};var g=r=>p(c({},"__esModule",{value:!0}),r);var k={};f(k,{summarizeRows:()=>d});module.exports=g(k);function s(r){if(typeof r!="number"||!Number.isFinite(r)||Math.abs(r)>Number.MAX_SAFE_INTEGER)throw new TypeError("[MachTable] Summary arithmetic requires finite numbers within the safe range; provide numeric for decimal strings or exact arithmetic.");return r}function m(r){if(r!=null&&typeof r.then=="function")throw Promise.resolve(r).catch(()=>{}),new TypeError("[MachTable] Summary numeric callbacks must return synchronous values.");return r}var V={zero:()=>0,add:(r,e)=>s(r+s(e)),divide:(r,e)=>e===0?null:s(r/e)};function l(r,e){let u=new Map;for(let a of r)(a.kind==="sum"||a.kind==="ratio")&&u.set(a.id,{value:m(e.zero()),denominator:m(e.zero())});return{rowCount:0,totals:u}}function b(r,e,u,a){e.rowCount++;for(let t of u){if(t.kind==="count"||t.kind==="none")continue;let n=e.totals.get(t.id),o=t.kind==="sum"?t.value(r):t.numerator(r);if(o!=null&&o!==""&&(n.value=m(a.add(n.value,o))),t.kind==="ratio"){let i=t.denominator(r);i!=null&&i!==""&&(n.denominator=m(a.add(n.denominator,i)))}}}function w(r,e,u){let a=Object.create(null);for(let t of e)if(t.kind!=="none")if(t.kind==="count")a[t.id]=r.rowCount;else{let n=r.totals.get(t.id);a[t.id]=t.kind==="sum"?n.value:m(u.divide(n.value,n.denominator))}return a}function d(r,e){let u=new Set;for(let n of e.metrics){if(!n.id||u.has(n.id))throw new TypeError("[MachTable] Summary metric IDs must be non-empty and unique.");u.add(n.id)}let a=e.numeric??V,t=new Map;e.groupBy||t.set(void 0,l(e.metrics,a));for(let n of r){let o=e.groupBy?.(n);if(e.groupBy&&typeof o!="string"&&(typeof o!="number"||!Number.isFinite(o)))throw new TypeError("[MachTable] Summary group keys must be strings or finite numbers.");let i=t.get(o);i||(i=l(e.metrics,a),t.set(o,i)),b(n,i,e.metrics,a)}return{scope:e.scope,groups:[...t].map(([n,o])=>({key:n,rowCount:o.rowCount,values:w(o,e.metrics,a)}))}}0&&(module.exports={summarizeRows});
|
package/dist/business.d.cts
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import { V as ValueOutputTarget, C as ColDef } from './api-Di5SQHAP.cjs';
|
|
2
|
-
import { D as DictionaryKey } from './cachedDictionary-C26hMT22.cjs';
|
|
3
|
-
|
|
4
|
-
type DictionaryDisplay = "code" | "label" | "code-label";
|
|
5
|
-
type ColumnKey = DictionaryKey | boolean;
|
|
6
|
-
interface ColumnEntry<TKey extends ColumnKey> {
|
|
7
|
-
value: TKey;
|
|
8
|
-
label: string;
|
|
9
|
-
}
|
|
10
|
-
/** Structural adapter for an existing provider; this helper never loads or caches remote data. */
|
|
11
|
-
interface DictionaryColumnSource<TKey extends ColumnKey = ColumnKey> {
|
|
12
|
-
get(key: TKey): string | undefined;
|
|
13
|
-
}
|
|
14
|
-
interface DictionaryColumnOptions<TKey extends ColumnKey = ColumnKey> {
|
|
15
|
-
/** Immutable snapshot for reverse parsing. Replace its identity when options change. */
|
|
16
|
-
options?: readonly ColumnEntry<TKey>[] | (() => readonly ColumnEntry<TKey>[]);
|
|
17
|
-
display?: DictionaryDisplay;
|
|
18
|
-
/** Array display/output only; input strings are never split implicitly. */
|
|
19
|
-
separator?: string;
|
|
20
|
-
/** Omitted targets preserve the original code and its type. */
|
|
21
|
-
output?: Partial<Record<ValueOutputTarget, DictionaryDisplay>>;
|
|
22
|
-
}
|
|
23
|
-
/** Explicit, synchronous dictionary presentation and typed IO; no existing defaults are changed. */
|
|
24
|
-
declare function createDictionaryColumn<TData = any, TKey extends ColumnKey = ColumnKey>(source: DictionaryColumnSource<TKey>, config?: DictionaryColumnOptions<TKey>): Partial<ColDef<TData>>;
|
|
25
|
-
|
|
26
1
|
type SummaryScope = "page" | "selected" | "query";
|
|
27
2
|
type SemanticSummaryMetric<TData> = {
|
|
28
3
|
id: string;
|
|
@@ -65,4 +40,4 @@ interface SemanticSummaryResult<TValue = number> {
|
|
|
65
40
|
/** O(rows × metrics) local aggregation, with explicit scope and no implicit currency/unit mixing. */
|
|
66
41
|
declare function summarizeRows<TData, TValue = number>(rows: readonly TData[], options: SemanticSummaryOptions<TData, TValue>): SemanticSummaryResult<TValue>;
|
|
67
42
|
|
|
68
|
-
export { type
|
|
43
|
+
export { type SemanticSummaryMetric, type SemanticSummaryOptions, type SemanticSummaryResult, type SummaryNumericStrategy, type SummaryScope, summarizeRows };
|
package/dist/business.d.ts
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import { V as ValueOutputTarget, C as ColDef } from './api-Di5SQHAP.js';
|
|
2
|
-
import { D as DictionaryKey } from './cachedDictionary-C26hMT22.js';
|
|
3
|
-
|
|
4
|
-
type DictionaryDisplay = "code" | "label" | "code-label";
|
|
5
|
-
type ColumnKey = DictionaryKey | boolean;
|
|
6
|
-
interface ColumnEntry<TKey extends ColumnKey> {
|
|
7
|
-
value: TKey;
|
|
8
|
-
label: string;
|
|
9
|
-
}
|
|
10
|
-
/** Structural adapter for an existing provider; this helper never loads or caches remote data. */
|
|
11
|
-
interface DictionaryColumnSource<TKey extends ColumnKey = ColumnKey> {
|
|
12
|
-
get(key: TKey): string | undefined;
|
|
13
|
-
}
|
|
14
|
-
interface DictionaryColumnOptions<TKey extends ColumnKey = ColumnKey> {
|
|
15
|
-
/** Immutable snapshot for reverse parsing. Replace its identity when options change. */
|
|
16
|
-
options?: readonly ColumnEntry<TKey>[] | (() => readonly ColumnEntry<TKey>[]);
|
|
17
|
-
display?: DictionaryDisplay;
|
|
18
|
-
/** Array display/output only; input strings are never split implicitly. */
|
|
19
|
-
separator?: string;
|
|
20
|
-
/** Omitted targets preserve the original code and its type. */
|
|
21
|
-
output?: Partial<Record<ValueOutputTarget, DictionaryDisplay>>;
|
|
22
|
-
}
|
|
23
|
-
/** Explicit, synchronous dictionary presentation and typed IO; no existing defaults are changed. */
|
|
24
|
-
declare function createDictionaryColumn<TData = any, TKey extends ColumnKey = ColumnKey>(source: DictionaryColumnSource<TKey>, config?: DictionaryColumnOptions<TKey>): Partial<ColDef<TData>>;
|
|
25
|
-
|
|
26
1
|
type SummaryScope = "page" | "selected" | "query";
|
|
27
2
|
type SemanticSummaryMetric<TData> = {
|
|
28
3
|
id: string;
|
|
@@ -65,4 +40,4 @@ interface SemanticSummaryResult<TValue = number> {
|
|
|
65
40
|
/** O(rows × metrics) local aggregation, with explicit scope and no implicit currency/unit mixing. */
|
|
66
41
|
declare function summarizeRows<TData, TValue = number>(rows: readonly TData[], options: SemanticSummaryOptions<TData, TValue>): SemanticSummaryResult<TValue>;
|
|
67
42
|
|
|
68
|
-
export { type
|
|
43
|
+
export { type SemanticSummaryMetric, type SemanticSummaryOptions, type SemanticSummaryResult, type SummaryNumericStrategy, type SummaryScope, summarizeRows };
|
package/dist/business.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function c(e){if(typeof e!="number"||!Number.isFinite(e)||Math.abs(e)>Number.MAX_SAFE_INTEGER)throw new TypeError("[MachTable] Summary arithmetic requires finite numbers within the safe range; provide numeric for decimal strings or exact arithmetic.");return e}function m(e){if(e!=null&&typeof e.then=="function")throw Promise.resolve(e).catch(()=>{}),new TypeError("[MachTable] Summary numeric callbacks must return synchronous values.");return e}var l={zero:()=>0,add:(e,r)=>c(e+c(r)),divide:(e,r)=>r===0?null:c(e/r)};function s(e,r){let o=new Map;for(let n of e)(n.kind==="sum"||n.kind==="ratio")&&o.set(n.id,{value:m(r.zero()),denominator:m(r.zero())});return{rowCount:0,totals:o}}function d(e,r,o,n){r.rowCount++;for(let t of o){if(t.kind==="count"||t.kind==="none")continue;let a=r.totals.get(t.id),u=t.kind==="sum"?t.value(e):t.numerator(e);if(u!=null&&u!==""&&(a.value=m(n.add(a.value,u))),t.kind==="ratio"){let i=t.denominator(e);i!=null&&i!==""&&(a.denominator=m(n.add(a.denominator,i)))}}}function T(e,r,o){let n=Object.create(null);for(let t of r)if(t.kind!=="none")if(t.kind==="count")n[t.id]=e.rowCount;else{let a=e.totals.get(t.id);n[t.id]=t.kind==="sum"?a.value:m(o.divide(a.value,a.denominator))}return n}function y(e,r){let o=new Set;for(let a of r.metrics){if(!a.id||o.has(a.id))throw new TypeError("[MachTable] Summary metric IDs must be non-empty and unique.");o.add(a.id)}let n=r.numeric??l,t=new Map;r.groupBy||t.set(void 0,s(r.metrics,n));for(let a of e){let u=r.groupBy?.(a);if(r.groupBy&&typeof u!="string"&&(typeof u!="number"||!Number.isFinite(u)))throw new TypeError("[MachTable] Summary group keys must be strings or finite numbers.");let i=t.get(u);i||(i=s(r.metrics,n),t.set(u,i)),d(a,i,r.metrics,n)}return{scope:r.scope,groups:[...t].map(([a,u])=>({key:a,rowCount:u.rowCount,values:T(u,r.metrics,n)}))}}export{y as summarizeRows};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-
|
|
1
|
+
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-Bgcy7aRd.js';
|
|
2
2
|
|
|
3
3
|
type MachTablePresetSelection = string | readonly string[] | false;
|
|
4
4
|
type MachTableInstanceOptionKey = "rowData" | "columnDefs" | "datasource" | "loading" | "error" | "initialState" | "persistence" | "components" | "columnTypes";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-
|
|
1
|
+
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-Bgcy7aRd.cjs';
|
|
2
2
|
|
|
3
3
|
type MachTablePresetSelection = string | readonly string[] | false;
|
|
4
4
|
type MachTableInstanceOptionKey = "rowData" | "columnDefs" | "datasource" | "loading" | "error" | "initialState" | "persistence" | "components" | "columnTypes";
|
package/dist/import.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var M=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var re=(e,r)=>{for(var o in r)M(e,o,{get:r[o],enumerable:!0})},te=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Z(r))!ee.call(e,t)&&t!==o&&M(e,t,{get:()=>r[t],enumerable:!(n=Y(r,t))||n.enumerable});return e};var oe=e=>te(M({},"__esModule",{value:!0}),e);var we={};re(we,{createImportPlan:()=>K});module.exports=oe(we);var ne=new Set(["__proto__","prototype","constructor"]),A=new Map;function _(e){if(typeof e!="string"||e.length===0)return null;let r=A.get(e);if(r!==void 0)return r;let o=e.split("."),n=o.every(t=>t.length>0&&!ne.has(t))?o:null;return e.length<=1024&&(A.size>=256&&A.delete(A.keys().next().value),A.set(e,n)),n}function B(e,r){if(e==null)return;let o=_(r);if(!o)return;let n=e;for(let t of o){if(n==null)return;n=n[t]}return n}function U(e,r,o){if(e==null)return!1;let n=_(r);if(!n)return!1;let t=e;for(let s=0;s<n.length-1;s++){if(typeof t!="object"&&typeof t!="function"||t===null)return!1;t[n[s]]==null&&(t[n[s]]={}),t=t[n[s]]}return typeof t!="object"&&typeof t!="function"||t===null?!1:(t[n[n.length-1]]=o,!0)}var se=Symbol.for("mach-table.import.v1");function j(e){let r=e[se];if(!r)throw new TypeError("Import plans require a MachTable GridApi");return r}function ie(e){return Object.entries(Object.getOwnPropertyDescriptors(e)).filter(([r,o])=>{if(r==="length"&&Array.isArray(e)||!o.enumerable)return!1;if(o.get||o.set||["__proto__","prototype","constructor"].includes(r))throw new TypeError("Unsafe import property");return!0})}function N(e){let r=new Set,o=0,n=(t,s)=>{if(++o>2e5||s>32)throw new RangeError("Import snapshot exceeds its value/depth limit");if(t==null||["string","number","boolean","bigint","undefined"].includes(typeof t))return t;if(t instanceof Date)return new Date(t.getTime());if(typeof t!="object"||r.has(t))throw new TypeError("Import values must be acyclic data");let i=Object.getPrototypeOf(t);if(!Array.isArray(t)&&i!==Object.prototype&&i!==null)throw new TypeError("Import records must contain plain data");r.add(t);let m=Array.isArray(t)?[]:{};for(let[l,d]of ie(t))m[l]=n(d.value,s+1);return r.delete(t),m};return n(e,0)}var ae=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/;function L(e,r=!0){if(e==="")return null;if(!r||typeof e!="string"||!ae.test(e)||/^[+-]?0\d/.test(e))return e;let o=Number(e);return Number.isFinite(o)&&(!Number.isInteger(o)||Number.isSafeInteger(o))?o:e}function pe(e,r,o,n){let t=e.columns().filter(a=>a.colDef.field),s=o.columns??r,i=new Map(t.map(a=>[a.id,a])),m=new Map,l=new Map;for(let a of t){let u=a.colDef.field;m.set(u,m.has(u)?null:a);let f=a.colDef.headerName;f&&l.set(f,l.has(f)?null:a)}let d=[],c=new Set;return s.forEach((a,u)=>{let f=(typeof a=="string"||typeof a=="number"?String(a):"").replace(/^\uFEFF/,"").trim(),P=i.get(f)??(m.has(f)?m.get(f):l.get(f));if(!P){if(n||o.columns||m.has(f)||l.has(f))throw new TypeError(`Unknown or ambiguous import column: ${f}`);return}if(c.has(P.colDef.field))throw new TypeError(`Duplicate import column: ${P.id}`);c.add(P.colDef.field),d.push({column:P,index:u})}),d.length?d:e.visibleColumns().filter(a=>a.colDef.field).map((a,u)=>({column:a,index:u}))}function ue(e,r){if(!Array.isArray(e)||e.some(o=>!Array.isArray(o)))throw new TypeError("Import requires an array of rows");if(!Number.isInteger(r)||r<-1||r>=e.length)throw new RangeError("Invalid import header row");if(e.length-r-1>1e4||e.reduce((o,n)=>o+n.length,0)>1e5)throw new RangeError("Import supports 10000 data rows and 100000 cells")}function le(e,r,o,n,t,s){let i=o.colDef.field,m=e.read(r.node,o),l=s.parseValue?s.parseValue({value:t,field:i,rowIndex:r.rowIndex,columnIndex:n}):o.colDef.valueParser?e.parse(r.node,o,t,m):L(t,s.coerceNumbers!==!1);if(l!=null&&typeof l.then=="function")throw new TypeError("Import parsers must return synchronous values");if(!U(r.data,i,l))throw new TypeError(`Unsafe import field: ${i}`);r.changes.push({node:r.node,column:o,oldValue:m,newValue:l})}function de(e,r,o,n,t,s,i,m){let l=m?.[o]??{},d=i?.[o]??{id:`import:${o}`,rowIndex:o,data:l,selected:!1},c={data:l,node:d,changes:[],rowIndex:o};for(let{column:a,index:u}of n)if(!(r[u]===void 0||i&&!e.editable(d,a)))try{le(e,c,a,u,r[u],t)}catch(f){s.issues.push({rowIndex:o,columnIndex:u,colId:a.id,code:"PARSE",message:f instanceof Error?f.message:String(f)})}s.rows.push(c)}function q(e,r,o={},n,t=!1,s){let i=o.headerRowIndex??(o.columns?-1:0);ue(r,i);let m=pe(e,i<0?[]:r[i],o,t);if(!m.length)throw new TypeError("Import requires a writable field column");let l={rows:[],issues:[]};for(let d=i+1;d<r.length;d++){let c=r[d];c.some(a=>a!==""&&a!==void 0)&&de(e,c,d-i-1,m,o,l,n,s)}return l}function F(e,r,o,n){if(e.rows.isRemote())throw new TypeError("Import plans require local records");if(n.mode!=="paste"&&e.getOption("treeData"))throw new TypeError("Import plans require a flat-record model for replace/append");if(r.isEditing())throw new TypeError("Finish active editing before importing");if(n.mode!=="paste"&&e.editing.getDirtyRowIds().length)throw new TypeError("Save or roll back pending changes before loading records");let t=N(o),s=n.mode==="paste"?r.pasteRows(t.rows.length):void 0,i,m;if(t.kind==="rows"){m=t.rows;let d=n.columns??r.columns().filter(u=>u.colDef.field).map(u=>u.id),c=new Map(r.columns().map(u=>[u.id,u.colDef.field])),a=d.map(u=>c.get(u)??u);i=t.rows.map(u=>a.map(f=>B(u,f))),n={...n,columns:d,headerRowIndex:-1}}else i=t.rows;let l=q(r,i,n,s,!0,m);if(!s&&l.rows.some(d=>d.changes.some(c=>c.column.colDef.valueGetter||c.column.colDef.valueSetter)))throw new TypeError("New records require ordinary field columns; custom getters/setters are ambiguous");return l}var b=(e,r="UNSUPPORTED",o=-1)=>({rowIndex:o,code:r,message:e}),z=e=>e instanceof Error?e.message:String(e);function me(e,r,o,n){let t=new Set;for(let s of o.rows){if(n==="paste"){e.rows.getById(s.node.id)!==s.node&&o.issues.push(b("Paste target is not loaded","MAPPING",s.rowIndex));continue}try{let i=r.resolveId(s.data,s.rowIndex);if(i===void 0)continue;(!i||t.has(i)||n==="append"&&e.rows.getById(i))&&o.issues.push(b(`Missing or duplicate row key: ${i}`,"MAPPING",s.rowIndex)),t.add(i),s.node.id=i}catch(i){o.issues.push(b(z(i),"MAPPING",s.rowIndex))}}}function ce(e,r,o,n){let t=F(e,r,o,n);if(n.mode==="paste")for(let s of t.rows)s.changes.length||t.issues.push(b("Paste row has no editable destination cells","VALIDATION",s.rowIndex)),s.changes=s.changes.filter(i=>i.newValue!==void 0&&!Object.is(i.oldValue,i.newValue));return t.rows.length||t.issues.push(b("Import contains no data rows","MAPPING")),me(e,r,t,n.mode),t}function $(e,r){return r.map(o=>({rowIndex:e.rowIndex,colId:o.colId,code:"VALIDATION",message:o.message}))}function fe(e){let r=e.rows.flatMap(n=>n.changes.map(t=>({rowIndex:n.rowIndex,colId:t.column.id,value:t.newValue}))),o=N(r.map(n=>n.value));return r.map((n,t)=>({...n,value:o[t]}))}function Ie(e){let r=new Map;for(let o of e){let n=r.get(o.rowIndex)??[];n.push(o),r.set(o.rowIndex,n)}return r}function K(e,r,o={}){let n=j(e),t={...o,columns:o.columns?[...o.columns]:void 0},s=!1,i=0,m=0,l=!1,d,c,a,u,f=[e.on("modelUpdated",()=>i++),e.on("cellValueChanged",()=>i++)],P=()=>s||e.isDestroyed()?"destroyed":"stale",T=(p,y=[])=>({status:p,rowCount:0,cells:[],issues:y}),k=()=>{s||(s=!0,m++,d=void 0,f.forEach(p=>p()))};f.push(e.on("gridDestroyed",k));async function H(){let p=++m;if(d=void 0,s||e.isDestroyed())return T("destroyed");if(l)return T("stale",[b("This import plan has already committed","STALE")]);let y=n.begin(),x=n.revision(),v=n.columns(),D=i,E=e.getOption("rowEditValidator"),R=e.getOption("rowKey"),O=()=>!s&&p===m&&y()&&n.revision()===x&&n.columns()===v&&e.getOption("rowEditValidator")===E&&e.getOption("rowKey")===R,w=()=>O()&&i===D;try{let I=ce(e,n,r,t),h=I.rows.map(g=>t.mode==="paste"&&g.changes.length?n.guard(g.changes):()=>!0),S=I.rows.map((g,V)=>({changes:g.changes,current:()=>w()&&h[V]()})),C=await Promise.all(S.map(g=>Promise.resolve(g.changes.length?n.validate(g.changes,g.current):[])));if(!w())return T(P(),[b("Grid, columns or input changed during validation","STALE")]);I.rows.forEach((g,V)=>I.issues.push(...$(g,C[V])));let W=fe(I);return d={prepared:I,rows:S,guards:h,errors:C,current:w,intent:O},{status:I.issues.length?"invalid":"ready",rowCount:I.rows.length,cells:W,issues:I.issues.map(g=>({...g}))}}catch(I){return T(w()?"invalid":P(),[b(z(I))])}}async function X(){c?await c:!d&&!a&&await G()}async function J(){if(await X(),s||e.isDestroyed())return{status:"destroyed",importedRowCount:0,issues:[]};let p=d;if(!p&&a?.status==="invalid")return{status:"invalid",importedRowCount:0,issues:a.issues.map(v=>({...v}))};if(!p?.current()||l)return{status:"stale",importedRowCount:0,issues:[b("Import preview is no longer current","STALE")]};let{prepared:y}=p;if(y.issues.length&&t.mode!=="paste")return{status:"invalid",importedRowCount:0,issues:y.issues.map(v=>({...v}))};if(l=!0,t.mode==="paste")return Q(p);let x=y.rows.map(v=>v.data);return t.mode==="append"?e.rows.transact({add:x}):e.rows.setData(x),{status:"applied",importedRowCount:x.length,issues:[]}}function Q(p){let y=Ie(p.prepared.issues),x=p.errors.map((w,I)=>[...w,...(y.get(p.prepared.rows[I].rowIndex)??[]).filter(h=>h.code!=="VALIDATION").map(h=>({colId:h.colId??"",message:h.message}))]),v=p.rows.map((w,I)=>({...w,current:()=>p.intent()&&p.guards[I]()})),D=n.commitRows(v,x,p.intent),E=[...p.prepared.issues,...D.flatMap((w,I)=>{let h=p.prepared.rows[I],S=new Set((y.get(h.rowIndex)??[]).map(C=>C.message));return $(h,w.errors).filter(C=>!S.has(C.message))})],R=D.filter(w=>w.applied).length;return p.intent()?{status:E.length>0||R<p.rows.filter(w=>w.changes.length).length?R?"partial":"invalid":"applied",importedRowCount:R,issues:E}:{status:P(),importedRowCount:R,issues:[...E,b("Input scope changed during commit","STALE")]}}function G(){let p=H();return c=p,a=void 0,p.then(y=>{c===p&&(a=y)}),p.finally(()=>{c===p&&(c=void 0)}),p}return{preview:G,commit:()=>u??(u=J().finally(()=>{u=void 0})),destroy:k}}0&&(module.exports={createImportPlan});
|
|
1
|
+
"use strict";var M=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var re=(e,r)=>{for(var o in r)M(e,o,{get:r[o],enumerable:!0})},te=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Z(r))!ee.call(e,t)&&t!==o&&M(e,t,{get:()=>r[t],enumerable:!(n=Y(r,t))||n.enumerable});return e};var oe=e=>te(M({},"__esModule",{value:!0}),e);var we={};re(we,{createImportPlan:()=>K});module.exports=oe(we);var ne=Symbol.for("mach-table.import.v1");function _(e){let r=e[ne];if(!r)throw new TypeError("Import plans require a MachTable GridApi");return r}function se(e){return Object.entries(Object.getOwnPropertyDescriptors(e)).filter(([r,o])=>{if(r==="length"&&Array.isArray(e)||!o.enumerable)return!1;if(o.get||o.set||["__proto__","prototype","constructor"].includes(r))throw new TypeError("Unsafe import property");return!0})}function N(e){let r=new Set,o=0,n=(t,s)=>{if(++o>2e5||s>32)throw new RangeError("Import snapshot exceeds its value/depth limit");if(t==null||["string","number","boolean","bigint","undefined"].includes(typeof t))return t;if(t instanceof Date)return new Date(t.getTime());if(typeof t!="object"||r.has(t))throw new TypeError("Import values must be acyclic data");let i=Object.getPrototypeOf(t);if(!Array.isArray(t)&&i!==Object.prototype&&i!==null)throw new TypeError("Import records must contain plain data");r.add(t);let m=Array.isArray(t)?[]:{};for(let[l,d]of se(t))m[l]=n(d.value,s+1);return r.delete(t),m};return n(e,0)}var ie=new Set(["__proto__","prototype","constructor"]),A=new Map;function B(e){if(typeof e!="string"||e.length===0)return null;let r=A.get(e);if(r!==void 0)return r;let o=e.split("."),n=o.every(t=>t.length>0&&!ie.has(t))?o:null;return e.length<=1024&&(A.size>=256&&A.delete(A.keys().next().value),A.set(e,n)),n}function U(e,r){if(e==null)return;let o=B(r);if(!o)return;let n=e;for(let t of o){if(n==null)return;n=n[t]}return n}function j(e,r,o){if(e==null)return!1;let n=B(r);if(!n)return!1;let t=e;for(let s=0;s<n.length-1;s++){if(typeof t!="object"&&typeof t!="function"||t===null)return!1;t[n[s]]==null&&(t[n[s]]={}),t=t[n[s]]}return typeof t!="object"&&typeof t!="function"||t===null?!1:(t[n[n.length-1]]=o,!0)}var ae=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/;function L(e,r=!0){if(e==="")return null;if(!r||typeof e!="string"||!ae.test(e)||/^[+-]?0\d/.test(e))return e;let o=Number(e);return Number.isFinite(o)&&(!Number.isInteger(o)||Number.isSafeInteger(o))?o:e}function pe(e,r,o,n){let t=e.columns().filter(a=>a.colDef.field),s=o.columns??r,i=new Map(t.map(a=>[a.id,a])),m=new Map,l=new Map;for(let a of t){let u=a.colDef.field;m.set(u,m.has(u)?null:a);let f=a.colDef.headerName;f&&l.set(f,l.has(f)?null:a)}let d=[],c=new Set;return s.forEach((a,u)=>{let f=(typeof a=="string"||typeof a=="number"?String(a):"").replace(/^\uFEFF/,"").trim(),P=i.get(f)??(m.has(f)?m.get(f):l.get(f));if(!P){if(n||o.columns||m.has(f)||l.has(f))throw new TypeError(`Unknown or ambiguous import column: ${f}`);return}if(c.has(P.colDef.field))throw new TypeError(`Duplicate import column: ${P.id}`);c.add(P.colDef.field),d.push({column:P,index:u})}),d.length?d:e.visibleColumns().filter(a=>a.colDef.field).map((a,u)=>({column:a,index:u}))}function ue(e,r){if(!Array.isArray(e)||e.some(o=>!Array.isArray(o)))throw new TypeError("Import requires an array of rows");if(!Number.isInteger(r)||r<-1||r>=e.length)throw new RangeError("Invalid import header row");if(e.length-r-1>1e4||e.reduce((o,n)=>o+n.length,0)>1e5)throw new RangeError("Import supports 10000 data rows and 100000 cells")}function le(e,r,o,n,t,s){let i=o.colDef.field,m=e.read(r.node,o),l=s.parseValue?s.parseValue({value:t,field:i,rowIndex:r.rowIndex,columnIndex:n}):o.colDef.valueParser?e.parse(r.node,o,t,m):L(t,s.coerceNumbers!==!1);if(l!=null&&typeof l.then=="function")throw new TypeError("Import parsers must return synchronous values");if(!j(r.data,i,l))throw new TypeError(`Unsafe import field: ${i}`);r.changes.push({node:r.node,column:o,oldValue:m,newValue:l})}function de(e,r,o,n,t,s,i,m){let l=m?.[o]??{},d=i?.[o]??{id:`import:${o}`,rowIndex:o,data:l,selected:!1},c={data:l,node:d,changes:[],rowIndex:o};for(let{column:a,index:u}of n)if(!(r[u]===void 0||i&&!e.editable(d,a)))try{le(e,c,a,u,r[u],t)}catch(f){s.issues.push({rowIndex:o,columnIndex:u,colId:a.id,code:"PARSE",message:f instanceof Error?f.message:String(f)})}s.rows.push(c)}function q(e,r,o={},n,t=!1,s){let i=o.headerRowIndex??(o.columns?-1:0);ue(r,i);let m=pe(e,i<0?[]:r[i],o,t);if(!m.length)throw new TypeError("Import requires a writable field column");let l={rows:[],issues:[]};for(let d=i+1;d<r.length;d++){let c=r[d];c.some(a=>a!==""&&a!==void 0)&&de(e,c,d-i-1,m,o,l,n,s)}return l}function F(e,r,o,n){if(e.rows.isRemote())throw new TypeError("Import plans require local records");if(n.mode!=="paste"&&e.getOption("treeData"))throw new TypeError("Import plans require a flat-record model for replace/append");if(r.isEditing())throw new TypeError("Finish active editing before importing");if(n.mode!=="paste"&&e.editing.getDirtyRowIds().length)throw new TypeError("Save or roll back pending changes before loading records");let t=N(o),s=n.mode==="paste"?r.pasteRows(t.rows.length):void 0,i,m;if(t.kind==="rows"){m=t.rows;let d=n.columns??r.columns().filter(u=>u.colDef.field).map(u=>u.id),c=new Map(r.columns().map(u=>[u.id,u.colDef.field])),a=d.map(u=>c.get(u)??u);i=t.rows.map(u=>a.map(f=>U(u,f))),n={...n,columns:d,headerRowIndex:-1}}else i=t.rows;let l=q(r,i,n,s,!0,m);if(!s&&l.rows.some(d=>d.changes.some(c=>c.column.colDef.valueGetter||c.column.colDef.valueSetter)))throw new TypeError("New records require ordinary field columns; custom getters/setters are ambiguous");return l}var b=(e,r="UNSUPPORTED",o=-1)=>({rowIndex:o,code:r,message:e}),z=e=>e instanceof Error?e.message:String(e);function me(e,r,o,n){let t=new Set;for(let s of o.rows){if(n==="paste"){e.rows.getById(s.node.id)!==s.node&&o.issues.push(b("Paste target is not loaded","MAPPING",s.rowIndex));continue}try{let i=r.resolveId(s.data,s.rowIndex);if(i===void 0)continue;(!i||t.has(i)||n==="append"&&e.rows.getById(i))&&o.issues.push(b(`Missing or duplicate row key: ${i}`,"MAPPING",s.rowIndex)),t.add(i),s.node.id=i}catch(i){o.issues.push(b(z(i),"MAPPING",s.rowIndex))}}}function ce(e,r,o,n){let t=F(e,r,o,n);if(n.mode==="paste")for(let s of t.rows)s.changes.length||t.issues.push(b("Paste row has no editable destination cells","VALIDATION",s.rowIndex)),s.changes=s.changes.filter(i=>i.newValue!==void 0&&!Object.is(i.oldValue,i.newValue));return t.rows.length||t.issues.push(b("Import contains no data rows","MAPPING")),me(e,r,t,n.mode),t}function $(e,r){return r.map(o=>({rowIndex:e.rowIndex,colId:o.colId,code:"VALIDATION",message:o.message}))}function fe(e){let r=e.rows.flatMap(n=>n.changes.map(t=>({rowIndex:n.rowIndex,colId:t.column.id,value:t.newValue}))),o=N(r.map(n=>n.value));return r.map((n,t)=>({...n,value:o[t]}))}function Ie(e){let r=new Map;for(let o of e){let n=r.get(o.rowIndex)??[];n.push(o),r.set(o.rowIndex,n)}return r}function K(e,r,o={}){let n=_(e),t={...o,columns:o.columns?[...o.columns]:void 0},s=!1,i=0,m=0,l=!1,d,c,a,u,f=[e.on("modelUpdated",()=>i++),e.on("cellValueChanged",()=>i++)],P=()=>s||e.isDestroyed()?"destroyed":"stale",T=(p,y=[])=>({status:p,rowCount:0,cells:[],issues:y}),k=()=>{s||(s=!0,m++,d=void 0,f.forEach(p=>p()))};f.push(e.on("gridDestroyed",k));async function H(){let p=++m;if(d=void 0,s||e.isDestroyed())return T("destroyed");if(l)return T("stale",[b("This import plan has already committed","STALE")]);let y=n.begin(),x=n.revision(),v=n.columns(),D=i,E=e.getOption("rowEditValidator"),R=e.getOption("rowKey"),O=()=>!s&&p===m&&y()&&n.revision()===x&&n.columns()===v&&e.getOption("rowEditValidator")===E&&e.getOption("rowKey")===R,w=()=>O()&&i===D;try{let I=ce(e,n,r,t),h=I.rows.map(g=>t.mode==="paste"&&g.changes.length?n.guard(g.changes):()=>!0),S=I.rows.map((g,V)=>({changes:g.changes,current:()=>w()&&h[V]()})),C=await Promise.all(S.map(g=>Promise.resolve(g.changes.length?n.validate(g.changes,g.current):[])));if(!w())return T(P(),[b("Grid, columns or input changed during validation","STALE")]);I.rows.forEach((g,V)=>I.issues.push(...$(g,C[V])));let W=fe(I);return d={prepared:I,rows:S,guards:h,errors:C,current:w,intent:O},{status:I.issues.length?"invalid":"ready",rowCount:I.rows.length,cells:W,issues:I.issues.map(g=>({...g}))}}catch(I){return T(w()?"invalid":P(),[b(z(I))])}}async function X(){c?await c:!d&&!a&&await G()}async function J(){if(await X(),s||e.isDestroyed())return{status:"destroyed",importedRowCount:0,issues:[]};let p=d;if(!p&&a?.status==="invalid")return{status:"invalid",importedRowCount:0,issues:a.issues.map(v=>({...v}))};if(!p?.current()||l)return{status:"stale",importedRowCount:0,issues:[b("Import preview is no longer current","STALE")]};let{prepared:y}=p;if(y.issues.length&&t.mode!=="paste")return{status:"invalid",importedRowCount:0,issues:y.issues.map(v=>({...v}))};if(l=!0,t.mode==="paste")return Q(p);let x=y.rows.map(v=>v.data);return t.mode==="append"?e.rows.transact({add:x}):e.rows.setData(x),{status:"applied",importedRowCount:x.length,issues:[]}}function Q(p){let y=Ie(p.prepared.issues),x=p.errors.map((w,I)=>[...w,...(y.get(p.prepared.rows[I].rowIndex)??[]).filter(h=>h.code!=="VALIDATION").map(h=>({colId:h.colId??"",message:h.message}))]),v=p.rows.map((w,I)=>({...w,current:()=>p.intent()&&p.guards[I]()})),D=n.commitRows(v,x,p.intent),E=[...p.prepared.issues,...D.flatMap((w,I)=>{let h=p.prepared.rows[I],S=new Set((y.get(h.rowIndex)??[]).map(C=>C.message));return $(h,w.errors).filter(C=>!S.has(C.message))})],R=D.filter(w=>w.applied).length;return p.intent()?{status:E.length>0||R<p.rows.filter(w=>w.changes.length).length?R?"partial":"invalid":"applied",importedRowCount:R,issues:E}:{status:P(),importedRowCount:R,issues:[...E,b("Input scope changed during commit","STALE")]}}function G(){let p=H();return c=p,a=void 0,p.then(y=>{c===p&&(a=y)}),p.finally(()=>{c===p&&(c=void 0)}),p}return{preview:G,commit:()=>u??(u=J().finally(()=>{u=void 0})),destroy:k}}0&&(module.exports={createImportPlan});
|
package/dist/import.d.cts
CHANGED
package/dist/import.d.ts
CHANGED
package/dist/import.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Q=
|
|
1
|
+
var Q=Symbol.for("mach-table.import.v1");function G(e){let o=e[Q];if(!o)throw new TypeError("Import plans require a MachTable GridApi");return o}function W(e){return Object.entries(Object.getOwnPropertyDescriptors(e)).filter(([o,t])=>{if(o==="length"&&Array.isArray(e)||!t.enumerable)return!1;if(t.get||t.set||["__proto__","prototype","constructor"].includes(o))throw new TypeError("Unsafe import property");return!0})}function N(e){let o=new Set,t=0,n=(r,s)=>{if(++t>2e5||s>32)throw new RangeError("Import snapshot exceeds its value/depth limit");if(r==null||["string","number","boolean","bigint","undefined"].includes(typeof r))return r;if(r instanceof Date)return new Date(r.getTime());if(typeof r!="object"||o.has(r))throw new TypeError("Import values must be acyclic data");let i=Object.getPrototypeOf(r);if(!Array.isArray(r)&&i!==Object.prototype&&i!==null)throw new TypeError("Import records must contain plain data");o.add(r);let m=Array.isArray(r)?[]:{};for(let[l,d]of W(r))m[l]=n(d.value,s+1);return o.delete(r),m};return n(e,0)}var Y=new Set(["__proto__","prototype","constructor"]),A=new Map;function _(e){if(typeof e!="string"||e.length===0)return null;let o=A.get(e);if(o!==void 0)return o;let t=e.split("."),n=t.every(r=>r.length>0&&!Y.has(r))?t:null;return e.length<=1024&&(A.size>=256&&A.delete(A.keys().next().value),A.set(e,n)),n}function B(e,o){if(e==null)return;let t=_(o);if(!t)return;let n=e;for(let r of t){if(n==null)return;n=n[r]}return n}function U(e,o,t){if(e==null)return!1;let n=_(o);if(!n)return!1;let r=e;for(let s=0;s<n.length-1;s++){if(typeof r!="object"&&typeof r!="function"||r===null)return!1;r[n[s]]==null&&(r[n[s]]={}),r=r[n[s]]}return typeof r!="object"&&typeof r!="function"||r===null?!1:(r[n[n.length-1]]=t,!0)}var Z=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/;function j(e,o=!0){if(e==="")return null;if(!o||typeof e!="string"||!Z.test(e)||/^[+-]?0\d/.test(e))return e;let t=Number(e);return Number.isFinite(t)&&(!Number.isInteger(t)||Number.isSafeInteger(t))?t:e}function ee(e,o,t,n){let r=e.columns().filter(a=>a.colDef.field),s=t.columns??o,i=new Map(r.map(a=>[a.id,a])),m=new Map,l=new Map;for(let a of r){let u=a.colDef.field;m.set(u,m.has(u)?null:a);let f=a.colDef.headerName;f&&l.set(f,l.has(f)?null:a)}let d=[],c=new Set;return s.forEach((a,u)=>{let f=(typeof a=="string"||typeof a=="number"?String(a):"").replace(/^\uFEFF/,"").trim(),P=i.get(f)??(m.has(f)?m.get(f):l.get(f));if(!P){if(n||t.columns||m.has(f)||l.has(f))throw new TypeError(`Unknown or ambiguous import column: ${f}`);return}if(c.has(P.colDef.field))throw new TypeError(`Duplicate import column: ${P.id}`);c.add(P.colDef.field),d.push({column:P,index:u})}),d.length?d:e.visibleColumns().filter(a=>a.colDef.field).map((a,u)=>({column:a,index:u}))}function re(e,o){if(!Array.isArray(e)||e.some(t=>!Array.isArray(t)))throw new TypeError("Import requires an array of rows");if(!Number.isInteger(o)||o<-1||o>=e.length)throw new RangeError("Invalid import header row");if(e.length-o-1>1e4||e.reduce((t,n)=>t+n.length,0)>1e5)throw new RangeError("Import supports 10000 data rows and 100000 cells")}function te(e,o,t,n,r,s){let i=t.colDef.field,m=e.read(o.node,t),l=s.parseValue?s.parseValue({value:r,field:i,rowIndex:o.rowIndex,columnIndex:n}):t.colDef.valueParser?e.parse(o.node,t,r,m):j(r,s.coerceNumbers!==!1);if(l!=null&&typeof l.then=="function")throw new TypeError("Import parsers must return synchronous values");if(!U(o.data,i,l))throw new TypeError(`Unsafe import field: ${i}`);o.changes.push({node:o.node,column:t,oldValue:m,newValue:l})}function oe(e,o,t,n,r,s,i,m){let l=m?.[t]??{},d=i?.[t]??{id:`import:${t}`,rowIndex:t,data:l,selected:!1},c={data:l,node:d,changes:[],rowIndex:t};for(let{column:a,index:u}of n)if(!(o[u]===void 0||i&&!e.editable(d,a)))try{te(e,c,a,u,o[u],r)}catch(f){s.issues.push({rowIndex:t,columnIndex:u,colId:a.id,code:"PARSE",message:f instanceof Error?f.message:String(f)})}s.rows.push(c)}function L(e,o,t={},n,r=!1,s){let i=t.headerRowIndex??(t.columns?-1:0);re(o,i);let m=ee(e,i<0?[]:o[i],t,r);if(!m.length)throw new TypeError("Import requires a writable field column");let l={rows:[],issues:[]};for(let d=i+1;d<o.length;d++){let c=o[d];c.some(a=>a!==""&&a!==void 0)&&oe(e,c,d-i-1,m,t,l,n,s)}return l}function q(e,o,t,n){if(e.rows.isRemote())throw new TypeError("Import plans require local records");if(n.mode!=="paste"&&e.getOption("treeData"))throw new TypeError("Import plans require a flat-record model for replace/append");if(o.isEditing())throw new TypeError("Finish active editing before importing");if(n.mode!=="paste"&&e.editing.getDirtyRowIds().length)throw new TypeError("Save or roll back pending changes before loading records");let r=N(t),s=n.mode==="paste"?o.pasteRows(r.rows.length):void 0,i,m;if(r.kind==="rows"){m=r.rows;let d=n.columns??o.columns().filter(u=>u.colDef.field).map(u=>u.id),c=new Map(o.columns().map(u=>[u.id,u.colDef.field])),a=d.map(u=>c.get(u)??u);i=r.rows.map(u=>a.map(f=>B(u,f))),n={...n,columns:d,headerRowIndex:-1}}else i=r.rows;let l=L(o,i,n,s,!0,m);if(!s&&l.rows.some(d=>d.changes.some(c=>c.column.colDef.valueGetter||c.column.colDef.valueSetter)))throw new TypeError("New records require ordinary field columns; custom getters/setters are ambiguous");return l}var b=(e,o="UNSUPPORTED",t=-1)=>({rowIndex:t,code:o,message:e}),$=e=>e instanceof Error?e.message:String(e);function ne(e,o,t,n){let r=new Set;for(let s of t.rows){if(n==="paste"){e.rows.getById(s.node.id)!==s.node&&t.issues.push(b("Paste target is not loaded","MAPPING",s.rowIndex));continue}try{let i=o.resolveId(s.data,s.rowIndex);if(i===void 0)continue;(!i||r.has(i)||n==="append"&&e.rows.getById(i))&&t.issues.push(b(`Missing or duplicate row key: ${i}`,"MAPPING",s.rowIndex)),r.add(i),s.node.id=i}catch(i){t.issues.push(b($(i),"MAPPING",s.rowIndex))}}}function se(e,o,t,n){let r=q(e,o,t,n);if(n.mode==="paste")for(let s of r.rows)s.changes.length||r.issues.push(b("Paste row has no editable destination cells","VALIDATION",s.rowIndex)),s.changes=s.changes.filter(i=>i.newValue!==void 0&&!Object.is(i.oldValue,i.newValue));return r.rows.length||r.issues.push(b("Import contains no data rows","MAPPING")),ne(e,o,r,n.mode),r}function F(e,o){return o.map(t=>({rowIndex:e.rowIndex,colId:t.colId,code:"VALIDATION",message:t.message}))}function ie(e){let o=e.rows.flatMap(n=>n.changes.map(r=>({rowIndex:n.rowIndex,colId:r.column.id,value:r.newValue}))),t=N(o.map(n=>n.value));return o.map((n,r)=>({...n,value:t[r]}))}function ae(e){let o=new Map;for(let t of e){let n=o.get(t.rowIndex)??[];n.push(t),o.set(t.rowIndex,n)}return o}function pe(e,o,t={}){let n=G(e),r={...t,columns:t.columns?[...t.columns]:void 0},s=!1,i=0,m=0,l=!1,d,c,a,u,f=[e.on("modelUpdated",()=>i++),e.on("cellValueChanged",()=>i++)],P=()=>s||e.isDestroyed()?"destroyed":"stale",T=(p,y=[])=>({status:p,rowCount:0,cells:[],issues:y}),M=()=>{s||(s=!0,m++,d=void 0,f.forEach(p=>p()))};f.push(e.on("gridDestroyed",M));async function z(){let p=++m;if(d=void 0,s||e.isDestroyed())return T("destroyed");if(l)return T("stale",[b("This import plan has already committed","STALE")]);let y=n.begin(),x=n.revision(),v=n.columns(),D=i,E=e.getOption("rowEditValidator"),R=e.getOption("rowKey"),O=()=>!s&&p===m&&y()&&n.revision()===x&&n.columns()===v&&e.getOption("rowEditValidator")===E&&e.getOption("rowKey")===R,w=()=>O()&&i===D;try{let I=se(e,n,o,r),h=I.rows.map(g=>r.mode==="paste"&&g.changes.length?n.guard(g.changes):()=>!0),S=I.rows.map((g,V)=>({changes:g.changes,current:()=>w()&&h[V]()})),C=await Promise.all(S.map(g=>Promise.resolve(g.changes.length?n.validate(g.changes,g.current):[])));if(!w())return T(P(),[b("Grid, columns or input changed during validation","STALE")]);I.rows.forEach((g,V)=>I.issues.push(...F(g,C[V])));let J=ie(I);return d={prepared:I,rows:S,guards:h,errors:C,current:w,intent:O},{status:I.issues.length?"invalid":"ready",rowCount:I.rows.length,cells:J,issues:I.issues.map(g=>({...g}))}}catch(I){return T(w()?"invalid":P(),[b($(I))])}}async function K(){c?await c:!d&&!a&&await k()}async function H(){if(await K(),s||e.isDestroyed())return{status:"destroyed",importedRowCount:0,issues:[]};let p=d;if(!p&&a?.status==="invalid")return{status:"invalid",importedRowCount:0,issues:a.issues.map(v=>({...v}))};if(!p?.current()||l)return{status:"stale",importedRowCount:0,issues:[b("Import preview is no longer current","STALE")]};let{prepared:y}=p;if(y.issues.length&&r.mode!=="paste")return{status:"invalid",importedRowCount:0,issues:y.issues.map(v=>({...v}))};if(l=!0,r.mode==="paste")return X(p);let x=y.rows.map(v=>v.data);return r.mode==="append"?e.rows.transact({add:x}):e.rows.setData(x),{status:"applied",importedRowCount:x.length,issues:[]}}function X(p){let y=ae(p.prepared.issues),x=p.errors.map((w,I)=>[...w,...(y.get(p.prepared.rows[I].rowIndex)??[]).filter(h=>h.code!=="VALIDATION").map(h=>({colId:h.colId??"",message:h.message}))]),v=p.rows.map((w,I)=>({...w,current:()=>p.intent()&&p.guards[I]()})),D=n.commitRows(v,x,p.intent),E=[...p.prepared.issues,...D.flatMap((w,I)=>{let h=p.prepared.rows[I],S=new Set((y.get(h.rowIndex)??[]).map(C=>C.message));return F(h,w.errors).filter(C=>!S.has(C.message))})],R=D.filter(w=>w.applied).length;return p.intent()?{status:E.length>0||R<p.rows.filter(w=>w.changes.length).length?R?"partial":"invalid":"applied",importedRowCount:R,issues:E}:{status:P(),importedRowCount:R,issues:[...E,b("Input scope changed during commit","STALE")]}}function k(){let p=z();return c=p,a=void 0,p.then(y=>{c===p&&(a=y)}),p.finally(()=>{c===p&&(c=void 0)}),p}return{preview:k,commit:()=>u??(u=H().finally(()=>{u=void 0})),destroy:M}}export{pe as createImportPlan};
|