@kanso-labs/kanso-ui 0.40.8 → 0.40.9

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,12 +1,14 @@
1
1
  "use client";
2
2
  import { props } from "../../node_modules/@stylexjs/stylex/lib/es/stylex.js";
3
+ import { mergeRefs } from "../../render/ref.js";
3
4
  import { mergeStatefulStyles, mergeStyles } from "../../styles/merge.js";
4
5
  import { focus } from "../../styles/focus.js";
5
6
  import { overlay, placementOf, popupOrigin } from "../../styles/overlay.js";
6
7
  import { c } from "react/compiler-runtime";
7
8
  import { createContext, useContext, useEffect, useId, useRef, useState } from "react";
8
9
  import { jsx } from "react/jsx-runtime";
9
- import { ButtonContext, DEFAULT_SLOT, Dialog, DialogContext, DialogTrigger, Heading, HeadingContext, OverlayTriggerStateContext, Popover, PreviewTrigger, Text, TextContext } from "react-aria-components";
10
+ import { ButtonContext, DEFAULT_SLOT, Dialog, DialogContext, DialogTrigger, Heading, HeadingContext, OverlayTriggerStateContext, Popover, PopoverContext, PreviewTrigger, Text, TextContext, useSlottedContext } from "react-aria-components";
11
+ import { useInteractOutside } from "react-aria";
10
12
  //#region src/components/popover/index.tsx
11
13
  const DEFAULT_SIDE_OFFSET = 8;
12
14
  const styles = {
@@ -49,7 +51,7 @@ const styles = {
49
51
  };
50
52
  const DEFAULT_HOVER_DELAY = 600;
51
53
  const DEFAULT_HOVER_CLOSE_DELAY = 200;
52
- const PopoverContext = createContext({
54
+ const PopoverContext$1 = createContext({
53
55
  modal: false,
54
56
  size: "md"
55
57
  });
@@ -80,63 +82,67 @@ const TEXT_SLOTS = { slots: {
80
82
  * focus handling of its own.
81
83
  */
82
84
  function PanelDialog(t0) {
83
- const $ = c(35);
85
+ const $ = c(37);
84
86
  let children;
85
87
  let id;
86
88
  let labelledBy;
89
+ let onPressWithin;
87
90
  let props$2;
88
91
  let slot;
89
92
  if ($[0] !== t0) {
90
- const { "aria-labelledby": t1, children: t2, id: t3, render: _render, slot: t4, ...t5 } = t0;
93
+ const { "aria-labelledby": t1, children: t2, id: t3, onPressWithin: t4, render: _render, slot: t5, ...t6 } = t0;
91
94
  labelledBy = t1;
92
95
  children = t2;
93
96
  id = t3;
94
- slot = t4;
95
- props$2 = t5;
97
+ onPressWithin = t4;
98
+ slot = t5;
99
+ props$2 = t6;
96
100
  $[0] = t0;
97
101
  $[1] = children;
98
102
  $[2] = id;
99
103
  $[3] = labelledBy;
100
- $[4] = props$2;
101
- $[5] = slot;
104
+ $[4] = onPressWithin;
105
+ $[5] = props$2;
106
+ $[6] = slot;
102
107
  } else {
103
108
  children = $[1];
104
109
  id = $[2];
105
110
  labelledBy = $[3];
106
- props$2 = $[4];
107
- slot = $[5];
111
+ onPressWithin = $[4];
112
+ props$2 = $[5];
113
+ slot = $[6];
108
114
  }
109
115
  const ref = useRef(null);
110
116
  const state = useContext(OverlayTriggerStateContext);
111
117
  const t1 = useContext(DialogContext);
112
118
  let t2;
113
- if ($[6] !== t1) {
119
+ if ($[7] !== t1) {
114
120
  t2 = triggerOf(t1);
115
- $[6] = t1;
116
- $[7] = t2;
117
- } else t2 = $[7];
121
+ $[7] = t1;
122
+ $[8] = t2;
123
+ } else t2 = $[8];
118
124
  const trigger = t2;
119
125
  const pressed = trigger !== void 0;
120
126
  const titleId = useId();
121
127
  const [titled, setTitled] = useState(false);
122
128
  let t3;
123
- if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
129
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
124
130
  t3 = () => {
125
131
  setTitled(true);
126
132
  return () => {
127
133
  setTitled(false);
128
134
  };
129
135
  };
130
- $[8] = t3;
131
- } else t3 = $[8];
136
+ $[9] = t3;
137
+ } else t3 = $[9];
132
138
  const registerTitle = t3;
133
139
  let t4;
134
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
140
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
135
141
  t4 = {};
136
- $[9] = t4;
137
- } else t4 = $[9];
142
+ $[10] = t4;
143
+ } else t4 = $[10];
138
144
  let t5;
139
- if ($[10] !== titleId) {
145
+ if ($[11] !== titleId) {
140
146
  t5 = { slots: {
141
147
  [DEFAULT_SLOT]: t4,
142
148
  title: {
@@ -144,68 +150,68 @@ function PanelDialog(t0) {
144
150
  level: 2
145
151
  }
146
152
  } };
147
- $[10] = titleId;
148
- $[11] = t5;
149
- } else t5 = $[11];
153
+ $[11] = titleId;
154
+ $[12] = t5;
155
+ } else t5 = $[12];
150
156
  const headings = t5;
151
157
  let t6;
152
- if ($[12] !== state) {
158
+ if ($[13] !== state) {
153
159
  t6 = { onPress: () => {
154
160
  state?.close();
155
161
  } };
156
- $[12] = state;
157
- $[13] = t6;
158
- } else t6 = $[13];
162
+ $[13] = state;
163
+ $[14] = t6;
164
+ } else t6 = $[14];
159
165
  let t7;
160
- if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
166
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
161
167
  t7 = {};
162
- $[14] = t7;
163
- } else t7 = $[14];
168
+ $[15] = t7;
169
+ } else t7 = $[15];
164
170
  let t8;
165
- if ($[15] !== t6) {
171
+ if ($[16] !== t6) {
166
172
  t8 = { slots: {
167
173
  close: t6,
168
174
  [DEFAULT_SLOT]: t7
169
175
  } };
170
- $[15] = t6;
171
- $[16] = t8;
172
- } else t8 = $[16];
176
+ $[16] = t6;
177
+ $[17] = t8;
178
+ } else t8 = $[17];
173
179
  const buttons = t8;
174
180
  let t10;
175
181
  let t9;
176
- if ($[17] !== pressed) {
182
+ if ($[18] !== pressed) {
177
183
  t9 = () => {
178
184
  const element = ref.current;
179
185
  if (pressed && element !== null && !element.contains(document.activeElement)) element.focus({ preventScroll: true });
180
186
  };
181
187
  t10 = [pressed];
182
- $[17] = pressed;
183
- $[18] = t10;
184
- $[19] = t9;
188
+ $[18] = pressed;
189
+ $[19] = t10;
190
+ $[20] = t9;
185
191
  } else {
186
- t10 = $[18];
187
- t9 = $[19];
192
+ t10 = $[19];
193
+ t9 = $[20];
188
194
  }
189
195
  useEffect(t9, t10);
190
196
  const t11 = labelledBy ?? (titled ? titleId : trigger?.labelledBy);
191
197
  const t12 = id ?? trigger?.id;
192
198
  const t13 = slot ?? void 0;
193
199
  let t14;
194
- if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
200
+ if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
195
201
  t14 = props(overlay.popupDialog, focus.ring);
196
- $[20] = t14;
197
- } else t14 = $[20];
202
+ $[21] = t14;
203
+ } else t14 = $[21];
198
204
  let t15;
