@g9tm/lynxcontrols-richtext 0.0.0-stage → 2.5.8

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.
Files changed (49) hide show
  1. package/README.md +32 -2
  2. package/catalog/cards/G9RichLines.md +16 -0
  3. package/catalog/cards/G9RichText.md +17 -0
  4. package/catalog/cards/G9RichTextEditor.md +17 -0
  5. package/catalog/catalog.json +1667 -0
  6. package/catalog/index.md +7 -0
  7. package/dist/.tsbuildinfo +1 -0
  8. package/dist/bidi.d.ts +24 -0
  9. package/dist/bidi.d.ts.map +1 -0
  10. package/dist/bidi.jsx +102 -0
  11. package/dist/editor.d.ts +111 -0
  12. package/dist/editor.d.ts.map +1 -0
  13. package/dist/editor.jsx +556 -0
  14. package/dist/element-core.d.ts +60 -0
  15. package/dist/element-core.d.ts.map +1 -0
  16. package/dist/element-core.jsx +173 -0
  17. package/dist/element-types.d.ts +31 -0
  18. package/dist/element-types.d.ts.map +1 -0
  19. package/dist/element-types.jsx +1 -0
  20. package/dist/index.d.ts +10 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.jsx +8 -0
  23. package/dist/lines-view.d.ts +27 -0
  24. package/dist/lines-view.d.ts.map +1 -0
  25. package/dist/lines-view.jsx +100 -0
  26. package/dist/mentions.d.ts +30 -0
  27. package/dist/mentions.d.ts.map +1 -0
  28. package/dist/mentions.jsx +40 -0
  29. package/dist/ot.d.ts +49 -0
  30. package/dist/ot.d.ts.map +1 -0
  31. package/dist/ot.jsx +306 -0
  32. package/dist/protocol.d.ts +199 -0
  33. package/dist/protocol.d.ts.map +1 -0
  34. package/dist/protocol.jsx +11 -0
  35. package/dist/rich-text.d.ts +48 -0
  36. package/dist/rich-text.d.ts.map +1 -0
  37. package/dist/rich-text.jsx +186 -0
  38. package/dist/richtext.css +411 -0
  39. package/dist/richtext.css.map +1 -0
  40. package/dist/session.d.ts +142 -0
  41. package/dist/session.d.ts.map +1 -0
  42. package/dist/session.jsx +665 -0
  43. package/dist/yjs.d.ts +3 -0
  44. package/dist/yjs.d.ts.map +1 -0
  45. package/dist/yjs.jsx +2 -0
  46. package/dist/ymodel.d.ts +178 -0
  47. package/dist/ymodel.d.ts.map +1 -0
  48. package/dist/ymodel.jsx +1379 -0
  49. package/package.json +68 -4
