@bexis2/bexis2-core-ui 0.2.30 → 0.2.31

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/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # bexis-core-ui
2
2
 
3
+ ## 0.2.31
4
+
5
+ - validation and syntax check for code editor component
6
+
3
7
  ## 0.2.30
4
8
 
5
9
  - fix routes for 'file' components ('.../file/...' -> '.../File/...')
6
- - 'Table' components is able to display heterogeneous data, that means data items/rows might have a different number of properties/columns.
10
+ - 'Table' component is able to display heterogeneous data, that means data items/rows might have a different number of properties/columns.
7
11
 
8
12
  ## 0.2.29
9
13
 
@@ -1,9 +1,11 @@
1
1
  <script>import { createEventDispatcher } from "svelte";
2
2
  import CodeMirror from "svelte-codemirror-editor";
3
3
  import Fa from "svelte-fa/src/fa.svelte";
4
+ import Linter from "eslint4b-prebuilt";
4
5
  import { html } from "@codemirror/lang-html";
5
- import { javascript } from "@codemirror/lang-javascript";
6
- import { json } from "@codemirror/lang-json";
6
+ import { javascript, esLint } from "@codemirror/lang-javascript";
7
+ import { lintGutter, linter } from "@codemirror/lint";
8
+ import { json, jsonParseLinter } from "@codemirror/lang-json";
7
9
  import { oneDark } from "@codemirror/theme-one-dark";
8
10
  import { Modal, modalStore } from "@skeletonlabs/skeleton";
9
11
  import { faMoon, faSave, faSun } from "@fortawesome/free-regular-svg-icons";
@@ -16,6 +18,7 @@ export let language = "html";
16
18
  export let dark = true;
17
19
  export let toggle = true;
18
20
  export let actions = true;
