@conduction/nextcloud-vue 2.56.0-beta.14 → 2.56.0-beta.15
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/CnContextMenu/CnContextMenu.vue2.js +37 -26
- package/dist/esm/components/CnContextMenu/CnContextMenu.vue2.js.map +1 -1
- package/dist/esm/components/CnContextMenu/CnContextMenu.vue3.js +3 -3
- package/dist/esm/components/CnContextMenu/CnContextMenu.vue3.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +58 -48
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js +2 -2
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
- package/dist/esm/components/CnIndexPage/defaultActions.js +6 -7
- package/dist/esm/components/CnIndexPage/defaultActions.js.map +1 -1
- package/dist/esm/components/CnRowActions/CnRowActions.vue2.js +33 -34
- package/dist/esm/components/CnRowActions/CnRowActions.vue2.js.map +1 -1
- package/dist/esm/components/CnRowActions/CnRowActions.vue3.js +3 -3
- package/dist/esm/components/CnRowActions/CnRowActions.vue3.js.map +1 -1
- package/dist/esm/components/CnTimelineWidget/CnTimelineWidget.vue2.js +3 -2
- package/dist/esm/components/CnTimelineWidget/CnTimelineWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnTimelineWidget/CnTimelineWidget.vue3.js.map +1 -1
- package/dist/esm/composables/useContextMenu.js +4 -2
- package/dist/esm/composables/useContextMenu.js.map +1 -1
- package/dist/esm/utils/resolveRowActions.js +130 -0
- package/dist/esm/utils/resolveRowActions.js.map +1 -0
- package/dist/esm/utils/rowActionItem.js +99 -0
- package/dist/esm/utils/rowActionItem.js.map +1 -0
- package/dist/esm/utils/timelineEvents.js +44 -1
- package/dist/esm/utils/timelineEvents.js.map +1 -1
- package/dist/esm/utils/validateManifest.js +59 -3
- package/dist/esm/utils/validateManifest.js.map +1 -1
- package/dist/esm/utils/validateManifestV2.compiled.js +2 -2
- package/dist/esm/utils/validateManifestV2.compiled.js.map +1 -1
- package/dist/nextcloud-vue.cjs.js +469 -130
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/package.json +1 -1
- package/scripts/.jsdoc-baselines.json +2 -2
- package/src/components/CnContextMenu/CnContextMenu.vue +40 -29
- package/src/components/CnIndexPage/CnIndexPage.md +21 -0
- package/src/components/CnIndexPage/CnIndexPage.vue +61 -51
- package/src/components/CnIndexPage/defaultActions.js +6 -7
- package/src/components/CnRowActions/CnRowActions.vue +36 -37
- package/src/components/CnTimelineWidget/CnTimelineWidget.vue +3 -2
- package/src/composables/useContextMenu.js +4 -2
- package/src/schemas/app-manifest-v2.schema.json +46 -8
- package/src/utils/resolveRowActions.js +127 -0
- package/src/utils/rowActionItem.js +95 -0
- package/src/utils/timelineEvents.js +43 -0
- package/src/utils/validateManifest.js +60 -3
- package/src/utils/validateManifestV2.compiled.js +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { onBeforeUnmount, ref } from 'vue'
|
|
2
|
+
import { rowActionPayload } from '../utils/rowActionItem.js'
|
|
2
3
|
|
|
3
4
|
export const CTX_MENU_CSS_VAR_X = '--cn-ctx-menu-x'
|
|
4
5
|
export const CTX_MENU_CSS_VAR_Y = '--cn-ctx-menu-y'
|
|
@@ -135,15 +136,16 @@ export function useContextMenu() {
|
|
|
135
136
|
*
|
|
136
137
|
* Calls `action.handler(targetItem)` if a handler exists, then returns a
|
|
137
138
|
* payload object the caller can pass to `$emit('action', payload)`.
|
|
139
|
+
* The payload is the one CnRowActions and CnContextMenu emit: the label as `action`, plus `id` and `builtin: true` when the action carries them.
|
|
138
140
|
*
|
|
139
141
|
* @param {object} action Action definition with `label` and optional `handler`
|
|
140
|
-
* @return {{ action: string, row: object }}
|
|
142
|
+
* @return {{ action: string, row: object, id?: string, builtin?: boolean }}
|
|
141
143
|
*/
|
|
142
144
|
function triggerAction(action) {
|
|
143
145
|
if (action.handler && typeof action.handler === 'function') {
|
|
144
146
|
action.handler(targetItem.value)
|
|
145
147
|
}
|
|
146
|
-
return
|
|
148
|
+
return rowActionPayload(action, targetItem.value)
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
// Clean up DOM if the consumer unmounts while the menu is open — nothing
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"$id": "https://raw.githubusercontent.com/ConductionNL/nextcloud-vue/main/src/schemas/app-manifest-v2.schema.json",
|
|
4
4
|
"title": "Conduction App Manifest v2",
|
|
5
5
|
"description": "v2 schema for the JSON-driven page and navigation manifest consumed by @conduction/nextcloud-vue. Introduces a uniform widgets[] array on every page type with a per-slot grid coordinate system, a typed actions[] discriminator, and the required $schema field for version detection. v1 manifests continue to validate against app-manifest.schema.json (unchanged).",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.50.0",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"required": ["$schema", "version"],
|
|
9
9
|
"allOf": [
|
|
@@ -3458,14 +3458,30 @@
|
|
|
3458
3458
|
"actions": {
|
|
3459
3459
|
"type": "array",
|
|
3460
3460
|
"items": {
|
|
3461
|
-
"
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3461
|
+
"anyOf": [
|
|
3462
|
+
{
|
|
3463
|
+
"type": "object",
|
|
3464
|
+
"required": ["label"],
|
|
3465
|
+
"additionalProperties": true,
|
|
3466
|
+
"properties": {
|
|
3467
|
+
"label": { "type": "string", "minLength": 1 },
|
|
3468
|
+
"id": { "type": "string", "not": { "pattern": "^builtin:" } },
|
|
3469
|
+
"builtin": false
|
|
3470
|
+
}
|
|
3471
|
+
},
|
|
3472
|
+
{
|
|
3473
|
+
"type": "string",
|
|
3474
|
+
"enum": ["builtin:view", "builtin:edit", "builtin:copy", "builtin:delete"]
|
|
3475
|
+
}
|
|
3476
|
+
]
|
|
3467
3477
|
},
|
|
3468
|
-
"
|
|
3478
|
+
"allOf": [
|
|
3479
|
+
{ "contains": { "const": "builtin:view" }, "minContains": 0, "maxContains": 1 },
|
|
3480
|
+
{ "contains": { "const": "builtin:edit" }, "minContains": 0, "maxContains": 1 },
|
|
3481
|
+
{ "contains": { "const": "builtin:copy" }, "minContains": 0, "maxContains": 1 },
|
|
3482
|
+
{ "contains": { "const": "builtin:delete" }, "minContains": 0, "maxContains": 1 }
|
|
3483
|
+
],
|
|
3484
|
+
"description": "Declarative actions on a page. An object entry is governed ONLY by \"an object carrying a non-empty label\", deliberately: this key is polymorphic by page type (index rows dispatch $defs/action; detail pages also carry type='lifecycle-transition' entries), so one closed grammar here would reject working manifests. A label is what every dialect needs — CnRowActions renders an entry from its label and icon, so an entry without one became a full-height, clickable, EMPTY row in the overflow menu. An object is always an app action whatever its id: an id, when present, must be a string that does not start with 'builtin:', and the object may not set a 'builtin' key. On a type='index' page an entry may also be one of the placeholders \"builtin:view\", \"builtin:edit\", \"builtin:copy\" or \"builtin:delete\", each at most once, which puts that built-in row action at its position in the menu. A placeholder only places a built-in: config.actionToggles / the show*Action keys still decide whether it renders. Enabled built-ins the array does not place are appended after everything else in the order View, Edit, Copy, Delete. Any other string (a bare \"edit\", an unknown \"builtin:archive\") is refused, and placeholders are refused on every page type other than index."
|
|
3469
3485
|
},
|
|
3470
3486
|
"rowIndicators": {
|
|
3471
3487
|
"type": "array",
|
|
@@ -3732,6 +3748,10 @@
|
|
|
3732
3748
|
"type": "boolean",
|
|
3733
3749
|
"description": "Whether the built-in create / edit form dialog is enabled. Maps to CnIndexPage `showFormDialog`."
|
|
3734
3750
|
},
|
|
3751
|
+
"showViewAction": {
|
|
3752
|
+
"type": "boolean",
|
|
3753
|
+
"description": "Whether to add a View action to row actions. Maps to CnIndexPage `showViewAction`."
|
|
3754
|
+
},
|
|
3735
3755
|
"showEditAction": {
|
|
3736
3756
|
"type": "boolean",
|
|
3737
3757
|
"description": "Whether to add an Edit action to row actions. Maps to CnIndexPage `showEditAction`."
|
|
@@ -3824,6 +3844,24 @@
|
|
|
3824
3844
|
}
|
|
3825
3845
|
}
|
|
3826
3846
|
},
|
|
3847
|
+
{
|
|
3848
|
+
"description": "The \"builtin:<id>\" placeholders in config.actions place CnIndexPage's built-in row actions, so only a type='index' page may use them. On every other page type config.actions holds objects only; a placeholder there would validate and then render nothing (row-action-builtin-placement).",
|
|
3849
|
+
"if": {
|
|
3850
|
+
"not": {
|
|
3851
|
+
"properties": { "type": { "const": "index" } },
|
|
3852
|
+
"required": ["type"]
|
|
3853
|
+
}
|
|
3854
|
+
},
|
|
3855
|
+
"then": {
|
|
3856
|
+
"properties": {
|
|
3857
|
+
"config": {
|
|
3858
|
+
"properties": {
|
|
3859
|
+
"actions": { "items": { "type": "object" } }
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
},
|
|
3827
3865
|
{
|
|
3828
3866
|
"description": "tabInAddress puts the active tab of a record in the address. Only a detail page has a record and a tab strip, so the key is refused elsewhere rather than validating into a no-op (case-page-and-list-as-a-place).",
|
|
3829
3867
|
"if": {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The built-in row action ids, in their default order.
|
|
8
|
+
*
|
|
9
|
+
* @type {ReadonlyArray<string>}
|
|
10
|
+
*/
|
|
11
|
+
export const BUILTIN_ROW_ACTION_IDS = Object.freeze(['view', 'edit', 'copy', 'delete'])
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The prefix that marks a row action entry as a placeholder for a built-in.
|
|
15
|
+
*
|
|
16
|
+
* @type {string}
|
|
17
|
+
*/
|
|
18
|
+
export const BUILTIN_PLACEHOLDER_PREFIX = 'builtin:'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether an entry is one of the four built-in placeholders (`"builtin:view"`, `"builtin:edit"`, `"builtin:copy"`, `"builtin:delete"`).
|
|
22
|
+
*
|
|
23
|
+
* @param {object|string} entry A declared row action entry.
|
|
24
|
+
* @return {boolean} True for a known placeholder string.
|
|
25
|
+
*/
|
|
26
|
+
export function isBuiltinPlaceholder(entry) {
|
|
27
|
+
return typeof entry === 'string'
|
|
28
|
+
&& entry.startsWith(BUILTIN_PLACEHOLDER_PREFIX)
|
|
29
|
+
&& BUILTIN_ROW_ACTION_IDS.includes(entry.slice(BUILTIN_PLACEHOLDER_PREFIX.length))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A short name for an entry in a warning message.
|
|
34
|
+
*
|
|
35
|
+
* @param {object} action An app action object.
|
|
36
|
+
* @return {string} Its id, else its label, quoted.
|
|
37
|
+
*/
|
|
38
|
+
function describe(action) {
|
|
39
|
+
const name = (typeof action.id === 'string' && action.id !== '') ? action.id : action.label
|
|
40
|
+
return JSON.stringify(name === undefined ? '' : name)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a page's declared row actions and its enabled built-ins into the one ordered list every row surface renders.
|
|
45
|
+
*
|
|
46
|
+
* - An object is an app action, whatever its `id`; a `builtin` key on it is dropped, since only real built-ins carry that marker.
|
|
47
|
+
* - A placeholder (`"builtin:edit"`) puts that built-in at its position when it is enabled, and renders nothing when it is not: the toggle wins.
|
|
48
|
+
* - A repeated placeholder keeps its first position.
|
|
49
|
+
* - Any other entry is dropped.
|
|
50
|
+
* - Enabled built-ins the entries do not place are appended in the order `builtins` gives them.
|
|
51
|
+
*
|
|
52
|
+
* Every dropped or questionable entry is reported in `warnings`; the caller decides whether to log them.
|
|
53
|
+
*
|
|
54
|
+
* @param {Array<object|string>} declared The declared entries: app action objects and placeholders.
|
|
55
|
+
* @param {Array<{id: string}>} builtins The enabled built-in actions, in default order.
|
|
56
|
+
* @param {object} [options] Options.
|
|
57
|
+
* @param {(action: object) => object} [options.prepare] Maps an app action to the object rendered for it.
|
|
58
|
+
* @return {{actions: Array<object>, warnings: Array<{code: string, message: string}>, deleteNotLast: boolean}} The ordered actions, the warnings, and whether the built-in Delete is enabled but not last.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveRowActions(declared, builtins, { prepare = (action) => action } = {}) {
|
|
61
|
+
const enabled = new Map()
|
|
62
|
+
for (const builtin of (Array.isArray(builtins) ? builtins : [])) {
|
|
63
|
+
if (builtin && typeof builtin.id === 'string') {
|
|
64
|
+
enabled.set(builtin.id, builtin)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const placed = new Set()
|
|
68
|
+
const actions = []
|
|
69
|
+
const warnings = []
|
|
70
|
+
|
|
71
|
+
for (const entry of (Array.isArray(declared) ? declared : [])) {
|
|
72
|
+
if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
|
|
73
|
+
let action = entry
|
|
74
|
+
if (Object.hasOwn(entry, 'builtin')) {
|
|
75
|
+
const { builtin, ...rest } = entry
|
|
76
|
+
action = rest
|
|
77
|
+
warnings.push({
|
|
78
|
+
code: 'builtin-key-ignored',
|
|
79
|
+
message: `Action ${describe(entry)} sets "builtin", which only built-in actions carry; the key is ignored and the entry stays an app action.`,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
actions.push(prepare(action))
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
if (isBuiltinPlaceholder(entry)) {
|
|
86
|
+
const id = entry.slice(BUILTIN_PLACEHOLDER_PREFIX.length)
|
|
87
|
+
if (placed.has(id)) {
|
|
88
|
+
warnings.push({
|
|
89
|
+
code: 'repeated-placeholder',
|
|
90
|
+
message: `"${entry}" is placed more than once; only its first position is used.`,
|
|
91
|
+
})
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
94
|
+
placed.add(id)
|
|
95
|
+
if (!enabled.has(id)) {
|
|
96
|
+
warnings.push({
|
|
97
|
+
code: 'disabled-placeholder',
|
|
98
|
+
message: `"${entry}" is placed but that built-in action is turned off, so it renders nothing. Its show*Action toggle decides whether it renders.`,
|
|
99
|
+
})
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
actions.push(enabled.get(id))
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
warnings.push({
|
|
106
|
+
code: 'invalid-entry',
|
|
107
|
+
message: `Ignoring action ${JSON.stringify(entry)}: actions must be objects with an id and a label, or one of ${BUILTIN_ROW_ACTION_IDS.map((id) => `"${BUILTIN_PLACEHOLDER_PREFIX}${id}"`).join(', ')}. To turn a built-in action on or off use the showViewAction / showEditAction / showCopyAction / showDeleteAction props.`,
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for (const builtin of enabled.values()) {
|
|
112
|
+
if (!placed.has(builtin.id)) {
|
|
113
|
+
actions.push(builtin)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const deleteIndex = actions.findIndex((action) => action && action.builtin === true && action.id === 'delete')
|
|
118
|
+
const deleteNotLast = deleteIndex !== -1 && deleteIndex !== actions.length - 1
|
|
119
|
+
if (deleteNotLast) {
|
|
120
|
+
warnings.push({
|
|
121
|
+
code: 'delete-not-last',
|
|
122
|
+
message: `"${BUILTIN_PLACEHOLDER_PREFIX}delete" is not the last row action; it renders before ${actions.slice(deleteIndex + 1).map((a) => (a.builtin === true ? `"${BUILTIN_PLACEHOLDER_PREFIX}${a.id}"` : describe(a))).join(', ')}. Delete is normally last.`,
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { actions, warnings, deleteNotLast }
|
|
127
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* How a row action renders as a menu entry.
|
|
6
|
+
* CnRowActions and CnContextMenu both use these, so a row's actions menu and its right-click menu agree on which entries show and on each entry's key, testid and event payload.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { evaluateVisibleWhenLocal, isLocallyDecidableVisibleWhen } from './visibleWhen.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Whether an action is a built-in row action (View, Edit, Copy, Delete).
|
|
13
|
+
*
|
|
14
|
+
* @param {object} action The action.
|
|
15
|
+
* @return {boolean} True for a built-in carrying an id.
|
|
16
|
+
*/
|
|
17
|
+
function isBuiltin(action) {
|
|
18
|
+
return !!action && action.builtin === true && typeof action.id === 'string' && action.id !== ''
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether an action shows for an item.
|
|
23
|
+
* A locally decidable `visibleWhen` that is false hides it; an endpoint or source condition is not decided here.
|
|
24
|
+
* Then `visible` (a boolean or `(item) => boolean`) applies; without it the action shows.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} action The action.
|
|
27
|
+
* @param {object|string|number|null} item The row or right-clicked item.
|
|
28
|
+
* @return {boolean} Whether the entry renders.
|
|
29
|
+
*/
|
|
30
|
+
export function isRowActionVisible(action, item) {
|
|
31
|
+
if (action.visibleWhen
|
|
32
|
+
&& isLocallyDecidableVisibleWhen(action.visibleWhen)
|
|
33
|
+
&& evaluateVisibleWhenLocal(action.visibleWhen, item) === false) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
if (action.visible === undefined) {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
if (typeof action.visible === 'function') {
|
|
40
|
+
return !!action.visible(item)
|
|
41
|
+
}
|
|
42
|
+
return !!action.visible
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Slugify a label for a `data-testid` suffix: lowercase, kebab-case, non-alphanumerics stripped.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} label The label.
|
|
49
|
+
* @return {string} The slug.
|
|
50
|
+
*/
|
|
51
|
+
export function slugifyActionLabel(label) {
|
|
52
|
+
return String(label || '')
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
55
|
+
.replace(/^-+|-+$/g, '')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The render key of an entry: `builtin:<id>` for a built-in, the label for an app action.
|
|
60
|
+
* An app action with `id: "edit"` therefore never shares a key with the built-in Edit.
|
|
61
|
+
*
|
|
62
|
+
* @param {object} action The action.
|
|
63
|
+
* @return {string} The key.
|
|
64
|
+
*/
|
|
65
|
+
export function rowActionKey(action) {
|
|
66
|
+
return isBuiltin(action) ? `builtin:${action.id}` : action.label
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The `data-testid` of an entry: `cn-action-item-<id>` for a built-in, in every locale, and the slug of the label for an app action.
|
|
71
|
+
*
|
|
72
|
+
* @param {object} action The action.
|
|
73
|
+
* @return {string} The testid.
|
|
74
|
+
*/
|
|
75
|
+
export function rowActionTestId(action) {
|
|
76
|
+
return `cn-action-item-${isBuiltin(action) ? action.id : slugifyActionLabel(action.label)}`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The `action` event payload for an entry: `action` is the label, `id` is the action's id when it has one, and `builtin: true` marks a built-in.
|
|
81
|
+
*
|
|
82
|
+
* @param {object} action The action.
|
|
83
|
+
* @param {object|string|number|null} row The row or right-clicked item.
|
|
84
|
+
* @return {{action: string, row: (object|string|number|null), id?: string, builtin?: true}} The payload.
|
|
85
|
+
*/
|
|
86
|
+
export function rowActionPayload(action, row) {
|
|
87
|
+
const payload = { action: action.label, row }
|
|
88
|
+
if (typeof action.id === 'string' && action.id !== '') {
|
|
89
|
+
payload.id = action.id
|
|
90
|
+
}
|
|
91
|
+
if (isBuiltin(action)) {
|
|
92
|
+
payload.builtin = true
|
|
93
|
+
}
|
|
94
|
+
return payload
|
|
95
|
+
}
|
|
@@ -97,6 +97,49 @@ export function fieldEvents(object, fields, now = new Date()) {
|
|
|
97
97
|
* @param {Date} [now] The reference moment.
|
|
98
98
|
* @return {Array<object>} The events.
|
|
99
99
|
*/
|
|
100
|
+
/**
|
|
101
|
+
* The text at a path of a list entry, or '' when the path is unset or empty.
|
|
102
|
+
*
|
|
103
|
+
* @param {object} row The list entry.
|
|
104
|
+
* @param {string|undefined} path The path to read.
|
|
105
|
+
* @return {string} The text.
|
|
106
|
+
*/
|
|
107
|
+
function textAt(row, path) {
|
|
108
|
+
if (!path) {
|
|
109
|
+
return ''
|
|
110
|
+
}
|
|
111
|
+
const value = readPath(row, path)
|
|
112
|
+
return value === null || value === undefined ? '' : String(value)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Events from a list held on the object itself, such as a status history:
|
|
117
|
+
* `[{ field, dateField, labelField?, label?, detailField? }]`. Each entry of the
|
|
118
|
+
* list at `field` becomes one event, dated by `dateField`, labelled by its
|
|
119
|
+
* `labelField` value (else `label`), with `detailField` as the line under it.
|
|
120
|
+
*
|
|
121
|
+
* @param {object} object The object.
|
|
122
|
+
* @param {Array<object>} lists The list configs.
|
|
123
|
+
* @param {Date} now The moment that separates past from upcoming.
|
|
124
|
+
* @return {Array<object>} The events.
|
|
125
|
+
* @spec openspec/changes/timeline-audit-trails-url/specs/timeline-widget/spec.md#requirement-a-list-on-the-object-becomes-dated-events
|
|
126
|
+
*/
|
|
127
|
+
export function listEvents(object, lists, now = new Date()) {
|
|
128
|
+
return (Array.isArray(lists) ? lists : [])
|
|
129
|
+
.filter((l) => l && typeof l.field === 'string' && typeof l.dateField === 'string')
|
|
130
|
+
.flatMap((l) => {
|
|
131
|
+
const rows = readPath(object, l.field)
|
|
132
|
+
return (Array.isArray(rows) ? rows : []).map((row, i) => makeEvent({
|
|
133
|
+
id: `list:${l.field}:${i}`,
|
|
134
|
+
raw: readPath(row, l.dateField),
|
|
135
|
+
label: textAt(row, l.labelField) || l.label || l.field,
|
|
136
|
+
detail: textAt(row, l.detailField),
|
|
137
|
+
source: 'list',
|
|
138
|
+
}, now))
|
|
139
|
+
})
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
}
|
|
142
|
+
|
|
100
143
|
export function relatedEvents(rows, config, now = new Date()) {
|
|
101
144
|
const cfg = config || {}
|
|
102
145
|
const dateField = cfg.dateField || '@self.created'
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// names exist.
|
|
7
7
|
import { BUILT_IN_FILE_COLUMNS } from '../components/CnFilesBrowser/filesBrowserColumns.js'
|
|
8
8
|
import { LIBRARY_WIDGET_KEYS } from './libraryWidgetKeys.js'
|
|
9
|
+
// The same resolver CnIndexPage orders row actions with, so the placement warnings measure the order that actually renders.
|
|
10
|
+
import { resolveRowActions } from './resolveRowActions.js'
|
|
9
11
|
// Shared slot→columns resolution so the validator's grid bound matches the
|
|
10
12
|
// renderer (CnWidgetGrid) exactly. A mismatch would let a manifest pass
|
|
11
13
|
// validation yet clip at render time.
|
|
@@ -120,9 +122,14 @@ const CHART_VALUE_AXIS_BASELINES = ['auto', 'zero', 'fit']
|
|
|
120
122
|
* page's own `config.columns` does not declare (the page declares which
|
|
121
123
|
* columns it has; a scope only chooses among them)
|
|
122
124
|
*
|
|
125
|
+
* It also returns non-fatal `warnings`, which never affect `valid` (index pages with an `entitySource` are skipped):
|
|
126
|
+
* - A `"builtin:<id>"` placeholder whose built-in the manifest's toggles turn off
|
|
127
|
+
* - The built-in Delete enabled but not the last entry of the rendered row action order
|
|
128
|
+
*
|
|
123
129
|
* @spec openspec/changes/manifest-v2-schema/specs/manifest-v2-schema/spec.md
|
|
130
|
+
* @spec openspec/changes/row-action-builtin-placement/specs/index-page/spec.md
|
|
124
131
|
* @param {object} manifest The v2 manifest object to validate.
|
|
125
|
-
* @return {{ valid: boolean, errors: string[] }}
|
|
132
|
+
* @return {{ valid: boolean, errors: string[], warnings: string[] }}
|
|
126
133
|
*/
|
|
127
134
|
export function validateManifestV2(manifest) {
|
|
128
135
|
// Clone so Ajv useDefaults mutations don't affect the caller's copy.
|
|
@@ -789,7 +796,57 @@ export function validateManifestV2(manifest) {
|
|
|
789
796
|
})
|
|
790
797
|
}
|
|
791
798
|
|
|
792
|
-
|
|
799
|
+
// --- Post-schema warnings (never affect `valid`) ---
|
|
800
|
+
const warnings = []
|
|
801
|
+
|
|
802
|
+
// W1. Row action placement on an index page: a placeholder whose built-in the manifest turns off, and the built-in Delete placed before other row actions.
|
|
803
|
+
// An entitySource page is skipped: its built-in defaults depend on the source at runtime.
|
|
804
|
+
if (Array.isArray(clone.pages)) {
|
|
805
|
+
clone.pages.forEach((page, pIndex) => {
|
|
806
|
+
const config = page && page.type === 'index' && isPlainObject(page.config) ? page.config : null
|
|
807
|
+
if (!config || !Array.isArray(config.actions) || typeof config.entitySource === 'string') {
|
|
808
|
+
return
|
|
809
|
+
}
|
|
810
|
+
const resolved = resolveRowActions(config.actions, indexPageBuiltinStubs(config))
|
|
811
|
+
for (const warning of resolved.warnings) {
|
|
812
|
+
if (warning.code === 'disabled-placeholder') {
|
|
813
|
+
warnings.push(`pages[${pIndex}]/config/actions: ${warning.message}`)
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (resolved.deleteNotLast) {
|
|
817
|
+
warnings.push(`pages[${pIndex}]/config/actions: "builtin:delete" is not the last row action in the rendered order (enabled built-ins the array does not place are appended after it); Delete is normally last`)
|
|
818
|
+
}
|
|
819
|
+
})
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
return { valid: errors.length === 0, errors, warnings }
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* The built-in row actions an index page enables, as `{ id, builtin, label }` stubs in default order.
|
|
827
|
+
* They are read from its config the way CnPageRenderer derives the show*Action props: an explicit `config.show*Action` wins over `config.actionToggles`, and `config.readOnly: true` turns Edit, Copy and Delete off by default.
|
|
828
|
+
* A non-boolean value counts as the default.
|
|
829
|
+
*
|
|
830
|
+
* @param {object} config The page's config.
|
|
831
|
+
* @return {Array<{id: string, builtin: true, label: string}>} The enabled built-ins.
|
|
832
|
+
*/
|
|
833
|
+
function indexPageBuiltinStubs(config) {
|
|
834
|
+
const toggles = isPlainObject(config.actionToggles) ? config.actionToggles : {}
|
|
835
|
+
const flag = (key, readOnlyOff) => {
|
|
836
|
+
if (typeof config[key] === 'boolean') {
|
|
837
|
+
return config[key]
|
|
838
|
+
}
|
|
839
|
+
if (typeof toggles[key] === 'boolean') {
|
|
840
|
+
return toggles[key]
|
|
841
|
+
}
|
|
842
|
+
return !(readOnlyOff && config.readOnly === true)
|
|
843
|
+
}
|
|
844
|
+
return [
|
|
845
|
+
['view', flag('showViewAction', false)],
|
|
846
|
+
['edit', flag('showEditAction', true)],
|
|
847
|
+
['copy', flag('showCopyAction', true)],
|
|
848
|
+
['delete', flag('showDeleteAction', true)],
|
|
849
|
+
].filter(([, on]) => on).map(([id]) => ({ id, builtin: true, label: id }))
|
|
793
850
|
}
|
|
794
851
|
|
|
795
852
|
/**
|
|
@@ -853,7 +910,7 @@ function isSentinel(value) {
|
|
|
853
910
|
* `pageTypes` registry is known up-front. When omitted, any
|
|
854
911
|
* non-empty string is accepted; the runtime renderer logs a warning
|
|
855
912
|
* for unknown types.
|
|
856
|
-
* @return {{ valid: boolean, errors: string[] }}
|
|
913
|
+
* @return {{ valid: boolean, errors: string[], warnings?: string[] }} A v2 manifest also gets `warnings`, which never affect `valid`.
|
|
857
914
|
*/
|
|
858
915
|
export function validateManifest(manifest, options = {}) {
|
|
859
916
|
// Dispatch to v2 validator when the manifest declares a v2 $schema.
|