@difizen/libro-codemirror 0.0.0-snapshot-20241017072317
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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/auto-complete/closebrackets.d.ts +12 -0
- package/es/auto-complete/closebrackets.d.ts.map +1 -0
- package/es/auto-complete/closebrackets.js +409 -0
- package/es/auto-complete/completion.d.ts +57 -0
- package/es/auto-complete/completion.d.ts.map +1 -0
- package/es/auto-complete/completion.js +267 -0
- package/es/auto-complete/config.d.ts +22 -0
- package/es/auto-complete/config.d.ts.map +1 -0
- package/es/auto-complete/config.js +44 -0
- package/es/auto-complete/filter.d.ts +13 -0
- package/es/auto-complete/filter.d.ts.map +1 -0
- package/es/auto-complete/filter.js +190 -0
- package/es/auto-complete/index.d.ts +17 -0
- package/es/auto-complete/index.d.ts.map +1 -0
- package/es/auto-complete/index.js +107 -0
- package/es/auto-complete/snippet.d.ts +14 -0
- package/es/auto-complete/snippet.d.ts.map +1 -0
- package/es/auto-complete/snippet.js +445 -0
- package/es/auto-complete/state.d.ts +63 -0
- package/es/auto-complete/state.d.ts.map +1 -0
- package/es/auto-complete/state.js +448 -0
- package/es/auto-complete/theme.d.ts +6 -0
- package/es/auto-complete/theme.d.ts.map +1 -0
- package/es/auto-complete/theme.js +150 -0
- package/es/auto-complete/tooltip.d.ts +5 -0
- package/es/auto-complete/tooltip.d.ts.map +1 -0
- package/es/auto-complete/tooltip.js +365 -0
- package/es/auto-complete/view.d.ts +38 -0
- package/es/auto-complete/view.d.ts.map +1 -0
- package/es/auto-complete/view.js +368 -0
- package/es/auto-complete/word.d.ts +3 -0
- package/es/auto-complete/word.d.ts.map +1 -0
- package/es/auto-complete/word.js +119 -0
- package/es/completion.d.ts +6 -0
- package/es/completion.d.ts.map +1 -0
- package/es/completion.js +84 -0
- package/es/config.d.ts +189 -0
- package/es/config.d.ts.map +1 -0
- package/es/config.js +482 -0
- package/es/editor-contribution.d.ts +9 -0
- package/es/editor-contribution.d.ts.map +1 -0
- package/es/editor-contribution.js +35 -0
- package/es/editor.d.ts +397 -0
- package/es/editor.d.ts.map +1 -0
- package/es/editor.js +1338 -0
- package/es/factory.d.ts +4 -0
- package/es/factory.d.ts.map +1 -0
- package/es/factory.js +24 -0
- package/es/hyperlink.d.ts +15 -0
- package/es/hyperlink.d.ts.map +1 -0
- package/es/hyperlink.js +120 -0
- package/es/indent.d.ts +8 -0
- package/es/indent.d.ts.map +1 -0
- package/es/indent.js +58 -0
- package/es/indentation-markers/config.d.ts +17 -0
- package/es/indentation-markers/config.d.ts.map +1 -0
- package/es/indentation-markers/config.js +10 -0
- package/es/indentation-markers/index.d.ts +3 -0
- package/es/indentation-markers/index.d.ts.map +1 -0
- package/es/indentation-markers/index.js +160 -0
- package/es/indentation-markers/map.d.ts +77 -0
- package/es/indentation-markers/map.d.ts.map +1 -0
- package/es/indentation-markers/map.js +265 -0
- package/es/indentation-markers/utils.d.ts +27 -0
- package/es/indentation-markers/utils.d.ts.map +1 -0
- package/es/indentation-markers/utils.js +91 -0
- package/es/index.d.ts +13 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +12 -0
- package/es/libro-icon.d.ts +3 -0
- package/es/libro-icon.d.ts.map +1 -0
- package/es/libro-icon.js +2 -0
- package/es/lsp/completion.d.ts +5 -0
- package/es/lsp/completion.d.ts.map +1 -0
- package/es/lsp/completion.js +245 -0
- package/es/lsp/format.d.ts +7 -0
- package/es/lsp/format.d.ts.map +1 -0
- package/es/lsp/format.js +193 -0
- package/es/lsp/index.d.ts +7 -0
- package/es/lsp/index.d.ts.map +1 -0
- package/es/lsp/index.js +6 -0
- package/es/lsp/lint.d.ts +3 -0
- package/es/lsp/lint.d.ts.map +1 -0
- package/es/lsp/lint.js +113 -0
- package/es/lsp/protocol.d.ts +7 -0
- package/es/lsp/protocol.d.ts.map +1 -0
- package/es/lsp/protocol.js +1 -0
- package/es/lsp/tooltip.d.ts +3 -0
- package/es/lsp/tooltip.d.ts.map +1 -0
- package/es/lsp/tooltip.js +113 -0
- package/es/lsp/util.d.ts +15 -0
- package/es/lsp/util.d.ts.map +1 -0
- package/es/lsp/util.js +57 -0
- package/es/mimetype.d.ts +22 -0
- package/es/mimetype.d.ts.map +1 -0
- package/es/mimetype.js +59 -0
- package/es/mode.d.ts +86 -0
- package/es/mode.d.ts.map +1 -0
- package/es/mode.js +280 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +4 -0
- package/es/monitor.d.ts +32 -0
- package/es/monitor.d.ts.map +1 -0
- package/es/monitor.js +129 -0
- package/es/python-lang.d.ts +3 -0
- package/es/python-lang.d.ts.map +1 -0
- package/es/python-lang.js +7 -0
- package/es/style/base.css +129 -0
- package/es/style/theme.css +12 -0
- package/es/style/variables.css +405 -0
- package/es/theme.d.ts +35 -0
- package/es/theme.d.ts.map +1 -0
- package/es/theme.js +223 -0
- package/es/tooltip.d.ts +10 -0
- package/es/tooltip.d.ts.map +1 -0
- package/es/tooltip.js +168 -0
- package/package.json +74 -0
- package/src/auto-complete/README.md +71 -0
- package/src/auto-complete/closebrackets.ts +423 -0
- package/src/auto-complete/completion.ts +345 -0
- package/src/auto-complete/config.ts +101 -0
- package/src/auto-complete/filter.ts +214 -0
- package/src/auto-complete/index.ts +112 -0
- package/src/auto-complete/snippet.ts +392 -0
- package/src/auto-complete/state.ts +465 -0
- package/src/auto-complete/theme.ts +127 -0
- package/src/auto-complete/tooltip.ts +386 -0
- package/src/auto-complete/view.ts +339 -0
- package/src/auto-complete/word.ts +118 -0
- package/src/completion.ts +61 -0
- package/src/config.ts +701 -0
- package/src/editor-contribution.ts +22 -0
- package/src/editor.ts +1287 -0
- package/src/factory.ts +31 -0
- package/src/hyperlink.ts +95 -0
- package/src/indent.ts +69 -0
- package/src/indentation-markers/config.ts +31 -0
- package/src/indentation-markers/index.ts +192 -0
- package/src/indentation-markers/map.ts +273 -0
- package/src/indentation-markers/utils.ts +84 -0
- package/src/index.spec.ts +12 -0
- package/src/index.ts +14 -0
- package/src/libro-icon.tsx +4 -0
- package/src/lsp/completion.ts +175 -0
- package/src/lsp/format.ts +144 -0
- package/src/lsp/index.ts +6 -0
- package/src/lsp/lint.ts +125 -0
- package/src/lsp/protocol.ts +8 -0
- package/src/lsp/tooltip.ts +76 -0
- package/src/lsp/util.ts +69 -0
- package/src/mimetype.ts +49 -0
- package/src/mode.ts +265 -0
- package/src/module.ts +8 -0
- package/src/monitor.ts +105 -0
- package/src/python-lang.ts +7 -0
- package/src/style/base.css +129 -0
- package/src/style/theme.css +12 -0
- package/src/style/variables.css +405 -0
- package/src/theme.ts +231 -0
- package/src/tooltip.ts +143 -0
package/src/tooltip.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-parameter-properties */
|
|
2
|
+
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
3
|
+
import { StateEffect, StateField } from '@codemirror/state';
|
|
4
|
+
import type { EditorState } from '@codemirror/state';
|
|
5
|
+
import type {
|
|
6
|
+
Command,
|
|
7
|
+
KeyBinding,
|
|
8
|
+
PluginValue,
|
|
9
|
+
Tooltip,
|
|
10
|
+
ViewUpdate,
|
|
11
|
+
} from '@codemirror/view';
|
|
12
|
+
import { ViewPlugin, showTooltip, EditorView } from '@codemirror/view';
|
|
13
|
+
import type { TooltipProvider } from '@difizen/libro-code-editor';
|
|
14
|
+
import { defaultSanitizer } from '@difizen/libro-common';
|
|
15
|
+
import { renderText } from '@difizen/libro-rendermime';
|
|
16
|
+
|
|
17
|
+
export const startTooltipEffect = StateEffect.define<boolean>();
|
|
18
|
+
export const closeTooltipEffect = StateEffect.define<null>();
|
|
19
|
+
const tooltipResultEffect = StateEffect.define<{ tooltipText: string | null }>({});
|
|
20
|
+
|
|
21
|
+
const getCursorTooltips = (state: EditorState, text: string): Tooltip => {
|
|
22
|
+
return {
|
|
23
|
+
pos: state.selection.main.head,
|
|
24
|
+
above: false,
|
|
25
|
+
strictSide: false,
|
|
26
|
+
arrow: false,
|
|
27
|
+
create: () => {
|
|
28
|
+
const dom = document.createElement('div');
|
|
29
|
+
dom.className = 'cm-tooltip-libro';
|
|
30
|
+
renderText({
|
|
31
|
+
sanitizer: defaultSanitizer,
|
|
32
|
+
source: text,
|
|
33
|
+
host: dom,
|
|
34
|
+
mimeType: '',
|
|
35
|
+
});
|
|
36
|
+
return { dom };
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const tooltipField = StateField.define<Tooltip | null>({
|
|
42
|
+
create() {
|
|
43
|
+
return null;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
update(tooltips, tr) {
|
|
47
|
+
const { effects } = tr;
|
|
48
|
+
for (const effect of effects) {
|
|
49
|
+
if (effect.is(closeTooltipEffect)) {
|
|
50
|
+
return null;
|
|
51
|
+
} else if (effect.is(tooltipResultEffect)) {
|
|
52
|
+
const text = effect.value.tooltipText;
|
|
53
|
+
if (text !== null) {
|
|
54
|
+
return getCursorTooltips(tr.state, text);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
provide: (f) =>
|
|
62
|
+
showTooltip.compute([f], (state) => {
|
|
63
|
+
const filed = state.field(f);
|
|
64
|
+
if (filed === null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return filed;
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/// Explicitly start tooltip.
|
|
72
|
+
export const startTooltip: Command = (view: EditorView) => {
|
|
73
|
+
view.dispatch({ effects: startTooltipEffect.of(true) });
|
|
74
|
+
return true;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/// Close tooltip.
|
|
78
|
+
export const closeTooltip: Command = (view: EditorView) => {
|
|
79
|
+
view.dispatch({ effects: closeTooltipEffect.of(null) });
|
|
80
|
+
return true;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const tooltipKeymap: readonly KeyBinding[] = [
|
|
84
|
+
{ key: 'Shift-Tab', run: startTooltip },
|
|
85
|
+
{ key: 'Escape', run: closeTooltip },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const cursorTooltipBaseTheme = EditorView.baseTheme({
|
|
89
|
+
'.cm-tooltip.cm-tooltip-libro': {
|
|
90
|
+
zIndex: '10001',
|
|
91
|
+
color: 'rgba(0,0,0,0.87)',
|
|
92
|
+
padding: '2px 7px',
|
|
93
|
+
borderRadius: '4px',
|
|
94
|
+
boxShadow:
|
|
95
|
+
'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',
|
|
96
|
+
maxHeight: '350px',
|
|
97
|
+
overflow: 'auto',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
class TooltipPlugin implements PluginValue {
|
|
102
|
+
constructor(
|
|
103
|
+
readonly view: EditorView,
|
|
104
|
+
readonly tooltipProvider: TooltipProvider | undefined,
|
|
105
|
+
) {}
|
|
106
|
+
|
|
107
|
+
update(update: ViewUpdate) {
|
|
108
|
+
update.transactions.forEach((tr) => {
|
|
109
|
+
for (const effect of tr.effects) {
|
|
110
|
+
if (effect.is(startTooltipEffect) && this.tooltipProvider) {
|
|
111
|
+
this.tooltipProvider({
|
|
112
|
+
cursorPosition: update.view.state.selection.main.anchor,
|
|
113
|
+
})
|
|
114
|
+
.then((result) => {
|
|
115
|
+
update.view.dispatch({
|
|
116
|
+
effects: tooltipResultEffect.of({
|
|
117
|
+
tooltipText: result,
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
return undefined;
|
|
121
|
+
})
|
|
122
|
+
.catch(console.error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const asyncShowTooltip = (tooltipProvider: TooltipProvider | undefined) =>
|
|
130
|
+
ViewPlugin.define((view) => new TooltipPlugin(view, tooltipProvider), {
|
|
131
|
+
eventHandlers: {
|
|
132
|
+
blur() {
|
|
133
|
+
const state = this.view.state.field(tooltipField, false);
|
|
134
|
+
if (state) {
|
|
135
|
+
this.view.dispatch({ effects: closeTooltipEffect.of(null) });
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export function tabTooltip(tooltipProvider: TooltipProvider | undefined) {
|
|
142
|
+
return [tooltipField, cursorTooltipBaseTheme, asyncShowTooltip(tooltipProvider)];
|
|
143
|
+
}
|