@articollab/react 0.0.0-stage → 0.12.0-beta.1
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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +248 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Michael Wang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @articollab/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hooks for Articollab documents and sync clients.
|
|
4
|
+
|
|
5
|
+
[Read the React guide](https://eastsun5566.github.io/articollab/#/react).
|
|
6
|
+
|
|
7
|
+
MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { BlockShape, ClientDocument, EmbedShape, CounterMapSchema, CounterSchema, DocumentState, JsonValue, ListSchema, MarkShape, MapSchema, SchemaShape, TextBlock, TextDeltaOp, TextSchema, UndoManager, ValueSchema } from "@articollab/core";
|
|
2
|
+
import type { PresenceSyncClient, SyncClient, SyncPushState, SyncStatus } from "@articollab/sync";
|
|
3
|
+
/** What `useCollection()` returns for a collection schema. */
|
|
4
|
+
export type CollectionSnapshot<D> = D extends ValueSchema<infer T> ? T : D extends ListSchema<infer T> ? readonly T[] : D extends TextSchema ? string : D extends MapSchema<infer T> ? Readonly<Record<string, T>> : D extends CounterSchema ? number : D extends CounterMapSchema ? Readonly<Record<string, number>> : never;
|
|
5
|
+
/** Equal arrays or plain objects with `Object.is`-equal entries, or `Object.is`-equal values. */
|
|
6
|
+
export declare function shallowEqual(left: unknown, right: unknown): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The visible state of the collection at `path`, re-rendering only when it changes:
|
|
9
|
+
*
|
|
10
|
+
* | Collection | Snapshot |
|
|
11
|
+
* | --- | --- |
|
|
12
|
+
* | Value | its value |
|
|
13
|
+
* | List | a frozen array of its values |
|
|
14
|
+
* | Text | its text |
|
|
15
|
+
* | Map, CounterMap | a frozen object from key to value |
|
|
16
|
+
* | Counter | its total |
|
|
17
|
+
*
|
|
18
|
+
* Every component reading one collection shares a subscription and a snapshot, which keeps its
|
|
19
|
+
* identity until the collection changes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useCollection<S extends SchemaShape, K extends keyof S & string>(doc: ClientDocument<S>, path: K): CollectionSnapshot<S[K]>;
|
|
22
|
+
type TextAt<S extends SchemaShape> = {
|
|
23
|
+
[K in keyof S & string]: S[K] extends TextSchema ? K : never;
|
|
24
|
+
}[keyof S & string];
|
|
25
|
+
type MarksOf<D> = D extends TextSchema<infer M extends MarkShape, BlockShape, EmbedShape> ? M : never;
|
|
26
|
+
type BlocksOf<D> = D extends TextSchema<MarkShape, infer B extends BlockShape, EmbedShape> ? B : never;
|
|
27
|
+
type EmbedsOf<D> = D extends TextSchema<MarkShape, BlockShape, infer E extends EmbedShape> ? E : never;
|
|
28
|
+
/** The Text at `path` as runs of equal marks, like `toDelta()`, re-rendering when its text, marks or embeds change. */
|
|
29
|
+
export declare function useTextDelta<S extends SchemaShape, K extends TextAt<S>>(doc: ClientDocument<S>, path: K): readonly TextDeltaOp<MarksOf<S[K]>, EmbedsOf<S[K]>>[];
|
|
30
|
+
/** The Text at `path` as paragraphs, like `blocks()`, re-rendering when its paragraphs or their attributes change. */
|
|
31
|
+
export declare function useTextBlocks<S extends SchemaShape, K extends TextAt<S>>(doc: ClientDocument<S>, path: K): readonly TextBlock<BlocksOf<S[K]>>[];
|
|
32
|
+
/**
|
|
33
|
+
* Derives a value from the document's visible state. `selector` runs after each change, and the
|
|
34
|
+
* component re-renders only when its result is not `isEqual` to the previous one (by default,
|
|
35
|
+
* shallowly equal), which then keeps its identity. `selector` may be a new function on each render.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useDocument<S extends SchemaShape, R>(doc: ClientDocument<S>, selector: (state: DocumentState<S>) => R, isEqual?: (left: R, right: R) => boolean): R;
|
|
38
|
+
/** The sync client's state, for a status badge. */
|
|
39
|
+
export interface SyncState {
|
|
40
|
+
readonly status: SyncStatus;
|
|
41
|
+
readonly push: SyncPushState;
|
|
42
|
+
/** Why the client failed, while `status` is "failed". */
|
|
43
|
+
readonly error: unknown;
|
|
44
|
+
}
|
|
45
|
+
/** The sync client's status, push channel and failure, re-rendering when any of them changes. */
|
|
46
|
+
export declare function useSyncStatus<S extends SchemaShape>(sync: SyncClient<S>): SyncState;
|
|
47
|
+
/** The other writers' presence states by client ID, re-rendering when they change. */
|
|
48
|
+
export declare function usePeers<S extends SchemaShape, P extends JsonValue>(sync: PresenceSyncClient<S, P>): ReadonlyMap<string, P>;
|
|
49
|
+
/** Whether `history` can undo or redo, for enabling buttons. */
|
|
50
|
+
export interface UndoState {
|
|
51
|
+
readonly canUndo: boolean;
|
|
52
|
+
readonly canRedo: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** `canUndo` and `canRedo` of an undo manager, re-rendering when either changes. */
|
|
55
|
+
export declare function useUndoState(history: UndoManager): UndoState;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAElG,8DAA8D;AAC9D,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAC9B,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAC9B,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,GAC1C,CAAC,SAAS,UAAU,GAAG,MAAM,GAC3B,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GACxD,CAAC,SAAS,aAAa,GAAG,MAAM,GAC9B,CAAC,SAAS,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,M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Q,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAa5D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { useRef, useSyncExternalStore } from "react";
|
|
2
|
+
/** Equal arrays or plain objects with `Object.is`-equal entries, or `Object.is`-equal values. */
|
|
3
|
+
export function shallowEqual(left, right) {
|
|
4
|
+
if (Object.is(left, right))
|
|
5
|
+
return true;
|
|
6
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null)
|
|
7
|
+
return false;
|
|
8
|
+
if (Array.isArray(left) !== Array.isArray(right))
|
|
9
|
+
return false;
|
|
10
|
+
const leftKeys = Object.keys(left), rightKeys = Object.keys(right);
|
|
11
|
+
return leftKeys.length === rightKeys.length &&
|
|
12
|
+
leftKeys.every((key) => Object.hasOwn(right, key) && Object.is(Reflect.get(left, key), Reflect.get(right, key)));
|
|
13
|
+
}
|
|
14
|
+
/** Equal JSON values, for formatting runs and paragraphs that are rebuilt on every read. */
|
|
15
|
+
function jsonEqual(left, right) {
|
|
16
|
+
if (Object.is(left, right))
|
|
17
|
+
return true;
|
|
18
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null)
|
|
19
|
+
return false;
|
|
20
|
+
if (Array.isArray(left) !== Array.isArray(right))
|
|
21
|
+
return false;
|
|
22
|
+
const leftKeys = Object.keys(left), rightKeys = Object.keys(right);
|
|
23
|
+
return leftKeys.length === rightKeys.length &&
|
|
24
|
+
leftKeys.every((key) => Object.hasOwn(right, key) && jsonEqual(Reflect.get(left, key), Reflect.get(right, key)));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A source that recomputes its snapshot only after a change, shared by every component that reads
|
|
28
|
+
* it. While nobody is subscribed it cannot hear changes, so each read recomputes and keeps the
|
|
29
|
+
* previous snapshot when the new one is equal.
|
|
30
|
+
*/
|
|
31
|
+
function cachedSource(listen, read, equal, affects = () => true) {
|
|
32
|
+
const listeners = new Set();
|
|
33
|
+
let stop;
|
|
34
|
+
let current;
|
|
35
|
+
let stale = true;
|
|
36
|
+
return {
|
|
37
|
+
subscribe(listener) {
|
|
38
|
+
listeners.add(listener);
|
|
39
|
+
if (stop === undefined) {
|
|
40
|
+
stop = listen((event) => {
|
|
41
|
+
if (!affects(event))
|
|
42
|
+
return;
|
|
43
|
+
stale = true;
|
|
44
|
+
for (const notify of [...listeners])
|
|
45
|
+
notify();
|
|
46
|
+
});
|
|
47
|
+
// Changes made before this subscription went unheard.
|
|
48
|
+
stale = true;
|
|
49
|
+
}
|
|
50
|
+
return () => {
|
|
51
|
+
listeners.delete(listener);
|
|
52
|
+
if (listeners.size === 0) {
|
|
53
|
+
stop?.();
|
|
54
|
+
stop = undefined;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
getSnapshot() {
|
|
59
|
+
if (current !== undefined && !stale && stop !== undefined)
|
|
60
|
+
return current.value;
|
|
61
|
+
const next = read();
|
|
62
|
+
if (stop !== undefined)
|
|
63
|
+
stale = false;
|
|
64
|
+
if (current !== undefined && equal(current.value, next))
|
|
65
|
+
return current.value;
|
|
66
|
+
current = { value: next };
|
|
67
|
+
return next;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** One source per owner and kind of reading, so components share subscriptions and snapshots. */
|
|
72
|
+
const sources = new WeakMap();
|
|
73
|
+
function shared(owner, key, create) {
|
|
74
|
+
let byKey = sources.get(owner);
|
|
75
|
+
if (byKey === undefined)
|
|
76
|
+
sources.set(owner, byKey = new Map());
|
|
77
|
+
const found = byKey.get(key);
|
|
78
|
+
if (found !== undefined) {
|
|
79
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Each key always stores the same kind of source.
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
const source = create();
|
|
83
|
+
byKey.set(key, source);
|
|
84
|
+
return source;
|
|
85
|
+
}
|
|
86
|
+
/** A document of any schema, read only through paths its own schema has. */
|
|
87
|
+
function wide(doc) {
|
|
88
|
+
return doc;
|
|
89
|
+
}
|
|
90
|
+
function useSource(source) {
|
|
91
|
+
return useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);
|
|
92
|
+
}
|
|
93
|
+
/** The collection at `path`, or a TypeError for a path the schema does not have. */
|
|
94
|
+
function collectionAt(doc, path) {
|
|
95
|
+
if (!Object.hasOwn(doc.state, path))
|
|
96
|
+
throw new TypeError(`Unknown collection path: ${path}`);
|
|
97
|
+
return doc.state[path];
|
|
98
|
+
}
|
|
99
|
+
/** The visible state of one collection, as it changes. */
|
|
100
|
+
function collectionSource(doc, path) {
|
|
101
|
+
const collection = collectionAt(doc, path);
|
|
102
|
+
return shared(collection, "collection", () => {
|
|
103
|
+
if ("toDelta" in collection) {
|
|
104
|
+
return cachedSource((listener) => collection.observe(listener), () => collection.toString(), Object.is, (event) => event.changes.length > 0);
|
|
105
|
+
}
|
|
106
|
+
if ("toArray" in collection) {
|
|
107
|
+
return cachedSource((listener) => collection.observe(listener), () => Object.freeze(collection.toArray()), shallowEqual);
|
|
108
|
+
}
|
|
109
|
+
if ("toObject" in collection) {
|
|
110
|
+
return cachedSource((listener) => collection.observe(listener), () => Object.freeze(collection.toObject()), shallowEqual);
|
|
111
|
+
}
|
|
112
|
+
// A Value or a Counter: no observe(), but its value keeps its identity until it changes.
|
|
113
|
+
return { subscribe: (listener) => doc.on("change", () => { listener(); }), getSnapshot: () => collection.value };
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The visible state of the collection at `path`, re-rendering only when it changes:
|
|
118
|
+
*
|
|
119
|
+
* | Collection | Snapshot |
|
|
120
|
+
* | --- | --- |
|
|
121
|
+
* | Value | its value |
|
|
122
|
+
* | List | a frozen array of its values |
|
|
123
|
+
* | Text | its text |
|
|
124
|
+
* | Map, CounterMap | a frozen object from key to value |
|
|
125
|
+
* | Counter | its total |
|
|
126
|
+
*
|
|
127
|
+
* Every component reading one collection shares a subscription and a snapshot, which keeps its
|
|
128
|
+
* identity until the collection changes.
|
|
129
|
+
*/
|
|
130
|
+
export function useCollection(doc, path) {
|
|
131
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- The schema decides the collection, and so the snapshot.
|
|
132
|
+
return useSource(collectionSource(wide(doc), path));
|
|
133
|
+
}
|
|
134
|
+
/** The Text at `path`. */
|
|
135
|
+
function textAt(doc, path) {
|
|
136
|
+
const text = collectionAt(doc, path);
|
|
137
|
+
if (!("toDelta" in text))
|
|
138
|
+
throw new TypeError(`Not a Text collection: ${path}`);
|
|
139
|
+
return text;
|
|
140
|
+
}
|
|
141
|
+
/** The Text at `path` as runs of equal marks, like `toDelta()`, re-rendering when its text, marks or embeds change. */
|
|
142
|
+
export function useTextDelta(doc, path) {
|
|
143
|
+
const text = textAt(wide(doc), path);
|
|
144
|
+
const source = shared(text, "delta", () => cachedSource((listener) => text.observe(listener), () => text.toDelta(), jsonEqual, (event) => event.changes.length > 0 || (event.formats?.length ?? 0) > 0 || (event.embeds?.length ?? 0) > 0));
|
|
145
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- toDelta() runs carry the schema's marks and embeds.
|
|
146
|
+
return useSource(source);
|
|
147
|
+
}
|
|
148
|
+
/** The Text at `path` as paragraphs, like `blocks()`, re-rendering when its paragraphs or their attributes change. */
|
|
149
|
+
export function useTextBlocks(doc, path) {
|
|
150
|
+
const text = textAt(wide(doc), path);
|
|
151
|
+
const source = shared(text, "blocks", () => cachedSource((listener) => text.observe(listener), () => text.blocks(), jsonEqual, (event) => event.changes.length > 0 || (event.blocks?.length ?? 0) > 0));
|
|
152
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- blocks() entries carry the schema's attributes.
|
|
153
|
+
return useSource(source);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* A counter of the document's visible changes. It cannot hear changes while nobody is subscribed,
|
|
157
|
+
* so starting a subscription counts as a change too: React reads again right after subscribing.
|
|
158
|
+
*/
|
|
159
|
+
function versionSource(doc) {
|
|
160
|
+
return shared(doc, "version", () => {
|
|
161
|
+
const listeners = new Set();
|
|
162
|
+
let stop;
|
|
163
|
+
let version = 0;
|
|
164
|
+
return {
|
|
165
|
+
subscribe(listener) {
|
|
166
|
+
listeners.add(listener);
|
|
167
|
+
if (stop === undefined) {
|
|
168
|
+
version++;
|
|
169
|
+
stop = doc.on("change", () => { version++; for (const notify of [...listeners])
|
|
170
|
+
notify(); });
|
|
171
|
+
}
|
|
172
|
+
return () => {
|
|
173
|
+
listeners.delete(listener);
|
|
174
|
+
if (listeners.size === 0) {
|
|
175
|
+
stop?.();
|
|
176
|
+
stop = undefined;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
getSnapshot: () => version,
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Derives a value from the document's visible state. `selector` runs after each change, and the
|
|
186
|
+
* component re-renders only when its result is not `isEqual` to the previous one (by default,
|
|
187
|
+
* shallowly equal), which then keeps its identity. `selector` may be a new function on each render.
|
|
188
|
+
*/
|
|
189
|
+
export function useDocument(doc, selector, isEqual = shallowEqual) {
|
|
190
|
+
const source = versionSource(wide(doc));
|
|
191
|
+
const memo = useRef(undefined);
|
|
192
|
+
const getSnapshot = () => {
|
|
193
|
+
const version = source.getSnapshot();
|
|
194
|
+
const previous = memo.current;
|
|
195
|
+
if (previous !== undefined && previous.doc === doc && previous.version === version && previous.selector === selector)
|
|
196
|
+
return previous.value;
|
|
197
|
+
const next = selector(doc.state);
|
|
198
|
+
const value = previous !== undefined && previous.doc === doc && isEqual(previous.value, next) ? previous.value : next;
|
|
199
|
+
memo.current = { doc, version, selector, value };
|
|
200
|
+
return value;
|
|
201
|
+
};
|
|
202
|
+
return useSyncExternalStore(source.subscribe, getSnapshot, getSnapshot);
|
|
203
|
+
}
|
|
204
|
+
/** The sync client's status, push channel and failure, re-rendering when any of them changes. */
|
|
205
|
+
export function useSyncStatus(sync) {
|
|
206
|
+
const source = shared(sync, "status", () => {
|
|
207
|
+
let current;
|
|
208
|
+
return {
|
|
209
|
+
subscribe(listener) {
|
|
210
|
+
const stopStatus = sync.on("status", () => { listener(); }), stopPush = sync.on("push", () => { listener(); });
|
|
211
|
+
return () => { stopStatus(); stopPush(); };
|
|
212
|
+
},
|
|
213
|
+
getSnapshot() {
|
|
214
|
+
const { status, push, error } = sync;
|
|
215
|
+
if (current?.status !== status || current.push !== push || !Object.is(current.error, error)) {
|
|
216
|
+
current = Object.freeze({ status, push, error });
|
|
217
|
+
}
|
|
218
|
+
return current;
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
return useSource(source);
|
|
223
|
+
}
|
|
224
|
+
/** The other writers' presence states by client ID, re-rendering when they change. */
|
|
225
|
+
export function usePeers(sync) {
|
|
226
|
+
const source = shared(sync, "peers", () => ({
|
|
227
|
+
subscribe: (listener) => sync.presence.on("change", () => { listener(); }),
|
|
228
|
+
getSnapshot: () => sync.presence.peers,
|
|
229
|
+
}));
|
|
230
|
+
return useSource(source);
|
|
231
|
+
}
|
|
232
|
+
/** `canUndo` and `canRedo` of an undo manager, re-rendering when either changes. */
|
|
233
|
+
export function useUndoState(history) {
|
|
234
|
+
const source = shared(history, "undo", () => {
|
|
235
|
+
let current;
|
|
236
|
+
return {
|
|
237
|
+
subscribe: (listener) => history.on("change", () => { listener(); }),
|
|
238
|
+
getSnapshot() {
|
|
239
|
+
const { canUndo, canRedo } = history;
|
|
240
|
+
if (current?.canUndo !== canUndo || current.canRedo !== canRedo)
|
|
241
|
+
current = Object.freeze({ canUndo, canRedo });
|
|
242
|
+
return current;
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
return useSource(source);
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=index.js.map
|
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E,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;gBACrC,IAAI,OAAO,EAAE,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO;oBAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC/G,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@articollab/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.12.0-beta.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org/",
|
|
7
|
+
"access": "public",
|
|
8
|
+
"tag": "beta"
|
|
9
|
+
},
|
|
10
|
+
"description": "React hooks for Articollab documents and sync clients.",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/EastSun5566/articollab.git",
|
|
14
|
+
"directory": "packages/react"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://eastsun5566.github.io/articollab/",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/EastSun5566/articollab/issues"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"collaboration",
|
|
22
|
+
"realtime",
|
|
23
|
+
"sync",
|
|
24
|
+
"local-first",
|
|
25
|
+
"server-reconciliation"
|
|
26
|
+
],
|
|
27
|
+
"author": {
|
|
28
|
+
"name": "EastSun5566",
|
|
29
|
+
"email": "hi@eastsun.me",
|
|
30
|
+
"url": "https://github.com/EastSun5566"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"type": "module",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=24.0.0"
|
|
36
|
+
},
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"import": "./dist/index.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@articollab/core": "0.12.0-beta.1",
|
|
51
|
+
"@articollab/sync": "0.12.0-beta.1"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": ">=18"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"react": "^19.3.1",
|
|
58
|
+
"@types/react": "^19.3.3"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsc -p tsconfig.build.json"
|
|
62
|
+
}
|
|
6
63
|
}
|