@conduction/nextcloud-vue 2.165.0 → 2.166.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/dist/esm/components/CnActionButtons/CnActionButtons.vue.js +1 -1
- package/dist/esm/components/CnActionButtons/CnActionButtons.vue2.js +7 -0
- package/dist/esm/components/CnActionButtons/CnActionButtons.vue2.js.map +1 -1
- package/dist/esm/components/CnActionButtons/CnActionButtons.vue3.js.map +1 -1
- package/dist/esm/components/CnAuditTrailCard/CnAuditTrailCard.vue.js +1 -1
- package/dist/esm/components/CnAuditTrailCard/CnAuditTrailCard.vue2.js +10 -0
- package/dist/esm/components/CnAuditTrailCard/CnAuditTrailCard.vue2.js.map +1 -1
- package/dist/esm/components/CnAuditTrailCard/CnAuditTrailCard.vue3.js +1 -1
- package/dist/esm/components/CnAuditTrailCard/CnAuditTrailCard.vue3.js.map +1 -1
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue.js +1 -1
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue2.js.map +1 -1
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue3.js.map +1 -1
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue.js +1 -1
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue2.js +50 -7
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue2.js.map +1 -1
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue3.js.map +1 -1
- package/dist/esm/components/CnDataTable/CnDataTable.vue2.js +13 -0
- package/dist/esm/components/CnDataTable/CnDataTable.vue2.js.map +1 -1
- package/dist/esm/components/CnDataTable/CnDataTable.vue3.js +1 -0
- package/dist/esm/components/CnDataTable/CnDataTable.vue3.js.map +1 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js +39 -4
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js.map +1 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js +2 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js.map +1 -1
- package/dist/esm/components/CnExpandableRow/CnExpandableRow.vue.js +1 -1
- package/dist/esm/components/CnExpandableRow/CnExpandableRow.vue2.js.map +1 -1
- package/dist/esm/components/CnExpandableRow/CnExpandableRow.vue3.js.map +1 -1
- package/dist/esm/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue.js +9 -0
- package/dist/esm/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue.js.map +1 -0
- package/dist/esm/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue2.js +232 -0
- package/dist/esm/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue2.js.map +1 -0
- package/dist/esm/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue3.js +61 -0
- package/dist/esm/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue3.js.map +1 -0
- package/dist/esm/components/CnFieldGroupsWidget/index.js +28 -0
- package/dist/esm/components/CnFieldGroupsWidget/index.js.map +1 -0
- package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue.js +1 -1
- package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue2.js +80 -6
- package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue3.js +361 -289
- package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnFlowDetail/CnFlowDetail.vue.js +1 -1
- package/dist/esm/components/CnFlowDetail/CnFlowDetail.vue2.js +9 -0
- package/dist/esm/components/CnFlowDetail/CnFlowDetail.vue2.js.map +1 -1
- package/dist/esm/components/CnFlowDetail/CnFlowDetail.vue3.js +2 -1
- package/dist/esm/components/CnFlowDetail/CnFlowDetail.vue3.js.map +1 -1
- package/dist/esm/components/CnFlowDetail/CnFlowRunSummary.vue.js +1 -1
- package/dist/esm/components/CnFlowDetail/CnFlowRunSummary.vue2.js +21 -0
- package/dist/esm/components/CnFlowDetail/CnFlowRunSummary.vue2.js.map +1 -1
- package/dist/esm/components/CnFlowDetail/CnFlowRunSummary.vue3.js +12 -2
- package/dist/esm/components/CnFlowDetail/CnFlowRunSummary.vue3.js.map +1 -1
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue.js +1 -1
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue2.js +17 -0
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue2.js.map +1 -1
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue3.js +6 -3
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue3.js.map +1 -1
- package/dist/esm/components/CnGraphCanvas/CnGraphCanvas.vue2.js +33 -2
- package/dist/esm/components/CnGraphCanvas/CnGraphCanvas.vue2.js.map +1 -1
- package/dist/esm/components/CnGraphCanvas/CnGraphCanvas.vue3.js +2 -2
- package/dist/esm/components/CnGraphCanvas/CnGraphCanvas.vue3.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +83 -8
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js +2 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinkDialog.vue.js +9 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinkDialog.vue.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinkDialog.vue2.js +187 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinkDialog.vue2.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinkDialog.vue3.js +106 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinkDialog.vue3.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinksWidget.vue.js +9 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinksWidget.vue.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinksWidget.vue2.js +421 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinksWidget.vue2.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinksWidget.vue3.js +131 -0
- package/dist/esm/components/CnObjectLinksWidget/CnObjectLinksWidget.vue3.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/index.js +29 -0
- package/dist/esm/components/CnObjectLinksWidget/index.js.map +1 -0
- package/dist/esm/components/CnObjectLinksWidget/objectLinks.js +22 -0
- package/dist/esm/components/CnObjectLinksWidget/objectLinks.js.map +1 -0
- package/dist/esm/components/CnObjectPartiesWidget/CnObjectPartiesWidget.vue.js +1 -1
- package/dist/esm/components/CnObjectPartiesWidget/CnObjectPartiesWidget.vue2.js +48 -13
- package/dist/esm/components/CnObjectPartiesWidget/CnObjectPartiesWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnObjectPartiesWidget/CnObjectPartiesWidget.vue3.js +44 -20
- package/dist/esm/components/CnObjectPartiesWidget/CnObjectPartiesWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnPagination/CnPagination.vue2.js +26 -0
- package/dist/esm/components/CnPagination/CnPagination.vue2.js.map +1 -1
- package/dist/esm/components/CnPagination/CnPagination.vue3.js +40 -37
- package/dist/esm/components/CnPagination/CnPagination.vue3.js.map +1 -1
- package/dist/esm/components/CnWidgetGrid/registerDashboardWidgets.js +2 -0
- package/dist/esm/components/CnWidgetGrid/registerDashboardWidgets.js.map +1 -1
- package/dist/esm/components/CnWidgetObjectTable/CnWidgetObjectTable.vue.js +1 -1
- package/dist/esm/components/CnWidgetObjectTable/CnWidgetObjectTable.vue2.js +4 -0
- package/dist/esm/components/CnWidgetObjectTable/CnWidgetObjectTable.vue2.js.map +1 -1
- package/dist/esm/components/CnWidgetObjectTable/CnWidgetObjectTable.vue3.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/l10n/en.json.js +18 -1
- package/dist/esm/l10n/en.json.js.map +1 -1
- package/dist/esm/l10n/nl.json.js +18 -1
- package/dist/esm/l10n/nl.json.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +635 -329
- package/dist/esm/utils/actionsDispatcher.js +9 -5
- package/dist/esm/utils/actionsDispatcher.js.map +1 -1
- package/dist/esm/utils/libraryWidgetKeys.js +2 -0
- package/dist/esm/utils/libraryWidgetKeys.js.map +1 -1
- package/dist/esm/utils/objectParties.js +68 -1
- package/dist/esm/utils/objectParties.js.map +1 -1
- package/dist/esm/utils/overlayInset.js +60 -0
- package/dist/esm/utils/overlayInset.js.map +1 -0
- package/dist/esm/utils/validateManifestV2.compiled.js +2 -2
- package/dist/esm/utils/validateManifestV2.compiled.js.map +1 -1
- package/dist/esm/utils/widgetDispatch.js +4 -1
- package/dist/esm/utils/widgetDispatch.js.map +1 -1
- package/dist/nextcloud-vue.cjs.js +8444 -6584
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +635 -329
- package/l10n/en.json +18 -1
- package/l10n/nl.json +18 -1
- package/package.json +1 -1
- package/src/components/CnActionButtons/CnActionButtons.vue +7 -0
- package/src/components/CnAuditTrailCard/CnAuditTrailCard.vue +11 -1
- package/src/components/CnChipListManager/CnChipListManager.vue +4 -1
- package/src/components/CnDashboardGrid/CnDashboardGrid.vue +50 -7
- package/src/components/CnDataTable/CnDataTable.md +1 -0
- package/src/components/CnDataTable/CnDataTable.vue +14 -0
- package/src/components/CnDetailPage/CnDetailPage.md +1 -0
- package/src/components/CnDetailPage/CnDetailPage.vue +40 -4
- package/src/components/CnExpandableRow/CnExpandableRow.vue +7 -4
- package/src/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue +287 -0
- package/src/components/CnFieldGroupsWidget/index.js +27 -0
- package/src/components/CnFieldListWidget/CnFieldListWidget.vue +162 -7
- package/src/components/CnFlowDetail/CnFlowDetail.vue +10 -0
- package/src/components/CnFlowDetail/CnFlowRunSummary.vue +26 -1
- package/src/components/CnFlowsPage/CnFlowBoard.vue +90 -4
- package/src/components/CnGraphCanvas/CnGraphCanvas.vue +35 -4
- package/src/components/CnIndexPage/CnIndexPage.md +1 -1
- package/src/components/CnIndexPage/CnIndexPage.vue +83 -7
- package/src/components/CnObjectLinksWidget/CnObjectLinkDialog.vue +267 -0
- package/src/components/CnObjectLinksWidget/CnObjectLinksWidget.vue +532 -0
- package/src/components/CnObjectLinksWidget/index.js +28 -0
- package/src/components/CnObjectLinksWidget/objectLinks.js +19 -0
- package/src/components/CnObjectPartiesWidget/CnObjectPartiesWidget.vue +65 -15
- package/src/components/CnPagination/CnPagination.md +1 -0
- package/src/components/CnPagination/CnPagination.vue +27 -1
- package/src/components/CnWidgetGrid/registerDashboardWidgets.js +2 -0
- package/src/components/CnWidgetObjectTable/CnWidgetObjectTable.vue +4 -0
- package/src/components/index.js +2 -0
- package/src/css/dialog.css +25 -3
- package/src/css/index-page.css +22 -8
- package/src/css/look-board-detail.css +41 -0
- package/src/css/look-board-index.css +52 -1
- package/src/css/look-board.css +17 -0
- package/src/index.js +2 -0
- package/src/schemas/app-manifest-v2.schema.json +3 -3
- package/src/utils/actionsDispatcher.js +9 -5
- package/src/utils/libraryWidgetKeys.js +2 -0
- package/src/utils/objectParties.js +67 -0
- package/src/utils/overlayInset.js +57 -0
- package/src/utils/validateManifestV2.compiled.js +2 -2
- package/src/utils/widgetDispatch.js +4 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { NcActionButton, NcActions } from '@nextcloud/vue';
|
|
2
|
+
import Plus from 'vue-material-design-icons/Plus.vue';
|
|
3
|
+
import __sfc_main from '../CnFieldListWidget/CnFieldListWidget.vue.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CnFieldGroupsWidget: the `field-groups` widget: several list fields of the
|
|
7
|
+
* record in one card, each drawn as a field list in the pairs look (a label
|
|
8
|
+
* beside a value), with one "Add" that offers a choice of list. Board PqKlant
|
|
9
|
+
* "Contactkanalen": e-mail addresses, phone numbers and social profiles, one
|
|
10
|
+
* "Toevoegen" menu in the card's title row.
|
|
11
|
+
*
|
|
12
|
+
* Each group is a `field-list` content (`field`, `row`, `add`, `edit`,
|
|
13
|
+
* `remove`, `mirror`, `emptyLabel`, `emptyText`), so a group saves exactly as
|
|
14
|
+
* a field list does: one PATCH of its own field after re-reading the stored
|
|
15
|
+
* value, the server's refusal shown in its words.
|
|
16
|
+
*
|
|
17
|
+
* @spec openspec/changes/contact-side-cards-generic/specs/contact-side-cards-generic/spec.md#requirement-several-list-fields-share-one-card-and-one-add-menu
|
|
18
|
+
*/
|
|
19
|
+
var script = {
|
|
20
|
+
name: 'CnFieldGroupsWidget',
|
|
21
|
+
|
|
22
|
+
components: { CnFieldListWidget: __sfc_main, NcActionButton, NcActions, Plus },
|
|
23
|
+
|
|
24
|
+
inject: {
|
|
25
|
+
cnTranslate: { default: () => (key) => key },
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
props: {
|
|
29
|
+
/**
|
|
30
|
+
* The widget configuration.
|
|
31
|
+
*
|
|
32
|
+
* - `groups`: `[<field-list content>]`, drawn in order in the pairs look.
|
|
33
|
+
* - `add`: `{ label?, ariaLabel?, placement?: 'title' | 'footer' }`: the one Add, a menu with an
|
|
34
|
+
* item per group that has an `add` (the group's `add.label`). `title` reports it for the card's
|
|
35
|
+
* title row on the `header` event; `footer` (default) draws it under the groups.
|
|
36
|
+
* - `readOnly`: no add, edit or remove in any group.
|
|
37
|
+
* - `afterSave`: the field-list `afterSave` for every group that declares none.
|
|
38
|
+
*
|
|
39
|
+
* @type {object}
|
|
40
|
+
*/
|
|
41
|
+
content: {
|
|
42
|
+
type: Object,
|
|
43
|
+
default: () => ({}),
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/** The current detail-page object. */
|
|
47
|
+
objectData: {
|
|
48
|
+
type: Object,
|
|
49
|
+
default: null,
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/** The current object id. */
|
|
53
|
+
objectId: {
|
|
54
|
+
type: [String, Number],
|
|
55
|
+
default: '',
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
/** OpenRegister register slug of the surface. */
|
|
59
|
+
register: {
|
|
60
|
+
type: [String, Object],
|
|
61
|
+
default: '',
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/** OpenRegister schema slug of the surface. */
|
|
65
|
+
schema: {
|
|
66
|
+
type: [String, Object],
|
|
67
|
+
default: '',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
emits: ['header', 'saved'],
|
|
72
|
+
|
|
73
|
+
data() {
|
|
74
|
+
return {
|
|
75
|
+
/** The add action each group reported, by group index. */
|
|
76
|
+
groupActions: {},
|
|
77
|
+
/** The mounted field lists, by group index. */
|
|
78
|
+
lists: {},
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
computed: {
|
|
83
|
+
/**
|
|
84
|
+
* The groups as field-list contents: the pairs look, the add opened
|
|
85
|
+
* from this widget's menu, and the shared `readOnly` and `afterSave`.
|
|
86
|
+
*
|
|
87
|
+
* @return {Array<object>}
|
|
88
|
+
*/
|
|
89
|
+
groupContents() {
|
|
90
|
+
const groups = Array.isArray(this.content.groups) ? this.content.groups : [];
|
|
91
|
+
return groups
|
|
92
|
+
.filter((group) => group && typeof group.field === 'string' && group.field !== '')
|
|
93
|
+
.map((group) => ({
|
|
94
|
+
...group,
|
|
95
|
+
variant: 'pairs',
|
|
96
|
+
readOnly: this.content.readOnly === true || group.readOnly === true,
|
|
97
|
+
afterSave: group.afterSave || this.content.afterSave,
|
|
98
|
+
add: group.add ? { ...group.add, trigger: 'button', placement: 'title' } : undefined,
|
|
99
|
+
}))
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
/** Whether the Add sits in the card's title row. */
|
|
103
|
+
inTitle() {
|
|
104
|
+
return this.content.add?.placement === 'title'
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
addLabel() {
|
|
108
|
+
return this.tr(this.content.add?.label || 'Add')
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
addAriaLabel() {
|
|
112
|
+
return this.tr(this.content.add?.ariaLabel || '') || this.addLabel
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* One item per group that can add: its label, and opening its form.
|
|
117
|
+
*
|
|
118
|
+
* @return {Array<{key: string, label: string, run: () => void}>}
|
|
119
|
+
*/
|
|
120
|
+
menuItems() {
|
|
121
|
+
return this.groupContents
|
|
122
|
+
.map((group, index) => ({ group, index, action: this.groupActions[index] }))
|
|
123
|
+
.filter(({ action }) => action)
|
|
124
|
+
.map(({ group, index, action }) => ({
|
|
125
|
+
key: `${group.field}-${index}`,
|
|
126
|
+
label: action.label,
|
|
127
|
+
run: () => this.openGroup(index),
|
|
128
|
+
}))
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* What the card's title row draws: one outlined Add with the menu.
|
|
133
|
+
*
|
|
134
|
+
* @return {{actions: Array<object>}}
|
|
135
|
+
*/
|
|
136
|
+
header() {
|
|
137
|
+
if (!this.inTitle || this.menuItems.length === 0) {
|
|
138
|
+
return { actions: [] }
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
actions: [{
|
|
142
|
+
label: this.addLabel,
|
|
143
|
+
ariaLabel: this.addAriaLabel,
|
|
144
|
+
icon: 'Plus',
|
|
145
|
+
variant: 'secondary',
|
|
146
|
+
items: this.menuItems.map(({ label, run }) => ({ label, run })),
|
|
147
|
+
}],
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
watch: {
|
|
153
|
+
header: {
|
|
154
|
+
immediate: true,
|
|
155
|
+
handler(header) {
|
|
156
|
+
/**
|
|
157
|
+
* @event header The card's title-row actions, `{ actions }`, for the host to draw.
|
|
158
|
+
*/
|
|
159
|
+
this.$emit('header', header);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
methods: {
|
|
165
|
+
/**
|
|
166
|
+
* Pass a group's save on.
|
|
167
|
+
*
|
|
168
|
+
* @param {{field: string, value: Array}} payload The group's field and the list it saved.
|
|
169
|
+
*/
|
|
170
|
+
onSaved(payload) {
|
|
171
|
+
/**
|
|
172
|
+
* @event saved One group's list was saved: one PATCH of its field succeeded.
|
|
173
|
+
* @type {{field: string, value: Array}}
|
|
174
|
+
*/
|
|
175
|
+
this.$emit('saved', payload);
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
tr(text) {
|
|
179
|
+
if (typeof text !== 'string' || text === '') {
|
|
180
|
+
return ''
|
|
181
|
+
}
|
|
182
|
+
return typeof this.cnTranslate === 'function' ? this.cnTranslate(text) : text
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
setList(index, el) {
|
|
186
|
+
if (el) {
|
|
187
|
+
this.lists[index] = el;
|
|
188
|
+
} else {
|
|
189
|
+
delete this.lists[index];
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Keep the add action a group reported (none on a read-only group).
|
|
195
|
+
*
|
|
196
|
+
* @param {number} index The group.
|
|
197
|
+
* @param {{actions?: Array}} header What the group reported.
|
|
198
|
+
* @return {void}
|
|
199
|
+
*/
|
|
200
|
+
onGroupHeader(index, header) {
|
|
201
|
+
const action = (header && Array.isArray(header.actions) ? header.actions : []).find((candidate) => candidate && candidate.add);
|
|
202
|
+
if (action) {
|
|
203
|
+
this.groupActions = { ...this.groupActions, [index]: action };
|
|
204
|
+
} else if (this.groupActions[index]) {
|
|
205
|
+
const rest = { ...this.groupActions };
|
|
206
|
+
delete rest[index];
|
|
207
|
+
this.groupActions = rest;
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Open one group's form and close the others.
|
|
213
|
+
*
|
|
214
|
+
* @param {number} index The group.
|
|
215
|
+
* @return {void}
|
|
216
|
+
*/
|
|
217
|
+
openGroup(index) {
|
|
218
|
+
for (const [key, list] of Object.entries(this.lists)) {
|
|
219
|
+
if (Number(key) !== index && list) {
|
|
220
|
+
list.adding = false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const list = this.lists[index];
|
|
224
|
+
if (list) {
|
|
225
|
+
list.adding = true;
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export { script as default };
|
|
232
|
+
//# sourceMappingURL=CnFieldGroupsWidget.vue2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CnFieldGroupsWidget.vue2.js","sources":["../../../../src/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2026 Conduction B.V.\n - SPDX-License-Identifier: EUPL-1.2\n-->\n\n<template>\n\t<div class=\"cn-field-groups-widget\" data-testid=\"cn-field-groups-widget\">\n\t\t<CnFieldListWidget\n\t\t\tv-for=\"(group, index) in groupContents\"\n\t\t\t:key=\"`${group.field}-${index}`\"\n\t\t\t:ref=\"(el) => setList(index, el)\"\n\t\t\t:content=\"group\"\n\t\t\t:objectData=\"objectData\"\n\t\t\t:objectId=\"objectId\"\n\t\t\t:register=\"register\"\n\t\t\t:schema=\"schema\"\n\t\t\t@header=\"onGroupHeader(index, $event)\"\n\t\t\t@saved=\"onSaved\" />\n\t\t<NcActions\n\t\t\tv-if=\"!inTitle && menuItems.length > 0\"\n\t\t\t:menuName=\"addLabel\"\n\t\t\t:ariaLabel=\"addAriaLabel\"\n\t\t\tclass=\"cn-field-groups-widget__add\"\n\t\t\tdata-testid=\"cn-field-groups-add\">\n\t\t\t<template #icon>\n\t\t\t\t<Plus :size=\"16\" />\n\t\t\t</template>\n\t\t\t<NcActionButton\n\t\t\t\tv-for=\"item in menuItems\"\n\t\t\t\t:key=\"item.key\"\n\t\t\t\t:data-testid=\"`cn-field-groups-add-${item.key}`\"\n\t\t\t\t@click=\"item.run\">\n\t\t\t\t{{ item.label }}\n\t\t\t</NcActionButton>\n\t\t</NcActions>\n\t</div>\n</template>\n\n<script>\nimport { NcActionButton, NcActions } from '@nextcloud/vue'\nimport Plus from 'vue-material-design-icons/Plus.vue'\nimport CnFieldListWidget from '../CnFieldListWidget/CnFieldListWidget.vue'\n\n/**\n * CnFieldGroupsWidget: the `field-groups` widget: several list fields of the\n * record in one card, each drawn as a field list in the pairs look (a label\n * beside a value), with one \"Add\" that offers a choice of list. Board PqKlant\n * \"Contactkanalen\": e-mail addresses, phone numbers and social profiles, one\n * \"Toevoegen\" menu in the card's title row.\n *\n * Each group is a `field-list` content (`field`, `row`, `add`, `edit`,\n * `remove`, `mirror`, `emptyLabel`, `emptyText`), so a group saves exactly as\n * a field list does: one PATCH of its own field after re-reading the stored\n * value, the server's refusal shown in its words.\n *\n * @spec openspec/changes/contact-side-cards-generic/specs/contact-side-cards-generic/spec.md#requirement-several-list-fields-share-one-card-and-one-add-menu\n */\nexport default {\n\tname: 'CnFieldGroupsWidget',\n\n\tcomponents: { CnFieldListWidget, NcActionButton, NcActions, Plus },\n\n\tinject: {\n\t\tcnTranslate: { default: () => (key) => key },\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * The widget configuration.\n\t\t *\n\t\t * - `groups`: `[<field-list content>]`, drawn in order in the pairs look.\n\t\t * - `add`: `{ label?, ariaLabel?, placement?: 'title' | 'footer' }`: the one Add, a menu with an\n\t\t * item per group that has an `add` (the group's `add.label`). `title` reports it for the card's\n\t\t * title row on the `header` event; `footer` (default) draws it under the groups.\n\t\t * - `readOnly`: no add, edit or remove in any group.\n\t\t * - `afterSave`: the field-list `afterSave` for every group that declares none.\n\t\t *\n\t\t * @type {object}\n\t\t */\n\t\tcontent: {\n\t\t\ttype: Object,\n\t\t\tdefault: () => ({}),\n\t\t},\n\n\t\t/** The current detail-page object. */\n\t\tobjectData: {\n\t\t\ttype: Object,\n\t\t\tdefault: null,\n\t\t},\n\n\t\t/** The current object id. */\n\t\tobjectId: {\n\t\t\ttype: [String, Number],\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** OpenRegister register slug of the surface. */\n\t\tregister: {\n\t\t\ttype: [String, Object],\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** OpenRegister schema slug of the surface. */\n\t\tschema: {\n\t\t\ttype: [String, Object],\n\t\t\tdefault: '',\n\t\t},\n\t},\n\n\temits: ['header', 'saved'],\n\n\tdata() {\n\t\treturn {\n\t\t\t/** The add action each group reported, by group index. */\n\t\t\tgroupActions: {},\n\t\t\t/** The mounted field lists, by group index. */\n\t\t\tlists: {},\n\t\t}\n\t},\n\n\tcomputed: {\n\t\t/**\n\t\t * The groups as field-list contents: the pairs look, the add opened\n\t\t * from this widget's menu, and the shared `readOnly` and `afterSave`.\n\t\t *\n\t\t * @return {Array<object>}\n\t\t */\n\t\tgroupContents() {\n\t\t\tconst groups = Array.isArray(this.content.groups) ? this.content.groups : []\n\t\t\treturn groups\n\t\t\t\t.filter((group) => group && typeof group.field === 'string' && group.field !== '')\n\t\t\t\t.map((group) => ({\n\t\t\t\t\t...group,\n\t\t\t\t\tvariant: 'pairs',\n\t\t\t\t\treadOnly: this.content.readOnly === true || group.readOnly === true,\n\t\t\t\t\tafterSave: group.afterSave || this.content.afterSave,\n\t\t\t\t\tadd: group.add ? { ...group.add, trigger: 'button', placement: 'title' } : undefined,\n\t\t\t\t}))\n\t\t},\n\n\t\t/** Whether the Add sits in the card's title row. */\n\t\tinTitle() {\n\t\t\treturn this.content.add?.placement === 'title'\n\t\t},\n\n\t\taddLabel() {\n\t\t\treturn this.tr(this.content.add?.label || 'Add')\n\t\t},\n\n\t\taddAriaLabel() {\n\t\t\treturn this.tr(this.content.add?.ariaLabel || '') || this.addLabel\n\t\t},\n\n\t\t/**\n\t\t * One item per group that can add: its label, and opening its form.\n\t\t *\n\t\t * @return {Array<{key: string, label: string, run: () => void}>}\n\t\t */\n\t\tmenuItems() {\n\t\t\treturn this.groupContents\n\t\t\t\t.map((group, index) => ({ group, index, action: this.groupActions[index] }))\n\t\t\t\t.filter(({ action }) => action)\n\t\t\t\t.map(({ group, index, action }) => ({\n\t\t\t\t\tkey: `${group.field}-${index}`,\n\t\t\t\t\tlabel: action.label,\n\t\t\t\t\trun: () => this.openGroup(index),\n\t\t\t\t}))\n\t\t},\n\n\t\t/**\n\t\t * What the card's title row draws: one outlined Add with the menu.\n\t\t *\n\t\t * @return {{actions: Array<object>}}\n\t\t */\n\t\theader() {\n\t\t\tif (!this.inTitle || this.menuItems.length === 0) {\n\t\t\t\treturn { actions: [] }\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tactions: [{\n\t\t\t\t\tlabel: this.addLabel,\n\t\t\t\t\tariaLabel: this.addAriaLabel,\n\t\t\t\t\ticon: 'Plus',\n\t\t\t\t\tvariant: 'secondary',\n\t\t\t\t\titems: this.menuItems.map(({ label, run }) => ({ label, run })),\n\t\t\t\t}],\n\t\t\t}\n\t\t},\n\t},\n\n\twatch: {\n\t\theader: {\n\t\t\timmediate: true,\n\t\t\thandler(header) {\n\t\t\t\t/**\n\t\t\t\t * @event header The card's title-row actions, `{ actions }`, for the host to draw.\n\t\t\t\t */\n\t\t\t\tthis.$emit('header', header)\n\t\t\t},\n\t\t},\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Pass a group's save on.\n\t\t *\n\t\t * @param {{field: string, value: Array}} payload The group's field and the list it saved.\n\t\t */\n\t\tonSaved(payload) {\n\t\t\t/**\n\t\t\t * @event saved One group's list was saved: one PATCH of its field succeeded.\n\t\t\t * @type {{field: string, value: Array}}\n\t\t\t */\n\t\t\tthis.$emit('saved', payload)\n\t\t},\n\n\t\ttr(text) {\n\t\t\tif (typeof text !== 'string' || text === '') {\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\treturn typeof this.cnTranslate === 'function' ? this.cnTranslate(text) : text\n\t\t},\n\n\t\tsetList(index, el) {\n\t\t\tif (el) {\n\t\t\t\tthis.lists[index] = el\n\t\t\t} else {\n\t\t\t\tdelete this.lists[index]\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Keep the add action a group reported (none on a read-only group).\n\t\t *\n\t\t * @param {number} index The group.\n\t\t * @param {{actions?: Array}} header What the group reported.\n\t\t * @return {void}\n\t\t */\n\t\tonGroupHeader(index, header) {\n\t\t\tconst action = (header && Array.isArray(header.actions) ? header.actions : []).find((candidate) => candidate && candidate.add)\n\t\t\tif (action) {\n\t\t\t\tthis.groupActions = { ...this.groupActions, [index]: action }\n\t\t\t} else if (this.groupActions[index]) {\n\t\t\t\tconst rest = { ...this.groupActions }\n\t\t\t\tdelete rest[index]\n\t\t\t\tthis.groupActions = rest\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Open one group's form and close the others.\n\t\t *\n\t\t * @param {number} index The group.\n\t\t * @return {void}\n\t\t */\n\t\topenGroup(index) {\n\t\t\tfor (const [key, list] of Object.entries(this.lists)) {\n\t\t\t\tif (Number(key) !== index && list) {\n\t\t\t\t\tlist.adding = false\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst list = this.lists[index]\n\t\t\tif (list) {\n\t\t\t\tlist.adding = true\n\t\t\t}\n\t\t},\n\t},\n}\n</script>\n\n<style scoped>\n.cn-field-groups-widget {\n\tdisplay: flex;\n\tflex-direction: column;\n\talign-items: stretch;\n\tgap: 8px;\n}\n\n/* One label column for every group, so the labels line up across the lists. */\n.cn-field-groups-widget :deep(.cn-field-list-widget__pairs) {\n\tgrid-template-columns: 120px minmax(0, 1fr);\n}\n\n.cn-field-groups-widget__add {\n\talign-self: flex-start;\n}\n</style>\n"],"names":["CnFieldListWidget"],"mappings":";;;;AA2CA;AACC;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAED,aAAe;CACd,IAAI,EAAE,qBAAqB;;CAE3B,UAAU,EAAE,q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AAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAA;AAC7B,GAAA,IAAI,IAAI,EAAE;AACT,IAAA,IAAI,CAAC,MAAK,GAAI,KAAG;AAClB,IAAA;GACA;EACD;AACF;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolveComponent, openBlock, createElementBlock, Fragment, renderList, createBlock, withCtx, createVNode, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
const _hoisted_1 = {
|
|
4
|
+
class: "cn-field-groups-widget",
|
|
5
|
+
"data-testid": "cn-field-groups-widget"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
9
|
+
const _component_CnFieldListWidget = resolveComponent("CnFieldListWidget");
|
|
10
|
+
const _component_Plus = resolveComponent("Plus");
|
|
11
|
+
const _component_NcActionButton = resolveComponent("NcActionButton");
|
|
12
|
+
const _component_NcActions = resolveComponent("NcActions");
|
|
13
|
+
|
|
14
|
+
return (openBlock(), createElementBlock("div", _hoisted_1, [
|
|
15
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList($options.groupContents, (group, index) => {
|
|
16
|
+
return (openBlock(), createBlock(_component_CnFieldListWidget, {
|
|
17
|
+
key: `${group.field}-${index}`,
|
|
18
|
+
ref_for: true,
|
|
19
|
+
ref: (el) => $options.setList(index, el),
|
|
20
|
+
content: group,
|
|
21
|
+
objectData: $props.objectData,
|
|
22
|
+
objectId: $props.objectId,
|
|
23
|
+
register: $props.register,
|
|
24
|
+
schema: $props.schema,
|
|
25
|
+
onHeader: $event => ($options.onGroupHeader(index, $event)),
|
|
26
|
+
onSaved: $options.onSaved
|
|
27
|
+
}, null, 8 /* PROPS */, ["content", "objectData", "objectId", "register", "schema", "onHeader", "onSaved"]))
|
|
28
|
+
}), 128 /* KEYED_FRAGMENT */)),
|
|
29
|
+
(!$options.inTitle && $options.menuItems.length > 0)
|
|
30
|
+
? (openBlock(), createBlock(_component_NcActions, {
|
|
31
|
+
key: 0,
|
|
32
|
+
menuName: $options.addLabel,
|
|
33
|
+
ariaLabel: $options.addAriaLabel,
|
|
34
|
+
class: "cn-field-groups-widget__add",
|
|
35
|
+
"data-testid": "cn-field-groups-add"
|
|
36
|
+
}, {
|
|
37
|
+
icon: withCtx(() => [
|
|
38
|
+
createVNode(_component_Plus, { size: 16 })
|
|
39
|
+
]),
|
|
40
|
+
default: withCtx(() => [
|
|
41
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList($options.menuItems, (item) => {
|
|
42
|
+
return (openBlock(), createBlock(_component_NcActionButton, {
|
|
43
|
+
key: item.key,
|
|
44
|
+
"data-testid": `cn-field-groups-add-${item.key}`,
|
|
45
|
+
onClick: item.run
|
|
46
|
+
}, {
|
|
47
|
+
default: withCtx(() => [
|
|
48
|
+
createTextVNode(toDisplayString(item.label), 1 /* TEXT */)
|
|
49
|
+
]),
|
|
50
|
+
_: 2 /* DYNAMIC */
|
|
51
|
+
}, 1032 /* PROPS, DYNAMIC_SLOTS */, ["data-testid", "onClick"]))
|
|
52
|
+
}), 128 /* KEYED_FRAGMENT */))
|
|
53
|
+
]),
|
|
54
|
+
_: 1 /* STABLE */
|
|
55
|
+
}, 8 /* PROPS */, ["menuName", "ariaLabel"]))
|
|
56
|
+
: createCommentVNode("v-if", true)
|
|
57
|
+
]))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { render };
|
|
61
|
+
//# sourceMappingURL=CnFieldGroupsWidget.vue3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CnFieldGroupsWidget.vue3.js","sources":["../../../../src/components/CnFieldGroupsWidget/CnFieldGroupsWidget.vue?vue&type=template&id=07590ebe&lang.js"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2026 Conduction B.V.\n - SPDX-License-Identifier: EUPL-1.2\n-->\n\n<template>\n\t<div class=\"cn-field-groups-widget\" data-testid=\"cn-field-groups-widget\">\n\t\t<CnFieldListWidget\n\t\t\tv-for=\"(group, index) in groupContents\"\n\t\t\t:key=\"`${group.field}-${index}`\"\n\t\t\t:ref=\"(el) => setList(index, el)\"\n\t\t\t:content=\"group\"\n\t\t\t:objectData=\"objectData\"\n\t\t\t:objectId=\"objectId\"\n\t\t\t:register=\"register\"\n\t\t\t:schema=\"schema\"\n\t\t\t@header=\"onGroupHeader(index, $event)\"\n\t\t\t@saved=\"onSaved\" />\n\t\t<NcActions\n\t\t\tv-if=\"!inTitle && menuItems.length > 0\"\n\t\t\t:menuName=\"addLabel\"\n\t\t\t:ariaLabel=\"addAriaLabel\"\n\t\t\tclass=\"cn-field-groups-widget__add\"\n\t\t\tdata-testid=\"cn-field-groups-add\">\n\t\t\t<template #icon>\n\t\t\t\t<Plus :size=\"16\" />\n\t\t\t</template>\n\t\t\t<NcActionButton\n\t\t\t\tv-for=\"item in menuItems\"\n\t\t\t\t:key=\"item.key\"\n\t\t\t\t:data-testid=\"`cn-field-groups-add-${item.key}`\"\n\t\t\t\t@click=\"item.run\">\n\t\t\t\t{{ item.label }}\n\t\t\t</NcActionButton>\n\t\t</NcActions>\n\t</div>\n</template>\n\n<script>\nimport { NcActionButton, NcActions } from '@nextcloud/vue'\nimport Plus from 'vue-material-design-icons/Plus.vue'\nimport CnFieldListWidget from '../CnFieldListWidget/CnFieldListWidget.vue'\n\n/**\n * CnFieldGroupsWidget: the `field-groups` widget: several list fields of the\n * record in one card, each drawn as a field list in the pairs look (a label\n * beside a value), with one \"Add\" that offers a choice of list. Board PqKlant\n * \"Contactkanalen\": e-mail addresses, phone numbers and social profiles, one\n * \"Toevoegen\" menu in the card's title row.\n *\n * Each group is a `field-list` content (`field`, `row`, `add`, `edit`,\n * `remove`, `mirror`, `emptyLabel`, `emptyText`), so a group saves exactly as\n * a field list does: one PATCH of its own field after re-reading the stored\n * value, the server's refusal shown in its words.\n *\n * @spec openspec/changes/contact-side-cards-generic/specs/contact-side-cards-generic/spec.md#requirement-several-list-fields-share-one-card-and-one-add-menu\n */\nexport default {\n\tname: 'CnFieldGroupsWidget',\n\n\tcomponents: { CnFieldListWidget, NcActionButton, NcActions, Plus },\n\n\tinject: {\n\t\tcnTranslate: { default: () => (key) => key },\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * The widget configuration.\n\t\t *\n\t\t * - `groups`: `[<field-list content>]`, drawn in order in the pairs look.\n\t\t * - `add`: `{ label?, ariaLabel?, placement?: 'title' | 'footer' }`: the one Add, a menu with an\n\t\t * item per group that has an `add` (the group's `add.label`). `title` reports it for the card's\n\t\t * title row on the `header` event; `footer` (default) draws it under the groups.\n\t\t * - `readOnly`: no add, edit or remove in any group.\n\t\t * - `afterSave`: the field-list `afterSave` for every group that declares none.\n\t\t *\n\t\t * @type {object}\n\t\t */\n\t\tcontent: {\n\t\t\ttype: Object,\n\t\t\tdefault: () => ({}),\n\t\t},\n\n\t\t/** The current detail-page object. */\n\t\tobjectData: {\n\t\t\ttype: Object,\n\t\t\tdefault: null,\n\t\t},\n\n\t\t/** The current object id. */\n\t\tobjectId: {\n\t\t\ttype: [String, Number],\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** OpenRegister register slug of the surface. */\n\t\tregister: {\n\t\t\ttype: [String, Object],\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** OpenRegister schema slug of the surface. */\n\t\tschema: {\n\t\t\ttype: [String, Object],\n\t\t\tdefault: '',\n\t\t},\n\t},\n\n\temits: ['header', 'saved'],\n\n\tdata() {\n\t\treturn {\n\t\t\t/** The add action each group reported, by group index. */\n\t\t\tgroupActions: {},\n\t\t\t/** The mounted field lists, by group index. */\n\t\t\tlists: {},\n\t\t}\n\t},\n\n\tcomputed: {\n\t\t/**\n\t\t * The groups as field-list contents: the pairs look, the add opened\n\t\t * from this widget's menu, and the shared `readOnly` and `afterSave`.\n\t\t *\n\t\t * @return {Array<object>}\n\t\t */\n\t\tgroupContents() {\n\t\t\tconst groups = Array.isArray(this.content.groups) ? this.content.groups : []\n\t\t\treturn groups\n\t\t\t\t.filter((group) => group && typeof group.field === 'string' && group.field !== '')\n\t\t\t\t.map((group) => ({\n\t\t\t\t\t...group,\n\t\t\t\t\tvariant: 'pairs',\n\t\t\t\t\treadOnly: this.content.readOnly === true || group.readOnly === true,\n\t\t\t\t\tafterSave: group.afterSave || this.content.afterSave,\n\t\t\t\t\tadd: group.add ? { ...group.add, trigger: 'button', placement: 'title' } : undefined,\n\t\t\t\t}))\n\t\t},\n\n\t\t/** Whether the Add sits in the card's title row. */\n\t\tinTitle() {\n\t\t\treturn this.content.add?.placement === 'title'\n\t\t},\n\n\t\taddLabel() {\n\t\t\treturn this.tr(this.content.add?.label || 'Add')\n\t\t},\n\n\t\taddAriaLabel() {\n\t\t\treturn this.tr(this.content.add?.ariaLabel || '') || this.addLabel\n\t\t},\n\n\t\t/**\n\t\t * One item per group that can add: its label, and opening its form.\n\t\t *\n\t\t * @return {Array<{key: string, label: string, run: () => void}>}\n\t\t */\n\t\tmenuItems() {\n\t\t\treturn this.groupContents\n\t\t\t\t.map((group, index) => ({ group, index, action: this.groupActions[index] }))\n\t\t\t\t.filter(({ action }) => action)\n\t\t\t\t.map(({ group, index, action }) => ({\n\t\t\t\t\tkey: `${group.field}-${index}`,\n\t\t\t\t\tlabel: action.label,\n\t\t\t\t\trun: () => this.openGroup(index),\n\t\t\t\t}))\n\t\t},\n\n\t\t/**\n\t\t * What the card's title row draws: one outlined Add with the menu.\n\t\t *\n\t\t * @return {{actions: Array<object>}}\n\t\t */\n\t\theader() {\n\t\t\tif (!this.inTitle || this.menuItems.length === 0) {\n\t\t\t\treturn { actions: [] }\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tactions: [{\n\t\t\t\t\tlabel: this.addLabel,\n\t\t\t\t\tariaLabel: this.addAriaLabel,\n\t\t\t\t\ticon: 'Plus',\n\t\t\t\t\tvariant: 'secondary',\n\t\t\t\t\titems: this.menuItems.map(({ label, run }) => ({ label, run })),\n\t\t\t\t}],\n\t\t\t}\n\t\t},\n\t},\n\n\twatch: {\n\t\theader: {\n\t\t\timmediate: true,\n\t\t\thandler(header) {\n\t\t\t\t/**\n\t\t\t\t * @event header The card's title-row actions, `{ actions }`, for the host to draw.\n\t\t\t\t */\n\t\t\t\tthis.$emit('header', header)\n\t\t\t},\n\t\t},\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Pass a group's save on.\n\t\t *\n\t\t * @param {{field: string, value: Array}} payload The group's field and the list it saved.\n\t\t */\n\t\tonSaved(payload) {\n\t\t\t/**\n\t\t\t * @event saved One group's list was saved: one PATCH of its field succeeded.\n\t\t\t * @type {{field: string, value: Array}}\n\t\t\t */\n\t\t\tthis.$emit('saved', payload)\n\t\t},\n\n\t\ttr(text) {\n\t\t\tif (typeof text !== 'string' || text === '') {\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\treturn typeof this.cnTranslate === 'function' ? this.cnTranslate(text) : text\n\t\t},\n\n\t\tsetList(index, el) {\n\t\t\tif (el) {\n\t\t\t\tthis.lists[index] = el\n\t\t\t} else {\n\t\t\t\tdelete this.lists[index]\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Keep the add action a group reported (none on a read-only group).\n\t\t *\n\t\t * @param {number} index The group.\n\t\t * @param {{actions?: Array}} header What the group reported.\n\t\t * @return {void}\n\t\t */\n\t\tonGroupHeader(index, header) {\n\t\t\tconst action = (header && Array.isArray(header.actions) ? header.actions : []).find((candidate) => candidate && candidate.add)\n\t\t\tif (action) {\n\t\t\t\tthis.groupActions = { ...this.groupActions, [index]: action }\n\t\t\t} else if (this.groupActions[index]) {\n\t\t\t\tconst rest = { ...this.groupActions }\n\t\t\t\tdelete rest[index]\n\t\t\t\tthis.groupActions = rest\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Open one group's form and close the others.\n\t\t *\n\t\t * @param {number} index The group.\n\t\t * @return {void}\n\t\t */\n\t\topenGroup(index) {\n\t\t\tfor (const [key, list] of Object.entries(this.lists)) {\n\t\t\t\tif (Number(key) !== index && list) {\n\t\t\t\t\tlist.adding = false\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst list = this.lists[index]\n\t\t\tif (list) {\n\t\t\t\tlist.adding = true\n\t\t\t}\n\t\t},\n\t},\n}\n</script>\n\n<style scoped>\n.cn-field-groups-widget {\n\tdisplay: flex;\n\tflex-direction: column;\n\talign-items: stretch;\n\tgap: 8px;\n}\n\n/* One label column for every group, so the labels line up across the lists. */\n.cn-field-groups-widget :deep(.cn-field-list-widget__pairs) {\n\tgrid-template-columns: 120px minmax(0, 1fr);\n}\n\n.cn-field-groups-widget__add {\n\talign-self: flex-start;\n}\n</style>\n"],"names":["_openBlock","_createElementBlock","_Fragment","_renderList","_createBlock","_createVNode"],"mappings":";;;AAWM,EAAA,KAAK,EAAC,wBAAM;AAAA,EAAA,aAAA,EAAA,wBAAA;;;;;;;;;AAAf,EAAA,QAAAA,SAAA,EAAA,EAAAC,kBAAA,QAAA;yCAWmBC,QATA,EAAA,IAAA,EAAAC,UAAA,CAAA,QAAA,CAAA,aAAA,EAAX,CAAA,KAAK,EAAE,KAAI,KAAA;sCASA,CAAA,4BAAA,EAAA;AARlB,QAAA,GAAG,EAAK,CAAA,EAAA,KAAK,CAAC,KAAI,IAAA,KAAA,CAAA,CAAA;;AAClB,QAAA,GAAG,GAAG,EAAE,KAAK,gBAAC,CAAA,KAAA,EAAA,EAAA,CAAA;AACd,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,UAAU,EAAE,MAAK,CAAA,UAAA;AACjB,QAAA,QAAO,EAAA,MAAA,CAAA,QAAA;AACP,QAAA,QAAQ,EAAE,MAAQ,CAAA,QAAA;AAClB,QAAA,MAAM,EAAE,MAAM,CAAA,MAAA;AACd,QAAA,QAAM,EAAE,MAAA,KAAA,QAAA,CAAA,aAAa,CAAC,KAAC,EAAA,MAAA,CAAA,CAAA;AACvB,QAAA,OAAK,EAAE,QAAO,CAAA,OAAA;;;MAER,QAAO,CAAA,OAAA,IAAC,QAAA,CAAA,SAAA,CAAA,MAAA,GAAA,CAAA;sBADfC;;AAEC,UAAA,QAAQ,EAAE,QAAQ,CAAA,QAAA;AAClB,UAAA,SAAS,EAAA,QAAA,CAAA,YAAA;AACV,UAAA,KAAK,EAAC,6BAAQ;uBACH,EAAA,qBAAc;;AACd,UAAA,IAAI,UACd,MAAmB;YAAnBC,WAAmB,CAAA,eAAA,EAAA,EAAZ,IAAI,EAAE,EAAE,EAAA,CAAA;;2BAGf,MAAe;4EAAA,QAAA,CAAA,SAAA,EAAA,CAAR,IAAI,KAAA;;gBACV,GAAG,EAAE,IAAG,CAAA,GAAA;gBACR,aAAC,EAAA,CAAA,oBAAA,EAAA,IAAA,CAAA,GAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import __sfc_main from './CnFieldGroupsWidget.vue.js';
|
|
2
|
+
import { registerDashboardWidget } from '../CnWidgetGrid/dashboardWidgetRegistry.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
6
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
7
|
+
*
|
|
8
|
+
* CnFieldGroupsWidget: self-registers the `field-groups` widget type
|
|
9
|
+
* (several list fields of the current object in one card, as label and value
|
|
10
|
+
* pairs, with one Add menu) into the shared dashboardWidgetRegistry at module
|
|
11
|
+
* load. Renderer only: declared in the manifest.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
registerDashboardWidget('field-groups', {
|
|
16
|
+
renderer: __sfc_main,
|
|
17
|
+
form: null,
|
|
18
|
+
defaultContent: {
|
|
19
|
+
groups: [],
|
|
20
|
+
readOnly: false,
|
|
21
|
+
},
|
|
22
|
+
displayName: 'Field groups',
|
|
23
|
+
icon: 'CardAccountPhoneOutline',
|
|
24
|
+
surfaces: ['detail-page'],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export { __sfc_main as CnFieldGroupsWidget, __sfc_main as default };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/CnFieldGroupsWidget/index.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * CnFieldGroupsWidget: self-registers the `field-groups` widget type\n * (several list fields of the current object in one card, as label and value\n * pairs, with one Add menu) into the shared dashboardWidgetRegistry at module\n * load. Renderer only: declared in the manifest.\n */\n\nimport CnFieldGroupsWidget from './CnFieldGroupsWidget.vue'\nimport { registerDashboardWidget } from '../CnWidgetGrid/dashboardWidgetRegistry.js'\n\nregisterDashboardWidget('field-groups', {\n\trenderer: CnFieldGroupsWidget,\n\tform: null,\n\tdefaultContent: {\n\t\tgroups: [],\n\t\treadOnly: false,\n\t},\n\tdisplayName: 'Field groups',\n\ticon: 'CardAccountPhoneOutline',\n\tsurfaces: ['detail-page'],\n})\n\nexport { CnFieldGroupsWidget }\nexport default CnFieldGroupsWidget\n"],"names":["CnFieldGroupsWidget"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA,uBAAuB,CAAC,cAAc,EAAE;AACxC,CAAC,QAAQ,EAAEA,UAAmB;AAC9B,CAAC,IAAI,EAAE,IAAI;AACX,CAAC,cAAc,EAAE;AACjB,EAAE,MAAM,EAAE,EAAE;AACZ,EAAE,QAAQ,EAAE,KAAK;AACjB,EAAE;AACF,CAAC,WAAW,EAAE,cAAc;AAC5B,CAAC,IAAI,EAAE,yBAAyB;AAChC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC;AAC1B,CAAC;;;;"}
|
|
@@ -2,7 +2,7 @@ import script from './CnFieldListWidget.vue2.js';
|
|
|
2
2
|
import { render } from './CnFieldListWidget.vue3.js';
|
|
3
3
|
|
|
4
4
|
script.render = render;
|
|
5
|
-
script.__scopeId = "data-v-
|
|
5
|
+
script.__scopeId = "data-v-089bbe34";
|
|
6
6
|
const __sfc_main = script;
|
|
7
7
|
|
|
8
8
|
export { __sfc_main as default };
|
|
@@ -93,6 +93,8 @@ var script = {
|
|
|
93
93
|
* - `add.fields[].type: 'checkbox'`; `add.exclusive` — flags only one entry holds; `add.requireOneOf` (+ `requireOneOfMessage`) — keys of which one must be filled.
|
|
94
94
|
* - `row.href` may be `{ path, scheme: 'mailto'|'tel' }`.
|
|
95
95
|
* - `afterSave` — `{ url, method?, body?, failureText? }`: called after every save that went through, with `@objectId` / `@object.<field>` tokens; when it fails the save stands and `failureText` shows.
|
|
96
|
+
* - `variant: 'pairs'`: each entry a label (`row.label`: a literal or a list of parts, a string part a literal and `{ path, map? }` a value, joined with ", ") beside its value (`row.title`, then the `row.meta` parts, joined with ", "; a link with `row.href`); edit and remove go in a "..." menu; an empty list shows `emptyLabel` beside the empty text, or nothing without one.
|
|
97
|
+
* - `mirror`: `{ field, path, prefer? }`: every save also writes `field` with the `path` of the entry flagged `prefer` (else the first entry, else ''), in the same PATCH.
|
|
96
98
|
*
|
|
97
99
|
* @type {object}
|
|
98
100
|
*/
|
|
@@ -177,10 +179,7 @@ var script = {
|
|
|
177
179
|
? { ...item, ...(this.live[key] || {}) }
|
|
178
180
|
: { value: item, ...(this.live[key] || {}) };
|
|
179
181
|
const title = this.text(entry, spec.title) || this.text(entry, spec.titleFallback) || (typeof item === 'string' ? item : key);
|
|
180
|
-
const meta =
|
|
181
|
-
.map((part) => this.text(entry, part))
|
|
182
|
-
.filter((part) => part !== '')
|
|
183
|
-
.join(' · ');
|
|
182
|
+
const meta = this.metaParts(entry, spec.meta).join(' · ');
|
|
184
183
|
const href = spec.href ? rowHref(entry, spec.href) : '';
|
|
185
184
|
return {
|
|
186
185
|
key,
|
|
@@ -188,6 +187,8 @@ var script = {
|
|
|
188
187
|
item,
|
|
189
188
|
entry,
|
|
190
189
|
title,
|
|
190
|
+
label: this.isPairs ? this.pairLabelOf(entry, spec.label) : '',
|
|
191
|
+
pairText: this.isPairs ? [title, ...this.metaParts(entry, spec.meta)].join(', ') : '',
|
|
191
192
|
href,
|
|
192
193
|
external: /^https?:\/\//i.test(href),
|
|
193
194
|
initials: spec.avatar ? this.initials(title) : '',
|
|
@@ -203,6 +204,16 @@ var script = {
|
|
|
203
204
|
})
|
|
204
205
|
},
|
|
205
206
|
|
|
207
|
+
/** Whether the rows are drawn as label and value pairs (`variant: 'pairs'`). */
|
|
208
|
+
isPairs() {
|
|
209
|
+
return this.content.variant === 'pairs'
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
/** The label an empty pairs list shows beside its empty text (`emptyLabel`), '' for none. */
|
|
213
|
+
pairsEmptyLabel() {
|
|
214
|
+
return this.tr(this.content.emptyLabel || '')
|
|
215
|
+
},
|
|
216
|
+
|
|
206
217
|
/** Whether the rows are drawn as framed options (`variant: 'options'`): a grip, the name, a code chip. */
|
|
207
218
|
isOptions() {
|
|
208
219
|
return this.content.variant === 'options'
|
|
@@ -420,7 +431,7 @@ var script = {
|
|
|
420
431
|
* placed in the band, then remove.
|
|
421
432
|
*
|
|
422
433
|
* @param {object} row The row.
|
|
423
|
-
* @return {Array<{id: string, label: string, run:
|
|
434
|
+
* @return {Array<{id: string, label: string, run: () => void}>}
|
|
424
435
|
*/
|
|
425
436
|
menuItems(row) {
|
|
426
437
|
const items = row.actions
|
|
@@ -449,6 +460,69 @@ var script = {
|
|
|
449
460
|
* @param {number} index Its position.
|
|
450
461
|
* @return {string}
|
|
451
462
|
*/
|
|
463
|
+
/**
|
|
464
|
+
* The filled meta parts of an entry, empty ones left out.
|
|
465
|
+
*
|
|
466
|
+
* @param {object} entry The entry.
|
|
467
|
+
* @param {Array|undefined} meta The `row.meta` config.
|
|
468
|
+
* @return {string[]}
|
|
469
|
+
*/
|
|
470
|
+
metaParts(entry, meta) {
|
|
471
|
+
return (Array.isArray(meta) ? meta : [])
|
|
472
|
+
.map((part) => this.text(entry, part))
|
|
473
|
+
.filter((part) => part !== '')
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* The label of a pair: `row.label` as one literal or a list of parts, a
|
|
478
|
+
* string part a literal and an object part a value off the entry
|
|
479
|
+
* (`{ path, map? }`), the filled parts joined with ", " ("E-mail, privé").
|
|
480
|
+
*
|
|
481
|
+
* @spec openspec/changes/contact-side-cards-generic/specs/contact-side-cards-generic/spec.md#requirement-a-field-list-draws-its-entries-as-label-and-value-pairs
|
|
482
|
+
* @param {object} entry The entry.
|
|
483
|
+
* @param {string|Array|undefined} label The `row.label` config.
|
|
484
|
+
* @return {string}
|
|
485
|
+
*/
|
|
486
|
+
pairLabelOf(entry, label) {
|
|
487
|
+
const parts = Array.isArray(label) ? label : [label];
|
|
488
|
+
return parts
|
|
489
|
+
.map((part) => (typeof part === 'string' ? this.tr(part) : this.text(entry, part)))
|
|
490
|
+
.filter((part) => typeof part === 'string' && part !== '')
|
|
491
|
+
.join(', ')
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* The "..." menu of a pair: edit and remove.
|
|
496
|
+
*
|
|
497
|
+
* @param {object} row The row.
|
|
498
|
+
* @return {Array<{id: string, label: string, run: Function}>}
|
|
499
|
+
*/
|
|
500
|
+
pairMenuItems(row) {
|
|
501
|
+
return [
|
|
502
|
+
...(this.canEdit ? [{ id: 'edit', label: this.editLabel, run: () => this.startEdit(row) }] : []),
|
|
503
|
+
...(this.canRemove ? [{ id: 'remove', label: this.removeLabel, run: () => this.remove(row) }] : []),
|
|
504
|
+
]
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* The plain field `mirror` keeps in step with the list: the `path` of the
|
|
509
|
+
* entry flagged `prefer`, else of the first entry, else ''.
|
|
510
|
+
*
|
|
511
|
+
* @spec openspec/changes/contact-side-cards-generic/specs/contact-side-cards-generic/spec.md#requirement-a-field-list-keeps-a-plain-field-in-step-with-its-preferred-entry
|
|
512
|
+
* @param {Array} list The list about to be saved.
|
|
513
|
+
* @return {object} `{ [mirror.field]: value }`, or `{}` without a mirror.
|
|
514
|
+
*/
|
|
515
|
+
mirrorOf(list) {
|
|
516
|
+
const mirror = this.content.mirror;
|
|
517
|
+
if (!mirror || typeof mirror.field !== 'string' || mirror.field === '' || typeof mirror.path !== 'string') {
|
|
518
|
+
return {}
|
|
519
|
+
}
|
|
520
|
+
const entries = list.filter((entry) => entry && typeof entry === 'object');
|
|
521
|
+
const chosen = (mirror.prefer && entries.find((entry) => entry[mirror.prefer] === true)) || entries[0];
|
|
522
|
+
const value = chosen ? readPath(chosen, mirror.path) : '';
|
|
523
|
+
return { [mirror.field]: value === undefined || value === null ? '' : value }
|
|
524
|
+
},
|
|
525
|
+
|
|
452
526
|
keyOf(item, index) {
|
|
453
527
|
if (item === null || typeof item !== 'object') {
|
|
454
528
|
return String(item)
|
|
@@ -816,7 +890,7 @@ var script = {
|
|
|
816
890
|
const { data: stored } = await axios.get(prefixUrl(this.objectUrl));
|
|
817
891
|
const current = readPath(stored || {}, this.content.field);
|
|
818
892
|
const next = change(Array.isArray(current) ? current : []);
|
|
819
|
-
const { data } = await axios.patch(prefixUrl(this.objectUrl), { [this.content.field]: next });
|
|
893
|
+
const { data } = await axios.patch(prefixUrl(this.objectUrl), { [this.content.field]: next, ...this.mirrorOf(next) });
|
|
820
894
|
const written = readPath(data || {}, this.content.field);
|
|
821
895
|
this.saved = Array.isArray(written) ? written : next;
|
|
822
896
|
/**
|