@dao42/d42paas-front 0.4.5 → 0.4.6
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/package.json +3 -2
- package/src/app.tsx +250 -0
- package/src/assets/code-brackets.svg +1 -0
- package/src/assets/colors.svg +1 -0
- package/src/assets/comments.svg +1 -0
- package/src/assets/direction.svg +1 -0
- package/src/assets/flow.svg +1 -0
- package/src/assets/plugin.svg +1 -0
- package/src/assets/repo.svg +1 -0
- package/src/assets/stackalt.svg +1 -0
- package/src/components/Avatar/index.tsx +27 -0
- package/src/components/CanvasHelper/index.tsx +89 -0
- package/src/components/Console/index.tsx +88 -0
- package/src/components/Editor/index.tsx +979 -0
- package/src/components/FileTree/index.tsx +477 -0
- package/src/components/LiveContent/index.tsx +221 -0
- package/src/components/LiveContent/video.tsx +213 -0
- package/src/components/LottieAnim/index.tsx +41 -0
- package/src/components/Message/index.tsx +64 -0
- package/src/components/Model/index.tsx +42 -0
- package/src/components/OutputBrowser/index.tsx +180 -0
- package/src/components/Skeleton/index.tsx +41 -0
- package/src/components/Tabs/index.tsx +23 -0
- package/src/components/Terminal/index.tsx +127 -0
- package/src/components/ToolBar/index.tsx +169 -0
- package/src/components/XTerm/index.tsx +113 -0
- package/src/components/index.tsx +4 -0
- package/src/components/loading/index.tsx +282 -0
- package/src/enum/FExtension.ts +168 -0
- package/src/helpers/collections/IoClient.tsx +314 -0
- package/src/helpers/collections/errorCatcher.tsx +0 -0
- package/src/helpers/collections/idb.tsx +186 -0
- package/src/helpers/collections/localStorage.tsx +13 -0
- package/src/helpers/collections/mock.tsx +30 -0
- package/src/helpers/collections/playgroundInit.tsx +311 -0
- package/src/helpers/collections/replay.tsx +168 -0
- package/src/helpers/collections/socket.tsx +6 -0
- package/src/helpers/collections/toast.tsx +19 -0
- package/src/helpers/collections/userTool.tsx +12 -0
- package/src/helpers/collections/util.tsx +4 -0
- package/src/helpers/index.tsx +6 -0
- package/src/helpers/monaco/monaco-ot-adapter.tsx +476 -0
- package/src/hooks/collections/useOT.tsx +38 -0
- package/src/hooks/index.tsx +1 -0
- package/src/pages/index.tsx +450 -0
- package/src/public/dev.html +35 -0
- package/src/public/index.html +45 -0
- package/src/public/sdkserver.html +35 -0
- package/src/stores/index.tsx +1 -0
- package/src/stores/oTStore.tsx +288 -0
- package/src/stories/BrowserWindow.tsx +30 -0
- package/src/stories/Console.tsx +46 -0
- package/src/stories/Editor.tsx +37 -0
- package/src/stories/FileTree.tsx +50 -0
- package/src/stories/Shell.tsx +53 -0
- package/src/stories/introduction.stories.mdx +193 -0
- package/src/stories/page.tsx +71 -0
- package/src/styles/collections/iconfont.scss +1 -0
- package/src/styles/collections/tabs-costumers.scss +20 -0
- package/src/styles/collections/tailwind.scss +3 -0
- package/src/styles/collections/tree-costumers.scss +53 -0
- package/src/styles/collections/utility.scss +10 -0
- package/src/styles/collections/xterm-costumers.scss +47 -0
- package/src/styles/index.scss +19 -0
- package/src/types/editor.d.ts +31 -0
- package/src/types/index.d.ts +158 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import * as ot from 'ot';
|
|
2
|
+
import * as monaco from 'monaco-editor';
|
|
3
|
+
|
|
4
|
+
class MonacoAdapter {
|
|
5
|
+
public myEditor: monaco.editor.IStandaloneCodeEditor;
|
|
6
|
+
|
|
7
|
+
constructor(MonacoEditor: monaco.editor.IStandaloneCodeEditor) {
|
|
8
|
+
// need to closure:
|
|
9
|
+
// content change event
|
|
10
|
+
// keyUp / keyDown events
|
|
11
|
+
// focus event
|
|
12
|
+
// blur event
|
|
13
|
+
// any cursour change event
|
|
14
|
+
this.myEditor = MonacoEditor;
|
|
15
|
+
this.myEditor.onDidChangeModelContent(this.onContentChange);
|
|
16
|
+
this.myEditor.onDidChangeCursorPosition(this.onCursorPositionChange);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
onContentChange(e: monaco.editor.IModelContentChangedEvent) {
|
|
20
|
+
console.log(`on model content change`, e);
|
|
21
|
+
// if (!this.ignoreNextChange) {
|
|
22
|
+
// const pair = CodeMirrorAdapter.operationFromCodeMirrorChanges(
|
|
23
|
+
// changes,
|
|
24
|
+
// this.cm,
|
|
25
|
+
// );
|
|
26
|
+
// this.trigger('change', pair[0], pair[1]);
|
|
27
|
+
// }
|
|
28
|
+
// if (this.selectionChanged) {
|
|
29
|
+
// this.trigger('selectionChange');
|
|
30
|
+
// }
|
|
31
|
+
// this.changeInProgress = false;
|
|
32
|
+
// this.ignoreNextChange = false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
onCursorPositionChange() {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const CodeMirrorAdapter = (function (global) {
|
|
39
|
+
'use strict';
|
|
40
|
+
|
|
41
|
+
const TextOperation = ot.TextOperation;
|
|
42
|
+
const Selection = ot.Selection;
|
|
43
|
+
|
|
44
|
+
// Bind a method to an object, so it doesn't matter whether you call
|
|
45
|
+
// object.method() directly or pass object.method as a reference to another
|
|
46
|
+
// function.
|
|
47
|
+
function bind(obj, method) {
|
|
48
|
+
const fn = obj[method];
|
|
49
|
+
obj[method] = function () {
|
|
50
|
+
fn.apply(obj, arguments);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function CodeMirrorAdapter(cm) {
|
|
55
|
+
this.cm = cm;
|
|
56
|
+
this.ignoreNextChange = false;
|
|
57
|
+
this.changeInProgress = false;
|
|
58
|
+
this.selectionChanged = false;
|
|
59
|
+
|
|
60
|
+
bind(this, 'onChanges');
|
|
61
|
+
bind(this, 'onChange');
|
|
62
|
+
bind(this, 'onCursorActivity');
|
|
63
|
+
bind(this, 'onFocus');
|
|
64
|
+
bind(this, 'onBlur');
|
|
65
|
+
|
|
66
|
+
cm.on('changes', this.onChanges);
|
|
67
|
+
cm.on('change', this.onChange);
|
|
68
|
+
cm.on('cursorActivity', this.onCursorActivity);
|
|
69
|
+
cm.on('focus', this.onFocus);
|
|
70
|
+
cm.on('blur', this.onBlur);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Removes all event listeners from the CodeMirror instance.
|
|
74
|
+
CodeMirrorAdapter.prototype.detach = function () {
|
|
75
|
+
this.cm.off('changes', this.onChanges);
|
|
76
|
+
this.cm.off('change', this.onChange);
|
|
77
|
+
this.cm.off('cursorActivity', this.onCursorActivity);
|
|
78
|
+
this.cm.off('focus', this.onFocus);
|
|
79
|
+
this.cm.off('blur', this.onBlur);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function cmpPos(a, b) {
|
|
83
|
+
if (a.line < b.line) {
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
if (a.line > b.line) {
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
if (a.ch < b.ch) {
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
if (a.ch > b.ch) {
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
function posEq(a, b) {
|
|
98
|
+
return cmpPos(a, b) === 0;
|
|
99
|
+
}
|
|
100
|
+
function posLe(a, b) {
|
|
101
|
+
return cmpPos(a, b) <= 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function minPos(a, b) {
|
|
105
|
+
return posLe(a, b) ? a : b;
|
|
106
|
+
}
|
|
107
|
+
function maxPos(a, b) {
|
|
108
|
+
return posLe(a, b) ? b : a;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function codemirrorDocLength(doc) {
|
|
112
|
+
return (
|
|
113
|
+
doc.indexFromPos({ line: doc.lastLine(), ch: 0 }) +
|
|
114
|
+
doc.getLine(doc.lastLine()).length
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Converts a CodeMirror change array (as obtained from the 'changes' event
|
|
119
|
+
// in CodeMirror v4) or single change or linked list of changes (as returned
|
|
120
|
+
// by the 'change' event in CodeMirror prior to version 4) into a
|
|
121
|
+
// TextOperation and its inverse and returns them as a two-element array.
|
|
122
|
+
CodeMirrorAdapter.operationFromCodeMirrorChanges = function (changes, doc) {
|
|
123
|
+
// Approach: Replay the changes, beginning with the most recent one, and
|
|
124
|
+
// construct the operation and its inverse. We have to convert the position
|
|
125
|
+
// in the pre-change coordinate system to an index. We have a method to
|
|
126
|
+
// convert a position in the coordinate system after all changes to an index,
|
|
127
|
+
// namely CodeMirror's `indexFromPos` method. We can use the information of
|
|
128
|
+
// a single change object to convert a post-change coordinate system to a
|
|
129
|
+
// pre-change coordinate system. We can now proceed inductively to get a
|
|
130
|
+
// pre-change coordinate system for all changes in the linked list.
|
|
131
|
+
// A disadvantage of this approach is its complexity `O(n^2)` in the length
|
|
132
|
+
// of the linked list of changes.
|
|
133
|
+
|
|
134
|
+
let docEndLength = codemirrorDocLength(doc);
|
|
135
|
+
let operation = new TextOperation().retain(docEndLength);
|
|
136
|
+
let inverse = new TextOperation().retain(docEndLength);
|
|
137
|
+
|
|
138
|
+
let indexFromPos = function (pos) {
|
|
139
|
+
return doc.indexFromPos(pos);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
function last(arr) {
|
|
143
|
+
return arr[arr.length - 1];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sumLengths(strArr) {
|
|
147
|
+
if (strArr.length === 0) {
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
let sum = 0;
|
|
151
|
+
for (let i = 0; i < strArr.length; i++) {
|
|
152
|
+
sum += strArr[i].length;
|
|
153
|
+
}
|
|
154
|
+
return sum + strArr.length - 1;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function updateIndexFromPos(indexFromPos, change) {
|
|
158
|
+
return function (pos) {
|
|
159
|
+
if (posLe(pos, change.from)) {
|
|
160
|
+
return indexFromPos(pos);
|
|
161
|
+
}
|
|
162
|
+
if (posLe(change.to, pos)) {
|
|
163
|
+
return (
|
|
164
|
+
indexFromPos({
|
|
165
|
+
line:
|
|
166
|
+
pos.line +
|
|
167
|
+
change.text.length -
|
|
168
|
+
1 -
|
|
169
|
+
(change.to.line - change.from.line),
|
|
170
|
+
ch:
|
|
171
|
+
change.to.line < pos.line
|
|
172
|
+
? pos.ch
|
|
173
|
+
: change.text.length <= 1
|
|
174
|
+
? pos.ch -
|
|
175
|
+
(change.to.ch - change.from.ch) +
|
|
176
|
+
sumLengths(change.text)
|
|
177
|
+
: pos.ch - change.to.ch + last(change.text).length,
|
|
178
|
+
}) +
|
|
179
|
+
sumLengths(change.removed) -
|
|
180
|
+
sumLengths(change.text)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (change.from.line === pos.line) {
|
|
184
|
+
return indexFromPos(change.from) + pos.ch - change.from.ch;
|
|
185
|
+
}
|
|
186
|
+
return (
|
|
187
|
+
indexFromPos(change.from) +
|
|
188
|
+
sumLengths(change.removed.slice(0, pos.line - change.from.line)) +
|
|
189
|
+
1 +
|
|
190
|
+
pos.ch
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (let i = changes.length - 1; i >= 0; i--) {
|
|
196
|
+
const change = changes[i];
|
|
197
|
+
indexFromPos = updateIndexFromPos(indexFromPos, change);
|
|
198
|
+
|
|
199
|
+
const fromIndex = indexFromPos(change.from);
|
|
200
|
+
const restLength = docEndLength - fromIndex - sumLengths(change.text);
|
|
201
|
+
|
|
202
|
+
operation = new TextOperation()
|
|
203
|
+
.retain(fromIndex)
|
|
204
|
+
['delete'](sumLengths(change.removed))
|
|
205
|
+
.insert(change.text.join('\n'))
|
|
206
|
+
.retain(restLength)
|
|
207
|
+
.compose(operation);
|
|
208
|
+
|
|
209
|
+
inverse = inverse.compose(
|
|
210
|
+
new TextOperation()
|
|
211
|
+
.retain(fromIndex)
|
|
212
|
+
['delete'](sumLengths(change.text))
|
|
213
|
+
.insert(change.removed.join('\n'))
|
|
214
|
+
.retain(restLength),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
docEndLength += sumLengths(change.removed) - sumLengths(change.text);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return [operation, inverse];
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// Singular form for backwards compatibility.
|
|
224
|
+
CodeMirrorAdapter.operationFromCodeMirrorChange =
|
|
225
|
+
CodeMirrorAdapter.operationFromCodeMirrorChanges;
|
|
226
|
+
|
|
227
|
+
// Apply an operation to a CodeMirror instance.
|
|
228
|
+
CodeMirrorAdapter.applyOperationToCodeMirror = function (
|
|
229
|
+
operation,
|
|
230
|
+
cm,
|
|
231
|
+
focusFlag,
|
|
232
|
+
) {
|
|
233
|
+
return cm.operation(function () {
|
|
234
|
+
let lastUpdatedLine = null;
|
|
235
|
+
const ops = operation.ops;
|
|
236
|
+
let index = 0; // holds the current index into CodeMirror's content
|
|
237
|
+
for (let i = 0, l = ops.length; i < l; i++) {
|
|
238
|
+
const op = ops[i];
|
|
239
|
+
let line = 0;
|
|
240
|
+
if (TextOperation.isRetain(op)) {
|
|
241
|
+
index += op;
|
|
242
|
+
continue;
|
|
243
|
+
} else if (TextOperation.isInsert(op)) {
|
|
244
|
+
cm.replaceRange(op, cm.posFromIndex(index));
|
|
245
|
+
line = cm.posFromIndex(index).line;
|
|
246
|
+
index += op.length;
|
|
247
|
+
} else if (TextOperation.isDelete(op)) {
|
|
248
|
+
const from = cm.posFromIndex(index);
|
|
249
|
+
const to = cm.posFromIndex(index - op);
|
|
250
|
+
line = from.line;
|
|
251
|
+
cm.replaceRange('', from, to);
|
|
252
|
+
}
|
|
253
|
+
if (focusFlag) {
|
|
254
|
+
cm.scrollIntoView({ line: line, ch: 0 }, 200);
|
|
255
|
+
}
|
|
256
|
+
lastUpdatedLine = line;
|
|
257
|
+
}
|
|
258
|
+
return lastUpdatedLine;
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
CodeMirrorAdapter.prototype.registerCallbacks = function (cb) {
|
|
263
|
+
this.callbacks = cb;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
CodeMirrorAdapter.prototype.onChange = function () {
|
|
267
|
+
// By default, CodeMirror's event order is the following:
|
|
268
|
+
// 1. 'change', 2. 'cursorActivity', 3. 'changes'.
|
|
269
|
+
// We want to fire the 'selectionChange' event after the 'change' event,
|
|
270
|
+
// but need the information from the 'changes' event. Therefore, we detect
|
|
271
|
+
// when a change is in progress by listening to the change event, setting
|
|
272
|
+
// a flag that makes this adapter defer all 'cursorActivity' events.
|
|
273
|
+
this.changeInProgress = true;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
CodeMirrorAdapter.prototype.onChanges = function (_, changes) {
|
|
277
|
+
if (!this.ignoreNextChange) {
|
|
278
|
+
const pair = CodeMirrorAdapter.operationFromCodeMirrorChanges(
|
|
279
|
+
changes,
|
|
280
|
+
this.cm,
|
|
281
|
+
);
|
|
282
|
+
this.trigger('change', pair[0], pair[1]);
|
|
283
|
+
}
|
|
284
|
+
if (this.selectionChanged) {
|
|
285
|
+
this.trigger('selectionChange');
|
|
286
|
+
}
|
|
287
|
+
this.changeInProgress = false;
|
|
288
|
+
this.ignoreNextChange = false;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
CodeMirrorAdapter.prototype.onCursorActivity =
|
|
292
|
+
CodeMirrorAdapter.prototype.onFocus = function () {
|
|
293
|
+
if (this.changeInProgress) {
|
|
294
|
+
this.selectionChanged = true;
|
|
295
|
+
} else {
|
|
296
|
+
this.trigger('selectionChange');
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
CodeMirrorAdapter.prototype.onBlur = function () {
|
|
301
|
+
if (!this.cm.somethingSelected()) {
|
|
302
|
+
this.trigger('blur');
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
CodeMirrorAdapter.prototype.getValue = function () {
|
|
307
|
+
return this.cm.getValue();
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
CodeMirrorAdapter.prototype.getSelection = function () {
|
|
311
|
+
const cm = this.cm;
|
|
312
|
+
|
|
313
|
+
const selectionList = cm.listSelections();
|
|
314
|
+
const ranges = [];
|
|
315
|
+
for (let i = 0; i < selectionList.length; i++) {
|
|
316
|
+
ranges[i] = new Selection.Range(
|
|
317
|
+
cm.indexFromPos(selectionList[i].anchor),
|
|
318
|
+
cm.indexFromPos(selectionList[i].head),
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return new Selection();
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
CodeMirrorAdapter.prototype.setSelection = function (selection) {
|
|
326
|
+
const ranges = [];
|
|
327
|
+
for (let i = 0; i < selection.ranges.length; i++) {
|
|
328
|
+
const range = selection.ranges[i];
|
|
329
|
+
ranges[i] = {
|
|
330
|
+
anchor: this.cm.posFromIndex(range.anchor),
|
|
331
|
+
head: this.cm.posFromIndex(range.head),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
this.cm.setSelections(ranges);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const addStyleRule = (function () {
|
|
338
|
+
const added = {};
|
|
339
|
+
const styleElement = document.createElement('style');
|
|
340
|
+
document.documentElement
|
|
341
|
+
.getElementsByTagName('head')[0]
|
|
342
|
+
.appendChild(styleElement);
|
|
343
|
+
const styleSheet = styleElement.sheet;
|
|
344
|
+
|
|
345
|
+
return function (css) {
|
|
346
|
+
if (added[css]) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
added[css] = true;
|
|
350
|
+
styleSheet.insertRule(
|
|
351
|
+
css,
|
|
352
|
+
(styleSheet.cssRules || styleSheet.rules).length,
|
|
353
|
+
);
|
|
354
|
+
};
|
|
355
|
+
})();
|
|
356
|
+
|
|
357
|
+
CodeMirrorAdapter.prototype.setOtherCursor = function (
|
|
358
|
+
position,
|
|
359
|
+
color,
|
|
360
|
+
clientId,
|
|
361
|
+
) {
|
|
362
|
+
const cursorPos = this.cm.posFromIndex(position);
|
|
363
|
+
const cursorCoords = this.cm.cursorCoords(cursorPos);
|
|
364
|
+
const cursorEl = document.createElement('span');
|
|
365
|
+
cursorEl.className = 'other-client';
|
|
366
|
+
cursorEl.style.borderLeftColor = color;
|
|
367
|
+
cursorEl.setAttribute('data-clientid', clientId);
|
|
368
|
+
return this.cm.setBookmark(cursorPos, {
|
|
369
|
+
widget: cursorEl,
|
|
370
|
+
insertLeft: true,
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
CodeMirrorAdapter.prototype.setOtherSelectionRange = function (
|
|
375
|
+
range,
|
|
376
|
+
color,
|
|
377
|
+
clientId,
|
|
378
|
+
) {
|
|
379
|
+
const match = /^#([0-9a-fA-F]{6})$/.exec(color);
|
|
380
|
+
if (!match) {
|
|
381
|
+
throw new Error('only six-digit hex colors are allowed.');
|
|
382
|
+
}
|
|
383
|
+
const selectionClassName = 'selection-' + match[1];
|
|
384
|
+
const rule = '.' + selectionClassName + ' { background: ' + color + '; }';
|
|
385
|
+
addStyleRule(rule);
|
|
386
|
+
|
|
387
|
+
const anchorPos = this.cm.posFromIndex(range.anchor);
|
|
388
|
+
const headPos = this.cm.posFromIndex(range.head);
|
|
389
|
+
|
|
390
|
+
return this.cm.markText(
|
|
391
|
+
minPos(anchorPos, headPos),
|
|
392
|
+
maxPos(anchorPos, headPos),
|
|
393
|
+
{ className: selectionClassName },
|
|
394
|
+
);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
CodeMirrorAdapter.prototype.setOtherSelection = function (
|
|
398
|
+
selection,
|
|
399
|
+
color,
|
|
400
|
+
clientId,
|
|
401
|
+
) {
|
|
402
|
+
const selectionObjects = [];
|
|
403
|
+
for (let i = 0; i < selection.ranges.length; i++) {
|
|
404
|
+
const range = selection.ranges[i];
|
|
405
|
+
if (range.isEmpty()) {
|
|
406
|
+
selectionObjects[i] = this.setOtherCursor(range.head, color, clientId);
|
|
407
|
+
} else {
|
|
408
|
+
selectionObjects[i] = this.setOtherSelectionRange(
|
|
409
|
+
range,
|
|
410
|
+
color,
|
|
411
|
+
clientId,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
clear: function () {
|
|
417
|
+
for (let i = 0; i < selectionObjects.length; i++) {
|
|
418
|
+
selectionObjects[i].clear();
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
CodeMirrorAdapter.prototype.isSelectionAtEnd = function (selection) {
|
|
425
|
+
if (selection.ranges.length > 1) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const range = selection.ranges[0];
|
|
430
|
+
if (!range.isEmpty()) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (range.head < this.cm.getValue().length) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return true;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
CodeMirrorAdapter.prototype.trigger = function (event) {
|
|
442
|
+
const args = Array.prototype.slice.call(arguments, 1);
|
|
443
|
+
const action = this.callbacks && this.callbacks[event];
|
|
444
|
+
if (action) {
|
|
445
|
+
action.apply(this, args);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
CodeMirrorAdapter.prototype.applyOperation = function (operation, focusFlag) {
|
|
450
|
+
this.ignoreNextChange = true;
|
|
451
|
+
return CodeMirrorAdapter.applyOperationToCodeMirror(
|
|
452
|
+
operation,
|
|
453
|
+
this.cm,
|
|
454
|
+
focusFlag,
|
|
455
|
+
);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
CodeMirrorAdapter.prototype.registerUndo = function (undoFn) {
|
|
459
|
+
this.cm.undo = undoFn;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
CodeMirrorAdapter.prototype.registerRedo = function (redoFn) {
|
|
463
|
+
this.cm.redo = redoFn;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// Throws an error if the first argument is falsy. Useful for debugging.
|
|
467
|
+
function assert(b, msg) {
|
|
468
|
+
if (!b) {
|
|
469
|
+
throw new Error(msg || 'assertion error');
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return CodeMirrorAdapter;
|
|
474
|
+
})(this);
|
|
475
|
+
|
|
476
|
+
export { MonacoAdapter };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { io } from 'socket.io-client';
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { oTStore } from '~/stores';
|
|
4
|
+
import { userStore } from '~/stores/oTStore';
|
|
5
|
+
|
|
6
|
+
const [host, port] = [
|
|
7
|
+
process.env.LOCAL_IP_HOST,
|
|
8
|
+
process.env.SOCKET_INSTANCE_CLIENT_PORT,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
// const SOCKET_INSTANCE = `${host}:${port}`;
|
|
12
|
+
// console.log(process.env.NODE_ENV);
|
|
13
|
+
const SOCKET_INSTANCE =
|
|
14
|
+
process.env.NODE_ENV === 'production' ? '' : `${host}:4001`;
|
|
15
|
+
|
|
16
|
+
type UseSocketType = {
|
|
17
|
+
socket: D42_FrontType.SocketType['Socket'];
|
|
18
|
+
setSocket: (arg: D42_FrontType.SocketType['Socket']) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Socket Store Logic Center
|
|
22
|
+
export const useOT = create<UseSocketType>((set) => ({
|
|
23
|
+
socket: null,
|
|
24
|
+
setSocket: (arg) => set(() => ({ socket: arg })),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export class sockerIO {
|
|
28
|
+
constructor(obj) {
|
|
29
|
+
// return io(SOCKET_INSTANCE || obj.ioPath, {
|
|
30
|
+
return io(SOCKET_INSTANCE || obj.ioPath, {
|
|
31
|
+
transports: ['websocket'],
|
|
32
|
+
auth: {
|
|
33
|
+
...obj,
|
|
34
|
+
uuid: obj.userId,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useOT } from './collections/useOT';
|