1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-28 13:39:11 +09:00
misskey/src/client/widgets/define.ts
syuilo 69d9aa71f2
Full view mode (#6636)
* wuip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update folder.vue

* wip

* Update size.ts

* wip

* wip

* Update index.vue

* wip
2020-08-09 15:51:02 +09:00

72 lines
1.3 KiB
TypeScript

import Vue from 'vue';
import { Form } from '../scripts/form';
export default function <T extends Form>(data: {
name: string;
props?: () => T;
}) {
return Vue.extend({
props: {
widget: {
type: Object,
required: false
},
isCustomizeMode: {
type: Boolean,
default: false
}
},
computed: {
id(): string {
return this.widget ? this.widget.id : null;
},
props(): Record<string, any> {
return this.widget ? this.widget.data : {};
}
},
created() {
this.mergeProps();
this.$watch('props', () => {
this.mergeProps();
});
},
methods: {
mergeProps() {
if (data.props) {
const defaultProps = data.props();
for (const prop of Object.keys(defaultProps)) {
if (this.props.hasOwnProperty(prop)) continue;
Vue.set(this.props, prop, defaultProps[prop].default);
}
}
},
async setting() {
const form = data.props();
for (const item of Object.keys(form)) {
form[item].default = this.props[item];
}
const { canceled, result } = await this.$root.form(data.name, form);
if (canceled) return;
for (const key of Object.keys(result)) {
Vue.set(this.props, key, result[key]);
}
this.save();
},
save() {
if (this.widget) {
this.$store.commit('deviceUser/updateWidget', this.widget);
}
}
}
});
}