@cripty2001/utils 0.0.223 → 0.0.225

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.
@@ -3,7 +3,7 @@ import BaseCopiable, { type CopiableProps as BaseCopiableProps } from './copiabl
3
3
  import BaseForm, { type FormComponentProps as BaseFormProps } from './form';
4
4
  import BaseInput, { type InputComponentProps as BaseInputProps } from './input';
5
5
  import BaseLoader, { type LoaderProps as BaseLoaderProps } from './loader';
6
- import BaseModal, { type ModalComponentProps as BaseModalProps } from './modal';
6
+ import BaseModal, { type ModalActions as BaseModalActions, type ModalContent as BaseModalContent, type ModalComponentProps as BaseModalProps } from './modal';
7
7
  import BaseTable, { type TableProps as BaseTableProps } from './table';
8
8
  import BaseTextButton, { type TextButtonProps as BaseTextButtonProps } from './textButton';
9
- export { BaseButton, BaseButtonProps, BaseCopiable, BaseCopiableProps, BaseForm, BaseFormProps, BaseInput, BaseInputProps, BaseLoader, BaseLoaderProps, BaseModal, BaseModalProps, BaseTable, BaseTableProps, BaseTextButton, BaseTextButtonProps };
9
+ export { BaseButton, BaseButtonProps, BaseCopiable, BaseCopiableProps, BaseForm, BaseFormProps, BaseInput, BaseInputProps, BaseLoader, BaseLoaderProps, BaseModal, BaseModalActions, BaseModalContent, BaseModalProps, BaseTable, BaseTableProps, BaseTextButton, BaseTextButtonProps };
@@ -1,7 +1,13 @@
1
+ import { type ReactNode } from "react";
2
+ export type ModalActions = {
3
+ dismiss: () => void;
4
+ };
5
+ export type ModalContent = ReactNode | ((actions: ModalActions) => ReactNode);
1
6
  export type ModalComponentProps = {
2
- children: React.ReactNode;
7
+ children: ModalContent;
3
8
  open: boolean;
4
9
  setOpen: (open: boolean) => void;
5
- animate: boolean;
10
+ animate?: boolean;
11
+ panelClassName?: string;
6
12
  };
7
- export default function ModalComponent(props: ModalComponentProps): import("react/jsx-runtime").JSX.Element | null;
13
+ export default function ModalComponent({ children, open, setOpen, animate, panelClassName, }: ModalComponentProps): import("react/jsx-runtime").JSX.Element | null;
@@ -24,11 +24,23 @@ if (typeof document !== 'undefined') {
24
24
  }
25
25
  }
26
26
  let modalCount = 0;
27
- function ModalComponent(props) {
27
+ function ModalComponent({ children, open, setOpen, animate = false, panelClassName = "", }) {
28
28
  const zIndex = (0, react_1.useRef)(1000 + modalCount++).current;
29
29
  const id = (0, react_1.useRef)(`modal-${zIndex}`).current;
30
- if (!props.open)
30
+ const dismiss = (0, react_1.useCallback)(() => setOpen(false), [setOpen]);
31
+ (0, react_1.useEffect)(() => {
32
+ if (!open)
33
+ return;
34
+ const onKey = (event) => {
35
+ if (event.key === "Escape")
36
+ dismiss();
37
+ };
38
+ window.addEventListener("keydown", onKey);
39
+ return () => window.removeEventListener("keydown", onKey);
40
+ }, [open, dismiss]);
41
+ if (!open)
31
42
  return null;
43
+ const content = typeof children === "function" ? children({ dismiss }) : children;
32
44
  return ((0, jsx_runtime_1.jsx)("div", { id: id, style: {
33
45
  position: 'fixed',
34
46
  top: 0,
@@ -42,6 +54,6 @@ function ModalComponent(props) {
42
54
  padding: '1.5rem',
43
55
  height: '100vh',
44
56
  width: '100vw',
45
- zIndex: zIndex
46
- }, onClick: () => props.setOpen(false), children: (0, jsx_runtime_1.jsx)("div", { style: { maxWidth: '100%', animation: props.animate ? 'slide-up 0.3s ease-out' : '' }, onClick: (e) => e.stopPropagation(), children: props.children }) }));
57
+ zIndex: zIndex,
58
+ }, onClick: dismiss, children: (0, jsx_runtime_1.jsx)("div", { role: "dialog", "aria-modal": "true", className: panelClassName, style: { maxWidth: '100%', animation: animate ? 'slide-up 0.3s ease-out' : undefined }, onClick: (e) => e.stopPropagation(), children: content }) }));
47
59
  }
package/llms/appserver.md CHANGED
@@ -131,6 +131,29 @@ handler: async (input, auth) => {
131
131
  }
132
132
  ```
133
133
 
134
+ ### [Example] Recommended OIDC integration pattern (oidc-spa)
135
+
136
+ `Client` deliberately doesn't fetch or refresh tokens — that's the OIDC library's job. To stay logged in indefinitely, **proactively** push fresh tokens into the Client whenever your OIDC library renews them, then bind a UI overlay to `client.loggedIn` for the unrecoverable case.
137
+
138
+ Two-line proactive renewal (using `oidc-spa`):
139
+
140
+ ```ts
141
+ const oidc = await createOidc({ /* … */ });
142
+
143
+ if (oidc.isUserLoggedIn) {
144
+ const { idToken } = await oidc.getTokens();
145
+ await client.login(idToken);
146
+
147
+ // Re-push every time the underlying library refreshes the session.
148
+ oidc.subscribeToTokensChange(({ idToken }) => {
149
+ void client.login(idToken);
150
+ });
151
+ }
152
+
153
+ ```
154
+
155
+ This works because Client logged in status only changes when an api report an auth error, this mean that as long as the latest set token is valid, the api will never report an auth error.
156
+
134
157
  ---
135
158
 
136
159
  ## 7. Error handling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.223",
3
+ "version": "0.0.225",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {