@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.
- package/README.md +32 -2
- package/catalog/cards/G9RichLines.md +16 -0
- package/catalog/cards/G9RichText.md +17 -0
- package/catalog/cards/G9RichTextEditor.md +17 -0
- package/catalog/catalog.json +1667 -0
- package/catalog/index.md +7 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/bidi.d.ts +24 -0
- package/dist/bidi.d.ts.map +1 -0
- package/dist/bidi.jsx +102 -0
- package/dist/editor.d.ts +111 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.jsx +556 -0
- package/dist/element-core.d.ts +60 -0
- package/dist/element-core.d.ts.map +1 -0
- package/dist/element-core.jsx +173 -0
- package/dist/element-types.d.ts +31 -0
- package/dist/element-types.d.ts.map +1 -0
- package/dist/element-types.jsx +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +8 -0
- package/dist/lines-view.d.ts +27 -0
- package/dist/lines-view.d.ts.map +1 -0
- package/dist/lines-view.jsx +100 -0
- package/dist/mentions.d.ts +30 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.jsx +40 -0
- package/dist/ot.d.ts +49 -0
- package/dist/ot.d.ts.map +1 -0
- package/dist/ot.jsx +306 -0
- package/dist/protocol.d.ts +199 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.jsx +11 -0
- package/dist/rich-text.d.ts +48 -0
- package/dist/rich-text.d.ts.map +1 -0
- package/dist/rich-text.jsx +186 -0
- package/dist/richtext.css +411 -0
- package/dist/richtext.css.map +1 -0
- package/dist/session.d.ts +142 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.jsx +665 -0
- package/dist/yjs.d.ts +3 -0
- package/dist/yjs.d.ts.map +1 -0
- package/dist/yjs.jsx +2 -0
- package/dist/ymodel.d.ts +178 -0
- package/dist/ymodel.d.ts.map +1 -0
- package/dist/ymodel.jsx +1379 -0
- package/package.json +68 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Awareness } from 'y-protocols/awareness';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { TextOp } from './ot.js';
|
|
4
|
+
import type { RtAction, RtApplied, RtEdit, RtLine, RtMessage, RtSelect, RtSplice } from './protocol.js';
|
|
5
|
+
import { type Attrs, DocModel, type ModelContext } from './ymodel.js';
|
|
6
|
+
/**
|
|
7
|
+
* One open document between the `<g9-richtext>` element and the Yjs document (protocol.ts): the element's edits go into
|
|
8
|
+
* the model, the model's changes (collaborators, commands, undo) go to the element, and both stay in step although they
|
|
9
|
+
* run on different threads.
|
|
10
|
+
*
|
|
11
|
+
* Jupiter: the app keeps the operations it changed the text by that the element has not confirmed yet (`queue`, in the
|
|
12
|
+
* element's coordinates). An edit from the element names the app state it was made on (`base`); it is transformed over
|
|
13
|
+
* the queued operations after that state (and they over it), then applied. When the model does not end up where the
|
|
14
|
+
* transformed edit predicts (Enter on an empty list item leaves the list, "# " becomes a heading…) the difference is
|
|
15
|
+
* queued as one more operation. Messages carry every queued operation the element has not applied, so applying one
|
|
16
|
+
* makes the element's text equal to the model's — the element applies a message only when it has no edit on its way
|
|
17
|
+
* (`ack` = its last `seq`), so it never needs to transform anything itself.
|
|
18
|
+
*/
|
|
19
|
+
export interface ElementPort {
|
|
20
|
+
send(message: RtMessage): void;
|
|
21
|
+
}
|
|
22
|
+
/** What a session needs: the document, the element's port and its callbacks. */
|
|
23
|
+
export interface SessionOptions {
|
|
24
|
+
doc: Y.Doc;
|
|
25
|
+
port: ElementPort;
|
|
26
|
+
context?: ModelContext;
|
|
27
|
+
awareness?: Awareness;
|
|
28
|
+
/** My identity on the carets of others (`{ id, name, color }` like the web editor). */
|
|
29
|
+
user?: Record<string, unknown>;
|
|
30
|
+
/** Collaborators' identities for their carets on this side. */
|
|
31
|
+
peerName?: (clientId: number, state: Record<string, unknown>) => {
|
|
32
|
+
name: string;
|
|
33
|
+
color: string;
|
|
34
|
+
} | null;
|
|
35
|
+
/** Called after every change of the text, the selection or the marks there (toolbar state). */
|
|
36
|
+
onState?: () => void;
|
|
37
|
+
/** The text changed (by anyone). */
|
|
38
|
+
onText?: () => void;
|
|
39
|
+
}
|
|
40
|
+
/** A selection in the flat text (anchor and head). */
|
|
41
|
+
export interface Selection {
|
|
42
|
+
a: number;
|
|
43
|
+
h: number;
|
|
44
|
+
}
|
|
45
|
+
/** What the toolbar shows for the selection. */
|
|
46
|
+
export interface SelectionState {
|
|
47
|
+
marks: Attrs;
|
|
48
|
+
block: 'p' | 'h1' | 'h2' | 'h3' | 'code' | 'hr' | 'img';
|
|
49
|
+
list: 'bullet' | 'ordered' | 'task' | null;
|
|
50
|
+
quote: boolean;
|
|
51
|
+
callout: string | null;
|
|
52
|
+
dir: 'rtl' | 'ltr' | null;
|
|
53
|
+
canIndent: boolean;
|
|
54
|
+
canOutdent: boolean;
|
|
55
|
+
inTable: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** A document and its element together: edits both ways, selection, marks, blocks and undo. */
|
|
58
|
+
export declare class RichTextSession {
|
|
59
|
+
private readonly options;
|
|
60
|
+
readonly model: DocModel;
|
|
61
|
+
readonly undoManager: Y.UndoManager;
|
|
62
|
+
private readonly port;
|
|
63
|
+
private readonly awareness?;
|
|
64
|
+
private rev;
|
|
65
|
+
private queue;
|
|
66
|
+
/** The last state the element is known to have (from an edit's base or `rtapplied`). */
|
|
67
|
+
private confirmed;
|
|
68
|
+
/** The state the element is believed to have (optimistic: the last message, if it had no edit on its way). */
|
|
69
|
+
private elemRev;
|
|
70
|
+
/** The last element edit applied. */
|
|
71
|
+
private ack;
|
|
72
|
+
private text;
|
|
73
|
+
private readonly linesAt;
|
|
74
|
+
private needFull;
|
|
75
|
+
private sendTimer;
|
|
76
|
+
private applying;
|
|
77
|
+
private pendingSel;
|
|
78
|
+
private focusNext;
|
|
79
|
+
private storedMarks;
|
|
80
|
+
private caretAfterEdit;
|
|
81
|
+
private focused;
|
|
82
|
+
private destroyed;
|
|
83
|
+
sel: Selection;
|
|
84
|
+
private readonly offModel;
|
|
85
|
+
private readonly onAwareness?;
|
|
86
|
+
constructor(options: SessionOptions);
|
|
87
|
+
destroy(): void;
|
|
88
|
+
/** The element (re)mounted — a new element counts its edits from 0: send it everything. */
|
|
89
|
+
reset(): void;
|
|
90
|
+
/** Labels changed (people, chips, pictures, the language): restyle the lines. */
|
|
91
|
+
relabel(context?: ModelContext): void;
|
|
92
|
+
get plainText(): string;
|
|
93
|
+
edit(event: RtEdit): void;
|
|
94
|
+
select(event: RtSelect): void;
|
|
95
|
+
applied(event: RtApplied): void;
|
|
96
|
+
/** `check` and `key` actions (taps on chips are the page's: it knows where they lead). */
|
|
97
|
+
action(event: RtAction): void;
|
|
98
|
+
/** Runs a model change from the page (toolbar, menus) and tells the element. `select`: where the caret goes. */
|
|
99
|
+
command(fn: () => unknown, select?: (op: TextOp) => Selection | null): void;
|
|
100
|
+
toggleMark(mark: 'bold' | 'italic' | 'underline' | 'strike' | 'code'): void;
|
|
101
|
+
setLink(href: string | null): void;
|
|
102
|
+
/** Replaces the selection (or `range`) with an inline object, then a space; the caret goes after them. */
|
|
103
|
+
insertInline(name: 'mention' | 'refChip' | 'dateChip', attrs: Attrs, range?: {
|
|
104
|
+
from: number;
|
|
105
|
+
to: number;
|
|
106
|
+
}): void;
|
|
107
|
+
/** Replaces `from..to` with text (slash commands remove their "/word", suggestions complete words). */
|
|
108
|
+
replaceText(from: number, to: number, text: string): void;
|
|
109
|
+
insertBlock(kind: 'hr' | 'image' | 'table', attrs?: Attrs): void;
|
|
110
|
+
undo(): void;
|
|
111
|
+
redo(): void;
|
|
112
|
+
get canUndo(): boolean;
|
|
113
|
+
get canRedo(): boolean;
|
|
114
|
+
private history;
|
|
115
|
+
/** Moves the selection (and shows the keyboard when `focus`). */
|
|
116
|
+
setSelection(sel: Selection, focus?: boolean): void;
|
|
117
|
+
focus(): void;
|
|
118
|
+
/** The toolbar's view of the selection. */
|
|
119
|
+
state(): SelectionState;
|
|
120
|
+
private modelChanged;
|
|
121
|
+
private commit;
|
|
122
|
+
private confirm;
|
|
123
|
+
/** An element position (after its edit `ack`, on state `base`) in the model's text. */
|
|
124
|
+
private toModel;
|
|
125
|
+
private lastFullRev;
|
|
126
|
+
private scheduleSend;
|
|
127
|
+
/** Sends the element what it lacks (also used directly by tests). */
|
|
128
|
+
flush(): void;
|
|
129
|
+
private applyOp;
|
|
130
|
+
/** Markdown shortcuts at a block start, typed with a space: "# ", "- ", "1. ", "[ ] ", "> ", "```". */
|
|
131
|
+
private inputRules;
|
|
132
|
+
private publishCursor;
|
|
133
|
+
/** A flat position as a Yjs relative position the web's y-prosemirror resolves (and back: {@link absolute}). */
|
|
134
|
+
relative(pos: number): Y.RelativePosition | null;
|
|
135
|
+
absolute(rel: Y.RelativePosition): number | null;
|
|
136
|
+
private peers;
|
|
137
|
+
/** Plain text of the document for search (blocks separated by blank lines, objects as their text). */
|
|
138
|
+
searchText(): string;
|
|
139
|
+
}
|
|
140
|
+
/** The line array change between two states (common start and end kept). */
|
|
141
|
+
export declare function spliceOf(before: RtLine[], after: RtLine[]): RtSplice | null;
|
|
142
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAiB,MAAM,EAAa,MAAM,MAAM,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACrG,OAAO,EAAE,KAAK,KAAK,EAAE,QAAQ,EAA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