@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,830 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent, ref } from 'vue'
4
+ import { ElConfigProvider } from 'element-plus'
5
+ import MlRibbon from '../ribbon/components/Ribbon.vue'
6
+ import type { RibbonTabModel } from '../ribbon'
7
+
8
+ const tabs: RibbonTabModel[] = [
9
+ {
10
+ id: 'home',
11
+ title: 'Home',
12
+ groups: [
13
+ {
14
+ id: 'grp',
15
+ title: 'Group',
16
+ collections: [{ id: 'c1', items: [{ id: 'btn1', type: 'button', label: 'Run' }] }],
17
+ },
18
+ ],
19
+ },
20
+ ]
21
+
22
+ describe('MlRibbon', () => {
23
+ it('renders tab and item', () => {
24
+ const wrapper = mount(MlRibbon, { props: { tabs } })
25
+ expect(wrapper.text()).toContain('Home')
26
+ expect(wrapper.text()).toContain('Run')
27
+ })
28
+
29
+ it('supports layout updates', async () => {
30
+ const wrapper = mount(MlRibbon, { props: { tabs, activeTab: 'home' } })
31
+ await wrapper.setProps({ layout: 'simplified' })
32
+ expect(wrapper.find('.ml-ribbon').classes()).toContain('ml-ribbon--simplified')
33
+ })
34
+
35
+ it('toggles inline key tips with Alt and shows active tab item tip labels', async () => {
36
+ const keyTipTabs: RibbonTabModel[] = [
37
+ {
38
+ id: 'home',
39
+ title: 'Home',
40
+ groups: [
41
+ {
42
+ id: 'grp',
43
+ title: 'Clipboard',
44
+ collections: [{ id: 'c1', items: [{ id: 'paste', type: 'button', label: 'Paste', keyTip: 'V' }] }],
45
+ },
46
+ ],
47
+ },
48
+ ]
49
+ const wrapper = mount(MlRibbon, { props: { tabs: keyTipTabs, activeTab: 'home' } })
50
+
51
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Alt', altKey: true, bubbles: true }))
52
+ await wrapper.vm.$nextTick()
53
+
54
+ expect(wrapper.find('.ml-ribbon').classes()).toContain('ml-ribbon--keytips-open')
55
+ const keyTipBadge = wrapper.find('.ml-ribbon-item-host[data-item-id="paste"] .ml-ribbon-item-host__keytip')
56
+ expect(keyTipBadge.exists()).toBe(true)
57
+ expect(keyTipBadge.text()).toBe('V')
58
+ })
59
+
60
+ it('triggers itemClick when key tip sequence is matched', async () => {
61
+ const keyTipTabs: RibbonTabModel[] = [
62
+ {
63
+ id: 'home',
64
+ title: 'Home',
65
+ groups: [
66
+ {
67
+ id: 'grp',
68
+ title: 'Clipboard',
69
+ collections: [{ id: 'c1', items: [{ id: 'run', type: 'button', label: 'Run', keyTip: 'R' }] }],
70
+ },
71
+ ],
72
+ },
73
+ ]
74
+ const wrapper = mount(MlRibbon, { props: { tabs: keyTipTabs, activeTab: 'home' } })
75
+
76
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Alt', altKey: true, bubbles: true }))
77
+ await wrapper.vm.$nextTick()
78
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'r', bubbles: true }))
79
+ await wrapper.vm.$nextTick()
80
+
81
+ const emissions = wrapper.emitted('itemClick') ?? []
82
+ expect(emissions).toHaveLength(1)
83
+ expect(emissions[0]?.[0]).toEqual({ tabId: 'home', groupId: 'grp', itemId: 'run' })
84
+ expect(wrapper.find('.ml-ribbon-item-host[data-item-id="run"] .ml-ribbon-item-host__keytip').exists()).toBe(false)
85
+ })
86
+
87
+ it('uses flat medium items without duplicated title in simplified popover', async () => {
88
+ // Dedicated schema for simplified mode to verify the flattening behavior in popover panels.
89
+ const simplifiedTabs: RibbonTabModel[] = [
90
+ {
91
+ id: 'home',
92
+ title: 'Home',
93
+ groups: [
94
+ {
95
+ id: 'grp',
96
+ title: 'Clipboard',
97
+ collections: [
98
+ {
99
+ id: 'c1',
100
+ items: [
101
+ { id: 'paste', type: 'button', label: 'Paste', size: 'large' },
102
+ { id: 'copy', type: 'button', label: 'Copy', size: 'small' },
103
+ ],
104
+ },
105
+ ],
106
+ },
107
+ ],
108
+ },
109
+ ]
110
+ const wrapper = mount(MlRibbon, {
111
+ attachTo: document.body,
112
+ props: { tabs: simplifiedTabs, layout: 'simplified', activeTab: 'home' },
113
+ })
114
+
115
+ try {
116
+ await wrapper.find('.ml-ribbon-simplified-group').trigger('click')
117
+ await wrapper.vm.$nextTick()
118
+ await wrapper.vm.$nextTick()
119
+
120
+ // The popover is rendered in document.body, so query from body instead of wrapper root.
121
+ const popoverPanel = Array.from(
122
+ document.body.querySelectorAll('.ml-ribbon-group-popover .ml-ribbon-simplified-group__panel'),
123
+ ).find((panel) => panel.textContent?.includes('Paste') && panel.textContent?.includes('Copy'))
124
+ expect(popoverPanel).not.toBeNull()
125
+ expect(popoverPanel?.querySelector('.ml-ribbon-simplified-group__title')).toBeNull()
126
+ expect(popoverPanel?.querySelector('.ml-ribbon-item-host.is-large')).toBeNull()
127
+ expect(popoverPanel?.querySelector('.ml-ribbon-item-host.is-small')).toBeNull()
128
+ expect(popoverPanel?.querySelectorAll('.ml-ribbon-item-host.is-medium').length).toBe(2)
129
+ } finally {
130
+ wrapper.unmount()
131
+ }
132
+ })
133
+
134
+ it('supports size prop', () => {
135
+ const wrapper = mount(MlRibbon, { props: { tabs, size: 'small' } })
136
+ expect(wrapper.find('.ml-ribbon').classes()).toContain('ml-ribbon--size-small')
137
+ })
138
+
139
+ it('uses externally provided i18n texts', () => {
140
+ const contextualTabs: RibbonTabModel[] = [
141
+ {
142
+ id: 'ctx',
143
+ title: 'Chart',
144
+ contextual: true,
145
+ groups: [{ id: 'g1', title: 'Group', collections: [{ id: 'c1', items: [] }] }],
146
+ },
147
+ ]
148
+ const wrapper = mount(MlRibbon, {
149
+ props: {
150
+ tabs: contextualTabs,
151
+ texts: {
152
+ fileMenuLabel: '文档',
153
+ contextualTabDefaultTitle: '图表工具',
154
+ },
155
+ },
156
+ })
157
+
158
+ expect(wrapper.find('.ml-ribbon-tab--file').text()).toBe('文档')
159
+ expect(wrapper.text()).toContain('图表工具')
160
+ })
161
+
162
+ it('inherits size from element plus config provider', () => {
163
+ // Host component mirrors app-level usage where ribbon inherits size from ElConfigProvider.
164
+ const Host = defineComponent({
165
+ components: { ElConfigProvider, MlRibbon },
166
+ setup() {
167
+ return { tabs }
168
+ },
169
+ template: `
170
+ <ElConfigProvider size="large">
171
+ <MlRibbon :tabs="tabs" />
172
+ </ElConfigProvider>
173
+ `,
174
+ })
175
+ const wrapper = mount(Host)
176
+ const ribbon = wrapper.find('.ml-ribbon')
177
+ expect(ribbon.classes()).toContain('ml-ribbon--size-large')
178
+ })
179
+
180
+ it('releases classic overflow groups when tab width becomes sufficient', async () => {
181
+ // Mutable width lets us simulate resize without remounting the component.
182
+ let panelWidth = 260
183
+ // Mock geometry so overflow decisions are deterministic in jsdom.
184
+ const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
185
+ this: HTMLElement,
186
+ ) {
187
+ const element = this
188
+ if (element.classList.contains('ml-ribbon__panel')) {
189
+ return new DOMRect(0, 0, panelWidth, 84)
190
+ }
191
+ if (element.classList.contains('ml-ribbon-group')) {
192
+ return new DOMRect(0, 0, 120, 76)
193
+ }
194
+ return new DOMRect(0, 0, 80, 24)
195
+ })
196
+
197
+ const clientWidthSpy = vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function (
198
+ this: HTMLElement,
199
+ ) {
200
+ return this.classList.contains('ml-ribbon__panel') ? panelWidth : 120
201
+ })
202
+
203
+ // Width budget is initially too narrow to fit all groups inline.
204
+ const overflowTabs: RibbonTabModel[] = [
205
+ {
206
+ id: 'home',
207
+ title: 'Home',
208
+ groups: [
209
+ {
210
+ id: 'g1',
211
+ title: 'Clipboard',
212
+ collections: [{ id: 'c1', items: [{ id: 'paste', type: 'button', label: 'Paste' }] }],
213
+ },
214
+ {
215
+ id: 'g2',
216
+ title: 'Font',
217
+ collections: [{ id: 'c2', items: [{ id: 'bold', type: 'button', label: 'Bold' }] }],
218
+ },
219
+ {
220
+ id: 'g3',
221
+ title: 'Insert',
222
+ collections: [{ id: 'c3', items: [{ id: 'shape', type: 'button', label: 'Shape' }] }],
223
+ },
224
+ ],
225
+ },
226
+ ]
227
+
228
+ try {
229
+ const wrapper = mount(MlRibbon, { props: { tabs: overflowTabs } })
230
+ await wrapper.vm.$nextTick()
231
+ await wrapper.vm.$nextTick()
232
+
233
+ expect(wrapper.find('.ml-ribbon-overflow-trigger').exists()).toBe(true)
234
+
235
+ // Trigger reactive relayout by changing props after expanding available panel width.
236
+ panelWidth = 480
237
+ await wrapper.setProps({ tabs: overflowTabs.map((tab) => ({ ...tab })) })
238
+ await wrapper.vm.$nextTick()
239
+ await wrapper.vm.$nextTick()
240
+
241
+ expect(wrapper.find('.ml-ribbon-overflow-trigger').exists()).toBe(false)
242
+ } finally {
243
+ rectSpy.mockRestore()
244
+ clientWidthSpy.mockRestore()
245
+ }
246
+ })
247
+
248
+ it('emits itemClick when triggering hidden group item from classic overflow popover', async () => {
249
+ // Keep the panel narrow so at least one group is guaranteed to move into overflow popover.
250
+ const panelWidth = 200
251
+ const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
252
+ this: HTMLElement,
253
+ ) {
254
+ const element = this
255
+ if (element.classList.contains('ml-ribbon__panel')) {
256
+ return new DOMRect(0, 0, panelWidth, 84)
257
+ }
258
+ if (element.classList.contains('ml-ribbon-group')) {
259
+ return new DOMRect(0, 0, 140, 76)
260
+ }
261
+ return new DOMRect(0, 0, 90, 24)
262
+ })
263
+
264
+ const clientWidthSpy = vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function (
265
+ this: HTMLElement,
266
+ ) {
267
+ return this.classList.contains('ml-ribbon__panel') ? panelWidth : 140
268
+ })
269
+
270
+ const overflowTabs: RibbonTabModel[] = [
271
+ {
272
+ id: 'home',
273
+ title: 'Home',
274
+ groups: [
275
+ {
276
+ id: 'g1',
277
+ title: 'Clipboard',
278
+ collections: [{ id: 'c1', items: [{ id: 'paste', type: 'button', label: 'Paste' }] }],
279
+ },
280
+ {
281
+ id: 'g2',
282
+ title: 'Insert',
283
+ collections: [{ id: 'c2', items: [{ id: 'hidden-action', type: 'button', label: 'Hidden Action' }] }],
284
+ },
285
+ ],
286
+ },
287
+ ]
288
+
289
+ const wrapper = mount(MlRibbon, {
290
+ attachTo: document.body,
291
+ props: { tabs: overflowTabs },
292
+ })
293
+
294
+ try {
295
+ await wrapper.vm.$nextTick()
296
+ await wrapper.vm.$nextTick()
297
+
298
+ const overflowTrigger = wrapper.find('.ml-ribbon-overflow-trigger')
299
+ expect(overflowTrigger.exists()).toBe(true)
300
+ await overflowTrigger.trigger('click')
301
+ await wrapper.vm.$nextTick()
302
+ await wrapper.vm.$nextTick()
303
+
304
+ // Overflow popover is teleported to body by Element Plus.
305
+ const hiddenButton = Array.from(
306
+ document.body.querySelectorAll<HTMLButtonElement>('.ml-ribbon-overflow-popover .el-button'),
307
+ ).find((button) => button.textContent?.includes('Hidden Action'))
308
+ expect(hiddenButton).toBeTruthy()
309
+ hiddenButton?.click()
310
+ await wrapper.vm.$nextTick()
311
+
312
+ const emissions = wrapper.emitted('itemClick') ?? []
313
+ expect(emissions).toHaveLength(1)
314
+ expect(emissions[0]?.[0]).toEqual({ tabId: 'home', groupId: 'g2', itemId: 'hidden-action' })
315
+ } finally {
316
+ wrapper.unmount()
317
+ rectSpy.mockRestore()
318
+ clientWidthSpy.mockRestore()
319
+ }
320
+ })
321
+
322
+ it('uses visible panel width to decide classic overflow trigger', async () => {
323
+ // getBoundingClientRect represents the true visible width even when clientWidth is stale/oversized.
324
+ const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
325
+ this: HTMLElement,
326
+ ) {
327
+ const element = this
328
+ if (element.classList.contains('ml-ribbon__panel')) {
329
+ return new DOMRect(0, 0, 220, 84)
330
+ }
331
+ if (element.classList.contains('ml-ribbon-group')) {
332
+ return new DOMRect(0, 0, 130, 76)
333
+ }
334
+ return new DOMRect(0, 0, 90, 24)
335
+ })
336
+
337
+ const clientWidthSpy = vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function (
338
+ this: HTMLElement,
339
+ ) {
340
+ if (this.classList.contains('ml-ribbon__panel')) return 1200
341
+ return 130
342
+ })
343
+
344
+ const overflowTabs: RibbonTabModel[] = [
345
+ {
346
+ id: 'home',
347
+ title: 'Home',
348
+ groups: [
349
+ {
350
+ id: 'g1',
351
+ title: 'Clipboard',
352
+ collections: [{ id: 'c1', items: [{ id: 'paste', type: 'button', label: 'Paste' }] }],
353
+ },
354
+ {
355
+ id: 'g2',
356
+ title: 'Insert',
357
+ collections: [{ id: 'c2', items: [{ id: 'hidden-action', type: 'button', label: 'Hidden Action' }] }],
358
+ },
359
+ ],
360
+ },
361
+ ]
362
+
363
+ try {
364
+ const wrapper = mount(MlRibbon, { props: { tabs: overflowTabs } })
365
+ await wrapper.vm.$nextTick()
366
+ await wrapper.vm.$nextTick()
367
+
368
+ expect(wrapper.find('.ml-ribbon-overflow-trigger').exists()).toBe(true)
369
+ } finally {
370
+ rectSpy.mockRestore()
371
+ clientWidthSpy.mockRestore()
372
+ }
373
+ })
374
+
375
+ it('keeps one group visible when width fits one group plus overflow slot', async () => {
376
+ // Exact width budget: one regular group + overflow trigger slot.
377
+ const panelWidth = 175
378
+ const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
379
+ this: HTMLElement,
380
+ ) {
381
+ const element = this
382
+ if (element.classList.contains('ml-ribbon__panel')) {
383
+ return new DOMRect(0, 0, panelWidth, 84)
384
+ }
385
+ if (element.classList.contains('ml-ribbon-group')) {
386
+ return new DOMRect(0, 0, 130, 76)
387
+ }
388
+ return new DOMRect(0, 0, 90, 24)
389
+ })
390
+
391
+ const overflowTabs: RibbonTabModel[] = [
392
+ {
393
+ id: 'home',
394
+ title: 'Home',
395
+ groups: [
396
+ {
397
+ id: 'g1',
398
+ title: 'Clipboard',
399
+ collections: [{ id: 'c1', items: [{ id: 'paste', type: 'button', label: 'Paste' }] }],
400
+ },
401
+ {
402
+ id: 'g2',
403
+ title: 'Insert',
404
+ collections: [{ id: 'c2', items: [{ id: 'shape', type: 'button', label: 'Shape' }] }],
405
+ },
406
+ ],
407
+ },
408
+ ]
409
+
410
+ try {
411
+ const wrapper = mount(MlRibbon, { props: { tabs: overflowTabs } })
412
+ await wrapper.vm.$nextTick()
413
+ await wrapper.vm.$nextTick()
414
+
415
+ const inlineGroups = wrapper
416
+ .findAll('.ml-ribbon__panel .ml-ribbon-group[data-group-id]')
417
+ .map((group) => group.attributes('data-group-id'))
418
+ expect(inlineGroups).toEqual(['g1'])
419
+ expect(wrapper.find('.ml-ribbon-overflow-trigger').exists()).toBe(true)
420
+ } finally {
421
+ rectSpy.mockRestore()
422
+ }
423
+ })
424
+
425
+ it('restores overflowable groups when width grows after only fixed group is visible', async () => {
426
+ // Start from a constrained width where only fixed (non-overflowable) group can stay visible.
427
+ let panelWidth = 220
428
+ const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
429
+ this: HTMLElement,
430
+ ) {
431
+ const element = this
432
+ if (element.classList.contains('ml-ribbon__panel')) {
433
+ return new DOMRect(0, 0, panelWidth, 84)
434
+ }
435
+ if (element.classList.contains('ml-ribbon-group')) {
436
+ if (element.dataset.groupId === 'g1') return new DOMRect(0, 0, 190, 76)
437
+ return new DOMRect(0, 0, 120, 76)
438
+ }
439
+ return new DOMRect(0, 0, 90, 24)
440
+ })
441
+
442
+ const overflowTabs: RibbonTabModel[] = [
443
+ {
444
+ id: 'home',
445
+ title: 'Home',
446
+ groups: [
447
+ {
448
+ id: 'g1',
449
+ title: 'Pinned',
450
+ enableGroupOverflow: false,
451
+ collections: [{ id: 'c1', items: [{ id: 'pin', type: 'button', label: 'Pin' }] }],
452
+ },
453
+ {
454
+ id: 'g2',
455
+ title: 'Font',
456
+ collections: [{ id: 'c2', items: [{ id: 'bold', type: 'button', label: 'Bold' }] }],
457
+ },
458
+ {
459
+ id: 'g3',
460
+ title: 'Insert',
461
+ collections: [{ id: 'c3', items: [{ id: 'shape', type: 'button', label: 'Shape' }] }],
462
+ },
463
+ ],
464
+ },
465
+ ]
466
+
467
+ try {
468
+ const wrapper = mount(MlRibbon, { props: { tabs: overflowTabs } })
469
+ await wrapper.vm.$nextTick()
470
+ await wrapper.vm.$nextTick()
471
+
472
+ expect(wrapper.findAll('.ml-ribbon__panel .ml-ribbon-group').length).toBe(2)
473
+ expect(wrapper.find('.ml-ribbon-overflow-trigger').exists()).toBe(true)
474
+
475
+ // Simulate grow event and force recalculation through prop update.
476
+ panelWidth = 480
477
+ await wrapper.setProps({ tabs: overflowTabs.map((tab) => ({ ...tab })) })
478
+ await wrapper.vm.$nextTick()
479
+ await wrapper.vm.$nextTick()
480
+
481
+ expect(wrapper.find('.ml-ribbon-overflow-trigger').exists()).toBe(false)
482
+ expect(wrapper.findAll('.ml-ribbon__panel .ml-ribbon-group').length).toBe(3)
483
+ } finally {
484
+ rectSpy.mockRestore()
485
+ }
486
+ })
487
+
488
+ it('shows group overflow arrow when items are clipped inside a group', async () => {
489
+ // Mock item coordinates so the second item appears outside the content viewport.
490
+ const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
491
+ this: HTMLElement,
492
+ ) {
493
+ const element = this
494
+ if (element.classList.contains('ml-ribbon-group__content')) {
495
+ return new DOMRect(0, 0, 100, 36)
496
+ }
497
+ if (element.classList.contains('ml-ribbon-item-host')) {
498
+ if (element.dataset.itemId === 'btn-hidden') {
499
+ return new DOMRect(110, 0, 24, 20)
500
+ }
501
+ return new DOMRect(4, 0, 24, 20)
502
+ }
503
+ return new DOMRect(0, 0, 160, 40)
504
+ })
505
+
506
+ const overflowTabs: RibbonTabModel[] = [
507
+ {
508
+ id: 'home',
509
+ title: 'Home',
510
+ groups: [
511
+ {
512
+ id: 'grp-overflow',
513
+ title: 'Group',
514
+ enableGroupOverflow: false,
515
+ collections: [
516
+ {
517
+ id: 'c1',
518
+ items: [
519
+ { id: 'btn-visible', type: 'button', label: 'Visible' },
520
+ { id: 'btn-hidden', type: 'button', label: 'Hidden' },
521
+ ],
522
+ },
523
+ ],
524
+ },
525
+ ],
526
+ },
527
+ ]
528
+
529
+ try {
530
+ const wrapper = mount(MlRibbon, { props: { tabs: overflowTabs } })
531
+ await wrapper.vm.$nextTick()
532
+ await wrapper.setProps({ tabs: overflowTabs.map((tab) => ({ ...tab })) })
533
+ await wrapper.vm.$nextTick()
534
+ await wrapper.vm.$nextTick()
535
+
536
+ expect(wrapper.find('.ml-ribbon-group__overflow-trigger').exists()).toBe(true)
537
+ } finally {
538
+ rectSpy.mockRestore()
539
+ }
540
+ })
541
+
542
+ it('avoids reactive component warnings for icon definitions in reactive tab schemas', async () => {
543
+ const IconStub = defineComponent({
544
+ name: 'IconStub',
545
+ template: '<span class="ml-test-icon" />',
546
+ })
547
+
548
+ // Keep schema reactive to mimic real-world dynamic tab updates.
549
+ const reactiveTabs = ref<RibbonTabModel[]>([
550
+ {
551
+ id: 'home',
552
+ title: 'Home',
553
+ groups: [
554
+ {
555
+ id: 'clipboard',
556
+ title: 'Clipboard',
557
+ collections: [
558
+ {
559
+ id: 'c1',
560
+ items: [{ id: 'paste', type: 'button', label: 'Paste', props: { icon: IconStub } }],
561
+ },
562
+ {
563
+ id: 'c2',
564
+ items: [
565
+ {
566
+ id: 'find-replace',
567
+ type: 'groupButton',
568
+ label: 'Find/Replace',
569
+ props: {
570
+ options: [
571
+ { label: 'Find', value: 'find', icon: IconStub },
572
+ { label: 'Replace', value: 'replace', icon: IconStub },
573
+ ],
574
+ },
575
+ },
576
+ ],
577
+ },
578
+ ],
579
+ },
580
+ ],
581
+ },
582
+ ])
583
+
584
+ // Silence console noise and assert no Vue warning about reactive component definitions is emitted.
585
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
586
+ const wrapper = mount(MlRibbon, { props: { tabs: reactiveTabs.value, activeTab: 'home' } })
587
+
588
+ try {
589
+ await wrapper.vm.$nextTick()
590
+ const hasReactiveComponentWarning = warnSpy.mock.calls.some((call) =>
591
+ call.some((value) => String(value).includes('Component that was made reactive')),
592
+ )
593
+ expect(hasReactiveComponentWarning).toBe(false)
594
+ } finally {
595
+ warnSpy.mockRestore()
596
+ wrapper.unmount()
597
+ }
598
+ })
599
+
600
+ it('hides item label when hideLabel is true', () => {
601
+ const iconOnlyTabs: RibbonTabModel[] = [
602
+ {
603
+ id: 'home',
604
+ title: 'Home',
605
+ groups: [
606
+ {
607
+ id: 'draw',
608
+ title: 'Draw',
609
+ collections: [
610
+ {
611
+ id: 'c1',
612
+ items: [
613
+ { id: 'ellipse', type: 'button', label: 'Ellipse', hideLabel: true },
614
+ {
615
+ id: 'rect',
616
+ type: 'dropdown',
617
+ label: 'Rectangle',
618
+ hideLabel: true,
619
+ props: { options: [{ label: 'Rectangle', value: 'rect' }] },
620
+ },
621
+ ],
622
+ },
623
+ ],
624
+ },
625
+ ],
626
+ },
627
+ ]
628
+
629
+ const wrapper = mount(MlRibbon, { props: { tabs: iconOnlyTabs } })
630
+ expect(wrapper.text()).not.toContain('Ellipse')
631
+ expect(wrapper.text()).not.toContain('Rectangle')
632
+ })
633
+
634
+ it('renders dropdown arrows next to labels and icon according to item size/label visibility', () => {
635
+ const IconStub = defineComponent({
636
+ name: 'DropdownIconStub',
637
+ template: '<span class="ml-test-icon" />',
638
+ })
639
+
640
+ const dropdownTabs: RibbonTabModel[] = [
641
+ {
642
+ id: 'home',
643
+ title: 'Home',
644
+ groups: [
645
+ {
646
+ id: 'draw',
647
+ title: 'Draw',
648
+ collections: [
649
+ {
650
+ id: 'c1',
651
+ items: [
652
+ {
653
+ id: 'large-dropdown',
654
+ type: 'dropdown',
655
+ label: 'Circle',
656
+ size: 'large',
657
+ props: { options: [{ label: 'Circle', value: 'circle' }], icon: IconStub },
658
+ },
659
+ {
660
+ id: 'small-dropdown',
661
+ type: 'dropdown',
662
+ label: 'Line',
663
+ size: 'small',
664
+ props: { options: [{ label: 'Line', value: 'line' }], icon: IconStub },
665
+ },
666
+ {
667
+ id: 'icon-only-dropdown',
668
+ type: 'dropdown',
669
+ hideLabel: true,
670
+ size: 'small',
671
+ props: { options: [{ label: 'Ray', value: 'ray' }], icon: IconStub },
672
+ },
673
+ ],
674
+ },
675
+ ],
676
+ },
677
+ ],
678
+ },
679
+ ]
680
+
681
+ const wrapper = mount(MlRibbon, { props: { tabs: dropdownTabs } })
682
+
683
+ const largeHost = wrapper.find('.ml-ribbon-item-host[data-item-id="large-dropdown"]')
684
+ expect(largeHost.find('.ml-ribbon-item-host__label').text()).toBe('Circle')
685
+ expect(largeHost.find('.ml-ribbon-item-host__text-row .ml-ribbon-item-host__dropdown-arrow').exists()).toBe(true)
686
+
687
+ const smallHost = wrapper.find('.ml-ribbon-item-host[data-item-id="small-dropdown"]')
688
+ expect(smallHost.find('.ml-ribbon-item-host__label').text()).toBe('Line')
689
+ expect(smallHost.find('.ml-ribbon-item-host__text-row .ml-ribbon-item-host__dropdown-arrow').exists()).toBe(true)
690
+
691
+ const iconOnlyHost = wrapper.find('.ml-ribbon-item-host[data-item-id="icon-only-dropdown"]')
692
+ expect(iconOnlyHost.find('.ml-ribbon-item-host__label').exists()).toBe(false)
693
+ expect(iconOnlyHost.find('.ml-ribbon-item-host__icon + .ml-ribbon-item-host__text-row').exists()).toBe(true)
694
+ expect(iconOnlyHost.find('.ml-ribbon-item-host__text-row .ml-ribbon-item-host__dropdown-arrow').exists()).toBe(true)
695
+ })
696
+
697
+ it('renders option icons inside dropdown menu items', async () => {
698
+ const IconStub = defineComponent({
699
+ name: 'DropdownOptionIconStub',
700
+ template: '<span class="ml-test-option-icon" />',
701
+ })
702
+
703
+ const dropdownTabs: RibbonTabModel[] = [
704
+ {
705
+ id: 'home',
706
+ title: 'Home',
707
+ groups: [
708
+ {
709
+ id: 'draw',
710
+ title: 'Draw',
711
+ collections: [
712
+ {
713
+ id: 'c1',
714
+ items: [
715
+ {
716
+ id: 'draw-circle',
717
+ type: 'dropdown',
718
+ label: 'Circle',
719
+ props: {
720
+ options: [
721
+ { label: 'Center, Radius', value: 'circle-center-radius', icon: IconStub },
722
+ { label: '2-Point', value: 'circle-two-point' },
723
+ ],
724
+ },
725
+ },
726
+ ],
727
+ },
728
+ ],
729
+ },
730
+ ],
731
+ },
732
+ ]
733
+
734
+ const wrapper = mount(MlRibbon, {
735
+ attachTo: document.body,
736
+ props: { tabs: dropdownTabs },
737
+ })
738
+
739
+ try {
740
+ const triggerButton = wrapper.find('.ml-ribbon-item-host[data-item-id="draw-circle"] .el-button')
741
+ expect(triggerButton.exists()).toBe(true)
742
+
743
+ await triggerButton.trigger('mouseenter')
744
+ await wrapper.vm.$nextTick()
745
+ await wrapper.vm.$nextTick()
746
+
747
+ // Dropdown menu is teleported to body, query there for icon assertions.
748
+ const dropdownIcon = document.body.querySelector('.ml-ribbon-dropdown-menu .ml-ribbon-dropdown-item__icon')
749
+ expect(dropdownIcon).toBeTruthy()
750
+ } finally {
751
+ wrapper.unmount()
752
+ }
753
+ })
754
+
755
+ it('renders string class icons inside dropdown menu items', async () => {
756
+ const dropdownTabs: RibbonTabModel[] = [
757
+ {
758
+ id: 'home',
759
+ title: 'Home',
760
+ groups: [
761
+ {
762
+ id: 'draw',
763
+ title: 'Draw',
764
+ collections: [
765
+ {
766
+ id: 'c1',
767
+ items: [
768
+ {
769
+ id: 'draw-rectangle',
770
+ type: 'dropdown',
771
+ label: 'Rectangle',
772
+ props: {
773
+ options: [
774
+ { label: 'Rectangle', value: 'rectangle', icon: 'ml-test-option-class-icon' },
775
+ { label: 'Polygon', value: 'polygon' },
776
+ ],
777
+ },
778
+ },
779
+ ],
780
+ },
781
+ ],
782
+ },
783
+ ],
784
+ },
785
+ ]
786
+
787
+ const wrapper = mount(MlRibbon, {
788
+ attachTo: document.body,
789
+ props: { tabs: dropdownTabs },
790
+ })
791
+
792
+ try {
793
+ const triggerButton = wrapper.find('.ml-ribbon-item-host[data-item-id="draw-rectangle"] .el-button')
794
+ expect(triggerButton.exists()).toBe(true)
795
+
796
+ await triggerButton.trigger('mouseenter')
797
+ await wrapper.vm.$nextTick()
798
+ await wrapper.vm.$nextTick()
799
+
800
+ // Validate CSS-class icon path instead of component-based icon path.
801
+ const classIcon = document.body.querySelector(
802
+ '.ml-ribbon-dropdown-menu .ml-ribbon-dropdown-item__icon--class.ml-test-option-class-icon',
803
+ )
804
+ expect(classIcon).toBeTruthy()
805
+ } finally {
806
+ wrapper.unmount()
807
+ }
808
+ })
809
+
810
+ it('shows footer title with a right arrow trigger when footer menu items are provided', () => {
811
+ const footerMenuTabs: RibbonTabModel[] = [
812
+ {
813
+ id: 'home',
814
+ title: 'Home',
815
+ groups: [
816
+ {
817
+ id: 'draw',
818
+ title: 'Draw',
819
+ footerMenuItems: [{ id: 'spline', type: 'button', hideLabel: true }],
820
+ collections: [{ id: 'c1', items: [{ id: 'line', type: 'button', label: 'Line' }] }],
821
+ },
822
+ ],
823
+ },
824
+ ]
825
+
826
+ const wrapper = mount(MlRibbon, { props: { tabs: footerMenuTabs } })
827
+ expect(wrapper.find('.ml-ribbon-group__title').text()).toBe('Draw')
828
+ expect(wrapper.find('.ml-ribbon-group__footer-trigger').exists()).toBe(true)
829
+ })
830
+ })