@mixd-id/web-scaffold 0.1.230406107 → 0.1.230406108

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mixd-id/web-scaffold",
3
3
  "private": false,
4
- "version": "0.1.230406107",
4
+ "version": "0.1.230406108",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -43,6 +43,7 @@
43
43
  "glob": "^8.0.3",
44
44
  "lodash": "^4.17.21",
45
45
  "md5": "^2.3.0",
46
+ "monaco-editor": "^0.41.0",
46
47
  "nprogress": "^0.2.0",
47
48
  "pinia": "^2.0.14",
48
49
  "prismjs": "^1.28.0",
@@ -0,0 +1,136 @@
1
+ <template>
2
+ <div :class="$style.comp">
3
+ <div class="flex flex-row p-2">
4
+ <code>{{ language }}</code>
5
+ <div class="flex-1"></div>
6
+ <button type="button" class="text-primary" @click="reformat">Beautify</button>
7
+ </div>
8
+ <div ref="editorContainer" :class="$style['monaco-editor-container']"></div>
9
+ </div>
10
+ </template>
11
+
12
+ <script>
13
+ import * as monaco from 'monaco-editor'
14
+ import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
15
+ import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
16
+ import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'
17
+ import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'
18
+ import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
19
+
20
+ self.MonacoEnvironment = {
21
+ getWorker(_, label) {
22
+ if (label === 'json') {
23
+ return new jsonWorker()
24
+ }
25
+ if (label === 'css' || label === 'scss' || label === 'less') {
26
+ return new cssWorker()
27
+ }
28
+ if (label === 'html' || label === 'handlebars' || label === 'razor') {
29
+ return new htmlWorker()
30
+ }
31
+ if (label === 'typescript' || label === 'javascript') {
32
+ return new tsWorker()
33
+ }
34
+ return new editorWorker()
35
+ }
36
+ }
37
+
38
+ export default {
39
+
40
+ props: {
41
+
42
+ language: {
43
+ type: String,
44
+ default: 'json'
45
+ },
46
+
47
+ theme: {
48
+ type: String,
49
+ default: 'vs-dark'
50
+ },
51
+
52
+ lineNumbers: {
53
+ type: String,
54
+ default: "off"
55
+ },
56
+
57
+ modelValue: String
58
+
59
+ },
60
+
61
+ methods: {
62
+
63
+ createEditor() {
64
+ this.editor = monaco.editor.create(this.$refs.editorContainer, {
65
+ value: this.modelValue,
66
+ language: this.language,
67
+ lineNumbers: this.lineNumbers,
68
+ minimap: {
69
+ enabled: false
70
+ },
71
+ theme: this.theme
72
+ });
73
+
74
+ this.editor.onDidChangeModelContent(event => {
75
+ const updatedCode = this.editor.getValue();
76
+ this.$emit('update:modelValue', updatedCode)
77
+ });
78
+ },
79
+
80
+ getErrors(){
81
+ const markers = monaco.editor.getModelMarkers({ owner: this.editor.getModel() });
82
+
83
+ let errors = []
84
+ if (markers.length >= 0) {
85
+ markers.forEach(marker => {
86
+ errors.push({
87
+ message: marker.message,
88
+ line: marker.startLineNumber,
89
+ column: marker.startColumn
90
+ })
91
+ });
92
+ }
93
+
94
+ return errors.length > 0 ? errors : null
95
+ },
96
+
97
+ reformat(){
98
+ const formatAction = this.editor.getAction('editor.action.formatDocument');
99
+ formatAction.run();
100
+ }
101
+
102
+ },
103
+
104
+ beforeDestroy() {
105
+ this.editor.dispose();
106
+ },
107
+
108
+ mounted() {
109
+ this.createEditor();
110
+ }
111
+
112
+ };
113
+ </script>
114
+
115
+ <style module>
116
+
117
+ .comp{
118
+ @apply flex-1 flex flex-col;
119
+ }
120
+
121
+ .monaco-editor-container {
122
+ width: 100%;
123
+ height: 300px;
124
+ }
125
+
126
+ .monaco-editor-container *{
127
+ font-family: Menlo, Monaco, "Courier New", monospace;
128
+ --vscode-editor-background: rgb(var(--base-300));
129
+ --vscode-editorGutter-background: rgb(var(--base-400));
130
+ }
131
+
132
+ .monaco-editor-container .margin-view-overlays .line-numbers {
133
+ font-family: 'Menlo', monospace;
134
+ }
135
+
136
+ </style>
package/src/index.js CHANGED
@@ -321,6 +321,7 @@ export default{
321
321
  app.component('Grid', defineAsyncComponent(() => import("./components/Grid.vue")))
322
322
  app.component('Modal', defineAsyncComponent(() => import("./components/Modal.vue")))
323
323
  app.component('Modal2', defineAsyncComponent(() => import("./components/Modal2.vue")))
324
+ app.component('MonacoEditor', defineAsyncComponent(() => import("./components/MonacoEditor.vue")))
324
325
  app.component('OTPField', defineAsyncComponent(() => import("./components/OTPField.vue")))
325
326
  app.component('PageBuilder', defineAsyncComponent(() => import("./components/PageBuilder.vue")))
326
327
  app.component('Radio', defineAsyncComponent(() => import("./components/Radio.vue")))
@@ -380,7 +380,7 @@
380
380
  </template>
381
381
  </Modal>
382
382
 
383
- <Modal ref="ldjsonModal" width="480" height="480">
383
+ <Modal ref="ldjsonModal" width="600" height="480">
384
384
  <template v-slot:head>
385
385
  <div class="relative p-5">
386
386
  <h3>JSON-LD</h3>
@@ -396,18 +396,14 @@
396
396
  <template #foot="{ context }">
397
397
  <div class="p-5">
398
398
  <Button type="button" class="w-[100px]"
399
- @click="'index' in context ?
400
- page.ldjson[context.index] = context.code :
401
- page.ldjson.push(context.code);
402
- $refs.ldjsonModal.close()
403
- save()">
399
+ @click="saveLdjson(context)">
404
400
  Save
405
401
  </Button>
406
402
  </div>
407
403
  </template>
408
404
  <template #default="{ context }">
409
405
  <div class="flex-1 p-5">
410
- <CodeEditor v-model="context.code" rows="10"/>
406
+ <MonacoEditor ref="monacoEditor" v-model="context.code"/>
411
407
  </div>
412
408
  </template>
413
409
  </Modal>
@@ -727,6 +723,20 @@ export default{
727
723
  })
728
724
  }, 300),
729
725
 
726
+ saveLdjson(context){
727
+ const errors = this.$refs.monacoEditor.getErrors()
728
+ if(errors){
729
+ this.alert('JSON is not valid', errors.map(_ => _.message).join("\n"))
730
+ return
731
+ }
732
+
733
+ 'index' in context ?
734
+ this.page.ldjson[context.index] = context.code :
735
+ this.page.ldjson.push(context.code);
736
+ this.$refs.ldjsonModal.close()
737
+ this.save()
738
+ },
739
+
730
740
  imageSrc(imageUrl){
731
741
  return typeof imageUrl === 'string' ? import.meta.env.VITE_IMAGE_HOST + '/' + imageUrl : imageUrl
732
742
  },
@@ -1031,7 +1041,7 @@ export default{
1031
1041
 
1032
1042
  emits: [ 'close' ],
1033
1043
 
1034
- inject: [ 'confirm', 'socket', 'socketEmit2', 'toast' ],
1044
+ inject: [ 'alert', 'confirm', 'socket', 'socketEmit2', 'toast' ],
1035
1045
 
1036
1046
  mounted() {
1037
1047
  this.load()