@signaltree/core 10.0.0 → 10.1.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/edit-session.js +1 -1
- package/dist/lib/edit-session.js +22 -1
- package/package.json +1 -1
- package/src/edit-session.d.ts +1 -1
- package/src/lib/edit-session.d.ts +11 -0
package/dist/edit-session.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createEditSession } from './lib/edit-session.js';
|
|
1
|
+
export { createEditSession, createTreeEditSession } from './lib/edit-session.js';
|
package/dist/lib/edit-session.js
CHANGED
|
@@ -80,5 +80,26 @@ function createEditSession(initial) {
|
|
|
80
80
|
getHistory
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
+
function createTreeEditSession(source) {
|
|
84
|
+
if (typeof source !== 'function' || typeof source.set !== 'function') {
|
|
85
|
+
throw new TypeError('createTreeEditSession: source must be a callable accessor with a .set() method ' + '(e.g. tree.$.user.profile or a WritableSignal).');
|
|
86
|
+
}
|
|
87
|
+
const initial = clone(source());
|
|
88
|
+
const base = createEditSession(initial);
|
|
89
|
+
return {
|
|
90
|
+
...base,
|
|
91
|
+
commit() {
|
|
92
|
+
source.set(clone(base.modified()));
|
|
93
|
+
},
|
|
94
|
+
cancel() {
|
|
95
|
+
const current = clone(source());
|
|
96
|
+
base.setOriginal(current);
|
|
97
|
+
},
|
|
98
|
+
pullFromSource() {
|
|
99
|
+
const current = clone(source());
|
|
100
|
+
base.original.set(current);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
83
104
|
|
|
84
|
-
export { createEditSession, createEditSession as default };
|
|
105
|
+
export { createEditSession, createTreeEditSession, createEditSession as default };
|
package/package.json
CHANGED
package/src/edit-session.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createEditSession, type EditSession, type UndoRedoHistory, } from './lib/edit-session';
|
|
1
|
+
export { createEditSession, createTreeEditSession, type EditSession, type TreeEditSession, type TreeEditSource, type UndoRedoHistory, } from './lib/edit-session';
|
|
@@ -19,3 +19,14 @@ export interface EditSession<T> {
|
|
|
19
19
|
}
|
|
20
20
|
export declare function createEditSession<T>(initial: T): EditSession<T>;
|
|
21
21
|
export default createEditSession;
|
|
22
|
+
export interface TreeEditSource<T> {
|
|
23
|
+
(): T;
|
|
24
|
+
set(value: T): void;
|
|
25
|
+
update?(fn: (current: T) => T): void;
|
|
26
|
+
}
|
|
27
|
+
export interface TreeEditSession<T> extends EditSession<T> {
|
|
28
|
+
commit(): void;
|
|
29
|
+
cancel(): void;
|
|
30
|
+
pullFromSource(): void;
|
|
31
|
+
}
|
|
32
|
+
export declare function createTreeEditSession<T>(source: TreeEditSource<T>): TreeEditSession<T>;
|