@g9tm/lynxcontrols-richtext 2.5.10 → 2.5.11

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/ot.js ADDED
@@ -0,0 +1,308 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) Object.defineProperty(obj, key, {
3
+ value: value,
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true
7
+ });
8
+ else obj[key] = value;
9
+ return obj;
10
+ }
11
+ class TextOp {
12
+ retain(n) {
13
+ if (n <= 0) return this;
14
+ this.baseLength += n;
15
+ this.targetLength += n;
16
+ const last = this.ops[this.ops.length - 1];
17
+ if ('number' == typeof last && last > 0) this.ops[this.ops.length - 1] = last + n;
18
+ else this.ops.push(n);
19
+ return this;
20
+ }
21
+ insert(text) {
22
+ if (!text) return this;
23
+ this.targetLength += text.length;
24
+ const ops = this.ops;
25
+ const last = ops[ops.length - 1];
26
+ if ('string' == typeof last) ops[ops.length - 1] = last + text;
27
+ else if ('number' == typeof last && last < 0) {
28
+ const before = ops[ops.length - 2];
29
+ if ('string' == typeof before) ops[ops.length - 2] = before + text;
30
+ else {
31
+ ops[ops.length] = last;
32
+ ops[ops.length - 2] = text;
33
+ }
34
+ } else ops.push(text);
35
+ return this;
36
+ }
37
+ delete(n) {
38
+ if (n <= 0) return this;
39
+ this.baseLength += n;
40
+ const last = this.ops[this.ops.length - 1];
41
+ if ('number' == typeof last && last < 0) this.ops[this.ops.length - 1] = last - n;
42
+ else this.ops.push(-n);
43
+ return this;
44
+ }
45
+ isNoop() {
46
+ return 0 === this.ops.length || 1 === this.ops.length && 'number' == typeof this.ops[0] && this.ops[0] > 0;
47
+ }
48
+ apply(text) {
49
+ if (text.length !== this.baseLength) throw new Error(`TextOp: base length ${this.baseLength} ≠ text length ${text.length}`);
50
+ let out = '';
51
+ let at = 0;
52
+ for (const op of this.ops)if ('string' == typeof op) out += op;
53
+ else if (op > 0) {
54
+ out += text.slice(at, at + op);
55
+ at += op;
56
+ } else at -= op;
57
+ return out;
58
+ }
59
+ toReplacements() {
60
+ const out = [];
61
+ let at = 0;
62
+ for(let i = 0; i < this.ops.length; i++){
63
+ const op = this.ops[i];
64
+ if ('number' == typeof op && op > 0) {
65
+ at += op;
66
+ continue;
67
+ }
68
+ let text = '';
69
+ let removed = 0;
70
+ while(i < this.ops.length && !('number' == typeof this.ops[i] && this.ops[i] > 0)){
71
+ const part = this.ops[i];
72
+ if ('string' == typeof part) text += part;
73
+ else removed -= part;
74
+ i++;
75
+ }
76
+ i--;
77
+ out.push({
78
+ from: at,
79
+ to: at + removed,
80
+ text
81
+ });
82
+ at += text.length;
83
+ }
84
+ return out;
85
+ }
86
+ map(pos, assoc = -1) {
87
+ let base = 0;
88
+ let target = 0;
89
+ for (const op of this.ops)if ('string' == typeof op) {
90
+ if (base === pos && assoc < 0) return target;
91
+ target += op.length;
92
+ } else if (op > 0) {
93
+ if (pos < base + op || pos === base + op && assoc < 0) return target + (pos - base);
94
+ base += op;
95
+ target += op;
96
+ } else {
97
+ if (pos < base - op) return target;
98
+ base -= op;
99
+ }
100
+ return target;
101
+ }
102
+ static replace(length, from, to, text) {
103
+ const f = Math.max(0, Math.min(from, length));
104
+ const t = Math.max(f, Math.min(to, length));
105
+ return new TextOp().retain(f).delete(t - f).insert(text).retain(length - t);
106
+ }
107
+ static identity(length) {
108
+ return new TextOp().retain(length);
109
+ }
110
+ constructor(){
111
+ _define_property(this, "ops", []);
112
+ _define_property(this, "baseLength", 0);
113
+ _define_property(this, "targetLength", 0);
114
+ }
115
+ }
116
+ function compose(a, b) {
117
+ if (a.targetLength !== b.baseLength) throw new Error('compose: lengths do not match');
118
+ const out = new TextOp();
119
+ const ops1 = a.ops;
120
+ const ops2 = b.ops;
121
+ let i1 = 0;
122
+ let i2 = 0;
123
+ let op1 = ops1[i1++];
124
+ let op2 = ops2[i2++];
125
+ for(;;){
126
+ if (void 0 === op1 && void 0 === op2) break;
127
+ if ('number' == typeof op1 && op1 < 0) {
128
+ out.delete(-op1);
129
+ op1 = ops1[i1++];
130
+ continue;
131
+ }
132
+ if ('string' == typeof op2) {
133
+ out.insert(op2);
134
+ op2 = ops2[i2++];
135
+ continue;
136
+ }
137
+ if (void 0 === op1 || void 0 === op2) throw new Error('compose: operation too short');
138
+ if ('number' == typeof op1 && 'number' == typeof op2 && op1 > 0 && op2 > 0) if (op1 > op2) {
139
+ out.retain(op2);
140
+ op1 -= op2;
141
+ op2 = ops2[i2++];
142
+ } else if (op1 === op2) {
143
+ out.retain(op1);
144
+ op1 = ops1[i1++];
145
+ op2 = ops2[i2++];
146
+ } else {
147
+ out.retain(op1);
148
+ op2 -= op1;
149
+ op1 = ops1[i1++];
150
+ }
151
+ else if ('string' == typeof op1 && 'number' == typeof op2 && op2 < 0) if (op1.length > -op2) {
152
+ op1 = op1.slice(-op2);
153
+ op2 = ops2[i2++];
154
+ } else if (op1.length === -op2) {
155
+ op1 = ops1[i1++];
156
+ op2 = ops2[i2++];
157
+ } else {
158
+ op2 += op1.length;
159
+ op1 = ops1[i1++];
160
+ }
161
+ else if ('string' == typeof op1 && 'number' == typeof op2 && op2 > 0) if (op1.length > op2) {
162
+ out.insert(op1.slice(0, op2));
163
+ op1 = op1.slice(op2);
164
+ op2 = ops2[i2++];
165
+ } else if (op1.length === op2) {
166
+ out.insert(op1);
167
+ op1 = ops1[i1++];
168
+ op2 = ops2[i2++];
169
+ } else {
170
+ out.insert(op1);
171
+ op2 -= op1.length;
172
+ op1 = ops1[i1++];
173
+ }
174
+ else if ('number' == typeof op1 && op1 > 0 && 'number' == typeof op2 && op2 < 0) if (op1 > -op2) {
175
+ out.delete(-op2);
176
+ op1 += op2;
177
+ op2 = ops2[i2++];
178
+ } else if (op1 === -op2) {
179
+ out.delete(-op2);
180
+ op1 = ops1[i1++];
181
+ op2 = ops2[i2++];
182
+ } else {
183
+ out.delete(op1);
184
+ op2 += op1;
185
+ op1 = ops1[i1++];
186
+ }
187
+ else throw new Error('compose: unexpected components');
188
+ }
189
+ return out;
190
+ }
191
+ function transform(a, b) {
192
+ if (a.baseLength !== b.baseLength) throw new Error('transform: base lengths differ');
193
+ const a1 = new TextOp();
194
+ const b1 = new TextOp();
195
+ const ops1 = a.ops;
196
+ const ops2 = b.ops;
197
+ let i1 = 0;
198
+ let i2 = 0;
199
+ let op1 = ops1[i1++];
200
+ let op2 = ops2[i2++];
201
+ for(;;){
202
+ if (void 0 === op1 && void 0 === op2) break;
203
+ if ('string' == typeof op1) {
204
+ a1.insert(op1);
205
+ b1.retain(op1.length);
206
+ op1 = ops1[i1++];
207
+ continue;
208
+ }
209
+ if ('string' == typeof op2) {
210
+ a1.retain(op2.length);
211
+ b1.insert(op2);
212
+ op2 = ops2[i2++];
213
+ continue;
214
+ }
215
+ if (void 0 === op1 || void 0 === op2) throw new Error('transform: operation too short');
216
+ let min;
217
+ if (op1 > 0 && op2 > 0) {
218
+ if (op1 > op2) {
219
+ min = op2;
220
+ op1 -= op2;
221
+ op2 = ops2[i2++];
222
+ } else if (op1 === op2) {
223
+ min = op2;
224
+ op1 = ops1[i1++];
225
+ op2 = ops2[i2++];
226
+ } else {
227
+ min = op1;
228
+ op2 -= op1;
229
+ op1 = ops1[i1++];
230
+ }
231
+ a1.retain(min);
232
+ b1.retain(min);
233
+ } else if (op1 < 0 && op2 < 0) if (-op1 > -op2) {
234
+ op1 -= op2;
235
+ op2 = ops2[i2++];
236
+ } else if (op1 === op2) {
237
+ op1 = ops1[i1++];
238
+ op2 = ops2[i2++];
239
+ } else {
240
+ op2 -= op1;
241
+ op1 = ops1[i1++];
242
+ }
243
+ else if (op1 < 0 && op2 > 0) {
244
+ if (-op1 > op2) {
245
+ min = op2;
246
+ op1 += op2;
247
+ op2 = ops2[i2++];
248
+ } else if (-op1 === op2) {
249
+ min = op2;
250
+ op1 = ops1[i1++];
251
+ op2 = ops2[i2++];
252
+ } else {
253
+ min = -op1;
254
+ op2 += op1;
255
+ op1 = ops1[i1++];
256
+ }
257
+ a1.delete(min);
258
+ } else {
259
+ const r = op1;
260
+ const d = op2;
261
+ if (r > -d) {
262
+ min = -d;
263
+ op1 = r + d;
264
+ op2 = ops2[i2++];
265
+ } else if (r === -d) {
266
+ min = r;
267
+ op1 = ops1[i1++];
268
+ op2 = ops2[i2++];
269
+ } else {
270
+ min = r;
271
+ op2 = d + r;
272
+ op1 = ops1[i1++];
273
+ }
274
+ b1.delete(min);
275
+ }
276
+ }
277
+ return [
278
+ a1,
279
+ b1
280
+ ];
281
+ }
282
+ function diff(before, after, hint = -1) {
283
+ if (before === after) return TextOp.identity(before.length);
284
+ const max = Math.min(before.length, after.length);
285
+ let prefix = 0;
286
+ while(prefix < max && before.charCodeAt(prefix) === after.charCodeAt(prefix))prefix++;
287
+ let suffix = 0;
288
+ while(suffix < max - prefix && before.charCodeAt(before.length - 1 - suffix) === after.charCodeAt(after.length - 1 - suffix))suffix++;
289
+ while(hint >= 0 && prefix > hint){
290
+ const c = before.charCodeAt(prefix - 1);
291
+ const removedEnd = before.length - suffix - 1;
292
+ const insertedEnd = after.length - suffix - 1;
293
+ const removedOk = removedEnd < prefix || before.charCodeAt(removedEnd) === c;
294
+ const insertedOk = insertedEnd < prefix || after.charCodeAt(insertedEnd) === c;
295
+ if (!removedOk || !insertedOk) break;
296
+ prefix--;
297
+ suffix++;
298
+ }
299
+ return new TextOp().retain(prefix).delete(before.length - prefix - suffix).insert(after.slice(prefix, after.length - suffix)).retain(suffix);
300
+ }
301
+ function fromReplacements(length, replacements) {
302
+ let op = TextOp.identity(length);
303
+ for (const r of replacements)op = compose(op, TextOp.replace(op.targetLength, r.from, r.to, r.text));
304
+ return op;
305
+ }
306
+ export { TextOp, compose, diff, fromReplacements, transform };
307
+
308
+ //# sourceMappingURL=ot.js.map
package/dist/ot.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ot.js","sources":["../src/ot.ts"],"sourcesContent":["/**\n * Plain-text operations between the `<g9-richtext>` element and the document model (the classic retain/insert/delete\n * operation of ot.js, re-implemented): the element edits a flat text and reports each change as a replacement; the\n * model may have moved on meanwhile (a collaborator typed, a command reshaped a block), so both sides' changes are\n * transformed against each other (Jupiter, see session.ts) and the element receives exactly the operations that turn its\n * text into the model's. Inserts at the same place: the side passed first to {@link transform} goes first.\n *\n * Components: a positive number retains, a negative number deletes, a string inserts.\n */\nexport type Component = number | string;\n\n/** An operation on a text (retain, insert, delete), composed and transformed. */\nexport class TextOp {\n readonly ops: Component[] = [];\n baseLength = 0;\n targetLength = 0;\n\n retain(n: number): this {\n if (n <= 0) return this;\n this.baseLength += n;\n this.targetLength += n;\n const last = this.ops[this.ops.length - 1];\n if (typeof last === 'number' && last > 0) this.ops[this.ops.length - 1] = last + n;\n else this.ops.push(n);\n return this;\n }\n\n insert(text: string): this {\n if (!text) return this;\n this.targetLength += text.length;\n const ops = this.ops;\n const last = ops[ops.length - 1];\n if (typeof last === 'string') ops[ops.length - 1] = last + text;\n else if (typeof last === 'number' && last < 0) {\n // Keep inserts before deletes (a canonical form, so equal operations compare equal).\n const before = ops[ops.length - 2];\n if (typeof before === 'string') ops[ops.length - 2] = before + text;\n else {\n ops[ops.length] = last;\n ops[ops.length - 2] = text;\n }\n } else ops.push(text);\n return this;\n }\n\n delete(n: number): this {\n if (n <= 0) return this;\n this.baseLength += n;\n const last = this.ops[this.ops.length - 1];\n if (typeof last === 'number' && last < 0) this.ops[this.ops.length - 1] = last - n;\n else this.ops.push(-n);\n return this;\n }\n\n isNoop(): boolean {\n return this.ops.length === 0 || (this.ops.length === 1 && typeof this.ops[0] === 'number' && this.ops[0] > 0);\n }\n\n apply(text: string): string {\n if (text.length !== this.baseLength)\n throw new Error(`TextOp: base length ${this.baseLength} ≠ text length ${text.length}`);\n let out = '';\n let at = 0;\n for (const op of this.ops) {\n if (typeof op === 'string') out += op;\n else if (op > 0) {\n out += text.slice(at, at + op);\n at += op;\n } else at -= op;\n }\n return out;\n }\n\n /** The operation as sequential replacements (positions in the text as it is after the previous ones). */\n toReplacements(): Replacement[] {\n const out: Replacement[] = [];\n let at = 0;\n for (let i = 0; i < this.ops.length; i++) {\n const op = this.ops[i];\n if (typeof op === 'number' && op > 0) {\n at += op;\n continue;\n }\n let text = '';\n let removed = 0;\n while (i < this.ops.length && !(typeof this.ops[i] === 'number' && (this.ops[i] as number) > 0)) {\n const part = this.ops[i];\n if (typeof part === 'string') text += part;\n else removed -= part;\n i++;\n }\n i--;\n out.push({ from: at, to: at + removed, text });\n at += text.length;\n }\n return out;\n }\n\n /** Maps a position in the base text to the target text (`assoc` < 0 keeps it before text inserted right there). */\n map(pos: number, assoc = -1): number {\n let base = 0;\n let target = 0;\n for (const op of this.ops) {\n if (typeof op === 'string') {\n if (base === pos && assoc < 0) return target;\n target += op.length;\n } else if (op > 0) {\n if (pos < base + op || (pos === base + op && assoc < 0)) return target + (pos - base);\n base += op;\n target += op;\n } else {\n // Inside a deleted range: where the range was.\n if (pos < base - op) return target;\n base -= op;\n }\n }\n return target;\n }\n\n static replace(length: number, from: number, to: number, text: string): TextOp {\n const f = Math.max(0, Math.min(from, length));\n const t = Math.max(f, Math.min(to, length));\n return new TextOp()\n .retain(f)\n .delete(t - f)\n .insert(text)\n .retain(length - t);\n }\n\n static identity(length: number): TextOp {\n return new TextOp().retain(length);\n }\n}\n\n/** A replaced range and its new text. */\nexport interface Replacement {\n from: number;\n to: number;\n text: string;\n}\n\n/** `a` then `b` as one operation. */\nexport function compose(a: TextOp, b: TextOp): TextOp {\n if (a.targetLength !== b.baseLength) throw new Error('compose: lengths do not match');\n const out = new TextOp();\n const ops1 = a.ops;\n const ops2 = b.ops;\n let i1 = 0;\n let i2 = 0;\n let op1: Component | undefined = ops1[i1++];\n let op2: Component | undefined = ops2[i2++];\n for (;;) {\n if (op1 === undefined && op2 === undefined) break;\n if (typeof op1 === 'number' && op1 < 0) {\n out.delete(-op1);\n op1 = ops1[i1++];\n continue;\n }\n if (typeof op2 === 'string') {\n out.insert(op2);\n op2 = ops2[i2++];\n continue;\n }\n if (op1 === undefined || op2 === undefined) throw new Error('compose: operation too short');\n if (typeof op1 === 'number' && typeof op2 === 'number' && op1 > 0 && op2 > 0) {\n if (op1 > op2) {\n out.retain(op2);\n op1 -= op2;\n op2 = ops2[i2++];\n } else if (op1 === op2) {\n out.retain(op1);\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n out.retain(op1);\n op2 -= op1;\n op1 = ops1[i1++];\n }\n } else if (typeof op1 === 'string' && typeof op2 === 'number' && op2 < 0) {\n if (op1.length > -op2) {\n op1 = op1.slice(-op2);\n op2 = ops2[i2++];\n } else if (op1.length === -op2) {\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n op2 = op2 + op1.length;\n op1 = ops1[i1++];\n }\n } else if (typeof op1 === 'string' && typeof op2 === 'number' && op2 > 0) {\n if (op1.length > op2) {\n out.insert(op1.slice(0, op2));\n op1 = op1.slice(op2);\n op2 = ops2[i2++];\n } else if (op1.length === op2) {\n out.insert(op1);\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n out.insert(op1);\n op2 = op2 - op1.length;\n op1 = ops1[i1++];\n }\n } else if (typeof op1 === 'number' && op1 > 0 && typeof op2 === 'number' && op2 < 0) {\n if (op1 > -op2) {\n out.delete(-op2);\n op1 = op1 + op2;\n op2 = ops2[i2++];\n } else if (op1 === -op2) {\n out.delete(-op2);\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n out.delete(op1);\n op2 = op2 + op1;\n op1 = ops1[i1++];\n }\n } else throw new Error('compose: unexpected components');\n }\n return out;\n}\n\n/**\n * `a` and `b` were made on the same text; returns `[a', b']` with apply(apply(s, a), b') === apply(apply(s, b), a').\n * Inserts at one place: `a`'s first.\n */\nexport function transform(a: TextOp, b: TextOp): [TextOp, TextOp] {\n if (a.baseLength !== b.baseLength) throw new Error('transform: base lengths differ');\n const a1 = new TextOp();\n const b1 = new TextOp();\n const ops1 = a.ops;\n const ops2 = b.ops;\n let i1 = 0;\n let i2 = 0;\n let op1: Component | undefined = ops1[i1++];\n let op2: Component | undefined = ops2[i2++];\n for (;;) {\n if (op1 === undefined && op2 === undefined) break;\n if (typeof op1 === 'string') {\n a1.insert(op1);\n b1.retain(op1.length);\n op1 = ops1[i1++];\n continue;\n }\n if (typeof op2 === 'string') {\n a1.retain(op2.length);\n b1.insert(op2);\n op2 = ops2[i2++];\n continue;\n }\n if (op1 === undefined || op2 === undefined) throw new Error('transform: operation too short');\n let min: number;\n if (op1 > 0 && op2 > 0) {\n if (op1 > op2) {\n min = op2;\n op1 -= op2;\n op2 = ops2[i2++];\n } else if (op1 === op2) {\n min = op2;\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n min = op1;\n op2 -= op1;\n op1 = ops1[i1++];\n }\n a1.retain(min);\n b1.retain(min);\n } else if (op1 < 0 && op2 < 0) {\n if (-op1 > -op2) {\n op1 -= op2;\n op2 = ops2[i2++];\n } else if (op1 === op2) {\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n op2 -= op1;\n op1 = ops1[i1++];\n }\n } else if (op1 < 0 && op2 > 0) {\n if (-op1 > op2) {\n min = op2;\n op1 += op2;\n op2 = ops2[i2++];\n } else if (-op1 === op2) {\n min = op2;\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n min = -op1;\n op2 += op1;\n op1 = ops1[i1++];\n }\n a1.delete(min);\n } else {\n // op1 retains, op2 deletes\n const r = op1 as number;\n const d = op2 as number;\n if (r > -d) {\n min = -d;\n op1 = r + d;\n op2 = ops2[i2++];\n } else if (r === -d) {\n min = r;\n op1 = ops1[i1++];\n op2 = ops2[i2++];\n } else {\n min = r;\n op2 = d + r;\n op1 = ops1[i1++];\n }\n b1.delete(min);\n }\n }\n return [a1, b1];\n}\n\n/**\n * The smallest single replacement turning `before` into `after` (common prefix and suffix). `hint`: a position the\n * change is known to touch (the caret) — among equal answers the one closest to it is taken, so typing \"a\" after \"a\"\n * is an insert at the caret, not at the start of the run.\n */\nexport function diff(before: string, after: string, hint = -1): TextOp {\n if (before === after) return TextOp.identity(before.length);\n const max = Math.min(before.length, after.length);\n let prefix = 0;\n while (prefix < max && before.charCodeAt(prefix) === after.charCodeAt(prefix)) prefix++;\n let suffix = 0;\n while (\n suffix < max - prefix &&\n before.charCodeAt(before.length - 1 - suffix) === after.charCodeAt(after.length - 1 - suffix)\n )\n suffix++;\n // A change inside a run of equal characters can be placed anywhere in the run: slide it back towards the hint while\n // the character leaving the prefix equals the last character of both the removed and the inserted part.\n while (hint >= 0 && prefix > hint) {\n const c = before.charCodeAt(prefix - 1);\n const removedEnd = before.length - suffix - 1;\n const insertedEnd = after.length - suffix - 1;\n const removedOk = removedEnd < prefix || before.charCodeAt(removedEnd) === c;\n const insertedOk = insertedEnd < prefix || after.charCodeAt(insertedEnd) === c;\n if (!removedOk || !insertedOk) break;\n prefix--;\n suffix++;\n }\n return new TextOp()\n .retain(prefix)\n .delete(before.length - prefix - suffix)\n .insert(after.slice(prefix, after.length - suffix))\n .retain(suffix);\n}\n\n/** Several replacements (sequential positions) as one operation on a text of `length`. */\nexport function fromReplacements(length: number, replacements: Replacement[]): TextOp {\n let op = TextOp.identity(length);\n for (const r of replacements) op = compose(op, TextOp.replace(op.targetLength, r.from, r.to, r.text));\n return op;\n}\n"],"names":["TextOp","n","last","text","ops","before","Error","out","at","op","i","removed","part","pos","assoc","base","target","length","from","to","f","Math","t","compose","a","b","ops1","ops2","i1","i2","op1","op2","undefined","transform","a1","b1","min","r","d","diff","after","hint","max","prefix","suffix","c","removedEnd","insertedEnd","removedOk","insertedOk","fromReplacements","replacements"],"mappings":"AAQC;;;;;;;;;;AAIM,MAAMA;IAKX,OAAOC,CAAS,EAAQ;QACtB,IAAIA,KAAK,GAAG,OAAO,IAAI;QACvB,IAAI,CAAC,UAAU,IAAIA;QACnB,IAAI,CAAC,YAAY,IAAIA;QACrB,MAAMC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE;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O,MAAM,GAAG,IAAIuC,YAAYJ,MAAM,UAAU,CAACA,MAAM,MAAM,GAAG,IAAII,QAEtFA;IAGF,MAAOH,QAAQ,KAAKE,SAASF,KAAM;QACjC,MAAMI,IAAIxC,OAAO,UAAU,CAACsC,SAAS;QACrC,MAAMG,aAAazC,OAAO,MAAM,GAAGuC,SAAS;QAC5C,MAAMG,cAAcP,MAAM,MAAM,GAAGI,SAAS;QAC5C,MAAMI,YAAYF,aAAaH,UAAUtC,OAAO,UAAU,CAACyC,gBAAgBD;QAC3E,MAAMI,aAAaF,cAAcJ,UAAUH,MAAM,UAAU,CAACO,iBAAiBF;QAC7E,IAAI,CAACG,aAAa,CAACC,YAAY;QAC/BN;QACAC;IACF;IACA,OAAO,IAAI5C,SACR,MAAM,CAAC2C,QACP,MAAM,CAACtC,OAAO,MAAM,GAAGsC,SAASC,QAChC,MAAM,CAACJ,MAAM,KAAK,CAACG,QAAQH,MAAM,MAAM,GAAGI,SAC1C,MAAM,CAACA;AACZ;AAGO,SAASM,iBAAiBjC,MAAc,EAAEkC,YAA2B;IAC1E,IAAI1C,KAAKT,OAAO,QAAQ,CAACiB;IACzB,KAAK,MAAMoB,KAAKc,aAAc1C,KAAKc,QAAQd,IAAIT,OAAO,OAAO,CAACS,GAAG,YAAY,EAAE4B,EAAE,IAAI,EAAEA,EAAE,EAAE,EAAEA,EAAE,IAAI;IACnG,OAAO5B;AACT"}
@@ -0,0 +1,13 @@
1
+ const MARK = {
2
+ bold: 1,
3
+ italic: 2,
4
+ underline: 4,
5
+ strike: 8,
6
+ code: 16,
7
+ link: 32
8
+ };
9
+ const OBJ = '';
10
+ const SOFT_BREAK = '
';
11
+ export { MARK, OBJ, SOFT_BREAK };
12
+
13
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sources":["../src/protocol.ts"],"sourcesContent":["/**\n * The `<g9-richtext>` contract (Plan-Lynx §6, W10): what the app and the host's element say to each other. The element\n * is a plain-text editor with styled lines; the document model (Yjs, TipTap's schema) lives in the app (session.ts).\n *\n * Text: the document as one string — blocks separated by \"\\n\" (a code block's own newlines and hard breaks are \"\\n\" too,\n * the line style says what the line belongs to), inline objects (mentions, chips, dates) and block objects (rules,\n * pictures) are one U+FFFC each. Every line has a style ({@link RtLine}). Positions are UTF-16 offsets into that text.\n *\n * app → element `invoke('apply', RtMessage)` (UI method), attributes `editable`, `placeholder`, `palette`, `lang`\n * element → app events `rtedit` {@link RtEdit}, `rtselect` {@link RtSelect}, `rtapplied` {@link RtApplied},\n * `rtaction` {@link RtAction}\n *\n * Concurrency (Jupiter): the element numbers its edits (`seq`) and says which app state (`base` = a message's `rev`) it\n * had applied when it made them; the app transforms them over whatever changed since. A message carries `ack` = the last\n * edit the app has applied: the element applies it only when `ack` equals its own last `seq` (otherwise newer typing is\n * on its way and the next message will contain it) — then its text becomes the model's exactly.\n */\n\n/** One run of a line's text with the same look. */\nexport interface RtRun {\n /** Length in UTF-16 units. */\n n: number;\n /** Marks: {@link MARK} bits. */\n m?: number;\n /** Link target (with {@link MARK.link}). */\n href?: string;\n /** An inline object (one U+FFFC): what to draw in its place. */\n a?: RtAtom;\n}\n\n/** An object inside a line (a mention, a picture): one character in the flat text. */\nexport interface RtAtom {\n /** `mention` (@name), `chip` (a link to a task, document, meeting…), `date` (a date in the reader's calendar). */\n k: 'mention' | 'chip' | 'date';\n /** The label. */\n t: string;\n /** Accent colour (#rrggbb) of a chip, when the target has one. */\n c?: string;\n /** Not available to this reader (drawn greyed, not tappable). */\n off?: boolean;\n}\n\n/** Inline marks as bits. */\nexport const MARK = { bold: 1, italic: 2, underline: 4, strike: 8, code: 16, link: 32 } as const;\n/** An inline mark's name. */\nexport type MarkName = keyof typeof MARK;\n\n/** The style of one line of the text. */\nexport interface RtLine {\n /** Paragraph, headings, a code line, a horizontal rule (its text is one U+FFFC), a picture (one U+FFFC). */\n t: 'p' | 'h1' | 'h2' | 'h3' | 'code' | 'hr' | 'img';\n /** Explicit direction; absent = the first strong letter decides (Persian right-to-left, English left-to-right). */\n dir?: 'rtl' | 'ltr';\n /** List nesting (indent steps). */\n ind?: number;\n /** Quote nesting (bars on the start side). */\n q?: number;\n /** The marker of a list item's first line: bullet, number (`n`: \"3.\" in the reader's digits), checkbox (`c`). */\n mk?: { k: 'b' | 'n' | 't'; n?: string; c?: boolean };\n /** Inside a checked task: struck through and dimmed. */\n done?: boolean;\n /** Callout tone: a tinted box. */\n co?: 'info' | 'success' | 'warning' | 'danger';\n /** A table cell's line: row and column (0-based), header cell, first line of the cell. */\n cell?: { r: number; c: number; h?: boolean; top?: boolean };\n /** First / last line of a code block (the box's rounded ends). */\n cf?: boolean;\n cl?: boolean;\n /** A picture: storage key, a signed address once known, its description. */\n img?: { key: string; src?: string; alt?: string };\n /** The line's text as runs (lengths add up to the line's length; an empty line has none). */\n r: RtRun[];\n}\n\n/** The line array changed: replace `del` lines at `at` with `ins` (positions in the array as the element has it). */\nexport interface RtSplice {\n at: number;\n del: number;\n ins: RtLine[];\n}\n\n/** app → element. */\nexport interface RtMessage {\n /** The app state this message brings the element to. */\n rev: number;\n /** The last element edit the app has applied (apply only when it equals the element's own last `seq`). */\n ack: number;\n /** A full state (first message, after `resync`): replaces text and lines. */\n full?: { text: string; lines: RtLine[] };\n /** Otherwise: replacements to apply in order (positions after the previous ones)… */\n ops?: { from: number; to: number; text: string }[];\n /** …and the line array changes, against the lines of state `of` (the element's last applied `rev`). */\n lines?: RtSplice & { of: number };\n /** Move the selection (after a command). */\n sel?: { a: number; h: number };\n /** Collaborators: caret `h`, selection from `a`, colour, name. */\n peers?: { a: number; h: number; c: string; n: string }[];\n /** Focus the editor (and show the keyboard). */\n focus?: boolean;\n}\n\n/** element → app: the user changed the text (replace `from..to` of the element's text, which had `len` characters). */\nexport interface RtEdit {\n seq: number;\n base: number;\n from: number;\n to: number;\n text: string;\n len: number;\n}\n\n/** element → app: the selection after edit `seq` (anchor, head). */\nexport interface RtSelect {\n seq: number;\n base: number;\n a: number;\n h: number;\n /** Whether the editor has the focus. */\n focus?: boolean;\n}\n\n/** element → app: message `rev` was applied (so the app can forget what came before). */\nexport interface RtApplied {\n rev: number;\n}\n\n/** element → app: something besides typing. */\nexport type RtAction =\n /** A task line's checkbox was tapped. */\n | { kind: 'check'; line: number }\n /** An inline object was tapped (a chip opens its target). */\n | { kind: 'tap'; at: number }\n /** A shortcut the element does not handle itself: undo, redo, bold, italic, underline, strike, code, link, indent, outdent. */\n | { kind: 'key'; key: string }\n /** The element's state does not match (a message it could not apply): send a full state. */\n | { kind: 'resync' }\n /** A picture line was tapped. */\n | { kind: 'image'; line: number };\n\n/** Colours for the element (it cannot read the app's CSS variables): `#rrggbb` / `#rrggbbaa`. */\nexport interface RtPalette {\n text: string;\n text2: string;\n text3: string;\n accent: string;\n link: string;\n border: string;\n surface2: string;\n selection: string;\n info: string;\n success: string;\n warning: string;\n danger: string;\n}\n\n/** U+FFFC: an inline or block object in the text. */\nexport const OBJ = '';\n/** U+2028 from the element: a line break inside the paragraph (Shift+Enter), not a new paragraph. */\nexport const SOFT_BREAK = '
';\n"],"names":["MARK","OBJ","SOFT_BREAK"],"mappings":"AA2CO,MAAMA,OAAO;IAAE,MAAM;IAAG,QAAQ;IAAG,WAAW;IAAG,QAAQ;IAAG,MAAM;IAAI,MAAM;AAAG;AAiH/E,MAAMC,MAAM;AAEZ,MAAMC,aAAa"}
@@ -0,0 +1,188 @@
1
+ import { G9TextEntry } from "@g9tm/lynxcontrols/fields";
2
+ import { useG9Direction, useG9Theme } from "@g9tm/lynxcontrols/provider";
3
+ import { resolveThemeColor } from "@g9tm/lynxcontrols-foundation";
4
+ import { useEffect, useMemo, useRef, useState } from "@lynx-js/react";
5
+ import { ElementCore } from "./element-core.js";
6
+ import { G9RichLines } from "./lines-view.js";
7
+ import { diff } from "./ot.js";
8
+ import "./richtext.css";
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) Object.defineProperty(obj, key, {
11
+ value: value,
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true
15
+ });
16
+ else obj[key] = value;
17
+ return obj;
18
+ }
19
+ class G9RichTextPort {
20
+ attach(target) {
21
+ this.target = target;
22
+ }
23
+ attachDirect(handler) {
24
+ this.direct = handler;
25
+ }
26
+ constructor(){
27
+ _define_property(this, "target", null);
28
+ _define_property(this, "direct", null);
29
+ _define_property(this, "send", (message)=>{
30
+ if (this.direct) return void this.direct(message);
31
+ if (!this.target) return;
32
+ this.target.invoke({
33
+ method: 'apply',
34
+ params: {
35
+ json: JSON.stringify(message)
36
+ }
37
+ }).exec();
38
+ });
39
+ }
40
+ }
41
+ function g9RichTextPalette(resolve) {
42
+ return {
43
+ text: resolve('--g9-text-primary'),
44
+ text2: resolve('--g9-text-secondary'),
45
+ text3: resolve('--g9-text-tertiary'),
46
+ accent: resolve('--g9-primary'),
47
+ link: resolve('--g9-primary'),
48
+ border: resolve('--g9-outline-variant'),
49
+ surface2: resolve('--g9-surface-container'),
50
+ selection: resolve('--g9-primary-container'),
51
+ info: resolve('--g9-info'),
52
+ success: resolve('--g9-success'),
53
+ warning: resolve('--g9-warning'),
54
+ danger: resolve('--g9-error')
55
+ };
56
+ }
57
+ function G9RichText(props) {
58
+ var _props_bottomInset;
59
+ const ref = useRef(null);
60
+ const theme = useG9Theme();
61
+ const rtl = 'rtl' === useG9Direction();
62
+ const palette = useMemo(()=>{
63
+ var _props_palette;
64
+ return JSON.stringify(null != (_props_palette = props.palette) ? _props_palette : g9RichTextPalette((t)=>resolveThemeColor(`var(${t})`, theme.palette)));
65
+ }, [
66
+ props.palette,
67
+ theme.palette
68
+ ]);
69
+ const focused = useRef(false);
70
+ const drawn = 'drawn' === props.surface;
71
+ useEffect(()=>{
72
+ if (drawn) return;
73
+ props.port.attach(ref.current);
74
+ props.session.reset();
75
+ return ()=>props.port.attach(null);
76
+ }, [
77
+ props.session,
78
+ props.port,
79
+ drawn
80
+ ]);
81
+ if (drawn) return <DrawnSurface {...props}/>;
82
+ return <g9-richtext ref={ref} className={`g9-rt-element${props.className ? ` ${props.className}` : ''}`} editable={props.editable} placeholder={props.placeholder} palette={palette} page-dir={rtl ? 'rtl' : 'ltr'} bottom-inset={null != (_props_bottomInset = props.bottomInset) ? _props_bottomInset : 0} bindrtedit={(e)=>props.session.edit(e.detail)} bindrtselect={(e)=>{
83
+ const d = e.detail;
84
+ if (void 0 !== d.focus && d.focus !== focused.current) {
85
+ var _props_onFocusChange;
86
+ focused.current = d.focus;
87
+ null == (_props_onFocusChange = props.onFocusChange) || _props_onFocusChange.call(props, d.focus);
88
+ }
89
+ props.session.select(d);
90
+ }} bindrtapplied={(e)=>props.session.applied(e.detail)} bindrtaction={(e)=>{
91
+ var _props_onTapObject;
92
+ const a = e.detail;
93
+ if ('tap' === a.kind) null == (_props_onTapObject = props.onTapObject) || _props_onTapObject.call(props, a.at);
94
+ else props.session.action(a);
95
+ }}/>;
96
+ }
97
+ function DrawnSurface(props) {
98
+ var _props_bottomInset;
99
+ const core = useRef(new ElementCore());
100
+ const rtl = 'rtl' === useG9Direction();
101
+ const [, setVersion] = useState(0);
102
+ const [editing, setEditing] = useState(-1);
103
+ const field = useRef(null);
104
+ const { session, port } = props;
105
+ useEffect(()=>{
106
+ port.attachDirect((message)=>{
107
+ const result = core.current.apply(message);
108
+ if ('resync' === result) session.action({
109
+ kind: 'resync'
110
+ });
111
+ else if (result) {
112
+ session.applied({
113
+ rev: message.rev
114
+ });
115
+ setVersion((v)=>v + 1);
116
+ }
117
+ });
118
+ session.reset();
119
+ return ()=>port.attachDirect(null);
120
+ }, [
121
+ session,
122
+ port
123
+ ]);
124
+ useEffect(()=>{
125
+ var _field_current_focus, _field_current;
126
+ if (editing >= 0) null == (_field_current = field.current) || null == (_field_current_focus = _field_current.focus) || _field_current_focus.call(_field_current);
127
+ }, [
128
+ editing
129
+ ]);
130
+ const text1 = core.current.text;
131
+ const lines = core.current.lines;
132
+ const parts = text1.split('\n');
133
+ const lineStart = (index)=>{
134
+ let pos = 0;
135
+ for(let i = 0; i < index; i++)pos += parts[i].length + 1;
136
+ return pos;
137
+ };
138
+ const edit = (index)=>{
139
+ var _props_onFocusChange;
140
+ if (!props.editable) return;
141
+ setEditing(index);
142
+ const end = lineStart(index) + parts[index].length;
143
+ session.select(core.current.select(end, end, true));
144
+ null == (_props_onFocusChange = props.onFocusChange) || _props_onFocusChange.call(props, true);
145
+ };
146
+ const changed = (index, value)=>{
147
+ const before = parts[index];
148
+ if (value === before) return;
149
+ const start = lineStart(index);
150
+ for (const r of diff(before, value).toReplacements())session.edit(core.current.edit(start + r.from, start + r.to, r.text));
151
+ session.select(core.current.select(core.current.sel.a, core.current.sel.h, true));
152
+ setVersion((v)=>v + 1);
153
+ };
154
+ const enter = (index)=>{
155
+ const end = lineStart(index) + parts[index].length;
156
+ session.edit(core.current.edit(end, end, '\n'));
157
+ session.select(core.current.select(end + 1, end + 1, true));
158
+ setEditing(index + 1);
159
+ setVersion((v)=>v + 1);
160
+ };
161
+ const cls = `g9-rt-drawn${props.className ? ` ${props.className}` : ''}`;
162
+ if (!text1 && lines.length <= 1 && editing < 0) return <scroll-view className={cls} scroll-orientation="vertical">
163
+ <view className="g9-rt-drawn__empty" bindtap={()=>edit(0)}>
164
+ <text className="g9-rt-drawn__placeholder">{props.placeholder}</text>
165
+ </view>
166
+ </scroll-view>;
167
+ return <scroll-view className={cls} scroll-orientation="vertical">
168
+ <view className="g9-rt-drawn__body" style={{
169
+ paddingBottom: `${(null != (_props_bottomInset = props.bottomInset) ? _props_bottomInset : 0) + 96}px`
170
+ }}>
171
+ <G9RichLines text={text1} lines={lines} editing={editing} direction={rtl ? 'rtl' : 'ltr'} onTapLine={(index)=>{
172
+ var _lines_index, _props_onTapObject;
173
+ const atom = null == (_lines_index = lines[index]) ? void 0 : _lines_index.r.find((run)=>run.a);
174
+ if (atom && !props.editable) null == (_props_onTapObject = props.onTapObject) || _props_onTapObject.call(props, lineStart(index));
175
+ edit(index);
176
+ }} onToggleCheck={(index)=>props.editable && session.action({
177
+ kind: 'check',
178
+ line: index
179
+ })} renderLine={(index, _line, value)=><G9TextEntry key={`line-${index}`} ref={field} value={value} onValueChange={(next)=>changed(index, next)} onConfirm={()=>enter(index)} onBlur={()=>{
180
+ var _props_onFocusChange;
181
+ return null == (_props_onFocusChange = props.onFocusChange) ? void 0 : _props_onFocusChange.call(props, false);
182
+ }} confirmType="next"/>}/>
183
+ </view>
184
+ </scroll-view>;
185
+ }
186
+ export { G9RichText, G9RichTextPort, g9RichTextPalette };
187
+
188
+ //# sourceMappingURL=rich-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text.js","sources":["../src/rich-text.tsx"],"sourcesContent":["// The host's `<g9-richtext>` element bound to a session (2.5.8, from G9Hub's RichText and DesktopRichText): the\n// session's messages go out through the element's `apply` method and its events come back. On a host without the\n// element (the desktop, Lynxtron) the same protocol drives a drawn surface: the document's lines as Lynx views and the\n// line being edited as a text field (ElementCore keeps the element's side), so sessions, collaboration and undo are\n// the same everywhere.\nimport { G9TextEntry, type G9TextEntryHandle } from '@g9tm/lynxcontrols/fields';\nimport { useG9Direction, useG9Theme } from '@g9tm/lynxcontrols/provider';\nimport { resolveThemeColor } from '@g9tm/lynxcontrols-foundation';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from '@lynx-js/react';\nimport type { NodesRef } from '@lynx-js/types';\nimport { ElementCore } from './element-core';\nimport { G9RichLines } from './lines-view';\nimport { diff } from './ot';\nimport type { RtAction, RtApplied, RtEdit, RtMessage, RtPalette, RtSelect } from './protocol';\nimport './richtext.css';\n\n/** What drives the element: a session (G9RichTextSession of `@g9tm/lynxcontrols-richtext/yjs`, or the app's own). */\nexport interface G9RichTextSessionLike {\n edit(event: RtEdit): void;\n select(event: RtSelect): void;\n applied(event: RtApplied): void;\n action(event: RtAction): void;\n /** Sends the full state again (the element was made or re-made). */\n reset(): void;\n}\n\n/**\n * The session's way to the element: create it first, give it to the session (`port`), then to {@link G9RichText}.\n * Before the element exists nothing is sent; mounting asks the session for the full state.\n */\nexport class G9RichTextPort {\n private target: NodesRef | null = null;\n private direct: ((message: RtMessage) => void) | null = null;\n\n /** Sends a message to the element (or the drawn surface). */\n send = (message: RtMessage): void => {\n if (this.direct) {\n this.direct(message);\n return;\n }\n if (!this.target) return;\n this.target.invoke({ method: 'apply', params: { json: JSON.stringify(message) } }).exec();\n };\n\n attach(target: NodesRef | null): void {\n this.target = target;\n }\n\n /** The drawn surface takes the messages itself. */\n attachDirect(handler: ((message: RtMessage) => void) | null): void {\n this.direct = handler;\n }\n}\n\n/** The element's colours from the theme (it cannot read CSS variables). */\nexport function g9RichTextPalette(resolve: (token: string) => string): RtPalette {\n return {\n text: resolve('--g9-text-primary'),\n text2: resolve('--g9-text-secondary'),\n text3: resolve('--g9-text-tertiary'),\n accent: resolve('--g9-primary'),\n link: resolve('--g9-primary'),\n border: resolve('--g9-outline-variant'),\n surface2: resolve('--g9-surface-container'),\n selection: resolve('--g9-primary-container'),\n info: resolve('--g9-info'),\n success: resolve('--g9-success'),\n warning: resolve('--g9-warning'),\n danger: resolve('--g9-error'),\n };\n}\n\n/** Props of {@link G9RichText}. */\nexport interface G9RichTextProps {\n readonly session: G9RichTextSessionLike;\n readonly port: G9RichTextPort;\n readonly editable: boolean;\n readonly placeholder: string;\n readonly className?: string;\n /** `'element'` (default): the host's `<g9-richtext>`; `'drawn'`: Lynx views (a host without the element). */\n readonly surface?: 'element' | 'drawn';\n /** Room under the content (a floating toolbar). */\n readonly bottomInset?: number;\n /** The element's colours; default the theme's. */\n readonly palette?: RtPalette;\n /** An inline object tapped (a chip): its position in the text. */\n readonly onTapObject?: (pos: number) => void;\n readonly onFocusChange?: (focused: boolean) => void;\n}\n\n/** An editable rich text on the host's element (or drawn, on the desktop). */\nexport function G9RichText(props: G9RichTextProps): ReactNode {\n const ref = useRef<NodesRef | null>(null);\n const theme = useG9Theme();\n const rtl = useG9Direction() === 'rtl';\n const palette = useMemo(\n () => JSON.stringify(props.palette ?? g9RichTextPalette((t) => resolveThemeColor(`var(${t})`, theme.palette))),\n [props.palette, theme.palette],\n );\n const focused = useRef(false);\n const drawn = props.surface === 'drawn';\n useEffect(() => {\n if (drawn) return;\n props.port.attach(ref.current);\n props.session.reset();\n return () => props.port.attach(null);\n }, [props.session, props.port, drawn]);\n if (drawn) return <DrawnSurface {...props} />;\n return (\n <g9-richtext\n ref={ref}\n className={`g9-rt-element${props.className ? ` ${props.className}` : ''}`}\n editable={props.editable}\n placeholder={props.placeholder}\n palette={palette}\n page-dir={rtl ? 'rtl' : 'ltr'}\n bottom-inset={props.bottomInset ?? 0}\n bindrtedit={(e) => props.session.edit(e.detail)}\n bindrtselect={(e) => {\n const d = e.detail;\n if (d.focus !== undefined && d.focus !== focused.current) {\n focused.current = d.focus;\n props.onFocusChange?.(d.focus);\n }\n props.session.select(d);\n }}\n bindrtapplied={(e) => props.session.applied(e.detail)}\n bindrtaction={(e) => {\n const a = e.detail;\n if (a.kind === 'tap') props.onTapObject?.(a.at);\n else props.session.action(a);\n }}\n />\n );\n}\n\nfunction DrawnSurface(props: G9RichTextProps): ReactNode {\n const core = useRef(new ElementCore());\n const rtl = useG9Direction() === 'rtl';\n const [, setVersion] = useState(0);\n const [editing, setEditing] = useState(-1);\n const field = useRef<G9TextEntryHandle | null>(null);\n const { session, port } = props;\n useEffect(() => {\n port.attachDirect((message) => {\n const result = core.current.apply(message);\n if (result === 'resync') session.action({ kind: 'resync' });\n else if (result) {\n session.applied({ rev: message.rev });\n setVersion((v) => v + 1);\n }\n });\n session.reset();\n return () => port.attachDirect(null);\n }, [session, port]);\n useEffect(() => {\n if (editing >= 0) (field.current as unknown as { focus?: () => void } | null)?.focus?.();\n }, [editing]);\n const text = core.current.text;\n const lines = core.current.lines;\n const parts = text.split('\\n');\n const lineStart = (index: number) => {\n let pos = 0;\n for (let i = 0; i < index; i++) pos += (parts[i] as string).length + 1;\n return pos;\n };\n const edit = (index: number) => {\n if (!props.editable) return;\n setEditing(index);\n const end = lineStart(index) + (parts[index] as string).length;\n session.select(core.current.select(end, end, true));\n props.onFocusChange?.(true);\n };\n const changed = (index: number, value: string) => {\n const before = parts[index] as string;\n if (value === before) return;\n const start = lineStart(index);\n for (const r of diff(before, value).toReplacements())\n session.edit(core.current.edit(start + r.from, start + r.to, r.text));\n session.select(core.current.select(core.current.sel.a, core.current.sel.h, true));\n setVersion((v) => v + 1);\n };\n const enter = (index: number) => {\n const end = lineStart(index) + (parts[index] as string).length;\n session.edit(core.current.edit(end, end, '\\n'));\n session.select(core.current.select(end + 1, end + 1, true));\n setEditing(index + 1);\n setVersion((v) => v + 1);\n };\n const cls = `g9-rt-drawn${props.className ? ` ${props.className}` : ''}`;\n if (!text && lines.length <= 1 && editing < 0) {\n return (\n <scroll-view className={cls} scroll-orientation=\"vertical\">\n <view className=\"g9-rt-drawn__empty\" bindtap={() => edit(0)}>\n <text className=\"g9-rt-drawn__placeholder\">{props.placeholder}</text>\n </view>\n </scroll-view>\n );\n }\n return (\n <scroll-view className={cls} scroll-orientation=\"vertical\">\n <view className=\"g9-rt-drawn__body\" style={{ paddingBottom: `${(props.bottomInset ?? 0) + 96}px` }}>\n <G9RichLines\n text={text}\n lines={lines}\n editing={editing}\n direction={rtl ? 'rtl' : 'ltr'}\n onTapLine={(index) => {\n const atom = lines[index]?.r.find((run) => run.a);\n if (atom && !props.editable) props.onTapObject?.(lineStart(index));\n edit(index);\n }}\n onToggleCheck={(index) => props.editable && session.action({ kind: 'check', line: index })}\n renderLine={(index, _line, value) => (\n <G9TextEntry\n key={`line-${index}`}\n ref={field}\n value={value}\n onValueChange={(next) => changed(index, next)}\n onConfirm={() => enter(index)}\n onBlur={() => props.onFocusChange?.(false)}\n confirmType=\"next\"\n />\n )}\n />\n </view>\n </scroll-view>\n );\n}\n"],"names":["G9RichTextPort","target","handler","message","JSON","g9RichTextPalette","resolve","G9RichText","props","_props_bottomInset","ref","useRef","theme","useG9Theme","rtl","useG9Direction","palette","useMemo","_props_palette","t","resolveThemeColor","focused","drawn","useEffect","DrawnSurface","g9-richtext","e","d","undefined","a","core","ElementCore","setVersion","useState","editing","setEditing","field","session","port","result","v","_field_current_focus","_field_current","text1","lines","parts","lineStart","index","pos","i","edit","end","changed","value","before","start","r","diff","enter","cls","scroll-view","view","text","G9RichLines","_lines_index","atom","run","_line","G9TextEntry","next"],"mappings":";;;;;;;;;;;;;;;;;;AA8BO,MAAMA;IAcX,OAAOC,MAAuB,EAAQ;QACpC,IAAI,CAAC,MAAM,GAAGA;IAChB;IAGA,aAAaC,OAA8C,EAAQ;QACjE,IAAI,CAAC,MAAM,GAAGA;IAChB;;QApBA,uBAAQ,UAA0B;QAClC,uBAAQ,UAAgD;QAGxD,+BAAO,CAACC;YACN,IAAI,IAAI,CAAC,MAAM,EAAE,YACf,IAAI,CAAC,MAAM,CAACA;YAGd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAClB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAE,QAAQ;gBAAS,QAAQ;oBAAE,MAAMC,KAAK,SAAS,CAACD;gBAAS;YAAE,GAAG,IAAI;QACzF;;AAUF;AAGO,SAASE,kBAAkBC,OAAkC;IAClE,OAAO;QACL,MAAMA,QAAQ;QACd,OAAOA,QAAQ;QACf,OAAOA,QAAQ;QACf,QAAQA,QAAQ;QAChB,MAAMA,QAAQ;QACd,QAAQA,QAAQ;QAChB,UAAUA,QAAQ;QAClB,WAAWA,QAAQ;QACnB,MAAMA,QAAQ;QACd,SAASA,QAAQ;QACjB,SAASA,QAAQ;QACjB,QAAQA,QAAQ;IAClB;AACF;AAqBO,SAASC,WAAWC,KAAsB;QAyB7BC;IAxBlB,MAAMC,MAAMC,OAAwB;IACpC,MAAMC,QAAQC;IACd,MAAMC,MAAMC,AAAqB,UAArBA;IACZ,MAAMC,UAAUC,QACd;YAAqBC;eAAfd,KAAK,SAAS,CAAC,QAAAc,CAAAA,iBAAAA,MAAM,OAAO,AAAD,IAAZA,iBAAiBb,kBAAkB,CAACc,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