-
Notifications
You must be signed in to change notification settings - Fork 626
Expand file tree
/
Copy pathAposSchema.vue
More file actions
159 lines (137 loc) · 4.47 KB
/
AposSchema.vue
File metadata and controls
159 lines (137 loc) · 4.47 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!--
AposSchema takes an array of fields (`schema`), renders their inputs,
and emits a new object with a `value` subproperty and a `hasErrors`
subproperty via the input event whenever the value of a field
or subfield changes.
At mount time the fields are initialized from the subproperties of the
`value.data` prop.
For performance reasons, this component is not strictly v-model compliant.
While all changes will emit an outgoing `input` event, the
incoming `value` prop only updates the fields in three situations:
1. At mount time, to set the initial values of the fields.
2. When `value.data._id` changes (an entirely different document is in play).
3. When the optional prop `generation` changes to a new number. This
prop is also passed on to the individual input field components.
If you need to force an update from the calling component, increment the
`generation` prop. This should be done only if the value has changed for
an external reason.
-->
<template>
<component
:is="fieldStyle === 'table' ? 'tr' : 'div'"
class="apos-schema"
:class="classes"
>
<slot name="before" />
<component
:is="fieldStyle === 'table' ? 'td' : 'div'"
v-for="field in schema"
:key="generateItemUniqueKey(field)"
:data-apos-field="field.name"
:style="(fieldStyle === 'table' && field.columnStyle) || {}"
:class="{'apos-field--hidden': !displayComponent(field)}"
>
<component
:is="fieldComponentMap[field.type]"
:ref="field.name"
v-model="fieldState[field.name]"
:class="{ 'apos-field__wrapper--highlight': highlight(field.name) }"
:following-values="followingValues[field.name]"
:condition-met="conditionalFields?.if[field.name]"
:field="fields[field.name].field"
:meta="meta"
:modifiers="fields[field.name].modifiers"
:display-options="getDisplayOptions(field.name)"
:trigger-validation="triggerValidation"
:server-error="fields[field.name].serverError"
:doc-id="docId"
:generation="generation"
@update-doc-data="onUpdateDocData"
@validate="emitValidate()"
/>
<component
:is="fieldComponentMap[field.type]"
v-if="hasCompareMeta"
v-show="displayComponent(field)"
:ref="field.name"
v-model="compareMetaState[field.name]"
:class="{ 'apos-field__wrapper--highlight': highlight(field.name) }"
:following-values="followingValues[field.name]"
:condition-met="conditionalFields?.if[field.name]"
:field="fields[field.name].field"
:meta="meta"
:modifiers="fields[field.name].modifiers"
:display-options="getDisplayOptions(field.name)"
:trigger-validation="triggerValidation"
:server-error="fields[field.name].serverError"
:doc-id="docId"
:generation="generation"
@update-doc-data="onUpdateDocData"
@validate="emitValidate()"
/>
</component>
<slot name="after" />
</component>
</template>
<script>
import AposSchemaLogic from '../logic/AposSchema';
export default {
name: 'AposSchema',
mixins: [ AposSchemaLogic ]
};
</script>
<style lang="scss" scoped>
.apos-schema {
line-height: var(--a-line-base);
}
.apos-schema :deep(.apos-field__wrapper) {
max-width: $input-max-width;
}
.apos-schema :deep(.apos-field__wrapper.apos-field__wrapper--full-width) {
max-width: inherit;
}
.apos-schema :deep(img) {
max-width: 100%;
}
.apos-schema .apos-field--hidden {
display: none;
}
.apos-schema :deep(.apos-field) {
margin-bottom: $spacing-quadruple;
&.apos-field--small,
&.apos-field--micro,
&.apos-field--margin-micro {
margin-bottom: $spacing-double;
}
&.apos-field--margin-none {
margin-bottom: 0;
}
}
.apos-field .apos-schema :deep(.apos-toolbar) {
margin-bottom: 0;
}
.apos-schema.apos-schema--compare > :deep([data-apos-field]) {
display: flex;
&.apos-field--hidden {
display: none;
}
& > .apos-field__wrapper {
flex-basis: 50%;
flex-grow: 1;
padding-right: 20px;
border-right: 1px solid var(--a-base-9);
}
& > .apos-field__wrapper + .apos-field__wrapper {
padding-right: 0;
padding-left: 20px;
border-right: none;
}
& .apos-field__label {
word-break: break-all;
}
}
:deep(.apos-field__wrapper--highlight > .apos-field) {
padding: 10px;
background: var(--a-highlight);
}
</style>