@g9tm/lynxcontrols-richtext 0.0.0-stage → 2.5.9

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
@@ -0,0 +1,178 @@
1
+ import * as Y from 'yjs';
2
+ import { type MarkName, type RtAtom, type RtLine } from './protocol.js';
3
+ /**
4
+ * The document model of `<g9-richtext>`: a live G9 document's Yjs fragment (`default`, written by the web app's TipTap
5
+ * through y-prosemirror — AIGuides/37) seen as one flat text with styled lines, and every edit the element or the
6
+ * toolbar makes, written back into that same Yjs structure exactly the way y-prosemirror would (element names, attribute
7
+ * values, marks as text formatting). The web app and this client therefore edit one document at the same time.
8
+ *
9
+ * The y-prosemirror mapping (schema: web `features/docs/editor/extensions.ts`):
10
+ * - every ProseMirror node is a `Y.XmlElement` named after its type, attributes = the node's non-null attrs;
11
+ * - a run of text nodes is one `Y.XmlText`; marks are formatting attributes `{ bold: {} }`, `{ link: { href, … } }`;
12
+ * - inline nodes (mention, refChip, dateChip, hardBreak) are `Y.XmlElement`s between the texts.
13
+ *
14
+ * The flat view: every textblock (paragraph, heading, code block) and every block object (horizontal rule, picture) is a
15
+ * segment; segments are joined with "\n". Inside a segment inline objects are U+FFFC and hard breaks "\n" (a code
16
+ * block keeps its own newlines). Containers (lists, items, quotes, callouts, tables) are not text — they become the
17
+ * line styles.
18
+ */
19
+ /** Origin of this client's own changes (undo tracks only these; the sync pushes everything that is not the server's). */
20
+ export declare const LOCAL_ORIGIN: {
21
+ readonly g9: "richtext";
22
+ };
23
+ /** A block's or mark's attributes. */
24
+ export type Attrs = Record<string, unknown>;
25
+ export type Parent = Y.XmlElement | Y.XmlFragment;
26
+ interface DeltaOp {
27
+ insert: string;
28
+ attributes?: Attrs;
29
+ }
30
+ interface TextPiece {
31
+ k: 'text';
32
+ y: Y.XmlText;
33
+ idx: number;
34
+ at: number;
35
+ len: number;
36
+ delta: DeltaOp[];
37
+ }
38
+ interface InlinePiece {
39
+ k: 'inline';
40
+ y: Y.XmlElement;
41
+ idx: number;
42
+ at: number;
43
+ name: string;
44
+ }
45
+ type Piece = TextPiece | InlinePiece;
46
+ export interface Seg {
47
+ el: Y.XmlElement;
48
+ name: string;
49
+ kind: 'text' | 'code' | 'atom';
50
+ start: number;
51
+ len: number;
52
+ text: string;
53
+ pieces: Piece[];
54
+ /** Ancestors, outermost first (the fragment is not included). */
55
+ frames: Y.XmlElement[];
56
+ }
57
+ export interface Flat {
58
+ text: string;
59
+ segs: Seg[];
60
+ lines: RtLine[];
61
+ }
62
+ /** How the reader sees objects: names, chips, dates, pictures, list numbers (labels come from the app). */
63
+ export interface ModelContext {
64
+ mention(id: string, label: string): string;
65
+ chip(href: string, kind: string): RtAtom;
66
+ date(key: string): string;
67
+ imageSrc(key: string): string | undefined;
68
+ number(n: number): string;
69
+ }
70
+ /** The model context without a schema of the app's (paragraphs, lists, marks). */
71
+ export declare const plainContext: ModelContext;
72
+ /** A text block's kind. */
73
+ export type BlockType = 'p' | 'h1' | 'h2' | 'h3' | 'code';
74
+ /** A list's kind. */
75
+ export type ListKind = 'bullet' | 'ordered' | 'task';
76
+ /** A callout's tone. */
77
+ export type CalloutTone = 'info' | 'success' | 'warning' | 'danger';
78
+ /** A Yjs document as flat text with lines, marks and blocks (the element's model of it). */
79
+ export declare class DocModel {
80
+ private ctx;
81
+ readonly doc: Y.Doc;
82
+ readonly root: Y.XmlFragment;
83
+ private readonly cache;
84
+ private current;
85
+ private readonly observer;
86
+ constructor(doc: Y.Doc, ctx?: ModelContext, field?: string);
87
+ destroy(): void;
88
+ /**
89
+ * Replaces the whole content with another document's (restoring a version — web: `setContent`): one change, undoable
90
+ * by me, an ordinary edit for everyone else.
91
+ */
92
+ replaceContent(source: Y.XmlFragment): void;
93
+ /** Labels (chips resolved, names learned, pictures signed) changed: draw the lines again. */
94
+ setContext(ctx: ModelContext): void;
95
+ relabel(): void;
96
+ get flat(): Flat;
97
+ private content;
98
+ private build;
99
+ private runsOf;
100
+ private atomOf;
101
+ private linesOf;
102
+ /** The segment at a flat position and the offset in it. */
103
+ locate(pos: number): {
104
+ seg: Seg;
105
+ off: number;
106
+ } | null;
107
+ /** Segments touching `from..to` (a caret touches its own). */
108
+ segsIn(from: number, to: number): Seg[];
109
+ /** The marks in effect at a position (what typed text gets): the character before, or after at a block start. */
110
+ marksAt(pos: number): Attrs;
111
+ /** Which marks the whole range carries (a caret: the typing marks there). */
112
+ activeMarks(from: number, to: number): Attrs;
113
+ private transact;
114
+ /**
115
+ * Replaces `from..to` of the flat text with `text`: what the element's typing, deleting and pasting turn into. "\n"
116
+ * splits the block (Enter: a new paragraph, list item…), U+2028 is a hard break, text gets `marks` (default: the
117
+ * marks where it is typed).
118
+ */
119
+ replace(from: number, to: number, text: string, marks?: Attrs | null): void;
120
+ /** Inserts text without newlines at a position (inside a code block newlines are text). */
121
+ insertText(pos: number, text: string, attrs?: Attrs): void;
122
+ /** Splits the block at a position (Enter); returns where the caret goes. */
123
+ split(pos: number): number;
124
+ /** Deletes `from..to`, joining the blocks at both ends. */
125
+ deleteRange(from: number, to: number): void;
126
+ /** Before a list item's first paragraph is joined away, its nested blocks move next to the block it joins into. */
127
+ private moveFollowers;
128
+ private ensureBlock;
129
+ /** Inserts an inline object (mention, chip, date, hard break). */
130
+ insertInline(pos: number, name: 'mention' | 'refChip' | 'dateChip' | 'hardBreak', attrs: Attrs): void;
131
+ /** Inserts a block object (horizontal rule, picture) or a table at a position (splitting the paragraph there). */
132
+ insertBlock(pos: number, kind: 'hr' | 'image' | 'table', attrs?: Attrs): number;
133
+ /** Adds or removes a mark on a range (adds when not every character has it). */
134
+ toggleMark(from: number, to: number, mark: MarkName, value?: Attrs): void;
135
+ setMark(from: number, to: number, name: string, value: Attrs | null): void;
136
+ /** Paragraph, heading or code for the textblocks in a range (the same type again: back to a paragraph). */
137
+ setBlockType(from: number, to: number, type: BlockType): void;
138
+ /** Direction of the textblocks in a range (`null`: by the first letter). */
139
+ setDirection(from: number, to: number, dir: 'rtl' | 'ltr' | null): void;
140
+ /** The direction set on the block at a position. */
141
+ directionAt(pos: number): 'rtl' | 'ltr' | null;
142
+ /** Bullet / numbered / task list on or off for the blocks in a range (another list kind: switches the list). */
143
+ toggleList(from: number, to: number, kind: ListKind): void;
144
+ /** Quote on or off for the blocks in a range. */
145
+ toggleQuote(from: number, to: number): void;
146
+ /** Callout on or off (`tone` when it is put on, or to change the tone of the one the caret is in). */
147
+ toggleCallout(from: number, to: number, tone?: CalloutTone): void;
148
+ private toggleWrap;
149
+ /** The tone of the callout at a position. */
150
+ setCalloutTone(pos: number, tone: CalloutTone): void;
151
+ /** Indents the list items in a range (into the previous item). */
152
+ indent(from: number, to: number): void;
153
+ /** Outdents the list items in a range (a top-level item leaves the list). */
154
+ outdent(from: number, to: number): void;
155
+ /** Ticks or unticks the task on a line. */
156
+ toggleCheck(line: number): boolean;
157
+ /** The segment a line belongs to. */
158
+ segOfLine(line: number): Seg | null;
159
+ /** The flat position where a line starts. */
160
+ lineStart(line: number): number;
161
+ /** The inline element at a flat position (a chip, mention or date someone tapped). */
162
+ inlineAt(pos: number): {
163
+ name: string;
164
+ attrs: Attrs;
165
+ } | null;
166
+ /**
167
+ * Moves an item one level out (ProseMirror's liftListItem): out of a nested list into the parent list (the items after
168
+ * it become its children), or out of a top-level list into plain blocks (the list splits around it).
169
+ */
170
+ private liftItem;
171
+ }
172
+ export declare function blockTypeOf(seg: Seg): BlockType | null;
173
+ export declare function parentOf(el: Y.XmlElement): Parent;
174
+ export declare function indexIn(parent: Parent, child: unknown): number;
175
+ /** Removes an element; containers left empty go too (or get the paragraph their schema requires). */
176
+ export declare function removeNode(el: Y.XmlElement, cleanup?: boolean): void;
177
+ export {};
178
+ //# sourceMappingURL=ymodel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ymodel.d.ts","sourceRoot":"","sources":["../src/ymodel.ts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