@dao42/d42paas-front 0.4.1 → 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.
Files changed (156) hide show
  1. package/dist/1569.js +1 -1
  2. package/dist/1585.js +1 -1
  3. package/dist/1593.js +1 -1
  4. package/dist/1594.js +1 -1
  5. package/dist/162.js +1 -1
  6. package/dist/1649.js +1 -1
  7. package/dist/1742.js +1 -1
  8. package/dist/1941.js +1 -1
  9. package/dist/2014.js +1 -1
  10. package/dist/2088.js +1 -1
  11. package/dist/2235.js +3 -3
  12. package/dist/2271.js +1 -1
  13. package/dist/2287.js +3 -3
  14. package/dist/2388.js +1 -1
  15. package/dist/2583.js +1 -1
  16. package/dist/2862.js +1 -1
  17. package/dist/2906.js +1 -1
  18. package/dist/300.js +1 -1
  19. package/dist/3008.js +1 -1
  20. package/dist/317.js +1 -1
  21. package/dist/3315.js +1 -1
  22. package/dist/3399.js +1 -1
  23. package/dist/3504.js +1 -1
  24. package/dist/3553.js +2 -2
  25. package/dist/3673.js +1 -1
  26. package/dist/3780.js +1 -1
  27. package/dist/3855.js +1 -1
  28. package/dist/4035.js +1 -1
  29. package/dist/4073.js +1 -1
  30. package/dist/4246.js +1 -1
  31. package/dist/4366.js +1 -1
  32. package/dist/4369.js +1 -1
  33. package/dist/4454.js +1 -1
  34. package/dist/4511.js +2 -2
  35. package/dist/4558.js +1 -1
  36. package/dist/4610.js +1 -1
  37. package/dist/471.js +1 -1
  38. package/dist/4858.js +1 -1
  39. package/dist/4896.js +1 -1
  40. package/dist/491.js +1 -1
  41. package/dist/5257.js +1 -1
  42. package/dist/5454.js +1 -1
  43. package/dist/5524.js +1 -1
  44. package/dist/5669.js +2 -2
  45. package/dist/5881.js +1 -1
  46. package/dist/5900.js +2 -2
  47. package/dist/5924.js +1 -1
  48. package/dist/5925.js +1 -1
  49. package/dist/5972.js +1 -1
  50. package/dist/5974.js +1 -1
  51. package/dist/6022.js +2 -2
  52. package/dist/6120.js +1 -1
  53. package/dist/615.js +1 -1
  54. package/dist/6162.js +1 -1
  55. package/dist/6175.js +1 -1
  56. package/dist/622.js +1 -1
  57. package/dist/6223.js +1 -1
  58. package/dist/6330.js +1 -1
  59. package/dist/6331.js +1 -1
  60. package/dist/6354.js +2 -2
  61. package/dist/6751.js +2 -2
  62. package/dist/6792.js +1 -1
  63. package/dist/6844.js +1 -1
  64. package/dist/7125.js +1 -1
  65. package/dist/7127.js +1 -1
  66. package/dist/7135.js +2 -2
  67. package/dist/7148.js +1 -1
  68. package/dist/7447.js +1 -1
  69. package/dist/7453.js +2 -2
  70. package/dist/7483.js +1 -1
  71. package/dist/7604.js +1 -1
  72. package/dist/7971.js +1 -1
  73. package/dist/8147.js +1 -1
  74. package/dist/8308.js +1 -1
  75. package/dist/8309.js +1 -1
  76. package/dist/8327.js +1 -1
  77. package/dist/849.js +1 -1
  78. package/dist/8677.js +1 -1
  79. package/dist/868.js +1 -1
  80. package/dist/8947.js +1 -1
  81. package/dist/930.js +1 -1
  82. package/dist/9342.js +2 -2
  83. package/dist/9482.js +1 -1
  84. package/dist/9538.js +1 -1
  85. package/dist/9741.js +2 -2
  86. package/dist/9909.js +1 -1
  87. package/dist/9953.js +2 -2
  88. package/dist/daoPaaS.js +3 -3
  89. package/dist/index.d.ts +31 -31
  90. package/dist/index.html +16 -16
  91. package/package.json +163 -161
  92. package/src/app.tsx +250 -0
  93. package/src/assets/code-brackets.svg +1 -0
  94. package/src/assets/colors.svg +1 -0
  95. package/src/assets/comments.svg +1 -0
  96. package/src/assets/direction.svg +1 -0
  97. package/src/assets/flow.svg +1 -0
  98. package/src/assets/plugin.svg +1 -0
  99. package/src/assets/repo.svg +1 -0
  100. package/src/assets/stackalt.svg +1 -0
  101. package/src/components/Avatar/index.tsx +27 -0
  102. package/src/components/CanvasHelper/index.tsx +89 -0
  103. package/src/components/Console/index.tsx +88 -0
  104. package/src/components/Editor/index.tsx +979 -0
  105. package/src/components/FileTree/index.tsx +477 -0
  106. package/src/components/LiveContent/index.tsx +221 -0
  107. package/src/components/LiveContent/video.tsx +213 -0
  108. package/src/components/LottieAnim/index.tsx +41 -0
  109. package/src/components/Message/index.tsx +64 -0
  110. package/src/components/Model/index.tsx +42 -0
  111. package/src/components/OutputBrowser/index.tsx +180 -0
  112. package/src/components/Skeleton/index.tsx +41 -0
  113. package/src/components/Tabs/index.tsx +23 -0
  114. package/src/components/Terminal/index.tsx +127 -0
  115. package/src/components/ToolBar/index.tsx +169 -0
  116. package/src/components/XTerm/index.tsx +113 -0
  117. package/src/components/index.tsx +4 -0
  118. package/src/components/loading/index.tsx +282 -0
  119. package/src/enum/FExtension.ts +168 -0
  120. package/src/helpers/collections/IoClient.tsx +314 -0
  121. package/src/helpers/collections/errorCatcher.tsx +0 -0
  122. package/src/helpers/collections/idb.tsx +186 -0
  123. package/src/helpers/collections/localStorage.tsx +13 -0
  124. package/src/helpers/collections/mock.tsx +30 -0
  125. package/src/helpers/collections/playgroundInit.tsx +311 -0
  126. package/src/helpers/collections/replay.tsx +168 -0
  127. package/src/helpers/collections/socket.tsx +6 -0
  128. package/src/helpers/collections/toast.tsx +19 -0
  129. package/src/helpers/collections/userTool.tsx +12 -0
  130. package/src/helpers/collections/util.tsx +4 -0
  131. package/src/helpers/index.tsx +6 -0
  132. package/src/helpers/monaco/monaco-ot-adapter.tsx +476 -0
  133. package/src/hooks/collections/useOT.tsx +38 -0
  134. package/src/hooks/index.tsx +1 -0
  135. package/src/pages/index.tsx +450 -0
  136. package/src/public/dev.html +35 -0
  137. package/src/public/index.html +45 -0
  138. package/src/public/sdkserver.html +35 -0
  139. package/src/stores/index.tsx +1 -0
  140. package/src/stores/oTStore.tsx +288 -0
  141. package/src/stories/BrowserWindow.tsx +30 -0
  142. package/src/stories/Console.tsx +46 -0
  143. package/src/stories/Editor.tsx +37 -0
  144. package/src/stories/FileTree.tsx +50 -0
  145. package/src/stories/Shell.tsx +53 -0
  146. package/src/stories/introduction.stories.mdx +193 -0
  147. package/src/stories/page.tsx +71 -0
  148. package/src/styles/collections/iconfont.scss +1 -0
  149. package/src/styles/collections/tabs-costumers.scss +20 -0
  150. package/src/styles/collections/tailwind.scss +3 -0
  151. package/src/styles/collections/tree-costumers.scss +53 -0
  152. package/src/styles/collections/utility.scss +10 -0
  153. package/src/styles/collections/xterm-costumers.scss +47 -0
  154. package/src/styles/index.scss +19 -0
  155. package/src/types/editor.d.ts +31 -0
  156. package/src/types/index.d.ts +158 -0
