@wipco/sdui 0.25.0 → 0.27.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.
@@ -1,137 +1,10 @@
1
+ import { useOverlayLayer, OverlayContainerContext, getOverlayRoot } from './chunk-XQPTSEJC.js';
1
2
  import { Icon } from './chunk-WIDDHR7L.js';
2
3
  import { boxed } from './chunk-SAN4IX6N.js';
3
- import React, { useState, useRef, useMemo, useEffect, useCallback, useLayoutEffect, useSyncExternalStore } from 'react';
4
- import { createPortal } from 'react-dom';
4
+ import React, { useState, useRef, useMemo, useEffect, useCallback, useLayoutEffect } from 'react';
5
5
  import { jsxs, jsx } from 'react/jsx-runtime';
6
+ import { createPortal } from 'react-dom';
6
7
 
7
- var OVERLAY_ROOT_ID = "wp-overlay-root";
8
- var DOCUMENT_POSITION_FOLLOWING = 4;
9
- function getOverlayRoot() {
10
- if (typeof document === "undefined") return null;
11
- const existing = document.getElementById(OVERLAY_ROOT_ID);
12
- if (existing) return existing;
13
- const created = document.createElement("div");
14
- created.id = OVERLAY_ROOT_ID;
15
- document.body.appendChild(created);
16
- return created;
17
- }
18
- var layers = [];
19
- var nextId = 0;
20
- var subscribers = /* @__PURE__ */ new Set();
21
- var keyListenerBound = false;
22
- function emit() {
23
- layers = layers.slice();
24
- subscribers.forEach((fn) => fn());
25
- }
26
- function topLayer(list) {
27
- let best;
28
- let bestNode = null;
29
- for (const layer of list) {
30
- const node = layer.node();
31
- if (!best) {
32
- best = layer;
33
- bestNode = node;
34
- continue;
35
- }
36
- if (!node) continue;
37
- if (!bestNode) {
38
- best = layer;
39
- bestNode = node;
40
- continue;
41
- }
42
- if (bestNode.compareDocumentPosition(node) & DOCUMENT_POSITION_FOLLOWING) {
43
- best = layer;
44
- bestNode = node;
45
- }
46
- }
47
- return best;
48
- }
49
- function layerHoldsTop(list, id) {
50
- const top = topLayer(list);
51
- if (!top) return false;
52
- if (top.id === id) return true;
53
- const mine = list.find((l) => l.id === id)?.node();
54
- const topNode = top.node();
55
- return !!mine && !!topNode && mine.contains(topNode);
56
- }
57
- function escapeTopmost() {
58
- topLayer(layers)?.onEscape();
59
- }
60
- function handleKeyDown(event) {
61
- if (event.key !== "Escape") return;
62
- escapeTopmost();
63
- }
64
- function push(layer) {
65
- layers.push(layer);
66
- if (!keyListenerBound && typeof document !== "undefined") {
67
- document.addEventListener("keydown", handleKeyDown);
68
- keyListenerBound = true;
69
- }
70
- emit();
71
- }
72
- function remove(id) {
73
- layers = layers.filter((l) => l.id !== id);
74
- emit();
75
- }
76
- function subscribe(fn) {
77
- subscribers.add(fn);
78
- return () => {
79
- subscribers.delete(fn);
80
- };
81
- }
82
- var snapshot = () => layers;
83
- var serverSnapshot = () => [];
84
- function useOverlayLayer(active, onEscape, nodeRef) {
85
- const idRef = useRef(0);
86
- if (idRef.current === 0) idRef.current = ++nextId;
87
- const escapeRef = useRef(onEscape);
88
- escapeRef.current = onEscape;
89
- const nodeRefRef = useRef(nodeRef);
90
- nodeRefRef.current = nodeRef;
91
- useEffect(() => {
92
- if (!active) return;
93
- const id2 = idRef.current;
94
- push({
95
- id: id2,
96
- onEscape: () => escapeRef.current?.(),
97
- node: () => nodeRefRef.current?.current ?? null
98
- });
99
- return () => remove(id2);
100
- }, [active]);
101
- const current = useSyncExternalStore(subscribe, snapshot, serverSnapshot);
102
- const id = idRef.current;
103
- return {
104
- isTop: active && topLayer(current)?.id === id,
105
- holdsTop: active && layerHoldsTop(current, id)
106
- };
107
- }
108
- var OverlayContainerContext = React.createContext(null);
109
- function OverlayLayer({
110
- onClose,
111
- children
112
- }) {
113
- const ref = useRef(null);
114
- const container = React.useContext(OverlayContainerContext);
115
- const { holdsTop } = useOverlayLayer(true, onClose, ref);
116
- useEffect(() => {
117
- ref.current?.toggleAttribute("inert", !holdsTop);
118
- }, [holdsTop]);
119
- const layer = /* @__PURE__ */ jsx(
120
- "div",
121
- {
122
- ref,
123
- className: "wp-overlay-layer",
124
- onClick: (event) => {
125
- if (onClose && event.target instanceof HTMLElement && event.target.classList.contains("wp-overlay")) {
126
- onClose();
127
- }
128
- },
129
- children
130
- }
131
- );
132
- const root = container ?? getOverlayRoot();
133
- return root ? createPortal(layer, root) : layer;
134
- }
135
8
  function HoistedStyle({ id, css }) {
136
9
  return /* @__PURE__ */ jsx("style", { href: id, precedence: "medium", children: css });
137
10
  }
