@pure-ds/core 0.7.59 → 0.7.61

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.
@@ -164,6 +164,14 @@
164
164
  <path d="M197.58,129.06,146,110l-19-51.62a15.92,15.92,0,0,0-29.88,0L78,110l-51.62,19a15.92,15.92,0,0,0,0,29.88L78,178l19,51.62a15.92,15.92,0,0,0,29.88,0L146,178l51.62-19a15.92,15.92,0,0,0,0-29.88ZM137,164.22a8,8,0,0,0-4.74,4.74L112,223.85,91.78,169A8,8,0,0,0,87,164.22L32.15,144,87,123.78A8,8,0,0,0,91.78,119L112,64.15,132.22,119a8,8,0,0,0,4.74,4.74L191.85,144ZM144,40a8,8,0,0,1,8-8h16V16a8,8,0,0,1,16,0V32h16a8,8,0,0,1,0,16H184V64a8,8,0,0,1-16,0V48H152A8,8,0,0,1,144,40ZM248,88a8,8,0,0,1-8,8h-8v8a8,8,0,0,1-16,0V96h-8a8,8,0,0,1,0-16h8V72a8,8,0,0,1,16,0v8h8A8,8,0,0,1,248,88Z"/>
165
165
  </symbol>
166
166
 
167
+ <symbol id="corners-out" viewBox="0 0 256 256">
168
+ <path d="M216,48V88a8,8,0,0,1-16,0V56H168a8,8,0,0,1,0-16h40A8,8,0,0,1,216,48ZM88,200H56V168a8,8,0,0,0-16,0v40a8,8,0,0,0,8,8H88a8,8,0,0,0,0-16Zm120-40a8,8,0,0,0-8,8v32H168a8,8,0,0,0,0,16h40a8,8,0,0,0,8-8V168A8,8,0,0,0,208,160ZM88,40H48a8,8,0,0,0-8,8V88a8,8,0,0,0,16,0V56H88a8,8,0,0,0,0-16Z"/>
169
+ </symbol>
170
+
171
+ <symbol id="corners-in" viewBox="0 0 256 256">
172
+ <path d="M152,96V48a8,8,0,0,1,16,0V88h40a8,8,0,0,1,0,16H160A8,8,0,0,1,152,96ZM96,152H48a8,8,0,0,0,0,16H88v40a8,8,0,0,0,16,0V160A8,8,0,0,0,96,152Zm112,0H160a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V168h40a8,8,0,0,0,0-16ZM96,40a8,8,0,0,0-8,8V88H48a8,8,0,0,0,0,16H96a8,8,0,0,0,8-8V48A8,8,0,0,0,96,40Z"/>
173
+ </symbol>
174
+
167
175
  <symbol id="envelope" viewBox="0 0 256 256">
168
176
  <path d="M224,48H32a8,8,0,0,0-8,8V192a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A8,8,0,0,0,224,48Zm-96,85.15L52.57,64H203.43ZM98.71,128,40,181.81V74.19Zm11.84,10.85,12,11.05a8,8,0,0,0,10.82,0l12-11.05,58,53.15H52.57ZM157.29,128,216,74.18V181.82Z"/>
169
177
  </symbol>
@@ -2607,6 +2607,8 @@ presets.default = {
2607
2607
  "clipboard",
2608
2608
  "magic-wand",
2609
2609
  "sparkle",
2610
+ "corners-out",
2611
+ "corners-in"
2610
2612
  ],
