|
1 | 1 | (function (global) { |
2 | | - let registeredActionButtons = []; |
| 2 | + let actionButtonConfigs = []; |
| 3 | + |
| 4 | + const registerButton = (config) => { |
| 5 | + if (!config || !config.container || actionButtonConfigs.some((btn) => btn.id === config.id)) { |
| 6 | + return; |
| 7 | + } |
| 8 | + |
| 9 | + actionButtonConfigs = [...actionButtonConfigs, config].sort((a, b) => a.priority - b.priority); |
| 10 | + recalculateButtonsLayout(); |
| 11 | + }; |
| 12 | + const unregisterButton = (id) => { |
| 13 | + actionButtonConfigs = actionButtonConfigs.filter((btn) => btn.id !== id); |
| 14 | + recalculateButtonsLayout(); |
| 15 | + }; |
| 16 | + const recalculateButtonsLayout = () => { |
| 17 | + const buttonsToRender = actionButtonConfigs.filter((btn) => { |
| 18 | + if (typeof btn.checkVisibility === 'function') { |
| 19 | + const isVisible = btn.checkVisibility(); |
| 20 | + |
| 21 | + return isVisible; |
| 22 | + } |
| 23 | + |
| 24 | + return false; |
| 25 | + }); |
| 26 | + |
| 27 | + buttonsToRender.forEach((buttonConfig, index) => { |
| 28 | + const { container } = buttonConfig; |
3 | 29 |
|
4 | | - const QuickActionManager = (() => { |
5 | | - const registerButton = (config) => { |
6 | | - if (!config || !config.selector || registeredActionButtons.some((btn) => btn.name === config.name)) { |
7 | | - return; |
| 30 | + if (!container.style.transition) { |
| 31 | + container.style.transition = 'all 0.3s ease-in-out'; |
8 | 32 | } |
9 | 33 |
|
10 | | - registeredActionButtons = [...registeredActionButtons, config]; |
11 | | - recalculateButtonsLayout(); |
12 | | - }; |
13 | | - const unregisterButton = (name) => { |
14 | | - registeredActionButtons = registeredActionButtons.filter((btn) => btn.name !== name); |
15 | | - recalculateButtonsLayout(); |
16 | | - }; |
17 | | - const recalculateButtonsLayout = () => { |
18 | | - const sortedButtons = registeredActionButtons.sort((a, b) => a.priority - b.priority); |
19 | | - const buttonsToRender = sortedButtons.filter((el) => { |
20 | | - if (el.checkVisibility && typeof el.checkVisibility === 'function') { |
21 | | - const isVisible = el.checkVisibility(); |
22 | | - |
23 | | - return isVisible; |
24 | | - } |
25 | | - |
26 | | - return false; |
27 | | - }); |
28 | | - |
29 | | - buttonsToRender.forEach((buttonConfig, index) => { |
30 | | - const { selector } = buttonConfig; |
31 | | - |
32 | | - if (!selector.style.transition) { |
33 | | - selector.style.transition = 'all 0.3s ease-in-out'; |
34 | | - } |
35 | | - |
36 | | - selector.style.position = 'fixed'; |
37 | | - selector.style.right = '2rem'; |
38 | | - selector.style.zIndex = buttonConfig.zIndex || 1040; |
39 | | - |
40 | | - const bottomPosition = `${index === 0 ? 2 : (index + 1) * 3.2}rem`; |
41 | | - |
42 | | - selector.style.bottom = bottomPosition; |
43 | | - }); |
44 | | - }; |
45 | | - |
46 | | - return { |
47 | | - registerButton, |
48 | | - unregisterButton, |
49 | | - recalculateButtonsLayout, |
50 | | - }; |
51 | | - })(); |
52 | | - |
53 | | - global.ibexa.adminUiConfig.quickActionManager = QuickActionManager; |
| 34 | + container.style.position = 'fixed'; |
| 35 | + container.style.right = '2rem'; |
| 36 | + container.style.zIndex = buttonConfig.zIndex || 1040; |
| 37 | + |
| 38 | + const bottomPosition = `${index === 0 ? 2 : index * 3.8 + 2 + index * 0.5}rem`; |
| 39 | + |
| 40 | + container.style.bottom = bottomPosition; |
| 41 | + }); |
| 42 | + }; |
| 43 | + |
| 44 | + global.ibexa.quickAction = { |
| 45 | + registerButton, |
| 46 | + unregisterButton, |
| 47 | + recalculateButtonsLayout, |
| 48 | + }; |
54 | 49 | })(window); |
0 commit comments