@onereach/ui-components 6.4.2 → 6.5.0-beta.3403.0

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 (77) hide show
  1. package/dist/bundled/v2/components/OrCode/OrCode.js +2 -2
  2. package/dist/bundled/v2/components/OrCode/index.js +5 -3
  3. package/dist/bundled/v2/components/OrCode/lang.js +5 -3
  4. package/dist/bundled/v2/components/OrCode/libs.js +5 -3
  5. package/dist/bundled/v2/components/OrCode/theme.js +1 -1
  6. package/dist/bundled/v2/components/OrCodeV3/OrCode.js +52 -30
  7. package/dist/bundled/v2/components/OrCodeV3/OrCode.vue.d.ts +4 -3
  8. package/dist/bundled/v2/components/OrCodeV3/index.d.ts +1 -0
  9. package/dist/bundled/v2/components/OrCodeV3/index.js +5 -0
  10. package/dist/bundled/v2/components/OrCodeV3/libs.d.ts +6 -0
  11. package/dist/bundled/v2/components/OrCodeV3/libs.js +5 -0
  12. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +2 -2
  13. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +1 -1
  14. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/theme.js +1 -1
  15. package/dist/bundled/v2/components/index.js +6 -3
  16. package/dist/bundled/v2/index-317a90b7.js +361 -0
  17. package/dist/bundled/v2/index-5465a04e.js +825 -0
  18. package/dist/bundled/v2/index-5df3b1d8.js +94 -0
  19. package/dist/bundled/v2/index-5fa53f66.js +759 -0
  20. package/dist/bundled/{v3/index-ceea3e83.js → v2/index-7caa3ac5.js} +3 -3
  21. package/dist/bundled/v2/{index-eca317e0.js → index-bd08fe6f.js} +27 -465
  22. package/dist/bundled/v2/index-d017a622.js +1892 -0
  23. package/dist/bundled/v2/{index-62bb1bac.js → index-d4e4f8a8.js} +10 -831
  24. package/dist/bundled/v2/{index-3cae2d25.js → index-d5c13979.js} +1 -1
  25. package/dist/bundled/v2/index-f949d42c.js +1598 -0
  26. package/dist/bundled/v2/index.js +6 -3
  27. package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-e88b2b44.js → OrCode.vue_vue_type_script_lang-9be03ab0.js} +2 -2
  28. package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-c9522cd5.js → OrCode.vue_vue_type_script_lang-f6022ce5.js} +52 -30
  29. package/dist/bundled/v3/components/OrCode/OrCode.js +2 -2
  30. package/dist/bundled/v3/components/OrCode/index.js +6 -4
  31. package/dist/bundled/v3/components/OrCode/lang.js +5 -3
  32. package/dist/bundled/v3/components/OrCode/libs.js +5 -3
  33. package/dist/bundled/v3/components/OrCode/theme.js +1 -1
  34. package/dist/bundled/v3/components/OrCodeV3/OrCode.js +2 -2
  35. package/dist/bundled/v3/components/OrCodeV3/OrCode.vue.d.ts +3 -2
  36. package/dist/bundled/v3/components/OrCodeV3/index.d.ts +1 -0
  37. package/dist/bundled/v3/components/OrCodeV3/index.js +6 -1
  38. package/dist/bundled/v3/components/OrCodeV3/libs.d.ts +6 -0
  39. package/dist/bundled/v3/components/OrCodeV3/libs.js +5 -0
  40. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.js +2 -2
  41. package/dist/bundled/v3/components/OrRichTextEditorV3/index.js +1 -1
  42. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +2 -2
  43. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +1 -1
  44. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/theme.js +1 -1
  45. package/dist/bundled/v3/components/index.js +9 -6
  46. package/dist/bundled/v3/{index-62bb1bac.js → index-16f605c7.js} +10 -831
  47. package/dist/bundled/v3/index-1f2974f3.js +1892 -0
  48. package/dist/bundled/v3/index-1fc9d52b.js +759 -0
  49. package/dist/bundled/v3/index-210fd8da.js +825 -0
  50. package/dist/bundled/{v2/index-ceea3e83.js → v3/index-71514f0d.js} +3 -3
  51. package/dist/bundled/v3/{index-eca317e0.js → index-766903ad.js} +27 -465
  52. package/dist/bundled/v3/index-a4b02e4e.js +1598 -0
  53. package/dist/bundled/v3/index-a8d259c3.js +361 -0
  54. package/dist/bundled/v3/{index-3cae2d25.js → index-e81a9bf9.js} +1 -1
  55. package/dist/bundled/v3/index-f6290750.js +94 -0
  56. package/dist/bundled/v3/index.js +9 -6
  57. package/dist/esm/v2/{OrCode-f5c25b63.js → OrCode-e2222cf7.js} +54 -34
  58. package/dist/esm/v2/components/index.js +3 -3
  59. package/dist/esm/v2/components/or-code-v3/OrCode.vue.d.ts +4 -3
  60. package/dist/esm/v2/components/or-code-v3/index.d.ts +1 -0
  61. package/dist/esm/v2/components/or-code-v3/index.js +9 -10
  62. package/dist/esm/v2/components/or-code-v3/libs.d.ts +6 -0
  63. package/dist/esm/v2/index.js +3 -3
  64. package/dist/esm/v3/{OrCode-9662d0da.js → OrCode-f6a8e9f2.js} +54 -34
  65. package/dist/esm/v3/components/index.js +3 -3
  66. package/dist/esm/v3/components/or-code-v3/OrCode.vue.d.ts +3 -2
  67. package/dist/esm/v3/components/or-code-v3/index.d.ts +1 -0
  68. package/dist/esm/v3/components/or-code-v3/index.js +9 -10
  69. package/dist/esm/v3/components/or-code-v3/libs.d.ts +6 -0
  70. package/dist/esm/v3/index.js +3 -3
  71. package/package.json +2 -3
  72. package/src/components/or-code-v3/OrCode.vue +70 -50
  73. package/src/components/or-code-v3/index.ts +1 -0
  74. package/src/components/or-code-v3/libs.ts +10 -0
  75. package/dist/bundled/v2/index-60e4eacf.js +0 -4048
  76. package/dist/bundled/v3/index-60e4eacf.js +0 -4048
  77. /package/dist/bundled/v3/{OrRichTextEditor.vue_vue_type_script_lang-5a2318e5.js → OrRichTextEditor.vue_vue_type_script_lang-63edf53c.js} +0 -0
