@molecule/app-auth-shell-svelte 0.0.0-stage → 1.1.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/LICENSE +202 -0
- package/README.md +439 -2
- package/dist/AuthFormStateProvider.svelte +22 -0
- package/dist/AuthFormStateProvider.svelte.d.ts +5 -0
- package/dist/AuthFormStateProvider.svelte.d.ts.map +1 -0
- package/dist/AuthShell.svelte +56 -0
- package/dist/AuthShell.svelte.d.ts +5 -0
- package/dist/AuthShell.svelte.d.ts.map +1 -0
- package/dist/AuthShellBackLink.svelte +28 -0
- package/dist/AuthShellBackLink.svelte.d.ts +5 -0
- package/dist/AuthShellBackLink.svelte.d.ts.map +1 -0
- package/dist/AuthShellCard.svelte +38 -0
- package/dist/AuthShellCard.svelte.d.ts +5 -0
- package/dist/AuthShellCard.svelte.d.ts.map +1 -0
- package/dist/AuthShellCardColumn.svelte +26 -0
- package/dist/AuthShellCardColumn.svelte.d.ts +5 -0
- package/dist/AuthShellCardColumn.svelte.d.ts.map +1 -0
- package/dist/AuthShellContainer.svelte +31 -0
- package/dist/AuthShellContainer.svelte.d.ts +5 -0
- package/dist/AuthShellContainer.svelte.d.ts.map +1 -0
- package/dist/AuthShellDecoration.svelte +16 -0
- package/dist/AuthShellDecoration.svelte.d.ts +8 -0
- package/dist/AuthShellDecoration.svelte.d.ts.map +1 -0
- package/dist/AuthShellFooter.svelte +18 -0
- package/dist/AuthShellFooter.svelte.d.ts +8 -0
- package/dist/AuthShellFooter.svelte.d.ts.map +1 -0
- package/dist/AuthShellHeading.svelte +38 -0
- package/dist/AuthShellHeading.svelte.d.ts +5 -0
- package/dist/AuthShellHeading.svelte.d.ts.map +1 -0
- package/dist/AuthShellPanel.svelte +18 -0
- package/dist/AuthShellPanel.svelte.d.ts +5 -0
- package/dist/AuthShellPanel.svelte.d.ts.map +1 -0
- package/dist/AuthShellSplit.svelte +18 -0
- package/dist/AuthShellSplit.svelte.d.ts +5 -0
- package/dist/AuthShellSplit.svelte.d.ts.map +1 -0
- package/dist/AuthShellSplitRow.svelte +18 -0
- package/dist/AuthShellSplitRow.svelte.d.ts +5 -0
- package/dist/AuthShellSplitRow.svelte.d.ts.map +1 -0
- package/dist/components.d.ts +19 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +18 -0
- package/dist/context.d.ts +20 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +26 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/keys.d.ts +9 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +8 -0
- package/dist/styles.d.ts +20 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +67 -0
- package/dist/types.d.ts +163 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/useAuthFormState.d.ts +27 -0
- package/dist/useAuthFormState.d.ts.map +1 -0
- package/dist/useAuthFormState.js +122 -0
- package/package.json +77 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-shell-svelte` — centered glassmorphic shell for auth
|
|
3
|
+
* pages (Login, Signup, ForgotPassword, ResetPassword), the Svelte counterpart
|
|
4
|
+
* of `@molecule/app-auth-shell-react`: the same exports, the same props (React
|
|
5
|
+
* names), and the same DOM for the same input.
|
|
6
|
+
*
|
|
7
|
+
* Apps pass per-app `decoration` (orbs, gradient backdrop) and `brand` (logo +
|
|
8
|
+
* tagline) as snippets. The shell handles layout, the glass card,
|
|
9
|
+
* heading/subheading, body, footer, and the "Back to home" link.
|
|
10
|
+
*
|
|
11
|
+
* The shell also publishes its content through `AuthFormStateProvider` (via
|
|
12
|
+
* Svelte context), so any form rendered inside inherits cross-view email
|
|
13
|
+
* persistence. Forms read it via `useAuthFormStateContext()`, or use the
|
|
14
|
+
* standalone `useAuthFormState` hook. Persistence flows through the
|
|
15
|
+
* `@molecule/app-storage` `StorageProvider` abstraction (never raw
|
|
16
|
+
* `sessionStorage`), defaulting to a process-shared in-memory store.
|
|
17
|
+
*
|
|
18
|
+
* Besides the `AuthShell` preset, the package exports the composable
|
|
19
|
+
* primitives — `AuthShellContainer`, `AuthShellDecoration`, `AuthShellCard`,
|
|
20
|
+
* `AuthShellHeading`, `AuthShellFooter`, `AuthShellBackLink` — plus a
|
|
21
|
+
* two-column family for the split layout: `AuthShellSplit` >
|
|
22
|
+
* `AuthShellSplitRow` > (`AuthShellPanel` + `AuthShellCardColumn`).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```svelte
|
|
26
|
+
* <script lang="ts">
|
|
27
|
+
* import { AuthShell, useAuthFormStateContext } from '@molecule/app-auth-shell-svelte'
|
|
28
|
+
* import { createSessionStorageProvider } from '@molecule/app-storage-localstorage'
|
|
29
|
+
*
|
|
30
|
+
* const sessionStore = createSessionStorageProvider({ prefix: 'auth_' })
|
|
31
|
+
* </script>
|
|
32
|
+
*
|
|
33
|
+
* <AuthShell
|
|
34
|
+
* heading="Sign in"
|
|
35
|
+
* subheading="Welcome back."
|
|
36
|
+
* formStateStorage={sessionStore}
|
|
37
|
+
* >
|
|
38
|
+
* {#snippet brand()}<h2>Acme</h2>{/snippet}
|
|
39
|
+
* {#snippet footer()}<p>No account? Sign up</p>{/snippet}
|
|
40
|
+
* <LoginForm />
|
|
41
|
+
* </AuthShell>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* `AuthShell` renders the binding's router `<Link>` ("Back to home") by
|
|
46
|
+
* default, so it MUST be rendered under `setMoleculeContext` with a router;
|
|
47
|
+
* pass `showBackLink={false}` in router-less setups. The back link's arrow
|
|
48
|
+
* uses the Material Symbols icon font; the glyph span is `aria-hidden="true"`,
|
|
49
|
+
* so the link's accessible name is its `t()` label alone. Form-state
|
|
50
|
+
* persistence defaults to a
|
|
51
|
+
* process-shared in-memory store (survives route swaps, not reloads) — inject
|
|
52
|
+
* `createSessionStorageProvider()` for reload-safe, tab-scoped persistence.
|
|
53
|
+
* Translations come from the companion `@molecule/app-locales-auth-shell`
|
|
54
|
+
* locale bond.
|
|
55
|
+
*
|
|
56
|
+
* @module
|
|
57
|
+
*/
|
|
58
|
+
export * from './components.js';
|
|
59
|
+
export * from './context.js';
|
|
60
|
+
export * from './types.js';
|
|
61
|
+
export * from './useAuthFormState.js';
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal context key for the shared auth-form state — the Svelte counterpart
|
|
3
|
+
* of React's `AuthFormStateContext`. Not part of the package's public surface.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/** The context key under which `<AuthShell>`/`AuthFormStateProvider` publish the state. */
|
|
8
|
+
export declare const AUTH_FORM_STATE_KEY: unique symbol;
|
|
9
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,2FAA2F;AAC3F,eAAO,MAAM,mBAAmB,eAAqC,CAAA"}
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal context key for the shared auth-form state — the Svelte counterpart
|
|
3
|
+
* of React's `AuthFormStateContext`. Not part of the package's public surface.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/** The context key under which `<AuthShell>`/`AuthFormStateProvider` publish the state. */
|
|
8
|
+
export const AUTH_FORM_STATE_KEY = Symbol('molecule-auth-form-state');
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-style serialization shared by the Svelte auth-shell components: turns
|
|
3
|
+
* a React-shaped style object into the `style` attribute text react-dom would
|
|
4
|
+
* produce, so both frameworks leave the same declarations on the element.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A React-shaped inline style object (camelCase properties; numbers allowed).
|
|
10
|
+
*/
|
|
11
|
+
export type AuthShellStyle = Record<string, string | number | undefined | null | false>;
|
|
12
|
+
/**
|
|
13
|
+
* Serializes a React-shaped style object to the `style` attribute text, with
|
|
14
|
+
* numbers gaining `px` unless the property is unitless.
|
|
15
|
+
*
|
|
16
|
+
* @param style - The style object (may be undefined).
|
|
17
|
+
* @returns The attribute text, or undefined when nothing is set.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toStyleText: (style: AuthShellStyle | undefined) => string | undefined;
|
|
20
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,CAAA;AA6CvF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,cAAc,GAAG,SAAS,KAAG,MAAM,GAAG,SAUxE,CAAA"}
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-style serialization shared by the Svelte auth-shell components: turns
|
|
3
|
+
* a React-shaped style object into the `style` attribute text react-dom would
|
|
4
|
+
* produce, so both frameworks leave the same declarations on the element.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Properties whose numeric values take no unit (React's `isUnitlessNumber`).
|
|
10
|
+
*/
|
|
11
|
+
const UNITLESS = new Set([
|
|
12
|
+
'animationIterationCount',
|
|
13
|
+
'aspectRatio',
|
|
14
|
+
'columnCount',
|
|
15
|
+
'columns',
|
|
16
|
+
'flex',
|
|
17
|
+
'flexGrow',
|
|
18
|
+
'flexShrink',
|
|
19
|
+
'fontWeight',
|
|
20
|
+
'gridArea',
|
|
21
|
+
'gridColumn',
|
|
22
|
+
'gridColumnEnd',
|
|
23
|
+
'gridColumnStart',
|
|
24
|
+
'gridRow',
|
|
25
|
+
'gridRowEnd',
|
|
26
|
+
'gridRowStart',
|
|
27
|
+
'lineClamp',
|
|
28
|
+
'lineHeight',
|
|
29
|
+
'opacity',
|
|
30
|
+
'order',
|
|
31
|
+
'scale',
|
|
32
|
+
'tabSize',
|
|
33
|
+
'zIndex',
|
|
34
|
+
'zoom',
|
|
35
|
+
'fillOpacity',
|
|
36
|
+
'floodOpacity',
|
|
37
|
+
'stopOpacity',
|
|
38
|
+
'strokeDashoffset',
|
|
39
|
+
'strokeOpacity',
|
|
40
|
+
'strokeWidth',
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Turns a camelCase CSS property name into its kebab-case DOM spelling.
|
|
44
|
+
*
|
|
45
|
+
* @param name - The camelCase property (`marginTop`, `zIndex`).
|
|
46
|
+
* @returns The kebab-case property (`margin-top`, `z-index`).
|
|
47
|
+
*/
|
|
48
|
+
const kebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
49
|
+
/**
|
|
50
|
+
* Serializes a React-shaped style object to the `style` attribute text, with
|
|
51
|
+
* numbers gaining `px` unless the property is unitless.
|
|
52
|
+
*
|
|
53
|
+
* @param style - The style object (may be undefined).
|
|
54
|
+
* @returns The attribute text, or undefined when nothing is set.
|
|
55
|
+
*/
|
|
56
|
+
export const toStyleText = (style) => {
|
|
57
|
+
if (!style)
|
|
58
|
+
return undefined;
|
|
59
|
+
const parts = [];
|
|
60
|
+
for (const [name, value] of Object.entries(style)) {
|
|
61
|
+
if (value === undefined || value === null || value === false || value === '')
|
|
62
|
+
continue;
|
|
63
|
+
const text = typeof value === 'number' && value !== 0 && !UNITLESS.has(name) ? `${value}px` : String(value);
|
|
64
|
+
parts.push(`${kebab(name)}: ${text}`);
|
|
65
|
+
}
|
|
66
|
+
return parts.length > 0 ? parts.join('; ') : undefined;
|
|
67
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Svelte auth-page layout shell — the Svelte counterpart of
|
|
3
|
+
* `@molecule/app-auth-shell-react`: the same props (React names) and the same
|
|
4
|
+
* DOM for the same input, with node props as snippets.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
import type { Writable } from 'svelte/store';
|
|
10
|
+
import type { StorageProvider } from '@molecule/app-storage';
|
|
11
|
+
import type { AuthShellStyle } from './styles.js';
|
|
12
|
+
/**
|
|
13
|
+
* Shared auth form field values. `email` is the canonical cross-view field;
|
|
14
|
+
* additional string fields (e.g. a name carried from Signup) may be stored
|
|
15
|
+
* alongside it.
|
|
16
|
+
*/
|
|
17
|
+
export interface AuthFormFields {
|
|
18
|
+
/** Email address, shared across all auth views. */
|
|
19
|
+
email?: string;
|
|
20
|
+
/** Any other shared string field (e.g. `name`). */
|
|
21
|
+
[field: string]: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Options for {@link useAuthFormState}. */
|
|
24
|
+
export interface UseAuthFormStateOptions {
|
|
25
|
+
/** Storage provider backing persistence (defaults to a process-shared in-memory provider). */
|
|
26
|
+
storage?: StorageProvider;
|
|
27
|
+
/** Storage key for the persisted fields. Defaults to `molecule.auth.form-state`. */
|
|
28
|
+
storageKey?: string;
|
|
29
|
+
/** Seed values used before hydration completes / when storage is empty. */
|
|
30
|
+
initialFields?: AuthFormFields;
|
|
31
|
+
}
|
|
32
|
+
/** The value {@link useAuthFormState} returns. */
|
|
33
|
+
export interface AuthFormState {
|
|
34
|
+
/** Current field values (email + any shared fields), as a writable store. */
|
|
35
|
+
fields: Writable<AuthFormFields>;
|
|
36
|
+
/** `true` once the initial read from storage has completed, as a writable store. */
|
|
37
|
+
hydrated: Writable<boolean>;
|
|
38
|
+
/** Sets a single field and persists the new state. */
|
|
39
|
+
setField: (name: string, value: string) => void;
|
|
40
|
+
/** Merges a patch of fields and persists the new state. */
|
|
41
|
+
setFields: (patch: AuthFormFields) => void;
|
|
42
|
+
/** Clears all persisted auth form state and removes the storage key. */
|
|
43
|
+
clear: () => void;
|
|
44
|
+
}
|
|
45
|
+
/** Props for {@link AuthFormStateProvider}. */
|
|
46
|
+
export interface AuthFormStateProviderProps {
|
|
47
|
+
/** Children rendered inside the provider. */
|
|
48
|
+
children?: Snippet;
|
|
49
|
+
/** Storage provider backing persistence (defaults to a shared in-memory provider). */
|
|
50
|
+
storage?: StorageProvider;
|
|
51
|
+
/** Storage key for the persisted fields. */
|
|
52
|
+
storageKey?: string;
|
|
53
|
+
/** Seed values used before hydration / when storage is empty. */
|
|
54
|
+
initialFields?: AuthFormFields;
|
|
55
|
+
}
|
|
56
|
+
/** Props accepted by {@link AuthShellContainer}. */
|
|
57
|
+
export interface AuthShellContainerProps {
|
|
58
|
+
/** Content rendered inside the container. */
|
|
59
|
+
children?: Snippet;
|
|
60
|
+
/** Optional CSS background applied to the container. */
|
|
61
|
+
style?: AuthShellStyle;
|
|
62
|
+
/** Extra classes appended after the defaults. */
|
|
63
|
+
className?: string;
|
|
64
|
+
/** Layout direction. Defaults to `'centered'`; pass `'column'` for a vertical stack. */
|
|
65
|
+
layout?: 'centered' | 'column';
|
|
66
|
+
}
|
|
67
|
+
/** Props accepted by {@link AuthShellCard}. */
|
|
68
|
+
export interface AuthShellCardProps {
|
|
69
|
+
/** Content rendered inside the card. */
|
|
70
|
+
children?: Snippet;
|
|
71
|
+
/** Override the default glass surface. */
|
|
72
|
+
surfaceClassName?: string;
|
|
73
|
+
/** Extra layout classes appended after the flex/padding defaults. */
|
|
74
|
+
className?: string;
|
|
75
|
+
/** Override the outer `<main>` wrapper classes. */
|
|
76
|
+
outerClassName?: string;
|
|
77
|
+
/** `data-mol-id` pass-through for E2E selectors. */
|
|
78
|
+
dataMolId?: string;
|
|
79
|
+
/** Optional CSS style applied to the card's inner surface. */
|
|
80
|
+
style?: AuthShellStyle;
|
|
81
|
+
}
|
|
82
|
+
/** Props accepted by {@link AuthShellHeading}. */
|
|
83
|
+
export interface AuthShellHeadingProps {
|
|
84
|
+
/** The heading text. */
|
|
85
|
+
heading: string;
|
|
86
|
+
/** Optional subheading paragraph. */
|
|
87
|
+
subheading?: string;
|
|
88
|
+
/** Optional small uppercase tag rendered above the heading. */
|
|
89
|
+
eyebrow?: string;
|
|
90
|
+
/** Optional override for the h1 className. */
|
|
91
|
+
headingClassName?: string;
|
|
92
|
+
/** Optional override for the h1 style. */
|
|
93
|
+
headingStyle?: AuthShellStyle;
|
|
94
|
+
}
|
|
95
|
+
/** Props accepted by {@link AuthShellBackLink}. */
|
|
96
|
+
export interface AuthShellBackLinkProps {
|
|
97
|
+
/** Destination. Defaults to `/`. */
|
|
98
|
+
to?: string;
|
|
99
|
+
/** Translated label override; falls back to `auth.backHome` → "Back to home" when absent, empty or blank. */
|
|
100
|
+
label?: string;
|
|
101
|
+
}
|
|
102
|
+
/** Props accepted by {@link AuthShellSplit}. */
|
|
103
|
+
export interface AuthShellSplitProps {
|
|
104
|
+
/** The split row (and optionally a site footer sibling). */
|
|
105
|
+
children?: Snippet;
|
|
106
|
+
/** Cosmetic classes (background, text color, font) for the outer container. */
|
|
107
|
+
className?: string;
|
|
108
|
+
/** Any other attribute React would spread onto the container. */
|
|
109
|
+
[attribute: string]: unknown;
|
|
110
|
+
}
|
|
111
|
+
/** Props accepted by {@link AuthShellSplitRow}. */
|
|
112
|
+
export interface AuthShellSplitRowProps {
|
|
113
|
+
/** The brand panel and the card column. */
|
|
114
|
+
children?: Snippet;
|
|
115
|
+
/** Layout classes for the row (typically `cm.flex({})` or `cm.grid({ cols: 2 })`). */
|
|
116
|
+
className?: string;
|
|
117
|
+
/** Any other attribute React would spread onto the row. */
|
|
118
|
+
[attribute: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
/** Props accepted by {@link AuthShellPanel}. */
|
|
121
|
+
export interface AuthShellPanelProps {
|
|
122
|
+
/** The app's bespoke decoration, wordmark or social proof. */
|
|
123
|
+
children?: Snippet;
|
|
124
|
+
/** Cosmetic classes — width ratio, padding, gradient, positioning. */
|
|
125
|
+
className?: string;
|
|
126
|
+
/** Any other attribute React would spread onto the panel. */
|
|
127
|
+
[attribute: string]: unknown;
|
|
128
|
+
}
|
|
129
|
+
/** Props accepted by {@link AuthShellCardColumn}. */
|
|
130
|
+
export interface AuthShellCardColumnProps {
|
|
131
|
+
/** The form card content. */
|
|
132
|
+
children?: Snippet;
|
|
133
|
+
/** Cosmetic classes — width ratio, padding. */
|
|
134
|
+
className?: string;
|
|
135
|
+
/** Element to render. Defaults to `'section'`. */
|
|
136
|
+
as?: 'section' | 'main';
|
|
137
|
+
/** Any other attribute React would spread onto the column. */
|
|
138
|
+
[attribute: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
/** Props accepted by {@link AuthShell}. */
|
|
141
|
+
export interface AuthShellProps {
|
|
142
|
+
/** The heading text. */
|
|
143
|
+
heading: string;
|
|
144
|
+
/** The subheading text. */
|
|
145
|
+
subheading: string;
|
|
146
|
+
/** The form body. */
|
|
147
|
+
children: Snippet;
|
|
148
|
+
/** Optional footer node. */
|
|
149
|
+
footer?: Snippet;
|
|
150
|
+
/** Optional brand node rendered above the heading. */
|
|
151
|
+
brand?: Snippet;
|
|
152
|
+
/** Optional background decoration node. */
|
|
153
|
+
decoration?: Snippet;
|
|
154
|
+
/** Destination of the back link. Defaults to `/`. */
|
|
155
|
+
backTo?: string;
|
|
156
|
+
/** Whether to render the back link. Defaults to `true`. */
|
|
157
|
+
showBackLink?: boolean;
|
|
158
|
+
/** Storage provider backing cross-view auth form persistence. */
|
|
159
|
+
formStateStorage?: StorageProvider;
|
|
160
|
+
/** Storage key for the persisted auth form state. */
|
|
161
|
+
formStateKey?: string;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,mDAAmD;IACnD,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACpC;AAED,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,oFAAoF;IACpF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,cAAc,CAAA;CAC/B;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;IAChC,oFAAoF;IACpF,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC3B,sDAAsD;IACtD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,2DAA2D;IAC3D,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;IAC1C,wEAAwE;IACxE,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB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A;IAChB,sDAAsD;IACtD,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,eAAe,CAAA;IAClC,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useAuthFormState` (Svelte hook) — cross-view auth form persistence.
|
|
3
|
+
*
|
|
4
|
+
* Holds the email (and any other shared auth fields) so a value typed on one
|
|
5
|
+
* auth view (Login / Signup / ForgotPassword / ResetPassword) is carried over
|
|
6
|
+
* when the user navigates to another. Backed by the `@molecule/app-storage`
|
|
7
|
+
* `StorageProvider` abstraction (never raw `sessionStorage`/`localStorage`).
|
|
8
|
+
*
|
|
9
|
+
* The state is CLEARED on successful auth (call `clear()` from the success
|
|
10
|
+
* handler) so credentials do not linger.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import type { AuthFormState, UseAuthFormStateOptions } from './types.js';
|
|
15
|
+
/** Default storage key for persisted auth form fields. */
|
|
16
|
+
export declare const DEFAULT_AUTH_FORM_STATE_KEY = "molecule.auth.form-state";
|
|
17
|
+
/**
|
|
18
|
+
* Svelte hook holding email + shared auth fields, persisted across auth views
|
|
19
|
+
* via an injectable `StorageProvider` and cleared on successful auth.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Optional storage provider, storage key, and seed fields, or
|
|
22
|
+
* a getter of them (a getter lets a component pass its `$props()` without
|
|
23
|
+
* Svelte's local-reference warning, since the props are read once at init).
|
|
24
|
+
* @returns The current fields plus `setField`/`setFields`/`clear` and a `hydrated` flag.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useAuthFormState(options?: UseAuthFormStateOptions | (() => UseAuthFormStateOptions | undefined)): AuthFormState;
|
|
27
|
+
//# sourceMappingURL=useAuthFormState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthFormState.d.ts","sourceRoot":"","sources":["../src/useAuthFormState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,OAAO,KAAK,EAAkB,aAAa,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAExF,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,6BAA6B,CAAA;AAoBrE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,CAAC,EAAE,uBAAuB,GAAG,CAAC,MAAM,uBAAuB,GAAG,SAAS,CAAC,GAC9E,aAAa,CAkFf"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useAuthFormState` (Svelte hook) — cross-view auth form persistence.
|
|
3
|
+
*
|
|
4
|
+
* Holds the email (and any other shared auth fields) so a value typed on one
|
|
5
|
+
* auth view (Login / Signup / ForgotPassword / ResetPassword) is carried over
|
|
6
|
+
* when the user navigates to another. Backed by the `@molecule/app-storage`
|
|
7
|
+
* `StorageProvider` abstraction (never raw `sessionStorage`/`localStorage`).
|
|
8
|
+
*
|
|
9
|
+
* The state is CLEARED on successful auth (call `clear()` from the success
|
|
10
|
+
* handler) so credentials do not linger.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { onDestroy, onMount } from 'svelte';
|
|
15
|
+
import { get, writable } from 'svelte/store';
|
|
16
|
+
import { getLogger } from '@molecule/app-logger';
|
|
17
|
+
import { createMemoryStorageProvider } from '@molecule/app-storage';
|
|
18
|
+
/** Default storage key for persisted auth form fields. */
|
|
19
|
+
export const DEFAULT_AUTH_FORM_STATE_KEY = 'molecule.auth.form-state';
|
|
20
|
+
/**
|
|
21
|
+
* Process-shared in-memory provider used as the default backing store.
|
|
22
|
+
* Shared (not per-call) so the email survives the unmount/remount of an auth
|
|
23
|
+
* view within one SPA session even without an injected provider.
|
|
24
|
+
*/
|
|
25
|
+
let defaultStorage;
|
|
26
|
+
/**
|
|
27
|
+
* Lazily creates (once) and returns the process-shared in-memory storage
|
|
28
|
+
* provider used as the default backing store.
|
|
29
|
+
*
|
|
30
|
+
* @returns The shared in-memory `StorageProvider`.
|
|
31
|
+
*/
|
|
32
|
+
const getDefaultStorage = () => {
|
|
33
|
+
defaultStorage ??= createMemoryStorageProvider();
|
|
34
|
+
return defaultStorage;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Svelte hook holding email + shared auth fields, persisted across auth views
|
|
38
|
+
* via an injectable `StorageProvider` and cleared on successful auth.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Optional storage provider, storage key, and seed fields, or
|
|
41
|
+
* a getter of them (a getter lets a component pass its `$props()` without
|
|
42
|
+
* Svelte's local-reference warning, since the props are read once at init).
|
|
43
|
+
* @returns The current fields plus `setField`/`setFields`/`clear` and a `hydrated` flag.
|
|
44
|
+
*/
|
|
45
|
+
export function useAuthFormState(options) {
|
|
46
|
+
const resolved = typeof options === 'function' ? options() : options;
|
|
47
|
+
const logger = getLogger('auth-form-state');
|
|
48
|
+
const storage = resolved?.storage ?? getDefaultStorage();
|
|
49
|
+
const storageKey = resolved?.storageKey ?? DEFAULT_AUTH_FORM_STATE_KEY;
|
|
50
|
+
const fields = writable({ ...(resolved?.initialFields ?? {}) });
|
|
51
|
+
const hydrated = writable(false);
|
|
52
|
+
// Mirror the latest fields so setters compute the next value synchronously.
|
|
53
|
+
let current = get(fields);
|
|
54
|
+
let cancelled = false;
|
|
55
|
+
onMount(() => {
|
|
56
|
+
void (async () => {
|
|
57
|
+
try {
|
|
58
|
+
const stored = await storage.get(storageKey);
|
|
59
|
+
if (cancelled)
|
|
60
|
+
return;
|
|
61
|
+
if (stored && typeof stored === 'object') {
|
|
62
|
+
// Values the user already typed win over stored.
|
|
63
|
+
const merged = { ...stored, ...current };
|
|
64
|
+
current = merged;
|
|
65
|
+
fields.set(merged);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
logger.warn('Failed to read persisted auth form state', { error, storageKey });
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
if (!cancelled)
|
|
73
|
+
hydrated.set(true);
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
});
|
|
77
|
+
onDestroy(() => {
|
|
78
|
+
cancelled = true;
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Persists the next state, logging (never throwing) on failure.
|
|
82
|
+
*
|
|
83
|
+
* @param next - The next field values.
|
|
84
|
+
*/
|
|
85
|
+
const persist = (next) => {
|
|
86
|
+
storage.set(storageKey, next).catch((error) => {
|
|
87
|
+
logger.warn('Failed to persist auth form state', { error, storageKey });
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Sets a single field and persists the new state.
|
|
92
|
+
*
|
|
93
|
+
* @param name - The field name.
|
|
94
|
+
* @param value - The new value.
|
|
95
|
+
*/
|
|
96
|
+
const setField = (name, value) => {
|
|
97
|
+
const next = { ...current, [name]: value };
|
|
98
|
+
current = next;
|
|
99
|
+
fields.set(next);
|
|
100
|
+
persist(next);
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Merges a patch of fields and persists the new state.
|
|
104
|
+
*
|
|
105
|
+
* @param patch - The fields to merge.
|
|
106
|
+
*/
|
|
107
|
+
const setFields = (patch) => {
|
|
108
|
+
const next = { ...current, ...patch };
|
|
109
|
+
current = next;
|
|
110
|
+
fields.set(next);
|
|
111
|
+
persist(next);
|
|
112
|
+
};
|
|
113
|
+
/** Clears all persisted auth form state and removes the storage key. */
|
|
114
|
+
const clear = () => {
|
|
115
|
+
current = {};
|
|
116
|
+
fields.set({});
|
|
117
|
+
storage.remove(storageKey).catch((error) => {
|
|
118
|
+
logger.warn('Failed to clear persisted auth form state', { error, storageKey });
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
return { fields, hydrated, setField, setFields, clear };
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-auth-shell-svelte",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Auth-page layout shell — centered card with heading/subheading/form/footer + back-link below. Composable children for per-app decorative background + brand mark.",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-auth-shell-svelte",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"svelte": "./dist/index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!dist/**/__tests__",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"!dist/**/*.spec.*",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
|
|
27
|
+
"dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"molecule",
|
|
33
|
+
"auth",
|
|
34
|
+
"shell",
|
|
35
|
+
"layout",
|
|
36
|
+
"svelte"
|
|
37
|
+
],
|
|
38
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
43
|
+
"directory": "packages/app/features/auth-shell-svelte"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@molecule/app-logger": "^1.0.1",
|
|
54
|
+
"@molecule/app-storage": "^1.0.1",
|
|
55
|
+
"@molecule/app-svelte": "^3.6.0",
|
|
56
|
+
"@molecule/app-ui": "^1.3.11",
|
|
57
|
+
"@molecule/app-ui-svelte": "^1.1.0",
|
|
58
|
+
"svelte": "^5.0.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
62
|
+
"@molecule/app-i18n": "1.2.2",
|
|
63
|
+
"@molecule/app-icons": "1.0.4",
|
|
64
|
+
"@molecule/app-logger": "1.1.0",
|
|
65
|
+
"@molecule/app-storage": "1.1.1",
|
|
66
|
+
"@molecule/app-svelte": "3.7.2",
|
|
67
|
+
"@molecule/app-ui": "1.4.0",
|
|
68
|
+
"@molecule/app-ui-svelte": "1.1.7",
|
|
69
|
+
"@sveltejs/package": "3.0.2",
|
|
70
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
71
|
+
"@types/node": "26.6.5",
|
|
72
|
+
"jsdom": "30.1.3",
|
|
73
|
+
"svelte": "5.57.2",
|
|
74
|
+
"svelte-check": "4.7.7",
|
|
75
|
+
"typescript": "6.0.3",
|
|
76
|
+
"vite": "8.3.5",
|
|
77
|
+
"vitest": "4.1.12"
|
|
78
|
+
}
|
|
79
|
+
}
|