routelit-client 0.4.2 → 0.5.2
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 +76 -3
- package/dist/{checkbox-Dbbt0aUf.js → checkbox-9lrNZctG.js} +2 -2
- package/dist/{checkbox-Dbbt0aUf.js.map → checkbox-9lrNZctG.js.map} +1 -1
- package/dist/{checkbox-yue557sD.js → checkbox-DQPZffx5.js} +1 -1
- package/dist/{checkbox-group-B5bHbsyN.js → checkbox-group--P655Yzh.js} +3 -3
- package/dist/checkbox-group--P655Yzh.js.map +1 -0
- package/dist/checkbox-group-DZmiz6tM.js +60 -0
- package/dist/{client-typrmY-O.js → client-D0Y6VDpm.js} +666 -177
- package/dist/client-D0Y6VDpm.js.map +1 -0
- package/dist/client-DShqkHLG.js +11087 -0
- package/dist/client.d.ts +2 -2
- package/dist/components/checkbox-group.d.ts +1 -1
- package/dist/components/link.d.ts +1 -1
- package/dist/components/select.d.ts +1 -1
- package/dist/core/actions.d.ts +7 -7
- package/dist/core/context.d.ts +40 -0
- package/dist/core/hoc.d.ts +50 -18
- package/dist/core/hooks.d.ts +45 -0
- package/dist/core/initializer.d.ts +1 -1
- package/dist/core/manager.d.ts +14 -6
- package/dist/core/react-renderer.d.ts +5 -1
- package/dist/core/server-api.d.ts +2 -2
- package/dist/core/utils/mutex.d.ts +19 -0
- package/dist/{dialog-DSbLZ_B3.js → dialog-BZJaeSg4.js} +1 -1
- package/dist/{dialog-rlC7_4v9.js → dialog-pMuiGCiC.js} +2 -2
- package/dist/{dialog-rlC7_4v9.js.map → dialog-pMuiGCiC.js.map} +1 -1
- package/dist/{input-BF_sdeXj.js → input-Dn8QeWuK.js} +1 -1
- package/dist/{input-BOd7EhRm.js → input-bU2tFE7u.js} +2 -2
- package/dist/{input-BOd7EhRm.js.map → input-bU2tFE7u.js.map} +1 -1
- package/dist/lib.d.ts +7 -2
- package/dist/{radio-DNywoZHY.js → radio-BHr9du__.js} +2 -2
- package/dist/{radio-DNywoZHY.js.map → radio-BHr9du__.js.map} +1 -1
- package/dist/{radio-nzEQWall.js → radio-DgrewWHx.js} +1 -1
- package/dist/routelit-client.es.dev.js +3 -1
- package/dist/routelit-client.es.js +13 -11
- package/dist/routelit-client.umd.dev.js +662 -177
- package/dist/routelit-client.umd.dev.js.map +1 -1
- package/dist/routelit-client.umd.js +18 -17
- package/dist/routelit.svg +7 -4
- package/dist/{select-BSiC7f0S.js → select-DKI11VJU.js} +4 -11
- package/dist/select-DKI11VJU.js.map +1 -0
- package/dist/select-Tp2rjInj.js +42 -0
- package/dist/{textarea-YI2O-Iu4.js → textarea-BTtEuLyx.js} +1 -1
- package/dist/{textarea-C5s5gdoT.js → textarea-DF-KYigU.js} +2 -2
- package/dist/{textarea-C5s5gdoT.js.map → textarea-DF-KYigU.js.map} +1 -1
- package/package.json +7 -4
- package/dist/checkbox-group-B5bHbsyN.js.map +0 -1
- package/dist/checkbox-group-GXSq-s9r.js +0 -60
- package/dist/client-DaSvON9F.js +0 -10713
- package/dist/client-typrmY-O.js.map +0 -1
- package/dist/select-BSiC7f0S.js.map +0 -1
- package/dist/select-DHtQ_3Tb.js +0 -49
- /package/dist/{style.css → client.css} +0 -0
package/README.md
CHANGED
|
@@ -18,12 +18,15 @@ This library contains core and basic components.
|
|
|
18
18
|
- link
|
|
19
19
|
- markdown
|
|
20
20
|
- headings
|
|
21
|
-
- checkbox
|
|
21
|
+
- checkbox (with label)
|
|
22
|
+
- single-checkbox
|
|
22
23
|
- checkbox_group
|
|
23
24
|
- radio (group)
|
|
24
25
|
- select
|
|
25
|
-
- textarea
|
|
26
|
-
-
|
|
26
|
+
- textarea (with label)
|
|
27
|
+
- single-textarea
|
|
28
|
+
- text_input (with label)
|
|
29
|
+
- single-text-input
|
|
27
30
|
- button
|
|
28
31
|
- expander
|
|
29
32
|
- heading
|
|
@@ -31,3 +34,73 @@ This library contains core and basic components.
|
|
|
31
34
|
- header
|
|
32
35
|
- subheader
|
|
33
36
|
|
|
37
|
+
### Public API (exports from `src/lib.ts`)
|
|
38
|
+
|
|
39
|
+
- This section documents everything you can import from `src/lib.ts` (and what is exposed on `window`).
|
|
40
|
+
|
|
41
|
+
#### Globals
|
|
42
|
+
|
|
43
|
+
- **`React`**: Re-exported and also attached to `window.React` for non-bundled environments.
|
|
44
|
+
- **`ReactDOM`**: Re-exported and also attached to `window.ReactDOM`.
|
|
45
|
+
- **`jsxRuntime`**: Re-exported and attached to `window.jsxRuntime` with `jsx`, `jsxs`, and `Fragment` for JSX runtime needs.
|
|
46
|
+
- **`RoutelitClient`**: Singleton attached to `window.RoutelitClient` that aggregates the most common API surface.
|
|
47
|
+
- Example:
|
|
48
|
+
```ts
|
|
49
|
+
const { manager, componentStore, renderApp } = window.RoutelitClient!;
|
|
50
|
+
renderApp("root");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Singletons
|
|
54
|
+
|
|
55
|
+
- **`manager`** (`RouteLitManager`): Central event/state manager. Handles `routelit:event` dispatch, navigation, throttled action batching, and subscriptions to loading and error state.
|
|
56
|
+
- **`componentStore`** (`ComponentStore`): Registry used by the renderer and components. Pre-registered with the core components listed above; you can extend it with `componentStore.register(name, Component)` and then use that `name` from the server.
|
|
57
|
+
|
|
58
|
+
#### Rendering
|
|
59
|
+
|
|
60
|
+
- **`renderApp(rootId?: string)`**: Mounts the app (default element id is `root`).
|
|
61
|
+
|
|
62
|
+
#### Hooks (context-aware)
|
|
63
|
+
|
|
64
|
+
- **`useDispatcherWith(id, type)`**: Returns a `(data: Record<string, unknown>) => void` that dispatches a custom Routelit event `{ id, type, ...data }`.
|
|
65
|
+
- **`useDispatcherWithAttr(id, type, attr)`**: Returns a `(value: unknown) => void` that dispatches `{ id, type, [attr]: value }`.
|
|
66
|
+
- **`useFormDispatcher(id, type)`**: Like `useDispatcherWith`, but includes the current `formId` in the payload. Useful inside form controls.
|
|
67
|
+
- **`useFormDispatcherWithAttr(id, type, attr)`**: Like `useDispatcherWithAttr`, but includes `formId`.
|
|
68
|
+
- **`useIsLoading()`**: Returns a boolean reflecting combined loading state (fragment or app-level).
|
|
69
|
+
- **`useError()`**: Returns the last `Error` (if any) bubbled from the manager chain.
|
|
70
|
+
|
|
71
|
+
#### Hooks (UI utilities)
|
|
72
|
+
|
|
73
|
+
- **`useLinkClickHandler({ id, href, replace, isExternal })`**: Returns an anchor `onClick` handler that dispatches a `navigate` event. Prevents default for internal links; lets external links proceed.
|
|
74
|
+
- **`useRLInlineElement(props, elementKeys)`**: Converts inline element descriptors on `props` to rendered elements using the `ComponentStore` (e.g., slots like `leftIcon`, `rightIcon`).
|
|
75
|
+
- **`useRLCallbackAttributes(props, rlCallbackAttrs)`**: Converts string function bodies found on `props` at the listed attribute names into real callbacks and returns them. Note: only use with trusted input.
|
|
76
|
+
|
|
77
|
+
#### Higher-order components (HOCs)
|
|
78
|
+
|
|
79
|
+
- **`withSimpleComponent(Component, props?)`**: Wraps any element/component, merging optional `props` and mapping any `rlInlineElementsAttrs` into real inline elements.
|
|
80
|
+
- Example:
|
|
81
|
+
```ts
|
|
82
|
+
const Title = withSimpleComponent("h1", { className: "title" });
|
|
83
|
+
```
|
|
84
|
+
- **`withEventDispatcher(Component, options?)`**: Attaches an event handler that dispatches a Routelit event (defaults: `rlEventName="click"`, `rlEventAttr="onClick"`). Works well for buttons.
|
|
85
|
+
- Example:
|
|
86
|
+
```ts
|
|
87
|
+
const Button = withEventDispatcher("button", { type: "button" });
|
|
88
|
+
// <Button id="save">Save</Button>
|
|
89
|
+
```
|
|
90
|
+
- **`withValueEventDispatcher(Component, options?)`**: Attaches a value-change handler that dispatches `{ [rlValueAttr]: value }` (defaults: `change`/`onChange`/`value`).
|
|
91
|
+
- Examples:
|
|
92
|
+
```ts
|
|
93
|
+
const TextInput = withValueEventDispatcher("input", { type: "text" });
|
|
94
|
+
const Checkbox = withValueEventDispatcher("input", {
|
|
95
|
+
type: "checkbox",
|
|
96
|
+
rlValueAttr: "checked",
|
|
97
|
+
rlEventValueGetter: (e) => e.currentTarget.checked,
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
- **`withInputValueEventDispatcher(Component, options?)`**: For text inputs/textareas; dispatches a `change` with `value` on `onBlur` or when pressing Enter. Defaults wire up `onBlur`/`onKeyDown` and read from `defaultValue`.
|
|
101
|
+
- Example:
|
|
102
|
+
```ts
|
|
103
|
+
const TextArea = withInputValueEventDispatcher("textarea");
|
|
104
|
+
```
|
|
105
|
+
- **`withCallbackAttributes(Component, { rlCallbackAttrs? })`**: Converts string callbacks on the listed attribute names into real functions and forwards them to the wrapped component.
|
|
106
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { memo, useCallback } from "react";
|
|
3
|
-
import { b as useFormDispatcherWithAttr } from "./client-
|
|
3
|
+
import { b as useFormDispatcherWithAttr } from "./client-D0Y6VDpm.js";
|
|
4
4
|
const Checkbox = memo(function Checkbox2({
|
|
5
5
|
label,
|
|
6
6
|
id,
|
|
@@ -38,4 +38,4 @@ Checkbox.displayName = "Checkbox";
|
|
|
38
38
|
export {
|
|
39
39
|
Checkbox as default
|
|
40
40
|
};
|
|
41
|
-
//# sourceMappingURL=checkbox-
|
|
41
|
+
//# sourceMappingURL=checkbox-9lrNZctG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox-
|
|
1
|
+
{"version":3,"file":"checkbox-9lrNZctG.js","sources":["../src/components/checkbox.tsx"],"sourcesContent":["import { memo, useCallback } from \"react\";\nimport { useFormDispatcherWithAttr } from \"../core/context\";\n\nconst Checkbox = memo(function Checkbox({\n label,\n id,\n required,\n defaultChecked,\n ...props\n}: {\n label: string;\n caption?: string;\n} & Omit<React.InputHTMLAttributes<HTMLInputElement>, \"onChange\">) {\n const dispatchChange = useFormDispatcherWithAttr(id!, \"change\", \"checked\");\n const onChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n dispatchChange(e.target.checked);\n },\n [dispatchChange]\n );\n return (\n <div className=\"rl-form-flex-control\">\n <input\n {...props}\n type=\"checkbox\"\n id={id}\n defaultChecked={defaultChecked}\n onChange={onChange}\n required={required}\n />\n <label htmlFor={id}>\n {label} {required && <span className=\"rl-required\">*</span>}\n </label>\n </div>\n );\n});\n\nCheckbox.displayName = \"Checkbox\";\n\nexport default Checkbox;\n"],"names":["Checkbox"],"mappings":";;;AAGM,MAAA,WAAW,KAAK,SAASA,UAAS;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAGmE;AACjE,QAAM,iBAAiB,0BAA0B,IAAK,UAAU,SAAS;AACzE,QAAM,WAAW;AAAA,IACf,CAAC,MAA2C;AAC3B,qBAAA,EAAE,OAAO,OAAO;AAAA,IACjC;AAAA,IACA,CAAC,cAAc;AAAA,EACjB;AAEE,SAAA,qBAAC,OAAI,EAAA,WAAU,wBACb,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ,MAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,IACA,qBAAC,SAAM,EAAA,SAAS,IACb,UAAA;AAAA,MAAA;AAAA,MAAM;AAAA,MAAE,YAAY,oBAAC,QAAK,EAAA,WAAU,eAAc,UAAC,IAAA,CAAA;AAAA,IAAA,EACtD,CAAA;AAAA,EAAA,GACF;AAEJ,CAAC;AAED,SAAS,cAAc;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { memo, useCallback } from "react";
|
|
3
|
-
import { b as useFormDispatcherWithAttr } from "./client-
|
|
3
|
+
import { b as useFormDispatcherWithAttr } from "./client-D0Y6VDpm.js";
|
|
4
4
|
function CheckboxGroupOption(props) {
|
|
5
5
|
const { id, value, onChange } = props;
|
|
6
|
-
const option =
|
|
6
|
+
const option = props.option;
|
|
7
7
|
return /* @__PURE__ */ jsxs("div", { className: "rl-form-flex-control", children: [
|
|
8
8
|
/* @__PURE__ */ jsx(
|
|
9
9
|
"input",
|
|
@@ -60,4 +60,4 @@ CheckboxGroup.displayName = "CheckboxGroup";
|
|
|
60
60
|
export {
|
|
61
61
|
CheckboxGroup as default
|
|
62
62
|
};
|
|
63
|
-
//# sourceMappingURL=checkbox-group
|
|
63
|
+
//# sourceMappingURL=checkbox-group--P655Yzh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox-group--P655Yzh.js","sources":["../src/components/checkbox-group.tsx"],"sourcesContent":["import { memo, useCallback } from \"react\";\nimport { useFormDispatcherWithAttr } from \"../core/context\";\n\ntype CheckboxGroupProps = {\n id: string;\n label: string;\n value: string[];\n required?: boolean;\n flexDirection?: \"row\" | \"col\";\n options: Array<{ label: string; value: string; caption?: string; disabled?: boolean }>;\n};\n\nfunction CheckboxGroupOption(props: {\n option: CheckboxGroupProps[\"options\"][number];\n id: string;\n value: string[];\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;\n}) {\n const { id, value, onChange } = props;\n\n const option: CheckboxGroupProps[\"options\"][number] =\n props.option;\n\n return (\n <div key={option.value} className=\"rl-form-flex-control\">\n <input\n disabled={option.disabled}\n type=\"checkbox\"\n value={option.value}\n id={`${id}-${option.value}`}\n checked={value.includes(option.value)}\n onChange={onChange}\n />\n <div className=\"rl-form-inline-label\">\n <label htmlFor={`${id}-${option.value}`}>{option.label}</label>\n {option.caption && (\n <small className=\"rl-form-control-caption\">{option.caption}</small>\n )}\n </div>\n </div>\n );\n}\n\nconst CheckboxGroup = memo(function CheckboxGroup({\n id,\n label,\n value,\n required,\n options,\n flexDirection = \"col\",\n}: CheckboxGroupProps) {\n const dispatchChange = useFormDispatcherWithAttr(id, \"change\", \"value\");\n const onChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.checked\n ? [...value, e.target.value]\n : value.filter((v) => v !== e.target.value);\n dispatchChange(newValue);\n },\n [dispatchChange, value]\n );\n return (\n <div className=\"rl-form-group\">\n {label && (\n <label>\n {label} {required && <span className=\"rl-required\">*</span>}\n </label>\n )}\n <div className={`rl-form-control-group rl-flex-${flexDirection}`}>\n {options.map((option) => (\n <CheckboxGroupOption\n key={typeof option === \"string\" ? option : option.value}\n id={id}\n value={value}\n onChange={onChange}\n option={option}\n />\n ))}\n </div>\n </div>\n );\n});\n\nCheckboxGroup.displayName = \"CheckboxGroup\";\n\nexport default CheckboxGroup;\n"],"names":["CheckboxGroup"],"mappings":";;;AAYA,SAAS,oBAAoB,OAK1B;AACD,QAAM,EAAE,IAAI,OAAO,SAAa,IAAA;AAEhC,QAAM,SACJ,MAAM;AAGN,SAAA,qBAAC,OAAuB,EAAA,WAAU,wBAChC,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAU,OAAO;AAAA,QACjB,MAAK;AAAA,QACL,OAAO,OAAO;AAAA,QACd,IAAI,GAAG,EAAE,IAAI,OAAO,KAAK;AAAA,QACzB,SAAS,MAAM,SAAS,OAAO,KAAK;AAAA,QACpC;AAAA,MAAA;AAAA,IACF;AAAA,IACA,qBAAC,OAAI,EAAA,WAAU,wBACb,UAAA;AAAA,MAAC,oBAAA,SAAA,EAAM,SAAS,GAAG,EAAE,IAAI,OAAO,KAAK,IAAK,UAAA,OAAO,MAAM,CAAA;AAAA,MACtD,OAAO,WACN,oBAAC,WAAM,WAAU,2BAA2B,iBAAO,QAAQ,CAAA;AAAA,IAAA,EAE/D,CAAA;AAAA,EAAA,EAAA,GAdQ,OAAO,KAejB;AAEJ;AAEM,MAAA,gBAAgB,KAAK,SAASA,eAAc;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAClB,GAAuB;AACrB,QAAM,iBAAiB,0BAA0B,IAAI,UAAU,OAAO;AACtE,QAAM,WAAW;AAAA,IACf,CAAC,MAA2C;AAC1C,YAAM,WAAW,EAAE,OAAO,UACtB,CAAC,GAAG,OAAO,EAAE,OAAO,KAAK,IACzB,MAAM,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,KAAK;AAC5C,qBAAe,QAAQ;AAAA,IACzB;AAAA,IACA,CAAC,gBAAgB,KAAK;AAAA,EACxB;AAEE,SAAA,qBAAC,OAAI,EAAA,WAAU,iBACZ,UAAA;AAAA,IAAA,8BACE,SACE,EAAA,UAAA;AAAA,MAAA;AAAA,MAAM;AAAA,MAAE,YAAY,oBAAC,QAAK,EAAA,WAAU,eAAc,UAAC,IAAA,CAAA;AAAA,IAAA,GACtD;AAAA,IAEF,oBAAC,SAAI,WAAW,iCAAiC,aAAa,IAC3D,UAAA,QAAQ,IAAI,CAAC,WACZ;AAAA,MAAC;AAAA,MAAA;AAAA,QAEC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAJK,OAAO,WAAW,WAAW,SAAS,OAAO;AAAA,IAAA,CAMrD,EACH,CAAA;AAAA,EAAA,GACF;AAEJ,CAAC;AAED,cAAc,cAAc;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsxs as n, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { memo as p, useCallback as f } from "react";
|
|
3
|
+
import { b } from "./client-DShqkHLG.js";
|
|
4
|
+
function v(t) {
|
|
5
|
+
const { id: o, value: c, onChange: r } = t, e = t.option;
|
|
6
|
+
return /* @__PURE__ */ n("div", { className: "rl-form-flex-control", children: [
|
|
7
|
+
/* @__PURE__ */ a(
|
|
8
|
+
"input",
|
|
9
|
+
{
|
|
10
|
+
disabled: e.disabled,
|
|
11
|
+
type: "checkbox",
|
|
12
|
+
value: e.value,
|
|
13
|
+
id: `${o}-${e.value}`,
|
|
14
|
+
checked: c.includes(e.value),
|
|
15
|
+
onChange: r
|
|
16
|
+
}
|
|
17
|
+
),
|
|
18
|
+
/* @__PURE__ */ n("div", { className: "rl-form-inline-label", children: [
|
|
19
|
+
/* @__PURE__ */ a("label", { htmlFor: `${o}-${e.value}`, children: e.label }),
|
|
20
|
+
e.caption && /* @__PURE__ */ a("small", { className: "rl-form-control-caption", children: e.caption })
|
|
21
|
+
] })
|
|
22
|
+
] }, e.value);
|
|
23
|
+
}
|
|
24
|
+
const g = p(function({
|
|
25
|
+
id: o,
|
|
26
|
+
label: c,
|
|
27
|
+
value: r,
|
|
28
|
+
required: e,
|
|
29
|
+
options: s,
|
|
30
|
+
flexDirection: u = "col"
|
|
31
|
+
}) {
|
|
32
|
+
const i = b(o, "change", "value"), d = f(
|
|
33
|
+
(l) => {
|
|
34
|
+
const m = l.target.checked ? [...r, l.target.value] : r.filter((h) => h !== l.target.value);
|
|
35
|
+
i(m);
|
|
36
|
+
},
|
|
37
|
+
[i, r]
|
|
38
|
+
);
|
|
39
|
+
return /* @__PURE__ */ n("div", { className: "rl-form-group", children: [
|
|
40
|
+
c && /* @__PURE__ */ n("label", { children: [
|
|
41
|
+
c,
|
|
42
|
+
" ",
|
|
43
|
+
e && /* @__PURE__ */ a("span", { className: "rl-required", children: "*" })
|
|
44
|
+
] }),
|
|
45
|
+
/* @__PURE__ */ a("div", { className: `rl-form-control-group rl-flex-${u}`, children: s.map((l) => /* @__PURE__ */ a(
|
|
46
|
+
v,
|
|
47
|
+
{
|
|
48
|
+
id: o,
|
|
49
|
+
value: r,
|
|
50
|
+
onChange: d,
|
|
51
|
+
option: l
|
|
52
|
+
},
|
|
53
|
+
typeof l == "string" ? l : l.value
|
|
54
|
+
)) })
|
|
55
|
+
] });
|
|
56
|
+
});
|
|
57
|
+
g.displayName = "CheckboxGroup";
|
|
58
|
+
export {
|
|
59
|
+
g as default
|
|
60
|
+
};
|