@flopay/ui 1.12.0 → 1.14.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,179 @@ 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
 
520
+ // src/components/select.tsx
521
+ import { jsx as jsx14 } from "react/jsx-runtime";
522
+ function Select({ id, label, value, options, onChange, disabled, name }) {
523
+ return /* @__PURE__ */ jsx14(Field, { label, htmlFor: id, children: /* @__PURE__ */ jsx14(
524
+ "select",
525
+ {
526
+ id,
527
+ name,
528
+ className: "field field-select",
529
+ value,
530
+ disabled,
531
+ onChange: (event) => onChange(event.target.value),
532
+ children: options.map((option) => /* @__PURE__ */ jsx14("option", { value: option.value, children: option.label }, option.value))
533
+ }
534
+ ) });
535
+ }
536
+
408
537
  // src/components/slot-text-field.tsx
409
538
  import {
410
539
  useCallback,
411
- useId as useId3,
412
- useRef as useRef2
540
+ useId as useId4,
541
+ useRef as useRef3
413
542
  } from "react";
414
543
 
415
544
  // src/components/text-selection.ts
@@ -448,7 +577,7 @@ function assignRef(ref, node) {
448
577
  }
449
578
 
450
579
  // src/components/slot-text-field.tsx
451
- import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
580
+ import { jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
452
581
  var LINK_PLACEHOLDER = "https://";
453
582
  function wrapWith(marker) {
454
583
  return (selected) => ({
@@ -481,9 +610,9 @@ function SlotTextField({
481
610
  name,
482
611
  className
483
612
  }) {
484
- const generatedId = useId3();
613
+ const generatedId = useId4();
485
614
  const controlId = id ?? generatedId;
486
- const control = useRef2(null);
615
+ const control = useRef3(null);
487
616
  const setControl = useCallback(
488
617
  (node) => {
489
618
  control.current = node;
@@ -501,7 +630,7 @@ function SlotTextField({
501
630
  className: multiline ? "field field-multiline" : "field",
502
631
  "aria-invalid": error ? true : void 0
503
632
  };
504
- return /* @__PURE__ */ jsxs7(
633
+ return /* @__PURE__ */ jsxs8(
505
634
  Field,
506
635
  {
507
636
  label,
@@ -510,7 +639,7 @@ function SlotTextField({
510
639
  htmlFor: controlId,
511
640
  className,
512
641
  children: [
513
- /* @__PURE__ */ jsx13("div", { className: "slot-toolbar", children: FORMATS.map((format) => /* @__PURE__ */ jsx13(
642
+ /* @__PURE__ */ jsx15("div", { className: "slot-toolbar", children: FORMATS.map((format) => /* @__PURE__ */ jsx15(
514
643
  "button",
515
644
  {
516
645
  type: "button",
@@ -522,14 +651,14 @@ function SlotTextField({
522
651
  },
523
652
  format.name
524
653
  )) }),
525
- multiline ? /* @__PURE__ */ jsx13("textarea", { ref: setControl, rows: 4, ...shared }) : /* @__PURE__ */ jsx13("input", { ref: setControl, type: "text", ...shared })
654
+ multiline ? /* @__PURE__ */ jsx15("textarea", { ref: setControl, rows: 4, ...shared }) : /* @__PURE__ */ jsx15("input", { ref: setControl, type: "text", ...shared })
526
655
  ]
527
656
  }
528
657
  );
529
658
  }
530
659
 
531
660
  // src/components/step-indicator.tsx
532
- import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
661
+ import { jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
533
662
  var defaultStatusLabels = {
534
663
  done: "Done",
535
664
  current: "Current",
@@ -541,21 +670,21 @@ var markerClass = {
541
670
  upcoming: ""
542
671
  };
543
672
  function StepIndicator({ steps, statusLabels, className }) {
544
- return /* @__PURE__ */ jsx14("ol", { className: cn("step-indicator", className), children: steps.map((step, index) => /* @__PURE__ */ jsxs8(
673
+ return /* @__PURE__ */ jsx16("ol", { className: cn("step-indicator", className), children: steps.map((step, index) => /* @__PURE__ */ jsxs9(
545
674
  "li",
546
675
  {
547
676
  className: "step-indicator-step",
548
677
  "aria-current": step.status === "current" ? "step" : void 0,
549
678
  children: [
550
- /* @__PURE__ */ jsx14(
679
+ /* @__PURE__ */ jsx16(
551
680
  "span",
552
681
  {
553
682
  className: cn("step-indicator-marker", markerClass[step.status]),
554
683
  "aria-hidden": "true",
555
- children: step.status === "done" ? /* @__PURE__ */ jsx14(CheckIcon, { className: "step-indicator-icon" }) : index + 1
684
+ children: step.status === "done" ? /* @__PURE__ */ jsx16(CheckIcon, { className: "step-indicator-icon" }) : index + 1
556
685
  }
557
686
  ),
558
- /* @__PURE__ */ jsx14(
687
+ /* @__PURE__ */ jsx16(
559
688
  "span",
560
689
  {
561
690
  className: cn(
@@ -565,7 +694,7 @@ function StepIndicator({ steps, statusLabels, className }) {
565
694
  children: step.label
566
695
  }
567
696
  ),
568
- /* @__PURE__ */ jsx14("span", { className: "visually-hidden", children: statusLabels?.[step.status] ?? defaultStatusLabels[step.status] })
697
+ /* @__PURE__ */ jsx16("span", { className: "visually-hidden", children: statusLabels?.[step.status] ?? defaultStatusLabels[step.status] })
569
698
  ]
570
699
  },
571
700
  index
@@ -573,8 +702,8 @@ function StepIndicator({ steps, statusLabels, className }) {
573
702
  }
574
703
 
575
704
  // src/components/switch.tsx
576
- import { useId as useId4, useState } from "react";
577
- import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
705
+ import { useId as useId5, useState } from "react";
706
+ import { jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
578
707
  function ignorePress(event) {
579
708
  event.preventDefault();
580
709
  }
@@ -590,7 +719,7 @@ function Switch({
590
719
  name,
591
720
  className
592
721
  }) {
593
- const generatedId = useId4();
722
+ const generatedId = useId5();
594
723
  const controlId = id ?? generatedId;
595
724
  const labelId = `${controlId}-label`;
596
725
  const [ownChecked, setOwnChecked] = useState(defaultChecked);
@@ -601,8 +730,8 @@ function Switch({
601
730
  if (checked === void 0) setOwnChecked(next);
602
731
  onCheckedChange?.(next);
603
732
  };
604
- return /* @__PURE__ */ jsxs9("span", { className: cn("switch", className), children: [
605
- /* @__PURE__ */ jsx15(
733
+ return /* @__PURE__ */ jsxs10("span", { className: cn("switch", className), children: [
734
+ /* @__PURE__ */ jsx17(
606
735
  "button",
607
736
  {
608
737
  type: "button",
@@ -616,10 +745,10 @@ function Switch({
616
745
  disabled,
617
746
  onMouseDown: loading ? ignorePress : void 0,
618
747
  onClick: toggle,
619
- children: /* @__PURE__ */ jsx15("span", { className: "switch-thumb", "aria-hidden": "true" })
748
+ children: /* @__PURE__ */ jsx17("span", { className: "switch-thumb", "aria-hidden": "true" })
620
749
  }
621
750
  ),
622
- /* @__PURE__ */ jsx15(
751
+ /* @__PURE__ */ jsx17(
623
752
  "label",
624
753
  {
625
754
  id: labelId,
@@ -628,19 +757,19 @@ function Switch({
628
757
  children: label
629
758
  }
630
759
  ),
631
- loading ? /* @__PURE__ */ jsx15(Spinner, { className: "switch-spinner" }) : null,
632
- name && isChecked && !disabled ? /* @__PURE__ */ jsx15("input", { type: "hidden", name, value: "on" }) : null
760
+ loading ? /* @__PURE__ */ jsx17(Spinner, { className: "switch-spinner" }) : null,
761
+ name && isChecked && !disabled ? /* @__PURE__ */ jsx17("input", { type: "hidden", name, value: "on" }) : null
633
762
  ] });
634
763
  }
635
764
 
636
765
  // src/components/variable-picker.tsx
637
766
  import {
638
- useEffect,
639
- useId as useId5,
640
- useRef as useRef3,
767
+ useEffect as useEffect2,
768
+ useId as useId6,
769
+ useRef as useRef4,
641
770
  useState as useState2
642
771
  } from "react";
643
- import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
772
+ import { jsx as jsx18, jsxs as jsxs11 } from "react/jsx-runtime";
644
773
  function liquidToken(name) {
645
774
  return `{{ ${name} }}`;
646
775
  }
@@ -648,17 +777,17 @@ function keepFocus(event) {
648
777
  event.preventDefault();
649
778
  }
650
779
  function VariablePicker({ variables, targetRef, className }) {
651
- const menuId = useId5();
652
- const trigger = useRef3(null);
653
- const menu = useRef3(null);
654
- const items = useRef3([]);
780
+ const menuId = useId6();
781
+ const trigger = useRef4(null);
782
+ const menu = useRef4(null);
783
+ const items = useRef4([]);
655
784
  const [open, setOpen] = useState2(false);
656
785
  const [active, setActive] = useState2(0);
657
786
  const count = variables.length;
658
- useEffect(() => {
787
+ useEffect2(() => {
659
788
  if (targetRef.current) watchFocus(targetRef.current);
660
789
  });
661
- useEffect(() => {
790
+ useEffect2(() => {
662
791
  if (open) items.current[active]?.focus();
663
792
  }, [open, active]);
664
793
  const openAt = (index) => {
@@ -707,8 +836,8 @@ function VariablePicker({ variables, targetRef, className }) {
707
836
  const onItemBlur = (event) => {
708
837
  if (!menu.current?.contains(event.relatedTarget)) setOpen(false);
709
838
  };
710
- return /* @__PURE__ */ jsxs10("div", { className: cn("variable-picker", className), children: [
711
- /* @__PURE__ */ jsx16(
839
+ return /* @__PURE__ */ jsxs11("div", { className: cn("variable-picker", className), children: [
840
+ /* @__PURE__ */ jsx18(
712
841
  "button",
713
842
  {
714
843
  ref: trigger,
@@ -727,7 +856,7 @@ function VariablePicker({ variables, targetRef, className }) {
727
856
  children: "Insert variable"
728
857
  }
729
858
  ),
730
- open ? /* @__PURE__ */ jsx16(
859
+ open ? /* @__PURE__ */ jsx18(
731
860
  "div",
732
861
  {
733
862
  ref: menu,
@@ -735,7 +864,7 @@ function VariablePicker({ variables, targetRef, className }) {
735
864
  role: "menu",
736
865
  "aria-label": "Variables",
737
866
  className: "variable-picker-menu",
738
- children: variables.map((variable, index) => /* @__PURE__ */ jsxs10(
867
+ children: variables.map((variable, index) => /* @__PURE__ */ jsxs11(
739
868
  "button",
740
869
  {
741
870
  ref: (node) => {
@@ -750,8 +879,8 @@ function VariablePicker({ variables, targetRef, className }) {
750
879
  onKeyDown: (event) => onItemKeyDown(event, index),
751
880
  onBlur: onItemBlur,
752
881
  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) })
882
+ /* @__PURE__ */ jsx18("span", { className: "variable-picker-item-label", children: variable.label }),
883
+ /* @__PURE__ */ jsx18("code", { className: "variable-picker-item-token", children: liquidToken(variable.name) })
755
884
  ]
756
885
  },
757
886
  variable.name
@@ -769,6 +898,7 @@ export {
769
898
  ChecklistRow,
770
899
  ChecklistSkeleton,
771
900
  CodeArea,
901
+ ConfirmDialog,
772
902
  Container,
773
903
  EmptyState,
774
904
  Field,
@@ -777,6 +907,7 @@ export {
777
907
  PreviewFrame,
778
908
  Section,
779
909
  SectionHeader,
910
+ Select,
780
911
  SlotTextField,
781
912
  Spinner,
782
913
  StepIndicator,