open-grid 1.6.1 → 1.7.1

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 (134) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/ExportProgressView-BYPw8osg.cjs +2 -0
  3. package/dist/ExportProgressView-Bt5-z7rE.js +2 -0
  4. package/dist/LcpMergeOrderer-CeP6C6G1.cjs +2 -0
  5. package/dist/LcpMergeOrderer-Ebwuir-r.js +2 -0
  6. package/dist/OpenGrid-Bh1NMOcm.cjs +98 -0
  7. package/dist/OpenGrid-CeXt04ho.js +98 -0
  8. package/dist/Registry-CrT46EAO.js +2 -0
  9. package/dist/Registry-DpHOpU5V.cjs +2 -0
  10. package/dist/XlsxChannel-CuOZ3LQz.js +2 -0
  11. package/dist/XlsxChannel-DQHLGend.cjs +2 -0
  12. package/dist/XlsxWorkbookWriter-DixuNGtw.cjs +3 -0
  13. package/dist/XlsxWorkbookWriter-VgbibI0Z.js +3 -0
  14. package/dist/fflate-Cs3txMgg.js +2 -0
  15. package/dist/fflate-G9RAFEgF.cjs +2 -0
  16. package/dist/index-1OXjJmct.js +2 -0
  17. package/dist/index-B5V7e4Xc.js +2 -0
  18. package/dist/index-DbKDox8y.cjs +2 -0
  19. package/dist/index-HaDoF1HM.cjs +2 -0
  20. package/dist/open-grid-react.cjs +1 -27
  21. package/dist/open-grid-react.js +1 -30
  22. package/dist/open-grid-vue.cjs +1 -31
  23. package/dist/open-grid-vue.js +1 -33
  24. package/dist/open-grid.cjs +6 -275
  25. package/dist/open-grid.js +6 -293
  26. package/dist/sinks-BCZFMGQJ.cjs +2 -0
  27. package/dist/sinks-qkBJ5bKn.js +2 -0
  28. package/dist/types/core/CFRenderBridge.d.ts +5 -1
  29. package/dist/types/core/CellEditManager.d.ts +26 -2
  30. package/dist/types/core/CellEventHandler.d.ts +6 -2
  31. package/dist/types/core/ColumnLayout.d.ts +8 -0
  32. package/dist/types/core/DataLayer.d.ts +48 -1
  33. package/dist/types/core/DetailManager.d.ts +43 -2
  34. package/dist/types/core/ExportManager.d.ts +25 -0
  35. package/dist/types/core/FindBarManager.d.ts +6 -2
  36. package/dist/types/core/FlatRowModel.d.ts +61 -3
  37. package/dist/types/core/FooterManager.d.ts +43 -1
  38. package/dist/types/core/FormulaController.d.ts +4 -4
  39. package/dist/types/core/GridComposer.d.ts +11 -1
  40. package/dist/types/core/GridRenderer.d.ts +84 -19
  41. package/dist/types/core/GroupTreeManager.d.ts +6 -4
  42. package/dist/types/core/KeyboardManager.d.ts +3 -2
  43. package/dist/types/core/MutationService.d.ts +10 -8
  44. package/dist/types/core/OpenGrid.d.ts +7 -5
  45. package/dist/types/core/RangeSelectionManager.d.ts +23 -2
  46. package/dist/types/core/RenderController.d.ts +126 -8
  47. package/dist/types/core/SortFilterManager.d.ts +10 -2
  48. package/dist/types/core/VirtualScroll.d.ts +12 -0
  49. package/dist/types/core/coordinate/CellTextPolicy.d.ts +58 -0
  50. package/dist/types/core/coordinate/ColumnGeometry.d.ts +60 -0
  51. package/dist/types/core/coordinate/ColumnWindow.d.ts +40 -0
  52. package/dist/types/core/coordinate/ColumnWindowPolicy.d.ts +89 -0
  53. package/dist/types/core/coordinate/ExtraColumns.d.ts +39 -0
  54. package/dist/types/core/coordinate/RangeRectCalculator.d.ts +35 -0
  55. package/dist/types/core/coordinate/ViewportHeightJudge.d.ts +28 -0
  56. package/dist/types/core/coordinate/geometryPorts.d.ts +250 -0
  57. package/dist/types/core/coordinate/ports.d.ts +5 -0
  58. package/dist/types/core/domain/footer/FooterValues.d.ts +50 -0
  59. package/dist/types/core/domain/footer/ports.d.ts +31 -0
  60. package/dist/types/core/domain/render/RenderPlanner.d.ts +17 -0
  61. package/dist/types/core/domain/render/RenderRequest.d.ts +91 -0
  62. package/dist/types/core/domain/render/ports.d.ts +169 -0
  63. package/dist/types/core/domain/resize/ResizeGesture.d.ts +25 -0
  64. package/dist/types/core/domain/resize/ResizeHitZone.d.ts +23 -0
  65. package/dist/types/core/domain/resize/ports.d.ts +64 -0
  66. package/dist/types/core/domain/sort/ComparisonOrderer.d.ts +11 -0
  67. package/dist/types/core/domain/sort/LcpMergeOrderer.d.ts +15 -0
  68. package/dist/types/core/domain/sort/RankIndex.d.ts +74 -0
  69. package/dist/types/core/domain/sort/SortCostEstimate.d.ts +36 -0
  70. package/dist/types/core/domain/sort/SortKeyColumn.d.ts +89 -0
  71. package/dist/types/core/domain/sort/SortKeyStore.d.ts +34 -0
  72. package/dist/types/core/domain/sort/Sorter.d.ts +54 -0
  73. package/dist/types/core/domain/sort/SyncSortRunner.d.ts +9 -0
  74. package/dist/types/core/domain/sort/commonPrefix.d.ts +5 -0
  75. package/dist/types/core/domain/sort/ports.d.ts +140 -0
  76. package/dist/types/core/export/ExportProgressView.d.ts +28 -0
  77. package/dist/types/core/export/channels/XlsxChannel.d.ts +38 -1
  78. package/dist/types/core/export/channels/XlsxRichTextRun.d.ts +14 -0
  79. package/dist/types/core/export/channels/XlsxSheetXml.d.ts +19 -0
  80. package/dist/types/core/export/channels/XlsxStyleEntries.d.ts +80 -0
  81. package/dist/types/core/export/channels/XlsxStylesRegistry.d.ts +20 -0
  82. package/dist/types/core/export/channels/XlsxWorkbookWriter.d.ts +20 -0
  83. package/dist/types/core/export/channels/XlsxXml.d.ts +6 -0
  84. package/dist/types/core/export/index.d.ts +2 -0
  85. package/dist/types/core/export/sinks.d.ts +81 -0
  86. package/dist/types/core/export/types.d.ts +63 -0
  87. package/dist/types/core/host/archCheck.d.ts +16 -1
  88. package/dist/types/core/i18n/locales/en.d.ts +6 -0
  89. package/dist/types/core/i18n/locales/ko.d.ts +6 -0
  90. package/dist/types/core/i18n/types.d.ts +8 -0
  91. package/dist/types/core/render/FooterView.d.ts +121 -0
  92. package/dist/types/core/render/GeometryApplier.d.ts +55 -0
  93. package/dist/types/core/render/HorizontalReveal.d.ts +26 -0
  94. package/dist/types/core/render/RangeOverlayAdapter.d.ts +10 -0
  95. package/dist/types/core/render/RenderScheduler.d.ts +225 -0
  96. package/dist/types/core/render/ResizeSinkAdapter.d.ts +35 -0
  97. package/dist/types/core/render/ScrollFollower.d.ts +34 -0
  98. package/dist/types/core/render/ScrollObserver.d.ts +47 -0
  99. package/dist/types/core/render/ScrollbarGutter.d.ts +19 -0
  100. package/dist/types/core/render/body/BodyEventRouter.d.ts +58 -0
  101. package/dist/types/core/render/body/BodyRowSet.d.ts +28 -0
  102. package/dist/types/core/render/body/BodyView.d.ts +185 -0
  103. package/dist/types/core/render/body/CellLocator.d.ts +36 -0
  104. package/dist/types/core/render/body/CellRegistry.d.ts +24 -0
  105. package/dist/types/core/render/body/ColumnPaintPlan.d.ts +19 -0
  106. package/dist/types/core/render/body/ExtraCellPainters.d.ts +20 -0
  107. package/dist/types/core/render/body/rows/BodyRowContext.d.ts +138 -0
  108. package/dist/types/core/render/body/rows/DataRowPainter.d.ts +58 -0
  109. package/dist/types/core/render/body/rows/DetailRowPainter.d.ts +24 -0
  110. package/dist/types/core/render/body/rows/GroupRowPainter.d.ts +32 -0
  111. package/dist/types/core/render/body/rows/RowPainterTable.d.ts +24 -0
  112. package/dist/types/core/render/body/rows/WindowLayout.d.ts +38 -0
  113. package/dist/types/core/render/dom.d.ts +10 -0
  114. package/dist/types/core/render/header/HeaderSortIndicator.d.ts +39 -0
  115. package/dist/types/core/render/header/HeaderView.d.ts +84 -0
  116. package/dist/types/core/render/header/ResizeHandleBinder.d.ts +110 -0
  117. package/dist/types/core/render/ports.d.ts +218 -0
  118. package/dist/types/core/renderers/CellRenderer.d.ts +7 -0
  119. package/dist/types/core/types.d.ts +94 -0
  120. package/dist/types/index.d.ts +1 -0
  121. package/dist/types/vue/OpenGrid.vue.d.ts +1 -1
  122. package/dist/xlsx.min-CMvrM6b4.cjs +138 -0
  123. package/dist/xlsx.min-i_b-4PvU.js +138 -0
  124. package/package.json +3 -8
  125. package/dist/OpenGrid-CLk8Vt7j.cjs +0 -7459
  126. package/dist/OpenGrid-D6YxCsnV.js +0 -7472
  127. package/dist/Registry-CPJYOqCn.js +0 -74
  128. package/dist/Registry-D74ZmdDz.cjs +0 -71
  129. package/dist/index-CeJ-0-80.cjs +0 -260
  130. package/dist/index-D0DJtKYI.cjs +0 -452
  131. package/dist/index-DnarQ4eR.js +0 -266
  132. package/dist/index-VkKgQ506.js +0 -481
  133. package/dist/xlsx.min-BQ1o3sB6.cjs +0 -11793
  134. package/dist/xlsx.min-Bbz2ZypC.js +0 -11794
