@kjun-ui/react 0.8.1 → 0.10.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.
Files changed (30) hide show
  1. package/dist/index.cjs +262 -54
  2. package/dist/index.js +308 -99
  3. package/dist/styles.css +30 -19
  4. package/dist/types/packages/react/src/button.d.cts +2 -0
  5. package/dist/types/packages/react/src/button.d.ts +2 -0
  6. package/dist/types/packages/react/src/display.d.cts +4 -1
  7. package/dist/types/packages/react/src/display.d.ts +4 -1
  8. package/dist/types/packages/react/src/floating-panel.d.cts +4 -1
  9. package/dist/types/packages/react/src/floating-panel.d.ts +4 -1
  10. package/dist/types/packages/react/src/input.d.cts +5 -1
  11. package/dist/types/packages/react/src/input.d.ts +5 -1
  12. package/dist/types/packages/react/src/popover.d.cts +12 -3
  13. package/dist/types/packages/react/src/popover.d.ts +12 -3
  14. package/dist/types/packages/react/src/select-control.d.cts +9 -1
  15. package/dist/types/packages/react/src/select-control.d.ts +9 -1
  16. package/dist/types/shared/package-runtime/alert-live.d.cts +3 -0
  17. package/dist/types/shared/package-runtime/alert-live.d.ts +3 -0
  18. package/dist/types/shared/package-runtime/aria-ids.d.cts +4 -0
  19. package/dist/types/shared/package-runtime/aria-ids.d.ts +4 -0
  20. package/dist/types/shared/package-runtime/layer-state.d.cts +3 -0
  21. package/dist/types/shared/package-runtime/layer-state.d.ts +3 -0
  22. package/dist/types/shared/package-runtime/options.d.cts +5 -1
  23. package/dist/types/shared/package-runtime/options.d.ts +5 -1
  24. package/dist/types/shared/package-runtime/popover-nonmodal.d.cts +12 -0
  25. package/dist/types/shared/package-runtime/popover-nonmodal.d.ts +12 -0
  26. package/dist/types/shared/package-runtime/table-presentation.d.cts +4 -0
  27. package/dist/types/shared/package-runtime/table-presentation.d.ts +4 -0
  28. package/dist/types/shared/package-runtime/use-layer.d.cts +3 -1
  29. package/dist/types/shared/package-runtime/use-layer.d.ts +3 -1
  30. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -140,9 +140,23 @@ function mergeIcons(parent, own) {
140
140
  function withFallbackIcons(registry, fallbacks) {
141
141
  return mergeIcons(fallbacks, registry);
142
142
  }
143
+ var warnedIcons = /* @__PURE__ */ new Set();
144
+ function developmentMode() {
145
+ try {
146
+ return true;
147
+ } catch (e) {
148
+ return false;
149
+ }
150
+ }
151
+ function warnMissingIcon(name) {
152
+ if (!developmentMode() || warnedIcons.has(name)) return;
153
+ warnedIcons.add(name);
154
+ console.warn(`KJUN Icon: "${name}" \uC544\uC774\uCF58\uC774 \uB4F1\uB85D\uB418\uC9C0 \uC54A\uC544 help-circle\uB85C \uB300\uC2E0\uD569\uB2C8\uB2E4. @kjun-ui/icons/icons/${name}\uB97C import\uD574 KjunProvider\uC758 icons\uC5D0 \uB4F1\uB85D\uD558\uC138\uC694.`);
155
+ }
143
156
  function resolveIcon(registry, name, filled = false) {
144
157
  var _a;
145
158
  const definition = Object.prototype.hasOwnProperty.call(registry, name) ? registry[name] : void 0;
159
+ if (!definition && name) warnMissingIcon(name);
146
160
  const filledNodes = filled && (definition == null ? void 0 : definition.filled);
147
161
  return { nodes: filledNodes || (definition == null ? void 0 : definition.outline) || ((_a = registry["help-circle"]) == null ? void 0 : _a.outline) || import_defaults.defaultIcons["help-circle"].outline, filled: !!filledNodes };
148
162
  }
@@ -233,6 +247,10 @@ function installLayerKeyboard(document2, state, keyupFallback = false) {
233
247
  var import_react2 = require("react");
234
248
 
235
249
  // shared/package-runtime/layer-state.ts
250
+ function chooseReturnTarget(chosen, fallback2) {
251
+ if (chosen === false) return void 0;
252
+ return chosen && chosen.isConnected !== false ? chosen : fallback2;
253
+ }
236
254
  function createLayerState() {
237
255
  const entries = /* @__PURE__ */ new Map(), listeners = /* @__PURE__ */ new Set();
238
256
  const restoredFocus = /* @__PURE__ */ new WeakSet();
@@ -253,6 +271,7 @@ function createLayerState() {
253
271
  return !layer.blocked && (layer.kind === "window" ? ((_a = topWindow()) == null ? void 0 : _a.id) === layer.id : ((_b = topWindow()) == null ? void 0 : _b.id) === layer.owner);
254
272
  };
255
273
  const top = () => [...entries.values()].filter(active).sort((a, b) => a.order - b.order).at(-1);
274
+ const topPopup = () => [...entries.values()].filter((layer) => layer.kind !== "tooltip" && active(layer)).sort((a, b) => a.order - b.order).at(-1);
256
275
  function dismiss(layer) {
257
276
  if (layer.closeRequested) return;
258
277
  layer.closeRequested = true;
@@ -272,6 +291,7 @@ function createLayerState() {
272
291
  entries,
273
292
  topWindow,
274
293
  top,
294
+ topPopup,
275
295
  windowOf,
276
296
  isRestoredFocus(target) {
277
297
  return !!target && restoredFocus.has(target);
@@ -415,21 +435,31 @@ function focusTrigger(target) {
415
435
  }
416
436
  return target;
417
437
  }
418
- function restoreFocus(target, state, id) {
438
+ function restoreFocus(target, state, id, fallback2) {
439
+ const usable = (item) => (item == null ? void 0 : item.isConnected) !== false && !(typeof HTMLElement !== "undefined" && item instanceof HTMLElement && item.closest("[inert]"));
419
440
  const restore = () => {
420
- var _a, _b, _c, _d;
441
+ var _a, _b, _c, _d, _e;
421
442
  if (state.entries.has(id)) return;
422
- if ((target == null ? void 0 : target.isConnected) !== false && !(typeof HTMLElement !== "undefined" && target instanceof HTMLElement && target.closest("[inert]"))) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
423
- else (_d = (_c = (_b = state.topWindow()) == null ? void 0 : _b.root) == null ? void 0 : _c.focus) == null ? void 0 : _d.call(_c, { preventScroll: true });
443
+ if (usable(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
444
+ else if (fallback2 && fallback2 !== target && usable(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
445
+ else (_e = (_d = (_c = state.topWindow()) == null ? void 0 : _c.root) == null ? void 0 : _d.focus) == null ? void 0 : _e.call(_d, { preventScroll: true });
424
446
  };
425
447
  if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(restore);
426
448
  else queueMicrotask(restore);
427
449
  }
428
- function useLayer(open, present, kind, close, trigger) {
450
+ function useLayer(open, present, kind, close, trigger, returnFocus) {
429
451
  var _a;
430
452
  const state = useLayerState(), parent = (0, import_react2.useContext)(LayerScope), id = (0, import_react2.useId)();
431
453
  const callback = (0, import_react2.useRef)(close);
432
454
  callback.current = close;
455
+ const returnRef = (0, import_react2.useRef)(returnFocus);
456
+ returnRef.current = returnFocus;
457
+ const fallbackFocus = (0, import_react2.useRef)(null);
458
+ const removeLayer = () => {
459
+ const removed = state.remove(id, currentFocus());
460
+ if (removed) fallbackFocus.current = removed;
461
+ return removed && returnRef.current ? chooseReturnTarget(returnRef.current(), removed) : removed;
462
+ };
433
463
  const openingFocus = (0, import_react2.useRef)(null);
434
464
  const wasOpen = (0, import_react2.useRef)(false);
435
465
  const pendingFocus = (0, import_react2.useRef)(null);
@@ -441,17 +471,17 @@ function useLayer(open, present, kind, close, trigger) {
441
471
  state.open(id, kind, parent, () => callback.current(), focusTrigger(trigger == null ? void 0 : trigger.current) || openingFocus.current);
442
472
  } else if (kind === "window" && present) state.markClosing(id);
443
473
  else if (kind !== "window" || !present) {
444
- const target = state.remove(id, currentFocus());
474
+ const target = removeLayer();
445
475
  if (target) pendingFocus.current = target;
446
476
  if (!present && pendingFocus.current) {
447
- restoreFocus(pendingFocus.current, state, id);
477
+ restoreFocus(pendingFocus.current, state, id, fallbackFocus.current);
448
478
  pendingFocus.current = null;
449
479
  }
450
480
  }
451
481
  }, [open, present, state, id, kind, parent, trigger]);
452
482
  (0, import_react2.useLayoutEffect)(() => () => {
453
- const target = state.remove(id, currentFocus());
454
- if (target || pendingFocus.current) restoreFocus(target || pendingFocus.current, state, id);
483
+ const target = removeLayer();
484
+ if (target || pendingFocus.current) restoreFocus(target || pendingFocus.current, state, id, fallbackFocus.current);
455
485
  }, [state, id]);
456
486
  const entry = state.entries.get(id);
457
487
  return {
@@ -673,6 +703,7 @@ var KjunButton = (0, import_react6.forwardRef)(
673
703
  style,
674
704
  onClick,
675
705
  type = "button",
706
+ wrap = false,
676
707
  ...rest
677
708
  } = props;
678
709
  const size = useActionSize(props.size, declaredSize);
@@ -701,6 +732,7 @@ var KjunButton = (0, import_react6.forwardRef)(
701
732
  "data-variant": variant,
702
733
  "data-size": size,
703
734
  "data-disabled": disabled,
735
+ "data-wrap": wrap || void 0,
704
736
  "aria-label": ariaLabel || rest["aria-label"],
705
737
  disabled: disabled || busy,
706
738
  "aria-busy": busy || void 0,
@@ -714,7 +746,7 @@ var KjunButton = (0, import_react6.forwardRef)(
714
746
  ...typeStyle(import_tokens5.tokens.button.typography[size]),
715
747
  borderRadius: import_tokens5.tokens.button.radii[size],
716
748
  gap: hasContent2 ? import_tokens5.tokens.button.contentGaps[size] : 0,
717
- ...navigation ? {
749
+ ...navigation || wrap ? {
718
750
  height: "auto",
719
751
  maxWidth: "100%",
720
752
  paddingBlock: Math.max(0, (height - contentHeight) / 2)
@@ -755,6 +787,14 @@ var KjunButton = (0, import_react6.forwardRef)(
755
787
 
756
788
  // packages/react/src/input.tsx
757
789
  var import_tokens7 = require("@kjun-ui/tokens");
790
+
791
+ // shared/package-runtime/aria-ids.ts
792
+ function mergeIds(...lists) {
793
+ const ids = [...new Set(lists.flatMap((list) => (list != null ? list : "").split(/\s+/)).filter(Boolean))];
794
+ return ids.length ? ids.join(" ") : void 0;
795
+ }
796
+
797
+ // packages/react/src/input.tsx
758
798
  var import_react8 = require("react");
759
799
 
760
800
  // packages/react/src/composition.ts
@@ -783,26 +823,30 @@ function KjunFormGroup({
783
823
  required = false,
784
824
  error = "",
785
825
  hint = "",
826
+ labelHidden = false,
786
827
  children
787
828
  }) {
788
829
  const uid = (0, import_react8.useId)().replace(/:/g, "");
789
830
  const fieldId = id || "kjun-field-" + uid;
790
831
  const labelId = label ? fieldId + "-label" : void 0;
791
- const describedBy = error ? fieldId + "-error" : hint ? fieldId + "-hint" : void 0;
832
+ const hintId = hint ? fieldId + "-hint" : void 0, errorId = error ? fieldId + "-error" : void 0;
833
+ const describedBy = mergeIds(hintId, errorId);
834
+ const [controlId, setControlId] = (0, import_react8.useState)();
792
835
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
793
836
  FieldContext.Provider,
794
837
  {
795
- value: { id: fieldId, labelId, describedBy, error, required },
838
+ value: { id: fieldId, labelId, describedBy, error, required, setControlId },
796
839
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kjun-form-group", children: [
797
- label && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "kjun-form-label", id: labelId, htmlFor: fieldId, children: [
840
+ label && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "kjun-form-label" + (labelHidden ? " kjun-sr-only" : ""), id: labelId, htmlFor: controlId || fieldId, children: [
798
841
  label,
799
842
  required && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { color: "var(--_kjun-color-danger)" }, children: " *" })
800
843
  ] }),
801
844
  children,
802
- error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { id: describedBy, className: "kjun-form-error", role: "alert", children: [
845
+ hint && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: hintId, className: "kjun-form-hint", children: hint }),
846
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { id: errorId, className: "kjun-form-error", role: "alert", children: [
803
847
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KjunIcon, { name: "alert-circle", size: import_tokens7.tokens.extensions.form.messageIconSize }),
804
848
  error
805
- ] }) : hint ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: describedBy, className: "kjun-form-hint", children: hint }) : null
849
+ ] })
806
850
  ] })
807
851
  }
808
852
  );
@@ -860,11 +904,7 @@ var KjunInput = (0, import_react8.forwardRef)(
860
904
  const showError = !!errorMessage && !(field == null ? void 0 : field.error);
861
905
  const invalid = !!(error || errorMessage || (field == null ? void 0 : field.error));
862
906
  const ownErrorId = "kjun-input-error-" + uid;
863
- const describedBy = [
864
- props["aria-describedby"],
865
- field == null ? void 0 : field.describedBy,
866
- showError ? ownErrorId : void 0
867
- ].filter(Boolean).join(" ") || void 0;
907
+ const describedBy = mergeIds(props["aria-describedby"], field == null ? void 0 : field.describedBy, showError ? ownErrorId : void 0);
868
908
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { minWidth: 0 }, children: [
869
909
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kjun-input-wrap", "data-disabled": disabled || void 0, children: [
870
910
  (prefix || prefixIcon) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -1267,6 +1307,13 @@ function hasContent(node) {
1267
1307
  return true;
1268
1308
  }
1269
1309
 
1310
+ // shared/package-runtime/alert-live.ts
1311
+ function alertRole(tone, live) {
1312
+ if (live === "off") return void 0;
1313
+ if (live) return live === "assertive" ? "alert" : "status";
1314
+ return tone === "danger" ? "alert" : "status";
1315
+ }
1316
+
1270
1317
  // packages/react/src/display.tsx
1271
1318
  var import_tokens10 = require("@kjun-ui/tokens");
1272
1319
  var import_react14 = require("react");
@@ -1422,6 +1469,7 @@ function KjunAlert({
1422
1469
  size = "md",
1423
1470
  title,
1424
1471
  closable = false,
1472
+ live,
1425
1473
  children,
1426
1474
  actions,
1427
1475
  onClose
@@ -1432,7 +1480,7 @@ function KjunAlert({
1432
1480
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1433
1481
  "div",
1434
1482
  {
1435
- role: tone === "danger" ? "alert" : "status",
1483
+ role: alertRole(tone, live),
1436
1484
  className: "kjun-alert",
1437
1485
  "data-size": small ? "sm" : "md",
1438
1486
  style: {
@@ -2153,12 +2201,17 @@ function KjunCheckbox({
2153
2201
  onChange
2154
2202
  }) {
2155
2203
  const checked = Array.isArray(value) ? value.includes(val) : value;
2204
+ const field = useKjunField();
2156
2205
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
2157
2206
  import_react_aria_components2.Checkbox,
2158
2207
  {
2159
2208
  isSelected: checked,
2160
2209
  isDisabled: disabled,
2161
2210
  "aria-label": ariaLabel,
2211
+ "aria-describedby": field == null ? void 0 : field.describedBy,
2212
+ isInvalid: !!(field == null ? void 0 : field.error),
2213
+ isRequired: field == null ? void 0 : field.required,
2214
+ validationBehavior: "aria",
2162
2215
  className: "kjun-choice" + (disabled ? " kjun-choice--disabled" : ""),
2163
2216
  onChange: (next) => {
2164
2217
  const result = Array.isArray(value) ? next ? [...value, val] : value.filter((v) => v !== val) : next;
@@ -2188,12 +2241,23 @@ function KjunSwitch({
2188
2241
  onValueChange,
2189
2242
  onChange
2190
2243
  }) {
2244
+ const field = useKjunField();
2245
+ const invalid = !!(field == null ? void 0 : field.error), required = !!(field == null ? void 0 : field.required);
2246
+ const markInput = (0, import_react22.useCallback)((input) => {
2247
+ if (!input) return;
2248
+ if (invalid) input.setAttribute("aria-invalid", "true");
2249
+ else input.removeAttribute("aria-invalid");
2250
+ if (required) input.setAttribute("aria-required", "true");
2251
+ else input.removeAttribute("aria-required");
2252
+ }, [invalid, required]);
2191
2253
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
2192
2254
  import_react_aria_components2.Switch,
2193
2255
  {
2194
2256
  isSelected: value,
2195
2257
  isDisabled: disabled,
2196
2258
  "aria-label": ariaLabel || label,
2259
+ "aria-describedby": field == null ? void 0 : field.describedBy,
2260
+ inputRef: markInput,
2197
2261
  className: "kjun-choice" + (disabled ? " kjun-choice--disabled" : ""),
2198
2262
  onChange: (next) => {
2199
2263
  onValueChange == null ? void 0 : onValueChange(next);
@@ -2283,7 +2347,8 @@ function KjunRadioGroup({
2283
2347
  style: {
2284
2348
  display: "flex",
2285
2349
  flexDirection: direction === "vertical" ? "column" : "row",
2286
- flexWrap: "wrap",
2350
+ // A wrapping column would split into extra columns whenever the group's height is fixed.
2351
+ flexWrap: direction === "vertical" ? "nowrap" : "wrap",
2287
2352
  gap: direction === "vertical" ? import_tokens16.tokens.dimension.value8 : import_tokens16.tokens.dimension.value16
2288
2353
  },
2289
2354
  children: children || options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
@@ -2328,7 +2393,7 @@ var KjunTextarea = (0, import_react22.forwardRef)(
2328
2393
  required: (_a = props.required) != null ? _a : field == null ? void 0 : field.required,
2329
2394
  "aria-label": ariaLabel || props["aria-label"],
2330
2395
  "aria-labelledby": props["aria-labelledby"] || (field == null ? void 0 : field.labelId),
2331
- "aria-describedby": props["aria-describedby"] || (field == null ? void 0 : field.describedBy),
2396
+ "aria-describedby": mergeIds(props["aria-describedby"], field == null ? void 0 : field.describedBy),
2332
2397
  "aria-invalid": error || !!(field == null ? void 0 : field.error) || void 0,
2333
2398
  className: "kjun-input kjun-textarea " + className,
2334
2399
  style: {
@@ -2488,10 +2553,12 @@ function FloatingPanel({
2488
2553
  maxHeight,
2489
2554
  field = false,
2490
2555
  flip = true,
2491
- nonModal = false
2556
+ nonModal = false,
2557
+ ownsDismiss = false,
2558
+ returnFocus
2492
2559
  }) {
2493
2560
  const motion = usePresence(open, useReducedMotion(), import_tokens17.tokens.motion.popupExit);
2494
- const layer = useLayer(open, motion.present, "popup", () => onOpenChange(false), triggerRef);
2561
+ const layer = useLayer(open, motion.present, "popup", () => onOpenChange(false), triggerRef, returnFocus);
2495
2562
  const container = useKjunPortalContainer();
2496
2563
  const panel = (0, import_react23.useRef)(null);
2497
2564
  (0, import_react23.useEffect)(() => {
@@ -2519,7 +2586,9 @@ function FloatingPanel({
2519
2586
  isNonModal: nonModal,
2520
2587
  isKeyboardDismissDisabled: layer.keyboardManaged,
2521
2588
  isOpen: motion.present,
2522
- onOpenChange,
2589
+ onOpenChange: ownsDismiss && layer.keyboardManaged ? (next) => {
2590
+ if (next) onOpenChange(next);
2591
+ } : onOpenChange,
2523
2592
  triggerRef,
2524
2593
  UNSTABLE_portalContainer: container,
2525
2594
  placement: placement.replace("-", " "),
@@ -2544,6 +2613,67 @@ function FloatingPanel({
2544
2613
  var import_tokens18 = require("@kjun-ui/tokens");
2545
2614
  var import_react24 = require("react");
2546
2615
  var import_react_aria_components4 = require("react-aria-components");
2616
+
2617
+ // shared/package-runtime/popover-nonmodal.ts
2618
+ var tabbableSelector = 'button,input,select,textarea,[href],[tabindex]:not([tabindex="-1"])';
2619
+ function tabbable(element) {
2620
+ return element.tabIndex >= 0 && !element.disabled && element.getClientRects().length > 0 && !element.closest("[inert]");
2621
+ }
2622
+ function tabbables(root) {
2623
+ return [...root.querySelectorAll(tabbableSelector)].filter(tabbable);
2624
+ }
2625
+ function nextTabbableAfter(trigger, skip) {
2626
+ var _a;
2627
+ return (_a = tabbables(trigger.ownerDocument).find((element) => !trigger.contains(element) && !(skip == null ? void 0 : skip.contains(element)) && !!(trigger.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING))) != null ? _a : null;
2628
+ }
2629
+ function installNonModalPopover({ panel, trigger, close }) {
2630
+ var _a, _b;
2631
+ const doc = (_a = trigger()) == null ? void 0 : _a.ownerDocument;
2632
+ if (!doc) return () => {
2633
+ };
2634
+ const inside = (node) => {
2635
+ var _a2, _b2;
2636
+ if (!(node instanceof Node)) return false;
2637
+ const element = node instanceof Element ? node : node.parentElement;
2638
+ return !!(((_a2 = panel()) == null ? void 0 : _a2.contains(node)) || ((_b2 = trigger()) == null ? void 0 : _b2.contains(node)) || (element == null ? void 0 : element.closest(".kjun-floating")));
2639
+ };
2640
+ const onKeyDown = (event) => {
2641
+ var _a2, _b2, _c;
2642
+ const root = panel(), opener = trigger();
2643
+ if (event.key !== "Tab" || !root || !opener || !root.contains(event.target)) return;
2644
+ const items = tabbables(root), first = items[0], last = items.at(-1);
2645
+ if (event.shiftKey && (event.target === first || event.target === root || !first)) {
2646
+ event.preventDefault();
2647
+ event.stopPropagation();
2648
+ ((_a2 = tabbables(opener)[0]) != null ? _a2 : opener).focus();
2649
+ } else if (!event.shiftKey && (event.target === last || !last)) {
2650
+ event.preventDefault();
2651
+ event.stopPropagation();
2652
+ const next = (_c = (_b2 = nextTabbableAfter(opener, root)) != null ? _b2 : tabbables(opener)[0]) != null ? _c : opener;
2653
+ close();
2654
+ let frames = 0;
2655
+ const moveOn = () => {
2656
+ if (root.isConnected && frames++ < 60) requestAnimationFrame(moveOn);
2657
+ else next.focus();
2658
+ };
2659
+ moveOn();
2660
+ }
2661
+ };
2662
+ const onOutside = (event) => {
2663
+ if (!inside(event.target)) close();
2664
+ };
2665
+ const view = (_b = doc.defaultView) != null ? _b : window;
2666
+ view.addEventListener("keydown", onKeyDown, true);
2667
+ doc.addEventListener("focusin", onOutside, true);
2668
+ doc.addEventListener("pointerdown", onOutside, true);
2669
+ return () => {
2670
+ view.removeEventListener("keydown", onKeyDown, true);
2671
+ doc.removeEventListener("focusin", onOutside, true);
2672
+ doc.removeEventListener("pointerdown", onOutside, true);
2673
+ };
2674
+ }
2675
+
2676
+ // packages/react/src/popover.tsx
2547
2677
  var import_jsx_runtime14 = require("react/jsx-runtime");
2548
2678
  function KjunPopover({
2549
2679
  noPadding = false,
@@ -2556,6 +2686,9 @@ function KjunPopover({
2556
2686
  focusOnOpen = false,
2557
2687
  ariaLabel,
2558
2688
  placement = "bottom",
2689
+ returnFocus,
2690
+ header,
2691
+ modal = true,
2559
2692
  trigger,
2560
2693
  children
2561
2694
  }) {
@@ -2566,10 +2699,28 @@ function KjunPopover({
2566
2699
  const focusContent = (0, import_react24.useCallback)((node) => {
2567
2700
  if (node && focusOnMount.current) node.focus();
2568
2701
  }, []);
2702
+ const resolveReturn = returnFocus === void 0 ? void 0 : () => typeof returnFocus === "function" ? returnFocus() : returnFocus instanceof HTMLElement ? returnFocus : returnFocus.current;
2569
2703
  const change = (v) => {
2570
2704
  setInternal(v);
2571
2705
  onOpenChange == null ? void 0 : onOpenChange(v);
2572
2706
  };
2707
+ const skipReturn = (0, import_react24.useRef)(false);
2708
+ (0, import_react24.useEffect)(() => {
2709
+ if (!open || modal) return;
2710
+ skipReturn.current = false;
2711
+ return installNonModalPopover({
2712
+ panel: () => {
2713
+ var _a, _b;
2714
+ return (_b = (_a = document.getElementById(id)) == null ? void 0 : _a.closest(".kjun-floating")) != null ? _b : null;
2715
+ },
2716
+ trigger: () => ref.current,
2717
+ close: () => {
2718
+ skipReturn.current = true;
2719
+ change(false);
2720
+ }
2721
+ });
2722
+ });
2723
+ const content = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "kjun-popover-content", "data-no-padding": noPadding, children: typeof children === "function" ? children(() => change(false)) : children });
2573
2724
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2574
2725
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2575
2726
  "div",
@@ -2597,25 +2748,29 @@ function KjunPopover({
2597
2748
  open,
2598
2749
  onOpenChange: change,
2599
2750
  triggerRef: ref,
2600
- className: "kjun-content-popover",
2751
+ className: "kjun-content-popover" + (header != null ? " kjun-popover-has-header" : ""),
2601
2752
  placement,
2602
2753
  matchTriggerWidth,
2603
2754
  maxHeight,
2604
2755
  flip,
2605
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2606
- import_react_aria_components4.Dialog,
2607
- {
2756
+ returnFocus: () => skipReturn.current ? false : resolveReturn == null ? void 0 : resolveReturn(),
2757
+ nonModal: !modal,
2758
+ ownsDismiss: !modal,
2759
+ children: (() => {
2760
+ const dialogProps = {
2608
2761
  id,
2609
- "aria-label": ariaLabel || "\uC0C1\uC138 \uC815\uBCF4",
2762
+ "aria-label": header != null && !ariaLabel ? void 0 : ariaLabel || "\uC0C1\uC138 \uC815\uBCF4",
2763
+ "aria-labelledby": header != null && !ariaLabel ? id + "-header" : void 0,
2610
2764
  className: "kjun-popover-dialog",
2611
- style: { maxHeight: maxHeight != null ? maxHeight : `min(60vh, ${import_tokens18.tokens.extensions.floating.maxHeight}px)`, overflowY: "auto" },
2612
- ref: focusContent,
2613
- children: [
2614
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "kjun-popover-content", "data-no-padding": noPadding, children: typeof children === "function" ? children(() => change(false)) : children }),
2615
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FeedbackLayerOutlet, {})
2616
- ]
2617
- }
2618
- )
2765
+ style: { maxHeight: maxHeight != null ? maxHeight : `min(60vh, ${import_tokens18.tokens.extensions.floating.maxHeight}px)`, overflowY: header != null ? void 0 : "auto" }
2766
+ };
2767
+ const body = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2768
+ header != null && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: id + "-header", className: "kjun-popover-header", children: header }),
2769
+ header != null ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "kjun-popover-body", children: content }) : content,
2770
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FeedbackLayerOutlet, {})
2771
+ ] });
2772
+ return modal ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_aria_components4.Dialog, { ...dialogProps, ref: focusContent, children: body }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("section", { ...dialogProps, role: "dialog", tabIndex: -1, ref: focusContent, children: body });
2773
+ })()
2619
2774
  }
2620
2775
  )
2621
2776
  ] });
@@ -2624,10 +2779,16 @@ function KjunTooltip({
2624
2779
  content = "",
2625
2780
  placement = "top",
2626
2781
  delay = 0,
2782
+ open: controlled,
2783
+ onOpenChange,
2627
2784
  children
2628
2785
  }) {
2629
2786
  const container = useKjunPortalContainer();
2630
- const [open, setOpen] = (0, import_react24.useState)(false);
2787
+ const [internal, setInternal] = (0, import_react24.useState)(false), open = controlled != null ? controlled : internal;
2788
+ const setOpen = (value) => {
2789
+ setInternal(value);
2790
+ onOpenChange == null ? void 0 : onOpenChange(value);
2791
+ };
2631
2792
  const layer = useLayer(open, open, "tooltip", () => setOpen(false));
2632
2793
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_aria_components4.TooltipTrigger, { isOpen: open && !layer.blocked, onOpenChange: setOpen, delay, closeDelay: 0, isDisabled: !content || !layer.scopeActive, children: [
2633
2794
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_aria_components4.Focusable, { children }),
@@ -2678,7 +2839,7 @@ function KjunDropdown({
2678
2839
  cancelAnimationFrame(frame);
2679
2840
  frame = requestAnimationFrame(() => {
2680
2841
  if (!currentOpen.current || !menu.isConnected || menu.ownerDocument.activeElement !== menu || menu.closest('[inert], [aria-hidden="true"]')) return;
2681
- const item = menu.querySelector('[data-focused="true"]:not([data-disabled])') || menu.querySelector('[role="menuitem"]:not([data-disabled])');
2842
+ const item = menu.querySelector('[data-focused="true"]:not([data-disabled])') || menu.querySelector(':is([role="menuitem"], [role="menuitemradio"]):not([data-disabled])');
2682
2843
  item == null ? void 0 : item.focus({ preventScroll: true });
2683
2844
  });
2684
2845
  };
@@ -2773,9 +2934,20 @@ function KjunDropdownItem({
2773
2934
  onClick
2774
2935
  }) {
2775
2936
  const close = (0, import_react25.useContext)(DropdownContext);
2937
+ const node = (0, import_react25.useCallback)((element) => {
2938
+ if (!element) return;
2939
+ if (selected === null) {
2940
+ element.setAttribute("role", "menuitem");
2941
+ element.removeAttribute("aria-checked");
2942
+ return;
2943
+ }
2944
+ element.setAttribute("role", "menuitemradio");
2945
+ element.setAttribute("aria-checked", String(selected));
2946
+ }, [selected]);
2776
2947
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2777
2948
  import_react_aria_components5.MenuItem,
2778
2949
  {
2950
+ ref: node,
2779
2951
  id,
2780
2952
  textValue: textValue || (typeof children === "string" ? children : void 0),
2781
2953
  isDisabled: disabled,
@@ -2981,6 +3153,17 @@ function nextOptionValue(value, option, key, multiple) {
2981
3153
  if (!multiple) return id;
2982
3154
  return Array.isArray(value) && value.includes(id) ? value.filter((item) => item !== id) : [...Array.isArray(value) ? value : [], id];
2983
3155
  }
3156
+ function optionMatchRank(option, query2, labelKey, searchKeys = []) {
3157
+ const needle = query2.trim().toLocaleLowerCase();
3158
+ if (!needle) return 0;
3159
+ const label = optionLabel(option, labelKey).toLocaleLowerCase();
3160
+ if (label.startsWith(needle)) return 0;
3161
+ if (label.includes(needle)) return 1;
3162
+ return typeof option === "object" && searchKeys.some((key) => {
3163
+ var _a;
3164
+ return String((_a = option[key]) != null ? _a : "").toLocaleLowerCase().includes(needle);
3165
+ }) ? 2 : -1;
3166
+ }
2984
3167
  function selectOptions({
2985
3168
  options,
2986
3169
  value,
@@ -2990,10 +3173,13 @@ function selectOptions({
2990
3173
  pageSize,
2991
3174
  limit,
2992
3175
  loading,
2993
- multiple
3176
+ multiple,
3177
+ filterFn,
3178
+ searchKeys = []
2994
3179
  }) {
2995
3180
  const selected = (option) => optionSelected(value, option, valueKey);
2996
- const matching = options.map((option, index) => ({ option, key: optionKey(option, valueKey, index) })).filter(({ option }) => optionLabel(option, labelKey).toLocaleLowerCase().includes(query2.trim().toLocaleLowerCase()));
3181
+ const indexed = options.map((option, index) => ({ option, key: optionKey(option, valueKey, index) }));
3182
+ const matching = filterFn ? indexed.filter(({ option }) => filterFn(option, query2)) : indexed.map((item, index) => ({ item, index, rank: optionMatchRank(item.option, query2, labelKey, searchKeys) })).filter(({ rank }) => rank >= 0).sort((a, b) => a.rank - b.rank || a.index - b.index).map(({ item }) => item);
2997
3183
  const visible = loading ? [] : pageSize > 0 ? matching.slice(0, limit) : matching;
2998
3184
  const selectedOption = options.find(selected);
2999
3185
  const label = multiple && Array.isArray(value) && value.length > 1 ? `${value.length}\uAC1C \uC120\uD0DD\uB428` : selectedOption !== void 0 ? optionLabel(selectedOption, labelKey) : "";
@@ -3574,6 +3760,8 @@ function KjunSelect({
3574
3760
  placeholder = "\uC120\uD0DD",
3575
3761
  ariaLabel,
3576
3762
  labelKey = "label",
3763
+ id: triggerId,
3764
+ ariaDescribedBy,
3577
3765
  valueKey = "value",
3578
3766
  size = "md",
3579
3767
  disabled = false,
@@ -3592,7 +3780,9 @@ function KjunSelect({
3592
3780
  onChange,
3593
3781
  onOpenChange,
3594
3782
  onSearch,
3595
- onClear
3783
+ onClear,
3784
+ filterFn,
3785
+ searchKeys
3596
3786
  }) {
3597
3787
  const { open, query: query2, limit, session, changeOpen, search, showMore } = useSelectState(controlled, disabled, optionPageSize, onOpenChange);
3598
3788
  const composition = useCompositionGuard();
@@ -3600,6 +3790,12 @@ function KjunSelect({
3600
3790
  const segment = (0, import_react33.useContext)(CompoundControlContext) !== null;
3601
3791
  const spec = import_tokens22.tokens.input[size];
3602
3792
  const expanded = usePopupExpanded(open, ref);
3793
+ const registerControl = field == null ? void 0 : field.setControlId;
3794
+ (0, import_react33.useEffect)(() => {
3795
+ if (!registerControl || !triggerId) return;
3796
+ registerControl(triggerId);
3797
+ return () => registerControl(void 0);
3798
+ }, [registerControl, triggerId]);
3603
3799
  (0, import_react33.useEffect)(() => {
3604
3800
  var _a, _b;
3605
3801
  if (open && searchable) (_b = (_a = menu.current) == null ? void 0 : _a.querySelector("input")) == null ? void 0 : _b.focus({ preventScroll: true });
@@ -3618,7 +3814,9 @@ function KjunSelect({
3618
3814
  pageSize: optionPageSize,
3619
3815
  limit,
3620
3816
  loading,
3621
- multiple
3817
+ multiple,
3818
+ filterFn,
3819
+ searchKeys
3622
3820
  });
3623
3821
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
3624
3822
  /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "kjun-select-shell", children: [
@@ -3626,7 +3824,7 @@ function KjunSelect({
3626
3824
  "button",
3627
3825
  {
3628
3826
  ref,
3629
- id: field == null ? void 0 : field.id,
3827
+ id: triggerId != null ? triggerId : field == null ? void 0 : field.id,
3630
3828
  type: "button",
3631
3829
  className: "kjun-input kjun-select-trigger",
3632
3830
  "data-time-segment": segment || void 0,
@@ -3634,9 +3832,9 @@ function KjunSelect({
3634
3832
  "aria-haspopup": "listbox",
3635
3833
  "aria-controls": expanded ? id : void 0,
3636
3834
  "aria-expanded": expanded,
3637
- "aria-label": ariaLabel || placeholder,
3835
+ "aria-label": ariaLabel || (triggerId || field ? void 0 : placeholder),
3638
3836
  "aria-labelledby": field == null ? void 0 : field.labelId,
3639
- "aria-describedby": field == null ? void 0 : field.describedBy,
3837
+ "aria-describedby": mergeIds(ariaDescribedBy, field == null ? void 0 : field.describedBy),
3640
3838
  "aria-invalid": error || !!(field == null ? void 0 : field.error) || void 0,
3641
3839
  style: {
3642
3840
  height: spec.height,
@@ -4434,7 +4632,7 @@ function KjunRefreshButton({
4434
4632
  }) {
4435
4633
  var _a;
4436
4634
  const reduced = useReducedMotion();
4437
- const label = ariaLabel || [targetName, "\uC0C8\uB85C\uACE0\uCE68"].filter(Boolean).join(" ");
4635
+ const label = ariaLabel || [targetName, mode === "text" ? text : "\uC0C8\uB85C\uACE0\uCE68"].filter(Boolean).join(" ");
4438
4636
  const hint = (_a = tooltip != null ? tooltip : title) != null ? _a : mode === "icon" ? label : "";
4439
4637
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(KjunTooltip, { content: props.disabled || props.loading ? "" : hint, placement: tooltipPlacement, delay: tooltipDelay, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4440
4638
  KjunButton,
@@ -4574,13 +4772,14 @@ function KjunDataState({
4574
4772
  }) {
4575
4773
  const state = useQueryDisplay(query2), blockingError = query2.error && !(state.usesQueryState && state.hasCurrentResult), visibleRefreshError = refreshError || (state.usesQueryState && state.hasCurrentResult ? query2.error : null), concealed = state.initialLoading || !!blockingError || empty, padding = import_tokens26.tokens.extensions.state.padding[size], revealed = useLoadingReveal(state.initialLoading, loadingDelay);
4576
4774
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "kjun-data-state", "aria-busy": !!query2.loading || refreshing, children: [
4577
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: (refreshing || state.queryRefreshing) && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "kjun-data-status", role: "status", children: [
4775
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "kjun-data-status-slot", children: (refreshing || state.queryRefreshing) && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "kjun-data-status", role: "status", children: [
4578
4776
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunSpinner, { size: "xs" }),
4579
4777
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: refreshingText })
4580
4778
  ] }) }),
4581
4779
  state.initialLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
4582
4780
  "div",
4583
4781
  {
4782
+ className: "kjun-data-loading-block",
4584
4783
  role: revealed ? "status" : void 0,
4585
4784
  "aria-label": revealed ? loadingText : void 0,
4586
4785
  "aria-hidden": revealed ? void 0 : true,
@@ -4590,11 +4789,11 @@ function KjunDataState({
4590
4789
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { children: loadingText })
4591
4790
  ] }))
4592
4791
  }
4593
- ) : blockingError ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "kjun-state-actions", style: { paddingBlock: padding }, children: errorContent || /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunAlert, { type: "danger", title: "\uC624\uB958 \uBC1C\uC0DD", actions: onRetry && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunButton, { variant: "secondary", onClick: onRetry, children: retryText }), children: query2.error }) }) : empty ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "kjun-data-empty kjun-state-actions", style: { paddingBlock: padding }, children: emptyContent || /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunEmpty, { text: emptyText, icon: emptyIcon, children: emptyActionText && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunButton, { onClick: onEmptyAction, children: emptyActionText }) }) }) : null,
4792
+ ) : blockingError ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "kjun-data-error kjun-state-actions", style: { paddingBlock: padding }, children: errorContent || /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunAlert, { type: "danger", title: "\uC624\uB958 \uBC1C\uC0DD", actions: onRetry && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunButton, { variant: "secondary", onClick: onRetry, children: retryText }), children: query2.error }) }) : empty ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "kjun-data-empty kjun-state-actions", style: { paddingBlock: padding }, children: emptyContent || /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunEmpty, { text: emptyText, icon: emptyIcon, children: emptyActionText && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(KjunButton, { onClick: onEmptyAction, children: emptyActionText }) }) }) : null,
4594
4793
  (!concealed || preserveContent && state.hasQueryResult) && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
4595
4794
  "div",
4596
4795
  {
4597
- className: concealed ? "kjun-data-concealed" : void 0,
4796
+ className: "kjun-data-content" + (concealed ? " kjun-data-concealed" : ""),
4598
4797
  "aria-hidden": concealed || void 0,
4599
4798
  inert: concealed || void 0,
4600
4799
  style: {
@@ -5368,9 +5567,18 @@ function tablePresentation(props, mobile) {
5368
5567
  }
5369
5568
  };
5370
5569
  }
5570
+ var warnedFormats = /* @__PURE__ */ new Set();
5571
+ function columnFormat(column) {
5572
+ if (typeof column.format === "function") return column.format;
5573
+ if (column.format != null && !warnedFormats.has(column.key)) {
5574
+ warnedFormats.add(column.key);
5575
+ console.warn(`KJUN Table: ${column.key} \uC5F4\uC758 format\uC740 \uD568\uC218\uC5EC\uC57C \uD569\uB2C8\uB2E4.`);
5576
+ }
5577
+ return void 0;
5578
+ }
5371
5579
  function tableCellValue(props, column, row, index) {
5372
5580
  const value = getValue(row, column.key);
5373
- const body = props.renderCell ? props.renderCell(value, column, row, index) : column.render ? column.render(value, row, index) : column.format ? column.format(value, row) : props.formatValue ? props.formatValue(value, column, row) : value == null ? "-" : typeof value === "number" && column.type === "number" ? new Intl.NumberFormat().format(value) : String(value);
5581
+ const body = props.renderCell ? props.renderCell(value, column, row, index) : column.render ? column.render(value, row, index) : columnFormat(column) ? columnFormat(column)(value, row) : props.formatValue ? props.formatValue(value, column, row) : value == null ? "-" : typeof value === "number" && column.type === "number" ? new Intl.NumberFormat().format(value) : String(value);
5374
5582
  return { value, body };
5375
5583
  }
5376
5584
 
@@ -5393,7 +5601,7 @@ function TableToolbar({
5393
5601
  selectable && selected.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
5394
5602
  "div",
5395
5603
  {
5396
- role: "toolbar",
5604
+ role: "group",
5397
5605
  "aria-label": "\uC120\uD0DD \uC791\uC5C5",
5398
5606
  className: "kjun-table-selection",
5399
5607
  children: [