@@ -357,7 +230,7 @@ function Calendar({
357
230
  const moveFocus = (next) => {
358
231
  onFocusDateChange(clampDate(next, minDate, maxDate));
359
232
  };
360
- const handleKeyDown2 = (event) => {
233
+ const handleKeyDown = (event) => {
361
234
  const deltaDays = event.key === "ArrowLeft" ? -1 : event.key === "ArrowRight" ? 1 : event.key === "ArrowUp" ? -7 : event.key === "ArrowDown" ? 7 : 0;
362
235
  if (deltaDays !== 0) {
363
236
  event.preventDefault();
@@ -375,7 +248,7 @@ function Calendar({
375
248
  moveFocus(addMonths(focusDate, event.key === "PageUp" ? -1 : 1));
376
249
  }
377
250
  };
378
- return /* @__PURE__ */ jsx("div", { className: "wp-dp", children: /* @__PURE__ */ jsxs("div", { className: "wp-dp__months", ref: gridRef, onKeyDown: handleKeyDown2, children: [
251
+ return /* @__PURE__ */ jsx("div", { className: "wp-dp", children: /* @__PURE__ */ jsxs("div", { className: "wp-dp__months", ref: gridRef, onKeyDown: handleKeyDown, children: [
379
252
  /* @__PURE__ */ jsxs("div", { className: "wp-dp__nav", children: [
380
253
  /* @__PURE__ */ jsx(
381
254
  "button",
@@ -553,7 +426,7 @@ function DatePickerImpl({
553
426
  }
554
427
  commit(next);
555
428
  };
556
- const handleKeyDown2 = (event) => {
429
+ const handleKeyDown = (event) => {
557
430
  if (event.key === "ArrowDown") {
558
431
  event.preventDefault();
559
432
  if (open) popRef.current?.querySelector('[tabindex="0"]')?.focus();
@@ -586,7 +459,7 @@ function DatePickerImpl({
586
459
  lead: true,
587
460
  expanded: open,
588
461
  onValueChange: handleTextChange,
589
- onKeyDown: handleKeyDown2,
462
+ onKeyDown: handleKeyDown,
590
463
  onPointerDown: () => {
591
464
  if (!disabled && !open) openCalendar(false);
592
465
  }
@@ -706,7 +579,7 @@ function DateRangePickerImpl({
706
579
  commit(fromDate && parsed.getTime() < fromDate.getTime() ? "" : fromValue, masked);
707
580
  }
708
581
  };
709
- const handleKeyDown2 = (which) => (event) => {
582
+ const handleKeyDown = (which) => (event) => {
710
583
  if (event.key === "ArrowDown") {
711
584
  event.preventDefault();
712
585
  if (open) popRef.current?.querySelector('[tabindex="0"]')?.focus();
@@ -761,7 +634,7 @@ function DateRangePickerImpl({
761
634
  expanded: open,
762
635
  ariaLabel: "\uC2DC\uC791\uC77C",
763
636
  onValueChange: (raw) => handleTextChange("from", raw),
764
- onKeyDown: handleKeyDown2("from"),
637
+ onKeyDown: handleKeyDown("from"),
765
638
  onFocus: () => setEnd("from"),
766
639
  onPointerDown: () => {
767
640
  if (!disabled && !open) openCalendar("from", false);
@@ -783,7 +656,7 @@ function DateRangePickerImpl({
783
656
  expanded: open,
784
657
  ariaLabel: "\uC885\uB8CC\uC77C",
785
658
  onValueChange: (raw) => handleTextChange("to", raw),
786
- onKeyDown: handleKeyDown2("to"),
659
+ onKeyDown: handleKeyDown("to"),
787
660
  onFocus: () => setEnd("to"),
788
661
  onPointerDown: () => {
789
662
  if (!disabled && !open) openCalendar("to", false);
@@ -872,4 +745,4 @@ var DP_CSS = `
872
745
  var DatePicker = boxed(DatePickerImpl, "DatePicker");
873
746
  var DateRangePicker = boxed(DateRangePickerImpl, "DateRangePicker");
874
747
 
875
- export { AnchoredPopoverStyles, DatePicker, DateRangePicker, HoistedStyle, OverlayContainerContext, OverlayLayer, anchorStyle, focusStaysInside, getOverlayRoot, useDismiss, useOverlayLayer, usePopoverAnchor, usePortalTo };
748
+ export { AnchoredPopoverStyles, DatePicker, DateRangePicker, HoistedStyle, anchorStyle, focusStaysInside, useDismiss, usePopoverAnchor, usePortalTo };
@@ -1,4 +1,4 @@
1
- import { DateRangePicker } from './chunk-XKLUCUVA.js';
1
+ import { DateRangePicker } from './chunk-EFMKWPZ3.js';
2
2
  import { SegmentedControl, Select } from './chunk-WIDDHR7L.js';
3
3
  import { boxed } from './chunk-SAN4IX6N.js';
4
4
  import { useState, useMemo } from 'react';
@@ -0,0 +1,39 @@
1
+ import { OverlayLayer } from './chunk-XQPTSEJC.js';
2
+ import { Dialog, warnOnce } from './chunk-WIDDHR7L.js';
3
+ import { createContext, useContext, useMemo } from 'react';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ var SduiDispatchContext = createContext(null);
7
+ function useSduiDispatch() {
8
+ const dispatch = useContext(SduiDispatchContext);
9
+ if (!dispatch) {
10
+ throw new Error("useSduiDispatch\uB294 SduiRenderer \uB0B4\uBD80\uC5D0\uC11C\uB9CC \uC0AC\uC6A9\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.");
11
+ }
12
+ return dispatch;
13
+ }
14
+ var ALLOW_ALL = () => true;
15
+ var DENY_ALL = () => false;
16
+ var MISSING = () => {
17
+ warnOnce(
18
+ "permission:missing",
19
+ '[sdui] \uAD8C\uD55C \uD310\uC815(can)\uC774 \uC8FC\uC785\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4 \u2014 <Can>\uC774 \uC804\uBD80 \uD1B5\uACFC\uD569\uB2C8\uB2E4. SduiRenderer\uC5D0 can \uCF5C\uBC31\uC744 \uB118\uAE30\uAC70\uB098, \uC138\uC158\uC774 \uC5C6\uB294 \uBBF8\uB9AC\uBCF4\uAE30\uB77C\uBA74 can="allow-all"\uC744 \uBA85\uC2DC\uD558\uC138\uC694.'
20
+ );
21
+ return true;
22
+ };
23
+ var SduiPermissionContext = createContext(null);
24
+ function SduiPermissionProvider({ can, children }) {
25
+ const value = useMemo(() => {
26
+ if (can === "allow-all") return ALLOW_ALL;
27
+ if (can === "deny-all") return DENY_ALL;
28
+ return typeof can === "function" ? can : null;
29
+ }, [can]);
30
+ return /* @__PURE__ */ jsx(SduiPermissionContext.Provider, { value, children });
31
+ }
32
+ function useSduiCan() {
33
+ return useContext(SduiPermissionContext) ?? MISSING;
34
+ }
35
+ function SduiDialog(props) {
36
+ return /* @__PURE__ */ jsx(OverlayLayer, { onClose: props.onClose, children: /* @__PURE__ */ jsx(Dialog, { ...props }) });
37
+ }
38
+
39
+ export { SduiDialog, SduiDispatchContext, SduiPermissionProvider, useSduiCan, useSduiDispatch };