@ishibashi0112/spreadsheet-grid-core 1.7.0 → 1.9.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.
Files changed (114) hide show
  1. package/dist/controllers/activeRowFollowController.cjs +1 -1
  2. package/dist/controllers/activeRowFollowController.d.ts +1 -0
  3. package/dist/controllers/activeRowFollowController.js +33 -24
  4. package/dist/controllers/changeTracker.cjs +1 -0
  5. package/dist/controllers/changeTracker.d.ts +39 -0
  6. package/dist/controllers/changeTracker.js +238 -0
  7. package/dist/controllers/clipboardController.cjs +1 -1
  8. package/dist/controllers/clipboardController.js +43 -40
  9. package/dist/controllers/columnAutosizeRunner.cjs +1 -1
  10. package/dist/controllers/columnAutosizeRunner.d.ts +3 -1
  11. package/dist/controllers/columnAutosizeRunner.js +12 -11
  12. package/dist/controllers/findController.cjs +1 -1
  13. package/dist/controllers/findController.d.ts +3 -1
  14. package/dist/controllers/findController.js +80 -75
  15. package/dist/controllers/historyController.cjs +1 -1
  16. package/dist/controllers/historyController.d.ts +25 -1
  17. package/dist/controllers/historyController.js +125 -71
  18. package/dist/controllers/keyboardController.cjs +1 -1
  19. package/dist/controllers/keyboardController.d.ts +1 -0
  20. package/dist/controllers/keyboardController.js +4 -0
  21. package/dist/engine/columnLayout.cjs +1 -1
  22. package/dist/engine/columnLayout.d.ts +1 -0
  23. package/dist/engine/columnLayout.js +10 -10
  24. package/dist/engine/createGridEngine.cjs +1 -1
  25. package/dist/engine/createGridEngine.d.ts +4 -1
  26. package/dist/engine/createGridEngine.js +48 -41
  27. package/dist/engine/exportCommands.cjs +2 -2
  28. package/dist/engine/exportCommands.js +82 -34
  29. package/dist/engine/features.cjs +1 -1
  30. package/dist/engine/features.d.ts +16 -0
  31. package/dist/engine/features.js +25 -1
  32. package/dist/engine/fullFeatures.cjs +1 -1
  33. package/dist/engine/fullFeatures.js +43 -31
  34. package/dist/engine/gridApi.cjs +9 -7
  35. package/dist/engine/gridApi.d.ts +23 -2
  36. package/dist/engine/gridApi.js +248 -96
  37. package/dist/engine/memo.cjs +1 -1
  38. package/dist/engine/memo.d.ts +1 -1
  39. package/dist/engine/memo.js +12 -11
  40. package/dist/engine/notifiers.cjs +1 -1
  41. package/dist/engine/notifiers.d.ts +9 -1
  42. package/dist/engine/notifiers.js +23 -8
  43. package/dist/engine/rowPipeline.cjs +1 -1
  44. package/dist/engine/rowPipeline.d.ts +29 -2
  45. package/dist/engine/rowPipeline.js +76 -50
  46. package/dist/engine/treeStage.cjs +1 -0
  47. package/dist/engine/treeStage.d.ts +46 -0
  48. package/dist/engine/treeStage.js +171 -0
  49. package/dist/index.cjs +1 -1
  50. package/dist/index.d.ts +2 -2
  51. package/dist/index.js +4 -4
  52. package/dist/locales/en.cjs +1 -1
  53. package/dist/locales/en.js +13 -0
  54. package/dist/logic/cellNote.cjs +1 -1
  55. package/dist/logic/cellNote.d.ts +1 -1
  56. package/dist/logic/cellNote.js +9 -1
  57. package/dist/logic/changeTracking.cjs +1 -0
  58. package/dist/logic/changeTracking.d.ts +51 -0
  59. package/dist/logic/changeTracking.js +185 -0
  60. package/dist/logic/clearCells.cjs +1 -1
  61. package/dist/logic/clearCells.js +54 -54
  62. package/dist/logic/columnAutosize.cjs +1 -1
  63. package/dist/logic/columnAutosize.d.ts +4 -1
  64. package/dist/logic/columnAutosize.js +89 -72
  65. package/dist/logic/conditionalFormat.cjs +1 -1
  66. package/dist/logic/conditionalFormat.js +8 -5
  67. package/dist/logic/contextMenuTarget.cjs +1 -1
  68. package/dist/logic/contextMenuTarget.d.ts +4 -3
  69. package/dist/logic/contextMenuTarget.js +42 -36
  70. package/dist/logic/exportCsv.cjs +2 -2
  71. package/dist/logic/exportCsv.d.ts +11 -1
  72. package/dist/logic/exportCsv.js +30 -22
  73. package/dist/logic/exportData.cjs +1 -1
  74. package/dist/logic/exportData.d.ts +3 -2
  75. package/dist/logic/exportData.js +40 -28
  76. package/dist/logic/fillHandle.cjs +1 -1
  77. package/dist/logic/fillHandle.js +109 -103
  78. package/dist/logic/find.cjs +1 -1
  79. package/dist/logic/find.d.ts +1 -1
  80. package/dist/logic/find.js +11 -9
  81. package/dist/logic/gridAsk.cjs +2 -2
  82. package/dist/logic/gridAsk.js +71 -71
  83. package/dist/logic/gridState.cjs +1 -1
  84. package/dist/logic/gridState.d.ts +3 -2
  85. package/dist/logic/gridState.js +6 -6
  86. package/dist/logic/groupExport.cjs +1 -1
  87. package/dist/logic/groupExport.js +12 -12
  88. package/dist/logic/localeTextFeatures.cjs +1 -1
  89. package/dist/logic/localeTextFeatures.d.ts +17 -0
  90. package/dist/logic/localeTextFeatures.js +22 -7
  91. package/dist/logic/selectionAggregates.cjs +1 -1
  92. package/dist/logic/selectionAggregates.js +2 -1
  93. package/dist/logic/sorting.cjs +1 -1
  94. package/dist/logic/sorting.d.ts +1 -1
  95. package/dist/logic/sorting.js +32 -32
  96. package/dist/logic/treeData.cjs +7 -0
  97. package/dist/logic/treeData.d.ts +83 -0
  98. package/dist/logic/treeData.js +438 -0
  99. package/dist/logic/validation.cjs +1 -1
  100. package/dist/logic/validation.d.ts +1 -1
  101. package/dist/logic/validation.js +23 -22
  102. package/dist/model/gridActions.cjs +1 -1
  103. package/dist/model/gridActions.d.ts +15 -0
  104. package/dist/model/gridActions.js +15 -0
  105. package/dist/model/gridReducer.cjs +1 -1
  106. package/dist/model/gridReducer.js +175 -156
  107. package/dist/model/gridTypes.core.d.ts +282 -6
  108. package/dist/utils/clipboard.cjs +1 -1
  109. package/dist/utils/clipboard.d.ts +1 -1
  110. package/dist/utils/clipboard.js +70 -67
  111. package/dist/utils/permissions.cjs +1 -1
  112. package/dist/utils/permissions.d.ts +6 -0
  113. package/dist/utils/permissions.js +11 -2
  114. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { type AutosizeChipOf, type AutosizeTotalRowTexts } from '../logic/columnAutosize.js';
1
+ import { type AutosizeAggregateTextOf, type AutosizeCellLeadingWidth, type AutosizeChipOf, type AutosizeTotalRowTexts } from '../logic/columnAutosize.js';
2
2
  import { gridActions } from '../model/gridActions.js';
