mossmd 0.8.1
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/CHANGELOG.md +87 -0
- package/LICENSE +21 -0
- package/README.md +336 -0
- package/dist/collab/index.d.ts +14 -0
- package/dist/collab/index.d.ts.map +1 -0
- package/dist/collab/index.js +6 -0
- package/dist/collab/index.js.map +1 -0
- package/dist/core/code-languages.d.ts +3 -0
- package/dist/core/code-languages.d.ts.map +1 -0
- package/dist/core/code-languages.js +130 -0
- package/dist/core/code-languages.js.map +1 -0
- package/dist/core/decoration-utils.d.ts +4 -0
- package/dist/core/decoration-utils.d.ts.map +1 -0
- package/dist/core/decoration-utils.js +25 -0
- package/dist/core/decoration-utils.js.map +1 -0
- package/dist/core/edit-helpers.d.ts +13 -0
- package/dist/core/edit-helpers.d.ts.map +1 -0
- package/dist/core/edit-helpers.js +318 -0
- package/dist/core/edit-helpers.js.map +1 -0
- package/dist/core/icons.d.ts +16 -0
- package/dist/core/icons.d.ts.map +1 -0
- package/dist/core/icons.js +86 -0
- package/dist/core/icons.js.map +1 -0
- package/dist/core/inline-preview.d.ts +32 -0
- package/dist/core/inline-preview.d.ts.map +1 -0
- package/dist/core/inline-preview.js +925 -0
- package/dist/core/inline-preview.js.map +1 -0
- package/dist/core/list-editing.d.ts +10 -0
- package/dist/core/list-editing.d.ts.map +1 -0
- package/dist/core/list-editing.js +244 -0
- package/dist/core/list-editing.js.map +1 -0
- package/dist/core/list-model.d.ts +40 -0
- package/dist/core/list-model.d.ts.map +1 -0
- package/dist/core/list-model.js +114 -0
- package/dist/core/list-model.js.map +1 -0
- package/dist/core/list-navigation.d.ts +3 -0
- package/dist/core/list-navigation.d.ts.map +1 -0
- package/dist/core/list-navigation.js +234 -0
- package/dist/core/list-navigation.js.map +1 -0
- package/dist/core/markdown-context.d.ts +3 -0
- package/dist/core/markdown-context.d.ts.map +1 -0
- package/dist/core/markdown-context.js +10 -0
- package/dist/core/markdown-context.js.map +1 -0
- package/dist/core/preview-activity.d.ts +18 -0
- package/dist/core/preview-activity.d.ts.map +1 -0
- package/dist/core/preview-activity.js +199 -0
- package/dist/core/preview-activity.js.map +1 -0
- package/dist/core/preview-widgets.d.ts +65 -0
- package/dist/core/preview-widgets.d.ts.map +1 -0
- package/dist/core/preview-widgets.js +359 -0
- package/dist/core/preview-widgets.js.map +1 -0
- package/dist/core/read-only.d.ts +26 -0
- package/dist/core/read-only.d.ts.map +1 -0
- package/dist/core/read-only.js +49 -0
- package/dist/core/read-only.js.map +1 -0
- package/dist/core/tree-progress.d.ts +29 -0
- package/dist/core/tree-progress.d.ts.map +1 -0
- package/dist/core/tree-progress.js +143 -0
- package/dist/core/tree-progress.js.map +1 -0
- package/dist/editor.d.ts +219 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +551 -0
- package/dist/editor.js.map +1 -0
- package/dist/features/callout/index.d.ts +9 -0
- package/dist/features/callout/index.d.ts.map +1 -0
- package/dist/features/callout/index.js +223 -0
- package/dist/features/callout/index.js.map +1 -0
- package/dist/features/file-blocks/index.d.ts +12 -0
- package/dist/features/file-blocks/index.d.ts.map +1 -0
- package/dist/features/file-blocks/index.js +397 -0
- package/dist/features/file-blocks/index.js.map +1 -0
- package/dist/features/image/index.d.ts +28 -0
- package/dist/features/image/index.d.ts.map +1 -0
- package/dist/features/image/index.js +699 -0
- package/dist/features/image/index.js.map +1 -0
- package/dist/features/index.d.ts +17 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +9 -0
- package/dist/features/index.js.map +1 -0
- package/dist/features/search/index.d.ts +4 -0
- package/dist/features/search/index.d.ts.map +1 -0
- package/dist/features/search/index.js +131 -0
- package/dist/features/search/index.js.map +1 -0
- package/dist/features/slash-commands/index.d.ts +52 -0
- package/dist/features/slash-commands/index.d.ts.map +1 -0
- package/dist/features/slash-commands/index.js +422 -0
- package/dist/features/slash-commands/index.js.map +1 -0
- package/dist/features/table/index.d.ts +44 -0
- package/dist/features/table/index.d.ts.map +1 -0
- package/dist/features/table/index.js +1262 -0
- package/dist/features/table/index.js.map +1 -0
- package/dist/features/upload/index.d.ts +80 -0
- package/dist/features/upload/index.d.ts.map +1 -0
- package/dist/features/upload/index.js +790 -0
- package/dist/features/upload/index.js.map +1 -0
- package/dist/features/wiki-links/index.d.ts +27 -0
- package/dist/features/wiki-links/index.d.ts.map +1 -0
- package/dist/features/wiki-links/index.js +577 -0
- package/dist/features/wiki-links/index.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/content.css +247 -0
- package/dist/styles/inline-preview.css +2116 -0
- package/dist/styles/tokens.css +234 -0
- package/dist/syntax/highlight.d.ts +10 -0
- package/dist/syntax/highlight.d.ts.map +1 -0
- package/dist/syntax/highlight.js +75 -0
- package/dist/syntax/highlight.js.map +1 -0
- package/dist/syntax/index.d.ts +16 -0
- package/dist/syntax/index.d.ts.map +1 -0
- package/dist/syntax/index.js +29 -0
- package/dist/syntax/index.js.map +1 -0
- package/dist/theme/index.d.ts +6 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +204 -0
- package/dist/theme/index.js.map +1 -0
- package/package.json +237 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { Facet } from '@codemirror/state';
|
|
2
|
+
import { WidgetType } from '@codemirror/view';
|
|
3
|
+
import { BadgeDollarSign, Bookmark, CalendarCheck, Check, Circle, CircleAlert, CircleQuestionMark, Copy, Info, Lightbulb, LoaderCircle, MapPin, Minus, Quote, Square, Star, StickyNote, ThumbsDown, ThumbsUp, TrendingDown, TrendingUp, } from 'lucide-react';
|
|
4
|
+
import { appendMossIcon, mossLucideIcon, } from './icons';
|
|
5
|
+
const taskIcon = (icon) => mossLucideIcon(icon);
|
|
6
|
+
const EMPTY_TASK_ICON = taskIcon(Circle);
|
|
7
|
+
export const DEFAULT_TASK_CHECKBOXES = {
|
|
8
|
+
' ': { icon: taskIcon(Square), label: 'To Do', completed: false, filled: false, toggleTo: 'x' },
|
|
9
|
+
'/': { icon: taskIcon(LoaderCircle), label: 'In Progress', completed: false, filled: false, toggleTo: null },
|
|
10
|
+
x: { icon: taskIcon(Check), label: 'Done', completed: true, filled: false, toggleTo: ' ' },
|
|
11
|
+
'-': { icon: taskIcon(Minus), label: 'Cancelled', completed: false, filled: false, toggleTo: null },
|
|
12
|
+
'<': { icon: taskIcon(CalendarCheck), label: 'Scheduled', completed: false, filled: false, toggleTo: null },
|
|
13
|
+
'!': { icon: taskIcon(CircleAlert), label: 'Important', completed: false, filled: false, toggleTo: null },
|
|
14
|
+
'?': { icon: taskIcon(CircleQuestionMark), label: 'Question', completed: false, filled: false, toggleTo: null },
|
|
15
|
+
i: { icon: taskIcon(Info), label: 'Information', completed: false, filled: false, toggleTo: null },
|
|
16
|
+
S: { icon: taskIcon(BadgeDollarSign), label: 'Amount', completed: false, filled: false, toggleTo: null },
|
|
17
|
+
'*': { icon: taskIcon(Star), label: 'Star', completed: false, filled: true, toggleTo: null },
|
|
18
|
+
b: { icon: taskIcon(Bookmark), label: 'Bookmark', completed: false, filled: true, toggleTo: null },
|
|
19
|
+
'"': { icon: taskIcon(Quote), label: 'Quote', completed: false, filled: false, toggleTo: null },
|
|
20
|
+
n: { icon: taskIcon(StickyNote), label: 'Note', completed: false, filled: false, toggleTo: null },
|
|
21
|
+
l: { icon: taskIcon(MapPin), label: 'Location', completed: false, filled: false, toggleTo: null },
|
|
22
|
+
I: { icon: taskIcon(Lightbulb), label: 'Idea', completed: false, filled: false, toggleTo: null },
|
|
23
|
+
p: { icon: taskIcon(ThumbsUp), label: 'Pro', completed: false, filled: false, toggleTo: null },
|
|
24
|
+
c: { icon: taskIcon(ThumbsDown), label: 'Con', completed: false, filled: false, toggleTo: null },
|
|
25
|
+
u: { icon: taskIcon(TrendingUp), label: 'Up', completed: false, filled: false, toggleTo: null },
|
|
26
|
+
d: { icon: taskIcon(TrendingDown), label: 'Down', completed: false, filled: false, toggleTo: null },
|
|
27
|
+
};
|
|
28
|
+
export const taskCheckboxConfigFacet = Facet.define({
|
|
29
|
+
combine: (values) => values[0] ?? {},
|
|
30
|
+
});
|
|
31
|
+
function normalizeTaskStatusKey(raw) {
|
|
32
|
+
if (raw === '\\*' || raw === '*')
|
|
33
|
+
return '*';
|
|
34
|
+
if (raw === 'X' || raw === 'x')
|
|
35
|
+
return 'x';
|
|
36
|
+
if (raw.length === 1 || (raw.length === 2 && raw.startsWith('-'))) {
|
|
37
|
+
return raw;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
export function resolveTaskCheckboxStatus(key, config) {
|
|
42
|
+
const emptyVariant = key.startsWith('-') && key.length > 1;
|
|
43
|
+
const baseKey = emptyVariant ? key.slice(1) : key;
|
|
44
|
+
const defaults = DEFAULT_TASK_CHECKBOXES[key] ?? DEFAULT_TASK_CHECKBOXES[baseKey];
|
|
45
|
+
const override = config[key];
|
|
46
|
+
const baseOverride = emptyVariant ? config[baseKey] : undefined;
|
|
47
|
+
if (!defaults && !override && !baseOverride)
|
|
48
|
+
return null;
|
|
49
|
+
const fallbackToggleTo = key === ' ' ? 'x' : key === 'x' ? ' ' : emptyVariant ? baseKey : `-${key}`;
|
|
50
|
+
const toggleTo = override?.toggleTo ??
|
|
51
|
+
(emptyVariant
|
|
52
|
+
? baseOverride?.toggleTo ?? fallbackToggleTo
|
|
53
|
+
: defaults?.toggleTo ?? fallbackToggleTo);
|
|
54
|
+
return {
|
|
55
|
+
icon: override?.icon ??
|
|
56
|
+
(emptyVariant ? EMPTY_TASK_ICON : undefined) ??
|
|
57
|
+
defaults?.icon ??
|
|
58
|
+
baseOverride?.icon ??
|
|
59
|
+
EMPTY_TASK_ICON,
|
|
60
|
+
label: override?.label ??
|
|
61
|
+
baseOverride?.label ??
|
|
62
|
+
defaults?.label ??
|
|
63
|
+
`Task: ${baseKey}`,
|
|
64
|
+
completed: emptyVariant
|
|
65
|
+
? false
|
|
66
|
+
: override?.completed ?? defaults?.completed ?? false,
|
|
67
|
+
filled: emptyVariant
|
|
68
|
+
? false
|
|
69
|
+
: override?.filled ?? defaults?.filled ?? false,
|
|
70
|
+
toggleTo,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function shouldUseNativeTaskCheckbox(key, config) {
|
|
74
|
+
return (key === ' ' || key === 'x') && config[key]?.icon == null;
|
|
75
|
+
}
|
|
76
|
+
function parseTaskMarker(lineText, markerFrom, listFrom, config) {
|
|
77
|
+
const match = lineText.slice(markerFrom).match(/^\[([^\]]+)\]/);
|
|
78
|
+
if (!match)
|
|
79
|
+
return null;
|
|
80
|
+
const key = normalizeTaskStatusKey(match[1]);
|
|
81
|
+
if (key == null)
|
|
82
|
+
return null;
|
|
83
|
+
const markerTo = markerFrom + match[0].length;
|
|
84
|
+
const separator = lineText.slice(markerTo).match(/^\s/)?.[0] ?? '';
|
|
85
|
+
if (markerTo < lineText.length && separator === '')
|
|
86
|
+
return null;
|
|
87
|
+
const status = resolveTaskCheckboxStatus(key, config);
|
|
88
|
+
if (!status)
|
|
89
|
+
return null;
|
|
90
|
+
return {
|
|
91
|
+
key,
|
|
92
|
+
raw: match[0],
|
|
93
|
+
markerFrom,
|
|
94
|
+
markerTo,
|
|
95
|
+
listFrom,
|
|
96
|
+
separator,
|
|
97
|
+
status,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function parseListTaskMarker(lineText, config) {
|
|
101
|
+
const listMatch = lineText.match(/^(\s*)([-*+])(\s+)/);
|
|
102
|
+
if (!listMatch)
|
|
103
|
+
return null;
|
|
104
|
+
const [, indent] = listMatch;
|
|
105
|
+
const markerFrom = listMatch[0].length;
|
|
106
|
+
return parseTaskMarker(lineText, markerFrom, indent.length, config);
|
|
107
|
+
}
|
|
108
|
+
export function fencedCodeSource(doc, from, to) {
|
|
109
|
+
const raw = doc.sliceString(from, to);
|
|
110
|
+
const lines = raw.split('\n');
|
|
111
|
+
if (lines.length < 2)
|
|
112
|
+
return raw;
|
|
113
|
+
if (!/^ {0,3}(`{3,}|~{3,})/.test(lines[0]))
|
|
114
|
+
return raw;
|
|
115
|
+
if (!/^ {0,3}(`{3,}|~{3,})\s*$/.test(lines[lines.length - 1]))
|
|
116
|
+
return raw;
|
|
117
|
+
return lines.slice(1, -1).join('\n');
|
|
118
|
+
}
|
|
119
|
+
const BULLET_SYMBOLS = ['✦', '✧'];
|
|
120
|
+
export class BulletWidget extends WidgetType {
|
|
121
|
+
constructor(depth) {
|
|
122
|
+
super();
|
|
123
|
+
Object.defineProperty(this, "symbol", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: true,
|
|
126
|
+
writable: true,
|
|
127
|
+
value: void 0
|
|
128
|
+
});
|
|
129
|
+
this.symbol = BULLET_SYMBOLS[Math.abs(depth) % BULLET_SYMBOLS.length];
|
|
130
|
+
}
|
|
131
|
+
eq(other) {
|
|
132
|
+
return other.symbol === this.symbol;
|
|
133
|
+
}
|
|
134
|
+
toDOM() {
|
|
135
|
+
const span = document.createElement('span');
|
|
136
|
+
span.className =
|
|
137
|
+
'cm-moss-list-marker cm-moss-unordered-marker cm-moss-bullet';
|
|
138
|
+
span.textContent = this.symbol;
|
|
139
|
+
return span;
|
|
140
|
+
}
|
|
141
|
+
ignoreEvent() {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function copyTextToClipboard(text) {
|
|
146
|
+
try {
|
|
147
|
+
if (navigator.clipboard?.writeText) {
|
|
148
|
+
await navigator.clipboard.writeText(text);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// Fall back to the legacy path below.
|
|
154
|
+
}
|
|
155
|
+
const textarea = document.createElement('textarea');
|
|
156
|
+
textarea.value = text;
|
|
157
|
+
textarea.setAttribute('readonly', 'true');
|
|
158
|
+
textarea.style.position = 'fixed';
|
|
159
|
+
textarea.style.left = '-9999px';
|
|
160
|
+
textarea.style.top = '0';
|
|
161
|
+
document.body.appendChild(textarea);
|
|
162
|
+
textarea.select();
|
|
163
|
+
try {
|
|
164
|
+
if (document.execCommand('copy'))
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
textarea.remove();
|
|
169
|
+
}
|
|
170
|
+
throw new Error('Copy failed');
|
|
171
|
+
}
|
|
172
|
+
const CODE_COPY_ICON = mossLucideIcon(Copy, { size: 16 });
|
|
173
|
+
const CODE_COPY_SUCCESS_ICON = mossLucideIcon(Check, { size: 16 });
|
|
174
|
+
export class CodeCopyWidget extends WidgetType {
|
|
175
|
+
constructor(code) {
|
|
176
|
+
super();
|
|
177
|
+
Object.defineProperty(this, "code", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
configurable: true,
|
|
180
|
+
writable: true,
|
|
181
|
+
value: code
|
|
182
|
+
});
|
|
183
|
+
Object.defineProperty(this, "button", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: null
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(this, "copiedTimer", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
configurable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
value: null
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
eq(other) {
|
|
197
|
+
return other.code === this.code;
|
|
198
|
+
}
|
|
199
|
+
setCopied(copied) {
|
|
200
|
+
if (!this.button)
|
|
201
|
+
return;
|
|
202
|
+
this.button.classList.toggle('is-copied', copied);
|
|
203
|
+
appendMossIcon(this.button, copied ? CODE_COPY_SUCCESS_ICON : CODE_COPY_ICON);
|
|
204
|
+
this.button.setAttribute('aria-label', copied ? 'Copied' : 'Copy code');
|
|
205
|
+
this.button.title = copied ? 'Copied' : 'Copy code';
|
|
206
|
+
}
|
|
207
|
+
clearTimer() {
|
|
208
|
+
if (this.copiedTimer != null) {
|
|
209
|
+
window.clearTimeout(this.copiedTimer);
|
|
210
|
+
this.copiedTimer = null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
flashCopied() {
|
|
214
|
+
this.clearTimer();
|
|
215
|
+
this.setCopied(true);
|
|
216
|
+
this.copiedTimer = window.setTimeout(() => {
|
|
217
|
+
this.copiedTimer = null;
|
|
218
|
+
this.setCopied(false);
|
|
219
|
+
}, 1200);
|
|
220
|
+
}
|
|
221
|
+
toDOM() {
|
|
222
|
+
const button = document.createElement('button');
|
|
223
|
+
button.type = 'button';
|
|
224
|
+
button.className = 'cm-moss-code-copy';
|
|
225
|
+
appendMossIcon(button, CODE_COPY_ICON);
|
|
226
|
+
button.setAttribute('aria-label', 'Copy code');
|
|
227
|
+
button.title = 'Copy code';
|
|
228
|
+
this.button = button;
|
|
229
|
+
button.addEventListener('mousedown', (event) => {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
event.stopPropagation();
|
|
232
|
+
});
|
|
233
|
+
button.addEventListener('click', async (event) => {
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
event.stopPropagation();
|
|
236
|
+
const copied = await copyTextToClipboard(this.code)
|
|
237
|
+
.then(() => true)
|
|
238
|
+
.catch(() => false);
|
|
239
|
+
if (copied)
|
|
240
|
+
this.flashCopied();
|
|
241
|
+
});
|
|
242
|
+
return button;
|
|
243
|
+
}
|
|
244
|
+
destroy() {
|
|
245
|
+
this.clearTimer();
|
|
246
|
+
this.button = null;
|
|
247
|
+
}
|
|
248
|
+
ignoreEvent(event) {
|
|
249
|
+
return event.type === 'mousedown' || event.type === 'click';
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export class TaskCheckboxWidget extends WidgetType {
|
|
253
|
+
constructor(key, raw, status, markerFrom, native = key === ' ' || key === 'x') {
|
|
254
|
+
super();
|
|
255
|
+
Object.defineProperty(this, "key", {
|
|
256
|
+
enumerable: true,
|
|
257
|
+
configurable: true,
|
|
258
|
+
writable: true,
|
|
259
|
+
value: key
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(this, "raw", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
configurable: true,
|
|
264
|
+
writable: true,
|
|
265
|
+
value: raw
|
|
266
|
+
});
|
|
267
|
+
Object.defineProperty(this, "status", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
configurable: true,
|
|
270
|
+
writable: true,
|
|
271
|
+
value: status
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(this, "markerFrom", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
configurable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
value: markerFrom
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(this, "native", {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
configurable: true,
|
|
282
|
+
writable: true,
|
|
283
|
+
value: native
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
eq(other) {
|
|
287
|
+
return (other.key === this.key &&
|
|
288
|
+
other.raw === this.raw &&
|
|
289
|
+
other.status.icon === this.status.icon &&
|
|
290
|
+
other.status.label === this.status.label &&
|
|
291
|
+
other.status.completed === this.status.completed &&
|
|
292
|
+
other.status.filled === this.status.filled &&
|
|
293
|
+
other.markerFrom === this.markerFrom &&
|
|
294
|
+
other.native === this.native);
|
|
295
|
+
}
|
|
296
|
+
toDOM(view) {
|
|
297
|
+
if (!this.native) {
|
|
298
|
+
const button = document.createElement('button');
|
|
299
|
+
button.type = 'button';
|
|
300
|
+
button.className =
|
|
301
|
+
`cm-moss-list-marker cm-moss-unordered-marker cm-moss-task-status${this.key.startsWith('-') ? ' cm-moss-task-status-empty' : ''}`;
|
|
302
|
+
button.setAttribute('contenteditable', 'false');
|
|
303
|
+
button.setAttribute('aria-label', this.status.label);
|
|
304
|
+
button.title = this.status.label;
|
|
305
|
+
button.dataset.status = this.key;
|
|
306
|
+
if (this.status.icon !== EMPTY_TASK_ICON) {
|
|
307
|
+
appendMossIcon(button, this.status.icon, {
|
|
308
|
+
size: 17,
|
|
309
|
+
strokeWidth: 2.5,
|
|
310
|
+
fill: this.status.filled ? 'currentColor' : 'none',
|
|
311
|
+
ariaHidden: true,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
this.bindToggle(button, view);
|
|
315
|
+
return button;
|
|
316
|
+
}
|
|
317
|
+
const input = document.createElement('input');
|
|
318
|
+
input.type = 'checkbox';
|
|
319
|
+
input.className = 'cm-moss-task-checkbox';
|
|
320
|
+
input.checked = this.status.completed;
|
|
321
|
+
input.className =
|
|
322
|
+
'cm-moss-list-marker cm-moss-unordered-marker cm-moss-task-checkbox';
|
|
323
|
+
input.setAttribute('contenteditable', 'false');
|
|
324
|
+
input.setAttribute('aria-label', this.status.label);
|
|
325
|
+
input.title = this.status.label;
|
|
326
|
+
input.dataset.status = this.key;
|
|
327
|
+
this.bindToggle(input, view);
|
|
328
|
+
return input;
|
|
329
|
+
}
|
|
330
|
+
bindToggle(element, view) {
|
|
331
|
+
element.addEventListener('mousedown', (event) => {
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
event.stopPropagation();
|
|
334
|
+
});
|
|
335
|
+
element.addEventListener('click', (event) => {
|
|
336
|
+
event.preventDefault();
|
|
337
|
+
event.stopPropagation();
|
|
338
|
+
const current = view.state.doc.sliceString(this.markerFrom, this.markerFrom + this.raw.length);
|
|
339
|
+
if (current !== this.raw)
|
|
340
|
+
return;
|
|
341
|
+
const config = view.state.facet(taskCheckboxConfigFacet);
|
|
342
|
+
const nextKey = this.status.toggleTo;
|
|
343
|
+
if (!nextKey || !resolveTaskCheckboxStatus(nextKey, config))
|
|
344
|
+
return;
|
|
345
|
+
const nextRaw = `[${nextKey}]`;
|
|
346
|
+
view.dispatch({
|
|
347
|
+
changes: {
|
|
348
|
+
from: this.markerFrom,
|
|
349
|
+
to: this.markerFrom + this.raw.length,
|
|
350
|
+
insert: nextRaw,
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
ignoreEvent(event) {
|
|
356
|
+
return event.type === 'mousedown' || event.type === 'click';
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
//# sourceMappingURL=preview-widgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-widgets.js","sourceRoot":"","sources":["../../src/core/preview-widgets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAc,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,eAAe,EACf,QAAQ,EACR,aAAa,EACb,KAAK,EACL,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,MAAM,EACN,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,UAAU,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,UAAU,GAEX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,cAAc,GAEf,MAAM,SAAS,CAAC;AAkBjB,MAAM,QAAQ,GAAG,CAAC,IAAgB,EAAoB,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AAC9E,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACF,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE;IAC/F,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC5G,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK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AC,MAAM;oBACrC,MAAM,EAAE,OAAO;iBAChB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,WAAW,CAAC,KAAY;QACtB,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Facet, type Extension } from '@codemirror/state';
|
|
2
|
+
export declare const readOnlyFacet: Facet<boolean, boolean>;
|
|
3
|
+
/**
|
|
4
|
+
* Bundle the CM6 levers that make the editor read-only, plus the
|
|
5
|
+
* `readOnlyFacet` the feature extensions read. Designed to live inside
|
|
6
|
+
* a `Compartment` so it can be reconfigured at runtime to toggle
|
|
7
|
+
* reading mode in place (no remount, scroll position preserved).
|
|
8
|
+
*
|
|
9
|
+
* Two distinct levers are combined:
|
|
10
|
+
* - `EditorView.editable.of(!ro)` — the UX lever. With `editable`
|
|
11
|
+
* false the `contentDOM` is no longer `contenteditable`, so there's
|
|
12
|
+
* no caret and clicks don't focus the editor — the reveal never
|
|
13
|
+
* triggers and the whole doc stays rendered.
|
|
14
|
+
* - `EditorState.readOnly.of(ro)` — defense-in-depth. Blocks
|
|
15
|
+
* paste / drop / IME edits and sets `state.readOnly` for any
|
|
16
|
+
* consumer command that checks it. It does NOT block our explicit
|
|
17
|
+
* checkbox `view.dispatch`, so checkbox toggling keeps working by
|
|
18
|
+
* design.
|
|
19
|
+
*
|
|
20
|
+
* In read-only the editor DOM also gets a `cm-moss-readonly` class as
|
|
21
|
+
* a styling hook (whole-link pointer cursor, inert table cells, etc.).
|
|
22
|
+
*/
|
|
23
|
+
export declare function readOnlyExtension(ro: boolean): Extension;
|
|
24
|
+
export declare const mossReadOnlyFacet: Facet<boolean, boolean>;
|
|
25
|
+
export declare const mossReadOnlyExtension: typeof readOnlyExtension;
|
|
26
|
+
//# sourceMappingURL=read-only.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-only.d.ts","sourceRoot":"","sources":["../../src/core/read-only.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAiBvE,eAAO,MAAM,aAAa,yBAExB,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,OAAO,GAAG,SAAS,CAOxD;AAED,eAAO,MAAM,iBAAiB,yBAAgB,CAAC;AAC/C,eAAO,MAAM,qBAAqB,0BAAoB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EditorState, Facet } from '@codemirror/state';
|
|
2
|
+
import { EditorView } from '@codemirror/view';
|
|
3
|
+
// Read-only ("reading") mode.
|
|
4
|
+
//
|
|
5
|
+
// The live-preview reveal already keys off `view.hasFocus` + the
|
|
6
|
+
// selection, so a view with no caret and no focus is, in effect, a
|
|
7
|
+
// fully-rendered reading view. Read-only mode makes that state
|
|
8
|
+
// permanent and re-routes clicks (links open instead of dropping a
|
|
9
|
+
// caret to edit).
|
|
10
|
+
//
|
|
11
|
+
// `readOnlyFacet` is the single source of truth the feature extensions
|
|
12
|
+
// (inline-preview, tables) read via `state.facet(readOnlyFacet)` to
|
|
13
|
+
// branch their behavior. It defaults to `false`, so composing
|
|
14
|
+
// `inlinePreview()` / `mossTables()` standalone — without ever
|
|
15
|
+
// supplying this facet — behaves exactly as before.
|
|
16
|
+
export const readOnlyFacet = Facet.define({
|
|
17
|
+
combine: (values) => (values.length ? values[values.length - 1] : false),
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Bundle the CM6 levers that make the editor read-only, plus the
|
|
21
|
+
* `readOnlyFacet` the feature extensions read. Designed to live inside
|
|
22
|
+
* a `Compartment` so it can be reconfigured at runtime to toggle
|
|
23
|
+
* reading mode in place (no remount, scroll position preserved).
|
|
24
|
+
*
|
|
25
|
+
* Two distinct levers are combined:
|
|
26
|
+
* - `EditorView.editable.of(!ro)` — the UX lever. With `editable`
|
|
27
|
+
* false the `contentDOM` is no longer `contenteditable`, so there's
|
|
28
|
+
* no caret and clicks don't focus the editor — the reveal never
|
|
29
|
+
* triggers and the whole doc stays rendered.
|
|
30
|
+
* - `EditorState.readOnly.of(ro)` — defense-in-depth. Blocks
|
|
31
|
+
* paste / drop / IME edits and sets `state.readOnly` for any
|
|
32
|
+
* consumer command that checks it. It does NOT block our explicit
|
|
33
|
+
* checkbox `view.dispatch`, so checkbox toggling keeps working by
|
|
34
|
+
* design.
|
|
35
|
+
*
|
|
36
|
+
* In read-only the editor DOM also gets a `cm-moss-readonly` class as
|
|
37
|
+
* a styling hook (whole-link pointer cursor, inert table cells, etc.).
|
|
38
|
+
*/
|
|
39
|
+
export function readOnlyExtension(ro) {
|
|
40
|
+
return [
|
|
41
|
+
EditorView.editable.of(!ro),
|
|
42
|
+
EditorState.readOnly.of(ro),
|
|
43
|
+
readOnlyFacet.of(ro),
|
|
44
|
+
ro ? EditorView.editorAttributes.of({ class: 'cm-moss-readonly' }) : [],
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
export const mossReadOnlyFacet = readOnlyFacet;
|
|
48
|
+
export const mossReadOnlyExtension = readOnlyExtension;
|
|
49
|
+
//# sourceMappingURL=read-only.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-only.js","sourceRoot":"","sources":["../../src/core/read-only.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAkB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,8BAA8B;AAC9B,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,+DAA+D;AAC/D,mEAAmE;AACnE,kBAAkB;AAClB,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,8DAA8D;AAC9D,+DAA+D;AAC/D,oDAAoD;AAEpD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAmB;IAC1D,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;CACzE,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAW;IAC3C,OAAO;QACL,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC3B,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QAC3B,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;KACxE,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EditorView, ViewPlugin, type ViewUpdate } from '@codemirror/view';
|
|
2
|
+
export declare const treeGrowthEffect: import("@codemirror/state").StateEffectType<null>;
|
|
3
|
+
type IdleHandle = {
|
|
4
|
+
kind: 'idle';
|
|
5
|
+
id: number;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'raf';
|
|
8
|
+
id: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* View plugin that monitors lezer's parse progress and dispatches a
|
|
12
|
+
* `treeGrowthEffect` whenever the tree has grown enough that
|
|
13
|
+
* downstream decoration builders should re-run. Include this in your
|
|
14
|
+
* extension set alongside the state fields that depend on tree
|
|
15
|
+
* coverage — it's a no-op for small docs where the initial parse
|
|
16
|
+
* already covers everything.
|
|
17
|
+
*/
|
|
18
|
+
export declare const treeProgressPlugin: ViewPlugin<{
|
|
19
|
+
view: EditorView;
|
|
20
|
+
_lastTreeLen: number;
|
|
21
|
+
_idleHandle: IdleHandle | null;
|
|
22
|
+
_destroyed: boolean;
|
|
23
|
+
update(update: ViewUpdate): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
_schedule(): void;
|
|
26
|
+
_tick(): void;
|
|
27
|
+
}, undefined>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=tree-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-progress.d.ts","sourceRoot":"","sources":["../../src/core/tree-progress.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAkB3E,eAAO,MAAM,gBAAgB,mDAA6B,CAAC;AAgB3D,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAiB7E;;;;;;;GAOG;AAOH,eAAO,MAAM,kBAAkB;UAErB,UAAU;kBACF,MAAM;iBACP,UAAU,GAAG,IAAI;;mBASf,UAAU;;;;aAqD5B,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { ensureSyntaxTree, syntaxTree } from '@codemirror/language';
|
|
2
|
+
import { StateEffect } from '@codemirror/state';
|
|
3
|
+
import { ViewPlugin } from '@codemirror/view';
|
|
4
|
+
// Broadcasts that lezer's incremental parser has advanced past where
|
|
5
|
+
// it was last observed. Consumers (tables, images, inline-preview)
|
|
6
|
+
// watch for this effect and rebuild their decorations so content
|
|
7
|
+
// parsed into existence during idle time actually renders.
|
|
8
|
+
//
|
|
9
|
+
// Needed because:
|
|
10
|
+
// - Our StateField builders call `ensureSyntaxTree(state, docLen,
|
|
11
|
+
// budget)` with a small budget (200ms) to avoid blocking the
|
|
12
|
+
// initial render. For documents large enough to exceed the
|
|
13
|
+
// budget, the tree covers only a prefix of the doc at mount.
|
|
14
|
+
// - StateFields only recompute on transactions. Without a transaction
|
|
15
|
+
// carrying a signal, the background parser can advance all it
|
|
16
|
+
// wants and the decorations never catch up — late tables and
|
|
17
|
+
// images stay as raw `| col |` / `` text forever.
|
|
18
|
+
// - The inline-preview ViewPlugin has the same shape: it walks a
|
|
19
|
+
// possibly-partial tree and caches the result.
|
|
20
|
+
export const treeGrowthEffect = StateEffect.define();
|
|
21
|
+
// How much must the parsed range grow before we dispatch a rebuild
|
|
22
|
+
// effect. A too-small threshold means a storm of tiny rebuilds while
|
|
23
|
+
// the parser chews through the doc; too large means the user might
|
|
24
|
+
// scroll past an unparsed region before it catches up. 8KB is roughly
|
|
25
|
+
// two viewport-heights of text and reliably contains several table/
|
|
26
|
+
// image blocks in our sample content.
|
|
27
|
+
const GROWTH_THRESHOLD = 8192;
|
|
28
|
+
// Budget per idle tick — short enough to keep the main thread
|
|
29
|
+
// responsive, long enough to make real progress. rIC/rAF fire at
|
|
30
|
+
// 16ms+, so 30ms is "push a bit past one frame" rather than "steal a
|
|
31
|
+
// whole frame."
|
|
32
|
+
const TICK_BUDGET_MS = 30;
|
|
33
|
+
function scheduleIdle(cb) {
|
|
34
|
+
if (typeof window.requestIdleCallback === 'function') {
|
|
35
|
+
return { kind: 'idle', id: window.requestIdleCallback(() => cb()) };
|
|
36
|
+
}
|
|
37
|
+
return { kind: 'raf', id: window.requestAnimationFrame(() => cb()) };
|
|
38
|
+
}
|
|
39
|
+
function cancelIdle(handle) {
|
|
40
|
+
if (handle.kind === 'idle' && typeof window.cancelIdleCallback === 'function') {
|
|
41
|
+
window.cancelIdleCallback(handle.id);
|
|
42
|
+
}
|
|
43
|
+
else if (handle.kind === 'raf') {
|
|
44
|
+
window.cancelAnimationFrame(handle.id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* View plugin that monitors lezer's parse progress and dispatches a
|
|
49
|
+
* `treeGrowthEffect` whenever the tree has grown enough that
|
|
50
|
+
* downstream decoration builders should re-run. Include this in your
|
|
51
|
+
* extension set alongside the state fields that depend on tree
|
|
52
|
+
* coverage — it's a no-op for small docs where the initial parse
|
|
53
|
+
* already covers everything.
|
|
54
|
+
*/
|
|
55
|
+
// TS caveat: ViewPlugin.fromClass takes an anonymous class, and
|
|
56
|
+
// tsc's declaration emit (for the exported plugin constant) rejects
|
|
57
|
+
// `private` / `protected` / `readonly` modifiers on its members
|
|
58
|
+
// ("property may not be private or protected on an exported
|
|
59
|
+
// anonymous class type"). Underscore prefix keeps the "don't touch"
|
|
60
|
+
// convention without tripping that check.
|
|
61
|
+
export const treeProgressPlugin = ViewPlugin.fromClass(class {
|
|
62
|
+
constructor(view) {
|
|
63
|
+
Object.defineProperty(this, "view", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "_lastTreeLen", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "_idleHandle", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: null
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "_destroyed", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: false
|
|
86
|
+
});
|
|
87
|
+
this.view = view;
|
|
88
|
+
this._lastTreeLen = syntaxTree(view.state).length;
|
|
89
|
+
this._schedule();
|
|
90
|
+
}
|
|
91
|
+
update(update) {
|
|
92
|
+
if (update.docChanged) {
|
|
93
|
+
// Doc edits invalidate everything we knew about tree length;
|
|
94
|
+
// lezer re-parses from the edit point. Reset and kick the
|
|
95
|
+
// loop so new content gets picked up.
|
|
96
|
+
this._lastTreeLen = syntaxTree(update.state).length;
|
|
97
|
+
this._schedule();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
destroy() {
|
|
101
|
+
this._destroyed = true;
|
|
102
|
+
if (this._idleHandle !== null) {
|
|
103
|
+
cancelIdle(this._idleHandle);
|
|
104
|
+
this._idleHandle = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_schedule() {
|
|
108
|
+
if (this._idleHandle !== null)
|
|
109
|
+
return;
|
|
110
|
+
this._idleHandle = scheduleIdle(() => {
|
|
111
|
+
this._idleHandle = null;
|
|
112
|
+
if (!this._destroyed)
|
|
113
|
+
this._tick();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
_tick() {
|
|
117
|
+
const state = this.view.state;
|
|
118
|
+
const docLen = state.doc.length;
|
|
119
|
+
if (this._lastTreeLen >= docLen)
|
|
120
|
+
return;
|
|
121
|
+
// Push the parser further. `ensureSyntaxTree` returns null if
|
|
122
|
+
// the budget expires before reaching the target — in that case
|
|
123
|
+
// we still want to read whatever progress was made.
|
|
124
|
+
const ensured = ensureSyntaxTree(state, docLen, TICK_BUDGET_MS);
|
|
125
|
+
const newLen = (ensured ?? syntaxTree(state)).length;
|
|
126
|
+
if (newLen >= this._lastTreeLen + GROWTH_THRESHOLD || newLen >= docLen) {
|
|
127
|
+
const previous = this._lastTreeLen;
|
|
128
|
+
this._lastTreeLen = newLen;
|
|
129
|
+
try {
|
|
130
|
+
this.view.dispatch({ effects: treeGrowthEffect.of(null) });
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// View destroyed mid-flight; revert the baseline so a
|
|
134
|
+
// subsequent tick (if any) still has something to report.
|
|
135
|
+
this._lastTreeLen = previous;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (newLen < docLen)
|
|
140
|
+
this._schedule();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=tree-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-progress.js","sourceRoot":"","sources":["../../src/core/tree-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAc,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAE3E,qEAAqE;AACrE,mEAAmE;AACnE,iEAAiE;AACjE,2DAA2D;AAC3D,EAAE;AACF,kBAAkB;AAClB,mEAAmE;AACnE,gEAAgE;AAChE,8DAA8D;AAC9D,gEAAgE;AAChE,uEAAuE;AACvE,iEAAiE;AACjE,gEAAgE;AAChE,4DAA4D;AAC5D,kEAAkE;AAClE,kDAAkD;AAClD,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,EAAQ,CAAC;AAE3D,mEAAmE;AACnE,qEAAqE;AACrE,mEAAmE;AACnE,sEAAsE;AACtE,oEAAoE;AACpE,sCAAsC;AACtC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,8DAA8D;AAC9D,iEAAiE;AACjE,qEAAqE;AACrE,gBAAgB;AAChB,MAAM,cAAc,GAAG,EAAE,CAAC;AAI1B,SAAS,YAAY,CAAC,EAAc;IAClC,IAAI,OAAO,MAAM,CAAC,mBAAmB,KAAK,UAAU,EAAE,CAAC;QACrD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;IACtE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,qBAAqB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