document-model 1.0.51 → 1.0.53
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/cjs/document-model.js +1 -1
- package/dist/browser/cjs/document.js +1 -1
- package/dist/browser/cjs/index.js +1 -1
- package/dist/{node/cjs/internal/index-CRjFLQNR.js → browser/cjs/internal/index-BAk-LH-1.js} +1 -1
- package/dist/browser/cjs/internal/{index-CPJM383s.js → index-Cb6Xq42D.js} +1 -1
- package/dist/browser/cjs/internal/object-D1n8rS0m.js +25 -0
- package/dist/browser/es/document-model.js +2 -2
- package/dist/browser/es/document.js +2 -2
- package/dist/browser/es/index.js +3 -3
- package/dist/browser/es/internal/{index-BzIVYv7p.js → index-DeOZH3b_.js} +1 -1
- package/dist/browser/es/internal/{index-tEH7iGUj.js → index-DwxnEmzI.js} +1 -1
- package/dist/browser/es/internal/{object-Dev4WFVH.js → object-DsqsdDFj.js} +767 -771
- package/dist/browser/src/document/object.d.ts +35 -0
- package/dist/browser/src/document/types.d.ts +2 -0
- package/dist/node/cjs/document-model.js +1 -1
- package/dist/node/cjs/document.js +1 -1
- package/dist/node/cjs/index.js +1 -1
- package/dist/{browser/cjs/internal/index-REU04m7f.js → node/cjs/internal/index-CpjKrifV.js} +1 -1
- package/dist/node/cjs/internal/{index-BX95XaQ_.js → index-DzXcygIJ.js} +1 -1
- package/dist/node/cjs/internal/object-Cx_c54j_.js +20 -0
- package/dist/node/es/document-model.js +2 -2
- package/dist/node/es/document.js +2 -2
- package/dist/node/es/index.js +3 -3
- package/dist/node/es/internal/{index-BzNCX_-9.js → index-CUitPgxf.js} +1 -1
- package/dist/node/es/internal/{index-DpH4_29z.js → index-V-nmqbyU.js} +1 -1
- package/dist/node/es/internal/{object-BFkXGmt6.js → object-C0WcyLCx.js} +500 -504
- package/dist/node/src/document/object.d.ts +35 -0
- package/dist/node/src/document/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/browser/cjs/internal/object-DkoS83BB.js +0 -25
- package/dist/node/cjs/internal/object-CGt7Qacd.js +0 -20
- package/dist/src/document/actions/creators.d.ts +0 -47
- package/dist/src/document/actions/index.d.ts +0 -14
- package/dist/src/document/actions/types.d.ts +0 -15
- package/dist/src/document/index.d.ts +0 -6
- package/dist/src/document/object.d.ts +0 -1140
- package/dist/src/document/reducer.d.ts +0 -32
- package/dist/src/document/schema/index.d.ts +0 -2
- package/dist/src/document/schema/types.d.ts +0 -176
- package/dist/src/document/schema/zod.d.ts +0 -113
- package/dist/src/document/signal.d.ts +0 -29
- package/dist/src/document/types.d.ts +0 -247
- package/dist/src/document/utils/base.d.ts +0 -85
- package/dist/src/document/utils/file.d.ts +0 -48
- package/dist/src/document/utils/index.d.ts +0 -4
- package/dist/src/document/utils/node.d.ts +0 -9
- package/dist/src/document/utils/validation.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/header.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/module.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/operation-error.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/operation-example.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/operation.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/state.d.ts +0 -2
- package/dist/src/document-model/custom/reducers/versioning.d.ts +0 -7
- package/dist/src/document-model/custom/utils.d.ts +0 -7
- package/dist/src/document-model/gen/actions.d.ts +0 -15
- package/dist/src/document-model/gen/creators.d.ts +0 -7
- package/dist/src/document-model/gen/document-model.d.ts +0 -2
- package/dist/src/document-model/gen/header/actions.d.ts +0 -9
- package/dist/src/document-model/gen/header/creators.d.ts +0 -8
- package/dist/src/document-model/gen/header/object.d.ts +0 -12
- package/dist/src/document-model/gen/header/operations.d.ts +0 -10
- package/dist/src/document-model/gen/index.d.ts +0 -5
- package/dist/src/document-model/gen/module/actions.d.ts +0 -8
- package/dist/src/document-model/gen/module/creators.d.ts +0 -7
- package/dist/src/document-model/gen/module/object.d.ts +0 -11
- package/dist/src/document-model/gen/module/operations.d.ts +0 -9
- package/dist/src/document-model/gen/object.d.ts +0 -28
- package/dist/src/document-model/gen/operation/actions.d.ts +0 -13
- package/dist/src/document-model/gen/operation/creators.d.ts +0 -12
- package/dist/src/document-model/gen/operation/object.d.ts +0 -16
- package/dist/src/document-model/gen/operation/operations.d.ts +0 -14
- package/dist/src/document-model/gen/operation-error/actions.d.ts +0 -10
- package/dist/src/document-model/gen/operation-error/creators.d.ts +0 -9
- package/dist/src/document-model/gen/operation-error/object.d.ts +0 -13
- package/dist/src/document-model/gen/operation-error/operations.d.ts +0 -11
- package/dist/src/document-model/gen/operation-example/actions.d.ts +0 -7
- package/dist/src/document-model/gen/operation-example/creators.d.ts +0 -6
- package/dist/src/document-model/gen/operation-example/object.d.ts +0 -10
- package/dist/src/document-model/gen/operation-example/operations.d.ts +0 -8
- package/dist/src/document-model/gen/reducer.d.ts +0 -5
- package/dist/src/document-model/gen/schema/index.d.ts +0 -2
- package/dist/src/document-model/gen/schema/types.d.ts +0 -453
- package/dist/src/document-model/gen/schema/zod.d.ts +0 -453
- package/dist/src/document-model/gen/state/actions.d.ts +0 -9
- package/dist/src/document-model/gen/state/creators.d.ts +0 -8
- package/dist/src/document-model/gen/state/object.d.ts +0 -12
- package/dist/src/document-model/gen/state/operations.d.ts +0 -10
- package/dist/src/document-model/gen/types.d.ts +0 -8
- package/dist/src/document-model/gen/utils.d.ts +0 -6
- package/dist/src/document-model/gen/versioning/actions.d.ts +0 -8
- package/dist/src/document-model/gen/versioning/creators.d.ts +0 -7
- package/dist/src/document-model/gen/versioning/object.d.ts +0 -11
- package/dist/src/document-model/gen/versioning/operations.d.ts +0 -9
- package/dist/src/document-model/index.d.ts +0 -80
- package/dist/src/index.d.ts +0 -25
- package/dist/vite.config.d.ts +0 -2
- package/dist/vitest.config.d.ts +0 -2
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { BaseAction } from './actions/types';
|
|
2
|
-
import { UndoRedoAction } from './schema';
|
|
3
|
-
import { Action, Document, ImmutableStateReducer, Operation, ReducerOptions } from './types';
|
|
4
|
-
import { SignalDispatch } from './signal';
|
|
5
|
-
type UndoRedoProcessResult<T, A extends Action, L> = {
|
|
6
|
-
document: Document<T, A, L>;
|
|
7
|
-
action: A | BaseAction;
|
|
8
|
-
skip: number;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Processes an UNDO or REDO action.
|
|
12
|
-
*
|
|
13
|
-
* @param document The current state of the document.
|
|
14
|
-
* @param action The action being applied to the document.
|
|
15
|
-
* @param skip The number of operations to skip before applying the action.
|
|
16
|
-
* @returns The updated document, calculated skip value and transformed action (if apply).
|
|
17
|
-
*/
|
|
18
|
-
export declare function processUndoRedo<T, A extends Action, L>(document: Document<T, A, L>, action: UndoRedoAction, skip: number): UndoRedoProcessResult<T, A, L>;
|
|
19
|
-
/**
|
|
20
|
-
* Base document reducer that wraps a custom document reducer and handles
|
|
21
|
-
* document-level actions such as undo, redo, prune, and set name.
|
|
22
|
-
*
|
|
23
|
-
* @template T - The type of the state of the custom reducer.
|
|
24
|
-
* @template A - The type of the actions of the custom reducer.
|
|
25
|
-
* @param state - The current state of the document.
|
|
26
|
-
* @param action - The action object to apply to the state.
|
|
27
|
-
* @param customReducer - The custom reducer that implements the application logic
|
|
28
|
-
* specific to the document's state.
|
|
29
|
-
* @returns The new state of the document.
|
|
30
|
-
*/
|
|
31
|
-
export declare function baseReducer<T, A extends Action, L>(document: Document<T, A, L>, action: A | BaseAction | Operation, customReducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, options?: ReducerOptions): Document<T, A, L>;
|
|
32
|
-
export {};
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { OperationScope } from '..';
|
|
2
|
-
export type Maybe<T> = T | null;
|
|
3
|
-
export type InputMaybe<T> = T | null | undefined;
|
|
4
|
-
export type Exact<T extends Record<string, unknown>> = {
|
|
5
|
-
[K in keyof T]: T[K];
|
|
6
|
-
};
|
|
7
|
-
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
8
|
-
[SubKey in K]?: Maybe<T[SubKey]>;
|
|
9
|
-
};
|
|
10
|
-
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
11
|
-
[SubKey in K]: Maybe<T[SubKey]>;
|
|
12
|
-
};
|
|
13
|
-
export type MakeEmpty<T extends Record<string, unknown>, K extends keyof T> = {
|
|
14
|
-
[_ in K]?: never;
|
|
15
|
-
};
|
|
16
|
-
export type Incremental<T> = T | {
|
|
17
|
-
[P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never;
|
|
18
|
-
};
|
|
19
|
-
/** All built-in and custom scalars, mapped to their actual values */
|
|
20
|
-
export type Scalars = {
|
|
21
|
-
ID: {
|
|
22
|
-
input: string;
|
|
23
|
-
output: string;
|
|
24
|
-
};
|
|
25
|
-
String: {
|
|
26
|
-
input: string;
|
|
27
|
-
output: string;
|
|
28
|
-
};
|
|
29
|
-
Boolean: {
|
|
30
|
-
input: boolean;
|
|
31
|
-
output: boolean;
|
|
32
|
-
};
|
|
33
|
-
Int: {
|
|
34
|
-
input: number;
|
|
35
|
-
output: number;
|
|
36
|
-
};
|
|
37
|
-
Float: {
|
|
38
|
-
input: number;
|
|
39
|
-
output: number;
|
|
40
|
-
};
|
|
41
|
-
Address: {
|
|
42
|
-
input: `${string}:0x${string}`;
|
|
43
|
-
output: `${string}:0x${string}`;
|
|
44
|
-
};
|
|
45
|
-
Attachment: {
|
|
46
|
-
input: string;
|
|
47
|
-
output: string;
|
|
48
|
-
};
|
|
49
|
-
DateTime: {
|
|
50
|
-
input: string;
|
|
51
|
-
output: string;
|
|
52
|
-
};
|
|
53
|
-
Unknown: {
|
|
54
|
-
input: unknown;
|
|
55
|
-
output: unknown;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
export type Action = IAction & {
|
|
59
|
-
__typename?: 'Action';
|
|
60
|
-
type: Scalars['String']['output'];
|
|
61
|
-
};
|
|
62
|
-
export type UndoRedoAction = RedoAction | UndoAction;
|
|
63
|
-
export type DocumentFile = {
|
|
64
|
-
__typename?: 'DocumentFile';
|
|
65
|
-
data: Scalars['String']['output'];
|
|
66
|
-
extension: Maybe<Scalars['String']['output']>;
|
|
67
|
-
fileName: Maybe<Scalars['String']['output']>;
|
|
68
|
-
mimeType: Scalars['String']['output'];
|
|
69
|
-
};
|
|
70
|
-
export type IAction = {
|
|
71
|
-
type: Scalars['String']['output'];
|
|
72
|
-
};
|
|
73
|
-
export type IDocument = {
|
|
74
|
-
created: Scalars['DateTime']['output'];
|
|
75
|
-
documentType: Scalars['String']['output'];
|
|
76
|
-
lastModified: Scalars['DateTime']['output'];
|
|
77
|
-
name: Scalars['String']['output'];
|
|
78
|
-
operations: Array<IOperation>;
|
|
79
|
-
revision: Scalars['Int']['output'];
|
|
80
|
-
};
|
|
81
|
-
export type IOperation = {
|
|
82
|
-
hash: Scalars['String']['output'];
|
|
83
|
-
index: Scalars['Int']['output'];
|
|
84
|
-
timestamp: Scalars['DateTime']['output'];
|
|
85
|
-
type: Scalars['String']['output'];
|
|
86
|
-
};
|
|
87
|
-
export type Load_State = 'LOAD_STATE';
|
|
88
|
-
export type LoadStateAction = {
|
|
89
|
-
input: LoadStateActionInput;
|
|
90
|
-
type: Load_State;
|
|
91
|
-
scope: OperationScope;
|
|
92
|
-
};
|
|
93
|
-
export type LoadStateActionInput = {
|
|
94
|
-
operations: Scalars['Int']['input'];
|
|
95
|
-
state: LoadStateActionStateInput;
|
|
96
|
-
};
|
|
97
|
-
export type LoadStateActionStateInput = {
|
|
98
|
-
data?: InputMaybe<Scalars['Unknown']['input']>;
|
|
99
|
-
name: Scalars['String']['input'];
|
|
100
|
-
};
|
|
101
|
-
export type Mutation = {
|
|
102
|
-
__typename?: 'Mutation';
|
|
103
|
-
loadState: Maybe<IDocument>;
|
|
104
|
-
prune: Maybe<IDocument>;
|
|
105
|
-
redo: Maybe<IDocument>;
|
|
106
|
-
setName: Maybe<IDocument>;
|
|
107
|
-
undo: Maybe<IDocument>;
|
|
108
|
-
};
|
|
109
|
-
export type MutationLoadStateArgs = {
|
|
110
|
-
input: LoadStateAction;
|
|
111
|
-
};
|
|
112
|
-
export type MutationPruneArgs = {
|
|
113
|
-
input: PruneAction;
|
|
114
|
-
};
|
|
115
|
-
export type MutationRedoArgs = {
|
|
116
|
-
input: RedoAction;
|
|
117
|
-
};
|
|
118
|
-
export type MutationSetNameArgs = {
|
|
119
|
-
input: SetNameAction;
|
|
120
|
-
};
|
|
121
|
-
export type MutationUndoArgs = {
|
|
122
|
-
input: UndoAction;
|
|
123
|
-
};
|
|
124
|
-
export type Operation = IOperation & {
|
|
125
|
-
__typename?: 'Operation';
|
|
126
|
-
hash: Scalars['String']['output'];
|
|
127
|
-
index: Scalars['Int']['output'];
|
|
128
|
-
timestamp: Scalars['DateTime']['output'];
|
|
129
|
-
type: Scalars['String']['output'];
|
|
130
|
-
};
|
|
131
|
-
export type Prune = 'PRUNE';
|
|
132
|
-
export type PruneAction = {
|
|
133
|
-
input: PruneActionInput;
|
|
134
|
-
type: Prune;
|
|
135
|
-
scope: OperationScope;
|
|
136
|
-
};
|
|
137
|
-
export type PruneActionInput = {
|
|
138
|
-
end?: InputMaybe<Scalars['Int']['input']>;
|
|
139
|
-
start?: InputMaybe<Scalars['Int']['input']>;
|
|
140
|
-
};
|
|
141
|
-
export type Query = {
|
|
142
|
-
__typename?: 'Query';
|
|
143
|
-
document: Maybe<IDocument>;
|
|
144
|
-
};
|
|
145
|
-
export type Redo = 'REDO';
|
|
146
|
-
export type RedoAction = {
|
|
147
|
-
input: Scalars['Int']['input'];
|
|
148
|
-
type: Redo;
|
|
149
|
-
scope: OperationScope;
|
|
150
|
-
};
|
|
151
|
-
export type Set_Name = 'SET_NAME';
|
|
152
|
-
export type SetNameAction = {
|
|
153
|
-
input: Scalars['String']['input'];
|
|
154
|
-
type: Set_Name;
|
|
155
|
-
scope: 'global';
|
|
156
|
-
};
|
|
157
|
-
export type SetNameOperation = IOperation & {
|
|
158
|
-
__typename?: 'SetNameOperation';
|
|
159
|
-
hash: Scalars['String']['output'];
|
|
160
|
-
index: Scalars['Int']['output'];
|
|
161
|
-
input: Scalars['String']['output'];
|
|
162
|
-
timestamp: Scalars['DateTime']['output'];
|
|
163
|
-
type: Scalars['String']['output'];
|
|
164
|
-
};
|
|
165
|
-
export type Undo = 'UNDO';
|
|
166
|
-
export type UndoAction = {
|
|
167
|
-
input: Scalars['Int']['input'];
|
|
168
|
-
type: Undo;
|
|
169
|
-
scope: OperationScope;
|
|
170
|
-
};
|
|
171
|
-
export type NOOP = 'NOOP';
|
|
172
|
-
export type NOOPAction = {
|
|
173
|
-
input: Scalars['Unknown']['input'];
|
|
174
|
-
type: NOOP;
|
|
175
|
-
scope: OperationScope;
|
|
176
|
-
};
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Action, DocumentFile, LoadStateAction, LoadStateActionInput, LoadStateActionStateInput, Operation, PruneAction, PruneActionInput, RedoAction, SetNameAction, SetNameOperation, UndoAction } from '.';
|
|
3
|
-
import { OperationScope } from '../types';
|
|
4
|
-
type Properties<T> = Required<{
|
|
5
|
-
[K in keyof T]: z.ZodType<T[K], any, T[K]>;
|
|
6
|
-
}>;
|
|
7
|
-
type definedNonNullAny = {};
|
|
8
|
-
export declare const isDefinedNonNullAny: (v: any) => v is definedNonNullAny;
|
|
9
|
-
export declare const definedNonNullAnySchema: z.ZodEffects<z.ZodAny, any, any>;
|
|
10
|
-
export declare const Load_StateSchema: z.ZodEnum<["LOAD_STATE"]>;
|
|
11
|
-
export declare const PruneSchema: z.ZodEnum<["PRUNE"]>;
|
|
12
|
-
export declare const RedoSchema: z.ZodEnum<["REDO"]>;
|
|
13
|
-
export declare const Set_NameSchema: z.ZodEnum<["SET_NAME"]>;
|
|
14
|
-
export declare const UndoSchema: z.ZodEnum<["UNDO"]>;
|
|
15
|
-
export declare function ActionSchema(): z.ZodObject<Properties<Action>>;
|
|
16
|
-
export declare function OperationScopeSchema(): z.ZodType<OperationScope>;
|
|
17
|
-
export declare function BaseActionSchema(): z.ZodUnion<[z.ZodObject<Required<{
|
|
18
|
-
input: z.ZodType<LoadStateActionInput, any, LoadStateActionInput>;
|
|
19
|
-
type: z.ZodType<"LOAD_STATE", any, "LOAD_STATE">;
|
|
20
|
-
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
21
|
-
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
22
|
-
input: LoadStateActionInput;
|
|
23
|
-
type: "LOAD_STATE";
|
|
24
|
-
scope: "global" | "local";
|
|
25
|
-
}, {
|
|
26
|
-
input: LoadStateActionInput;
|
|
27
|
-
type: "LOAD_STATE";
|
|
28
|
-
scope: "global" | "local";
|
|
29
|
-
}>, z.ZodObject<Required<{
|
|
30
|
-
input: z.ZodType<PruneActionInput, any, PruneActionInput>;
|
|
31
|
-
type: z.ZodType<"PRUNE", any, "PRUNE">;
|
|
32
|
-
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
33
|
-
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
34
|
-
input: PruneActionInput;
|
|
35
|
-
type: "PRUNE";
|
|
36
|
-
scope: "global" | "local";
|
|
37
|
-
}, {
|
|
38
|
-
input: PruneActionInput;
|
|
39
|
-
type: "PRUNE";
|
|
40
|
-
scope: "global" | "local";
|
|
41
|
-
}>, z.ZodObject<Required<{
|
|
42
|
-
input: z.ZodType<number, any, number>;
|
|
43
|
-
type: z.ZodType<"REDO", any, "REDO">;
|
|
44
|
-
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
45
|
-
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
46
|
-
input: number;
|
|
47
|
-
type: "REDO";
|
|
48
|
-
scope: "global" | "local";
|
|
49
|
-
}, {
|
|
50
|
-
input: number;
|
|
51
|
-
type: "REDO";
|
|
52
|
-
scope: "global" | "local";
|
|
53
|
-
}>, z.ZodObject<Required<{
|
|
54
|
-
input: z.ZodType<string, any, string>;
|
|
55
|
-
type: z.ZodType<"SET_NAME", any, "SET_NAME">;
|
|
56
|
-
scope: z.ZodType<"global", any, "global">;
|
|
57
|
-
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
58
|
-
input: string;
|
|
59
|
-
type: "SET_NAME";
|
|
60
|
-
scope: "global";
|
|
61
|
-
}, {
|
|
62
|
-
input: string;
|
|
63
|
-
type: "SET_NAME";
|
|
64
|
-
scope: "global";
|
|
65
|
-
}>, z.ZodObject<Required<{
|
|
66
|
-
input: z.ZodType<number, any, number>;
|
|
67
|
-
type: z.ZodType<"UNDO", any, "UNDO">;
|
|
68
|
-
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
69
|
-
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
70
|
-
input: number;
|
|
71
|
-
type: "UNDO";
|
|
72
|
-
scope: "global" | "local";
|
|
73
|
-
}, {
|
|
74
|
-
input: number;
|
|
75
|
-
type: "UNDO";
|
|
76
|
-
scope: "global" | "local";
|
|
77
|
-
}>]>;
|
|
78
|
-
export declare function DocumentFileSchema(): z.ZodObject<Properties<DocumentFile>>;
|
|
79
|
-
export declare function LoadStateActionSchema(): z.ZodObject<Properties<LoadStateAction>>;
|
|
80
|
-
export declare function LoadStateActionInputSchema(): z.ZodObject<Properties<LoadStateActionInput>>;
|
|
81
|
-
export declare function LoadStateActionStateInputSchema(): z.ZodObject<Properties<LoadStateActionStateInput>>;
|
|
82
|
-
export declare function OperationSchema(): z.ZodObject<Properties<Operation>>;
|
|
83
|
-
export declare function PruneActionSchema(): z.ZodObject<Properties<PruneAction>>;
|
|
84
|
-
export declare function PruneActionInputSchema(): z.ZodObject<Properties<PruneActionInput>>;
|
|
85
|
-
export declare const RedoActionInputSchema: (params?: ({
|
|
86
|
-
errorMap?: z.ZodErrorMap | undefined;
|
|
87
|
-
invalid_type_error?: string | undefined;
|
|
88
|
-
required_error?: string | undefined;
|
|
89
|
-
description?: string | undefined;
|
|
90
|
-
} & {
|
|
91
|
-
coerce?: boolean | undefined;
|
|
92
|
-
}) | undefined) => z.ZodNumber;
|
|
93
|
-
export declare function RedoActionSchema(): z.ZodObject<Properties<RedoAction>>;
|
|
94
|
-
export declare const SetNameActionInputSchema: (params?: ({
|
|
95
|
-
errorMap?: z.ZodErrorMap | undefined;
|
|
96
|
-
invalid_type_error?: string | undefined;
|
|
97
|
-
required_error?: string | undefined;
|
|
98
|
-
description?: string | undefined;
|
|
99
|
-
} & {
|
|
100
|
-
coerce?: true | undefined;
|
|
101
|
-
}) | undefined) => z.ZodString;
|
|
102
|
-
export declare function SetNameActionSchema(): z.ZodObject<Properties<SetNameAction>>;
|
|
103
|
-
export declare function SetNameOperationSchema(): z.ZodObject<Properties<SetNameOperation>>;
|
|
104
|
-
export declare const UndoActionInputSchema: (params?: ({
|
|
105
|
-
errorMap?: z.ZodErrorMap | undefined;
|
|
106
|
-
invalid_type_error?: string | undefined;
|
|
107
|
-
required_error?: string | undefined;
|
|
108
|
-
description?: string | undefined;
|
|
109
|
-
} & {
|
|
110
|
-
coerce?: boolean | undefined;
|
|
111
|
-
}) | undefined) => z.ZodNumber;
|
|
112
|
-
export declare function UndoActionSchema(): z.ZodObject<Properties<UndoAction>>;
|
|
113
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Document, OperationScope } from './types';
|
|
2
|
-
export interface ISignal<T extends string = string, I = unknown> {
|
|
3
|
-
type: T;
|
|
4
|
-
input: I;
|
|
5
|
-
}
|
|
6
|
-
export type SynchronizationUnit = {
|
|
7
|
-
syncId: string;
|
|
8
|
-
scope: OperationScope;
|
|
9
|
-
branch: string;
|
|
10
|
-
};
|
|
11
|
-
export type CreateChildDocumentInput = {
|
|
12
|
-
id: string;
|
|
13
|
-
documentType: string;
|
|
14
|
-
document?: Document;
|
|
15
|
-
synchronizationUnits: SynchronizationUnit[];
|
|
16
|
-
};
|
|
17
|
-
export type CreateChildDocumentSignal = ISignal<'CREATE_CHILD_DOCUMENT', CreateChildDocumentInput>;
|
|
18
|
-
export type DeleteChildDocumentInput = {
|
|
19
|
-
id: string;
|
|
20
|
-
};
|
|
21
|
-
export type DeleteChildDocumentSignal = ISignal<'DELETE_CHILD_DOCUMENT', DeleteChildDocumentInput>;
|
|
22
|
-
export type CopyChildDocumentInput = {
|
|
23
|
-
id: string;
|
|
24
|
-
newId: string;
|
|
25
|
-
synchronizationUnits: SynchronizationUnit[];
|
|
26
|
-
};
|
|
27
|
-
export type CopyChildDocumentSignal = ISignal<'COPY_CHILD_DOCUMENT', CopyChildDocumentInput>;
|
|
28
|
-
export type Signal = CreateChildDocumentSignal | DeleteChildDocumentSignal | CopyChildDocumentSignal;
|
|
29
|
-
export type SignalDispatch = (signal: Signal) => void;
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import type { Draft } from 'immer';
|
|
2
|
-
import type { FC } from 'react';
|
|
3
|
-
import type { DocumentModelState } from '../document-model/';
|
|
4
|
-
import type { BaseAction } from './actions/types';
|
|
5
|
-
import { BaseDocument } from './object';
|
|
6
|
-
import { FileInput } from './utils';
|
|
7
|
-
import { SignalDispatch } from './signal';
|
|
8
|
-
export { z } from './schema';
|
|
9
|
-
export type * from './schema/types';
|
|
10
|
-
export type { FileInput } from './utils';
|
|
11
|
-
export type { Immutable } from 'immer';
|
|
12
|
-
export type { BaseAction } from './actions/types';
|
|
13
|
-
export type ActionSigner = {
|
|
14
|
-
user: {
|
|
15
|
-
address: string;
|
|
16
|
-
networkId: string;
|
|
17
|
-
chainId: number;
|
|
18
|
-
};
|
|
19
|
-
app: {
|
|
20
|
-
name: string;
|
|
21
|
-
key: string;
|
|
22
|
-
};
|
|
23
|
-
signature: string;
|
|
24
|
-
};
|
|
25
|
-
export type ActionContext = {
|
|
26
|
-
signer?: ActionSigner;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Defines the basic structure of an action.
|
|
30
|
-
*
|
|
31
|
-
* @typeParam T - The name of the action type. A `string` type by default.
|
|
32
|
-
*/
|
|
33
|
-
export type Action<T extends string = string, I = unknown, S extends OperationScope = OperationScope> = {
|
|
34
|
-
/** The name of the action. */
|
|
35
|
-
type: T;
|
|
36
|
-
/** The payload of the action. */
|
|
37
|
-
input: I;
|
|
38
|
-
/** The scope of the action, can either be 'global' or 'local' */
|
|
39
|
-
scope: S;
|
|
40
|
-
/** The attachments included in the action. */
|
|
41
|
-
attachments?: AttachmentInput[] | undefined;
|
|
42
|
-
/** The context of the action. */
|
|
43
|
-
context?: ActionContext;
|
|
44
|
-
};
|
|
45
|
-
export type ActionWithAttachment<T extends string = string, I = unknown, S extends OperationScope = OperationScope> = Action<T, I, S> & {
|
|
46
|
-
attachments: AttachmentInput[];
|
|
47
|
-
};
|
|
48
|
-
export type ReducerOptions = {
|
|
49
|
-
/** The number of operations to skip before this new action is applied */
|
|
50
|
-
skip?: number;
|
|
51
|
-
/** When true the skip count is ignored and the action is applied regardless of the skip count */
|
|
52
|
-
ignoreSkipOperations?: boolean;
|
|
53
|
-
/** if true reuses the provided action hash */
|
|
54
|
-
reuseHash?: boolean;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* A pure function that takes an action and the previous state
|
|
58
|
-
* of the document and returns the new state.
|
|
59
|
-
*
|
|
60
|
-
* @typeParam State - The type of the document data.
|
|
61
|
-
* @typeParam A - The type of the actions supported by the reducer.
|
|
62
|
-
*/
|
|
63
|
-
export type Reducer<State, A extends Action, LocalState> = (state: Document<State, A, LocalState>, action: A | BaseAction, dispatch?: SignalDispatch, options?: ReducerOptions) => Document<State, A, LocalState>;
|
|
64
|
-
/**
|
|
65
|
-
* A {@link Reducer} that prevents mutable code from changing the previous state.
|
|
66
|
-
*
|
|
67
|
-
* @remarks
|
|
68
|
-
* This reducer is wrapped with {@link https://immerjs.github.io/immer/ | Immer}.
|
|
69
|
-
* This allows the reducer code to be mutable, making it simpler and
|
|
70
|
-
* avoiding unintended changes in the provided state.
|
|
71
|
-
* The returned state will always be a new object.
|
|
72
|
-
*
|
|
73
|
-
* @typeParam State - The type of the document data.
|
|
74
|
-
* @typeParam A - The type of the actions supported by the reducer.
|
|
75
|
-
*/
|
|
76
|
-
export type ImmutableReducer<State, A extends Action, LocalState> = (state: Draft<Document<State, A, LocalState>>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A, LocalState> | undefined;
|
|
77
|
-
export type ImmutableStateReducer<S, A extends Action, L = unknown> = (state: Draft<State<S, L>>, action: A, dispatch?: SignalDispatch) => State<S, L> | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* Scope of an operation.
|
|
80
|
-
* Global: The operation is synchronized everywhere in the network. This is the default document operation.
|
|
81
|
-
* Local: The operation is applied only locally (to a local state). Used for local settings such as a drive's local path
|
|
82
|
-
*/
|
|
83
|
-
export type OperationScope = 'global' | 'local';
|
|
84
|
-
/**
|
|
85
|
-
* An operation that was applied to a {@link Document}.
|
|
86
|
-
*
|
|
87
|
-
* @remarks
|
|
88
|
-
* Wraps an action with an index, to be added to the operations history of a Document.
|
|
89
|
-
* The `index` field is used to keep all operations in order and enable replaying the
|
|
90
|
-
* document's history from the beginning.
|
|
91
|
-
*
|
|
92
|
-
* @typeParam A - The type of the action.
|
|
93
|
-
*/
|
|
94
|
-
export type Operation<A extends Action = Action> = A & {
|
|
95
|
-
/** Position of the operation in the history */
|
|
96
|
-
index: number;
|
|
97
|
-
/** Timestamp of when the operation was added */
|
|
98
|
-
timestamp: string;
|
|
99
|
-
/** Hash of the resulting document data after the operation */
|
|
100
|
-
hash: string;
|
|
101
|
-
/** The number of operations skipped with this Operation */
|
|
102
|
-
skip: number;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* The base attributes of a {@link Document}.
|
|
106
|
-
*/
|
|
107
|
-
export type DocumentHeader = {
|
|
108
|
-
/** The name of the document. */
|
|
109
|
-
name: string;
|
|
110
|
-
/** The number of operations applied to the document. */
|
|
111
|
-
revision: Required<Record<OperationScope, number>>;
|
|
112
|
-
/** The type of the document model. */
|
|
113
|
-
documentType: string;
|
|
114
|
-
/** The timestamp of the creation date of the document. */
|
|
115
|
-
created: string;
|
|
116
|
-
/** The timestamp of the last change in the document. */
|
|
117
|
-
lastModified: string;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* The attributes stored for a file. Namely, attachments of a document.
|
|
121
|
-
*/
|
|
122
|
-
export type Attachment = {
|
|
123
|
-
/** The binary data of the attachment in Base64 */
|
|
124
|
-
data: string;
|
|
125
|
-
/** The MIME type of the attachment */
|
|
126
|
-
mimeType: string;
|
|
127
|
-
extension?: string | null;
|
|
128
|
-
fileName?: string | null;
|
|
129
|
-
};
|
|
130
|
-
export type AttachmentInput = Attachment & {
|
|
131
|
-
hash: string;
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Object that indexes attachments of a Document.
|
|
135
|
-
*
|
|
136
|
-
* @remarks
|
|
137
|
-
* This is used to reduce memory usage to avoid
|
|
138
|
-
* multiple instances of the binary data of the attachments.
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
export type FileRegistry = Record<AttachmentRef, Attachment>;
|
|
142
|
-
export type State<GlobalState, LocalState> = {
|
|
143
|
-
global: GlobalState;
|
|
144
|
-
local: LocalState;
|
|
145
|
-
};
|
|
146
|
-
export type PartialState<S> = S | Partial<S>;
|
|
147
|
-
export type CreateState<S, L> = (state?: Partial<State<PartialState<S>, PartialState<L>>>) => State<S, L>;
|
|
148
|
-
export type ExtendedState<GlobalState, LocalState = unknown> = DocumentHeader & {
|
|
149
|
-
/** The document model specific state. */
|
|
150
|
-
state: State<GlobalState, LocalState>;
|
|
151
|
-
/** The index of document attachments. */
|
|
152
|
-
attachments: FileRegistry;
|
|
153
|
-
};
|
|
154
|
-
export type DocumentOperations<A extends Action> = Required<Record<OperationScope, Operation<A | BaseAction>[]>>;
|
|
155
|
-
export type MappedOperation<A extends Action> = {
|
|
156
|
-
ignore: boolean;
|
|
157
|
-
operation: Operation<A | BaseAction>;
|
|
158
|
-
};
|
|
159
|
-
export type DocumentOperationsIgnoreMap<A extends Action> = Required<Record<OperationScope, MappedOperation<A>[]>>;
|
|
160
|
-
/**
|
|
161
|
-
* The base type of a document model.
|
|
162
|
-
*
|
|
163
|
-
* @remarks
|
|
164
|
-
* This type is extended by all Document models.
|
|
165
|
-
*
|
|
166
|
-
* @typeParam Data - The type of the document data attribute.
|
|
167
|
-
* @typeParam A - The type of the actions supported by the Document.
|
|
168
|
-
*/
|
|
169
|
-
export type Document<GlobalState = unknown, A extends Action = Action, LocalState = unknown> =
|
|
170
|
-
/** The document model specific state. */
|
|
171
|
-
ExtendedState<GlobalState, LocalState> & {
|
|
172
|
-
/** The operations history of the document. */
|
|
173
|
-
operations: DocumentOperations<A>;
|
|
174
|
-
/** The initial state of the document, enabling replaying operations. */
|
|
175
|
-
initialState: ExtendedState<GlobalState, LocalState>;
|
|
176
|
-
/** A list of undone operations */
|
|
177
|
-
clipboard: Operation<BaseAction | A>[];
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* String type representing an attachment in a Document.
|
|
181
|
-
*
|
|
182
|
-
* @remarks
|
|
183
|
-
* Attachment string is formatted as `attachment://<filename>`.
|
|
184
|
-
*/
|
|
185
|
-
export type AttachmentRef = string;
|
|
186
|
-
export interface DocumentClass<S, A extends Action = Action, L = unknown, C extends BaseDocument<S, A, L> = BaseDocument<S, A, L>> {
|
|
187
|
-
fileExtension: string;
|
|
188
|
-
fromFile: (path: string) => Promise<C>;
|
|
189
|
-
new (initialState?: ExtendedState<S, L>): C;
|
|
190
|
-
}
|
|
191
|
-
export type DocumentModelUtils<S = unknown, A extends Action = Action, L = unknown> = {
|
|
192
|
-
fileExtension: string;
|
|
193
|
-
createState: CreateState<S, L>;
|
|
194
|
-
createExtendedState: (extendedState?: Partial<ExtendedState<PartialState<S>, PartialState<L>>>, createState?: CreateState<S, L>) => ExtendedState<S, L>;
|
|
195
|
-
createDocument: (document?: Partial<ExtendedState<PartialState<S>, PartialState<L>>>, createState?: CreateState<S, L>) => Document<S, A, L>;
|
|
196
|
-
loadFromFile: (path: string) => Promise<Document<S, A, L>>;
|
|
197
|
-
loadFromInput: (input: FileInput) => Promise<Document<S, A, L>>;
|
|
198
|
-
saveToFile: (document: Document<S, A, L>, path: string, name?: string) => Promise<string>;
|
|
199
|
-
saveToFileHandle: (document: Document<S, A, L>, input: FileSystemFileHandle) => Promise<void>;
|
|
200
|
-
};
|
|
201
|
-
export type ActionCreator<A extends Action> = ((input: any) => A) | ((input: any, attachments: AttachmentInput[]) => A) | ((...input: any) => BaseAction);
|
|
202
|
-
export type DocumentModel<S = unknown, A extends Action = Action, L = unknown, C extends BaseDocument<S, A, L> = BaseDocument<S, A, L>> = {
|
|
203
|
-
Document: DocumentClass<S, A, L, C>;
|
|
204
|
-
reducer: Reducer<S, A, L>;
|
|
205
|
-
actions: Record<string, ActionCreator<A>>;
|
|
206
|
-
utils: DocumentModelUtils<S, A, L>;
|
|
207
|
-
documentModel: DocumentModelState;
|
|
208
|
-
};
|
|
209
|
-
export type ENSInfo = {
|
|
210
|
-
name?: string;
|
|
211
|
-
avatarUrl?: string;
|
|
212
|
-
};
|
|
213
|
-
export type User = {
|
|
214
|
-
address: `0x${string}`;
|
|
215
|
-
networkId: string;
|
|
216
|
-
chainId: number;
|
|
217
|
-
ens?: ENSInfo;
|
|
218
|
-
};
|
|
219
|
-
export type EditorContext = {
|
|
220
|
-
theme: 'light' | 'dark';
|
|
221
|
-
debug?: boolean;
|
|
222
|
-
user?: User;
|
|
223
|
-
};
|
|
224
|
-
export type ActionErrorCallback = (error: unknown) => void;
|
|
225
|
-
export type EditorProps<S, A extends Action, L> = {
|
|
226
|
-
document: Document<S, A, L>;
|
|
227
|
-
dispatch: (action: A | BaseAction, onErrorCallback?: ActionErrorCallback) => void;
|
|
228
|
-
context: EditorContext;
|
|
229
|
-
error?: unknown;
|
|
230
|
-
};
|
|
231
|
-
export type Editor<S = unknown, A extends Action = Action, L = unknown> = {
|
|
232
|
-
Component: FC<EditorProps<S, A, L>>;
|
|
233
|
-
documentTypes: string[];
|
|
234
|
-
};
|
|
235
|
-
export type DocumentModelLib = {
|
|
236
|
-
documentModels: DocumentModel[];
|
|
237
|
-
editors: Editor[];
|
|
238
|
-
};
|
|
239
|
-
export type UndoRedoProcessResult<T, A extends Action, L> = {
|
|
240
|
-
document: Document<T, A, L>;
|
|
241
|
-
action: A | BaseAction;
|
|
242
|
-
skip: number;
|
|
243
|
-
};
|
|
244
|
-
export type ValidationError = {
|
|
245
|
-
message: string;
|
|
246
|
-
details: object;
|
|
247
|
-
};
|