@onereach/ui-components 6.4.2 → 6.5.0-beta.3403.0

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 (77) hide show
  1. package/dist/bundled/v2/components/OrCode/OrCode.js +2 -2
  2. package/dist/bundled/v2/components/OrCode/index.js +5 -3
  3. package/dist/bundled/v2/components/OrCode/lang.js +5 -3
  4. package/dist/bundled/v2/components/OrCode/libs.js +5 -3
  5. package/dist/bundled/v2/components/OrCode/theme.js +1 -1
  6. package/dist/bundled/v2/components/OrCodeV3/OrCode.js +52 -30
  7. package/dist/bundled/v2/components/OrCodeV3/OrCode.vue.d.ts +4 -3
  8. package/dist/bundled/v2/components/OrCodeV3/index.d.ts +1 -0
  9. package/dist/bundled/v2/components/OrCodeV3/index.js +5 -0
  10. package/dist/bundled/v2/components/OrCodeV3/libs.d.ts +6 -0
  11. package/dist/bundled/v2/components/OrCodeV3/libs.js +5 -0
  12. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +2 -2
  13. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +1 -1
  14. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/theme.js +1 -1
  15. package/dist/bundled/v2/components/index.js +6 -3
  16. package/dist/bundled/v2/index-317a90b7.js +361 -0
  17. package/dist/bundled/v2/index-5465a04e.js +825 -0
  18. package/dist/bundled/v2/index-5df3b1d8.js +94 -0
  19. package/dist/bundled/v2/index-5fa53f66.js +759 -0
  20. package/dist/bundled/{v3/index-ceea3e83.js → v2/index-7caa3ac5.js} +3 -3
  21. package/dist/bundled/v2/{index-eca317e0.js → index-bd08fe6f.js} +27 -465
  22. package/dist/bundled/v2/index-d017a622.js +1892 -0
  23. package/dist/bundled/v2/{index-62bb1bac.js → index-d4e4f8a8.js} +10 -831
  24. package/dist/bundled/v2/{index-3cae2d25.js → index-d5c13979.js} +1 -1
  25. package/dist/bundled/v2/index-f949d42c.js +1598 -0
  26. package/dist/bundled/v2/index.js +6 -3
  27. package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-e88b2b44.js → OrCode.vue_vue_type_script_lang-9be03ab0.js} +2 -2
  28. package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-c9522cd5.js → OrCode.vue_vue_type_script_lang-f6022ce5.js} +52 -30
  29. package/dist/bundled/v3/components/OrCode/OrCode.js +2 -2
  30. package/dist/bundled/v3/components/OrCode/index.js +6 -4
  31. package/dist/bundled/v3/components/OrCode/lang.js +5 -3
  32. package/dist/bundled/v3/components/OrCode/libs.js +5 -3
  33. package/dist/bundled/v3/components/OrCode/theme.js +1 -1
  34. package/dist/bundled/v3/components/OrCodeV3/OrCode.js +2 -2
  35. package/dist/bundled/v3/components/OrCodeV3/OrCode.vue.d.ts +3 -2
  36. package/dist/bundled/v3/components/OrCodeV3/index.d.ts +1 -0
  37. package/dist/bundled/v3/components/OrCodeV3/index.js +6 -1
  38. package/dist/bundled/v3/components/OrCodeV3/libs.d.ts +6 -0
  39. package/dist/bundled/v3/components/OrCodeV3/libs.js +5 -0
  40. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.js +2 -2
  41. package/dist/bundled/v3/components/OrRichTextEditorV3/index.js +1 -1
  42. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +2 -2
  43. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +1 -1
  44. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/theme.js +1 -1
  45. package/dist/bundled/v3/components/index.js +9 -6
  46. package/dist/bundled/v3/{index-62bb1bac.js → index-16f605c7.js} +10 -831
  47. package/dist/bundled/v3/index-1f2974f3.js +1892 -0
  48. package/dist/bundled/v3/index-1fc9d52b.js +759 -0
  49. package/dist/bundled/v3/index-210fd8da.js +825 -0
  50. package/dist/bundled/{v2/index-ceea3e83.js → v3/index-71514f0d.js} +3 -3
  51. package/dist/bundled/v3/{index-eca317e0.js → index-766903ad.js} +27 -465
  52. package/dist/bundled/v3/index-a4b02e4e.js +1598 -0
  53. package/dist/bundled/v3/index-a8d259c3.js +361 -0
  54. package/dist/bundled/v3/{index-3cae2d25.js → index-e81a9bf9.js} +1 -1
  55. package/dist/bundled/v3/index-f6290750.js +94 -0
  56. package/dist/bundled/v3/index.js +9 -6
  57. package/dist/esm/v2/{OrCode-f5c25b63.js → OrCode-e2222cf7.js} +54 -34
  58. package/dist/esm/v2/components/index.js +3 -3
  59. package/dist/esm/v2/components/or-code-v3/OrCode.vue.d.ts +4 -3
  60. package/dist/esm/v2/components/or-code-v3/index.d.ts +1 -0
  61. package/dist/esm/v2/components/or-code-v3/index.js +9 -10
  62. package/dist/esm/v2/components/or-code-v3/libs.d.ts +6 -0
  63. package/dist/esm/v2/index.js +3 -3
  64. package/dist/esm/v3/{OrCode-9662d0da.js → OrCode-f6a8e9f2.js} +54 -34
  65. package/dist/esm/v3/components/index.js +3 -3
  66. package/dist/esm/v3/components/or-code-v3/OrCode.vue.d.ts +3 -2
  67. package/dist/esm/v3/components/or-code-v3/index.d.ts +1 -0
  68. package/dist/esm/v3/components/or-code-v3/index.js +9 -10
  69. package/dist/esm/v3/components/or-code-v3/libs.d.ts +6 -0
  70. package/dist/esm/v3/index.js +3 -3
  71. package/package.json +2 -3
  72. package/src/components/or-code-v3/OrCode.vue +70 -50
  73. package/src/components/or-code-v3/index.ts +1 -0
  74. package/src/components/or-code-v3/libs.ts +10 -0
  75. package/dist/bundled/v2/index-60e4eacf.js +0 -4048
  76. package/dist/bundled/v3/index-60e4eacf.js +0 -4048
  77. /package/dist/bundled/v3/{OrRichTextEditor.vue_vue_type_script_lang-5a2318e5.js → OrRichTextEditor.vue_vue_type_script_lang-63edf53c.js} +0 -0
