@melodicdev/components 3.1.0 → 4.0.0

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 (177) hide show
  1. package/assets/melodic-components.js +4269 -2377
  2. package/assets/melodic-components.js.map +1 -1
  3. package/assets/melodic-components.min.js +5477 -3831
  4. package/lib/components/data-display/calendar-view/calendar-view-month.template.d.ts.map +1 -1
  5. package/lib/components/data-display/calendar-view/calendar-view-month.template.js +17 -0
  6. package/lib/components/data-display/calendar-view/calendar-view.component.d.ts +23 -3
  7. package/lib/components/data-display/calendar-view/calendar-view.component.d.ts.map +1 -1
  8. package/lib/components/data-display/calendar-view/calendar-view.component.js +76 -21
  9. package/lib/components/data-display/calendar-view/calendar-view.utils.d.ts +9 -0
  10. package/lib/components/data-display/calendar-view/calendar-view.utils.d.ts.map +1 -1
  11. package/lib/components/data-display/calendar-view/calendar-view.utils.js +68 -19
  12. package/lib/components/data-display/data-grid/data-grid.component.d.ts +24 -0
  13. package/lib/components/data-display/data-grid/data-grid.component.d.ts.map +1 -1
  14. package/lib/components/data-display/data-grid/data-grid.component.js +104 -31
  15. package/lib/components/data-display/data-grid/data-grid.template.d.ts.map +1 -1
  16. package/lib/components/data-display/data-grid/data-grid.template.js +3 -0
  17. package/lib/components/data-display/table/table.component.d.ts +7 -0
  18. package/lib/components/data-display/table/table.component.d.ts.map +1 -1
  19. package/lib/components/data-display/table/table.component.js +20 -5
  20. package/lib/components/data-display/table/table.template.d.ts.map +1 -1
  21. package/lib/components/data-display/table/table.template.js +3 -0
  22. package/lib/components/data-display/table-core/index.d.ts +1 -0
  23. package/lib/components/data-display/table-core/index.d.ts.map +1 -1
  24. package/lib/components/data-display/table-core/index.js +1 -0
  25. package/lib/components/data-display/table-core/memo.d.ts +10 -0
  26. package/lib/components/data-display/table-core/memo.d.ts.map +1 -0
  27. package/lib/components/data-display/table-core/memo.js +20 -0
  28. package/lib/components/feedback/alert/alert.styles.d.ts.map +1 -1
  29. package/lib/components/feedback/alert/alert.styles.js +25 -0
  30. package/lib/components/feedback/progress/progress.styles.d.ts.map +1 -1
  31. package/lib/components/feedback/progress/progress.styles.js +8 -3
  32. package/lib/components/feedback/spinner/spinner.styles.d.ts.map +1 -1
  33. package/lib/components/feedback/spinner/spinner.styles.js +2 -11
  34. package/lib/components/feedback/toast/toast-container.template.d.ts.map +1 -1
  35. package/lib/components/feedback/toast/toast-container.template.js +4 -0
  36. package/lib/components/feedback/toast/toast.component.d.ts +3 -2
  37. package/lib/components/feedback/toast/toast.component.d.ts.map +1 -1
  38. package/lib/components/feedback/toast/toast.component.js +10 -0
  39. package/lib/components/feedback/toast/toast.service.d.ts +26 -6
  40. package/lib/components/feedback/toast/toast.service.d.ts.map +1 -1
  41. package/lib/components/feedback/toast/toast.service.js +53 -18
  42. package/lib/components/feedback/toast/toast.template.js +1 -1
  43. package/lib/components/forms/autocomplete/autocomplete.component.d.ts +7 -0
  44. package/lib/components/forms/autocomplete/autocomplete.component.d.ts.map +1 -1
  45. package/lib/components/forms/autocomplete/autocomplete.component.js +39 -0
  46. package/lib/components/forms/autocomplete/autocomplete.template.d.ts.map +1 -1
  47. package/lib/components/forms/autocomplete/autocomplete.template.js +5 -1
  48. package/lib/components/forms/button-group/button-group.component.d.ts +3 -2
  49. package/lib/components/forms/button-group/button-group.component.d.ts.map +1 -1
  50. package/lib/components/forms/button-group/button-group.component.js +11 -1
  51. package/lib/components/forms/checkbox/checkbox.component.d.ts +4 -0
  52. package/lib/components/forms/checkbox/checkbox.component.d.ts.map +1 -1
  53. package/lib/components/forms/checkbox/checkbox.component.js +5 -1
  54. package/lib/components/forms/checkbox/checkbox.template.d.ts.map +1 -1
  55. package/lib/components/forms/checkbox/checkbox.template.js +2 -0
  56. package/lib/components/forms/date-picker/calendar.component.d.ts +21 -0
  57. package/lib/components/forms/date-picker/calendar.component.d.ts.map +1 -1
  58. package/lib/components/forms/date-picker/calendar.component.js +69 -2
  59. package/lib/components/forms/date-picker/calendar.template.d.ts.map +1 -1
  60. package/lib/components/forms/date-picker/calendar.template.js +6 -3
  61. package/lib/components/forms/date-picker/date-picker.component.d.ts +6 -0
  62. package/lib/components/forms/date-picker/date-picker.component.d.ts.map +1 -1
  63. package/lib/components/forms/date-picker/date-picker.component.js +41 -12
  64. package/lib/components/forms/file-upload/file-upload.component.d.ts.map +1 -1
  65. package/lib/components/forms/file-upload/file-upload.component.js +15 -5
  66. package/lib/components/forms/form-field/form-field.component.d.ts +8 -0
  67. package/lib/components/forms/form-field/form-field.component.d.ts.map +1 -1
  68. package/lib/components/forms/form-field/form-field.component.js +41 -6
  69. package/lib/components/forms/form-field/form-field.template.js +1 -1
  70. package/lib/components/forms/input/input.component.d.ts +26 -3
  71. package/lib/components/forms/input/input.component.d.ts.map +1 -1
  72. package/lib/components/forms/input/input.component.js +46 -6
  73. package/lib/components/forms/input/input.template.d.ts.map +1 -1
  74. package/lib/components/forms/input/input.template.js +9 -0
  75. package/lib/components/forms/radio-card-group/radio-card-group.component.d.ts +6 -0
  76. package/lib/components/forms/radio-card-group/radio-card-group.component.d.ts.map +1 -1
  77. package/lib/components/forms/radio-card-group/radio-card-group.component.js +34 -0
  78. package/lib/components/forms/radio-card-group/radio-card.component.d.ts +6 -0
  79. package/lib/components/forms/radio-card-group/radio-card.component.d.ts.map +1 -1
  80. package/lib/components/forms/radio-card-group/radio-card.component.js +7 -1
  81. package/lib/components/forms/radio-card-group/radio-card.template.js +1 -1
  82. package/lib/components/forms/select/select.component.d.ts.map +1 -1
  83. package/lib/components/forms/select/select.component.js +13 -1
  84. package/lib/components/forms/select/select.template.d.ts.map +1 -1
  85. package/lib/components/forms/select/select.template.js +5 -1
  86. package/lib/components/forms/textarea/textarea.component.d.ts +10 -3
  87. package/lib/components/forms/textarea/textarea.component.d.ts.map +1 -1
  88. package/lib/components/forms/textarea/textarea.component.js +10 -5
  89. package/lib/components/forms/textarea/textarea.template.d.ts.map +1 -1
  90. package/lib/components/forms/textarea/textarea.template.js +2 -0
  91. package/lib/components/forms/time-picker/time-picker.component.d.ts +16 -0
  92. package/lib/components/forms/time-picker/time-picker.component.d.ts.map +1 -1
  93. package/lib/components/forms/time-picker/time-picker.component.js +43 -3
  94. package/lib/components/foundation/container/container.component.js +5 -5
  95. package/lib/components/foundation/container/container.styles.d.ts.map +1 -1
  96. package/lib/components/foundation/container/container.styles.js +10 -0
  97. package/lib/components/foundation/stack/stack.component.d.ts +6 -0
  98. package/lib/components/foundation/stack/stack.component.d.ts.map +1 -1
  99. package/lib/components/foundation/stack/stack.component.js +11 -5
  100. package/lib/components/foundation/stack/stack.styles.d.ts.map +1 -1
  101. package/lib/components/foundation/stack/stack.styles.js +14 -0
  102. package/lib/components/general/icon/icon.template.d.ts.map +1 -1
  103. package/lib/components/general/icon/icon.template.js +7 -1
  104. package/lib/components/navigation/breadcrumb/breadcrumb-item.template.d.ts.map +1 -1
  105. package/lib/components/navigation/breadcrumb/breadcrumb-item.template.js +2 -1
  106. package/lib/components/navigation/functions/match-by-route.function.d.ts +16 -0
  107. package/lib/components/navigation/functions/match-by-route.function.d.ts.map +1 -0
  108. package/lib/components/navigation/functions/match-by-route.function.js +34 -0
  109. package/lib/components/navigation/functions/route-link.function.d.ts +20 -0
  110. package/lib/components/navigation/functions/route-link.function.d.ts.map +1 -0
  111. package/lib/components/navigation/functions/route-link.function.js +34 -0
  112. package/lib/components/navigation/pagination/pagination.component.d.ts +8 -0
  113. package/lib/components/navigation/pagination/pagination.component.d.ts.map +1 -1
  114. package/lib/components/navigation/pagination/pagination.component.js +12 -2
  115. package/lib/components/navigation/pagination/pagination.styles.d.ts.map +1 -1
  116. package/lib/components/navigation/pagination/pagination.styles.js +10 -0
  117. package/lib/components/navigation/pagination/pagination.template.js +2 -2
  118. package/lib/components/navigation/sidebar/sidebar-item.template.d.ts.map +1 -1
  119. package/lib/components/navigation/sidebar/sidebar-item.template.js +5 -1
  120. package/lib/components/navigation/sidebar/sidebar.component.d.ts +12 -6
  121. package/lib/components/navigation/sidebar/sidebar.component.d.ts.map +1 -1
  122. package/lib/components/navigation/sidebar/sidebar.component.js +20 -12
  123. package/lib/components/navigation/sidebar/sidebar.template.d.ts.map +1 -1
  124. package/lib/components/navigation/sidebar/sidebar.template.js +5 -1
  125. package/lib/components/navigation/steps/step.component.d.ts.map +1 -1
  126. package/lib/components/navigation/steps/step.component.js +19 -1
  127. package/lib/components/navigation/steps/step.template.d.ts.map +1 -1
  128. package/lib/components/navigation/steps/step.template.js +6 -0
  129. package/lib/components/navigation/steps/steps.component.d.ts +10 -0
  130. package/lib/components/navigation/steps/steps.component.d.ts.map +1 -1
  131. package/lib/components/navigation/steps/steps.component.js +42 -9
  132. package/lib/components/navigation/steps/steps.template.js +9 -0
  133. package/lib/components/navigation/tabs/tab-panel.styles.d.ts.map +1 -1
  134. package/lib/components/navigation/tabs/tab-panel.styles.js +7 -2
  135. package/lib/components/navigation/tabs/tabs.component.d.ts +10 -0
  136. package/lib/components/navigation/tabs/tabs.component.d.ts.map +1 -1
  137. package/lib/components/navigation/tabs/tabs.component.js +36 -7
  138. package/lib/components/overlays/dialog/dialog-ref.class.d.ts +19 -9
  139. package/lib/components/overlays/dialog/dialog-ref.class.d.ts.map +1 -1
  140. package/lib/components/overlays/dialog/dialog-ref.class.js +37 -5
  141. package/lib/components/overlays/dropdown/dropdown.component.d.ts +7 -0
  142. package/lib/components/overlays/dropdown/dropdown.component.d.ts.map +1 -1
  143. package/lib/components/overlays/dropdown/dropdown.component.js +26 -11
  144. package/lib/components/overlays/popover/popover.component.d.ts +8 -0
  145. package/lib/components/overlays/popover/popover.component.d.ts.map +1 -1
  146. package/lib/components/overlays/popover/popover.component.js +17 -0
  147. package/lib/components/overlays/tooltip/tooltip.component.d.ts +6 -5
  148. package/lib/components/overlays/tooltip/tooltip.component.d.ts.map +1 -1
  149. package/lib/components/overlays/tooltip/tooltip.component.js +14 -10
  150. package/lib/components/sections/app-shell/app-shell.component.d.ts +13 -0
  151. package/lib/components/sections/app-shell/app-shell.component.d.ts.map +1 -1
  152. package/lib/components/sections/app-shell/app-shell.component.js +45 -1
  153. package/lib/components/sections/app-shell/app-shell.styles.d.ts.map +1 -1
  154. package/lib/components/sections/app-shell/app-shell.styles.js +15 -0
  155. package/lib/components/sections/app-shell/app-shell.template.d.ts.map +1 -1
  156. package/lib/components/sections/app-shell/app-shell.template.js +5 -0
  157. package/lib/components/sections/page-section/page-section.template.d.ts.map +1 -1
  158. package/lib/components/sections/page-section/page-section.template.js +6 -1
  159. package/lib/directives/tooltip.directive.d.ts.map +1 -1
  160. package/lib/directives/tooltip.directive.js +39 -6
  161. package/lib/theme/functions/apply-theme.function.d.ts +4 -1
  162. package/lib/theme/functions/apply-theme.function.d.ts.map +1 -1
  163. package/lib/theme/functions/apply-theme.function.js +20 -4
  164. package/lib/theme/functions/create-theme.function.js +0 -1
  165. package/lib/utils/accessibility/cross-root-aria.d.ts +40 -0
  166. package/lib/utils/accessibility/cross-root-aria.d.ts.map +1 -0
  167. package/lib/utils/accessibility/cross-root-aria.js +97 -0
  168. package/lib/utils/accessibility/index.d.ts +1 -0
  169. package/lib/utils/accessibility/index.d.ts.map +1 -1
  170. package/lib/utils/accessibility/index.js +1 -0
  171. package/lib/utils/directives/index.d.ts +1 -0
  172. package/lib/utils/directives/index.d.ts.map +1 -1
  173. package/lib/utils/directives/index.js +1 -0
  174. package/lib/utils/directives/watch-light-slots.d.ts +20 -0
  175. package/lib/utils/directives/watch-light-slots.d.ts.map +1 -0
  176. package/lib/utils/directives/watch-light-slots.js +36 -0
  177. package/package.json +2 -2
