Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(field): add code field with vue-codemirror #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/crm-admin-pro
Submodule crm-admin-pro added at e2f0d0
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"element-ui": "^2.12.0",
"normalize.css": "^8.0.1",
"vue": "^2.6.10",
"vue-codemirror": "^4.0.6",
"vue-router": "^3.0.6"
},
"devDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions src/fields/code/__config__/ams.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const config = {
BASE: 'CONFIG_FIELD',
type: {
default: 'code'
},
default: {
type: 'code',
valueType: 'js',
default: ''
}
};

export const defaults = {};
1 change: 1 addition & 0 deletions src/fields/code/__config__/default.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
41 changes: 41 additions & 0 deletions src/fields/code/code.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<div class="code-field-wrapper">
<codemirror
v-model="localValue" :options="cmOptions"
/>
</div>
</template>

<script>
import 'codemirror/mode/javascript/javascript';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/base16-dark.css';
import { codemirror } from 'vue-codemirror'
import mixins from '../../ams/mixins';

export default {
mixins: [mixins.fieldEditMixin],
components: {
codemirror
},
data() {
return {
cmOptions: Object.freeze({
tabSize: 2,
mode: 'text/javascript',
theme: 'base16-dark',
lineNumbers: true,
line: true,
})
};
},
};
</script>
<style lang="scss" scoped>
.code-field-wrapper {
height: 100%;
box-sizing: border-box;
font-size: 14px;
line-height: 1.5;
}
</style>
9 changes: 9 additions & 0 deletions src/fields/code/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import code from './code';

export default {
type: 'code',
install(Vue) {
Vue.component(`ams-field-${this.type}-view`, code);
Vue.component(`ams-field-${this.type}-edit`, code);
}
};
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import tree from './fields/tree';
import link from './fields/link';
import fbutton from './fields/button';
import html from './fields/html';
import code from './fields/code';

// operation
import button from './operations/button';
Expand Down Expand Up @@ -157,6 +158,7 @@ ams.install = function(Vue) {
ams.registerField(link);
ams.registerField(fbutton);
ams.registerField(html);
ams.registerField(code);
// operations
ams.registerOperation(button);
ams.registerOperation(operationsText);
Expand Down