@daasboard/doc 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -0
- package/README.md +6 -2
- package/dist/DocumentAdapter.d.ts +41 -0
- package/dist/DocumentAdapter.js +34 -0
- package/dist/LoroPageDoc.d.ts +137 -0
- package/dist/LoroPageDoc.js +2662 -0
- package/dist/MemoryDocument.d.ts +42 -0
- package/dist/MemoryDocument.js +868 -0
- package/dist/connectors.d.ts +8 -0
- package/dist/connectors.js +44 -0
- package/dist/imageHashes.d.ts +3 -0
- package/dist/imageHashes.js +61 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +12 -0
- package/dist/normalize.d.ts +50 -0
- package/dist/normalize.js +203 -0
- package/dist/presence/RoomPresence.d.ts +107 -0
- package/dist/presence/RoomPresence.js +515 -0
- package/dist/schema.d.ts +728 -0
- package/dist/schema.js +891 -0
- package/dist/text.d.ts +80 -0
- package/dist/text.js +244 -0
- package/dist/textDelta.d.ts +27 -0
- package/dist/textDelta.js +688 -0
- package/dist/transport/WsTransport.d.ts +178 -0
- package/dist/transport/WsTransport.js +1314 -0
- package/dist/transport/connectRoom.d.ts +47 -0
- package/dist/transport/connectRoom.js +303 -0
- package/dist/transport/prefix.d.ts +4 -0
- package/dist/transport/prefix.js +27 -0
- package/dist/transport/slices.d.ts +9 -0
- package/dist/transport/slices.js +151 -0
- package/dist/transport/snapshot.d.ts +46 -0
- package/dist/transport/snapshot.js +248 -0
- package/dist/transport/token.d.ts +2 -0
- package/dist/transport/token.js +6 -0
- package/package.json +34 -3
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { LoroText, Delta } from "loro-crdt";
|
|
2
|
+
import type { TextContent, TextParagraphContent, TextRunContent } from "@daasboard/render-core";
|
|
3
|
+
export declare const HARD_LINE_BREAK = "\u2028";
|
|
4
|
+
export declare const TEXT_STYLE_CONFIG: {
|
|
5
|
+
readonly weight: {
|
|
6
|
+
readonly expand: "after";
|
|
7
|
+
};
|
|
8
|
+
readonly italic: {
|
|
9
|
+
readonly expand: "after";
|
|
10
|
+
};
|
|
11
|
+
readonly underline: {
|
|
12
|
+
readonly expand: "after";
|
|
13
|
+
};
|
|
14
|
+
readonly strike: {
|
|
15
|
+
readonly expand: "after";
|
|
16
|
+
};
|
|
17
|
+
readonly color: {
|
|
18
|
+
readonly expand: "after";
|
|
19
|
+
};
|
|
20
|
+
readonly size: {
|
|
21
|
+
readonly expand: "after";
|
|
22
|
+
};
|
|
23
|
+
readonly family: {
|
|
24
|
+
readonly expand: "after";
|
|
25
|
+
};
|
|
26
|
+
readonly letterSpacing: {
|
|
27
|
+
readonly expand: "after";
|
|
28
|
+
};
|
|
29
|
+
readonly textCase: {
|
|
30
|
+
readonly expand: "after";
|
|
31
|
+
};
|
|
32
|
+
readonly link: {
|
|
33
|
+
readonly expand: "none";
|
|
34
|
+
};
|
|
35
|
+
readonly align: {
|
|
36
|
+
readonly expand: "none";
|
|
37
|
+
};
|
|
38
|
+
readonly lineHeight: {
|
|
39
|
+
readonly expand: "none";
|
|
40
|
+
};
|
|
41
|
+
readonly list: {
|
|
42
|
+
readonly expand: "none";
|
|
43
|
+
};
|
|
44
|
+
readonly indent: {
|
|
45
|
+
readonly expand: "none";
|
|
46
|
+
};
|
|
47
|
+
readonly start: {
|
|
48
|
+
readonly expand: "none";
|
|
49
|
+
};
|
|
50
|
+
readonly checked: {
|
|
51
|
+
readonly expand: "none";
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export declare const INLINE_KEYS: readonly ["weight", "italic", "underline", "strike", "color", "size", "family", "letterSpacing", "textCase", "link"];
|
|
55
|
+
export declare const TEXT_CASES: ReadonlySet<unknown>;
|
|
56
|
+
export declare const PARA_KEYS: readonly ["align", "lineHeight", "list", "indent", "start", "checked"];
|
|
57
|
+
export type Attrs = Record<string, unknown>;
|
|
58
|
+
export interface Flat {
|
|
59
|
+
text: string;
|
|
60
|
+
attrs: Attrs[];
|
|
61
|
+
}
|
|
62
|
+
export declare function isCodePointBoundary(s: string, i: number): boolean;
|
|
63
|
+
export declare function snapDown(s: string, i: number): number;
|
|
64
|
+
export declare function snapUp(s: string, i: number): number;
|
|
65
|
+
export declare function runAttrs(r: TextRunContent): Attrs;
|
|
66
|
+
export declare function paragraphFromAttrs(pa: Attrs, runs: TextRunContent[]): TextParagraphContent;
|
|
67
|
+
export declare function contentToFlat(c: TextContent): Flat;
|
|
68
|
+
export declare function paragraphAttrs(p: TextParagraphContent): Attrs;
|
|
69
|
+
export declare function loroToFlat(t: LoroText): Flat;
|
|
70
|
+
export declare function deltaToFlat(delta: readonly Delta<string>[]): Flat;
|
|
71
|
+
export declare function runFromAttrs(text: string, a: Attrs): TextRunContent;
|
|
72
|
+
export declare function flatToContent(f: Flat): TextContent;
|
|
73
|
+
export declare function readText(t: LoroText): TextContent;
|
|
74
|
+
export declare function readTextFromDelta(delta: readonly Delta<string>[]): TextContent;
|
|
75
|
+
export declare const sameAttrs: (a: Attrs, b: Attrs) => boolean;
|
|
76
|
+
export declare function flatToLoroDelta(f: Flat): Delta<string>[];
|
|
77
|
+
export declare function writeText(t: LoroText, content: TextContent): void;
|
|
78
|
+
export declare function plainText(c: TextContent | undefined): string;
|
|
79
|
+
export declare function isEmptyTextContent(c: TextContent | undefined): boolean;
|
|
80
|
+
export declare function normalizeTextContent(c: TextContent | undefined): TextContent | undefined;
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
export const HARD_LINE_BREAK = "\u2028";
|
|
2
|
+
export const TEXT_STYLE_CONFIG = {
|
|
3
|
+
weight: { expand: "after" },
|
|
4
|
+
italic: { expand: "after" },
|
|
5
|
+
underline: { expand: "after" },
|
|
6
|
+
strike: { expand: "after" },
|
|
7
|
+
color: { expand: "after" },
|
|
8
|
+
size: { expand: "after" },
|
|
9
|
+
family: { expand: "after" },
|
|
10
|
+
letterSpacing: { expand: "after" },
|
|
11
|
+
textCase: { expand: "after" },
|
|
12
|
+
link: { expand: "none" },
|
|
13
|
+
align: { expand: "none" },
|
|
14
|
+
lineHeight: { expand: "none" },
|
|
15
|
+
list: { expand: "none" },
|
|
16
|
+
indent: { expand: "none" },
|
|
17
|
+
start: { expand: "none" },
|
|
18
|
+
checked: { expand: "none" },
|
|
19
|
+
};
|
|
20
|
+
export const INLINE_KEYS = ["weight", "italic", "underline", "strike", "color", "size", "family", "letterSpacing", "textCase", "link"];
|
|
21
|
+
export const TEXT_CASES = new Set(["none", "upper", "lower"]);
|
|
22
|
+
export const PARA_KEYS = ["align", "lineHeight", "list", "indent", "start", "checked"];
|
|
23
|
+
const isHigh = (c) => c >= 0xd800 && c <= 0xdbff;
|
|
24
|
+
const isLow = (c) => c >= 0xdc00 && c <= 0xdfff;
|
|
25
|
+
export function isCodePointBoundary(s, i) {
|
|
26
|
+
return !(i > 0 && i < s.length && isLow(s.charCodeAt(i)) && isHigh(s.charCodeAt(i - 1)));
|
|
27
|
+
}
|
|
28
|
+
export function snapDown(s, i) {
|
|
29
|
+
return isCodePointBoundary(s, i) ? i : i - 1;
|
|
30
|
+
}
|
|
31
|
+
export function snapUp(s, i) {
|
|
32
|
+
return isCodePointBoundary(s, i) ? i : i + 1;
|
|
33
|
+
}
|
|
34
|
+
export function runAttrs(r) {
|
|
35
|
+
const a = {};
|
|
36
|
+
if (r.weight !== undefined)
|
|
37
|
+
a.weight = r.weight;
|
|
38
|
+
if (r.italic !== undefined)
|
|
39
|
+
a.italic = r.italic;
|
|
40
|
+
if (r.underline !== undefined)
|
|
41
|
+
a.underline = r.underline;
|
|
42
|
+
if (r.strike !== undefined)
|
|
43
|
+
a.strike = r.strike;
|
|
44
|
+
if (r.color)
|
|
45
|
+
a.color = r.color;
|
|
46
|
+
if (r.size)
|
|
47
|
+
a.size = r.size;
|
|
48
|
+
if (r.family)
|
|
49
|
+
a.family = r.family;
|
|
50
|
+
if (r.letterSpacing !== undefined)
|
|
51
|
+
a.letterSpacing = r.letterSpacing;
|
|
52
|
+
if (r.textCase)
|
|
53
|
+
a.textCase = r.textCase;
|
|
54
|
+
if (r.link)
|
|
55
|
+
a.link = r.link;
|
|
56
|
+
return a;
|
|
57
|
+
}
|
|
58
|
+
const LIST_KINDS = new Set(["bullet", "number", "task"]);
|
|
59
|
+
export function paragraphFromAttrs(pa, runs) {
|
|
60
|
+
const p = { runs };
|
|
61
|
+
if (typeof pa.align === "string")
|
|
62
|
+
p.align = pa.align;
|
|
63
|
+
if (typeof pa.lineHeight === "number")
|
|
64
|
+
p.lineHeight = pa.lineHeight;
|
|
65
|
+
if (LIST_KINDS.has(pa.list))
|
|
66
|
+
p.list = pa.list;
|
|
67
|
+
if (typeof pa.indent === "number" && pa.indent)
|
|
68
|
+
p.indent = pa.indent;
|
|
69
|
+
if (typeof pa.start === "number")
|
|
70
|
+
p.start = pa.start;
|
|
71
|
+
if (pa.checked === true)
|
|
72
|
+
p.checked = true;
|
|
73
|
+
return p;
|
|
74
|
+
}
|
|
75
|
+
export function contentToFlat(c) {
|
|
76
|
+
let text = "";
|
|
77
|
+
const attrs = [];
|
|
78
|
+
if (c.paragraphs.length === 0)
|
|
79
|
+
return { text: "\n", attrs: [{}] };
|
|
80
|
+
for (const p of c.paragraphs) {
|
|
81
|
+
for (const r of p.runs) {
|
|
82
|
+
const a = runAttrs(r);
|
|
83
|
+
text += r.text;
|
|
84
|
+
for (let i = 0; i < r.text.length; i++)
|
|
85
|
+
attrs.push(a);
|
|
86
|
+
}
|
|
87
|
+
text += "\n";
|
|
88
|
+
attrs.push(paragraphAttrs(p));
|
|
89
|
+
}
|
|
90
|
+
return { text, attrs };
|
|
91
|
+
}
|
|
92
|
+
export function paragraphAttrs(p) {
|
|
93
|
+
const pa = {};
|
|
94
|
+
if (p.align)
|
|
95
|
+
pa.align = p.align;
|
|
96
|
+
if (p.lineHeight !== undefined)
|
|
97
|
+
pa.lineHeight = p.lineHeight;
|
|
98
|
+
if (p.list)
|
|
99
|
+
pa.list = p.list;
|
|
100
|
+
if (p.indent)
|
|
101
|
+
pa.indent = p.indent;
|
|
102
|
+
if (p.start !== undefined)
|
|
103
|
+
pa.start = p.start;
|
|
104
|
+
if (p.checked)
|
|
105
|
+
pa.checked = true;
|
|
106
|
+
return pa;
|
|
107
|
+
}
|
|
108
|
+
export function loroToFlat(t) {
|
|
109
|
+
return deltaToFlat(t.toDelta());
|
|
110
|
+
}
|
|
111
|
+
export function deltaToFlat(delta) {
|
|
112
|
+
let s = "";
|
|
113
|
+
const attrs = [];
|
|
114
|
+
for (const op of delta) {
|
|
115
|
+
const ins = op.insert;
|
|
116
|
+
const a = (op.attributes ?? {});
|
|
117
|
+
s += ins;
|
|
118
|
+
for (let i = 0; i < ins.length; i++)
|
|
119
|
+
attrs.push(a);
|
|
120
|
+
}
|
|
121
|
+
if (!s.endsWith("\n")) {
|
|
122
|
+
s += "\n";
|
|
123
|
+
attrs.push({});
|
|
124
|
+
}
|
|
125
|
+
return { text: s, attrs };
|
|
126
|
+
}
|
|
127
|
+
const sameInline = (a, b) => {
|
|
128
|
+
if (a === b)
|
|
129
|
+
return true;
|
|
130
|
+
for (const k of INLINE_KEYS)
|
|
131
|
+
if (a[k] !== b[k])
|
|
132
|
+
return false;
|
|
133
|
+
return true;
|
|
134
|
+
};
|
|
135
|
+
export function runFromAttrs(text, a) {
|
|
136
|
+
const run = { text };
|
|
137
|
+
if (typeof a.weight === "number")
|
|
138
|
+
run.weight = a.weight;
|
|
139
|
+
if (typeof a.italic === "boolean")
|
|
140
|
+
run.italic = a.italic;
|
|
141
|
+
if (typeof a.underline === "boolean")
|
|
142
|
+
run.underline = a.underline;
|
|
143
|
+
if (typeof a.strike === "boolean")
|
|
144
|
+
run.strike = a.strike;
|
|
145
|
+
if (typeof a.color === "string")
|
|
146
|
+
run.color = a.color;
|
|
147
|
+
if (typeof a.size === "number")
|
|
148
|
+
run.size = a.size;
|
|
149
|
+
if (typeof a.family === "string")
|
|
150
|
+
run.family = a.family;
|
|
151
|
+
if (typeof a.letterSpacing === "number")
|
|
152
|
+
run.letterSpacing = a.letterSpacing;
|
|
153
|
+
if (TEXT_CASES.has(a.textCase))
|
|
154
|
+
run.textCase = a.textCase;
|
|
155
|
+
if (typeof a.link === "string")
|
|
156
|
+
run.link = a.link;
|
|
157
|
+
return run;
|
|
158
|
+
}
|
|
159
|
+
export function flatToContent(f) {
|
|
160
|
+
const paragraphs = [];
|
|
161
|
+
let runs = [];
|
|
162
|
+
let runStart = 0;
|
|
163
|
+
const { text, attrs } = f;
|
|
164
|
+
const flush = (end) => {
|
|
165
|
+
if (end > runStart) {
|
|
166
|
+
const a = attrs[runStart];
|
|
167
|
+
runs.push(runFromAttrs(text.slice(runStart, end), a));
|
|
168
|
+
}
|
|
169
|
+
runStart = end;
|
|
170
|
+
};
|
|
171
|
+
for (let i = 0; i < text.length; i++) {
|
|
172
|
+
if (text.charCodeAt(i) === 10) {
|
|
173
|
+
flush(i);
|
|
174
|
+
paragraphs.push(paragraphFromAttrs(attrs[i], runs));
|
|
175
|
+
runs = [];
|
|
176
|
+
runStart = i + 1;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (i > runStart && !sameInline(attrs[i], attrs[i - 1]))
|
|
180
|
+
flush(i);
|
|
181
|
+
}
|
|
182
|
+
if (paragraphs.length === 0)
|
|
183
|
+
paragraphs.push({ runs: [] });
|
|
184
|
+
return { paragraphs };
|
|
185
|
+
}
|
|
186
|
+
export function readText(t) {
|
|
187
|
+
return flatToContent(loroToFlat(t));
|
|
188
|
+
}
|
|
189
|
+
export function readTextFromDelta(delta) {
|
|
190
|
+
return flatToContent(deltaToFlat(delta));
|
|
191
|
+
}
|
|
192
|
+
const isSet = (v) => v !== undefined && v !== null;
|
|
193
|
+
export const sameAttrs = (a, b) => {
|
|
194
|
+
if (a === b)
|
|
195
|
+
return true;
|
|
196
|
+
const ka = Object.keys(a).filter((k) => isSet(a[k]));
|
|
197
|
+
const kb = Object.keys(b).filter((k) => isSet(b[k]));
|
|
198
|
+
return ka.length === kb.length && ka.every((k) => a[k] === b[k]);
|
|
199
|
+
};
|
|
200
|
+
export function flatToLoroDelta(f) {
|
|
201
|
+
const ops = [];
|
|
202
|
+
let i = 0;
|
|
203
|
+
while (i < f.text.length) {
|
|
204
|
+
const a = f.attrs[i];
|
|
205
|
+
let j = i + 1;
|
|
206
|
+
while (j < f.text.length && sameAttrs(f.attrs[j], a))
|
|
207
|
+
j++;
|
|
208
|
+
const attributes = {};
|
|
209
|
+
let any = false;
|
|
210
|
+
for (const [k, v] of Object.entries(a))
|
|
211
|
+
if (isSet(v)) {
|
|
212
|
+
attributes[k] = v;
|
|
213
|
+
any = true;
|
|
214
|
+
}
|
|
215
|
+
ops.push(any ? { insert: f.text.slice(i, j), attributes } : { insert: f.text.slice(i, j) });
|
|
216
|
+
i = j;
|
|
217
|
+
}
|
|
218
|
+
return ops;
|
|
219
|
+
}
|
|
220
|
+
export function writeText(t, content) {
|
|
221
|
+
const target = contentToFlat(content);
|
|
222
|
+
const len = t.length;
|
|
223
|
+
if (len)
|
|
224
|
+
t.delete(0, len);
|
|
225
|
+
const ops = flatToLoroDelta(target);
|
|
226
|
+
if (ops.length)
|
|
227
|
+
t.applyDelta(ops);
|
|
228
|
+
}
|
|
229
|
+
export function plainText(c) {
|
|
230
|
+
return c ? c.paragraphs.map((p) => p.runs.map((r) => r.text).join("")).join("\n") : "";
|
|
231
|
+
}
|
|
232
|
+
export function isEmptyTextContent(c) {
|
|
233
|
+
if (!c)
|
|
234
|
+
return true;
|
|
235
|
+
if (c.paragraphs.length === 0)
|
|
236
|
+
return true;
|
|
237
|
+
if (c.paragraphs.length !== 1)
|
|
238
|
+
return false;
|
|
239
|
+
const p = c.paragraphs[0];
|
|
240
|
+
return p.runs.every((r) => r.text.length === 0) && !p.align && !p.list && !p.indent && p.lineHeight === undefined && p.start === undefined && !p.checked;
|
|
241
|
+
}
|
|
242
|
+
export function normalizeTextContent(c) {
|
|
243
|
+
return isEmptyTextContent(c) ? undefined : c;
|
|
244
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LoroText, Delta } from "loro-crdt";
|
|
2
|
+
import type { TextContent } from "@daasboard/render-core";
|
|
3
|
+
import type { TextDelta } from "./DocumentAdapter.js";
|
|
4
|
+
import { type Flat } from "./text.js";
|
|
5
|
+
export declare const isClearValue: (v: unknown) => boolean;
|
|
6
|
+
export declare function emptyTextContent(): TextContent;
|
|
7
|
+
export declare function textDeltaIsKeystroke(delta: TextDelta): boolean;
|
|
8
|
+
export declare function textDeltaIsEmpty(delta: TextDelta): boolean;
|
|
9
|
+
export declare function textDeltaOnlyClears(delta: TextDelta): boolean;
|
|
10
|
+
export declare function sameTextContent(a: TextContent, b: TextContent): boolean;
|
|
11
|
+
export declare function applyDeltaToString(text: string, delta: TextDelta): string;
|
|
12
|
+
export declare function textAfterDelta(text: string, delta: TextDelta): string;
|
|
13
|
+
export declare function formatChangesLoroText(ops: readonly Delta<string>[], delta: TextDelta): boolean;
|
|
14
|
+
export declare function rewriteDelta(cur: Flat, target: Flat): TextDelta;
|
|
15
|
+
export declare function deltaLength(delta: TextDelta): number;
|
|
16
|
+
export declare function validateTextAttributes(attributes: Record<string, unknown> | undefined, i: number): void;
|
|
17
|
+
export declare function validateTextDelta(text: string, delta: TextDelta): void;
|
|
18
|
+
export declare function applyTextDelta(content: TextContent, delta: TextDelta): TextContent;
|
|
19
|
+
export declare function flatTextOf(content: TextContent): string;
|
|
20
|
+
export declare function applyTextDeltaToParagraphs(content: TextContent, delta: TextDelta): {
|
|
21
|
+
content: TextContent;
|
|
22
|
+
changed: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function toLoroDelta(delta: TextDelta): Delta<string>[];
|
|
25
|
+
export declare function splitDeleteAtAstral(text: string, pos: number, n: number): number[];
|
|
26
|
+
export declare function applyLoroDelta(t: LoroText, cur: string, delta: TextDelta): void;
|
|
27
|
+
export declare function ensureTrailingNewline(t: LoroText): string;
|