@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 +90 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -40,6 +40,7 @@ declare class EditorController {
|
|
|
40
40
|
private readonly onMarkdownChange?;
|
|
41
41
|
private readonly onTokensChange?;
|
|
42
42
|
private readonly onSelectionChange?;
|
|
43
|
+
private baselineContent;
|
|
43
44
|
constructor(options?: EditorControllerOptions);
|
|
44
45
|
private enforcePlainTextClipboard;
|
|
45
46
|
private handleUpdate;
|
|
@@ -51,6 +52,11 @@ declare class EditorController {
|
|
|
51
52
|
insertText(text: string): void;
|
|
52
53
|
insertTextAt(pos: number, text: string): void;
|
|
53
54
|
replaceRange(from: number, to: number, text: string): void;
|
|
55
|
+
getCurrentContentString(): string;
|
|
56
|
+
isDirty(): boolean;
|
|
57
|
+
setCheckpoint(content?: string): void;
|
|
58
|
+
resetDirty(): void;
|
|
59
|
+
getBaselineContent(): string;
|
|
54
60
|
destroy(): void;
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
@@ -58,4 +64,41 @@ declare class EditorController {
|
|
|
58
64
|
*/
|
|
59
65
|
declare function createEditor(options?: EditorControllerOptions): EditorController;
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Compares two values for structural equality.
|
|
69
|
+
* Handles primitives, objects, arrays, and null/undefined.
|
|
70
|
+
*/
|
|
71
|
+
declare function defaultIsEqual<T>(a: T, b: T): boolean;
|
|
72
|
+
interface DirtyTrackerOptions<T> {
|
|
73
|
+
isEqual?: (a: T, b: T) => boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Tracks a baseline value and determines if the current state is dirty (modified).
|
|
77
|
+
*/
|
|
78
|
+
declare class DirtyTracker<T = unknown> {
|
|
79
|
+
private baseline;
|
|
80
|
+
private readonly isEqual;
|
|
81
|
+
constructor(initialBaseline: T, options?: DirtyTrackerOptions<T> | ((a: T, b: T) => boolean));
|
|
82
|
+
/**
|
|
83
|
+
* Returns current baseline value.
|
|
84
|
+
*/
|
|
85
|
+
getBaseline(): T;
|
|
86
|
+
/**
|
|
87
|
+
* Sets a new baseline value without triggering any dirty state.
|
|
88
|
+
*/
|
|
89
|
+
setBaseline(value: T): void;
|
|
90
|
+
/**
|
|
91
|
+
* Checks whether the given value differs from the baseline.
|
|
92
|
+
*/
|
|
93
|
+
isDirty(current: T): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Resets the baseline to the provided current value (or clears dirty status).
|
|
96
|
+
*/
|
|
97
|
+
reset(current: T): void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a DirtyTracker instance.
|
|
101
|
+
*/
|
|
102
|
+
declare function createDirtyTracker<T>(initialBaseline: T, options?: DirtyTrackerOptions<T> | ((a: T, b: T) => boolean)): DirtyTracker<T>;
|
|
103
|
+
|
|
104
|
+
export { DirtyTracker, type DirtyTrackerOptions, EditorController, type EditorControllerOptions, Token, createDirtyTracker, createEditor, defaultIsEqual };
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare class EditorController {
|
|
|
40
40
|
private readonly onMarkdownChange?;
|
|
41
41
|
private readonly onTokensChange?;
|
|
42
42
|
private readonly onSelectionChange?;
|
|
43
|
+
private baselineContent;
|
|
43
44
|
constructor(options?: EditorControllerOptions);
|
|
44
45
|
private enforcePlainTextClipboard;
|
|
45
46
|
private handleUpdate;
|
|
@@ -51,6 +52,11 @@ declare class EditorController {
|
|
|
51
52
|
insertText(text: string): void;
|
|
52
53
|
insertTextAt(pos: number, text: string): void;
|
|
53
54
|
replaceRange(from: number, to: number, text: string): void;
|
|
55
|
+
getCurrentContentString(): string;
|
|
56
|
+
isDirty(): boolean;
|
|
57
|
+
setCheckpoint(content?: string): void;
|
|
58
|
+
resetDirty(): void;
|
|
59
|
+
getBaselineContent(): string;
|
|
54
60
|
destroy(): void;
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
@@ -58,4 +64,41 @@ declare class EditorController {
|
|
|
58
64
|
*/
|
|
59
65
|
declare function createEditor(options?: EditorControllerOptions): EditorController;
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Compares two values for structural equality.
|
|
69
|
+
* Handles primitives, objects, arrays, and null/undefined.
|
|
70
|
+
*/
|
|
71
|
+
declare function defaultIsEqual<T>(a: T, b: T): boolean;
|
|
72
|
+
interface DirtyTrackerOptions<T> {
|
|
73
|
+
isEqual?: (a: T, b: T) => boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Tracks a baseline value and determines if the current state is dirty (modified).
|
|
77
|
+
*/
|
|
78
|
+
declare class DirtyTracker<T = unknown> {
|
|
79
|
+
private baseline;
|
|
80
|
+
private readonly isEqual;
|
|
81
|
+
constructor(initialBaseline: T, options?: DirtyTrackerOptions<T> | ((a: T, b: T) => boolean));
|
|
82
|
+
/**
|
|
83
|
+
* Returns current baseline value.
|
|
84
|
+
*/
|
|
85
|
+
getBaseline(): T;
|
|
86
|
+
/**
|
|
87
|
+
* Sets a new baseline value without triggering any dirty state.
|
|
88
|
+
*/
|
|
89
|
+
setBaseline(value: T): void;
|
|
90
|
+
/**
|
|
91
|
+
* Checks whether the given value differs from the baseline.
|
|
92
|
+
*/
|
|
93
|
+
isDirty(current: T): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Resets the baseline to the provided current value (or clears dirty status).
|
|
96
|
+
*/
|
|
97
|
+
reset(current: T): void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a DirtyTracker instance.
|
|
101
|
+
*/
|
|
102
|
+
declare function createDirtyTracker<T>(initialBaseline: T, options?: DirtyTrackerOptions<T> | ((a: T, b: T) => boolean)): DirtyTracker<T>;
|
|
103
|
+
|
|
104
|
+
export { DirtyTracker, type DirtyTrackerOptions, EditorController, type EditorControllerOptions, Token, createDirtyTracker, createEditor, defaultIsEqual };
|
package/dist/index.js
CHANGED
|
@@ -2358,6 +2358,7 @@ var EditorController = class {
|
|
|
2358
2358
|
onMarkdownChange;
|
|
2359
2359
|
onTokensChange;
|
|
2360
2360
|
onSelectionChange;
|
|
2361
|
+
baselineContent;
|
|
2361
2362
|
constructor(options = {}) {
|
|
2362
2363
|
const {
|
|
2363
2364
|
element,
|
|
@@ -2395,6 +2396,7 @@ var EditorController = class {
|
|
|
2395
2396
|
if (plainTextMode) {
|
|
2396
2397
|
this.enforcePlainTextClipboard();
|
|
2397
2398
|
}
|
|
2399
|
+
this.baselineContent = this.getCurrentContentString();
|
|
2398
2400
|
}
|
|
2399
2401
|
enforcePlainTextClipboard() {
|
|
2400
2402
|
this.editor.setOptions({
|
|
@@ -2468,6 +2470,23 @@ var EditorController = class {
|
|
|
2468
2470
|
replaceRange(from, to, text) {
|
|
2469
2471
|
this.editor.chain().focus().deleteRange({ from, to }).insertContentAt(from, text).run();
|
|
2470
2472
|
}
|
|
2473
|
+
getCurrentContentString() {
|
|
2474
|
+
if (this.plainTextMode) return this.getPlainText();
|
|
2475
|
+
if (this.markdownMode) return this.getMarkdown();
|
|
2476
|
+
return this.editor.getHTML();
|
|
2477
|
+
}
|
|
2478
|
+
isDirty() {
|
|
2479
|
+
return this.getCurrentContentString() !== this.baselineContent;
|
|
2480
|
+
}
|
|
2481
|
+
setCheckpoint(content) {
|
|
2482
|
+
this.baselineContent = content !== void 0 ? content : this.getCurrentContentString();
|
|
2483
|
+
}
|
|
2484
|
+
resetDirty() {
|
|
2485
|
+
this.setCheckpoint();
|
|
2486
|
+
}
|
|
2487
|
+
getBaselineContent() {
|
|
2488
|
+
return this.baselineContent;
|
|
2489
|
+
}
|
|
2471
2490
|
destroy() {
|
|
2472
2491
|
this.editor.destroy();
|
|
2473
2492
|
}
|
|
@@ -3750,10 +3769,76 @@ var SpreadsheetController = class {
|
|
|
3750
3769
|
this.onDocumentChange?.(this.document);
|
|
3751
3770
|
}
|
|
3752
3771
|
};
|
|
3772
|
+
|
|
3773
|
+
// src/dirty.ts
|
|
3774
|
+
function defaultIsEqual(a, b) {
|
|
3775
|
+
if (Object.is(a, b)) return true;
|
|
3776
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
3777
|
+
return false;
|
|
3778
|
+
}
|
|
3779
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
3780
|
+
if (a.length !== b.length) return false;
|
|
3781
|
+
for (let i = 0; i < a.length; i++) {
|
|
3782
|
+
if (!defaultIsEqual(a[i], b[i])) return false;
|
|
3783
|
+
}
|
|
3784
|
+
return true;
|
|
3785
|
+
}
|
|
3786
|
+
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
3787
|
+
return false;
|
|
3788
|
+
}
|
|
3789
|
+
const keysA = Object.keys(a);
|
|
3790
|
+
const keysB = Object.keys(b);
|
|
3791
|
+
if (keysA.length !== keysB.length) return false;
|
|
3792
|
+
for (const key of keysA) {
|
|
3793
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
3794
|
+
if (!defaultIsEqual(a[key], b[key])) return false;
|
|
3795
|
+
}
|
|
3796
|
+
return true;
|
|
3797
|
+
}
|
|
3798
|
+
var DirtyTracker = class {
|
|
3799
|
+
baseline;
|
|
3800
|
+
isEqual;
|
|
3801
|
+
constructor(initialBaseline, options) {
|
|
3802
|
+
this.baseline = initialBaseline;
|
|
3803
|
+
if (typeof options === "function") {
|
|
3804
|
+
this.isEqual = options;
|
|
3805
|
+
} else {
|
|
3806
|
+
this.isEqual = options?.isEqual ?? defaultIsEqual;
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
/**
|
|
3810
|
+
* Returns current baseline value.
|
|
3811
|
+
*/
|
|
3812
|
+
getBaseline() {
|
|
3813
|
+
return this.baseline;
|
|
3814
|
+
}
|
|
3815
|
+
/**
|
|
3816
|
+
* Sets a new baseline value without triggering any dirty state.
|
|
3817
|
+
*/
|
|
3818
|
+
setBaseline(value) {
|
|
3819
|
+
this.baseline = value;
|
|
3820
|
+
}
|
|
3821
|
+
/**
|
|
3822
|
+
* Checks whether the given value differs from the baseline.
|
|
3823
|
+
*/
|
|
3824
|
+
isDirty(current) {
|
|
3825
|
+
return !this.isEqual(this.baseline, current);
|
|
3826
|
+
}
|
|
3827
|
+
/**
|
|
3828
|
+
* Resets the baseline to the provided current value (or clears dirty status).
|
|
3829
|
+
*/
|
|
3830
|
+
reset(current) {
|
|
3831
|
+
this.baseline = current;
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
function createDirtyTracker(initialBaseline, options) {
|
|
3835
|
+
return new DirtyTracker(initialBaseline, options);
|
|
3836
|
+
}
|
|
3753
3837
|
export {
|
|
3754
3838
|
ColorHighlighter,
|
|
3755
3839
|
DataSourceBinder,
|
|
3756
3840
|
DependencyGraph,
|
|
3841
|
+
DirtyTracker,
|
|
3757
3842
|
EditorController,
|
|
3758
3843
|
FontSize,
|
|
3759
3844
|
FormulaEvaluator,
|
|
@@ -3771,9 +3856,11 @@ export {
|
|
|
3771
3856
|
TemplateSuggestions,
|
|
3772
3857
|
VARIABLE_REGEX,
|
|
3773
3858
|
colNameToIndex,
|
|
3859
|
+
createDirtyTracker,
|
|
3774
3860
|
createEditor,
|
|
3775
3861
|
createMentionExtension,
|
|
3776
3862
|
createRichTextPreset,
|
|
3863
|
+
defaultIsEqual,
|
|
3777
3864
|
escapeHtml,
|
|
3778
3865
|
extractCellDependencies,
|
|
3779
3866
|
extractInstructionNames,
|