diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0ddbeb66..bbe028fee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Adds support for supplying CSS variable names to a color field's `presetColors` array as selectable values. * Adds support for dynamic focus trap in Context menus (prop `dynamicFocus`). When set to `true`, the focusable elements are recalculated on each cycle step. * Adds option to disable `tabindex` on `AposToggle` component. A new prop `disableFocus` can be set to `false` to disable the focus on the toggle button. It's enabled by default. +* Adds support for event on `addContextOperation`, an option `type` can now be passed and can be `modal` (default) or `event`, in this case it does not try to open a modal but emit a bus event using the action as name. ## 4.10.0 (2024-11-20) diff --git a/modules/@apostrophecms/doc-type/ui/apos/components/AposDocContextMenu.vue b/modules/@apostrophecms/doc-type/ui/apos/components/AposDocContextMenu.vue index cc28bdde93..6fe678c81c 100644 --- a/modules/@apostrophecms/doc-type/ui/apos/components/AposDocContextMenu.vue +++ b/modules/@apostrophecms/doc-type/ui/apos/components/AposDocContextMenu.vue @@ -24,7 +24,6 @@ import AposDocContextMenuLogic from 'Modules/@apostrophecms/doc-type/logic/AposD export default { name: 'AposDocContextMenu', mixins: [ AposDocContextMenuLogic ], - // Satisfy linting. emits: [ 'menu-open', 'menu-close', 'close' ] }; diff --git a/modules/@apostrophecms/doc-type/ui/apos/logic/AposDocContextMenu.js b/modules/@apostrophecms/doc-type/ui/apos/logic/AposDocContextMenu.js index a2f6aa42d5..6ff136e512 100644 --- a/modules/@apostrophecms/doc-type/ui/apos/logic/AposDocContextMenu.js +++ b/modules/@apostrophecms/doc-type/ui/apos/logic/AposDocContextMenu.js @@ -168,6 +168,7 @@ export default { } ] : []) ]; + return menu; }, customMenusByContext() { @@ -394,6 +395,7 @@ export default { this.customAction(this.context, operation); return; } + this[action](this.context); }, async edit(doc) { @@ -449,6 +451,10 @@ export default { ...docProps(doc), ...operation.props }; + if (operation.type === 'event') { + apos.bus.$emit(operation.action, props); + return; + } await apos.modal.execute(operation.modal, props); function docProps(doc) { return Object.fromEntries(Object.entries(operation.docProps || {}).map(([ key, value ]) => { diff --git a/modules/@apostrophecms/doc/index.js b/modules/@apostrophecms/doc/index.js index 77727915a4..3911c74d3d 100644 --- a/modules/@apostrophecms/doc/index.js +++ b/modules/@apostrophecms/doc/index.js @@ -1486,7 +1486,7 @@ module.exports = { ]; function validate ({ - action, context, label, modal, conditions, if: ifProps + action, context, type = 'modal', label, modal, conditions, if: ifProps }) { const allowedConditions = [ 'canPublish', @@ -1503,8 +1503,12 @@ module.exports = { 'canShareDraft' ]; - if (!action || !context || !label || !modal) { - throw self.apos.error('invalid', 'addContextOperation requires action, context, label and modal properties.'); + if (![ 'event', 'modal' ].includes(type)) { + throw self.apos.error('invalid', '`type` option must be `modal` (default) or `event`'); + } + + if (!action || !context || !label || (type === 'modal' && !modal)) { + throw self.apos.error('invalid', 'addContextOperation requires action, context, label and modal (if type is set to `modal` or unset) properties.'); } if (