@@ -0,0 +1,825 @@
1
+ import { E as EditorView, p as Decoration, Y as hoverTooltip, S as StateField, w as showPanel, V as ViewPlugin, Z as logException, F as Facet, c as combineConfig, _ as gutter, $ as RangeSet, a0 as showTooltip, m as StateEffect, t as getPanel, a1 as WidgetType, a2 as GutterMarker } from './index-e81a9bf9.js';
2
+
3
+ function crelt() {
4
+ var elt = arguments[0];
5
+ if (typeof elt == "string") elt = document.createElement(elt);
6
+ var i = 1,
7
+ next = arguments[1];
8
+ if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
9
+ for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
10
+ var value = next[name];
11
+ if (typeof value == "string") elt.setAttribute(name, value);else if (value != null) elt[name] = value;
12
+ }
13
+ i++;
14
+ }
15
+ for (; i < arguments.length; i++) add(elt, arguments[i]);
16
+ return elt;
17
+ }
18
+ function add(elt, child) {
19
+ if (typeof child == "string") {
20
+ elt.appendChild(document.createTextNode(child));
21
+ } else if (child == null) ; else if (child.nodeType != null) {
22
+ elt.appendChild(child);
23
+ } else if (Array.isArray(child)) {
24
+ for (var i = 0; i < child.length; i++) add(elt, child[i]);
25
+ } else {
26
+ throw new RangeError("Unsupported child node: " + child);
27
+ }
28
+ }
29
+
30
+ class SelectedDiagnostic {
31
+ constructor(from, to, diagnostic) {
32
+ this.from = from;
33
+ this.to = to;
34
+ this.diagnostic = diagnostic;
35
+ }
36
+ }
37
+ class LintState {
38
+ constructor(diagnostics, panel, selected) {
39
+ this.diagnostics = diagnostics;
40
+ this.panel = panel;
41
+ this.selected = selected;
42
+ }
43
+ static init(diagnostics, panel, state) {
44
+ // Filter the list of diagnostics for which to create markers
45
+ let markedDiagnostics = diagnostics;
46
+ let diagnosticFilter = state.facet(lintConfig).markerFilter;
47
+ if (diagnosticFilter) markedDiagnostics = diagnosticFilter(markedDiagnostics);
48
+ let ranges = Decoration.set(markedDiagnostics.map(d => {
49
+ // For zero-length ranges or ranges covering only a line break, create a widget
50
+ return d.from == d.to || d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from ? Decoration.widget({
51
+ widget: new DiagnosticWidget(d),
52
+ diagnostic: d
53
+ }).range(d.from) : Decoration.mark({
54
+ attributes: {
55
+ class: "cm-lintRange cm-lintRange-" + d.severity
56
+ },
57
+ diagnostic: d
58
+ }).range(d.from, d.to);
59
+ }), true);
60
+ return new LintState(ranges, panel, findDiagnostic(ranges));
61
+ }
62
+ }
63
+ function findDiagnostic(diagnostics) {
64
+ let diagnostic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
65
+ let after = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
66
+ let found = null;
67
+ diagnostics.between(after, 1e9, (from, to, _ref) => {
68
+ let {
69
+ spec
70
+ } = _ref;
71
+ if (diagnostic && spec.diagnostic != diagnostic) return;
72
+ found = new SelectedDiagnostic(from, to, spec.diagnostic);
73
+ return false;
74
+ });
75
+ return found;
76
+ }
77
+ function hideTooltip(tr, tooltip) {
78
+ return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
79
+ }
80
+ function maybeEnableLint(state, effects) {
81
+ return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of(lintExtensions));
82
+ }
83
+ /**
84
+ Returns a transaction spec which updates the current set of
85
+ diagnostics, and enables the lint extension if if wasn't already
86
+ active.
87
+ */
88
+ function setDiagnostics(state, diagnostics) {
89
+ return {
90
+ effects: maybeEnableLint(state, [setDiagnosticsEffect.of(diagnostics)])
91
+ };
92
+ }
93
+ /**
94
+ The state effect that updates the set of active diagnostics. Can
95
+ be useful when writing an extension that needs to track these.
96
+ */
97
+ const setDiagnosticsEffect = /*@__PURE__*/StateEffect.define();
98
+ const togglePanel = /*@__PURE__*/StateEffect.define();
99
+ const movePanelSelection = /*@__PURE__*/StateEffect.define();
100
+ const lintState = /*@__PURE__*/StateField.define({
101
+ create() {
102
+ return new LintState(Decoration.none, null, null);
103
+ },
104
+ update(value, tr) {
105
+ if (tr.docChanged) {
106
+ let mapped = value.diagnostics.map(tr.changes),
107
+ selected = null;
108
+ if (value.selected) {
109
+ let selPos = tr.changes.mapPos(value.selected.from, 1);
110
+ selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
111
+ }
112
+ value = new LintState(mapped, value.panel, selected);
113
+ }
114
+ for (let effect of tr.effects) {
115
+ if (effect.is(setDiagnosticsEffect)) {
116
+ value = LintState.init(effect.value, value.panel, tr.state);
117
+ } else if (effect.is(togglePanel)) {
118
+ value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
119
+ } else if (effect.is(movePanelSelection)) {
120
+ value = new LintState(value.diagnostics, value.panel, effect.value);
121
+ }
122
+ }
123
+ return value;
124
+ },
125
+ provide: f => [showPanel.from(f, val => val.panel), EditorView.decorations.from(f, s => s.diagnostics)]
126
+ });
127
+ const activeMark = /*@__PURE__*/Decoration.mark({
128
+ class: "cm-lintRange cm-lintRange-active"
129
+ });
130
+ function lintTooltip(view, pos, side) {
131
+ let {
132
+ diagnostics
133
+ } = view.state.field(lintState);
134
+ let found = [],
135
+ stackStart = 2e8,
136
+ stackEnd = 0;
137
+ diagnostics.between(pos - (side < 0 ? 1 : 0), pos + (side > 0 ? 1 : 0), (from, to, _ref2) => {
138
+ let {
139
+ spec
140
+ } = _ref2;
141
+ if (pos >= from && pos <= to && (from == to || (pos > from || side > 0) && (pos < to || side < 0))) {
142
+ found.push(spec.diagnostic);
143
+ stackStart = Math.min(from, stackStart);
144
+ stackEnd = Math.max(to, stackEnd);
145
+ }
146
+ });
147
+ let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
148
+ if (diagnosticFilter) found = diagnosticFilter(found);
149
+ if (!found.length) return null;
150
+ return {
151
+ pos: stackStart,
152
+ end: stackEnd,
153
+ above: view.state.doc.lineAt(stackStart).to < stackEnd,
154
+ create() {
155
+ return {
156
+ dom: diagnosticsTooltip(view, found)
157
+ };
158
+ }
159
+ };
160
+ }
161
+ function diagnosticsTooltip(view, diagnostics) {
162
+ return crelt("ul", {
163
+ class: "cm-tooltip-lint"
164
+ }, diagnostics.map(d => renderDiagnostic(view, d, false)));
165
+ }
166
+ /**
167
+ Command to open and focus the lint panel.
168
+ */
169
+ const openLintPanel = view => {
170
+ let field = view.state.field(lintState, false);
171
+ if (!field || !field.panel) view.dispatch({
172
+ effects: maybeEnableLint(view.state, [togglePanel.of(true)])
173
+ });
174
+ let panel = getPanel(view, LintPanel.open);
175
+ if (panel) panel.dom.querySelector(".cm-panel-lint ul").focus();
176
+ return true;
177
+ };
178
+ /**
179
+ Command to close the lint panel, when open.
180
+ */
181
+ const closeLintPanel = view => {
182
+ let field = view.state.field(lintState, false);
183
+ if (!field || !field.panel) return false;
184
+ view.dispatch({
185
+ effects: togglePanel.of(false)
186
+ });
187
+ return true;
188
+ };
189
+ /**
190
+ Move the selection to the next diagnostic.
191
+ */
192
+ const nextDiagnostic = view => {
193
+ let field = view.state.field(lintState, false);
194
+ if (!field) return false;
195
+ let sel = view.state.selection.main,
196
+ next = field.diagnostics.iter(sel.to + 1);
197
+ if (!next.value) {
198
+ next = field.diagnostics.iter(0);
199
+ if (!next.value || next.from == sel.from && next.to == sel.to) return false;
200
+ }
201
+ view.dispatch({
202
+ selection: {
203
+ anchor: next.from,
204
+ head: next.to
205
+ },
206
+ scrollIntoView: true
207
+ });
208
+ return true;
209
+ };
210
+ /**
211
+ A set of default key bindings for the lint functionality.
212
+
213
+ - Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
214
+ - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
215
+ */
216
+ const lintKeymap = [{
217
+ key: "Mod-Shift-m",
218
+ run: openLintPanel,
219
+ preventDefault: true
220
+ }, {
221
+ key: "F8",
222
+ run: nextDiagnostic
223
+ }];
224
+ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
225
+ constructor(view) {
226
+ this.view = view;
227
+ this.timeout = -1;
228
+ this.set = true;
229
+ let {
230
+ delay
231
+ } = view.state.facet(lintConfig);
232
+ this.lintTime = Date.now() + delay;
233
+ this.run = this.run.bind(this);
234
+ this.timeout = setTimeout(this.run, delay);
235
+ }
236
+ run() {
237
+ let now = Date.now();
238
+ if (now < this.lintTime - 10) {
239
+ setTimeout(this.run, this.lintTime - now);
240
+ } else {
241
+ this.set = false;
242
+ let {
243
+ state
244
+ } = this.view,
245
+ {
246
+ sources
247
+ } = state.facet(lintConfig);
248
+ Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
249
+ let all = annotations.reduce((a, b) => a.concat(b));
250
+ if (this.view.state.doc == state.doc) this.view.dispatch(setDiagnostics(this.view.state, all));
251
+ }, error => {
252
+ logException(this.view.state, error);
253
+ });
254
+ }
255
+ }
256
+ update(update) {
257
+ let config = update.state.facet(lintConfig);
258
+ if (update.docChanged || config != update.startState.facet(lintConfig) || config.needsRefresh && config.needsRefresh(update)) {
259
+ this.lintTime = Date.now() + config.delay;
260
+ if (!this.set) {
261
+ this.set = true;
262
+ this.timeout = setTimeout(this.run, config.delay);
263
+ }
264
+ }
265
+ }
266
+ force() {
267
+ if (this.set) {
268
+ this.lintTime = Date.now();
269
+ this.run();
270
+ }
271
+ }
272
+ destroy() {
273
+ clearTimeout(this.timeout);
274
+ }
275
+ });
276
+ const lintConfig = /*@__PURE__*/Facet.define({
277
+ combine(input) {
278
+ return Object.assign({
279
+ sources: input.map(i => i.source)
280
+ }, combineConfig(input.map(i => i.config), {
281
+ delay: 750,
282
+ markerFilter: null,
283
+ tooltipFilter: null,
284
+ needsRefresh: null
285
+ }, {
286
+ needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
287
+ }));
288
+ }
289
+ });
290
+ /**
291
+ Given a diagnostic source, this function returns an extension that
292
+ enables linting with that source. It will be called whenever the
293
+ editor is idle (after its content changed).
294
+ */
295
+ function linter(source) {
296
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
297
+ return [lintConfig.of({
298
+ source,
299
+ config
300
+ }), lintPlugin, lintExtensions];
301
+ }
302
+ function assignKeys(actions) {
303
+ let assigned = [];
304
+ if (actions) actions: for (let {
305
+ name
306
+ } of actions) {
307
+ for (let i = 0; i < name.length; i++) {
308
+ let ch = name[i];
309
+ if (/[a-zA-Z]/.test(ch) && !assigned.some(c => c.toLowerCase() == ch.toLowerCase())) {
310
+ assigned.push(ch);
311
+ continue actions;
312
+ }
313
+ }
314
+ assigned.push("");
315
+ }
316
+ return assigned;
317
+ }
318
+ function renderDiagnostic(view, diagnostic, inPanel) {
319
+ var _a;
320
+ let keys = inPanel ? assignKeys(diagnostic.actions) : [];
321
+ return crelt("li", {
322
+ class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity
323
+ }, crelt("span", {
324
+ class: "cm-diagnosticText"
325
+ }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
326
+ let fired = false,
327
+ click = e => {
328
+ e.preventDefault();
329
+ if (fired) return;
330
+ fired = true;
331
+ let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
332
+ if (found) action.apply(view, found.from, found.to);
333
+ };
334
+ let {
335
+ name
336
+ } = action,
337
+ keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
338
+ let nameElt = keyIndex < 0 ? name : [name.slice(0, keyIndex), crelt("u", name.slice(keyIndex, keyIndex + 1)), name.slice(keyIndex + 1)];
339
+ return crelt("button", {
340
+ type: "button",
341
+ class: "cm-diagnosticAction",
342
+ onclick: click,
343
+ onmousedown: click,
344
+ "aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
345
+ }, nameElt);
346
+ }), diagnostic.source && crelt("div", {
347
+ class: "cm-diagnosticSource"
348
+ }, diagnostic.source));
349
+ }
350
+ class DiagnosticWidget extends WidgetType {
351
+ constructor(diagnostic) {
352
+ super();
353
+ this.diagnostic = diagnostic;
354
+ }
355
+ eq(other) {
356
+ return other.diagnostic == this.diagnostic;
357
+ }
358
+ toDOM() {
359
+ return crelt("span", {
360
+ class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity
361
+ });
362
+ }
363
+ }
364
+ class PanelItem {
365
+ constructor(view, diagnostic) {
366
+ this.diagnostic = diagnostic;
367
+ this.id = "item_" + Math.floor(Math.random() * 0xffffffff).toString(16);
368
+ this.dom = renderDiagnostic(view, diagnostic, true);
369
+ this.dom.id = this.id;
370
+ this.dom.setAttribute("role", "option");
371
+ }
372
+ }
373
+ class LintPanel {
374
+ constructor(view) {
375
+ this.view = view;
376
+ this.items = [];
377
+ let onkeydown = event => {
378
+ if (event.keyCode == 27) {
379
+ // Escape
380
+ closeLintPanel(this.view);
381
+ this.view.focus();
382
+ } else if (event.keyCode == 38 || event.keyCode == 33) {
383
+ // ArrowUp, PageUp
384
+ this.moveSelection((this.selectedIndex - 1 + this.items.length) % this.items.length);
385
+ } else if (event.keyCode == 40 || event.keyCode == 34) {
386
+ // ArrowDown, PageDown
387
+ this.moveSelection((this.selectedIndex + 1) % this.items.length);
388
+ } else if (event.keyCode == 36) {
389
+ // Home
390
+ this.moveSelection(0);
391
+ } else if (event.keyCode == 35) {
392
+ // End
393
+ this.moveSelection(this.items.length - 1);
394
+ } else if (event.keyCode == 13) {
395
+ // Enter
396
+ this.view.focus();
397
+ } else if (event.keyCode >= 65 && event.keyCode <= 90 && this.selectedIndex >= 0) {
398
+ // A-Z
399
+ let {
400
+ diagnostic
401
+ } = this.items[this.selectedIndex],
402
+ keys = assignKeys(diagnostic.actions);
403
+ for (let i = 0; i < keys.length; i++) if (keys[i].toUpperCase().charCodeAt(0) == event.keyCode) {
404
+ let found = findDiagnostic(this.view.state.field(lintState).diagnostics, diagnostic);
405
+ if (found) diagnostic.actions[i].apply(view, found.from, found.to);
406
+ }
407
+ } else {
408
+ return;
409
+ }
410
+ event.preventDefault();
411
+ };
412
+ let onclick = event => {
413
+ for (let i = 0; i < this.items.length; i++) {
414
+ if (this.items[i].dom.contains(event.target)) this.moveSelection(i);
415
+ }
416
+ };
417
+ this.list = crelt("ul", {
418
+ tabIndex: 0,
419
+ role: "listbox",
420
+ "aria-label": this.view.state.phrase("Diagnostics"),
421
+ onkeydown,
422
+ onclick
423
+ });
424
+ this.dom = crelt("div", {
425
+ class: "cm-panel-lint"
426
+ }, this.list, crelt("button", {
427
+ type: "button",
428
+ name: "close",
429
+ "aria-label": this.view.state.phrase("close"),
430
+ onclick: () => closeLintPanel(this.view)
431
+ }, "×"));
432
+ this.update();
433
+ }
434
+ get selectedIndex() {
435
+ let selected = this.view.state.field(lintState).selected;
436
+ if (!selected) return -1;
437
+ for (let i = 0; i < this.items.length; i++) if (this.items[i].diagnostic == selected.diagnostic) return i;
438
+ return -1;
439
+ }
440
+ update() {
441
+ let {
442
+ diagnostics,
443
+ selected
444
+ } = this.view.state.field(lintState);
445
+ let i = 0,
446
+ needsSync = false,
447
+ newSelectedItem = null;
448
+ diagnostics.between(0, this.view.state.doc.length, (_start, _end, _ref3) => {
449
+ let {
450
+ spec
451
+ } = _ref3;
452
+ let found = -1,
453
+ item;
454
+ for (let j = i; j < this.items.length; j++) if (this.items[j].diagnostic == spec.diagnostic) {
455
+ found = j;
456
+ break;
457
+ }
458
+ if (found < 0) {
459
+ item = new PanelItem(this.view, spec.diagnostic);
460
+ this.items.splice(i, 0, item);
461
+ needsSync = true;
462
+ } else {
463
+ item = this.items[found];
464
+ if (found > i) {
465
+ this.items.splice(i, found - i);
466
+ needsSync = true;
467
+ }
468
+ }
469
+ if (selected && item.diagnostic == selected.diagnostic) {
470
+ if (!item.dom.hasAttribute("aria-selected")) {
471
+ item.dom.setAttribute("aria-selected", "true");
472
+ newSelectedItem = item;
473
+ }
474
+ } else if (item.dom.hasAttribute("aria-selected")) {
475
+ item.dom.removeAttribute("aria-selected");
476
+ }
477
+ i++;
478
+ });
479
+ while (i < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0)) {
480
+ needsSync = true;
481
+ this.items.pop();
482
+ }
483
+ if (this.items.length == 0) {
484
+ this.items.push(new PanelItem(this.view, {
485
+ from: -1,
486
+ to: -1,
487
+ severity: "info",
488
+ message: this.view.state.phrase("No diagnostics")
489
+ }));
490
+ needsSync = true;
491
+ }
492
+ if (newSelectedItem) {
493
+ this.list.setAttribute("aria-activedescendant", newSelectedItem.id);
494
+ this.view.requestMeasure({
495
+ key: this,
496
+ read: () => ({
497
+ sel: newSelectedItem.dom.getBoundingClientRect(),
498
+ panel: this.list.getBoundingClientRect()
499
+ }),
500
+ write: _ref4 => {
501
+ let {
502
+ sel,
503
+ panel
504
+ } = _ref4;
505
+ if (sel.top < panel.top) this.list.scrollTop -= panel.top - sel.top;else if (sel.bottom > panel.bottom) this.list.scrollTop += sel.bottom - panel.bottom;
506
+ }
507
+ });
508
+ } else if (this.selectedIndex < 0) {
509
+ this.list.removeAttribute("aria-activedescendant");
510
+ }
511
+ if (needsSync) this.sync();
512
+ }
513
+ sync() {
514
+ let domPos = this.list.firstChild;
515
+ function rm() {
516
+ let prev = domPos;
517
+ domPos = prev.nextSibling;
518
+ prev.remove();
519
+ }
520
+ for (let item of this.items) {
521
+ if (item.dom.parentNode == this.list) {
522
+ while (domPos != item.dom) rm();
523
+ domPos = item.dom.nextSibling;
524
+ } else {
525
+ this.list.insertBefore(item.dom, domPos);
526
+ }
527
+ }
528
+ while (domPos) rm();
529
+ }
530
+ moveSelection(selectedIndex) {
531
+ if (this.selectedIndex < 0) return;
532
+ let field = this.view.state.field(lintState);
533
+ let selection = findDiagnostic(field.diagnostics, this.items[selectedIndex].diagnostic);
534
+ if (!selection) return;
535
+ this.view.dispatch({
536
+ selection: {
537
+ anchor: selection.from,
538
+ head: selection.to
539
+ },
540
+ scrollIntoView: true,
541
+ effects: movePanelSelection.of(selection)
542
+ });
543
+ }
544
+ static open(view) {
545
+ return new LintPanel(view);
546
+ }
547
+ }
548
+ function svg(content) {
549
+ let attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : `viewBox="0 0 40 40"`;
550
+ return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${attrs}>${encodeURIComponent(content)}</svg>')`;
551
+ }
552
+ function underline(color) {
553
+ return svg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${color}" fill="none" stroke-width=".7"/>`, `width="6" height="3"`);
554
+ }
555
+ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
556
+ ".cm-diagnostic": {
557
+ padding: "3px 6px 3px 8px",
558
+ marginLeft: "-1px",
559
+ display: "block",
560
+ whiteSpace: "pre-wrap"
561
+ },
562
+ ".cm-diagnostic-error": {
563
+ borderLeft: "5px solid #d11"
564
+ },
565
+ ".cm-diagnostic-warning": {
566
+ borderLeft: "5px solid orange"
567
+ },
568
+ ".cm-diagnostic-info": {
569
+ borderLeft: "5px solid #999"
570
+ },
571
+ ".cm-diagnosticAction": {
572
+ font: "inherit",
573
+ border: "none",
574
+ padding: "2px 4px",
575
+ backgroundColor: "#444",
576
+ color: "white",
577
+ borderRadius: "3px",
578
+ marginLeft: "8px",
579
+ cursor: "pointer"
580
+ },
581
+ ".cm-diagnosticSource": {
582
+ fontSize: "70%",
583
+ opacity: .7
584
+ },
585
+ ".cm-lintRange": {
586
+ backgroundPosition: "left bottom",
587
+ backgroundRepeat: "repeat-x",
588
+ paddingBottom: "0.7px"
589
+ },
590
+ ".cm-lintRange-error": {
591
+ backgroundImage: /*@__PURE__*/underline("#d11")
592
+ },
593
+ ".cm-lintRange-warning": {
594
+ backgroundImage: /*@__PURE__*/underline("orange")
595
+ },
596
+ ".cm-lintRange-info": {
597
+ backgroundImage: /*@__PURE__*/underline("#999")
598
+ },
599
+ ".cm-lintRange-active": {
600
+ backgroundColor: "#ffdd9980"
601
+ },
602
+ ".cm-tooltip-lint": {
603
+ padding: 0,
604
+ margin: 0
605
+ },
606
+ ".cm-lintPoint": {
607
+ position: "relative",
608
+ "&:after": {
609
+ content: '""',
610
+ position: "absolute",
611
+ bottom: 0,
612
+ left: "-2px",
613
+ borderLeft: "3px solid transparent",
614
+ borderRight: "3px solid transparent",
615
+ borderBottom: "4px solid #d11"
616
+ }
617
+ },
618
+ ".cm-lintPoint-warning": {
619
+ "&:after": {
620
+ borderBottomColor: "orange"
621
+ }
622
+ },
623
+ ".cm-lintPoint-info": {
624
+ "&:after": {
625
+ borderBottomColor: "#999"
626
+ }
627
+ },
628
+ ".cm-panel.cm-panel-lint": {
629
+ position: "relative",
630
+ "& ul": {
631
+ maxHeight: "100px",
632
+ overflowY: "auto",
633
+ "& [aria-selected]": {
634
+ backgroundColor: "#ddd",
635
+ "& u": {
636
+ textDecoration: "underline"
637
+ }
638
+ },
639
+ "&:focus [aria-selected]": {
640
+ background_fallback: "#bdf",
641
+ backgroundColor: "Highlight",
642
+ color_fallback: "white",
643
+ color: "HighlightText"
644
+ },
645
+ "& u": {
646
+ textDecoration: "none"
647
+ },
648
+ padding: 0,
649
+ margin: 0
650
+ },
651
+ "& [name=close]": {
652
+ position: "absolute",
653
+ top: "0",
654
+ right: "2px",
655
+ background: "inherit",
656
+ border: "none",
657
+ font: "inherit",
658
+ padding: 0,
659
+ margin: 0
660
+ }
661
+ }
662
+ });
663
+ class LintGutterMarker extends GutterMarker {
664
+ constructor(diagnostics) {
665
+ super();
666
+ this.diagnostics = diagnostics;
667
+ this.severity = diagnostics.reduce((max, d) => {
668
+ let s = d.severity;
669
+ return s == "error" || s == "warning" && max == "info" ? s : max;
670
+ }, "info");
671
+ }
672
+ toDOM(view) {
673
+ let elt = document.createElement("div");
674
+ elt.className = "cm-lint-marker cm-lint-marker-" + this.severity;
675
+ let diagnostics = this.diagnostics;
676
+ let diagnosticsFilter = view.state.facet(lintGutterConfig).tooltipFilter;
677
+ if (diagnosticsFilter) diagnostics = diagnosticsFilter(diagnostics);
678
+ if (diagnostics.length) elt.onmouseover = () => gutterMarkerMouseOver(view, elt, diagnostics);
679
+ return elt;
680
+ }
681
+ }
682
+ function trackHoverOn(view, marker) {
683
+ let mousemove = event => {
684
+ let rect = marker.getBoundingClientRect();
685
+ if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ && event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */) return;
686
+ for (let target = event.target; target; target = target.parentNode) {
687
+ if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint")) return;
688
+ }
689
+ window.removeEventListener("mousemove", mousemove);
690
+ if (view.state.field(lintGutterTooltip)) view.dispatch({
691
+ effects: setLintGutterTooltip.of(null)
692
+ });
693
+ };
694
+ window.addEventListener("mousemove", mousemove);
695
+ }
696
+ function gutterMarkerMouseOver(view, marker, diagnostics) {
697
+ function hovered() {
698
+ let line = view.elementAtHeight(marker.getBoundingClientRect().top + 5 - view.documentTop);
699
+ const linePos = view.coordsAtPos(line.from);
700
+ if (linePos) {
701
+ view.dispatch({
702
+ effects: setLintGutterTooltip.of({
703
+ pos: line.from,
704
+ above: false,
705
+ create() {
706
+ return {
707
+ dom: diagnosticsTooltip(view, diagnostics),
708
+ getCoords: () => marker.getBoundingClientRect()
709
+ };
710
+ }
711
+ })
712
+ });
713
+ }
714
+ marker.onmouseout = marker.onmousemove = null;
715
+ trackHoverOn(view, marker);
716
+ }
717
+ let {
718
+ hoverTime
719
+ } = view.state.facet(lintGutterConfig);
720
+ let hoverTimeout = setTimeout(hovered, hoverTime);
721
+ marker.onmouseout = () => {
722
+ clearTimeout(hoverTimeout);
723
+ marker.onmouseout = marker.onmousemove = null;
724
+ };
725
+ marker.onmousemove = () => {
726
+ clearTimeout(hoverTimeout);
727
+ hoverTimeout = setTimeout(hovered, hoverTime);
728
+ };
729
+ }
730
+ function markersForDiagnostics(doc, diagnostics) {
731
+ let byLine = Object.create(null);
732
+ for (let diagnostic of diagnostics) {
733
+ let line = doc.lineAt(diagnostic.from);
734
+ (byLine[line.from] || (byLine[line.from] = [])).push(diagnostic);
735
+ }
736
+ let markers = [];
737
+ for (let line in byLine) {
738
+ markers.push(new LintGutterMarker(byLine[line]).range(+line));
739
+ }
740
+ return RangeSet.of(markers, true);
741
+ }
742
+ const lintGutterExtension = /*@__PURE__*/gutter({
743
+ class: "cm-gutter-lint",
744
+ markers: view => view.state.field(lintGutterMarkers)
745
+ });
746
+ const lintGutterMarkers = /*@__PURE__*/StateField.define({
747
+ create() {
748
+ return RangeSet.empty;
749
+ },
750
+ update(markers, tr) {
751
+ markers = markers.map(tr.changes);
752
+ let diagnosticFilter = tr.state.facet(lintGutterConfig).markerFilter;
753
+ for (let effect of tr.effects) {
754
+ if (effect.is(setDiagnosticsEffect)) {
755
+ let diagnostics = effect.value;
756
+ if (diagnosticFilter) diagnostics = diagnosticFilter(diagnostics || []);
757
+ markers = markersForDiagnostics(tr.state.doc, diagnostics.slice(0));
758
+ }
759
+ }
760
+ return markers;
761
+ }
762
+ });
763
+ const setLintGutterTooltip = /*@__PURE__*/StateEffect.define();
764
+ const lintGutterTooltip = /*@__PURE__*/StateField.define({
765
+ create() {
766
+ return null;
767
+ },
768
+ update(tooltip, tr) {
769
+ if (tooltip && tr.docChanged) tooltip = hideTooltip(tr, tooltip) ? null : Object.assign(Object.assign({}, tooltip), {
770
+ pos: tr.changes.mapPos(tooltip.pos)
771
+ });
772
+ return tr.effects.reduce((t, e) => e.is(setLintGutterTooltip) ? e.value : t, tooltip);
773
+ },
774
+ provide: field => showTooltip.from(field)
775
+ });
776
+ const lintGutterTheme = /*@__PURE__*/EditorView.baseTheme({
777
+ ".cm-gutter-lint": {
778
+ width: "1.4em",
779
+ "& .cm-gutterElement": {
780
+ padding: ".2em"
781
+ }
782
+ },
783
+ ".cm-lint-marker": {
784
+ width: "1em",
785
+ height: "1em"
786
+ },
787
+ ".cm-lint-marker-info": {
788
+ content: /*@__PURE__*/svg(`<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>`)
789
+ },
790
+ ".cm-lint-marker-warning": {
791
+ content: /*@__PURE__*/svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`)
792
+ },
793
+ ".cm-lint-marker-error": {
794
+ content: /*@__PURE__*/svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
795
+ }
796
+ });
797
+ const lintExtensions = [lintState, /*@__PURE__*/EditorView.decorations.compute([lintState], state => {
798
+ let {
799
+ selected,
800
+ panel
801
+ } = state.field(lintState);
802
+ return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([activeMark.range(selected.from, selected.to)]);
803
+ }), /*@__PURE__*/hoverTooltip(lintTooltip, {
804
+ hideOn: hideTooltip
805
+ }), baseTheme];
806
+ const lintGutterConfig = /*@__PURE__*/Facet.define({
807
+ combine(configs) {
808
+ return combineConfig(configs, {
809
+ hoverTime: 300 /* Hover.Time */,
810
+ markerFilter: null,
811
+ tooltipFilter: null
812
+ });
813
+ }
814
+ });
815
+ /**
816
+ Returns an extension that installs a gutter showing markers for
817
+ each line that has diagnostics, which can be hovered over to see
818
+ the diagnostics.
819
+ */
820
+ function lintGutter() {
821
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
822
+ return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
823
+ }
824
+
825
+ export { lintGutter as a, lintKeymap as b, crelt as c, linter as l };