qword 1.1.11 → 1.1.13
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/ChangeLog +10 -0
- package/bower.json +25 -0
- package/client/_clipboard.js +50 -0
- package/client/_init-socket.js +76 -0
- package/client/_on-save.js +38 -0
- package/client/content.d.ts +8 -0
- package/client/content.js +14 -0
- package/client/create.d.ts +33 -0
- package/client/create.js +101 -0
- package/client/decorations.d.ts +38 -0
- package/client/decorations.js +110 -0
- package/client/dom.d.ts +8 -0
- package/client/dom.js +17 -0
- package/client/editor.d.ts +46 -0
- package/client/editor.js +178 -0
- package/client/events.d.ts +8 -0
- package/client/events.js +8 -0
- package/client/highlight.d.ts +3 -0
- package/client/highlight.js +82 -0
- package/client/history.d.ts +5 -0
- package/client/history.js +14 -0
- package/client/index.d.ts +60 -0
- package/client/index.js +38 -0
- package/client/loadremote.js +102 -0
- package/client/options.d.ts +31 -0
- package/client/options.js +70 -0
- package/client/position.d.ts +19 -0
- package/client/position.js +33 -0
- package/client/qword.js +196 -0
- package/client/save.js +53 -0
- package/client/scroll.d.ts +11 -0
- package/client/scroll.js +9 -0
- package/client/show-message.js +30 -0
- package/client/story.js +55 -0
- package/client/types.d.ts +28 -0
- package/dist/qword.js +1 -1
- package/dist/qword.js.map +1 -1
- package/dist-dev/qword.js +1 -1
- package/package.json +1 -1
- package/modules/cm-searchbox/ChangeLog +0 -60
- package/modules/cm-searchbox/LICENSE +0 -21
- package/modules/cm-searchbox/README.md +0 -27
- package/modules/cm-searchbox/img/searchbox.png +0 -0
- package/modules/cm-searchbox/lib/searchbox.js +0 -679
- package/modules/cm-searchbox/package.json +0 -27
- package/modules/cm-show-invisibles/ChangeLog +0 -108
- package/modules/cm-show-invisibles/LICENSE +0 -21
- package/modules/cm-show-invisibles/README.md +0 -25
- package/modules/cm-show-invisibles/lib/show-invisibles.js +0 -131
- package/modules/cm-show-invisibles/package.json +0 -34
- package/modules/codemirror-emmet/README.md +0 -56
- package/modules/codemirror-emmet/dist/emmet.js +0 -48661
- package/modules/codemirror-emmet/dist/emmet.min.js +0 -8
- package/modules/codemirror-emmet/dist/emmetPlugin.js +0 -840
- package/modules/codemirror-emmet/dist/emmetPlugin.min.js +0 -1
- package/modules/codemirror-emmet/dist/index.html +0 -46
- package/modules/codemirror-emmet/editor.js +0 -204
- package/modules/codemirror-emmet/gulpfile.js +0 -54
- package/modules/codemirror-emmet/index.html +0 -68
- package/modules/codemirror-emmet/package.json +0 -36
- package/modules/codemirror-emmet/plugin.js +0 -201
- package/modules/codemirror-emmet/shim.js +0 -19
- package/modules/codemirror-emmet/vendor/almond.js +0 -410
- package/modules/codemirror-emmet/vendor/codemirror/v4/codemirror.css +0 -270
- package/modules/codemirror-emmet/vendor/codemirror/v4/codemirror.js +0 -7339
- package/modules/codemirror-emmet/vendor/codemirror/v4/css.js +0 -701
- package/modules/codemirror-emmet/vendor/codemirror/v4/htmlmixed.js +0 -117
- package/modules/codemirror-emmet/vendor/codemirror/v4/xml.js +0 -349
- package/modules/loadremote/ChangeLog +0 -23
- package/modules/loadremote/LICENSE +0 -21
- package/modules/loadremote/README.md +0 -53
- package/modules/loadremote/lib/loadremote.js +0 -147
- package/modules/loadremote/package.json +0 -26
package/client/editor.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import Emitify from 'emitify';
|
|
2
|
+
import {EditorView} from '@codemirror/view';
|
|
3
|
+
import {createEditor} from './create.js';
|
|
4
|
+
import {getValue, setValue} from './content.js';
|
|
5
|
+
import {
|
|
6
|
+
posFromIndex,
|
|
7
|
+
getCursorIndex,
|
|
8
|
+
getCursor,
|
|
9
|
+
} from './position.js';
|
|
10
|
+
import {
|
|
11
|
+
markText,
|
|
12
|
+
addLineClass,
|
|
13
|
+
removeLineClass,
|
|
14
|
+
} from './decorations.js';
|
|
15
|
+
import {setOption} from './options.js';
|
|
16
|
+
import {clearHistory} from './history.js';
|
|
17
|
+
import {observeResize} from './dom.js';
|
|
18
|
+
|
|
19
|
+
export default class Editor {
|
|
20
|
+
#view;
|
|
21
|
+
#vimEnabled = false;
|
|
22
|
+
#savedValue = '';
|
|
23
|
+
#emitter;
|
|
24
|
+
constructor(element, options = {}) {
|
|
25
|
+
this.#emitter = Emitify();
|
|
26
|
+
|
|
27
|
+
this.#view = createEditor(element, {
|
|
28
|
+
...options,
|
|
29
|
+
updateListener: (update) => {
|
|
30
|
+
if (update.docChanged)
|
|
31
|
+
this.#emitter.emit('change', {
|
|
32
|
+
value: this.getValue(),
|
|
33
|
+
cursor: this.getCursorIndex(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (update.selectionSet)
|
|
37
|
+
this.#emitter.emit('cursorMove', this.getCursorIndex());
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
observeResize(this.#view, element);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getValue() {
|
|
45
|
+
return getValue(this.#view);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setValue(value) {
|
|
49
|
+
setValue(this.#view, value);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getCursorIndex() {
|
|
54
|
+
return getCursorIndex(this.#view);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getCursor() {
|
|
58
|
+
return getCursor(this.#view);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
posFromIndex(index) {
|
|
62
|
+
return posFromIndex(this.#view, index);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
focus() {
|
|
66
|
+
this.#view.focus();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
moveCursorTo(row, column = 0) {
|
|
71
|
+
const line = this.#view.state.doc.line(row + 1);
|
|
72
|
+
|
|
73
|
+
this.#view.dispatch({
|
|
74
|
+
selection: {
|
|
75
|
+
anchor: line.from + column,
|
|
76
|
+
},
|
|
77
|
+
scrollIntoView: true,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
markRange(from, to, className) {
|
|
84
|
+
return markText(this.#view, from, to, {
|
|
85
|
+
className,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
addLineClass(line, className) {
|
|
90
|
+
addLineClass(this.#view, line, 'text', className);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
removeLineClass(line, className) {
|
|
95
|
+
removeLineClass(this.#view, line, 'text', className);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
setOption(name, value) {
|
|
100
|
+
if (name === 'keyMap')
|
|
101
|
+
this.#vimEnabled = value === 'vim';
|
|
102
|
+
|
|
103
|
+
setOption(this.#view, name, value);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setMode(mode) {
|
|
108
|
+
return this.setOption('mode', mode);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
setTheme(theme) {
|
|
112
|
+
return this.setOption('theme', theme);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setKeyMap(name) {
|
|
116
|
+
return this.setOption('keyMap', name);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setModeForPath(path) {
|
|
120
|
+
return this.setMode(path
|
|
121
|
+
.split('.')
|
|
122
|
+
.pop());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
isChanged() {
|
|
126
|
+
return this.getValue() !== this.#savedValue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
clearHistory() {
|
|
130
|
+
clearHistory(
|
|
131
|
+
this.#view,
|
|
132
|
+
this.#view._historyCompartment,
|
|
133
|
+
this.#vimEnabled,
|
|
134
|
+
);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
on(event, handler) {
|
|
139
|
+
this.#emitter.on(event, handler);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
addListener(event, handler) {
|
|
144
|
+
return this.on(event, handler);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
once(event, handler) {
|
|
148
|
+
this.#emitter.once(event, handler);
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
removeListener(event, handler) {
|
|
153
|
+
this.#emitter.removeListener(event, handler);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
emit(...args) {
|
|
158
|
+
this.#emitter.emit(...args);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setOptions(options = {}) {
|
|
163
|
+
if (options.fontSize)
|
|
164
|
+
this._view.dispatch({
|
|
165
|
+
effects: this._view._themeCompartment.reconfigure(EditorView.theme({
|
|
166
|
+
'&': {
|
|
167
|
+
fontSize: `${options.fontSize}px`,
|
|
168
|
+
},
|
|
169
|
+
})),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
get _view() {
|
|
176
|
+
return this.#view;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type {EditorView} from '@codemirror/view';
|
|
2
|
+
|
|
3
|
+
export type EventBinding = [string, EventListener];
|
|
4
|
+
|
|
5
|
+
export function on(view: EditorView, event: string, handler: EventListener): EventBinding;
|
|
6
|
+
|
|
7
|
+
export function off(view: EditorView, event: string, handler: EventListener): void;
|
|
8
|
+
|
package/client/events.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {HighlightStyle} from '@codemirror/language';
|
|
2
|
+
import {tags} from '@lezer/highlight';
|
|
3
|
+
|
|
4
|
+
export const highlightStyle = HighlightStyle.define([{
|
|
5
|
+
tag: tags.keyword,
|
|
6
|
+
class: 'hl-keyword',
|
|
7
|
+
}, {
|
|
8
|
+
tag: tags.definitionKeyword,
|
|
9
|
+
class: 'hl-keyword',
|
|
10
|
+
}, {
|
|
11
|
+
tag: tags.controlKeyword,
|
|
12
|
+
class: 'hl-keyword',
|
|
13
|
+
}, {
|
|
14
|
+
tag: tags.moduleKeyword,
|
|
15
|
+
class: 'hl-module-keyword',
|
|
16
|
+
}, {
|
|
17
|
+
tag: tags.operatorKeyword,
|
|
18
|
+
class: 'hl-operator',
|
|
19
|
+
}, {
|
|
20
|
+
tag: tags.string,
|
|
21
|
+
class: 'hl-string',
|
|
22
|
+
}, {
|
|
23
|
+
tag: tags.number,
|
|
24
|
+
class: 'hl-number',
|
|
25
|
+
}, {
|
|
26
|
+
tag: tags.integer,
|
|
27
|
+
class: 'hl-number',
|
|
28
|
+
}, {
|
|
29
|
+
tag: tags.float,
|
|
30
|
+
class: 'hl-number',
|
|
31
|
+
}, {
|
|
32
|
+
tag: tags.bool,
|
|
33
|
+
class: 'hl-constant',
|
|
34
|
+
}, {
|
|
35
|
+
tag: tags.null,
|
|
36
|
+
class: 'hl-constant',
|
|
37
|
+
}, {
|
|
38
|
+
tag: tags.comment,
|
|
39
|
+
class: 'hl-comment',
|
|
40
|
+
}, {
|
|
41
|
+
tag: tags.lineComment,
|
|
42
|
+
class: 'hl-comment',
|
|
43
|
+
}, {
|
|
44
|
+
tag: tags.blockComment,
|
|
45
|
+
class: 'hl-comment',
|
|
46
|
+
}, {
|
|
47
|
+
tag: tags.variableName,
|
|
48
|
+
class: 'hl-name',
|
|
49
|
+
}, {
|
|
50
|
+
tag: tags.function(tags.variableName),
|
|
51
|
+
class: 'hl-function',
|
|
52
|
+
}, {
|
|
53
|
+
tag: tags.definition(tags.variableName),
|
|
54
|
+
class: 'hl-name',
|
|
55
|
+
}, {
|
|
56
|
+
tag: tags.propertyName,
|
|
57
|
+
class: 'hl-name',
|
|
58
|
+
}, {
|
|
59
|
+
tag: tags.className,
|
|
60
|
+
class: 'hl-class',
|
|
61
|
+
}, {
|
|
62
|
+
tag: tags.typeName,
|
|
63
|
+
class: 'hl-type',
|
|
64
|
+
}, {
|
|
65
|
+
tag: tags.operator,
|
|
66
|
+
class: 'hl-operator',
|
|
67
|
+
}, {
|
|
68
|
+
tag: tags.punctuation,
|
|
69
|
+
class: 'hl-punctuation',
|
|
70
|
+
}, {
|
|
71
|
+
tag: tags.regexp,
|
|
72
|
+
class: 'hl-regexp',
|
|
73
|
+
}, {
|
|
74
|
+
tag: tags.escape,
|
|
75
|
+
class: 'hl-escape',
|
|
76
|
+
}, {
|
|
77
|
+
tag: tags.tagName,
|
|
78
|
+
class: 'hl-tag',
|
|
79
|
+
}, {
|
|
80
|
+
tag: tags.attributeName,
|
|
81
|
+
class: 'hl-attr',
|
|
82
|
+
}]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {history, historyKeymap} from '@codemirror/commands';
|
|
2
|
+
import {keymap} from '@codemirror/view';
|
|
3
|
+
|
|
4
|
+
export function clearHistory(view, historyCompartment, vimEnabled) {
|
|
5
|
+
if (!view)
|
|
6
|
+
return;
|
|
7
|
+
|
|
8
|
+
view.dispatch({
|
|
9
|
+
effects: historyCompartment.reconfigure(vimEnabled ? [] : [
|
|
10
|
+
history(),
|
|
11
|
+
keymap.of(historyKeymap),
|
|
12
|
+
]),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createEditor,
|
|
3
|
+
type CreateEditorOptions,
|
|
4
|
+
type QwordEditorView,
|
|
5
|
+
} from './create.js';
|
|
6
|
+
export {
|
|
7
|
+
getValue,
|
|
8
|
+
setValue,
|
|
9
|
+
getDocValue,
|
|
10
|
+
setDocValue,
|
|
11
|
+
} from './content.js';
|
|
12
|
+
export {
|
|
13
|
+
offsetToPosition,
|
|
14
|
+
positionToOffset,
|
|
15
|
+
posFromIndex,
|
|
16
|
+
indexFromPos,
|
|
17
|
+
getCursorIndex,
|
|
18
|
+
getCursor,
|
|
19
|
+
} from './position.js';
|
|
20
|
+
export {
|
|
21
|
+
markField,
|
|
22
|
+
lineField,
|
|
23
|
+
markText,
|
|
24
|
+
addLineClass,
|
|
25
|
+
removeLineClass,
|
|
26
|
+
type MarkHandle,
|
|
27
|
+
} from './decorations.js';
|
|
28
|
+
export {
|
|
29
|
+
on,
|
|
30
|
+
off,
|
|
31
|
+
type EventBinding,
|
|
32
|
+
} from './events.js';
|
|
33
|
+
export {
|
|
34
|
+
getScrollInfo,
|
|
35
|
+
scrollTo,
|
|
36
|
+
type ScrollInfo,
|
|
37
|
+
} from './scroll.js';
|
|
38
|
+
export {
|
|
39
|
+
getView,
|
|
40
|
+
refresh,
|
|
41
|
+
observeResize,
|
|
42
|
+
} from './dom.js';
|
|
43
|
+
export {
|
|
44
|
+
keymapExtension,
|
|
45
|
+
themeExtension,
|
|
46
|
+
languageExtension,
|
|
47
|
+
setOption,
|
|
48
|
+
type OptionKey,
|
|
49
|
+
type OptionValue,
|
|
50
|
+
} from './options.js';
|
|
51
|
+
export {clearHistory} from './history.js';
|
|
52
|
+
export {highlightStyle} from './highlight.js';
|
|
53
|
+
export type {
|
|
54
|
+
SourceCode,
|
|
55
|
+
SourcePosition,
|
|
56
|
+
CharOffset,
|
|
57
|
+
EditorMode,
|
|
58
|
+
EditorTheme,
|
|
59
|
+
KeyMap,
|
|
60
|
+
} from './types.js';
|
package/client/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export {createEditor} from './create.js';
|
|
2
|
+
export {
|
|
3
|
+
getValue,
|
|
4
|
+
setValue,
|
|
5
|
+
getDocValue,
|
|
6
|
+
setDocValue,
|
|
7
|
+
} from './content.js';
|
|
8
|
+
export {
|
|
9
|
+
offsetToPosition,
|
|
10
|
+
positionToOffset,
|
|
11
|
+
posFromIndex,
|
|
12
|
+
indexFromPos,
|
|
13
|
+
getCursorIndex,
|
|
14
|
+
getCursor,
|
|
15
|
+
} from './position.js';
|
|
16
|
+
export {
|
|
17
|
+
markField,
|
|
18
|
+
lineField,
|
|
19
|
+
markText,
|
|
20
|
+
addLineClass,
|
|
21
|
+
removeLineClass,
|
|
22
|
+
} from './decorations.js';
|
|
23
|
+
export {on, off} from './events.js';
|
|
24
|
+
export {getScrollInfo, scrollTo} from './scroll.js';
|
|
25
|
+
export {
|
|
26
|
+
getView,
|
|
27
|
+
refresh,
|
|
28
|
+
observeResize,
|
|
29
|
+
} from './dom.js';
|
|
30
|
+
export {
|
|
31
|
+
keymapExtension,
|
|
32
|
+
themeExtension,
|
|
33
|
+
languageExtension,
|
|
34
|
+
indentKeymap,
|
|
35
|
+
setOption,
|
|
36
|
+
} from './options.js';
|
|
37
|
+
export {clearHistory} from './history.js';
|
|
38
|
+
export {highlightStyle} from './highlight.js';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import load from 'load.js';
|
|
2
|
+
import {tryToCatch} from 'try-to-catch';
|
|
3
|
+
import once from 'once';
|
|
4
|
+
|
|
5
|
+
const isString = (a) => typeof a === 'string';
|
|
6
|
+
|
|
7
|
+
export const loadModules = once(async (prefix) => {
|
|
8
|
+
const url = `${prefix}/modules.json`;
|
|
9
|
+
return await load.json(url);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const loadOptions = once(async (prefix) => {
|
|
13
|
+
const url = `${prefix}/options.json`;
|
|
14
|
+
return await load.json(url);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const on = async ({remote, local}) => {
|
|
18
|
+
const [error] = await tryToCatch(load.parallel, remote);
|
|
19
|
+
|
|
20
|
+
if (error)
|
|
21
|
+
await off(local);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const off = async function(local) {
|
|
25
|
+
await load.parallel(local);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default async (name, options = {}) => {
|
|
29
|
+
const o = options;
|
|
30
|
+
|
|
31
|
+
const {prefix = ''} = o;
|
|
32
|
+
|
|
33
|
+
if (o.name && global[o.name])
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
const promises = [
|
|
37
|
+
loadModules(prefix),
|
|
38
|
+
loadOptions(prefix),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const [error, [modules, config]] = await tryToCatch(Promise.all.bind(Promise), promises);
|
|
42
|
+
|
|
43
|
+
let remoteTmpls;
|
|
44
|
+
let local;
|
|
45
|
+
|
|
46
|
+
if (error)
|
|
47
|
+
return alert(`Error: could not load module or config: ${error.message}`);
|
|
48
|
+
|
|
49
|
+
const online = config.online && navigator.onLine;
|
|
50
|
+
const module = binom(name, modules);
|
|
51
|
+
const isArray = Array.isArray(module.local);
|
|
52
|
+
const {version} = module;
|
|
53
|
+
|
|
54
|
+
if (isArray) {
|
|
55
|
+
remoteTmpls = module.remote;
|
|
56
|
+
({local} = module);
|
|
57
|
+
} else {
|
|
58
|
+
remoteTmpls = [module.remote];
|
|
59
|
+
local = [module.local];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
local = [];
|
|
63
|
+
|
|
64
|
+
for (const url of local) {
|
|
65
|
+
local.push(prefix + url);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const remote = [];
|
|
69
|
+
|
|
70
|
+
for (const tmpl of remoteTmpls) {
|
|
71
|
+
remote.push(tmpl.replace(/{{\s*version\s*}}/g, version));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!online)
|
|
75
|
+
return await off(local);
|
|
76
|
+
|
|
77
|
+
await on({
|
|
78
|
+
remote,
|
|
79
|
+
local,
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function binom(name, array) {
|
|
84
|
+
let ret;
|
|
85
|
+
|
|
86
|
+
if (!isString(name))
|
|
87
|
+
throw Error('name should be string!');
|
|
88
|
+
|
|
89
|
+
if (!Array.isArray(array))
|
|
90
|
+
throw Error('array should be array!');
|
|
91
|
+
|
|
92
|
+
array.some((item) => {
|
|
93
|
+
const is = item.name === name;
|
|
94
|
+
|
|
95
|
+
if (is)
|
|
96
|
+
ret = item;
|
|
97
|
+
|
|
98
|
+
return is;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return ret;
|
|
102
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {type Extension} from '@codemirror/state';
|
|
2
|
+
import type {QwordEditorView} from './create.js';
|
|
3
|
+
import type {
|
|
4
|
+
KeyMap,
|
|
5
|
+
EditorMode,
|
|
6
|
+
EditorTheme,
|
|
7
|
+
} from './types.js';
|
|
8
|
+
|
|
9
|
+
export function keymapExtension(name: KeyMap): Extension;
|
|
10
|
+
|
|
11
|
+
export function themeExtension(name: EditorTheme): Extension;
|
|
12
|
+
|
|
13
|
+
export function languageExtension(mode: EditorMode | {
|
|
14
|
+
name: EditorMode;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
} | null): Extension;
|
|
17
|
+
|
|
18
|
+
export type OptionKey = 'theme' | 'keyMap' | 'mode';
|
|
19
|
+
|
|
20
|
+
export type OptionValue =
|
|
21
|
+
| EditorTheme
|
|
22
|
+
| KeyMap
|
|
23
|
+
| EditorMode
|
|
24
|
+
| {
|
|
25
|
+
name: EditorMode;
|
|
26
|
+
json?: boolean;
|
|
27
|
+
}
|
|
28
|
+
| null;
|
|
29
|
+
|
|
30
|
+
export function setOption(view: QwordEditorView, key: OptionKey, value: OptionValue): void;
|
|
31
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {keymap} from '@codemirror/view';
|
|
2
|
+
import {javascript} from '@codemirror/lang-javascript';
|
|
3
|
+
import {json} from '@codemirror/lang-json';
|
|
4
|
+
import {html} from '@codemirror/lang-html';
|
|
5
|
+
import {vim} from '@replit/codemirror-vim';
|
|
6
|
+
import {nord} from '@uiw/codemirror-theme-nord';
|
|
7
|
+
import {Prec} from '@codemirror/state';
|
|
8
|
+
import {
|
|
9
|
+
defaultKeymap,
|
|
10
|
+
emacsStyleKeymap,
|
|
11
|
+
indentWithTab,
|
|
12
|
+
insertNewlineKeepIndent,
|
|
13
|
+
} from '@codemirror/commands';
|
|
14
|
+
|
|
15
|
+
const enterKeepIndent = {
|
|
16
|
+
key: 'Enter',
|
|
17
|
+
run: insertNewlineKeepIndent,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function keymapExtension(name) {
|
|
21
|
+
if (name === 'vim')
|
|
22
|
+
return vim();
|
|
23
|
+
|
|
24
|
+
if (name === 'emacs')
|
|
25
|
+
return keymap.of([...emacsStyleKeymap, indentWithTab]);
|
|
26
|
+
|
|
27
|
+
return Prec.highest(keymap.of([enterKeepIndent, indentWithTab, ...defaultKeymap]));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function themeExtension(name) {
|
|
31
|
+
if (name === 'nord' || name === 'dark' || name === 'one-dark')
|
|
32
|
+
return nord;
|
|
33
|
+
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const indentKeymap = keymap.of([indentWithTab]);
|
|
38
|
+
|
|
39
|
+
export function languageExtension(mode) {
|
|
40
|
+
const name = typeof mode === 'object' ? mode?.name : mode;
|
|
41
|
+
|
|
42
|
+
if (name === 'javascript' || name === 'js')
|
|
43
|
+
return javascript();
|
|
44
|
+
|
|
45
|
+
if (name === 'json')
|
|
46
|
+
return json();
|
|
47
|
+
|
|
48
|
+
if (name === 'html')
|
|
49
|
+
return html();
|
|
50
|
+
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function setOption(view, key, value) {
|
|
55
|
+
if (key === 'theme')
|
|
56
|
+
return view.dispatch({
|
|
57
|
+
effects: view._themeCompartment.reconfigure(themeExtension(value)),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (key === 'keyMap')
|
|
61
|
+
return view.dispatch({
|
|
62
|
+
effects: view._keymapCompartment.reconfigure(keymapExtension(value)),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (key === 'mode')
|
|
66
|
+
return view.dispatch({
|
|
67
|
+
effects: view._langCompartment.reconfigure(languageExtension(value)),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type {Text} from '@codemirror/state';
|
|
2
|
+
import type {EditorView} from '@codemirror/view';
|
|
3
|
+
import type {CharOffset, SourcePosition} from './types.js';
|
|
4
|
+
|
|
5
|
+
export function offsetToPosition(document_: Text, offset: CharOffset): SourcePosition;
|
|
6
|
+
|
|
7
|
+
export function positionToOffset(document_: Text, {line, ch}: SourcePosition): CharOffset;
|
|
8
|
+
|
|
9
|
+
export function posFromIndex(view: EditorView, index: CharOffset): SourcePosition;
|
|
10
|
+
|
|
11
|
+
export function indexFromPos(view: EditorView, position: SourcePosition): CharOffset;
|
|
12
|
+
|
|
13
|
+
export function getCursor(view: EditorView): {
|
|
14
|
+
row: number;
|
|
15
|
+
column: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function getCursorIndex(view: EditorView): CharOffset;
|
|
19
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function offsetToPosition(document_, offset) {
|
|
2
|
+
const index = offset < 0 ? 0 : offset > document_.length ? document_.length : offset;
|
|
3
|
+
const line = document_.lineAt(index);
|
|
4
|
+
|
|
5
|
+
return {
|
|
6
|
+
line: line.number - 1,
|
|
7
|
+
ch: index - line.from,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function positionToOffset(document_, {line, ch}) {
|
|
12
|
+
return document_.line(line + 1).from + ch;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function posFromIndex(view, index) {
|
|
16
|
+
return offsetToPosition(view.state.doc, index);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function indexFromPos(view, position) {
|
|
20
|
+
return positionToOffset(view.state.doc, position);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getCursor(view) {
|
|
24
|
+
const index = getCursorIndex(view);
|
|
25
|
+
const position = offsetToPosition(view.state.doc, index);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
row: position.line,
|
|
29
|
+
column: position.ch,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const getCursorIndex = (view) => view.state.selection.main.head;
|