@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,44 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * @component MlRibbonTab
4
+ * @description
5
+ * Declarative tab definition component. It is primarily used as a structural marker
6
+ * and keeps tab metadata close to authored markup.
7
+ *
8
+ * @prop id - Unique tab identifier.
9
+ * @prop title - Display title in the tab strip.
10
+ * @prop visible - Controls tab visibility. Defaults to `true`.
11
+ * @prop contextual - Marks the tab as contextual.
12
+ * @prop contextualColor - Accent color used by contextual tab blocks.
13
+ * @prop contextualTitle - Group label shown above contextual tabs.
14
+ *
15
+ * @slot default - Optional declarative content for custom tab authoring workflows.
16
+ *
17
+ * @example
18
+ * ```vue
19
+ * <MlRibbonTab
20
+ * id="chart-tools"
21
+ * title="Chart Design"
22
+ * contextual
23
+ * contextual-title="Chart Tools"
24
+ * contextual-color="#eebe77"
25
+ * />
26
+ * ```
27
+ */
28
+ defineProps<{
29
+ id: string
30
+ title: string
31
+ visible?: boolean
32
+ contextual?: boolean
33
+ contextualColor?: string
34
+ contextualTitle?: string
35
+ }>()
36
+ </script>
37
+
38
+ <template>
39
+ <div class="ml-ribbon-tab-definition" hidden>
40
+ <slot />
41
+ </div>
42
+ </template>
43
+
44
+
@@ -0,0 +1,49 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+
4
+ /**
5
+ * @component MlRibbonTabs
6
+ * @description
7
+ * Renders the tab strip used by the ribbon header and emits selection changes.
8
+ *
9
+ * @prop tabs - Tab definitions to render. Tabs with `visible: false` are hidden.
10
+ * @prop activeTab - Currently active tab id.
11
+ *
12
+ * @event select - Emitted when a tab is clicked. Payload is the selected tab id.
13
+ *
14
+ * @example
15
+ * ```vue
16
+ * <MlRibbonTabs
17
+ * :tabs="[{ id: 'home', title: 'Home' }, { id: 'insert', title: 'Insert' }]"
18
+ * active-tab="home"
19
+ * @select="onTabSelect"
20
+ * />
21
+ * ```
22
+ */
23
+ const props = defineProps<{
24
+ tabs: { id: string; title: string; visible?: boolean }[]
25
+ activeTab: string
26
+ }>()
27
+
28
+ const emit = defineEmits<{ (e: 'select', id: string): void }>()
29
+ const visibleTabs = computed(() => props.tabs.filter((x) => x.visible !== false))
30
+ </script>
31
+
32
+ <template>
33
+ <div class="ml-ribbon-tabs" role="tablist">
34
+ <button
35
+ v-for="tab in visibleTabs"
36
+ :key="tab.id"
37
+ type="button"
38
+ class="ml-ribbon-tab"
39
+ :class="{ 'is-active': activeTab === tab.id }"
40
+ role="tab"
41
+ :aria-selected="activeTab === tab.id"
42
+ @click="emit('select', tab.id)"
43
+ >
44
+ {{ tab.title }}
45
+ </button>
46
+ </div>
47
+ </template>
48
+
49
+
@@ -0,0 +1,272 @@
1
+ import { computed, markRaw, ref, toRaw } from 'vue'
2
+ import type {
3
+ KeyTipModel,
4
+ RibbonContextValue,
5
+ RibbonDynamicApi,
6
+ RibbonGroupModel,
7
+ RibbonItemModel,
8
+ RibbonLayout,
9
+ RibbonTabModel,
10
+ } from '../types'
11
+
12
+ /**
13
+ * Normalizes potential component definitions to non-reactive objects.
14
+ * @param value Unknown schema value that may contain a component.
15
+ * @returns Normalized value safe for reactive storage.
16
+ */
17
+ function normalizeComponentCandidate<T>(value: T): T {
18
+ if (value == null || typeof value === 'string') return value
19
+ if (typeof value === 'object' || typeof value === 'function') {
20
+ return markRaw(toRaw(value as object)) as T
21
+ }
22
+ return value
23
+ }
24
+
25
+ /**
26
+ * Clones and normalizes item props, including icon-like fields.
27
+ * @param props Raw item props from schema.
28
+ * @returns Normalized props clone.
29
+ */
30
+ function normalizeItemProps(props?: Record<string, unknown>): Record<string, unknown> | undefined {
31
+ if (!props) return undefined
32
+ const nextProps: Record<string, unknown> = { ...props }
33
+ if ('icon' in nextProps) {
34
+ nextProps.icon = normalizeComponentCandidate(nextProps.icon)
35
+ }
36
+ if (Array.isArray(nextProps.options)) {
37
+ nextProps.options = nextProps.options.map((option) => {
38
+ if (!option || typeof option !== 'object') return option
39
+ const optionRecord = option as Record<string, unknown>
40
+ if (!('icon' in optionRecord)) return optionRecord
41
+ return {
42
+ ...optionRecord,
43
+ icon: normalizeComponentCandidate(optionRecord.icon),
44
+ }
45
+ })
46
+ }
47
+ return nextProps
48
+ }
49
+
50
+ /**
51
+ * Clones a ribbon item and normalizes component-like fields.
52
+ * @param item Source item model.
53
+ * @returns Cloned item model.
54
+ */
55
+ function cloneItem(item: RibbonItemModel): RibbonItemModel {
56
+ return {
57
+ ...item,
58
+ icon: normalizeComponentCandidate(item.icon),
59
+ props: normalizeItemProps(item.props),
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Clones a ribbon group recursively.
65
+ * @param group Source group model.
66
+ * @returns Cloned group model.
67
+ */
68
+ function cloneGroup(group: RibbonGroupModel): RibbonGroupModel {
69
+ return {
70
+ ...group,
71
+ icon: normalizeComponentCandidate(group.icon),
72
+ collections: group.collections?.map((collection) => ({
73
+ ...collection,
74
+ items: collection.items.map(cloneItem),
75
+ })),
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Clones a ribbon tab recursively.
81
+ * @param tab Source tab model.
82
+ * @returns Cloned tab model.
83
+ */
84
+ function cloneTab(tab: RibbonTabModel): RibbonTabModel {
85
+ return {
86
+ ...tab,
87
+ groups: tab.groups?.map(cloneGroup),
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Clones a tab array for mutable runtime state.
93
+ * @param tabs Source tab list.
94
+ * @returns Cloned tab list.
95
+ */
96
+ function cloneTabs(tabs: RibbonTabModel[]): RibbonTabModel[] {
97
+ return tabs.map(cloneTab)
98
+ }
99
+
100
+ /**
101
+ * Ensures group has at least one collection for item insertion.
102
+ * @param group Group model that may miss collections.
103
+ */
104
+ function ensureCollections(group: RibbonGroupModel) {
105
+ if (!group.collections || group.collections.length === 0) {
106
+ group.collections = [{ id: `${group.id}-collection-1`, items: [] }]
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Locates a target item list and applies a mutation callback.
112
+ * @param tabs Current mutable tabs tree.
113
+ * @param tabId Target tab id.
114
+ * @param groupId Target group id.
115
+ * @param collectionId Target collection id.
116
+ * @param fn Mutation callback for collection items.
117
+ */
118
+ function mutateItem(
119
+ tabs: RibbonTabModel[],
120
+ tabId: string,
121
+ groupId: string,
122
+ collectionId: string,
123
+ fn: (items: RibbonItemModel[]) => void,
124
+ ) {
125
+ const tab = tabs.find((x) => x.id === tabId)
126
+ if (!tab?.groups) return
127
+ const group = tab.groups.find((x) => x.id === groupId)
128
+ if (!group?.collections) return
129
+ const collection = group.collections.find((x) => x.id === collectionId)
130
+ if (!collection) return
131
+ fn(collection.items)
132
+ }
133
+
134
+ /**
135
+ * Creates the ribbon runtime state container and dynamic mutation API.
136
+ * @param ribbonId Ribbon instance id.
137
+ * @param initialTabs Initial tab schema.
138
+ * @param initialLayout Initial layout mode.
139
+ * @param initialMinimized Initial minimized state.
140
+ * @param initialActiveTab Initial active tab id.
141
+ * @returns Ribbon context plus computed visible tabs.
142
+ */
143
+ export function useRibbonState(
144
+ ribbonId: string,
145
+ initialTabs: RibbonTabModel[],
146
+ initialLayout: RibbonLayout,
147
+ initialMinimized: boolean,
148
+ initialActiveTab: string,
149
+ ) {
150
+ const layout = ref<RibbonLayout>(initialLayout)
151
+ const minimized = ref(initialMinimized)
152
+ const activeTab = ref(initialActiveTab)
153
+ const tabs = ref<RibbonTabModel[]>(cloneTabs(initialTabs))
154
+ const overflowOpen = ref(false)
155
+ const backdropOpen = ref(false)
156
+ const keyTipsOpen = ref(false)
157
+ const keyTips = ref<KeyTipModel[]>([])
158
+ const keyTipsSequence = ref('')
159
+
160
+ const visibleTabs = computed(() => tabs.value.filter((tab) => tab.visible !== false))
161
+
162
+ const api: RibbonDynamicApi = {
163
+ addTab(tab) {
164
+ tabs.value.push(cloneTab(tab))
165
+ if (!activeTab.value) activeTab.value = tab.id
166
+ },
167
+ removeTab(tabId) {
168
+ tabs.value = tabs.value.filter((tab) => tab.id !== tabId)
169
+ if (activeTab.value === tabId) {
170
+ activeTab.value = visibleTabs.value[0]?.id ?? ''
171
+ }
172
+ },
173
+ showTab(tabId) {
174
+ const tab = tabs.value.find((x) => x.id === tabId)
175
+ if (tab) tab.visible = true
176
+ },
177
+ hideTab(tabId) {
178
+ const tab = tabs.value.find((x) => x.id === tabId)
179
+ if (tab) tab.visible = false
180
+ },
181
+ selectTab(tabId) {
182
+ activeTab.value = tabId
183
+ },
184
+ addGroup(tabId, group) {
185
+ const tab = tabs.value.find((x) => x.id === tabId)
186
+ if (!tab) return
187
+ tab.groups ??= []
188
+ ensureCollections(group)
189
+ tab.groups.push(cloneGroup(group))
190
+ },
191
+ removeGroup(tabId, groupId) {
192
+ const tab = tabs.value.find((x) => x.id === tabId)
193
+ if (!tab?.groups) return
194
+ tab.groups = tab.groups.filter((group) => group.id !== groupId)
195
+ },
196
+ showGroup(tabId, groupId) {
197
+ const tab = tabs.value.find((x) => x.id === tabId)
198
+ const group = tab?.groups?.find((x) => x.id === groupId)
199
+ if (group) group.visible = true
200
+ },
201
+ hideGroup(tabId, groupId) {
202
+ const tab = tabs.value.find((x) => x.id === tabId)
203
+ const group = tab?.groups?.find((x) => x.id === groupId)
204
+ if (group) group.visible = false
205
+ },
206
+ addItem(tabId, groupId, collectionId, item) {
207
+ mutateItem(tabs.value, tabId, groupId, collectionId, (items) => items.push(cloneItem(item)))
208
+ },
209
+ removeItem(tabId, groupId, collectionId, itemId) {
210
+ mutateItem(tabs.value, tabId, groupId, collectionId, (items) => {
211
+ const index = items.findIndex((x) => x.id === itemId)
212
+ if (index >= 0) items.splice(index, 1)
213
+ })
214
+ },
215
+ updateItem(tabId, groupId, collectionId, itemId, patch) {
216
+ mutateItem(tabs.value, tabId, groupId, collectionId, (items) => {
217
+ const item = items.find((x) => x.id === itemId)
218
+ if (item) Object.assign(item, patch)
219
+ })
220
+ },
221
+ enableItem(tabId, groupId, collectionId, itemId) {
222
+ api.updateItem(tabId, groupId, collectionId, itemId, { disabled: false })
223
+ },
224
+ disableItem(tabId, groupId, collectionId, itemId) {
225
+ api.updateItem(tabId, groupId, collectionId, itemId, { disabled: true })
226
+ },
227
+ refreshLayout() {
228
+ overflowOpen.value = false
229
+ },
230
+ minimize(value) {
231
+ minimized.value = value
232
+ },
233
+ toggleSimplified() {
234
+ layout.value = layout.value === 'classic' ? 'simplified' : 'classic'
235
+ },
236
+ }
237
+
238
+ /**
239
+ * Registers a key tip if it is not already present.
240
+ * @param tip Key tip model.
241
+ */
242
+ const registerKeyTip = (tip: KeyTipModel) => {
243
+ if (keyTips.value.some((x) => x.id === tip.id)) return
244
+ keyTips.value.push(tip)
245
+ }
246
+
247
+ /**
248
+ * Unregisters a key tip by id.
249
+ * @param id Key tip id.
250
+ */
251
+ const unregisterKeyTip = (id: string) => {
252
+ keyTips.value = keyTips.value.filter((x) => x.id !== id)
253
+ }
254
+
255
+ const context: RibbonContextValue = {
256
+ id: ribbonId,
257
+ layout,
258
+ minimized,
259
+ activeTab,
260
+ tabs,
261
+ overflowOpen,
262
+ backdropOpen,
263
+ keyTipsOpen,
264
+ keyTips,
265
+ keyTipsSequence,
266
+ registerKeyTip,
267
+ unregisterKeyTip,
268
+ api,
269
+ }
270
+
271
+ return { context, visibleTabs }
272
+ }
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'vue'
2
+ import type { RibbonContextValue } from './types'
3
+
4
+ export const ribbonKey: InjectionKey<RibbonContextValue> = Symbol('RibbonContext')
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @component MlRibbon
3
+ * @description Root ribbon orchestrator component.
4
+ * @example
5
+ * ```vue
6
+ * <MlRibbon :tabs="tabs" v-model:active-tab="activeTab" />
7
+ * ```
8
+ */
9
+ export { default as MlRibbon } from './components/Ribbon.vue'
10
+
11
+ /**
12
+ * @component MlRibbonTabs
13
+ * @description Basic tab strip renderer for ribbon headers.
14
+ */
15
+ export { default as MlRibbonTabs } from './components/RibbonTabs.vue'
16
+
17
+ /**
18
+ * @component MlRibbonTab
19
+ * @description Declarative tab metadata component.
20
+ */
21
+ export { default as MlRibbonTab } from './components/RibbonTab.vue'
22
+
23
+ /**
24
+ * @component MlRibbonGroup
25
+ * @description Group container with optional overflow handling.
26
+ */
27
+ export { default as MlRibbonGroup } from './components/RibbonGroup.vue'
28
+
29
+ /**
30
+ * @component MlRibbonCollection
31
+ * @description Collection layout container inside a ribbon group.
32
+ */
33
+ export { default as MlRibbonCollection } from './components/RibbonCollection.vue'
34
+
35
+ /**
36
+ * @component MlRibbonItemHost
37
+ * @description Type-driven ribbon item renderer.
38
+ */
39
+ export { default as MlRibbonItemHost } from './components/RibbonItemHost.vue'
40
+
41
+ /**
42
+ * @component MlRibbonGroupButton
43
+ * @description Segmented group button ribbon item.
44
+ */
45
+ export { default as MlRibbonGroupButton } from './items/RibbonGroupButton.vue'
46
+
47
+ /**
48
+ * @component MlRibbonGallery
49
+ * @description Categorized gallery selector ribbon item.
50
+ */
51
+ export { default as MlRibbonGallery } from './items/RibbonGallery.vue'
52
+
53
+ /**
54
+ * @component MlRibbonTemplateItem
55
+ * @description Custom-template ribbon item wrapper.
56
+ */
57
+ export { default as MlRibbonTemplateItem } from './items/RibbonTemplateItem.vue'
58
+
59
+ /**
60
+ * @component MlRibbonFileMenu
61
+ * @description File tab dropdown module.
62
+ */
63
+ export { default as MlRibbonFileMenu } from './modules/RibbonFileMenu.vue'
64
+
65
+ /**
66
+ * @component MlRibbonBackstage
67
+ * @description Full-screen backstage drawer module.
68
+ */
69
+ export { default as MlRibbonBackstage } from './modules/RibbonBackstage.vue'
70
+
71
+ /**
72
+ * @component MlRibbonKeyTips
73
+ * @description Keyboard key tips overlay module.
74
+ */
75
+ export { default as MlRibbonKeyTips } from './modules/RibbonKeyTips.vue'
76
+
77
+ /**
78
+ * @component MlRibbonContextualTabs
79
+ * @description Context-aware tab strip module.
80
+ */
81
+ export { default as MlRibbonContextualTabs } from './modules/RibbonContextualTabs.vue'
82
+
83
+ export type {
84
+ RibbonLayout,
85
+ RibbonItemSize,
86
+ RibbonItemType,
87
+ RibbonCollectionLayout,
88
+ RibbonGroupOrientation,
89
+ RibbonComponentSize,
90
+ RibbonTabModel,
91
+ RibbonGroupModel,
92
+ RibbonCollectionModel,
93
+ RibbonItemModel,
94
+ RibbonDynamicApi,
95
+ KeyTipModel,
96
+ FileMenuItemModel,
97
+ BackstageItemModel,
98
+ RibbonLocaleTexts,
99
+ } from './types'
@@ -0,0 +1,78 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+
4
+ /**
5
+ * @component MlRibbonGallery
6
+ * @description
7
+ * Categorized gallery selector for previewable ribbon commands.
8
+ *
9
+ * @prop id - Gallery identifier.
10
+ * @prop label - Optional gallery title.
11
+ * @prop categories - Gallery categories and their selectable items.
12
+ * @prop disabled - Disables selection.
13
+ * @prop previewFallback - Fallback preview text when an item has no preview.
14
+ *
15
+ * @event select - Emitted with selected gallery item id.
16
+ *
17
+ * @example
18
+ * ```vue
19
+ * <MlRibbonGallery
20
+ * id="styles"
21
+ * label="Styles"
22
+ * :categories="styleCategories"
23
+ * preview-fallback="Preview"
24
+ * @select="onStylePick"
25
+ * />
26
+ * ```
27
+ */
28
+ const props = withDefaults(
29
+ defineProps<{
30
+ id: string
31
+ label: string
32
+ categories: { id: string; title: string; items: { id: string; label: string; preview?: string }[] }[]
33
+ disabled?: boolean
34
+ previewFallback?: string
35
+ }>(),
36
+ { disabled: false },
37
+ )
38
+
39
+ const emit = defineEmits<{ (e: 'select', id: string): void }>()
40
+ const selected = ref<string>('')
41
+
42
+ /**
43
+ * Selects a gallery item and emits its id.
44
+ * @param id Target gallery item id.
45
+ */
46
+ function selectItem(id: string) {
47
+ if (props.disabled) return
48
+ selected.value = id
49
+ emit('select', id)
50
+ }
51
+ </script>
52
+
53
+ <template>
54
+ <div class="ml-ribbon-gallery" :class="{ 'is-disabled': disabled }">
55
+ <div v-if="label" class="ml-ribbon-gallery__title">{{ label }}</div>
56
+ <div class="ml-ribbon-gallery__categories">
57
+ <section v-for="category in categories" :key="category.id" class="ml-ribbon-gallery__category">
58
+ <h4 class="ml-ribbon-gallery__category-title">{{ category.title }}</h4>
59
+ <div class="ml-ribbon-gallery__grid">
60
+ <button
61
+ v-for="item in category.items"
62
+ :key="item.id"
63
+ type="button"
64
+ class="ml-ribbon-gallery__item"
65
+ :class="{ 'is-selected': selected === item.id }"
66
+ :disabled="disabled"
67
+ @click="selectItem(item.id)"
68
+ >
69
+ <div class="ml-ribbon-gallery__preview">{{ item.preview ?? props.previewFallback }}</div>
70
+ <div class="ml-ribbon-gallery__label">{{ item.label }}</div>
71
+ </button>
72
+ </div>
73
+ </section>
74
+ </div>
75
+ </div>
76
+ </template>
77
+
78
+
@@ -0,0 +1,85 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+ import { ElButton, ElButtonGroup, ElIcon } from 'element-plus'
4
+ import type { Component } from 'vue'
5
+
6
+ /**
7
+ * @component MlRibbonGroupButton
8
+ * @description
9
+ * Segmented button control for ribbon items. Supports single-select and
10
+ * multi-select modes and emits selected values.
11
+ *
12
+ * @prop id - Component identifier.
13
+ * @prop label - Caption shown above segmented buttons.
14
+ * @prop options - Selectable options with optional icons.
15
+ * @prop multiple - Enables multi-select behavior.
16
+ * @prop disabled - Disables interaction.
17
+ *
18
+ * @event change - Emitted with `string` in single mode or `string[]` in multiple mode.
19
+ *
20
+ * @example
21
+ * ```vue
22
+ * <MlRibbonGroupButton
23
+ * id="find-replace"
24
+ * label="Find / Replace"
25
+ * :options="[
26
+ * { label: 'Find', value: 'find' },
27
+ * { label: 'Replace', value: 'replace' }
28
+ * ]"
29
+ * @change="onModeChange"
30
+ * />
31
+ * ```
32
+ */
33
+ const props = withDefaults(
34
+ defineProps<{
35
+ id: string
36
+ label: string
37
+ options: { label: string; value: string; icon?: Component }[]
38
+ multiple?: boolean
39
+ disabled?: boolean
40
+ }>(),
41
+ { multiple: false, disabled: false },
42
+ )
43
+
44
+ const emit = defineEmits<{ (e: 'change', value: string | string[]): void }>()
45
+ const selected = ref<string[]>([])
46
+
47
+ /**
48
+ * Toggles option selection state and emits normalized payload by selection mode.
49
+ * @param value Option value to toggle.
50
+ */
51
+ function toggle(value: string) {
52
+ if (props.disabled) return
53
+ if (props.multiple) {
54
+ if (selected.value.includes(value)) {
55
+ selected.value = selected.value.filter((x) => x !== value)
56
+ } else {
57
+ selected.value = [...selected.value, value]
58
+ }
59
+ emit('change', selected.value)
60
+ return
61
+ }
62
+ selected.value = [value]
63
+ emit('change', value)
64
+ }
65
+ </script>
66
+
67
+ <template>
68
+ <div class="ml-ribbon-group-button" :data-id="id">
69
+ <div class="ml-ribbon-group-button__label">{{ label }}</div>
70
+ <ElButtonGroup>
71
+ <ElButton
72
+ v-for="option in options"
73
+ :key="option.value"
74
+ :disabled="disabled"
75
+ :type="selected.includes(option.value) ? 'primary' : 'default'"
76
+ @click="toggle(option.value)"
77
+ >
78
+ <ElIcon v-if="option.icon" class="ml-ribbon-item-host__icon"><component :is="option.icon" /></ElIcon>
79
+ {{ option.label }}
80
+ </ElButton>
81
+ </ElButtonGroup>
82
+ </div>
83
+ </template>
84
+
85
+
@@ -0,0 +1,38 @@
1
+ <script setup lang="ts">
2
+ import type { RibbonItemModel } from '../types'
3
+
4
+ /**
5
+ * @component MlRibbonTemplateItem
6
+ * @description
7
+ * Wrapper for fully custom ribbon item rendering while preserving ribbon layout
8
+ * and item metadata context.
9
+ *
10
+ * @prop id - Template item identifier.
11
+ * @prop item - Original ribbon item model passed to slot consumers.
12
+ *
13
+ * @slot default - Custom template content with `{ item }` slot prop.
14
+ *
15
+ * @example
16
+ * ```vue
17
+ * <MlRibbonTemplateItem :id="item.id" :item="item">
18
+ * <template #default="{ item }">
19
+ * <MyCustomCommand :label="item.label" />
20
+ * </template>
21
+ * </MlRibbonTemplateItem>
22
+ * ```
23
+ */
24
+ defineProps<{
25
+ id: string
26
+ item: RibbonItemModel
27
+ }>()
28
+ </script>
29
+
30
+ <template>
31
+ <div class="ml-ribbon-template-item" :data-template-id="id">
32
+ <slot :item="item">
33
+ <span>{{ item.label ?? item.id }}</span>
34
+ </slot>
35
+ </div>
36
+ </template>
37
+
38
+