@onereach/ui-components 6.2.0-beta.3281.0 → 6.2.0-beta.3286.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 (57) hide show
  1. package/dist/bundled/v2/components/OrCode/OrCode.js +2 -2
  2. package/dist/bundled/v2/components/OrCode/index.js +4 -5
  3. package/dist/bundled/v2/components/OrCode/lang.js +5 -5
  4. package/dist/bundled/v2/components/OrCode/libs.js +4 -5
  5. package/dist/bundled/v2/components/OrCode/theme.js +1 -1
  6. package/dist/bundled/v2/components/OrCodeV3/OrCode.js +24 -12
  7. package/dist/bundled/v2/components/OrCodeV3/index.js +2 -3
  8. package/dist/bundled/v2/components/OrCodeV3/libs.d.ts +1 -3
  9. package/dist/bundled/v2/components/OrCodeV3/libs.js +2 -3
  10. package/dist/bundled/v2/components/index.js +5 -6
  11. package/dist/bundled/v2/{index-86927ce2.js → index-5ce3ef85.js} +831 -10
  12. package/dist/bundled/{v3/index-b6bfd165.js → v2/index-5dd41049.js} +4 -4
  13. package/dist/bundled/{v3/index-ae9c3d66.js → v2/index-5ee42d1f.js} +2 -2
  14. package/dist/bundled/v2/{index-8bffe4d5.js → index-61aeae22.js} +1 -184
  15. package/dist/bundled/v2/{index-bd1ee981.js → index-648acd9e.js} +1 -1
  16. package/dist/bundled/{v3/index-83070a21.js → v2/index-64a3a364.js} +3 -3
  17. package/dist/bundled/v2/{index-14ee755d.js → index-c26082b9.js} +1 -1
  18. package/dist/bundled/v2/{index-118afe52.js → index-e72fe4a8.js} +2 -2
  19. package/dist/bundled/v2/{index-586d2cf4.js → index-f31843f4.js} +2 -2
  20. package/dist/bundled/v2/index.js +5 -6
  21. package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-8355d429.js → OrCode.vue_vue_type_script_lang-8c5b4f6e.js} +2 -2
  22. package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-29120928.js → OrCode.vue_vue_type_script_lang-b46a0f8a.js} +24 -12
  23. package/dist/bundled/v3/components/OrCode/OrCode.js +2 -2
  24. package/dist/bundled/v3/components/OrCode/index.js +5 -6
  25. package/dist/bundled/v3/components/OrCode/lang.js +5 -5
  26. package/dist/bundled/v3/components/OrCode/libs.js +4 -5
  27. package/dist/bundled/v3/components/OrCode/theme.js +1 -1
  28. package/dist/bundled/v3/components/OrCodeV3/OrCode.js +2 -2
  29. package/dist/bundled/v3/components/OrCodeV3/index.js +3 -4
  30. package/dist/bundled/v3/components/OrCodeV3/libs.d.ts +1 -3
  31. package/dist/bundled/v3/components/OrCodeV3/libs.js +2 -3
  32. package/dist/bundled/v3/components/index.js +7 -8
  33. package/dist/bundled/v3/{index-1ec4fb10.js → index-19d70079.js} +2 -2
  34. package/dist/bundled/{v2/index-181d90ab.js → v3/index-22f7d3aa.js} +3 -3
  35. package/dist/bundled/v3/{index-93c7d0e8.js → index-792c62f6.js} +2 -2
  36. package/dist/bundled/{v2/index-49b0c759.js → v3/index-84ea2fc8.js} +4 -4
  37. package/dist/bundled/v3/{index-e488383c.js → index-929b54f2.js} +1 -184
  38. package/dist/bundled/{v2/index-bbdfebea.js → v3/index-b71d76f4.js} +2 -2
  39. package/dist/bundled/v3/{index-68fb579e.js → index-bb6d92dd.js} +1 -1
  40. package/dist/bundled/v3/{index-7006d0a5.js → index-df2529d7.js} +1 -1
  41. package/dist/bundled/v3/{index-b6a28985.js → index-f92296d7.js} +831 -10
  42. package/dist/bundled/v3/index.js +7 -8
  43. package/dist/esm/v2/{OrCode-920482b7.js → OrCode-adb9790d.js} +16 -4
  44. package/dist/esm/v2/components/index.js +3 -3
  45. package/dist/esm/v2/components/or-code-v3/index.js +3 -4
  46. package/dist/esm/v2/components/or-code-v3/libs.d.ts +1 -3
  47. package/dist/esm/v2/index.js +3 -3
  48. package/dist/esm/v3/{OrCode-a9234c28.js → OrCode-5457417e.js} +16 -4
  49. package/dist/esm/v3/components/index.js +3 -3
  50. package/dist/esm/v3/components/or-code-v3/index.js +3 -4
  51. package/dist/esm/v3/components/or-code-v3/libs.d.ts +1 -3
  52. package/dist/esm/v3/index.js +3 -3
  53. package/package.json +1 -1
  54. package/src/components/or-code-v3/OrCode.vue +14 -4
  55. package/src/components/or-code-v3/libs.ts +1 -6
  56. package/dist/bundled/v2/index-c6b2aeae.js +0 -825
  57. package/dist/bundled/v3/index-e556efde.js +0 -825
