@seahax/elemental 0.4.2 → 0.5.1
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 +67 -14
- package/dist/{store.js → createStore.js} +3 -3
- package/dist/createStore.js.map +1 -0
- package/dist/{component.d.ts → defineComponent.d.ts} +11 -7
- package/dist/defineComponent.js +57 -0
- package/dist/defineComponent.js.map +1 -0
- package/dist/{router.d.ts → getRouter.d.ts} +3 -2
- package/dist/getRouter.js +33 -0
- package/dist/getRouter.js.map +1 -0
- package/dist/hooks/useAsync.d.ts +11 -0
- package/dist/hooks/{loading.js → useAsync.js} +5 -5
- package/dist/hooks/useAsync.js.map +1 -0
- package/dist/hooks/{attributes.d.ts → useAttributes.d.ts} +1 -1
- package/dist/hooks/useAttributes.js +37 -0
- package/dist/hooks/useAttributes.js.map +1 -0
- package/dist/hooks/useChildEffect.js +24 -0
- package/dist/hooks/useChildEffect.js.map +1 -0
- package/dist/hooks/useDisconnect.d.ts +2 -0
- package/dist/hooks/useDisconnect.js +9 -0
- package/dist/hooks/useDisconnect.js.map +1 -0
- package/dist/hooks/useDocument.d.ts +3 -0
- package/dist/hooks/useDocument.js +9 -0
- package/dist/hooks/useDocument.js.map +1 -0
- package/dist/hooks/useEffect.d.ts +3 -0
- package/dist/hooks/useEffect.js +17 -0
- package/dist/hooks/useEffect.js.map +1 -0
- package/dist/hooks/useElementInternals.d.ts +2 -0
- package/dist/hooks/useElementInternals.js +9 -0
- package/dist/hooks/useElementInternals.js.map +1 -0
- package/dist/hooks/useForm.d.ts +9 -0
- package/dist/hooks/useForm.js +23 -0
- package/dist/hooks/useForm.js.map +1 -0
- package/dist/hooks/{host.d.ts → useHost.d.ts} +1 -1
- package/dist/hooks/useHost.js +9 -0
- package/dist/hooks/useHost.js.map +1 -0
- package/dist/hooks/useInternalController.d.ts +3 -0
- package/dist/hooks/useInternalController.js +11 -0
- package/dist/hooks/useInternalController.js.map +1 -0
- package/dist/hooks/useParent.d.ts +3 -0
- package/dist/hooks/useParent.js +9 -0
- package/dist/hooks/useParent.js.map +1 -0
- package/dist/hooks/{ref.d.ts → useRef.d.ts} +1 -2
- package/dist/hooks/useRef.js +9 -0
- package/dist/hooks/useRef.js.map +1 -0
- package/dist/hooks/{route.d.ts → useRoute.d.ts} +3 -3
- package/dist/hooks/{route.js → useRoute.js} +6 -6
- package/dist/hooks/useRoute.js.map +1 -0
- package/dist/hooks/{store.d.ts → useStore.d.ts} +2 -2
- package/dist/hooks/{store.js → useStore.js} +4 -4
- package/dist/hooks/useStore.js.map +1 -0
- package/dist/html.d.ts +1 -1
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.js +17 -13
- package/dist/internal/constants.d.ts +1 -0
- package/dist/internal/constants.js +6 -0
- package/dist/internal/constants.js.map +1 -0
- package/dist/internal/controllers.d.ts +2 -0
- package/dist/internal/controllers.js +6 -0
- package/dist/internal/controllers.js.map +1 -0
- package/dist/internal/{callbacks.js → createCallbacks.js} +2 -2
- package/dist/internal/createCallbacks.js.map +1 -0
- package/dist/internal/createController.d.ts +33 -0
- package/dist/internal/createController.js +73 -0
- package/dist/internal/createController.js.map +1 -0
- package/dist/internal/getOrInsert.d.ts +4 -0
- package/dist/internal/getOrInsert.js +10 -0
- package/dist/internal/getOrInsert.js.map +1 -0
- package/package.json +7 -3
- package/dist/component.js +0 -34
- package/dist/component.js.map +0 -1
- package/dist/hooks/attributes.js +0 -25
- package/dist/hooks/attributes.js.map +0 -1
- package/dist/hooks/child-effect.js +0 -14
- package/dist/hooks/child-effect.js.map +0 -1
- package/dist/hooks/context.d.ts +0 -3
- package/dist/hooks/context.js +0 -11
- package/dist/hooks/context.js.map +0 -1
- package/dist/hooks/effect.d.ts +0 -9
- package/dist/hooks/effect.js +0 -20
- package/dist/hooks/effect.js.map +0 -1
- package/dist/hooks/host.js +0 -9
- package/dist/hooks/host.js.map +0 -1
- package/dist/hooks/loading.d.ts +0 -11
- package/dist/hooks/loading.js.map +0 -1
- package/dist/hooks/ref.js +0 -19
- package/dist/hooks/ref.js.map +0 -1
- package/dist/hooks/route.js.map +0 -1
- package/dist/hooks/store.js.map +0 -1
- package/dist/internal/callbacks.js.map +0 -1
- package/dist/internal/context.d.ts +0 -13
- package/dist/internal/context.js +0 -32
- package/dist/internal/context.js.map +0 -1
- package/dist/router.js +0 -35
- package/dist/router.js.map +0 -1
- package/dist/store.js.map +0 -1
- /package/dist/{store.d.ts → createStore.d.ts} +0 -0
- /package/dist/hooks/{child-effect.d.ts → useChildEffect.d.ts} +0 -0
- /package/dist/internal/{callbacks.d.ts → createCallbacks.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -23,16 +23,19 @@ Contains everything you need to build anything from a single component up to a f
|
|
|
23
23
|
```ts
|
|
24
24
|
import {
|
|
25
25
|
defineComponent,
|
|
26
|
+
h,
|
|
26
27
|
useRef,
|
|
27
28
|
useStore,
|
|
28
29
|
useAttributes,
|
|
30
|
+
useParent,
|
|
31
|
+
useDocument,
|
|
29
32
|
useRoute,
|
|
30
|
-
|
|
33
|
+
useAsync,
|
|
31
34
|
useEffect,
|
|
32
35
|
useChildEffect,
|
|
33
|
-
|
|
36
|
+
useDisconnectCallback,
|
|
37
|
+
useElementInternals,
|
|
34
38
|
useHost,
|
|
35
|
-
h,
|
|
36
39
|
} from '@seahax/elemental';
|
|
37
40
|
|
|
38
41
|
export const MyComponent = defineComponent((shadow) => {
|
|
@@ -65,9 +68,15 @@ export const MyComponent = defineComponent((shadow) => {
|
|
|
65
68
|
// Use a reference (reactive state) bound to a (shared) store.
|
|
66
69
|
const globalStateRef = useStore(myStore, select, mutate);
|
|
67
70
|
|
|
68
|
-
// Use references (reactive state) bound to attributes.
|
|
71
|
+
// Use references (reactive state) bound to the component's attributes.
|
|
69
72
|
const [dataValueRef, ...] = useAttributes('data-value', ...);
|
|
70
73
|
|
|
74
|
+
// Use a reference (reactive state) bound to the component's parent node.
|
|
75
|
+
const parentNode = useParent();
|
|
76
|
+
|
|
77
|
+
// Use a reference (reactive state) bound to the component's owner document.
|
|
78
|
+
const ownerDocument = useDocument();
|
|
79
|
+
|
|
71
80
|
// Use a reference (reactive state) bound to route matching.
|
|
72
81
|
const routeMatchRef = useRoute('/path/', {
|
|
73
82
|
match: 'prefix', // 'exact' | 'prefix' | RegExp
|
|
@@ -75,7 +84,7 @@ export const MyComponent = defineComponent((shadow) => {
|
|
|
75
84
|
});
|
|
76
85
|
|
|
77
86
|
// Use a reference (reactive state) bound to an async loader function.
|
|
78
|
-
const
|
|
87
|
+
const asyncRef = useAsync([
|
|
79
88
|
// dependency references
|
|
80
89
|
], async (signal, ...dependencyValues) => {
|
|
81
90
|
// Reactive async code runs when the component is connected to the
|
|
@@ -91,8 +100,7 @@ export const MyComponent = defineComponent((shadow) => {
|
|
|
91
100
|
globalStateRef,
|
|
92
101
|
dataValueRef,
|
|
93
102
|
routeMatchRef,
|
|
94
|
-
|
|
95
|
-
loadingStateRef,
|
|
103
|
+
asyncRef,
|
|
96
104
|
], (...dependencyValues) => {
|
|
97
105
|
// Reactive code runs when the component is connected to the document,
|
|
98
106
|
// and when any of the dependencies change.
|
|
@@ -116,29 +124,74 @@ export const MyComponent = defineComponent((shadow) => {
|
|
|
116
124
|
};
|
|
117
125
|
});
|
|
118
126
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// document.
|
|
127
|
+
// Register a document disconnection callback.
|
|
128
|
+
useDisconnectCallback(() => {
|
|
129
|
+
// Called when the component is disconnected from the document.
|
|
122
130
|
});
|
|
123
131
|
|
|
124
|
-
// Use the
|
|
132
|
+
// Use the element's internals.
|
|
133
|
+
const elementInternals = useElementInternals();
|
|
134
|
+
|
|
135
|
+
// Use the component host element.
|
|
125
136
|
const host = useHost();
|
|
126
137
|
});
|
|
127
138
|
```
|
|
128
139
|
|
|
140
|
+
## Enable Form Association
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import {
|
|
144
|
+
useElementInternals,
|
|
145
|
+
useForm,
|
|
146
|
+
useFormDisabled,
|
|
147
|
+
useFormResetCallback,
|
|
148
|
+
useFormRestoreCallback,
|
|
149
|
+
} from '@seahax/elemental';
|
|
150
|
+
|
|
151
|
+
const MyComponent = defineComponent(
|
|
152
|
+
(shadow) => {
|
|
153
|
+
// Use the element's internals.
|
|
154
|
+
const elementInternals = useElementInternals();
|
|
155
|
+
|
|
156
|
+
// Use a reference (reactive state) bound to the associated form.
|
|
157
|
+
const formRef = useForm();
|
|
158
|
+
|
|
159
|
+
// Use a reference (reactive state) bound to the form disabled state.
|
|
160
|
+
const formDisabledRef = useFormDisabled();
|
|
161
|
+
|
|
162
|
+
// Register a form reset callback.
|
|
163
|
+
useFormResetCallback(() => {
|
|
164
|
+
// Called when the associated form is reset. Only called on connect
|
|
165
|
+
// if the form was reset while the component was disconnected.
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Register a form restore callback.
|
|
169
|
+
useFormRestoreCallback((state, reason) => {
|
|
170
|
+
// Called when the associated form is restored. Only called on connect
|
|
171
|
+
// if the form was restored while the component was disconnected.
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
// Enable form association.
|
|
176
|
+
formAssociated: true,
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
```
|
|
180
|
+
|
|
129
181
|
## Customize The Shadow Root
|
|
130
182
|
|
|
131
183
|
```ts
|
|
132
184
|
const MyComponent = defineComponent(
|
|
133
185
|
(shadow) => {
|
|
134
|
-
|
|
186
|
+
...
|
|
135
187
|
},
|
|
136
188
|
{
|
|
137
|
-
//
|
|
189
|
+
// Use custom shadow root initialization options.
|
|
190
|
+
// (default: { mode: 'open' }).
|
|
138
191
|
shadow: {
|
|
139
192
|
mode: 'closed',
|
|
140
193
|
...
|
|
141
|
-
}
|
|
194
|
+
},
|
|
142
195
|
}
|
|
143
196
|
);
|
|
144
197
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createCallbacks as e } from "./internal/
|
|
2
|
-
//#region src/
|
|
1
|
+
import { createCallbacks as e } from "./internal/createCallbacks.js";
|
|
2
|
+
//#region src/createStore.ts
|
|
3
3
|
function t(t) {
|
|
4
4
|
let n = e(), r = t;
|
|
5
5
|
return {
|
|
@@ -15,4 +15,4 @@ function t(t) {
|
|
|
15
15
|
//#endregion
|
|
16
16
|
export { t as createStore };
|
|
17
17
|
|
|
18
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=createStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStore.js","names":[],"sources":["../src/createStore.ts"],"sourcesContent":["import { createCallbacks } from './internal/createCallbacks.ts';\n\nexport interface Store<TState> {\n state: TState;\n subscribe: (callback: (state: TState) => void) => () => void;\n}\n\n/** Create a new store containing an observable state. */\nexport function createStore<TState>(initialState: TState): Store<TState> {\n const callbacks = createCallbacks();\n let state = initialState;\n\n return {\n get state() {\n return state;\n },\n set state(newState) {\n if (newState === state) return;\n state = newState;\n callbacks.run();\n },\n subscribe: (callback) => callbacks.push(() => callback(state)),\n };\n}\n"],"mappings":";;AAQA,SAAgB,EAAoB,GAAqC;CACvE,IAAM,IAAY,GAAiB,EAC/B,IAAQ;AAEZ,QAAO;EACL,IAAI,QAAQ;AACV,UAAO;;EAET,IAAI,MAAM,GAAU;AACd,SAAa,MACjB,IAAQ,GACR,EAAU,KAAK;;EAEjB,YAAY,MAAa,EAAU,WAAW,EAAS,EAAM,CAAC;EAC/D"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { type Ref } from './hooks/
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
} : never;
|
|
1
|
+
import { type Ref } from './hooks/useRef.ts';
|
|
2
|
+
type UnsafeProps = 'connectedCallback' | 'connectedMoveCallback' | 'disconnectedCallback' | 'adoptedCallback' | 'formResetCallback' | 'formStateRestoreCallback' | 'formDisabledCallback';
|
|
3
|
+
type SafePropKeys<TProps> = Exclude<keyof TProps, keyof HTMLElement | UnsafeProps>;
|
|
5
4
|
export interface ComponentConstructor<TProps extends object> {
|
|
5
|
+
readonly formAssociated: boolean;
|
|
6
6
|
new (): ComponentWithProps<TProps>;
|
|
7
7
|
}
|
|
8
8
|
export interface ComponentOptions<TProps extends object> {
|
|
9
|
+
/** Shadow root attachment options. */
|
|
9
10
|
readonly shadow?: Partial<ShadowRootInit>;
|
|
11
|
+
/** Component custom property descriptors. */
|
|
10
12
|
readonly props?: ComponentPropDescriptors<TProps>;
|
|
13
|
+
/** True to mark the component as form-associated. */
|
|
14
|
+
readonly formAssociated?: boolean;
|
|
11
15
|
}
|
|
12
16
|
export type ComponentPropDescriptors<TProps extends object> = {
|
|
13
|
-
readonly [P in
|
|
17
|
+
readonly [P in SafePropKeys<TProps>]: ComponentPropDescriptorFactory<TProps[P]>;
|
|
14
18
|
};
|
|
15
19
|
export type ComponentPropDescriptorFactory<TType> = (ref: Ref<TType | undefined>, host: HTMLElement) => ComponentPropDescriptor<TType>;
|
|
16
20
|
export interface ComponentPropDescriptor<T> extends Omit<PropertyDescriptor, 'value' | 'get' | 'set'> {
|
|
@@ -18,13 +22,13 @@ export interface ComponentPropDescriptor<T> extends Omit<PropertyDescriptor, 'va
|
|
|
18
22
|
set?(value: T): void;
|
|
19
23
|
}
|
|
20
24
|
export type ComponentWithProps<TProps extends object> = HTMLElement & {
|
|
21
|
-
-readonly [P in
|
|
25
|
+
-readonly [P in SafePropKeys<TProps>]: TProps[P];
|
|
22
26
|
};
|
|
23
27
|
export type ComponentShadowRoot<TProps extends object> = Omit<ShadowRoot, 'host'> & {
|
|
24
28
|
readonly host: ComponentWithProps<TProps>;
|
|
25
29
|
};
|
|
26
30
|
export type ComponentPropRefs<TProps extends object> = {
|
|
27
|
-
readonly [P in
|
|
31
|
+
readonly [P in SafePropKeys<TProps>]: Ref<TProps[P] | undefined>;
|
|
28
32
|
};
|
|
29
33
|
/** Define a custom `HTMLElement` that is functional and reactive. */
|
|
30
34
|
export declare function defineComponent<TProps extends object = {}>(render: (shadowRoot: ComponentShadowRoot<TProps>, props: ComponentPropRefs<TProps>) => void, options?: ComponentOptions<TProps>): ComponentConstructor<TProps>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createController as e } from "./internal/createController.js";
|
|
2
|
+
//#region src/defineComponent.ts
|
|
3
|
+
function t(t, { props: n, shadow: r, formAssociated: i = !1 } = {}) {
|
|
4
|
+
return class extends HTMLElement {
|
|
5
|
+
static formAssociated = i;
|
|
6
|
+
#e;
|
|
7
|
+
#t;
|
|
8
|
+
#n = {};
|
|
9
|
+
constructor() {
|
|
10
|
+
if (super(), this.#e = this.attachShadow({
|
|
11
|
+
...r,
|
|
12
|
+
mode: r?.mode ?? "open"
|
|
13
|
+
}), this.#t = e({
|
|
14
|
+
host: this,
|
|
15
|
+
formAssociated: i,
|
|
16
|
+
render: () => t(this.#e, this.#n),
|
|
17
|
+
attachInternals: () => super.attachInternals()
|
|
18
|
+
}), n) {
|
|
19
|
+
let e = this.#n;
|
|
20
|
+
for (let [t, r] of Object.entries(n)) {
|
|
21
|
+
if (t in this) continue;
|
|
22
|
+
let n = r(e[t] = this.#t.createRef(void 0), this);
|
|
23
|
+
Object.defineProperty(this, t, n);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
i && this.attachInternals();
|
|
27
|
+
}
|
|
28
|
+
attachInternals() {
|
|
29
|
+
return this.#t.attachInternals();
|
|
30
|
+
}
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this.#t.connectedCallback();
|
|
33
|
+
}
|
|
34
|
+
connectedMoveCallback() {
|
|
35
|
+
this.#t.connectedMoveCallback();
|
|
36
|
+
}
|
|
37
|
+
disconnectedCallback() {
|
|
38
|
+
this.#t.disconnectedCallback();
|
|
39
|
+
}
|
|
40
|
+
adoptedCallback() {
|
|
41
|
+
this.#t.adoptedCallback();
|
|
42
|
+
}
|
|
43
|
+
formDisabledCallback(e) {
|
|
44
|
+
this.#t.formDisabledCallback(e);
|
|
45
|
+
}
|
|
46
|
+
formResetCallback() {
|
|
47
|
+
this.#t.formResetCallback();
|
|
48
|
+
}
|
|
49
|
+
formStateRestoreCallback(e, t) {
|
|
50
|
+
this.#t.formStateRestoreCallback(e, t);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { t as defineComponent };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=defineComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineComponent.js","names":["#shadow","#controller","#props"],"sources":["../src/defineComponent.ts"],"sourcesContent":["import { type Ref } from './hooks/useRef.ts';\nimport { type Controller, createController } from './internal/createController.ts';\n\ntype UnsafeProps =\n | 'connectedCallback'\n | 'connectedMoveCallback'\n | 'disconnectedCallback'\n | 'adoptedCallback'\n | 'formResetCallback'\n | 'formStateRestoreCallback'\n | 'formDisabledCallback';\n\ntype SafePropKeys<TProps> = Exclude<keyof TProps, keyof HTMLElement | UnsafeProps>;\n\nexport interface ComponentConstructor<TProps extends object> {\n readonly formAssociated: boolean;\n new (): ComponentWithProps<TProps>;\n}\n\nexport interface ComponentOptions<TProps extends object> {\n /** Shadow root attachment options. */\n readonly shadow?: Partial<ShadowRootInit>;\n /** Component custom property descriptors. */\n readonly props?: ComponentPropDescriptors<TProps>;\n /** True to mark the component as form-associated. */\n readonly formAssociated?: boolean;\n}\n\nexport type ComponentPropDescriptors<TProps extends object> = {\n readonly [P in SafePropKeys<TProps>]: ComponentPropDescriptorFactory<TProps[P]>;\n};\n\nexport type ComponentPropDescriptorFactory<TType> = (\n ref: Ref<TType | undefined>,\n host: HTMLElement,\n) => ComponentPropDescriptor<TType>;\n\nexport interface ComponentPropDescriptor<T> extends Omit<PropertyDescriptor, 'value' | 'get' | 'set'> {\n get(): T;\n set?(value: T): void;\n}\n\nexport type ComponentWithProps<TProps extends object> = HTMLElement & {\n -readonly [P in SafePropKeys<TProps>]: TProps[P];\n};\n\nexport type ComponentShadowRoot<TProps extends object> = Omit<ShadowRoot, 'host'> & {\n readonly host: ComponentWithProps<TProps>;\n};\n\nexport type ComponentPropRefs<TProps extends object> = {\n readonly [P in SafePropKeys<TProps>]: Ref<TProps[P] | undefined>;\n};\n\n/** Define a custom `HTMLElement` that is functional and reactive. */\nexport function defineComponent<TProps extends object = {}>(\n render: (shadowRoot: ComponentShadowRoot<TProps>, props: ComponentPropRefs<TProps>) => void,\n options?: ComponentOptions<TProps>,\n): ComponentConstructor<TProps>;\nexport function defineComponent(\n render: (\n shadowRoot: ComponentShadowRoot<Record<string, unknown>>,\n props: ComponentPropRefs<Record<string, unknown>>,\n ) => void,\n { props, shadow, formAssociated = false }: ComponentOptions<Record<string, unknown>> = {},\n): ComponentConstructor<{}> {\n return class extends HTMLElement {\n static readonly formAssociated = formAssociated;\n\n readonly #shadow: ComponentShadowRoot<Record<string, unknown>>;\n readonly #controller: Controller;\n readonly #props: ComponentPropRefs<Record<string, unknown>> = {};\n\n constructor() {\n super();\n\n this.#shadow = this.attachShadow({\n ...shadow,\n mode: shadow?.mode ?? 'open',\n }) as ComponentShadowRoot<Record<string, unknown>>;\n\n this.#controller = createController({\n host: this,\n formAssociated,\n render: () => render(this.#shadow, this.#props),\n attachInternals: () => super.attachInternals(),\n });\n\n if (props) {\n const propRefs: Record<string, Ref<unknown>> = this.#props;\n\n for (const [key, getDescriptor] of Object.entries(props)) {\n if (key in this) continue;\n const ref = (propRefs[key] = this.#controller.createRef<any>(undefined));\n const descriptor = getDescriptor(ref, this);\n Object.defineProperty(this, key, descriptor);\n }\n }\n\n if (formAssociated) {\n this.attachInternals();\n }\n }\n\n override attachInternals(): ElementInternals {\n return this.#controller.attachInternals();\n }\n\n protected connectedCallback(): void {\n this.#controller.connectedCallback();\n }\n\n protected connectedMoveCallback(): void {\n this.#controller.connectedMoveCallback();\n }\n\n protected disconnectedCallback(): void {\n this.#controller.disconnectedCallback();\n }\n\n protected adoptedCallback(): void {\n this.#controller.adoptedCallback();\n }\n\n protected formDisabledCallback(disabled: boolean): void {\n this.#controller.formDisabledCallback(disabled);\n }\n\n protected formResetCallback(): void {\n this.#controller.formResetCallback();\n }\n\n protected formStateRestoreCallback(state: string | File | FormData, reason: 'restore' | 'autocomplete'): void {\n this.#controller.formStateRestoreCallback(state, reason);\n }\n };\n}\n"],"mappings":";;AA2DA,SAAgB,EACd,GAIA,EAAE,UAAO,WAAQ,oBAAiB,OAAqD,EAAE,EAC/D;AAC1B,QAAO,cAAc,YAAY;EAC/B,OAAgB,iBAAiB;EAEjC;EACA;EACA,KAA8D,EAAE;EAEhE,cAAc;AAeZ,OAdA,OAAO,EAEP,MAAA,IAAe,KAAK,aAAa;IAC/B,GAAG;IACH,MAAM,GAAQ,QAAQ;IACvB,CAAC,EAEF,MAAA,IAAmB,EAAiB;IAClC,MAAM;IACN;IACA,cAAc,EAAO,MAAA,GAAc,MAAA,EAAY;IAC/C,uBAAuB,MAAM,iBAAiB;IAC/C,CAAC,EAEE,GAAO;IACT,IAAM,IAAyC,MAAA;AAE/C,SAAK,IAAM,CAAC,GAAK,MAAkB,OAAO,QAAQ,EAAM,EAAE;AACxD,SAAI,KAAO,KAAM;KAEjB,IAAM,IAAa,EAAc,EADX,KAAO,MAAA,EAAiB,UAAe,KAAA,EAAU,EACjC,KAAK;AAC3C,YAAO,eAAe,MAAM,GAAK,EAAW;;;AAIhD,GAAI,KACF,KAAK,iBAAiB;;EAI1B,kBAA6C;AAC3C,UAAO,MAAA,EAAiB,iBAAiB;;EAG3C,oBAAoC;AAClC,SAAA,EAAiB,mBAAmB;;EAGtC,wBAAwC;AACtC,SAAA,EAAiB,uBAAuB;;EAG1C,uBAAuC;AACrC,SAAA,EAAiB,sBAAsB;;EAGzC,kBAAkC;AAChC,SAAA,EAAiB,iBAAiB;;EAGpC,qBAA+B,GAAyB;AACtD,SAAA,EAAiB,qBAAqB,EAAS;;EAGjD,oBAAoC;AAClC,SAAA,EAAiB,mBAAmB;;EAGtC,yBAAmC,GAAiC,GAA0C;AAC5G,SAAA,EAAiB,yBAAyB,GAAO,EAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Store } from './
|
|
2
|
-
|
|
1
|
+
import { type Store } from './createStore.ts';
|
|
2
|
+
interface RouterState {
|
|
3
3
|
readonly pathname: string;
|
|
4
4
|
readonly hash: string;
|
|
5
5
|
}
|
|
@@ -9,3 +9,4 @@ export interface RouterState {
|
|
|
9
9
|
* called (ie. a singleton).
|
|
10
10
|
*/
|
|
11
11
|
export declare function getRouter(): Store<RouterState>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createStore as e } from "./createStore.js";
|
|
2
|
+
//#region src/getRouter.ts
|
|
3
|
+
var t;
|
|
4
|
+
function n() {
|
|
5
|
+
if (t) return t;
|
|
6
|
+
let n = e({
|
|
7
|
+
pathname: window.location.pathname,
|
|
8
|
+
hash: window.location.hash
|
|
9
|
+
}), r = () => {
|
|
10
|
+
let e = n.state;
|
|
11
|
+
n.state.pathname !== window.location.pathname && (e = {
|
|
12
|
+
...e,
|
|
13
|
+
pathname: window.location.pathname
|
|
14
|
+
}), n.state.hash !== window.location.hash && (e = {
|
|
15
|
+
...e,
|
|
16
|
+
hash: window.location.hash
|
|
17
|
+
}), n.state = e;
|
|
18
|
+
};
|
|
19
|
+
return Object.defineProperties(history, Object.fromEntries(["pushState", "replaceState"].map((e) => {
|
|
20
|
+
let t = history[e].bind(history);
|
|
21
|
+
return [e, {
|
|
22
|
+
value: (...e) => {
|
|
23
|
+
t(...e), r();
|
|
24
|
+
},
|
|
25
|
+
enumerable: !0,
|
|
26
|
+
configurable: !0
|
|
27
|
+
}];
|
|
28
|
+
}))), window.addEventListener("popstate", r), t = n, t;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { n as getRouter };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=getRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRouter.js","names":[],"sources":["../src/getRouter.ts"],"sourcesContent":["import { createStore, type Store } from './createStore.ts';\n\ninterface RouterState {\n readonly pathname: string;\n readonly hash: string;\n}\n\nlet singleton: Store<RouterState> | undefined;\n\n/**\n * Get a router {@link Store} that is updated when the client side route (aka:\n * `History`) changes. This method returns the same store every time it is\n * called (ie. a singleton).\n */\nexport function getRouter(): Store<RouterState> {\n if (singleton) return singleton;\n\n const store = createStore<RouterState>({\n pathname: window.location.pathname,\n hash: window.location.hash,\n });\n\n const onUpdate = (): void => {\n let state = store.state;\n\n if (store.state.pathname !== window.location.pathname) {\n state = { ...state, pathname: window.location.pathname };\n }\n\n if (store.state.hash !== window.location.hash) {\n state = { ...state, hash: window.location.hash };\n }\n\n store.state = state;\n };\n\n Object.defineProperties(\n history,\n Object.fromEntries(\n (['pushState', 'replaceState'] as const).map((method: 'pushState' | 'replaceState') => {\n const original = history[method].bind(history) as History['pushState'] & History['replaceState'];\n const descriptor: PropertyDescriptor = {\n value: (...args: Parameters<typeof original>) => {\n original(...args);\n onUpdate();\n },\n enumerable: true,\n configurable: true,\n };\n\n return [method, descriptor];\n }),\n ),\n );\n\n window.addEventListener('popstate', onUpdate);\n singleton = store;\n return singleton;\n}\n"],"mappings":";;AAOA,IAAI;AAOJ,SAAgB,IAAgC;AAC9C,KAAI,EAAW,QAAO;CAEtB,IAAM,IAAQ,EAAyB;EACrC,UAAU,OAAO,SAAS;EAC1B,MAAM,OAAO,SAAS;EACvB,CAAC,EAEI,UAAuB;EAC3B,IAAI,IAAQ,EAAM;AAUlB,EARI,EAAM,MAAM,aAAa,OAAO,SAAS,aAC3C,IAAQ;GAAE,GAAG;GAAO,UAAU,OAAO,SAAS;GAAU,GAGtD,EAAM,MAAM,SAAS,OAAO,SAAS,SACvC,IAAQ;GAAE,GAAG;GAAO,MAAM,OAAO,SAAS;GAAM,GAGlD,EAAM,QAAQ;;AAwBhB,QArBA,OAAO,iBACL,SACA,OAAO,YACJ,CAAC,aAAa,eAAe,CAAW,KAAK,MAAyC;EACrF,IAAM,IAAW,QAAQ,GAAQ,KAAK,QAAQ;AAU9C,SAAO,CAAC,GAAQ;GARd,QAAQ,GAAG,MAAsC;AAE/C,IADA,EAAS,GAAG,EAAK,EACjB,GAAU;;GAEZ,YAAY;GACZ,cAAc;GAGA,CAAW;GAC3B,CACH,CACF,EAED,OAAO,iBAAiB,YAAY,EAAS,EAC7C,IAAY,GACL"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReadonlyRef, type Ref, type RefValues } from './useRef.ts';
|
|
2
|
+
export interface AsyncValue<TValue> {
|
|
3
|
+
readonly value: TValue | undefined;
|
|
4
|
+
readonly error: unknown;
|
|
5
|
+
readonly isLoading: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface AsyncOptions {
|
|
8
|
+
readonly debounceMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Use a reference (reactive state) bound to an async loader function. */
|
|
11
|
+
export declare function useAsync<const TDeps extends readonly ReadonlyRef<any>[], TValue>(deps: TDeps, callback: (signal: AbortSignal, ...values: RefValues<TDeps>) => Promise<TValue>, { debounceMs }?: AsyncOptions): Ref<AsyncValue<TValue>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useRef as e } from "./
|
|
2
|
-
import { useEffect as t } from "./
|
|
3
|
-
//#region src/hooks/
|
|
1
|
+
import { useRef as e } from "./useRef.js";
|
|
2
|
+
import { useEffect as t } from "./useEffect.js";
|
|
3
|
+
//#region src/hooks/useAsync.ts
|
|
4
4
|
function n(n, r, { debounceMs: i } = {}) {
|
|
5
5
|
let a = e({
|
|
6
6
|
value: void 0,
|
|
@@ -27,6 +27,6 @@ function n(n, r, { debounceMs: i } = {}) {
|
|
|
27
27
|
}), t([], () => () => o = !0), a;
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
|
-
export { n as
|
|
30
|
+
export { n as useAsync };
|
|
31
31
|
|
|
32
|
-
//# sourceMappingURL=
|
|
32
|
+
//# sourceMappingURL=useAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsync.js","names":[],"sources":["../../src/hooks/useAsync.ts"],"sourcesContent":["import { useEffect } from './useEffect.ts';\nimport { type ReadonlyRef, type Ref, type RefValues, useRef } from './useRef.ts';\n\nexport interface AsyncValue<TValue> {\n readonly value: TValue | undefined;\n readonly error: unknown;\n readonly isLoading: boolean;\n}\n\nexport interface AsyncOptions {\n readonly debounceMs?: number;\n}\n\n/** Use a reference (reactive state) bound to an async loader function. */\nexport function useAsync<const TDeps extends readonly ReadonlyRef<any>[], TValue>(\n deps: TDeps,\n callback: (signal: AbortSignal, ...values: RefValues<TDeps>) => Promise<TValue>,\n { debounceMs }: AsyncOptions = {},\n): Ref<AsyncValue<TValue>> {\n const ref = useRef<AsyncValue<TValue>>({ value: undefined, error: undefined, isLoading: true });\n let skipDebounce = true;\n\n useEffect(deps, () => (...values) => {\n const ac = new AbortController();\n\n Promise.race(\n skipDebounce\n ? [Promise.resolve()]\n : [\n new Promise((resolve) => setTimeout(resolve, debounceMs)),\n new Promise((resolve) => ac.signal.addEventListener('abort', resolve, { once: true })),\n ],\n )\n .then(() => {\n if (ac.signal.aborted) return;\n return callback(ac.signal, ...(values as any));\n })\n .then((value) => {\n if (ac.signal.aborted) return;\n ref.value = { isLoading: false, value, error: undefined };\n })\n .catch((error: unknown) => {\n if (ac.signal.aborted) return;\n ref.value = { isLoading: false, value: undefined, error };\n });\n\n skipDebounce = false;\n return () => ac.abort();\n });\n\n // Skip the debounce again if the component unmounts.\n useEffect([], () => () => (skipDebounce = true));\n\n return ref;\n}\n"],"mappings":";;;AAcA,SAAgB,EACd,GACA,GACA,EAAE,kBAA6B,EAAE,EACR;CACzB,IAAM,IAAM,EAA2B;EAAE,OAAO,KAAA;EAAW,OAAO,KAAA;EAAW,WAAW;EAAM,CAAC,EAC3F,IAAe;AAiCnB,QA/BA,EAAU,UAAa,GAAG,MAAW;EACnC,IAAM,IAAK,IAAI,iBAAiB;AAwBhC,SAtBA,QAAQ,KACN,IACI,CAAC,QAAQ,SAAS,CAAC,GACnB,CACE,IAAI,SAAS,MAAY,WAAW,GAAS,EAAW,CAAC,EACzD,IAAI,SAAS,MAAY,EAAG,OAAO,iBAAiB,SAAS,GAAS,EAAE,MAAM,IAAM,CAAC,CAAC,CACvF,CACN,CACE,WAAW;AACN,UAAG,OAAO,QACd,QAAO,EAAS,EAAG,QAAQ,GAAI,EAAe;IAC9C,CACD,MAAM,MAAU;AACX,KAAG,OAAO,YACd,EAAI,QAAQ;IAAE,WAAW;IAAO;IAAO,OAAO,KAAA;IAAW;IACzD,CACD,OAAO,MAAmB;AACrB,KAAG,OAAO,YACd,EAAI,QAAQ;IAAE,WAAW;IAAO,OAAO,KAAA;IAAW;IAAO;IACzD,EAEJ,IAAe,UACF,EAAG,OAAO;GACvB,EAGF,EAAU,EAAE,cAAe,IAAe,GAAM,EAEzC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ref } from './
|
|
1
|
+
import { type Ref } from './useRef.ts';
|
|
2
2
|
/** Use references (reactive state) bound to attributes. */
|
|
3
3
|
export declare function useAttributes<const TNames extends string[]>(...names: TNames): {
|
|
4
4
|
-readonly [P in keyof TNames]: Ref<string | null>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useInternalController as e } from "./useInternalController.js";
|
|
2
|
+
import { useRef as t } from "./useRef.js";
|
|
3
|
+
import { getOrInsert as n } from "../internal/getOrInsert.js";
|
|
4
|
+
import { useHost as r } from "./useHost.js";
|
|
5
|
+
//#region src/hooks/useAttributes.ts
|
|
6
|
+
var i = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function a(...a) {
|
|
8
|
+
if (a.length === 0) return {};
|
|
9
|
+
let o = r(), s = [], c = n(i, o, (t) => {
|
|
10
|
+
let { onAfterRender: n, onDisconnect: r } = e(), a = /* @__PURE__ */ new Map();
|
|
11
|
+
return i.set(t, a), n.push(() => {
|
|
12
|
+
i.delete(t);
|
|
13
|
+
let e = new MutationObserver((e) => {
|
|
14
|
+
for (let { attributeName: n } of e) {
|
|
15
|
+
if (n == null) continue;
|
|
16
|
+
let e = a.get(n);
|
|
17
|
+
e && (e.value = t.getAttribute(n));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
e.observe(t, {
|
|
21
|
+
attributeFilter: [...a.keys()],
|
|
22
|
+
attributes: !0
|
|
23
|
+
}), r.push(() => e.disconnect());
|
|
24
|
+
}), a;
|
|
25
|
+
});
|
|
26
|
+
for (let e of a) {
|
|
27
|
+
let r = n(c, e, (e) => t(o.getAttribute(e), (t) => {
|
|
28
|
+
t == null ? o.removeAttribute(e) : o.setAttribute(e, t);
|
|
29
|
+
}));
|
|
30
|
+
s.push(r);
|
|
31
|
+
}
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { a as useAttributes };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=useAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAttributes.js","names":[],"sources":["../../src/hooks/useAttributes.ts"],"sourcesContent":["import { getOrInsert } from '../internal/getOrInsert.ts';\nimport { useHost } from './useHost.ts';\nimport { useInternalController } from './useInternalController.ts';\nimport { type Ref, useRef } from './useRef.ts';\n\nconst hostRefMaps = new WeakMap<HTMLElement, Map<string, Ref<string | null>>>();\n\n/** Use references (reactive state) bound to attributes. */\nexport function useAttributes<const TNames extends string[]>(\n ...names: TNames\n): { -readonly [P in keyof TNames]: Ref<string | null> } {\n if (names.length === 0) return {} as any;\n const host = useHost();\n const refs: Ref<string | null>[] = [];\n const refMap = getOrInsert(hostRefMaps, host, (host) => {\n const { onAfterRender, onDisconnect } = useInternalController();\n const refMap = new Map<string, Ref<string | null>>();\n hostRefMaps.set(host, refMap);\n\n onAfterRender.push(() => {\n hostRefMaps.delete(host);\n\n const observer = new MutationObserver((mutation) => {\n for (const { attributeName } of mutation) {\n if (attributeName == null) continue;\n const ref = refMap.get(attributeName);\n if (ref) ref.value = host.getAttribute(attributeName);\n }\n });\n\n observer.observe(host, { attributeFilter: [...refMap.keys()], attributes: true });\n onDisconnect.push(() => observer.disconnect());\n });\n\n return refMap;\n });\n\n for (const name of names) {\n const ref = getOrInsert(refMap, name, (name) => {\n return useRef(host.getAttribute(name), (value) => {\n if (value == null) host.removeAttribute(name);\n else host.setAttribute(name, value);\n });\n });\n\n refs.push(ref);\n }\n\n return refs as any;\n}\n"],"mappings":";;;;;AAKA,IAAM,oBAAc,IAAI,SAAuD;AAG/E,SAAgB,EACd,GAAG,GACoD;AACvD,KAAI,EAAM,WAAW,EAAG,QAAO,EAAE;CACjC,IAAM,IAAO,GAAS,EAChB,IAA6B,EAAE,EAC/B,IAAS,EAAY,GAAa,IAAO,MAAS;EACtD,IAAM,EAAE,kBAAe,oBAAiB,GAAuB,EACzD,oBAAS,IAAI,KAAiC;AAkBpD,SAjBA,EAAY,IAAI,GAAM,EAAO,EAE7B,EAAc,WAAW;AACvB,KAAY,OAAO,EAAK;GAExB,IAAM,IAAW,IAAI,kBAAkB,MAAa;AAClD,SAAK,IAAM,EAAE,sBAAmB,GAAU;AACxC,SAAI,KAAiB,KAAM;KAC3B,IAAM,IAAM,EAAO,IAAI,EAAc;AACrC,KAAI,MAAK,EAAI,QAAQ,EAAK,aAAa,EAAc;;KAEvD;AAGF,GADA,EAAS,QAAQ,GAAM;IAAE,iBAAiB,CAAC,GAAG,EAAO,MAAM,CAAC;IAAE,YAAY;IAAM,CAAC,EACjF,EAAa,WAAW,EAAS,YAAY,CAAC;IAC9C,EAEK;GACP;AAEF,MAAK,IAAM,KAAQ,GAAO;EACxB,IAAM,IAAM,EAAY,GAAQ,IAAO,MAC9B,EAAO,EAAK,aAAa,EAAK,GAAG,MAAU;AAChD,GAAI,KAAS,OAAM,EAAK,gBAAgB,EAAK,GACxC,EAAK,aAAa,GAAM,EAAM;IACnC,CACF;AAEF,IAAK,KAAK,EAAI;;AAGhB,QAAO"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useInternalController as e } from "./useInternalController.js";
|
|
2
|
+
import { useRef as t } from "./useRef.js";
|
|
3
|
+
import { useEffect as n } from "./useEffect.js";
|
|
4
|
+
import { getOrInsert as r } from "../internal/getOrInsert.js";
|
|
5
|
+
import { useHost as i } from "./useHost.js";
|
|
6
|
+
//#region src/hooks/useChildEffect.ts
|
|
7
|
+
var a = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function o(o) {
|
|
9
|
+
let s = i();
|
|
10
|
+
n([r(a, s, () => {
|
|
11
|
+
let { onAfterRender: n, onDisconnect: r } = e(), i = t({});
|
|
12
|
+
return n.push(() => {
|
|
13
|
+
a.delete(s);
|
|
14
|
+
let e = new MutationObserver(() => {
|
|
15
|
+
i.value = {};
|
|
16
|
+
});
|
|
17
|
+
e.observe(s, { childList: !0 }), r.push(() => e.disconnect());
|
|
18
|
+
}), i;
|
|
19
|
+
})], () => o());
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { o as useChildEffect };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=useChildEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChildEffect.js","names":[],"sources":["../../src/hooks/useChildEffect.ts"],"sourcesContent":["import { getOrInsert } from '../internal/getOrInsert.ts';\nimport { useEffect } from './useEffect.ts';\nimport { useHost } from './useHost.ts';\nimport { useInternalController } from './useInternalController.ts';\nimport { type Ref, useRef } from './useRef.ts';\n\nconst hostRefs = new WeakMap<HTMLElement, Ref<{}>>();\n\n/** React to child list changes (non-recursive). */\nexport function useChildEffect(callback: () => (() => void) | void): void {\n const host = useHost();\n const ref = getOrInsert(hostRefs, host, () => {\n const { onAfterRender, onDisconnect } = useInternalController();\n const ref = useRef({});\n\n onAfterRender.push(() => {\n hostRefs.delete(host);\n\n const observer = new MutationObserver(() => {\n ref.value = {};\n });\n\n observer.observe(host, { childList: true });\n onDisconnect.push(() => observer.disconnect());\n });\n\n return ref;\n });\n\n useEffect([ref], () => callback());\n}\n"],"mappings":";;;;;;AAMA,IAAM,oBAAW,IAAI,SAA+B;AAGpD,SAAgB,EAAe,GAA2C;CACxE,IAAM,IAAO,GAAS;AAmBtB,GAAU,CAlBE,EAAY,GAAU,SAAY;EAC5C,IAAM,EAAE,kBAAe,oBAAiB,GAAuB,EACzD,IAAM,EAAO,EAAE,CAAC;AAatB,SAXA,EAAc,WAAW;AACvB,KAAS,OAAO,EAAK;GAErB,IAAM,IAAW,IAAI,uBAAuB;AAC1C,MAAI,QAAQ,EAAE;KACd;AAGF,GADA,EAAS,QAAQ,GAAM,EAAE,WAAW,IAAM,CAAC,EAC3C,EAAa,WAAW,EAAS,YAAY,CAAC;IAC9C,EAEK;GAGE,CAAI,QAAQ,GAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDisconnect.js","names":[],"sources":["../../src/hooks/useDisconnect.ts"],"sourcesContent":["import { useInternalController } from './useInternalController.ts';\n\n/** Register a callback for disconnections. */\nexport function useDisconnectCallback(callback: () => void): void {\n useInternalController().onDisconnect.push(callback);\n}\n"],"mappings":";;AAGA,SAAgB,EAAsB,GAA4B;AAChE,IAAuB,CAAC,aAAa,KAAK,EAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDocument.js","names":[],"sources":["../../src/hooks/useDocument.ts"],"sourcesContent":["import { useInternalController } from './useInternalController.ts';\nimport type { ReadonlyRef } from './useRef.ts';\n\n/** Use a reference (reactive state) bound to the owner document. */\nexport function useDocument(): ReadonlyRef<Document> {\n return useInternalController().refDocument;\n}\n"],"mappings":";;AAIA,SAAgB,IAAqC;AACnD,QAAO,GAAuB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ReadonlyRef, RefValues } from './useRef.ts';
|
|
2
|
+
/** React to observable (reference) changes. */
|
|
3
|
+
export declare function useEffect<const TDeps extends readonly ReadonlyRef<any>[]>(deps: TDeps, callback: (...values: RefValues<TDeps>) => (() => void) | void): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useInternalController as e } from "./useInternalController.js";
|
|
2
|
+
import { useDisconnectCallback as t } from "./useDisconnect.js";
|
|
3
|
+
//#region src/hooks/useEffect.ts
|
|
4
|
+
function n(n, r) {
|
|
5
|
+
let i, a, o = () => {
|
|
6
|
+
let e = i;
|
|
7
|
+
i = void 0, e?.();
|
|
8
|
+
};
|
|
9
|
+
e().onNotify.push(() => {
|
|
10
|
+
let e = n.map((e) => e.value);
|
|
11
|
+
a?.length === e.length && a?.every((t, n) => t === e[n]) || (a = e, o(), i = r(...a));
|
|
12
|
+
}), t(o);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { n as useEffect };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=useEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEffect.js","names":[],"sources":["../../src/hooks/useEffect.ts"],"sourcesContent":["import { useDisconnectCallback } from './useDisconnect.ts';\nimport { useInternalController } from './useInternalController.ts';\nimport type { ReadonlyRef, RefValues } from './useRef.ts';\n\n/** React to observable (reference) changes. */\nexport function useEffect<const TDeps extends readonly ReadonlyRef<any>[]>(\n deps: TDeps,\n callback: (...values: RefValues<TDeps>) => (() => void) | void,\n): void {\n let cleanupCallback: (() => void) | void;\n let values: any[] | undefined;\n\n const cleanup = () => {\n const callback = cleanupCallback;\n cleanupCallback = undefined;\n callback?.();\n };\n\n useInternalController().onNotify.push((): void => {\n const newValues = deps.map((dep) => dep.value);\n if (values?.length === newValues.length && values?.every((value, i) => value === newValues[i])) return;\n values = newValues;\n cleanup();\n cleanupCallback = callback(...(values as any));\n });\n\n useDisconnectCallback(cleanup);\n}\n"],"mappings":";;;AAKA,SAAgB,EACd,GACA,GACM;CACN,IAAI,GACA,GAEE,UAAgB;EACpB,IAAM,IAAW;AAEjB,EADA,IAAkB,KAAA,GAClB,KAAY;;AAWd,CARA,GAAuB,CAAC,SAAS,WAAiB;EAChD,IAAM,IAAY,EAAK,KAAK,MAAQ,EAAI,MAAM;AAC1C,KAAQ,WAAW,EAAU,UAAU,GAAQ,OAAO,GAAO,MAAM,MAAU,EAAU,GAAG,KAC9F,IAAS,GACT,GAAS,EACT,IAAkB,EAAS,GAAI,EAAe;GAC9C,EAEF,EAAsB,EAAQ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useInternalController as e } from "./useInternalController.js";
|
|
2
|
+
//#region src/hooks/useElementInternals.ts
|
|
3
|
+
function t() {
|
|
4
|
+
return e().attachInternals();
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { t as useElementInternals };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=useElementInternals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useElementInternals.js","names":[],"sources":["../../src/hooks/useElementInternals.ts"],"sourcesContent":["import { useInternalController } from './useInternalController.ts';\n\n/** Use the element internals. */\nexport function useElementInternals(): ElementInternals {\n return useInternalController().attachInternals();\n}\n"],"mappings":";;AAGA,SAAgB,IAAwC;AACtD,QAAO,GAAuB,CAAC,iBAAiB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReadonlyRef } from './useRef.ts';
|
|
2
|
+
/** Use a reference (reactive state) bound to the associated form. */
|
|
3
|
+
export declare function useForm(): ReadonlyRef<HTMLFormElement | null>;
|
|
4
|
+
/** Use a reference (reactive state) bound to the form disabled state. */
|
|
5
|
+
export declare function useFormDisabled(): ReadonlyRef<boolean>;
|
|
6
|
+
/** Register a callback for form resets. */
|
|
7
|
+
export declare function useFormResetCallback(callback: () => void): void;
|
|
8
|
+
/** Register a callback for form restorations. */
|
|
9
|
+
export declare function useFormRestoreCallback(callback: (state: string | File | FormData, reason: 'restore' | 'autocomplete') => void): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useInternalController as e } from "./useInternalController.js";
|
|
2
|
+
//#region src/hooks/useForm.ts
|
|
3
|
+
function t() {
|
|
4
|
+
return a().refForm;
|
|
5
|
+
}
|
|
6
|
+
function n() {
|
|
7
|
+
return a().refDisabled;
|
|
8
|
+
}
|
|
9
|
+
function r(e) {
|
|
10
|
+
a().onReset.push(e);
|
|
11
|
+
}
|
|
12
|
+
function i(e) {
|
|
13
|
+
a().onRestore.push(e);
|
|
14
|
+
}
|
|
15
|
+
function a() {
|
|
16
|
+
let { formAssociated: t } = e();
|
|
17
|
+
if (!t) throw Error("form hooks must be called in a form-associated component");
|
|
18
|
+
return t;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { t as useForm, n as useFormDisabled, r as useFormResetCallback, i as useFormRestoreCallback };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=useForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useForm.js","names":[],"sources":["../../src/hooks/useForm.ts"],"sourcesContent":["import type { Controller } from '../internal/createController.ts';\nimport { useInternalController } from './useInternalController.ts';\nimport type { ReadonlyRef } from './useRef.ts';\n\n/** Use a reference (reactive state) bound to the associated form. */\nexport function useForm(): ReadonlyRef<HTMLFormElement | null> {\n return useInternalFormAssociatedController().refForm;\n}\n\n/** Use a reference (reactive state) bound to the form disabled state. */\nexport function useFormDisabled(): ReadonlyRef<boolean> {\n return useInternalFormAssociatedController().refDisabled;\n}\n\n/** Register a callback for form resets. */\nexport function useFormResetCallback(callback: () => void): void {\n useInternalFormAssociatedController().onReset.push(callback);\n}\n\n/** Register a callback for form restorations. */\nexport function useFormRestoreCallback(\n callback: (state: string | File | FormData, reason: 'restore' | 'autocomplete') => void,\n): void {\n useInternalFormAssociatedController().onRestore.push(callback);\n}\n\nfunction useInternalFormAssociatedController(): Controller['formAssociated'] & {} {\n const { formAssociated } = useInternalController();\n if (!formAssociated) throw new Error('form hooks must be called in a form-associated component');\n return formAssociated;\n}\n"],"mappings":";;AAKA,SAAgB,IAA+C;AAC7D,QAAO,GAAqC,CAAC;;AAI/C,SAAgB,IAAwC;AACtD,QAAO,GAAqC,CAAC;;AAI/C,SAAgB,EAAqB,GAA4B;AAC/D,IAAqC,CAAC,QAAQ,KAAK,EAAS;;AAI9D,SAAgB,EACd,GACM;AACN,IAAqC,CAAC,UAAU,KAAK,EAAS;;AAGhE,SAAS,IAAyE;CAChF,IAAM,EAAE,sBAAmB,GAAuB;AAClD,KAAI,CAAC,EAAgB,OAAU,MAAM,2DAA2D;AAChG,QAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Use the component host element. */
|
|
2
2
|
export declare function useHost(): HTMLElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHost.js","names":[],"sources":["../../src/hooks/useHost.ts"],"sourcesContent":["import { useInternalController } from './useInternalController.ts';\n\n/** Use the component host element. */\nexport function useHost(): HTMLElement {\n return useInternalController().host;\n}\n"],"mappings":";;AAGA,SAAgB,IAAuB;AACrC,QAAO,GAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { controllers as e } from "../internal/controllers.js";
|
|
2
|
+
//#region src/hooks/useInternalController.ts
|
|
3
|
+
function t() {
|
|
4
|
+
let t = e.at(-1);
|
|
5
|
+
if (!t) throw Error("hooks must be called by a render function");
|
|
6
|
+
return t;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as useInternalController };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=useInternalController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInternalController.js","names":[],"sources":["../../src/hooks/useInternalController.ts"],"sourcesContent":["import { controllers } from '../internal/controllers.ts';\nimport { type Controller } from '../internal/createController.ts';\n\n/** @internal Get the controller of the currently rendering component. */\nexport function useInternalController(): Controller {\n const controller = controllers.at(-1);\n if (!controller) throw new Error('hooks must be called by a render function');\n return controller;\n}\n"],"mappings":";;AAIA,SAAgB,IAAoC;CAClD,IAAM,IAAa,EAAY,GAAG,GAAG;AACrC,KAAI,CAAC,EAAY,OAAU,MAAM,4CAA4C;AAC7E,QAAO"}
|