document-model 1.0.14 → 1.0.16
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/browser/document/actions/creators.d.ts +1 -1
- package/dist/browser/document/actions/index.d.ts +8 -8
- package/dist/browser/document/object.d.ts +123 -99
- package/dist/browser/document/reducer.d.ts +1 -1
- package/dist/browser/document/schema/types.d.ts +5 -0
- package/dist/browser/document/schema/zod.d.ts +15 -0
- package/dist/browser/document/signal.d.ts +3 -2
- package/dist/browser/document/types.d.ts +36 -27
- package/dist/browser/document/utils/base.d.ts +5 -5
- package/dist/browser/document/utils/file.d.ts +2 -2
- package/dist/browser/document-model/gen/reducer.d.ts +1 -1
- package/dist/browser/document-model/gen/schema/types.d.ts +5 -2
- package/dist/browser/document-model/index.d.ts +8 -8
- package/dist/browser/document-model.cjs +1 -1
- package/dist/browser/document-model.js +2 -2
- package/dist/browser/document.cjs +1 -1
- package/dist/browser/document.js +2 -2
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.js +3 -3
- package/dist/browser/internal/{index-8142b58e.js → index-37753e74.js} +1 -1
- package/dist/{node/internal/index-0b0cb8c2.js → browser/internal/index-9b4d67fc.js} +1 -1
- package/dist/browser/internal/{index-cbe39f72.js → index-a5150e7e.js} +1 -1
- package/dist/{node/internal/index-c9d178be.js → browser/internal/index-f5587600.js} +1 -1
- package/dist/browser/internal/{object-4ec03a36.js → object-17aee7a9.js} +693 -659
- package/dist/browser/internal/object-28a1a8bf.js +6 -0
- package/dist/node/document/actions/creators.d.ts +1 -1
- package/dist/node/document/actions/index.d.ts +8 -8
- package/dist/node/document/object.d.ts +123 -99
- package/dist/node/document/reducer.d.ts +1 -1
- package/dist/node/document/schema/types.d.ts +5 -0
- package/dist/node/document/schema/zod.d.ts +15 -0
- package/dist/node/document/signal.d.ts +3 -2
- package/dist/node/document/types.d.ts +36 -27
- package/dist/node/document/utils/base.d.ts +5 -5
- package/dist/node/document/utils/file.d.ts +2 -2
- package/dist/node/document-model/gen/reducer.d.ts +1 -1
- package/dist/node/document-model/gen/schema/types.d.ts +5 -2
- package/dist/node/document-model/index.d.ts +8 -8
- package/dist/node/document-model.cjs +1 -1
- package/dist/node/document-model.js +2 -2
- package/dist/node/document.cjs +1 -1
- package/dist/node/document.js +2 -2
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.js +3 -3
- package/dist/{browser/internal/index-cb990484.js → node/internal/index-0e7af6c6.js} +1 -1
- package/dist/{browser/internal/index-9f1cf811.js → node/internal/index-124bda95.js} +1 -1
- package/dist/node/internal/{index-63db4708.js → index-417115f1.js} +1 -1
- package/dist/node/internal/{index-0c87fbed.js → index-9037f83a.js} +1 -1
- package/dist/node/internal/object-f3dd289e.js +1 -0
- package/dist/node/internal/{object-89d9b82f.js → object-f7cd4777.js} +369 -337
- package/package.json +3 -3
- package/dist/browser/internal/object-5f03095e.js +0 -6
- package/dist/node/internal/object-397a9b23.js +0 -1
|
@@ -43,4 +43,4 @@ export declare const prune: (start?: number | undefined, end?: number | undefine
|
|
|
43
43
|
* @param operations - Number of operations that were removed from the previous state.
|
|
44
44
|
* @category Actions
|
|
45
45
|
*/
|
|
46
|
-
export declare const loadState: (state: Pick<ExtendedState,
|
|
46
|
+
export declare const loadState: <S, T>(state: Pick<ExtendedState<S, T>, "name" | "state">, operations: number) => LoadStateAction;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Action, Document, ImmutableStateReducer } from '../types';
|
|
2
|
-
export declare function setNameOperation<T
|
|
3
|
-
export declare function undoOperation<T, A extends Action>(document: Document<T, A>, count: number, wrappedReducer: ImmutableStateReducer<T, A>): Document<T, A>;
|
|
4
|
-
export declare function redoOperation<T, A extends Action>(document: Document<T, A>, count: number, wrappedReducer: ImmutableStateReducer<T, A>): Document<T, A>;
|
|
5
|
-
export declare function pruneOperation<T, A extends Action>(document: Document<T, A>, start: number | null | undefined, end: number | null | undefined, wrappedReducer: ImmutableStateReducer<T, A>): Document<T, A>;
|
|
6
|
-
export declare function loadStateOperation<T, A extends Action>(oldDocument: Document<T, A>, newDocument: {
|
|
1
|
+
import { Action, Document, ImmutableStateReducer, State } from '../types';
|
|
2
|
+
export declare function setNameOperation<T>(document: T, name: string): T;
|
|
3
|
+
export declare function undoOperation<T, A extends Action, L>(document: Document<T, A, L>, count: number, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
|
|
4
|
+
export declare function redoOperation<T, A extends Action, L>(document: Document<T, A, L>, count: number, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
|
|
5
|
+
export declare function pruneOperation<T, A extends Action, L>(document: Document<T, A, L>, start: number | null | undefined, end: number | null | undefined, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
|
|
6
|
+
export declare function loadStateOperation<T, A extends Action, L>(oldDocument: Document<T, A, L>, newDocument: {
|
|
7
7
|
name: string;
|
|
8
|
-
state?: T
|
|
9
|
-
}): Document<T, A>;
|
|
8
|
+
state?: State<T, L>;
|
|
9
|
+
}): Document<T, A, L>;
|
|
10
10
|
export * from './creators';
|
|
@@ -7,8 +7,8 @@ import type { Action, AttachmentRef, Document, ExtendedState, Reducer } from './
|
|
|
7
7
|
* @typeparam T - The type of data stored in the document.
|
|
8
8
|
* @typeparam A - The type of action the document can take.
|
|
9
9
|
*/
|
|
10
|
-
export declare abstract class BaseDocument<T, A extends Action> {
|
|
11
|
-
protected _document: Document<T, A>;
|
|
10
|
+
export declare abstract class BaseDocument<T, A extends Action, L = unknown> {
|
|
11
|
+
protected _document: Document<T, A, L>;
|
|
12
12
|
private _reducer;
|
|
13
13
|
private _signalDispatch?;
|
|
14
14
|
/**
|
|
@@ -16,7 +16,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
16
16
|
* @param reducer - The reducer function that updates the state.
|
|
17
17
|
* @param document - The initial state of the document.
|
|
18
18
|
*/
|
|
19
|
-
constructor(reducer: Reducer<T, A>, document: Document<T, A>, signalDispatch?: SignalDispatch);
|
|
19
|
+
constructor(reducer: Reducer<T, A, L>, document: Document<T, A, L>, signalDispatch?: SignalDispatch);
|
|
20
20
|
/**
|
|
21
21
|
* Dispatches an action to update the state of the document.
|
|
22
22
|
* @param action - The action to dispatch.
|
|
@@ -41,60 +41,69 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
41
41
|
* @param reducer - The reducer function that updates the state.
|
|
42
42
|
* @returns The state of the document.
|
|
43
43
|
*/
|
|
44
|
-
protected static stateFromFile<T, A extends Action>(path: string, reducer: Reducer<T, A>): Promise<Document<T, A>>;
|
|
44
|
+
protected static stateFromFile<T, A extends Action, L>(path: string, reducer: Reducer<T, A, L>): Promise<Document<T, A, L>>;
|
|
45
45
|
/**
|
|
46
46
|
* Gets the current state of the document.
|
|
47
47
|
*/
|
|
48
|
-
get state():
|
|
48
|
+
get state(): {
|
|
49
|
+
readonly global: import("immer").Immutable<T>;
|
|
50
|
+
readonly local: import("immer").Immutable<L>;
|
|
51
|
+
};
|
|
49
52
|
/**
|
|
50
53
|
* Gets the list of operations performed on the document.
|
|
51
54
|
*/
|
|
52
|
-
get operations():
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
|
|
56
|
-
readonly
|
|
57
|
-
|
|
55
|
+
get operations(): {
|
|
56
|
+
readonly global: readonly ({
|
|
57
|
+
readonly input: {
|
|
58
|
+
readonly operations: number;
|
|
59
|
+
readonly state: {
|
|
60
|
+
readonly data?: unknown;
|
|
61
|
+
readonly name: string;
|
|
62
|
+
};
|
|
58
63
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
64
|
+
readonly type: "LOAD_STATE";
|
|
65
|
+
readonly scope: "global";
|
|
66
|
+
readonly index: number;
|
|
67
|
+
readonly timestamp: string;
|
|
68
|
+
readonly hash: string;
|
|
69
|
+
} | {
|
|
70
|
+
readonly input: {
|
|
71
|
+
readonly end?: import("./types").InputMaybe<number>;
|
|
72
|
+
readonly start?: import("./types").InputMaybe<number>;
|
|
73
|
+
};
|
|
74
|
+
readonly type: "PRUNE";
|
|
75
|
+
readonly scope: "global";
|
|
76
|
+
readonly index: number;
|
|
77
|
+
readonly timestamp: string;
|
|
78
|
+
readonly hash: string;
|
|
79
|
+
} | {
|
|
80
|
+
readonly input: number;
|
|
81
|
+
readonly type: "REDO";
|
|
82
|
+
readonly scope: "global";
|
|
83
|
+
readonly index: number;
|
|
84
|
+
readonly timestamp: string;
|
|
85
|
+
readonly hash: string;
|
|
86
|
+
} | {
|
|
87
|
+
readonly input: string;
|
|
88
|
+
readonly type: "SET_NAME";
|
|
89
|
+
readonly scope: "global";
|
|
90
|
+
readonly index: number;
|
|
91
|
+
readonly timestamp: string;
|
|
92
|
+
readonly hash: string;
|
|
93
|
+
} | {
|
|
94
|
+
readonly input: number;
|
|
95
|
+
readonly type: "UNDO";
|
|
96
|
+
readonly scope: "global";
|
|
97
|
+
readonly index: number;
|
|
98
|
+
readonly timestamp: string;
|
|
99
|
+
readonly hash: string;
|
|
100
|
+
} | import("immer").Immutable<A & {
|
|
101
|
+
index: number;
|
|
102
|
+
timestamp: string;
|
|
103
|
+
hash: string;
|
|
104
|
+
}>)[];
|
|
105
|
+
readonly local: readonly import("immer").Immutable<import("./types").Operation<A>>[];
|
|
106
|
+
};
|
|
98
107
|
/**
|
|
99
108
|
* Gets the name of the document.
|
|
100
109
|
*/
|
|
@@ -124,7 +133,10 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
124
133
|
readonly documentType: string;
|
|
125
134
|
readonly created: string;
|
|
126
135
|
readonly lastModified: string;
|
|
127
|
-
readonly state:
|
|
136
|
+
readonly state: {
|
|
137
|
+
readonly global: import("immer").Immutable<T>;
|
|
138
|
+
readonly local: import("immer").Immutable<L>;
|
|
139
|
+
};
|
|
128
140
|
readonly attachments: {
|
|
129
141
|
readonly [x: string]: {
|
|
130
142
|
readonly data: string;
|
|
@@ -143,7 +155,10 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
143
155
|
readonly documentType: string;
|
|
144
156
|
readonly created: string;
|
|
145
157
|
readonly lastModified: string;
|
|
146
|
-
readonly state:
|
|
158
|
+
readonly state: {
|
|
159
|
+
readonly global: import("immer").Immutable<T>;
|
|
160
|
+
readonly local: import("immer").Immutable<L>;
|
|
161
|
+
};
|
|
147
162
|
readonly attachments: {
|
|
148
163
|
readonly [x: string]: {
|
|
149
164
|
readonly data: string;
|
|
@@ -152,59 +167,68 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
152
167
|
readonly fileName?: string | null | undefined;
|
|
153
168
|
};
|
|
154
169
|
};
|
|
155
|
-
readonly operations:
|
|
156
|
-
readonly
|
|
157
|
-
readonly
|
|
158
|
-
|
|
159
|
-
readonly
|
|
160
|
-
|
|
170
|
+
readonly operations: {
|
|
171
|
+
readonly global: readonly ({
|
|
172
|
+
readonly input: {
|
|
173
|
+
readonly operations: number;
|
|
174
|
+
readonly state: {
|
|
175
|
+
readonly data?: unknown;
|
|
176
|
+
readonly name: string;
|
|
177
|
+
};
|
|
161
178
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
179
|
+
readonly type: "LOAD_STATE";
|
|
180
|
+
readonly scope: "global";
|
|
181
|
+
readonly index: number;
|
|
182
|
+
readonly timestamp: string;
|
|
183
|
+
readonly hash: string;
|
|
184
|
+
} | {
|
|
185
|
+
readonly input: {
|
|
186
|
+
readonly end?: import("./types").InputMaybe<number>;
|
|
187
|
+
readonly start?: import("./types").InputMaybe<number>;
|
|
188
|
+
};
|
|
189
|
+
readonly type: "PRUNE";
|
|
190
|
+
readonly scope: "global";
|
|
191
|
+
readonly index: number;
|
|
192
|
+
readonly timestamp: string;
|
|
193
|
+
readonly hash: string;
|
|
194
|
+
} | {
|
|
195
|
+
readonly input: number;
|
|
196
|
+
readonly type: "REDO";
|
|
197
|
+
readonly scope: "global";
|
|
198
|
+
readonly index: number;
|
|
199
|
+
readonly timestamp: string;
|
|
200
|
+
readonly hash: string;
|
|
201
|
+
} | {
|
|
202
|
+
readonly input: string;
|
|
203
|
+
readonly type: "SET_NAME";
|
|
204
|
+
readonly scope: "global";
|
|
205
|
+
readonly index: number;
|
|
206
|
+
readonly timestamp: string;
|
|
207
|
+
readonly hash: string;
|
|
208
|
+
} | {
|
|
209
|
+
readonly input: number;
|
|
210
|
+
readonly type: "UNDO";
|
|
211
|
+
readonly scope: "global";
|
|
212
|
+
readonly index: number;
|
|
213
|
+
readonly timestamp: string;
|
|
214
|
+
readonly hash: string;
|
|
215
|
+
} | import("immer").Immutable<A & {
|
|
216
|
+
index: number;
|
|
217
|
+
timestamp: string;
|
|
218
|
+
hash: string;
|
|
219
|
+
}>)[];
|
|
220
|
+
readonly local: readonly import("immer").Immutable<import("./types").Operation<A>>[];
|
|
221
|
+
};
|
|
201
222
|
readonly initialState: {
|
|
202
223
|
readonly name: string;
|
|
203
224
|
readonly revision: number;
|
|
204
225
|
readonly documentType: string;
|
|
205
226
|
readonly created: string;
|
|
206
227
|
readonly lastModified: string;
|
|
207
|
-
readonly state:
|
|
228
|
+
readonly state: {
|
|
229
|
+
readonly global: import("immer").Immutable<T>;
|
|
230
|
+
readonly local: import("immer").Immutable<L>;
|
|
231
|
+
};
|
|
208
232
|
readonly attachments: {
|
|
209
233
|
readonly [x: string]: {
|
|
210
234
|
readonly data: string;
|
|
@@ -246,7 +270,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
|
|
|
246
270
|
* @param state - The state to load.
|
|
247
271
|
* @param operations - The operations to apply to the document.
|
|
248
272
|
*/
|
|
249
|
-
loadState(state: Pick<ExtendedState<T>, 'state' | 'name'>, operations: number): this;
|
|
273
|
+
loadState(state: Pick<ExtendedState<T, L>, 'state' | 'name'>, operations: number): this;
|
|
250
274
|
}
|
|
251
275
|
/**
|
|
252
276
|
* Applies multiple mixins to a base class.
|
|
@@ -13,4 +13,4 @@ import { SignalDispatch } from './signal';
|
|
|
13
13
|
* specific to the document's state.
|
|
14
14
|
* @returns The new state of the document.
|
|
15
15
|
*/
|
|
16
|
-
export declare function baseReducer<T, A extends Action>(document: Document<T, A>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A>, dispatch?: SignalDispatch): Document<T, A>;
|
|
16
|
+
export declare function baseReducer<T, A extends Action, L>(document: Document<T, A, L>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch): Document<T, A, L>;
|
|
@@ -91,6 +91,7 @@ export type Load_State = 'LOAD_STATE';
|
|
|
91
91
|
export type LoadStateAction = {
|
|
92
92
|
input: LoadStateActionInput;
|
|
93
93
|
type: Load_State | `${Load_State}`;
|
|
94
|
+
scope: "global";
|
|
94
95
|
};
|
|
95
96
|
export type LoadStateActionInput = {
|
|
96
97
|
operations: Scalars['Int']['input'];
|
|
@@ -134,6 +135,7 @@ export type Prune = 'PRUNE';
|
|
|
134
135
|
export type PruneAction = {
|
|
135
136
|
input: PruneActionInput;
|
|
136
137
|
type: Prune | `${Prune}`;
|
|
138
|
+
scope: "global";
|
|
137
139
|
};
|
|
138
140
|
export type PruneActionInput = {
|
|
139
141
|
end?: InputMaybe<Scalars['Int']['input']>;
|
|
@@ -147,11 +149,13 @@ export type Redo = 'REDO';
|
|
|
147
149
|
export type RedoAction = {
|
|
148
150
|
input: Scalars['Int']['input'];
|
|
149
151
|
type: Redo | `${Redo}`;
|
|
152
|
+
scope: "global";
|
|
150
153
|
};
|
|
151
154
|
export type Set_Name = 'SET_NAME';
|
|
152
155
|
export type SetNameAction = {
|
|
153
156
|
input: Scalars['String']['input'];
|
|
154
157
|
type: Set_Name | `${Set_Name}`;
|
|
158
|
+
scope: "global";
|
|
155
159
|
};
|
|
156
160
|
export type SetNameOperation = IOperation & {
|
|
157
161
|
__typename?: 'SetNameOperation';
|
|
@@ -165,4 +169,5 @@ export type Undo = 'UNDO';
|
|
|
165
169
|
export type UndoAction = {
|
|
166
170
|
input: Scalars['Int']['input'];
|
|
167
171
|
type: Undo | `${Undo}`;
|
|
172
|
+
scope: "global";
|
|
168
173
|
};
|
|
@@ -15,48 +15,63 @@ export declare function ActionSchema(): z.ZodObject<Properties<Action>>;
|
|
|
15
15
|
export declare function BaseActionSchema(): z.ZodUnion<[z.ZodObject<Required<{
|
|
16
16
|
input: z.ZodType<LoadStateActionInput, any, LoadStateActionInput>;
|
|
17
17
|
type: z.ZodType<"LOAD_STATE", any, "LOAD_STATE">;
|
|
18
|
+
scope: z.ZodType<"global", any, "global">;
|
|
18
19
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
19
20
|
input: LoadStateActionInput;
|
|
20
21
|
type: "LOAD_STATE";
|
|
22
|
+
scope: "global";
|
|
21
23
|
}, {
|
|
22
24
|
input: LoadStateActionInput;
|
|
23
25
|
type: "LOAD_STATE";
|
|
26
|
+
scope: "global";
|
|
24
27
|
}>, z.ZodObject<Required<{
|
|
25
28
|
input: z.ZodType<PruneActionInput, any, PruneActionInput>;
|
|
26
29
|
type: z.ZodType<"PRUNE", any, "PRUNE">;
|
|
30
|
+
scope: z.ZodType<"global", any, "global">;
|
|
27
31
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
28
32
|
input: PruneActionInput;
|
|
29
33
|
type: "PRUNE";
|
|
34
|
+
scope: "global";
|
|
30
35
|
}, {
|
|
31
36
|
input: PruneActionInput;
|
|
32
37
|
type: "PRUNE";
|
|
38
|
+
scope: "global";
|
|
33
39
|
}>, z.ZodObject<Required<{
|
|
34
40
|
input: z.ZodType<number, any, number>;
|
|
35
41
|
type: z.ZodType<"REDO", any, "REDO">;
|
|
42
|
+
scope: z.ZodType<"global", any, "global">;
|
|
36
43
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
37
44
|
input: number;
|
|
38
45
|
type: "REDO";
|
|
46
|
+
scope: "global";
|
|
39
47
|
}, {
|
|
40
48
|
input: number;
|
|
41
49
|
type: "REDO";
|
|
50
|
+
scope: "global";
|
|
42
51
|
}>, z.ZodObject<Required<{
|
|
43
52
|
input: z.ZodType<string, any, string>;
|
|
44
53
|
type: z.ZodType<"SET_NAME", any, "SET_NAME">;
|
|
54
|
+
scope: z.ZodType<"global", any, "global">;
|
|
45
55
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
46
56
|
input: string;
|
|
47
57
|
type: "SET_NAME";
|
|
58
|
+
scope: "global";
|
|
48
59
|
}, {
|
|
49
60
|
input: string;
|
|
50
61
|
type: "SET_NAME";
|
|
62
|
+
scope: "global";
|
|
51
63
|
}>, z.ZodObject<Required<{
|
|
52
64
|
input: z.ZodType<number, any, number>;
|
|
53
65
|
type: z.ZodType<"UNDO", any, "UNDO">;
|
|
66
|
+
scope: z.ZodType<"global", any, "global">;
|
|
54
67
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
55
68
|
input: number;
|
|
56
69
|
type: "UNDO";
|
|
70
|
+
scope: "global";
|
|
57
71
|
}, {
|
|
58
72
|
input: number;
|
|
59
73
|
type: "UNDO";
|
|
74
|
+
scope: "global";
|
|
60
75
|
}>]>;
|
|
61
76
|
export declare function DocumentFileSchema(): z.ZodObject<Properties<DocumentFile>>;
|
|
62
77
|
export declare function LoadStateActionSchema(): z.ZodObject<Properties<LoadStateAction>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Document } from './types';
|
|
1
2
|
export interface ISignal<T extends string = string, I = unknown> {
|
|
2
3
|
type: T;
|
|
3
4
|
input: I;
|
|
@@ -12,10 +13,10 @@ export type DeleteChildDocumentInput = {
|
|
|
12
13
|
id: string;
|
|
13
14
|
};
|
|
14
15
|
export type DeleteChildDocumentSignal = ISignal<'DELETE_CHILD_DOCUMENT', DeleteChildDocumentInput>;
|
|
15
|
-
export type
|
|
16
|
+
export type CopyChildDocumentInput = {
|
|
16
17
|
id: string;
|
|
17
18
|
newId: string;
|
|
18
19
|
};
|
|
19
|
-
export type CopyChildDocumentSignal = ISignal<'COPY_CHILD_DOCUMENT',
|
|
20
|
+
export type CopyChildDocumentSignal = ISignal<'COPY_CHILD_DOCUMENT', CopyChildDocumentInput>;
|
|
20
21
|
export type Signal = CreateChildDocumentSignal | DeleteChildDocumentSignal | CopyChildDocumentSignal;
|
|
21
22
|
export type SignalDispatch = (signal: Signal) => void;
|
|
@@ -34,7 +34,7 @@ export type ActionWithAttachment<T extends string = string, I = unknown> = Actio
|
|
|
34
34
|
* @typeParam State - The type of the document data.
|
|
35
35
|
* @typeParam A - The type of the actions supported by the reducer.
|
|
36
36
|
*/
|
|
37
|
-
export type Reducer<State, A extends Action> = (state: Document<State, A>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A>;
|
|
37
|
+
export type Reducer<State, A extends Action, LocalState> = (state: Document<State, A, LocalState>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A, LocalState>;
|
|
38
38
|
/**
|
|
39
39
|
* A {@link Reducer} that prevents mutable code from changing the previous state.
|
|
40
40
|
*
|
|
@@ -47,8 +47,8 @@ export type Reducer<State, A extends Action> = (state: Document<State, A>, actio
|
|
|
47
47
|
* @typeParam State - The type of the document data.
|
|
48
48
|
* @typeParam A - The type of the actions supported by the reducer.
|
|
49
49
|
*/
|
|
50
|
-
export type ImmutableReducer<State, A extends Action> = (state: Draft<Document<State, A>>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A> | void;
|
|
51
|
-
export type ImmutableStateReducer<
|
|
50
|
+
export type ImmutableReducer<State, A extends Action, LocalState> = (state: Draft<Document<State, A, LocalState>>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A, LocalState> | void;
|
|
51
|
+
export type ImmutableStateReducer<S, A extends Action, L = unknown> = (state: Draft<State<S, L>>, action: A, dispatch?: SignalDispatch) => State<S, L> | void;
|
|
52
52
|
/**
|
|
53
53
|
* Scope of an operation.
|
|
54
54
|
* Global: The operation is synchronized everywhere in the network. This is the default document operation.
|
|
@@ -111,12 +111,21 @@ export type AttachmentInput = Attachment & {
|
|
|
111
111
|
*
|
|
112
112
|
*/
|
|
113
113
|
export type FileRegistry = Record<AttachmentRef, Attachment>;
|
|
114
|
-
export type
|
|
114
|
+
export type State<GlobalState, LocalState> = {
|
|
115
|
+
global: GlobalState;
|
|
116
|
+
local: LocalState;
|
|
117
|
+
};
|
|
118
|
+
export type CreateState<S, L> = (state?: Partial<State<Partial<S>, Partial<L>>>) => State<S, L>;
|
|
119
|
+
export type ExtendedState<GlobalState, LocalState = unknown> = DocumentHeader & {
|
|
115
120
|
/** The document model specific state. */
|
|
116
|
-
state: State
|
|
121
|
+
state: State<GlobalState, LocalState>;
|
|
117
122
|
/** The index of document attachments. */
|
|
118
123
|
attachments: FileRegistry;
|
|
119
124
|
};
|
|
125
|
+
export type DocumentOperations<A extends Action> = {
|
|
126
|
+
global: Operation<A | BaseAction>[];
|
|
127
|
+
local: Operation<A>[];
|
|
128
|
+
};
|
|
120
129
|
/**
|
|
121
130
|
* The base type of a document model.
|
|
122
131
|
*
|
|
@@ -126,13 +135,13 @@ export type ExtendedState<State = unknown> = DocumentHeader & {
|
|
|
126
135
|
* @typeParam Data - The type of the document data attribute.
|
|
127
136
|
* @typeParam A - The type of the actions supported by the Document.
|
|
128
137
|
*/
|
|
129
|
-
export type Document<
|
|
138
|
+
export type Document<GlobalState = unknown, A extends Action = Action, LocalState = unknown> =
|
|
130
139
|
/** The document model specific state. */
|
|
131
|
-
ExtendedState<
|
|
140
|
+
ExtendedState<GlobalState, LocalState> & {
|
|
132
141
|
/** The operations history of the document. */
|
|
133
|
-
operations:
|
|
142
|
+
operations: DocumentOperations<A>;
|
|
134
143
|
/** The initial state of the document, enabling replaying operations. */
|
|
135
|
-
initialState: ExtendedState<
|
|
144
|
+
initialState: ExtendedState<GlobalState, LocalState>;
|
|
136
145
|
};
|
|
137
146
|
/**
|
|
138
147
|
* String type representing an attachment in a Document.
|
|
@@ -141,40 +150,40 @@ ExtendedState<S> & {
|
|
|
141
150
|
* Attachment string is formatted as `attachment://<filename>`.
|
|
142
151
|
*/
|
|
143
152
|
export type AttachmentRef = string;
|
|
144
|
-
export interface DocumentClass<S, A extends Action = Action, C extends BaseDocument<S, A> = BaseDocument<S, A>> {
|
|
153
|
+
export interface DocumentClass<S, A extends Action = Action, L = unknown, C extends BaseDocument<S, A, L> = BaseDocument<S, A, L>> {
|
|
145
154
|
fileExtension: string;
|
|
146
155
|
fromFile: (path: string) => Promise<C>;
|
|
147
|
-
new (initialState?: ExtendedState<S>): C;
|
|
156
|
+
new (initialState?: ExtendedState<S, L>): C;
|
|
148
157
|
}
|
|
149
|
-
export type DocumentModelUtils<S = unknown, A extends Action = Action> = {
|
|
158
|
+
export type DocumentModelUtils<S = unknown, A extends Action = Action, L = unknown> = {
|
|
150
159
|
fileExtension: string;
|
|
151
|
-
createState:
|
|
152
|
-
createExtendedState: (extendedState?: Partial<ExtendedState<Partial<S>>>, createState?:
|
|
153
|
-
createDocument: (document?: Partial<ExtendedState<Partial<S>>>, createState?:
|
|
154
|
-
loadFromFile: (path: string) => Promise<Document<S, A>>;
|
|
155
|
-
loadFromInput: (input: FileInput) => Promise<Document<S, A>>;
|
|
156
|
-
saveToFile: (document: Document<S, A>, path: string, name?: string) => Promise<string>;
|
|
157
|
-
saveToFileHandle: (document: Document<S, A>, input: FileSystemFileHandle) => Promise<void>;
|
|
160
|
+
createState: CreateState<S, L>;
|
|
161
|
+
createExtendedState: (extendedState?: Partial<ExtendedState<Partial<S>, Partial<L>>>, createState?: CreateState<S, L>) => ExtendedState<S, L>;
|
|
162
|
+
createDocument: (document?: Partial<ExtendedState<Partial<S>, Partial<L>>>, createState?: CreateState<S, L>) => Document<S, A, L>;
|
|
163
|
+
loadFromFile: (path: string) => Promise<Document<S, A, L>>;
|
|
164
|
+
loadFromInput: (input: FileInput) => Promise<Document<S, A, L>>;
|
|
165
|
+
saveToFile: (document: Document<S, A, L>, path: string, name?: string) => Promise<string>;
|
|
166
|
+
saveToFileHandle: (document: Document<S, A, L>, input: FileSystemFileHandle) => Promise<void>;
|
|
158
167
|
};
|
|
159
168
|
export type ActionCreator<A extends Action> = ((input: any) => A) | ((input: any, attachments: AttachmentInput[]) => A) | ((...input: any) => BaseAction);
|
|
160
|
-
export type DocumentModel<S = unknown, A extends Action = Action, C extends BaseDocument<S, A> = BaseDocument<S, A>> = {
|
|
161
|
-
Document: DocumentClass<S, A, C>;
|
|
162
|
-
reducer: Reducer<S, A>;
|
|
169
|
+
export type DocumentModel<S = unknown, A extends Action = Action, L = unknown, C extends BaseDocument<S, A, L> = BaseDocument<S, A, L>> = {
|
|
170
|
+
Document: DocumentClass<S, A, L, C>;
|
|
171
|
+
reducer: Reducer<S, A, L>;
|
|
163
172
|
actions: Record<string, ActionCreator<A>>;
|
|
164
|
-
utils: DocumentModelUtils<S, A>;
|
|
173
|
+
utils: DocumentModelUtils<S, A, L>;
|
|
165
174
|
documentModel: DocumentModelState;
|
|
166
175
|
};
|
|
167
176
|
export type EditorContext = {
|
|
168
177
|
theme: 'light' | 'dark';
|
|
169
178
|
debug?: boolean;
|
|
170
179
|
};
|
|
171
|
-
export type EditorProps<S, A extends Action> = {
|
|
172
|
-
document: Document<S, A>;
|
|
180
|
+
export type EditorProps<S, A extends Action, L> = {
|
|
181
|
+
document: Document<S, A, L>;
|
|
173
182
|
dispatch: (action: A | BaseAction) => void;
|
|
174
183
|
editorContext: EditorContext;
|
|
175
184
|
};
|
|
176
|
-
export type Editor<S = unknown, A extends Action = Action> = {
|
|
177
|
-
Component: FC<EditorProps<S, A>>;
|
|
185
|
+
export type Editor<S = unknown, A extends Action = Action, L = unknown> = {
|
|
186
|
+
Component: FC<EditorProps<S, A, L>>;
|
|
178
187
|
documentTypes: string[];
|
|
179
188
|
};
|
|
180
189
|
export type DocumentModelLib = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { baseReducer } from '../reducer';
|
|
2
|
-
import { Action, BaseAction, Document, ExtendedState, ImmutableStateReducer, Reducer, Immutable, OperationScope } from '../types';
|
|
2
|
+
import { Action, BaseAction, Document, ExtendedState, ImmutableStateReducer, Reducer, Immutable, OperationScope, State, CreateState } from '../types';
|
|
3
3
|
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
4
4
|
/**
|
|
5
5
|
* Helper function to be used by action creators.
|
|
@@ -38,8 +38,8 @@ export declare function createAction<A extends Action>(type: A['type'], input?:
|
|
|
38
38
|
*
|
|
39
39
|
* @returns The new reducer.
|
|
40
40
|
*/
|
|
41
|
-
export declare function createReducer<S = unknown, A extends Action = Action>(reducer: ImmutableStateReducer<S, A>, documentReducer?: typeof baseReducer): Reducer<S, A>;
|
|
42
|
-
export declare const createExtendedState: <S>(initialState?: Partial<ExtendedState<Partial<S>>> | undefined, createState?:
|
|
41
|
+
export declare function createReducer<S = unknown, A extends Action = Action, L = unknown>(reducer: ImmutableStateReducer<S, A, L>, documentReducer?: typeof baseReducer): Reducer<S, A, L>;
|
|
42
|
+
export declare const createExtendedState: <S, L>(initialState?: Partial<ExtendedState<Partial<S>, Partial<L>>> | undefined, createState?: CreateState<S, L> | undefined) => ExtendedState<S, L>;
|
|
43
43
|
/**
|
|
44
44
|
* Builds the initial document state from the provided data.
|
|
45
45
|
*
|
|
@@ -51,7 +51,7 @@ export declare const createExtendedState: <S>(initialState?: Partial<ExtendedSta
|
|
|
51
51
|
*
|
|
52
52
|
* @returns The new document state.
|
|
53
53
|
*/
|
|
54
|
-
export declare const createDocument: <S, A extends Action>(initialState?: Partial<ExtendedState<Partial<S>>> | undefined, createState?: ((state?: Partial<S
|
|
55
|
-
export declare const hashDocument: (document: Document) => string;
|
|
54
|
+
export declare const createDocument: <S, A extends Action, L = unknown>(initialState?: Partial<ExtendedState<Partial<S>, Partial<L>>> | undefined, createState?: ((state?: Partial<State<Partial<S>, Partial<L>>> | undefined) => State<S, L>) | undefined) => Document<S, A, L>;
|
|
55
|
+
export declare const hashDocument: (document: Document, scope?: OperationScope) => string;
|
|
56
56
|
export declare const hashKey: (date?: Date, randomLimit?: number) => string;
|
|
57
57
|
export declare function readOnly<T>(value: T): Immutable<T>;
|
|
@@ -31,8 +31,8 @@ export declare const saveToFileHandle: (document: Document, input: FileSystemFil
|
|
|
31
31
|
* @returns A promise that resolves to the document state after applying all the operations.
|
|
32
32
|
* @throws An error if the initial state or the operations history is not found in the ZIP file.
|
|
33
33
|
*/
|
|
34
|
-
export declare const loadFromFile: <S, A extends Action>(path: string, reducer: Reducer<S, A>) => Promise<Document<S, A>>;
|
|
35
|
-
export declare const loadFromInput: <S, A extends Action>(input: FileInput, reducer: Reducer<S, A>) => Promise<Document<S, A>>;
|
|
34
|
+
export declare const loadFromFile: <S, A extends Action, L>(path: string, reducer: Reducer<S, A, L>) => Promise<Document<S, A, L>>;
|
|
35
|
+
export declare const loadFromInput: <S, A extends Action, L>(input: FileInput, reducer: Reducer<S, A, L>) => Promise<Document<S, A, L>>;
|
|
36
36
|
/**
|
|
37
37
|
* Fetches an attachment from a URL and returns its base64-encoded data and MIME type.
|
|
38
38
|
* @param url - The URL of the attachment to fetch.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DocumentModelState } from './schema';
|
|
2
2
|
import { DocumentModelAction } from './actions';
|
|
3
|
-
export declare const reducer: import("../../document/types").Reducer<DocumentModelState, DocumentModelAction>;
|
|
3
|
+
export declare const reducer: import("../../document/types").Reducer<DocumentModelState, DocumentModelAction, unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OperationScope } from
|
|
1
|
+
import { OperationScope } from '../../../document';
|
|
2
2
|
export type Maybe<T> = T | null;
|
|
3
3
|
export type InputMaybe<T> = T | null | undefined;
|
|
4
4
|
export type Exact<T extends {
|
|
@@ -126,7 +126,10 @@ export type DocumentSpecification = {
|
|
|
126
126
|
__typename?: 'DocumentSpecification';
|
|
127
127
|
changeLog: Array<Scalars['String']['output']>;
|
|
128
128
|
modules: Array<Module>;
|
|
129
|
-
state:
|
|
129
|
+
state: {
|
|
130
|
+
global: State;
|
|
131
|
+
local: State;
|
|
132
|
+
};
|
|
130
133
|
version: Scalars['Int']['output'];
|
|
131
134
|
};
|
|
132
135
|
export type Module = {
|