@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,3 @@
1
+ import type { CodeEditorFactory } from '@difizen/libro-code-editor';
2
+ export declare const codeMirrorEditorFactory: CodeEditorFactory;
3
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,4BAA4B,CAAC;AAIpF,eAAO,MAAM,uBAAuB,EAAE,iBAKrC,CAAC"}
package/es/factory.js ADDED
@@ -0,0 +1,12 @@
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 _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ 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); }
7
+ import { codeMirrorDefaultConfig, CodeMirrorEditor } from "./editor.js";
8
+ export var codeMirrorEditorFactory = function codeMirrorEditorFactory(options) {
9
+ return new CodeMirrorEditor(_objectSpread(_objectSpread({}, options), {}, {
10
+ config: _objectSpread(_objectSpread({}, codeMirrorDefaultConfig), options.config)
11
+ }));
12
+ };
@@ -0,0 +1,15 @@
1
+ import type { Extension } from '@codemirror/state';
2
+ import type { DecorationSet, ViewUpdate } from '@codemirror/view';
3
+ import { ViewPlugin } from '@codemirror/view';
4
+ export interface HyperLinkState {
5
+ from: number;
6
+ to: number;
7
+ url: string;
8
+ }
9
+ export declare function hyperLinkExtension(): ViewPlugin<{
10
+ decorations: DecorationSet;
11
+ update(update: ViewUpdate): void;
12
+ }>;
13
+ export declare const hyperLinkStyle: Extension;
14
+ export declare const hyperLink: Extension;
15
+ //# sourceMappingURL=hyperlink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hyperlink.d.ts","sourceRoot":"","sources":["../src/hyperlink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAS,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAsC,MAAM,kBAAkB,CAAC;AAIlF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAqDD,wBAAgB,kBAAkB;;mBAOb,UAAU;GAU9B;AAED,eAAO,MAAM,cAAc,WASzB,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,SAAkD,CAAC"}
@@ -0,0 +1,120 @@
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 _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; } } }; }
3
+ 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); }
4
+ 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; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
+ 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); }
10
+ 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); }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ 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); }; }
13
+ 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); }
14
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
+ 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; } }
16
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
+ import { syntaxTree } from '@codemirror/language';
18
+ import { ViewPlugin, EditorView, Decoration, WidgetType } from '@codemirror/view';
19
+ var pathStr = "<svg viewBox=\"0 0 1024 1024\" width=\"16\" height=\"16\" fill=\"currentColor\"><path d=\"M607.934444 417.856853c-6.179746-6.1777-12.766768-11.746532-19.554358-16.910135l-0.01228 0.011256c-6.986111-6.719028-16.47216-10.857279-26.930349-10.857279-21.464871 0-38.864146 17.400299-38.864146 38.864146 0 9.497305 3.411703 18.196431 9.071609 24.947182l-0.001023 0c0.001023 0.001023 0.00307 0.00307 0.005117 0.004093 2.718925 3.242857 5.953595 6.03853 9.585309 8.251941 3.664459 3.021823 7.261381 5.997598 10.624988 9.361205l3.203972 3.204995c40.279379 40.229237 28.254507 109.539812-12.024871 149.820214L371.157763 796.383956c-40.278355 40.229237-105.761766 40.229237-146.042167 0l-3.229554-3.231601c-40.281425-40.278355-40.281425-105.809861 0-145.991002l75.93546-75.909877c9.742898-7.733125 15.997346-19.668968 15.997346-33.072233 0-23.312962-18.898419-42.211381-42.211381-42.211381-8.797363 0-16.963347 2.693342-23.725354 7.297197-0.021489-0.045025-0.044002-0.088004-0.066515-0.134053l-0.809435 0.757247c-2.989077 2.148943-5.691629 4.669346-8.025791 7.510044l-78.913281 73.841775c-74.178443 74.229608-74.178443 195.632609 0 269.758863l3.203972 3.202948c74.178443 74.127278 195.529255 74.127278 269.707698 0l171.829484-171.880649c74.076112-74.17435 80.357166-191.184297 6.282077-265.311575L607.934444 417.856853z\"></path><path d=\"M855.61957 165.804257l-3.203972-3.203972c-74.17742-74.178443-195.528232-74.178443-269.706675 0L410.87944 334.479911c-74.178443 74.178443-78.263481 181.296089-4.085038 255.522628l3.152806 3.104711c3.368724 3.367701 6.865361 6.54302 10.434653 9.588379 2.583848 2.885723 5.618974 5.355985 8.992815 7.309476 0.025583 0.020466 0.052189 0.041956 0.077771 0.062422l0.011256-0.010233c5.377474 3.092431 11.608386 4.870938 18.257829 4.870938 20.263509 0 36.68962-16.428158 36.68962-36.68962 0-5.719258-1.309832-11.132548-3.645017-15.95846l0 0c-4.850471-10.891048-13.930267-17.521049-20.210297-23.802102l-3.15383-3.102664c-40.278355-40.278355-24.982998-98.79612 15.295358-139.074476l171.930791-171.830507c40.179095-40.280402 105.685018-40.280402 145.965419 0l3.206018 3.152806c40.279379 40.281425 40.279379 105.838513 0 146.06775l-75.686796 75.737962c-10.296507 7.628748-16.97358 19.865443-16.97358 33.662681 0 23.12365 18.745946 41.87062 41.87062 41.87062 8.048303 0 15.563464-2.275833 21.944801-6.211469 0.048095 0.081864 0.093121 0.157589 0.141216 0.240477l1.173732-1.083681c3.616364-2.421142 6.828522-5.393847 9.529027-8.792247l79.766718-73.603345C929.798013 361.334535 929.798013 239.981676 855.61957 165.804257z\"></path></svg>";
20
+ var HyperLink = /*#__PURE__*/function (_WidgetType) {
21
+ _inherits(HyperLink, _WidgetType);
22
+ var _super = _createSuper(HyperLink);
23
+ function HyperLink(state) {
24
+ var _this;
25
+ _classCallCheck(this, HyperLink);
26
+ _this = _super.call(this);
27
+ _this.state = state;
28
+ return _this;
29
+ }
30
+ _createClass(HyperLink, [{
31
+ key: "eq",
32
+ value: function eq(other) {
33
+ return this.state.url === other.state.url && this.state.to === other.state.to && this.state.from === other.state.from;
34
+ }
35
+ }, {
36
+ key: "toDOM",
37
+ value: function toDOM() {
38
+ var wrapper = document.createElement('a');
39
+ wrapper.href = this.state.url;
40
+ wrapper.target = '__blank';
41
+ wrapper.innerHTML = pathStr;
42
+ wrapper.className = 'cm-hyper-link-icon';
43
+ return wrapper;
44
+ }
45
+ }, {
46
+ key: "ignoreEvent",
47
+ value: function ignoreEvent() {
48
+ return false;
49
+ }
50
+ }]);
51
+ return HyperLink;
52
+ }(WidgetType);
53
+ function hyperLinkDecorations(view) {
54
+ var widgets = [];
55
+ var _iterator = _createForOfIteratorHelper(view.visibleRanges),
56
+ _step;
57
+ try {
58
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
+ var range = _step.value;
60
+ syntaxTree(view.state).iterate({
61
+ from: range.from,
62
+ to: range.to,
63
+ enter: function enter(_ref) {
64
+ var type = _ref.type,
65
+ from = _ref.from,
66
+ to = _ref.to;
67
+ var callExp = view.state.doc.sliceString(from, to);
68
+ if (type.name === 'URL') {
69
+ var widget = Decoration.widget({
70
+ widget: new HyperLink({
71
+ from: from,
72
+ to: to,
73
+ url: callExp
74
+ }),
75
+ side: 1
76
+ });
77
+ widgets.push(widget.range(to));
78
+ }
79
+ }
80
+ });
81
+ }
82
+ } catch (err) {
83
+ _iterator.e(err);
84
+ } finally {
85
+ _iterator.f();
86
+ }
87
+ return Decoration.set(widgets);
88
+ }
89
+ export function hyperLinkExtension() {
90
+ return ViewPlugin.fromClass( /*#__PURE__*/function () {
91
+ function HyperLinkView(view) {
92
+ _classCallCheck(this, HyperLinkView);
93
+ this.decorations = hyperLinkDecorations(view);
94
+ }
95
+ _createClass(HyperLinkView, [{
96
+ key: "update",
97
+ value: function update(_update) {
98
+ if (_update.docChanged || _update.viewportChanged) {
99
+ this.decorations = hyperLinkDecorations(_update.view);
100
+ }
101
+ }
102
+ }]);
103
+ return HyperLinkView;
104
+ }(), {
105
+ decorations: function decorations(v) {
106
+ return v.decorations;
107
+ }
108
+ });
109
+ }
110
+ export var hyperLinkStyle = EditorView.baseTheme({
111
+ '.cm-hyper-link-icon': {
112
+ display: 'inline-block',
113
+ verticalAlign: 'middle',
114
+ marginLeft: '0.2ch'
115
+ },
116
+ '.cm-hyper-link-icon svg': {
117
+ display: 'block'
118
+ }
119
+ });
120
+ export var hyperLink = [hyperLinkExtension(), hyperLinkStyle];
package/es/indent.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { Command } from '@codemirror/view';
2
+ /**
3
+ * Indent or insert a tab as appropriate.
4
+ */
5
+ export declare const indentMoreOrInsertTab: Command;
6
+ export declare const indentOrCompletion: Command;
7
+ export declare const indentOrTooltip: Command;
8
+ //# sourceMappingURL=indent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indent.d.ts","sourceRoot":"","sources":["../src/indent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAK5D;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,OAanC,CAAC;AAMF,eAAO,MAAM,kBAAkB,EAAE,OA0BhC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,OAY7B,CAAC"}
package/es/indent.js ADDED
@@ -0,0 +1,58 @@
1
+ import { indentLess, indentMore, insertTab } from '@codemirror/commands';
2
+ import { completionState, startCompletionEffect } from "./auto-complete/state.js";
3
+ import { startTooltip } from "./tooltip.js";
4
+
5
+ /**
6
+ * Indent or insert a tab as appropriate.
7
+ */
8
+ export var indentMoreOrInsertTab = function indentMoreOrInsertTab(view) {
9
+ var from = view.state.selection.main.from;
10
+ var to = view.state.selection.main.to;
11
+ if (from !== to) {
12
+ return indentMore(view);
13
+ }
14
+ var line = view.state.doc.lineAt(from);
15
+ var before = view.state.doc.slice(line.from, from).toString();
16
+ if (/^\s*$/.test(before)) {
17
+ return indentMore(view);
18
+ } else {
19
+ return insertTab(view);
20
+ }
21
+ };
22
+
23
+ /**
24
+ * RegExp to test for leading whitespace
25
+ */
26
+ var leadingWhitespaceRe = /^\s+$/;
27
+ export var indentOrCompletion = function indentOrCompletion(view) {
28
+ var from = view.state.selection.main.from;
29
+ var line = view.state.doc.lineAt(from);
30
+ var shouldIndent = false;
31
+ if (line.from === from) {
32
+ shouldIndent = true;
33
+ } else {
34
+ shouldIndent = view.state.doc.slice(from - 1, from).toString().match(leadingWhitespaceRe) !== null;
35
+ }
36
+ if (shouldIndent) {
37
+ return indentMoreOrInsertTab(view);
38
+ } else {
39
+ var cState = view.state.field(completionState, false);
40
+ if (!cState) {
41
+ return false;
42
+ }
43
+ view.dispatch({
44
+ effects: startCompletionEffect.of(true)
45
+ });
46
+ return true;
47
+ }
48
+ };
49
+ export var indentOrTooltip = function indentOrTooltip(view) {
50
+ var from = view.state.selection.main.from;
51
+ var line = view.state.doc.lineAt(from);
52
+ var shouldIndentLess = view.state.doc.slice(line.from, from).toString().match(leadingWhitespaceRe) !== null;
53
+ if (shouldIndentLess) {
54
+ return indentLess(view);
55
+ } else {
56
+ return startTooltip(view);
57
+ }
58
+ };
@@ -0,0 +1,17 @@
1
+ import { Facet } from '@codemirror/state';
2
+ export interface IndentationMarkerConfiguration {
3
+ /**
4
+ * Determines whether active block marker is styled differently.
5
+ */
6
+ highlightActiveBlock?: boolean;
7
+ /**
8
+ * Determines whether markers in the first column are omitted.
9
+ */
10
+ hideFirstIndent?: boolean;
11
+ /**
12
+ * Determines the type of indentation marker.
13
+ */
14
+ markerType?: 'fullScope' | 'codeOnly';
15
+ }
16
+ export declare const indentationMarkerConfig: Facet<IndentationMarkerConfiguration, Required<IndentationMarkerConfiguration>>;
17
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/indentation-markers/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;CACvC;AAED,eAAO,MAAM,uBAAuB,iFAWlC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { combineConfig, Facet } from '@codemirror/state';
2
+ export var indentationMarkerConfig = Facet.define({
3
+ combine: function combine(configs) {
4
+ return combineConfig(configs, {
5
+ highlightActiveBlock: true,
6
+ hideFirstIndent: false,
7
+ markerType: 'codeOnly'
8
+ });
9
+ }
10
+ });
@@ -0,0 +1,3 @@
1
+ import type { IndentationMarkerConfiguration } from './config.js';
2
+ export declare function indentationMarkers(config?: IndentationMarkerConfiguration): import("@codemirror/state").Extension[];
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/indentation-markers/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAgLlE,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,8BAAmC,2CAQ7E"}
@@ -0,0 +1,160 @@
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 _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; } } }; }
3
+ 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); }
4
+ 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; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
+ 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); }
10
+ import { getIndentUnit } from '@codemirror/language';
11
+ import { RangeSetBuilder } from '@codemirror/state';
12
+ import { Decoration, ViewPlugin, EditorView } from '@codemirror/view';
13
+ import { indentationMarkerConfig } from "./config.js";
14
+ import { IndentationMap } from "./map.js";
15
+ import { getCurrentLine, getVisibleLines } from "./utils.js";
16
+
17
+ // CSS classes:
18
+ // - .cm-indent-markers
19
+
20
+ // CSS variables:
21
+ // - --indent-marker-bg-part
22
+ // - --indent-marker-active-bg-part
23
+
24
+ /** Color of inactive indent markers. Based on RUI's var(--background-higher) */
25
+ var MARKER_COLOR_LIGHT = '#5f6064';
26
+ var MARKER_COLOR_DARK = '#5f6064';
27
+
28
+ /** Color of active indent markers. Based on RUI's var(--background-highest) */
29
+ var MARKER_COLOR_ACTIVE_LIGHT = '#A4AECB';
30
+ var MARKER_COLOR_ACTIVE_DARK = '#565C6D';
31
+
32
+ /** Thickness of indent markers. Probably should be integer pixel values. */
33
+ var MARKER_THICKNESS = '1px';
34
+ var indentTheme = EditorView.baseTheme({
35
+ '&light': {
36
+ '--indent-marker-bg-color': MARKER_COLOR_LIGHT,
37
+ '--indent-marker-active-bg-color': MARKER_COLOR_ACTIVE_LIGHT
38
+ },
39
+ '&dark': {
40
+ '--indent-marker-bg-color': MARKER_COLOR_DARK,
41
+ '--indent-marker-active-bg-color': MARKER_COLOR_ACTIVE_DARK
42
+ },
43
+ '.cm-line': {
44
+ position: 'relative'
45
+ },
46
+ // this pseudo-element is used to draw the indent markers,
47
+ // while still allowing the line to have its own background.
48
+ '.cm-indent-markers::before': {
49
+ content: '""',
50
+ position: 'absolute',
51
+ top: 0,
52
+ left: 0,
53
+ right: 0,
54
+ bottom: 0,
55
+ background: 'var(--indent-markers)',
56
+ pointerEvents: 'none',
57
+ zIndex: '-1'
58
+ }
59
+ });
60
+ function createGradient(markerCssProperty, indentWidth, startOffset, columns) {
61
+ var gradient = "repeating-linear-gradient(to right, var(".concat(markerCssProperty, ") 0 ").concat(MARKER_THICKNESS, ", transparent ").concat(MARKER_THICKNESS, " ").concat(indentWidth, "ch)");
62
+ // Subtract one pixel from the background width to get rid of artifacts of pixel rounding
63
+ return "".concat(gradient, " ").concat(startOffset * indentWidth, "ch/calc(").concat(indentWidth * columns, "ch - 1px) no-repeat");
64
+ }
65
+
66
+ // libro 没有使用codemirror的dark theme机制
67
+ // const indentMarkerBgColor = '--indent-marker-bg-color';
68
+ // const indentMarkerActiveBgColor = '--indent-marker-active-bg-color';
69
+ var indentMarkerBgColor = '--mana-libro-editor-indent-marker-bg-color';
70
+ var indentMarkerActiveBgColor = '--mana-libro-editor-indent-marker-active-bg-color';
71
+ function makeBackgroundCSS(entry, indentWidth, hideFirstIndent) {
72
+ var level = entry.level,
73
+ active = entry.active;
74
+ if (hideFirstIndent && level === 0) {
75
+ return [];
76
+ }
77
+ var startAt = hideFirstIndent ? 1 : 0;
78
+ var backgrounds = [];
79
+ if (active !== undefined) {
80
+ var markersBeforeActive = active - startAt - 1;
81
+ if (markersBeforeActive > 0) {
82
+ backgrounds.push(createGradient(indentMarkerBgColor, indentWidth, startAt, markersBeforeActive));
83
+ }
84
+ backgrounds.push(createGradient(indentMarkerActiveBgColor, indentWidth, active - 1, 1));
85
+ if (active !== level) {
86
+ backgrounds.push(createGradient(indentMarkerBgColor, indentWidth, active, level - active));
87
+ }
88
+ } else {
89
+ backgrounds.push(createGradient(indentMarkerBgColor, indentWidth, startAt, level - startAt));
90
+ }
91
+ return backgrounds.join(',');
92
+ }
93
+ var IndentMarkersClass = /*#__PURE__*/function () {
94
+ function IndentMarkersClass(view) {
95
+ _classCallCheck(this, IndentMarkersClass);
96
+ this.view = view;
97
+ this.unitWidth = getIndentUnit(view.state);
98
+ this.currentLineNumber = getCurrentLine(view.state).number;
99
+ this.generate(view.state);
100
+ }
101
+ _createClass(IndentMarkersClass, [{
102
+ key: "update",
103
+ value: function update(_update) {
104
+ var unitWidth = getIndentUnit(_update.state);
105
+ var unitWidthChanged = unitWidth !== this.unitWidth;
106
+ if (unitWidthChanged) {
107
+ this.unitWidth = unitWidth;
108
+ }
109
+ var lineNumber = getCurrentLine(_update.state).number;
110
+ var lineNumberChanged = lineNumber !== this.currentLineNumber;
111
+ this.currentLineNumber = lineNumber;
112
+ var activeBlockUpdateRequired = _update.state.facet(indentationMarkerConfig).highlightActiveBlock && lineNumberChanged;
113
+ if (_update.docChanged || _update.viewportChanged || unitWidthChanged || activeBlockUpdateRequired) {
114
+ this.generate(_update.state);
115
+ }
116
+ }
117
+ }, {
118
+ key: "generate",
119
+ value: function generate(state) {
120
+ var builder = new RangeSetBuilder();
121
+ var lines = getVisibleLines(this.view, state);
122
+ var _state$facet = state.facet(indentationMarkerConfig),
123
+ hideFirstIndent = _state$facet.hideFirstIndent,
124
+ markerType = _state$facet.markerType;
125
+ var map = new IndentationMap(lines, state, this.unitWidth, markerType);
126
+ var _iterator = _createForOfIteratorHelper(lines),
127
+ _step;
128
+ try {
129
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
130
+ var line = _step.value;
131
+ var entry = map.get(line.number);
132
+ if (!(entry !== null && entry !== void 0 && entry.level)) {
133
+ continue;
134
+ }
135
+ var backgrounds = makeBackgroundCSS(entry, this.unitWidth, hideFirstIndent);
136
+ builder.add(line.from, line.from, Decoration.line({
137
+ class: 'cm-indent-markers',
138
+ attributes: {
139
+ style: "--indent-markers: ".concat(backgrounds)
140
+ }
141
+ }));
142
+ }
143
+ } catch (err) {
144
+ _iterator.e(err);
145
+ } finally {
146
+ _iterator.f();
147
+ }
148
+ this.decorations = builder.finish();
149
+ }
150
+ }]);
151
+ return IndentMarkersClass;
152
+ }();
153
+ export function indentationMarkers() {
154
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
155
+ return [indentationMarkerConfig.of(config), indentTheme, ViewPlugin.fromClass(IndentMarkersClass, {
156
+ decorations: function decorations(v) {
157
+ return v.decorations;
158
+ }
159
+ })];
160
+ }
@@ -0,0 +1,77 @@
1
+ import type { EditorState, Line } from '@codemirror/state';
2
+ export interface IndentEntry {
3
+ line: Line;
4
+ col: number;
5
+ level: number;
6
+ empty: boolean;
7
+ active?: number;
8
+ }
9
+ /**
10
+ * Indentation map for a set of lines.
11
+ *
12
+ * This map will contain the indentation for lines that are not a part of the given set,
13
+ * but this is because calculating the indentation for those lines was necessary to
14
+ * calculate the indentation for the lines provided to the constructor.
15
+ *
16
+ * @see {@link IndentEntry}
17
+ */
18
+ export declare class IndentationMap {
19
+ /** The {@link EditorState} indentation is derived from. */
20
+ private state;
21
+ /** The set of lines that are used as an entrypoint. */
22
+ private lines;
23
+ /** The internal mapping of line numbers to {@link IndentEntry} objects. */
24
+ private map;
25
+ /** The width of the editor's indent unit. */
26
+ private unitWidth;
27
+ /** The type of indentation to use (terminate at end of scope vs last non-empty line in scope) */
28
+ private markerType;
29
+ /**
30
+ * @param lines - The set of lines to get the indentation map for.
31
+ * @param state - The {@link EditorState} to derive the indentation map from.
32
+ * @param unitWidth - The width of the editor's indent unit.
33
+ * @param markerType - The type of indentation to use (terminate at end of scope vs last line of code in scope)
34
+ */
35
+ constructor(lines: Set<Line>, state: EditorState, unitWidth: number, markerType: 'fullScope' | 'codeOnly');
36
+ /**
37
+ * Checks if the indentation map has an entry for the given line.
38
+ *
39
+ * @param line - The {@link Line} or line number to check for.
40
+ */
41
+ has(line: Line | number): boolean;
42
+ /**
43
+ * Returns the {@link IndentEntry} for the given line.
44
+ *
45
+ * Note that this function will throw an error if the line does not exist in the map.
46
+ *
47
+ * @param line - The {@link Line} or line number to get the entry for.
48
+ */
49
+ get(line: Line | number): IndentEntry;
50
+ /**
51
+ * Sets the {@link IndentEntry} for the given line.
52
+ *
53
+ * @param line - The {@link Line} to set the entry for.
54
+ * @param col - The visual beginning whitespace width of the line.
55
+ * @param level - The indentation level of the line.
56
+ */
57
+ private set;
58
+ /**
59
+ * Adds a line to the indentation map.
60
+ *
61
+ * @param line - The {@link Line} to add to the map.
62
+ */
63
+ private add;
64
+ /**
65
+ * Finds the closest non-empty line, starting from the given line.
66
+ *
67
+ * @param from - The {@link Line} to start from.
68
+ * @param dir - The direction to search in. Either `1` or `-1`.
69
+ */
70
+ private closestNonEmpty;
71
+ /**
72
+ * Finds the state's active block (via the current selection) and sets all
73
+ * the active indent level for the lines in the block.
74
+ */
75
+ private findAndSetActiveLines;
76
+ }
77
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/indentation-markers/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAK3D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,qBAAa,cAAc;IACzB,2DAA2D;IAC3D,OAAO,CAAC,KAAK,CAAc;IAE3B,uDAAuD;IACvD,OAAO,CAAC,KAAK,CAAY;IAEzB,2EAA2E;IAC3E,OAAO,CAAC,GAAG,CAA2B;IAEtC,6CAA6C;IAC7C,OAAO,CAAC,SAAS,CAAS;IAE1B,iGAAiG;IACjG,OAAO,CAAC,UAAU,CAA2B;IAE7C;;;;;OAKG;gBAED,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,EAChB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,WAAW,GAAG,UAAU;IAiBtC;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAIvB;;;;;;OAMG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAUvB;;;;;;OAMG;IACH,OAAO,CAAC,GAAG;IAQX;;;;OAIG;IACH,OAAO,CAAC,GAAG;IAkDX;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAoCvB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAiE9B"}