@flopay/ui 1.12.0 → 1.13.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.
package/dist/index.mjs CHANGED
@@ -366,50 +366,162 @@ function CodeArea({
366
366
  ) });
367
367
  }
368
368
 
369
+ // src/components/confirm-dialog.tsx
370
+ import { useEffect, useId as useId3, useRef as useRef2 } from "react";
371
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
372
+ var FOCUSABLE = [
373
+ "a[href]",
374
+ "button:not([disabled])",
375
+ "input:not([disabled])",
376
+ "select:not([disabled])",
377
+ "textarea:not([disabled])",
378
+ '[tabindex]:not([tabindex="-1"])'
379
+ ].join(", ");
380
+ function nextFocusTarget(panel, backwards) {
381
+ const focusable = Array.from(panel.querySelectorAll(FOCUSABLE));
382
+ const last = focusable.length - 1;
383
+ if (last < 0) return panel;
384
+ const index = focusable.indexOf(document.activeElement);
385
+ if (backwards) return focusable[index <= 0 ? last : index - 1] ?? panel;
386
+ return focusable[index >= last ? 0 : index + 1] ?? panel;
387
+ }
388
+ function OpenConfirmDialog({
389
+ title,
390
+ description,
391
+ confirmLabel,
392
+ cancelLabel,
393
+ onConfirm,
394
+ onCancel,
395
+ confirming = false
396
+ }) {
397
+ const id = useId3();
398
+ const titleId = `${id}-title`;
399
+ const descriptionId = `${id}-description`;
400
+ const cancelId = `${id}-cancel`;
401
+ const panelRef = useRef2(null);
402
+ useEffect(() => {
403
+ const opener = document.activeElement;
404
+ return () => {
405
+ if (opener instanceof HTMLElement && opener.isConnected) opener.focus();
406
+ };
407
+ }, []);
408
+ useEffect(() => {
409
+ const panel = panelRef.current;
410
+ if (!panel) return;
411
+ const active = document.activeElement;
412
+ if (confirming) {
413
+ if (!panel.contains(active) || active instanceof HTMLButtonElement) panel.focus();
414
+ } else if (!panel.contains(active) || active === panel) {
415
+ document.getElementById(cancelId)?.focus();
416
+ }
417
+ }, [confirming, cancelId]);
418
+ useEffect(() => {
419
+ function onKeyDown(event) {
420
+ const panel = panelRef.current;
421
+ if (!panel) return;
422
+ if (event.key === "Escape") {
423
+ if (!confirming) onCancel();
424
+ } else if (event.key === "Tab") {
425
+ event.preventDefault();
426
+ nextFocusTarget(panel, event.shiftKey).focus();
427
+ }
428
+ }
429
+ document.addEventListener("keydown", onKeyDown);
430
+ return () => document.removeEventListener("keydown", onKeyDown);
431
+ }, [confirming, onCancel]);
432
+ const pressStartedOnBackdrop = useRef2(false);
433
+ const onBackdropMouseDown = (event) => {
434
+ pressStartedOnBackdrop.current = event.target === event.currentTarget;
435
+ if (pressStartedOnBackdrop.current) event.preventDefault();
436
+ };
437
+ const onBackdropClick = (event) => {
438
+ const startedOnBackdrop = pressStartedOnBackdrop.current;
439
+ pressStartedOnBackdrop.current = false;
440
+ if (startedOnBackdrop && event.target === event.currentTarget && !confirming) onCancel();
441
+ };
442
+ return (
443
+ // biome-ignore lint/a11y/noNoninteractiveElementInteractions: the backdrop click is only a pointer shortcut for Cancel; keyboard and screen-reader users have the Cancel button and Escape, so the backdrop needs no role or focus of its own
444
+ // biome-ignore lint/a11y/noStaticElementInteractions: as above, the backdrop is a pointer-only shortcut for Cancel and must not be announced as a control
445
+ // biome-ignore lint/a11y/useKeyWithClickEvents: the keyboard equivalent of a backdrop click is Escape, handled by the document listener while open
446
+ /* @__PURE__ */ jsx9(
447
+ "div",
448
+ {
449
+ className: "confirm-dialog-backdrop",
450
+ onMouseDown: onBackdropMouseDown,
451
+ onClick: onBackdropClick,
452
+ children: /* @__PURE__ */ jsxs5(
453
+ "div",
454
+ {
455
+ ref: panelRef,
456
+ role: "alertdialog",
457
+ "aria-modal": "true",
458
+ "aria-labelledby": titleId,
459
+ "aria-describedby": descriptionId,
460
+ tabIndex: -1,
461
+ className: "confirm-dialog",
462
+ children: [
463
+ /* @__PURE__ */ jsx9("h2", { id: titleId, className: "confirm-dialog-title", children: title }),
464
+ /* @__PURE__ */ jsx9("div", { id: descriptionId, className: "confirm-dialog-description", children: description }),
465
+ /* @__PURE__ */ jsxs5("div", { className: "confirm-dialog-actions", children: [
466
+ /* @__PURE__ */ jsx9(Button, { id: cancelId, variant: "outline", disabled: confirming, onClick: onCancel, children: cancelLabel }),
467
+ /* @__PURE__ */ jsx9(Button, { variant: "primary", disabled: confirming, onClick: onConfirm, children: confirmLabel })
468
+ ] })
469
+ ]
470
+ }
471
+ )
472
+ }
473
+ )
474
+ );
475
+ }
476
+ function ConfirmDialog({ open, ...props }) {
477
+ if (!open) return null;
478
+ return /* @__PURE__ */ jsx9(OpenConfirmDialog, { ...props });
479
+ }
480
+
369
481
  // src/components/container.tsx
