@editora/ui-react 0.1.11 → 0.1.12

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.
@@ -1,59 +1,668 @@
1
1
  'use client';
2
- import t, { useRef as B, useImperativeHandle as R, useEffect as A, useLayoutEffect as x } from "react";
3
- const I = typeof window < "u" ? x : A, N = t.forwardRef(function({
4
- children: E,
5
- label: i,
6
- menuLabel: o,
7
- menuHeading: f,
8
- menuDescription: b,
9
- variant: r,
10
- density: u,
11
- menuDensity: l,
12
- menuShape: a,
13
- disabled: p,
14
- items: c,
15
- onPrimaryAction: s,
16
- onSelect: n,
17
- ...h
18
- }, L) {
19
- const d = B(null);
20
- R(L, () => d.current), A(() => {
21
- const e = d.current;
22
- if (!e)
2
+ import t from "react";
3
+ import { createPortal as oe } from "react-dom";
4
+ const V = "editora-split-button-styles", se = `
5
+ .ed-split-button {
6
+ --ed-split-radius: 12px;
7
+ --ed-split-bg: var(--ui-color-primary, #2563eb);
8
+ --ed-split-bg-hover: color-mix(in srgb, var(--ed-split-bg) 84%, #0f172a 16%);
9
+ --ed-split-border: 1px solid color-mix(in srgb, var(--ui-color-border, #cbd5e1) 70%, transparent);
10
+ --ed-split-text: #ffffff;
11
+ --ed-split-shadow: 0 1px 2px rgba(2, 6, 23, 0.12), 0 8px 18px color-mix(in srgb, var(--ed-split-bg) 20%, transparent);
12
+ --ed-split-menu-bg: var(--ui-color-surface, #ffffff);
13
+ --ed-split-menu-text: var(--ui-color-text, #0f172a);
14
+ --ed-split-menu-muted: color-mix(in srgb, var(--ed-split-menu-text) 58%, transparent);
15
+ --ed-split-menu-border: 1px solid color-mix(in srgb, var(--ui-color-border, #cbd5e1) 64%, transparent);
16
+ --ed-split-menu-shadow: 0 22px 44px rgba(2, 6, 23, 0.16), 0 2px 8px rgba(2, 6, 23, 0.08);
17
+ --ed-split-menu-radius: 14px;
18
+ --ed-split-menu-gap: 2px;
19
+ --ed-split-menu-item-radius: 10px;
20
+ --ed-split-menu-item-min-height: 44px;
21
+ --ed-split-menu-item-padding: 10px 10px;
22
+ --ed-split-menu-accent: color-mix(in srgb, var(--ed-split-bg) 12%, transparent);
23
+ --ed-split-menu-accent-strong: color-mix(in srgb, var(--ed-split-bg) 18%, transparent);
24
+ --ed-split-menu-accent-border: color-mix(in srgb, var(--ed-split-bg) 24%, transparent);
25
+ --ed-split-menu-danger: var(--ui-color-danger, #dc2626);
26
+ display: inline-flex;
27
+ position: relative;
28
+ min-width: 0;
29
+ font-family: "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
30
+ }
31
+
32
+ .ed-split-button--neutral {
33
+ --ed-split-bg: #ffffff;
34
+ --ed-split-bg-hover: #f8fafc;
35
+ --ed-split-border: 1px solid color-mix(in srgb, #0f172a 12%, transparent);
36
+ --ed-split-text: #0f172a;
37
+ --ed-split-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 10px 24px rgba(15, 23, 42, 0.08);
38
+ }
39
+
40
+ .ed-split-button--flat {
41
+ --ed-split-radius: 10px;
42
+ --ed-split-bg: #ffffff;
43
+ --ed-split-bg-hover: #f1f5f9;
44
+ --ed-split-border: 1px solid #dbe4f0;
45
+ --ed-split-text: #0f172a;
46
+ --ed-split-shadow: none;
47
+ --ed-split-menu-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
48
+ }
49
+
50
+ .ed-split-button--contrast {
51
+ --ed-split-bg: #111827;
52
+ --ed-split-bg-hover: #0b1220;
53
+ --ed-split-text: #f8fafc;
54
+ --ed-split-shadow: 0 1px 2px rgba(15, 23, 42, 0.2), 0 16px 36px rgba(15, 23, 42, 0.18);
55
+ }
56
+
57
+ .ed-split-button--compact {
58
+ --ed-split-radius: 10px;
59
+ }
60
+
61
+ .ed-split-button--square {
62
+ --ed-split-radius: 0px;
63
+ }
64
+
65
+ .ed-split-button__group {
66
+ display: inline-grid;
67
+ grid-template-columns: minmax(0, 1fr) auto;
68
+ min-width: 0;
69
+ border: var(--ed-split-border);
70
+ border-radius: var(--ed-split-radius);
71
+ overflow: hidden;
72
+ background: var(--ed-split-bg);
73
+ color: var(--ed-split-text);
74
+ box-shadow: var(--ed-split-shadow);
75
+ }
76
+
77
+ .ed-split-button__primary,
78
+ .ed-split-button__toggle {
79
+ appearance: none;
80
+ border: 0;
81
+ margin: 0;
82
+ background: transparent;
83
+ color: inherit;
84
+ font: 600 14px/1.2 "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
85
+ cursor: pointer;
86
+ transition: background-color 130ms ease, color 130ms ease;
87
+ }
88
+
89
+ .ed-split-button__primary {
90
+ min-height: 40px;
91
+ padding: 0 14px;
92
+ display: inline-flex;
93
+ align-items: center;
94
+ justify-content: center;
95
+ gap: 8px;
96
+ }
97
+
98
+ .ed-split-button__toggle {
99
+ min-height: 40px;
100
+ inline-size: 42px;
101
+ display: inline-grid;
102
+ place-items: center;
103
+ border-inline-start: 1px solid color-mix(in srgb, currentColor 16%, transparent);
104
+ }
105
+
106
+ .ed-split-button__primary:hover,
107
+ .ed-split-button__primary:focus-visible,
108
+ .ed-split-button__toggle:hover,
109
+ .ed-split-button__toggle:focus-visible,
110
+ .ed-split-button[data-open="true"] .ed-split-button__toggle {
111
+ background: var(--ed-split-bg-hover);
112
+ outline: none;
113
+ }
114
+
115
+ .ed-split-button--compact .ed-split-button__primary,
116
+ .ed-split-button--compact .ed-split-button__toggle {
117
+ min-height: 36px;
118
+ font-size: 13px;
119
+ }
120
+
121
+ .ed-split-button--compact .ed-split-button__primary {
122
+ padding-inline: 12px;
123
+ }
124
+
125
+ .ed-split-button--compact .ed-split-button__toggle {
126
+ inline-size: 38px;
127
+ }
128
+
129
+ .ed-split-button--comfortable .ed-split-button__primary,
130
+ .ed-split-button--comfortable .ed-split-button__toggle {
131
+ min-height: 44px;
132
+ }
133
+
134
+ .ed-split-button--comfortable .ed-split-button__primary {
135
+ padding-inline: 16px;
136
+ }
137
+
138
+ .ed-split-button--comfortable .ed-split-button__toggle {
139
+ inline-size: 46px;
140
+ }
141
+
142
+ .ed-split-button__toggleIcon {
143
+ inline-size: 14px;
144
+ block-size: 14px;
145
+ display: block;
146
+ }
147
+
148
+ .ed-split-button[aria-disabled="true"] {
149
+ opacity: 0.72;
150
+ pointer-events: none;
151
+ }
152
+
153
+ .ed-split-button__menu {
154
+ --ed-split-bg: var(--ui-color-primary, #2563eb);
155
+ --ed-split-menu-bg: var(--ui-color-surface, #ffffff);
156
+ --ed-split-menu-text: var(--ui-color-text, #0f172a);
157
+ --ed-split-menu-muted: color-mix(in srgb, var(--ed-split-menu-text) 58%, transparent);
158
+ --ed-split-menu-border: 1px solid color-mix(in srgb, var(--ui-color-border, #cbd5e1) 64%, transparent);
159
+ --ed-split-menu-shadow: 0 22px 44px rgba(2, 6, 23, 0.16), 0 2px 8px rgba(2, 6, 23, 0.08);
160
+ --ed-split-menu-radius: 14px;
161
+ --ed-split-menu-gap: 2px;
162
+ --ed-split-menu-item-radius: 10px;
163
+ --ed-split-menu-item-min-height: 44px;
164
+ --ed-split-menu-item-padding: 10px 10px;
165
+ --ed-split-menu-accent: color-mix(in srgb, var(--ed-split-bg) 12%, transparent);
166
+ --ed-split-menu-accent-strong: color-mix(in srgb, var(--ed-split-bg) 18%, transparent);
167
+ --ed-split-menu-accent-border: color-mix(in srgb, var(--ed-split-bg) 24%, transparent);
168
+ --ed-split-menu-danger: var(--ui-color-danger, #dc2626);
169
+ position: fixed;
170
+ z-index: 1600;
171
+ display: grid;
172
+ gap: 8px;
173
+ min-width: 240px;
174
+ max-width: min(360px, calc(100vw - 16px));
175
+ max-height: min(420px, calc(100vh - 16px));
176
+ overflow: hidden auto;
177
+ padding: 8px;
178
+ box-sizing: border-box;
179
+ border: var(--ed-split-menu-border);
180
+ border-radius: calc(var(--ed-split-menu-radius) + 2px);
181
+ background: var(--ed-split-menu-bg);
182
+ color: var(--ed-split-menu-text);
183
+ box-shadow: var(--ed-split-menu-shadow);
184
+ outline: none;
185
+ opacity: 0;
186
+ transform: translateY(-4px) scale(0.985);
187
+ animation: ed-split-button-menu-in 150ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
188
+ }
189
+
190
+ .ed-split-button__menu--neutral {
191
+ --ed-split-bg: #2563eb;
192
+ --ed-split-menu-bg: #ffffff;
193
+ --ed-split-menu-text: #0f172a;
194
+ --ed-split-menu-muted: color-mix(in srgb, var(--ed-split-menu-text) 58%, transparent);
195
+ --ed-split-menu-border: 1px solid color-mix(in srgb, #0f172a 12%, transparent);
196
+ --ed-split-menu-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
197
+ }
198
+
199
+ .ed-split-button__menu--flat {
200
+ --ed-split-bg: #2563eb;
201
+ --ed-split-menu-bg: #ffffff;
202
+ --ed-split-menu-text: #0f172a;
203
+ --ed-split-menu-muted: color-mix(in srgb, var(--ed-split-menu-text) 58%, transparent);
204
+ --ed-split-menu-border: 1px solid #dbe4f0;
205
+ --ed-split-menu-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
206
+ --ed-split-menu-accent: #eef4ff;
207
+ --ed-split-menu-accent-strong: #e0ecff;
208
+ --ed-split-menu-accent-border: color-mix(in srgb, #2563eb 20%, transparent);
209
+ }
210
+
211
+ .ed-split-button__menu--contrast {
212
+ --ed-split-bg: #2563eb;
213
+ --ed-split-menu-bg: #111827;
214
+ --ed-split-menu-text: #f8fafc;
215
+ --ed-split-menu-muted: color-mix(in srgb, var(--ed-split-menu-text) 58%, transparent);
216
+ --ed-split-menu-border: 1px solid #334155;
217
+ --ed-split-menu-shadow: 0 18px 36px rgba(15, 23, 42, 0.3), 0 2px 8px rgba(15, 23, 42, 0.2);
218
+ }
219
+
220
+ .ed-split-button__menu[data-placement="top"] {
221
+ transform-origin: bottom left;
222
+ }
223
+
224
+ .ed-split-button__menu[data-placement="bottom"] {
225
+ transform-origin: top left;
226
+ }
227
+
228
+ .ed-split-button__menuHeader {
229
+ display: grid;
230
+ gap: 4px;
231
+ padding: 4px 6px 2px;
232
+ }
233
+
234
+ .ed-split-button__menuHeading {
235
+ margin: 0;
236
+ font: 700 13px/1.25 "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
237
+ letter-spacing: 0.015em;
238
+ color: var(--ed-split-menu-text);
239
+ }
240
+
241
+ .ed-split-button__menuDescription {
242
+ margin: 0;
243
+ font: 500 12px/1.5 "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
244
+ color: var(--ed-split-menu-muted);
245
+ }
246
+
247
+ .ed-split-button__list {
248
+ display: grid;
249
+ gap: var(--ed-split-menu-gap);
250
+ }
251
+
252
+ .ed-split-button__menu--compact {
253
+ --ed-split-menu-gap: 1px;
254
+ --ed-split-menu-item-radius: 8px;
255
+ --ed-split-menu-item-min-height: 38px;
256
+ --ed-split-menu-item-padding: 8px 10px;
257
+ }
258
+
259
+ .ed-split-button__menu--airy {
260
+ --ed-split-menu-gap: 4px;
261
+ --ed-split-menu-item-radius: 14px;
262
+ --ed-split-menu-item-min-height: 50px;
263
+ --ed-split-menu-item-padding: 12px;
264
+ }
265
+
266
+ .ed-split-button__menu--flat {
267
+ --ed-split-menu-radius: 10px;
268
+ --ed-split-menu-item-radius: 8px;
269
+ }
270
+
271
+ .ed-split-button__menu--soft {
272
+ --ed-split-menu-radius: 18px;
273
+ --ed-split-menu-item-radius: 14px;
274
+ }
275
+
276
+ .ed-split-button__menu--square {
277
+ --ed-split-menu-radius: 0px;
278
+ --ed-split-menu-item-radius: 0px;
279
+ }
280
+
281
+ .ed-split-button__item {
282
+ inline-size: 100%;
283
+ min-inline-size: 0;
284
+ min-block-size: var(--ed-split-menu-item-min-height);
285
+ box-sizing: border-box;
286
+ display: grid;
287
+ grid-template-columns: minmax(0, 1fr) auto;
288
+ align-items: center;
289
+ gap: 10px;
290
+ padding: var(--ed-split-menu-item-padding);
291
+ border: 1px solid transparent;
292
+ border-radius: var(--ed-split-menu-item-radius);
293
+ background: transparent;
294
+ color: inherit;
295
+ text-align: left;
296
+ font: 500 13px/1.35 "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
297
+ cursor: pointer;
298
+ transition:
299
+ background-color 130ms ease,
300
+ border-color 130ms ease,
301
+ color 130ms ease,
302
+ box-shadow 130ms ease;
303
+ }
304
+
305
+ .ed-split-button__item:hover,
306
+ .ed-split-button__item[data-active="true"] {
307
+ background: var(--ed-split-menu-accent);
308
+ border-color: var(--ed-split-menu-accent-border);
309
+ }
310
+
311
+ .ed-split-button__item[data-active="true"] {
312
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ed-split-bg) 12%, transparent);
313
+ }
314
+
315
+ .ed-split-button__item:active {
316
+ background: var(--ed-split-menu-accent-strong);
317
+ }
318
+
319
+ .ed-split-button__item:focus-visible {
320
+ outline: none;
321
+ background: var(--ed-split-menu-accent);
322
+ border-color: var(--ed-split-menu-accent-border);
323
+ box-shadow:
324
+ inset 0 0 0 1px color-mix(in srgb, var(--ed-split-bg) 12%, transparent),
325
+ 0 0 0 3px color-mix(in srgb, var(--ed-split-bg) 14%, transparent);
326
+ }
327
+
328
+ .ed-split-button__item[aria-disabled="true"] {
329
+ opacity: 0.52;
330
+ cursor: not-allowed;
331
+ }
332
+
333
+ .ed-split-button__item--danger {
334
+ color: color-mix(in srgb, var(--ed-split-menu-danger) 88%, var(--ed-split-menu-text));
335
+ }
336
+
337
+ .ed-split-button__item--danger .ed-split-button__itemDescription {
338
+ color: color-mix(in srgb, var(--ed-split-menu-danger) 68%, transparent);
339
+ }
340
+
341
+ .ed-split-button__item--danger:hover,
342
+ .ed-split-button__item--danger[data-active="true"],
343
+ .ed-split-button__item--danger:focus-visible {
344
+ border-color: color-mix(in srgb, var(--ed-split-menu-danger) 28%, transparent);
345
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ed-split-menu-danger) 14%, transparent);
346
+ }
347
+
348
+ .ed-split-button__itemText {
349
+ min-inline-size: 0;
350
+ display: grid;
351
+ gap: 2px;
352
+ }
353
+
354
+ .ed-split-button__itemLabel {
355
+ display: block;
356
+ min-inline-size: 0;
357
+ overflow: hidden;
358
+ text-overflow: ellipsis;
359
+ white-space: nowrap;
360
+ }
361
+
362
+ .ed-split-button__itemDescription {
363
+ display: -webkit-box;
364
+ min-inline-size: 0;
365
+ overflow: hidden;
366
+ -webkit-box-orient: vertical;
367
+ -webkit-line-clamp: 2;
368
+ white-space: normal;
369
+ color: var(--ed-split-menu-muted);
370
+ font-size: 12px;
371
+ line-height: 1.4;
372
+ }
373
+
374
+ .ed-split-button__itemShortcut {
375
+ white-space: nowrap;
376
+ color: var(--ed-split-menu-muted);
377
+ font: 600 12px/1 "IBM Plex Mono", "SFMono-Regular", "SF Mono", Consolas, monospace;
378
+ letter-spacing: 0.03em;
379
+ }
380
+
381
+ @keyframes ed-split-button-menu-in {
382
+ from {
383
+ opacity: 0;
384
+ transform: translateY(-4px) scale(0.985);
385
+ }
386
+ to {
387
+ opacity: 1;
388
+ transform: translateY(0) scale(1);
389
+ }
390
+ }
391
+
392
+ @media (prefers-reduced-motion: reduce) {
393
+ .ed-split-button__menu {
394
+ animation: none;
395
+ opacity: 1;
396
+ transform: none;
397
+ }
398
+ }
399
+ `;
400
+ function le() {
401
+ if (typeof document > "u" || document.getElementById(V))
402
+ return;
403
+ const r = document.createElement("style");
404
+ r.id = V, r.textContent = se, document.head.appendChild(r);
405
+ }
406
+ function D(...r) {
407
+ return r.filter(Boolean).join(" ");
408
+ }
409
+ function L(r) {
410
+ return r.findIndex((u) => !u.disabled);
411
+ }
412
+ function G(r, u, y) {
413
+ var f;
414
+ if (!r.length)
415
+ return -1;
416
+ let d = u;
417
+ for (let m = 0; m < r.length; m += 1)
418
+ if (d = (d + y + r.length) % r.length, !((f = r[d]) != null && f.disabled))
419
+ return d;
420
+ return -1;
421
+ }
422
+ function J(r, u) {
423
+ const d = (u === "first" ? r : [...r].reverse()).findIndex((f) => !f.disabled);
424
+ return d < 0 ? -1 : u === "first" ? d : r.length - 1 - d;
425
+ }
426
+ const ae = t.forwardRef(function({
427
+ children: u,
428
+ className: y,
429
+ label: d = "Run action",
430
+ menuLabel: f = "Open action menu",
431
+ menuHeading: m,
432
+ menuDescription: k,
433
+ variant: E = "primary",
434
+ density: F = "default",
435
+ shape: W = "default",
436
+ menuDensity: $ = "default",
437
+ menuShape: H = "default",
438
+ disabled: x = !1,
439
+ items: o = [],
440
+ onPrimaryAction: B,
441
+ onSelect: I,
442
+ style: P,
443
+ ...Q
444
+ }, X) {
445
+ const z = t.useRef(null), T = t.useRef(null), N = t.useRef(null), _ = t.useRef(null), U = t.useRef([]), [l, M] = t.useState(!1), [s, b] = t.useState(-1), [a, q] = t.useState(null), K = t.useId(), Y = t.useId();
446
+ t.useImperativeHandle(X, () => z.current), t.useLayoutEffect(() => {
447
+ le();
448
+ }, []);
449
+ const v = t.useCallback(() => {
450
+ const e = T.current, n = _.current;
451
+ if (!e || !n)
23
452
  return;
24
- const v = () => s == null ? void 0 : s(), m = (y) => n == null ? void 0 : n(y.detail);
25
- return e.addEventListener("primary-action", v), e.addEventListener("select", m), () => {
26
- e.removeEventListener("primary-action", v), e.removeEventListener("select", m);
453
+ const i = e.getBoundingClientRect(), c = window.innerWidth || document.documentElement.clientWidth || 0, p = window.innerHeight || document.documentElement.clientHeight || 0, j = Math.max(260, Math.round(i.width));
454
+ n.style.minWidth = `${j}px`;
455
+ const g = n.getBoundingClientRect(), A = Math.max(0, p - i.bottom - 8), re = Math.max(0, i.top - 8), O = A < g.height && re > A;
456
+ let h = O ? i.top - g.height - 6 : i.bottom + 6, w = i.left;
457
+ w + g.width > c - 8 && (w = c - g.width - 8), w < 8 && (w = 8), h < 8 && (h = 8), h + g.height > p - 8 && (h = Math.max(8, p - g.height - 8)), q({
458
+ top: Math.round(h),
459
+ left: Math.round(w),
460
+ minWidth: j,
461
+ placement: O ? "top" : "bottom"
462
+ });
463
+ }, []);
464
+ t.useEffect(() => {
465
+ var n;
466
+ if (!l) {
467
+ q(null);
468
+ return;
469
+ }
470
+ const e = s >= 0 && !((n = o[s]) != null && n.disabled) ? s : L(o);
471
+ b(e);
472
+ }, [l, o, s]), t.useLayoutEffect(() => {
473
+ if (!l)
474
+ return;
475
+ v();
476
+ const e = requestAnimationFrame(() => {
477
+ var c, p;
478
+ v();
479
+ try {
480
+ (c = _.current) == null || c.focus({ preventScroll: !0 });
481
+ } catch {
482
+ (p = _.current) == null || p.focus();
483
+ }
484
+ }), n = () => v(), i = () => v();
485
+ return window.addEventListener("resize", n, { passive: !0 }), window.addEventListener("scroll", i, !0), () => {
486
+ cancelAnimationFrame(e), window.removeEventListener("resize", n), window.removeEventListener("scroll", i, !0);
487
+ };
488
+ }, [l, v]), t.useEffect(() => {
489
+ if (!l)
490
+ return;
491
+ const e = (n) => {
492
+ var c, p;
493
+ const i = n.target;
494
+ i && ((c = z.current) != null && c.contains(i)) || i && ((p = _.current) != null && p.contains(i)) || M(!1);
27
495
  };
28
- }, [s, n]), I(() => {
29
- const e = d.current;
30
- e && (i ? e.setAttribute("label", i) : e.removeAttribute("label"), o ? e.setAttribute("menu-label", o) : e.removeAttribute("menu-label"), f ? e.setAttribute("menu-heading", f) : e.removeAttribute("menu-heading"), b ? e.setAttribute("menu-description", b) : e.removeAttribute("menu-description"), r && r !== "primary" ? e.setAttribute("variant", r) : e.removeAttribute("variant"), u && u !== "default" ? e.setAttribute("density", u) : e.removeAttribute("density"), l && l !== "default" ? e.setAttribute("menu-density", l) : e.removeAttribute("menu-density"), a && a !== "default" ? e.setAttribute("menu-shape", a) : e.removeAttribute("menu-shape"), p ? e.setAttribute("disabled", "") : e.removeAttribute("disabled"));
31
- }, [i, o, f, b, r, u, l, a, p]);
32
- const w = (c == null ? void 0 : c.map(
33
- (e) => t.createElement(
496
+ return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
497
+ }, [l]), t.useEffect(() => {
498
+ l || queueMicrotask(() => {
499
+ var e, n;
500
+ try {
501
+ (e = N.current) == null || e.focus({ preventScroll: !0 });
502
+ } catch {
503
+ (n = N.current) == null || n.focus();
504
+ }
505
+ });
506
+ }, [l]), t.useEffect(() => {
507
+ if (!l || s < 0)
508
+ return;
509
+ const e = U.current[s];
510
+ !e || typeof e.scrollIntoView != "function" || e.scrollIntoView({ block: "nearest" });
511
+ }, [l, s]);
512
+ const R = t.useCallback((e) => {
513
+ const n = o[e];
514
+ !n || n.disabled || (I == null || I({
515
+ index: e,
516
+ value: n.value,
517
+ label: n.label
518
+ }), M(!1));
519
+ }, [o, I]), C = t.useCallback(() => {
520
+ x || o.length === 0 || M(!0);
521
+ }, [x, o.length]), S = t.useCallback(() => {
522
+ M(!1);
523
+ }, []), Z = t.useCallback((e) => {
524
+ (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") && (e.preventDefault(), C());
525
+ }, [C]), ee = t.useCallback((e) => {
526
+ switch (e.key) {
527
+ case "Escape":
528
+ e.preventDefault(), S();
529
+ return;
530
+ case "Tab":
531
+ S();
532
+ return;
533
+ case "ArrowDown": {
534
+ e.preventDefault();
535
+ const n = s >= 0 ? s : L(o) - 1, i = G(o, n, 1);
536
+ i >= 0 && b(i);
537
+ return;
538
+ }
539
+ case "ArrowUp": {
540
+ e.preventDefault();
541
+ const n = s >= 0 ? s : L(o) + 1, i = G(o, n, -1);
542
+ i >= 0 && b(i);
543
+ return;
544
+ }
545
+ case "Home": {
546
+ e.preventDefault();
547
+ const n = J(o, "first");
548
+ n >= 0 && b(n);
549
+ return;
550
+ }
551
+ case "End": {
552
+ e.preventDefault();
553
+ const n = J(o, "last");
554
+ n >= 0 && b(n);
555
+ return;
556
+ }
557
+ case "Enter":
558
+ case " ": {
559
+ e.preventDefault(), s >= 0 && R(s);
560
+ return;
561
+ }
562
+ default:
563
+ return;
564
+ }
565
+ }, [s, S, o, R]), te = D(
566
+ "ed-split-button",
567
+ E !== "primary" && `ed-split-button--${E}`,
568
+ F !== "default" && `ed-split-button--${F}`,
569
+ W !== "default" && `ed-split-button--${W}`,
570
+ y
571
+ ), ne = D(
572
+ "ed-split-button__menu",
573
+ E !== "primary" && `ed-split-button__menu--${E}`,
574
+ $ !== "default" && `ed-split-button__menu--${$}`,
575
+ H !== "default" && `ed-split-button__menu--${H}`
576
+ ), ie = l && typeof document < "u" ? oe(
577
+ /* @__PURE__ */ t.createElement(
578
+ "div",
579
+ {
580
+ ref: _,
581
+ className: ne,
582
+ role: "menu",
583
+ tabIndex: -1,
584
+ "aria-labelledby": m ? K : void 0,
585
+ "aria-describedby": k ? Y : void 0,
586
+ "data-placement": (a == null ? void 0 : a.placement) || "bottom",
587
+ onKeyDown: ee,
588
+ style: {
589
+ top: (a == null ? void 0 : a.top) ?? -9999,
590
+ left: (a == null ? void 0 : a.left) ?? -9999,
591
+ minWidth: a == null ? void 0 : a.minWidth,
592
+ visibility: a ? "visible" : "hidden"
593
+ }
594
+ },
595
+ m || k ? /* @__PURE__ */ t.createElement("div", { className: "ed-split-button__menuHeader" }, m ? /* @__PURE__ */ t.createElement("p", { id: K, className: "ed-split-button__menuHeading" }, m) : null, k ? /* @__PURE__ */ t.createElement("p", { id: Y, className: "ed-split-button__menuDescription" }, k) : null) : null,
596
+ /* @__PURE__ */ t.createElement("div", { className: "ed-split-button__list" }, o.map((e, n) => /* @__PURE__ */ t.createElement(
597
+ "button",
598
+ {
599
+ key: e.value,
600
+ ref: (i) => {
601
+ U.current[n] = i;
602
+ },
603
+ type: "button",
604
+ role: "menuitem",
605
+ className: D(
606
+ "ed-split-button__item",
607
+ e.tone === "danger" && "ed-split-button__item--danger"
608
+ ),
609
+ "data-active": n === s ? "true" : void 0,
610
+ "aria-disabled": e.disabled ? "true" : void 0,
611
+ disabled: e.disabled,
612
+ onPointerMove: () => {
613
+ e.disabled || b(n);
614
+ },
615
+ onFocus: () => {
616
+ e.disabled || b(n);
617
+ },
618
+ onClick: () => R(n)
619
+ },
620
+ /* @__PURE__ */ t.createElement("span", { className: "ed-split-button__itemText" }, /* @__PURE__ */ t.createElement("span", { className: "ed-split-button__itemLabel" }, e.label), e.description ? /* @__PURE__ */ t.createElement("span", { className: "ed-split-button__itemDescription" }, e.description) : null),
621
+ e.shortcut ? /* @__PURE__ */ t.createElement("span", { className: "ed-split-button__itemShortcut" }, e.shortcut) : null
622
+ )), u)
623
+ ),
624
+ document.body
625
+ ) : null;
626
+ return /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement(
627
+ "div",
628
+ {
629
+ ...Q,
630
+ ref: z,
631
+ className: te,
632
+ style: P,
633
+ "aria-disabled": x ? "true" : void 0,
634
+ "data-open": l ? "true" : void 0
635
+ },
636
+ /* @__PURE__ */ t.createElement("div", { ref: T, className: "ed-split-button__group" }, /* @__PURE__ */ t.createElement(
637
+ "button",
638
+ {
639
+ type: "button",
640
+ className: "ed-split-button__primary",
641
+ disabled: x,
642
+ onClick: () => B == null ? void 0 : B()
643
+ },
644
+ d
645
+ ), /* @__PURE__ */ t.createElement(
34
646
  "button",
35
647
  {
36
- key: e.value,
37
- slot: "menuitem",
648
+ ref: N,
38
649
  type: "button",
39
- "data-value": e.value,
40
- "data-label": e.label,
41
- "data-tone": e.tone || "default",
42
- disabled: e.disabled
650
+ className: "ed-split-button__toggle",
651
+ "aria-label": f,
652
+ "aria-haspopup": "menu",
653
+ "aria-expanded": l ? "true" : "false",
654
+ disabled: x || o.length === 0,
655
+ onClick: () => {
656
+ l ? S() : C();
657
+ },
658
+ onKeyDown: Z
43
659
  },
44
- t.createElement(
45
- "span",
46
- { "data-menu-text": "true" },
47
- t.createElement("span", { "data-menu-label": "true" }, e.label),
48
- e.description ? t.createElement("span", { "data-menu-description": "true" }, e.description) : null
49
- ),
50
- e.shortcut ? t.createElement("span", { "data-menu-shortcut": "true" }, e.shortcut) : null
51
- )
52
- )) || null;
53
- return t.createElement("ui-split-button", { ref: d, ...h }, w, E);
660
+ /* @__PURE__ */ t.createElement("svg", { className: "ed-split-button__toggleIcon", viewBox: "0 0 20 20", "aria-hidden": "true", focusable: "false" }, /* @__PURE__ */ t.createElement("path", { d: "m5 8 5 5 5-5", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }))
661
+ ))
662
+ ), ie);
54
663
  });
55
- N.displayName = "SplitButton";
664
+ ae.displayName = "SplitButton";
56
665
  export {
57
- N as SplitButton,
58
- N as default
666
+ ae as SplitButton,
667
+ ae as default
59
668
  };