2611
2613
  communication: [
2612
2614
  "envelope",
@@ -33,6 +33,12 @@ export const defaultPDSEnhancerMetadata = [
33
33
  description:
34
34
  "Enhances a nav element with data-dropdown to toggle its last child as a dropdown panel (menu, card, form, etc.). Add data-dropdown-close to any clickable descendant that should close the menu on selection.",
35
35
  attributes: [
36
+ {
37
+ name: "split-button",
38
+ description:
39
+ "Class that creates a split-button layout by mirroring the default menu item into a primary action button. Uses the first <li> by default, or <li data-default> when present.",
40
+ appliesTo: "nav[data-dropdown]",
41
+ },
36
42
  {
37
43
  name: "data-dropdown-close",
38
44
  description:
@@ -54,6 +54,7 @@ function enhanceDropdown(elem) {
54
54
  if (elem.dataset.enhancedDropdown) return;
55
55
  elem.dataset.enhancedDropdown = "true";
56
56
  const menu = elem.lastElementChild;
57
+ const usesDefaultAction = elem.classList.contains("split-button");
57
58
 
58
59
  if (!menu) return;
59
60
 
@@ -89,6 +90,63 @@ function enhanceDropdown(elem) {
89
90
  trigger.setAttribute("aria-expanded", "false");
90
91
  }
91
92
 
93
+ const resolveDefaultItem = () => {
94
+ if (!usesDefaultAction || !isMenu) return null;
95
+ return menu.querySelector(":scope > li[data-default]") || menu.querySelector(":scope > li");
96
+ };
97
+
98
+ const resolveDefaultAction = (item) => {
99
+ if (!item) return null;
100
+ return item.querySelector(":scope > a, :scope > button") || item.firstElementChild;
101
+ };
102
+
103
+ const createOrResolveDefaultButton = () => {
104
+ if (!usesDefaultAction || !trigger) return null;
105
+ let button = elem.querySelector(":scope > [data-dropdown-default]");
106
+ if (button) return button;
107
+ button = document.createElement("button");
108
+ button.setAttribute("type", "button");
109
+ button.setAttribute("data-dropdown-default", "");
110
+ button.className = trigger.className;
111
+ elem.insertBefore(button, trigger);
112
+ return button;
113
+ };
114
+
115
+ const syncDefaultButton = (button, action) => {
116
+ if (!button || !action) return;
117
+
118
+ button.replaceChildren(...Array.from(action.childNodes).map((node) => node.cloneNode(true)));
119
+
120
+ const label =
121
+ action.getAttribute("aria-label") ||
122
+ action.textContent?.replace(/\s+/g, " ").trim() ||
123
+ msg("Default action");
124
+ button.setAttribute("aria-label", label);
125
+ button.title = label;
126
+ };
127
+
128
+ const setupDefaultAction = () => {
129
+ if (!usesDefaultAction) return;
130
+ const defaultButton = createOrResolveDefaultButton();
131
+ const defaultItem = resolveDefaultItem();
132
+ const defaultAction = resolveDefaultAction(defaultItem);
133
+ if (!defaultButton || !defaultAction) return;
134
+
135
+ syncDefaultButton(defaultButton, defaultAction);
136
+
137
+ const executeDefault = () => {
138
+ if (!defaultAction) return;
139
+ if (typeof defaultAction.click === "function") {
140
+ defaultAction.click();
141
+ }
142
+ };
143
+
144
+ defaultButton.addEventListener("click", (event) => {
145
+ event.preventDefault();
146
+ executeDefault();
147
+ });
148
+ };
149
+
92
150
  if (!supportsPopover) {
93
151
  const warnKey = "__PDS_DROPDOWN_POPOVER_WARNED__";
94
152
  if (!globalThis[warnKey]) {
@@ -100,6 +158,8 @@ function enhanceDropdown(elem) {
100
158
  return;
101
159
  }
102
160
 
161
+ setupDefaultAction();
162
+
103
163
  menu.setAttribute("popover", "auto");
104
164
 
105
165
  const measureMenuSize = () => {
@@ -4547,6 +4547,41 @@ nav[data-dropdown] {
4547
4547
  display: flex;
4548
4548
  padding: 0;
4549
4549
 
4550
+ &.split-button {
4551
+ display: inline-flex;
4552
+ align-items: stretch;
4553
+ gap: 0;
4554
+
4555
+ & > [data-dropdown-default],
4556
+ & > [data-dropdown-toggle] {
4557
+ border-radius: 0;
4558
+ position: relative;
4559
+ }
4560
+
4561
+ & > [data-dropdown-default] {
4562
+ border-start-start-radius: var(--radius-md);
4563
+ border-end-start-radius: var(--radius-md);
4564
+ border-inline-end: 0;
4565
+ padding-inline: var(--spacing-3);
4566
+ min-inline-size: 9.5rem;
4567
+ justify-content: center;
4568
+ }
4569
+
4570
+ & > [data-dropdown-toggle] {
4571
+ border-start-end-radius: var(--radius-md);
4572
+ border-end-end-radius: var(--radius-md);
4573
+ inline-size: 2.5rem;
4574
+ min-inline-size: 2.5rem;
4575
+ padding-inline: 0;
4576
+ justify-content: center;
4577
+ }
4578
+
4579
+ & > [data-dropdown-toggle] pds-icon,
4580
+ & > [data-dropdown-default] pds-icon {
4581
+ pointer-events: none;
4582
+ }
4583
+ }
4584
+
4550
4585
  & > :last-child {
4551
4586
  position: absolute;
4552
4587
  padding: 0 var(--spacing-2);
package/src/js/pds.d.ts CHANGED
@@ -461,6 +461,8 @@ export class PDS extends EventTarget {
461
461
  /**
462
462
  * Reactive state container class for building reactive components.
463
463
  * Fires custom events ('change' and 'change:propertyName') when state properties are modified.
464
+ *
465
+ * @experimental API shape and event patterns may evolve.
464
466
  */
465
467
  static State: typeof State;
466
468
 
@@ -771,12 +773,20 @@ export class SchemaForm extends HTMLElement {
771
773
  }
772
774
 
773
775
  export function parse(html: PDSParseInput, ...values: unknown[]): NodeListOf<ChildNode>;
776
+ /**
777
+ * Experimental tagged-template helper for building DOM fragments without Lit.
778
+ * Supports attribute, event, boolean, and property-style bindings.
779
+ *
780
+ * @experimental API shape and binding semantics may evolve.
781
+ */
774
782
  export function html(html: PDSParseInput, ...values: unknown[]): DocumentFragment;
775
783
 
776
784
  /**
777
785
  * Reactive state container that fires custom events on property mutations.
778
786
  * When properties change, it emits "change" and "change:propertyName" events.
779
787
  *
788
+ * @experimental API shape and event patterns may evolve.
789
+ *
780
790
  * @example
781
791
  * ```javascript
782
792
  * const state = new State({ count: 0 });
package/src/js/pds.js CHANGED
@@ -643,11 +643,11 @@ PDS.adoptPrimitives = adoptPrimitives;
643
643
  export const parse = common.parseHTML;
644
644
  PDS.parse = parse;
645
645
 
646
- /** Parse HTML or tagged templates into a DocumentFragment */
646
+ /** Experimental: parse HTML or tagged templates into a DocumentFragment */
647
647
  export const html = common.parseFragment;
648
648
  PDS.html = html;
649
649
 
650
- /** Reactive state container for building reactive components */
650
+ /** Experimental reactive state container for building reactive components */
651
651
  PDS.State = State;
652
652
 
653
653
  // /** Create a reactive component with automatic re-rendering */