@mlightcad/ribbon 0.0.1

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.
Files changed (46) hide show
  1. package/.github/workflows/ci.yml +110 -0
  2. package/.vscode/extensions.json +3 -0
  3. package/AGENTS.md +42 -0
  4. package/README.md +168 -0
  5. package/docs/requirements.md +96 -0
  6. package/eslint.config.js +41 -0
  7. package/images/ribbon.jpg +0 -0
  8. package/index.html +13 -0
  9. package/package.json +43 -0
  10. package/playwright/ribbon.spec.ts +6 -0
  11. package/playwright.config.ts +10 -0
  12. package/public/favicon.svg +1 -0
  13. package/public/icons.svg +24 -0
  14. package/src/App.vue +418 -0
  15. package/src/assets/hero.png +0 -0
  16. package/src/assets/vite.svg +1 -0
  17. package/src/assets/vue.svg +1 -0
  18. package/src/components/HelloWorld.vue +106 -0
  19. package/src/main.ts +9 -0
  20. package/src/ribbon/components/Ribbon.vue +844 -0
  21. package/src/ribbon/components/RibbonCollection.vue +51 -0
  22. package/src/ribbon/components/RibbonGroup.vue +327 -0
  23. package/src/ribbon/components/RibbonGroupContent.vue +61 -0
  24. package/src/ribbon/components/RibbonItemHost.vue +221 -0
  25. package/src/ribbon/components/RibbonTab.vue +44 -0
  26. package/src/ribbon/components/RibbonTabs.vue +49 -0
  27. package/src/ribbon/composables/useRibbonState.ts +272 -0
  28. package/src/ribbon/context.ts +4 -0
  29. package/src/ribbon/index.ts +99 -0
  30. package/src/ribbon/items/RibbonGallery.vue +78 -0
  31. package/src/ribbon/items/RibbonGroupButton.vue +85 -0
  32. package/src/ribbon/items/RibbonTemplateItem.vue +38 -0
  33. package/src/ribbon/modules/RibbonBackstage.vue +69 -0
  34. package/src/ribbon/modules/RibbonContextualTabs.vue +65 -0
  35. package/src/ribbon/modules/RibbonFileMenu.vue +88 -0
  36. package/src/ribbon/modules/RibbonKeyTips.vue +114 -0
  37. package/src/ribbon/styles/ribbon.css +925 -0
  38. package/src/ribbon/types.ts +162 -0
  39. package/src/style.css +328 -0
  40. package/src/tests/ribbon.spec.ts +830 -0
  41. package/src/tests/setup.ts +4 -0
  42. package/tools/release.mjs +107 -0
  43. package/tsconfig.app.json +14 -0
  44. package/tsconfig.json +7 -0
  45. package/tsconfig.node.json +24 -0
  46. package/vite.config.ts +38 -0