@@ -0,0 +1,97 @@
1
+ /**
2
+ * ARIA relationships that cross a shadow-root boundary.
3
+ *
4
+ * `aria-describedby`, `aria-labelledby` and friends are IDREFs, and an IDREF
5
+ * only resolves within the same tree. A component whose description lives in
6
+ * its shadow root therefore cannot point a light-DOM trigger at it — the
7
+ * attribute is set, resolves to nothing, and the content is never announced.
8
+ *
9
+ * Element-reference properties (`ariaDescribedByElements`,
10
+ * `ariaLabelledByElements`) do cross the boundary and are the correct fix
11
+ * where they exist. Where they do not, the text itself is copied onto the
12
+ * element via `aria-description` / `aria-label`, which is announced even
13
+ * though it duplicates the string.
14
+ */
15
+ /** True when this engine supports ARIA element references. */
16
+ export function supportsAriaElementReferences() {
17
+ return typeof Element !== 'undefined' && 'ariaDescribedByElements' in Element.prototype;
18
+ }
19
+ /**
20
+ * Describe `target` with `describers`, which may live in another root.
21
+ * Pass an empty array to clear the relationship.
22
+ */
23
+ export function setCrossRootDescription(target, describers) {
24
+ const reflected = target;
25
+ if ('ariaDescribedByElements' in reflected) {
26
+ reflected.ariaDescribedByElements = describers.length > 0 ? describers : null;
27
+ target.removeAttribute('aria-description');
28
+ return;
29
+ }
30
+ const text = describers
31
+ .map((element) => element.textContent?.trim() ?? '')
32
+ .filter(Boolean)
33
+ .join('. ');
34
+ if (text) {
35
+ target.setAttribute('aria-description', text);
36
+ }
37
+ else {
38
+ target.removeAttribute('aria-description');
39
+ }
40
+ }
41
+ /** Label `target` with `labels`, which may live in another root. */
42
+ export function setCrossRootLabel(target, labels) {
43
+ const reflected = target;
44
+ if ('ariaLabelledByElements' in reflected) {
45
+ reflected.ariaLabelledByElements = labels.length > 0 ? labels : null;
46
+ return;
47
+ }
48
+ const text = labels
49
+ .map((element) => element.textContent?.trim() ?? '')
50
+ .filter(Boolean)
51
+ .join(' ');
52
+ if (text) {
53
+ target.setAttribute('aria-label', text);
54
+ }
55
+ else {
56
+ target.removeAttribute('aria-label');
57
+ }
58
+ }
59
+ /**
60
+ * Point `target` at the currently active option, which may live in another
61
+ * root (a composite listbox's options are in the light DOM while the focused
62
+ * control is inside a shadow root).
63
+ */
64
+ export function setCrossRootActiveDescendant(target, active) {
65
+ const reflected = target;
66
+ if ('ariaActiveDescendantElement' in reflected) {
67
+ reflected.ariaActiveDescendantElement = active;
68
+ return;
69
+ }
70
+ if (active?.id) {
71
+ target.setAttribute('aria-activedescendant', active.id);
72
+ }
73
+ else {
74
+ target.removeAttribute('aria-activedescendant');
75
+ }
76
+ }
77
+ /**
78
+ * The element that actually takes focus for a (possibly composite) control.
79
+ *
80
+ * ARIA state must sit on the focusable node, not on a wrapper: setting
81
+ * `aria-haspopup`/`aria-expanded` on an `<ml-button>` host leaves the real
82
+ * `<button>` inside its shadow root announcing nothing.
83
+ */
84
+ export function getFocusableControl(element) {
85
+ const root = element.shadowRoot;
86
+ if (root) {
87
+ const control = root.querySelector('button, [role="button"], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
88
+ if (control) {
89
+ return control;
90
+ }
91
+ }
92
+ return element;
93
+ }
94
+ /** Remove any cross-root description this module applied. */
95
+ export function clearCrossRootDescription(target) {
96
+ setCrossRootDescription(target, []);
97
+ }
@@ -3,4 +3,5 @@ export type { FocusTrap, FocusTrapOptions, FocusTrapDeactivateOptions } from './
3
3
  export { focusVisible, isFocusVisible } from './focus-visible.js';
4
4
  export { announce, createLiveRegion } from './live-region.js';
5
5
  export { getFirstFocusable, getLastFocusable, getFocusableElements, focusFirst, focusLast } from './focus-utils.js';
6
+ export { setCrossRootDescription, setCrossRootLabel, setCrossRootActiveDescendant, clearCrossRootDescription, getFocusableControl, supportsAriaElementReferences } from './cross-root-aria.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/accessibility/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACtG,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/accessibility/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACtG,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpH,OAAO,EACN,uBAAuB,EACvB,iBAAiB,EACjB,4BAA4B,EAC5B,yBAAyB,EACzB,mBAAmB,EACnB,6BAA6B,EAC7B,MAAM,sBAAsB,CAAC"}
@@ -2,3 +2,4 @@ export { focusTrap, createFocusTrap, getDeepActiveElement, isDeepFocusWithin } f
2
2
  export { focusVisible, isFocusVisible } from './focus-visible.js';
3
3
  export { announce, createLiveRegion } from './live-region.js';
4
4
  export { getFirstFocusable, getLastFocusable, getFocusableElements, focusFirst, focusLast } from './focus-utils.js';
5
+ export { setCrossRootDescription, setCrossRootLabel, setCrossRootActiveDescendant, clearCrossRootDescription, getFocusableControl, supportsAriaElementReferences } from './cross-root-aria.js';
@@ -1,2 +1,3 @@
1
1
  export { clickOutside } from './click-outside.directive.js';
2
+ export { watchLightSlots, hasLightSlot } from './watch-light-slots.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +1,2 @@
1
1
  export { clickOutside } from './click-outside.directive.js';
2
+ export { watchLightSlots, hasLightSlot } from './watch-light-slots.js';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Watch the light DOM for which named slots have content.
3
+ *
4
+ * `watchSlotPresence` listens on the shadow `<slot>` elements, which only
5
+ * works when those slots are always rendered. A component that renders a slot
6
+ * conditionally (`${when(hasSearch, …)}`) has a chicken-and-egg problem: the
7
+ * slot that would fire `slotchange` exists only once the flag is already true,
8
+ * so content slotted after mount never appears at all.
9
+ *
10
+ * Only direct children participate in slot projection, but a `slot` attribute
11
+ * change on a child is observable only with `subtree: true` — so the subtree is
12
+ * observed and the mutations are filtered down to the ones that can actually
13
+ * change projection. Deep mutations inside slotted content are ignored.
14
+ *
15
+ * Returns a disconnect function; call it from `onDestroy`.
16
+ */
17
+ export declare function watchLightSlots(host: HTMLElement, onChange: () => void): () => void;
18
+ /** True when `host` has a direct child assigned to `slotName`. */
19
+ export declare function hasLightSlot(host: HTMLElement, slotName: string): boolean;
20
+ //# sourceMappingURL=watch-light-slots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-light-slots.d.ts","sourceRoot":"","sources":["../../../src/utils/directives/watch-light-slots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAqBnF;AAED,kEAAkE;AAClE,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzE"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Watch the light DOM for which named slots have content.
3
+ *
4
+ * `watchSlotPresence` listens on the shadow `<slot>` elements, which only
5
+ * works when those slots are always rendered. A component that renders a slot
6
+ * conditionally (`${when(hasSearch, …)}`) has a chicken-and-egg problem: the
7
+ * slot that would fire `slotchange` exists only once the flag is already true,
8
+ * so content slotted after mount never appears at all.
9
+ *
10
+ * Only direct children participate in slot projection, but a `slot` attribute
11
+ * change on a child is observable only with `subtree: true` — so the subtree is
12
+ * observed and the mutations are filtered down to the ones that can actually
13
+ * change projection. Deep mutations inside slotted content are ignored.
14
+ *
15
+ * Returns a disconnect function; call it from `onDestroy`.
16
+ */
17
+ export function watchLightSlots(host, onChange) {
18
+ const observer = new MutationObserver((mutations) => {
19
+ const relevant = mutations.some((mutation) => mutation.type === 'childList' ? mutation.target === host : mutation.target.parentNode === host);
20
+ if (relevant) {
21
+ onChange();
22
+ }
23
+ });
24
+ observer.observe(host, {
25
+ childList: true,
26
+ subtree: true,
27
+ attributes: true,
28
+ attributeFilter: ['slot']
29
+ });
30
+ onChange();
31
+ return () => observer.disconnect();
32
+ }
33
+ /** True when `host` has a direct child assigned to `slotName`. */
34
+ export function hasLightSlot(host, slotName) {
35
+ return host.querySelector(`:scope > [slot="${slotName}"]`) !== null;
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melodicdev/components",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "Themeable UI component library built on the Melodic Framework",
5
5
  "license": "MIT",
6
6
  "author": "Melodic Development",
@@ -280,7 +280,7 @@
280
280
  "generate:icon-map": "node scripts/generate-icon-map.mjs"
281
281
  },
282
282
  "peerDependencies": {
283
- "@melodicdev/core": "^3.0.0"
283
+ "@melodicdev/core": "^4.0.0"
284
284
  },
285
285
  "devDependencies": {
286
286
  "@melodicdev/core": "file:../..",