mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 22:56:43 -06:00
70 lines
1.1 KiB
TypeScript
70 lines
1.1 KiB
TypeScript
import Vue from 'vue';
|
|
|
|
export default function <T extends object>(data: {
|
|
name: string;
|
|
props?: () => T;
|
|
}) {
|
|
return Vue.extend({
|
|
props: {
|
|
widget: {
|
|
type: Object
|
|
},
|
|
column: {
|
|
type: Object,
|
|
default: null
|
|
},
|
|
platform: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
isCustomizeMode: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
|
|
computed: {
|
|
id(): string {
|
|
return this.widget.id;
|
|
},
|
|
|
|
props(): T {
|
|
return this.widget.data;
|
|
}
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
bakedOldProps: null
|
|
};
|
|
},
|
|
|
|
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]);
|
|
}
|
|
}
|
|
},
|
|
|
|
save() {
|
|
if (this.platform == 'deck') {
|
|
this.$store.commit('updateDeckColumn', this.column);
|
|
} else {
|
|
this.$store.commit('updateWidget', this.widget);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|