open-grid 1.2.0 → 1.3.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/CHANGELOG.md +376 -353
- package/README.md +1 -1
- package/dist/OpenGrid-B7m7ei7f.cjs +7385 -0
- package/dist/OpenGrid-CeUdO_fM.js +7398 -0
- package/dist/index-CeJ-0-80.cjs +260 -0
- package/dist/index-DnarQ4eR.js +266 -0
- package/dist/index-DrCPRuYi.js +548 -0
- package/dist/index-JjfWY3Bt.cjs +520 -0
- package/dist/open-grid-base.css +12 -1
- package/dist/open-grid-react.cjs +27 -1
- package/dist/open-grid-react.js +22 -82
- package/dist/open-grid-vue.cjs +31 -1
- package/dist/open-grid-vue.js +29 -79
- package/dist/open-grid.cjs +272 -6
- package/dist/open-grid.js +177 -266
- package/dist/types/bench/perf.d.ts +14 -8
- package/dist/types/core/AppearanceResolver.d.ts +98 -11
- package/dist/types/core/CFRenderBridge.d.ts +13 -0
- package/dist/types/core/CellEditManager.d.ts +73 -0
- package/dist/types/core/CellEventHandler.d.ts +99 -2
- package/dist/types/core/CellTypeRegistry.d.ts +24 -0
- package/dist/types/core/ChartManager.d.ts +51 -3
- package/dist/types/core/ColumnLayout.d.ts +100 -2
- package/dist/types/core/ContextMenu.d.ts +43 -2
- package/dist/types/core/CrossGridController.d.ts +86 -15
- package/dist/types/core/CrossGridMapper.d.ts +43 -5
- package/dist/types/core/CrossGridRegistry.d.ts +36 -2
- package/dist/types/core/DataLayer.d.ts +210 -15
- package/dist/types/core/DetailManager.d.ts +106 -15
- package/dist/types/core/DragVisuals.d.ts +33 -4
- package/dist/types/core/EventEmitter.d.ts +54 -0
- package/dist/types/core/ExportManager.d.ts +66 -1
- package/dist/types/core/ExtensionPointRegistry.d.ts +160 -14
- package/dist/types/core/FilterPanel.d.ts +17 -2
- package/dist/types/core/FilterSelect.d.ts +37 -13
- package/dist/types/core/FindBarManager.d.ts +26 -0
- package/dist/types/core/FlatRowModel.d.ts +54 -11
- package/dist/types/core/FooterManager.d.ts +53 -1
- package/dist/types/core/FormulaController.d.ts +139 -10
- package/dist/types/core/FormulaEngine.d.ts +15 -4
- package/dist/types/core/GridComposer.d.ts +54 -6
- package/dist/types/core/GridRenderer.d.ts +143 -10
- package/dist/types/core/GridShuttle.d.ts +44 -4
- package/dist/types/core/GroupEngine.d.ts +68 -10
- package/dist/types/core/GroupTreeManager.d.ts +86 -2
- package/dist/types/core/IconRegistry.d.ts +56 -9
- package/dist/types/core/KeyboardManager.d.ts +88 -4
- package/dist/types/core/MaskingEngine.d.ts +10 -9
- package/dist/types/core/MathUtils.d.ts +58 -5
- package/dist/types/core/MergeEngine.d.ts +45 -10
- package/dist/types/core/MutationService.d.ts +113 -10
- package/dist/types/core/OGDecimal.d.ts +144 -13
- package/dist/types/core/OpenGrid.d.ts +99 -0
- package/dist/types/core/OrgChart.d.ts +56 -1
- package/dist/types/core/OverrideKernel.d.ts +59 -15
- package/dist/types/core/Pagination.d.ts +38 -4
- package/dist/types/core/PivotEngine.d.ts +37 -0
- package/dist/types/core/RangeSelectionManager.d.ts +121 -7
- package/dist/types/core/RenderController.d.ts +56 -0
- package/dist/types/core/RowDragDrop.d.ts +52 -6
- package/dist/types/core/RowManager.d.ts +55 -0
- package/dist/types/core/SkinRegistry.d.ts +55 -15
- package/dist/types/core/SortFilterManager.d.ts +80 -1
- package/dist/types/core/TreeEngine.d.ts +60 -6
- package/dist/types/core/TriggerManager.d.ts +46 -0
- package/dist/types/core/VirtualScroll.d.ts +64 -0
- package/dist/types/core/WorksheetManager.d.ts +61 -2
- package/dist/types/core/XmlConverter.d.ts +56 -23
- package/dist/types/core/a11y/AccessibilityAdapter.d.ts +103 -0
- package/dist/types/core/a11y/AriaIntent.d.ts +34 -0
- package/dist/types/core/a11y/KeyboardInteractionModel.d.ts +64 -0
- package/dist/types/core/a11y/LiveRegionController.d.ts +89 -0
- package/dist/types/core/a11y/OverlayStack.d.ts +36 -0
- package/dist/types/core/a11y/VisualEquivRegistry.d.ts +37 -0
- package/dist/types/core/a11y/index.d.ts +13 -0
- package/dist/types/core/a11y/ports.d.ts +24 -0
- package/dist/types/core/appearance/Appearance.d.ts +68 -0
- package/dist/types/core/appearance/AppearanceAxis.d.ts +94 -0
- package/dist/types/core/appearance/AppearanceComposer.d.ts +45 -0
- package/dist/types/core/appearance/AppearanceProvider.d.ts +50 -0
- package/dist/types/core/appearance/AppearanceView.d.ts +51 -0
- package/dist/types/core/appearance/DensityRegistry.d.ts +36 -0
- package/dist/types/core/appearance/ResolvedAppearanceSnapshot.d.ts +84 -0
- package/dist/types/core/appearance/TextureRegistry.d.ts +32 -0
- package/dist/types/core/appearance/ThemeMetaRegistry.d.ts +67 -0
- package/dist/types/core/appearance/axisAdapters.d.ts +37 -0
- package/dist/types/core/appearance/defaults.d.ts +10 -0
- package/dist/types/core/appearance/index.d.ts +20 -0
- package/dist/types/core/appearance/tokenCatalog.d.ts +30 -0
- package/dist/types/core/cf/CFEngine.d.ts +56 -0
- package/dist/types/core/cf/CFEvaluator.d.ts +24 -0
- package/dist/types/core/cf/CFRule.d.ts +127 -0
- package/dist/types/core/cf/ColorScale.d.ts +49 -0
- package/dist/types/core/cf/InkResolver.d.ts +33 -0
- package/dist/types/core/cf/appearance.d.ts +20 -0
- package/dist/types/core/cf/encoders.d.ts +61 -0
- package/dist/types/core/cf/eval-types.d.ts +93 -0
- package/dist/types/core/cf/index.d.ts +21 -0
- package/dist/types/core/cf/lineage.d.ts +32 -0
- package/dist/types/core/cf/predicates.d.ts +27 -0
- package/dist/types/core/cf/serialize.d.ts +46 -0
- package/dist/types/core/chart/CanvasAdapter.d.ts +50 -1
- package/dist/types/core/chart/DataExtractor.d.ts +53 -12
- package/dist/types/core/chart/a11y.d.ts +22 -0
- package/dist/types/core/chart/chart-type-registry.d.ts +53 -0
- package/dist/types/core/chart/downsample-report.d.ts +36 -0
- package/dist/types/core/chart/downsample.d.ts +26 -1
- package/dist/types/core/chart/engine/ChartEngineRegistry.d.ts +52 -0
- package/dist/types/core/chart/geometry.d.ts +96 -0
- package/dist/types/core/chart/hittest.d.ts +21 -3
- package/dist/types/core/chart/palette.d.ts +96 -12
- package/dist/types/core/chart/parity.d.ts +12 -0
- package/dist/types/core/chart/provenance.d.ts +47 -0
- package/dist/types/core/chart/scales.d.ts +28 -1
- package/dist/types/core/chart/scene.d.ts +102 -0
- package/dist/types/core/chart/server.d.ts +36 -0
- package/dist/types/core/chart/surfaces/CanvasSurface.d.ts +48 -0
- package/dist/types/core/chart/surfaces/ServerRasterSurface.d.ts +26 -0
- package/dist/types/core/chart/surfaces/SvgSurface.d.ts +24 -0
- package/dist/types/core/chart/surfaces/pattern-overlay.d.ts +24 -0
- package/dist/types/core/chart/types.d.ts +107 -10
- package/dist/types/core/command/CommandBus.d.ts +51 -0
- package/dist/types/core/command/CommandRegistry.d.ts +43 -0
- package/dist/types/core/command/CommandStack.d.ts +38 -0
- package/dist/types/core/command/ICommand.d.ts +110 -0
- package/dist/types/core/command/commands/CellWriteCommand.d.ts +32 -0
- package/dist/types/core/command/commands/CompositeCommand.d.ts +17 -0
- package/dist/types/core/command/commands/RowCommands.d.ts +39 -0
- package/dist/types/core/command/index.d.ts +9 -0
- package/dist/types/core/command/support.d.ts +51 -0
- package/dist/types/core/coordinate/ColumnMetrics.d.ts +30 -0
- package/dist/types/core/coordinate/CoordinateKernel.d.ts +88 -0
- package/dist/types/core/coordinate/FrozenPanes.d.ts +29 -0
- package/dist/types/core/coordinate/MergeSourceAdapter.d.ts +18 -0
- package/dist/types/core/coordinate/NodeBudget.d.ts +33 -0
- package/dist/types/core/coordinate/ResizeGovernor.d.ts +50 -0
- package/dist/types/core/coordinate/RowMetrics.d.ts +37 -0
- package/dist/types/core/coordinate/ViewPermutation.d.ts +23 -0
- package/dist/types/core/coordinate/index.d.ts +10 -0
- package/dist/types/core/coordinate/ports.d.ts +45 -0
- package/dist/types/core/coordinate/types.d.ts +76 -0
- package/dist/types/core/detail/DetailGlyph.d.ts +42 -7
- package/dist/types/core/detail/DetailSplice.d.ts +42 -11
- package/dist/types/core/detail/DetailState.d.ts +80 -11
- package/dist/types/core/detail/SubgridCache.d.ts +72 -10
- package/dist/types/core/detail/index.d.ts +8 -0
- package/dist/types/core/domain/AggregateResult.d.ts +54 -0
- package/dist/types/core/domain/CellAddress.d.ts +61 -0
- package/dist/types/core/domain/CellValueAccess.d.ts +29 -0
- package/dist/types/core/domain/Delta.d.ts +37 -0
- package/dist/types/core/domain/DomainValue.d.ts +80 -0
- package/dist/types/core/domain/Missing.d.ts +65 -0
- package/dist/types/core/domain/Money.d.ts +42 -0
- package/dist/types/core/domain/NormalizationBasis.d.ts +47 -0
- package/dist/types/core/domain/Plain.d.ts +45 -0
- package/dist/types/core/domain/Quantity.d.ts +32 -0
- package/dist/types/core/domain/Ratios.d.ts +100 -0
- package/dist/types/core/domain/ThresholdSet.d.ts +46 -0
- package/dist/types/core/domain/ValueType.d.ts +71 -0
- package/dist/types/core/domain/rounding.d.ts +25 -0
- package/dist/types/core/domain/strategies.d.ts +38 -0
- package/dist/types/core/editors/CellEditor.d.ts +29 -2
- package/dist/types/core/editors/DateEditor.d.ts +18 -0
- package/dist/types/core/editors/SelectEditor.d.ts +29 -0
- package/dist/types/core/export/ChannelRegistry.d.ts +18 -0
- package/dist/types/core/export/ExportManifest.d.ts +13 -0
- package/dist/types/core/export/GridArtifactSource.d.ts +62 -0
- package/dist/types/core/export/Provenance.d.ts +34 -0
- package/dist/types/core/export/StreamPump.d.ts +28 -0
- package/dist/types/core/export/channels/CsvChannel.d.ts +20 -0
- package/dist/types/core/export/channels/JsonChannel.d.ts +18 -0
- package/dist/types/core/export/channels/XlsxChannel.d.ts +53 -0
- package/dist/types/core/export/channels/XmlChannel.d.ts +21 -0
- package/dist/types/core/export/channels/capabilities.d.ts +13 -0
- package/dist/types/core/export/index.d.ts +24 -0
- package/dist/types/core/export/print/OutputChannelAdapter.d.ts +61 -0
- package/dist/types/core/export/print/Paginator.d.ts +48 -0
- package/dist/types/core/export/print/PrintRenderTarget.d.ts +36 -0
- package/dist/types/core/export/sinks.d.ts +40 -0
- package/dist/types/core/export/types.d.ts +211 -0
- package/dist/types/core/extension/DeprecationManager.d.ts +42 -0
- package/dist/types/core/extension/IExtension.d.ts +90 -0
- package/dist/types/core/extension/Registry.d.ts +142 -0
- package/dist/types/core/extension/SlotRegistry.d.ts +46 -0
- package/dist/types/core/extension/adapters.d.ts +44 -0
- package/dist/types/core/extension/conformance.d.ts +47 -0
- package/dist/types/core/extension/index.d.ts +16 -0
- package/dist/types/core/extension/registries.d.ts +31 -0
- package/dist/types/core/extension/reserved.d.ts +10 -0
- package/dist/types/core/format/DisplayFormatter.d.ts +47 -0
- package/dist/types/core/format/FormatCache.d.ts +20 -0
- package/dist/types/core/format/FormatterRegistry.d.ts +22 -0
- package/dist/types/core/format/grammar/AstRenderer.d.ts +10 -0
- package/dist/types/core/format/grammar/FormatCompiler.d.ts +16 -0
- package/dist/types/core/format/index.d.ts +55 -0
- package/dist/types/core/format/pipeline/DomainTypeResolver.d.ts +8 -0
- package/dist/types/core/format/pipeline/LocaleFormat.d.ts +11 -0
- package/dist/types/core/format/pipeline/ValueInterpreter.d.ts +8 -0
- package/dist/types/core/format/policy/MaskPolicy.d.ts +8 -0
- package/dist/types/core/format/policy/NegativePolicy.d.ts +12 -0
- package/dist/types/core/format/policy/NullPolicy.d.ts +10 -0
- package/dist/types/core/format/policy/TruncatePolicy.d.ts +11 -0
- package/dist/types/core/format/types.d.ts +292 -0
- package/dist/types/core/formula/CalcCacheStore.d.ts +89 -0
- package/dist/types/core/formula/CalcProvenance.d.ts +44 -0
- package/dist/types/core/formula/CalcService.d.ts +137 -0
- package/dist/types/core/formula/CyclePathReporter.d.ts +28 -0
- package/dist/types/core/formula/FormulaEvaluator.d.ts +35 -1
- package/dist/types/core/formula/FormulaGraph.d.ts +84 -7
- package/dist/types/core/formula/FormulaParser.d.ts +9 -0
- package/dist/types/core/formula/FormulaStore.d.ts +63 -1
- package/dist/types/core/formula/FunctionRegistry.d.ts +138 -0
- package/dist/types/core/formula/Generation.d.ts +86 -0
- package/dist/types/core/formula/RecalcCoordinator.d.ts +151 -9
- package/dist/types/core/formula/ReferenceRewriter.d.ts +81 -0
- package/dist/types/core/formula/functions/essential.d.ts +3 -0
- package/dist/types/core/formula/functions/extended/index.d.ts +10 -0
- package/dist/types/core/formula/normalizeRefs.d.ts +34 -3
- package/dist/types/core/formula/numericLiteral.d.ts +11 -1
- package/dist/types/core/formula/serializeFormula.d.ts +10 -1
- package/dist/types/core/formula/types.d.ts +71 -8
- package/dist/types/core/host/CapabilityRegistry.d.ts +61 -0
- package/dist/types/core/host/GridHostDriver.d.ts +27 -0
- package/dist/types/core/host/GridHostPort.d.ts +37 -0
- package/dist/types/core/host/SliceOwnershipGuard.d.ts +27 -0
- package/dist/types/core/host/archCheck.d.ts +26 -0
- package/dist/types/core/host/index.d.ts +6 -0
- package/dist/types/core/host/reconcile.d.ts +22 -0
- package/dist/types/core/i18n/LocaleContext.d.ts +40 -0
- package/dist/types/core/i18n/types.d.ts +26 -1
- package/dist/types/core/icons/bootstrap-icons.d.ts +4 -2
- package/dist/types/core/quality/ContrastAuditor.d.ts +64 -0
- package/dist/types/core/quality/DeterminismKernel.d.ts +68 -0
- package/dist/types/core/quality/PerfBaseline.d.ts +23 -0
- package/dist/types/core/quality/PerfSpec.d.ts +95 -0
- package/dist/types/core/quality/RealBrowserGate.d.ts +69 -0
- package/dist/types/core/quality/RegressionJudge.d.ts +35 -0
- package/dist/types/core/quality/ReleaseGate.d.ts +94 -0
- package/dist/types/core/quality/VisualRegression.d.ts +74 -0
- package/dist/types/core/quality/hooks.d.ts +53 -0
- package/dist/types/core/quality/index.d.ts +20 -0
- package/dist/types/core/quality/pixelMetrics.d.ts +24 -0
- package/dist/types/core/range/ClipboardCodec.d.ts +46 -4
- package/dist/types/core/range/FillEngine.d.ts +69 -9
- package/dist/types/core/range/RangeModel.d.ts +100 -13
- package/dist/types/core/range/RangeQuery.d.ts +24 -2
- package/dist/types/core/range/types.d.ts +27 -11
- package/dist/types/core/realtime/BackpressureScheduler.d.ts +0 -0
- package/dist/types/core/realtime/FreshnessClock.d.ts +34 -0
- package/dist/types/core/realtime/IRealtimeSource.d.ts +82 -0
- package/dist/types/core/realtime/LiveStateGuard.d.ts +23 -0
- package/dist/types/core/realtime/PollingSource.d.ts +42 -0
- package/dist/types/core/realtime/RealtimeController.d.ts +54 -0
- package/dist/types/core/realtime/RtAnnouncePolicy.d.ts +53 -0
- package/dist/types/core/realtime/RtApplyCommand.d.ts +29 -0
- package/dist/types/core/realtime/RtChartTargetTrigger.d.ts +26 -0
- package/dist/types/core/realtime/StreamingSource.d.ts +47 -0
- package/dist/types/core/realtime/backoff.d.ts +12 -0
- package/dist/types/core/realtime/index.d.ts +13 -0
- package/dist/types/core/realtime/ports.d.ts +80 -0
- package/dist/types/core/render/CellApplier.d.ts +18 -0
- package/dist/types/core/render/CellErrorBoundary.d.ts +65 -0
- package/dist/types/core/render/CellPipeline.d.ts +39 -0
- package/dist/types/core/render/CellRenderRequest.d.ts +209 -0
- package/dist/types/core/render/CellStageRegistry.d.ts +53 -0
- package/dist/types/core/render/OverlayCompositor.d.ts +38 -0
- package/dist/types/core/render/RenderBudget.d.ts +67 -0
- package/dist/types/core/render/contrast.d.ts +33 -0
- package/dist/types/core/render/index.d.ts +35 -0
- package/dist/types/core/render/stages/BackgroundStage.d.ts +14 -0
- package/dist/types/core/render/stages/DecoratorStage.d.ts +12 -0
- package/dist/types/core/render/stages/OverlayStage.d.ts +12 -0
- package/dist/types/core/render/stages/ValueRendererStage.d.ts +15 -0
- package/dist/types/core/render/stages/index.d.ts +14 -0
- package/dist/types/core/renderers/CellRenderer.d.ts +100 -8
- package/dist/types/core/state/AutosaveController.d.ts +63 -0
- package/dist/types/core/state/IStatePersistence.d.ts +59 -0
- package/dist/types/core/state/MultiTabGuard.d.ts +33 -0
- package/dist/types/core/state/SchemaMigrator.d.ts +33 -0
- package/dist/types/core/state/SemVerPolicy.d.ts +39 -0
- package/dist/types/core/state/StateCodec.d.ts +75 -0
- package/dist/types/core/state/index.d.ts +6 -0
- package/dist/types/core/types.d.ts +17 -0
- package/dist/types/react/OpenGrid.d.ts +54 -0
- package/dist/types/react/index.d.ts +5 -0
- package/dist/types/realtime/index.d.ts +1 -0
- package/dist/types/vue/index.d.ts +5 -0
- package/dist/types/vue/types.d.ts +35 -0
- package/dist/xlsx.min-BQ1o3sB6.cjs +11793 -0
- package/dist/{xlsx.min-Wavxcamn.js → xlsx.min-Bbz2ZypC.js} +453 -566
- package/package.json +112 -110
- package/dist/OpenGrid-B0Spm0rU.js +0 -10404
- package/dist/OpenGrid-CuXj0isp.cjs +0 -97
- package/dist/xlsx.min-Bx-LxWOf.cjs +0 -138
|
@@ -0,0 +1,260 @@
|
|
|
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
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
const a = (h) => {
|
|
2
|
+
const e = globalThis.requestAnimationFrame;
|
|
3
|
+
if (typeof e == "function") {
|
|
4
|
+
const i = e(() => h()), o = globalThis.cancelAnimationFrame;
|
|
5
|
+
return { cancel: () => o == null ? void 0 : o(i) };
|
|
6
|
+
}
|
|
7
|
+
const s = setTimeout(h, 16);
|
|
8
|
+
return { cancel: () => clearTimeout(s) };
|
|
9
|
+
};
|
|
10
|
+
class c {
|
|
11
|
+
constructor(e) {
|
|
12
|
+
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;
|
|
13
|
+
}
|
|
14
|
+
enqueue(e) {
|
|
15
|
+
if (!this._disposed) {
|
|
16
|
+
if (e.kind === "snapshot") {
|
|
17
|
+
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();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this._mergeDelta(e), this._scheduleFrame();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
_mergeDelta(e) {
|
|
24
|
+
if (e.removes) for (const s of e.removes) {
|
|
25
|
+
this._removes.add(s), this._upserts.delete(s);
|
|
26
|
+
for (const i of this._cells.keys()) i.slice(0, i.indexOf("\0")) === s && this._cells.delete(i);
|
|
27
|
+
}
|
|
28
|
+
if (e.upserts) for (const s of e.upserts) {
|
|
29
|
+
if (this._removes.has(s.rowId)) continue;
|
|
30
|
+
const i = this._upserts.get(s.rowId);
|
|
31
|
+
i && this._coalesced++, this._upserts.set(s.rowId, { ...i ?? {}, ...s.row });
|
|
32
|
+
}
|
|
33
|
+
if (e.cells) for (const s of e.cells) {
|
|
34
|
+
if (this._removes.has(s.rowId)) continue;
|
|
35
|
+
const i = s.rowId + "\0" + s.field;
|
|
36
|
+
this._cells.has(i) && this._coalesced++, this._cells.set(i, { rowId: s.rowId, field: s.field, value: s.value });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_scheduleFrame() {
|
|
40
|
+
this._frame || (this._frame = this._cfg.scheduleFrame(() => {
|
|
41
|
+
this._frame = void 0, this._flushFrame();
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
_flushFrame() {
|
|
45
|
+
if (this._disposed) return;
|
|
46
|
+
if (this._snapshot) {
|
|
47
|
+
const r = this._snapshot;
|
|
48
|
+
this._snapshot = void 0, this._cfg.flush({ cells: [], upserts: [], removes: [], snapshot: r, overflowToNextFrame: false });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const e = this._cfg.maxBatchPerFrame ?? 0, s = [];
|
|
52
|
+
let i = false;
|
|
53
|
+
for (const [r, n] of this._cells) {
|
|
54
|
+
if (e > 0 && s.length >= e) {
|
|
55
|
+
i = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
s.push(n), this._cells.delete(r);
|
|
59
|
+
}
|
|
60
|
+
const o = [...this._upserts.entries()].map(([r, n]) => ({ rowId: r, row: n })), t = [...this._removes];
|
|
61
|
+
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());
|
|
62
|
+
}
|
|
63
|
+
get stats() {
|
|
64
|
+
return { pending: this._cells.size + this._upserts.size + this._removes.size, coalesced: this._coalesced, dropped: this._dropped };
|
|
65
|
+
}
|
|
66
|
+
dispose() {
|
|
67
|
+
var _a;
|
|
68
|
+
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;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class d {
|
|
72
|
+
constructor(e) {
|
|
73
|
+
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 = d._footprintOf(e);
|
|
74
|
+
}
|
|
75
|
+
get appliedDelta() {
|
|
76
|
+
return this._applied;
|
|
77
|
+
}
|
|
78
|
+
do(e) {
|
|
79
|
+
this._at = e.clock.now(), this._cellInverse = [], this._insertedRowIds = [], this._removedInverse = [];
|
|
80
|
+
const s = [];
|
|
81
|
+
e.mutation.beginBatch();
|
|
82
|
+
try {
|
|
83
|
+
const i = [];
|
|
84
|
+
for (const t of this._batch.cells) {
|
|
85
|
+
const r = e.coords.indexOf(t.rowId);
|
|
86
|
+
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 }));
|
|
87
|
+
}
|
|
88
|
+
i.length > 0 && e.mutation.writeCells(i);
|
|
89
|
+
for (const t of this._batch.upserts) {
|
|
90
|
+
const r = e.coords.indexOf(t.rowId);
|
|
91
|
+
if (r >= 0) {
|
|
92
|
+
const n = [];
|
|
93
|
+
for (const [l, _] 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: _ }), s.push({ rowId: t.rowId, field: l });
|
|
94
|
+
n.length > 0 && e.mutation.writeCells(n);
|
|
95
|
+
} else e.mutation.insertRow(t.row, "last"), this._insertedRowIds.push(t.rowId);
|
|
96
|
+
}
|
|
97
|
+
const o = [];
|
|
98
|
+
for (const t of this._batch.removes) {
|
|
99
|
+
const r = e.coords.indexOf(t);
|
|
100
|
+
r < 0 || (this._removedInverse.push({ rowId: t, snapshot: e.coords.getRowSnapshot(t) }), o.push({ rowId: t, index: r }));
|
|
101
|
+
}
|
|
102
|
+
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 };
|
|
103
|
+
} finally {
|
|
104
|
+
e.mutation.endBatch();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
undo(e) {
|
|
108
|
+
e.mutation.beginBatch();
|
|
109
|
+
try {
|
|
110
|
+
const s = this._insertedRowIds.map((o) => e.coords.indexOf(o)).filter((o) => o >= 0).sort((o, t) => t - o);
|
|
111
|
+
s.length > 0 && e.mutation.deleteRows(s);
|
|
112
|
+
for (const o of this._removedInverse) o.snapshot && e.mutation.insertRow(o.snapshot, "last");
|
|
113
|
+
const i = [];
|
|
114
|
+
for (const o of this._cellInverse) {
|
|
115
|
+
const t = e.coords.indexOf(o.rowId);
|
|
116
|
+
t >= 0 && i.push({ rowIndex: t, field: o.field, value: o.oldValue });
|
|
117
|
+
}
|
|
118
|
+
i.length > 0 && e.mutation.writeCells(i);
|
|
119
|
+
} finally {
|
|
120
|
+
e.mutation.endBatch();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
serialize() {
|
|
124
|
+
return { kind: this.kind, payload: { cells: this._batch.cells, upserts: this._batch.upserts, removes: this._batch.removes }, at: this._at };
|
|
125
|
+
}
|
|
126
|
+
static _footprintOf(e) {
|
|
127
|
+
if (e.snapshot || e.upserts.length > 0 || e.removes.length > 0) return { scope: "structure" };
|
|
128
|
+
const s = [...new Set(e.cells.map((o) => o.rowId))], i = [...new Set(e.cells.map((o) => o.field))];
|
|
129
|
+
return s.length === 1 && i.length === 1 ? { scope: "cell", rowId: s[0], field: i[0] } : { scope: "range", rowIds: s, fields: i };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class u {
|
|
133
|
+
constructor(e, s) {
|
|
134
|
+
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 c({ ...s.maxBatchPerFrame !== void 0 ? { maxBatchPerFrame: s.maxBatchPerFrame } : {}, scheduleFrame: s.scheduleFrame ?? a, flush: (i) => this._applyBatch(i) });
|
|
135
|
+
}
|
|
136
|
+
attach() {
|
|
137
|
+
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());
|
|
138
|
+
}
|
|
139
|
+
detach() {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
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());
|
|
142
|
+
}
|
|
143
|
+
get connection() {
|
|
144
|
+
return this._connection;
|
|
145
|
+
}
|
|
146
|
+
get backpressureStats() {
|
|
147
|
+
return this._scheduler.stats;
|
|
148
|
+
}
|
|
149
|
+
onConnection(e) {
|
|
150
|
+
return this._statusListeners.add(e), () => this._statusListeners.delete(e);
|
|
151
|
+
}
|
|
152
|
+
_onData(e) {
|
|
153
|
+
this._deps.freshness.markReceived(e.serverTime ?? this._now()), this._scheduler.enqueue(e);
|
|
154
|
+
}
|
|
155
|
+
_onStatus(e) {
|
|
156
|
+
this._connection = e, this._deps.announce.onConnection(e.status), this._deps.freshness.tick();
|
|
157
|
+
for (const s of this._statusListeners) s(e);
|
|
158
|
+
}
|
|
159
|
+
_applyBatch(e) {
|
|
160
|
+
const s = this._deps.stateGuard.capture();
|
|
161
|
+
if (e.snapshot) {
|
|
162
|
+
if (this._deps.applySnapshot) {
|
|
163
|
+
this._deps.applySnapshot(e.snapshot.rows);
|
|
164
|
+
const t = { changedCells: [], insertedRowIds: [], removedRowIds: [], userInitiated: false };
|
|
165
|
+
this._deps.stateGuard.restore(s, t), this._deps.announce.onBackgroundChange(t);
|
|
166
|
+
} else console.warn("[open-grid/realtime] snapshot received but no applySnapshot dep wired — skipped");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const i = new d(e);
|
|
170
|
+
this._deps.sink.beginBatch();
|
|
171
|
+
try {
|
|
172
|
+
this._deps.sink.dispatchSilent(i);
|
|
173
|
+
} finally {
|
|
174
|
+
this._deps.sink.endBatch();
|
|
175
|
+
}
|
|
176
|
+
const o = i.appliedDelta;
|
|
177
|
+
if (o && (this._deps.stateGuard.restore(s, o), this._deps.announce.onBackgroundChange(o), this._deps.chart)) {
|
|
178
|
+
const t = [.../* @__PURE__ */ new Set([...o.changedCells.map((r) => r.rowId), ...o.insertedRowIds, ...o.removedRowIds])];
|
|
179
|
+
t.length > 0 && this._deps.chart.markDirty(t);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
class f {
|
|
184
|
+
constructor(e, s) {
|
|
185
|
+
this._lastConflicts = [], this._src = e, this._coords = s;
|
|
186
|
+
}
|
|
187
|
+
get lastConflicts() {
|
|
188
|
+
return this._lastConflicts;
|
|
189
|
+
}
|
|
190
|
+
capture() {
|
|
191
|
+
const e = this._src.readEditing();
|
|
192
|
+
return { selection: this._src.readSelection(), scroll: this._src.readScroll(), ...e ? { editing: e } : {}, sortFilterSig: this._src.readSortFilterSig() };
|
|
193
|
+
}
|
|
194
|
+
restore(e, s) {
|
|
195
|
+
this._lastConflicts = [];
|
|
196
|
+
const i = new Set(s.removedRowIds), o = e.selection.filter((t) => !i.has(t.rowId) && this._coords.rowIdToIndex(t.rowId) >= 0);
|
|
197
|
+
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));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
class p {
|
|
201
|
+
constructor(e) {
|
|
202
|
+
this._lastState = "stale", this._listeners = /* @__PURE__ */ new Set(), this._staleAfterMs = e.staleAfterMs, this._now = e.now ?? (() => Date.now());
|
|
203
|
+
}
|
|
204
|
+
markReceived(e) {
|
|
205
|
+
this._lastReceivedAt = e, this._emitIfChanged();
|
|
206
|
+
}
|
|
207
|
+
compute() {
|
|
208
|
+
const e = this._now();
|
|
209
|
+
if (this._lastReceivedAt === void 0) return { state: "stale", ageMs: 1 / 0 };
|
|
210
|
+
const s = e - this._lastReceivedAt;
|
|
211
|
+
return { state: s > this._staleAfterMs ? "stale" : "fresh", ageMs: s, lastReceivedAt: this._lastReceivedAt };
|
|
212
|
+
}
|
|
213
|
+
tick() {
|
|
214
|
+
return this._emitIfChanged();
|
|
215
|
+
}
|
|
216
|
+
_emitIfChanged() {
|
|
217
|
+
const e = this.compute();
|
|
218
|
+
if (e.state !== this._lastState) {
|
|
219
|
+
this._lastState = e.state;
|
|
220
|
+
for (const s of this._listeners) s(e);
|
|
221
|
+
}
|
|
222
|
+
return e;
|
|
223
|
+
}
|
|
224
|
+
onChange(e) {
|
|
225
|
+
return this._listeners.add(e), () => this._listeners.delete(e);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
class w {
|
|
229
|
+
constructor(e) {
|
|
230
|
+
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) => {
|
|
231
|
+
const o = setTimeout(s, i);
|
|
232
|
+
return { cancel: () => clearTimeout(o) };
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
onBackgroundChange(e) {
|
|
236
|
+
for (const s of e.changedCells) this._pendingCells.add(s.rowId + " " + s.field), this._pendingRows.add(s.rowId);
|
|
237
|
+
for (const s of e.insertedRowIds) this._pendingRows.add(s);
|
|
238
|
+
for (const s of e.removedRowIds) this._pendingRows.add(s);
|
|
239
|
+
this._arm();
|
|
240
|
+
}
|
|
241
|
+
_arm() {
|
|
242
|
+
this._timer || (this._timer = this._schedule(() => {
|
|
243
|
+
this._timer = void 0, this._flush();
|
|
244
|
+
}, this._debounceMs));
|
|
245
|
+
}
|
|
246
|
+
_flush() {
|
|
247
|
+
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());
|
|
248
|
+
}
|
|
249
|
+
onConnection(e) {
|
|
250
|
+
this._announce({ kind: "connection", changedCount: 0, rowCount: 0, label: "connection", interruptsFocus: false, connectionStatus: e });
|
|
251
|
+
}
|
|
252
|
+
dispose() {
|
|
253
|
+
var _a;
|
|
254
|
+
(_a = this._timer) == null ? void 0 : _a.cancel(), this._timer = void 0, this._pendingCells.clear(), this._pendingRows.clear();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
export {
|
|
258
|
+
c as BackpressureScheduler,
|
|
259
|
+
p as FreshnessClock,
|
|
260
|
+
f as LiveStateGuard,
|
|
261
|
+
u as RealtimeController,
|
|
262
|
+
w as RtAnnouncePolicy,
|
|
263
|
+
d as RtApplyCommand,
|
|
264
|
+
a as defaultFrameScheduler
|
|
265
|
+
};
|
|
266
|
+
//# sourceMappingURL=index-DnarQ4eR.js.map
|