@@ -57,19 +57,20 @@
57
57
  </template>
58
58
 
59
59
  <script lang="ts">
60
- import { indentWithTab } from '@codemirror/commands';
61
- import { css } from '@codemirror/lang-css';
62
- import { html } from '@codemirror/lang-html';
63
- import { javascript } from '@codemirror/lang-javascript';
64
- import { json } from '@codemirror/lang-json';
65
- import { markdown } from '@codemirror/lang-markdown';
66
- import { EditorState, Extension } from '@codemirror/state';
67
- import { EditorView, keymap } from '@codemirror/view';
68
- import { basicSetup } from 'codemirror';
69
60
  import { PropType, computed, defineComponent, onMounted, onUnmounted, reactive, ref, toRef, watch } from 'vue-demi';
70
61
  import { useControlAttributes, useIdAttribute, useProxyModelValue, useTheme, useValidationAttributes } from '../../hooks';
62
+
63
+ /* Codemirror core */
64
+ import { basicSetup } from 'codemirror';
65
+
66
+ import { EditorView, keymap } from '@codemirror/view';
67
+ import { indentWithTab } from '@codemirror/commands';
68
+ import { EditorState, Extension, Compartment } from '@codemirror/state';
69
+
70
+ /* Components */
71
71
  import { OrIconButtonV3 as OrIconButton } from '../or-icon-button-v3';
72
72
  import { OrModalV3 as OrModal } from '../or-modal-v3';
73
+
73
74
  import { CodeLanguage } from './props';
74
75
  import { Code, CodeControl, CodeModal } from './styles';
75
76
  import OrCodeControl from './partials/OrCodeControl.vue';