@@ -0,0 +1,51 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import type { RibbonCollectionLayout } from '../types'
4
+
5
+ /**
6
+ * @component MlRibbonCollection
7
+ * @description
8
+ * Layout container for a group-level item collection. It controls row/column flow
9
+ * and exposes a CSS variable for row-based packing.
10
+ *
11
+ * @prop id - Unique collection identifier.
12
+ * @prop layout - Collection flow direction (`row` or `column`).
13
+ * @prop rows - Desired row count when the collection is rendered in grid-like modes.
14
+ *
15
+ * @slot default - Collection items, typically `MlRibbonItemHost` components.
16
+ *
17
+ * @example
18
+ * ```vue
19
+ * <MlRibbonCollection id="clipboard-right" layout="column" :rows="3">
20
+ * <MlRibbonItemHost ... />
21
+ * </MlRibbonCollection>
22
+ * ```
23
+ */
24
+ const props = withDefaults(
25
+ defineProps<{
26
+ id: string
27
+ layout?: RibbonCollectionLayout
28
+ rows?: number
29
+ }>(),
30
+ {
31
+ layout: 'row',
32
+ rows: 3,
33
+ },
34
+ )
35
+
36
+ const collectionStyle = computed(() => ({
37
+ '--ml-ribbon-collection-rows': String(props.rows),
38
+ }))
39
+ </script>
40
+
41
+ <template>
42
+ <div
43
+ class="ml-ribbon-collection"
44
+ :class="[`ml-ribbon-collection--${props.layout}`]"
45
+ :style="collectionStyle"
46
+ >
47
+ <slot />
48
+ </div>
49
+ </template>
50
+
51
+
@@ -0,0 +1,327 @@
1
+ <script setup lang="ts">
2
+ import { ElButton, ElIcon, ElPopover } from 'element-plus'
3
+ import { ArrowDown, Promotion } from '@element-plus/icons-vue'
4
+ import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
5
+ import type { Component } from 'vue'
6
+ import { useGlobalConfig } from 'element-plus'
7
+ import type { RibbonGroupModel } from '../types'
8
+ import MlRibbonGroupContent from './RibbonGroupContent.vue'
9
+
10
+ /**
11
+ * @component MlRibbonGroup
12
+ * @description
13
+ * Visual wrapper for a ribbon group. It renders the group frame/title area and
14
+ * automatically moves clipped items into an overflow popover when space is limited.
15
+ *
16
+ * @prop id - Group identifier.
17
+ * @prop title - Group title shown in the footer.
18
+ * @prop icon - Optional Vue icon component for the group title area.
19
+ * @prop groupIconCss - Optional CSS marker used by host logic to map string icons.
20
+ * @prop orientation - Primary group layout direction.
21
+ * @prop autoWidth - Whether group width is auto-sized.
22
+ * @prop priority - Overflow priority hint (higher values overflow first).
23
+ * @prop launcher - Enables launcher affordance.
24
+ * @prop showLauncherIcon - Explicit launcher icon visibility override.
25
+ * @prop groupModel - Full group model used to construct overflow content.
26
+ * @prop overflowTriggerAriaLabel - Accessible label for overflow trigger button.
27
+ * @prop galleryPreviewFallback - Fallback text passed to nested gallery items.
28
+ *
29
+ * @event item-click - Emitted when an item click bubbles from group content.
30
+ * Payload includes `{ groupId, itemId }`.
31
+ *
32
+ * @slot default - Group body content, usually `MlRibbonGroupContent`.
33
+ *
34
+ * @example
35
+ * ```vue
36
+ * <MlRibbonGroup
37
+ * id="clipboard"
38
+ * title="Clipboard"
39
+ * :group-model="group"
40
+ * :priority="10"
41
+ * overflow-trigger-aria-label="Show hidden commands"
42
+ * @item-click="onItemClick"
43
+ * >
44
+ * <MlRibbonGroupContent :group="group" />
45
+ * </MlRibbonGroup>
46
+ * ```
47
+ */
48
+ const props = defineProps<{
49
+ id: string
50
+ title: string
51
+ icon?: string | Component
52
+ groupIconCss?: string
53
+ orientation?: 'row' | 'column'
54
+ autoWidth?: boolean
55
+ priority?: number
56
+ launcher?: boolean
57
+ showLauncherIcon?: boolean
58
+ groupModel?: RibbonGroupModel
59
+ overflowTriggerAriaLabel?: string
60
+ galleryPreviewFallback?: string
61
+ }>()
62
+
63
+ const emit = defineEmits<{ (e: 'item-click', payload: { groupId: string; itemId: string }): void }>()
64
+
65
+ const isAutoWidth = computed(() => props.autoWidth !== false)
66
+ const groupSectionRef = ref<HTMLElement | null>(null)
67
+ const overflowItemIds = ref<string[]>([])
68
+ const overflowTriggerRef = ref<HTMLElement | null>(null)
69
+ const footerTriggerRef = ref<HTMLElement | null>(null)
70
+ const overflowSkidOffset = ref(0)
71
+ const footerSkidOffset = ref(0)
72
+ const globalSize = useGlobalConfig('size', '')
73
+ const resolvedSize = computed(() => globalSize.value || 'default')
74
+ const overflowPopperClass = computed(
75
+ () => `ml-ribbon-group__overflow-popover ml-ribbon-group__overflow-popover--size-${resolvedSize.value}`,
76
+ )
77
+ const overflowPopperOptions = computed(() => ({
78
+ modifiers: [
79
+ {
80
+ name: 'offset',
81
+ options: {
82
+ offset: [overflowSkidOffset.value, 8],
83
+ },
84
+ },
85
+ ],
86
+ }))
87
+ const footerPopperOptions = computed(() => ({
88
+ modifiers: [
89
+ {
90
+ name: 'offset',
91
+ options: {
92
+ offset: [footerSkidOffset.value, 8],
93
+ },
94
+ },
95
+ ],
96
+ }))
97
+
98
+ const iconComponent = computed<Component | null>(() => {
99
+ if (!props.icon || typeof props.icon === 'string') return null
100
+ return props.icon
101
+ })
102
+
103
+ const hasOverflowItems = computed(() => overflowItemIds.value.length > 0)
104
+ const hasFooterMenuItems = computed(() => (props.groupModel?.footerMenuItems?.length ?? 0) > 0)
105
+
106
+ const overflowGroupModel = computed<RibbonGroupModel | null>(() => {
107
+ if (!props.groupModel || !overflowItemIds.value.length) return null
108
+ const overflowSet = new Set(overflowItemIds.value)
109
+ const collections =
110
+ props.groupModel.collections
111
+ ?.map((collection) => ({
112
+ ...collection,
113
+ items: collection.items.filter((item) => overflowSet.has(item.id)),
114
+ }))
115
+ .filter((collection) => collection.items.length > 0) ?? []
116
+ if (!collections.length) return null
117
+
118
+ return {
119
+ ...props.groupModel,
120
+ collections,
121
+ }
122
+ })
123
+
124
+ const footerMenuGroupModel = computed<RibbonGroupModel | null>(() => {
125
+ if (!props.groupModel?.footerMenuItems?.length) return null
126
+ return {
127
+ id: `${props.groupModel.id}-footer-menu`,
128
+ title: '',
129
+ orientation: 'row',
130
+ collections: [
131
+ {
132
+ id: `${props.groupModel.id}-footer-menu-collection`,
133
+ layout: 'row',
134
+ items: props.groupModel.footerMenuItems,
135
+ },
136
+ ],
137
+ }
138
+ })
139
+
140
+ /**
141
+ * Recomputes which items are visually clipped and should appear in group overflow.
142
+ */
143
+ function recomputeOverflowItems() {
144
+ const section = groupSectionRef.value
145
+ const content = section?.querySelector<HTMLElement>('.ml-ribbon-group__content')
146
+ if (!content) {
147
+ if (overflowItemIds.value.length > 0) overflowItemIds.value = []
148
+ return
149
+ }
150
+ const contentRect = content.getBoundingClientRect()
151
+ if (contentRect.width <= 0 || contentRect.height <= 0) {
152
+ if (overflowItemIds.value.length > 0) overflowItemIds.value = []
153
+ return
154
+ }
155
+
156
+ const hiddenIds: string[] = []
157
+ const itemHosts = content.querySelectorAll<HTMLElement>('.ml-ribbon-item-host[data-item-id]')
158
+ itemHosts.forEach((host) => {
159
+ const itemId = host.dataset.itemId
160
+ if (!itemId) return
161
+ const rect = host.getBoundingClientRect()
162
+ const isOutOfBounds =
163
+ rect.right - contentRect.right > 0.5 ||
164
+ rect.bottom - contentRect.bottom > 0.5 ||
165
+ contentRect.left - rect.left > 0.5 ||
166
+ contentRect.top - rect.top > 0.5
167
+ if (isOutOfBounds) hiddenIds.push(itemId)
168
+ })
169
+
170
+ const same =
171
+ overflowItemIds.value.length === hiddenIds.length &&
172
+ overflowItemIds.value.every((id, index) => id === hiddenIds[index])
173
+ if (!same) overflowItemIds.value = hiddenIds
174
+ }
175
+
176
+ /**
177
+ * Schedules overflow-related recalculation after next DOM update.
178
+ */
179
+ function scheduleOverflowRecompute() {
180
+ nextTick(() => {
181
+ syncObservedContent()
182
+ recomputeOverflowOffset()
183
+ recomputeFooterOffset()
184
+ recomputeOverflowItems()
185
+ })
186
+ }
187
+
188
+ /**
189
+ * Recomputes popover horizontal offset for the group overflow trigger.
190
+ */
191
+ function recomputeOverflowOffset() {
192
+ const sectionRect = groupSectionRef.value?.getBoundingClientRect()
193
+ const triggerRect = overflowTriggerRef.value?.getBoundingClientRect()
194
+ if (!sectionRect || !triggerRect) {
195
+ if (overflowSkidOffset.value !== 0) overflowSkidOffset.value = 0
196
+ return
197
+ }
198
+ const nextOffset = Math.round(sectionRect.left - triggerRect.left)
199
+ if (overflowSkidOffset.value !== nextOffset) overflowSkidOffset.value = nextOffset
200
+ }
201
+
202
+ /**
203
+ * Recomputes popover horizontal offset for the footer trigger.
204
+ */
205
+ function recomputeFooterOffset() {
206
+ const sectionRect = groupSectionRef.value?.getBoundingClientRect()
207
+ const triggerRect = footerTriggerRef.value?.getBoundingClientRect()
208
+ if (!sectionRect || !triggerRect) {
209
+ if (footerSkidOffset.value !== 0) footerSkidOffset.value = 0
210
+ return
211
+ }
212
+ const nextOffset = Math.round(sectionRect.left - triggerRect.left)
213
+ if (footerSkidOffset.value !== nextOffset) footerSkidOffset.value = nextOffset
214
+ }
215
+
216
+ let resizeObserver: ResizeObserver | null = null
217
+ let observedContent: HTMLElement | null = null
218
+
219
+ /**
220
+ * Keeps ResizeObserver subscription aligned to the current content node.
221
+ */
222
+ function syncObservedContent() {
223
+ if (!resizeObserver) return
224
+ const content = groupSectionRef.value?.querySelector<HTMLElement>('.ml-ribbon-group__content') ?? null
225
+ if (observedContent === content) return
226
+ if (observedContent) resizeObserver.unobserve(observedContent)
227
+ if (content) resizeObserver.observe(content)
228
+ observedContent = content
229
+ }
230
+
231
+ watch(
232
+ () => props.groupModel,
233
+ () => {
234
+ scheduleOverflowRecompute()
235
+ },
236
+ { deep: true },
237
+ )
238
+
239
+ onMounted(() => {
240
+ if (typeof ResizeObserver !== 'undefined') {
241
+ resizeObserver = new ResizeObserver(() => {
242
+ recomputeOverflowOffset()
243
+ recomputeFooterOffset()
244
+ recomputeOverflowItems()
245
+ })
246
+ if (groupSectionRef.value) resizeObserver.observe(groupSectionRef.value)
247
+ syncObservedContent()
248
+ }
249
+ scheduleOverflowRecompute()
250
+ })
251
+
252
+ onUnmounted(() => {
253
+ resizeObserver?.disconnect()
254
+ })
255
+ </script>
256
+
257
+ <template>
258
+ <section
259
+ ref="groupSectionRef"
260
+ class="ml-ribbon-group"
261
+ :class="{ 'ml-ribbon-group--auto-width': isAutoWidth }"
262
+ :data-priority="priority ?? 100"
263
+ >
264
+ <div class="ml-ribbon-group__body">
265
+ <slot />
266
+ </div>
267
+ <footer class="ml-ribbon-group__footer">
268
+ <ElIcon v-if="iconComponent" class="ml-ribbon-group__icon"><component :is="iconComponent" /></ElIcon>
269
+ <span class="ml-ribbon-group__title">{{ title }}</span>
270
+ <ElPopover
271
+ v-if="hasFooterMenuItems && footerMenuGroupModel"
272
+ trigger="click"
273
+ placement="bottom-start"
274
+ :popper-class="overflowPopperClass"
275
+ :popper-options="footerPopperOptions"
276
+ >
277
+ <template #reference>
278
+ <button
279
+ ref="footerTriggerRef"
280
+ type="button"
281
+ class="ml-ribbon-group__footer-trigger"
282
+ :aria-label="overflowTriggerAriaLabel"
283
+ >
284
+ <ElIcon><ArrowDown /></ElIcon>
285
+ </button>
286
+ </template>
287
+ <div class="ml-ribbon-group__overflow-content">
288
+ <MlRibbonGroupContent
289
+ :group="footerMenuGroupModel"
290
+ :gallery-preview-fallback="galleryPreviewFallback"
291
+ @item-click="emit('item-click', $event)"
292
+ />
293
+ </div>
294
+ </ElPopover>
295
+ <ElPopover
296
+ v-if="hasOverflowItems && overflowGroupModel"
297
+ trigger="click"
298
+ placement="bottom-start"
299
+ :popper-class="overflowPopperClass"
300
+ :popper-options="overflowPopperOptions"
301
+ >
302
+ <template #reference>
303
+ <button
304
+ ref="overflowTriggerRef"
305
+ type="button"
306
+ class="ml-ribbon-group__overflow-trigger"
307
+ :aria-label="overflowTriggerAriaLabel"
308
+ >
309
+ <ElIcon><ArrowDown /></ElIcon>
310
+ </button>
311
+ </template>
312
+ <div class="ml-ribbon-group__overflow-content">
313
+ <MlRibbonGroupContent
314
+ :group="overflowGroupModel"
315
+ :gallery-preview-fallback="galleryPreviewFallback"
316
+ @item-click="emit('item-click', $event)"
317
+ />
318
+ </div>
319
+ </ElPopover>
320
+ <ElButton v-if="showLauncherIcon ?? launcher" link class="ml-ribbon-group__launcher">
321
+ <ElIcon><Promotion /></ElIcon>
322
+ </ElButton>
323
+ </footer>
324
+ </section>
325
+ </template>
326
+
327
+
@@ -0,0 +1,61 @@
1
+ <script setup lang="ts">
2
+ import type { RibbonGroupModel } from '../types'
3
+ import MlRibbonCollection from './RibbonCollection.vue'
4
+ import MlRibbonItemHost from './RibbonItemHost.vue'
5
+
6
+ /**
7
+ * @component MlRibbonGroupContent
8
+ * @description
9
+ * Internal renderer that expands a `RibbonGroupModel` into collections and concrete
10
+ * interactive items.
11
+ *
12
+ * @prop group - Group model with collections and items to render.
13
+ * @prop galleryPreviewFallback - Fallback text for gallery item previews.
14
+ *
15
+ * @event item-click - Emitted when any nested item is activated.
16
+ * Payload includes `{ groupId, itemId }`.
17
+ *
18
+ * @example
19
+ * ```vue
20
+ * <MlRibbonGroupContent
21
+ * :group="groupModel"
22
+ * gallery-preview-fallback="Preview"
23
+ * @item-click="onGroupItemClick"
24
+ * />
25
+ * ```
26
+ */
27
+ const props = withDefaults(
28
+ defineProps<{
29
+ group: RibbonGroupModel
30
+ galleryPreviewFallback?: string
31
+ }>(),
32
+ {},
33
+ )
34
+
35
+ const emit = defineEmits<{ (e: 'item-click', payload: { groupId: string; itemId: string }): void }>()
36
+ </script>
37
+
38
+ <template>
39
+ <div
40
+ class="ml-ribbon-group__content"
41
+ :class="[`ml-ribbon-group__content--${props.group.orientation ?? 'column'}`]"
42
+ >
43
+ <MlRibbonCollection
44
+ v-for="collection in props.group.collections ?? []"
45
+ :id="collection.id"
46
+ :key="collection.id"
47
+ :layout="collection.layout ?? (props.group.orientation === 'row' ? 'row' : 'column')"
48
+ :rows="collection.rows"
49
+ >
50
+ <MlRibbonItemHost
51
+ v-for="item in collection.items"
52
+ :id="item.id"
53
+ :key="item.id"
54
+ :item="item"
55
+ :group-id="props.group.id"
56
+ :gallery-preview-fallback="props.galleryPreviewFallback"
57
+ @item-click="emit('item-click', { groupId: props.group.id, itemId: item.id })"
58
+ />
59
+ </MlRibbonCollection>
60
+ </div>
61
+ </template>
@@ -0,0 +1,221 @@
1
+ <script setup lang="ts">
2
+ import { ArrowDown } from '@element-plus/icons-vue'
3
+ import { computed, inject } from 'vue'
4
+ import {
5
+ ElButton,
6
+ ElCheckbox,
7
+ ElColorPicker,
8
+ ElDropdown,
9
+ ElDropdownItem,
10
+ ElDropdownMenu,
11
+ ElIcon,
12
+ ElOption,
13
+ ElSelect,
14
+ useGlobalConfig,
15
+ } from 'element-plus'
16
+ import type { Component } from 'vue'
17
+ import { ribbonKey } from '../context'
18
+ import type { RibbonItemModel } from '../types'
19
+ import MlRibbonGallery from '../items/RibbonGallery.vue'
20
+ import MlRibbonGroupButton from '../items/RibbonGroupButton.vue'
21
+ import MlRibbonTemplateItem from '../items/RibbonTemplateItem.vue'
22
+
23
+ /**
24
+ * @component MlRibbonItemHost
25
+ * @description
26
+ * Type-aware item renderer. It maps `RibbonItemModel.type` to Element Plus controls
27
+ * or ribbon-specific item components and normalizes click/change emissions.
28
+ *
29
+ * @prop id - Item identifier.
30
+ * @prop item - Full item model, including type and item-specific props.
31
+ * @prop groupId - Parent group id used for telemetry and callbacks.
32
+ * @prop galleryPreviewFallback - Fallback label passed to `MlRibbonGallery`.
33
+ *
34
+ * @event item-click - Emitted when the hosted item is activated. Payload is item id.
35
+ *
36
+ * @slot template - Custom renderer slot for `template` item type.
37
+ *
38
+ * @example
39
+ * ```vue
40
+ * <MlRibbonItemHost
41
+ * id="font-family"
42
+ * :item="itemModel"
43
+ * group-id="font"
44
+ * gallery-preview-fallback="Preview"
45
+ * @item-click="onItemClick"
46
+ * />
47
+ * ```
48
+ */
49
+ const props = defineProps<{
50
+ id: string
51
+ item: RibbonItemModel
52
+ groupId: string
53
+ galleryPreviewFallback?: string
54
+ }>()
55
+
56
+ const emit = defineEmits<{ (e: 'item-click', payload: string): void }>()
57
+ const ribbon = inject(ribbonKey, null)
58
+ // Dropdown/combobox options are normalized to a stable array to simplify template rendering.
59
+ const options = computed(() => (Array.isArray(props.item.props?.options) ? props.item.props.options : []))
60
+ // Read Element Plus global size so popup menus inherit the same visual scale as ribbon controls.
61
+ const globalSize = useGlobalConfig('size', '')
62
+ const resolvedSize = computed(() => globalSize.value || 'default')
63
+ // Shared popper class names keep dropdown/select overlays on the same ribbon size theme.
64
+ const dropdownPopperClass = computed(
65
+ () => `ml-ribbon-dropdown-menu ml-ribbon-popper ml-ribbon-popper--size-${resolvedSize.value}`,
66
+ )
67
+ const selectPopperClass = computed(
68
+ () => `ml-ribbon-select-dropdown ml-ribbon-popper ml-ribbon-popper--size-${resolvedSize.value}`,
69
+ )
70
+ // Prefer icon declared in item props, then fallback to the top-level item icon.
71
+ const iconComponent = computed<Component | null>(() => {
72
+ const byProps = props.item.props?.icon as Component | undefined
73
+ if (byProps) return byProps
74
+ if (typeof props.item.icon === 'string' || !props.item.icon) return null
75
+ return props.item.icon as Component
76
+ })
77
+ // Hide label only when the schema explicitly sets hideLabel to true.
78
+ const shouldShowLabel = computed(() => props.item.hideLabel !== true)
79
+ const buttonAriaLabel = computed(() => props.item.label || props.item.id)
80
+ const keyTipText = computed(() => props.item.keyTip?.trim().toUpperCase() ?? '')
81
+ const shouldShowKeyTip = computed(() => {
82
+ if (!ribbon?.keyTipsOpen.value) return false
83
+ if (!keyTipText.value) return false
84
+ const sequence = ribbon.keyTipsSequence.value.toLowerCase()
85
+ if (!sequence) return true
86
+ return keyTipText.value.toLowerCase().startsWith(sequence)
87
+ })
88
+
89
+ /**
90
+ * Emits a normalized click payload so parent components only care about item id.
91
+ */
92
+ function handleClick() {
93
+ emit('item-click', props.id)
94
+ }
95
+
96
+ /**
97
+ * Resolves an option icon as a Vue component instance.
98
+ * @param option Dropdown option candidate.
99
+ * @returns Component icon when present and non-string; otherwise `null`.
100
+ */
101
+ function optionIconAsComponent(option: unknown): Component | null {
102
+ if (!option || typeof option !== 'object') return null
103
+ const icon = (option as { icon?: unknown }).icon
104
+ if (!icon || typeof icon === 'string') return null
105
+ return icon as Component
106
+ }
107
+
108
+ /**
109
+ * Resolves an option icon as a CSS class name.
110
+ * @param option Dropdown option candidate.
111
+ * @returns CSS class string when provided by schema; otherwise `null`.
112
+ */
113
+ function optionIconAsClass(option: unknown): string | null {
114
+ if (!option || typeof option !== 'object') return null
115
+ const icon = (option as { icon?: unknown }).icon
116
+ if (typeof icon !== 'string' || icon.trim().length === 0) return null
117
+ return icon
118
+ }
119
+ </script>
120
+
121
+ <template>
122
+ <div
123
+ class="ml-ribbon-item-host"
124
+ :class="[`is-${item.size ?? 'medium'}`, `type-${item.type}`, { 'is-label-hidden': item.hideLabel === true }]"
125
+ :data-item-id="id"
126
+ role="group"
127
+ >
128
+ <span v-if="shouldShowKeyTip" class="ml-ribbon-item-host__keytip">{{ keyTipText }}</span>
129
+
130
+ <MlRibbonGroupButton
131
+ v-if="item.type === 'groupButton'"
132
+ :id="item.id"
133
+ :label="item.label ?? ''"
134
+ :options="(item.props?.options as any[]) ?? []"
135
+ :multiple="Boolean(item.props?.multiple)"
136
+ :disabled="item.disabled"
137
+ @change="handleClick"
138
+ />
139
+
140
+ <MlRibbonGallery
141
+ v-else-if="item.type === 'gallery'"
142
+ :id="item.id"
143
+ :label="item.label ?? ''"
144
+ :categories="(item.props?.categories as any[]) ?? []"
145
+ :preview-fallback="props.galleryPreviewFallback"
146
+ :disabled="item.disabled"
147
+ @select="handleClick"
148
+ />
149
+
150
+ <MlRibbonTemplateItem v-else-if="item.type === 'template'" :id="item.id" :item="item">
151
+ <slot name="template" :item="item" />
152
+ </MlRibbonTemplateItem>
153
+
154
+ <ElDropdown
155
+ v-else-if="item.type === 'dropdown'"
156
+ :disabled="item.disabled"
157
+ :popper-class="dropdownPopperClass"
158
+ @command="handleClick"
159
+ >
160
+ <ElButton type="default" :aria-label="buttonAriaLabel">
161
+ <span class="ml-ribbon-item-host__content">
162
+ <ElIcon v-if="iconComponent" class="ml-ribbon-item-host__icon"><component :is="iconComponent" /></ElIcon>
163
+ <span class="ml-ribbon-item-host__text-row">
164
+ <span v-if="shouldShowLabel" class="ml-ribbon-item-host__label">{{ item.label }}</span>
165
+ <ElIcon class="ml-ribbon-item-host__dropdown-arrow"><ArrowDown /></ElIcon>
166
+ </span>
167
+ </span>
168
+ </ElButton>
169
+ <template #dropdown>
170
+ <ElDropdownMenu>
171
+ <ElDropdownItem
172
+ v-for="opt in options"
173
+ :key="String((opt as any).value)"
174
+ :command="(opt as any).value"
175
+ >
176
+ <span class="ml-ribbon-dropdown-item__content">
177
+ <ElIcon v-if="optionIconAsComponent(opt)" class="ml-ribbon-dropdown-item__icon">
178
+ <component :is="optionIconAsComponent(opt)" />
179
+ </ElIcon>
180
+ <i
181
+ v-else-if="optionIconAsClass(opt)"
182
+ class="ml-ribbon-dropdown-item__icon ml-ribbon-dropdown-item__icon--class"
183
+ :class="optionIconAsClass(opt)"
184
+ aria-hidden="true"
185
+ />
186
+ <span class="ml-ribbon-dropdown-item__label">{{ (opt as any).label }}</span>
187
+ </span>
188
+ </ElDropdownItem>
189
+ </ElDropdownMenu>
190
+ </template>
191
+ </ElDropdown>
192
+
193
+ <ElCheckbox v-else-if="item.type === 'checkbox'" :disabled="item.disabled" @change="handleClick">
194
+ {{ item.label }}
195
+ </ElCheckbox>
196
+
197
+ <ElColorPicker v-else-if="item.type === 'colorPicker'" :disabled="item.disabled" @change="handleClick" />
198
+
199
+ <ElSelect
200
+ v-else-if="item.type === 'comboBox'"
201
+ :disabled="item.disabled"
202
+ :popper-class="selectPopperClass"
203
+ style="width: 92px"
204
+ @change="handleClick"
205
+ >
206
+ <ElOption
207
+ v-for="opt in options"
208
+ :key="String((opt as any).value)"
209
+ :label="String((opt as any).label)"
210
+ :value="(opt as any).value"
211
+ />
212
+ </ElSelect>
213
+
214
+ <ElButton v-else :disabled="item.disabled" :aria-label="buttonAriaLabel" @click="handleClick">
215
+ <ElIcon v-if="iconComponent" class="ml-ribbon-item-host__icon"><component :is="iconComponent" /></ElIcon>
216
+ <span v-if="shouldShowLabel" class="ml-ribbon-item-host__label">{{ item.label ?? item.id }}</span>
217
+ </ElButton>
218
+ </div>
219
+ </template>
220
+
221
+