@pixerate/editor 0.6.1 → 0.7.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/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(src_exports, {
33
33
  ColorHighlighter: () => ColorHighlighter,
34
34
  DataSourceBinder: () => DataSourceBinder,
35
35
  DependencyGraph: () => DependencyGraph,
36
+ DirtyTracker: () => DirtyTracker,
36
37
  EditorController: () => EditorController,
37
38
  FontSize: () => FontSize,
38
39
  FormulaEvaluator: () => FormulaEvaluator,
@@ -50,9 +51,11 @@ __export(src_exports, {
50
51
  TemplateSuggestions: () => TemplateSuggestions,
51
52
  VARIABLE_REGEX: () => VARIABLE_REGEX,
52
53
  colNameToIndex: () => colNameToIndex,
54
+ createDirtyTracker: () => createDirtyTracker,
53
55
  createEditor: () => createEditor,
54
56
  createMentionExtension: () => createMentionExtension,
55
57
  createRichTextPreset: () => createRichTextPreset,
58
+ defaultIsEqual: () => defaultIsEqual,
56
59
  escapeHtml: () => escapeHtml,
57
60
  extractCellDependencies: () => extractCellDependencies,
58
61
  extractInstructionNames: () => extractInstructionNames,
@@ -2443,6 +2446,7 @@ var EditorController = class {
2443
2446
  onMarkdownChange;
2444
2447
  onTokensChange;
2445
2448
  onSelectionChange;
2449
+ baselineContent;
2446
2450
  constructor(options = {}) {
2447
2451
  const {
2448
2452
  element,
@@ -2480,6 +2484,7 @@ var EditorController = class {
2480
2484
  if (plainTextMode) {
2481
2485
  this.enforcePlainTextClipboard();
2482
2486
  }
2487
+ this.baselineContent = this.getCurrentContentString();
2483
2488
  }
2484
2489
  enforcePlainTextClipboard() {
2485
2490
  this.editor.setOptions({
@@ -2553,6 +2558,23 @@ var EditorController = class {
2553
2558
  replaceRange(from, to, text) {
2554
2559
  this.editor.chain().focus().deleteRange({ from, to }).insertContentAt(from, text).run();
2555
2560
  }
2561
+ getCurrentContentString() {
2562
+ if (this.plainTextMode) return this.getPlainText();
2563
+ if (this.markdownMode) return this.getMarkdown();
2564
+ return this.editor.getHTML();
2565
+ }
2566
+ isDirty() {
2567
+ return this.getCurrentContentString() !== this.baselineContent;
2568
+ }
2569
+ setCheckpoint(content) {
2570
+ this.baselineContent = content !== void 0 ? content : this.getCurrentContentString();
2571
+ }
2572
+ resetDirty() {
2573
+ this.setCheckpoint();
2574
+ }
2575
+ getBaselineContent() {
2576
+ return this.baselineContent;
2577
+ }
2556
2578
  destroy() {
2557
2579
  this.editor.destroy();
2558
2580
  }
@@ -3835,11 +3857,77 @@ var SpreadsheetController = class {
3835
3857
  this.onDocumentChange?.(this.document);
3836
3858
  }
3837
3859
  };
3860
+
3861
+ // src/dirty.ts
3862
+ function defaultIsEqual(a, b) {
3863
+ if (Object.is(a, b)) return true;
3864
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
3865
+ return false;
3866
+ }
3867
+ if (Array.isArray(a) && Array.isArray(b)) {
3868
+ if (a.length !== b.length) return false;
3869
+ for (let i = 0; i < a.length; i++) {
3870
+ if (!defaultIsEqual(a[i], b[i])) return false;
3871
+ }
3872
+ return true;
3873
+ }
3874
+ if (Array.isArray(a) !== Array.isArray(b)) {
3875
+ return false;
3876
+ }
3877
+ const keysA = Object.keys(a);
3878
+ const keysB = Object.keys(b);
3879
+ if (keysA.length !== keysB.length) return false;
3880
+ for (const key of keysA) {
3881
+ if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
3882
+ if (!defaultIsEqual(a[key], b[key])) return false;
3883
+ }
3884
+ return true;
3885
+ }
3886
+ var DirtyTracker = class {
3887
+ baseline;
3888
+ isEqual;
3889
+ constructor(initialBaseline, options) {
3890
+ this.baseline = initialBaseline;
3891
+ if (typeof options === "function") {
3892
+ this.isEqual = options;
3893
+ } else {
3894
+ this.isEqual = options?.isEqual ?? defaultIsEqual;
3895
+ }
3896
+ }
3897
+ /**
3898
+ * Returns current baseline value.
3899
+ */
3900
+ getBaseline() {
3901
+ return this.baseline;
3902
+ }
3903
+ /**
3904
+ * Sets a new baseline value without triggering any dirty state.
3905
+ */
3906
+ setBaseline(value) {
3907
+ this.baseline = value;
3908
+ }
3909
+ /**
3910
+ * Checks whether the given value differs from the baseline.
3911
+ */
3912
+ isDirty(current) {
3913
+ return !this.isEqual(this.baseline, current);
3914
+ }
3915
+ /**
3916
+ * Resets the baseline to the provided current value (or clears dirty status).
3917
+ */
3918
+ reset(current) {
3919
+ this.baseline = current;
3920
+ }
3921
+ };
3922
+ function createDirtyTracker(initialBaseline, options) {
3923
+ return new DirtyTracker(initialBaseline, options);
3924
+ }
3838
3925
  // Annotate the CommonJS export names for ESM import in node:
3839
3926
  0 && (module.exports = {
3840
3927
  ColorHighlighter,
3841
3928
  DataSourceBinder,
3842
3929
  DependencyGraph,
3930
+ DirtyTracker,
3843
3931
  EditorController,
3844
3932
  FontSize,
3845
3933
  FormulaEvaluator,
@@ -3857,9 +3945,11 @@ var SpreadsheetController = class {
3857
3945
  TemplateSuggestions,
3858
3946
  VARIABLE_REGEX,
3859
3947
  colNameToIndex,
3948
+ createDirtyTracker,
3860
3949
  createEditor,
3861
3950
  createMentionExtension,
3862
3951
  createRichTextPreset,
3952
+ defaultIsEqual,
3863
3953
  escapeHtml,
3864
3954
  extractCellDependencies,
3865
3955
  extractInstructionNames,