@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
package/es/tooltip.js ADDED
@@ -0,0 +1,170 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
+ 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; } } }; }
8
+ 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); }
9
+ 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; }
10
+ /* eslint-disable @typescript-eslint/no-parameter-properties */
11
+ /* eslint-disable @typescript-eslint/parameter-properties */
12
+ import { StateEffect, StateField } from '@codemirror/state';
13
+ import { ViewPlugin, showTooltip, EditorView } from '@codemirror/view';
14
+ import { defaultSanitizer } from '@difizen/libro-common';
15
+ import { renderText } from '@difizen/libro-rendermime';
16
+ export var startTooltipEffect = StateEffect.define();
17
+ export var closeTooltipEffect = StateEffect.define();
18
+ var tooltipResultEffect = StateEffect.define({});
19
+ var getCursorTooltips = function getCursorTooltips(state, text) {
20
+ return {
21
+ pos: state.selection.main.head,
22
+ above: false,
23
+ strictSide: false,
24
+ arrow: false,
25
+ create: function create() {
26
+ var dom = document.createElement('div');
27
+ dom.className = 'cm-tooltip-libro';
28
+ renderText({
29
+ sanitizer: defaultSanitizer,
30
+ source: text,
31
+ host: dom,
32
+ mimeType: ''
33
+ });
34
+ return {
35
+ dom: dom
36
+ };
37
+ }
38
+ };
39
+ };
40
+ var tooltipField = StateField.define({
41
+ create: function create() {
42
+ return null;
43
+ },
44
+ update: function update(_tooltips, tr) {
45
+ var effects = tr.effects;
46
+ var _iterator = _createForOfIteratorHelper(effects),
47
+ _step;
48
+ try {
49
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
50
+ var effect = _step.value;
51
+ if (effect.is(closeTooltipEffect)) {
52
+ return null;
53
+ } else if (effect.is(tooltipResultEffect)) {
54
+ var text = effect.value.tooltipText;
55
+ if (text !== null) {
56
+ return getCursorTooltips(tr.state, text);
57
+ }
58
+ }
59
+ }
60
+ } catch (err) {
61
+ _iterator.e(err);
62
+ } finally {
63
+ _iterator.f();
64
+ }
65
+ return null;
66
+ },
67
+ provide: function provide(f) {
68
+ return showTooltip.compute([f], function (state) {
69
+ var filed = state.field(f);
70
+ if (filed === null) {
71
+ return null;
72
+ }
73
+ return filed;
74
+ });
75
+ }
76
+ });
77
+
78
+ /// Explicitly start tooltip.
79
+ export var startTooltip = function startTooltip(view) {
80
+ view.dispatch({
81
+ effects: startTooltipEffect.of(true)
82
+ });
83
+ return true;
84
+ };
85
+
86
+ /// Close tooltip.
87
+ export var closeTooltip = function closeTooltip(view) {
88
+ view.dispatch({
89
+ effects: closeTooltipEffect.of(null)
90
+ });
91
+ return true;
92
+ };
93
+ export var tooltipKeymap = [{
94
+ key: 'Shift-Tab',
95
+ run: startTooltip
96
+ }, {
97
+ key: 'Escape',
98
+ run: closeTooltip
99
+ }];
100
+ var cursorTooltipBaseTheme = EditorView.baseTheme({
101
+ '.cm-tooltip.cm-tooltip-libro': {
102
+ zIndex: '10001',
103
+ color: 'rgba(0,0,0,0.87)',
104
+ padding: '2px 7px',
105
+ borderRadius: '4px',
106
+ boxShadow: 'rgba(0,0,0,0.2) 0px 3px 5px -1px, rgba(0,0,0,0.0.14) 0px 6px 10px 0px, rgba(0,0,0,0.0.12) 0px 1px 18px 0px',
107
+ maxHeight: '350px',
108
+ overflow: 'auto'
109
+ }
110
+ });
111
+ var TooltipPlugin = /*#__PURE__*/function () {
112
+ function TooltipPlugin(view, tooltipProvider) {
113
+ _classCallCheck(this, TooltipPlugin);
114
+ this.view = view;
115
+ this.tooltipProvider = tooltipProvider;
116
+ }
117
+ _createClass(TooltipPlugin, [{
118
+ key: "update",
119
+ value: function update(_update) {
120
+ var _this = this;
121
+ _update.transactions.forEach(function (tr) {
122
+ var _iterator2 = _createForOfIteratorHelper(tr.effects),
123
+ _step2;
124
+ try {
125
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
126
+ var effect = _step2.value;
127
+ if (effect.is(startTooltipEffect) && _this.tooltipProvider) {
128
+ _this.tooltipProvider({
129
+ cursorPosition: _update.view.state.selection.main.anchor
130
+ }).then(function (result) {
131
+ _update.view.dispatch({
132
+ effects: tooltipResultEffect.of({
133
+ tooltipText: result
134
+ })
135
+ });
136
+ return undefined;
137
+ }).catch(function () {
138
+ //
139
+ });
140
+ }
141
+ }
142
+ } catch (err) {
143
+ _iterator2.e(err);
144
+ } finally {
145
+ _iterator2.f();
146
+ }
147
+ });
148
+ }
149
+ }]);
150
+ return TooltipPlugin;
151
+ }();
152
+ var asyncShowTooltip = function asyncShowTooltip(tooltipProvider) {
153
+ return ViewPlugin.define(function (view) {
154
+ return new TooltipPlugin(view, tooltipProvider);
155
+ }, {
156
+ eventHandlers: {
157
+ blur: function blur() {
158
+ var state = this.view.state.field(tooltipField, false);
159
+ if (state) {
160
+ this.view.dispatch({
161
+ effects: closeTooltipEffect.of(null)
162
+ });
163
+ }
164
+ }
165
+ }
166
+ });
167
+ };
168
+ export function tabTooltip(tooltipProvider) {
169
+ return [tooltipField, cursorTooltipBaseTheme, asyncShowTooltip(tooltipProvider)];
170
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@difizen/libro-codemirror",
3
+ "version": "0.0.2-alpha.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "libro",
7
+ "notebook"
8
+ ],
9
+ "repository": "git@github.com:difizen/libro.git",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "typings": "./es/index.d.ts",
15
+ "default": "./es/index.js"
16
+ },
17
+ "./mock": {
18
+ "typings": "./es/mock/index.d.ts",
19
+ "default": "./es/mock/index.js"
20
+ },
21
+ "./es/mock": {
22
+ "typings": "./es/mock/index.d.ts",
23
+ "default": "./es/mock/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "es/index.js",
28
+ "module": "es/index.js",
29
+ "typings": "es/index.d.ts",
30
+ "files": [
31
+ "es",
32
+ "src"
33
+ ],
34
+ "dependencies": {
35
+ "@difizen/mana-app": "alpha",
36
+ "@codemirror/autocomplete": "^6.0.0",
37
+ "@codemirror/commands": "^6.1.0",
38
+ "@codemirror/lang-javascript": "^6.0.2",
39
+ "@codemirror/lang-json": "^6.0.0",
40
+ "@codemirror/lang-markdown": "^6.0.5",
41
+ "@codemirror/lang-python": "^6.0.1",
42
+ "@codemirror/lang-sql": "^6.3.0",
43
+ "@codemirror/language": "^6.2.1",
44
+ "@codemirror/lint": "^6.0.0",
45
+ "@codemirror/search": "^6.0.0",
46
+ "@codemirror/state": "^6.0.0",
47
+ "@codemirror/view": "^6.2.2",
48
+ "@difizen/libro-code-editor": "^0.0.2-alpha.0",
49
+ "@difizen/libro-common": "^0.0.2-alpha.0",
50
+ "@difizen/libro-rendermime": "^0.0.2-alpha.0",
51
+ "@lezer/common": "^1.1.0",
52
+ "@lezer/highlight": "^1.1.4",
53
+ "markdown-it": "^13.0.1",
54
+ "uuid": "^9.0.0",
55
+ "vscode-languageserver-protocol": "^3.17.0"
56
+ },
57
+ "devDependencies": {
58
+ "@types/markdown-it": "^12.2.3",
59
+ "@types/uuid": "^8.3.4"
60
+ },
61
+ "scripts": {
62
+ "setup": "father build",
63
+ "build": "father build",
64
+ "test": ": Note: lint task is delegated to test:* scripts",
65
+ "test:vitest": "vitest run",
66
+ "test:jest": "jest",
67
+ "coverage": ": Note: lint task is delegated to coverage:* scripts",
68
+ "coverage:vitest": "vitest run --coverage",
69
+ "coverage:jest": "jest --coverage",
70
+ "lint": ": Note: lint task is delegated to lint:* scripts",
71
+ "lint:eslint": "eslint src",
72
+ "lint:tsc": "tsc --noEmit"
73
+ }
74
+ }
@@ -0,0 +1,71 @@
1
+ @Completion
2
+
3
+ @autocompletion
4
+
5
+ @completionStatus
6
+
7
+ @currentCompletions
8
+
9
+ @selectedCompletion
10
+
11
+ @selectedCompletionIndex
12
+
13
+ @setSelectedCompletion
14
+
15
+ @pickedCompletion
16
+
17
+ ### Sources
18
+
19
+ @CompletionContext
20
+
21
+ @CompletionResult
22
+
23
+ @CompletionSource
24
+
25
+ @completeFromList
26
+
27
+ @ifIn
28
+
29
+ @ifNotIn
30
+
31
+ @completeAnyWord
32
+
33
+ @insertCompletionText
34
+
35
+ ### Commands
36
+
37
+ @startCompletion
38
+
39
+ @closeCompletion
40
+
41
+ @acceptCompletion
42
+
43
+ @moveCompletionSelection
44
+
45
+ @completionKeymap
46
+
47
+ ### Snippets
48
+
49
+ @snippet
50
+
51
+ @snippetCompletion
52
+
53
+ @nextSnippetField
54
+
55
+ @prevSnippetField
56
+
57
+ @clearSnippet
58
+
59
+ @snippetKeymap
60
+
61
+ ### Automatic Bracket Closing
62
+
63
+ @CloseBracketConfig
64
+
65
+ @closeBrackets
66
+
67
+ @closeBracketsKeymap
68
+
69
+ @deleteBracketPair
70
+
71
+ @insertBracket