@arun-dev/headless 4.13.0 → 4.15.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/avatar/index.cjs +218 -0
- package/dist/avatar/index.d.cts +52 -0
- package/dist/avatar/index.d.ts +52 -0
- package/dist/avatar/index.js +105 -0
- package/dist/chunk-36N5DD5K.js +78 -0
- package/dist/chunk-E4JBFRMM.js +11 -0
- package/dist/chunk-ETNICT5M.js +8 -0
- package/dist/combobox/index.cjs +3 -1
- package/dist/combobox/index.js +6 -6
- package/dist/menu/index.cjs +311 -19
- package/dist/menu/index.d.cts +144 -10
- package/dist/menu/index.d.ts +144 -10
- package/dist/menu/index.js +310 -22
- package/dist/rovingFocus-BZB3yicE.d.cts +11 -0
- package/dist/rovingFocus-BZB3yicE.d.ts +11 -0
- package/dist/tabs/index.d.cts +1 -10
- package/dist/tabs/index.d.ts +1 -10
- package/dist/toggle/index.cjs +232 -0
- package/dist/toggle/index.d.cts +26 -0
- package/dist/toggle/index.d.ts +26 -0
- package/dist/toggle/index.js +68 -0
- package/dist/toggle-group/index.cjs +292 -0
- package/dist/toggle-group/index.d.cts +31 -0
- package/dist/toggle-group/index.d.ts +31 -0
- package/dist/toggle-group/index.js +68 -0
- package/dist/toolbar/index.cjs +357 -0
- package/dist/toolbar/index.d.cts +89 -0
- package/dist/toolbar/index.d.ts +89 -0
- package/dist/toolbar/index.js +152 -0
- package/package.json +41 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/avatar/index.ts
|
|
21
|
+
var avatar_exports = {};
|
|
22
|
+
__export(avatar_exports, {
|
|
23
|
+
Avatar: () => index_parts_exports
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(avatar_exports);
|
|
26
|
+
|
|
27
|
+
// src/avatar/index.parts.ts
|
|
28
|
+
var index_parts_exports = {};
|
|
29
|
+
__export(index_parts_exports, {
|
|
30
|
+
Fallback: () => AvatarFallback,
|
|
31
|
+
Image: () => AvatarImage,
|
|
32
|
+
Root: () => AvatarRoot
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// src/avatar/AvatarRoot.tsx
|
|
36
|
+
var import_react2 = require("react");
|
|
37
|
+
|
|
38
|
+
// src/core/useRender.ts
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
|
|
41
|
+
// src/core/mergeProps.ts
|
|
42
|
+
function isEventHandler(key) {
|
|
43
|
+
return key.length > 2 && key.startsWith("on") && key[2] === key[2]?.toUpperCase();
|
|
44
|
+
}
|
|
45
|
+
function mergeRefs(...refs) {
|
|
46
|
+
return (node) => {
|
|
47
|
+
const cleanups = refs.map((ref) => {
|
|
48
|
+
if (typeof ref === "function") {
|
|
49
|
+
const result = ref(node);
|
|
50
|
+
return typeof result === "function" ? result : () => ref(null);
|
|
51
|
+
}
|
|
52
|
+
if (ref && typeof ref === "object") {
|
|
53
|
+
ref.current = node;
|
|
54
|
+
return () => {
|
|
55
|
+
ref.current = null;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
});
|
|
60
|
+
return () => {
|
|
61
|
+
cleanups.forEach((cleanup) => {
|
|
62
|
+
if (typeof cleanup === "function") cleanup();
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function isSyntheticEvent(event) {
|
|
68
|
+
return typeof event === "object" && event !== null && "nativeEvent" in event;
|
|
69
|
+
}
|
|
70
|
+
function makeEventPreventable(event) {
|
|
71
|
+
if (Object.prototype.hasOwnProperty.call(event, "preventComponentHandler")) return;
|
|
72
|
+
const target = event;
|
|
73
|
+
target.preventComponentHandler = () => {
|
|
74
|
+
target.componentHandlerPrevented = true;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function isComponentHandlerPrevented(event) {
|
|
78
|
+
return typeof event === "object" && event !== null && event.componentHandlerPrevented === true;
|
|
79
|
+
}
|
|
80
|
+
function chainHandlers(earlier, value) {
|
|
81
|
+
return (...args) => {
|
|
82
|
+
const event = args[0];
|
|
83
|
+
if (isSyntheticEvent(event)) makeEventPreventable(event);
|
|
84
|
+
value(...args);
|
|
85
|
+
if (isComponentHandlerPrevented(event)) return;
|
|
86
|
+
earlier(...args);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function mergeProps(...objects) {
|
|
90
|
+
const merged = {};
|
|
91
|
+
for (const props of objects) {
|
|
92
|
+
if (!props) continue;
|
|
93
|
+
for (const key of Object.keys(props)) {
|
|
94
|
+
const value = props[key];
|
|
95
|
+
if (value === void 0) continue;
|
|
96
|
+
if (isEventHandler(key) && typeof value === "function") {
|
|
97
|
+
const earlier = merged[key];
|
|
98
|
+
merged[key] = typeof earlier === "function" ? chainHandlers(earlier, value) : value;
|
|
99
|
+
} else if (key === "className") {
|
|
100
|
+
merged.className = merged.className ? `${String(merged.className)} ${String(value)}` : value;
|
|
101
|
+
} else if (key === "style") {
|
|
102
|
+
merged.style = { ...merged.style, ...value };
|
|
103
|
+
} else if (key === "ref") {
|
|
104
|
+
merged.ref = merged.ref ? mergeRefs(merged.ref, value) : value;
|
|
105
|
+
} else {
|
|
106
|
+
merged[key] = value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return merged;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/core/useRender.ts
|
|
114
|
+
function useRender({
|
|
115
|
+
render,
|
|
116
|
+
defaultTagName,
|
|
117
|
+
props,
|
|
118
|
+
consumerProps
|
|
119
|
+
}) {
|
|
120
|
+
const merged = mergeProps(props, consumerProps);
|
|
121
|
+
if ((0, import_react.isValidElement)(render)) {
|
|
122
|
+
return (0, import_react.cloneElement)(render, mergeProps(merged, render.props));
|
|
123
|
+
}
|
|
124
|
+
return (0, import_react.createElement)(defaultTagName, merged);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/avatar/AvatarRoot.tsx
|
|
128
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
129
|
+
var AvatarContext = (0, import_react2.createContext)(null);
|
|
130
|
+
function useAvatarContext(part) {
|
|
131
|
+
const context = (0, import_react2.useContext)(AvatarContext);
|
|
132
|
+
if (!context) throw new Error(`<Avatar.${part}> must be rendered inside <Avatar.Root>.`);
|
|
133
|
+
return context;
|
|
134
|
+
}
|
|
135
|
+
function AvatarRoot({ className, children, render, ...rest }) {
|
|
136
|
+
const [status, setStatus] = (0, import_react2.useState)("idle");
|
|
137
|
+
const context = (0, import_react2.useMemo)(() => ({ status, setStatus }), [status]);
|
|
138
|
+
const element = useRender({
|
|
139
|
+
render,
|
|
140
|
+
defaultTagName: "span",
|
|
141
|
+
props: { "data-image-status": status, className, children },
|
|
142
|
+
consumerProps: rest
|
|
143
|
+
});
|
|
144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarContext.Provider, { value: context, children: element });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/avatar/AvatarImage.tsx
|
|
148
|
+
var import_react3 = require("react");
|
|
149
|
+
function AvatarImage({
|
|
150
|
+
src,
|
|
151
|
+
srcSet,
|
|
152
|
+
sizes,
|
|
153
|
+
crossOrigin,
|
|
154
|
+
referrerPolicy,
|
|
155
|
+
className,
|
|
156
|
+
render,
|
|
157
|
+
...rest
|
|
158
|
+
}) {
|
|
159
|
+
const { status, setStatus } = useAvatarContext("Image");
|
|
160
|
+
(0, import_react3.useLayoutEffect)(() => {
|
|
161
|
+
if (!src && !srcSet) {
|
|
162
|
+
setStatus("error");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
let active = true;
|
|
166
|
+
const image = new window.Image();
|
|
167
|
+
const settle = (next) => () => {
|
|
168
|
+
if (active) setStatus(next);
|
|
169
|
+
};
|
|
170
|
+
image.onload = settle("loaded");
|
|
171
|
+
image.onerror = settle("error");
|
|
172
|
+
if (crossOrigin !== void 0) image.crossOrigin = crossOrigin;
|
|
173
|
+
if (referrerPolicy) image.referrerPolicy = referrerPolicy;
|
|
174
|
+
if (sizes) image.sizes = sizes;
|
|
175
|
+
if (srcSet) image.srcset = srcSet;
|
|
176
|
+
if (src) image.src = src;
|
|
177
|
+
setStatus(image.complete && image.naturalWidth > 0 ? "loaded" : "loading");
|
|
178
|
+
return () => {
|
|
179
|
+
active = false;
|
|
180
|
+
};
|
|
181
|
+
}, [src, srcSet, sizes, crossOrigin, referrerPolicy, setStatus]);
|
|
182
|
+
const element = useRender({
|
|
183
|
+
render,
|
|
184
|
+
defaultTagName: "img",
|
|
185
|
+
props: { src, srcSet, sizes, crossOrigin, referrerPolicy, className },
|
|
186
|
+
consumerProps: rest
|
|
187
|
+
});
|
|
188
|
+
return status === "loaded" ? element : null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/avatar/AvatarFallback.tsx
|
|
192
|
+
var import_react4 = require("react");
|
|
193
|
+
function AvatarFallback({
|
|
194
|
+
delay = 0,
|
|
195
|
+
className,
|
|
196
|
+
children,
|
|
197
|
+
render,
|
|
198
|
+
...rest
|
|
199
|
+
}) {
|
|
200
|
+
const { status } = useAvatarContext("Fallback");
|
|
201
|
+
const [waited, setWaited] = (0, import_react4.useState)(delay === 0);
|
|
202
|
+
(0, import_react4.useEffect)(() => {
|
|
203
|
+
if (delay === 0) return;
|
|
204
|
+
const timer = setTimeout(() => setWaited(true), delay);
|
|
205
|
+
return () => clearTimeout(timer);
|
|
206
|
+
}, [delay]);
|
|
207
|
+
const element = useRender({
|
|
208
|
+
render,
|
|
209
|
+
defaultTagName: "span",
|
|
210
|
+
props: { className, children },
|
|
211
|
+
consumerProps: rest
|
|
212
|
+
});
|
|
213
|
+
return status !== "loaded" && waited ? element : null;
|
|
214
|
+
}
|
|
215
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
216
|
+
0 && (module.exports = {
|
|
217
|
+
Avatar
|
|
218
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactElement, Ref, ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Where the Image is: none yet, on its way, shown, or failed for good. */
|
|
5
|
+
type AvatarImageStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
6
|
+
type AvatarRootOwnProps = {
|
|
7
|
+
/** Element to render instead of the default `<span>`. Props and ref are merged onto it. */
|
|
8
|
+
render?: ReactElement;
|
|
9
|
+
/** Ref to the rendered element. Merged with any ref on the `render` element. */
|
|
10
|
+
ref?: Ref<HTMLElement>;
|
|
11
|
+
};
|
|
12
|
+
type AvatarRootProps = AvatarRootOwnProps & Omit<ComponentPropsWithRef<'span'>, keyof AvatarRootOwnProps>;
|
|
13
|
+
/**
|
|
14
|
+
* A person's picture, or their initials until it loads (decision 17). Holds whether the Image
|
|
15
|
+
* has loaded; `data-image-status` carries it for styling.
|
|
16
|
+
*/
|
|
17
|
+
declare function AvatarRoot({ className, children, render, ...rest }: AvatarRootProps): react.JSX.Element;
|
|
18
|
+
|
|
19
|
+
type AvatarImageOwnProps = {
|
|
20
|
+
/** Element to render instead of the default `<img>`. Props and ref are merged onto it. */
|
|
21
|
+
render?: ReactElement;
|
|
22
|
+
/** Ref to the rendered element. Merged with any ref on the `render` element. */
|
|
23
|
+
ref?: Ref<HTMLElement>;
|
|
24
|
+
};
|
|
25
|
+
type AvatarImageProps = AvatarImageOwnProps & Omit<ComponentPropsWithRef<'img'>, keyof AvatarImageOwnProps>;
|
|
26
|
+
/**
|
|
27
|
+
* The picture. Loaded off-screen first, and rendered only once it has loaded, so a broken
|
|
28
|
+
* image never shows — the Fallback does instead. Give it an `alt`: the person's name.
|
|
29
|
+
*/
|
|
30
|
+
declare function AvatarImage({ src, srcSet, sizes, crossOrigin, referrerPolicy, className, render, ...rest }: AvatarImageProps): ReactElement<unknown, string | react.JSXElementConstructor<any>> | null;
|
|
31
|
+
|
|
32
|
+
type AvatarFallbackOwnProps = {
|
|
33
|
+
/** Milliseconds to wait before showing, so a quick image does not flash the initials first. */
|
|
34
|
+
delay?: number;
|
|
35
|
+
/** Element to render instead of the default `<span>`. Props and ref are merged onto it. */
|
|
36
|
+
render?: ReactElement;
|
|
37
|
+
/** Ref to the rendered element. Merged with any ref on the `render` element. */
|
|
38
|
+
ref?: Ref<HTMLElement>;
|
|
39
|
+
};
|
|
40
|
+
type AvatarFallbackProps = AvatarFallbackOwnProps & Omit<ComponentPropsWithRef<'span'>, keyof AvatarFallbackOwnProps>;
|
|
41
|
+
/**
|
|
42
|
+
* Initials or an icon, shown until the Image loads, and for good if it fails or there is none.
|
|
43
|
+
* Initials read out as letters; give the Root an `aria-label` with the name, or mark these
|
|
44
|
+
* `aria-hidden` beside a visible name.
|
|
45
|
+
*/
|
|
46
|
+
declare function AvatarFallback({ delay, className, children, render, ...rest }: AvatarFallbackProps): ReactElement<unknown, string | react.JSXElementConstructor<any>> | null;
|
|
47
|
+
|
|
48
|
+
declare namespace index_parts {
|
|
49
|
+
export { AvatarFallback as Fallback, AvatarImage as Image, AvatarRoot as Root };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { index_parts as Avatar, type AvatarFallbackProps, type AvatarImageProps, type AvatarImageStatus, type AvatarRootProps };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactElement, Ref, ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Where the Image is: none yet, on its way, shown, or failed for good. */
|
|
5
|
+
type AvatarImageStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
6
|
+
type AvatarRootOwnProps = {
|
|
7
|
+
/** Element to render instead of the default `<span>`. Props and ref are merged onto it. */
|
|
8
|
+
render?: ReactElement;
|
|
9
|
+
/** Ref to the rendered element. Merged with any ref on the `render` element. */
|
|
10
|
+
ref?: Ref<HTMLElement>;
|
|
11
|
+
};
|
|
12
|
+
type AvatarRootProps = AvatarRootOwnProps & Omit<ComponentPropsWithRef<'span'>, keyof AvatarRootOwnProps>;
|
|
13
|
+
/**
|
|
14
|
+
* A person's picture, or their initials until it loads (decision 17). Holds whether the Image
|
|
15
|
+
* has loaded; `data-image-status` carries it for styling.
|
|
16
|
+
*/
|
|
17
|
+
declare function AvatarRoot({ className, children, render, ...rest }: AvatarRootProps): react.JSX.Element;
|
|
18
|
+
|
|
19
|
+
type AvatarImageOwnProps = {
|
|
20
|
+
/** Element to render instead of the default `<img>`. Props and ref are merged onto it. */
|
|
21
|
+
render?: ReactElement;
|
|
22
|
+
/** Ref to the rendered element. Merged with any ref on the `render` element. */
|
|
23
|
+
ref?: Ref<HTMLElement>;
|
|
24
|
+
};
|
|
25
|
+
type AvatarImageProps = AvatarImageOwnProps & Omit<ComponentPropsWithRef<'img'>, keyof AvatarImageOwnProps>;
|
|
26
|
+
/**
|
|
27
|
+
* The picture. Loaded off-screen first, and rendered only once it has loaded, so a broken
|
|
28
|
+
* image never shows — the Fallback does instead. Give it an `alt`: the person's name.
|
|
29
|
+
*/
|
|
30
|
+
declare function AvatarImage({ src, srcSet, sizes, crossOrigin, referrerPolicy, className, render, ...rest }: AvatarImageProps): ReactElement<unknown, string | react.JSXElementConstructor<any>> | null;
|
|
31
|
+
|
|
32
|
+
type AvatarFallbackOwnProps = {
|
|
33
|
+
/** Milliseconds to wait before showing, so a quick image does not flash the initials first. */
|
|
34
|
+
delay?: number;
|
|
35
|
+
/** Element to render instead of the default `<span>`. Props and ref are merged onto it. */
|
|
36
|
+
render?: ReactElement;
|
|
37
|
+
/** Ref to the rendered element. Merged with any ref on the `render` element. */
|
|
38
|
+
ref?: Ref<HTMLElement>;
|
|
39
|
+
};
|
|
40
|
+
type AvatarFallbackProps = AvatarFallbackOwnProps & Omit<ComponentPropsWithRef<'span'>, keyof AvatarFallbackOwnProps>;
|
|
41
|
+
/**
|
|
42
|
+
* Initials or an icon, shown until the Image loads, and for good if it fails or there is none.
|
|
43
|
+
* Initials read out as letters; give the Root an `aria-label` with the name, or mark these
|
|
44
|
+
* `aria-hidden` beside a visible name.
|
|
45
|
+
*/
|
|
46
|
+
declare function AvatarFallback({ delay, className, children, render, ...rest }: AvatarFallbackProps): ReactElement<unknown, string | react.JSXElementConstructor<any>> | null;
|
|
47
|
+
|
|
48
|
+
declare namespace index_parts {
|
|
49
|
+
export { AvatarFallback as Fallback, AvatarImage as Image, AvatarRoot as Root };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { index_parts as Avatar, type AvatarFallbackProps, type AvatarImageProps, type AvatarImageStatus, type AvatarRootProps };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export,
|
|
3
|
+
useRender
|
|
4
|
+
} from "../chunk-OQTWWZ4B.js";
|
|
5
|
+
|
|
6
|
+
// src/avatar/index.parts.ts
|
|
7
|
+
var index_parts_exports = {};
|
|
8
|
+
__export(index_parts_exports, {
|
|
9
|
+
Fallback: () => AvatarFallback,
|
|
10
|
+
Image: () => AvatarImage,
|
|
11
|
+
Root: () => AvatarRoot
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// src/avatar/AvatarRoot.tsx
|
|
15
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
var AvatarContext = createContext(null);
|
|
18
|
+
function useAvatarContext(part) {
|
|
19
|
+
const context = useContext(AvatarContext);
|
|
20
|
+
if (!context) throw new Error(`<Avatar.${part}> must be rendered inside <Avatar.Root>.`);
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
function AvatarRoot({ className, children, render, ...rest }) {
|
|
24
|
+
const [status, setStatus] = useState("idle");
|
|
25
|
+
const context = useMemo(() => ({ status, setStatus }), [status]);
|
|
26
|
+
const element = useRender({
|
|
27
|
+
render,
|
|
28
|
+
defaultTagName: "span",
|
|
29
|
+
props: { "data-image-status": status, className, children },
|
|
30
|
+
consumerProps: rest
|
|
31
|
+
});
|
|
32
|
+
return /* @__PURE__ */ jsx(AvatarContext.Provider, { value: context, children: element });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/avatar/AvatarImage.tsx
|
|
36
|
+
import { useLayoutEffect } from "react";
|
|
37
|
+
function AvatarImage({
|
|
38
|
+
src,
|
|
39
|
+
srcSet,
|
|
40
|
+
sizes,
|
|
41
|
+
crossOrigin,
|
|
42
|
+
referrerPolicy,
|
|
43
|
+
className,
|
|
44
|
+
render,
|
|
45
|
+
...rest
|
|
46
|
+
}) {
|
|
47
|
+
const { status, setStatus } = useAvatarContext("Image");
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
if (!src && !srcSet) {
|
|
50
|
+
setStatus("error");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let active = true;
|
|
54
|
+
const image = new window.Image();
|
|
55
|
+
const settle = (next) => () => {
|
|
56
|
+
if (active) setStatus(next);
|
|
57
|
+
};
|
|
58
|
+
image.onload = settle("loaded");
|
|
59
|
+
image.onerror = settle("error");
|
|
60
|
+
if (crossOrigin !== void 0) image.crossOrigin = crossOrigin;
|
|
61
|
+
if (referrerPolicy) image.referrerPolicy = referrerPolicy;
|
|
62
|
+
if (sizes) image.sizes = sizes;
|
|
63
|
+
if (srcSet) image.srcset = srcSet;
|
|
64
|
+
if (src) image.src = src;
|
|
65
|
+
setStatus(image.complete && image.naturalWidth > 0 ? "loaded" : "loading");
|
|
66
|
+
return () => {
|
|
67
|
+
active = false;
|
|
68
|
+
};
|
|
69
|
+
}, [src, srcSet, sizes, crossOrigin, referrerPolicy, setStatus]);
|
|
70
|
+
const element = useRender({
|
|
71
|
+
render,
|
|
72
|
+
defaultTagName: "img",
|
|
73
|
+
props: { src, srcSet, sizes, crossOrigin, referrerPolicy, className },
|
|
74
|
+
consumerProps: rest
|
|
75
|
+
});
|
|
76
|
+
return status === "loaded" ? element : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/avatar/AvatarFallback.tsx
|
|
80
|
+
import { useEffect, useState as useState2 } from "react";
|
|
81
|
+
function AvatarFallback({
|
|
82
|
+
delay = 0,
|
|
83
|
+
className,
|
|
84
|
+
children,
|
|
85
|
+
render,
|
|
86
|
+
...rest
|
|
87
|
+
}) {
|
|
88
|
+
const { status } = useAvatarContext("Fallback");
|
|
89
|
+
const [waited, setWaited] = useState2(delay === 0);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (delay === 0) return;
|
|
92
|
+
const timer = setTimeout(() => setWaited(true), delay);
|
|
93
|
+
return () => clearTimeout(timer);
|
|
94
|
+
}, [delay]);
|
|
95
|
+
const element = useRender({
|
|
96
|
+
render,
|
|
97
|
+
defaultTagName: "span",
|
|
98
|
+
props: { className, children },
|
|
99
|
+
consumerProps: rest
|
|
100
|
+
});
|
|
101
|
+
return status !== "loaded" && waited ? element : null;
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
index_parts_exports as Avatar
|
|
105
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
byDocumentOrder,
|
|
3
|
+
rovingIndex
|
|
4
|
+
} from "./chunk-2S4XG4VD.js";
|
|
5
|
+
|
|
6
|
+
// src/core/rovingGroup.ts
|
|
7
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useState } from "react";
|
|
8
|
+
var RovingGroupContext = createContext(null);
|
|
9
|
+
function useRovingGroupContext() {
|
|
10
|
+
return useContext(RovingGroupContext);
|
|
11
|
+
}
|
|
12
|
+
function keyBelongsToField(event, orientation) {
|
|
13
|
+
const target = event.target;
|
|
14
|
+
if (!(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) return false;
|
|
15
|
+
if (target instanceof HTMLInputElement && !/^(text|search|url|tel|email|password|number)$/.test(target.type)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const { key } = event;
|
|
19
|
+
const along = orientation === "horizontal" ? ["ArrowLeft", "ArrowRight", "Home", "End"] : [];
|
|
20
|
+
if (!along.includes(key)) return false;
|
|
21
|
+
const start = target.selectionStart ?? 0;
|
|
22
|
+
const end = target.selectionEnd ?? 0;
|
|
23
|
+
const atStart = start === 0 && end === 0;
|
|
24
|
+
const atEnd = start === target.value.length && end === target.value.length;
|
|
25
|
+
const rtl = getComputedStyle(target).direction === "rtl";
|
|
26
|
+
const towardStart = key === (rtl ? "ArrowRight" : "ArrowLeft") || key === "Home";
|
|
27
|
+
return towardStart ? !atStart : !atEnd;
|
|
28
|
+
}
|
|
29
|
+
function useRovingGroup({ orientation }) {
|
|
30
|
+
const [items, setItems] = useState([]);
|
|
31
|
+
const register = useCallback((item) => {
|
|
32
|
+
setItems((current) => [...current, item].sort(byDocumentOrder));
|
|
33
|
+
return () => setItems((current) => current.filter((i) => i !== item));
|
|
34
|
+
}, []);
|
|
35
|
+
const [chosen, setTabStop] = useState(null);
|
|
36
|
+
const enabled = items.filter((item) => !item.disabled);
|
|
37
|
+
const tabStop = (
|
|
38
|
+
// Matched by element: an item re-registers when its props change.
|
|
39
|
+
chosen && enabled.find((item) => item.ref === chosen.ref) || enabled.find((item) => item.selected) || enabled[0] || null
|
|
40
|
+
);
|
|
41
|
+
const onKeyDown = useCallback(
|
|
42
|
+
(event) => {
|
|
43
|
+
if (event.defaultPrevented || keyBelongsToField(event, orientation)) return;
|
|
44
|
+
const current = enabled.findIndex((item2) => item2.ref.current?.contains(event.target));
|
|
45
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
46
|
+
const next = rovingIndex(event.key, { count: enabled.length, current, orientation, rtl });
|
|
47
|
+
if (next === null) return;
|
|
48
|
+
const item = enabled[next];
|
|
49
|
+
if (!item) return;
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
item.ref.current?.focus();
|
|
52
|
+
setTabStop(item);
|
|
53
|
+
},
|
|
54
|
+
[enabled, orientation]
|
|
55
|
+
);
|
|
56
|
+
const context = useMemo(() => ({ tabStop, register, setTabStop }), [tabStop, register]);
|
|
57
|
+
return { context, onKeyDown };
|
|
58
|
+
}
|
|
59
|
+
function useRovingItem(ref, disabled, selected = false) {
|
|
60
|
+
const group = useRovingGroupContext();
|
|
61
|
+
const item = useMemo(() => ({ ref, disabled, selected }), [ref, disabled, selected]);
|
|
62
|
+
const register = group?.register;
|
|
63
|
+
useLayoutEffect(() => register?.(item), [register, item]);
|
|
64
|
+
if (!group) return { tabIndex: void 0, onFocus: void 0 };
|
|
65
|
+
return {
|
|
66
|
+
tabIndex: group.tabStop?.ref === ref ? 0 : -1,
|
|
67
|
+
onFocus() {
|
|
68
|
+
group.setTabStop(item);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
RovingGroupContext,
|
|
75
|
+
useRovingGroupContext,
|
|
76
|
+
useRovingGroup,
|
|
77
|
+
useRovingItem
|
|
78
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/toggle-group/ToggleGroupContext.ts
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
var ToggleGroupContext = createContext(null);
|
|
4
|
+
function useToggleGroupContext() {
|
|
5
|
+
return useContext(ToggleGroupContext);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
ToggleGroupContext,
|
|
10
|
+
useToggleGroupContext
|
|
11
|
+
};
|
package/dist/combobox/index.cjs
CHANGED
|
@@ -133,10 +133,12 @@ function useControlled({
|
|
|
133
133
|
return [value, setValue];
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
// src/
|
|
136
|
+
// src/core/fold.ts
|
|
137
137
|
function fold(text) {
|
|
138
138
|
return text.normalize("NFD").replace(/\p{M}/gu, "").toLocaleLowerCase();
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
// src/combobox/defaultFilter.ts
|
|
140
142
|
function defaultFilter(items, query, itemToString) {
|
|
141
143
|
const needle = fold(query.trim());
|
|
142
144
|
if (needle === "") return [...items];
|
package/dist/combobox/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "../chunk-2S4XG4VD.js";
|
|
2
|
+
fold
|
|
3
|
+
} from "../chunk-ETNICT5M.js";
|
|
5
4
|
import {
|
|
6
5
|
anchorNameFor,
|
|
7
6
|
anchoredDataAttributes,
|
|
8
7
|
anchoredPopupStyle
|
|
9
8
|
} from "../chunk-HCOCPQXS.js";
|
|
9
|
+
import {
|
|
10
|
+
byDocumentOrder,
|
|
11
|
+
rovingIndex
|
|
12
|
+
} from "../chunk-2S4XG4VD.js";
|
|
10
13
|
import {
|
|
11
14
|
useControlled
|
|
12
15
|
} from "../chunk-UEIB3I3T.js";
|
|
@@ -40,9 +43,6 @@ __export(index_parts_exports, {
|
|
|
40
43
|
import { useCallback, useDeferredValue, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
41
44
|
|
|
42
45
|
// src/combobox/defaultFilter.ts
|
|
43
|
-
function fold(text) {
|
|
44
|
-
return text.normalize("NFD").replace(/\p{M}/gu, "").toLocaleLowerCase();
|
|
45
|
-
}
|
|
46
46
|
function defaultFilter(items, query, itemToString) {
|
|
47
47
|
const needle = fold(query.trim());
|
|
48
48
|
if (needle === "") return [...items];
|