@appscode/design-system 2.0.22-alpha.6 → 2.0.23-alpha.1
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
|
@@ -10,6 +10,10 @@ interface Props {
|
|
|
10
10
|
editorHeight?: number | string;
|
|
11
11
|
editorTheme?: string;
|
|
12
12
|
wordWrap?: string;
|
|
13
|
+
validation?: {
|
|
14
|
+
schema?: Record<string, unknown>;
|
|
15
|
+
uri: string;
|
|
16
|
+
};
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -21,6 +25,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
21
25
|
editorHeight: 40,
|
|
22
26
|
editorTheme: "",
|
|
23
27
|
wordWrap: "on",
|
|
28
|
+
validation: () => ({ uri: "" }),
|
|
24
29
|
});
|
|
25
30
|
|
|
26
31
|
const emit = defineEmits(["update:modelValue"]);
|
|
@@ -111,22 +116,10 @@ watch(
|
|
|
111
116
|
|
|
112
117
|
<template>
|
|
113
118
|
<div>
|
|
114
|
-
<editor-tabs
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
:
|
|
118
|
-
/>
|
|
119
|
-
<monaco-editor
|
|
120
|
-
v-if="activeTab === 'edit'"
|
|
121
|
-
@editorDidMount="onEditorMount"
|
|
122
|
-
key="edit"
|
|
123
|
-
class="is-clipped"
|
|
124
|
-
:class="computeHightInClass"
|
|
125
|
-
:style="computeHightInStyle"
|
|
126
|
-
:value="editorContent"
|
|
127
|
-
@change="onChange"
|
|
128
|
-
:language="language"
|
|
129
|
-
:options="{
|
|
119
|
+
<editor-tabs v-if="!readOnly" @tabchange="activeTab = $event" :active-tab="activeTab" />
|
|
120
|
+
<monaco-editor v-if="activeTab === 'edit'" @editorDidMount="onEditorMount" key="edit" class="is-clipped"
|
|
121
|
+
:class="computeHightInClass" :style="computeHightInStyle" :value="editorContent" @change="onChange"
|
|
122
|
+
:language="language" :options="{
|
|
130
123
|
minimap: {
|
|
131
124
|
enabled: calcShowMinimap,
|
|
132
125
|
},
|
|
@@ -134,18 +127,9 @@ watch(
|
|
|
134
127
|
readOnly: readOnly,
|
|
135
128
|
wordWrap: wordWrap,
|
|
136
129
|
scrollBeyondLastLine: false,
|
|
137
|
-
}"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
<monaco-editor
|
|
141
|
-
v-if="activeTab === 'preview'"
|
|
142
|
-
key="preview"
|
|
143
|
-
class="is-clipped"
|
|
144
|
-
:class="computeHightInClass"
|
|
145
|
-
:style="computeHightInStyle"
|
|
146
|
-
:value="editorContent"
|
|
147
|
-
:language="language"
|
|
148
|
-
:options="{
|
|
130
|
+
}" :validation="validation" data-testid="monaco-editor-edit-section" />
|
|
131
|
+
<monaco-editor v-if="activeTab === 'preview'" key="preview" class="is-clipped" :class="computeHightInClass"
|
|
132
|
+
:style="computeHightInStyle" :value="editorContent" :language="language" :options="{
|
|
149
133
|
minimap: {
|
|
150
134
|
enabled: calcShowMinimap,
|
|
151
135
|
},
|
|
@@ -153,10 +137,7 @@ watch(
|
|
|
153
137
|
readOnly: true,
|
|
154
138
|
wordWrap: wordWrap,
|
|
155
139
|
scrollBeyondLastLine: false,
|
|
156
|
-
}"
|
|
157
|
-
|
|
158
|
-
:diff-editor="true"
|
|
159
|
-
data-testid="monaco-editor-preview-section"
|
|
160
|
-
/>
|
|
140
|
+
}" :original="originalEditorContent" :diff-editor="true" :validation="validation"
|
|
141
|
+
data-testid="monaco-editor-preview-section" />
|
|
161
142
|
</div>
|
|
162
143
|
</template>
|
|
@@ -22,6 +22,10 @@ export default defineComponent({
|
|
|
22
22
|
return {};
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
+
validation: {
|
|
26
|
+
type: Object,
|
|
27
|
+
default: () => ({}),
|
|
28
|
+
},
|
|
25
29
|
},
|
|
26
30
|
emits: ["editorWillMount", "editorDidMount", "change"],
|
|
27
31
|
setup(props) {
|
|
@@ -47,21 +51,73 @@ export default defineComponent({
|
|
|
47
51
|
this.initMonaco();
|
|
48
52
|
},
|
|
49
53
|
beforeUnmount() {
|
|
54
|
+
monaco.editor.getModels().forEach((model) => model.dispose());
|
|
50
55
|
this.editor && this.editor.dispose();
|
|
51
56
|
},
|
|
52
57
|
methods: {
|
|
53
58
|
initMonaco() {
|
|
54
59
|
this.$emit("editorWillMount", this.monaco);
|
|
55
|
-
const { value, language, theme, options } = this;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const { value, language, theme, options, original, validation } = this;
|
|
61
|
+
|
|
62
|
+
if (!this.diffEditor) {
|
|
63
|
+
const modifiedModel = monaco.editor.createModel(
|
|
64
|
+
value,
|
|
65
|
+
language,
|
|
66
|
+
monaco.Uri.parse("file:///file.yaml")
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (validation.uri) {
|
|
70
|
+
const schemas = [
|
|
71
|
+
{
|
|
72
|
+
fileMatch: ["file:///file.yaml"],
|
|
73
|
+
schema: validation.schema
|
|
74
|
+
? JSON.parse(
|
|
75
|
+
JSON.stringify({
|
|
76
|
+
...validation.schema,
|
|
77
|
+
$schema: "http://json-schema.org/schema#",
|
|
78
|
+
})
|
|
79
|
+
)
|
|
80
|
+
: undefined,
|
|
81
|
+
uri: validation.uri,
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
// yaml validation
|
|
85
|
+
if (this.$monacoYaml) {
|
|
86
|
+
this.$monacoYaml.update({
|
|
87
|
+
schemas,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// json validation
|
|
92
|
+
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
93
|
+
validate: true,
|
|
94
|
+
enableSchemaRequest: true,
|
|
95
|
+
schemas,
|
|
96
|
+
allowComments: true,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.editor = monaco.editor.create(this.$el, {
|
|
101
|
+
automaticLayout: true,
|
|
102
|
+
model: modifiedModel,
|
|
103
|
+
theme: theme,
|
|
104
|
+
fixedOverflowWidgets: true,
|
|
105
|
+
...options,
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
const originalModel = monaco.editor.createModel(original, language);
|
|
109
|
+
const modifiedModel = monaco.editor.createModel(value, language);
|
|
110
|
+
this.editor = monaco.editor.createDiffEditor(this.$el, {
|
|
111
|
+
automaticLayout: true,
|
|
112
|
+
theme: theme,
|
|
113
|
+
fixedOverflowWidgets: true,
|
|
114
|
+
...options,
|
|
115
|
+
});
|
|
116
|
+
this.editor.setModel({
|
|
117
|
+
original: originalModel,
|
|
118
|
+
modified: modifiedModel,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
65
121
|
|
|
66
122
|
// @event `change`
|
|
67
123
|
const editor = this._getEditor();
|
|
@@ -74,15 +130,6 @@ export default defineComponent({
|
|
|
74
130
|
|
|
75
131
|
this.$emit("editorDidMount", this.editor);
|
|
76
132
|
},
|
|
77
|
-
_setModel(value, original) {
|
|
78
|
-
const { language } = this;
|
|
79
|
-
const originalModel = monaco.editor.createModel(original, language);
|
|
80
|
-
const modifiedModel = monaco.editor.createModel(value, language);
|
|
81
|
-
this.editor.setModel({
|
|
82
|
-
original: originalModel,
|
|
83
|
-
modified: modifiedModel,
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
133
|
_setValue(value) {
|
|
87
134
|
let editor = this._getEditor();
|
|
88
135
|
if (editor) return editor.setValue(value);
|
|
@@ -128,4 +175,4 @@ export default defineComponent({
|
|
|
128
175
|
},
|
|
129
176
|
},
|
|
130
177
|
});
|
|
131
|
-
</script>
|
|
178
|
+
</script>
|