@@ -1,6 +1,5 @@
1
- import { w as EditorView, F as Facet, o as combineConfig, k as StateField, E as EditorSelection, l as Transaction, b as ChangeSet, C as ChangeDesc, ai as IndentContext, aj as getIndentation, ak as indentString, T as Text, al as indentUnit, p as countColumn, am as getIndentUnit, A as Annotation, i as StateEffect, an as matchBrackets, ao as syntaxTree, ap as NodeProp, v as Direction, q as findClusterBreak, V as ViewPlugin, D as Decoration, m as codePointAt, s as fromCodePoint, n as codePointSize, N as getPanel, c as CharCategory, P as Prec, af as showPanel, g as RangeSetBuilder, e as EditorState, ad as runScopeHandlers, a7 as lineNumbers, $ as highlightActiveLineGutter, a0 as highlightSpecialChars, aq as foldGutter, J as drawSelection, K as dropCursor, ar as indentOnInput, as as syntaxHighlighting, at as defaultHighlightStyle, au as bracketMatching, ab as rectangularSelection, I as crosshairCursor, Z as highlightActiveLine, a4 as keymap, av as foldKeymap } from './index-8bffe4d5.js';
2
- import { c as crelt, b as lintKeymap } from './index-c6b2aeae.js';
3
- import { c as closeBrackets, a as autocompletion, b as closeBracketsKeymap, d as completionKeymap } from './index-14ee755d.js';
1
+ import { E as EditorView, F as Facet, c as combineConfig, S as StateField, b as EditorSelection, T as Transaction, d as ChangeSet, e as ChangeDesc, I as IndentContext, g as getIndentation, i as indentString, f as Text, h as indentUnit, j as countColumn, l as getIndentUnit, A as Annotation, m as StateEffect, n as matchBrackets, s as syntaxTree, N as NodeProp, D as Direction, o as findClusterBreak, V as ViewPlugin, p as Decoration, q as codePointAt, r as codePointSize, t as getPanel, u as CharCategory, P as Prec, v as fromCodePoint, w as showPanel, R as RangeSetBuilder, a as EditorState, x as runScopeHandlers, y as hoverTooltip, z as logException, B as gutter, G as RangeSet, H as showTooltip, W as WidgetType, J as GutterMarker, K as lineNumbers, L as highlightActiveLineGutter, M as highlightSpecialChars, O as foldGutter, Q as drawSelection, U as dropCursor, X as indentOnInput, Y as syntaxHighlighting, Z as defaultHighlightStyle, _ as bracketMatching, $ as rectangularSelection, a0 as crosshairCursor, a1 as highlightActiveLine, k as keymap, a2 as foldKeymap } from './index-61aeae22.js';
2
+ import { c as closeBrackets, a as autocompletion, b as closeBracketsKeymap, d as completionKeymap } from './index-c26082b9.js';
4
3
 
5
4
  /**
6
5
  Comment or uncomment the current selection. Will use line comments
@@ -1820,6 +1819,33 @@ const indentWithTab = {
1820
1819
  shift: indentLess
1821
1820
  };
1822
1821
 
1822
+ function crelt() {
1823
+ var elt = arguments[0];
1824
+ if (typeof elt == "string") elt = document.createElement(elt);
1825
+ var i = 1,
1826
+ next = arguments[1];
1827
+ if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
1828
+ for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
1829
+ var value = next[name];
1830
+ if (typeof value == "string") elt.setAttribute(name, value);else if (value != null) elt[name] = value;
1831
+ }
1832
+ i++;
1833
+ }
1834
+ for (; i < arguments.length; i++) add(elt, arguments[i]);
1835
+ return elt;
1836
+ }
1837
+ function add(elt, child) {
1838
+ if (typeof child == "string") {
1839
+ elt.appendChild(document.createTextNode(child));
1840
+ } else if (child == null) ; else if (child.nodeType != null) {
1841
+ elt.appendChild(child);
1842
+ } else if (Array.isArray(child)) {
1843
+ for (var i = 0; i < child.length; i++) add(elt, child[i]);
1844
+ } else {
1845
+ throw new RangeError("Unsupported child node: " + child);
1846
+ }
1847
+ }
1848
+
1823
1849
  const basicNormalize = typeof String.prototype.normalize == "function" ? x => x.normalize("NFKD") : x => x;
1824
1850
  /**
1825
1851
  A search cursor provides an iterator over text matches in a
@@ -2583,14 +2609,14 @@ by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSea
2583
2609
  once).
2584
2610
  */
2585
2611
  const setSearchQuery = /*@__PURE__*/StateEffect.define();
2586
- const togglePanel = /*@__PURE__*/StateEffect.define();
2612
+ const togglePanel$1 = /*@__PURE__*/StateEffect.define();
2587
2613
  const searchState = /*@__PURE__*/StateField.define({
2588
2614
  create(state) {
2589
2615
  return new SearchState(defaultQuery(state).create(), null);
2590
2616
  },
2591
2617
  update(value, tr) {
2592
2618
  for (let effect of tr.effects) {
2593
- if (effect.is(setSearchQuery)) value = new SearchState(effect.value.create(), value.panel);else if (effect.is(togglePanel)) value = new SearchState(value.query, effect.value ? createSearchPanel : null);
2619
+ if (effect.is(setSearchQuery)) value = new SearchState(effect.value.create(), value.panel);else if (effect.is(togglePanel$1)) value = new SearchState(value.query, effect.value ? createSearchPanel : null);
2594
2620
  }
2595
2621
  return value;
2596
2622
  },
@@ -2858,7 +2884,7 @@ const openSearchPanel = view => {
2858
2884
  }
2859
2885
  } else {
2860
2886
  view.dispatch({
2861
- effects: [togglePanel.of(true), state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions)]
2887
+ effects: [togglePanel$1.of(true), state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions)]
2862
2888
  });
2863
2889
  }
2864
2890
  return true;
