@appscode/design-system 1.0.43-alpha.146 → 1.0.43-alpha.147

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@appscode/design-system",
3
- "version": "1.0.43-alpha.146",
3
+ "version": "1.0.43-alpha.147",
4
4
  "description": "A design system for Appscode websites and dashboards made using Bulma",
5
5
  "main": "main.scss",
6
6
  "scripts": {
@@ -7,11 +7,11 @@
7
7
  />
8
8
  <monaco-editor
9
9
  v-if="activeTab === 'edit'"
10
- ref="monacoEditor"
11
10
  @editorDidMount="onEditorMount"
12
11
  key="edit"
13
12
  :class="`vh-${editorHeight} is-clipped`"
14
- v-model="editorContent"
13
+ :value="editorContent"
14
+ @change="onChange"
15
15
  :language="language"
16
16
  :options="{
17
17
  minimap: {
@@ -82,10 +82,11 @@ export default {
82
82
  default: "off",
83
83
  },
84
84
  },
85
+
85
86
  components: {
86
87
  EditorTabs: () => import("../tabs/EditorTabs.vue"),
87
88
  MonacoEditor: () => ({
88
- component: import("vue-monaco"),
89
+ component: import("./MonacoEditor.vue"),
89
90
  loading: Preloader,
90
91
  delay: 200,
91
92
  error: Banner,
@@ -136,8 +137,10 @@ export default {
136
137
  },
137
138
 
138
139
  methods: {
139
- onEditorMount() {
140
- const editor = this.$refs.monacoEditor.getEditor();
140
+ onChange(e) {
141
+ if (typeof e === "string") this.editorContent = e;
142
+ },
143
+ onEditorMount(editor) {
141
144
  // add event listeners
142
145
  editor.onDidBlurEditorText(() => {
143
146
  this.$emit("input", this.editorContent);
@@ -0,0 +1,125 @@
1
+ <template>
2
+ <div class="monaco-editor-vue2" :style="style"></div>
3
+ </template>
4
+
5
+ <script>
6
+ import * as monaco from "monaco-editor";
7
+
8
+ export default {
9
+ name: "MonacoEditor",
10
+ props: {
11
+ diffEditor: { type: Boolean, default: false },
12
+ width: { type: [String, Number], default: "100%" },
13
+ height: { type: [String, Number], default: "100%" },
14
+ original: String,
15
+ value: String,
16
+ language: { type: String, default: "javascript" },
17
+ theme: { type: String, default: "vs" },
18
+ options: {
19
+ type: Object,
20
+ default() {
21
+ return {};
22
+ },
23
+ },
24
+ },
25
+ computed: {
26
+ style() {
27
+ const fixedWidth = this.width.toString().includes("%")
28
+ ? this.width
29
+ : `${this.width}px`;
30
+ const fixedHeight = this.height.toString().includes("%")
31
+ ? this.height
32
+ : `${this.height}px`;
33
+ return {
34
+ width: fixedWidth,
35
+ height: fixedHeight,
36
+ "text-align": "left",
37
+ };
38
+ },
39
+ },
40
+ mounted() {
41
+ this.initMonaco();
42
+ },
43
+ beforeDestroy() {
44
+ this.editor && this.editor.dispose();
45
+ },
46
+ methods: {
47
+ initMonaco() {
48
+ this.$emit("editorWillMount", this.monaco);
49
+ const { value, language, theme, options } = this;
50
+ this.editor = monaco.editor[
51
+ this.diffEditor ? "createDiffEditor" : "create"
52
+ ](this.$el, {
53
+ value: value,
54
+ language: language,
55
+ theme: theme,
56
+ ...options,
57
+ });
58
+ this.diffEditor && this._setModel(this.value, this.original);
59
+
60
+ // @event `change`
61
+ const editor = this._getEditor();
62
+ editor.onDidChangeModelContent((event) => {
63
+ const value = editor.getValue();
64
+ if (this.value !== value) {
65
+ this.$emit("change", value, event);
66
+ }
67
+ });
68
+
69
+ this.$emit("editorDidMount", this.editor);
70
+ },
71
+ _setModel(value, original) {
72
+ const { language } = this;
73
+ const originalModel = monaco.editor.createModel(original, language);
74
+ const modifiedModel = monaco.editor.createModel(value, language);
75
+ this.editor.setModel({
76
+ original: originalModel,
77
+ modified: modifiedModel,
78
+ });
79
+ },
80
+ _setValue(value) {
81
+ let editor = this._getEditor();
82
+ if (editor) return editor.setValue(value);
83
+ },
84
+ _getValue() {
85
+ let editor = this._getEditor();
86
+ if (!editor) return "";
87
+ return editor.getValue();
88
+ },
89
+ _getEditor() {
90
+ if (!this.editor) return null;
91
+ return this.diffEditor ? this.editor.getModifiedEditor() : this.editor;
92
+ },
93
+ _setOriginal() {
94
+ const { original } = this.editor.getModel();
95
+ original.setValue(this.original);
96
+ },
97
+ },
98
+ watch: {
99
+ options: {
100
+ deep: true,
101
+ handler(options) {
102
+ this.editor.updateOptions(options);
103
+ },
104
+ },
105
+ value() {
106
+ this.value !== this._getValue() && this._setValue(this.value);
107
+ },
108
+ original() {
109
+ this._setOriginal();
110
+ },
111
+ language() {
112
+ if (!this.editor) return;
113
+ if (this.diffEditor) {
114
+ const { original, modified } = this.editor.getModel();
115
+ monaco.editor.setModelLanguage(original, this.language);
116
+ monaco.editor.setModelLanguage(modified, this.language);
117
+ } else
118
+ monaco.editor.setModelLanguage(this.editor.getModel(), this.language);
119
+ },
120
+ theme() {
121
+ monaco.editor.setTheme(this.theme);
122
+ },
123
+ },
124
+ };
125
+ </script>
@@ -6,7 +6,7 @@
6
6
  v-if="showModal"
7
7
  class="ac-modal is-middle-alignment"
8
8
  :class="modifierClasses"
9
- @click.self="destroyModal"
9
+ @click.self="onModalOutsideClick"
10
10
  >
11
11
  <div class="ac-modal-inner">
12
12
  <!-- modal header start -->
@@ -37,7 +37,9 @@
37
37
  <!-- modal body end -->
38
38
 
39
39
  <!-- modal footer start -->
40
- <div class="ac-modal-footer action-footer is-flex is-align-items-center is-justify-content-space-between">
40
+ <div
41
+ class="ac-modal-footer action-footer is-flex is-align-items-center is-justify-content-space-between"
42
+ >
41
43
  <div>
42
44
  <slot name="modal-footer-left" />
43
45
  </div>
@@ -58,36 +60,40 @@ export default defineComponent({
58
60
  props: {
59
61
  open: {
60
62
  type: Boolean,
61
- default: false,
63
+ default: false
62
64
  },
63
65
  title: {
64
66
  type: String,
65
- default: "Modal",
67
+ default: "Modal"
66
68
  },
67
69
  modifierClasses: {
68
70
  type: String,
69
- default: "",
71
+ default: ""
70
72
  },
71
73
  isCloseOptionDisabled: {
72
74
  type: Boolean,
73
- default: false,
75
+ default: false
76
+ },
77
+ ignoreOutsideClick: {
78
+ type: Boolean,
79
+ default: false
74
80
  }
75
81
  },
76
82
  emits: ["closemodal"],
77
83
 
78
84
  components: {
79
85
  HeaderItems: defineAsyncComponent(() =>
80
- import("../../v2/header/HeaderItems.vue").then((module) => module.default)
86
+ import("../../v2/header/HeaderItems.vue").then(module => module.default)
81
87
  ),
82
88
  HeaderItem: defineAsyncComponent(() =>
83
- import("../../v2/header/HeaderItem.vue").then((module) => module.default)
89
+ import("../../v2/header/HeaderItem.vue").then(module => module.default)
84
90
  ),
85
91
  Buttons: defineAsyncComponent(() =>
86
- import("../../v2/button/Buttons.vue").then((module) => module.default)
92
+ import("../../v2/button/Buttons.vue").then(module => module.default)
87
93
  ),
88
94
  AcButton: defineAsyncComponent(() =>
89
- import("../button/Button.vue").then((module) => module.default)
90
- ),
95
+ import("../button/Button.vue").then(module => module.default)
96
+ )
91
97
  },
92
98
 
93
99
  data() {
@@ -95,7 +101,7 @@ export default defineComponent({
95
101
  showModal: false,
96
102
  crossIcon: import.meta.globEager(
97
103
  "/src/assets/icons/modal/close-icon.svg"
98
- )["/src/assets/icons/modal/close-icon.svg"].default,
104
+ )["/src/assets/icons/modal/close-icon.svg"].default
99
105
  };
100
106
  },
101
107
 
@@ -108,8 +114,8 @@ export default defineComponent({
108
114
  } else {
109
115
  this.destroyModal();
110
116
  }
111
- },
112
- },
117
+ }
118
+ }
113
119
  },
114
120
 
115
121
  methods: {
@@ -123,13 +129,17 @@ export default defineComponent({
123
129
  this.showModal = true;
124
130
  document.addEventListener("keydown", this.onKeyDown);
125
131
  },
132
+ onModalOutsideClick() {
133
+ if (this.ignoreOutsideClick) return;
134
+ this.destroyModal();
135
+ },
126
136
  destroyModal() {
127
137
  if (this.isCloseOptionDisabled) return;
128
138
  this.showModal = false;
129
139
  document.removeEventListener("keydown", this.onKeyDown);
130
140
 
131
141
  this.$emit("closemodal", true);
132
- },
133
- },
142
+ }
143
+ }
134
144
  });
135
145
  </script>