package/dist/ot.jsx ADDED
@@ -0,0 +1,306 @@
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 };
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The `<g9-richtext>` contract (Plan-Lynx §6, W10): what the app and the host's element say to each other. The element
3
+ * is a plain-text editor with styled lines; the document model (Yjs, TipTap's schema) lives in the app (session.ts).
4
+ *
5
+ * Text: the document as one string — blocks separated by "\n" (a code block's own newlines and hard breaks are "\n" too,
6
+ * the line style says what the line belongs to), inline objects (mentions, chips, dates) and block objects (rules,
7
+ * pictures) are one U+FFFC each. Every line has a style ({@link RtLine}). Positions are UTF-16 offsets into that text.
8
+ *
9
+ * app → element `invoke('apply', RtMessage)` (UI method), attributes `editable`, `placeholder`, `palette`, `lang`
10
+ * element → app events `rtedit` {@link RtEdit}, `rtselect` {@link RtSelect}, `rtapplied` {@link RtApplied},
11
+ * `rtaction` {@link RtAction}
12
+ *
13
+ * Concurrency (Jupiter): the element numbers its edits (`seq`) and says which app state (`base` = a message's `rev`) it
14
+ * had applied when it made them; the app transforms them over whatever changed since. A message carries `ack` = the last
15
+ * edit the app has applied: the element applies it only when `ack` equals its own last `seq` (otherwise newer typing is
16
+ * on its way and the next message will contain it) — then its text becomes the model's exactly.
17
+ */
18
+ /** One run of a line's text with the same look. */
19
+ export interface RtRun {
20
+ /** Length in UTF-16 units. */
21
+ n: number;
22
+ /** Marks: {@link MARK} bits. */
23
+ m?: number;
24
+ /** Link target (with {@link MARK.link}). */
25
+ href?: string;
26
+ /** An inline object (one U+FFFC): what to draw in its place. */
27
+ a?: RtAtom;
28
+ }
29
+ /** An object inside a line (a mention, a picture): one character in the flat text. */
30
+ export interface RtAtom {
31
+ /** `mention` (@name), `chip` (a link to a task, document, meeting…), `date` (a date in the reader's calendar). */
32
+ k: 'mention' | 'chip' | 'date';
33
+ /** The label. */
34
+ t: string;
35
+ /** Accent colour (#rrggbb) of a chip, when the target has one. */
36
+ c?: string;
37
+ /** Not available to this reader (drawn greyed, not tappable). */
38
+ off?: boolean;
39
+ }
40
+ /** Inline marks as bits. */
41
+ export declare const MARK: {
42
+ readonly bold: 1;
43
+ readonly italic: 2;
44
+ readonly underline: 4;
45
+ readonly strike: 8;
46
+ readonly code: 16;
47
+ readonly link: 32;
48
+ };
49
+ /** An inline mark's name. */
50
+ export type MarkName = keyof typeof MARK;
51
+ /** The style of one line of the text. */
52
+ export interface RtLine {
53
+ /** Paragraph, headings, a code line, a horizontal rule (its text is one U+FFFC), a picture (one U+FFFC). */
54
+ t: 'p' | 'h1' | 'h2' | 'h3' | 'code' | 'hr' | 'img';
55
+ /** Explicit direction; absent = the first strong letter decides (Persian right-to-left, English left-to-right). */
56
+ dir?: 'rtl' | 'ltr';
57
+ /** List nesting (indent steps). */
58
+ ind?: number;
59
+ /** Quote nesting (bars on the start side). */
60
+ q?: number;
61
+ /** The marker of a list item's first line: bullet, number (`n`: "3." in the reader's digits), checkbox (`c`). */
62
+ mk?: {
63
+ k: 'b' | 'n' | 't';
64
+ n?: string;
65
+ c?: boolean;
66
+ };
67
+ /** Inside a checked task: struck through and dimmed. */
68
+ done?: boolean;
69
+ /** Callout tone: a tinted box. */
70
+ co?: 'info' | 'success' | 'warning' | 'danger';
71
+ /** A table cell's line: row and column (0-based), header cell, first line of the cell. */
72
+ cell?: {
73
+ r: number;
74
+ c: number;
75
+ h?: boolean;
76
+ top?: boolean;
77
+ };
78
+ /** First / last line of a code block (the box's rounded ends). */
79
+ cf?: boolean;
80
+ cl?: boolean;
81
+ /** A picture: storage key, a signed address once known, its description. */
82
+ img?: {
83
+ key: string;
84
+ src?: string;
85
+ alt?: string;
86
+ };
87
+ /** The line's text as runs (lengths add up to the line's length; an empty line has none). */
88
+ r: RtRun[];
89
+ }
90
+ /** The line array changed: replace `del` lines at `at` with `ins` (positions in the array as the element has it). */
91
+ export interface RtSplice {
92
+ at: number;
93
+ del: number;
94
+ ins: RtLine[];
95
+ }
96
+ /** app → element. */
97
+ export interface RtMessage {
98
+ /** The app state this message brings the element to. */
99
+ rev: number;
100
+ /** The last element edit the app has applied (apply only when it equals the element's own last `seq`). */
101
+ ack: number;
102
+ /** A full state (first message, after `resync`): replaces text and lines. */
103
+ full?: {
104
+ text: string;
105
+ lines: RtLine[];
106
+ };
107
+ /** Otherwise: replacements to apply in order (positions after the previous ones)… */
108
+ ops?: {
109
+ from: number;
110
+ to: number;
111
+ text: string;
112
+ }[];
113
+ /** …and the line array changes, against the lines of state `of` (the element's last applied `rev`). */
114
+ lines?: RtSplice & {
115
+ of: number;
116
+ };
117
+ /** Move the selection (after a command). */
118
+ sel?: {
119
+ a: number;
120
+ h: number;
121
+ };
122
+ /** Collaborators: caret `h`, selection from `a`, colour, name. */
123
+ peers?: {
124
+ a: number;
125
+ h: number;
126
+ c: string;
127
+ n: string;
128
+ }[];
129
+ /** Focus the editor (and show the keyboard). */
130
+ focus?: boolean;
131
+ }
132
+ /** element → app: the user changed the text (replace `from..to` of the element's text, which had `len` characters). */
133
+ export interface RtEdit {
134
+ seq: number;
135
+ base: number;
136
+ from: number;
137
+ to: number;
138
+ text: string;
139
+ len: number;
140
+ }
141
+ /** element → app: the selection after edit `seq` (anchor, head). */
142
+ export interface RtSelect {
143
+ seq: number;
144
+ base: number;
145
+ a: number;
146
+ h: number;
147
+ /** Whether the editor has the focus. */
148
+ focus?: boolean;
149
+ }
150
+ /** element → app: message `rev` was applied (so the app can forget what came before). */
151
+ export interface RtApplied {
152
+ rev: number;
153
+ }
154
+ /** element → app: something besides typing. */
155
+ export type RtAction =
156
+ /** A task line's checkbox was tapped. */
157
+ {
158
+ kind: 'check';
159
+ line: number;
160
+ }
161
+ /** An inline object was tapped (a chip opens its target). */
162
+ | {
163
+ kind: 'tap';
164
+ at: number;
165
+ }
166
+ /** A shortcut the element does not handle itself: undo, redo, bold, italic, underline, strike, code, link, indent, outdent. */
167
+ | {
168
+ kind: 'key';
169
+ key: string;
170
+ }
171
+ /** The element's state does not match (a message it could not apply): send a full state. */
172
+ | {
173
+ kind: 'resync';
174
+ }
175
+ /** A picture line was tapped. */
176
+ | {
177
+ kind: 'image';
178
+ line: number;
179
+ };
180
+ /** Colours for the element (it cannot read the app's CSS variables): `#rrggbb` / `#rrggbbaa`. */
181
+ export interface RtPalette {
182
+ text: string;
183
+ text2: string;
184
+ text3: string;
185
+ accent: string;
186
+ link: string;
187
+ border: string;
188
+ surface2: string;
189
+ selection: string;
190
+ info: string;
191
+ success: string;
192
+ warning: string;
193
+ danger: string;
194
+ }
195
+ /** U+FFFC: an inline or block object in the text. */
196
+ export declare const OBJ = "\uFFFC";
197
+ /** U+2028 from the element: a line break inside the paragraph (Shift+Enter), not a new paragraph. */
198
+ export declare const SOFT_BREAK = "\u2028";
199
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,mDAAmD;AACnD,MAAM,WAAW,KAAK;IACpB,8BAA8B;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,gCAAgC;IAChC,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED,sFAAsF;AACtF,MAAM,WAAW,MAAM;IACrB,kHAAkH;IAClH,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,iBAAiB;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,kEAAkE;IAClE,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,iEAAiE;IACjE,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,4BAA4B;AAC5B,eAAO,MAAM,IAAI;;;;;;;CAA+E,CAAC;AACjG,6BAA6B;AAC7B,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,IAAI,CAAC;AAEzC,yCAAyC;AACzC,MAAM,WAAW,MAAM;IACrB,4GAA4G;IAC5G,CAAC,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;IACpD,mHAAmH;IACnH,GAAG,CAAC,EAAE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I,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AACjC,6DAA6D;GAC3D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AAC7B,+HAA+H;GAC7H;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE;AAC9B,4FAA4F;GAC1F;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE;AACpB,iCAAiC;GAC/B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpC,iGAAiG;AACjG,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qDAAqD;AACrD,eAAO,MAAM,GAAG,WAAM,CAAC;AACvB,qGAAqG;AACrG,eAAO,MAAM,UAAU,WACtB,CAAC"}
@@ -0,0 +1,11 @@
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 };
@@ -0,0 +1,48 @@
1
+ import { type ReactNode } from '@lynx-js/react';
2
+ import type { NodesRef } from '@lynx-js/types';
3
+ import type { RtAction, RtApplied, RtEdit, RtMessage, RtPalette, RtSelect } from './protocol.js';
4
+ import './richtext.css';
5
+ /** What drives the element: a session (G9RichTextSession of `@g9tm/lynxcontrols-richtext/yjs`, or the app's own). */
6
+ export interface G9RichTextSessionLike {
7
+ edit(event: RtEdit): void;
8
+ select(event: RtSelect): void;
9
+ applied(event: RtApplied): void;
10
+ action(event: RtAction): void;
11
+ /** Sends the full state again (the element was made or re-made). */
12
+ reset(): void;
13
+ }
14
+ /**
15
+ * The session's way to the element: create it first, give it to the session (`port`), then to {@link G9RichText}.
16
+ * Before the element exists nothing is sent; mounting asks the session for the full state.
17
+ */
18
+ export declare class G9RichTextPort {
19
+ private target;
20
+ private direct;
21
+ /** Sends a message to the element (or the drawn surface). */
22
+ send: (message: RtMessage) => void;
23
+ attach(target: NodesRef | null): void;
24
+ /** The drawn surface takes the messages itself. */
25
+ attachDirect(handler: ((message: RtMessage) => void) | null): void;
26
+ }
27
+ /** The element's colours from the theme (it cannot read CSS variables). */
28
+ export declare function g9RichTextPalette(resolve: (token: string) => string): RtPalette;
29
+ /** Props of {@link G9RichText}. */
30
+ export interface G9RichTextProps {
31
+ readonly session: G9RichTextSessionLike;
32
+ readonly port: G9RichTextPort;
33
+ readonly editable: boolean;
34
+ readonly placeholder: string;
35
+ readonly className?: string;
36
+ /** `'element'` (default): the host's `<g9-richtext>`; `'drawn'`: Lynx views (a host without the element). */
37
+ readonly surface?: 'element' | 'drawn';
38
+ /** Room under the content (a floating toolbar). */
39
+ readonly bottomInset?: number;
40
+ /** The element's colours; default the theme's. */
41
+ readonly palette?: RtPalette;
42
+ /** An inline object tapped (a chip): its position in the text. */
43
+ readonly onTapObject?: (pos: number) => void;
44
+ readonly onFocusChange?: (focused: boolean) => void;
45
+ }
46
+ /** An editable rich text on the host's element (or drawn, on the desktop). */
47
+ export declare function G9RichText(props: G9RichTextProps): ReactNode;
48
+ //# sourceMappingURL=rich-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text.d.ts","sourceRoot":"","sources":["../src/rich-text.tsx"],"names":[],"mappings":"AAQA,OAAO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