@yarcl/react 0.1.0 → 0.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.
- package/README.md +14 -2
- package/{src/apply.ts → dist/apply.d.ts} +4 -23
- package/dist/apply.js +37 -0
- package/dist/classes.d.ts +13 -0
- package/dist/classes.js +22 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +58 -0
- package/dist/color.js +49 -32
- package/dist/components/Accordion.d.ts +96 -0
- package/dist/components/Accordion.js +148 -0
- package/dist/components/Alert.d.ts +60 -0
- package/dist/components/Alert.js +61 -0
- package/dist/components/Avatar.d.ts +100 -0
- package/dist/components/Avatar.js +89 -0
- package/dist/components/Badge.d.ts +44 -0
- package/dist/components/Badge.js +43 -0
- package/dist/components/Breadcrumb.d.ts +77 -0
- package/dist/components/Breadcrumb.js +126 -0
- package/dist/components/Button.d.ts +18 -0
- package/dist/components/Button.js +33 -0
- package/dist/components/ButtonGroup.d.ts +29 -0
- package/dist/components/ButtonGroup.js +37 -0
- package/dist/components/Card.d.ts +36 -0
- package/dist/components/Card.js +26 -0
- package/dist/components/Checkbox.d.ts +28 -0
- package/dist/components/Checkbox.js +38 -0
- package/dist/components/Combobox.d.ts +75 -0
- package/dist/components/Combobox.js +362 -0
- package/dist/components/CommandPalette.d.ts +92 -0
- package/dist/components/CommandPalette.js +293 -0
- package/dist/components/DatePicker.d.ts +157 -0
- package/dist/components/DatePicker.js +230 -0
- package/dist/components/Dialog.d.ts +25 -0
- package/dist/components/Dialog.js +29 -0
- package/dist/components/Divider.d.ts +23 -0
- package/dist/components/Divider.js +25 -0
- package/dist/components/Drawer.d.ts +21 -0
- package/dist/components/Drawer.js +25 -0
- package/dist/components/EmptyState.d.ts +51 -0
- package/dist/components/EmptyState.js +47 -0
- package/dist/components/Field.d.ts +27 -0
- package/dist/components/Field.js +59 -0
- package/dist/components/Heading.d.ts +26 -0
- package/dist/components/Heading.js +25 -0
- package/dist/components/HoverCard.d.ts +47 -0
- package/dist/components/HoverCard.js +53 -0
- package/dist/components/IconButton.d.ts +19 -0
- package/dist/components/IconButton.js +32 -0
- package/dist/components/Inline.d.ts +21 -0
- package/dist/components/Inline.js +24 -0
- package/dist/components/Input.d.ts +19 -0
- package/dist/components/Input.js +25 -0
- package/dist/components/Label.d.ts +46 -0
- package/dist/components/Label.js +33 -0
- package/dist/components/Link.d.ts +27 -0
- package/dist/components/Link.js +26 -0
- package/dist/components/Menu.d.ts +73 -0
- package/dist/components/Menu.js +143 -0
- package/dist/components/Modal.d.ts +45 -0
- package/dist/components/Modal.js +110 -0
- package/dist/components/NumberInput.d.ts +49 -0
- package/dist/components/NumberInput.js +130 -0
- package/dist/components/Pagination.d.ts +86 -0
- package/dist/components/Pagination.js +119 -0
- package/dist/components/Popover.d.ts +72 -0
- package/dist/components/Popover.js +87 -0
- package/dist/components/Progress.d.ts +60 -0
- package/dist/components/Progress.js +59 -0
- package/dist/components/Radio.d.ts +32 -0
- package/dist/components/Radio.js +47 -0
- package/dist/components/RadioGroup.d.ts +57 -0
- package/dist/components/RadioGroup.js +68 -0
- package/dist/components/Select.d.ts +47 -0
- package/dist/components/Select.js +138 -0
- package/dist/components/Skeleton.d.ts +46 -0
- package/dist/components/Skeleton.js +40 -0
- package/dist/components/Slider.d.ts +126 -0
- package/dist/components/Slider.js +166 -0
- package/dist/components/Spinner.d.ts +23 -0
- package/dist/components/Spinner.js +23 -0
- package/dist/components/Stack.d.ts +35 -0
- package/dist/components/Stack.js +24 -0
- package/dist/components/Switch.d.ts +27 -0
- package/dist/components/Switch.js +33 -0
- package/dist/components/Table.d.ts +71 -0
- package/dist/components/Table.js +61 -0
- package/dist/components/Tabs.d.ts +66 -0
- package/dist/components/Tabs.js +109 -0
- package/dist/components/Text.d.ts +32 -0
- package/dist/components/Text.js +28 -0
- package/dist/components/Textarea.d.ts +15 -0
- package/dist/components/Textarea.js +24 -0
- package/dist/components/Toast.d.ts +90 -0
- package/dist/components/Toast.js +156 -0
- package/dist/components/ToggleGroup.d.ts +79 -0
- package/dist/components/ToggleGroup.js +101 -0
- package/dist/components/Tooltip.d.ts +46 -0
- package/dist/components/Tooltip.js +62 -0
- package/dist/components/VisuallyHidden.d.ts +18 -0
- package/dist/components/VisuallyHidden.js +22 -0
- package/dist/contrast.d.ts +32 -0
- package/dist/css.d.ts +2 -2
- package/dist/css.js +193 -157
- package/dist/define.d.ts +40 -15
- package/dist/define.js +30 -27
- package/dist/demo.d.ts +2 -0
- package/dist/demo.js +2 -0
- package/dist/esbuild.cjs +5 -0
- package/dist/esbuild.d.ts +4 -0
- package/dist/esbuild.js +6 -0
- package/dist/field-context.d.ts +16 -0
- package/dist/field-context.js +17 -0
- package/dist/floating.d.ts +12 -0
- package/dist/floating.js +52 -0
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +12 -0
- package/{src/index.ts → dist/index.d.ts} +11 -33
- package/dist/index.js +50 -0
- package/dist/init.d.ts +18 -0
- package/dist/init.js +224 -0
- package/dist/plugin.d.ts +10 -26
- package/dist/plugin.js +152 -78
- package/dist/reference/DemoYarcl.d.ts +12 -0
- package/dist/reference/DemoYarcl.js +312 -0
- package/dist/reference/DesignReference.d.ts +24 -0
- package/dist/reference/DesignReference.js +403 -0
- package/dist/reference/index.js +2 -0
- package/dist/rollup.cjs +5 -0
- package/dist/rollup.d.ts +4 -0
- package/dist/rollup.js +6 -0
- package/dist/rspack.cjs +5 -0
- package/dist/rspack.d.ts +4 -0
- package/dist/rspack.js +6 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.js +30 -0
- package/dist/setup.d.ts +6 -0
- package/dist/setup.js +33 -0
- package/{src → dist}/styles.css +224 -106
- package/dist/themes/bloom.d.ts +295 -0
- package/dist/themes/bloom.js +202 -0
- package/dist/themes/brutalist.d.ts +277 -0
- package/dist/themes/brutalist.js +199 -0
- package/dist/themes/compact.d.ts +274 -0
- package/dist/themes/compact.js +200 -0
- package/dist/themes/contract.d.ts +23 -0
- package/dist/themes/editorial.d.ts +277 -0
- package/dist/themes/editorial.js +183 -0
- package/dist/themes/index.d.ts +1425 -0
- package/dist/themes/index.js +45 -0
- package/{src/types.ts → dist/types.d.ts} +40 -37
- package/dist/vite.cjs +5 -0
- package/dist/vite.d.ts +4 -0
- package/dist/vite.js +6 -0
- package/dist/webpack.cjs +5 -0
- package/dist/webpack.d.ts +4 -0
- package/dist/webpack.js +6 -0
- package/dist/yarcl.config.d.ts +276 -0
- package/dist/yarcl.config.js +273 -0
- package/package.json +69 -17
- package/src/classes.ts +0 -23
- package/src/color.ts +0 -48
- package/src/components/Accordion.tsx +0 -274
- package/src/components/Alert.tsx +0 -85
- package/src/components/Badge.tsx +0 -79
- package/src/components/Breadcrumb.tsx +0 -239
- package/src/components/Button.tsx +0 -58
- package/src/components/ButtonGroup.tsx +0 -61
- package/src/components/Card.tsx +0 -50
- package/src/components/Checkbox.tsx +0 -49
- package/src/components/Combobox.tsx +0 -522
- package/src/components/CommandPalette.tsx +0 -452
- package/src/components/DatePicker.tsx +0 -432
- package/src/components/Dialog.tsx +0 -39
- package/src/components/Divider.tsx +0 -34
- package/src/components/Drawer.tsx +0 -31
- package/src/components/Field.tsx +0 -61
- package/src/components/Heading.tsx +0 -40
- package/src/components/HoverCard.tsx +0 -108
- package/src/components/IconButton.tsx +0 -59
- package/src/components/Inline.tsx +0 -42
- package/src/components/Input.tsx +0 -28
- package/src/components/Label.tsx +0 -58
- package/src/components/Link.tsx +0 -41
- package/src/components/Menu.tsx +0 -207
- package/src/components/Modal.tsx +0 -164
- package/src/components/NumberInput.tsx +0 -208
- package/src/components/Pagination.tsx +0 -227
- package/src/components/Popover.tsx +0 -140
- package/src/components/Progress.tsx +0 -122
- package/src/components/Radio.tsx +0 -59
- package/src/components/RadioGroup.tsx +0 -114
- package/src/components/Select.tsx +0 -197
- package/src/components/Skeleton.tsx +0 -95
- package/src/components/Slider.tsx +0 -315
- package/src/components/Spinner.tsx +0 -38
- package/src/components/Stack.tsx +0 -57
- package/src/components/Switch.tsx +0 -42
- package/src/components/Table.tsx +0 -99
- package/src/components/Tabs.tsx +0 -159
- package/src/components/Text.tsx +0 -67
- package/src/components/Textarea.tsx +0 -26
- package/src/components/Toast.tsx +0 -190
- package/src/components/ToggleGroup.tsx +0 -227
- package/src/components/Tooltip.tsx +0 -78
- package/src/contrast.ts +0 -82
- package/src/css.ts +0 -228
- package/src/define.check.ts +0 -259
- package/src/define.ts +0 -379
- package/src/field-context.ts +0 -31
- package/src/floating.tsx +0 -61
- package/src/hooks.ts +0 -19
- package/src/plugin.ts +0 -94
- package/src/reference/DesignReference.tsx +0 -374
- package/src/runtime.ts +0 -38
- package/src/themes/bloom.ts +0 -72
- package/src/themes/brutalist.ts +0 -63
- package/src/themes/compact.ts +0 -63
- package/src/themes/contract.ts +0 -24
- package/src/themes/editorial.ts +0 -55
- package/src/themes/index.ts +0 -47
- package/src/yarcl.config.ts +0 -104
- /package/{src/reference/index.ts → dist/reference/index.d.ts} +0 -0
- /package/{src → dist}/reference/reference.css +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface FieldContextValue {
|
|
2
|
+
id: string;
|
|
3
|
+
labelId: string;
|
|
4
|
+
describedBy: string | undefined;
|
|
5
|
+
invalid: boolean;
|
|
6
|
+
required: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare const FieldContext: import("react").Context<FieldContextValue | null>;
|
|
9
|
+
interface FieldControlProps {
|
|
10
|
+
id?: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
'aria-describedby'?: string;
|
|
13
|
+
'aria-invalid'?: boolean | 'true' | 'false' | 'grammar' | 'spelling';
|
|
14
|
+
}
|
|
15
|
+
export declare function useFieldProps<T extends FieldControlProps>(props: T): T;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { cx } from "./classes.js";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
//#region src/field-context.ts
|
|
4
|
+
var FieldContext = createContext(null);
|
|
5
|
+
function useFieldProps(props) {
|
|
6
|
+
const field = useContext(FieldContext);
|
|
7
|
+
if (!field) return props;
|
|
8
|
+
return {
|
|
9
|
+
...props,
|
|
10
|
+
id: props.id ?? field.id,
|
|
11
|
+
required: props.required ?? field.required,
|
|
12
|
+
"aria-describedby": cx(field.describedBy, props["aria-describedby"]) || void 0,
|
|
13
|
+
"aria-invalid": props["aria-invalid"] ?? (field.invalid || void 0)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { FieldContext, useFieldProps };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Middleware } from '@floating-ui/react';
|
|
2
|
+
import { type ReactElement, type RefObject } from 'react';
|
|
3
|
+
interface MiddlewareOptions {
|
|
4
|
+
gap?: number;
|
|
5
|
+
matchWidth?: boolean;
|
|
6
|
+
arrowRef?: RefObject<SVGSVGElement | null>;
|
|
7
|
+
}
|
|
8
|
+
export declare function floatingMiddleware({ gap, matchWidth, arrowRef }?: MiddlewareOptions): Middleware[];
|
|
9
|
+
export declare function useTrigger(child: ReactElement, setReference: (node: Element | null) => void, getReferenceProps: (props?: Record<string, unknown>) => Record<string, unknown>): ReactElement;
|
|
10
|
+
export declare function ChevronIcon(): import("react").JSX.Element;
|
|
11
|
+
export declare function CheckIcon(): import("react").JSX.Element;
|
|
12
|
+
export {};
|
package/dist/floating.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { cloneElement, isValidElement } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { arrow, flip, offset, shift, size, useMergeRefs } from "@floating-ui/react";
|
|
4
|
+
//#region src/floating.tsx
|
|
5
|
+
function floatingMiddleware({ gap = 6, matchWidth = false, arrowRef } = {}) {
|
|
6
|
+
return [
|
|
7
|
+
offset(gap),
|
|
8
|
+
flip({ padding: 8 }),
|
|
9
|
+
shift({ padding: 8 }),
|
|
10
|
+
size({
|
|
11
|
+
padding: 8,
|
|
12
|
+
apply({ rects, availableHeight, elements }) {
|
|
13
|
+
elements.floating.style.maxHeight = `${Math.max(availableHeight, 120)}px`;
|
|
14
|
+
if (matchWidth) elements.floating.style.minWidth = `${rects.reference.width}px`;
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
...arrowRef ? [arrow({ element: arrowRef })] : []
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
function useTrigger(child, setReference, getReferenceProps) {
|
|
21
|
+
if (!isValidElement(child)) throw new Error("yarcl: trigger must be a single React element");
|
|
22
|
+
const element = child;
|
|
23
|
+
const ref = useMergeRefs([setReference, element.props.ref]);
|
|
24
|
+
return cloneElement(element, getReferenceProps({
|
|
25
|
+
...element.props,
|
|
26
|
+
ref
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function ChevronIcon() {
|
|
30
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
31
|
+
viewBox: "0 0 24 24",
|
|
32
|
+
fill: "none",
|
|
33
|
+
stroke: "currentColor",
|
|
34
|
+
strokeWidth: "2",
|
|
35
|
+
strokeLinecap: "round",
|
|
36
|
+
"aria-hidden": "true",
|
|
37
|
+
children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function CheckIcon() {
|
|
41
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
42
|
+
viewBox: "0 0 24 24",
|
|
43
|
+
fill: "none",
|
|
44
|
+
stroke: "currentColor",
|
|
45
|
+
strokeWidth: "2.5",
|
|
46
|
+
strokeLinecap: "round",
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
children: /* @__PURE__ */ jsx("path", { d: "m5 12 5 5 9-10" })
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { CheckIcon, ChevronIcon, floatingMiddleware, useTrigger };
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (value: T) => void): [T, (next: T) => void];
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
//#region src/hooks.ts
|
|
3
|
+
function useControllable(value, defaultValue, onChange) {
|
|
4
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
5
|
+
const controlled = value !== void 0;
|
|
6
|
+
return [controlled ? value : internal, useCallback((next) => {
|
|
7
|
+
if (!controlled) setInternal(next);
|
|
8
|
+
onChange?.(next);
|
|
9
|
+
}, [controlled, onChange])];
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useControllable };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import '@yarcl/react/styles.css';
|
|
2
2
|
import './styles.css';
|
|
3
|
-
|
|
4
3
|
export { Button } from './components/Button';
|
|
5
4
|
export type { ButtonProps } from './components/Button';
|
|
6
5
|
export { ButtonGroup } from './components/ButtonGroup';
|
|
@@ -24,7 +23,7 @@ export type { RadioGroupProps } from './components/RadioGroup';
|
|
|
24
23
|
export { Switch } from './components/Switch';
|
|
25
24
|
export type { SwitchProps } from './components/Switch';
|
|
26
25
|
export { Slider } from './components/Slider';
|
|
27
|
-
export type { SliderProps, SliderValue } from './components/Slider';
|
|
26
|
+
export type { SliderProps, SliderRangeProps, SliderValue } from './components/Slider';
|
|
28
27
|
export { Field } from './components/Field';
|
|
29
28
|
export type { FieldProps } from './components/Field';
|
|
30
29
|
export { Label } from './components/Label';
|
|
@@ -45,6 +44,8 @@ export { Card } from './components/Card';
|
|
|
45
44
|
export type { CardProps } from './components/Card';
|
|
46
45
|
export { Divider } from './components/Divider';
|
|
47
46
|
export type { DividerProps } from './components/Divider';
|
|
47
|
+
export { VisuallyHidden } from './components/VisuallyHidden';
|
|
48
|
+
export type { VisuallyHiddenProps } from './components/VisuallyHidden';
|
|
48
49
|
export { Popover } from './components/Popover';
|
|
49
50
|
export type { PopoverProps, PopoverTriggerProps, PopoverContentProps } from './components/Popover';
|
|
50
51
|
export { Tooltip } from './components/Tooltip';
|
|
@@ -58,14 +59,7 @@ export type { SelectProps, SelectOption } from './components/Select';
|
|
|
58
59
|
export { Combobox } from './components/Combobox';
|
|
59
60
|
export type { ComboboxBaseProps, ComboboxProps } from './components/Combobox';
|
|
60
61
|
export { DatePicker } from './components/DatePicker';
|
|
61
|
-
export type {
|
|
62
|
-
DatePickerProps,
|
|
63
|
-
DatePickerBaseProps,
|
|
64
|
-
DatePickerSingleProps,
|
|
65
|
-
DatePickerRangeProps,
|
|
66
|
-
DatePickerLabels,
|
|
67
|
-
DateRange,
|
|
68
|
-
} from './components/DatePicker';
|
|
62
|
+
export type { DatePickerProps, DatePickerBaseProps, DatePickerSingleProps, DatePickerRangeProps, DatePickerLabels, DateRange, } from './components/DatePicker';
|
|
69
63
|
export { Dialog } from './components/Dialog';
|
|
70
64
|
export type { DialogProps } from './components/Dialog';
|
|
71
65
|
export { Drawer } from './components/Drawer';
|
|
@@ -76,13 +70,7 @@ export type { CommandPaletteProps, CommandPaletteCommand } from './components/Co
|
|
|
76
70
|
export { Toaster, toast } from './components/Toast';
|
|
77
71
|
export type { ToasterProps, ToastOptions } from './components/Toast';
|
|
78
72
|
export { Accordion } from './components/Accordion';
|
|
79
|
-
export type {
|
|
80
|
-
AccordionProps,
|
|
81
|
-
AccordionBaseProps,
|
|
82
|
-
AccordionItemProps,
|
|
83
|
-
AccordionTriggerProps,
|
|
84
|
-
AccordionContentProps,
|
|
85
|
-
} from './components/Accordion';
|
|
73
|
+
export type { AccordionProps, AccordionBaseProps, AccordionItemProps, AccordionTriggerProps, AccordionContentProps, } from './components/Accordion';
|
|
86
74
|
export { Tabs } from './components/Tabs';
|
|
87
75
|
export type { TabsProps, TabsBaseProps, TabsListProps, TabsTriggerProps, TabsPanelProps } from './components/Tabs';
|
|
88
76
|
export { Pagination } from './components/Pagination';
|
|
@@ -91,6 +79,8 @@ export { Table } from './components/Table';
|
|
|
91
79
|
export type { TableProps, TableHeaderCellProps, TableCellProps, CellAlign } from './components/Table';
|
|
92
80
|
export { Badge } from './components/Badge';
|
|
93
81
|
export type { BadgeProps } from './components/Badge';
|
|
82
|
+
export { Avatar, AvatarGroup } from './components/Avatar';
|
|
83
|
+
export type { AvatarProps, AvatarGroupProps } from './components/Avatar';
|
|
94
84
|
export { Alert } from './components/Alert';
|
|
95
85
|
export type { AlertProps } from './components/Alert';
|
|
96
86
|
export { Spinner } from './components/Spinner';
|
|
@@ -99,21 +89,9 @@ export { Skeleton } from './components/Skeleton';
|
|
|
99
89
|
export type { SkeletonProps } from './components/Skeleton';
|
|
100
90
|
export { Progress } from './components/Progress';
|
|
101
91
|
export type { ProgressProps } from './components/Progress';
|
|
102
|
-
export
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Color,
|
|
106
|
-
Variant,
|
|
107
|
-
Spacing,
|
|
108
|
-
Shadow,
|
|
109
|
-
TextStyle,
|
|
110
|
-
Density,
|
|
111
|
-
ModalSize,
|
|
112
|
-
Align,
|
|
113
|
-
Justify,
|
|
114
|
-
TokenProps,
|
|
115
|
-
VariantProps,
|
|
116
|
-
} from './types';
|
|
92
|
+
export { EmptyState } from './components/EmptyState';
|
|
93
|
+
export type { EmptyStateProps } from './components/EmptyState';
|
|
94
|
+
export type { Size, ComponentSize, Radius, Color, Variant, Spacing, Shadow, TextStyle, Density, ModalSize, Align, Justify, TokenProps, VariantProps, } from './types';
|
|
117
95
|
/** The build-time design system config: the consumer's, or the library default. */
|
|
118
96
|
export { default as config } from '@yarcl/config';
|
|
119
97
|
export { useConfig } from './runtime';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useConfig } from "./runtime.js";
|
|
2
|
+
import { ButtonGroup } from "./components/ButtonGroup.js";
|
|
3
|
+
import { Spinner } from "./components/Spinner.js";
|
|
4
|
+
import { Button } from "./components/Button.js";
|
|
5
|
+
import { ToggleGroup } from "./components/ToggleGroup.js";
|
|
6
|
+
import { IconButton } from "./components/IconButton.js";
|
|
7
|
+
import { Input } from "./components/Input.js";
|
|
8
|
+
import { Textarea } from "./components/Textarea.js";
|
|
9
|
+
import { NumberInput } from "./components/NumberInput.js";
|
|
10
|
+
import { Checkbox } from "./components/Checkbox.js";
|
|
11
|
+
import { RadioGroup } from "./components/RadioGroup.js";
|
|
12
|
+
import { Radio } from "./components/Radio.js";
|
|
13
|
+
import { Switch } from "./components/Switch.js";
|
|
14
|
+
import { Slider } from "./components/Slider.js";
|
|
15
|
+
import { Label } from "./components/Label.js";
|
|
16
|
+
import { Field } from "./components/Field.js";
|
|
17
|
+
import { Text } from "./components/Text.js";
|
|
18
|
+
import { Heading } from "./components/Heading.js";
|
|
19
|
+
import { Link } from "./components/Link.js";
|
|
20
|
+
import { Breadcrumb } from "./components/Breadcrumb.js";
|
|
21
|
+
import { Stack } from "./components/Stack.js";
|
|
22
|
+
import { Inline } from "./components/Inline.js";
|
|
23
|
+
import { Card } from "./components/Card.js";
|
|
24
|
+
import { Divider } from "./components/Divider.js";
|
|
25
|
+
import { VisuallyHidden } from "./components/VisuallyHidden.js";
|
|
26
|
+
import { Popover } from "./components/Popover.js";
|
|
27
|
+
import { Tooltip } from "./components/Tooltip.js";
|
|
28
|
+
import { HoverCard } from "./components/HoverCard.js";
|
|
29
|
+
import { Menu } from "./components/Menu.js";
|
|
30
|
+
import { Select } from "./components/Select.js";
|
|
31
|
+
import { Badge } from "./components/Badge.js";
|
|
32
|
+
import { Combobox } from "./components/Combobox.js";
|
|
33
|
+
import { DatePicker } from "./components/DatePicker.js";
|
|
34
|
+
import { Dialog } from "./components/Dialog.js";
|
|
35
|
+
import { Drawer } from "./components/Drawer.js";
|
|
36
|
+
import { CommandPalette } from "./components/CommandPalette.js";
|
|
37
|
+
import { Toaster, toast } from "./components/Toast.js";
|
|
38
|
+
import { Accordion } from "./components/Accordion.js";
|
|
39
|
+
import { Tabs } from "./components/Tabs.js";
|
|
40
|
+
import { Pagination } from "./components/Pagination.js";
|
|
41
|
+
import { Table } from "./components/Table.js";
|
|
42
|
+
import { Avatar, AvatarGroup } from "./components/Avatar.js";
|
|
43
|
+
import { Alert } from "./components/Alert.js";
|
|
44
|
+
import { Skeleton } from "./components/Skeleton.js";
|
|
45
|
+
import { Progress } from "./components/Progress.js";
|
|
46
|
+
import { EmptyState } from "./components/EmptyState.js";
|
|
47
|
+
import "@yarcl/react/styles.css";
|
|
48
|
+
import "./styles.css";
|
|
49
|
+
import config from "@yarcl/config";
|
|
50
|
+
export { Accordion, Alert, Avatar, AvatarGroup, Badge, Breadcrumb, Button, ButtonGroup, Card, Checkbox, Combobox, CommandPalette, DatePicker, Dialog, Divider, Drawer, EmptyState, Field, Heading, HoverCard, IconButton, Inline, Input, Label, Link, Menu, NumberInput, Pagination, Popover, Progress, Radio, RadioGroup, Select, Skeleton, Slider, Spinner, Stack, Switch, Table, Tabs, Text, Textarea, Toaster, ToggleGroup, Tooltip, VisuallyHidden, config, toast, useConfig };
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface InitOptions {
|
|
2
|
+
root: string;
|
|
3
|
+
configPath?: string;
|
|
4
|
+
configProvided?: boolean;
|
|
5
|
+
buildTool?: BuildTool;
|
|
6
|
+
install?: boolean;
|
|
7
|
+
version: string;
|
|
8
|
+
}
|
|
9
|
+
export interface InitResult {
|
|
10
|
+
configPath: string;
|
|
11
|
+
tsconfig: string;
|
|
12
|
+
buildConfig: string;
|
|
13
|
+
buildTool: BuildTool;
|
|
14
|
+
dependencyAdded: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type BuildTool = 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';
|
|
17
|
+
export declare function initProject(options: InitOptions): Promise<InitResult>;
|
|
18
|
+
export {};
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { CONFIG_MODULE, DEFAULT_CONFIG_PATH, configMappings, findTsconfig } from "./setup.js";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { applyEdits, modify } from "jsonc-parser";
|
|
6
|
+
import { env } from "node:process";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { platform } from "node:os";
|
|
9
|
+
//#region src/init.ts
|
|
10
|
+
var buildConfigNames = {
|
|
11
|
+
vite: [
|
|
12
|
+
"vite.config.ts",
|
|
13
|
+
"vite.config.mts",
|
|
14
|
+
"vite.config.js",
|
|
15
|
+
"vite.config.mjs"
|
|
16
|
+
],
|
|
17
|
+
webpack: [
|
|
18
|
+
"webpack.config.ts",
|
|
19
|
+
"webpack.config.mts",
|
|
20
|
+
"webpack.config.js",
|
|
21
|
+
"webpack.config.mjs",
|
|
22
|
+
"webpack.config.cjs",
|
|
23
|
+
"webpack.config.cts"
|
|
24
|
+
],
|
|
25
|
+
rspack: [
|
|
26
|
+
"rspack.config.ts",
|
|
27
|
+
"rspack.config.mts",
|
|
28
|
+
"rspack.config.js",
|
|
29
|
+
"rspack.config.mjs",
|
|
30
|
+
"rspack.config.cjs",
|
|
31
|
+
"rspack.config.cts"
|
|
32
|
+
],
|
|
33
|
+
rollup: [
|
|
34
|
+
"rollup.config.ts",
|
|
35
|
+
"rollup.config.mts",
|
|
36
|
+
"rollup.config.js",
|
|
37
|
+
"rollup.config.mjs",
|
|
38
|
+
"rollup.config.cjs",
|
|
39
|
+
"rollup.config.cts"
|
|
40
|
+
],
|
|
41
|
+
esbuild: [
|
|
42
|
+
"esbuild.config.ts",
|
|
43
|
+
"esbuild.config.mts",
|
|
44
|
+
"esbuild.config.js",
|
|
45
|
+
"esbuild.config.mjs",
|
|
46
|
+
"esbuild.config.cjs",
|
|
47
|
+
"esbuild.config.cts"
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
function findBuildConfig(root, requested) {
|
|
51
|
+
const tools = requested ? [requested] : Object.keys(buildConfigNames);
|
|
52
|
+
for (const tool of tools) {
|
|
53
|
+
const file = buildConfigNames[tool].map((name) => resolve(root, name)).find((candidate) => existsSync(candidate));
|
|
54
|
+
if (file) return {
|
|
55
|
+
tool,
|
|
56
|
+
file
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function closingToken(source, start, open, close) {
|
|
61
|
+
let depth = 0;
|
|
62
|
+
let quote = "";
|
|
63
|
+
let escaped = false;
|
|
64
|
+
let lineComment = false;
|
|
65
|
+
let blockComment = false;
|
|
66
|
+
for (let index = start; index < source.length; index += 1) {
|
|
67
|
+
const character = source[index];
|
|
68
|
+
const next = source[index + 1];
|
|
69
|
+
if (lineComment) {
|
|
70
|
+
if (character === "\n") lineComment = false;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (blockComment) {
|
|
74
|
+
if (character === "*" && next === "/") {
|
|
75
|
+
blockComment = false;
|
|
76
|
+
index += 1;
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (quote) {
|
|
81
|
+
if (escaped) escaped = false;
|
|
82
|
+
else if (character === "\\") escaped = true;
|
|
83
|
+
else if (character === quote) quote = "";
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (character === "/" && next === "/") {
|
|
87
|
+
lineComment = true;
|
|
88
|
+
index += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (character === "/" && next === "*") {
|
|
92
|
+
blockComment = true;
|
|
93
|
+
index += 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (character === "'" || character === "\"" || character === "`") {
|
|
97
|
+
quote = character;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (character === open) depth += 1;
|
|
101
|
+
if (character === close) {
|
|
102
|
+
depth -= 1;
|
|
103
|
+
if (depth === 0) return index;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
function existingPluginPath(source) {
|
|
109
|
+
const call = /\byarcl\s*\(/g.exec(source);
|
|
110
|
+
if (!call) return void 0;
|
|
111
|
+
const open = source.indexOf("(", call.index);
|
|
112
|
+
const close = closingToken(source, open, "(", ")");
|
|
113
|
+
if (close < 0) throw new Error("yarcl: Could not parse the yarcl plugin call in the build config.");
|
|
114
|
+
const options = source.slice(open + 1, close).trim();
|
|
115
|
+
if (!options) return DEFAULT_CONFIG_PATH;
|
|
116
|
+
const match = /\bconfig\s*:\s*(['"`])([^'"`]+)\1/.exec(options);
|
|
117
|
+
if (match) return match[2];
|
|
118
|
+
if (options.startsWith("{")) return /\bconfig\s*:/.test(options) ? null : DEFAULT_CONFIG_PATH;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
function pluginImport(source, tool, file) {
|
|
122
|
+
const entry = `@yarcl/react/${tool}`;
|
|
123
|
+
const oldImport = /import\s*\{\s*yarcl\s*\}\s*from\s*['"]@yarcl\/react\/plugin['"]\s*;?/;
|
|
124
|
+
if (oldImport.test(source)) return source.replace(oldImport, `import yarcl from '${entry}';`);
|
|
125
|
+
if (source.includes(entry)) return source;
|
|
126
|
+
return /\.(?:cjs|cts)$/.test(file) || /\bmodule\.exports\b|\brequire\s*\(/.test(source) && !/\bimport\s/.test(source) ? `const yarcl = require('${entry}');\n${source}` : `import yarcl from '${entry}';\n${source}`;
|
|
127
|
+
}
|
|
128
|
+
function addPlugin(source, configPath, config) {
|
|
129
|
+
if (existingPluginPath(source) !== void 0) return pluginImport(source, config.tool, config.file);
|
|
130
|
+
const match = /\bplugins\s*:\s*\[/g.exec(source);
|
|
131
|
+
if (!match) throw new Error(`yarcl: Could not find a plugins array in the ${config.tool} config. Add one and run "yarcl init" again.`);
|
|
132
|
+
const open = source.indexOf("[", match.index);
|
|
133
|
+
const close = closingToken(source, open, "[", "]");
|
|
134
|
+
if (close < 0) throw new Error(`yarcl: Could not parse the plugins array in the ${config.tool} config.`);
|
|
135
|
+
const body = source.slice(open + 1, close);
|
|
136
|
+
const plugin = `yarcl({ config: '${configPath.replaceAll("'", "\\'")}' })`;
|
|
137
|
+
let updatedBody;
|
|
138
|
+
if (!body.includes("\n")) updatedBody = body.trim() ? `${body.trimEnd()}, ${plugin}` : plugin;
|
|
139
|
+
else {
|
|
140
|
+
const trailing = /\s*$/.exec(body)?.[0] ?? "";
|
|
141
|
+
const content = body.slice(0, body.length - trailing.length).trimEnd();
|
|
142
|
+
const closeIndent = /(?:^|\n)([ \t]*)[^\n]*$/.exec(source.slice(0, close))?.[1] ?? "";
|
|
143
|
+
const itemIndent = /\n([ \t]+)\S/.exec(body)?.[1] ?? `${closeIndent} `;
|
|
144
|
+
updatedBody = `${content}${content.endsWith(",") ? "" : ","}\n${itemIndent}${plugin},${trailing}`;
|
|
145
|
+
}
|
|
146
|
+
return pluginImport(source.slice(0, open + 1) + updatedBody + source.slice(close), config.tool, config.file);
|
|
147
|
+
}
|
|
148
|
+
function detectPackageManager(root) {
|
|
149
|
+
if (existsSync(resolve(root, "pnpm-lock.yaml"))) return "pnpm";
|
|
150
|
+
if (existsSync(resolve(root, "yarn.lock"))) return "yarn";
|
|
151
|
+
if (existsSync(resolve(root, "bun.lock")) || existsSync(resolve(root, "bun.lockb"))) return "bun";
|
|
152
|
+
const caller = env.npm_config_user_agent?.split("/")[0];
|
|
153
|
+
if (caller === "pnpm" || caller === "yarn" || caller === "bun") return caller;
|
|
154
|
+
return "npm";
|
|
155
|
+
}
|
|
156
|
+
function install(root) {
|
|
157
|
+
const manager = detectPackageManager(root);
|
|
158
|
+
const executable = platform() === "win32" ? `${manager}.cmd` : manager;
|
|
159
|
+
const result = spawnSync(executable, manager === "pnpm" ? ["install", "--no-frozen-lockfile"] : ["install"], {
|
|
160
|
+
cwd: root,
|
|
161
|
+
stdio: "inherit"
|
|
162
|
+
});
|
|
163
|
+
if (result.error) throw result.error;
|
|
164
|
+
if (result.status !== 0) throw new Error(`yarcl: ${manager} install failed with status ${result.status ?? "unknown"}.`);
|
|
165
|
+
}
|
|
166
|
+
function normalizedConfigPath(root, configPath) {
|
|
167
|
+
const projectRelative = relative(root, resolve(root, configPath));
|
|
168
|
+
if (isAbsolute(configPath) || projectRelative === ".." || projectRelative.startsWith(`..${sep}`)) throw new Error("yarcl: The config path must be inside the project.");
|
|
169
|
+
return configPath.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
170
|
+
}
|
|
171
|
+
async function initProject(options) {
|
|
172
|
+
const root = resolve(options.root);
|
|
173
|
+
const manifestPath = resolve(root, "package.json");
|
|
174
|
+
const buildConfig = findBuildConfig(root, options.buildTool);
|
|
175
|
+
const tsconfig = findTsconfig(root);
|
|
176
|
+
if (!existsSync(manifestPath)) throw new Error(`yarcl: No package.json found in ${root}.`);
|
|
177
|
+
if (!buildConfig) {
|
|
178
|
+
const requested = options.buildTool ? `${options.buildTool} config` : "Vite, webpack, Rspack, Rollup or esbuild config";
|
|
179
|
+
throw new Error(`yarcl: No ${requested} found in ${root}.`);
|
|
180
|
+
}
|
|
181
|
+
if (!tsconfig) throw new Error(`yarcl: No tsconfig.app.json or tsconfig.json found in ${root}.`);
|
|
182
|
+
const requested = normalizedConfigPath(root, options.configPath ?? "src/yarcl.config.ts");
|
|
183
|
+
const buildSource = await readFile(buildConfig.file, "utf8");
|
|
184
|
+
const existing = existingPluginPath(buildSource);
|
|
185
|
+
if (existing === null) throw new Error("yarcl: The existing yarcl plugin uses a dynamic config path that cannot be updated.");
|
|
186
|
+
if (options.configProvided && existing && resolve(root, existing) !== resolve(root, requested)) throw new Error(`yarcl: The ${buildConfig.tool} plugin already uses "${existing}", not "${requested}".`);
|
|
187
|
+
const configPath = normalizedConfigPath(root, existing ?? requested);
|
|
188
|
+
const updatedBuildConfig = addPlugin(buildSource, configPath, buildConfig);
|
|
189
|
+
const tsconfigSource = await readFile(tsconfig, "utf8");
|
|
190
|
+
const eol = tsconfigSource.includes("\r\n") ? "\r\n" : "\n";
|
|
191
|
+
const edits = modify(tsconfigSource, [
|
|
192
|
+
"compilerOptions",
|
|
193
|
+
"paths",
|
|
194
|
+
CONFIG_MODULE
|
|
195
|
+
], configMappings(root, tsconfig, configPath), { formattingOptions: {
|
|
196
|
+
insertSpaces: true,
|
|
197
|
+
tabSize: 2,
|
|
198
|
+
eol
|
|
199
|
+
} });
|
|
200
|
+
const updatedTsconfig = applyEdits(tsconfigSource, edits);
|
|
201
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
202
|
+
const dependencyAdded = !manifest.dependencies?.["@yarcl/react"] && !manifest.devDependencies?.["@yarcl/react"];
|
|
203
|
+
if (dependencyAdded) manifest.dependencies = {
|
|
204
|
+
...manifest.dependencies,
|
|
205
|
+
"@yarcl/react": `^${options.version}`
|
|
206
|
+
};
|
|
207
|
+
const targetConfig = resolve(root, configPath);
|
|
208
|
+
await Promise.all([
|
|
209
|
+
writeFile(buildConfig.file, updatedBuildConfig),
|
|
210
|
+
writeFile(tsconfig, updatedTsconfig),
|
|
211
|
+
writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`),
|
|
212
|
+
existsSync(targetConfig) ? Promise.resolve() : mkdir(dirname(targetConfig), { recursive: true }).then(() => writeFile(targetConfig, "import { defineConfig } from '@yarcl/react/define';\nimport defaults from '@yarcl/react/defaults';\n\nexport default defineConfig({\n ...defaults,\n});\n"))
|
|
213
|
+
]);
|
|
214
|
+
if (dependencyAdded && options.install !== false) install(root);
|
|
215
|
+
return {
|
|
216
|
+
configPath,
|
|
217
|
+
tsconfig,
|
|
218
|
+
buildConfig: buildConfig.file,
|
|
219
|
+
buildTool: buildConfig.tool,
|
|
220
|
+
dependencyAdded
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
export { initProject };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
/** Options for the yarcl Vite plugin. */
|
|
1
|
+
/** Options shared by every yarcl build-tool plugin. */
|
|
3
2
|
export interface YarclPluginOptions {
|
|
4
3
|
/**
|
|
5
|
-
* Path to the consumer's config file, relative to the
|
|
4
|
+
* Path to the consumer's config file, relative to the project root.
|
|
6
5
|
* If the file does not exist, the library's default config is used.
|
|
7
6
|
* @default 'src/yarcl.config.ts'
|
|
8
7
|
*/
|
|
9
8
|
config?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Project root used to resolve the config and TypeScript mapping.
|
|
11
|
+
* Build-tool adapters normally detect it automatically.
|
|
12
|
+
* @default process.cwd()
|
|
13
|
+
*/
|
|
14
|
+
root?: string;
|
|
10
15
|
}
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* - Aliases `@yarcl/config` to the consumer's config file (or the library default).
|
|
15
|
-
* - Generates `virtual:yarcl.css` from the config at build time: CSS variables on `:root`
|
|
16
|
-
* and one `yarcl-{group}-{key}` class per key. No inline styles, no runtime cost.
|
|
17
|
-
* - Warns when a color's foreground fails WCAG AA contrast.
|
|
18
|
-
* - Regenerates the CSS when the config file changes.
|
|
19
|
-
*
|
|
20
|
-
* Must be paired with a matching `paths` entry for `@yarcl/config` in the
|
|
21
|
-
* consumer's `tsconfig.json`, so the types resolve to the same file.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* // vite.config.ts
|
|
26
|
-
* import { yarcl } from '@yarcl/react/plugin';
|
|
27
|
-
*
|
|
28
|
-
* export default defineConfig({
|
|
29
|
-
* plugins: [react(), yarcl({ config: 'src/yarcl.config.ts' })],
|
|
30
|
-
* });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function yarcl({ config }?: YarclPluginOptions): Plugin;
|
|
16
|
+
/** Shared yarcl plugin implementation used by every build-tool adapter. */
|
|
17
|
+
export declare const yarclPlugin: import("unplugin").UnpluginInstance<YarclPluginOptions | undefined, boolean>;
|