@@ -0,0 +1,168 @@
1
+ export enum FExtension {
2
+ erb = 'erb',
3
+ ru = 'ruby',
4
+ ejs = 'html',
5
+ json = 'json',
6
+ abap = 'abap',
7
+ cls = 'apex',
8
+ azcli = 'azcli',
9
+ bat = 'bat',
10
+ cmd = 'bat',
11
+ c = 'c',
12
+ h = 'c',
13
+ mligo = 'cameligo',
14
+ clj = 'clojure',
15
+ cljs = 'clojure',
16
+ cljc = 'clojure',
17
+ edn = 'clojure',
18
+ coffee = 'coffeescript',
19
+ cpp = 'cpp',
20
+ cc = 'cpp',
21
+ cxx = 'cpp',
22
+ hpp = 'cpp',
23
+ hh = 'cpp',
24
+ hxx = 'cpp',
25
+ cs = 'csharp',
26
+ csx = 'csharp',
27
+ cake = 'csharp',
28
+ css = 'css',
29
+ dart = 'dart',
30
+ dockerfile = 'dockerfile',
31
+ ecl = 'ecl',
32
+ fs = 'fsharp',
33
+ fsi = 'fsharp',
34
+ ml = 'fsharp',
35
+ mli = 'fsharp',
36
+ fsx = 'fsharp',
37
+ fsscript = 'fsharp',
38
+ go = 'go',
39
+ graphql = 'graphql',
40
+ gql = 'graphql',
41
+ handlebars = 'handlebars',
42
+ hbs = 'handlebars',
43
+ tf = 'hcl',
44
+ tfvars = 'hcl',
45
+ hcl = 'hcl',
46
+ html = 'html',
47
+ htm = 'html',
48
+ shtml = 'html',
49
+ xhtml = 'html',
50
+ mdoc = 'html',
51
+ jsp = 'html',
52
+ asp = 'html',
53
+ aspx = 'html',
54
+ jshtm = 'html',
55
+ ini = 'ini',
56
+ properties = 'ini',
57
+ gitconfig = 'ini',
58
+ java = 'java',
59
+ jav = 'java',
60
+ js = 'javascript',
61
+ es6 = 'javascript',
62
+ jsx = 'javascript',
63
+ mjs = 'javascript',
64
+ jl = 'julia',
65
+ kt = 'kotlin',
66
+ less = 'less',
67
+ lex = 'lexon',
68
+ lua = 'lua',
69
+ m3 = 'm3',
70
+ i3 = 'm3',
71
+ mg = 'm3',
72
+ ig = 'm3',
73
+ md = 'markdown',
74
+ markdown = 'markdown',
75
+ mdown = 'markdown',
76
+ mkdn = 'markdown',
77
+ mkd = 'markdown',
78
+ mdwn = 'markdown',
79
+ mdtxt = 'markdown',
80
+ mdtext = 'markdown',
81
+ s = 'mips',
82
+ dax = 'msdax',
83
+ msdax = 'msdax',
84
+ m = 'c',
85
+ pas = 'pascal',
86
+ p = 'pascal',
87
+ pp = 'pascal',
88
+ ligo = 'pascaligo',
89
+ pl = 'perl',
90
+ php = 'php',
91
+ php4 = 'php',
92
+ php5 = 'php',
93
+ phtml = 'php',
94
+ ctp = 'php',
95
+ dats = 'postiats',
96
+ sats = 'postiats',
97
+ hats = 'postiats',
98
+ pq = 'powerquery',
99
+ pqm = 'powerquery',
100
+ ps1 = 'powershell',
101
+ psm1 = 'powershell',
102
+ psd1 = 'powershell',
103
+ jade = 'pug',
104
+ pug = 'pug',
105
+ py = 'python',
106
+ rpy = 'python',
107
+ pyw = 'python',
108
+ cpy = 'python',
109
+ gyp = 'python',
110
+ gypi = 'python',
111
+ r = 'r',
112
+ rhistory = 'r',
113
+ rmd = 'r',
114
+ rprofile = 'r',
115
+ rt = 'r',
116
+ cshtml = 'razor',
117
+ redis = 'redis',
118
+ rst = 'restructuredtext',
119
+ rb = 'ruby',
120
+ rbx = 'ruby',
121
+ rjs = 'ruby',
122
+ gemspec = 'ruby',
123
+ rs = 'rust',
124
+ rlib = 'rust',
125
+ sb = 'sb',
126
+ scala = 'scala',
127
+ sc = 'scala',
128
+ sbt = 'scala',
129
+ scm = 'scheme',
130
+ ss = 'scheme',
131
+ sch = 'scheme',
132
+ rkt = 'scheme',
133
+ scss = 'scss',
134
+ sh = 'shell',
135
+ bash = 'shell',
136
+ aes = 'sophia',
137
+ sol = 'sol',
138
+ sql = 'sql',
139
+ st = 'st',
140
+ iecst = 'st',
141
+ iecplc = 'st',
142
+ lc3lib = 'st',
143
+ swift = 'swift',
144
+ sv = 'systemverilog',
145
+ svh = 'systemverilog',
146
+ tcl = 'tcl',
147
+ twig = 'twig',
148
+ ts = 'typescript',
149
+ tsx = 'typescript',
150
+ vb = 'vb',
151
+ v = 'verilog',
152
+ vh = 'verilog',
153
+ xml = 'xml',
154
+ dtd = 'xml',
155
+ ascx = 'xml',
156
+ csproj = 'xml',
157
+ config = 'xml',
158
+ wxi = 'xml',
159
+ wxl = 'xml',
160
+ wxs = 'xml',
161
+ xaml = 'xml',
162
+ svg = 'xml',
163
+ svgz = 'xml',
164
+ opf = 'xml',
165
+ xsl = 'xml',
166
+ yaml = 'yaml',
167
+ yml = 'yaml',
168
+ }
@@ -0,0 +1,314 @@
1
+ // import { openDB } from 'idb';
2
+ // import { omit, pick } from 'lodash';
3
+ // import { Client, Selection, TextOperation } from 'ot';
4
+ // import { useOT } from '~/hooks';
5
+ // import { oTStore } from '~/stores';
6
+ // import { setEditorOT } from './idb';
7
+
8
+ import { omit, pick } from 'lodash';
9
+ import { TextOperation } from 'ot';
10
+ import { useOT } from '~/hooks';
11
+ import { oTStore } from '~/stores';
12
+ // import { setEditorOT } from './idb';
13
+
14
+ // import { openDB } from 'idb';
15
+ // import { omit, pick } from 'lodash';
16
+ // import { Client, Selection, TextOperation } from 'ot';
17
+ // import { useOT } from '~/hooks';
18
+ // import { oTStore } from '~/stores';
19
+ // import { setEditorOT } from './idb';
20
+
21
+ export function IoClient(this: any, revision) {
22
+ this.revision = revision; // the next expected revision number
23
+ this.state = synchronized_; // start state
24
+ this.operation = [];
25
+ this.receiveOperation = [];
26
+ this.io = useOT.getState().socket;
27
+ }
28
+
29
+ IoClient.prototype.setState = function (state) {
30
+ this.state = state;
31
+ };
32
+
33
+ // Call this method when the user changes the document.
34
+ IoClient.prototype.applyClient = function (operation) {
35
+ this.operation = operation;
36
+ this.setState(this.state.applyClient(this, operation));
37
+ };
38
+
39
+ // Call this method with a new operation from the server
40
+ IoClient.prototype.applyServer = function (operation) {
41
+ this.revision++;
42
+ // debugger;
43
+ this.setState(this.state.applyServer(this, operation));
44
+ };
45
+
46
+ IoClient.prototype.serverAck = function () {
47
+ // debugger;
48
+ this.revision++;
49
+ this.setState(this.state.serverAck(this));
50
+ };
51
+
52
+ IoClient.prototype.serverReconnect = function () {
53
+ if (typeof this.state.resend === 'function') {
54
+ this.state.resend(this);
55
+ }
56
+ };
57
+
58
+ // Transforms a selection from the latest known server state to the current
59
+ // client state. For example, if we get from the server the information that
60
+ // another user's cursor is at position 3, but the server hasn't yet received
61
+ // our newest operation, an insertion of 5 characters at the beginning of the
62
+ // document, the correct position of the other user's cursor in our current
63
+ // document is 8.
64
+ IoClient.prototype.transformSelection = function (selection) {
65
+ return this.state.transformSelection(selection);
66
+ };
67
+
68
+ IoClient.prototype.insertOTForDB = (obj) => {
69
+ // setEditorOT(obj.ot.revision, pick(obj.ot, 'file', 'operation'));
70
+ // await db.put('editor', pick(obj.ot, 'file', 'operation'), obj.ot.revision);
71
+ // await db.add('favourite-number', obj, 'price');
72
+ };
73
+
74
+ // Override this method.
75
+ IoClient.prototype.sendOperation = function (
76
+ revision: number,
77
+ operation: TextOperation,
78
+ ) {
79
+ throw new Error('sendOperation must be defined in child class');
80
+ };
81
+ // Override this method.
82
+ IoClient.prototype.applyOperation = function (operation) {
83
+ // oTStore.getState().setOperation(operation);
84
+
85
+ this.receiveOperation = operation;
86
+ // console.log('operation is coming back', operation);
87
+ // throw new Error('applyOperation must be defined in child class');
88
+ // this.serverAck();
89
+ };
90
+
91
+ // In the 'Synchronized' state, there is no pending operation that the client
92
+ // has sent to the server.
93
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
94
+ function Synchronized() {}
95
+ IoClient.Synchronized = Synchronized;
96
+
97
+ Synchronized.prototype.applyClient = function (client, operation) {
98
+ // When the user makes an edit, send the operation to the server and
99
+ // switch to the 'AwaitingConfirm' state
100
+ // debugger;
101
+ client.sendOperation(client.revision, operation);
102
+ return new AwaitingConfirm(operation);
103
+ };
104
+
105
+ Synchronized.prototype.applyServer = function (client, operation) {
106
+ // When we receive a new operation from the server, the operation can be
107
+ // simply applied to the current document
108
+ // debugger;
109
+ client.applyOperation(operation);
110
+ return this;
111
+ };
112
+
113
+ Synchronized.prototype.serverAck = function (client) {
114
+ throw new Error('There is no pending operation.');
115
+ };
116
+
117
+ // Nothing to do because the latest server state and client state are the same.
118
+ Synchronized.prototype.transformSelection = function (x) {
119
+ return x;
120
+ };
121
+
122
+ // Singleton
123
+ const synchronized_ = new Synchronized();
124
+
125
+ // In the 'AwaitingConfirm' state, there's one operation the client has sent
126
+ // to the server and is still waiting for an acknowledgement.
127
+ function AwaitingConfirm(this: any, outstanding) {
128
+ // Save the pending operation
129
+ this.outstanding = outstanding;
130
+ }
131
+ IoClient.AwaitingConfirm = AwaitingConfirm;
132
+
133
+ AwaitingConfirm.prototype.applyClient = function (client, operation) {
134
+ // When the user makes an edit, don't send the operation immediately,
135
+ // instead switch to 'AwaitingWithBuffer' state
136
+ return new AwaitingWithBuffer(this.outstanding, operation);
137
+ };
138
+
139
+ AwaitingConfirm.prototype.applyServer = function (client, operation) {
140
+ // This is another client's operation. Visualization:
141
+ //
142
+ // /\
143
+ // this.outstanding / \ operation
144
+ // / \
145
+ // \ /
146
+ // pair[1] \ / pair[0] (new outstanding)
147
+ // (can be applied \/
148
+ // to the client's
149
+ // current document)
150
+ const pair = operation.constructor.transform(this.outstanding, operation);
151
+ client.applyOperation(pair[1]);
152
+ return new AwaitingConfirm(pair[0]);
153
+ };
154
+
155
+ AwaitingConfirm.prototype.serverAck = function (client) {
156
+ // The client's operation has been acknowledged
157
+ // => switch to synchronized state
158
+ return synchronized_;
159
+ };
160
+
161
+ AwaitingConfirm.prototype.transformSelection = function (selection) {
162
+ return selection.transform(this.outstanding);
163
+ };
164
+
165
+ AwaitingConfirm.prototype.resend = function (client) {
166
+ // The confirm didn't come because the client was disconnected.
167
+ // Now that it has reconnected, we resend the outstanding operation.
168
+ client.sendOperation(client.revision, this.outstanding);
169
+ };
170
+
171
+ // In the 'AwaitingWithBuffer' state, the client is waiting for an operation
172
+ // to be acknowledged by the server while buffering the edits the user makes
173
+ function AwaitingWithBuffer(this: any, outstanding, buffer) {
174
+ // Save the pending operation and the user's edits since then
175
+ this.outstanding = outstanding;
176
+ this.buffer = buffer;
177
+ }
178
+ IoClient.AwaitingWithBuffer = AwaitingWithBuffer;
179
+
180
+ AwaitingWithBuffer.prototype.applyClient = function (client, operation) {
181
+ // Compose the user's changes onto the buffer
182
+ const newBuffer = this.buffer.compose(operation);
183
+ return new AwaitingWithBuffer(this.outstanding, newBuffer);
184
+ };
185
+
186
+ AwaitingWithBuffer.prototype.applyServer = function (client, operation) {
187
+ // Operation comes from another client
188
+ //
189
+ // /\
190
+ // this.outstanding / \ operation
191
+ // / \
192
+ // /\ /
193
+ // this.buffer / \* / pair1[0] (new outstanding)
194
+ // / \/
195
+ // \ /
196
+ // pair2[1] \ / pair2[0] (new buffer)
197
+ // the transformed \/
198
+ // operation -- can
199
+ // be applied to the
200
+ // client's current
201
+ // document
202
+ //
203
+ // * pair1[1]
204
+ const transform = operation.constructor.transform;
205
+ const pair1 = transform(this.outstanding, operation);
206
+ const pair2 = transform(this.buffer, pair1[1]);
207
+ client.applyOperation(pair2[1]);
208
+ return new AwaitingWithBuffer(pair1[0], pair2[0]);
209
+ };
210
+
211
+ AwaitingWithBuffer.prototype.serverAck = function (client) {
212
+ // The pending operation has been acknowledged
213
+ // => send buffer
214
+ client.sendOperation(client.revision, this.buffer);
215
+ return new AwaitingConfirm(this.buffer);
216
+ };
217
+
218
+ AwaitingWithBuffer.prototype.transformSelection = function (selection) {
219
+ return selection.transform(this.outstanding).transform(this.buffer);
220
+ };
221
+
222
+ AwaitingWithBuffer.prototype.resend = function (client) {
223
+ // The confirm didn't come because the client was disconnected.
224
+ // Now that it has reconnected, we resend the outstanding operation.
225
+ client.sendOperation(client.revision, this.outstanding);
226
+ };
227
+
228
+ // export default Client;
229
+
230
+ // export class IoClient extends Client {
231
+ // constructor(revision) {
232
+ // super(revision);
233
+ // // return ioClient;
234
+ // }
235
+ // revision: number;
236
+ // state: Client.Synchronized;
237
+ // io = useOT.getState().socket;
238
+
239
+ // setState(state: Client.Synchronized): void {
240
+ // throw new Error('Method not implemented.');
241
+ // }
242
+ // applyClient(operation: TextOperation): void {
243
+ // throw new Error('Method not implemented.');
244
+ // }
245
+ // applyServer(operation: TextOperation): void {
246
+ // throw new Error('Method not implemented.');
247
+ // }
248
+ // serverAck(): void {
249
+ // throw new Error('Method not implemented.');
250
+ // }
251
+ // serverReconnect(): void {
252
+ // throw new Error('Method not implemented.');
253
+ // }
254
+ // transformSelection(selection: Selection): Selection {
255
+ // throw new Error('Method not implemented.');
256
+ // }
257
+ // sendOperation(revision: number, operation: TextOperation): void {
258
+ // console.log('调用监听');
259
+
260
+ // this.insertOTForDB({
261
+ // ot: {
262
+ // operation,
263
+ // revision,
264
+ // file: {
265
+ // ...omit(oTStore.getState().file, 'value'),
266
+ // // valueAndPos,
267
+ // },
268
+ // userInfo: userStore.getState().userInfo,
269
+ // },
270
+ // });
271
+ // this.io.emit(
272
+ // 'editFile',
273
+ // // blob,
274
+ // JSON.stringify({
275
+ // ot: {
276
+ // operation,
277
+ // revision,
278
+ // file: {
279
+ // ...omit(oTStore.getState().file, 'value'),
280
+ // // valueAndPos,
281
+ // },
282
+ // userInfo: userStore.getState().userInfo,
283
+ // },
284
+ // }),
285
+ // );
286
+
287
+ // // throw new Error('Method not implemented.');
288
+ // }
289
+ // async insertOTForDB(obj) {
290
+ // setEditorOT(obj.ot.revision, pick(obj.ot, 'file', 'operation'));
291
+ // // await db.put('editor', pick(obj.ot, 'file', 'operation'), obj.ot.revision);
292
+ // // await db.add('favourite-number', obj, 'price');
293
+ // }
294
+ // applyOperation(operation: TextOperation): void {
295
+ // throw new Error('Method not implemented.');
296
+ // }
297
+ // // sendOperation = (revision, operation) => {
298
+ // // this.io.emit(
299
+ // // 'editFile',
300
+ // // // blob,
301
+ // // JSON.stringify({
302
+ // // ot: {
303
+ // // operation,
304
+ // // revision,
305
+ // // file: {
306
+ // // ...omit(oTStore.getState().file, 'value'),
307
+ // // // valueAndPos,
308
+ // // },
309
+ // // userInfo: userStore.getState().userInfo,
310
+ // // },
311
+ // // }),
312
+ // // );
313
+ // // };
314
+ // }
File without changes
@@ -0,0 +1,186 @@
1
+ import { DBSchema, IDBPDatabase, openDB } from 'idb';
2
+ import { oTStore } from '~/stores';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import { omit, pick } from 'lodash';
5
+ const crdtInfo = {
6
+ timestamp: '',
7
+ editor: new Map(),
8
+ selection: new Map(),
9
+ terminal: new Map(),
10
+ console: new Map(),
11
+ file: new Map(),
12
+ media: new Map(),
13
+ };
14
+ export const daopaasDB = openDB('daopaas', 1, {
15
+ upgrade(db) {
16
+ db.createObjectStore('crdts');
17
+ db.createObjectStore('oTStore');
18
+ db.createObjectStore('files');
19
+ db.createObjectStore('replayFiles');
20
+ db.createObjectStore('users');
21
+ db.createObjectStore('media');
22
+ },
23
+ });
24
+
25
+ export const GenerateDB = async (db_name, length = 1, obj) => {
26
+ return openDB(db_name, length, {
27
+ upgrade(db) {
28
+ db.createObjectStore(obj);
29
+ },
30
+ });
31
+ };
32
+
33
+ export async function setReplaySource(val, status?: string) {
34
+ // const dao = await daopaasDB;
35
+
36
+ const { CRDTInfo, appStatus, globalData } = oTStore.getState();
37
+
38
+ if (appStatus === 'replay') return;
39
+
40
+ // crdtInfo.timestamp = CRDTInfo.timestamp as string;
41
+
42
+ // crdtInfo.editor.set(
43
+ // val.userInfo.uuid,
44
+ // val.editor ? val.editor : crdtInfo.editor.get(val.userInfo.uuid),
45
+ // );
46
+
47
+ // crdtInfo.file.set(
48
+ // val.userInfo.uuid,
49
+ // val.file
50
+ // ? omit(val.file, 'value')
51
+ // : omit(crdtInfo.file.get(val.userInfo.uuid), 'value'),
52
+ // );
53
+
54
+ // crdtInfo.selection.set(
55
+ // val.userInfo.uuid,
56
+ // val.selection ? val.selection : crdtInfo.selection.get(val.userInfo.uuid),
57
+ // );
58
+
59
+ // crdtInfo.terminal.set(
60
+ // val.userInfo.uuid,
61
+ // val.terminal ? val.terminal : crdtInfo.terminal.get(val.userInfo.uuid),
62
+ // );
63
+
64
+ // crdtInfo.console.set(
65
+ // val.userInfo.uuid,
66
+ // val.console ? val.console : crdtInfo.console.get(val.userInfo.uuid),
67
+ // );
68
+
69
+ // crdtInfo.media.set(
70
+ // val.userInfo.uuid,
71
+ // val.media ? val.media : crdtInfo.media.get(val.userInfo.uuid),
72
+ // );
73
+
74
+ // const valTime = val.timestamp + '.' + (await dao.count('crdts'));
75
+ // return dao.put('crdts', val, val.timestamp + '.' + uuidv4().split('-')[0]);
76
+ // if (globalData.isRecording) {
77
+ return (await daopaasDB).put(
78
+ 'crdts',
79
+ // crdtInfo,
80
+ {
81
+ ...val,
82
+ userInfo: pick(val.userInfo, ['uuid', 'role']),
83
+ file: omit(val.file, 'value'),
84
+ },
85
+ val.timestamp + '.' + uuidv4().split('-')[0],
86
+ );
87
+ // }
88
+ }
89
+
90
+ export const GetDB = async (db_name, key, obj_name) => {
91
+ return (await db_name).get(obj_name, key);
92
+ };
93
+
94
+ export const SetDB = async (db_name, key, val, obj_name) => {
95
+ return (await db_name).put(obj_name, val, key);
96
+ };
97
+
98
+ export async function getLocalFile(key) {
99
+ return (await daopaasDB).get('files', key);
100
+ }
101
+ export async function getLocalReplayFile(key) {
102
+ return (await daopaasDB).get('replayFiles', key);
103
+ }
104
+
105
+ export async function setLocalFile(key, val) {
106
+ return (await daopaasDB).put('files', val, key);
107
+ }
108
+
109
+ export async function setLocalReplayFile(key, val) {
110
+ return (await daopaasDB).put('replayFiles', val, key);
111
+ }
112
+
113
+ export async function getLocalCRDTs() {
114
+ // .filter((a) => a.editor.evtType !== 'File')
115
+ return (await (await daopaasDB).getAll('crdts')).filter(
116
+ (a) => a?.editor?.evtType !== 'File',
117
+ );
118
+ }
119
+
120
+ export async function setLocalMedia(key, val) {
121
+ return (await daopaasDB).put('media', val, key);
122
+ }
123
+
124
+ export async function getLocalMedia() {
125
+ return (await daopaasDB).getAll('media');
126
+ }
127
+
128
+ // export async function getEditorOTLength(key) {
129
+ // return (await dbPromise).get('editor', key);
130
+ // }
131
+
132
+ // export async function setEditorOT(key, val) {
133
+ // return (await dbPromise).put('editor', val, key);
134
+ // }
135
+
136
+ // export async function delEditorOT(key) {
137
+ // return (await dbPromise).delete('editor', key);
138
+ // }
139
+
140
+ // export async function clearEditorOT() {
141
+ // return (await dbPromise).clear('editor');
142
+ // }
143
+
144
+ // export async function keys() {
145
+ // return (await dbPromise).getAllKeys('keyval');
146
+ // }
147
+
148
+ // export { IDB };
149
+
150
+ // export interface MyDB extends DBSchema {
151
+ // 'favourite-number': {
152
+ // key: string;
153
+ // value: number;
154
+ // };
155
+ // file: {
156
+ // key: string;
157
+ // value: number;
158
+ // };
159
+ // editor: {
160
+ // value: {
161
+ // file: string;
162
+ // operation: number;
163
+ // };
164
+ // key: string;
165
+ // indexes: {
166
+ // 'by-price': number;
167
+ // // name: string;
168
+ // };
169
+ // };
170
+ // }
171
+
172
+ // const dbPromise = openDB('oTStore', 1, {
173
+ // upgrade(db) {
174
+ // db.createObjectStore('editor');
175
+ // // db.put()
176
+ // },
177
+ // });
178
+
179
+ // export const GenerateDB = async (db_name, length = 1, obj) => {
180
+ // openDB(db_name, length, {
181
+ // upgrade(db) {
182
+ // // callback(db);
183
+ // db.createObjectStore(obj);
184
+ // },
185
+ // });
186
+ // };
@@ -0,0 +1,13 @@
1
+ const localStorageSpace = function () {
2
+ let allStrings = '';
3
+ for (const key in window.localStorage) {
4
+ if (window.localStorage.hasOwnProperty(key)) {
5
+ allStrings += window.localStorage[key];
6
+ }
7
+ }
8
+ return allStrings
9
+ ? 3 + (allStrings.length * 16) / (8 * 1024) + ' KB'
10
+ : 'Empty (0 KB)';
11
+ };
12
+
13
+ export { localStorageSpace };