@@ -150,6 +151,7 @@ export default defineComponent({
150
151
 
151
152
  expose: [
152
153
  'root',
154
+ 'editorView',
153
155
 
154
156
  'focus',
155
157
  'blur',
@@ -177,6 +179,9 @@ export default defineComponent({
177
179
  ...CodeModal,
178
180
  ]);
179
181
 
182
+ const addedExtensionCompartment = new Compartment();
183
+ const languageExtensionCompartment = new Compartment();
184
+
180
185
  // State
181
186
  const controlAttributes = reactive({
182
187
  id: useIdAttribute(),
@@ -186,27 +191,27 @@ export default defineComponent({
186
191
 
187
192
  const proxyModelValue = useProxyModelValue(toRef(props, 'modelValue'), context.emit);
188
193
 
189
- const proxyLanguage = computed(() => {
190
- switch (props.language) {
194
+ const getLanguageExtension = async (language: CodeLanguage) => {
195
+ switch (language) {
191
196
  case CodeLanguage.HTML:
192
- return html();
197
+ return (await import('@codemirror/lang-html')).html();
193
198
 
194
199
  case CodeLanguage.CSS:
195
- return css();
200
+ return (await import('@codemirror/lang-css')).css();
196
201
 
197
202
  case CodeLanguage.JS:
198
- return javascript();
203
+ return (await import('@codemirror/lang-javascript')).javascript();
199
204
 
200
205
  case CodeLanguage.TS:
201
- return javascript({ typescript: true });
206
+ return (await import('@codemirror/lang-javascript')).javascript({ typescript: true });
202
207
 
203
208
  case CodeLanguage.JSON:
204
- return json();
209
+ return (await import('@codemirror/lang-json')).json();
205
210
 
206
211
  case CodeLanguage.MD:
207
- return markdown();
212
+ return (await import('@codemirror/lang-markdown')).markdown();
208
213
  }
209
- });
214
+ };
210
215
 
211
216
  // Methods
212
217
  function focus(): void {
@@ -222,19 +227,8 @@ export default defineComponent({
222
227
  }
223
228
 
224
229
  // #region Codemirror
225
- const editorView = new EditorView({
226
- dispatch: (transaction) => {
227
- editorView.update([
228
- transaction,
229
- ]);
230
-
231
- proxyModelValue.value = String(editorView.state.doc);
232
- },
233
- });
234
-
235
230
  const theme = useTheme();
236
-
237
- const extensions = computed<Extension[]>(() => [
231
+ const defaultExtensions = [
238
232
  basicSetup,
239
233
 
240
234
  keymap.of([
@@ -289,30 +283,56 @@ export default defineComponent({
289
283
  backgroundColor: theme.backgroundColor['primary-opacity-0-08'],
290
284
  },
291
285
  }),
286
+ ];
287
+
288
+ const state = EditorState.create({
289
+ doc: proxyModelValue.value,
290
+ extensions: [
291
+ ...defaultExtensions,
292
+ languageExtensionCompartment.of([]),
293
+ addedExtensionCompartment.of(props.extensions),
294
+ ],
295
+ });
292
296
 
293
- proxyLanguage.value,
294
- ...props.extensions,
295
- ]);
297
+ const editorView = new EditorView({
298
+ state,
299
+ dispatch: (transaction) => {
300
+ editorView.update([
301
+ transaction,
302
+ ]);
296
303
 
297
- watch([
298
- proxyModelValue,
299
- extensions,
300
- ], ([
301
- modelValue = '',
302
- extensions,
303
- ]) => {
304
+ if (transaction.docChanged) {
305
+ proxyModelValue.value = String(editorView.state.doc);
306
+ }
307
+ },
308
+ });
309
+
310
+ watch(proxyModelValue, (value) => {
311
+ const modelValue = value ?? '';
304
312
  const { selection } = editorView.state;
305
313
 
306
- editorView.setState(
307
- EditorState.create({
308
- doc: modelValue,
309
- extensions,
314
+ editorView!.dispatch({
315
+ changes: {
316
+ from: 0,
317
+ to: editorView!.state.doc.length,
318
+ insert: modelValue,
319
+ },
320
+ selection: selection.ranges.some((range) => range.to > modelValue.length) ? { anchor: modelValue.length } : selection,
321
+ });
322
+ });
323
+
324
+ watch([() => props.extensions, () => props.language], async ([extensions, language], [, prevLanguage]) => {
325
+ let effects = [];
326
+
327
+ if (language !== prevLanguage) {
328
+ const languageExt = await getLanguageExtension(language as CodeLanguage);
329
+
330
+ effects.push(languageExtensionCompartment.reconfigure([languageExt]));
331
+ }
332
+
333
+ effects.push(addedExtensionCompartment.reconfigure(extensions));
310
334
 
311
- selection: selection.ranges.some((range) => range.to > modelValue.length)
312
- ? { anchor: modelValue.length }
313
- : selection,
314
- }),
315
- );
335
+ editorView!.dispatch({ effects });
316
336
  }, { immediate: true });
317
337
  // #endregion
318
338
 
@@ -337,6 +357,7 @@ export default defineComponent({
337
357
  });
338
358
 
339
359
  return {
360
+ editorView,
340
361
  root,
341
362
  control,
342
363
  fullscreenControl,
@@ -346,7 +367,6 @@ export default defineComponent({
346
367
  modalStyles,
347
368
  controlAttributes,
348
369
  proxyModelValue,
349
- proxyLanguage,
350
370
  focus,
351
371
  blur,
352
372
  openFullscreen,
@@ -1,2 +1,3 @@
1
1
  export { default as OrCodeV3 } from './OrCode.vue';
2
2
  export * from './props';
3
+ export * from './libs';
@@ -0,0 +1,10 @@
1
+ // used in the bundled expression-components
2
+
3
+ export { linter, lintGutter } from '@codemirror/lint';
4
+ export { javascript } from '@codemirror/lang-javascript';
5
+ export { json, jsonParseLinter } from '@codemirror/lang-json';
6
+ export { html } from '@codemirror/lang-html';
7
+
8
+ export { EditorView } from '@codemirror/view';
9
+ export { EditorState } from '@codemirror/state';
10
+