3
3
  import type { AutoSizeColumnsMode, GridColumn, RowModel } from '../model/gridTypes.unbound.js';
4
4
  type ReadonlyRef<V> = {
@@ -12,6 +12,8 @@ export type ColumnAutosizeRunnerArgs<T> = {
12
12
  totalRowTexts?: AutosizeTotalRowTexts;
13
13
  chipOf?: AutosizeChipOf<T> | undefined;
14
14
  pinnedRows?: readonly T[] | undefined;
15
+ cellLeadingWidth?: AutosizeCellLeadingWidth<T> | undefined;
16
+ aggregateTextOf?: AutosizeAggregateTextOf<T> | undefined;
15
17
  };
16
18
  export type ColumnAutosizeRunner<T> = {
17
19
  update: (args: ColumnAutosizeRunnerArgs<T>) => void;
@@ -14,27 +14,28 @@ var o = 180, s = () => {
14
14
  },
15
15
  runAutosize: async (t) => {
16
16
  if (a === null || t.length === 0 || !r()) return;
17
- let { rowModel: d, gridRootRef: f, columnWidths: p, dispatch: m, totalRowTexts: h, chipOf: g, pinnedRows: _ } = a, v = c += 1;
17
+ let { rowModel: d, gridRootRef: f, columnWidths: p, dispatch: m, totalRowTexts: h, chipOf: g, pinnedRows: _, cellLeadingWidth: v, aggregateTextOf: y } = a, b = c += 1;
18
18
  u();
19
- let y = d.getRowCount(), b = f.current, x = i(t, g);
19
+ let x = d.getRowCount(), S = f.current, C = i(t, g, y);
20
20
  l = setTimeout(() => {
21
- c === v && s.setSnapshot(!0);
21
+ c === b && s.setSnapshot(!0);
22
22
  }, o);
23
23
  try {
24
- if (!await n(y, (e) => {
24
+ if (!await n(x, (e) => {
25
25
  let t = d.getRow(e);
26
- t && x.collect(t, e);
27
- }, { isCancelled: () => c !== v || a?.rowModel !== d })) return;
28
- _?.forEach((e, t) => x.collect(e, -1 - t));
29
- let t = x.finalize({
30
- gridRoot: b,
26
+ t && C.collect(t, e);
27
+ }, { isCancelled: () => c !== b || a?.rowModel !== d })) return;
28
+ _?.forEach((e, t) => C.collect(e, -1 - t));
29
+ let t = C.finalize({
30
+ gridRoot: S,
31
31
  currentWidths: p,
32
32
  totalRowTexts: h,
33
- chipOf: g
33
+ chipOf: g,
34
+ cellLeadingWidth: v
34
35
  });
35
36
  Object.keys(t).length > 0 && m(e.syncColumnWidths(t));
36
37
  } finally {
37
- c === v && (u(), s.setSnapshot(!1));
38
+ c === b && (u(), s.setSnapshot(!1));
38
39
  }
39
40
  },
40
41
  subscribe: s.subscribe,
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../logic/detailRow.cjs"),t=require("../logic/valueStore.cjs"),n=require("../logic/chunkedLoop.cjs"),r=require("../logic/find.cjs");var i=1e4,a=5e4,o=new Map,s=[],c=(e,t)=>e.length===t.length&&e.every((e,n)=>{let r=t[n];return e.rowIndex===r.rowIndex&&e.colIndex===r.colIndex&&e.columnKey===r.columnKey&&e.start===r.start&&e.length===r.length}),l=()=>{let i=null,l=0,u=null,d=!1,f=null,p=t.createValueStore({open:!1,query:``,matches:[],index:o,currentIndex:null,scanning:!1,truncated:!1}),m=e=>{p.setSnapshot({...p.getSnapshot(),...e})},h=null,g=()=>{let e=p.getSnapshot(),t={query:e.query,matchCount:e.matches.length,currentIndex:e.currentIndex,open:e.open,truncated:e.truncated};h!==null&&h.query===t.query&&h.matchCount===t.matchCount&&h.currentIndex===t.currentIndex&&h.open===t.open&&h.truncated===t.truncated||(h=t,i?.onChange?.(t))},_=()=>{let e=p.getSnapshot();if(e.currentIndex===null)return;let t=e.matches[e.currentIndex];t&&i?.onNavigate(t.rowIndex,t.colIndex)},v=()=>{l+=1,f=null,u=null,d=!1,m({matches:[],index:o,currentIndex:null,scanning:!1,truncated:!1})},y=(t,o=!1)=>{let h=i,b=p.getSnapshot();if(!h||!b.open||b.query.length===0){v(),g();return}l+=1;let x=l,{rowModel:S,columns:C,caseSensitive:w}=h,T=h.conditionalFormat!==!1,E=b.query,D=f!==null&&f.query===E&&f.caseSensitive===w;f={rowModel:S,columns:C,query:E,caseSensitive:w,conditionalFormatShown:T},(o||u===null||u.columns!==C||u.query!==E||u.caseSensitive!==w||u.conditionalFormatShown!==T)&&(u={columns:C,query:E,caseSensitive:w,conditionalFormatShown:T,byRow:new WeakMap});let O=u.byRow,k=0,A=t||d;d=A;let j=b.currentIndex===null?null:b.matches[b.currentIndex]??null,M=[],N=!1,P=S.getRowCount(),F=P>a,I=(t,n)=>{let i=[];return C.forEach((a,o)=>{if(e.isSyntheticColumnKey(a.key)||!r.isFindableColumn(a,T))return;let s=r.resolveFindCellText(a,t,!T||a.conditionalFormat?.chips===void 0?void 0:{rowIndex:n,sourceRowIndex:S.getSourceIndex(n)??n,rowKey:S.getRowKey(n)??n,colIndex:o});for(let e of r.findRangesInText(s,E,w))i.push({colIndex:o,columnKey:String(a.key),start:e.start,length:e.length})}),i.length===0?s:i};!D&&!b.scanning&&m({scanning:!0}),n.runChunked(P,e=>{if(N)return;let t=S.getRow(e);if(t===void 0)return;let n;F&&typeof t==`object`&&t?(n=O.get(t),n===void 0?(n=I(t,e),O.set(t,n)):k+=1):n=I(t,e);for(let t of n){if(M.length>=1e4){N=!0;return}M.push({rowIndex:e,colIndex:t.colIndex,columnKey:t.columnKey,start:t.start,length:t.length})}},{isCancelled:()=>l!==x}).then(e=>{if(!e||l!==x||(d=!1,o&&N===p.getSnapshot().truncated&&c(p.getSnapshot().matches,M)))return;let t=r.resolveCurrentAfterRescan(M,j);m({matches:M,index:r.buildFindIndex(M),currentIndex:t,scanning:!1,truncated:N}),g(),A&&_(),!o&&k>0&&y(!1,!0)})},b=()=>{let e=p.getSnapshot();return!i||!e.open||e.query.length===0?!1:f===null||f.rowModel!==i.rowModel||f.columns!==i.columns||f.query!==e.query||f.caseSensitive!==i.caseSensitive||f.conditionalFormatShown!==(i.conditionalFormat!==!1)};return{update:e=>{let t=i;if(i=e,!e.enabled){p.getSnapshot().open&&(m({open:!1,query:``}),v(),g());return}t!==e&&b()&&y(!1)},open:e=>{if(!i?.enabled)return;let t=p.getSnapshot(),n=e??t.query;m({open:!0,query:n}),n!==t.query||!t.open?y(!0):g()},close:()=>{p.getSnapshot().open&&(m({open:!1,query:``}),v(),g())},setQuery:e=>{let t=p.getSnapshot();!t.open||e===t.query||(m({query:e}),y(!0))},next:()=>{let e=p.getSnapshot(),t=r.stepFindIndex(e.currentIndex,e.matches.length,1);m({currentIndex:t}),g(),_()},prev:()=>{let e=p.getSnapshot(),t=r.stepFindIndex(e.currentIndex,e.matches.length,-1);m({currentIndex:t}),g(),_()},subscribe:p.subscribe,getSnapshot:p.getSnapshot,dispose:()=>{l+=1,i=null}}};exports.FIND_HIT_CACHE_ROW_THRESHOLD=a,exports.MAX_FIND_MATCHES=i,exports.createFindController=l;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../logic/detailRow.cjs"),t=require("../logic/valueStore.cjs"),n=require("../logic/chunkedLoop.cjs"),r=require("../logic/find.cjs");var i=1e4,a=5e4,o=new Map,s=[],c=(e,t)=>e.length===t.length&&e.every((e,n)=>{let r=t[n];return e.rowIndex===r.rowIndex&&e.colIndex===r.colIndex&&e.columnKey===r.columnKey&&e.start===r.start&&e.length===r.length}),l=()=>{let i=null,l=0,u=null,d=!1,f,p=null,m=t.createValueStore({open:!1,query:``,matches:[],index:o,currentIndex:null,scanning:!1,truncated:!1}),h=e=>{m.setSnapshot({...m.getSnapshot(),...e})},g=null,_=()=>{let e=m.getSnapshot(),t={query:e.query,matchCount:e.matches.length,currentIndex:e.currentIndex,open:e.open,truncated:e.truncated};g!==null&&g.query===t.query&&g.matchCount===t.matchCount&&g.currentIndex===t.currentIndex&&g.open===t.open&&g.truncated===t.truncated||(g=t,i?.onChange?.(t))},v=e=>{let t=m.getSnapshot();if(t.currentIndex===null)return;let n=t.matches[t.currentIndex];n&&i?.onNavigate(n.rowIndex,n.colIndex,e)},y=()=>{l+=1,p=null,u=null,d=!1,h({matches:[],index:o,currentIndex:null,scanning:!1,truncated:!1})},b=(t,o=!1)=>{let g=i,x=m.getSnapshot();if(!g||!x.open||x.query.length===0){y(),_();return}l+=1;let S=l,{rowModel:C,columns:w,caseSensitive:T}=g,E=g.conditionalFormat!==!1,D=x.query,O=p!==null&&p.query===D&&p.caseSensitive===T;p={rowModel:C,columns:w,query:D,caseSensitive:T,conditionalFormatShown:E},(o||u===null||u.columns!==w||u.query!==D||u.caseSensitive!==T||u.conditionalFormatShown!==E)&&(u={columns:w,query:D,caseSensitive:T,conditionalFormatShown:E,byRow:new WeakMap});let k=u.byRow,A=0,j=t||d;d=j;let M=x.currentIndex===null?null:x.matches[x.currentIndex]??null,N=[],P=!1,F=C.getRowCount(),I=F>a,L=(t,n)=>{let i=[];return w.forEach((a,o)=>{if(e.isSyntheticColumnKey(a.key)||!r.isFindableColumn(a,E))return;let s=r.resolveFindCellText(a,t,!E||a.conditionalFormat?.chips===void 0?void 0:{rowIndex:n,sourceRowIndex:C.getSourceIndex(n)??n,rowKey:C.getRowKey(n)??n,colIndex:o});for(let e of r.findRangesInText(s,D,T))i.push({colIndex:o,columnKey:String(a.key),start:e.start,length:e.length})}),i.length===0?s:i};!O&&!x.scanning&&h({scanning:!0}),n.runChunked(F,e=>{if(P)return;let t=C.getRow(e);if(t===void 0)return;let n=C.getTreeRow?.(e)?.aggregates,r;I&&typeof t==`object`&&t?(r=k.get(t),r===void 0?(r=L(t,e),k.set(t,r)):A+=1):r=L(t,e);for(let t of r)if(!(n!==void 0&&t.columnKey in n)){if(N.length>=1e4){P=!0;return}N.push({rowIndex:e,colIndex:t.colIndex,columnKey:t.columnKey,start:t.start,length:t.length})}},{isCancelled:()=>l!==S}).then(e=>{if(!e||l!==S||(d=!1,o&&P===m.getSnapshot().truncated&&c(m.getSnapshot().matches,N)))return;let t=r.resolveCurrentAfterRescan(N,M);h({matches:N,index:r.buildFindIndex(N,i?.toViewRow),currentIndex:t,scanning:!1,truncated:P}),f=i?.toViewRow,_(),j&&v(`query`),!o&&A>0&&b(!1,!0)})},x=()=>{let e=m.getSnapshot();return!i||!e.open||e.query.length===0?!1:p===null||p.rowModel!==i.rowModel||p.columns!==i.columns||p.query!==e.query||p.caseSensitive!==i.caseSensitive||p.conditionalFormatShown!==(i.conditionalFormat!==!1)};return{update:e=>{let t=i;if(i=e,!e.enabled){m.getSnapshot().open&&(h({open:!1,query:``}),y(),_());return}if(t!==e&&x()){b(!1);return}let n=m.getSnapshot();e.toViewRow!==f&&!n.scanning&&(f=e.toViewRow,n.matches.length>0&&h({index:r.buildFindIndex(n.matches,e.toViewRow)}))},open:e=>{if(!i?.enabled)return;let t=m.getSnapshot(),n=e??t.query;h({open:!0,query:n}),n!==t.query||!t.open?b(!0):_()},close:()=>{m.getSnapshot().open&&(h({open:!1,query:``}),y(),_())},setQuery:e=>{let t=m.getSnapshot();!t.open||e===t.query||(h({query:e}),b(!0))},next:()=>{let e=m.getSnapshot(),t=r.stepFindIndex(e.currentIndex,e.matches.length,1);h({currentIndex:t}),_(),v(`step`)},prev:()=>{let e=m.getSnapshot(),t=r.stepFindIndex(e.currentIndex,e.matches.length,-1);h({currentIndex:t}),_(),v(`step`)},subscribe:m.subscribe,getSnapshot:m.getSnapshot,dispose:()=>{l+=1,i=null}}};exports.FIND_HIT_CACHE_ROW_THRESHOLD=a,exports.MAX_FIND_MATCHES=i,exports.createFindController=l;
@@ -1,4 +1,5 @@
1
1
  import type { GridColumn, RowModel } from '../model/gridTypes.unbound.js';
2
+ export type FindNavigateCause = 'query' | 'step';
2
3
  import { type FindIndex, type FindMatch } from '../logic/find.js';
3
4
  export type FindChangeParams = {
4
5
  query: string;
@@ -12,9 +13,10 @@ export type FindArgs<T> = {
12
13
  rowModel: RowModel<T>;
13
14
  columns: readonly GridColumn<T>[];
14
15
  caseSensitive: boolean;
15
- onNavigate: (rowIndex: number, colIndex: number) => void;
16
+ onNavigate: (rowIndex: number, colIndex: number, cause: FindNavigateCause) => void;
16
17
  onChange?: (params: FindChangeParams) => void;
17
18
  conditionalFormat?: boolean | undefined;
19
+ toViewRow?: ((rowIndex: number) => number) | undefined;
18
20
  };
19
21
  export type FindSnapshot = {
20
22
  open: boolean;
@@ -7,7 +7,7 @@ var l = 1e4, u = 5e4, d = /* @__PURE__ */ new Map(), f = [], p = (e, t) => e.len
7
7
  let r = t[n];
8
8
  return e.rowIndex === r.rowIndex && e.colIndex === r.colIndex && e.columnKey === r.columnKey && e.start === r.start && e.length === r.length;
9
9
  }), m = () => {
10
- let l = null, m = 0, h = null, g = !1, _ = null, v = t({
10
+ let l = null, m = 0, h = null, g = !1, _, v = null, y = t({
11
11
  open: !1,
12
12
  query: "",
13
13
  matches: [],
@@ -15,67 +15,67 @@ var l = 1e4, u = 5e4, d = /* @__PURE__ */ new Map(), f = [], p = (e, t) => e.len
15
15
  currentIndex: null,
16
16
  scanning: !1,
17
17
  truncated: !1
18
- }), y = (e) => {
19
- v.setSnapshot({
20
- ...v.getSnapshot(),
18
+ }), b = (e) => {
19
+ y.setSnapshot({
20
+ ...y.getSnapshot(),
21
21
  ...e
22
22
  });
23
- }, b = null, x = () => {
24
- let e = v.getSnapshot(), t = {
23
+ }, x = null, S = () => {
24
+ let e = y.getSnapshot(), t = {
25
25
  query: e.query,
26
26
  matchCount: e.matches.length,
27
27
  currentIndex: e.currentIndex,
28
28
  open: e.open,
29
29
  truncated: e.truncated
30
30
  };
31
- b !== null && b.query === t.query && b.matchCount === t.matchCount && b.currentIndex === t.currentIndex && b.open === t.open && b.truncated === t.truncated || (b = t, l?.onChange?.(t));
32
- }, S = () => {
33
- let e = v.getSnapshot();
34
- if (e.currentIndex === null) return;
35
- let t = e.matches[e.currentIndex];
36
- t && l?.onNavigate(t.rowIndex, t.colIndex);
37
- }, C = () => {
38
- m += 1, _ = null, h = null, g = !1, y({
31
+ x !== null && x.query === t.query && x.matchCount === t.matchCount && x.currentIndex === t.currentIndex && x.open === t.open && x.truncated === t.truncated || (x = t, l?.onChange?.(t));
32
+ }, C = (e) => {
33
+ let t = y.getSnapshot();
34
+ if (t.currentIndex === null) return;
35
+ let n = t.matches[t.currentIndex];
36
+ n && l?.onNavigate(n.rowIndex, n.colIndex, e);
37
+ }, w = () => {
38
+ m += 1, v = null, h = null, g = !1, b({
39
39
  matches: [],
40
40
  index: d,
41
41
  currentIndex: null,
42
42
  scanning: !1,
43
43
  truncated: !1
44
44
  });
45
- }, w = (t, c = !1) => {
46
- let d = l, b = v.getSnapshot();
47
- if (!d || !b.open || b.query.length === 0) {
48
- C(), x();
45
+ }, T = (t, c = !1) => {
46
+ let d = l, x = y.getSnapshot();
47
+ if (!d || !x.open || x.query.length === 0) {
48
+ w(), S();
49
49
  return;
50
50
  }
51
51
  m += 1;
52
- let T = m, { rowModel: E, columns: D, caseSensitive: O } = d, k = d.conditionalFormat !== !1, A = b.query, j = _ !== null && _.query === A && _.caseSensitive === O;
53
- _ = {
54
- rowModel: E,
55
- columns: D,
56
- query: A,
57
- caseSensitive: O,
58
- conditionalFormatShown: k
59
- }, (c || h === null || h.columns !== D || h.query !== A || h.caseSensitive !== O || h.conditionalFormatShown !== k) && (h = {
60
- columns: D,
61
- query: A,
62
- caseSensitive: O,
63
- conditionalFormatShown: k,
52
+ let E = m, { rowModel: D, columns: O, caseSensitive: k } = d, A = d.conditionalFormat !== !1, j = x.query, M = v !== null && v.query === j && v.caseSensitive === k;
53
+ v = {
54
+ rowModel: D,
55
+ columns: O,
56
+ query: j,
57
+ caseSensitive: k,
58
+ conditionalFormatShown: A
59
+ }, (c || h === null || h.columns !== O || h.query !== j || h.caseSensitive !== k || h.conditionalFormatShown !== A) && (h = {
60
+ columns: O,
61
+ query: j,
62
+ caseSensitive: k,
63
+ conditionalFormatShown: A,
64
64
  byRow: /* @__PURE__ */ new WeakMap()
65
65
  });
66
- let M = h.byRow, N = 0, P = t || g;
67
- g = P;
68
- let F = b.currentIndex === null ? null : b.matches[b.currentIndex] ?? null, I = [], L = !1, R = E.getRowCount(), z = R > u, B = (t, n) => {
66
+ let N = h.byRow, P = 0, F = t || g;
67
+ g = F;
68
+ let I = x.currentIndex === null ? null : x.matches[x.currentIndex] ?? null, L = [], R = !1, z = D.getRowCount(), B = z > u, V = (t, n) => {
69
69
  let r = [];
70
- return D.forEach((o, c) => {
71
- if (e(o.key) || !a(o, k)) return;
72
- let l = s(o, t, !k || o.conditionalFormat?.chips === void 0 ? void 0 : {
70
+ return O.forEach((o, c) => {
71
+ if (e(o.key) || !a(o, A)) return;
72
+ let l = s(o, t, !A || o.conditionalFormat?.chips === void 0 ? void 0 : {
73
73
  rowIndex: n,
74
- sourceRowIndex: E.getSourceIndex(n) ?? n,
75
- rowKey: E.getRowKey(n) ?? n,
74
+ sourceRowIndex: D.getSourceIndex(n) ?? n,
75
+ rowKey: D.getRowKey(n) ?? n,
76
76
  colIndex: c
77
77
  });
78
- for (let e of i(l, A, O)) r.push({
78
+ for (let e of i(l, j, k)) r.push({
79
79
  colIndex: c,
80
80
  columnKey: String(o.key),
81
81
  start: e.start,
@@ -83,18 +83,18 @@ var l = 1e4, u = 5e4, d = /* @__PURE__ */ new Map(), f = [], p = (e, t) => e.len
83
83
  });
84
84
  }), r.length === 0 ? f : r;
85
85
  };
86
- !j && !b.scanning && y({ scanning: !0 }), n(R, (e) => {
87
- if (L) return;
88
- let t = E.getRow(e);
86
+ !M && !x.scanning && b({ scanning: !0 }), n(z, (e) => {
87
+ if (R) return;
88
+ let t = D.getRow(e);
89
89
  if (t === void 0) return;
90
- let n;
91
- z && typeof t == "object" && t ? (n = M.get(t), n === void 0 ? (n = B(t, e), M.set(t, n)) : N += 1) : n = B(t, e);
92
- for (let t of n) {
93
- if (I.length >= 1e4) {
94
- L = !0;
90
+ let n = D.getTreeRow?.(e)?.aggregates, r;
91
+ B && typeof t == "object" && t ? (r = N.get(t), r === void 0 ? (r = V(t, e), N.set(t, r)) : P += 1) : r = V(t, e);
92
+ for (let t of r) if (!(n !== void 0 && t.columnKey in n)) {
93
+ if (L.length >= 1e4) {
94
+ R = !0;
95
95
  return;
96
96
  }
97
- I.push({
97
+ L.push({
98
98
  rowIndex: e,
99
99
  colIndex: t.colIndex,
100
100
  columnKey: t.columnKey,
@@ -102,61 +102,66 @@ var l = 1e4, u = 5e4, d = /* @__PURE__ */ new Map(), f = [], p = (e, t) => e.len
102
102
  length: t.length
103
103
  });
104
104
  }
105
- }, { isCancelled: () => m !== T }).then((e) => {
106
- if (!e || m !== T || (g = !1, c && L === v.getSnapshot().truncated && p(v.getSnapshot().matches, I))) return;
107
- let t = o(I, F);
108
- y({
109
- matches: I,
110
- index: r(I),
105
+ }, { isCancelled: () => m !== E }).then((e) => {
106
+ if (!e || m !== E || (g = !1, c && R === y.getSnapshot().truncated && p(y.getSnapshot().matches, L))) return;
107
+ let t = o(L, I);
108
+ b({
109
+ matches: L,
110
+ index: r(L, l?.toViewRow),
111
111
  currentIndex: t,
112
112
  scanning: !1,
113
- truncated: L
114
- }), x(), P && S(), !c && N > 0 && w(!1, !0);
113
+ truncated: R
114
+ }), _ = l?.toViewRow, S(), F && C("query"), !c && P > 0 && T(!1, !0);
115
115
  });
116
- }, T = () => {
117
- let e = v.getSnapshot();
118
- return !l || !e.open || e.query.length === 0 ? !1 : _ === null || _.rowModel !== l.rowModel || _.columns !== l.columns || _.query !== e.query || _.caseSensitive !== l.caseSensitive || _.conditionalFormatShown !== (l.conditionalFormat !== !1);
116
+ }, E = () => {
117
+ let e = y.getSnapshot();
118
+ return !l || !e.open || e.query.length === 0 ? !1 : v === null || v.rowModel !== l.rowModel || v.columns !== l.columns || v.query !== e.query || v.caseSensitive !== l.caseSensitive || v.conditionalFormatShown !== (l.conditionalFormat !== !1);
119
119
  };
120
120
  return {
121
121
  update: (e) => {
122
122
  let t = l;
123
123
  if (l = e, !e.enabled) {
124
- v.getSnapshot().open && (y({
124
+ y.getSnapshot().open && (b({
125
125
  open: !1,
126
126
  query: ""
127
- }), C(), x());
127
+ }), w(), S());
128
128
  return;
129
129
  }
130
- t !== e && T() && w(!1);
130
+ if (t !== e && E()) {
131
+ T(!1);
132
+ return;
133
+ }
134
+ let n = y.getSnapshot();
135
+ e.toViewRow !== _ && !n.scanning && (_ = e.toViewRow, n.matches.length > 0 && b({ index: r(n.matches, e.toViewRow) }));
131
136
  },
132
137
  open: (e) => {
133
138
  if (!l?.enabled) return;
134
- let t = v.getSnapshot(), n = e ?? t.query;
135
- y({
139
+ let t = y.getSnapshot(), n = e ?? t.query;
140
+ b({
136
141
  open: !0,
137
142
  query: n
138
- }), n !== t.query || !t.open ? w(!0) : x();
143
+ }), n !== t.query || !t.open ? T(!0) : S();
139
144
  },
140
145
  close: () => {
141
- v.getSnapshot().open && (y({
146
+ y.getSnapshot().open && (b({
142
147
  open: !1,
143
148
  query: ""
144
- }), C(), x());
149
+ }), w(), S());
145
150
  },
146
151
  setQuery: (e) => {
147
- let t = v.getSnapshot();
148
- !t.open || e === t.query || (y({ query: e }), w(!0));
152
+ let t = y.getSnapshot();
153
+ !t.open || e === t.query || (b({ query: e }), T(!0));
149
154
  },
150
155
  next: () => {
151
- let e = v.getSnapshot(), t = c(e.currentIndex, e.matches.length, 1);
152
- y({ currentIndex: t }), x(), S();
156
+ let e = y.getSnapshot(), t = c(e.currentIndex, e.matches.length, 1);
157
+ b({ currentIndex: t }), S(), C("step");
153
158
  },
154
159
  prev: () => {
155
- let e = v.getSnapshot(), t = c(e.currentIndex, e.matches.length, -1);
156
- y({ currentIndex: t }), x(), S();
160
+ let e = y.getSnapshot(), t = c(e.currentIndex, e.matches.length, -1);
161
+ b({ currentIndex: t }), S(), C("step");
157
162
  },
158
- subscribe: v.subscribe,
159
- getSnapshot: v.getSnapshot,
163
+ subscribe: y.subscribe,
164
+ getSnapshot: y.getSnapshot,
160
165
  dispose: () => {
161
166
  m += 1, l = null;
162
167
  }
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../logic/historyRebase.cjs"),n=require("../logic/history.cjs");var r=()=>{let r=null,i=n.createHistoryStack(),a=null,o=null,s={canUndo:!1,canRedo:!1},c=null,l=!1,u=()=>r!==null&&r.enabled&&r.onRowsChange!=null,d=()=>u()&&n.canUndoHistory(i),f=()=>u()&&n.canRedoHistory(i),p=()=>{let e={canUndo:d(),canRedo:f()};e.canUndo===s.canUndo&&e.canRedo===s.canRedo||(s=e,r?.onUndoRedoStateChange?.(e))},m=e=>{r=e,e.rows!==o&&(c=null),o===null?o=e.rows:e.rows!==o&&(o=e.rows,a===e.rows?a=null:(a=null,i=n.createHistoryStack(),l=!1)),p()},h=t=>{if(r===null)return;let{dispatch:n}=r,i=t.selection;i?.type===`cell`?(n(e.gridActions.startSelection(i.range.start)),n(e.gridActions.updateSelection(i.range.end)),n(e.gridActions.endSelection())):i?.type===`row`?(n(e.gridActions.startRowSelection(i.startRow)),n(e.gridActions.updateRowSelection(i.endRow)),n(e.gridActions.endSelection())):i?.type===`col`?(n(e.gridActions.startColumnSelection(i.startCol)),n(e.gridActions.updateColumnSelection(i.endCol)),n(e.gridActions.endSelection())):n(e.gridActions.clearSelection()),n(e.gridActions.activateCell(t.activeCell))},g=(e,t)=>{r===null||!r.onRowsChange||(r.enabled&&(i=n.pushHistory(i,{rows:e,after:t,selection:r.selection,activeCell:r.activeCell},r.limit),a=t,p()),c=t,r.onRowsChange(t))},_=e=>{r===null||!r.onRowsChange||g(r.rows,e)},v=e=>{if(!(r===null||!r.onRowsChange)){if(r.enabled){a=e;let t=i.past[i.past.length-1];t&&(i={...i,past:[...i.past.slice(0,-1),{...t,after:e}]})}c=e,r.onRowsChange(e)}},y=(e,t)=>{if(r===null||!r.onRowsChange)return;let n=c??r.rows,i=Array.isArray(e)?e:e(n);if(t?.undoable!==!1){g(n,i);return}r.enabled&&(a=i,l=!0),c=i,r.onRowsChange(i)},b=(e,n)=>{if(!e)return null;if(!l||e.after===n)return e.rows;let i=r?.rowKeyGetter;return!i&&(e.rows.length!==e.after.length||e.after.length!==n.length)?e.rows:t.revertRowsChange(e.rows,e.after,n,i??((e,t)=>t))},x=e=>{e===null||r===null||!r.onRowsChange||(i=e.stack,a=e.snapshot.rows,c=e.snapshot.rows,r.onRowsChange(e.snapshot.rows),h(e.snapshot),r.onAfterRestore?.(e.snapshot.activeCell),p())},S=(e,t)=>r===null?null:{rows:e,after:t,selection:r.selection,activeCell:r.activeCell},C=(e,t)=>{if(!u()||r===null)return;let n=c??r.rows,a=b(e,n),o=a===null?null:S(n,a);if(a===null||o===null)return;let s=t(i,o);x(s===null?null:{stack:s.stack,snapshot:{...s.snapshot,rows:a}})};return{update:m,handleRowsChange:_,amendRowsChange:v,applyRows:y,undo:()=>{C(i.past[i.past.length-1],n.undoHistory)},redo:()=>{C(i.future[i.future.length-1],n.redoHistory)},canUndo:d,canRedo:f,clearHistory:()=>{i=n.createHistoryStack(),l=!1,p()}}};exports.createHistoryController=r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../logic/detailRow.cjs"),n=require("../logic/historyRebase.cjs"),r=require("../logic/history.cjs");var i=(e,n)=>{let r=new Map;return{getRowKey:t=>t>=0&&t<e.getRowCount()?e.getRowKey(t):void 0,viewIndexOf:i=>{if(n){let e=n.structure.keyToIndex.get(i);for(;e!==void 0&&e>=0;){let t=n.display.viewIndexOf[e];if(t>=0)return t;e=n.structure.parent[e]}return-1}return t.findViewRowIndexByKey(e,i,r)}}},a=()=>{let t=null,i=r.createHistoryStack(),a=null,o=null,s={canUndo:!1,canRedo:!1},c=null,l=!1,u=null,d=()=>t!==null&&t.enabled&&t.onRowsChange!=null,f=()=>d()&&r.canUndoHistory(i),p=()=>d()&&r.canRedoHistory(i),m=()=>{let e={canUndo:f(),canRedo:p()};e.canUndo===s.canUndo&&e.canRedo===s.canRedo||(s=e,t?.onUndoRedoStateChange?.(e))},h=e=>{let n=o!==null&&e.rows!==o;t=e,e.rows!==o&&(c=null),o===null?o=e.rows:e.rows!==o&&(o=e.rows,a===e.rows?a=null:(a=null,i=r.createHistoryStack(),l=!1)),m();let s=u;s!==null&&(e.rows===s.rows?(u=null,e.onAfterRestore?.(_(s.entry))):n&&(u=null))},g=(e,n)=>{let r=t?.rowLocator;if(!r)return;let i=e=>e===void 0||e<0?void 0:r.getRowKey(e),a=e?.type===`cell`?[e.range.start.row,e.range.end.row]:e?.type===`row`?[e.startRow,e.endRow]:[void 0,void 0];return{active:i(n?.row),start:i(a[0]),end:i(a[1])}},_=n=>{let r=t?.rowLocator,i=n.rowKeys;if(!t||!r||!i)return n.activeCell;let{dispatch:a}=t,o=e=>e===void 0?-1:r.viewIndexOf(e),s=n.activeCell,c=o(i.active);s&&c>=0&&c!==s.row&&(s={row:c,col:s.col});let l=n.selection,u=o(i.start),d=o(i.end);return l?.type===`cell`&&u>=0&&d>=0?(a(e.gridActions.startSelection({row:u,col:l.range.start.col})),a(e.gridActions.updateSelection({row:d,col:l.range.end.col})),a(e.gridActions.endSelection())):l?.type===`row`&&u>=0&&d>=0&&(a(e.gridActions.startRowSelection(u)),a(e.gridActions.updateRowSelection(d)),a(e.gridActions.endSelection())),s!==null&&t.noteFollowMove?.(s),a(e.gridActions.activateCell(s)),s},v=n=>{if(t===null)return;let{dispatch:r}=t,i=n.selection;i?.type===`cell`?(r(e.gridActions.startSelection(i.range.start)),r(e.gridActions.updateSelection(i.range.end)),r(e.gridActions.endSelection())):i?.type===`row`?(r(e.gridActions.startRowSelection(i.startRow)),r(e.gridActions.updateRowSelection(i.endRow)),r(e.gridActions.endSelection())):i?.type===`col`?(r(e.gridActions.startColumnSelection(i.startCol)),r(e.gridActions.updateColumnSelection(i.endCol)),r(e.gridActions.endSelection())):r(e.gridActions.clearSelection()),r(e.gridActions.activateCell(n.activeCell))},y=(e,n)=>{t===null||!t.onRowsChange||(t.enabled&&(i=r.pushHistory(i,{rows:e,after:n,selection:t.selection,activeCell:t.activeCell,rowKeys:g(t.selection,t.activeCell)},t.limit),a=n,m()),c=n,t.onGridRowsChange?.(e,n),t.onRowsChange(n))},b=e=>{t===null||!t.onRowsChange||y(t.rows,e)},x=e=>{if(t===null||!t.onRowsChange)return;if(t.enabled){a=e;let t=i.past[i.past.length-1];t&&(i={...i,past:[...i.past.slice(0,-1),{...t,after:e}]})}let n=c??t.rows;c=e,t.onGridRowsChange?.(n,e),t.onRowsChange(e)},S=(e,n)=>{if(t===null||!t.onRowsChange)return;let r=c??t.rows,i=Array.isArray(e)?e:e(r);if(n?.undoable!==!1){y(r,i);return}t.enabled&&(a=i,l=!0),c=i,t.onRowsChange(i)},C=(e,r)=>{if(!e)return null;if(!l||e.after===r)return e.rows;let i=t?.rowKeyGetter;return!i&&(e.rows.length!==e.after.length||e.after.length!==r.length)?e.rows:n.revertRowsChange(e.rows,e.after,r,i??((e,t)=>t))},w=e=>{if(e===null||t===null||!t.onRowsChange)return;i=e.stack,a=e.snapshot.rows;let n=c??t.rows;c=e.snapshot.rows,t.onGridRowsChange?.(n,e.snapshot.rows),t.onRowsChange(e.snapshot.rows),e.snapshot.rowKeys&&t.rowLocator&&e.snapshot.activeCell!==null&&t.noteFollowMove?.(e.snapshot.activeCell),v(e.snapshot),e.snapshot.rowKeys&&t.rowLocator?u={rows:e.snapshot.rows,entry:e.snapshot}:t.onAfterRestore?.(e.snapshot.activeCell),m()},T=(e,n)=>t===null?null:{rows:e,after:n,selection:t.selection,activeCell:t.activeCell,rowKeys:g(t.selection,t.activeCell)},E=(e,n)=>{if(!d()||t===null)return;let r=c??t.rows,a=C(e,r),o=a===null?null:T(r,a);if(a===null||o===null)return;let s=n(i,o);w(s===null?null:{stack:s.stack,snapshot:{...s.snapshot,rows:a}})};return{update:h,handleRowsChange:b,amendRowsChange:x,applyRows:S,undo:()=>{E(i.past[i.past.length-1],r.undoHistory)},redo:()=>{E(i.future[i.future.length-1],r.redoHistory)},canUndo:f,canRedo:p,clearHistory:()=>{i=r.createHistoryStack(),l=!1,m()}}};exports.createHistoryController=a,exports.createHistoryRowLocator=i;
@@ -1,11 +1,31 @@
1
1
  import { type GridUiAction } from '../model/gridActions.js';
2
- import type { CellCoord, GridSelection, UndoRedoState } from '../model/gridTypes.unbound.js';
2
+ import type { CellCoord, GridRowKey, GridSelection, RowModel, UndoRedoState } from '../model/gridTypes.unbound.js';
3
3
  export type GridHistoryEntry<T> = {
4
4
  rows: T[];
5
5
  after: T[];
6
6
  selection: GridSelection;
7
7
  activeCell: CellCoord | null;
8
+ rowKeys?: HistoryRowKeys | undefined;
8
9
  };
10
+ type HistoryRowKeys = {
11
+ active: GridRowKey | undefined;
12
+ start: GridRowKey | undefined;
13
+ end: GridRowKey | undefined;
14
+ };
15
+ export type HistoryRowLocator = {
16
+ getRowKey: (viewIndex: number) => GridRowKey | undefined;
17
+ viewIndexOf: (rowKey: GridRowKey) => number;
18
+ };
19
+ type HistoryTreeLookup = {
20
+ structure: {
21
+ keyToIndex: ReadonlyMap<GridRowKey, number>;
22
+ parent: Int32Array;
23
+ };
24
+ display: {
25
+ viewIndexOf: Int32Array;
26
+ };
27
+ };
28
+ export declare const createHistoryRowLocator: <T>(rowModel: RowModel<T>, tree?: HistoryTreeLookup | null | undefined) => HistoryRowLocator;
9
29
  export type HistoryApplyRowsOptions = {
10
30
  undoable?: boolean | undefined;
11
31
  };
@@ -20,6 +40,9 @@ export type HistoryControllerArgs<T> = {
20
40
  onUndoRedoStateChange?: (state: UndoRedoState) => void;
21
41
  onAfterRestore?: (activeCell: CellCoord | null) => void;
22
42
  rowKeyGetter?: ((row: T, index: number) => unknown) | undefined;
43
+ onGridRowsChange?: ((prevRows: T[], nextRows: T[]) => void) | undefined;
44
+ rowLocator?: HistoryRowLocator | undefined;
45
+ noteFollowMove?: ((cell: CellCoord) => void) | undefined;
23
46
  };
24
47
  export type HistoryController<T> = {
25
48
  update: (args: HistoryControllerArgs<T>) => void;
@@ -33,3 +56,4 @@ export type HistoryController<T> = {
33
56
  clearHistory: () => void;
34
57
  };
35
58
  export declare const createHistoryController: <T>() => HistoryController<T>;
59
+ export {};
@@ -1,97 +1,151 @@
1
1
  import { gridActions as e } from "../model/gridActions.js";
2
- import { revertRowsChange as t } from "../logic/historyRebase.js";
3
- import { canRedoHistory as n, canUndoHistory as r, createHistoryStack as i, pushHistory as a, redoHistory as o, undoHistory as s } from "../logic/history.js";
2
+ import { findViewRowIndexByKey as t } from "../logic/detailRow.js";
3
+ import { revertRowsChange as n } from "../logic/historyRebase.js";
4
+ import { canRedoHistory as r, canUndoHistory as i, createHistoryStack as a, pushHistory as o, redoHistory as s, undoHistory as c } from "../logic/history.js";
4
5
  //#region src/controllers/historyController.ts
5
- var c = () => {
6
- let c = null, l = i(), u = null, d = null, f = {
6
+ var l = (e, n) => {
7
+ let r = /* @__PURE__ */ new Map();
8
+ return {
9
+ getRowKey: (t) => t >= 0 && t < e.getRowCount() ? e.getRowKey(t) : void 0,
10
+ viewIndexOf: (i) => {
11
+ if (n) {
12
+ let e = n.structure.keyToIndex.get(i);
13
+ for (; e !== void 0 && e >= 0;) {
14
+ let t = n.display.viewIndexOf[e];
15
+ if (t >= 0) return t;
16
+ e = n.structure.parent[e];
17
+ }
18
+ return -1;
19
+ }
20
+ return t(e, i, r);
21
+ }
22
+ };
23
+ }, u = () => {
24
+ let t = null, l = a(), u = null, d = null, f = {
7
25
  canUndo: !1,
8
26
  canRedo: !1
9
- }, p = null, m = !1, h = () => c !== null && c.enabled && c.onRowsChange != null, g = () => h() && r(l), _ = () => h() && n(l), v = () => {
27
+ }, p = null, m = !1, h = null, g = () => t !== null && t.enabled && t.onRowsChange != null, _ = () => g() && i(l), v = () => g() && r(l), y = () => {
10
28
  let e = {
11
- canUndo: g(),
12
- canRedo: _()
29
+ canUndo: _(),
30
+ canRedo: v()
31
+ };
32
+ e.canUndo === f.canUndo && e.canRedo === f.canRedo || (f = e, t?.onUndoRedoStateChange?.(e));
33
+ }, b = (e) => {
34
+ let n = d !== null && e.rows !== d;
35
+ t = e, e.rows !== d && (p = null), d === null ? d = e.rows : e.rows !== d && (d = e.rows, u === e.rows ? u = null : (u = null, l = a(), m = !1)), y();
36
+ let r = h;
37
+ r !== null && (e.rows === r.rows ? (h = null, e.onAfterRestore?.(S(r.entry))) : n && (h = null));
38
+ }, x = (e, n) => {
39
+ let r = t?.rowLocator;
40
+ if (!r) return;
41
+ let i = (e) => e === void 0 || e < 0 ? void 0 : r.getRowKey(e), a = e?.type === "cell" ? [e.range.start.row, e.range.end.row] : e?.type === "row" ? [e.startRow, e.endRow] : [void 0, void 0];
42
+ return {
43
+ active: i(n?.row),
44
+ start: i(a[0]),
45
+ end: i(a[1])
13
46
  };
14
- e.canUndo === f.canUndo && e.canRedo === f.canRedo || (f = e, c?.onUndoRedoStateChange?.(e));
15
- }, y = (e) => {
16
- c = e, e.rows !== d && (p = null), d === null ? d = e.rows : e.rows !== d && (d = e.rows, u === e.rows ? u = null : (u = null, l = i(), m = !1)), v();
17
- }, b = (t) => {
18
- if (c === null) return;
19
- let { dispatch: n } = c, r = t.selection;
20
- r?.type === "cell" ? (n(e.startSelection(r.range.start)), n(e.updateSelection(r.range.end)), n(e.endSelection())) : r?.type === "row" ? (n(e.startRowSelection(r.startRow)), n(e.updateRowSelection(r.endRow)), n(e.endSelection())) : r?.type === "col" ? (n(e.startColumnSelection(r.startCol)), n(e.updateColumnSelection(r.endCol)), n(e.endSelection())) : n(e.clearSelection()), n(e.activateCell(t.activeCell));
21
- }, x = (e, t) => {
22
- c === null || !c.onRowsChange || (c.enabled && (l = a(l, {
47
+ }, S = (n) => {
48
+ let r = t?.rowLocator, i = n.rowKeys;
49
+ if (!t || !r || !i) return n.activeCell;
50
+ let { dispatch: a } = t, o = (e) => e === void 0 ? -1 : r.viewIndexOf(e), s = n.activeCell, c = o(i.active);
51
+ s && c >= 0 && c !== s.row && (s = {
52
+ row: c,
53
+ col: s.col
54
+ });
55
+ let l = n.selection, u = o(i.start), d = o(i.end);
56
+ return l?.type === "cell" && u >= 0 && d >= 0 ? (a(e.startSelection({
57
+ row: u,
58
+ col: l.range.start.col
59
+ })), a(e.updateSelection({
60
+ row: d,
61
+ col: l.range.end.col
62
+ })), a(e.endSelection())) : l?.type === "row" && u >= 0 && d >= 0 && (a(e.startRowSelection(u)), a(e.updateRowSelection(d)), a(e.endSelection())), s !== null && t.noteFollowMove?.(s), a(e.activateCell(s)), s;
63
+ }, C = (n) => {
64
+ if (t === null) return;
65
+ let { dispatch: r } = t, i = n.selection;
66
+ i?.type === "cell" ? (r(e.startSelection(i.range.start)), r(e.updateSelection(i.range.end)), r(e.endSelection())) : i?.type === "row" ? (r(e.startRowSelection(i.startRow)), r(e.updateRowSelection(i.endRow)), r(e.endSelection())) : i?.type === "col" ? (r(e.startColumnSelection(i.startCol)), r(e.updateColumnSelection(i.endCol)), r(e.endSelection())) : r(e.clearSelection()), r(e.activateCell(n.activeCell));
67
+ }, w = (e, n) => {
68
+ t === null || !t.onRowsChange || (t.enabled && (l = o(l, {
23
69
  rows: e,
24
- after: t,
25
- selection: c.selection,
26
- activeCell: c.activeCell
27
- }, c.limit), u = t, v()), p = t, c.onRowsChange(t));
28
- }, S = (e) => {
29
- c === null || !c.onRowsChange || x(c.rows, e);
30
- }, C = (e) => {
31
- if (!(c === null || !c.onRowsChange)) {
32
- if (c.enabled) {
33
- u = e;
34
- let t = l.past[l.past.length - 1];
35
- t && (l = {
36
- ...l,
37
- past: [...l.past.slice(0, -1), {
38
- ...t,
39
- after: e
40
- }]
41
- });
42
- }
43
- p = e, c.onRowsChange(e);
70
+ after: n,
71
+ selection: t.selection,
72
+ activeCell: t.activeCell,
73
+ rowKeys: x(t.selection, t.activeCell)
74
+ }, t.limit), u = n, y()), p = n, t.onGridRowsChange?.(e, n), t.onRowsChange(n));
75
+ }, T = (e) => {
76
+ t === null || !t.onRowsChange || w(t.rows, e);
77
+ }, E = (e) => {
78
+ if (t === null || !t.onRowsChange) return;
79
+ if (t.enabled) {
80
+ u = e;
81
+ let t = l.past[l.past.length - 1];
82
+ t && (l = {
83
+ ...l,
84
+ past: [...l.past.slice(0, -1), {
85
+ ...t,
86
+ after: e
87
+ }]
88
+ });
44
89
  }
45
- }, w = (e, t) => {
46
- if (c === null || !c.onRowsChange) return;
47
- let n = p ?? c.rows, r = Array.isArray(e) ? e : e(n);
48
- if (t?.undoable !== !1) {
49
- x(n, r);
90
+ let n = p ?? t.rows;
91
+ p = e, t.onGridRowsChange?.(n, e), t.onRowsChange(e);
92
+ }, D = (e, n) => {
93
+ if (t === null || !t.onRowsChange) return;
94
+ let r = p ?? t.rows, i = Array.isArray(e) ? e : e(r);
95
+ if (n?.undoable !== !1) {
96
+ w(r, i);
50
97
  return;
51
98
  }
52
- c.enabled && (u = r, m = !0), p = r, c.onRowsChange(r);
53
- }, T = (e, n) => {
99
+ t.enabled && (u = i, m = !0), p = i, t.onRowsChange(i);
100
+ }, O = (e, r) => {
54
101
  if (!e) return null;
55
- if (!m || e.after === n) return e.rows;
56
- let r = c?.rowKeyGetter;
57
- return !r && (e.rows.length !== e.after.length || e.after.length !== n.length) ? e.rows : t(e.rows, e.after, n, r ?? ((e, t) => t));
58
- }, E = (e) => {
59
- e === null || c === null || !c.onRowsChange || (l = e.stack, u = e.snapshot.rows, p = e.snapshot.rows, c.onRowsChange(e.snapshot.rows), b(e.snapshot), c.onAfterRestore?.(e.snapshot.activeCell), v());
60
- }, D = (e, t) => c === null ? null : {
102
+ if (!m || e.after === r) return e.rows;
103
+ let i = t?.rowKeyGetter;
104
+ return !i && (e.rows.length !== e.after.length || e.after.length !== r.length) ? e.rows : n(e.rows, e.after, r, i ?? ((e, t) => t));
105
+ }, k = (e) => {
106
+ if (e === null || t === null || !t.onRowsChange) return;
107
+ l = e.stack, u = e.snapshot.rows;
108
+ let n = p ?? t.rows;
109
+ p = e.snapshot.rows, t.onGridRowsChange?.(n, e.snapshot.rows), t.onRowsChange(e.snapshot.rows), e.snapshot.rowKeys && t.rowLocator && e.snapshot.activeCell !== null && t.noteFollowMove?.(e.snapshot.activeCell), C(e.snapshot), e.snapshot.rowKeys && t.rowLocator ? h = {
110
+ rows: e.snapshot.rows,
111
+ entry: e.snapshot
112
+ } : t.onAfterRestore?.(e.snapshot.activeCell), y();
113
+ }, A = (e, n) => t === null ? null : {
61
114
  rows: e,
62
- after: t,
63
- selection: c.selection,
64
- activeCell: c.activeCell
65
- }, O = (e, t) => {
66
- if (!h() || c === null) return;
67
- let n = p ?? c.rows, r = T(e, n), i = r === null ? null : D(n, r);
68
- if (r === null || i === null) return;
69
- let a = t(l, i);
70
- E(a === null ? null : {
71
- stack: a.stack,
115
+ after: n,
116
+ selection: t.selection,
117
+ activeCell: t.activeCell,
118
+ rowKeys: x(t.selection, t.activeCell)
119
+ }, j = (e, n) => {
120
+ if (!g() || t === null) return;
121
+ let r = p ?? t.rows, i = O(e, r), a = i === null ? null : A(r, i);
122
+ if (i === null || a === null) return;
123
+ let o = n(l, a);
124
+ k(o === null ? null : {
125
+ stack: o.stack,
72
126
  snapshot: {
73
- ...a.snapshot,
74
- rows: r
127
+ ...o.snapshot,
128
+ rows: i
75
129
  }
76
130
  });
77
131
  };
78
132
  return {
79
- update: y,
80
- handleRowsChange: S,
81
- amendRowsChange: C,
82
- applyRows: w,
133
+ update: b,
134
+ handleRowsChange: T,
135
+ amendRowsChange: E,
136
+ applyRows: D,
83
137
  undo: () => {
84
- O(l.past[l.past.length - 1], s);
138
+ j(l.past[l.past.length - 1], c);
85
139
  },
86
140
  redo: () => {
87
- O(l.future[l.future.length - 1], o);
141
+ j(l.future[l.future.length - 1], s);
88
142
  },
89
- canUndo: g,
90
- canRedo: _,
143
+ canUndo: _,
144
+ canRedo: v,
91
145
  clearHistory: () => {
92
- l = i(), m = !1, v();
146
+ l = a(), m = !1, y();
93
147
  }
94
148
  };
95
149
  };
96
150
  //#endregion
97
- export { c as createHistoryController };
151
+ export { u as createHistoryController, l as createHistoryRowLocator };