@pluv/crdt-loro 5.0.1 → 5.0.3
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/README.md +7 -7
- package/dist/browser.d.mts +91 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +289 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/bundler.mjs +300 -0
- package/dist/bundler.mjs.map +1 -0
- package/dist/node.mjs +300 -0
- package/dist/node.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +10 -10
- package/CHANGELOG.md +0 -1041
- package/eslint.config.mjs +0 -4
- package/src/counter.ts +0 -8
- package/src/doc/CrdtLoroDoc.ts +0 -259
- package/src/doc/CrdtLoroDocFactory.ts +0 -33
- package/src/doc/builder.ts +0 -70
- package/src/doc/doc.ts +0 -9
- package/src/doc/index.ts +0 -4
- package/src/index.ts +0 -5
- package/src/list.ts +0 -16
- package/src/loro.ts +0 -11
- package/src/map.ts +0 -16
- package/src/movableList.ts +0 -14
- package/src/object.ts +0 -14
- package/src/text.ts +0 -10
- package/src/tree.ts +0 -7
- package/src/types.ts +0 -7
- package/src/utils/index.ts +0 -1
- package/src/utils/oneLine.ts +0 -7
- package/tsconfig.bundler.build.json +0 -3
- package/tsconfig.json +0 -8
- package/tsconfig.node.build.json +0 -3
- package/tsdown.browser.config.ts +0 -11
- package/tsdown.bundler.config.ts +0 -26
- package/tsdown.config.ts +0 -5
- package/tsdown.node.config.ts +0 -26
package/eslint.config.mjs
DELETED
package/src/counter.ts
DELETED
package/src/doc/CrdtLoroDoc.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DocApplyEncodedStateParams,
|
|
3
|
-
DocBatchApplyEncodedStateParams,
|
|
4
|
-
DocSubscribeCallbackParams,
|
|
5
|
-
InferCrdtJson,
|
|
6
|
-
} from "@pluv/crdt";
|
|
7
|
-
import type { CrdtDocLike } from "@pluv/types";
|
|
8
|
-
import { fromUint8Array, toUint8Array } from "js-base64";
|
|
9
|
-
import type { Container } from "loro-crdt";
|
|
10
|
-
import {
|
|
11
|
-
LoroCounter,
|
|
12
|
-
LoroDoc,
|
|
13
|
-
LoroEventBatch,
|
|
14
|
-
LoroList,
|
|
15
|
-
LoroMap,
|
|
16
|
-
LoroMovableList,
|
|
17
|
-
LoroText,
|
|
18
|
-
LoroTree,
|
|
19
|
-
UndoManager,
|
|
20
|
-
} from "loro-crdt";
|
|
21
|
-
import type { LoroType } from "../types";
|
|
22
|
-
import type { LoroBuilder } from "./builder";
|
|
23
|
-
import { builder } from "./builder";
|
|
24
|
-
|
|
25
|
-
const MAX_UNDO_STEPS = 100;
|
|
26
|
-
const MERGE_INTERVAL_MS = 1_000;
|
|
27
|
-
const PLUV_ID_FIELD = "__$pluv";
|
|
28
|
-
|
|
29
|
-
export type CrdtLoroDocParams<TStorage extends Record<string, LoroType<any, any>>> = (
|
|
30
|
-
builder: LoroBuilder,
|
|
31
|
-
) => TStorage;
|
|
32
|
-
|
|
33
|
-
export class CrdtLoroDoc<
|
|
34
|
-
TStorage extends Record<string, LoroType<any, any>>,
|
|
35
|
-
> implements CrdtDocLike<LoroDoc, TStorage> {
|
|
36
|
-
public value: LoroDoc = new LoroDoc();
|
|
37
|
-
|
|
38
|
-
#_storage: TStorage;
|
|
39
|
-
#_undoManager: UndoManager | null = null;
|
|
40
|
-
|
|
41
|
-
constructor(params: CrdtLoroDocParams<TStorage> = () => ({}) as TStorage) {
|
|
42
|
-
const storage = params(builder(this.value));
|
|
43
|
-
|
|
44
|
-
const keys = Object.keys(this.value.toJSON()).reduce(
|
|
45
|
-
(set, key) => set.add(key),
|
|
46
|
-
new Set<string>(),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
this.#_storage = Object.entries(storage).reduce(
|
|
50
|
-
(acc, [key, node]) => (keys.has(key) ? { ...acc, [key]: node } : acc),
|
|
51
|
-
{} as TStorage,
|
|
52
|
-
);
|
|
53
|
-
if (!!Object.keys(storage).length) this.#_setPluvId();
|
|
54
|
-
|
|
55
|
-
this.value.commit();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public applyEncodedState(params: DocApplyEncodedStateParams): this {
|
|
59
|
-
const update =
|
|
60
|
-
typeof params.update === "string" ? toUint8Array(params.update) : params.update;
|
|
61
|
-
|
|
62
|
-
if (!update) return this;
|
|
63
|
-
|
|
64
|
-
this.value.import(update);
|
|
65
|
-
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this {
|
|
70
|
-
const updates = params.updates ?? [];
|
|
71
|
-
|
|
72
|
-
const filtered = updates.reduce<Uint8Array[]>((acc, update) => {
|
|
73
|
-
if (!update) return acc;
|
|
74
|
-
|
|
75
|
-
if (typeof update === "string") {
|
|
76
|
-
acc.push(toUint8Array(update));
|
|
77
|
-
return acc;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (typeof update === "object") {
|
|
81
|
-
acc.push(update);
|
|
82
|
-
return acc;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return acc;
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
if (!filtered.length) return this;
|
|
89
|
-
|
|
90
|
-
if (filtered.length === 1) {
|
|
91
|
-
const update = filtered[0] ?? null;
|
|
92
|
-
|
|
93
|
-
if (!!update) this.value.import(update);
|
|
94
|
-
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.value.importBatch(filtered);
|
|
99
|
-
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public canRedo(): boolean {
|
|
104
|
-
if (!this.#_undoManager) return false;
|
|
105
|
-
|
|
106
|
-
return this.#_undoManager.canRedo();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public canUndo(): boolean {
|
|
110
|
-
if (!this.#_undoManager) return false;
|
|
111
|
-
|
|
112
|
-
return this.#_undoManager.canUndo();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public destroy(): void {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public get(key?: undefined): TStorage;
|
|
120
|
-
public get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
121
|
-
public get<TKey extends keyof TStorage>(key?: TKey): TStorage | TStorage[TKey] {
|
|
122
|
-
if (typeof key === "undefined") return this.#_storage;
|
|
123
|
-
|
|
124
|
-
return this.#_storage[key as TKey];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public getEncodedState(): string {
|
|
128
|
-
return fromUint8Array(this.value.export({ mode: "snapshot" }));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public toJson(): InferCrdtJson<TStorage>;
|
|
132
|
-
public toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
133
|
-
public toJson<TKey extends keyof TStorage>(type?: TKey) {
|
|
134
|
-
if (typeof type === "string") {
|
|
135
|
-
const container = this.#_storage[type] as unknown as Container;
|
|
136
|
-
|
|
137
|
-
return container instanceof LoroText
|
|
138
|
-
? container.toString()
|
|
139
|
-
: container instanceof LoroCounter
|
|
140
|
-
? container.value
|
|
141
|
-
: container.toJSON!();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return Object.entries(this.#_storage).reduce(
|
|
145
|
-
(acc, [key, value]) => ({
|
|
146
|
-
...(acc as any),
|
|
147
|
-
[key]: value instanceof LoroText ? value.toString() : value.toJSON!(),
|
|
148
|
-
}),
|
|
149
|
-
{} as InferCrdtJson<TStorage>,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public isEmpty(): boolean {
|
|
154
|
-
const serialized = this.value.toJSON();
|
|
155
|
-
|
|
156
|
-
return !serialized || !Object.keys(serialized).length;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
public rebuildStorage(reference: TStorage): this {
|
|
160
|
-
const isBuilt = !!Object.keys(this.#_storage).length;
|
|
161
|
-
|
|
162
|
-
if (isBuilt) {
|
|
163
|
-
console.warn("Attempted to rebuild storage multiple times");
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this.#_storage = Object.entries(reference).reduce((acc, [key, node]) => {
|
|
168
|
-
if (node instanceof LoroCounter) return { ...acc, [key]: this.value.getCounter(key) };
|
|
169
|
-
if (node instanceof LoroList) return { ...acc, [key]: this.value.getList(key) };
|
|
170
|
-
if (node instanceof LoroMap) return { ...acc, [key]: this.value.getMap(key) };
|
|
171
|
-
if (node instanceof LoroMovableList) {
|
|
172
|
-
return { ...acc, [key]: this.value.getMovableList(key) };
|
|
173
|
-
}
|
|
174
|
-
if (node instanceof LoroText) return { ...acc, [key]: this.value.getText(key) };
|
|
175
|
-
if (node instanceof LoroTree) return { ...acc, [key]: this.value.getTree(key) };
|
|
176
|
-
|
|
177
|
-
return acc;
|
|
178
|
-
}, {} as TStorage);
|
|
179
|
-
|
|
180
|
-
return this.track();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public redo(): this {
|
|
184
|
-
this.#_undoManager?.redo();
|
|
185
|
-
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
public subscribe(
|
|
190
|
-
listener: (params: DocSubscribeCallbackParams<LoroDoc, TStorage>) => void,
|
|
191
|
-
): () => void {
|
|
192
|
-
const fn = (event: LoroEventBatch) => {
|
|
193
|
-
const update = fromUint8Array(this.value.export({ mode: "update" }));
|
|
194
|
-
|
|
195
|
-
listener({
|
|
196
|
-
doc: this,
|
|
197
|
-
local: event.by === "local",
|
|
198
|
-
origin: event.origin ? String(event.origin) : null,
|
|
199
|
-
update,
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const unsubcribeAll = Object.values(this.#_storage).reduce<() => void>(
|
|
204
|
-
(acc, crdtType) => {
|
|
205
|
-
const container = crdtType as unknown as Container;
|
|
206
|
-
const unsubscribe = container.subscribe(fn);
|
|
207
|
-
|
|
208
|
-
return () => {
|
|
209
|
-
acc();
|
|
210
|
-
unsubscribe();
|
|
211
|
-
};
|
|
212
|
-
},
|
|
213
|
-
() => undefined,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
return unsubcribeAll;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
public track(): this {
|
|
220
|
-
if (this.#_undoManager) {
|
|
221
|
-
this.#_undoManager.clear();
|
|
222
|
-
this.#_undoManager.free();
|
|
223
|
-
|
|
224
|
-
this.#_undoManager = null;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
this.#_undoManager = new UndoManager(this.value, {
|
|
228
|
-
maxUndoSteps: MAX_UNDO_STEPS,
|
|
229
|
-
mergeInterval: MERGE_INTERVAL_MS,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @description Unlike Yjs, this method is required to be called after each loro operation.
|
|
237
|
-
* @date January 12, 2025
|
|
238
|
-
*/
|
|
239
|
-
public transact(fn: () => void): this {
|
|
240
|
-
fn();
|
|
241
|
-
|
|
242
|
-
this.value.commit();
|
|
243
|
-
|
|
244
|
-
return this;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
public undo(): this {
|
|
248
|
-
this.#_undoManager?.undo();
|
|
249
|
-
|
|
250
|
-
return this;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
#_setPluvId() {
|
|
254
|
-
const text = this.value.getText(PLUV_ID_FIELD);
|
|
255
|
-
const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
|
|
256
|
-
|
|
257
|
-
text.insert(0, id);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
|
-
import type { LoroDoc } from "loro-crdt";
|
|
3
|
-
import type { LoroType } from "../types";
|
|
4
|
-
import { CrdtLoroDoc } from "./CrdtLoroDoc";
|
|
5
|
-
import type { LoroBuilder } from "./builder";
|
|
6
|
-
|
|
7
|
-
export class CrdtLoroDocFactory<
|
|
8
|
-
TStorage extends Record<string, LoroType<any, any>>,
|
|
9
|
-
> extends AbstractCrdtDocFactory<LoroDoc, TStorage> {
|
|
10
|
-
public readonly _initialStorage: (builder: LoroBuilder) => TStorage;
|
|
11
|
-
|
|
12
|
-
constructor(initialStorage: (builder: LoroBuilder) => TStorage = () => ({}) as TStorage) {
|
|
13
|
-
super(initialStorage);
|
|
14
|
-
|
|
15
|
-
this._initialStorage = initialStorage;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public getEmpty(): CrdtLoroDoc<TStorage> {
|
|
19
|
-
return new CrdtLoroDoc<TStorage>();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public getFactory(
|
|
23
|
-
initialStorage?: ((builder: LoroBuilder) => TStorage) | undefined,
|
|
24
|
-
): CrdtLoroDocFactory<TStorage> {
|
|
25
|
-
return new CrdtLoroDocFactory<TStorage>(initialStorage ?? this._initialStorage);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public getInitialized(
|
|
29
|
-
initialStorage?: (builder: LoroBuilder) => TStorage,
|
|
30
|
-
): CrdtLoroDoc<TStorage> {
|
|
31
|
-
return new CrdtLoroDoc<TStorage>(initialStorage ?? this._initialStorage);
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/doc/builder.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Container,
|
|
3
|
-
LoroCounter,
|
|
4
|
-
LoroDoc,
|
|
5
|
-
LoroList,
|
|
6
|
-
LoroMap,
|
|
7
|
-
LoroMovableList,
|
|
8
|
-
LoroText,
|
|
9
|
-
} from "loro-crdt";
|
|
10
|
-
import { isContainer } from "loro-crdt";
|
|
11
|
-
import type { LoroType } from "../types";
|
|
12
|
-
|
|
13
|
-
export type LoroBuilder = ReturnType<typeof builder>;
|
|
14
|
-
|
|
15
|
-
export const builder = (doc: LoroDoc) => {
|
|
16
|
-
return {
|
|
17
|
-
counter(name: string): LoroCounter {
|
|
18
|
-
return doc.getCounter(name);
|
|
19
|
-
},
|
|
20
|
-
list<T extends unknown>(
|
|
21
|
-
name: string,
|
|
22
|
-
value: T[] | readonly T[] = [],
|
|
23
|
-
): LoroType<LoroList<T>, T[]> {
|
|
24
|
-
const list = doc.getList(name);
|
|
25
|
-
|
|
26
|
-
value.forEach((item, i) => {
|
|
27
|
-
if (isContainer(item)) list.insertContainer(i, item);
|
|
28
|
-
else list.insert(i, item as Exclude<T, Container>);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return list as unknown as LoroType<LoroList<T>, T[]>;
|
|
32
|
-
},
|
|
33
|
-
map<T extends Record<string, unknown>>(
|
|
34
|
-
name: string,
|
|
35
|
-
value: T = {} as T,
|
|
36
|
-
): LoroType<LoroMap<T>, T> {
|
|
37
|
-
const container = doc.getMap(name);
|
|
38
|
-
|
|
39
|
-
Object.entries(value).forEach(([key, item]) => {
|
|
40
|
-
if (isContainer(item)) container.setContainer(key, item);
|
|
41
|
-
else container.set(key, item as Exclude<T, Container>);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return container as unknown as LoroType<LoroMap<T>, T>;
|
|
45
|
-
},
|
|
46
|
-
moveableList<T extends unknown>(
|
|
47
|
-
name: string,
|
|
48
|
-
value: T[] | readonly T[] = [],
|
|
49
|
-
): LoroType<LoroMovableList<T>, T[]> {
|
|
50
|
-
const list = doc.getMovableList(name);
|
|
51
|
-
|
|
52
|
-
value.forEach((item, i) => {
|
|
53
|
-
if (isContainer(item)) list.insertContainer(i, item);
|
|
54
|
-
else list.insert(i, item as Exclude<T, Container>);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return list as unknown as LoroType<LoroMovableList<T>, T[]>;
|
|
58
|
-
},
|
|
59
|
-
text(name: string, value: string = ""): LoroType<LoroText, string> {
|
|
60
|
-
const text = doc.getText(name);
|
|
61
|
-
|
|
62
|
-
text.insert(0, value);
|
|
63
|
-
|
|
64
|
-
return text as unknown as LoroType<LoroText, string>;
|
|
65
|
-
},
|
|
66
|
-
tree(name: string) {
|
|
67
|
-
return doc.getTree(name);
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
};
|
package/src/doc/doc.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { LoroType } from "../types";
|
|
2
|
-
import type { LoroBuilder } from "./builder";
|
|
3
|
-
import { CrdtLoroDocFactory } from "./CrdtLoroDocFactory";
|
|
4
|
-
|
|
5
|
-
export const doc = <TStorage extends Record<string, LoroType<any, any>>>(
|
|
6
|
-
value: (builder: LoroBuilder) => TStorage = () => ({}) as TStorage,
|
|
7
|
-
): CrdtLoroDocFactory<TStorage> => {
|
|
8
|
-
return new CrdtLoroDocFactory<TStorage>(value);
|
|
9
|
-
};
|
package/src/doc/index.ts
DELETED
package/src/index.ts
DELETED
package/src/list.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Container } from "loro-crdt";
|
|
2
|
-
import { LoroList, isContainer } from "loro-crdt";
|
|
3
|
-
import type { LoroType } from "./types";
|
|
4
|
-
|
|
5
|
-
export const list = <T extends unknown>(
|
|
6
|
-
value: T[] | readonly T[] = [],
|
|
7
|
-
): LoroType<LoroList<T>, T[]> => {
|
|
8
|
-
const container = new LoroList();
|
|
9
|
-
|
|
10
|
-
value.forEach((item, i) => {
|
|
11
|
-
if (isContainer(item)) container.insertContainer(i, item);
|
|
12
|
-
else container.insert(i, item as Exclude<T, Container>);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return container as unknown as LoroType<LoroList<T>, T[]>;
|
|
16
|
-
};
|
package/src/loro.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { counter } from "./counter";
|
|
2
|
-
export { CrdtLoroDoc, doc } from "./doc";
|
|
3
|
-
export type { LoroBuilder } from "./doc";
|
|
4
|
-
export { list } from "./list";
|
|
5
|
-
export { map } from "./map";
|
|
6
|
-
export { movableList } from "./movableList";
|
|
7
|
-
export { object } from "./object";
|
|
8
|
-
export { text } from "./text";
|
|
9
|
-
export { tree } from "./tree";
|
|
10
|
-
export type { LoroType } from "./types";
|
|
11
|
-
export const kind = "loro" as const;
|
package/src/map.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Container } from "loro-crdt";
|
|
2
|
-
import { LoroMap, isContainer } from "loro-crdt";
|
|
3
|
-
import type { LoroType } from "./types";
|
|
4
|
-
|
|
5
|
-
export const map = <T extends unknown>(
|
|
6
|
-
value: readonly (readonly [key: string, value: T])[] = [],
|
|
7
|
-
): LoroType<LoroMap<Record<string, T>>, Record<string, T>> => {
|
|
8
|
-
const container = new LoroMap();
|
|
9
|
-
|
|
10
|
-
value.forEach(([key, item]) => {
|
|
11
|
-
if (isContainer(item)) container.setContainer(key, item);
|
|
12
|
-
else container.set(key, item as Exclude<T, Container>);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return container as unknown as LoroType<LoroMap<Record<string, T>>, Record<string, T>>;
|
|
16
|
-
};
|
package/src/movableList.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Container } from "loro-crdt";
|
|
2
|
-
import { isContainer, LoroMovableList } from "loro-crdt";
|
|
3
|
-
import type { LoroType } from "./types";
|
|
4
|
-
|
|
5
|
-
export const movableList = <T extends unknown>(value: T[] | readonly T[] = []) => {
|
|
6
|
-
const container = new LoroMovableList();
|
|
7
|
-
|
|
8
|
-
value.forEach((item, i) => {
|
|
9
|
-
if (isContainer(item)) container.insertContainer(i, item);
|
|
10
|
-
else container.insert(i, item as Exclude<T, Container>);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return container as unknown as LoroType<LoroMovableList<T>, T[]>;
|
|
14
|
-
};
|
package/src/object.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Container } from "loro-crdt";
|
|
2
|
-
import { LoroMap, isContainer } from "loro-crdt";
|
|
3
|
-
import type { LoroType } from "./types";
|
|
4
|
-
|
|
5
|
-
export const object = <T extends Record<string, any>>(value: T): LoroType<LoroMap<T>, T> => {
|
|
6
|
-
const container = new LoroMap();
|
|
7
|
-
|
|
8
|
-
Object.entries(value).forEach(([key, item]) => {
|
|
9
|
-
if (isContainer(item)) container.setContainer(key, item);
|
|
10
|
-
else container.set(key, item as Exclude<T, Container>);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return container as unknown as LoroType<LoroMap<T>, T>;
|
|
14
|
-
};
|
package/src/text.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { LoroText } from "loro-crdt";
|
|
2
|
-
import type { LoroType } from "./types";
|
|
3
|
-
|
|
4
|
-
export const text = (value: string = ""): LoroType<LoroText, string> => {
|
|
5
|
-
const container = new LoroText();
|
|
6
|
-
|
|
7
|
-
container.insert(0, value);
|
|
8
|
-
|
|
9
|
-
return container as unknown as LoroType<LoroText, string>;
|
|
10
|
-
};
|
package/src/tree.ts
DELETED
package/src/types.ts
DELETED
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { oneLine } from "./oneLine";
|
package/src/utils/oneLine.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const oneLine = (strings: TemplateStringsArray, ...values: unknown[]): string => {
|
|
2
|
-
return strings
|
|
3
|
-
.map((str) => str.replace(/\s+/g, " "))
|
|
4
|
-
.reduce((acc, str, i) => acc + str + (i < values.length ? values[i] : ""), "")
|
|
5
|
-
.replace(/\s+/g, " ")
|
|
6
|
-
.trim();
|
|
7
|
-
};
|
package/tsconfig.json
DELETED
package/tsconfig.node.build.json
DELETED
package/tsdown.browser.config.ts
DELETED
package/tsdown.bundler.config.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsdown";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: { bundler: "src/index.ts" },
|
|
5
|
-
plugins: [
|
|
6
|
-
{
|
|
7
|
-
name: "rewrite-loro-import",
|
|
8
|
-
renderChunk(code) {
|
|
9
|
-
return {
|
|
10
|
-
code: code.replaceAll(
|
|
11
|
-
/from\s*["']loro-crdt["']/g,
|
|
12
|
-
'from "loro-crdt/bundler"',
|
|
13
|
-
),
|
|
14
|
-
map: null,
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
format: ["esm"],
|
|
20
|
-
target: "esnext",
|
|
21
|
-
sourcemap: true,
|
|
22
|
-
tsconfig: "tsconfig.bundler.build.json",
|
|
23
|
-
dts: false,
|
|
24
|
-
outDir: "dist",
|
|
25
|
-
clean: false,
|
|
26
|
-
});
|
package/tsdown.config.ts
DELETED
package/tsdown.node.config.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsdown";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: { node: "src/index.ts" },
|
|
5
|
-
plugins: [
|
|
6
|
-
{
|
|
7
|
-
name: "rewrite-loro-import",
|
|
8
|
-
renderChunk(code) {
|
|
9
|
-
return {
|
|
10
|
-
code: code.replaceAll(
|
|
11
|
-
/from\s*["']loro-crdt["']/g,
|
|
12
|
-
'from "loro-crdt/nodejs"',
|
|
13
|
-
),
|
|
14
|
-
map: null,
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
format: ["esm"],
|
|
20
|
-
target: "esnext",
|
|
21
|
-
sourcemap: true,
|
|
22
|
-
tsconfig: "tsconfig.node.build.json",
|
|
23
|
-
dts: false,
|
|
24
|
-
outDir: "dist",
|
|
25
|
-
clean: false,
|
|
26
|
-
});
|