370
- import { jsx as jsx9 } from "react/jsx-runtime";
482
+ import { jsx as jsx10 } from "react/jsx-runtime";
371
483
  function Container({ className, ...props }) {
372
- return /* @__PURE__ */ jsx9("div", { className: cn("container", className), ...props });
484
+ return /* @__PURE__ */ jsx10("div", { className: cn("container", className), ...props });
373
485
  }
374
486
 
375
487
  // src/components/feedback.tsx
376
- import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
488
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
377
489
  function Spinner({ center = false, className, ...props }) {
378
- const spinner = /* @__PURE__ */ jsx10("span", { className: cn("spinner", className), role: "status", "aria-label": "Loading", ...props });
379
- return center ? /* @__PURE__ */ jsx10("div", { className: "spinner-center", children: spinner }) : spinner;
490
+ const spinner = /* @__PURE__ */ jsx11("span", { className: cn("spinner", className), role: "status", "aria-label": "Loading", ...props });
491
+ return center ? /* @__PURE__ */ jsx11("div", { className: "spinner-center", children: spinner }) : spinner;
380
492
  }
381
493
  function EmptyState({ title, description, icon, className }) {
382
- return /* @__PURE__ */ jsxs5("div", { className: cn("empty-state", className), children: [
383
- icon ? /* @__PURE__ */ jsx10("div", { className: "empty-state-icon", children: icon }) : null,
384
- /* @__PURE__ */ jsx10("h3", { className: "empty-state-title", children: title }),
385
- description ? /* @__PURE__ */ jsx10("p", { className: "empty-state-desc", children: description }) : null
494
+ return /* @__PURE__ */ jsxs6("div", { className: cn("empty-state", className), children: [
495
+ icon ? /* @__PURE__ */ jsx11("div", { className: "empty-state-icon", children: icon }) : null,
496
+ /* @__PURE__ */ jsx11("h3", { className: "empty-state-title", children: title }),
497
+ description ? /* @__PURE__ */ jsx11("p", { className: "empty-state-desc", children: description }) : null
386
498
  ] });
387
499
  }
388
500
 
389
501
  // src/components/preview-frame.tsx
390
- import { jsx as jsx11 } from "react/jsx-runtime";
502
+ import { jsx as jsx12 } from "react/jsx-runtime";
391
503
  function PreviewFrame({ html, title, className }) {
392
- return /* @__PURE__ */ jsx11("div", { className: cn("preview-frame", className), children: /* @__PURE__ */ jsx11("iframe", { className: "preview-frame-iframe", title, srcDoc: html, sandbox: "" }) });
504
+ return /* @__PURE__ */ jsx12("div", { className: cn("preview-frame", className), children: /* @__PURE__ */ jsx12("iframe", { className: "preview-frame-iframe", title, srcDoc: html, sandbox: "" }) });
393
505
  }
394
506
 
395
507
  // src/components/section.tsx
396
- import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
508
+ import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
397
509
  function Section({ className, ...props }) {
398
- return /* @__PURE__ */ jsx12("section", { className: cn("section", className), ...props });
510
+ return /* @__PURE__ */ jsx13("section", { className: cn("section", className), ...props });
399
511
  }
400
512
  function SectionHeader({ label, title, description, className }) {
401
- return /* @__PURE__ */ jsxs6("div", { className: cn("section-center", className), children: [
402
- label ? /* @__PURE__ */ jsx12("div", { className: "section-label", children: label }) : null,
403
- /* @__PURE__ */ jsx12("h2", { className: "section-title", children: title }),
404
- description ? /* @__PURE__ */ jsx12("p", { className: "section-desc", children: description }) : null
513
+ return /* @__PURE__ */ jsxs7("div", { className: cn("section-center", className), children: [
514
+ label ? /* @__PURE__ */ jsx13("div", { className: "section-label", children: label }) : null,
515
+ /* @__PURE__ */ jsx13("h2", { className: "section-title", children: title }),
516
+ description ? /* @__PURE__ */ jsx13("p", { className: "section-desc", children: description }) : null
405
517
  ] });
406
518
  }
407
519
 
408
520
  // src/components/slot-text-field.tsx
409
521
  import {
410
522
  useCallback,
411
- useId as useId3,
412
- useRef as useRef2
523
+ useId as useId4,
524
+ useRef as useRef3
413
525
  } from "react";
414
526
 
415
527
  // src/components/text-selection.ts
@@ -448,7 +560,7 @@ function assignRef(ref, node) {
448
560
  }
449
561
 
450
562
  // src/components/slot-text-field.tsx
451
- import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
563
+ import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
452
564
  var LINK_PLACEHOLDER = "https://";
453
565
  function wrapWith(marker) {
454
566
  return (selected) => ({
@@ -481,9 +593,9 @@ function SlotTextField({
481
593
  name,
482
594
  className
483
595
  }) {
484
- const generatedId = useId3();
596
+ const generatedId = useId4();
485
597
  const controlId = id ?? generatedId;
486
- const control = useRef2(null);
598
+ const control = useRef3(null);
487
599
  const setControl = useCallback(
488
600
  (node) => {
489
601
  control.current = node;
@@ -501,7 +613,7 @@ function SlotTextField({
501
613
  className: multiline ? "field field-multiline" : "field",
502
614
  "aria-invalid": error ? true : void 0
503
615
  };
504
- return /* @__PURE__ */ jsxs7(
616
+ return /* @__PURE__ */ jsxs8(
505
617
  Field,
506
618
  {
507
619
  label,
@@ -510,7 +622,7 @@ function SlotTextField({
510
622
  htmlFor: controlId,
511
623
  className,
512
624
  children: [
513
- /* @__PURE__ */ jsx13("div", { className: "slot-toolbar", children: FORMATS.map((format) => /* @__PURE__ */ jsx13(
625
+ /* @__PURE__ */ jsx14("div", { className: "slot-toolbar", children: FORMATS.map((format) => /* @__PURE__ */ jsx14(
514
626
  "button",
515
627
  {
516
628
  type: "button",
@@ -522,14 +634,14 @@ function SlotTextField({
522
634
  },
523
635
  format.name
524
636
  )) }),
525
- multiline ? /* @__PURE__ */ jsx13("textarea", { ref: setControl, rows: 4, ...shared }) : /* @__PURE__ */ jsx13("input", { ref: setControl, type: "text", ...shared })
637
+ multiline ? /* @__PURE__ */ jsx14("textarea", { ref: setControl, rows: 4, ...shared }) : /* @__PURE__ */ jsx14("input", { ref: setControl, type: "text", ...shared })
526
638
  ]
527
639
  }
528
640
  );
529
641
  }
530
642
 
531
643
  // src/components/step-indicator.tsx
532
- import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
644
+ import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
533
645
  var defaultStatusLabels = {
534
646
  done: "Done",
535
647
  current: "Current",
@@ -541,21 +653,21 @@ var markerClass = {
541
653
  upcoming: ""
542
654
  };
543
655
  function StepIndicator({ steps, statusLabels, className }) {
544
- return /* @__PURE__ */ jsx14("ol", { className: cn("step-indicator", className), children: steps.map((step, index) => /* @__PURE__ */ jsxs8(
656
+ return /* @__PURE__ */ jsx15("ol", { className: cn("step-indicator", className), children: steps.map((step, index) => /* @__PURE__ */ jsxs9(
545
657
  "li",
546
658
  {
547
659
  className: "step-indicator-step",
548
660
  "aria-current": step.status === "current" ? "step" : void 0,
549
661
  children: [
550
- /* @__PURE__ */ jsx14(
662
+ /* @__PURE__ */ jsx15(
551
663
  "span",
552
664
  {
553
665
  className: cn("step-indicator-marker", markerClass[step.status]),
554
666
  "aria-hidden": "true",
555
- children: step.status === "done" ? /* @__PURE__ */ jsx14(CheckIcon, { className: "step-indicator-icon" }) : index + 1
667
+ children: step.status === "done" ? /* @__PURE__ */ jsx15(CheckIcon, { className: "step-indicator-icon" }) : index + 1
556
668
  }
557
669
  ),
558
- /* @__PURE__ */ jsx14(
670
+ /* @__PURE__ */ jsx15(
559
671
  "span",
560
672
  {
561
673
  className: cn(
@@ -565,7 +677,7 @@ function StepIndicator({ steps, statusLabels, className }) {
565
677
  children: step.label
566
678
  }
567
679
  ),
568
- /* @__PURE__ */ jsx14("span", { className: "visually-hidden", children: statusLabels?.[step.status] ?? defaultStatusLabels[step.status] })
680
+ /* @__PURE__ */ jsx15("span", { className: "visually-hidden", children: statusLabels?.[step.status] ?? defaultStatusLabels[step.status] })
569
681
  ]
570
682
  },
571
683
  index
@@ -573,8 +685,8 @@ function StepIndicator({ steps, statusLabels, className }) {
573
685
  }
574
686
 
575
687
  // src/components/switch.tsx
576
- import { useId as useId4, useState } from "react";
577
- import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
688
+ import { useId as useId5, useState } from "react";
689
+ import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
578
690
  function ignorePress(event) {
579
691
  event.preventDefault();
580
692
  }
@@ -590,7 +702,7 @@ function Switch({
590
702
  name,
591
703
  className
592
704
  }) {
593
- const generatedId = useId4();
705
+ const generatedId = useId5();
594
706
  const controlId = id ?? generatedId;
595
707
  const labelId = `${controlId}-label`;
596
708
  const [ownChecked, setOwnChecked] = useState(defaultChecked);
@@ -601,8 +713,8 @@ function Switch({
601
713
  if (checked === void 0) setOwnChecked(next);
602
714
  onCheckedChange?.(next);
603
715
  };
604
- return /* @__PURE__ */ jsxs9("span", { className: cn("switch", className), children: [
605
- /* @__PURE__ */ jsx15(
716
+ return /* @__PURE__ */ jsxs10("span", { className: cn("switch", className), children: [
717
+ /* @__PURE__ */ jsx16(
606
718
  "button",
607
719
  {
608
720
  type: "button",
@@ -616,10 +728,10 @@ function Switch({
616
728
  disabled,
617
729
  onMouseDown: loading ? ignorePress : void 0,
618
730
  onClick: toggle,
619
- children: /* @__PURE__ */ jsx15("span", { className: "switch-thumb", "aria-hidden": "true" })
731
+ children: /* @__PURE__ */ jsx16("span", { className: "switch-thumb", "aria-hidden": "true" })
620
732
  }
621
733
  ),
622
- /* @__PURE__ */ jsx15(
734
+ /* @__PURE__ */ jsx16(
623
735
  "label",
624
736
  {
625
737
  id: labelId,
@@ -628,19 +740,19 @@ function Switch({
628
740
  children: label
629
741
  }
630
742
  ),
631
- loading ? /* @__PURE__ */ jsx15(Spinner, { className: "switch-spinner" }) : null,
632
- name && isChecked && !disabled ? /* @__PURE__ */ jsx15("input", { type: "hidden", name, value: "on" }) : null
743
+ loading ? /* @__PURE__ */ jsx16(Spinner, { className: "switch-spinner" }) : null,
744
+ name && isChecked && !disabled ? /* @__PURE__ */ jsx16("input", { type: "hidden", name, value: "on" }) : null
633
745
  ] });
634
746
  }
635
747
 
636
748
  // src/components/variable-picker.tsx
637
749
  import {
638
- useEffect,
639
- useId as useId5,
640
- useRef as useRef3,
750
+ useEffect as useEffect2,
751
+ useId as useId6,
752
+ useRef as useRef4,
641
753
  useState as useState2
642
754
  } from "react";
643
- import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
755
+ import { jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
644
756
  function liquidToken(name) {
645
757
  return `{{ ${name} }}`;
646
758
  }
@@ -648,17 +760,17 @@ function keepFocus(event) {
648
760
  event.preventDefault();
649
761
  }
650
762
  function VariablePicker({ variables, targetRef, className }) {
651
- const menuId = useId5();
652
- const trigger = useRef3(null);
653
- const menu = useRef3(null);
654
- const items = useRef3([]);
763
+ const menuId = useId6();
764
+ const trigger = useRef4(null);
765
+ const menu = useRef4(null);
766
+ const items = useRef4([]);
655
767
  const [open, setOpen] = useState2(false);
656
768
  const [active, setActive] = useState2(0);
657
769
  const count = variables.length;
658
- useEffect(() => {
770
+ useEffect2(() => {
659
771
  if (targetRef.current) watchFocus(targetRef.current);
660
772
  });
661
- useEffect(() => {
773
+ useEffect2(() => {
662
774
  if (open) items.current[active]?.focus();
663
775
  }, [open, active]);
664
776
  const openAt = (index) => {
@@ -707,8 +819,8 @@ function VariablePicker({ variables, targetRef, className }) {
707
819
  const onItemBlur = (event) => {
708
820
  if (!menu.current?.contains(event.relatedTarget)) setOpen(false);
709
821
  };
710
- return /* @__PURE__ */ jsxs10("div", { className: cn("variable-picker", className), children: [
711
- /* @__PURE__ */ jsx16(
822
+ return /* @__PURE__ */ jsxs11("div", { className: cn("variable-picker", className), children: [
823
+ /* @__PURE__ */ jsx17(
712
824
  "button",
713
825
  {
714
826
  ref: trigger,
@@ -727,7 +839,7 @@ function VariablePicker({ variables, targetRef, className }) {
727
839
  children: "Insert variable"
728
840
  }
729
841
  ),
730
- open ? /* @__PURE__ */ jsx16(
842
+ open ? /* @__PURE__ */ jsx17(
731
843
  "div",
732
844
  {
733
845
  ref: menu,
@@ -735,7 +847,7 @@ function VariablePicker({ variables, targetRef, className }) {
735
847
  role: "menu",
736
848
  "aria-label": "Variables",
737
849
  className: "variable-picker-menu",
738
- children: variables.map((variable, index) => /* @__PURE__ */ jsxs10(
850
+ children: variables.map((variable, index) => /* @__PURE__ */ jsxs11(
739
851
  "button",
740
852
  {
741
853
  ref: (node) => {
@@ -750,8 +862,8 @@ function VariablePicker({ variables, targetRef, className }) {
750
862
  onKeyDown: (event) => onItemKeyDown(event, index),
751
863
  onBlur: onItemBlur,
752
864
  children: [
753
- /* @__PURE__ */ jsx16("span", { className: "variable-picker-item-label", children: variable.label }),
754
- /* @__PURE__ */ jsx16("code", { className: "variable-picker-item-token", children: liquidToken(variable.name) })
865
+ /* @__PURE__ */ jsx17("span", { className: "variable-picker-item-label", children: variable.label }),
866
+ /* @__PURE__ */ jsx17("code", { className: "variable-picker-item-token", children: liquidToken(variable.name) })
755
867
  ]
756
868
  },
757
869
  variable.name
@@ -769,6 +881,7 @@ export {
769
881
  ChecklistRow,
770
882
  ChecklistSkeleton,
771
883
  CodeArea,
884
+ ConfirmDialog,
772
885
  Container,
773
886
  EmptyState,
774
887
  Field,