@@ -2872,7 +2898,7 @@ const closeSearchPanel = view => {
2872
2898
  let panel = getPanel(view, createSearchPanel);
2873
2899
  if (panel && panel.dom.contains(view.root.activeElement)) view.focus();
2874
2900
  view.dispatch({
2875
- effects: togglePanel.of(false)
2901
+ effects: togglePanel$1.of(false)
2876
2902
  });
2877
2903
  return true;
2878
2904
  };
@@ -3059,7 +3085,7 @@ function announceMatch(view, _ref10) {
3059
3085
  }
3060
3086
  return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`);
3061
3087
  }
3062
- const baseTheme = /*@__PURE__*/EditorView.baseTheme({
3088
+ const baseTheme$2 = /*@__PURE__*/EditorView.baseTheme({
3063
3089
  ".cm-panel.cm-search": {
3064
3090
  padding: "2px 6px 4px",
3065
3091
  position: "relative",
@@ -3097,7 +3123,802 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
3097
3123
  backgroundColor: "#ff00ff8a"
3098
3124
  }
3099
3125
  });
3100
- const searchExtensions = [searchState, /*@__PURE__*/Prec.lowest(searchHighlighter), baseTheme];
3126
+ const searchExtensions = [searchState, /*@__PURE__*/Prec.lowest(searchHighlighter), baseTheme$2];
3127
+
3128
+ class SelectedDiagnostic {
3129
+ constructor(from, to, diagnostic) {
3130
+ this.from = from;
3131
+ this.to = to;
3132
+ this.diagnostic = diagnostic;
3133
+ }
3134
+ }
3135
+ class LintState {
3136
+ constructor(diagnostics, panel, selected) {
3137
+ this.diagnostics = diagnostics;
3138
+ this.panel = panel;
3139
+ this.selected = selected;
3140
+ }
3141
+ static init(diagnostics, panel, state) {
3142
+ // Filter the list of diagnostics for which to create markers
3143
+ let markedDiagnostics = diagnostics;
3144
+ let diagnosticFilter = state.facet(lintConfig).markerFilter;
3145
+ if (diagnosticFilter) markedDiagnostics = diagnosticFilter(markedDiagnostics);
3146
+ let ranges = Decoration.set(markedDiagnostics.map(d => {
3147
+ // For zero-length ranges or ranges covering only a line break, create a widget
3148
+ return d.from == d.to || d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from ? Decoration.widget({
3149
+ widget: new DiagnosticWidget(d),
3150
+ diagnostic: d
3151
+ }).range(d.from) : Decoration.mark({
3152
+ attributes: {
3153
+ class: "cm-lintRange cm-lintRange-" + d.severity
3154
+ },
3155
+ diagnostic: d
3156
+ }).range(d.from, d.to);
3157
+ }), true);
3158
+ return new LintState(ranges, panel, findDiagnostic(ranges));
3159
+ }
3160
+ }
3161
+ function findDiagnostic(diagnostics) {
3162
+ let diagnostic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
3163
+ let after = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
3164
+ let found = null;
3165
+ diagnostics.between(after, 1e9, (from, to, _ref) => {
3166
+ let {
3167
+ spec
3168
+ } = _ref;
3169
+ if (diagnostic && spec.diagnostic != diagnostic) return;
3170
+ found = new SelectedDiagnostic(from, to, spec.diagnostic);
3171
+ return false;
3172
+ });
3173
+ return found;
3174
+ }
3175
+ function hideTooltip(tr, tooltip) {
3176
+ return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
3177
+ }
3178
+ function maybeEnableLint(state, effects) {
3179
+ return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of(lintExtensions));
3180
+ }
3181
+ /**
3182
+ Returns a transaction spec which updates the current set of
3183
+ diagnostics, and enables the lint extension if if wasn't already
3184
+ active.
3185
+ */
3186
+ function setDiagnostics(state, diagnostics) {
3187
+ return {
3188
+ effects: maybeEnableLint(state, [setDiagnosticsEffect.of(diagnostics)])
3189
+ };
3190
+ }
3191
+ /**
3192
+ The state effect that updates the set of active diagnostics. Can
3193
+ be useful when writing an extension that needs to track these.
3194
+ */
3195
+ const setDiagnosticsEffect = /*@__PURE__*/StateEffect.define();
3196
+ const togglePanel = /*@__PURE__*/StateEffect.define();
3197
+ const movePanelSelection = /*@__PURE__*/StateEffect.define();
3198
+ const lintState = /*@__PURE__*/StateField.define({
3199
+ create() {
3200
+ return new LintState(Decoration.none, null, null);
3201
+ },
3202
+ update(value, tr) {
3203
+ if (tr.docChanged) {
3204
+ let mapped = value.diagnostics.map(tr.changes),
3205
+ selected = null;
3206
+ if (value.selected) {
3207
+ let selPos = tr.changes.mapPos(value.selected.from, 1);
3208
+ selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
3209
+ }
3210
+ value = new LintState(mapped, value.panel, selected);
3211
+ }
3212
+ for (let effect of tr.effects) {
3213
+ if (effect.is(setDiagnosticsEffect)) {
3214
+ value = LintState.init(effect.value, value.panel, tr.state);
3215
+ } else if (effect.is(togglePanel)) {
3216
+ value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
3217
+ } else if (effect.is(movePanelSelection)) {
3218
+ value = new LintState(value.diagnostics, value.panel, effect.value);
3219
+ }
3220
+ }
3221
+ return value;
3222
+ },
3223
+ provide: f => [showPanel.from(f, val => val.panel), EditorView.decorations.from(f, s => s.diagnostics)]
3224
+ });
3225
+ const activeMark = /*@__PURE__*/Decoration.mark({
3226
+ class: "cm-lintRange cm-lintRange-active"
3227
+ });
3228
+ function lintTooltip(view, pos, side) {
3229
+ let {
3230
+ diagnostics
3231
+ } = view.state.field(lintState);
3232
+ let found = [],
3233
+ stackStart = 2e8,
3234
+ stackEnd = 0;
3235
+ diagnostics.between(pos - (side < 0 ? 1 : 0), pos + (side > 0 ? 1 : 0), (from, to, _ref2) => {
3236
+ let {
3237
+ spec
3238
+ } = _ref2;
3239
+ if (pos >= from && pos <= to && (from == to || (pos > from || side > 0) && (pos < to || side < 0))) {
3240
+ found.push(spec.diagnostic);
3241
+ stackStart = Math.min(from, stackStart);
3242
+ stackEnd = Math.max(to, stackEnd);
3243
+ }
3244
+ });
3245
+ let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
3246
+ if (diagnosticFilter) found = diagnosticFilter(found);
3247
+ if (!found.length) return null;
3248
+ return {
3249
+ pos: stackStart,
3250
+ end: stackEnd,
3251
+ above: view.state.doc.lineAt(stackStart).to < stackEnd,
3252
+ create() {
3253
+ return {
3254
+ dom: diagnosticsTooltip(view, found)
3255
+ };
3256
+ }
3257
+ };
3258
+ }
3259
+ function diagnosticsTooltip(view, diagnostics) {
3260
+ return crelt("ul", {
3261
+ class: "cm-tooltip-lint"
3262
+ }, diagnostics.map(d => renderDiagnostic(view, d, false)));
3263
+ }
3264
+ /**
3265
+ Command to open and focus the lint panel.
3266
+ */
3267
+ const openLintPanel = view => {
3268
+ let field = view.state.field(lintState, false);
3269
+ if (!field || !field.panel) view.dispatch({
3270
+ effects: maybeEnableLint(view.state, [togglePanel.of(true)])
3271
+ });
3272
+ let panel = getPanel(view, LintPanel.open);
3273
+ if (panel) panel.dom.querySelector(".cm-panel-lint ul").focus();
3274
+ return true;
3275
+ };
3276
+ /**
3277
+ Command to close the lint panel, when open.
3278
+ */
3279
+ const closeLintPanel = view => {
3280
+ let field = view.state.field(lintState, false);
3281
+ if (!field || !field.panel) return false;
3282
+ view.dispatch({
3283
+ effects: togglePanel.of(false)
3284
+ });
3285
+ return true;
3286
+ };
3287
+ /**
3288
+ Move the selection to the next diagnostic.
3289
+ */
3290
+ const nextDiagnostic = view => {
3291
+ let field = view.state.field(lintState, false);
3292
+ if (!field) return false;
3293
+ let sel = view.state.selection.main,
3294
+ next = field.diagnostics.iter(sel.to + 1);
3295
+ if (!next.value) {
3296
+ next = field.diagnostics.iter(0);
3297
+ if (!next.value || next.from == sel.from && next.to == sel.to) return false;
3298
+ }
3299
+ view.dispatch({
3300
+ selection: {
3301
+ anchor: next.from,
3302
+ head: next.to
3303
+ },
3304
+ scrollIntoView: true
3305
+ });
3306
+ return true;
3307
+ };
3308
+ /**
3309
+ A set of default key bindings for the lint functionality.
3310
+
3311
+ - Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
3312
+ - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
3313
+ */
3314
+ const lintKeymap = [{
3315
+ key: "Mod-Shift-m",
3316
+ run: openLintPanel,
3317
+ preventDefault: true
3318
+ }, {
3319
+ key: "F8",
3320
+ run: nextDiagnostic
3321
+ }];
3322
+ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
3323
+ constructor(view) {
3324
+ this.view = view;
3325
+ this.timeout = -1;
3326
+ this.set = true;
3327
+ let {
3328
+ delay
3329
+ } = view.state.facet(lintConfig);
3330
+ this.lintTime = Date.now() + delay;
3331
+ this.run = this.run.bind(this);
3332
+ this.timeout = setTimeout(this.run, delay);
3333
+ }
3334
+ run() {
3335
+ let now = Date.now();
3336
+ if (now < this.lintTime - 10) {
3337
+ setTimeout(this.run, this.lintTime - now);
3338
+ } else {
3339
+ this.set = false;
3340
+ let {
3341
+ state
3342
+ } = this.view,
3343
+ {
3344
+ sources
3345
+ } = state.facet(lintConfig);
3346
+ Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
3347
+ let all = annotations.reduce((a, b) => a.concat(b));
3348
+ if (this.view.state.doc == state.doc) this.view.dispatch(setDiagnostics(this.view.state, all));
3349
+ }, error => {
3350
+ logException(this.view.state, error);
3351
+ });
3352
+ }
3353
+ }
3354
+ update(update) {
3355
+ let config = update.state.facet(lintConfig);
3356
+ if (update.docChanged || config != update.startState.facet(lintConfig) || config.needsRefresh && config.needsRefresh(update)) {
3357
+ this.lintTime = Date.now() + config.delay;
3358
+ if (!this.set) {
3359
+ this.set = true;
3360
+ this.timeout = setTimeout(this.run, config.delay);
3361
+ }
3362
+ }
3363
+ }
3364
+ force() {
3365
+ if (this.set) {
3366
+ this.lintTime = Date.now();
3367
+ this.run();
3368
+ }
3369
+ }
3370
+ destroy() {
3371
+ clearTimeout(this.timeout);
3372
+ }
3373
+ });
3374
+ const lintConfig = /*@__PURE__*/Facet.define({
3375
+ combine(input) {
3376
+ return Object.assign({
3377
+ sources: input.map(i => i.source)
3378
+ }, combineConfig(input.map(i => i.config), {
3379
+ delay: 750,
3380
+ markerFilter: null,
3381
+ tooltipFilter: null,
3382
+ needsRefresh: null
3383
+ }, {
3384
+ needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
3385
+ }));
3386
+ }
3387
+ });
3388
+ /**
3389
+ Given a diagnostic source, this function returns an extension that
3390
+ enables linting with that source. It will be called whenever the
3391
+ editor is idle (after its content changed).
3392
+ */
3393
+ function linter(source) {
3394
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3395
+ return [lintConfig.of({
3396
+ source,
3397
+ config
3398
+ }), lintPlugin, lintExtensions];
3399
+ }
3400
+ function assignKeys(actions) {
3401
+ let assigned = [];
3402
+ if (actions) actions: for (let {
3403
+ name
3404
+ } of actions) {
3405
+ for (let i = 0; i < name.length; i++) {
3406
+ let ch = name[i];
3407
+ if (/[a-zA-Z]/.test(ch) && !assigned.some(c => c.toLowerCase() == ch.toLowerCase())) {
3408
+ assigned.push(ch);
3409
+ continue actions;
3410
+ }
3411
+ }
3412
+ assigned.push("");
3413
+ }
3414
+ return assigned;
3415
+ }
3416
+ function renderDiagnostic(view, diagnostic, inPanel) {
3417
+ var _a;
3418
+ let keys = inPanel ? assignKeys(diagnostic.actions) : [];
3419
+ return crelt("li", {
3420
+ class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity
3421
+ }, crelt("span", {
3422
+ class: "cm-diagnosticText"
3423
+ }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
3424
+ let fired = false,
3425
+ click = e => {
3426
+ e.preventDefault();
3427
+ if (fired) return;
3428
+ fired = true;
3429
+ let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
3430
+ if (found) action.apply(view, found.from, found.to);
3431
+ };
3432
+ let {
3433
+ name
3434
+ } = action,
3435
+ keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
3436
+ let nameElt = keyIndex < 0 ? name : [name.slice(0, keyIndex), crelt("u", name.slice(keyIndex, keyIndex + 1)), name.slice(keyIndex + 1)];
3437
+ return crelt("button", {
3438
+ type: "button",
3439
+ class: "cm-diagnosticAction",
3440
+ onclick: click,
3441
+ onmousedown: click,
3442
+ "aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
3443
+ }, nameElt);
3444
+ }), diagnostic.source && crelt("div", {
3445
+ class: "cm-diagnosticSource"
3446
+ }, diagnostic.source));
3447
+ }
3448
+ class DiagnosticWidget extends WidgetType {
3449
+ constructor(diagnostic) {
3450
+ super();
3451
+ this.diagnostic = diagnostic;
3452
+ }
3453
+ eq(other) {
3454
+ return other.diagnostic == this.diagnostic;
3455
+ }
3456
+ toDOM() {
3457
+ return crelt("span", {
3458
+ class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity
3459
+ });
3460
+ }
3461
+ }
3462
+ class PanelItem {
3463
+ constructor(view, diagnostic) {
3464
+ this.diagnostic = diagnostic;
3465
+ this.id = "item_" + Math.floor(Math.random() * 0xffffffff).toString(16);
3466
+ this.dom = renderDiagnostic(view, diagnostic, true);
3467
+ this.dom.id = this.id;
3468
+ this.dom.setAttribute("role", "option");
3469
+ }
3470
+ }
3471
+ class LintPanel {
3472
+ constructor(view) {
3473
+ this.view = view;
3474
+ this.items = [];
3475
+ let onkeydown = event => {
3476
+ if (event.keyCode == 27) {
3477
+ // Escape
3478
+ closeLintPanel(this.view);
3479
+ this.view.focus();
3480
+ } else if (event.keyCode == 38 || event.keyCode == 33) {
3481
+ // ArrowUp, PageUp
3482
+ this.moveSelection((this.selectedIndex - 1 + this.items.length) % this.items.length);
3483
+ } else if (event.keyCode == 40 || event.keyCode == 34) {
3484
+ // ArrowDown, PageDown
3485
+ this.moveSelection((this.selectedIndex + 1) % this.items.length);
3486
+ } else if (event.keyCode == 36) {
3487
+ // Home
3488
+ this.moveSelection(0);
3489
+ } else if (event.keyCode == 35) {
3490
+ // End
3491
+ this.moveSelection(this.items.length - 1);
3492
+ } else if (event.keyCode == 13) {
3493
+ // Enter
3494
+ this.view.focus();
3495
+ } else if (event.keyCode >= 65 && event.keyCode <= 90 && this.selectedIndex >= 0) {
3496
+ // A-Z
3497
+ let {
3498
+ diagnostic
3499
+ } = this.items[this.selectedIndex],
3500
+ keys = assignKeys(diagnostic.actions);
3501
+ for (let i = 0; i < keys.length; i++) if (keys[i].toUpperCase().charCodeAt(0) == event.keyCode) {
3502
+ let found = findDiagnostic(this.view.state.field(lintState).diagnostics, diagnostic);
3503
+ if (found) diagnostic.actions[i].apply(view, found.from, found.to);
3504
+ }
3505
+ } else {
3506
+ return;
3507
+ }
3508
+ event.preventDefault();
3509
+ };
3510
+ let onclick = event => {
3511
+ for (let i = 0; i < this.items.length; i++) {
3512
+ if (this.items[i].dom.contains(event.target)) this.moveSelection(i);
3513
+ }
3514
+ };
3515
+ this.list = crelt("ul", {
3516
+ tabIndex: 0,
3517
+ role: "listbox",
3518
+ "aria-label": this.view.state.phrase("Diagnostics"),
3519
+ onkeydown,
3520
+ onclick
3521
+ });
3522
+ this.dom = crelt("div", {
3523
+ class: "cm-panel-lint"
3524
+ }, this.list, crelt("button", {
3525
+ type: "button",
3526
+ name: "close",
3527
+ "aria-label": this.view.state.phrase("close"),
3528
+ onclick: () => closeLintPanel(this.view)
3529
+ }, "×"));
3530
+ this.update();
3531
+ }
3532
+ get selectedIndex() {
3533
+ let selected = this.view.state.field(lintState).selected;
3534
+ if (!selected) return -1;
3535
+ for (let i = 0; i < this.items.length; i++) if (this.items[i].diagnostic == selected.diagnostic) return i;
3536
+ return -1;
3537
+ }
3538
+ update() {
3539
+ let {
3540
+ diagnostics,
3541
+ selected
3542
+ } = this.view.state.field(lintState);
3543
+ let i = 0,
3544
+ needsSync = false,
3545
+ newSelectedItem = null;
3546
+ diagnostics.between(0, this.view.state.doc.length, (_start, _end, _ref3) => {
3547
+ let {
3548
+ spec
3549
+ } = _ref3;
3550
+ let found = -1,
3551
+ item;
3552
+ for (let j = i; j < this.items.length; j++) if (this.items[j].diagnostic == spec.diagnostic) {
3553
+ found = j;
3554
+ break;
3555
+ }
3556
+ if (found < 0) {
3557
+ item = new PanelItem(this.view, spec.diagnostic);
3558
+ this.items.splice(i, 0, item);
3559
+ needsSync = true;
3560
+ } else {
3561
+ item = this.items[found];
3562
+ if (found > i) {
3563
+ this.items.splice(i, found - i);
3564
+ needsSync = true;
3565
+ }
3566
+ }
3567
+ if (selected && item.diagnostic == selected.diagnostic) {
3568
+ if (!item.dom.hasAttribute("aria-selected")) {
3569
+ item.dom.setAttribute("aria-selected", "true");
3570
+ newSelectedItem = item;
3571
+ }
3572
+ } else if (item.dom.hasAttribute("aria-selected")) {
3573
+ item.dom.removeAttribute("aria-selected");
3574
+ }
3575
+ i++;
3576
+ });
3577
+ while (i < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0)) {
3578
+ needsSync = true;
3579
+ this.items.pop();
3580
+ }
3581
+ if (this.items.length == 0) {
3582
+ this.items.push(new PanelItem(this.view, {
3583
+ from: -1,
3584
+ to: -1,
3585
+ severity: "info",
3586
+ message: this.view.state.phrase("No diagnostics")
3587
+ }));
3588
+ needsSync = true;
3589
+ }
3590
+ if (newSelectedItem) {
3591
+ this.list.setAttribute("aria-activedescendant", newSelectedItem.id);
3592
+ this.view.requestMeasure({
3593
+ key: this,
3594
+ read: () => ({
3595
+ sel: newSelectedItem.dom.getBoundingClientRect(),
3596
+ panel: this.list.getBoundingClientRect()
3597
+ }),
3598
+ write: _ref4 => {
3599
+ let {
3600
+ sel,
3601
+ panel
3602
+ } = _ref4;
3603
+ 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;
3604
+ }
3605
+ });
3606
+ } else if (this.selectedIndex < 0) {
3607
+ this.list.removeAttribute("aria-activedescendant");
3608
+ }
3609
+ if (needsSync) this.sync();
3610
+ }
3611
+ sync() {
3612
+ let domPos = this.list.firstChild;
3613
+ function rm() {
3614
+ let prev = domPos;
3615
+ domPos = prev.nextSibling;
3616
+ prev.remove();
3617
+ }
3618
+ for (let item of this.items) {
3619
+ if (item.dom.parentNode == this.list) {
3620
+ while (domPos != item.dom) rm();
3621
+ domPos = item.dom.nextSibling;
3622
+ } else {
3623
+ this.list.insertBefore(item.dom, domPos);
3624
+ }
3625
+ }
3626
+ while (domPos) rm();
3627
+ }
3628
+ moveSelection(selectedIndex) {
3629
+ if (this.selectedIndex < 0) return;
3630
+ let field = this.view.state.field(lintState);
3631
+ let selection = findDiagnostic(field.diagnostics, this.items[selectedIndex].diagnostic);
3632
+ if (!selection) return;
3633
+ this.view.dispatch({
3634
+ selection: {
3635
+ anchor: selection.from,
3636
+ head: selection.to
3637
+ },
3638
+ scrollIntoView: true,
3639
+ effects: movePanelSelection.of(selection)
3640
+ });
3641
+ }
3642
+ static open(view) {
3643
+ return new LintPanel(view);
3644
+ }
3645
+ }
3646
+ function svg(content) {
3647
+ let attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : `viewBox="0 0 40 40"`;
3648
+ return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${attrs}>${encodeURIComponent(content)}</svg>')`;
3649
+ }
3650
+ function underline(color) {
3651
+ 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"`);
3652
+ }
3653
+ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
3654
+ ".cm-diagnostic": {
3655
+ padding: "3px 6px 3px 8px",
3656
+ marginLeft: "-1px",
3657
+ display: "block",
3658
+ whiteSpace: "pre-wrap"
3659
+ },
3660
+ ".cm-diagnostic-error": {
3661
+ borderLeft: "5px solid #d11"
3662
+ },
3663
+ ".cm-diagnostic-warning": {
3664
+ borderLeft: "5px solid orange"
3665
+ },
3666
+ ".cm-diagnostic-info": {
3667
+ borderLeft: "5px solid #999"
3668
+ },
3669
+ ".cm-diagnosticAction": {
3670
+ font: "inherit",
3671
+ border: "none",
3672
+ padding: "2px 4px",
3673
+ backgroundColor: "#444",
3674
+ color: "white",
3675
+ borderRadius: "3px",
3676
+ marginLeft: "8px",
3677
+ cursor: "pointer"
3678
+ },
3679
+ ".cm-diagnosticSource": {
3680
+ fontSize: "70%",
3681
+ opacity: .7
3682
+ },
3683
+ ".cm-lintRange": {
3684
+ backgroundPosition: "left bottom",
3685
+ backgroundRepeat: "repeat-x",
3686
+ paddingBottom: "0.7px"
3687
+ },
3688
+ ".cm-lintRange-error": {
3689
+ backgroundImage: /*@__PURE__*/underline("#d11")
3690
+ },
3691
+ ".cm-lintRange-warning": {
3692
+ backgroundImage: /*@__PURE__*/underline("orange")
3693
+ },
3694
+ ".cm-lintRange-info": {
3695
+ backgroundImage: /*@__PURE__*/underline("#999")
3696
+ },
3697
+ ".cm-lintRange-active": {
3698
+ backgroundColor: "#ffdd9980"
3699
+ },
3700
+ ".cm-tooltip-lint": {
3701
+ padding: 0,
3702
+ margin: 0
3703
+ },
3704
+ ".cm-lintPoint": {
3705
+ position: "relative",
3706
+ "&:after": {
3707
+ content: '""',
3708
+ position: "absolute",
3709
+ bottom: 0,
3710
+ left: "-2px",
3711
+ borderLeft: "3px solid transparent",
3712
+ borderRight: "3px solid transparent",
3713
+ borderBottom: "4px solid #d11"
3714
+ }
3715
+ },
3716
+ ".cm-lintPoint-warning": {
3717
+ "&:after": {
3718
+ borderBottomColor: "orange"
3719
+ }
3720
+ },
3721
+ ".cm-lintPoint-info": {
3722
+ "&:after": {
3723
+ borderBottomColor: "#999"
3724
+ }
3725
+ },
3726
+ ".cm-panel.cm-panel-lint": {
3727
+ position: "relative",
3728
+ "& ul": {
3729
+ maxHeight: "100px",
3730
+ overflowY: "auto",
3731
+ "& [aria-selected]": {
3732
+ backgroundColor: "#ddd",
3733
+ "& u": {
3734
+ textDecoration: "underline"
3735
+ }
3736
+ },
3737
+ "&:focus [aria-selected]": {
3738
+ background_fallback: "#bdf",
3739
+ backgroundColor: "Highlight",
3740
+ color_fallback: "white",
3741
+ color: "HighlightText"
3742
+ },
3743
+ "& u": {
3744
+ textDecoration: "none"
3745
+ },
3746
+ padding: 0,
3747
+ margin: 0
3748
+ },
3749
+ "& [name=close]": {
3750
+ position: "absolute",
3751
+ top: "0",
3752
+ right: "2px",
3753
+ background: "inherit",
3754
+ border: "none",
3755
+ font: "inherit",
3756
+ padding: 0,
3757
+ margin: 0
3758
+ }
3759
+ }
3760
+ });
3761
+ class LintGutterMarker extends GutterMarker {
3762
+ constructor(diagnostics) {
3763
+ super();
3764
+ this.diagnostics = diagnostics;
3765
+ this.severity = diagnostics.reduce((max, d) => {
3766
+ let s = d.severity;
3767
+ return s == "error" || s == "warning" && max == "info" ? s : max;
3768
+ }, "info");
3769
+ }
3770
+ toDOM(view) {
3771
+ let elt = document.createElement("div");
3772
+ elt.className = "cm-lint-marker cm-lint-marker-" + this.severity;
3773
+ let diagnostics = this.diagnostics;
3774
+ let diagnosticsFilter = view.state.facet(lintGutterConfig).tooltipFilter;
3775
+ if (diagnosticsFilter) diagnostics = diagnosticsFilter(diagnostics);
3776
+ if (diagnostics.length) elt.onmouseover = () => gutterMarkerMouseOver(view, elt, diagnostics);
3777
+ return elt;
3778
+ }
3779
+ }
3780
+ function trackHoverOn(view, marker) {
3781
+ let mousemove = event => {
3782
+ let rect = marker.getBoundingClientRect();
3783
+ 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;
3784
+ for (let target = event.target; target; target = target.parentNode) {
3785
+ if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint")) return;
3786
+ }
3787
+ window.removeEventListener("mousemove", mousemove);
3788
+ if (view.state.field(lintGutterTooltip)) view.dispatch({
3789
+ effects: setLintGutterTooltip.of(null)
3790
+ });
3791
+ };
3792
+ window.addEventListener("mousemove", mousemove);
3793
+ }
3794
+ function gutterMarkerMouseOver(view, marker, diagnostics) {
3795
+ function hovered() {
3796
+ let line = view.elementAtHeight(marker.getBoundingClientRect().top + 5 - view.documentTop);
3797
+ const linePos = view.coordsAtPos(line.from);
3798
+ if (linePos) {
3799
+ view.dispatch({
3800
+ effects: setLintGutterTooltip.of({
3801
+ pos: line.from,
3802
+ above: false,
3803
+ create() {
3804
+ return {
3805
+ dom: diagnosticsTooltip(view, diagnostics),
3806
+ getCoords: () => marker.getBoundingClientRect()
3807
+ };
3808
+ }
3809
+ })
3810
+ });
3811
+ }
3812
+ marker.onmouseout = marker.onmousemove = null;
3813
+ trackHoverOn(view, marker);
3814
+ }
3815
+ let {
3816
+ hoverTime
3817
+ } = view.state.facet(lintGutterConfig);
3818
+ let hoverTimeout = setTimeout(hovered, hoverTime);
3819
+ marker.onmouseout = () => {
3820
+ clearTimeout(hoverTimeout);
3821
+ marker.onmouseout = marker.onmousemove = null;
3822
+ };
3823
+ marker.onmousemove = () => {
3824
+ clearTimeout(hoverTimeout);
3825
+ hoverTimeout = setTimeout(hovered, hoverTime);
3826
+ };
3827
+ }
3828
+ function markersForDiagnostics(doc, diagnostics) {
3829
+ let byLine = Object.create(null);
3830
+ for (let diagnostic of diagnostics) {
3831
+ let line = doc.lineAt(diagnostic.from);
3832
+ (byLine[line.from] || (byLine[line.from] = [])).push(diagnostic);
3833
+ }
3834
+ let markers = [];
3835
+ for (let line in byLine) {
3836
+ markers.push(new LintGutterMarker(byLine[line]).range(+line));
3837
+ }
3838
+ return RangeSet.of(markers, true);
3839
+ }
3840
+ const lintGutterExtension = /*@__PURE__*/gutter({
3841
+ class: "cm-gutter-lint",
3842
+ markers: view => view.state.field(lintGutterMarkers)
3843
+ });
3844
+ const lintGutterMarkers = /*@__PURE__*/StateField.define({
3845
+ create() {
3846
+ return RangeSet.empty;
3847
+ },
3848
+ update(markers, tr) {
3849
+ markers = markers.map(tr.changes);
3850
+ let diagnosticFilter = tr.state.facet(lintGutterConfig).markerFilter;
3851
+ for (let effect of tr.effects) {
3852
+ if (effect.is(setDiagnosticsEffect)) {
3853
+ let diagnostics = effect.value;
3854
+ if (diagnosticFilter) diagnostics = diagnosticFilter(diagnostics || []);
3855
+ markers = markersForDiagnostics(tr.state.doc, diagnostics.slice(0));
3856
+ }
3857
+ }
3858
+ return markers;
3859
+ }
3860
+ });
3861
+ const setLintGutterTooltip = /*@__PURE__*/StateEffect.define();
3862
+ const lintGutterTooltip = /*@__PURE__*/StateField.define({
3863
+ create() {
3864
+ return null;
3865
+ },
3866
+ update(tooltip, tr) {
3867
+ if (tooltip && tr.docChanged) tooltip = hideTooltip(tr, tooltip) ? null : Object.assign(Object.assign({}, tooltip), {
3868
+ pos: tr.changes.mapPos(tooltip.pos)
3869
+ });
3870
+ return tr.effects.reduce((t, e) => e.is(setLintGutterTooltip) ? e.value : t, tooltip);
3871
+ },
3872
+ provide: field => showTooltip.from(field)
3873
+ });
3874
+ const lintGutterTheme = /*@__PURE__*/EditorView.baseTheme({
3875
+ ".cm-gutter-lint": {
3876
+ width: "1.4em",
3877
+ "& .cm-gutterElement": {
3878
+ padding: ".2em"
3879
+ }
3880
+ },
3881
+ ".cm-lint-marker": {
3882
+ width: "1em",
3883
+ height: "1em"
3884
+ },
3885
+ ".cm-lint-marker-info": {
3886
+ content: /*@__PURE__*/svg(`<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>`)
3887
+ },
3888
+ ".cm-lint-marker-warning": {
3889
+ content: /*@__PURE__*/svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`)
3890
+ },
3891
+ ".cm-lint-marker-error": {
3892
+ content: /*@__PURE__*/svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
3893
+ }
3894
+ });
3895
+ const lintExtensions = [lintState, /*@__PURE__*/EditorView.decorations.compute([lintState], state => {
3896
+ let {
3897
+ selected,
3898
+ panel
3899
+ } = state.field(lintState);
3900
+ return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([activeMark.range(selected.from, selected.to)]);
3901
+ }), /*@__PURE__*/hoverTooltip(lintTooltip, {
3902
+ hideOn: hideTooltip
3903
+ }), baseTheme];
3904
+ const lintGutterConfig = /*@__PURE__*/Facet.define({
3905
+ combine(configs) {
3906
+ return combineConfig(configs, {
3907
+ hoverTime: 300 /* Hover.Time */,
3908
+ markerFilter: null,
3909
+ tooltipFilter: null
3910
+ });
3911
+ }
3912
+ });
3913
+ /**
3914
+ Returns an extension that installs a gutter showing markers for
3915
+ each line that has diagnostics, which can be hovered over to see
3916
+ the diagnostics.
3917
+ */
3918
+ function lintGutter() {
3919
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3920
+ return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
3921
+ }
3101
3922
 
3102
3923
  // (The superfluous function calls around the list of extensions work
3103
3924
  // around current limitations in tree-shaking software.)
@@ -3142,4 +3963,4 @@ const basicSetup = /*@__PURE__*/(() => [lineNumbers(), highlightActiveLineGutter
3142
3963
  fallback: true
3143
3964
  }), bracketMatching(), closeBrackets(), autocompletion(), rectangularSelection(), crosshairCursor(), highlightActiveLine(), highlightSelectionMatches(), keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap, ...foldKeymap, ...completionKeymap, ...lintKeymap])])();
3144
3965
 
3145
- export { basicSetup as b, indentWithTab as i };
3966
+ export { lintGutter as a, basicSetup as b, indentWithTab as i, linter as l };