@veritone-ce/design-system 2.7.2 → 2.7.4

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.
@@ -24,15 +24,24 @@ function _interopNamespaceDefault(e) {
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- function useDialog({ open, onDismiss: dismissDialog }) {
27
+ function useDialog({
28
+ open,
29
+ onDismiss: dismissDialog,
30
+ preventOutsideDismiss,
31
+ preventEscapeDismiss
32
+ }) {
28
33
  const [labelId, setLabelId] = React__namespace.useState();
29
34
  const [descriptionId, setDescriptionId] = React__namespace.useState();
30
35
  const data = react.useFloating({
31
36
  open,
32
- onOpenChange: (newOpen) => !newOpen && dismissDialog()
37
+ onOpenChange: (newOpen) => !newOpen && typeof dismissDialog === "function" && dismissDialog()
33
38
  });
34
39
  const context = data.context;
35
- const dismiss = react.useDismiss(context, { outsidePressEvent: "mousedown" });
40
+ const dismiss = react.useDismiss(context, {
41
+ outsidePressEvent: "mousedown",
42
+ outsidePress: !preventOutsideDismiss,
43
+ escapeKey: !preventEscapeDismiss
44
+ });
36
45
  const role = react.useRole(context);
37
46
  const interactions = react.useInteractions([dismiss, role]);
38
47
  return React__namespace.useMemo(
@@ -0,0 +1,160 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var vanilla = require('./vanilla.js');
6
+ var internals = require('./vanilla/internals.js');
7
+
8
+ const StoreContext = React.createContext(
9
+ void 0
10
+ );
11
+ function useStore(options) {
12
+ const store = React.useContext(StoreContext);
13
+ return store || vanilla.getDefaultStore();
14
+ }
15
+
16
+ const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
17
+ const attachPromiseStatus = (promise) => {
18
+ if (!promise.status) {
19
+ promise.status = "pending";
20
+ promise.then(
21
+ (v) => {
22
+ promise.status = "fulfilled";
23
+ promise.value = v;
24
+ },
25
+ (e) => {
26
+ promise.status = "rejected";
27
+ promise.reason = e;
28
+ }
29
+ );
30
+ }
31
+ };
32
+ const use = React.use || // A shim for older React versions
33
+ ((promise) => {
34
+ if (promise.status === "pending") {
35
+ throw promise;
36
+ } else if (promise.status === "fulfilled") {
37
+ return promise.value;
38
+ } else if (promise.status === "rejected") {
39
+ throw promise.reason;
40
+ } else {
41
+ attachPromiseStatus(promise);
42
+ throw promise;
43
+ }
44
+ });
45
+ const continuablePromiseMap = /* @__PURE__ */ new WeakMap();
46
+ const createContinuablePromise = (promise, getValue) => {
47
+ let continuablePromise = continuablePromiseMap.get(promise);
48
+ if (!continuablePromise) {
49
+ continuablePromise = new Promise((resolve, reject) => {
50
+ let curr = promise;
51
+ const onFulfilled = (me) => (v) => {
52
+ if (curr === me) {
53
+ resolve(v);
54
+ }
55
+ };
56
+ const onRejected = (me) => (e) => {
57
+ if (curr === me) {
58
+ reject(e);
59
+ }
60
+ };
61
+ const onAbort = () => {
62
+ try {
63
+ const nextValue = getValue();
64
+ if (isPromiseLike(nextValue)) {
65
+ continuablePromiseMap.set(nextValue, continuablePromise);
66
+ curr = nextValue;
67
+ nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
68
+ internals.INTERNAL_registerAbortHandler(nextValue, onAbort);
69
+ } else {
70
+ resolve(nextValue);
71
+ }
72
+ } catch (e) {
73
+ reject(e);
74
+ }
75
+ };
76
+ promise.then(onFulfilled(promise), onRejected(promise));
77
+ internals.INTERNAL_registerAbortHandler(promise, onAbort);
78
+ });
79
+ continuablePromiseMap.set(promise, continuablePromise);
80
+ }
81
+ return continuablePromise;
82
+ };
83
+ function useAtomValue(atom, options) {
84
+ const { delay, unstable_promiseStatus: promiseStatus = !React.use } = {};
85
+ const store = useStore();
86
+ const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = React.useReducer(
87
+ (prev) => {
88
+ const nextValue = store.get(atom);
89
+ if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
90
+ return prev;
91
+ }
92
+ return [nextValue, store, atom];
93
+ },
94
+ void 0,
95
+ () => [store.get(atom), store, atom]
96
+ );
97
+ let value = valueFromReducer;
98
+ if (storeFromReducer !== store || atomFromReducer !== atom) {
99
+ rerender();
100
+ value = store.get(atom);
101
+ }
102
+ React.useEffect(() => {
103
+ const unsub = store.sub(atom, () => {
104
+ if (promiseStatus) {
105
+ try {
106
+ const value2 = store.get(atom);
107
+ if (isPromiseLike(value2)) {
108
+ attachPromiseStatus(
109
+ createContinuablePromise(value2, () => store.get(atom))
110
+ );
111
+ }
112
+ } catch (e) {
113
+ }
114
+ }
115
+ if (typeof delay === "number") {
116
+ setTimeout(rerender, delay);
117
+ return;
118
+ }
119
+ rerender();
120
+ });
121
+ rerender();
122
+ return unsub;
123
+ }, [store, atom, delay, promiseStatus]);
124
+ React.useDebugValue(value);
125
+ if (isPromiseLike(value)) {
126
+ const promise = createContinuablePromise(value, () => store.get(atom));
127
+ if (promiseStatus) {
128
+ attachPromiseStatus(promise);
129
+ }
130
+ return use(promise);
131
+ }
132
+ return value;
133
+ }
134
+
135
+ function useSetAtom(atom, options) {
136
+ const store = useStore();
137
+ const setAtom = React.useCallback(
138
+ (...args) => {
139
+ if ((undefined ? undefined.MODE : void 0) !== "production" && !("write" in atom)) {
140
+ throw new Error("not writable atom");
141
+ }
142
+ return store.set(atom, ...args);
143
+ },
144
+ [store, atom]
145
+ );
146
+ return setAtom;
147
+ }
148
+
149
+ function useAtom(atom, options) {
150
+ return [
151
+ useAtomValue(atom),
152
+ // We do wrong type assertion here, which results in throwing an error.
153
+ useSetAtom(atom)
154
+ ];
155
+ }
156
+
157
+ exports.useAtom = useAtom;
158
+ exports.useAtomValue = useAtomValue;
159
+ exports.useSetAtom = useSetAtom;
160
+ exports.useStore = useStore;