@@ -1,74 +0,0 @@
1
- const a = ["og:", "og-"];
2
- function d(t) {
3
- return a.some((i) => t.startsWith(i));
4
- }
5
- function c(t) {
6
- const i = t.lastIndexOf("@"), r = i >= 0 ? t.slice(i + 1) : t;
7
- return r.split(".")[0] ?? r;
8
- }
9
- function u(t, i) {
10
- return c(t) === c(i);
11
- }
12
- function l(t, i, r, e, s) {
13
- const n = { key: t, value: i, origin: r, priority: e.priority ?? 0, seq: s };
14
- return e.pluginId !== void 0 && (n.pluginId = e.pluginId), e.spiVersion !== void 0 && (n.spiVersion = e.spiVersion), e.deprecated !== void 0 && (n.deprecated = e.deprecated), n;
15
- }
16
- class p {
17
- constructor(i = {}) {
18
- this._map = /* @__PURE__ */ new Map(), this._seq = 0, this._disposed = false, this._warned = /* @__PURE__ */ new Set(), this._cfg = i;
19
- }
20
- _warn(i, r) {
21
- const e = `[OpenGrid] ${r}`, s = `${i}::${r}`;
22
- return this._warned.has(s) || (this._warned.add(s), (this._cfg.onWarn ?? ((o) => {
23
- typeof console < "u" && console.warn(o);
24
- }))(e)), e;
25
- }
26
- register(i, r, e = {}) {
27
- if (this._disposed) return { ok: false, action: "rejected", reason: "disposed" };
28
- if (typeof i != "string" || i.length === 0) return { ok: false, action: "rejected", reason: "invalid-key" };
29
- const s = e.origin ?? "user";
30
- if (d(i) && s !== "builtin") return { ok: false, action: "rejected", reason: "reserved-namespace", warning: this._warn(i, `reserved namespace: '${i}' 는 og:* 코어 예약 대역입니다(origin:'builtin' 만 점유).`) };
31
- if (this._cfg.spi && e.spiVersion !== void 0 && !u(this._cfg.spi.version, e.spiVersion)) return { ok: false, action: "rejected", reason: "spi-mismatch", warning: this._warn(i, `SPI major 불일치: '${i}' 선언 ${e.spiVersion}, 코어 ${this._cfg.spi.name}@${this._cfg.spi.version}.`) };
32
- const n = this._map.get(i);
33
- return n && !this._resolveConflict(n, e) ? { ok: false, action: "kept", reason: "protected-builtin", warning: this._warn(i, `'${i}' 는 ${n.origin === "builtin" ? "내장(built-in) 보호" : "override 미지정"} — 덮으려면 { override:true }.`) } : (this._map.set(i, l(i, r, s, e, this._seq++)), { ok: true, action: n ? "replaced" : "added" });
34
- }
35
- _resolveConflict(i, r) {
36
- return i.origin === "builtin" && r.override !== true ? false : this._cfg.duplicatePolicy === "explicit-override" ? r.override === true : true;
37
- }
38
- get(i) {
39
- var _a;
40
- return (_a = this._map.get(i)) == null ? void 0 : _a.value;
41
- }
42
- require(i, r) {
43
- const e = this.get(i);
44
- if (e !== void 0) return e;
45
- if (r !== void 0) return r;
46
- if (this._cfg.placeholder) return this._cfg.placeholder(i);
47
- }
48
- has(i) {
49
- return this._map.has(i);
50
- }
51
- list() {
52
- return [...this._map.keys()];
53
- }
54
- entries() {
55
- return [...this._map.values()];
56
- }
57
- unregister(i) {
58
- return this._map.delete(i);
59
- }
60
- disposePlugin(i) {
61
- let r = 0;
62
- for (const [e, s] of this._map) s.pluginId === i && (this._map.delete(e), r++);
63
- return r;
64
- }
65
- dispose() {
66
- this._map.clear(), this._warned.clear(), this._disposed = true;
67
- }
68
- }
69
- export {
70
- a as R,
71
- p as T,
72
- d as i
73
- };
74
- //# sourceMappingURL=Registry-CPJYOqCn.js.map
@@ -1,71 +0,0 @@
1
- "use strict";
2
- const RESERVED_PREFIXES = ["og:", "og-"];
3
- function isReserved(t) {
4
- return RESERVED_PREFIXES.some((e) => t.startsWith(e));
5
- }
6
- function spiMajor(t) {
7
- const e = t.lastIndexOf("@"), r = e >= 0 ? t.slice(e + 1) : t;
8
- return r.split(".")[0] ?? r;
9
- }
10
- function spiCompatible(t, e) {
11
- return spiMajor(t) === spiMajor(e);
12
- }
13
- function buildEntry(t, e, r, i, s) {
14
- const n = { key: t, value: e, origin: r, priority: i.priority ?? 0, seq: s };
15
- return i.pluginId !== void 0 && (n.pluginId = i.pluginId), i.spiVersion !== void 0 && (n.spiVersion = i.spiVersion), i.deprecated !== void 0 && (n.deprecated = i.deprecated), n;
16
- }
17
- class TypedRegistry {
18
- constructor(e = {}) {
19
- this._map = /* @__PURE__ */ new Map(), this._seq = 0, this._disposed = false, this._warned = /* @__PURE__ */ new Set(), this._cfg = e;
20
- }
21
- _warn(e, r) {
22
- const i = `[OpenGrid] ${r}`, s = `${e}::${r}`;
23
- return this._warned.has(s) || (this._warned.add(s), (this._cfg.onWarn ?? ((o) => {
24
- typeof console < "u" && console.warn(o);
25
- }))(i)), i;
26
- }
27
- register(e, r, i = {}) {
28
- if (this._disposed) return { ok: false, action: "rejected", reason: "disposed" };
29
- if (typeof e != "string" || e.length === 0) return { ok: false, action: "rejected", reason: "invalid-key" };
30
- const s = i.origin ?? "user";
31
- if (isReserved(e) && s !== "builtin") return { ok: false, action: "rejected", reason: "reserved-namespace", warning: this._warn(e, `reserved namespace: '${e}' 는 og:* 코어 예약 대역입니다(origin:'builtin' 만 점유).`) };
32
- if (this._cfg.spi && i.spiVersion !== void 0 && !spiCompatible(this._cfg.spi.version, i.spiVersion)) return { ok: false, action: "rejected", reason: "spi-mismatch", warning: this._warn(e, `SPI major 불일치: '${e}' 선언 ${i.spiVersion}, 코어 ${this._cfg.spi.name}@${this._cfg.spi.version}.`) };
33
- const n = this._map.get(e);
34
- return n && !this._resolveConflict(n, i) ? { ok: false, action: "kept", reason: "protected-builtin", warning: this._warn(e, `'${e}' 는 ${n.origin === "builtin" ? "내장(built-in) 보호" : "override 미지정"} — 덮으려면 { override:true }.`) } : (this._map.set(e, buildEntry(e, r, s, i, this._seq++)), { ok: true, action: n ? "replaced" : "added" });
35
- }
36
- _resolveConflict(e, r) {
37
- return e.origin === "builtin" && r.override !== true ? false : this._cfg.duplicatePolicy === "explicit-override" ? r.override === true : true;
38
- }
39
- get(e) {
40
- var _a;
41
- return (_a = this._map.get(e)) == null ? void 0 : _a.value;
42
- }
43
- require(e, r) {
44
- const i = this.get(e);
45
- if (i !== void 0) return i;
46
- if (r !== void 0) return r;
47
- if (this._cfg.placeholder) return this._cfg.placeholder(e);
48
- }
49
- has(e) {
50
- return this._map.has(e);
51
- }
52
- list() {
53
- return [...this._map.keys()];
54
- }
55
- entries() {
56
- return [...this._map.values()];
57
- }
58
- unregister(e) {
59
- return this._map.delete(e);
60
- }
61
- disposePlugin(e) {
62
- let r = 0;
63
- for (const [i, s] of this._map) s.pluginId === e && (this._map.delete(i), r++);
64
- return r;
65
- }
66
- dispose() {
67
- this._map.clear(), this._warned.clear(), this._disposed = true;
68
- }
69
- }
70
- exports.RESERVED_PREFIXES = RESERVED_PREFIXES, exports.TypedRegistry = TypedRegistry, exports.isReserved = isReserved;
71
- //# sourceMappingURL=Registry-D74ZmdDz.cjs.map
@@ -1,260 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const defaultFrameScheduler = (h) => {
4
- const e = globalThis.requestAnimationFrame;
5
- if (typeof e == "function") {
6
- const i = e(() => h()), o = globalThis.cancelAnimationFrame;
7
- return { cancel: () => o == null ? void 0 : o(i) };
8
- }
9
- const s = setTimeout(h, 16);
10
- return { cancel: () => clearTimeout(s) };
11
- };
12
- class BackpressureScheduler {
13
- constructor(e) {
14
- this._cells = /* @__PURE__ */ new Map(), this._upserts = /* @__PURE__ */ new Map(), this._removes = /* @__PURE__ */ new Set(), this._coalesced = 0, this._dropped = 0, this._disposed = false, this._cfg = e;
15
- }
16
- enqueue(e) {
17
- if (!this._disposed) {
18
- if (e.kind === "snapshot") {
19
- this._dropped += this._cells.size + this._upserts.size + this._removes.size, this._cells.clear(), this._upserts.clear(), this._removes.clear(), this._snapshot = e, this._scheduleFrame();
20
- return;
21
- }
22
- this._mergeDelta(e), this._scheduleFrame();
23
- }
24
- }
25
- _mergeDelta(e) {
26
- if (e.removes) for (const s of e.removes) {
27
- this._removes.add(s), this._upserts.delete(s);
28
- for (const i of this._cells.keys()) i.slice(0, i.indexOf("\0")) === s && this._cells.delete(i);
29
- }
30
- if (e.upserts) for (const s of e.upserts) {
31
- if (this._removes.has(s.rowId)) continue;
32
- const i = this._upserts.get(s.rowId);
33
- i && this._coalesced++, this._upserts.set(s.rowId, { ...i ?? {}, ...s.row });
34
- }
35
- if (e.cells) for (const s of e.cells) {
36
- if (this._removes.has(s.rowId)) continue;
37
- const i = s.rowId + "\0" + s.field;
38
- this._cells.has(i) && this._coalesced++, this._cells.set(i, { rowId: s.rowId, field: s.field, value: s.value });
39
- }
40
- }
41
- _scheduleFrame() {
42
- this._frame || (this._frame = this._cfg.scheduleFrame(() => {
43
- this._frame = void 0, this._flushFrame();
44
- }));
45
- }
46
- _flushFrame() {
47
- if (this._disposed) return;
48
- if (this._snapshot) {
49
- const r = this._snapshot;
50
- this._snapshot = void 0, this._cfg.flush({ cells: [], upserts: [], removes: [], snapshot: r, overflowToNextFrame: false });
51
- return;
52
- }
53
- const e = this._cfg.maxBatchPerFrame ?? 0, s = [];
54
- let i = false;
55
- for (const [r, n] of this._cells) {
56
- if (e > 0 && s.length >= e) {
57
- i = true;
58
- break;
59
- }
60
- s.push(n), this._cells.delete(r);
61
- }
62
- const o = [...this._upserts.entries()].map(([r, n]) => ({ rowId: r, row: n })), t = [...this._removes];
63
- this._upserts.clear(), this._removes.clear(), !(s.length === 0 && o.length === 0 && t.length === 0) && (this._cfg.flush({ cells: s.map((r) => ({ rowId: r.rowId, field: r.field, value: r.value })), upserts: o, removes: t, overflowToNextFrame: i }), (i || this._cells.size > 0) && this._scheduleFrame());
64
- }
65
- get stats() {
66
- return { pending: this._cells.size + this._upserts.size + this._removes.size, coalesced: this._coalesced, dropped: this._dropped };
67
- }
68
- dispose() {
69
- var _a;
70
- this._disposed = true, (_a = this._frame) == null ? void 0 : _a.cancel(), this._frame = void 0, this._cells.clear(), this._upserts.clear(), this._removes.clear(), this._snapshot = void 0;
71
- }
72
- }
73
- class RtApplyCommand {
74
- constructor(e) {
75
- this.spi = "command", this.kind = "rt.apply", this.label = "rt.backgroundUpdate", this._at = 0, this._cellInverse = [], this._insertedRowIds = [], this._removedInverse = [], this._batch = e, this.footprint = RtApplyCommand._footprintOf(e);
76
- }
77
- get appliedDelta() {
78
- return this._applied;
79
- }
80
- do(e) {
81
- this._at = e.clock.now(), this._cellInverse = [], this._insertedRowIds = [], this._removedInverse = [];
82
- const s = [];
83
- e.mutation.beginBatch();
84
- try {
85
- const i = [];
86
- for (const t of this._batch.cells) {
87
- const r = e.coords.indexOf(t.rowId);
88
- r < 0 || (this._cellInverse.push({ rowId: t.rowId, field: t.field, oldValue: e.coords.getCellValue(t.rowId, t.field) }), i.push({ rowIndex: r, field: t.field, value: t.value }), s.push({ rowId: t.rowId, field: t.field }));
89
- }
90
- i.length > 0 && e.mutation.writeCells(i);
91
- for (const t of this._batch.upserts) {
92
- const r = e.coords.indexOf(t.rowId);
93
- if (r >= 0) {
94
- const n = [];
95
- for (const [l, a] of Object.entries(t.row)) this._cellInverse.push({ rowId: t.rowId, field: l, oldValue: e.coords.getCellValue(t.rowId, l) }), n.push({ rowIndex: r, field: l, value: a }), s.push({ rowId: t.rowId, field: l });
96
- n.length > 0 && e.mutation.writeCells(n);
97
- } else e.mutation.insertRow(t.row, "last"), this._insertedRowIds.push(t.rowId);
98
- }
99
- const o = [];
100
- for (const t of this._batch.removes) {
101
- const r = e.coords.indexOf(t);
102
- r < 0 || (this._removedInverse.push({ rowId: t, snapshot: e.coords.getRowSnapshot(t) }), o.push({ rowId: t, index: r }));
103
- }
104
- o.length > 0 && e.mutation.deleteRows(o.sort((t, r) => r.index - t.index).map((t) => t.index)), this._applied = { changedCells: s, insertedRowIds: [...this._insertedRowIds], removedRowIds: this._removedInverse.map((t) => t.rowId), userInitiated: false };
105
- } finally {
106
- e.mutation.endBatch();
107
- }
108
- }
109
- undo(e) {
110
- e.mutation.beginBatch();
111
- try {
112
- const s = this._insertedRowIds.map((o) => e.coords.indexOf(o)).filter((o) => o >= 0).sort((o, t) => t - o);
113
- s.length > 0 && e.mutation.deleteRows(s);
114
- for (const o of this._removedInverse) o.snapshot && e.mutation.insertRow(o.snapshot, "last");
115
- const i = [];
116
- for (const o of this._cellInverse) {
117
- const t = e.coords.indexOf(o.rowId);
118
- t >= 0 && i.push({ rowIndex: t, field: o.field, value: o.oldValue });
119
- }
120
- i.length > 0 && e.mutation.writeCells(i);
121
- } finally {
122
- e.mutation.endBatch();
123
- }
124
- }
125
- serialize() {
126
- return { kind: this.kind, payload: { cells: this._batch.cells, upserts: this._batch.upserts, removes: this._batch.removes }, at: this._at };
127
- }
128
- static _footprintOf(e) {
129
- if (e.snapshot || e.upserts.length > 0 || e.removes.length > 0) return { scope: "structure" };
130
- const s = [...new Set(e.cells.map((o) => o.rowId))], i = [...new Set(e.cells.map((o) => o.field))];
131
- return s.length === 1 && i.length === 1 ? { scope: "cell", rowId: s[0], field: i[0] } : { scope: "range", rowIds: s, fields: i };
132
- }
133
- }
134
- class RealtimeController {
135
- constructor(e, s) {
136
- this._statusListeners = /* @__PURE__ */ new Set(), this._attached = false, this._source = e, this._deps = s, this._now = s.now ?? (() => Date.now()), this._connection = e.status, this._scheduler = new BackpressureScheduler({ ...s.maxBatchPerFrame !== void 0 ? { maxBatchPerFrame: s.maxBatchPerFrame } : {}, scheduleFrame: s.scheduleFrame ?? defaultFrameScheduler, flush: (i) => this._applyBatch(i) });
137
- }
138
- attach() {
139
- this._attached || (this._attached = true, this._offData = this._source.onData((e) => this._onData(e)), this._offStatus = this._source.onStatus((e) => this._onStatus(e)), this._source.start());
140
- }
141
- detach() {
142
- var _a, _b;
143
- this._attached && (this._attached = false, (_a = this._offData) == null ? void 0 : _a.call(this), (_b = this._offStatus) == null ? void 0 : _b.call(this), this._offData = void 0, this._offStatus = void 0, this._source.stop(), this._scheduler.dispose());
144
- }
145
- get connection() {
146
- return this._connection;
147
- }
148
- get backpressureStats() {
149
- return this._scheduler.stats;
150
- }
151
- onConnection(e) {
152
- return this._statusListeners.add(e), () => this._statusListeners.delete(e);
153
- }
154
- _onData(e) {
155
- this._deps.freshness.markReceived(e.serverTime ?? this._now()), this._scheduler.enqueue(e);
156
- }
157
- _onStatus(e) {
158
- this._connection = e, this._deps.announce.onConnection(e.status), this._deps.freshness.tick();
159
- for (const s of this._statusListeners) s(e);
160
- }
161
- _applyBatch(e) {
162
- const s = this._deps.stateGuard.capture();
163
- if (e.snapshot) {
164
- if (this._deps.applySnapshot) {
165
- this._deps.applySnapshot(e.snapshot.rows);
166
- const t = { changedCells: [], insertedRowIds: [], removedRowIds: [], userInitiated: false };
167
- this._deps.stateGuard.restore(s, t), this._deps.announce.onBackgroundChange(t);
168
- } else console.warn("[open-grid/realtime] snapshot received but no applySnapshot dep wired — skipped");
169
- return;
170
- }
171
- const i = new RtApplyCommand(e);
172
- this._deps.sink.beginBatch();
173
- try {
174
- this._deps.sink.dispatchSilent(i);
175
- } finally {
176
- this._deps.sink.endBatch();
177
- }
178
- const o = i.appliedDelta;
179
- if (o && (this._deps.stateGuard.restore(s, o), this._deps.announce.onBackgroundChange(o), this._deps.chart)) {
180
- const t = [.../* @__PURE__ */ new Set([...o.changedCells.map((r) => r.rowId), ...o.insertedRowIds, ...o.removedRowIds])];
181
- t.length > 0 && this._deps.chart.markDirty(t);
182
- }
183
- }
184
- }
185
- class LiveStateGuard {
186
- constructor(e, s) {
187
- this._lastConflicts = [], this._src = e, this._coords = s;
188
- }
189
- get lastConflicts() {
190
- return this._lastConflicts;
191
- }
192
- capture() {
193
- const e = this._src.readEditing();
194
- return { selection: this._src.readSelection(), scroll: this._src.readScroll(), ...e ? { editing: e } : {}, sortFilterSig: this._src.readSortFilterSig() };
195
- }
196
- restore(e, s) {
197
- this._lastConflicts = [];
198
- const i = new Set(s.removedRowIds), o = e.selection.filter((t) => !i.has(t.rowId) && this._coords.rowIdToIndex(t.rowId) >= 0);
199
- this._src.writeSelection(o), e.scroll.anchorRowId && (i.has(e.scroll.anchorRowId) || this._coords.rowIdToIndex(e.scroll.anchorRowId) < 0) ? this._src.writeScroll({ pixelWithinRow: 0, scrollLeft: e.scroll.scrollLeft }) : this._src.writeScroll(e.scroll), e.editing && (!i.has(e.editing.rowId) && this._coords.rowIdToIndex(e.editing.rowId) >= 0 ? (s.changedCells.some((n) => n.rowId === e.editing.rowId && n.field === e.editing.field) && this._lastConflicts.push({ rowId: e.editing.rowId, field: e.editing.field }), this._src.writeEditing(e.editing)) : this._src.writeEditing(void 0));
200
- }
201
- }
202
- class FreshnessClock {
203
- constructor(e) {
204
- this._lastState = "stale", this._listeners = /* @__PURE__ */ new Set(), this._staleAfterMs = e.staleAfterMs, this._now = e.now ?? (() => Date.now());
205
- }
206
- markReceived(e) {
207
- this._lastReceivedAt = e, this._emitIfChanged();
208
- }
209
- compute() {
210
- const e = this._now();
211
- if (this._lastReceivedAt === void 0) return { state: "stale", ageMs: 1 / 0 };
212
- const s = e - this._lastReceivedAt;
213
- return { state: s > this._staleAfterMs ? "stale" : "fresh", ageMs: s, lastReceivedAt: this._lastReceivedAt };
214
- }
215
- tick() {
216
- return this._emitIfChanged();
217
- }
218
- _emitIfChanged() {
219
- const e = this.compute();
220
- if (e.state !== this._lastState) {
221
- this._lastState = e.state;
222
- for (const s of this._listeners) s(e);
223
- }
224
- return e;
225
- }
226
- onChange(e) {
227
- return this._listeners.add(e), () => this._listeners.delete(e);
228
- }
229
- }
230
- class RtAnnouncePolicy {
231
- constructor(e) {
232
- this._pendingCells = /* @__PURE__ */ new Set(), this._pendingRows = /* @__PURE__ */ new Set(), this._announce = e.announce, this._debounceMs = e.debounceMs ?? 500, this._schedule = e.schedule ?? ((s, i) => {
233
- const o = setTimeout(s, i);
234
- return { cancel: () => clearTimeout(o) };
235
- });
236
- }
237
- onBackgroundChange(e) {
238
- for (const s of e.changedCells) this._pendingCells.add(s.rowId + " " + s.field), this._pendingRows.add(s.rowId);
239
- for (const s of e.insertedRowIds) this._pendingRows.add(s);
240
- for (const s of e.removedRowIds) this._pendingRows.add(s);
241
- this._arm();
242
- }
243
- _arm() {
244
- this._timer || (this._timer = this._schedule(() => {
245
- this._timer = void 0, this._flush();
246
- }, this._debounceMs));
247
- }
248
- _flush() {
249
- this._pendingCells.size === 0 && this._pendingRows.size === 0 || (this._announce({ kind: "background-update", changedCount: this._pendingCells.size, rowCount: this._pendingRows.size, label: "background", interruptsFocus: false }), this._pendingCells.clear(), this._pendingRows.clear());
250
- }
251
- onConnection(e) {
252
- this._announce({ kind: "connection", changedCount: 0, rowCount: 0, label: "connection", interruptsFocus: false, connectionStatus: e });
253
- }
254
- dispose() {
255
- var _a;
256
- (_a = this._timer) == null ? void 0 : _a.cancel(), this._timer = void 0, this._pendingCells.clear(), this._pendingRows.clear();
257
- }
258
- }
259
- exports.BackpressureScheduler = BackpressureScheduler, exports.FreshnessClock = FreshnessClock, exports.LiveStateGuard = LiveStateGuard, exports.RealtimeController = RealtimeController, exports.RtAnnouncePolicy = RtAnnouncePolicy, exports.RtApplyCommand = RtApplyCommand, exports.defaultFrameScheduler = defaultFrameScheduler;
260
- //# sourceMappingURL=index-CeJ-0-80.cjs.map