@classic-homes/theme-react 0.5.2 → 0.6.1
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/index.d.mts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +92 -3
- package/dist/index.mjs +245 -157
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -69,6 +69,15 @@ interface InputProps extends React$1.InputHTMLAttributes<HTMLInputElement> {
|
|
|
69
69
|
* @example aria-describedby="email-error email-hint"
|
|
70
70
|
*/
|
|
71
71
|
'aria-describedby'?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Saved value to offer a revert to. While the value differs from it, a
|
|
74
|
+
* small revert button shows at the end of the field; the revert goes onto
|
|
75
|
+
* the browser's undo stack, so Ctrl/Cmd+Z brings the edit back. The wrapper
|
|
76
|
+
* fills its container: size the container, not the input.
|
|
77
|
+
*/
|
|
78
|
+
revertTo?: string;
|
|
79
|
+
/** Accessible label / tooltip of the revert button (default "Revert to saved") */
|
|
80
|
+
revertLabel?: string;
|
|
72
81
|
}
|
|
73
82
|
declare const Input: React$1.ForwardRefExoticComponent<InputProps & React$1.RefAttributes<HTMLInputElement>>;
|
|
74
83
|
|
|
@@ -1441,4 +1450,35 @@ declare function useClickOutside<T extends HTMLElement>(ref: React$1.RefObject<T
|
|
|
1441
1450
|
*/
|
|
1442
1451
|
declare function cn(...inputs: ClassValue[]): string;
|
|
1443
1452
|
|
|
1444
|
-
|
|
1453
|
+
/**
|
|
1454
|
+
* Mirror of packages/svelte/src/lib/utils/undoable-text.ts — keep in sync.
|
|
1455
|
+
*
|
|
1456
|
+
* Write text into a native text field so the change lands on the browser's
|
|
1457
|
+
* own undo stack: Ctrl/Cmd+Z restores what was there before, and
|
|
1458
|
+
* Ctrl/Cmd+Shift+Z (or Ctrl+Y) re-applies it.
|
|
1459
|
+
*
|
|
1460
|
+
* Assigning `el.value` (or changing a bound `value` prop) wipes the native undo
|
|
1461
|
+
* history, so text written for the user (AI drafts, snippet inserts, reverts)
|
|
1462
|
+
* could never be undone. Routing the write through `execCommand('insertText')`
|
|
1463
|
+
* keeps it in the history and fires a real `input` event, so components'
|
|
1464
|
+
* `oninput` / `onValueChange` handlers run exactly as for typing.
|
|
1465
|
+
*
|
|
1466
|
+
* Where the editing pipeline is unavailable (no `execCommand`, a field type it
|
|
1467
|
+
* refuses such as `number` or `date`, or a test DOM) it falls back to
|
|
1468
|
+
* `setRangeText` / `value` plus a synthetic bubbling `input` event: the value
|
|
1469
|
+
* still updates and handlers still run, but the change is not undoable.
|
|
1470
|
+
*/
|
|
1471
|
+
type TextField = HTMLInputElement | HTMLTextAreaElement;
|
|
1472
|
+
interface SetTextOptions {
|
|
1473
|
+
/** Start of the range to replace (default 0, i.e. the whole value). */
|
|
1474
|
+
start?: number;
|
|
1475
|
+
/** End of the range to replace (default the end of the value). */
|
|
1476
|
+
end?: number;
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Replace `[start, end)` of the field's value with `text` (the whole value by
|
|
1480
|
+
* default). Returns `true` when the change went onto the native undo stack.
|
|
1481
|
+
*/
|
|
1482
|
+
declare function setTextUndoable(el: TextField, text: string, options?: SetTextOptions): boolean;
|
|
1483
|
+
|
|
1484
|
+
export { type ArrowNavigationOrientation, Avatar, AvatarFallback, AvatarImage, type AvatarImageProps, type AvatarProps, Badge, type BadgeProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps, DataPanel, DataPanelContent, type DataPanelContentProps, DataPanelFooter, type DataPanelFooterProps, DataPanelHeader, type DataPanelHeaderProps, type DataPanelProps, DataPanelTab, type DataPanelTabProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, type DialogSize, DialogTitle, DialogTrigger, Input, type InputProps, InsertPalette, type InsertPaletteGroup, type InsertPaletteItem, type InsertPaletteProps, IssuesButton, type IssuesButtonProps, Label, LiveRegion, type LiveRegionProps, LoadingLogo, type LoadingLogoProps, LoadingOverlay, type LoadingOverlayProps, LoadingPage, type LoadingPageProps, LoadingSection, type LoadingSectionProps, PageHeader, type PageHeaderProps, PasswordInput, type PasswordInputProps, ProgressBar, type ProgressBarProps, type SaveState, SaveStatus, type SaveStatusProps, Separator, type SeparatorProps, type SetTextOptions, Sheet, type SheetProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, type SortableHandleProps, type SortableItemContext, SortableList, type SortableListProps, Spinner, type SpinnerProps, Studio, StudioBar, type StudioBarProps, StudioCanvas, StudioCanvasItem, type StudioCanvasItemProps, type StudioCanvasProps, type StudioContextValue, StudioInspector, type StudioInspectorProps, StudioInspectorSection, type StudioInspectorSectionProps, type StudioInspectorTab, type StudioIssue, type StudioLayout, type StudioMenuItem, type StudioMode, StudioOutline, type StudioOutlineEntry, type StudioOutlineProps, StudioPage, type StudioPageProps, type StudioProps, Switch, type SwitchProps, type TextField, type UseAnnounceOptions, type UseAnnounceReturn, type UseArrowNavigationOptions, type UseClickOutsideOptions, type UseDataPanelOptions, type UseEscapeKeyOptions, type UseFocusRefOptions, type UseFocusTrapOptions, type UseRovingTabindexOptions, badgeVariants, buttonVariants, cn, labelVariants, pageHeaderActionsVariants, pageHeaderContainerVariants, pageHeaderSubtitleVariants, pageHeaderTitleVariants, progressBarVariants, setTextUndoable, skeletonVariants, spinnerVariants, useAnnounce, useArrowNavigation, useClickOutside, useDataPanel, useEscapeKey, useFocusRef, useFocusTrap, useReducedMotion, useRovingTabindex, useStudio };
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,15 @@ interface InputProps extends React$1.InputHTMLAttributes<HTMLInputElement> {
|
|
|
69
69
|
* @example aria-describedby="email-error email-hint"
|
|
70
70
|
*/
|
|
71
71
|
'aria-describedby'?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Saved value to offer a revert to. While the value differs from it, a
|
|
74
|
+
* small revert button shows at the end of the field; the revert goes onto
|
|
75
|
+
* the browser's undo stack, so Ctrl/Cmd+Z brings the edit back. The wrapper
|
|
76
|
+
* fills its container: size the container, not the input.
|
|
77
|
+
*/
|
|
78
|
+
revertTo?: string;
|
|
79
|
+
/** Accessible label / tooltip of the revert button (default "Revert to saved") */
|
|
80
|
+
revertLabel?: string;
|
|
72
81
|
}
|
|
73
82
|
declare const Input: React$1.ForwardRefExoticComponent<InputProps & React$1.RefAttributes<HTMLInputElement>>;
|
|
74
83
|
|
|
@@ -1441,4 +1450,35 @@ declare function useClickOutside<T extends HTMLElement>(ref: React$1.RefObject<T
|
|
|
1441
1450
|
*/
|
|
1442
1451
|
declare function cn(...inputs: ClassValue[]): string;
|
|
1443
1452
|
|
|
1444
|
-
|
|
1453
|
+
/**
|
|
1454
|
+
* Mirror of packages/svelte/src/lib/utils/undoable-text.ts — keep in sync.
|
|
1455
|
+
*
|
|
1456
|
+
* Write text into a native text field so the change lands on the browser's
|
|
1457
|
+
* own undo stack: Ctrl/Cmd+Z restores what was there before, and
|
|
1458
|
+
* Ctrl/Cmd+Shift+Z (or Ctrl+Y) re-applies it.
|
|
1459
|
+
*
|
|
1460
|
+
* Assigning `el.value` (or changing a bound `value` prop) wipes the native undo
|
|
1461
|
+
* history, so text written for the user (AI drafts, snippet inserts, reverts)
|
|
1462
|
+
* could never be undone. Routing the write through `execCommand('insertText')`
|
|
1463
|
+
* keeps it in the history and fires a real `input` event, so components'
|
|
1464
|
+
* `oninput` / `onValueChange` handlers run exactly as for typing.
|
|
1465
|
+
*
|
|
1466
|
+
* Where the editing pipeline is unavailable (no `execCommand`, a field type it
|
|
1467
|
+
* refuses such as `number` or `date`, or a test DOM) it falls back to
|
|
1468
|
+
* `setRangeText` / `value` plus a synthetic bubbling `input` event: the value
|
|
1469
|
+
* still updates and handlers still run, but the change is not undoable.
|
|
1470
|
+
*/
|
|
1471
|
+
type TextField = HTMLInputElement | HTMLTextAreaElement;
|
|
1472
|
+
interface SetTextOptions {
|
|
1473
|
+
/** Start of the range to replace (default 0, i.e. the whole value). */
|
|
1474
|
+
start?: number;
|
|
1475
|
+
/** End of the range to replace (default the end of the value). */
|
|
1476
|
+
end?: number;
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Replace `[start, end)` of the field's value with `text` (the whole value by
|
|
1480
|
+
* default). Returns `true` when the change went onto the native undo stack.
|
|
1481
|
+
*/
|
|
1482
|
+
declare function setTextUndoable(el: TextField, text: string, options?: SetTextOptions): boolean;
|
|
1483
|
+
|
|
1484
|
+
export { type ArrowNavigationOrientation, Avatar, AvatarFallback, AvatarImage, type AvatarImageProps, type AvatarProps, Badge, type BadgeProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps, DataPanel, DataPanelContent, type DataPanelContentProps, DataPanelFooter, type DataPanelFooterProps, DataPanelHeader, type DataPanelHeaderProps, type DataPanelProps, DataPanelTab, type DataPanelTabProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, type DialogSize, DialogTitle, DialogTrigger, Input, type InputProps, InsertPalette, type InsertPaletteGroup, type InsertPaletteItem, type InsertPaletteProps, IssuesButton, type IssuesButtonProps, Label, LiveRegion, type LiveRegionProps, LoadingLogo, type LoadingLogoProps, LoadingOverlay, type LoadingOverlayProps, LoadingPage, type LoadingPageProps, LoadingSection, type LoadingSectionProps, PageHeader, type PageHeaderProps, PasswordInput, type PasswordInputProps, ProgressBar, type ProgressBarProps, type SaveState, SaveStatus, type SaveStatusProps, Separator, type SeparatorProps, type SetTextOptions, Sheet, type SheetProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, type SortableHandleProps, type SortableItemContext, SortableList, type SortableListProps, Spinner, type SpinnerProps, Studio, StudioBar, type StudioBarProps, StudioCanvas, StudioCanvasItem, type StudioCanvasItemProps, type StudioCanvasProps, type StudioContextValue, StudioInspector, type StudioInspectorProps, StudioInspectorSection, type StudioInspectorSectionProps, type StudioInspectorTab, type StudioIssue, type StudioLayout, type StudioMenuItem, type StudioMode, StudioOutline, type StudioOutlineEntry, type StudioOutlineProps, StudioPage, type StudioPageProps, type StudioProps, Switch, type SwitchProps, type TextField, type UseAnnounceOptions, type UseAnnounceReturn, type UseArrowNavigationOptions, type UseClickOutsideOptions, type UseDataPanelOptions, type UseEscapeKeyOptions, type UseFocusRefOptions, type UseFocusTrapOptions, type UseRovingTabindexOptions, badgeVariants, buttonVariants, cn, labelVariants, pageHeaderActionsVariants, pageHeaderContainerVariants, pageHeaderSubtitleVariants, pageHeaderTitleVariants, progressBarVariants, setTextUndoable, skeletonVariants, spinnerVariants, useAnnounce, useArrowNavigation, useClickOutside, useDataPanel, useEscapeKey, useFocusRef, useFocusTrap, useReducedMotion, useRovingTabindex, useStudio };
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,7 @@ __export(index_exports, {
|
|
|
93
93
|
pageHeaderSubtitleVariants: () => pageHeaderSubtitleVariants,
|
|
94
94
|
pageHeaderTitleVariants: () => pageHeaderTitleVariants,
|
|
95
95
|
progressBarVariants: () => progressBarVariants,
|
|
96
|
+
setTextUndoable: () => setTextUndoable,
|
|
96
97
|
skeletonVariants: () => skeletonVariants,
|
|
97
98
|
spinnerVariants: () => spinnerVariants,
|
|
98
99
|
useAnnounce: () => useAnnounce,
|
|
@@ -224,8 +225,57 @@ function useDevWarning(condition, message, once = false) {
|
|
|
224
225
|
}, [condition, message, once]);
|
|
225
226
|
}
|
|
226
227
|
|
|
228
|
+
// src/lib/undoable-text.ts
|
|
229
|
+
var RANGE_TYPES = /* @__PURE__ */ new Set(["text", "search", "url", "tel", "password"]);
|
|
230
|
+
function supportsRange(el) {
|
|
231
|
+
return el instanceof HTMLTextAreaElement || RANGE_TYPES.has(el.type);
|
|
232
|
+
}
|
|
233
|
+
function setNativeValue(el, text) {
|
|
234
|
+
const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement : HTMLInputElement;
|
|
235
|
+
const setter = Object.getOwnPropertyDescriptor(proto.prototype, "value")?.set;
|
|
236
|
+
if (setter) setter.call(el, text);
|
|
237
|
+
else el.value = text;
|
|
238
|
+
}
|
|
239
|
+
function setTextUndoable(el, text, options = {}) {
|
|
240
|
+
const current = el.value;
|
|
241
|
+
const ranged = supportsRange(el);
|
|
242
|
+
const start = ranged ? Math.max(0, Math.min(options.start ?? 0, current.length)) : 0;
|
|
243
|
+
const end = ranged ? Math.max(start, Math.min(options.end ?? current.length, current.length)) : current.length;
|
|
244
|
+
if (current.slice(start, end) === text) return true;
|
|
245
|
+
if (ranged && typeof document !== "undefined" && typeof document.execCommand === "function") {
|
|
246
|
+
if (document.activeElement !== el) el.focus({ preventScroll: true });
|
|
247
|
+
el.setSelectionRange(start, end);
|
|
248
|
+
let applied = false;
|
|
249
|
+
try {
|
|
250
|
+
applied = text === "" ? document.execCommand("delete", false) : document.execCommand("insertText", false, text);
|
|
251
|
+
} catch {
|
|
252
|
+
applied = false;
|
|
253
|
+
}
|
|
254
|
+
if (applied && el.value !== current) return true;
|
|
255
|
+
}
|
|
256
|
+
if (ranged) el.setRangeText(text, start, end, "end");
|
|
257
|
+
else setNativeValue(el, text);
|
|
258
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
|
|
227
262
|
// src/components/Input.tsx
|
|
228
263
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
264
|
+
var UndoIcon = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
265
|
+
"svg",
|
|
266
|
+
{
|
|
267
|
+
width: 14,
|
|
268
|
+
height: 14,
|
|
269
|
+
viewBox: "0 0 24 24",
|
|
270
|
+
fill: "none",
|
|
271
|
+
stroke: "currentColor",
|
|
272
|
+
strokeWidth: 2,
|
|
273
|
+
strokeLinecap: "round",
|
|
274
|
+
strokeLinejoin: "round",
|
|
275
|
+
"aria-hidden": "true",
|
|
276
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 7v6h6M3 13a9 9 0 1 0 2.64-6.36L3 9" })
|
|
277
|
+
}
|
|
278
|
+
);
|
|
229
279
|
var Input = React4.forwardRef(
|
|
230
280
|
({
|
|
231
281
|
className,
|
|
@@ -233,13 +283,29 @@ var Input = React4.forwardRef(
|
|
|
233
283
|
"aria-invalid": ariaInvalid,
|
|
234
284
|
required,
|
|
235
285
|
"aria-describedby": ariaDescribedBy,
|
|
286
|
+
revertTo,
|
|
287
|
+
revertLabel = "Revert to saved",
|
|
236
288
|
...props
|
|
237
289
|
}, ref) => {
|
|
290
|
+
const innerRef = React4.useRef(null);
|
|
291
|
+
const setRefs = React4.useCallback(
|
|
292
|
+
(el) => {
|
|
293
|
+
innerRef.current = el;
|
|
294
|
+
if (typeof ref === "function") ref(el);
|
|
295
|
+
else if (ref) ref.current = el;
|
|
296
|
+
},
|
|
297
|
+
[ref]
|
|
298
|
+
);
|
|
299
|
+
const [liveValue, setLiveValue] = React4.useState(
|
|
300
|
+
() => String(props.value ?? props.defaultValue ?? "")
|
|
301
|
+
);
|
|
302
|
+
const shown = props.value !== void 0 ? String(props.value) : liveValue;
|
|
303
|
+
const canRevert = revertTo !== void 0 && !props.disabled && !props.readOnly && shown !== revertTo;
|
|
238
304
|
useDevWarning(
|
|
239
305
|
!props["aria-label"] && !props["aria-labelledby"] && !props.id,
|
|
240
306
|
"Input: Missing accessible label. Provide aria-label, aria-labelledby, or associate with a Label using id/htmlFor for WCAG compliance."
|
|
241
307
|
);
|
|
242
|
-
|
|
308
|
+
const input = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
243
309
|
"input",
|
|
244
310
|
{
|
|
245
311
|
type,
|
|
@@ -250,12 +316,34 @@ var Input = React4.forwardRef(
|
|
|
250
316
|
className: cn(
|
|
251
317
|
"flex h-10 w-full rounded-md border border-input bg-background text-foreground px-3 py-2 text-sm max-sm:text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
252
318
|
ariaInvalid === true || ariaInvalid === "true" ? "border-destructive focus-visible:ring-destructive" : "",
|
|
319
|
+
revertTo !== void 0 && "pr-9",
|
|
253
320
|
className
|
|
254
321
|
),
|
|
255
|
-
ref,
|
|
256
|
-
...props
|
|
322
|
+
ref: setRefs,
|
|
323
|
+
...props,
|
|
324
|
+
onChange: (e) => {
|
|
325
|
+
setLiveValue(e.currentTarget.value);
|
|
326
|
+
props.onChange?.(e);
|
|
327
|
+
}
|
|
257
328
|
}
|
|
258
329
|
);
|
|
330
|
+
if (revertTo === void 0) return input;
|
|
331
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "relative w-full", children: [
|
|
332
|
+
input,
|
|
333
|
+
canRevert && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
334
|
+
"button",
|
|
335
|
+
{
|
|
336
|
+
type: "button",
|
|
337
|
+
className: "absolute right-1.5 top-1/2 inline-flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
338
|
+
"aria-label": revertLabel,
|
|
339
|
+
title: revertLabel,
|
|
340
|
+
onClick: () => {
|
|
341
|
+
if (innerRef.current) setTextUndoable(innerRef.current, revertTo);
|
|
342
|
+
},
|
|
343
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UndoIcon, {})
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
] });
|
|
259
347
|
}
|
|
260
348
|
);
|
|
261
349
|
Input.displayName = "Input";
|
|
@@ -5313,6 +5401,7 @@ function useClickOutside(ref, callback, options) {
|
|
|
5313
5401
|
pageHeaderSubtitleVariants,
|
|
5314
5402
|
pageHeaderTitleVariants,
|
|
5315
5403
|
progressBarVariants,
|
|
5404
|
+
setTextUndoable,
|
|
5316
5405
|
skeletonVariants,
|
|
5317
5406
|
spinnerVariants,
|
|
5318
5407
|
useAnnounce,
|