@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.
- 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,173 @@
|
|
|
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 ElementCore {
|
|
12
|
+
edit(from, to, text) {
|
|
13
|
+
const event = {
|
|
14
|
+
seq: ++this.seq,
|
|
15
|
+
base: this.rev,
|
|
16
|
+
from,
|
|
17
|
+
to,
|
|
18
|
+
text,
|
|
19
|
+
len: this.text.length
|
|
20
|
+
};
|
|
21
|
+
const removedLines = countLines(this.text.slice(from, to));
|
|
22
|
+
const addedLines = countLines(text);
|
|
23
|
+
this.text = this.text.slice(0, from) + text + this.text.slice(to);
|
|
24
|
+
if (removedLines || addedLines) {
|
|
25
|
+
var _this_lines_line;
|
|
26
|
+
const line = countLines(this.text.slice(0, from));
|
|
27
|
+
const style = null != (_this_lines_line = this.lines[line]) ? _this_lines_line : {
|
|
28
|
+
t: 'p',
|
|
29
|
+
r: []
|
|
30
|
+
};
|
|
31
|
+
const copy = {
|
|
32
|
+
...style,
|
|
33
|
+
r: []
|
|
34
|
+
};
|
|
35
|
+
delete copy.mk;
|
|
36
|
+
this.lines.splice(line + 1, removedLines, ...Array.from({
|
|
37
|
+
length: addedLines
|
|
38
|
+
}, ()=>copy));
|
|
39
|
+
}
|
|
40
|
+
const caret = from + text.length;
|
|
41
|
+
this.sel = {
|
|
42
|
+
a: caret,
|
|
43
|
+
h: caret
|
|
44
|
+
};
|
|
45
|
+
return event;
|
|
46
|
+
}
|
|
47
|
+
select(a, h, focus = this.focused) {
|
|
48
|
+
this.sel = {
|
|
49
|
+
a,
|
|
50
|
+
h
|
|
51
|
+
};
|
|
52
|
+
this.focused = focus;
|
|
53
|
+
return {
|
|
54
|
+
seq: this.seq,
|
|
55
|
+
base: this.rev,
|
|
56
|
+
a,
|
|
57
|
+
h,
|
|
58
|
+
focus
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
apply(message) {
|
|
62
|
+
var _message_ops, _message_sel, _message_ops1;
|
|
63
|
+
var _message_ops2;
|
|
64
|
+
if (message.ack !== this.seq) return null;
|
|
65
|
+
if (message.full) {
|
|
66
|
+
var _message_sel1;
|
|
67
|
+
this.text = message.full.text;
|
|
68
|
+
this.appLines = message.full.lines;
|
|
69
|
+
this.lines = this.appLines.slice();
|
|
70
|
+
this.rev = message.rev;
|
|
71
|
+
const max = this.text.length;
|
|
72
|
+
this.sel = null != (_message_sel1 = message.sel) ? _message_sel1 : {
|
|
73
|
+
a: Math.min(this.sel.a, max),
|
|
74
|
+
h: Math.min(this.sel.h, max)
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
ops: [],
|
|
78
|
+
full: true,
|
|
79
|
+
restyle: [
|
|
80
|
+
0,
|
|
81
|
+
this.lines.length
|
|
82
|
+
],
|
|
83
|
+
sel: this.sel,
|
|
84
|
+
focus: Boolean(message.focus)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (message.lines && message.lines.of !== this.rev) return 'resync';
|
|
88
|
+
let { a, h } = this.sel;
|
|
89
|
+
for (const op of null != (_message_ops = message.ops) ? _message_ops : []){
|
|
90
|
+
if (op.from > this.text.length || op.to > this.text.length) return 'resync';
|
|
91
|
+
this.text = this.text.slice(0, op.from) + op.text + this.text.slice(op.to);
|
|
92
|
+
a = mapPos(a, op);
|
|
93
|
+
h = mapPos(h, op);
|
|
94
|
+
}
|
|
95
|
+
let restyle = null;
|
|
96
|
+
if (message.lines) {
|
|
97
|
+
const { at, del, ins } = message.lines;
|
|
98
|
+
this.appLines = [
|
|
99
|
+
...this.appLines.slice(0, at),
|
|
100
|
+
...ins,
|
|
101
|
+
...this.appLines.slice(at + del)
|
|
102
|
+
];
|
|
103
|
+
restyle = [
|
|
104
|
+
at,
|
|
105
|
+
at + ins.length
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
this.lines = this.appLines.slice();
|
|
109
|
+
if (this.lines.length !== countLines(this.text) + 1) return 'resync';
|
|
110
|
+
this.rev = message.rev;
|
|
111
|
+
this.sel = null != (_message_sel = message.sel) ? _message_sel : {
|
|
112
|
+
a,
|
|
113
|
+
h
|
|
114
|
+
};
|
|
115
|
+
if (null == (_message_ops2 = message.ops) ? void 0 : _message_ops2.length) {
|
|
116
|
+
let first = 1 / 0;
|
|
117
|
+
let last = -1;
|
|
118
|
+
for (const op of message.ops){
|
|
119
|
+
const line = countLines(this.text.slice(0, op.from));
|
|
120
|
+
first = Math.min(first, line);
|
|
121
|
+
last = Math.max(last, line + countLines(op.text) + 1);
|
|
122
|
+
}
|
|
123
|
+
restyle = restyle ? [
|
|
124
|
+
Math.min(restyle[0], first),
|
|
125
|
+
Math.max(restyle[1], last)
|
|
126
|
+
] : [
|
|
127
|
+
first,
|
|
128
|
+
last
|
|
129
|
+
];
|
|
130
|
+
restyle[1] = Math.min(restyle[1], this.lines.length);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
ops: null != (_message_ops1 = message.ops) ? _message_ops1 : [],
|
|
134
|
+
full: false,
|
|
135
|
+
restyle,
|
|
136
|
+
sel: this.sel,
|
|
137
|
+
focus: Boolean(message.focus)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
constructor(){
|
|
141
|
+
_define_property(this, "text", '');
|
|
142
|
+
_define_property(this, "appLines", [
|
|
143
|
+
{
|
|
144
|
+
t: 'p',
|
|
145
|
+
r: []
|
|
146
|
+
}
|
|
147
|
+
]);
|
|
148
|
+
_define_property(this, "lines", [
|
|
149
|
+
{
|
|
150
|
+
t: 'p',
|
|
151
|
+
r: []
|
|
152
|
+
}
|
|
153
|
+
]);
|
|
154
|
+
_define_property(this, "seq", 0);
|
|
155
|
+
_define_property(this, "rev", 0);
|
|
156
|
+
_define_property(this, "sel", {
|
|
157
|
+
a: 0,
|
|
158
|
+
h: 0
|
|
159
|
+
});
|
|
160
|
+
_define_property(this, "focused", false);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function countLines(text) {
|
|
164
|
+
let n = 0;
|
|
165
|
+
for(let i = 0; i < text.length; i++)if (10 === text.charCodeAt(i)) n++;
|
|
166
|
+
return n;
|
|
167
|
+
}
|
|
168
|
+
function mapPos(pos, op) {
|
|
169
|
+
if (pos <= op.from) return pos;
|
|
170
|
+
if (pos >= op.to) return pos + op.text.length - (op.to - op.from);
|
|
171
|
+
return op.from + op.text.length;
|
|
172
|
+
}
|
|
173
|
+
export { ElementCore, mapPos };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StandardProps } from '@lynx-js/types';
|
|
2
|
+
import type { RtAction, RtApplied, RtEdit, RtSelect } from './protocol.js';
|
|
3
|
+
/** The attributes and events of `<g9-richtext>`. */
|
|
4
|
+
export interface G9RichTextElementProps extends StandardProps {
|
|
5
|
+
editable?: boolean;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
/** `RtPalette` as JSON. */
|
|
8
|
+
palette?: string;
|
|
9
|
+
/** The page's direction for empty lines. */
|
|
10
|
+
'page-dir'?: 'rtl' | 'ltr';
|
|
11
|
+
/** Room under the content (px), so the last line can scroll above a floating toolbar. */
|
|
12
|
+
'bottom-inset'?: number;
|
|
13
|
+
bindrtedit?: (event: {
|
|
14
|
+
detail: RtEdit;
|
|
15
|
+
}) => void;
|
|
16
|
+
bindrtselect?: (event: {
|
|
17
|
+
detail: RtSelect;
|
|
18
|
+
}) => void;
|
|
19
|
+
bindrtapplied?: (event: {
|
|
20
|
+
detail: RtApplied;
|
|
21
|
+
}) => void;
|
|
22
|
+
bindrtaction?: (event: {
|
|
23
|
+
detail: RtAction;
|
|
24
|
+
}) => void;
|
|
25
|
+
}
|
|
26
|
+
declare module '@lynx-js/types' {
|
|
27
|
+
interface IntrinsicElements {
|
|
28
|
+
'g9-richtext': G9RichTextElementProps;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=element-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-types.d.ts","sourceRoot":"","sources":["../src/element-types.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAExE,oDAAoD;AACpD,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC3B,yFAAyF;IACzF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE,KAAK,IAAI,CAAC;IACrD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE,KAAK,IAAI,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE,KAAK,IAAI,CAAC;CACtD;AAED,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,iBAAiB;QACzB,aAAa,EAAE,sBAAsB,CAAC;KACvC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { guillemet, nextDirection, normalizeForSearch, resolvedDirection, wantsZwnj, ZWNJ } from './bidi.js';
|
|
2
|
+
export { type G9RichLinkOption, type G9RichMention, G9RichTextEditor, type G9RichTextEditorLabels, type G9RichTextEditorProps, type G9RichTextSessionHandle, useG9RichTextSession, } from './editor.js';
|
|
3
|
+
export { type Applied as G9RichApplied, ElementCore as G9RichElementCore, mapPos } from './element-core.js';
|
|
4
|
+
export type { G9RichTextElementProps } from './element-types.js';
|
|
5
|
+
export { G9RichLines, type G9RichLinesProps, lineClass, lineStyle, textClass } from './lines-view.js';
|
|
6
|
+
export { type JsonNode as G9RichJsonNode, type MentionCandidate as G9RichMentionCandidate, matchPeople, mentionIds, } from './mentions.js';
|
|
7
|
+
export { compose, diff, fromReplacements, type Replacement, TextOp, transform } from './ot.js';
|
|
8
|
+
export * from './protocol.js';
|
|
9
|
+
export { G9RichText, G9RichTextPort, type G9RichTextProps, type G9RichTextSessionLike, g9RichTextPalette, } from './rich-text.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC1G,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,OAAO,IAAI,aAAa,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACzG,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACnG,OAAO,EACL,KAAK,QAAQ,IAAI,cAAc,EAC/B,KAAK,gBAAgB,IAAI,sBAAsB,EAC/C,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC5F,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,UAAU,EACV,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./protocol.jsx";
|
|
2
|
+
export { ZWNJ, guillemet, nextDirection, normalizeForSearch, resolvedDirection, wantsZwnj } from "./bidi.jsx";
|
|
3
|
+
export { G9RichTextEditor, useG9RichTextSession } from "./editor.jsx";
|
|
4
|
+
export { ElementCore as G9RichElementCore, mapPos } from "./element-core.jsx";
|
|
5
|
+
export { G9RichLines, lineClass, lineStyle, textClass } from "./lines-view.jsx";
|
|
6
|
+
export { matchPeople, mentionIds } from "./mentions.jsx";
|
|
7
|
+
export { TextOp, compose, diff, fromReplacements, transform } from "./ot.jsx";
|
|
8
|
+
export { G9RichText, G9RichTextPort, g9RichTextPalette } from "./rich-text.jsx";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from '@lynx-js/react';
|
|
2
|
+
import { type RtLine } from './protocol.js';
|
|
3
|
+
import './richtext.css';
|
|
4
|
+
/** Props of {@link G9RichLines}. */
|
|
5
|
+
export interface G9RichLinesProps {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly lines: readonly RtLine[];
|
|
8
|
+
/** The line being edited (drawn by `renderLine`). */
|
|
9
|
+
readonly editing?: number;
|
|
10
|
+
readonly renderLine?: (index: number, line: RtLine, text: string) => ReactNode | null;
|
|
11
|
+
readonly onTapLine?: (index: number) => void;
|
|
12
|
+
readonly onToggleCheck?: (index: number) => void;
|
|
13
|
+
readonly className?: string;
|
|
14
|
+
/** The document's direction (a line without its own takes it). Default `ltr`. */
|
|
15
|
+
readonly direction?: 'ltr' | 'rtl';
|
|
16
|
+
}
|
|
17
|
+
/** The styled lines of a text (`text` split at `\n`, one {@link RtLine} each). */
|
|
18
|
+
export declare function G9RichLines(props: G9RichLinesProps): ReactNode;
|
|
19
|
+
/** A line's box classes (`rtl`: the line reads right to left). */
|
|
20
|
+
export declare function lineClass(line: RtLine, rtl?: boolean): string;
|
|
21
|
+
/** A line's text classes (the heading or code size, a done task struck through). */
|
|
22
|
+
export declare function textClass(line: RtLine): string;
|
|
23
|
+
/** A line's font classes, set on its text and on each of its runs (an inline text does not take its parent's font). */
|
|
24
|
+
export declare function fontClass(line: RtLine): string;
|
|
25
|
+
/** A line's indent (on its reading start: physical sides, Lynx has no logical ones) and explicit direction. */
|
|
26
|
+
export declare function lineStyle(line: RtLine, rtl?: boolean): Record<string, string>;
|
|
27
|
+
//# sourceMappingURL=lines-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines-view.d.ts","sourceRoot":"","sources":["../src/lines-view.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAa,KAAK,MAAM,EAAc,MAAM,YAAY,CAAC;AAChE,OAAO,gBAAgB,CAAC;AAExB,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,qDAAqD;IACrD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,CAAC;IACtF,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACpC;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAsB9D;AA2DD,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAQ,GAAG,MAAM,CAa3D;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,uHAAuH;AACvH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,+GAA+G;AAC/G,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM3E"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { memo } from "@lynx-js/react";
|
|
2
|
+
import { MARK, OBJ } from "./protocol.jsx";
|
|
3
|
+
import "./richtext.css";
|
|
4
|
+
function G9RichLines(props) {
|
|
5
|
+
var _props_editing;
|
|
6
|
+
const parts = props.text.split('\n');
|
|
7
|
+
const editing = null != (_props_editing = props.editing) ? _props_editing : -1;
|
|
8
|
+
return <view className={`g9-rt-lines${props.className ? ` ${props.className}` : ''}`}>
|
|
9
|
+
{props.lines.map((line, index)=>{
|
|
10
|
+
var _parts_index, _parts_index1, _line_dir;
|
|
11
|
+
return index === editing && props.renderLine ? <view key={`e${index}`}>{props.renderLine(index, line, null != (_parts_index = parts[index]) ? _parts_index : '')}</view> : <Line key={index} index={index} line={line} text={null != (_parts_index1 = parts[index]) ? _parts_index1 : ''} rtl={(null != (_line_dir = line.dir) ? _line_dir : props.direction) === 'rtl'} {...props.onTapLine ? {
|
|
12
|
+
onTap: props.onTapLine
|
|
13
|
+
} : {}} {...props.onToggleCheck ? {
|
|
14
|
+
onToggleCheck: props.onToggleCheck
|
|
15
|
+
} : {}}/>;
|
|
16
|
+
})}
|
|
17
|
+
</view>;
|
|
18
|
+
}
|
|
19
|
+
const Line = memo(function(props) {
|
|
20
|
+
var _mk_n, _line_ind;
|
|
21
|
+
var _line_img;
|
|
22
|
+
const { line, index } = props;
|
|
23
|
+
const mk = line.mk;
|
|
24
|
+
return <view className={lineClass(line, props.rtl)} style={lineStyle(line, props.rtl)} bindtap={()=>{
|
|
25
|
+
var _props_onTap;
|
|
26
|
+
return null == (_props_onTap = props.onTap) ? void 0 : _props_onTap.call(props, index);
|
|
27
|
+
}}>
|
|
28
|
+
{line.q ? <view className={props.rtl ? 'g9-rt-quote g9-rt-quote--rtl' : 'g9-rt-quote'} style={{
|
|
29
|
+
width: `${14 * line.q}px`
|
|
30
|
+
}}/> : null}
|
|
31
|
+
{mk ? <view className="g9-rt-marker" catchtap={()=>{
|
|
32
|
+
var _props_onToggleCheck;
|
|
33
|
+
return 't' === mk.k && (null == (_props_onToggleCheck = props.onToggleCheck) ? void 0 : _props_onToggleCheck.call(props, index));
|
|
34
|
+
}}>
|
|
35
|
+
{'t' === mk.k ? <view className={mk.c ? 'g9-rt-check g9-rt-check--on' : 'g9-rt-check'}/> : <text className="g9-rt-marker-text">{'n' === mk.k ? null != (_mk_n = mk.n) ? _mk_n : '' : bullet(null != (_line_ind = line.ind) ? _line_ind : 1)}</text>}
|
|
36
|
+
</view> : line.ind ? <view className="g9-rt-marker"/> : null}
|
|
37
|
+
{'hr' === line.t ? <view className="g9-rt-hr"/> : 'img' === line.t ? (null == (_line_img = line.img) ? void 0 : _line_img.src) ? <image src={line.img.src} mode="aspectFit" className="g9-rt-img" {...line.img.alt ? {
|
|
38
|
+
'accessibility-label': line.img.alt
|
|
39
|
+
} : {}}/> : <view className="g9-rt-img g9-rt-img--loading"/> : <text className={textClass(line)}>{runs(line.r, props.text, fontClass(line))}</text>}
|
|
40
|
+
</view>;
|
|
41
|
+
});
|
|
42
|
+
function bullet(depth) {
|
|
43
|
+
return depth % 3 === 1 ? '•' : depth % 3 === 2 ? '◦' : '▪';
|
|
44
|
+
}
|
|
45
|
+
function lineClass(line, rtl = false) {
|
|
46
|
+
return [
|
|
47
|
+
'g9-rt-line',
|
|
48
|
+
`g9-rt-line--${line.t}`,
|
|
49
|
+
line.co ? `g9-rt-callout g9-rt-callout--${line.co}${rtl ? ' g9-rt-callout--rtl' : ''}` : '',
|
|
50
|
+
line.cell ? `g9-rt-cell${line.cell.h ? ' g9-rt-cell--head' : ''}${line.cell.top ? ' g9-rt-cell--top' : ''}${rtl ? ' g9-rt-cell--rtl' : ''}` : '',
|
|
51
|
+
line.cf ? 'g9-rt-line--code-first' : '',
|
|
52
|
+
line.cl ? 'g9-rt-line--code-last' : ''
|
|
53
|
+
].filter(Boolean).join(' ');
|
|
54
|
+
}
|
|
55
|
+
function textClass(line) {
|
|
56
|
+
return `g9-rt-text ${fontClass(line)}`;
|
|
57
|
+
}
|
|
58
|
+
function fontClass(line) {
|
|
59
|
+
return `g9-rt-font g9-rt-text--${line.t}${'code' === line.t ? ' g9-rt-mono' : ''}${line.done ? ' g9-rt-text--done' : ''}`;
|
|
60
|
+
}
|
|
61
|
+
function lineStyle(line, rtl = false) {
|
|
62
|
+
var _line_ind;
|
|
63
|
+
const indent = (null != (_line_ind = line.ind) ? _line_ind : 0) > 1 ? (line.ind - 1) * 22 : 0;
|
|
64
|
+
const style = {};
|
|
65
|
+
if (indent) style[rtl ? 'paddingRight' : 'paddingLeft'] = `${indent}px`;
|
|
66
|
+
if (line.dir) style.direction = line.dir;
|
|
67
|
+
return style;
|
|
68
|
+
}
|
|
69
|
+
const OBJS = new RegExp(OBJ, 'g');
|
|
70
|
+
function runs(list, text1, font) {
|
|
71
|
+
if (!list.length) return '';
|
|
72
|
+
const out = [];
|
|
73
|
+
let at = 0;
|
|
74
|
+
list.forEach((run, index)=>{
|
|
75
|
+
var _run_m;
|
|
76
|
+
const part = text1.slice(at, at + run.n);
|
|
77
|
+
at += run.n;
|
|
78
|
+
if (run.a) return void out.push(<text key={index} className={`${font} g9-rt-atom g9-rt-atom--${run.a.k}${run.a.off ? ' g9-rt-atom--off' : ''}`} style={run.a.c ? {
|
|
79
|
+
color: run.a.c
|
|
80
|
+
} : {}}>
|
|
81
|
+
{` ${run.a.t} `}
|
|
82
|
+
</text>);
|
|
83
|
+
const m = null != (_run_m = run.m) ? _run_m : 0;
|
|
84
|
+
const classes = [
|
|
85
|
+
'g9-rt-run',
|
|
86
|
+
font,
|
|
87
|
+
m & MARK.bold ? 'g9-rt-run--b' : '',
|
|
88
|
+
m & MARK.italic ? 'g9-rt-run--i' : '',
|
|
89
|
+
m & MARK.underline ? 'g9-rt-run--u' : '',
|
|
90
|
+
m & MARK.strike ? 'g9-rt-run--s' : '',
|
|
91
|
+
m & MARK.code ? 'g9-rt-run--c' : '',
|
|
92
|
+
m & MARK.link ? 'g9-rt-run--a' : ''
|
|
93
|
+
].filter(Boolean).join(' ');
|
|
94
|
+
out.push(<text key={index} className={classes}>
|
|
95
|
+
{part.replace(OBJS, '')}
|
|
96
|
+
</text>);
|
|
97
|
+
});
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
export { G9RichLines, fontClass, lineClass, lineStyle, textClass };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mentions in documents: who a document mentions, and the people the @ picker offers. The server notifies from the
|
|
3
|
+
* mention nodes an update really inserts; these helpers serve the editor. Pure — tested in mentions.test.ts.
|
|
4
|
+
*/
|
|
5
|
+
/** A ProseMirror JSON node (what `editor.getJSON()` returns). */
|
|
6
|
+
export interface JsonNode {
|
|
7
|
+
type?: string;
|
|
8
|
+
attrs?: Record<string, unknown>;
|
|
9
|
+
content?: JsonNode[];
|
|
10
|
+
marks?: {
|
|
11
|
+
type: string;
|
|
12
|
+
attrs?: Record<string, unknown>;
|
|
13
|
+
}[];
|
|
14
|
+
text?: string;
|
|
15
|
+
}
|
|
16
|
+
/** The distinct people a document mentions, in order of first appearance. */
|
|
17
|
+
export declare function mentionIds(node: JsonNode | null | undefined): string[];
|
|
18
|
+
/** A person a mention can name. */
|
|
19
|
+
export interface MentionCandidate {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
userName?: string | null;
|
|
23
|
+
avatarUrl?: string | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* People matching what was typed after @, best first: a name or user name that starts with the query, then a word of
|
|
27
|
+
* the name that does, then anything containing it. Persian spelling variants match (ی/ي, ک/ك, with or without ZWNJ).
|
|
28
|
+
*/
|
|
29
|
+
export declare function matchPeople(people: MentionCandidate[], query: string, limit?: number, exclude?: string | null): MentionCandidate[];
|
|
30
|
+
//# sourceMappingURL=mentions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../src/mentions.ts"],"names":[],"mappings":"AAKA;;;GAGG;AAEH,iEAAiE;AACjE,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAAE,CAAC;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAStE;AAED,mCAAmC;AACnC,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,gBAAgB,EAAE,EAC1B,KAAK,EAAE,MAAM,EACb,KAAK,SAAI,EACT,OAAO,GAAE,MAAM,GAAG,IAAW,GAC5B,gBAAgB,EAAE,CAqBpB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { normalizeForSearch } from "./bidi.jsx";
|
|
2
|
+
const byCode = (a, b)=>Number(a > b) - Number(a < b);
|
|
3
|
+
function mentionIds(node) {
|
|
4
|
+
const ids = [];
|
|
5
|
+
const walk = (current)=>{
|
|
6
|
+
var _current_content;
|
|
7
|
+
var _current_attrs;
|
|
8
|
+
if ('mention' === current.type && 'string' == typeof (null == (_current_attrs = current.attrs) ? void 0 : _current_attrs.id) && !ids.includes(current.attrs.id)) ids.push(current.attrs.id);
|
|
9
|
+
for (const child of null != (_current_content = current.content) ? _current_content : [])walk(child);
|
|
10
|
+
};
|
|
11
|
+
if (node) walk(node);
|
|
12
|
+
return ids;
|
|
13
|
+
}
|
|
14
|
+
function matchPeople(people, query, limit = 8, exclude = null) {
|
|
15
|
+
const q = normalizeForSearch(query.trim());
|
|
16
|
+
const scored = [];
|
|
17
|
+
for (const person of people){
|
|
18
|
+
var _person_userName;
|
|
19
|
+
if (person.id === exclude) continue;
|
|
20
|
+
if (!q) {
|
|
21
|
+
scored.push({
|
|
22
|
+
person,
|
|
23
|
+
score: 1
|
|
24
|
+
});
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const name = normalizeForSearch(person.name);
|
|
28
|
+
const user = normalizeForSearch(null != (_person_userName = person.userName) ? _person_userName : '');
|
|
29
|
+
let score = 0;
|
|
30
|
+
if (name.startsWith(q) || user.startsWith(q)) score = 4;
|
|
31
|
+
else if (name.split(/\s+/).some((word)=>word.startsWith(q))) score = 3;
|
|
32
|
+
else if (name.includes(q) || user.includes(q)) score = 2;
|
|
33
|
+
if (score) scored.push({
|
|
34
|
+
person,
|
|
35
|
+
score
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return scored.sort((a, b)=>b.score - a.score || byCode(a.person.name, b.person.name)).slice(0, limit).map((entry)=>entry.person);
|
|
39
|
+
}
|
|
40
|
+
export { matchPeople, mentionIds };
|
package/dist/ot.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-text operations between the `<g9-richtext>` element and the document model (the classic retain/insert/delete
|
|
3
|
+
* operation of ot.js, re-implemented): the element edits a flat text and reports each change as a replacement; the
|
|
4
|
+
* model may have moved on meanwhile (a collaborator typed, a command reshaped a block), so both sides' changes are
|
|
5
|
+
* transformed against each other (Jupiter, see session.ts) and the element receives exactly the operations that turn its
|
|
6
|
+
* text into the model's. Inserts at the same place: the side passed first to {@link transform} goes first.
|
|
7
|
+
*
|
|
8
|
+
* Components: a positive number retains, a negative number deletes, a string inserts.
|
|
9
|
+
*/
|
|
10
|
+
export type Component = number | string;
|
|
11
|
+
/** An operation on a text (retain, insert, delete), composed and transformed. */
|
|
12
|
+
export declare class TextOp {
|
|
13
|
+
readonly ops: Component[];
|
|
14
|
+
baseLength: number;
|
|
15
|
+
targetLength: number;
|
|
16
|
+
retain(n: number): this;
|
|
17
|
+
insert(text: string): this;
|
|
18
|
+
delete(n: number): this;
|
|
19
|
+
isNoop(): boolean;
|
|
20
|
+
apply(text: string): string;
|
|
21
|
+
/** The operation as sequential replacements (positions in the text as it is after the previous ones). */
|
|
22
|
+
toReplacements(): Replacement[];
|
|
23
|
+
/** Maps a position in the base text to the target text (`assoc` < 0 keeps it before text inserted right there). */
|
|
24
|
+
map(pos: number, assoc?: number): number;
|
|
25
|
+
static replace(length: number, from: number, to: number, text: string): TextOp;
|
|
26
|
+
static identity(length: number): TextOp;
|
|
27
|
+
}
|
|
28
|
+
/** A replaced range and its new text. */
|
|
29
|
+
export interface Replacement {
|
|
30
|
+
from: number;
|
|
31
|
+
to: number;
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
/** `a` then `b` as one operation. */
|
|
35
|
+
export declare function compose(a: TextOp, b: TextOp): TextOp;
|
|
36
|
+
/**
|
|
37
|
+
* `a` and `b` were made on the same text; returns `[a', b']` with apply(apply(s, a), b') === apply(apply(s, b), a').
|
|
38
|
+
* Inserts at one place: `a`'s first.
|
|
39
|
+
*/
|
|
40
|
+
export declare function transform(a: TextOp, b: TextOp): [TextOp, TextOp];
|
|
41
|
+
/**
|
|
42
|
+
* The smallest single replacement turning `before` into `after` (common prefix and suffix). `hint`: a position the
|
|
43
|
+
* change is known to touch (the caret) — among equal answers the one closest to it is taken, so typing "a" after "a"
|
|
44
|
+
* is an insert at the caret, not at the start of the run.
|
|
45
|
+
*/
|
|
46
|
+
export declare function diff(before: string, after: string, hint?: number): TextOp;
|
|
47
|
+
/** Several replacements (sequential positions) as one operation on a text of `length`. */
|
|
48
|
+
export declare function fromReplacements(length: number, replacements: Replacement[]): TextOp;
|
|
49
|
+
//# sourceMappingURL=ot.d.ts.map
|
package/dist/ot.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ot.d.ts","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAExC,iFAAiF;AACjF,qBAAa,MAAM;IACjB,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,CAAM;IAC/B,UAAU,SAAK;IACf,YAAY,SAAK;IAEjB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAUvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAkB1B,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IASvB,MAAM,IAAI,OAAO;IAIjB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAe3B,yGAAyG;IACzG,cAAc,IAAI,WAAW,EAAE;IAwB/B,mHAAmH;IACnH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM;IAoBpC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAU9E,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAGxC;AAED,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qCAAqC;AACrC,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA8EpD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAyFhE;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,MAAM,CA4BrE;AAED,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAIpF"}
|