@kirana-ui/react 0.3.0 → 0.4.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/CHANGELOG.md +140 -0
- package/llms.txt +1507 -121
- package/package.json +44 -3
- package/skills/kirana-ui-primitives/SKILL.md +24 -4
- package/src/accordion.d.ts +2 -2
- package/src/accordion.js +3 -2
- package/src/accordion.js.map +1 -1
- package/src/autosize.d.ts +1 -1
- package/src/avatar.d.ts +2 -2
- package/src/avatar.js +3 -3
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +5 -2
- package/src/button.js +4 -1
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +6 -6
- package/src/calendar.js +13 -5
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +6 -3
- package/src/carousel.js +1 -1
- package/src/carousel.js.map +1 -1
- package/src/checkbox-group.d.ts +2 -1
- package/src/checkbox-group.js +1 -1
- package/src/checkbox-group.js.map +1 -1
- package/src/checkbox.d.ts +6 -1
- package/src/checkbox.js +1 -1
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +1 -1
- package/src/color-picker.d.ts +61 -0
- package/src/color-picker.js +119 -0
- package/src/color-picker.js.map +1 -0
- package/src/combobox.d.ts +13 -4
- package/src/combobox.js +13 -5
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +3 -3
- package/src/command.js.map +1 -1
- package/src/date-field.d.ts +2 -2
- package/src/date-field.js +3 -2
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +29 -8
- package/src/date-picker.js +21 -5
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +6 -6
- package/src/dialog.js +22 -7
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -1
- package/src/direction.js +1 -1
- package/src/editable.d.ts +32 -0
- package/src/editable.js +63 -0
- package/src/editable.js.map +1 -0
- package/src/field.d.ts +1 -1
- package/src/fieldset.d.ts +1 -1
- package/src/file-upload.d.ts +54 -0
- package/src/file-upload.js +96 -0
- package/src/file-upload.js.map +1 -0
- package/src/form.d.ts +1 -1
- package/src/hover-popup.d.ts +1 -1
- package/src/hover-popup.js +1 -1
- package/src/index.d.ts +26 -8
- package/src/index.js +11 -1
- package/src/input.d.ts +1 -1
- package/src/input.js +1 -1
- package/src/label.d.ts +1 -1
- package/src/listbox.d.ts +1 -1
- package/src/listbox.js +1 -1
- package/src/menu.d.ts +5 -5
- package/src/menu.js +14 -9
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +2 -2
- package/src/menubar.js +4 -2
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +1 -1
- package/src/navigation-menu.d.ts +5 -5
- package/src/navigation-menu.js +14 -4
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +2 -1
- package/src/number-field.js +1 -1
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +3 -2
- package/src/otp.js +9 -2
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +1 -1
- package/src/password-input.d.ts +23 -0
- package/src/password-input.js +40 -0
- package/src/password-input.js.map +1 -0
- package/src/popover.d.ts +1 -1
- package/src/popover.js +1 -1
- package/src/qr-code.d.ts +1 -1
- package/src/radio-group.d.ts +1 -1
- package/src/radio-group.js +1 -1
- package/src/rating.d.ts +28 -0
- package/src/rating.js +59 -0
- package/src/rating.js.map +1 -0
- package/src/resizable.d.ts +1 -1
- package/src/resizable.js +1 -1
- package/src/runtime.d.ts +10 -3
- package/src/runtime.js +18 -4
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +1 -1
- package/src/scroll-area.js +1 -1
- package/src/select.d.ts +17 -6
- package/src/select.js +6 -3
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +1 -1
- package/src/slider.d.ts +1 -1
- package/src/slider.js +1 -1
- package/src/steps.d.ts +51 -0
- package/src/steps.js +69 -0
- package/src/steps.js.map +1 -0
- package/src/switch.d.ts +2 -1
- package/src/switch.js +1 -1
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +2 -2
- package/src/tabs.js +4 -3
- package/src/tabs.js.map +1 -1
- package/src/tags-input.d.ts +47 -0
- package/src/tags-input.js +92 -0
- package/src/tags-input.js.map +1 -0
- package/src/time-field.d.ts +32 -0
- package/src/time-field.js +67 -0
- package/src/time-field.js.map +1 -0
- package/src/toast.d.ts +1 -1
- package/src/toggle-group.d.ts +2 -2
- package/src/toggle-group.js +4 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +1 -1
- package/src/toggle.js +1 -1
- package/src/toolbar.d.ts +14 -6
- package/src/toolbar.js +19 -9
- package/src/toolbar.js.map +1 -1
- package/src/tour.d.ts +61 -0
- package/src/tour.js +68 -0
- package/src/tour.js.map +1 -0
- package/src/tree.d.ts +45 -0
- package/src/tree.js +93 -0
- package/src/tree.js.map +1 -0
- package/src/use-render.js +1 -1
- package/src/value-bar.d.ts +1 -1
package/src/otp.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { OtpProps } from "@kirana-ui/core/otp";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["otp"];
|
|
7
7
|
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<OtpProps, "id"> & {
|
|
8
|
+
/** The id of its input, not of the root: a `<label for>` names it. */
|
|
8
9
|
id?: string;
|
|
9
10
|
}>;
|
|
10
|
-
declare function Root({ length, value, defaultValue, onValueChange, onComplete, mode, pattern, disabled, name, form, id, ...rest }: RootProps): ReactElement;
|
|
11
|
+
declare function Root({ length, value, defaultValue, onValueChange, onValueComplete, onComplete, validationType, mode, pattern, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
11
12
|
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
|
|
12
13
|
declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
14
|
export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>>;
|
package/src/otp.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { FieldContext } from "./field-context.js";
|
|
1
2
|
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
2
3
|
import { createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
3
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
4
6
|
import { createOtp } from "@kirana-ui/core/otp";
|
|
5
7
|
// src/otp.tsx
|
|
@@ -10,16 +12,21 @@ function useOtp(part) {
|
|
|
10
12
|
if (!controller) throw new Error(`<Otp.${part}> must be inside <Otp.Root>`);
|
|
11
13
|
return controller;
|
|
12
14
|
}
|
|
13
|
-
function Root({ length, value, defaultValue, onValueChange, onComplete, mode, pattern, disabled, name, form, id, ...rest }) {
|
|
14
|
-
const
|
|
15
|
+
function Root({ length, value, defaultValue, onValueChange, onValueComplete, onComplete, validationType, mode, pattern, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
16
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
17
|
+
const controller = useController(within(createOtp, { field }), {
|
|
15
18
|
length,
|
|
16
19
|
value,
|
|
17
20
|
defaultValue,
|
|
18
21
|
onValueChange,
|
|
22
|
+
onValueComplete,
|
|
19
23
|
onComplete,
|
|
24
|
+
validationType,
|
|
20
25
|
mode,
|
|
21
26
|
pattern,
|
|
22
27
|
disabled,
|
|
28
|
+
readOnly,
|
|
29
|
+
required,
|
|
23
30
|
name,
|
|
24
31
|
form,
|
|
25
32
|
id
|
package/src/otp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otp.js","names":[],"sources":["../../../../packages/react/src/otp.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createOtp } from \"@kirana-ui/core/otp\"\nimport type { Otp as Controller, OtpProps, OtpSlot } from \"@kirana-ui/core/otp\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"otp\"]\n\nconst Context = createContext<Controller | null>(null)\nconst SlotContext = createContext<OtpSlot | null>(null)\n\nfunction useOtp(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Otp.${part}> must be inside <Otp.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<OtpProps, \"id\"> & { id?: string
|
|
1
|
+
{"version":3,"file":"otp.js","names":[],"sources":["../../../../packages/react/src/otp.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createOtp } from \"@kirana-ui/core/otp\"\nimport type { Otp as Controller, OtpProps, OtpSlot } from \"@kirana-ui/core/otp\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"otp\"]\n\nconst Context = createContext<Controller | null>(null)\nconst SlotContext = createContext<OtpSlot | null>(null)\n\nfunction useOtp(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Otp.${part}> must be inside <Otp.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<OtpProps, \"id\"> & {\n /** The id of its input, not of the root: a `<label for>` names it. */\n id?: string\n }\n>\n\nfunction Root({\n length,\n value,\n defaultValue,\n onValueChange,\n onValueComplete,\n onComplete,\n validationType,\n mode,\n pattern,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<OtpProps, Controller>(within(createOtp, { field }), {\n length,\n value,\n defaultValue,\n onValueChange,\n onValueComplete,\n onComplete,\n validationType,\n mode,\n pattern,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n })\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useOtp(\"Input\").input, \"input\", props)\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>>\n\nconst Group = (props: GroupProps) => usePart(useOtp(\"Group\").group, \"div\", props)\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\nconst Separator = (props: SeparatorProps) => usePart(useOtp(\"Separator\").separator, \"div\", props)\n\nexport type SlotProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"slot\"]>,\n {\n /** Which character of the code it shows, from 0. */\n index: number\n }\n>\n\n/** One cell: it shows its character, then whatever it is given (a caret). */\nfunction Slot({ index, ...props }: SlotProps): ReactElement {\n const slot = useOtp(\"Slot\").slot(index)\n const char = useSignal(slot.char)\n return (\n <SlotContext.Provider value={slot}>\n {usePart(slot.part, \"div\", props, undefined, (content) => (\n // Its character comes first, whatever element the caller asked for.\n <>\n {char}\n {content}\n </>\n ))}\n </SlotContext.Provider>\n )\n}\n\nexport type CaretProps = PartComponentProps<\"div\", StateOf<Parts[\"caret\"]>>\n\n/** Drawn in its cell while the cell is the active one and empty. */\nfunction Caret(props: CaretProps): ReactElement | null {\n const controller = useOtp(\"Caret\")\n const slot = useContext(SlotContext)\n if (!slot) throw new Error(\"<Otp.Caret> must be inside <Otp.Slot>\")\n const shown = useSignal(slot.caret)\n return shown ? <PartElement of={controller.caretPart} tag=\"div\" {...props} /> : null\n}\n\nexport const Otp = /* @__PURE__ */ parts(\"Otp\", { Root, Input, Group, Slot, Separator, Caret })\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAA8B,IAAI;AAEtD,SAAS,OAAO,MAA0B;CACxC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,QAAQ,KAAK,4BAA4B;CAC1E,OAAO;AACT;AAWA,SAAS,KAAK,EACZ,QACA,OACA,cACA,eACA,iBACA,YACA,gBACA,MACA,SACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cAAoC,OAAO,WAAW,EAAE,MAAM,CAAC,GAAG;EACnF;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;AAIA,MAAM,SAAS,UAAsB,QAAQ,OAAO,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAGlF,MAAM,SAAS,UAAsB,QAAQ,OAAO,OAAO,CAAC,CAAC,OAAO,OAAO,KAAK;AAGhF,MAAM,aAAa,UAA0B,QAAQ,OAAO,WAAW,CAAC,CAAC,WAAW,OAAO,KAAK;;AAYhG,SAAS,KAAK,EAAE,OAAO,GAAG,SAAkC;CAC1D,MAAM,OAAO,OAAO,MAAM,CAAC,CAAC,KAAK,KAAK;CACtC,MAAM,OAAO,UAAU,KAAK,IAAI;CAChC,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAC1B,UAAA,QAAQ,KAAK,MAAM,OAAO,OAAO,KAAA,IAAY,YAE5C,qBAAA,YAAA,EAAA,UAAA,CACG,MACA,OACD,EAAA,CAAA,CACH;CACmB,CAAA;AAE1B;;AAKA,SAAS,MAAM,OAAwC;CACrD,MAAM,aAAa,OAAO,OAAO;CACjC,MAAM,OAAO,WAAW,WAAW;CACnC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,uCAAuC;CAElE,OADc,UAAU,KAAK,KAClB,IAAI,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAM,GAAI;CAAQ,CAAA,IAAI;AAClF;AAEA,MAAa,MAAsB,sBAAM,OAAO;CAAE;CAAM;CAAO;CAAO;CAAM;CAAW;AAAM,CAAC"}
|
package/src/pagination.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { PaginationEntry, PaginationProps } from "@kirana-ui/core/pagination";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["pagination"];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { PasswordInputProps } from "@kirana-ui/core/password-input";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["passwordInput"];
|
|
7
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, PasswordInputProps>;
|
|
8
|
+
declare function Root({ visible, defaultVisible, onVisibleChange, disabled, onValueChange, ...rest }: RootProps): ReactElement;
|
|
9
|
+
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
|
|
10
|
+
/** It takes what an `<input>` takes (`value`, `defaultValue`, `autoComplete`). */
|
|
11
|
+
declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
12
|
+
export type ToggleProps = PartComponentProps<"button", StateOf<Parts["toggle"]>>;
|
|
13
|
+
declare const Toggle: (props: ToggleProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
14
|
+
export type IndicatorProps = PartComponentProps<"span", StateOf<Parts["indicator"]>>;
|
|
15
|
+
declare const Indicator: (props: IndicatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
16
|
+
export declare const PasswordInput: {
|
|
17
|
+
readonly Root: typeof Root;
|
|
18
|
+
readonly Input: typeof Input;
|
|
19
|
+
readonly Toggle: typeof Toggle;
|
|
20
|
+
readonly Indicator: typeof Indicator;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=password-input.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FieldContext } from "./field-context.js";
|
|
2
|
+
import { parts, useController, usePart } from "./runtime.js";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createPasswordInput } from "@kirana-ui/core/password-input";
|
|
7
|
+
// src/password-input.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
function usePasswordInput(part) {
|
|
10
|
+
const controller = useContext(Context);
|
|
11
|
+
if (!controller) throw new Error(`<PasswordInput.${part}> must be inside <PasswordInput.Root>`);
|
|
12
|
+
return controller;
|
|
13
|
+
}
|
|
14
|
+
function Root({ visible, defaultVisible, onVisibleChange, disabled, onValueChange, ...rest }) {
|
|
15
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
16
|
+
const controller = useController(within(createPasswordInput, { field }), {
|
|
17
|
+
visible,
|
|
18
|
+
defaultVisible,
|
|
19
|
+
onVisibleChange,
|
|
20
|
+
disabled,
|
|
21
|
+
onValueChange
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
24
|
+
value: controller,
|
|
25
|
+
children: usePart(controller.root, "div", rest)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** It takes what an `<input>` takes (`value`, `defaultValue`, `autoComplete`). */
|
|
29
|
+
const Input = (props) => usePart(usePasswordInput("Input").input, "input", props);
|
|
30
|
+
const Toggle = (props) => usePart(usePasswordInput("Toggle").toggle, "button", props);
|
|
31
|
+
const Indicator = (props) => usePart(usePasswordInput("Indicator").indicator, "span", props);
|
|
32
|
+
const PasswordInput = /* @__PURE__ */ parts("PasswordInput", {
|
|
33
|
+
Root,
|
|
34
|
+
Input,
|
|
35
|
+
Toggle,
|
|
36
|
+
Indicator
|
|
37
|
+
});
|
|
38
|
+
export { PasswordInput };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=password-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-input.js","names":[],"sources":["../../../../packages/react/src/password-input.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createPasswordInput } from \"@kirana-ui/core/password-input\"\nimport type {\n PasswordInput as Controller,\n PasswordInputProps,\n} from \"@kirana-ui/core/password-input\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"passwordInput\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction usePasswordInput(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<PasswordInput.${part}> must be inside <PasswordInput.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\"div\", StateOf<Parts[\"root\"]>, PasswordInputProps>\n\nfunction Root({\n visible,\n defaultVisible,\n onVisibleChange,\n disabled,\n onValueChange,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<PasswordInputProps, Controller>(\n within(createPasswordInput, { field }),\n { visible, defaultVisible, onVisibleChange, disabled, onValueChange }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\n/** It takes what an `<input>` takes (`value`, `defaultValue`, `autoComplete`). */\nconst Input = (props: InputProps) => usePart(usePasswordInput(\"Input\").input, \"input\", props)\n\nexport type ToggleProps = PartComponentProps<\"button\", StateOf<Parts[\"toggle\"]>>\n\nconst Toggle = (props: ToggleProps) => usePart(usePasswordInput(\"Toggle\").toggle, \"button\", props)\n\nexport type IndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"indicator\"]>>\n\nconst Indicator = (props: IndicatorProps) =>\n usePart(usePasswordInput(\"Indicator\").indicator, \"span\", props)\n\nexport const PasswordInput = /* @__PURE__ */ parts(\"PasswordInput\", {\n Root,\n Input,\n Toggle,\n Indicator,\n})\n"],"mappings":";;;;;;;AAiBA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,iBAAiB,MAA0B;CAClD,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,kBAAkB,KAAK,sCAAsC;CAC9F,OAAO;AACT;AAIA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,UACA,eACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cACjB,OAAO,qBAAqB,EAAE,MAAM,CAAC,GACrC;EAAE;EAAS;EAAgB;EAAiB;EAAU;CAAc,CACtE;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAKA,MAAM,SAAS,UAAsB,QAAQ,iBAAiB,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAI5F,MAAM,UAAU,UAAuB,QAAQ,iBAAiB,QAAQ,CAAC,CAAC,QAAQ,UAAU,KAAK;AAIjG,MAAM,aAAa,UACjB,QAAQ,iBAAiB,WAAW,CAAC,CAAC,WAAW,QAAQ,KAAK;AAEhE,MAAa,gBAAgC,sBAAM,iBAAiB;CAClE;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/popover.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { Popover as Popover$1, PopoverProps, PopoverTriggerOptions } from "@kirana-ui/core/popover";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["popover"];
|
package/src/popover.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Portal as Portal$1, parts, useController, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
2
|
-
import { defined } from "@kirana-ui/core";
|
|
3
2
|
import { createContext, useContext } from "react";
|
|
3
|
+
import { defined } from "@kirana-ui/core";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { createPopover } from "@kirana-ui/core/popover";
|
|
6
6
|
// src/popover.tsx
|
package/src/qr-code.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { QrCodeProps } from "@kirana-ui/core/qr-code";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["qrCode"];
|
package/src/radio-group.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { RadioGroupProps } from "@kirana-ui/core/radio-group";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["radioGroup"];
|
package/src/radio-group.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { FieldContext } from "./field-context.js";
|
|
3
3
|
import { PartElement, parts, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
4
|
-
import { defined, within } from "@kirana-ui/core";
|
|
5
4
|
import { createContext, useContext, useMemo } from "react";
|
|
5
|
+
import { defined, within } from "@kirana-ui/core";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { createRadioGroup } from "@kirana-ui/core/radio-group";
|
|
8
8
|
// src/radio-group.tsx
|
package/src/rating.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { RatingProps } from "@kirana-ui/core/rating";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["rating"];
|
|
7
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<RatingProps, "id"> & {
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare function Root({ value, defaultValue, onValueChange, onHoverChange, count, allowHalf, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
11
|
+
export interface ItemsProps {
|
|
12
|
+
/** Draws one item, once for each place, from 1. */
|
|
13
|
+
children: (place: number) => ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/** Draws its child once for each item, from 1 to `count`. */
|
|
16
|
+
declare function Items({ children }: ItemsProps): ReactElement;
|
|
17
|
+
export type ItemProps = PartComponentProps<"span", StateOf<Parts["item"]>, {
|
|
18
|
+
/** Its place among the items, from 1. */
|
|
19
|
+
place: number;
|
|
20
|
+
}>;
|
|
21
|
+
declare function Item({ place, ...props }: ItemProps): ReactElement;
|
|
22
|
+
export declare const Rating: {
|
|
23
|
+
readonly Root: typeof Root;
|
|
24
|
+
readonly Items: typeof Items;
|
|
25
|
+
readonly Item: typeof Item;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=rating.d.ts.map
|
package/src/rating.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { FieldContext } from "./field-context.js";
|
|
3
|
+
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
4
|
+
import { Fragment, createContext, useContext } from "react";
|
|
5
|
+
import { within } from "@kirana-ui/core";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { createRating } from "@kirana-ui/core/rating";
|
|
8
|
+
// src/rating.tsx
|
|
9
|
+
const Context = createContext(null);
|
|
10
|
+
function useRating(part) {
|
|
11
|
+
const controller = useContext(Context);
|
|
12
|
+
if (!controller) throw new Error(`<Rating.${part}> must be inside <Rating.Root>`);
|
|
13
|
+
return controller;
|
|
14
|
+
}
|
|
15
|
+
function Root({ value, defaultValue, onValueChange, onHoverChange, count, allowHalf, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
16
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
17
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
18
|
+
const create = within(createRating, {
|
|
19
|
+
field,
|
|
20
|
+
direction
|
|
21
|
+
});
|
|
22
|
+
const controller = useController(create, {
|
|
23
|
+
value,
|
|
24
|
+
defaultValue,
|
|
25
|
+
onValueChange,
|
|
26
|
+
onHoverChange,
|
|
27
|
+
count,
|
|
28
|
+
allowHalf,
|
|
29
|
+
disabled,
|
|
30
|
+
readOnly,
|
|
31
|
+
required,
|
|
32
|
+
name,
|
|
33
|
+
form,
|
|
34
|
+
id
|
|
35
|
+
});
|
|
36
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
37
|
+
value: controller,
|
|
38
|
+
children: usePart(controller.root, "div", rest, void 0, (content) => /* @__PURE__ */ jsxs(Fragment$1, { children: [content, /* @__PURE__ */ jsx(PartElement, {
|
|
39
|
+
of: controller.input,
|
|
40
|
+
tag: "input"
|
|
41
|
+
})] }))
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Draws its child once for each item, from 1 to `count`. */
|
|
45
|
+
function Items({ children }) {
|
|
46
|
+
const places = useSignal(useRating("Items").places);
|
|
47
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: places.map((place) => /* @__PURE__ */ jsx(Fragment, { children: children(place) }, place)) });
|
|
48
|
+
}
|
|
49
|
+
function Item({ place, ...props }) {
|
|
50
|
+
return usePart(useRating("Item").item(place), "span", props);
|
|
51
|
+
}
|
|
52
|
+
const Rating = /* @__PURE__ */ parts("Rating", {
|
|
53
|
+
Root,
|
|
54
|
+
Items,
|
|
55
|
+
Item
|
|
56
|
+
});
|
|
57
|
+
export { Rating };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=rating.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rating.js","names":[],"sources":["../../../../packages/react/src/rating.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createRating } from \"@kirana-ui/core/rating\"\nimport type { Rating as Controller, RatingProps } from \"@kirana-ui/core/rating\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"rating\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useRating(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Rating.${part}> must be inside <Rating.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<RatingProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n onHoverChange,\n count,\n allowHalf,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createRating, { field, direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onHoverChange,\n count,\n allowHalf,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n })\n return (\n <Context.Provider value={controller}>\n {usePart(controller.root, \"div\", rest, undefined, (content) => (\n // The input a form reads is the element's last child, whatever element was asked for.\n <>\n {content}\n <PartElement of={controller.input} tag=\"input\" />\n </>\n ))}\n </Context.Provider>\n )\n}\n\nexport interface ItemsProps {\n /** Draws one item, once for each place, from 1. */\n children: (place: number) => ReactNode\n}\n\n/** Draws its child once for each item, from 1 to `count`. */\nfunction Items({ children }: ItemsProps): ReactElement {\n const places = useSignal(useRating(\"Items\").places)\n return (\n <>\n {places.map((place) => (\n <Fragment key={place}>{children(place)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type ItemProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"item\"]>,\n {\n /** Its place among the items, from 1. */\n place: number\n }\n>\n\nfunction Item({ place, ...props }: ItemProps): ReactElement {\n return usePart(useRating(\"Item\").item(place), \"span\", props)\n}\n\nexport const Rating = /* @__PURE__ */ parts(\"Rating\", { Root, Items, Item })\n"],"mappings":";;;;;;;;AAeA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,eACA,OACA,WACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,cAAc;EAAE;EAAO;CAAU,CAAC;CACxD,MAAM,aAAyB,cAAc,QAAQ;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACtB,UAAA,QAAQ,WAAW,MAAM,OAAO,MAAM,KAAA,IAAY,YAEjD,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAO,KAAI;EAAS,CAAA,CAChD,EAAA,CAAA,CACH;CACe,CAAA;AAEtB;;AAQA,SAAS,MAAM,EAAE,YAAsC;CACrD,MAAM,SAAS,UAAU,UAAU,OAAO,CAAC,CAAC,MAAM;CAClD,OACE,oBAAA,YAAA,EAAA,UACG,OAAO,KAAK,UACX,oBAAC,UAAD,EAAA,UAAuB,SAAS,KAAK,EAAY,GAAlC,KAAkC,CAClD,EACD,CAAA;AAEN;AAWA,SAAS,KAAK,EAAE,OAAO,GAAG,SAAkC;CAC1D,OAAO,QAAQ,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,GAAG,QAAQ,KAAK;AAC7D;AAEA,MAAa,SAAyB,sBAAM,UAAU;CAAE;CAAM;CAAO;AAAK,CAAC"}
|
package/src/resizable.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { ResizablePanelOptions, ResizableProps } from "@kirana-ui/core/resizable";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["resizable"];
|
package/src/resizable.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { parts, useController, useOptions, usePart } from "./runtime.js";
|
|
3
|
-
import { defined, within } from "@kirana-ui/core";
|
|
4
3
|
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createResizable } from "@kirana-ui/core/resizable";
|
|
7
7
|
// src/resizable.tsx
|
package/src/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Anchor, Part, PartEvent, PartState, PositionOptions, ReadonlySignal, Signal } from "@kirana-ui/core";
|
|
2
1
|
import { ClassAttributes, ComponentPropsWithoutRef, HTMLAttributes, JSX, ReactElement, ReactNode, Ref, RefCallback, RefObject, SyntheticEvent, useLayoutEffect } from "react";
|
|
2
|
+
import { Anchor, Direction, Part, PartEvent, PartState, PositionOptions, ReadonlySignal, Signal } from "@kirana-ui/core";
|
|
3
3
|
/** A layout effect in the browser, an effect (which never runs) on a server. */
|
|
4
4
|
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
5
5
|
/** A core signal's value, re-rendering when it changes. */
|
|
@@ -11,9 +11,9 @@ export declare function useSignal<T>(source: ReadonlySignal<T>): T;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function useController<P extends object, C extends {
|
|
13
13
|
mount(): () => void;
|
|
14
|
-
}>(create: (props: ReadonlySignal<P>) => C, props: Omit<P, "id"> & {
|
|
14
|
+
}>(create: (props: ReadonlySignal<P>) => C, props: NoInfer<Omit<P, "id"> & {
|
|
15
15
|
id?: string | undefined;
|
|
16
|
-
}): C;
|
|
16
|
+
}>): C;
|
|
17
17
|
/**
|
|
18
18
|
* Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an
|
|
19
19
|
* effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:
|
|
@@ -134,5 +134,12 @@ export interface PortalProps {
|
|
|
134
134
|
}
|
|
135
135
|
/** Its children in a container at the end of the page, once the page has hydrated. */
|
|
136
136
|
export declare function Portal({ children }: PortalProps): ReactElement | null;
|
|
137
|
+
/**
|
|
138
|
+
* The reading direction a `DirectionProvider` around this component states, as the signal a
|
|
139
|
+
* controller takes (`within(createX, { direction })`); `undefined` outside one, where the
|
|
140
|
+
* controller reads the direction its element is laid out in. For a component of your own: the
|
|
141
|
+
* library's parts read the same.
|
|
142
|
+
*/
|
|
143
|
+
export declare function useDirectionAround(): ReadonlySignal<Direction> | undefined;
|
|
137
144
|
export type { PartEvent };
|
|
138
145
|
//# sourceMappingURL=runtime.d.ts.map
|
package/src/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
1
2
|
import { REF_IS_A_PROP, give, refOf } from "./element.js";
|
|
2
|
-
import { composeProps, computed, defined, mergeProps, sameProps, signal, stateOf } from "@kirana-ui/core";
|
|
3
3
|
import { cloneElement, createContext, createElement, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { composeProps, computed, defined, forElement, mergeProps, sameProps, signal, stateOf, untype } from "@kirana-ui/core";
|
|
4
5
|
import { createPortal } from "react-dom";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
// src/runtime.tsx
|
|
@@ -110,8 +111,9 @@ function reactStyle(style) {
|
|
|
110
111
|
}
|
|
111
112
|
return out;
|
|
112
113
|
}
|
|
113
|
-
function toReact(props) {
|
|
114
|
+
function toReact(props, own) {
|
|
114
115
|
const out = {};
|
|
116
|
+
for (const key in own) if (BOOLEAN.has(key) && !(key in props) && (key !== "inert" || REF_IS_A_PROP)) out[RENAMED[key] ?? key] = false;
|
|
115
117
|
for (const key in props) {
|
|
116
118
|
const value = props[key];
|
|
117
119
|
if (BOOLEAN.has(key)) {
|
|
@@ -160,6 +162,7 @@ function usePart(part, tag, props, state, hold) {
|
|
|
160
162
|
now.leaving = false;
|
|
161
163
|
now.detach();
|
|
162
164
|
}
|
|
165
|
+
untype(element);
|
|
163
166
|
held.current = {
|
|
164
167
|
element,
|
|
165
168
|
part,
|
|
@@ -179,8 +182,10 @@ function usePart(part, tag, props, state, hold) {
|
|
|
179
182
|
const { ref: _ref, ...element } = REF_IS_A_PROP ? asked.props : { ...asked.props };
|
|
180
183
|
under = composeProps(caller, element);
|
|
181
184
|
}
|
|
185
|
+
const drawnAs = asked ? typeof asked.type === "string" ? asked.type : void 0 : typeof render === "function" ? void 0 : tag;
|
|
186
|
+
const placed = forElement(own, under, drawnAs);
|
|
182
187
|
const drawn = {
|
|
183
|
-
...toReact(mergeProps(under,
|
|
188
|
+
...toReact(mergeProps(under, placed), placed),
|
|
184
189
|
ref: attach
|
|
185
190
|
};
|
|
186
191
|
if (hold) drawn.children = hold(drawn.children);
|
|
@@ -301,6 +306,15 @@ function Portal({ children }) {
|
|
|
301
306
|
children
|
|
302
307
|
}), container ?? document.body);
|
|
303
308
|
}
|
|
304
|
-
|
|
309
|
+
/**
|
|
310
|
+
* The reading direction a `DirectionProvider` around this component states, as the signal a
|
|
311
|
+
* controller takes (`within(createX, { direction })`); `undefined` outside one, where the
|
|
312
|
+
* controller reads the direction its element is laid out in. For a component of your own: the
|
|
313
|
+
* library's parts read the same.
|
|
314
|
+
*/
|
|
315
|
+
function useDirectionAround() {
|
|
316
|
+
return useContext(DirectionContext) ?? void 0;
|
|
317
|
+
}
|
|
318
|
+
export { PartElement, Portal, PortalProvider, component, parts, useController, useDirectionAround, useIsomorphicLayoutEffect, useMount, useOptions, useOwnText, usePart, usePositioning, useSignal };
|
|
305
319
|
|
|
306
320
|
//# sourceMappingURL=runtime.js.map
|
package/src/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import {\n composeProps,\n computed,\n defined,\n mergeProps,\n sameProps,\n signal,\n stateOf,\n} from \"@kirana-ui/core\"\nimport type {\n Anchor,\n Part,\n PartEvent,\n PartProps,\n PartState,\n PositionOptions,\n ReadonlySignal,\n Signal,\n} from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createContext,\n createElement,\n forwardRef,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\"\nimport type {\n ClassAttributes,\n ComponentPropsWithoutRef,\n HTMLAttributes,\n JSX,\n ReactElement,\n ReactNode,\n Ref,\n RefCallback,\n RefObject,\n SyntheticEvent,\n} from \"react\"\nimport { createPortal } from \"react-dom\"\n\nimport { REF_IS_A_PROP, give, refOf } from \"./element.ts\"\n\n/** A layout effect in the browser, an effect (which never runs) on a server. */\nexport const useIsomorphicLayoutEffect =\n typeof document === \"undefined\" ? useEffect : useLayoutEffect\n\n/** A core signal's value, re-rendering when it changes. */\nexport function useSignal<T>(source: ReadonlySignal<T>): T {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source])\n const read = useCallback(() => source.peek(), [source])\n return useSyncExternalStore(subscribe, read, read)\n}\n\n/**\n * A component's controller, made once, following the props of each render. The props reach the\n * core after the render commits (a layout effect), never during it: another part that reads the\n * controller is another component, and React forbids updating it mid-render.\n */\nexport function useController<P extends object, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n props: Omit<P, \"id\"> & { id?: string | undefined }\n): C {\n const generated = useId()\n const next = { ...props, id: props.id ?? generated } as P\n const latest = useRef(next)\n latest.current = next\n const [state] = useState(() => {\n // The callbacks the core holds always call the latest render's.\n const stable = {} as Record<string, unknown>\n for (const key in next) {\n stable[key] =\n typeof next[key] === \"function\"\n ? (...args: unknown[]) =>\n (latest.current[key] as ((...args: unknown[]) => unknown) | undefined)?.(...args)\n : next[key]\n }\n const source: Signal<P> = signal(stable as P, sameProps as (a: P, b: P) => boolean)\n return { source, controller: create(source) }\n })\n useIsomorphicLayoutEffect(() => {\n const stable = { ...state.source.peek() } as Record<string, unknown>\n for (const key in next) {\n if (typeof next[key] !== \"function\") stable[key] = next[key]\n }\n state.source.set(stable as P)\n })\n useMount(state.controller)\n return state.controller\n}\n\n/**\n * Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an\n * effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:\n * a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in\n * the meantime keeps what is running.\n */\nexport function useMount(mounted: { mount(): () => void }): void {\n const [state] = useState(() => ({\n of: mounted,\n unmount: undefined as (() => void) | undefined,\n leaving: false,\n }))\n useEffect(() => {\n if (state.of !== mounted) {\n state.unmount?.()\n state.unmount = undefined\n state.of = mounted\n }\n state.leaving = false\n state.unmount ??= mounted.mount()\n return () => {\n state.leaving = true\n queueMicrotask(() => {\n if (!state.leaving) return\n state.unmount?.()\n state.unmount = undefined\n })\n }\n }, [state, mounted])\n}\n\n/** A part's own options as a core signal that follows each render, after it commits. */\nexport function useOptions<T extends Record<string, unknown>>(options: T): ReadonlySignal<T> {\n const [source] = useState(() => signal(options, sameProps as (a: T, b: T) => boolean))\n useIsomorphicLayoutEffect(() => source.set(options))\n return source\n}\n\n// HTML's boolean attributes, which React takes as booleans: a part's `\"\"` means \"present\".\nconst BOOLEAN = new Set([\n \"hidden\",\n \"disabled\",\n \"inert\",\n \"required\",\n \"readonly\",\n \"multiple\",\n \"checked\",\n \"novalidate\",\n])\nconst RENAMED: Record<string, string> = {\n tabindex: \"tabIndex\",\n for: \"htmlFor\",\n readonly: \"readOnly\",\n novalidate: \"noValidate\",\n autocomplete: \"autoComplete\",\n inputmode: \"inputMode\",\n maxlength: \"maxLength\",\n contenteditable: \"contentEditable\",\n spellcheck: \"spellCheck\",\n autocapitalize: \"autoCapitalize\",\n enterkeyhint: \"enterKeyHint\",\n}\n\n/** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */\nfunction reactStyle(style: Record<string, string>): Record<string, string> {\n const out: Record<string, string> = {}\n for (const name in style) {\n const key = name.startsWith(\"--\")\n ? name\n : name.replace(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase())\n out[key] = style[name]!\n }\n return out\n}\n\nfunction toReact(props: PartProps): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n for (const key in props) {\n const value = props[key]\n if (BOOLEAN.has(key)) {\n const name = RENAMED[key] ?? key\n // Always a boolean, never left out: an input whose `checked` comes and goes is, to React,\n // one that changes from controlled to not. But a part with nothing to say leaves what a\n // caller wrote under React's own name (`readOnly`).\n if (value !== undefined || !(name in out)) {\n const present = value === \"\" || value === true\n // React 19 knows `inert` as a boolean, and takes `\"\"` for false with a warning. Before,\n // it is an attribute React does not know: `true` is dropped with a warning, and `\"\"`\n // is written.\n out[name] = key === \"inert\" && !REF_IS_A_PROP ? (present ? \"\" : undefined) : present\n }\n } else if (key === \"style\" && value) out.style = reactStyle(value as Record<string, string>)\n else if (value !== undefined) out[RENAMED[key] ?? key] = value\n }\n return out\n}\n\n/** The elements a part is drawn as, by their tag: `\"button\"`, `\"div\"`, `\"svg\"`. */\nexport type PartTag = keyof JSX.IntrinsicElements\n\n/** The element a tag draws: an `HTMLButtonElement` for `\"button\"`. */\nexport type ElementOf<Tag extends PartTag> =\n JSX.IntrinsicElements[Tag] extends ClassAttributes<infer Drawn> ? Drawn : Element\n\nexport type { PartEvent }\n\n// A handler takes the event with its `preventKiranaHandler()`; anything else is as it was.\ntype Hearing<Prop> = Prop extends (event: infer Heard) => infer Answer\n ? Heard extends SyntheticEvent\n ? (event: PartEvent<Heard>) => Answer\n : Prop\n : Prop\n\n/**\n * The props a `render` function is handed, to spread on what it draws: the part's attributes,\n * its handlers and its ref, with the caller's under them. An attribute of one kind of element\n * (`href`, `type`) is among them unnamed, as `unknown`.\n */\nexport type RenderedProps = HTMLAttributes<HTMLElement> & {\n ref?: RefCallback<HTMLElement> | undefined\n} & Record<string, unknown>\n\n/**\n * What `render` takes: an element, drawn with the part's props merged over its own, or a\n * function given the part's props and its state. Unnamed, a state is any entries a `data-*`\n * attribute is written from: a part's own entry names its exactly.\n */\nexport type RenderProp<State = Record<string, string | boolean | null | undefined>> =\n | ReactElement<Record<string, unknown>>\n | ((props: RenderedProps, state: State) => ReactElement)\n\n/**\n * A part's props: its element's own (`Tag`'s attributes and handlers, a `ref` to that\n * element), `render`, and the part's own props (`Own`) in place of the element's of the same\n * name. `State` is what a `render` function is told of the part. A plain element of one's own\n * drawn through `useRender` names its state here (`PartComponentProps<\"span\", { variant:\n * string | null }>`); unnamed, it is any entries of `string | boolean | null | undefined`.\n */\nexport type PartComponentProps<\n Tag extends PartTag = \"div\",\n State = Record<string, string | boolean | null | undefined>,\n Own = unknown,\n> = {\n [Name in keyof ComponentPropsWithoutRef<Tag> as Name extends keyof Own ? never : Name]: Hearing<\n ComponentPropsWithoutRef<Tag>[Name]\n >\n} & Own & {\n /**\n * Renders the part as another element or component. An element's own props lie over the\n * props handed to the part, and the part's own (its role, its state, its handlers) over\n * both; a function is given the part's props and its state (`open`, `side` …, read from\n * its `data-*` attributes).\n */\n render?: RenderProp<State> | undefined\n ref?: Ref<ElementOf<Tag>> | undefined\n }\n\n// A part's props as `usePart` reads them, whatever element they are typed for.\ninterface Handed {\n render?: RenderProp<never> | undefined\n ref?: Ref<never> | undefined\n [attribute: string]: unknown\n}\n\n/** A part's DOM work on the element it is on. */\ninterface Attached {\n element: HTMLElement\n part: Part\n detach(): void\n leaving: boolean\n}\n\n/**\n * Renders a part: its element (or the caller's `render`), and the part's DOM work attached to\n * the element. Three layers of props, lowest first: what was handed to the part, the `render`\n * element's own, the part's. A higher layer wins an attribute; classes join; styles are merged\n * property by property; every handler of an event runs, lowest first, and\n * `event.preventKiranaHandler()` in a caller's stops the part's. The `render` element's own\n * children are drawn when it has any, and both its ref and the part's `ref` get the element.\n * `hold` is for a part that keeps something of its own in its element (a hidden input): it is\n * given the content and returns what the element holds, whoever drew the element.\n */\nexport function usePart<Tag extends PartTag, State = PartState>(\n part: Part,\n tag: Tag,\n props: PartComponentProps<Tag, State>,\n state?: State,\n hold?: (content: ReactNode) => ReactNode\n): ReactElement {\n const { render: asRender, ref: asRef, ...caller } = props as Handed\n const render = asRender as RenderProp<State> | undefined\n const ref = asRef as Ref<HTMLElement> | undefined\n const own = useSignal(part.props)\n const asked = isValidElement(render) ? render : undefined\n const theirs = asked ? refOf(asked) : undefined\n const held = useRef<Attached | undefined>(undefined)\n const attach = useCallback(\n (element: HTMLElement | null) => {\n const now = held.current\n if (!element) {\n // React takes a ref away and hands it straight back when the caller's `ref` is a new\n // function, and in StrictMode when the element is first drawn. The part's DOM work is\n // not undone for that (a popup would close its layer and give focus back): it is\n // undone a moment later, if the element has not come back.\n if (now) {\n now.leaving = true\n queueMicrotask(() => {\n if (!now.leaving) return\n now.detach()\n if (held.current === now) held.current = undefined\n })\n }\n } else if (now && now.element === element && now.part === part) {\n now.leaving = false\n } else {\n if (now) {\n now.leaving = false\n now.detach()\n }\n held.current = { element, part, detach: part.attach(element), leaving: false }\n }\n give(ref, element)\n give(theirs, element)\n },\n [part, ref, theirs]\n )\n let under: PartProps = caller\n if (asked) {\n // React 19 keeps an element's ref among its props: it is given the element above. Before,\n // the props have none, and reading it there warns.\n const { ref: _ref, ...element } = REF_IS_A_PROP ? asked.props : { ...asked.props }\n under = composeProps(caller, element)\n }\n const drawn: Record<string, unknown> = { ...toReact(mergeProps(under, own)), ref: attach }\n if (hold) drawn.children = hold(drawn.children as ReactNode)\n if (asked) return cloneElement(asked, drawn)\n if (typeof render === \"function\") return render(drawn, state ?? (stateOf(own) as State))\n return createElement(tag, drawn)\n}\n\nconst forwarded = new WeakMap<object, unknown>()\n\n/**\n * A component that is handed its caller's `ref` on every React the package takes, under the\n * name DevTools shows it by. React 19 gives a component its `ref` among its props, which is\n * where a part reads it; before, only a `forwardRef` component was given one, so there the\n * component is drawn by one that puts the ref back among the props. Its type is its own\n * either way, so one that is generic stays generic. One that already has a name keeps it.\n */\nexport function component<Drawn extends (props: never) => ReactNode>(\n name: string,\n draw: Drawn\n): Drawn {\n const named = draw as Drawn & { displayName?: string }\n if (REF_IS_A_PROP) {\n named.displayName ??= name\n return draw\n }\n let made = forwarded.get(draw)\n if (!made) {\n const drawing = draw as unknown as (props: object) => ReactElement | null\n const forwards = forwardRef<unknown, object>((props, ref) =>\n drawing(ref === null ? props : { ...props, ref })\n )\n forwards.displayName = name\n forwarded.set(draw, (made = forwards))\n }\n return made as Drawn\n}\n\n/**\n * A component's parts, each one a `component` named `Name.Part`. A part that is another\n * component's (a date picker's trigger is a popover's) is the same component there and here.\n */\nexport function parts<const Parts extends Record<string, unknown>>(\n name: string,\n all: Parts\n): Parts {\n const made: Record<string, unknown> = {}\n for (const key in all) {\n const part: unknown = all[key]\n made[key] =\n typeof part === \"function\"\n ? component(`${name}.${key}`, part as (props: never) => ReactNode)\n : part\n }\n return made as Parts\n}\n\n/**\n * A part's element as a component of its own, for a part that is not always in the page: the\n * part decides, and draws this when it is. It takes the part's props, with the part it is the\n * element `of`, its tag, and what the element holds of the part's own (`hold`, as `usePart`'s).\n */\nexport const PartElement = /* @__PURE__ */ component(\n \"PartElement\",\n function PartElement<Tag extends PartTag, State = PartState>({\n of,\n tag,\n hold,\n ...props\n }: PartComponentProps<Tag, State> & {\n of: Part\n tag: Tag\n hold?: ((content: ReactNode) => ReactNode) | undefined\n }): ReactElement {\n return usePart(of, tag, props as unknown as PartComponentProps<Tag, State>, undefined, hold)\n }\n)\n\n/** A positioner's own props: where its popup goes, and what it is placed against. */\nexport type PositionerOptions = Partial<Omit<PositionOptions, \"anchor\">> & {\n /**\n * What the popup is placed against, when that is not its trigger: an element, a ref to one,\n * a place in the viewport (an object with `getBoundingClientRect`), or a function that gives\n * one. It may change while the popup is open: the popup follows.\n */\n anchor?: Anchor | RefObject<Element | null> | (() => Anchor | null | undefined) | null | undefined\n}\n\n/** A positioner's props: where its popup goes and what it is placed against, and its element's. */\nexport type PositionerProps<State = PartState> = PartComponentProps<\"div\", State, PositionerOptions>\n\n// A ref's reader, the same function for the same ref: a render that changes nothing asks for\n// no new placement.\nconst readers = new WeakMap<object, () => Element | null>()\n\nfunction anchorOf(anchor: PositionerOptions[\"anchor\"]): PositionOptions[\"anchor\"] {\n if (!anchor || typeof anchor === \"function\") return anchor\n if (!(\"current\" in anchor) || \"getBoundingClientRect\" in anchor) return anchor as Anchor\n let read = readers.get(anchor)\n if (!read) readers.set(anchor, (read = () => anchor.current))\n return read\n}\n\n/**\n * A positioner's own props, written where its placement reads them: the one place they are\n * named. Gives back what is left, for the part's element.\n */\nexport function usePositioning<Props extends PositionerOptions>(\n positioning: Signal<Partial<PositionOptions>>,\n {\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n collisionBoundary,\n collisionAvoidance,\n sticky,\n arrowPadding,\n positionMethod,\n anchor,\n ...rest\n }: Props\n): Omit<Props, keyof PositionerOptions> {\n // Written while rendering, so the first placement (made when the element attaches, before\n // this component's effects) reads them. Nothing re-renders for it: the core compares.\n positioning.set(\n defined({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n collisionBoundary,\n collisionAvoidance,\n sticky,\n arrowPadding,\n positionMethod,\n anchor: anchorOf(anchor),\n })\n )\n return rest\n}\n\n/**\n * A text input whose text is the core's own (a combobox's, a number field's): its `value` is\n * given to React as the input's default. To React a `value` with no `onChange` is an input\n * that cannot be typed in; the core writes the text itself, as it changes.\n */\nexport function useOwnText(part: Part): Part {\n return useMemo(\n () => ({\n props: computed(() => {\n const { value, ...rest } = part.props.get()\n return { ...rest, defaultValue: value }\n }),\n attach: (element) => part.attach(element),\n }),\n [part]\n )\n}\n\nconst PortalContainer = createContext<HTMLElement | null | undefined>(undefined)\n\n/** What `PortalProvider` takes. */\nexport interface PortalProviderProps {\n /** Where the popups inside are drawn; the end of `<body>` while it is not given. */\n container?: HTMLElement | null | undefined\n children?: ReactNode\n}\n\n/**\n * Says where every popup inside it is drawn, the popups those open included: an element of\n * the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.\n */\nexport function PortalProvider({ container, children }: PortalProviderProps): ReactElement {\n return <PortalContainer.Provider value={container}>{children}</PortalContainer.Provider>\n}\n\n/** Draws no element of its own: its children at the end of `<body>`, or where a `PortalProvider` says. */\nexport interface PortalProps {\n children?: ReactNode\n}\n\n/** Its children in a container at the end of the page, once the page has hydrated. */\nexport function Portal({ children }: PortalProps): ReactElement | null {\n const container = useContext(PortalContainer)\n const [ready, setReady] = useState(false)\n useIsomorphicLayoutEffect(() => setReady(true), [])\n if (!ready) return null\n return createPortal(<div data-kirana-portal=\"\">{children}</div>, container ?? document.body)\n}\n"],"mappings":";;;;;;;AAoDA,MAAa,4BACX,OAAO,aAAa,cAAc,YAAY;;AAGhD,SAAgB,UAAa,QAA8B;CACzD,MAAM,YAAY,aAAa,aAAyB,OAAO,UAAU,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC5F,MAAM,OAAO,kBAAkB,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC;CACtD,OAAO,qBAAqB,WAAW,MAAM,IAAI;AACnD;;;;;;AAOA,SAAgB,cACd,QACA,OACG;CACH,MAAM,YAAY,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AAS,YAAY,KAAK,OAAO,OAAO;CAC1C,IACA,CAAC,IAAI,CACP;AACF;AAEA,MAAM,kBAAkB,cAA8C,KAAA,CAAS;;;;;AAa/E,SAAgB,eAAe,EAAE,WAAW,YAA+C;CACzF,OAAO,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAY;CAAmC,CAAA;AACzF;;AAQA,SAAgB,OAAO,EAAE,YAA8C;CACrE,MAAM,YAAY,WAAW,eAAe;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,gCAAgC,SAAS,IAAI,GAAG,CAAC,CAAC;CAClD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,oBAAC,OAAD;EAAK,sBAAmB;EAAI;CAAc,CAAA,GAAG,aAAa,SAAS,IAAI;AAC7F"}
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import {\n composeProps,\n computed,\n defined,\n forElement,\n mergeProps,\n sameProps,\n signal,\n stateOf,\n untype,\n} from \"@kirana-ui/core\"\nimport type {\n Anchor,\n Direction,\n Part,\n PartEvent,\n PartProps,\n PartState,\n PositionOptions,\n ReadonlySignal,\n Signal,\n} from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createContext,\n createElement,\n forwardRef,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\"\nimport type {\n ClassAttributes,\n ComponentPropsWithoutRef,\n HTMLAttributes,\n JSX,\n ReactElement,\n ReactNode,\n Ref,\n RefCallback,\n RefObject,\n SyntheticEvent,\n} from \"react\"\nimport { createPortal } from \"react-dom\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\n\nimport { REF_IS_A_PROP, give, refOf } from \"./element.ts\"\n\n/** A layout effect in the browser, an effect (which never runs) on a server. */\nexport const useIsomorphicLayoutEffect =\n typeof document === \"undefined\" ? useEffect : useLayoutEffect\n\n/** A core signal's value, re-rendering when it changes. */\nexport function useSignal<T>(source: ReadonlySignal<T>): T {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source])\n const read = useCallback(() => source.peek(), [source])\n return useSyncExternalStore(subscribe, read, read)\n}\n\n/**\n * A component's controller, made once, following the props of each render. The props reach the\n * core after the render commits (a layout effect), never during it: another part that reads the\n * controller is another component, and React forbids updating it mid-render.\n */\nexport function useController<P extends object, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n // The maker says what the props are: read from the props too, a maker written in place\n // (`within(createX, around)`) had them come out as `object`.\n props: NoInfer<Omit<P, \"id\"> & { id?: string | undefined }>\n): C {\n const generated = useId()\n const next = { ...props, id: props.id ?? generated } as P\n const latest = useRef(next)\n latest.current = next\n const [state] = useState(() => {\n // The callbacks the core holds always call the latest render's.\n const stable = {} as Record<string, unknown>\n for (const key in next) {\n stable[key] =\n typeof next[key] === \"function\"\n ? (...args: unknown[]) =>\n (latest.current[key] as ((...args: unknown[]) => unknown) | undefined)?.(...args)\n : next[key]\n }\n const source: Signal<P> = signal(stable as P, sameProps as (a: P, b: P) => boolean)\n return { source, controller: create(source) }\n })\n useIsomorphicLayoutEffect(() => {\n const stable = { ...state.source.peek() } as Record<string, unknown>\n for (const key in next) {\n if (typeof next[key] !== \"function\") stable[key] = next[key]\n }\n state.source.set(stable as P)\n })\n useMount(state.controller)\n return state.controller\n}\n\n/**\n * Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an\n * effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:\n * a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in\n * the meantime keeps what is running.\n */\nexport function useMount(mounted: { mount(): () => void }): void {\n const [state] = useState(() => ({\n of: mounted,\n unmount: undefined as (() => void) | undefined,\n leaving: false,\n }))\n useEffect(() => {\n if (state.of !== mounted) {\n state.unmount?.()\n state.unmount = undefined\n state.of = mounted\n }\n state.leaving = false\n state.unmount ??= mounted.mount()\n return () => {\n state.leaving = true\n queueMicrotask(() => {\n if (!state.leaving) return\n state.unmount?.()\n state.unmount = undefined\n })\n }\n }, [state, mounted])\n}\n\n/** A part's own options as a core signal that follows each render, after it commits. */\nexport function useOptions<T extends Record<string, unknown>>(options: T): ReadonlySignal<T> {\n const [source] = useState(() => signal(options, sameProps as (a: T, b: T) => boolean))\n useIsomorphicLayoutEffect(() => source.set(options))\n return source\n}\n\n// HTML's boolean attributes, which React takes as booleans: a part's `\"\"` means \"present\".\nconst BOOLEAN = new Set([\n \"hidden\",\n \"disabled\",\n \"inert\",\n \"required\",\n \"readonly\",\n \"multiple\",\n \"checked\",\n \"novalidate\",\n])\nconst RENAMED: Record<string, string> = {\n tabindex: \"tabIndex\",\n for: \"htmlFor\",\n readonly: \"readOnly\",\n novalidate: \"noValidate\",\n autocomplete: \"autoComplete\",\n inputmode: \"inputMode\",\n maxlength: \"maxLength\",\n contenteditable: \"contentEditable\",\n spellcheck: \"spellCheck\",\n autocapitalize: \"autoCapitalize\",\n enterkeyhint: \"enterKeyHint\",\n}\n\n/** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */\nfunction reactStyle(style: Record<string, string>): Record<string, string> {\n const out: Record<string, string> = {}\n for (const name in style) {\n const key = name.startsWith(\"--\")\n ? name\n : name.replace(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase())\n out[key] = style[name]!\n }\n return out\n}\n\nfunction toReact(props: PartProps, own: PartProps): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n // A boolean the part has a key for is always given: the merge leaves out one that no layer\n // has a value for, and `checked` would then come and go.\n for (const key in own) {\n if (BOOLEAN.has(key) && !(key in props) && (key !== \"inert\" || REF_IS_A_PROP))\n out[RENAMED[key] ?? key] = false\n }\n for (const key in props) {\n const value = props[key]\n if (BOOLEAN.has(key)) {\n const name = RENAMED[key] ?? key\n // Always a boolean, never left out: an input whose `checked` comes and goes is, to React,\n // one that changes from controlled to not. But a part with nothing to say leaves what a\n // caller wrote under React's own name (`readOnly`).\n if (value !== undefined || !(name in out)) {\n const present = value === \"\" || value === true\n // React 19 knows `inert` as a boolean, and takes `\"\"` for false with a warning. Before,\n // it is an attribute React does not know: `true` is dropped with a warning, and `\"\"`\n // is written.\n out[name] = key === \"inert\" && !REF_IS_A_PROP ? (present ? \"\" : undefined) : present\n }\n } else if (key === \"style\" && value) out.style = reactStyle(value as Record<string, string>)\n else if (value !== undefined) out[RENAMED[key] ?? key] = value\n }\n return out\n}\n\n/** The elements a part is drawn as, by their tag: `\"button\"`, `\"div\"`, `\"svg\"`. */\nexport type PartTag = keyof JSX.IntrinsicElements\n\n/** The element a tag draws: an `HTMLButtonElement` for `\"button\"`. */\nexport type ElementOf<Tag extends PartTag> =\n JSX.IntrinsicElements[Tag] extends ClassAttributes<infer Drawn> ? Drawn : Element\n\nexport type { PartEvent }\n\n// A handler takes the event with its `preventKiranaHandler()`; anything else is as it was.\ntype Hearing<Prop> = Prop extends (event: infer Heard) => infer Answer\n ? Heard extends SyntheticEvent\n ? (event: PartEvent<Heard>) => Answer\n : Prop\n : Prop\n\n/**\n * The props a `render` function is handed, to spread on what it draws: the part's attributes,\n * its handlers and its ref, with the caller's under them. An attribute of one kind of element\n * (`href`, `type`) is among them unnamed, as `unknown`.\n */\nexport type RenderedProps = HTMLAttributes<HTMLElement> & {\n ref?: RefCallback<HTMLElement> | undefined\n} & Record<string, unknown>\n\n/**\n * What `render` takes: an element, drawn with the part's props merged over its own, or a\n * function given the part's props and its state. Unnamed, a state is any entries a `data-*`\n * attribute is written from: a part's own entry names its exactly.\n */\nexport type RenderProp<State = Record<string, string | boolean | null | undefined>> =\n | ReactElement<Record<string, unknown>>\n | ((props: RenderedProps, state: State) => ReactElement)\n\n/**\n * A part's props: its element's own (`Tag`'s attributes and handlers, a `ref` to that\n * element), `render`, and the part's own props (`Own`) in place of the element's of the same\n * name. `State` is what a `render` function is told of the part. A plain element of one's own\n * drawn through `useRender` names its state here (`PartComponentProps<\"span\", { variant:\n * string | null }>`); unnamed, it is any entries of `string | boolean | null | undefined`.\n */\nexport type PartComponentProps<\n Tag extends PartTag = \"div\",\n State = Record<string, string | boolean | null | undefined>,\n Own = unknown,\n> = {\n [Name in keyof ComponentPropsWithoutRef<Tag> as Name extends keyof Own ? never : Name]: Hearing<\n ComponentPropsWithoutRef<Tag>[Name]\n >\n} & Own & {\n /**\n * Renders the part as another element or component. An element's own props lie over the\n * props handed to the part, and the part's own (its role, its state, its handlers) over\n * both; a function is given the part's props and its state (`open`, `side` …, read from\n * its `data-*` attributes).\n */\n render?: RenderProp<State> | undefined\n ref?: Ref<ElementOf<Tag>> | undefined\n }\n\n// A part's props as `usePart` reads them, whatever element they are typed for.\ninterface Handed {\n render?: RenderProp<never> | undefined\n ref?: Ref<never> | undefined\n [attribute: string]: unknown\n}\n\n/** A part's DOM work on the element it is on. */\ninterface Attached {\n element: HTMLElement\n part: Part\n detach(): void\n leaving: boolean\n}\n\n/**\n * Renders a part: its element (or the caller's `render`), and the part's DOM work attached to\n * the element. Three layers of props, lowest first: what was handed to the part, the `render`\n * element's own, the part's. A higher layer wins an attribute; classes join; styles are merged\n * property by property; every handler of an event runs, lowest first, and\n * `event.preventKiranaHandler()` in a caller's stops the part's. The `render` element's own\n * children are drawn when it has any, and both its ref and the part's `ref` get the element.\n * `hold` is for a part that keeps something of its own in its element (a hidden input): it is\n * given the content and returns what the element holds, whoever drew the element.\n */\nexport function usePart<Tag extends PartTag, State = PartState>(\n part: Part,\n tag: Tag,\n props: PartComponentProps<Tag, State>,\n state?: State,\n hold?: (content: ReactNode) => ReactNode\n): ReactElement {\n const { render: asRender, ref: asRef, ...caller } = props as Handed\n const render = asRender as RenderProp<State> | undefined\n const ref = asRef as Ref<HTMLElement> | undefined\n const own = useSignal(part.props)\n const asked = isValidElement(render) ? render : undefined\n const theirs = asked ? refOf(asked) : undefined\n const held = useRef<Attached | undefined>(undefined)\n const attach = useCallback(\n (element: HTMLElement | null) => {\n const now = held.current\n if (!element) {\n // React takes a ref away and hands it straight back when the caller's `ref` is a new\n // function, and in StrictMode when the element is first drawn. The part's DOM work is\n // not undone for that (a popup would close its layer and give focus back): it is\n // undone a moment later, if the element has not come back.\n if (now) {\n now.leaving = true\n queueMicrotask(() => {\n if (!now.leaving) return\n now.detach()\n if (held.current === now) held.current = undefined\n })\n }\n } else if (now && now.element === element && now.part === part) {\n now.leaving = false\n } else {\n if (now) {\n now.leaving = false\n now.detach()\n }\n untype(element)\n held.current = { element, part, detach: part.attach(element), leaving: false }\n }\n give(ref, element)\n give(theirs, element)\n },\n [part, ref, theirs]\n )\n let under: PartProps = caller\n if (asked) {\n // React 19 keeps an element's ref among its props: it is given the element above. Before,\n // the props have none, and reading it there warns.\n const { ref: _ref, ...element } = REF_IS_A_PROP ? asked.props : { ...asked.props }\n under = composeProps(caller, element)\n }\n // The element's tag, where it is known before it is drawn: a function, or a component given\n // as `render`, draws one of its own choosing.\n const drawnAs = asked\n ? typeof asked.type === \"string\"\n ? asked.type\n : undefined\n : typeof render === \"function\"\n ? undefined\n : tag\n const placed = forElement(own, under, drawnAs)\n const drawn: Record<string, unknown> = {\n ...toReact(mergeProps(under, placed), placed),\n ref: attach,\n }\n if (hold) drawn.children = hold(drawn.children as ReactNode)\n if (asked) return cloneElement(asked, drawn)\n if (typeof render === \"function\") return render(drawn, state ?? (stateOf(own) as State))\n return createElement(tag, drawn)\n}\n\nconst forwarded = new WeakMap<object, unknown>()\n\n/**\n * A component that is handed its caller's `ref` on every React the package takes, under the\n * name DevTools shows it by. React 19 gives a component its `ref` among its props, which is\n * where a part reads it; before, only a `forwardRef` component was given one, so there the\n * component is drawn by one that puts the ref back among the props. Its type is its own\n * either way, so one that is generic stays generic. One that already has a name keeps it.\n */\nexport function component<Drawn extends (props: never) => ReactNode>(\n name: string,\n draw: Drawn\n): Drawn {\n const named = draw as Drawn & { displayName?: string }\n if (REF_IS_A_PROP) {\n named.displayName ??= name\n return draw\n }\n let made = forwarded.get(draw)\n if (!made) {\n const drawing = draw as unknown as (props: object) => ReactElement | null\n const forwards = forwardRef<unknown, object>((props, ref) =>\n drawing(ref === null ? props : { ...props, ref })\n )\n forwards.displayName = name\n forwarded.set(draw, (made = forwards))\n }\n return made as Drawn\n}\n\n/**\n * A component's parts, each one a `component` named `Name.Part`. A part that is another\n * component's (a date picker's trigger is a popover's) is the same component there and here.\n */\nexport function parts<const Parts extends Record<string, unknown>>(\n name: string,\n all: Parts\n): Parts {\n const made: Record<string, unknown> = {}\n for (const key in all) {\n const part: unknown = all[key]\n made[key] =\n typeof part === \"function\"\n ? component(`${name}.${key}`, part as (props: never) => ReactNode)\n : part\n }\n return made as Parts\n}\n\n/**\n * A part's element as a component of its own, for a part that is not always in the page: the\n * part decides, and draws this when it is. It takes the part's props, with the part it is the\n * element `of`, its tag, and what the element holds of the part's own (`hold`, as `usePart`'s).\n */\nexport const PartElement = /* @__PURE__ */ component(\n \"PartElement\",\n function PartElement<Tag extends PartTag, State = PartState>({\n of,\n tag,\n hold,\n ...props\n }: PartComponentProps<Tag, State> & {\n of: Part\n tag: Tag\n hold?: ((content: ReactNode) => ReactNode) | undefined\n }): ReactElement {\n return usePart(of, tag, props as unknown as PartComponentProps<Tag, State>, undefined, hold)\n }\n)\n\n/** A positioner's own props: where its popup goes, and what it is placed against. */\nexport type PositionerOptions = Partial<Omit<PositionOptions, \"anchor\">> & {\n /**\n * What the popup is placed against, when that is not its trigger: an element, a ref to one,\n * a place in the viewport (an object with `getBoundingClientRect`), or a function that gives\n * one. It may change while the popup is open: the popup follows.\n */\n anchor?: Anchor | RefObject<Element | null> | (() => Anchor | null | undefined) | null | undefined\n}\n\n/** A positioner's props: where its popup goes and what it is placed against, and its element's. */\nexport type PositionerProps<State = PartState> = PartComponentProps<\"div\", State, PositionerOptions>\n\n// A ref's reader, the same function for the same ref: a render that changes nothing asks for\n// no new placement.\nconst readers = new WeakMap<object, () => Element | null>()\n\nfunction anchorOf(anchor: PositionerOptions[\"anchor\"]): PositionOptions[\"anchor\"] {\n if (!anchor || typeof anchor === \"function\") return anchor\n if (!(\"current\" in anchor) || \"getBoundingClientRect\" in anchor) return anchor as Anchor\n let read = readers.get(anchor)\n if (!read) readers.set(anchor, (read = () => anchor.current))\n return read\n}\n\n/**\n * A positioner's own props, written where its placement reads them: the one place they are\n * named. Gives back what is left, for the part's element.\n */\nexport function usePositioning<Props extends PositionerOptions>(\n positioning: Signal<Partial<PositionOptions>>,\n {\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n collisionBoundary,\n collisionAvoidance,\n sticky,\n arrowPadding,\n positionMethod,\n anchor,\n ...rest\n }: Props\n): Omit<Props, keyof PositionerOptions> {\n // Written while rendering, so the first placement (made when the element attaches, before\n // this component's effects) reads them. Nothing re-renders for it: the core compares.\n positioning.set(\n defined({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n collisionBoundary,\n collisionAvoidance,\n sticky,\n arrowPadding,\n positionMethod,\n anchor: anchorOf(anchor),\n })\n )\n return rest\n}\n\n/**\n * A text input whose text is the core's own (a combobox's, a number field's): its `value` is\n * given to React as the input's default. To React a `value` with no `onChange` is an input\n * that cannot be typed in; the core writes the text itself, as it changes.\n */\nexport function useOwnText(part: Part): Part {\n return useMemo(\n () => ({\n props: computed(() => {\n const { value, ...rest } = part.props.get()\n return { ...rest, defaultValue: value }\n }),\n attach: (element) => part.attach(element),\n }),\n [part]\n )\n}\n\nconst PortalContainer = createContext<HTMLElement | null | undefined>(undefined)\n\n/** What `PortalProvider` takes. */\nexport interface PortalProviderProps {\n /** Where the popups inside are drawn; the end of `<body>` while it is not given. */\n container?: HTMLElement | null | undefined\n children?: ReactNode\n}\n\n/**\n * Says where every popup inside it is drawn, the popups those open included: an element of\n * the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.\n */\nexport function PortalProvider({ container, children }: PortalProviderProps): ReactElement {\n return <PortalContainer.Provider value={container}>{children}</PortalContainer.Provider>\n}\n\n/** Draws no element of its own: its children at the end of `<body>`, or where a `PortalProvider` says. */\nexport interface PortalProps {\n children?: ReactNode\n}\n\n/** Its children in a container at the end of the page, once the page has hydrated. */\nexport function Portal({ children }: PortalProps): ReactElement | null {\n const container = useContext(PortalContainer)\n const [ready, setReady] = useState(false)\n useIsomorphicLayoutEffect(() => setReady(true), [])\n if (!ready) return null\n return createPortal(<div data-kirana-portal=\"\">{children}</div>, container ?? document.body)\n}\n\n/**\n * The reading direction a `DirectionProvider` around this component states, as the signal a\n * controller takes (`within(createX, { direction })`); `undefined` outside one, where the\n * controller reads the direction its element is laid out in. For a component of your own: the\n * library's parts read the same.\n */\nexport function useDirectionAround(): ReadonlySignal<Direction> | undefined {\n return useContext(DirectionContext) ?? undefined\n}\n"],"mappings":";;;;;;;;AAyDA,MAAa,4BACX,OAAO,aAAa,cAAc,YAAY;;AAGhD,SAAgB,UAAa,QAA8B;CACzD,MAAM,YAAY,aAAa,aAAyB,OAAO,UAAU,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC5F,MAAM,OAAO,kBAAkB,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC;CACtD,OAAO,qBAAqB,WAAW,MAAM,IAAI;AACnD;;;;;;AAOA,SAAgB,cACd,QAGA,OACG;CACH,MAAM,YAAY,MAAM;CACxB,MAAM,OAAO;EAAE,GAAG;EAAO,IAAI,MAAM,MAAM;CAAU;CACnD,MAAM,SAAS,OAAO,IAAI;CAC1B,OAAO,UAAU;CACjB,MAAM,CAAC,SAAS,eAAe;EAE7B,MAAM,SAAS,CAAC;EAChB,KAAK,MAAM,OAAO,MAChB,OAAO,OACL,OAAO,KAAK,SAAS,cAChB,GAAG,SACD,OAAO,QAAQ,IAAI,GAAqD,GAAG,IAAI,IAClF,KAAK;EAEb,MAAM,SAAoB,OAAO,QAAa,SAAoC;EAClF,OAAO;GAAE;GAAQ,YAAY,OAAO,MAAM;EAAE;CAC9C,CAAC;CACD,gCAAgC;EAC9B,MAAM,SAAS,EAAE,GAAG,MAAM,OAAO,KAAK,EAAE;EACxC,KAAK,M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B;EAA0B,OAAO;EAAY;CAAmC,CAAA;AACzF;;AAQA,SAAgB,OAAO,EAAE,YAA8C;CACrE,MAAM,YAAY,WAAW,eAAe;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,gCAAgC,SAAS,IAAI,GAAG,CAAC,CAAC;CAClD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,oBAAC,OAAD;EAAK,sBAAmB;EAAI;CAAc,CAAA,GAAG,aAAa,SAAS,IAAI;AAC7F;;;;;;;AAQA,SAAgB,qBAA4D;CAC1E,OAAO,WAAW,gBAAgB,KAAK,KAAA;AACzC"}
|
package/src/scroll-area.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { Orientation, StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { Orientation, StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
5
5
|
type Parts = Vocabulary["scrollArea"];
|
|
6
6
|
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>>;
|
package/src/scroll-area.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
3
|
-
import { within } from "@kirana-ui/core";
|
|
4
3
|
import { createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createScrollArea } from "@kirana-ui/core/scroll-area";
|
|
7
7
|
// src/scroll-area.tsx
|