@kinetis/vector-ui 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/app/components/Vx/Cell/BooleanGroup.vue +20 -0
- package/app/components/Vx/Cell/Country.vue +13 -0
- package/app/components/Vx/Cell/Json.vue +2 -8
- package/app/components/Vx/Cell/Repeater.vue +64 -0
- package/app/components/Vx/Cell/Select.vue +26 -0
- package/app/components/Vx/Cell/Tag.vue +15 -0
- package/app/components/Vx/CommandPalette.vue +5 -2
- package/app/components/Vx/Import/Dialog.vue +2 -1
- package/app/components/Vx/Input/BooleanGroup.vue +39 -0
- package/app/components/Vx/Input/Country.vue +14 -0
- package/app/components/Vx/Input/Json.vue +63 -0
- package/app/components/Vx/Input/Repeater.vue +142 -35
- package/app/components/Vx/Input/Select.vue +31 -0
- package/app/components/Vx/Input/Tag.vue +47 -0
- package/app/components/Vx/Input/Textarea.vue +0 -1
- package/app/components/Vx/Layout.vue +1 -1
- package/app/components/Vx/List/BulkEdit.vue +2 -1
- package/app/components/Vx/List/FilterBar.vue +25 -5
- package/app/components/Vx/Resource/Audit.vue +2 -1
- package/app/components/Vx/Resource/Form.vue +13 -10
- package/app/composables/useVectorCountryNames.ts +38 -0
- package/app/composables/useVectorFields.ts +5 -1
- package/app/composables/useVectorForm.ts +27 -3
- package/app/composables/useVectorInputs.ts +7 -5
- package/app/i18n/ar/fields.ts +15 -0
- package/app/i18n/ar/list.ts +2 -0
- package/app/i18n/de/fields.ts +15 -0
- package/app/i18n/de/list.ts +2 -0
- package/app/i18n/en/fields.ts +15 -0
- package/app/i18n/en/list.ts +2 -0
- package/app/i18n/es/fields.ts +15 -0
- package/app/i18n/es/list.ts +2 -0
- package/app/i18n/fr/fields.ts +15 -0
- package/app/i18n/fr/list.ts +2 -0
- package/app/i18n/he/fields.ts +15 -0
- package/app/i18n/he/list.ts +2 -0
- package/app/i18n/it/fields.ts +15 -0
- package/app/i18n/it/list.ts +2 -0
- package/app/i18n/ja/fields.ts +15 -0
- package/app/i18n/ja/list.ts +2 -0
- package/app/i18n/ko/fields.ts +15 -0
- package/app/i18n/ko/list.ts +2 -0
- package/app/i18n/nl/fields.ts +15 -0
- package/app/i18n/nl/list.ts +2 -0
- package/app/i18n/pl/fields.ts +15 -0
- package/app/i18n/pl/list.ts +2 -0
- package/app/i18n/pt/fields.ts +15 -0
- package/app/i18n/pt/list.ts +2 -0
- package/app/i18n/pt-BR/fields.ts +15 -0
- package/app/i18n/pt-BR/list.ts +2 -0
- package/app/i18n/ru/fields.ts +15 -0
- package/app/i18n/ru/list.ts +2 -0
- package/app/i18n/tr/fields.ts +15 -0
- package/app/i18n/tr/list.ts +2 -0
- package/app/i18n/uk/fields.ts +15 -0
- package/app/i18n/uk/list.ts +2 -0
- package/app/i18n/zh-Hans/fields.ts +15 -0
- package/app/i18n/zh-Hans/list.ts +2 -0
- package/app/types/vector.ts +47 -8
- package/app/utils/countries/ar.ts +252 -0
- package/app/utils/countries/de.ts +252 -0
- package/app/utils/countries/en.ts +252 -0
- package/app/utils/countries/es.ts +252 -0
- package/app/utils/countries/fr.ts +252 -0
- package/app/utils/countries/he.ts +252 -0
- package/app/utils/countries/index.ts +44 -0
- package/app/utils/countries/it.ts +252 -0
- package/app/utils/countries/ja.ts +252 -0
- package/app/utils/countries/ko.ts +252 -0
- package/app/utils/countries/nl.ts +252 -0
- package/app/utils/countries/pl.ts +252 -0
- package/app/utils/countries/pt-BR.ts +252 -0
- package/app/utils/countries/pt.ts +252 -0
- package/app/utils/countries/ru.ts +252 -0
- package/app/utils/countries/tr.ts +252 -0
- package/app/utils/countries/uk.ts +252 -0
- package/app/utils/countries/zh-Hans.ts +252 -0
- package/app/utils/internal/repeater.ts +26 -0
- package/app/utils/rules.ts +7 -4
- package/dist/static/200.html +1 -1
- package/dist/static/404.html +1 -1
- package/dist/static/_nuxt/{CVGEoUmj.js → 1608Z87P.js} +1 -1
- package/dist/static/_nuxt/26EG815s.js +1 -0
- package/dist/static/_nuxt/{y5gvPoD3.js → 5DQbzGzQ.js} +1 -1
- package/dist/static/_nuxt/6LnFMZ9h.js +1 -0
- package/dist/static/_nuxt/{B65UlNtP.js → 81b_JWVP.js} +1 -1
- package/dist/static/_nuxt/951AFxTF.js +1 -0
- package/dist/static/_nuxt/{DDsQjoa8.js → B-3DkDEW.js} +1 -1
- package/dist/static/_nuxt/{BSj4WTjT.js → B-OK38pz.js} +1 -1
- package/dist/static/_nuxt/B4lOfJ_0.js +1 -0
- package/dist/static/_nuxt/{DwpSsR4l.js → B5Jt7Eqg.js} +1 -1
- package/dist/static/_nuxt/{CWfptrnU.js → B9JchbmS.js} +1 -1
- package/dist/static/_nuxt/{Dao3p0cp.js → BAH3b61H.js} +1 -1
- package/dist/static/_nuxt/BAkfhUIC.js +1 -0
- package/dist/static/_nuxt/BAz8wQLD.js +1 -0
- package/dist/static/_nuxt/BDoRuUKE.js +1 -0
- package/dist/static/_nuxt/{DOEj9Txc.js → BHK5j1Wx.js} +1 -1
- package/dist/static/_nuxt/{B-b861aP.js → BJ0_qGcm.js} +1 -1
- package/dist/static/_nuxt/BLF1JZGX.js +1 -0
- package/dist/static/_nuxt/BLZaIPT-.js +1 -0
- package/dist/static/_nuxt/BPF07eww.js +1 -0
- package/dist/static/_nuxt/{DGQrzV9s.js → BPXec4rF.js} +1 -1
- package/dist/static/_nuxt/BRKbRioI.js +1 -0
- package/dist/static/_nuxt/{B2rZ5lwu.js → BRRBOyND.js} +1 -1
- package/dist/static/_nuxt/{DHNZ4ANp.js → BTJZEoE6.js} +1 -1
- package/dist/static/_nuxt/{XnbMqODk.js → BU7J96HZ.js} +1 -1
- package/dist/static/_nuxt/{CE5HzlKJ.js → BUzE9uBK.js} +1 -1
- package/dist/static/_nuxt/BV8jrBHa.js +1 -0
- package/dist/static/_nuxt/BVtNJY11.js +1 -0
- package/dist/static/_nuxt/BW2cAI58.js +1 -0
- package/dist/static/_nuxt/{B9s6vEby.js → BXXQNvGc.js} +1 -1
- package/dist/static/_nuxt/{DdYMnBKs.js → B_CsPjDm.js} +1 -1
- package/dist/static/_nuxt/{CLJSzUt5.js → B_VpcKtj.js} +1 -1
- package/dist/static/_nuxt/BaztYiAl.js +1 -0
- package/dist/static/_nuxt/{DYPYEI74.js → BfkrLuli.js} +1 -1
- package/dist/static/_nuxt/{BQitPbA5.js → Bg7Wm7qC.js} +1 -1
- package/dist/static/_nuxt/{B8JL5gwX.js → Bk8atvdO.js} +1 -1
- package/dist/static/_nuxt/BklrzIIE.js +1 -0
- package/dist/static/_nuxt/Bl60DsIN.js +1 -0
- package/dist/static/_nuxt/{Clx69IQe.js → BoceWX8_.js} +1 -1
- package/dist/static/_nuxt/BooleanGroup.Ctn8QJv3.css +1 -0
- package/dist/static/_nuxt/BqdQqPGG.js +1 -0
- package/dist/static/_nuxt/{CFuvN8kq.js → BsHddetz.js} +1 -1
- package/dist/static/_nuxt/BtBn_mmM.js +1 -0
- package/dist/static/_nuxt/BtWvh8h-.js +1 -0
- package/dist/static/_nuxt/ByM6U2Qe.js +1 -0
- package/dist/static/_nuxt/C2ZWScju.js +1 -0
- package/dist/static/_nuxt/C6doA815.js +1 -0
- package/dist/static/_nuxt/CALBeSnc.js +1 -0
- package/dist/static/_nuxt/CB2gkR4K.js +1 -0
- package/dist/static/_nuxt/CCXHWF63.js +1 -0
- package/dist/static/_nuxt/CCnG_04Y.js +1 -0
- package/dist/static/_nuxt/CDzeC03e.js +1 -0
- package/dist/static/_nuxt/{BJxaGigr.js → CFgMeWCA.js} +1 -1
- package/dist/static/_nuxt/CG1HFqc_.js +1 -0
- package/dist/static/_nuxt/CGdWq8l5.js +1 -0
- package/dist/static/_nuxt/{CSgLLbCN.js → CJCWDpGq.js} +1 -1
- package/dist/static/_nuxt/{DcC5rHQt.js → CKfr82y9.js} +1 -1
- package/dist/static/_nuxt/CMc4sXE8.js +1 -0
- package/dist/static/_nuxt/CMqJrosi.js +1 -0
- package/dist/static/_nuxt/{CF_C4t63.js → CRKTuX5e.js} +1 -1
- package/dist/static/_nuxt/{tv5vSe5Y.js → CS--aGS9.js} +1 -1
- package/dist/static/_nuxt/{BJh6qVAK.js → CVQf7G1i.js} +1 -1
- package/dist/static/_nuxt/CVnTGJCS.js +1 -0
- package/dist/static/_nuxt/{vbxP0T99.js → CXfD1O41.js} +11 -11
- package/dist/static/_nuxt/{DAXm0JlI.js → CZJzNdT8.js} +1 -1
- package/dist/static/_nuxt/Cdge5zAy.js +1 -0
- package/dist/static/_nuxt/CghQmIiQ.js +2 -0
- package/dist/static/_nuxt/{2u7wMpR1.js → Ci8knhX0.js} +1 -1
- package/dist/static/_nuxt/CjX9KrPv.js +1 -0
- package/dist/static/_nuxt/{Bw6FrC2B.js → CkYhLHis.js} +1 -1
- package/dist/static/_nuxt/{Dw7WalTb.js → CrHibPfx.js} +1 -1
- package/dist/static/_nuxt/CrVTXZp1.js +2 -0
- package/dist/static/_nuxt/CuOAA5sP.js +1 -0
- package/dist/static/_nuxt/{Bl4F_9Di.js → CuW09Pf9.js} +1 -1
- package/dist/static/_nuxt/D4MxxnmM.js +1 -0
- package/dist/static/_nuxt/D52PLnR1.js +1 -0
- package/dist/static/_nuxt/DFM4TY5F.js +1 -0
- package/dist/static/_nuxt/DG9iSq1o.js +1 -0
- package/dist/static/_nuxt/{CRAHgjs4.js → DK-FyJq0.js} +1 -1
- package/dist/static/_nuxt/{AbcTnLPe.js → DL-Y-SrR.js} +1 -1
- package/dist/static/_nuxt/DMsb54_5.js +2 -0
- package/dist/static/_nuxt/{CD5zJmlk.js → DPDKc2ix.js} +1 -1
- package/dist/static/_nuxt/DSzAMcFx.js +1 -0
- package/dist/static/_nuxt/DTacXreK.js +1 -0
- package/dist/static/_nuxt/DXCyzcMc.js +2 -0
- package/dist/static/_nuxt/DaThP9To.js +1 -0
- package/dist/static/_nuxt/{DryMzf1V.js → DoBDwz9i.js} +1 -1
- package/dist/static/_nuxt/{CIcNJyjb.js → Doofu92H.js} +1 -1
- package/dist/static/_nuxt/{SacKuioS.js → DvUd-qQE.js} +1 -1
- package/dist/static/_nuxt/ETG88Leh.js +1 -0
- package/dist/static/_nuxt/{WAarVmAq.js → IeIjl2of.js} +1 -1
- package/dist/static/_nuxt/MCKoiB3E.js +1 -0
- package/dist/static/_nuxt/{CjYmnU-l.js → NWmnUlHT.js} +1 -1
- package/dist/static/_nuxt/QPvezGDN.js +1 -0
- package/dist/static/_nuxt/QfM1ukFT.js +1 -0
- package/dist/static/_nuxt/RHss5Znh.js +1 -0
- package/dist/static/_nuxt/Repeater.Dt7fQjxv.css +1 -0
- package/dist/static/_nuxt/Rvt5jKoB.js +1 -0
- package/dist/static/_nuxt/{BowgCQje.js → UOMH3sKh.js} +1 -1
- package/dist/static/_nuxt/VCombobox.xsOJFBr8.css +1 -0
- package/dist/static/_nuxt/Yxj3clqu.js +1 -0
- package/dist/static/_nuxt/ZgjlRAd9.js +1 -0
- package/dist/static/_nuxt/{_resource_.Q2lVCG-n.css → _resource_.DiGLdv9u.css} +1 -1
- package/dist/static/_nuxt/builds/latest.json +1 -1
- package/dist/static/_nuxt/builds/meta/691bfc1d-4be7-4e21-9e24-735eb94ef678.json +1 -0
- package/dist/static/_nuxt/{CHIGMs2v.js → jFK8N1q6.js} +1 -1
- package/dist/static/_nuxt/{DOq2YmIE.js → k4v9WOKm.js} +1 -1
- package/dist/static/_nuxt/{yIw8BzU6.js → lSAJcvgX.js} +1 -1
- package/dist/static/_nuxt/{B8wNbnS0.js → nJa3B-VU.js} +1 -1
- package/dist/static/_nuxt/{Cpel4vlt.js → sjOc3hy9.js} +1 -1
- package/dist/static/_nuxt/wFK8Gpv4.js +1 -0
- package/dist/static/_nuxt/{HdAGfEVj.js → xCL8Cexv.js} +1 -1
- package/dist/static/_nuxt/yks44VUO.js +1 -0
- package/dist/static/_nuxt/ypCgn3lo.js +1 -0
- package/dist/static/_nuxt/zY76lC6C.js +1 -0
- package/dist/static/index.html +1 -1
- package/dist/static/jobs/index.html +1 -1
- package/dist/static/login/index.html +1 -1
- package/dist/static/queues/index.html +1 -1
- package/dist/static/settings/index.html +1 -1
- package/dist/static/vector-bundle.json +124 -91
- package/package.json +1 -1
- package/app/components/Vx/Cell/Enum.vue +0 -14
- package/app/components/Vx/Input/Enum.vue +0 -21
- package/dist/static/_nuxt/-ksGenLl.js +0 -1
- package/dist/static/_nuxt/0Q9tQaGZ.js +0 -1
- package/dist/static/_nuxt/7hLwEPpo.js +0 -1
- package/dist/static/_nuxt/B4hfz7cN.js +0 -1
- package/dist/static/_nuxt/BE6e_jlD.js +0 -1
- package/dist/static/_nuxt/BFZfZyte.js +0 -1
- package/dist/static/_nuxt/BW9qBvMR.js +0 -1
- package/dist/static/_nuxt/BWscDCZb.js +0 -1
- package/dist/static/_nuxt/BXnWvqRw.js +0 -1
- package/dist/static/_nuxt/BcSEGymu.js +0 -2
- package/dist/static/_nuxt/Bj-QksVr.js +0 -2
- package/dist/static/_nuxt/BuTE4a2w.js +0 -1
- package/dist/static/_nuxt/C1y0neXX.js +0 -1
- package/dist/static/_nuxt/C52FYB-5.js +0 -1
- package/dist/static/_nuxt/CAXk9Oc1.js +0 -1
- package/dist/static/_nuxt/CQvUQgZO.js +0 -2
- package/dist/static/_nuxt/CXSf4TOH.js +0 -1
- package/dist/static/_nuxt/Cf2NM87n.js +0 -1
- package/dist/static/_nuxt/D3cIKCPa.js +0 -1
- package/dist/static/_nuxt/D3jC5ZAK.js +0 -1
- package/dist/static/_nuxt/D3xofh1k.js +0 -1
- package/dist/static/_nuxt/DOxWca9k.js +0 -1
- package/dist/static/_nuxt/DllQuWrz.js +0 -1
- package/dist/static/_nuxt/DvEvjhbF.js +0 -1
- package/dist/static/_nuxt/FfebEZGy.js +0 -1
- package/dist/static/_nuxt/PqTF-5Vs.js +0 -1
- package/dist/static/_nuxt/Repeater.CLIPcHKX.css +0 -1
- package/dist/static/_nuxt/bNqxxQg2.js +0 -1
- package/dist/static/_nuxt/builds/meta/febd0fe3-67f9-4afd-94c3-97178a3ef2b1.json +0 -1
- package/dist/static/_nuxt/rYfJ_RlJ.js +0 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { VectorField } from '#vector/app/types/vector'
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
// the
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// Rows edited inside the record's form: one line of inputs per row, added
|
|
5
|
+
// and removed within the repeater's bounds, and dragged by their handle
|
|
6
|
+
// (or moved with the arrow keys on it) when the repeater is sortable. A
|
|
7
|
+
// JSON repeater's rows are objects of its own row fields; a relationship
|
|
8
|
+
// repeater's are child records, each keeping its `id`, so the server
|
|
9
|
+
// updates that child, and a row without one is created. The form sends
|
|
10
|
+
// the whole list, in its order.
|
|
8
11
|
const props = defineProps<{
|
|
9
12
|
field: VectorField
|
|
10
13
|
/** the form's rules for the field itself; a row's inputs carry their own */
|
|
@@ -22,17 +25,32 @@ const { t, noun } = useVectorT()
|
|
|
22
25
|
const { resource: resourceOf } = useVectorSchema()
|
|
23
26
|
const { inputFor } = useVectorInputs()
|
|
24
27
|
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const json = computed(() => props.field.repeater?.mode !== 'relationship')
|
|
29
|
+
const child = computed(() => !json.value && props.field.relation ? resourceOf(props.field.relation.resource) : undefined)
|
|
30
|
+
const available = computed(() => json.value || child.value !== undefined)
|
|
31
|
+
const columns = computed<VectorField[]>(() => json.value
|
|
32
|
+
? props.field.repeater?.rowFields ?? []
|
|
33
|
+
: (props.field.repeater?.fields ?? [])
|
|
34
|
+
.map(name => child.value?.fields.find(f => f.name === name))
|
|
35
|
+
.filter((f): f is VectorField => f !== undefined))
|
|
29
36
|
const min = computed(() => props.field.repeater?.min ?? 0)
|
|
30
37
|
const max = computed(() => props.field.repeater?.max ?? 100)
|
|
38
|
+
const sortable = computed(() => props.field.repeater?.sortable === true && !props.disabled)
|
|
31
39
|
const rows = computed(() => (Array.isArray(model.value) ? model.value : []))
|
|
32
40
|
const width = computed(() => Math.max(3, Math.floor(12 / Math.max(1, Math.min(columns.value.length, 4)))))
|
|
41
|
+
// a row's inputs ask for options and uploads as the resource they belong to
|
|
42
|
+
const rowResource = computed(() => child.value?.slug ?? props.resource)
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
const rowLabel = (index: number) => child.value
|
|
45
|
+
? t('fields.repeater.row', { label: child.value.labelSingular, n: index + 1 })
|
|
46
|
+
: t('fields.rows.row', { n: index + 1 })
|
|
47
|
+
const removeLabel = (index: number) => child.value
|
|
48
|
+
? t('fields.repeater.remove', { label: noun(child.value.labelSingular), n: index + 1 })
|
|
49
|
+
: t('fields.rows.remove', { n: index + 1 })
|
|
50
|
+
const addLabel = computed(() => child.value ? t('fields.repeater.add', { label: noun(child.value.labelSingular) }) : t('fields.rows.add'))
|
|
51
|
+
|
|
52
|
+
// Stable keys, so removing or moving a row keeps every other row's inputs
|
|
53
|
+
// (and a relation input's loaded label) with the row it belongs to.
|
|
36
54
|
let next = 0
|
|
37
55
|
const keys = ref<number[]>([])
|
|
38
56
|
watch(() => rows.value.length, (length) => {
|
|
@@ -42,6 +60,7 @@ watch(() => rows.value.length, (length) => {
|
|
|
42
60
|
/** A new row's value for a column: its default, else unchecked for a checkbox, else empty. */
|
|
43
61
|
function blankValue(f: VectorField): unknown {
|
|
44
62
|
if (f.hasDefault) return f.default
|
|
63
|
+
if (f.type === 'tag') return []
|
|
45
64
|
return f.type === 'boolean' ? false : null
|
|
46
65
|
}
|
|
47
66
|
|
|
@@ -67,23 +86,88 @@ function set(index: number, name: string, value: unknown) {
|
|
|
67
86
|
if (props.serverErrors) delete props.serverErrors[`${props.field.name}.${index}.${name}`]
|
|
68
87
|
}
|
|
69
88
|
|
|
70
|
-
/** Row errors are keyed by position, which a removal shifts: they go with it. */
|
|
89
|
+
/** Row errors are keyed by position, which a removal or a move shifts: they go with it. */
|
|
71
90
|
function clearRowErrors() {
|
|
72
91
|
for (const key of Object.keys(props.serverErrors ?? {})) {
|
|
73
92
|
if (key.startsWith(`${props.field.name}.`)) delete props.serverErrors![key]
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
//
|
|
78
|
-
|
|
96
|
+
// --- reordering ----------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
/** What a screen reader hears after a move. */
|
|
99
|
+
const announcement = ref('')
|
|
100
|
+
const handles = ref<HTMLElement[]>([])
|
|
101
|
+
|
|
102
|
+
/** Moves the row at `from` to `to`, its key and inputs with it. */
|
|
103
|
+
function move(from: number, to: number) {
|
|
104
|
+
if (from === to || to < 0 || to >= rows.value.length) return
|
|
105
|
+
|
|
106
|
+
const reorder = <T,>(list: T[]) => {
|
|
107
|
+
const copy = [...list]
|
|
108
|
+
const [moved] = copy.splice(from, 1)
|
|
109
|
+
copy.splice(to, 0, moved as T)
|
|
110
|
+
return copy
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
keys.value = reorder(keys.value)
|
|
114
|
+
model.value = reorder(rows.value)
|
|
115
|
+
clearRowErrors()
|
|
116
|
+
announcement.value = t('fields.rows.moved', { from: from + 1, to: to + 1 })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The arrow keys on a row's handle move the row, the handle keeping focus. */
|
|
120
|
+
async function onHandleKey(event: KeyboardEvent, index: number) {
|
|
121
|
+
const to = event.key === 'ArrowUp' ? index - 1 : event.key === 'ArrowDown' ? index + 1 : null
|
|
122
|
+
if (to === null || to < 0 || to >= rows.value.length) return
|
|
123
|
+
|
|
124
|
+
event.preventDefault()
|
|
125
|
+
move(index, to)
|
|
126
|
+
await nextTick()
|
|
127
|
+
handles.value[to]?.focus()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const dragging = ref<number | null>(null)
|
|
131
|
+
const over = ref<number | null>(null)
|
|
132
|
+
|
|
133
|
+
function onDragStart(event: DragEvent, index: number) {
|
|
134
|
+
dragging.value = index
|
|
135
|
+
event.dataTransfer?.setData('text/plain', String(index))
|
|
136
|
+
if (event.dataTransfer) event.dataTransfer.effectAllowed = 'move'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function onDrop(index: number) {
|
|
140
|
+
if (dragging.value !== null) move(dragging.value, index)
|
|
141
|
+
dragging.value = null
|
|
142
|
+
over.value = null
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// A relationship row's inputs read the record they belong to through the
|
|
146
|
+
// relation back to it: a line priced in `order.currency` sees the order
|
|
147
|
+
// being edited. A JSON row's inputs read the row.
|
|
79
148
|
const inverse = computed(() => props.field.relation?.inverse)
|
|
80
149
|
const rowRecord = (row: Record<string, unknown>) => (inverse.value ? { ...row, [inverse.value]: props.record ?? {} } : row)
|
|
81
150
|
|
|
82
151
|
const rowErrors = (index: number, name: string) => props.serverErrors?.[`${props.field.name}.${index}.${name}`] ?? []
|
|
152
|
+
/**
|
|
153
|
+
* A row's errors no input of it shows: the row's own (`specs.2`, a row
|
|
154
|
+
* that is not an object) and a key the row may not hold (`specs.2.colour`).
|
|
155
|
+
*/
|
|
156
|
+
function rowOwnErrors(index: number): string[] {
|
|
157
|
+
const prefix = `${props.field.name}.${index}`
|
|
158
|
+
|
|
159
|
+
return Object.entries(props.serverErrors ?? {}).flatMap(([key, messages]) => {
|
|
160
|
+
if (key === prefix) return messages
|
|
161
|
+
if (!key.startsWith(`${prefix}.`)) return []
|
|
162
|
+
|
|
163
|
+
const column = key.slice(prefix.length + 1)
|
|
164
|
+
return columns.value.some(c => c.name === column) ? [] : messages.map(message => `${column}: ${message}`)
|
|
165
|
+
})
|
|
166
|
+
}
|
|
83
167
|
|
|
84
168
|
// A new record starts with the rows it must hold.
|
|
85
169
|
onMounted(() => {
|
|
86
|
-
if (
|
|
170
|
+
if (available.value && rows.value.length < min.value && !props.record?.id) {
|
|
87
171
|
model.value = [...rows.value, ...Array.from({ length: min.value - rows.value.length }, blank)]
|
|
88
172
|
}
|
|
89
173
|
})
|
|
@@ -97,43 +181,64 @@ onMounted(() => {
|
|
|
97
181
|
<span class="text-caption text-medium-emphasis">{{ t('fields.repeater.count', { count: rows.length, max }) }}</span>
|
|
98
182
|
</div>
|
|
99
183
|
<v-alert v-for="message in errorMessages" :key="message" type="error" variant="tonal" density="compact" class="mb-2" :text="message" />
|
|
100
|
-
<p v-if="!
|
|
184
|
+
<p v-if="!available" class="text-medium-emphasis text-body-2">{{ t('fields.repeater.unavailable') }}</p>
|
|
101
185
|
<template v-else>
|
|
102
186
|
<fieldset
|
|
103
187
|
v-for="(row, index) in rows"
|
|
104
188
|
:key="keys[index]"
|
|
105
|
-
class="vx-fieldset d-flex ga-2 align-start mb-1"
|
|
106
|
-
:
|
|
189
|
+
class="vx-fieldset vx-repeater-row d-flex ga-2 align-start mb-1"
|
|
190
|
+
:class="{ 'vx-repeater-row--over': over === index && dragging !== index }"
|
|
191
|
+
:aria-label="rowLabel(index)"
|
|
192
|
+
@dragover.prevent="over = index"
|
|
193
|
+
@dragleave="over = over === index ? null : over"
|
|
194
|
+
@drop.prevent="onDrop(index)"
|
|
107
195
|
>
|
|
108
|
-
<v-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
196
|
+
<v-btn
|
|
197
|
+
v-if="sortable"
|
|
198
|
+
:ref="(el: unknown) => { const node = (el as { $el?: HTMLElement } | null)?.$el; if (node) handles[index] = node }"
|
|
199
|
+
icon="mdi-drag-vertical"
|
|
200
|
+
variant="text"
|
|
201
|
+
size="small"
|
|
202
|
+
class="mt-2 vx-repeater-handle"
|
|
203
|
+
draggable="true"
|
|
204
|
+
:aria-label="t('fields.rows.drag', { n: index + 1 })"
|
|
205
|
+
@dragstart="onDragStart($event, index)"
|
|
206
|
+
@dragend="dragging = null; over = null"
|
|
207
|
+
@keydown="onHandleKey($event, index)"
|
|
208
|
+
/>
|
|
209
|
+
<div class="flex-grow-1">
|
|
210
|
+
<v-alert v-for="message in rowOwnErrors(index)" :key="message" type="error" variant="tonal" density="compact" class="mb-1" :text="message" />
|
|
211
|
+
<v-row density="compact">
|
|
212
|
+
<v-col v-for="column in columns" :key="column.name" cols="12" :md="width">
|
|
213
|
+
<component
|
|
214
|
+
:is="inputFor(column)"
|
|
215
|
+
:model-value="row[column.name]"
|
|
216
|
+
:field="column"
|
|
217
|
+
:rules="rulesFor(column, row.id ? 'update' : 'create')"
|
|
218
|
+
:error-messages="rowErrors(index, column.name)"
|
|
219
|
+
:record="rowRecord(row)"
|
|
220
|
+
:resource="rowResource"
|
|
221
|
+
:disabled="disabled"
|
|
222
|
+
density="compact"
|
|
223
|
+
@update:model-value="(value: unknown) => set(index, column.name, value)"
|
|
224
|
+
/>
|
|
225
|
+
</v-col>
|
|
226
|
+
</v-row>
|
|
227
|
+
</div>
|
|
124
228
|
<v-btn
|
|
125
229
|
icon="mdi-close"
|
|
126
230
|
variant="text"
|
|
127
231
|
size="small"
|
|
128
232
|
class="mt-2"
|
|
129
233
|
:disabled="disabled || rows.length <= min"
|
|
130
|
-
:aria-label="
|
|
234
|
+
:aria-label="removeLabel(index)"
|
|
131
235
|
@click="remove(index)"
|
|
132
236
|
/>
|
|
133
237
|
</fieldset>
|
|
134
238
|
<v-btn variant="tonal" size="small" prepend-icon="mdi-plus" :disabled="disabled || rows.length >= max" @click="add">
|
|
135
|
-
{{
|
|
239
|
+
{{ addLabel }}
|
|
136
240
|
</v-btn>
|
|
241
|
+
<span class="d-sr-only" aria-live="polite">{{ announcement }}</span>
|
|
137
242
|
</template>
|
|
138
243
|
</v-card>
|
|
139
244
|
</template>
|
|
@@ -141,4 +246,6 @@ onMounted(() => {
|
|
|
141
246
|
<style scoped>
|
|
142
247
|
/* a fieldset that groups without a fieldset's own border, padding and margin */
|
|
143
248
|
.vx-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
249
|
+
.vx-repeater-handle { cursor: grab; }
|
|
250
|
+
.vx-repeater-row--over { outline: 2px dashed rgb(var(--v-theme-primary)); outline-offset: 2px; border-radius: 4px; }
|
|
144
251
|
</style>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { VectorField } from '#vector/app/types/vector'
|
|
3
|
+
|
|
4
|
+
// One option, or several for a multiple select (shown as chips). A
|
|
5
|
+
// searchable select types to narrow a long list.
|
|
6
|
+
// `disabled` stays undefined when not given, so a disabled v-form still disables the field
|
|
7
|
+
const props = withDefaults(defineProps<{ field: VectorField, rules: ((v: unknown) => true | string)[], errorMessages: string[], record?: Record<string, unknown>, resource?: string, disabled?: boolean }>(), { record: undefined, resource: undefined, disabled: undefined })
|
|
8
|
+
const model = defineModel<string | number | (string | number)[] | null>()
|
|
9
|
+
const multiple = computed(() => props.field.multiple === true)
|
|
10
|
+
// what both inputs share; each is named in the template so Vuetify imports it
|
|
11
|
+
const shared = computed(() => ({
|
|
12
|
+
label: props.field.label,
|
|
13
|
+
items: props.field.options ?? [],
|
|
14
|
+
itemTitle: 'label',
|
|
15
|
+
itemValue: 'value',
|
|
16
|
+
multiple: multiple.value,
|
|
17
|
+
chips: multiple.value,
|
|
18
|
+
closableChips: multiple.value,
|
|
19
|
+
rules: props.rules,
|
|
20
|
+
errorMessages: props.errorMessages,
|
|
21
|
+
clearable: props.field.nullable === true,
|
|
22
|
+
hint: props.field.help ?? undefined,
|
|
23
|
+
persistentHint: !!props.field.help,
|
|
24
|
+
disabled: props.disabled,
|
|
25
|
+
}))
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<v-autocomplete v-if="field.autocomplete" v-model="model" v-bind="shared" auto-select-first />
|
|
30
|
+
<v-select v-else v-model="model" v-bind="shared" />
|
|
31
|
+
</template>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { VectorField } from '#vector/app/types/vector'
|
|
3
|
+
import { normalizeTags } from '#vector/app/utils/internal/repeater'
|
|
4
|
+
|
|
5
|
+
// Free-text tags as chips: typed and confirmed with Enter (or a comma),
|
|
6
|
+
// picked from the field's suggestions, or pasted. The list is kept as the
|
|
7
|
+
// server stores it: trimmed, without empty tags, each at most once
|
|
8
|
+
// ignoring case. A suggestion never restricts what a tag may be.
|
|
9
|
+
const props = defineProps<{ field: VectorField, rules: ((v: unknown) => true | string)[], errorMessages: string[], record?: Record<string, unknown>, resource?: string, disabled?: boolean }>()
|
|
10
|
+
const model = defineModel<string[] | null>()
|
|
11
|
+
|
|
12
|
+
const { t } = useVectorT()
|
|
13
|
+
const maxLength = computed(() => props.field.tags?.maxLength ?? 50)
|
|
14
|
+
const maxTags = computed(() => props.field.tags?.maxTags ?? 20)
|
|
15
|
+
const tags = computed(() => (Array.isArray(model.value) ? model.value : []))
|
|
16
|
+
|
|
17
|
+
const limits = (value: unknown) => {
|
|
18
|
+
const list = Array.isArray(value) ? value : []
|
|
19
|
+
if (list.some(tag => typeof tag === 'string' && tag.trim().length > maxLength.value)) return t('fields.rules.maxLength', { max: maxLength.value })
|
|
20
|
+
if (list.length > maxTags.value) return t('fields.tags.tooMany', { max: maxTags.value })
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function update(value: unknown) {
|
|
25
|
+
const list = normalizeTags(Array.isArray(value) ? value : [])
|
|
26
|
+
model.value = list.length === 0 && props.field.nullable === true ? null : list
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<v-combobox
|
|
32
|
+
:model-value="tags"
|
|
33
|
+
:label="field.label"
|
|
34
|
+
:items="field.tags?.suggestions ?? []"
|
|
35
|
+
:rules="[...rules, limits]"
|
|
36
|
+
:error-messages="errorMessages"
|
|
37
|
+
:disabled="disabled"
|
|
38
|
+
:hint="field.help ?? t('fields.tags.hint')"
|
|
39
|
+
:delimiters="[',']"
|
|
40
|
+
multiple
|
|
41
|
+
chips
|
|
42
|
+
closable-chips
|
|
43
|
+
hide-no-data
|
|
44
|
+
persistent-hint
|
|
45
|
+
@update:model-value="update"
|
|
46
|
+
/>
|
|
47
|
+
</template>
|
|
@@ -17,7 +17,6 @@ const innerAddons = useVectorInputAddons(() => props.field.type, () => 'inner')
|
|
|
17
17
|
:hint="field.help ?? undefined"
|
|
18
18
|
:persistent-hint="!!field.help"
|
|
19
19
|
:disabled="props.disabled"
|
|
20
|
-
:class="{ 'font-monospace': props.field.type === 'json' }"
|
|
21
20
|
auto-grow
|
|
22
21
|
rows="3"
|
|
23
22
|
>
|
|
@@ -64,7 +64,7 @@ watch(() => props.errors, () => {
|
|
|
64
64
|
</v-col>
|
|
65
65
|
|
|
66
66
|
<v-col v-else-if="node.kind === 'section'" cols="12" class="vx-layout-section" :data-layout-section="node.label">
|
|
67
|
-
<v-expansion-panels v-if="node.collapsible" :model-value="open[key] ? [0] : []" variant="accordion" @update:model-value="(v: unknown) => open[key] = Array.isArray(v) && v.length > 0">
|
|
67
|
+
<v-expansion-panels v-if="node.collapsible" :model-value="open[key] ? [0] : []" multiple variant="accordion" @update:model-value="(v: unknown) => open[key] = Array.isArray(v) && v.length > 0">
|
|
68
68
|
<v-expansion-panel :value="0">
|
|
69
69
|
<v-expansion-panel-title>
|
|
70
70
|
<span class="font-weight-medium">{{ node.label }}</span>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { childRepeater } from '#vector/app/utils/internal/repeater'
|
|
2
3
|
import type { SubmitEventPromise } from 'vuetify'
|
|
3
4
|
import type { VectorResource, VectorSelection } from '#vector/app/types/vector'
|
|
4
5
|
|
|
@@ -19,7 +20,7 @@ const notifications = useVectorNotifications()
|
|
|
19
20
|
const client = useVectorResource(() => props.resource.slug)
|
|
20
21
|
const { editable } = useVectorInputs()
|
|
21
22
|
|
|
22
|
-
const editableFields = computed(() => props.resource.fields.filter(f => editable(f, 'update') && f.type !== 'password' && f
|
|
23
|
+
const editableFields = computed(() => props.resource.fields.filter(f => editable(f, 'update') && f.type !== 'password' && !childRepeater(f)))
|
|
23
24
|
const chosen = ref<string[]>([])
|
|
24
25
|
const fields = computed(() => editableFields.value.filter(f => chosen.value.includes(f.name)))
|
|
25
26
|
const values = reactive<Record<string, unknown>>({})
|
|
@@ -24,8 +24,18 @@ function openAdd(where: Target, event: Event) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const { t, locale } = useVectorT()
|
|
27
|
+
const countryNames = useVectorCountryNames()
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
/** The values a choice field offers, each named as the UI shows it: a currency by its name, a country in the UI's language, a flag by its label. */
|
|
30
|
+
function choicesOf(f: VectorField): { value: string | number, label: string }[] {
|
|
31
|
+
if (f.type === 'currency') return (f.options ?? []).map(o => ({ value: o.value, label: currencyLabel(String(o.value), locale.value) }))
|
|
32
|
+
if (f.type === 'country') return withCountryNames(f, countryNames.value).options ?? []
|
|
33
|
+
return f.options ?? []
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const CHOICE_TYPES = new Set(['select', 'country', 'booleanGroup', 'currency'])
|
|
37
|
+
|
|
38
|
+
const OPERATORS: readonly VectorOperator[] = ['eq', 'ne', 'lt', 'lte', 'gt', 'gte', 'in', 'nin', 'like', 'nlike', 'between', 'any', 'all', 'null', 'nnull']
|
|
29
39
|
|
|
30
40
|
const operatorLabel = (op: string): string => (OPERATORS as readonly string[]).includes(op) ? t(`list.filter.operators.${op}`) : op
|
|
31
41
|
|
|
@@ -52,7 +62,16 @@ watch(field, (f) => {
|
|
|
52
62
|
})
|
|
53
63
|
|
|
54
64
|
const needsValue = computed(() => operator.value !== null && !['null', 'nnull'].includes(operator.value))
|
|
55
|
-
|
|
65
|
+
// a list of values: in/nin of a column, any/all of a multiple select's options or of tags
|
|
66
|
+
const list = computed(() => ['in', 'nin', 'any', 'all'].includes(operator.value ?? ''))
|
|
67
|
+
|
|
68
|
+
/** What a choice input shows as picked: the comma-separated `value` as the options' own values, a list for a list operator. */
|
|
69
|
+
const picked = computed(() => {
|
|
70
|
+
const own = new Map(field.value ? choicesOf(field.value).map(o => [String(o.value), o.value] as const) : [])
|
|
71
|
+
const parts = value.value === '' ? [] : value.value.split(',').map(text => own.get(text) ?? text)
|
|
72
|
+
|
|
73
|
+
return list.value ? parts : (parts[0] ?? null)
|
|
74
|
+
})
|
|
56
75
|
|
|
57
76
|
const searchRelation = useDebounceFn(async (q: string) => {
|
|
58
77
|
if (!field.value) return
|
|
@@ -157,8 +176,7 @@ function chipText(name: string, op: string, v: string): string {
|
|
|
157
176
|
|
|
158
177
|
let shown = v
|
|
159
178
|
|
|
160
|
-
if (f.type
|
|
161
|
-
if (f.type === 'currency') shown = v.split(',').map(x => currencyLabel(x, locale.value)).join(', ')
|
|
179
|
+
if (CHOICE_TYPES.has(f.type)) shown = v.split(',').map(x => choicesOf(f).find(o => String(o.value) === x)?.label ?? x).join(', ')
|
|
162
180
|
if (f.type === 'boolean') shown = v === 'true' || v === '1' ? t('list.filter.yes') : t('list.filter.no')
|
|
163
181
|
if (f.type === 'money' && !['in', 'nin', 'between'].includes(op)) shown = (Number(v) / 10 ** moneyDigits(f)).toFixed(moneyDigits(f))
|
|
164
182
|
if (op === 'between') shown = v.replace(',', ` ${t('list.filter.and')} `)
|
|
@@ -204,7 +222,9 @@ const anything = computed(() => active.value.length > 0 || groups.value.length >
|
|
|
204
222
|
<v-select v-model="fieldName" :label="t('list.field')" :items="filterable" item-title="label" item-value="name" density="compact" hide-details class="mb-3" />
|
|
205
223
|
<v-select v-if="field" v-model="operator" :label="t('list.filter.condition')" :items="field.operators.map(op => ({ title: operatorLabel(op), value: op }))" density="compact" hide-details class="mb-3" />
|
|
206
224
|
<template v-if="field && needsValue">
|
|
207
|
-
<v-
|
|
225
|
+
<v-autocomplete v-if="CHOICE_TYPES.has(field.type) && field.autocomplete" :model-value="picked" :label="t('list.filter.value')" :items="choicesOf(field)" item-title="label" item-value="value" density="compact" hide-details class="mb-3" :multiple="list" @update:model-value="(v: unknown) => value = Array.isArray(v) ? v.join(',') : String(v ?? '')" />
|
|
226
|
+
<v-select v-else-if="CHOICE_TYPES.has(field.type)" :model-value="picked" :label="t('list.filter.value')" :items="choicesOf(field)" item-title="label" item-value="value" density="compact" hide-details class="mb-3" :multiple="list" @update:model-value="(v: unknown) => value = Array.isArray(v) ? v.join(',') : String(v ?? '')" />
|
|
227
|
+
<v-combobox v-else-if="field.type === 'tag'" :model-value="value === '' ? [] : value.split(',')" :label="t('list.filter.value')" :items="field.tags?.suggestions ?? []" :hint="t('fields.tags.hint')" :delimiters="[',']" density="compact" class="mb-3" multiple chips closable-chips hide-no-data persistent-hint @update:model-value="(v: unknown) => value = Array.isArray(v) ? v.map(x => String(x).trim()).filter(x => x !== '').join(',') : String(v ?? '')" />
|
|
208
228
|
<v-select v-else-if="field.type === 'boolean'" v-model="value" :label="t('list.filter.value')" :items="[{ title: t('common.yes'), value: 'true' }, { title: t('common.no'), value: 'false' }]" density="compact" hide-details class="mb-3" />
|
|
209
229
|
<v-autocomplete v-else-if="field.type === 'belongsTo'" v-model:search="relationSearch" :label="t('list.filter.value')" :items="relationOptions" item-title="label" item-value="id" density="compact" hide-details class="mb-3" :multiple="list" no-filter @update:model-value="(v: unknown) => value = Array.isArray(v) ? v.join(',') : String(v ?? '')" />
|
|
210
230
|
<template v-else>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { childRepeater } from '#vector/app/utils/internal/repeater'
|
|
2
3
|
import type { VectorAuditEntry, VectorResource } from '#vector/app/types/vector'
|
|
3
4
|
|
|
4
5
|
// The audit trail of one record: who changed what, when, as whom. An
|
|
@@ -27,7 +28,7 @@ function revertableFields(entry: VectorAuditEntry): string[] {
|
|
|
27
28
|
if (!props.canUpdate || !['update', 'revert'].includes(entry.event)) return []
|
|
28
29
|
return Object.keys(entry.changes).filter((name) => {
|
|
29
30
|
const field = props.resource.fields.find(f => f.name === name)
|
|
30
|
-
return field !== undefined && !field.readonly && field.views.includes('update') && !['id', 'hasOne', 'hasMany', 'manyToMany', 'password'].includes(field.type)
|
|
31
|
+
return field !== undefined && !field.readonly && field.views.includes('update') && !['id', 'hasOne', 'hasMany', 'manyToMany', 'password'].includes(field.type) && !childRepeater(field)
|
|
31
32
|
})
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { SubmitEventPromise } from 'vuetify'
|
|
3
3
|
import type { VectorField, VectorFieldState, VectorLayoutNode, VectorRecord, VectorResource } from '#vector/app/types/vector'
|
|
4
4
|
import { type Violation, violationsOf } from '#vector/app/utils/internal/violations'
|
|
5
|
+
import { childRepeater } from '#vector/app/utils/internal/repeater'
|
|
5
6
|
|
|
6
7
|
// A create or edit form generated from the descriptor: one input per
|
|
7
8
|
// editable field, client rules mirroring the server's, and the server's
|
|
@@ -52,10 +53,12 @@ const clone = (value: unknown) => value === undefined ? undefined : JSON.parse(J
|
|
|
52
53
|
* (a stored key belongs to its record). Collections load below.
|
|
53
54
|
*/
|
|
54
55
|
const copies = (field: VectorField) => props.operation === 'create' && props.copyOf !== undefined
|
|
55
|
-
&& field.unique !== true && !['file', 'image', 'manyToMany'
|
|
56
|
+
&& field.unique !== true && !['file', 'image', 'manyToMany'].includes(field.type) && !childRepeater(field)
|
|
56
57
|
|
|
57
58
|
/** What a field starts with when nothing gives it a value: on create its declared default, else its type's empty one. */
|
|
58
59
|
function initialValue(field: VectorField): unknown {
|
|
60
|
+
// a flag group starts with every flag, off unless its default turns it on
|
|
61
|
+
if (field.type === 'booleanGroup') return flagsStart(field, props.operation === 'create')
|
|
59
62
|
return props.operation === 'create' && field.hasDefault ? JSON.parse(JSON.stringify(field.default ?? null)) : defaultFor(field)
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -70,8 +73,8 @@ function start() {
|
|
|
70
73
|
value = (current as { id: unknown }).id
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
if (field.type === 'manyToMany' || field
|
|
74
|
-
value = [] // the ids, or a repeater's rows, load from their endpoint below
|
|
76
|
+
if (field.type === 'manyToMany' || childRepeater(field)) {
|
|
77
|
+
value = [] // the ids, or a relationship repeater's rows, load from their endpoint below
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
values[field.name] = value
|
|
@@ -82,7 +85,7 @@ start()
|
|
|
82
85
|
|
|
83
86
|
function defaultFor(field: VectorField): unknown {
|
|
84
87
|
if (field.type === 'boolean') return false
|
|
85
|
-
if (
|
|
88
|
+
if (['manyToMany', 'repeater', 'tag'].includes(field.type)) return []
|
|
86
89
|
return null
|
|
87
90
|
}
|
|
88
91
|
|
|
@@ -103,8 +106,8 @@ if (loadFrom) {
|
|
|
103
106
|
})
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
// A repeater's rows: each child as a row of the fields it writes, its relations as ids.
|
|
107
|
-
for (const field of fields.value.filter(
|
|
109
|
+
// A relationship repeater's rows: each child as a row of the fields it writes, its relations as ids.
|
|
110
|
+
for (const field of fields.value.filter(childRepeater)) {
|
|
108
111
|
client.rows(loadFrom.id, field.name).catch((error) => {
|
|
109
112
|
unloaded.add(field.name)
|
|
110
113
|
formError.value = vectorErrorMessage(error)
|
|
@@ -140,7 +143,7 @@ async function allRelatedIds(id: string | number, field: VectorField): Promise<u
|
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
|
|
143
|
-
const wide = (field: VectorField) => ['markdown', 'richtext', 'text', 'json', 'keyValue'].includes(field.type)
|
|
146
|
+
const wide = (field: VectorField) => ['markdown', 'richtext', 'text', 'json', 'keyValue', 'repeater'].includes(field.type)
|
|
144
147
|
|
|
145
148
|
/** Fields the browser's own rules refused on the last submit, by the input id each carries. */
|
|
146
149
|
const clientErrors = ref<string[]>([])
|
|
@@ -245,8 +248,8 @@ function showFailure(error: unknown) {
|
|
|
245
248
|
|
|
246
249
|
/** One violation under the field it names, or above the form when it names none the form holds. */
|
|
247
250
|
function showViolation(violation: Violation) {
|
|
248
|
-
// a repeater row's own violation stays with its row: `lines.2.quantity`
|
|
249
|
-
const repeated = violation.path.length >=
|
|
251
|
+
// a repeater row's own violation stays with its row: `lines.2.quantity`, or `specs.2` for the row itself
|
|
252
|
+
const repeated = violation.path.length >= 2 && fields.value.some(f => f.name === violation.path[0] && f.type === 'repeater')
|
|
250
253
|
const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
|
|
251
254
|
|
|
252
255
|
if (key && (key in values || repeated)) {
|
|
@@ -350,7 +353,7 @@ const hiddenErrors = computed(() => Object.entries(serverErrors)
|
|
|
350
353
|
:error-messages="serverErrors[name] ?? []"
|
|
351
354
|
:record="inputRecord"
|
|
352
355
|
:resource="resource.slug"
|
|
353
|
-
v-bind="fieldsByName.get(name)!.repeater ? { serverErrors } : {}"
|
|
356
|
+
v-bind="fieldsByName.get(name)!.type === 'repeater' ? { serverErrors } : {}"
|
|
354
357
|
@update:model-value="clearServerError(name)"
|
|
355
358
|
/>
|
|
356
359
|
<VxInputAddons
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import type { VectorField } from '#vector/app/types/vector'
|
|
3
|
+
import { loadCountryNames } from '#vector/app/utils/countries'
|
|
4
|
+
|
|
5
|
+
// The static names never change, so one load per locale serves every component.
|
|
6
|
+
const loaded = new Map<string, Record<string, string>>()
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The country names of the UI's language, keyed by ISO 3166-1 alpha-2
|
|
10
|
+
* code, empty until they load; follows a change of language.
|
|
11
|
+
*/
|
|
12
|
+
export function useVectorCountryNames(): Ref<Record<string, string>> {
|
|
13
|
+
const { locale } = useVectorT()
|
|
14
|
+
const names = ref<Record<string, string>>(loaded.get(locale.value) ?? {})
|
|
15
|
+
|
|
16
|
+
watch(locale, async (code) => {
|
|
17
|
+
let found = loaded.get(code)
|
|
18
|
+
if (found === undefined) {
|
|
19
|
+
// A chunk that fails to load leaves the names as they are (the
|
|
20
|
+
// server's English labels until a load succeeds), and the next
|
|
21
|
+
// change of language tries again.
|
|
22
|
+
try {
|
|
23
|
+
found = await loadCountryNames(code)
|
|
24
|
+
} catch {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
loaded.set(code, found)
|
|
29
|
+
if (locale.value === code) names.value = found
|
|
30
|
+
}, { immediate: true })
|
|
31
|
+
|
|
32
|
+
return names
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A country field with each option named in the UI's language, or by the server's English name until the names load. */
|
|
36
|
+
export function withCountryNames(field: VectorField, names: Record<string, string>): VectorField {
|
|
37
|
+
return { ...field, options: (field.options ?? []).map(option => ({ ...option, label: names[String(option.value)] ?? option.label })) }
|
|
38
|
+
}
|
|
@@ -20,7 +20,9 @@ const cells: Record<string, Component> = {
|
|
|
20
20
|
number: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Number.vue')),
|
|
21
21
|
money: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Money.vue')),
|
|
22
22
|
boolean: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Boolean.vue')),
|
|
23
|
-
|
|
23
|
+
select: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Select.vue')),
|
|
24
|
+
country: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Country.vue')),
|
|
25
|
+
booleanGroup: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/BooleanGroup.vue')),
|
|
24
26
|
date: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Date.vue')),
|
|
25
27
|
datetime: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/DateTime.vue')),
|
|
26
28
|
email: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Email.vue')),
|
|
@@ -36,6 +38,8 @@ const cells: Record<string, Component> = {
|
|
|
36
38
|
hasOne: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Relation.vue')),
|
|
37
39
|
hasMany: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Count.vue')),
|
|
38
40
|
manyToMany: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Count.vue')),
|
|
41
|
+
repeater: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Repeater.vue')),
|
|
42
|
+
tag: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Tag.vue')),
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
/** The cell type a computed field is shown as: what it is computed as, text as a string. */
|
|
@@ -3,18 +3,42 @@ import { violationsOf } from '#vector/app/utils/internal/violations'
|
|
|
3
3
|
|
|
4
4
|
/** The value a fresh input holds: the field's default, or the type's empty value. */
|
|
5
5
|
export function initialValue(field: VectorField): unknown {
|
|
6
|
+
if (field.type === 'booleanGroup') return flagsStart(field, true)
|
|
6
7
|
if (field.hasDefault) return field.default
|
|
7
8
|
if (field.type === 'boolean') return false
|
|
8
9
|
if (field.type === 'manyToMany') return []
|
|
10
|
+
if (field.type === 'tag' || field.type === 'repeater') return []
|
|
9
11
|
return null
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
/**
|
|
15
|
+
* What a flag group starts with: every option key false, with the keys a
|
|
16
|
+
* declared default names over them ($withDefault), so a form with no box
|
|
17
|
+
* ticked still sends every flag. A nullable group (one JSON column that
|
|
18
|
+
* may hold null) without a default starts empty instead, as null.
|
|
19
|
+
*/
|
|
20
|
+
export function flagsStart(field: VectorField, withDefault: boolean): Record<string, boolean> | null {
|
|
21
|
+
const declared = withDefault && field.hasDefault ? field.default : undefined
|
|
22
|
+
|
|
23
|
+
if ((declared === undefined || declared === null) && field.nullable === true) return null
|
|
24
|
+
|
|
25
|
+
const flags: Record<string, boolean> = Object.fromEntries((field.options ?? []).map(option => [String(option.value), false]))
|
|
26
|
+
|
|
27
|
+
if (declared !== null && typeof declared === 'object' && !Array.isArray(declared)) {
|
|
28
|
+
for (const [key, on] of Object.entries(declared)) {
|
|
29
|
+
if (key in flags) flags[key] = on === true
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return flags
|
|
34
|
+
}
|
|
35
|
+
|
|
12
36
|
/**
|
|
13
37
|
* Maps the framework's 422 document onto field names; returns the
|
|
14
38
|
* message that names no field, if any. A violation deeper in a value
|
|
15
|
-
* (`tags.2
|
|
16
|
-
*
|
|
17
|
-
*
|
|
39
|
+
* (`tags.2`, or a JSON repeater's `specs.1.label` in bulk edit) shows on
|
|
40
|
+
* its field as a whole: only `Vx/Resource/Form.vue` maps a repeater's
|
|
41
|
+
* row errors onto their row.
|
|
18
42
|
*/
|
|
19
43
|
export function applyViolations(error: unknown, values: Record<string, unknown>, serverErrors: Record<string, string[]>): string | null {
|
|
20
44
|
const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
|