@difizen/libro-codemirror 0.0.2-alpha.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 (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/auto-complete/closebrackets.d.ts +12 -0
  4. package/es/auto-complete/closebrackets.d.ts.map +1 -0
  5. package/es/auto-complete/closebrackets.js +408 -0
  6. package/es/auto-complete/completion.d.ts +57 -0
  7. package/es/auto-complete/completion.d.ts.map +1 -0
  8. package/es/auto-complete/completion.js +265 -0
  9. package/es/auto-complete/config.d.ts +22 -0
  10. package/es/auto-complete/config.d.ts.map +1 -0
  11. package/es/auto-complete/config.js +44 -0
  12. package/es/auto-complete/filter.d.ts +13 -0
  13. package/es/auto-complete/filter.d.ts.map +1 -0
  14. package/es/auto-complete/filter.js +191 -0
  15. package/es/auto-complete/index.d.ts +17 -0
  16. package/es/auto-complete/index.d.ts.map +1 -0
  17. package/es/auto-complete/index.js +107 -0
  18. package/es/auto-complete/snippet.d.ts +14 -0
  19. package/es/auto-complete/snippet.d.ts.map +1 -0
  20. package/es/auto-complete/snippet.js +447 -0
  21. package/es/auto-complete/state.d.ts +63 -0
  22. package/es/auto-complete/state.d.ts.map +1 -0
  23. package/es/auto-complete/state.js +452 -0
  24. package/es/auto-complete/theme.d.ts +6 -0
  25. package/es/auto-complete/theme.d.ts.map +1 -0
  26. package/es/auto-complete/theme.js +151 -0
  27. package/es/auto-complete/tooltip.d.ts +5 -0
  28. package/es/auto-complete/tooltip.d.ts.map +1 -0
  29. package/es/auto-complete/tooltip.js +365 -0
  30. package/es/auto-complete/view.d.ts +43 -0
  31. package/es/auto-complete/view.d.ts.map +1 -0
  32. package/es/auto-complete/view.js +372 -0
  33. package/es/auto-complete/word.d.ts +3 -0
  34. package/es/auto-complete/word.d.ts.map +1 -0
  35. package/es/auto-complete/word.js +119 -0
  36. package/es/completion.d.ts +6 -0
  37. package/es/completion.d.ts.map +1 -0
  38. package/es/completion.js +84 -0
  39. package/es/config.d.ts +184 -0
  40. package/es/config.d.ts.map +1 -0
  41. package/es/config.js +473 -0
  42. package/es/editor.d.ts +361 -0
  43. package/es/editor.d.ts.map +1 -0
  44. package/es/editor.js +1126 -0
  45. package/es/factory.d.ts +3 -0
  46. package/es/factory.d.ts.map +1 -0
  47. package/es/factory.js +12 -0
  48. package/es/hyperlink.d.ts +15 -0
  49. package/es/hyperlink.d.ts.map +1 -0
  50. package/es/hyperlink.js +120 -0
  51. package/es/indent.d.ts +8 -0
  52. package/es/indent.d.ts.map +1 -0
  53. package/es/indent.js +58 -0
  54. package/es/indentation-markers/config.d.ts +17 -0
  55. package/es/indentation-markers/config.d.ts.map +1 -0
  56. package/es/indentation-markers/config.js +10 -0
  57. package/es/indentation-markers/index.d.ts +3 -0
  58. package/es/indentation-markers/index.d.ts.map +1 -0
  59. package/es/indentation-markers/index.js +160 -0
  60. package/es/indentation-markers/map.d.ts +77 -0
  61. package/es/indentation-markers/map.d.ts.map +1 -0
  62. package/es/indentation-markers/map.js +265 -0
  63. package/es/indentation-markers/utils.d.ts +27 -0
  64. package/es/indentation-markers/utils.d.ts.map +1 -0
  65. package/es/indentation-markers/utils.js +91 -0
  66. package/es/index.d.ts +11 -0
  67. package/es/index.d.ts.map +1 -0
  68. package/es/index.js +10 -0
  69. package/es/libro-icon.d.ts +3 -0
  70. package/es/libro-icon.d.ts.map +1 -0
  71. package/es/libro-icon.js +2 -0
  72. package/es/mimetype.d.ts +22 -0
  73. package/es/mimetype.d.ts.map +1 -0
  74. package/es/mimetype.js +59 -0
  75. package/es/mode.d.ts +86 -0
  76. package/es/mode.d.ts.map +1 -0
  77. package/es/mode.js +284 -0
  78. package/es/monitor.d.ts +32 -0
  79. package/es/monitor.d.ts.map +1 -0
  80. package/es/monitor.js +129 -0
  81. package/es/python-lang.d.ts +3 -0
  82. package/es/python-lang.d.ts.map +1 -0
  83. package/es/python-lang.js +7 -0
  84. package/es/style/base.css +131 -0
  85. package/es/style/theme.css +12 -0
  86. package/es/style/variables.css +403 -0
  87. package/es/theme.d.ts +35 -0
  88. package/es/theme.d.ts.map +1 -0
  89. package/es/theme.js +225 -0
  90. package/es/tooltip.d.ts +10 -0
  91. package/es/tooltip.d.ts.map +1 -0
  92. package/es/tooltip.js +170 -0
  93. package/package.json +74 -0
  94. package/src/auto-complete/README.md +71 -0
  95. package/src/auto-complete/closebrackets.ts +423 -0
  96. package/src/auto-complete/completion.ts +345 -0
  97. package/src/auto-complete/config.ts +101 -0
  98. package/src/auto-complete/filter.ts +215 -0
  99. package/src/auto-complete/index.ts +112 -0
  100. package/src/auto-complete/snippet.ts +394 -0
  101. package/src/auto-complete/state.ts +472 -0
  102. package/src/auto-complete/theme.ts +126 -0
  103. package/src/auto-complete/tooltip.ts +386 -0
  104. package/src/auto-complete/view.ts +343 -0
  105. package/src/auto-complete/word.ts +118 -0
  106. package/src/completion.ts +61 -0
  107. package/src/config.ts +689 -0
  108. package/src/editor.ts +1078 -0
  109. package/src/factory.ts +10 -0
  110. package/src/hyperlink.ts +95 -0
  111. package/src/indent.ts +69 -0
  112. package/src/indentation-markers/config.ts +31 -0
  113. package/src/indentation-markers/index.ts +192 -0
  114. package/src/indentation-markers/map.ts +273 -0
  115. package/src/indentation-markers/utils.ts +84 -0
  116. package/src/index.ts +11 -0
  117. package/src/libro-icon.ts +4 -0
  118. package/src/mimetype.ts +49 -0
  119. package/src/mode.ts +269 -0
  120. package/src/monitor.ts +105 -0
  121. package/src/python-lang.ts +7 -0
  122. package/src/style/base.css +129 -0
  123. package/src/style/theme.css +12 -0
  124. package/src/style/variables.css +405 -0
  125. package/src/theme.ts +231 -0
  126. package/src/tooltip.ts +145 -0
@@ -0,0 +1,107 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
2
+
3
+ import { Prec } from '@codemirror/state';
4
+ import { keymap } from '@codemirror/view';
5
+ import { indentOrCompletion, indentOrTooltip } from "../indent.js";
6
+ import { completionConfig } from "./config.js";
7
+ import { completionState, State, setSelectedEffect } from "./state.js";
8
+ import { baseTheme } from "./theme.js";
9
+ import { completionPlugin, moveCompletionSelection, acceptCompletion, closeCompletion } from "./view.js";
10
+ export * from "./snippet.js";
11
+ export * from "./completion.js";
12
+ export * from "./view.js";
13
+ export * from "./word.js";
14
+ export * from "./closebrackets.js";
15
+
16
+ /// Returns an extension that enables autocompletion.
17
+ export function autocompletion() {
18
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ return [completionState, completionConfig.of(config), completionPlugin, completionKeymapExt, baseTheme];
20
+ }
21
+
22
+ /// Basic keybindings for autocompletion.
23
+ ///
24
+ /// - Ctrl-Space: [`startCompletion`](#autocomplete.startCompletion)
25
+ /// - Escape: [`closeCompletion`](#autocomplete.closeCompletion)
26
+ /// - ArrowDown: [`moveCompletionSelection`](#autocomplete.moveCompletionSelection)`(true)`
27
+ /// - ArrowUp: [`moveCompletionSelection`](#autocomplete.moveCompletionSelection)`(false)`
28
+ /// - PageDown: [`moveCompletionSelection`](#autocomplete.moveCompletionSelection)`(true, "page")`
29
+ /// - PageDown: [`moveCompletionSelection`](#autocomplete.moveCompletionSelection)`(true, "page")`
30
+ /// - Enter: [`acceptCompletion`](#autocomplete.acceptCompletion)
31
+ export var completionKeymap = [{
32
+ key: 'Tab',
33
+ run: indentOrCompletion,
34
+ shift: indentOrTooltip
35
+ }, {
36
+ key: 'Escape',
37
+ run: closeCompletion
38
+ }, {
39
+ key: 'ArrowDown',
40
+ run: moveCompletionSelection(true)
41
+ }, {
42
+ key: 'ArrowUp',
43
+ run: moveCompletionSelection(false)
44
+ }, {
45
+ key: 'PageDown',
46
+ run: moveCompletionSelection(true, 'page')
47
+ }, {
48
+ key: 'PageUp',
49
+ run: moveCompletionSelection(false, 'page')
50
+ }, {
51
+ key: 'Enter',
52
+ run: acceptCompletion
53
+ }];
54
+ var completionKeymapExt = Prec.highest(keymap.computeN([completionConfig], function (state) {
55
+ return state.facet(completionConfig).defaultKeymap ? [completionKeymap] : [];
56
+ }));
57
+
58
+ /// Get the current completion status. When completions are available,
59
+ /// this will return `"active"`. When completions are pending (in the
60
+ /// process of being queried), this returns `"pending"`. Otherwise, it
61
+ /// returns `null`.
62
+ export function completionStatus(state) {
63
+ var cState = state.field(completionState, false);
64
+ return cState && cState.active.some(function (a) {
65
+ return a.state === State.Pending;
66
+ }) ? 'pending' : cState && cState.active.some(function (a) {
67
+ return a.state !== State.Inactive;
68
+ }) ? 'active' : null;
69
+ }
70
+ var completionArrayCache = new WeakMap();
71
+
72
+ /// Returns the available completions as an array.
73
+ export function currentCompletions(state) {
74
+ var _state$field;
75
+ var open = (_state$field = state.field(completionState, false)) === null || _state$field === void 0 ? void 0 : _state$field.open;
76
+ if (!open) {
77
+ return [];
78
+ }
79
+ var completions = completionArrayCache.get(open.options);
80
+ if (!completions) {
81
+ completionArrayCache.set(open.options, completions = open.options.map(function (o) {
82
+ return o.completion;
83
+ }));
84
+ }
85
+ return completions;
86
+ }
87
+
88
+ /// Return the currently selected completion, if any.
89
+ export function selectedCompletion(state) {
90
+ var _state$field2;
91
+ var open = (_state$field2 = state.field(completionState, false)) === null || _state$field2 === void 0 ? void 0 : _state$field2.open;
92
+ return open && open.selected >= 0 ? open.options[open.selected].completion : null;
93
+ }
94
+
95
+ /// Returns the currently selected position in the active completion
96
+ /// list, or null if no completions are active.
97
+ export function selectedCompletionIndex(state) {
98
+ var _state$field3;
99
+ var open = (_state$field3 = state.field(completionState, false)) === null || _state$field3 === void 0 ? void 0 : _state$field3.open;
100
+ return open && open.selected >= 0 ? open.selected : null;
101
+ }
102
+
103
+ /// Create an effect that can be attached to a transaction to change
104
+ /// the currently selected completion.
105
+ export function setSelectedCompletion(index) {
106
+ return setSelectedEffect.of(index);
107
+ }
@@ -0,0 +1,14 @@
1
+ import type { EditorState, Transaction, StateCommand } from '@codemirror/state';
2
+ import { Facet } from '@codemirror/state';
3
+ import type { KeyBinding } from '@codemirror/view';
4
+ import type { Completion } from './completion.js';
5
+ export declare function snippet(template: string): (editor: {
6
+ state: EditorState;
7
+ dispatch: (tr: Transaction) => void;
8
+ }, _completion: Completion, from: number, to: number) => void;
9
+ export declare const clearSnippet: StateCommand;
10
+ export declare const nextSnippetField: StateCommand;
11
+ export declare const prevSnippetField: StateCommand;
12
+ export declare const snippetKeymap: Facet<readonly KeyBinding[], readonly KeyBinding[]>;
13
+ export declare function snippetCompletion(template: string, completion: Completion): Completion;
14
+ //# sourceMappingURL=snippet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snippet.d.ts","sourceRoot":"","sources":["../../src/auto-complete/snippet.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,WAAW,EACX,WAAW,EAEX,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAML,KAAK,EAEN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAmPlD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM;WAGnB,WAAW;mBAAiB,WAAW,KAAK,IAAI;gBACpD,UAAU,QACjB,MAAM,MACR,MAAM,UA0Bb;AAqBD,eAAO,MAAM,YAAY,EAAE,YAO1B,CAAC;AAGF,eAAO,MAAM,gBAAgB,cAAe,CAAC;AAG7C,eAAO,MAAM,gBAAgB,cAAgB,CAAC;AAY9C,eAAO,MAAM,aAAa,qDAMzB,CAAC;AASF,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,UAAU,GACrB,UAAU,CAEZ"}
@@ -0,0 +1,447 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
19
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
+ /* eslint-disable @typescript-eslint/no-use-before-define */
21
+ /* eslint-disable @typescript-eslint/no-shadow */
22
+ /* eslint-disable prefer-const */
23
+ /* eslint-disable no-param-reassign */
24
+ /* eslint-disable @typescript-eslint/no-parameter-properties */
25
+ /* eslint-disable @typescript-eslint/parameter-properties */
26
+ import { indentUnit } from '@codemirror/language';
27
+ import { StateField, StateEffect, EditorSelection, Text, Prec, Facet, MapMode } from '@codemirror/state';
28
+ import { Decoration, WidgetType, EditorView, keymap } from '@codemirror/view';
29
+ import { baseTheme } from "./theme.js";
30
+ var FieldPos = /*#__PURE__*/_createClass(function FieldPos(field, line, from, to) {
31
+ _classCallCheck(this, FieldPos);
32
+ this.field = field;
33
+ this.line = line;
34
+ this.from = from;
35
+ this.to = to;
36
+ });
37
+ var FieldRange = /*#__PURE__*/function () {
38
+ function FieldRange(field, from, to) {
39
+ _classCallCheck(this, FieldRange);
40
+ this.field = field;
41
+ this.from = from;
42
+ this.to = to;
43
+ }
44
+ _createClass(FieldRange, [{
45
+ key: "map",
46
+ value: function map(changes) {
47
+ var from = changes.mapPos(this.from, -1, MapMode.TrackDel);
48
+ var to = changes.mapPos(this.to, 1, MapMode.TrackDel);
49
+ return from === null || to === null ? null : new FieldRange(this.field, from, to);
50
+ }
51
+ }]);
52
+ return FieldRange;
53
+ }();
54
+ var Snippet = /*#__PURE__*/function () {
55
+ function Snippet(lines, fieldPositions) {
56
+ _classCallCheck(this, Snippet);
57
+ this.lines = lines;
58
+ this.fieldPositions = fieldPositions;
59
+ }
60
+ _createClass(Snippet, [{
61
+ key: "instantiate",
62
+ value: function instantiate(state, pos) {
63
+ var text = [],
64
+ lineStart = [pos];
65
+ var lineObj = state.doc.lineAt(pos),
66
+ baseIndent = /^\s*/.exec(lineObj.text)[0];
67
+ var _iterator = _createForOfIteratorHelper(this.lines),
68
+ _step;
69
+ try {
70
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
71
+ var _line = _step.value;
72
+ if (text.length) {
73
+ var indent = baseIndent,
74
+ tabs = /^\t*/.exec(_line)[0].length;
75
+ for (var i = 0; i < tabs; i++) {
76
+ indent += state.facet(indentUnit);
77
+ }
78
+ lineStart.push(pos + indent.length - tabs);
79
+ _line = indent + _line.slice(tabs);
80
+ }
81
+ text.push(_line);
82
+ pos += _line.length + 1;
83
+ }
84
+ } catch (err) {
85
+ _iterator.e(err);
86
+ } finally {
87
+ _iterator.f();
88
+ }
89
+ var ranges = this.fieldPositions.map(function (pos) {
90
+ return new FieldRange(pos.field, lineStart[pos.line] + pos.from, lineStart[pos.line] + pos.to);
91
+ });
92
+ return {
93
+ text: text,
94
+ ranges: ranges
95
+ };
96
+ }
97
+ }], [{
98
+ key: "parse",
99
+ value: function parse(template) {
100
+ var fields = [];
101
+ var lines = [],
102
+ positions = [],
103
+ m;
104
+ var _iterator2 = _createForOfIteratorHelper(template.split(/\r\n?|\n/)),
105
+ _step2;
106
+ try {
107
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
108
+ var _line2 = _step2.value;
109
+ while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(_line2)) {
110
+ var seq = m[1] ? +m[1] : null,
111
+ name = m[2] || m[3] || '',
112
+ found = -1;
113
+ for (var i = 0; i < fields.length; i++) {
114
+ if (seq !== null ? fields[i].seq === seq : name ? fields[i].name === name : false) {
115
+ found = i;
116
+ }
117
+ }
118
+ if (found < 0) {
119
+ var _i = 0;
120
+ while (_i < fields.length && (seq === null || fields[_i].seq !== null && fields[_i].seq < seq)) {
121
+ _i++;
122
+ }
123
+ fields.splice(_i, 0, {
124
+ seq: seq,
125
+ name: name
126
+ });
127
+ found = _i;
128
+ var _iterator3 = _createForOfIteratorHelper(positions),
129
+ _step3;
130
+ try {
131
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
132
+ var pos = _step3.value;
133
+ if (pos.field >= found) {
134
+ pos.field++;
135
+ }
136
+ }
137
+ } catch (err) {
138
+ _iterator3.e(err);
139
+ } finally {
140
+ _iterator3.f();
141
+ }
142
+ }
143
+ positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
144
+ _line2 = _line2.slice(0, m.index) + name + _line2.slice(m.index + m[0].length);
145
+ }
146
+ for (var esc; esc = /([$#])\\{/.exec(_line2);) {
147
+ _line2 = _line2.slice(0, esc.index) + esc[1] + '{' + _line2.slice(esc.index + esc[0].length);
148
+ var _iterator4 = _createForOfIteratorHelper(positions),
149
+ _step4;
150
+ try {
151
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
152
+ var _pos = _step4.value;
153
+ if (_pos.line === lines.length && _pos.from > esc.index) {
154
+ _pos.from--;
155
+ _pos.to--;
156
+ }
157
+ }
158
+ } catch (err) {
159
+ _iterator4.e(err);
160
+ } finally {
161
+ _iterator4.f();
162
+ }
163
+ }
164
+ lines.push(_line2);
165
+ }
166
+ } catch (err) {
167
+ _iterator2.e(err);
168
+ } finally {
169
+ _iterator2.f();
170
+ }
171
+ return new Snippet(lines, positions);
172
+ }
173
+ }]);
174
+ return Snippet;
175
+ }();
176
+ var fieldMarker = Decoration.widget({
177
+ widget: new ( /*#__PURE__*/function (_WidgetType) {
178
+ _inherits(_class, _WidgetType);
179
+ var _super = _createSuper(_class);
180
+ function _class() {
181
+ _classCallCheck(this, _class);
182
+ return _super.apply(this, arguments);
183
+ }
184
+ _createClass(_class, [{
185
+ key: "toDOM",
186
+ value: function toDOM() {
187
+ var span = document.createElement('span');
188
+ span.className = 'cm-snippetFieldPosition';
189
+ return span;
190
+ }
191
+ }, {
192
+ key: "ignoreEvent",
193
+ value: function ignoreEvent() {
194
+ return false;
195
+ }
196
+ }]);
197
+ return _class;
198
+ }(WidgetType))()
199
+ });
200
+ var fieldRange = Decoration.mark({
201
+ class: 'cm-snippetField'
202
+ });
203
+ var ActiveSnippet = /*#__PURE__*/function () {
204
+ function ActiveSnippet(ranges, active) {
205
+ _classCallCheck(this, ActiveSnippet);
206
+ this.ranges = ranges;
207
+ this.active = active;
208
+ this.deco = Decoration.set(ranges.map(function (r) {
209
+ return (r.from === r.to ? fieldMarker : fieldRange).range(r.from, r.to);
210
+ }));
211
+ }
212
+ _createClass(ActiveSnippet, [{
213
+ key: "map",
214
+ value: function map(changes) {
215
+ var ranges = [];
216
+ var _iterator5 = _createForOfIteratorHelper(this.ranges),
217
+ _step5;
218
+ try {
219
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
220
+ var r = _step5.value;
221
+ var mapped = r.map(changes);
222
+ if (!mapped) {
223
+ return null;
224
+ }
225
+ ranges.push(mapped);
226
+ }
227
+ } catch (err) {
228
+ _iterator5.e(err);
229
+ } finally {
230
+ _iterator5.f();
231
+ }
232
+ return new ActiveSnippet(ranges, this.active);
233
+ }
234
+ }, {
235
+ key: "selectionInsideField",
236
+ value: function selectionInsideField(sel) {
237
+ var _this = this;
238
+ return sel.ranges.every(function (range) {
239
+ return _this.ranges.some(function (r) {
240
+ return r.field === _this.active && r.from <= range.from && r.to >= range.to;
241
+ });
242
+ });
243
+ }
244
+ }]);
245
+ return ActiveSnippet;
246
+ }();
247
+ var setActive = StateEffect.define({
248
+ map: function map(value, changes) {
249
+ return value && value.map(changes);
250
+ }
251
+ });
252
+ var moveToField = StateEffect.define();
253
+ var snippetState = StateField.define({
254
+ create: function create() {
255
+ return null;
256
+ },
257
+ update: function update(value, tr) {
258
+ var _iterator6 = _createForOfIteratorHelper(tr.effects),
259
+ _step6;
260
+ try {
261
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
262
+ var effect = _step6.value;
263
+ if (effect.is(setActive)) {
264
+ return effect.value;
265
+ }
266
+ if (effect.is(moveToField) && value) {
267
+ return new ActiveSnippet(value.ranges, effect.value);
268
+ }
269
+ }
270
+ } catch (err) {
271
+ _iterator6.e(err);
272
+ } finally {
273
+ _iterator6.f();
274
+ }
275
+ if (value && tr.docChanged) {
276
+ value = value.map(tr.changes);
277
+ }
278
+ if (value && tr.selection && !value.selectionInsideField(tr.selection)) {
279
+ value = null;
280
+ }
281
+ return value;
282
+ },
283
+ provide: function provide(f) {
284
+ return EditorView.decorations.from(f, function (val) {
285
+ return val ? val.deco : Decoration.none;
286
+ });
287
+ }
288
+ });
289
+ function fieldSelection(ranges, field) {
290
+ return EditorSelection.create(ranges.filter(function (r) {
291
+ return r.field === field;
292
+ }).map(function (r) {
293
+ return EditorSelection.range(r.from, r.to);
294
+ }));
295
+ }
296
+
297
+ /// Convert a snippet template to a function that can
298
+ /// [apply](#autocomplete.Completion.apply) it. Snippets are written
299
+ /// using syntax like this:
300
+ ///
301
+ /// "for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"
302
+ ///
303
+ /// Each `${}` placeholder (you may also use `#{}`) indicates a field
304
+ /// that the user can fill in. Its name, if any, will be the default
305
+ /// content for the field.
306
+ ///
307
+ /// When the snippet is activated by calling the returned function,
308
+ /// the code is inserted at the given position. Newlines in the
309
+ /// template are indented by the indentation of the start line, plus
310
+ /// one [indent unit](#language.indentUnit) per tab character after
311
+ /// the newline.
312
+ ///
313
+ /// On activation, (all instances of) the first field are selected.
314
+ /// The user can move between fields with Tab and Shift-Tab as long as
315
+ /// the fields are active. Moving to the last field or moving the
316
+ /// cursor out of the current field deactivates the fields.
317
+ ///
318
+ /// The order of fields defaults to textual order, but you can add
319
+ /// numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
320
+ /// a custom order.
321
+ ///
322
+ /// To include a literal `${` or `#{` in your template, put a
323
+ /// backslash after the dollar or hash and before the brace (`$\\{`).
324
+ /// This will be removed and the sequence will not be interpreted as a
325
+ /// placeholder.
326
+ export function snippet(template) {
327
+ var snippet = Snippet.parse(template);
328
+ return function (editor, _completion, from, to) {
329
+ var _snippet$instantiate = snippet.instantiate(editor.state, from),
330
+ text = _snippet$instantiate.text,
331
+ ranges = _snippet$instantiate.ranges;
332
+ var spec = {
333
+ changes: {
334
+ from: from,
335
+ to: to,
336
+ insert: Text.of(text)
337
+ },
338
+ scrollIntoView: true
339
+ };
340
+ if (ranges.length) {
341
+ spec.selection = fieldSelection(ranges, 0);
342
+ }
343
+ if (ranges.length > 1) {
344
+ var _active = new ActiveSnippet(ranges, 0);
345
+ var effects = spec.effects = [setActive.of(_active)];
346
+ if (editor.state.field(snippetState, false) === undefined) {
347
+ effects.push(StateEffect.appendConfig.of([snippetState, addSnippetKeymap, snippetPointerHandler, baseTheme]));
348
+ }
349
+ }
350
+ editor.dispatch(editor.state.update(spec));
351
+ };
352
+ }
353
+ function moveField(dir) {
354
+ return function (_ref) {
355
+ var state = _ref.state,
356
+ dispatch = _ref.dispatch;
357
+ var active = state.field(snippetState, false);
358
+ if (!active || dir < 0 && active.active === 0) {
359
+ return false;
360
+ }
361
+ var next = active.active + dir,
362
+ last = dir > 0 && !active.ranges.some(function (r) {
363
+ return r.field === next + dir;
364
+ });
365
+ dispatch(state.update({
366
+ selection: fieldSelection(active.ranges, next),
367
+ effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next))
368
+ }));
369
+ return true;
370
+ };
371
+ }
372
+
373
+ /// A command that clears the active snippet, if any.
374
+ export var clearSnippet = function clearSnippet(_ref2) {
375
+ var state = _ref2.state,
376
+ dispatch = _ref2.dispatch;
377
+ var active = state.field(snippetState, false);
378
+ if (!active) {
379
+ return false;
380
+ }
381
+ dispatch(state.update({
382
+ effects: setActive.of(null)
383
+ }));
384
+ return true;
385
+ };
386
+
387
+ /// Move to the next snippet field, if available.
388
+ export var nextSnippetField = moveField(1);
389
+
390
+ /// Move to the previous snippet field, if available.
391
+ export var prevSnippetField = moveField(-1);
392
+ var defaultSnippetKeymap = [{
393
+ key: 'Tab',
394
+ run: nextSnippetField,
395
+ shift: prevSnippetField
396
+ }, {
397
+ key: 'Escape',
398
+ run: clearSnippet
399
+ }];
400
+
401
+ /// A facet that can be used to configure the key bindings used by
402
+ /// snippets. The default binds Tab to
403
+ /// [`nextSnippetField`](#autocomplete.nextSnippetField), Shift-Tab to
404
+ /// [`prevSnippetField`](#autocomplete.prevSnippetField), and Escape
405
+ /// to [`clearSnippet`](#autocomplete.clearSnippet).
406
+ export var snippetKeymap = Facet.define({
407
+ combine: function combine(maps) {
408
+ return maps.length ? maps[0] : defaultSnippetKeymap;
409
+ }
410
+ });
411
+ var addSnippetKeymap = Prec.highest(keymap.compute([snippetKeymap], function (state) {
412
+ return state.facet(snippetKeymap);
413
+ }));
414
+
415
+ /// Create a completion from a snippet. Returns an object with the
416
+ /// properties from `completion`, plus an `apply` function that
417
+ /// applies the snippet.
418
+ export function snippetCompletion(template, completion) {
419
+ return _objectSpread(_objectSpread({}, completion), {}, {
420
+ apply: snippet(template)
421
+ });
422
+ }
423
+ var snippetPointerHandler = EditorView.domEventHandlers({
424
+ mousedown: function mousedown(event, view) {
425
+ var active = view.state.field(snippetState, false),
426
+ pos;
427
+ if (!active || (pos = view.posAtCoords({
428
+ x: event.clientX,
429
+ y: event.clientY
430
+ })) === null) {
431
+ return false;
432
+ }
433
+ var match = active.ranges.find(function (r) {
434
+ return r.from <= pos && r.to >= pos;
435
+ });
436
+ if (!match || match.field === active.active) {
437
+ return false;
438
+ }
439
+ view.dispatch({
440
+ selection: fieldSelection(active.ranges, match.field),
441
+ effects: setActive.of(active.ranges.some(function (r) {
442
+ return r.field > match.field;
443
+ }) ? new ActiveSnippet(active.ranges, match.field) : null)
444
+ });
445
+ return true;
446
+ }
447
+ });
@@ -0,0 +1,63 @@
1
+ import type { Transaction, EditorState, ChangeDesc } from '@codemirror/state';
2
+ import { StateField } from '@codemirror/state';
3
+ import type { Tooltip } from '@codemirror/view';
4
+ import type { CompletionSource, CompletionResult } from './completion.js';
5
+ import { Option } from './completion.js';
6
+ import type { CompletionConfig } from './config.js';
7
+ declare class CompletionDialog {
8
+ readonly options: readonly Option[];
9
+ readonly attrs: Record<string, string>;
10
+ readonly tooltip: Tooltip;
11
+ readonly timestamp: number;
12
+ readonly selected: number;
13
+ constructor(options: readonly Option[], attrs: Record<string, string>, tooltip: Tooltip, timestamp: number, selected: number);
14
+ setSelected(selected: number, id: string): CompletionDialog;
15
+ static build(active: readonly ActiveSource[], state: EditorState, id: string, prev: CompletionDialog | null, conf: Required<CompletionConfig>): CompletionDialog | null;
16
+ map(changes: ChangeDesc): CompletionDialog;
17
+ }
18
+ export declare class CompletionState {
19
+ readonly active: readonly ActiveSource[];
20
+ readonly id: string;
21
+ readonly open: CompletionDialog | null;
22
+ constructor(active: readonly ActiveSource[], id: string, open: CompletionDialog | null);
23
+ static start(): CompletionState;
24
+ update(tr: Transaction): CompletionState;
25
+ get tooltip(): Tooltip | null;
26
+ get attrs(): Record<string, string> | {
27
+ 'aria-autocomplete': string;
28
+ };
29
+ }
30
+ export declare const enum State {
31
+ Inactive = 0,
32
+ Pending = 1,
33
+ Result = 2
34
+ }
35
+ export declare function getUserEvent(tr: Transaction): 'input' | 'delete' | null;
36
+ export declare class ActiveSource {
37
+ readonly source: CompletionSource;
38
+ readonly state: State;
39
+ readonly explicitPos: number;
40
+ constructor(source: CompletionSource, state: State, explicitPos?: number);
41
+ hasResult(): this is ActiveResult;
42
+ update(tr: Transaction, conf: Required<CompletionConfig>): ActiveSource;
43
+ handleUserEvent(tr: Transaction, type: 'input' | 'delete', conf: Required<CompletionConfig>): ActiveSource;
44
+ handleChange(tr: Transaction): ActiveSource;
45
+ map(changes: ChangeDesc): ActiveSource;
46
+ }
47
+ export declare class ActiveResult extends ActiveSource {
48
+ readonly result: CompletionResult;
49
+ readonly from: number;
50
+ readonly to: number;
51
+ constructor(source: CompletionSource, explicitPos: number, result: CompletionResult, from: number, to: number);
52
+ hasResult(): this is ActiveResult;
53
+ handleUserEvent(tr: Transaction, type: 'input' | 'delete', conf: Required<CompletionConfig>): ActiveSource;
54
+ handleChange(tr: Transaction): ActiveSource;
55
+ map(mapping: ChangeDesc): ActiveResult;
56
+ }
57
+ export declare const startCompletionEffect: import("@codemirror/state").StateEffectType<boolean>;
58
+ export declare const closeCompletionEffect: import("@codemirror/state").StateEffectType<null>;
59
+ export declare const setActiveEffect: import("@codemirror/state").StateEffectType<readonly ActiveSource[]>;
60
+ export declare const setSelectedEffect: import("@codemirror/state").StateEffectType<number>;
61
+ export declare const completionState: StateField<CompletionState>;
62
+ export {};
63
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/auto-complete/state.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAe,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AACtF,OAAO,EACL,MAAM,EAKP,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,a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