@arc-ui/components 11.1.0 → 11.2.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.
@@ -0,0 +1,408 @@
1
+ import React__default, { createContext, useMemo, createElement, useContext, useCallback, forwardRef, Children, isValidElement, cloneElement, Fragment, useEffect, useRef, useLayoutEffect, useState } from 'react';
2
+ import { flushSync } from 'react-dom';
3
+
4
+ function _extends() {
5
+ _extends = Object.assign || function (target) {
6
+ for (var i = 1; i < arguments.length; i++) {
7
+ var source = arguments[i];
8
+
9
+ for (var key in source) {
10
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
11
+ target[key] = source[key];
12
+ }
13
+ }
14
+ }
15
+
16
+ return target;
17
+ };
18
+
19
+ return _extends.apply(this, arguments);
20
+ }
21
+
22
+ function $e42e1063c40fb3ef$export$b9ecd428b558ff10(originalEventHandler, ourEventHandler, { checkForDefaultPrevented: checkForDefaultPrevented = true } = {}) {
23
+ return function handleEvent(event) {
24
+ originalEventHandler === null || originalEventHandler === void 0 || originalEventHandler(event);
25
+ if (checkForDefaultPrevented === false || !event.defaultPrevented) return ourEventHandler === null || ourEventHandler === void 0 ? void 0 : ourEventHandler(event);
26
+ };
27
+ }
28
+
29
+ /* -------------------------------------------------------------------------------------------------
30
+ * createContextScope
31
+ * -----------------------------------------------------------------------------------------------*/ function $c512c27ab02ef895$export$50c7b4e9d9f19c1(scopeName, createContextScopeDeps = []) {
32
+ let defaultContexts = [];
33
+ /* -----------------------------------------------------------------------------------------------
34
+ * createContext
35
+ * ---------------------------------------------------------------------------------------------*/ function $c512c27ab02ef895$export$fd42f52fd3ae1109(rootComponentName, defaultContext) {
36
+ const BaseContext = /*#__PURE__*/ createContext(defaultContext);
37
+ const index = defaultContexts.length;
38
+ defaultContexts = [
39
+ ...defaultContexts,
40
+ defaultContext
41
+ ];
42
+ function Provider(props) {
43
+ const { scope: scope , children: children , ...context } = props;
44
+ const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index]) || BaseContext; // Only re-memoize when prop values change
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ const value = useMemo(()=>context
47
+ , Object.values(context));
48
+ return /*#__PURE__*/ createElement(Context.Provider, {
49
+ value: value
50
+ }, children);
51
+ }
52
+ function useContext$1(consumerName, scope) {
53
+ const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index]) || BaseContext;
54
+ const context = useContext(Context);
55
+ if (context) return context;
56
+ if (defaultContext !== undefined) return defaultContext; // if a defaultContext wasn't specified, it's a required context.
57
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
58
+ }
59
+ Provider.displayName = rootComponentName + 'Provider';
60
+ return [
61
+ Provider,
62
+ useContext$1
63
+ ];
64
+ }
65
+ /* -----------------------------------------------------------------------------------------------
66
+ * createScope
67
+ * ---------------------------------------------------------------------------------------------*/ const createScope = ()=>{
68
+ const scopeContexts = defaultContexts.map((defaultContext)=>{
69
+ return /*#__PURE__*/ createContext(defaultContext);
70
+ });
71
+ return function useScope(scope) {
72
+ const contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
73
+ return useMemo(()=>({
74
+ [`__scope${scopeName}`]: {
75
+ ...scope,
76
+ [scopeName]: contexts
77
+ }
78
+ })
79
+ , [
80
+ scope,
81
+ contexts
82
+ ]);
83
+ };
84
+ };
85
+ createScope.scopeName = scopeName;
86
+ return [
87
+ $c512c27ab02ef895$export$fd42f52fd3ae1109,
88
+ $c512c27ab02ef895$var$composeContextScopes(createScope, ...createContextScopeDeps)
89
+ ];
90
+ }
91
+ /* -------------------------------------------------------------------------------------------------
92
+ * composeContextScopes
93
+ * -----------------------------------------------------------------------------------------------*/ function $c512c27ab02ef895$var$composeContextScopes(...scopes) {
94
+ const baseScope = scopes[0];
95
+ if (scopes.length === 1) return baseScope;
96
+ const createScope1 = ()=>{
97
+ const scopeHooks = scopes.map((createScope)=>({
98
+ useScope: createScope(),
99
+ scopeName: createScope.scopeName
100
+ })
101
+ );
102
+ return function useComposedScopes(overrideScopes) {
103
+ const nextScopes1 = scopeHooks.reduce((nextScopes, { useScope: useScope , scopeName: scopeName })=>{
104
+ // We are calling a hook inside a callback which React warns against to avoid inconsistent
105
+ // renders, however, scoping doesn't have render side effects so we ignore the rule.
106
+ // eslint-disable-next-line react-hooks/rules-of-hooks
107
+ const scopeProps = useScope(overrideScopes);
108
+ const currentScope = scopeProps[`__scope${scopeName}`];
109
+ return {
110
+ ...nextScopes,
111
+ ...currentScope
112
+ };
113
+ }, {});
114
+ return useMemo(()=>({
115
+ [`__scope${baseScope.scopeName}`]: nextScopes1
116
+ })
117
+ , [
118
+ nextScopes1
119
+ ]);
120
+ };
121
+ };
122
+ createScope1.scopeName = baseScope.scopeName;
123
+ return createScope1;
124
+ }
125
+
126
+ /**
127
+ * Set a given ref to a given value
128
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
129
+ */ function $6ed0406888f73fc4$var$setRef(ref, value) {
130
+ if (typeof ref === 'function') ref(value);
131
+ else if (ref !== null && ref !== undefined) ref.current = value;
132
+ }
133
+ /**
134
+ * A utility to compose multiple refs together
135
+ * Accepts callback refs and RefObject(s)
136
+ */ function $6ed0406888f73fc4$export$43e446d32b3d21af(...refs) {
137
+ return (node)=>refs.forEach((ref)=>$6ed0406888f73fc4$var$setRef(ref, node)
138
+ )
139
+ ;
140
+ }
141
+ /**
142
+ * A custom hook that composes multiple refs
143
+ * Accepts callback refs and RefObject(s)
144
+ */ function $6ed0406888f73fc4$export$c7b2cbe3552a0d05(...refs) {
145
+ // eslint-disable-next-line react-hooks/exhaustive-deps
146
+ return useCallback($6ed0406888f73fc4$export$43e446d32b3d21af(...refs), refs);
147
+ }
148
+
149
+ /* -------------------------------------------------------------------------------------------------
150
+ * Slot
151
+ * -----------------------------------------------------------------------------------------------*/ const $5e63c961fc1ce211$export$8c6ed5c666ac1360 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
152
+ const { children: children , ...slotProps } = props;
153
+ const childrenArray = Children.toArray(children);
154
+ const slottable = childrenArray.find($5e63c961fc1ce211$var$isSlottable);
155
+ if (slottable) {
156
+ // the new element to render is the one passed as a child of `Slottable`
157
+ const newElement = slottable.props.children;
158
+ const newChildren = childrenArray.map((child)=>{
159
+ if (child === slottable) {
160
+ // because the new element will be the one rendered, we are only interested
161
+ // in grabbing its children (`newElement.props.children`)
162
+ if (Children.count(newElement) > 1) return Children.only(null);
163
+ return /*#__PURE__*/ isValidElement(newElement) ? newElement.props.children : null;
164
+ } else return child;
165
+ });
166
+ return /*#__PURE__*/ createElement($5e63c961fc1ce211$var$SlotClone, _extends({}, slotProps, {
167
+ ref: forwardedRef
168
+ }), /*#__PURE__*/ isValidElement(newElement) ? /*#__PURE__*/ cloneElement(newElement, undefined, newChildren) : null);
169
+ }
170
+ return /*#__PURE__*/ createElement($5e63c961fc1ce211$var$SlotClone, _extends({}, slotProps, {
171
+ ref: forwardedRef
172
+ }), children);
173
+ });
174
+ $5e63c961fc1ce211$export$8c6ed5c666ac1360.displayName = 'Slot';
175
+ /* -------------------------------------------------------------------------------------------------
176
+ * SlotClone
177
+ * -----------------------------------------------------------------------------------------------*/ const $5e63c961fc1ce211$var$SlotClone = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
178
+ const { children: children , ...slotProps } = props;
179
+ if (/*#__PURE__*/ isValidElement(children)) return /*#__PURE__*/ cloneElement(children, {
180
+ ...$5e63c961fc1ce211$var$mergeProps(slotProps, children.props),
181
+ ref: $6ed0406888f73fc4$export$43e446d32b3d21af(forwardedRef, children.ref)
182
+ });
183
+ return Children.count(children) > 1 ? Children.only(null) : null;
184
+ });
185
+ $5e63c961fc1ce211$var$SlotClone.displayName = 'SlotClone';
186
+ /* -------------------------------------------------------------------------------------------------
187
+ * Slottable
188
+ * -----------------------------------------------------------------------------------------------*/ const $5e63c961fc1ce211$export$d9f1ccf0bdb05d45 = ({ children: children })=>{
189
+ return /*#__PURE__*/ createElement(Fragment, null, children);
190
+ };
191
+ /* ---------------------------------------------------------------------------------------------- */ function $5e63c961fc1ce211$var$isSlottable(child) {
192
+ return /*#__PURE__*/ isValidElement(child) && child.type === $5e63c961fc1ce211$export$d9f1ccf0bdb05d45;
193
+ }
194
+ function $5e63c961fc1ce211$var$mergeProps(slotProps, childProps) {
195
+ // all child props should override
196
+ const overrideProps = {
197
+ ...childProps
198
+ };
199
+ for(const propName in childProps){
200
+ const slotPropValue = slotProps[propName];
201
+ const childPropValue = childProps[propName];
202
+ const isHandler = /^on[A-Z]/.test(propName);
203
+ if (isHandler) {
204
+ // if the handler exists on both, we compose them
205
+ if (slotPropValue && childPropValue) overrideProps[propName] = (...args)=>{
206
+ childPropValue(...args);
207
+ slotPropValue(...args);
208
+ };
209
+ else if (slotPropValue) overrideProps[propName] = slotPropValue;
210
+ } else if (propName === 'style') overrideProps[propName] = {
211
+ ...slotPropValue,
212
+ ...childPropValue
213
+ };
214
+ else if (propName === 'className') overrideProps[propName] = [
215
+ slotPropValue,
216
+ childPropValue
217
+ ].filter(Boolean).join(' ');
218
+ }
219
+ return {
220
+ ...slotProps,
221
+ ...overrideProps
222
+ };
223
+ }
224
+
225
+ const $8927f6f2acc4f386$var$NODES = [
226
+ 'a',
227
+ 'button',
228
+ 'div',
229
+ 'h2',
230
+ 'h3',
231
+ 'img',
232
+ 'label',
233
+ 'li',
234
+ 'nav',
235
+ 'ol',
236
+ 'p',
237
+ 'span',
238
+ 'svg',
239
+ 'ul'
240
+ ]; // Temporary while we await merge of this fix:
241
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396
242
+ // prettier-ignore
243
+ /* -------------------------------------------------------------------------------------------------
244
+ * Primitive
245
+ * -----------------------------------------------------------------------------------------------*/ const $8927f6f2acc4f386$export$250ffa63cdc0d034 = $8927f6f2acc4f386$var$NODES.reduce((primitive, node)=>{
246
+ const Node = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
247
+ const { asChild: asChild , ...primitiveProps } = props;
248
+ const Comp = asChild ? $5e63c961fc1ce211$export$8c6ed5c666ac1360 : node;
249
+ useEffect(()=>{
250
+ window[Symbol.for('radix-ui')] = true;
251
+ }, []);
252
+ return /*#__PURE__*/ createElement(Comp, _extends({}, primitiveProps, {
253
+ ref: forwardedRef
254
+ }));
255
+ });
256
+ Node.displayName = `Primitive.${node}`;
257
+ return {
258
+ ...primitive,
259
+ [node]: Node
260
+ };
261
+ }, {});
262
+ /* -------------------------------------------------------------------------------------------------
263
+ * Utils
264
+ * -----------------------------------------------------------------------------------------------*/ /**
265
+ * Flush custom event dispatch
266
+ * https://github.com/radix-ui/primitives/pull/1378
267
+ *
268
+ * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
269
+ *
270
+ * Internally, React prioritises events in the following order:
271
+ * - discrete
272
+ * - continuous
273
+ * - default
274
+ *
275
+ * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
276
+ *
277
+ * `discrete` is an important distinction as updates within these events are applied immediately.
278
+ * React however, is not able to infer the priority of custom event types due to how they are detected internally.
279
+ * Because of this, it's possible for updates from custom events to be unexpectedly batched when
280
+ * dispatched by another `discrete` event.
281
+ *
282
+ * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
283
+ * This utility should be used when dispatching a custom event from within another `discrete` event, this utility
284
+ * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
285
+ * For example:
286
+ *
287
+ * dispatching a known click 👎
288
+ * target.dispatchEvent(new Event(‘click’))
289
+ *
290
+ * dispatching a custom type within a non-discrete event 👎
291
+ * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
292
+ *
293
+ * dispatching a custom type within a `discrete` event 👍
294
+ * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
295
+ *
296
+ * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
297
+ * this utility with them. This is because it's possible for those handlers to be called implicitly during render
298
+ * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
299
+ */ function $8927f6f2acc4f386$export$6d1a0317bde7de7f(target, event) {
300
+ if (target) flushSync(()=>target.dispatchEvent(event)
301
+ );
302
+ }
303
+
304
+ /**
305
+ * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
306
+ * prop or avoid re-executing effects when passed as a dependency
307
+ */ function $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(callback) {
308
+ const callbackRef = useRef(callback);
309
+ useEffect(()=>{
310
+ callbackRef.current = callback;
311
+ }); // https://github.com/facebook/react/issues/19240
312
+ return useMemo(()=>(...args)=>{
313
+ var _callbackRef$current;
314
+ return (_callbackRef$current = callbackRef.current) === null || _callbackRef$current === void 0 ? void 0 : _callbackRef$current.call(callbackRef, ...args);
315
+ }
316
+ , []);
317
+ }
318
+
319
+ /**
320
+ * On the server, React emits a warning when calling `useLayoutEffect`.
321
+ * This is because neither `useLayoutEffect` nor `useEffect` run on the server.
322
+ * We use this safe version which suppresses the warning by replacing it with a noop on the server.
323
+ *
324
+ * See: https://reactjs.org/docs/hooks-reference.html#uselayouteffect
325
+ */ const $9f79659886946c16$export$e5c5a5f917a5871c = Boolean(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) ? useLayoutEffect : ()=>{};
326
+
327
+ function $71cd76cc60e0454e$export$6f32135080cb4c3({ prop: prop , defaultProp: defaultProp , onChange: onChange = ()=>{} }) {
328
+ const [uncontrolledProp, setUncontrolledProp] = $71cd76cc60e0454e$var$useUncontrolledState({
329
+ defaultProp: defaultProp,
330
+ onChange: onChange
331
+ });
332
+ const isControlled = prop !== undefined;
333
+ const value1 = isControlled ? prop : uncontrolledProp;
334
+ const handleChange = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onChange);
335
+ const setValue = useCallback((nextValue)=>{
336
+ if (isControlled) {
337
+ const setter = nextValue;
338
+ const value = typeof nextValue === 'function' ? setter(prop) : nextValue;
339
+ if (value !== prop) handleChange(value);
340
+ } else setUncontrolledProp(nextValue);
341
+ }, [
342
+ isControlled,
343
+ prop,
344
+ setUncontrolledProp,
345
+ handleChange
346
+ ]);
347
+ return [
348
+ value1,
349
+ setValue
350
+ ];
351
+ }
352
+ function $71cd76cc60e0454e$var$useUncontrolledState({ defaultProp: defaultProp , onChange: onChange }) {
353
+ const uncontrolledState = useState(defaultProp);
354
+ const [value] = uncontrolledState;
355
+ const prevValueRef = useRef(value);
356
+ const handleChange = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onChange);
357
+ useEffect(()=>{
358
+ if (prevValueRef.current !== value) {
359
+ handleChange(value);
360
+ prevValueRef.current = value;
361
+ }
362
+ }, [
363
+ value,
364
+ prevValueRef,
365
+ handleChange
366
+ ]);
367
+ return uncontrolledState;
368
+ }
369
+
370
+ function $010c2913dbd2fe3d$export$5cae361ad82dce8b(value) {
371
+ const ref = useRef({
372
+ value: value,
373
+ previous: value
374
+ }); // We compare values before making an update to ensure that
375
+ // a change has been made. This ensures the previous value is
376
+ // persisted correctly between renders.
377
+ return useMemo(()=>{
378
+ if (ref.current.value !== value) {
379
+ ref.current.previous = ref.current.value;
380
+ ref.current.value = value;
381
+ }
382
+ return ref.current.previous;
383
+ }, [
384
+ value
385
+ ]);
386
+ }
387
+
388
+ const React = React__default;
389
+ const BtIconTickAlt2Px = props =>
390
+ /*#__PURE__*/ React.createElement(
391
+ "svg",
392
+ Object.assign(
393
+ {
394
+ xmlns: "http://www.w3.org/2000/svg",
395
+ viewBox: "0 0 32 32"
396
+ },
397
+ props
398
+ ),
399
+ /*#__PURE__*/ React.createElement("defs", null),
400
+ /*#__PURE__*/ React.createElement("path", {
401
+ d:
402
+ "M13.49963,21.91418l-4.707-4.707a1.0014,1.0014,0,0,1,0-1.41406,1.02353,1.02353,0,0,1,1.41406,0l3.293,3.293,8.293-8.293a.99989.99989,0,1,1,1.41406,1.41406Z",
403
+ fill: "currentColor"
404
+ })
405
+ );
406
+ var BtIconTickAlt2Px_2 = BtIconTickAlt2Px;
407
+
408
+ export { $c512c27ab02ef895$export$50c7b4e9d9f19c1 as $, BtIconTickAlt2Px_2 as B, _extends as _, $6ed0406888f73fc4$export$c7b2cbe3552a0d05 as a, $5e63c961fc1ce211$export$8c6ed5c666ac1360 as b, $b1b2314f5f9a1d84$export$25bec8c6f54ee79a as c, $8927f6f2acc4f386$export$250ffa63cdc0d034 as d, $e42e1063c40fb3ef$export$b9ecd428b558ff10 as e, $8927f6f2acc4f386$export$6d1a0317bde7de7f as f, $9f79659886946c16$export$e5c5a5f917a5871c as g, $71cd76cc60e0454e$export$6f32135080cb4c3 as h, $010c2913dbd2fe3d$export$5cae361ad82dce8b as i };
@@ -0,0 +1,18 @@
1
+ import { FC } from "react";
2
+ /**
3
+ * Use `VerticalSpace` to create vertical space between components.
4
+ */
5
+ declare const VerticalSpace: FC<VerticalSpaceProps>;
6
+ type VerticalSpaceSize = "4" | "8" | "12" | "16" | "24" | "32" | "48" | "64" | "96" | "128";
7
+ interface VerticalSpaceProps {
8
+ /**
9
+ * Should the VerticalSpace be visible for debugging and documentation
10
+ * purposes?
11
+ */
12
+ isDebugVisible?: boolean;
13
+ /**
14
+ * Size of the VerticalSpace.
15
+ */
16
+ size?: VerticalSpaceSize;
17
+ }
18
+ export { VerticalSpace, VerticalSpaceSize, VerticalSpaceProps };
@@ -0,0 +1,19 @@
1
+ import { _ as __rest, a as __assign, f as filterDataAttrs } from './index-229fc864.js';
2
+ import { c as classNames } from './index-2ae58626.js';
3
+ import React__default from 'react';
4
+
5
+ /**
6
+ * Use `VerticalSpace` to create vertical space between components.
7
+ */
8
+ var VerticalSpace = function (_a) {
9
+ var _b;
10
+ var _c = _a.isDebugVisible, isDebugVisible = _c === void 0 ? false : _c, _d = _a.size, size = _d === void 0 ? "24" : _d, props = __rest(_a, ["isDebugVisible", "size"]);
11
+ return (React__default.createElement("div", __assign({ className: classNames((_b = {
12
+ "arc-VerticalSpace": true
13
+ },
14
+ _b["arc-VerticalSpace--size".concat(size)] = size && size !== "24",
15
+ _b["arc-VerticalSpace--debugVisible"] = isDebugVisible,
16
+ _b)) }, filterDataAttrs(props))));
17
+ };
18
+
19
+ export { VerticalSpace as V };