Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 6x 4x 1x 8x 8x 24x 5x 5x 1x 4x 4x 1x 1x 1x 2x 2x 26x 2x 24x | /*
This mixin is shared by all components.
Do not place any component specific logic here!
*/
import { v4 } from 'uuid';
import {
assign,
cloneDeep,
map,
} from 'lodash';
import { storeHelpers } from '../utility';
const uuid = () => v4();
export default {
props: {
definition: {
type: Object,
required: true,
},
unselectable: {
type: Boolean,
default: false,
},
},
computed: {
schema() {
return assign({
uid: uuid(),
parentUid: null,
}, this.config._schema);
},
/* DEPRECATED: Use this.registry in components */
options() {
return this.registry;
},
registry() {
/*
Bundle can access store registry.
If store is not available then fallback to prototype vue instance.
Prototype vue instance is created for testing bundle without builder
and/or for generated apps where this information is also needed.
*/
const registry = this.$store && this.$store.getters.registry;
return registry || this.$chameleon;
},
},
data() {
return {
/*
This is a local copy of definition object.
If component uses reactions to change definition then
config should be mutated. Recommendation is that bundles
use config in their components.
*/
config: {},
/*
Static classes needed for chameleon builder.
This is required for all elements used in builder.
*/
baseClass: 'c-element',
baseParentClass: 'c-element-parent',
baseChildrenClass: 'c-element-children',
};
},
methods: {
/*
DEPRECATED:
Helper function to support element types which are
not namespaces. This should be only used in base
material bundle.
*/
getElementTag(type) {
const separatorIndex = type.indexOf('-');
if (separatorIndex > -1 && separatorIndex <= 2) {
return type;
}
const namespace = this.$options.namespace || 'c-';
return `${namespace}${type}`;
},
/*
Generates data attributes needed
for chameleon builder.
*/
getSchemaAttributes() {
return {
'data-type': this.schema.type,
'data-name': this.schema.name,
'data-group': this.schema.group,
'data-uid': this.schema.uid,
'data-parent': this.schema.parentUid,
};
},
/*
Renders child components of container that
has no specific children like panel, hlist, vlist.
*/
renderChildren() {
const children = this.config.elements;
return map(children, (child) => {
const el = this.$createElement(
this.getElementTag(child.type),
{
staticClass: `${this.$options.name}-item`,
props: {
definition: child,
},
},
);
return el;
});
},
setConfig(value) {
this.config = cloneDeep(value);
},
registerModule(storeModule, state) {
storeHelpers.registerModule(this, storeModule, state);
},
unregisterModule(storeModule, state) {
storeHelpers.unregisterModule(this, storeModule, state);
},
},
watch: {
definition: {
handler(value) {
this.setConfig(value);
},
/*
Arghhhh!
This is not needed in generated apps.
Set it to false when using in generated apps by
setting env variable CHAMELEON_OPTIMIZE.
*/
deep: !process.env.CHAMELEON_OPTIMIZE,
},
},
created() {
this.setConfig(this.definition);
},
};
|