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/qword.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import '../css/qword.css';
|
|
2
|
+
import * as smalltalk from 'smalltalk';
|
|
3
|
+
import jssha from 'jssha';
|
|
4
|
+
import load from 'load.js';
|
|
5
|
+
import {createPatch} from 'daffy';
|
|
6
|
+
import * as restafary from 'restafary/client';
|
|
7
|
+
import {tryToCatch} from 'try-to-catch';
|
|
8
|
+
import {tryCatch} from 'try-catch';
|
|
9
|
+
import Editor from './editor.js';
|
|
10
|
+
import Story from './story.js';
|
|
11
|
+
import _clipboard from './_clipboard.js';
|
|
12
|
+
import save from './save.js';
|
|
13
|
+
import _initSocket from './_init-socket.js';
|
|
14
|
+
import _onSave from './_on-save.js';
|
|
15
|
+
import showMessage from './show-message.js';
|
|
16
|
+
import loadRemote, {loadModules, loadOptions} from './loadremote.js';
|
|
17
|
+
|
|
18
|
+
const isString = (a) => typeof a === 'string';
|
|
19
|
+
|
|
20
|
+
const noop = () => {};
|
|
21
|
+
|
|
22
|
+
export default function Qword(el, options, callback) {
|
|
23
|
+
if (isString(el))
|
|
24
|
+
el = document.querySelector(el);
|
|
25
|
+
|
|
26
|
+
return new MainQword(el, options, callback);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class MainQword extends Editor {
|
|
30
|
+
constructor(element, options = {}, callback = noop) {
|
|
31
|
+
super(element, options);
|
|
32
|
+
|
|
33
|
+
this._initSocket = _initSocket;
|
|
34
|
+
this._TITLE = 'Qword';
|
|
35
|
+
this._story = Story();
|
|
36
|
+
this._savedValue = '';
|
|
37
|
+
this._filename = '';
|
|
38
|
+
this._maxSize = options.maxSize || 512_000;
|
|
39
|
+
this._PREFIX = options.prefix || '/qword';
|
|
40
|
+
this._prefixSocket = options.prefixSocket || '/qword';
|
|
41
|
+
this._socketPath = options.socketPath || '';
|
|
42
|
+
|
|
43
|
+
restafary.prefix(`${this._PREFIX}/api/v1/fs`);
|
|
44
|
+
this
|
|
45
|
+
._init()
|
|
46
|
+
.then(() => callback(this));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async _init() {
|
|
50
|
+
const [error, config] = await tryToCatch(load.json, `${this._PREFIX}/edit.json`);
|
|
51
|
+
|
|
52
|
+
if (error)
|
|
53
|
+
return smalltalk.alert(this._TITLE, 'Could not load edit.json!');
|
|
54
|
+
|
|
55
|
+
this._Config = config;
|
|
56
|
+
|
|
57
|
+
await Promise.all([
|
|
58
|
+
loadOptions(this._PREFIX),
|
|
59
|
+
loadModules(this._PREFIX),
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
await loadRemote('socket', {
|
|
63
|
+
prefix: this._socketPath,
|
|
64
|
+
});
|
|
65
|
+
this._initSocket();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setValueFirst(name, value) {
|
|
69
|
+
this.setModeForPath(name);
|
|
70
|
+
this.setValue(value);
|
|
71
|
+
this._filename = name;
|
|
72
|
+
this._savedValue = value;
|
|
73
|
+
this.clearHistory();
|
|
74
|
+
this.moveCursorTo(0, 0);
|
|
75
|
+
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
sha() {
|
|
80
|
+
const sha = new jssha('SHA-1', 'TEXT');
|
|
81
|
+
sha.update(this.getValue());
|
|
82
|
+
|
|
83
|
+
return sha.getHash('HEX');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
evaluate() {
|
|
87
|
+
if (!this._filename?.endsWith('.js'))
|
|
88
|
+
return smalltalk.alert(this._TITLE, 'JS only');
|
|
89
|
+
|
|
90
|
+
const [error] = tryCatch(new Function(this.getValue()));
|
|
91
|
+
|
|
92
|
+
if (error)
|
|
93
|
+
smalltalk.alert(this._TITLE, error.message);
|
|
94
|
+
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
goToLine() {
|
|
99
|
+
const number = Number(prompt('Line number'));
|
|
100
|
+
|
|
101
|
+
if (!number)
|
|
102
|
+
return;
|
|
103
|
+
|
|
104
|
+
const line = this._view.state.doc.line(number);
|
|
105
|
+
|
|
106
|
+
this._view.dispatch({
|
|
107
|
+
selection: {
|
|
108
|
+
anchor: line.from,
|
|
109
|
+
},
|
|
110
|
+
scrollIntoView: true,
|
|
111
|
+
});
|
|
112
|
+
this.focus();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
remove(direction) {
|
|
116
|
+
const {state} = this._view;
|
|
117
|
+
const {from, to} = state.selection.main;
|
|
118
|
+
const isCollapsed = from === to;
|
|
119
|
+
|
|
120
|
+
if (direction === 'right') {
|
|
121
|
+
const end = isCollapsed ? to + 1 : to;
|
|
122
|
+
|
|
123
|
+
this._view.dispatch({
|
|
124
|
+
changes: {
|
|
125
|
+
from,
|
|
126
|
+
to: end,
|
|
127
|
+
insert: '',
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
const start = isCollapsed ? from - 1 : from;
|
|
132
|
+
|
|
133
|
+
if (start >= 0)
|
|
134
|
+
this._view.dispatch({
|
|
135
|
+
changes: {
|
|
136
|
+
from: start,
|
|
137
|
+
to,
|
|
138
|
+
insert: '',
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
selectAll() {
|
|
147
|
+
const {doc} = this._view.state;
|
|
148
|
+
|
|
149
|
+
this._view.dispatch({
|
|
150
|
+
selection: {
|
|
151
|
+
anchor: 0,
|
|
152
|
+
head: doc.length,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
enableKey() {
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
cutToClipboard() {
|
|
164
|
+
return this._clipboard('cut');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
copyToClipboard() {
|
|
168
|
+
return this._clipboard('copy');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
pasteFromClipboard() {
|
|
172
|
+
return this._clipboard('paste');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
_patchHttp(path, patch) {
|
|
176
|
+
restafary.patch(path, patch, this._onSave.bind(this));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_writeHttp(path, data) {
|
|
180
|
+
restafary.write(path, data, this._onSave.bind(this));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async _doDiff(path) {
|
|
184
|
+
const equal = await this
|
|
185
|
+
._story
|
|
186
|
+
.checkHash(path)
|
|
187
|
+
.catch(() => false);
|
|
188
|
+
|
|
189
|
+
return equal ? '' : createPatch(this._savedValue || '', this.getValue());
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
Qword.prototype._clipboard = _clipboard;
|
|
194
|
+
Qword.prototype.save = save;
|
|
195
|
+
Qword.prototype._onSave = _onSave;
|
|
196
|
+
Qword.prototype.showMessage = showMessage;
|
package/client/save.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import wraptile from 'wraptile';
|
|
2
|
+
import {promisify} from 'es6-promisify';
|
|
3
|
+
import _zipio from 'zipio';
|
|
4
|
+
|
|
5
|
+
const isString = (a) => typeof a === 'string';
|
|
6
|
+
const zipio = promisify(_zipio);
|
|
7
|
+
|
|
8
|
+
const setValue = wraptile(_setValue);
|
|
9
|
+
|
|
10
|
+
export default function() {
|
|
11
|
+
save
|
|
12
|
+
.call(this)
|
|
13
|
+
.then(setValue(this))
|
|
14
|
+
.catch(this._onSave.bind(this));
|
|
15
|
+
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function save() {
|
|
20
|
+
const value = this.getValue();
|
|
21
|
+
const {length} = value;
|
|
22
|
+
const {_FileName: _filename, _maxSize} = this;
|
|
23
|
+
|
|
24
|
+
const {diff, zip} = await this._loadOptions();
|
|
25
|
+
|
|
26
|
+
if (diff) {
|
|
27
|
+
const patch = await this._doDiff(_filename);
|
|
28
|
+
const isPatch = checkPatch(length, _maxSize, patch);
|
|
29
|
+
|
|
30
|
+
if (isPatch)
|
|
31
|
+
return this._patch(_filename, patch);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!zip)
|
|
35
|
+
return this._write(_filename, value);
|
|
36
|
+
|
|
37
|
+
const zippedValue = await zipio(value);
|
|
38
|
+
|
|
39
|
+
return this._write(`${_filename}?unzip`, zippedValue);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _setValue(ctx) {
|
|
43
|
+
ctx._Value = ctx.getValue();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function checkPatch(length, maxSize, patch) {
|
|
47
|
+
const patchLength = patch?.length || 0;
|
|
48
|
+
const isLessMaxLength = length < maxSize;
|
|
49
|
+
const isLessLength = isLessMaxLength && patchLength < length;
|
|
50
|
+
const isStr = isString(patch);
|
|
51
|
+
|
|
52
|
+
return patch && isStr && isLessLength;
|
|
53
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {EditorView} from '@codemirror/view';
|
|
2
|
+
|
|
3
|
+
export type ScrollInfo = {
|
|
4
|
+
left: number;
|
|
5
|
+
top: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const getScrollInfo: (view: EditorView) => ScrollInfo;
|
|
9
|
+
|
|
10
|
+
export function scrollTo(view: EditorView, left: number, top: number): void;
|
|
11
|
+
|
package/client/scroll.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import createElement from '@cloudcmd/create-element';
|
|
2
|
+
|
|
3
|
+
function createMsg() {
|
|
4
|
+
const innerHTML = '<div class="dword-msg">/div>';
|
|
5
|
+
const wrapper = createElement('div', {
|
|
6
|
+
innerHTML,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
return wrapper.firstChild;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default showMessage;
|
|
13
|
+
|
|
14
|
+
function showMessage(text) {
|
|
15
|
+
const HIDE_TIME = 2000;
|
|
16
|
+
|
|
17
|
+
if (!this._ElementMsg) {
|
|
18
|
+
this._ElementMsg = createMsg();
|
|
19
|
+
this._Element.appendChild(this._ElementMsg);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this._ElementMsg.textContent = text;
|
|
23
|
+
this._ElementMsg.hidden = false;
|
|
24
|
+
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
this._ElementMsg.hidden = true;
|
|
27
|
+
}, HIDE_TIME);
|
|
28
|
+
|
|
29
|
+
return this;
|
|
30
|
+
}
|
package/client/story.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {promisify} from 'es6-promisify';
|
|
2
|
+
import * as restafary from 'restafary/client';
|
|
3
|
+
|
|
4
|
+
export default Story;
|
|
5
|
+
|
|
6
|
+
function Story() {
|
|
7
|
+
if (!(this instanceof Story))
|
|
8
|
+
return new Story();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Story.prototype.checkHash = async function(name) {
|
|
12
|
+
const loadHash = await this.loadHash(name);
|
|
13
|
+
const nameHash = `${name}-hash`;
|
|
14
|
+
const storeHash = localStorage.getItem(nameHash);
|
|
15
|
+
|
|
16
|
+
return loadHash === storeHash;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Story.prototype.loadHash = promisify(function(name, callback) {
|
|
20
|
+
const query = '?hash';
|
|
21
|
+
|
|
22
|
+
restafary.read(name + query, callback);
|
|
23
|
+
|
|
24
|
+
return this;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
Story.prototype.setData = function(name, data) {
|
|
28
|
+
const nameData = `${name}-data`;
|
|
29
|
+
|
|
30
|
+
localStorage.setItem(nameData, data);
|
|
31
|
+
|
|
32
|
+
return this;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Story.prototype.setHash = function(name, hash) {
|
|
36
|
+
const nameHash = `${name}-hash`;
|
|
37
|
+
|
|
38
|
+
localStorage.setItem(nameHash, hash);
|
|
39
|
+
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Story.prototype.getData = function(name) {
|
|
44
|
+
const nameData = `${name}-data`;
|
|
45
|
+
const data = localStorage.getItem(nameData);
|
|
46
|
+
|
|
47
|
+
return data || '';
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Story.prototype.getHash = function(name) {
|
|
51
|
+
const item = `${name}-hash`;
|
|
52
|
+
const data = localStorage.getItem(item);
|
|
53
|
+
|
|
54
|
+
return data || '';
|
|
55
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Character offset into source text (0-indexed, matches CM6) — same convention as putout-editor's codemirror-adapter.
|
|
2
|
+
export type CharOffset = number;
|
|
3
|
+
|
|
4
|
+
// Line/column position — matches CodeMirror's {line, ch} convention.
|
|
5
|
+
export type SourcePosition = {
|
|
6
|
+
line: number;
|
|
7
|
+
ch: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// CodeMirror editor mode string — e.g. 'javascript', 'json', 'html'.
|
|
11
|
+
export type EditorMode = string;
|
|
12
|
+
|
|
13
|
+
// CodeMirror key map name.
|
|
14
|
+
export type KeyMap =
|
|
15
|
+
| 'vim'
|
|
16
|
+
| 'emacs'
|
|
17
|
+
| 'sublime'
|
|
18
|
+
| 'default';
|
|
19
|
+
|
|
20
|
+
// Editor theme name.
|
|
21
|
+
export type EditorTheme =
|
|
22
|
+
| 'nord'
|
|
23
|
+
| 'default'
|
|
24
|
+
| 'dark'
|
|
25
|
+
| 'one-dark';
|
|
26
|
+
|
|
27
|
+
// JavaScript/TypeScript source code.
|
|
28
|
+
export type SourceCode = string;
|