21
+ export let isValid = false;
19
22
  export let styles = {
20
23
  "&": {
21
24
  borderRadius: "0.5rem",
@@ -32,14 +35,34 @@ const modal = {
32
35
  body: "Unsaved changes will be lost. Are you sure you want to continue?",
33
36
  response: (r) => r ? value = initialValue : null
34
37
  };
38
+ const extensions = language === "js" ? [linter(esLint(new Linter())), lintGutter()] : language === "json" ? [linter(jsonParseLinter()), lintGutter()] : [];
39
+ const isValidJSON = (str) => {
40
+ try {
41
+ JSON.parse(str);
42
+ } catch (e) {
43
+ return false;
44
+ }
45
+ return true;
46
+ };
47
+ const isValidJS = (str) => {
48
+ try {
49
+ new Function(str);
50
+ } catch (e) {
51
+ return false;
52
+ }
53
+ return true;
54
+ };
55
+ $:
56
+ isValid = language === "json" ? isValidJSON(value) : language === "js" ? isValidJS(value) : true;
35
57
  </script>
36
58
 
37
- <div class="items-center justify-center">
38
-
39
- <h1 class="h1 font-semibold text-primary-500 mb-3" id="{id}-title">{title}</h1>
59
+ <div class="grid items-stretch justify-stretch gap-1">
60
+ <label class="label" for="{id}-editor" id="{id}-title">
61
+ <span>{title}</span>
62
+ </label>
40
63
  <slot id="{id}-description" />
41
- <div class="grid gap-1 w-full h-full mt-5">
42
- <div class="rounded-lg shadow-lg w-full" id="{id}-editor">
64
+ <div class="grid gap-1 w-full h-full">
65
+ <div class="rounded-lg shadow-lg w-full overflow-auto" id="{id}-editor">
43
66
  <CodeMirror
44
67
  bind:value
45
68
  lang={language === 'html'
@@ -50,11 +73,11 @@ const modal = {
50
73
  theme={dark ? oneDark : null}
51
74
  class="flex w-full"
52
75
  {styles}
76
+ {extensions}
53
77
  />
54
78
  </div>
55
79
  </div>
56
80
 
57
-
58
81
  <div class="flex justify-between gap-2 items-center mt-3" id="{id}-footer">
59
82
  <div class="flex gap-2">
60
83
  <button
@@ -89,6 +112,7 @@ const modal = {
89
112
  <button
90
113
  class="btn variant-filled-primary"
91
114
  id="{id}-save"
115
+ disabled={!isValid}
92
116
  on:click|preventDefault={() => dispatch('save')}><Fa icon={faSave} /></button
93
117
  >
94
118
  </div>
@@ -10,6 +10,7 @@ declare const __propDef: {
10
10
  dark?: boolean | undefined;
11
11
  toggle?: boolean | undefined;
12
12
  actions?: boolean | undefined;
13
+ isValid?: boolean | undefined;
13
14
  styles?: ThemeSpec | undefined;
14
15
  };
15
16
  events: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bexis2/bexis2-core-ui",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -60,6 +60,7 @@
60
60
  "@codemirror/lang-html": "^6.4.5",
61
61
  "@codemirror/lang-javascript": "^6.1.9",
62
62
  "@codemirror/lang-json": "^6.0.1",
63
+ "@codemirror/lint": "^6.4.2",
63
64
  "@codemirror/theme-one-dark": "^6.1.2",
64
65
  "@floating-ui/dom": "^1.2.7",
65
66
  "@fortawesome/fontawesome-free": "^6.2.1",
@@ -70,6 +71,7 @@
70
71
  "codemirror": "^6.0.1",
71
72
  "delay": "^6.0.0",
72
73
  "dotenv": "^16.3.1",
74
+ "eslint4b-prebuilt": "^6.7.2",
73
75
  "highlight.js": "^11.8.0",
74
76
  "highlightjs-svelte": "^1.0.6",
75
77
  "svelte": "^3.54.0",
@@ -3,16 +3,19 @@
3
3
 
4
4
  import CodeMirror from 'svelte-codemirror-editor';
5
5
  import Fa from 'svelte-fa/src/fa.svelte';
6
+ import Linter from 'eslint4b-prebuilt';
6
7
  import { html } from '@codemirror/lang-html';
7
- import { javascript } from '@codemirror/lang-javascript';
8
- import { json } from '@codemirror/lang-json';
8
+ import { javascript, esLint } from '@codemirror/lang-javascript';
9
+ import { lintGutter, linter } from '@codemirror/lint';
10
+ import { json, jsonParseLinter } from '@codemirror/lang-json';
9
11
  import { oneDark } from '@codemirror/theme-one-dark';
10
12
  import { Modal, modalStore } from '@skeletonlabs/skeleton';
11
13
  import { faMoon, faSave, faSun } from '@fortawesome/free-regular-svg-icons';
12
14
  import { faArrowRotateLeft, faXmark } from '@fortawesome/free-solid-svg-icons';
13
15
  import type { ThemeSpec } from 'svelte-codemirror-editor';
14
16
  import type { ModalSettings } from '@skeletonlabs/skeleton';
15
-
17
+ import type { Extension } from '@codemirror/state';
18
+
16
19
  export let id: string;
17
20
  export let title = '';
18
21
  export let initialValue = '';
@@ -21,6 +24,7 @@
21
24
  export let dark = true;
22
25
  export let toggle = true;
23
26
  export let actions = true;
27
+ export let isValid = false;
24
28
  export let styles: ThemeSpec = {
25
29
  '&': {
26
30
  borderRadius: '0.5rem',
@@ -39,14 +43,43 @@
39
43
  body: 'Unsaved changes will be lost. Are you sure you want to continue?',
40
44
  response: (r: boolean) => (r ? (value = initialValue) : null)
41
45
  };
42
- </script>
43
46
 
44
- <div class="items-center justify-center">
47
+ const extensions: Extension[] =
48
+ language === 'js'
49
+ ? [linter(esLint(new Linter())), lintGutter()]
50
+ : language === 'json'
51
+ ? [linter(jsonParseLinter()), lintGutter()]
52
+ : [];
53
+
54
+ const isValidJSON = (str: string) => {
55
+ try {
56
+ JSON.parse(str);
57
+ } catch (e) {
58
+ return false;
59
+ }
60
+ return true;
61
+ };
45
62
 
46
- <h1 class="h1 font-semibold text-primary-500 mb-3" id="{id}-title">{title}</h1>
63
+ const isValidJS = (str: string) => {
64
+ try {
65
+ new Function(str);
66
+ } catch (e) {
67
+ return false;
68
+ }
69
+ return true;
70
+ };
71
+
72
+ $: isValid =
73
+ language === 'json' ? isValidJSON(value) : language === 'js' ? isValidJS(value) : true;
74
+ </script>
75
+
76
+ <div class="grid items-stretch justify-stretch gap-1">
77
+ <label class="label" for="{id}-editor" id="{id}-title">
78
+ <span>{title}</span>
79
+ </label>
47
80
  <slot id="{id}-description" />
48
- <div class="grid gap-1 w-full h-full mt-5">
49
- <div class="rounded-lg shadow-lg w-full" id="{id}-editor">
81
+ <div class="grid gap-1 w-full h-full">
82
+ <div class="rounded-lg shadow-lg w-full overflow-auto" id="{id}-editor">
50
83
  <CodeMirror
51
84
  bind:value
52
85
  lang={language === 'html'
@@ -57,11 +90,11 @@
57
90
  theme={dark ? oneDark : null}
58
91
  class="flex w-full"
59
92
  {styles}
93
+ {extensions}
60
94
  />
61
95
  </div>
62
96
  </div>
63
97
 
64
-
65
98
  <div class="flex justify-between gap-2 items-center mt-3" id="{id}-footer">
66
99
  <div class="flex gap-2">
67
100
  <button
@@ -96,6 +129,7 @@
96
129
  <button
97
130
  class="btn variant-filled-primary"
98
131
  id="{id}-save"
132
+ disabled={!isValid}
99
133
  on:click|preventDefault={() => dispatch('save')}><Fa icon={faSave} /></button
100
134
  >
101
135
  </div>