199
- if ($[21] !== children) {
205
+ if ($[22] !== children) {
200
206
  t15 = /* @__PURE__ */ jsx(TitleContext, {
201
207
  value: registerTitle,
202
208
  children
203
209
  });
204
- $[21] = children;
205
- $[22] = t15;
206
- } else t15 = $[22];
210
+ $[22] = children;
211
+ $[23] = t15;
212
+ } else t15 = $[23];
207
213
  let t16;
208
- if ($[23] !== buttons || $[24] !== t15) {
214
+ if ($[24] !== buttons || $[25] !== t15) {
209
215
  t16 = /* @__PURE__ */ jsx(TextContext, {
210
216
  value: TEXT_SLOTS,
211
217
  children: /* @__PURE__ */ jsx(ButtonContext, {
@@ -213,26 +219,27 @@ function PanelDialog(t0) {
213
219
  children: t15
214
220
  })
215
221
  });
216
- $[23] = buttons;
217
- $[24] = t15;
218
- $[25] = t16;
219
- } else t16 = $[25];
222
+ $[24] = buttons;
223
+ $[25] = t15;
224
+ $[26] = t16;
225
+ } else t16 = $[26];
220
226
  let t17;
221
- if ($[26] !== headings || $[27] !== t16) {
227
+ if ($[27] !== headings || $[28] !== t16) {
222
228
  t17 = /* @__PURE__ */ jsx(HeadingContext, {
223
229
  value: headings,
224
230
  children: t16
225
231
  });
226
- $[26] = headings;
227
- $[27] = t16;
228
- $[28] = t17;
229
- } else t17 = $[28];
232
+ $[27] = headings;
233
+ $[28] = t16;
234
+ $[29] = t17;
235
+ } else t17 = $[29];
230
236
  let t18;
231
- if ($[29] !== props$2 || $[30] !== t11 || $[31] !== t12 || $[32] !== t13 || $[33] !== t17) {
237
+ if ($[30] !== onPressWithin || $[31] !== props$2 || $[32] !== t11 || $[33] !== t12 || $[34] !== t13 || $[35] !== t17) {
232
238
  t18 = /* @__PURE__ */ jsx("section", {
233
239
  ...props$2,
234
240
  "aria-labelledby": t11,
235
241
  id: t12,
242
+ onPointerDownCapture: onPressWithin,
236
243
  ref,
237
244
  role: "dialog",
238
245
  slot: t13,
@@ -240,13 +247,14 @@ function PanelDialog(t0) {
240
247
  ...t14,
241
248
  children: t17
242
249
  });
243
- $[29] = props$2;
244
- $[30] = t11;
245
- $[31] = t12;
246
- $[32] = t13;
247
- $[33] = t17;
248
- $[34] = t18;
249
- } else t18 = $[34];
250
+ $[30] = onPressWithin;
251
+ $[31] = props$2;
252
+ $[32] = t11;
253
+ $[33] = t12;
254
+ $[34] = t13;
255
+ $[35] = t17;
256
+ $[36] = t18;
257
+ } else t18 = $[36];
250
258
  return t18;
251
259
  }
252
260
  /**
@@ -255,7 +263,10 @@ function PanelDialog(t0) {
255
263
  * keep its own.
256
264
  *
257
265
  * Non-modal by design — the page behind stays scrollable and clickable, which
258
- * is the difference from `Sheet`. Pass `modal` to change that.
266
+ * is the difference from `Sheet`. Pass `modal` to change that. Escape, a press
267
+ * anywhere outside the panel and a button given `slot="close"` close it, and
268
+ * a press on its trigger toggles it. Inside a dialog, a press on the scrim
269
+ * closes the popover first and the dialog on the next, as a menu does.
259
270
  *
260
271
  * Composed rather than configured by props, because a popover's contents are
261
272
  * arbitrary — the parts are `Popover.Content`, `Popover.Title`, and
@@ -325,7 +336,7 @@ function Popover$1(t0) {
325
336
  } else t8 = $[15];
326
337
  let t9;
327
338
  if ($[16] !== context || $[17] !== t8) {
328
- t9 = /* @__PURE__ */ jsx(PopoverContext, {
339
+ t9 = /* @__PURE__ */ jsx(PopoverContext$1, {
329
340
  value: context,
330
341
  children: t8
331
342
  });
@@ -347,7 +358,7 @@ function Popover$1(t0) {
347
358
  } else t8 = $[21];
348
359
  let t9;
349
360
  if ($[22] !== context || $[23] !== t8) {
350
- t9 = /* @__PURE__ */ jsx(PopoverContext, {
361
+ t9 = /* @__PURE__ */ jsx(PopoverContext$1, {
351
362
  value: context,
352
363
  children: t8
353
364
  });
@@ -367,7 +378,7 @@ function Popover$1(t0) {
367
378
  * than being clipped by it.
368
379
  */
369
380
  function PopoverContent(t0) {
370
- const $ = c(41);
381
+ const $ = c(58);
371
382
  let alignOffset;
372
383
  let children;
373
384
  let className;
@@ -409,58 +420,146 @@ function PopoverContent(t0) {
409
420
  const align = t1 === void 0 ? "center" : t1;
410
421
  const side = t2 === void 0 ? "bottom" : t2;
411
422
  const sideOffset = t3 === void 0 ? DEFAULT_SIDE_OFFSET : t3;
412
- const { modal, size } = useContext(PopoverContext);
423
+ const { modal, size } = useContext(PopoverContext$1);
424
+ const state = useContext(OverlayTriggerStateContext);
425
+ const handed = useSlottedContext(PopoverContext)?.triggerRef;
426
+ const panel = useRef(null);
427
+ const t4 = ref ?? void 0;
428
+ let t5;
429
+ if ($[12] !== t4) {
430
+ t5 = mergeRefs(panel, t4);
431
+ $[12] = t4;
432
+ $[13] = t5;
433
+ } else t5 = $[13];
434
+ const merged = t5;
435
+ const pressedWithin = useRef(false);
436
+ let t6;
437
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
438
+ t6 = () => {
439
+ pressedWithin.current = true;
440
+ };
441
+ $[14] = t6;
442
+ } else t6 = $[14];
443
+ const markPressWithin = t6;
444
+ let t7;
445
+ if ($[15] !== handed || $[16] !== triggerRef) {
446
+ t7 = {
447
+ handed,
448
+ own: triggerRef
449
+ };
450
+ $[15] = handed;
451
+ $[16] = triggerRef;
452
+ $[17] = t7;
453
+ } else t7 = $[17];
454
+ const triggers = useRef(t7);
455
+ let t8;
456
+ if ($[18] !== handed || $[19] !== triggerRef) {
457
+ t8 = () => {
458
+ triggers.current = {
459
+ handed,
460
+ own: triggerRef
461
+ };
462
+ };
463
+ $[18] = handed;
464
+ $[19] = triggerRef;
465
+ $[20] = t8;
466
+ } else t8 = $[20];
467
+ useEffect(t8);
468
+ let t9;
469
+ if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
470
+ t9 = (element) => {
471
+ const { handed: fromTrigger, own } = triggers.current;
472
+ return !((own?.current ?? fromTrigger?.current)?.contains(element) ?? false);
473
+ };
474
+ $[21] = t9;
475
+ } else t9 = $[21];
476
+ const isOutsideTrigger = t9;
477
+ const t10 = modal || state === null || !state.isOpen;
478
+ let t11;
479
+ if ($[22] !== state) {
480
+ t11 = (event) => {
481
+ if (pressedWithin.current) {
482
+ pressedWithin.current = false;
483
+ return;
484
+ }
485
+ if (event.target instanceof Element && !isOutsideTrigger(event.target)) return;
486
+ state?.close();
487
+ };
488
+ $[22] = state;
489
+ $[23] = t11;
490
+ } else t11 = $[23];
491
+ let t12;
492
+ if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
493
+ t12 = () => {
494
+ pressedWithin.current = false;
495
+ };
496
+ $[24] = t12;
497
+ } else t12 = $[24];
498
+ let t13;
499
+ if ($[25] !== t10 || $[26] !== t11) {
500
+ t13 = {
501
+ isDisabled: t10,
502
+ onInteractOutside: t11,
503
+ onInteractOutsideStart: t12,
504
+ ref: panel
505
+ };
506
+ $[25] = t10;
507
+ $[26] = t11;
508
+ $[27] = t13;
509
+ } else t13 = $[27];
510
+ useInteractOutside(t13);
413
511
  const descriptionId = useId();
414
512
  const [described, setDescribed] = useState(false);
415
- let t4;
416
- if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
417
- t4 = () => {
513
+ let t14;
514
+ if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
515
+ t14 = () => {
418
516
  setDescribed(true);
419
517
  return () => {
420
518
  setDescribed(false);
421
519
  };
422
520
  };
423
- $[12] = t4;
424
- } else t4 = $[12];
425
- const register = t4;
426
- let t5;
427
- if ($[13] !== descriptionId) {
428
- t5 = {
521
+ $[28] = t14;
522
+ } else t14 = $[28];
523
+ const register = t14;
524
+ let t15;
525
+ if ($[29] !== descriptionId) {
526
+ t15 = {
429
527
  id: descriptionId,
430
528
  register
431
529
  };
432
- $[13] = descriptionId;
433
- $[14] = t5;
434
- } else t5 = $[14];
435
- const description = t5;
436
- const t6 = !modal;
437
- let t7;
438
- if ($[15] !== align || $[16] !== side) {
439
- t7 = placementOf(side, align);
440
- $[15] = align;
441
- $[16] = side;
442
- $[17] = t7;
443
- } else t7 = $[17];
444
- let t8;
445
- if ($[18] !== size) {
446
- t8 = (state) => props(overlay.popup, styles.content, styles[size], popupOrigin(state.placement));
447
- $[18] = size;
448
- $[19] = t8;
449
- } else t8 = $[19];
450
- let t9;
451
- if ($[20] !== className || $[21] !== style || $[22] !== t8) {
452
- t9 = mergeStatefulStyles(t8, {
530
+ $[29] = descriptionId;
531
+ $[30] = t15;
532
+ } else t15 = $[30];
533
+ const description = t15;
534
+ const t16 = !modal;
535
+ let t17;
536
+ if ($[31] !== align || $[32] !== side) {
537
+ t17 = placementOf(side, align);
538
+ $[31] = align;
539
+ $[32] = side;
540
+ $[33] = t17;
541
+ } else t17 = $[33];
542
+ const t18 = modal ? void 0 : isOutsideTrigger;
543
+ let t19;
544
+ if ($[34] !== size) {
545
+ t19 = (render) => props(overlay.popup, styles.content, styles[size], popupOrigin(render.placement));
546
+ $[34] = size;
547
+ $[35] = t19;
548
+ } else t19 = $[35];
549
+ let t20;
550
+ if ($[36] !== className || $[37] !== style || $[38] !== t19) {
551
+ t20 = mergeStatefulStyles(t19, {
453
552
  className,
454
553
  style
455
554
  });
456
- $[20] = className;
457
- $[21] = style;
458
- $[22] = t8;
459
- $[23] = t9;
460
- } else t9 = $[23];
461
- let t10;
462
- if ($[24] !== children || $[25] !== described || $[26] !== description || $[27] !== descriptionId || $[28] !== modal || $[29] !== props$1) {
463
- t10 = modal ? /* @__PURE__ */ jsx(Dialog, {
555
+ $[36] = className;
556
+ $[37] = style;
557
+ $[38] = t19;
558
+ $[39] = t20;
559
+ } else t20 = $[39];
560
+ let t21;
561
+ if ($[40] !== children || $[41] !== described || $[42] !== description || $[43] !== descriptionId || $[44] !== modal || $[45] !== props$1) {
562
+ t21 = modal ? /* @__PURE__ */ jsx(Dialog, {
464
563
  "aria-describedby": described ? descriptionId : void 0,
465
564
  ...props$1,
466
565
  ...props(overlay.popupDialog, focus.ring),
@@ -470,45 +569,48 @@ function PopoverContent(t0) {
470
569
  })
471
570
  }) : /* @__PURE__ */ jsx(PanelDialog, {
472
571
  "aria-describedby": described ? descriptionId : void 0,
572
+ onPressWithin: markPressWithin,
473
573
  ...props$1,
474
574
  children: /* @__PURE__ */ jsx(DescriptionContext, {
475
575
  value: description,
476
576
  children
477
577
  })
478
578
  });
479
- $[24] = children;
480
- $[25] = described;
481
- $[26] = description;
482
- $[27] = descriptionId;
483
- $[28] = modal;
484
- $[29] = props$1;
485
- $[30] = t10;
486
- } else t10 = $[30];
487
- let t11;
488
- if ($[31] !== alignOffset || $[32] !== container || $[33] !== ref || $[34] !== sideOffset || $[35] !== t10 || $[36] !== t6 || $[37] !== t7 || $[38] !== t9 || $[39] !== triggerRef) {
489
- t11 = /* @__PURE__ */ jsx(Popover, {
579
+ $[40] = children;
580
+ $[41] = described;
581
+ $[42] = description;
582
+ $[43] = descriptionId;
583
+ $[44] = modal;
584
+ $[45] = props$1;
585
+ $[46] = t21;
586
+ } else t21 = $[46];
587
+ let t22;
588
+ if ($[47] !== alignOffset || $[48] !== container || $[49] !== merged || $[50] !== sideOffset || $[51] !== t16 || $[52] !== t17 || $[53] !== t18 || $[54] !== t20 || $[55] !== t21 || $[56] !== triggerRef) {
589
+ t22 = /* @__PURE__ */ jsx(Popover, {
490
590
  crossOffset: alignOffset,
491
- isNonModal: t6,
591
+ isNonModal: t16,
492
592
  offset: sideOffset,
493
- placement: t7,
494
- ref,
593
+ placement: t17,
594
+ ref: merged,
595
+ shouldCloseOnInteractOutside: t18,
495
596
  triggerRef,
496
597
  UNSTABLE_portalContainer: container,
497
- ...t9,
498
- children: t10
598
+ ...t20,
599
+ children: t21
499
600
  });
500
- $[31] = alignOffset;
501
- $[32] = container;
502
- $[33] = ref;
503
- $[34] = sideOffset;
504
- $[35] = t10;
505
- $[36] = t6;
506
- $[37] = t7;
507
- $[38] = t9;
508
- $[39] = triggerRef;
509
- $[40] = t11;
510
- } else t11 = $[40];
511
- return t11;
601
+ $[47] = alignOffset;
602
+ $[48] = container;
603
+ $[49] = merged;
604
+ $[50] = sideOffset;
605
+ $[51] = t16;
606
+ $[52] = t17;
607
+ $[53] = t18;
608
+ $[54] = t20;
609
+ $[55] = t21;
610
+ $[56] = triggerRef;
611
+ $[57] = t22;
612
+ } else t22 = $[57];
613
+ return t22;
512
614
  }
513
615
  /**
514
616
  * Supporting copy under the title. The panel's `aria-describedby` points at