thunderous 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +34 -17
- package/dist/index.d.cts +56 -5
- package/dist/index.d.ts +56 -5
- package/dist/index.js +34 -17
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
@@ -294,6 +294,7 @@ var customElement = (render, options) => {
|
|
294
294
|
#connectedFns = /* @__PURE__ */ new Set();
|
295
295
|
#disconnectedFns = /* @__PURE__ */ new Set();
|
296
296
|
#adoptedCallbackFns = /* @__PURE__ */ new Set();
|
297
|
+
#formAssociatedCallbackFns = /* @__PURE__ */ new Set();
|
297
298
|
#formDisabledCallbackFns = /* @__PURE__ */ new Set();
|
298
299
|
#formResetCallbackFns = /* @__PURE__ */ new Set();
|
299
300
|
#formStateRestoreCallbackFns = /* @__PURE__ */ new Set();
|
@@ -325,6 +326,7 @@ var customElement = (render, options) => {
|
|
325
326
|
connectedCallback: (fn) => this.#connectedFns.add(fn),
|
326
327
|
disconnectedCallback: (fn) => this.#disconnectedFns.add(fn),
|
327
328
|
adoptedCallback: (fn) => this.#adoptedCallbackFns.add(fn),
|
329
|
+
formAssociatedCallback: (fn) => this.#formAssociatedCallbackFns.add(fn),
|
328
330
|
formDisabledCallback: (fn) => this.#formDisabledCallbackFns.add(fn),
|
329
331
|
formResetCallback: (fn) => this.#formResetCallbackFns.add(fn),
|
330
332
|
formStateRestoreCallback: (fn) => this.#formStateRestoreCallbackFns.add(fn),
|
@@ -348,24 +350,34 @@ var customElement = (render, options) => {
|
|
348
350
|
}
|
349
351
|
}
|
350
352
|
),
|
351
|
-
propSignals: new Proxy(
|
352
|
-
{
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
353
|
+
propSignals: new Proxy({}, {
|
354
|
+
get: (_, prop) => {
|
355
|
+
if (!(prop in this.#propSignals)) this.#propSignals[prop] = createSignal();
|
356
|
+
const [_getter, _setter] = this.#propSignals[prop];
|
357
|
+
const setter = (newValue) => {
|
358
|
+
this[prop] = newValue;
|
359
|
+
_setter(newValue);
|
360
|
+
};
|
361
|
+
const getter = () => {
|
362
|
+
const value = _getter();
|
363
|
+
if (value === void 0)
|
364
|
+
throw new Error(
|
365
|
+
`
|
366
|
+
|
367
|
+
Property: ${prop}
|
368
|
+
|
369
|
+
You must set an initial value before calling a property signal's getter.
|
370
|
+
`
|
371
|
+
);
|
372
|
+
return value;
|
373
|
+
};
|
374
|
+
return [getter, setter];
|
375
|
+
},
|
376
|
+
set: () => {
|
377
|
+
console.error("Signals must be assigned via setters.");
|
378
|
+
return false;
|
367
379
|
}
|
368
|
-
),
|
380
|
+
}),
|
369
381
|
refs: new Proxy(
|
370
382
|
{},
|
371
383
|
{
|
@@ -476,6 +488,11 @@ var customElement = (render, options) => {
|
|
476
488
|
fn();
|
477
489
|
}
|
478
490
|
}
|
491
|
+
formAssociatedCallback() {
|
492
|
+
for (const fn of this.#formAssociatedCallbackFns) {
|
493
|
+
fn();
|
494
|
+
}
|
495
|
+
}
|
479
496
|
formDisabledCallback() {
|
480
497
|
for (const fn of this.#formDisabledCallbackFns) {
|
481
498
|
fn();
|
package/dist/index.d.cts
CHANGED
@@ -14,8 +14,35 @@ type SignalOptions = {
|
|
14
14
|
type SignalGetter<T> = (options?: SignalOptions) => T;
|
15
15
|
type SignalSetter<T> = (newValue: T, options?: SignalOptions) => void;
|
16
16
|
type Signal<T = unknown> = [SignalGetter<T>, SignalSetter<T>];
|
17
|
+
/**
|
18
|
+
* Create a signal with an initial value.
|
19
|
+
* @example
|
20
|
+
* ```ts
|
21
|
+
* const [getCount, setCount] = createSignal(0);
|
22
|
+
* const increment = () => setCount(getCount() + 1);
|
23
|
+
* const decrement = () => setCount(getCount() - 1);
|
24
|
+
* ```
|
25
|
+
*/
|
17
26
|
declare const createSignal: <T = undefined>(initVal?: T, options?: SignalOptions) => Signal<T>;
|
27
|
+
/**
|
28
|
+
* Create a derived signal that depends on other signals.
|
29
|
+
* @example
|
30
|
+
* ```ts
|
31
|
+
* const [getCount, setCount] = createSignal(0);
|
32
|
+
* const doubleCount = derived(() => getCount() * 2);
|
33
|
+
* ```
|
34
|
+
*/
|
18
35
|
declare const derived: <T>(fn: () => T) => SignalGetter<T>;
|
36
|
+
/**
|
37
|
+
* Create an effect that runs when signals change.
|
38
|
+
* @example
|
39
|
+
* ```ts
|
40
|
+
* const [getCount, setCount] = createSignal(0);
|
41
|
+
* createEffect(() => {
|
42
|
+
* console.log('Count:', getCount());
|
43
|
+
* });
|
44
|
+
* ```
|
45
|
+
*/
|
19
46
|
declare const createEffect: (fn: () => void) => void;
|
20
47
|
|
21
48
|
declare global {
|
@@ -29,7 +56,8 @@ type ElementResult = {
|
|
29
56
|
eject: () => CustomElementConstructor;
|
30
57
|
};
|
31
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
32
|
-
type
|
59
|
+
type CustomElementProps = Record<PropertyKey, unknown>;
|
60
|
+
type RenderArgs<Props extends CustomElementProps> = {
|
33
61
|
elementRef: HTMLElement;
|
34
62
|
root: ShadowRoot | HTMLElement;
|
35
63
|
internals: ElementInternals;
|
@@ -40,9 +68,12 @@ type RenderProps = {
|
|
40
68
|
formDisabledCallback: (fn: () => void) => void;
|
41
69
|
formResetCallback: (fn: () => void) => void;
|
42
70
|
formStateRestoreCallback: (fn: () => void) => void;
|
71
|
+
formAssociatedCallback: (fn: () => void) => void;
|
43
72
|
customCallback: (fn: () => void) => `{{callback:${string}}}`;
|
44
73
|
attrSignals: Record<string, Signal<string | null>>;
|
45
|
-
propSignals:
|
74
|
+
propSignals: {
|
75
|
+
[K in keyof Props]: Signal<Props[K]>;
|
76
|
+
};
|
46
77
|
refs: Record<string, HTMLElement | null>;
|
47
78
|
adoptStyleSheet: (stylesheet: Styles) => void;
|
48
79
|
};
|
@@ -54,12 +85,32 @@ type RenderOptions = {
|
|
54
85
|
attachShadow: boolean;
|
55
86
|
shadowRootOptions: ShadowRootInit;
|
56
87
|
};
|
57
|
-
type RenderFunction = (
|
58
|
-
|
88
|
+
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
89
|
+
/**
|
90
|
+
* Create a custom element that can be defined for use in the DOM.
|
91
|
+
* @example
|
92
|
+
* ```ts
|
93
|
+
* const MyElement = customElement(() => {
|
94
|
+
* return html`<h1>Hello, World!</h1>`;
|
95
|
+
* });
|
96
|
+
* MyElement.define('my-element');
|
97
|
+
* ```
|
98
|
+
*/
|
99
|
+
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
59
100
|
type Registry = {
|
60
101
|
register: (tagName: string, element: CustomElementConstructor) => void;
|
61
102
|
getTagName: (element: CustomElementConstructor) => string | undefined;
|
62
103
|
};
|
104
|
+
/**
|
105
|
+
* Create a registry for custom elements.
|
106
|
+
* @example
|
107
|
+
* ```ts
|
108
|
+
* const registry = createRegistry();
|
109
|
+
* registry.register('my-element', MyElement);
|
110
|
+
* const tagName = registry.getTagName(MyElement);
|
111
|
+
* console.log(tagName); // 'MY-ELEMENT'
|
112
|
+
* ```
|
113
|
+
*/
|
63
114
|
declare const createRegistry: () => Registry;
|
64
115
|
|
65
|
-
export { type RenderFunction, type RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
116
|
+
export { type RenderArgs, type RenderFunction, type RenderArgs as RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
package/dist/index.d.ts
CHANGED
@@ -14,8 +14,35 @@ type SignalOptions = {
|
|
14
14
|
type SignalGetter<T> = (options?: SignalOptions) => T;
|
15
15
|
type SignalSetter<T> = (newValue: T, options?: SignalOptions) => void;
|
16
16
|
type Signal<T = unknown> = [SignalGetter<T>, SignalSetter<T>];
|
17
|
+
/**
|
18
|
+
* Create a signal with an initial value.
|
19
|
+
* @example
|
20
|
+
* ```ts
|
21
|
+
* const [getCount, setCount] = createSignal(0);
|
22
|
+
* const increment = () => setCount(getCount() + 1);
|
23
|
+
* const decrement = () => setCount(getCount() - 1);
|
24
|
+
* ```
|
25
|
+
*/
|
17
26
|
declare const createSignal: <T = undefined>(initVal?: T, options?: SignalOptions) => Signal<T>;
|
27
|
+
/**
|
28
|
+
* Create a derived signal that depends on other signals.
|
29
|
+
* @example
|
30
|
+
* ```ts
|
31
|
+
* const [getCount, setCount] = createSignal(0);
|
32
|
+
* const doubleCount = derived(() => getCount() * 2);
|
33
|
+
* ```
|
34
|
+
*/
|
18
35
|
declare const derived: <T>(fn: () => T) => SignalGetter<T>;
|
36
|
+
/**
|
37
|
+
* Create an effect that runs when signals change.
|
38
|
+
* @example
|
39
|
+
* ```ts
|
40
|
+
* const [getCount, setCount] = createSignal(0);
|
41
|
+
* createEffect(() => {
|
42
|
+
* console.log('Count:', getCount());
|
43
|
+
* });
|
44
|
+
* ```
|
45
|
+
*/
|
19
46
|
declare const createEffect: (fn: () => void) => void;
|
20
47
|
|
21
48
|
declare global {
|
@@ -29,7 +56,8 @@ type ElementResult = {
|
|
29
56
|
eject: () => CustomElementConstructor;
|
30
57
|
};
|
31
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
32
|
-
type
|
59
|
+
type CustomElementProps = Record<PropertyKey, unknown>;
|
60
|
+
type RenderArgs<Props extends CustomElementProps> = {
|
33
61
|
elementRef: HTMLElement;
|
34
62
|
root: ShadowRoot | HTMLElement;
|
35
63
|
internals: ElementInternals;
|
@@ -40,9 +68,12 @@ type RenderProps = {
|
|
40
68
|
formDisabledCallback: (fn: () => void) => void;
|
41
69
|
formResetCallback: (fn: () => void) => void;
|
42
70
|
formStateRestoreCallback: (fn: () => void) => void;
|
71
|
+
formAssociatedCallback: (fn: () => void) => void;
|
43
72
|
customCallback: (fn: () => void) => `{{callback:${string}}}`;
|
44
73
|
attrSignals: Record<string, Signal<string | null>>;
|
45
|
-
propSignals:
|
74
|
+
propSignals: {
|
75
|
+
[K in keyof Props]: Signal<Props[K]>;
|
76
|
+
};
|
46
77
|
refs: Record<string, HTMLElement | null>;
|
47
78
|
adoptStyleSheet: (stylesheet: Styles) => void;
|
48
79
|
};
|
@@ -54,12 +85,32 @@ type RenderOptions = {
|
|
54
85
|
attachShadow: boolean;
|
55
86
|
shadowRootOptions: ShadowRootInit;
|
56
87
|
};
|
57
|
-
type RenderFunction = (
|
58
|
-
|
88
|
+
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
89
|
+
/**
|
90
|
+
* Create a custom element that can be defined for use in the DOM.
|
91
|
+
* @example
|
92
|
+
* ```ts
|
93
|
+
* const MyElement = customElement(() => {
|
94
|
+
* return html`<h1>Hello, World!</h1>`;
|
95
|
+
* });
|
96
|
+
* MyElement.define('my-element');
|
97
|
+
* ```
|
98
|
+
*/
|
99
|
+
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
59
100
|
type Registry = {
|
60
101
|
register: (tagName: string, element: CustomElementConstructor) => void;
|
61
102
|
getTagName: (element: CustomElementConstructor) => string | undefined;
|
62
103
|
};
|
104
|
+
/**
|
105
|
+
* Create a registry for custom elements.
|
106
|
+
* @example
|
107
|
+
* ```ts
|
108
|
+
* const registry = createRegistry();
|
109
|
+
* registry.register('my-element', MyElement);
|
110
|
+
* const tagName = registry.getTagName(MyElement);
|
111
|
+
* console.log(tagName); // 'MY-ELEMENT'
|
112
|
+
* ```
|
113
|
+
*/
|
63
114
|
declare const createRegistry: () => Registry;
|
64
115
|
|
65
|
-
export { type RenderFunction, type RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
116
|
+
export { type RenderArgs, type RenderFunction, type RenderArgs as RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
package/dist/index.js
CHANGED
@@ -252,6 +252,7 @@ var customElement = (render, options) => {
|
|
252
252
|
#connectedFns = /* @__PURE__ */ new Set();
|
253
253
|
#disconnectedFns = /* @__PURE__ */ new Set();
|
254
254
|
#adoptedCallbackFns = /* @__PURE__ */ new Set();
|
255
|
+
#formAssociatedCallbackFns = /* @__PURE__ */ new Set();
|
255
256
|
#formDisabledCallbackFns = /* @__PURE__ */ new Set();
|
256
257
|
#formResetCallbackFns = /* @__PURE__ */ new Set();
|
257
258
|
#formStateRestoreCallbackFns = /* @__PURE__ */ new Set();
|
@@ -283,6 +284,7 @@ var customElement = (render, options) => {
|
|
283
284
|
connectedCallback: (fn) => this.#connectedFns.add(fn),
|
284
285
|
disconnectedCallback: (fn) => this.#disconnectedFns.add(fn),
|
285
286
|
adoptedCallback: (fn) => this.#adoptedCallbackFns.add(fn),
|
287
|
+
formAssociatedCallback: (fn) => this.#formAssociatedCallbackFns.add(fn),
|
286
288
|
formDisabledCallback: (fn) => this.#formDisabledCallbackFns.add(fn),
|
287
289
|
formResetCallback: (fn) => this.#formResetCallbackFns.add(fn),
|
288
290
|
formStateRestoreCallback: (fn) => this.#formStateRestoreCallbackFns.add(fn),
|
@@ -306,24 +308,34 @@ var customElement = (render, options) => {
|
|
306
308
|
}
|
307
309
|
}
|
308
310
|
),
|
309
|
-
propSignals: new Proxy(
|
310
|
-
{
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
311
|
+
propSignals: new Proxy({}, {
|
312
|
+
get: (_, prop) => {
|
313
|
+
if (!(prop in this.#propSignals)) this.#propSignals[prop] = createSignal();
|
314
|
+
const [_getter, _setter] = this.#propSignals[prop];
|
315
|
+
const setter = (newValue) => {
|
316
|
+
this[prop] = newValue;
|
317
|
+
_setter(newValue);
|
318
|
+
};
|
319
|
+
const getter = () => {
|
320
|
+
const value = _getter();
|
321
|
+
if (value === void 0)
|
322
|
+
throw new Error(
|
323
|
+
`
|
324
|
+
|
325
|
+
Property: ${prop}
|
326
|
+
|
327
|
+
You must set an initial value before calling a property signal's getter.
|
328
|
+
`
|
329
|
+
);
|
330
|
+
return value;
|
331
|
+
};
|
332
|
+
return [getter, setter];
|
333
|
+
},
|
334
|
+
set: () => {
|
335
|
+
console.error("Signals must be assigned via setters.");
|
336
|
+
return false;
|
325
337
|
}
|
326
|
-
),
|
338
|
+
}),
|
327
339
|
refs: new Proxy(
|
328
340
|
{},
|
329
341
|
{
|
@@ -434,6 +446,11 @@ var customElement = (render, options) => {
|
|
434
446
|
fn();
|
435
447
|
}
|
436
448
|
}
|
449
|
+
formAssociatedCallback() {
|
450
|
+
for (const fn of this.#formAssociatedCallbackFns) {
|
451
|
+
fn();
|
452
|
+
}
|
453
|
+
}
|
437
454
|
formDisabledCallback() {
|
438
455
|
for (const fn of this.#formDisabledCallbackFns) {
|
439
456
|
fn();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "thunderous",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./dist/index.cjs",
|
@@ -30,7 +30,8 @@
|
|
30
30
|
"homepage": "https://github.com/Thunder-Solutions/Thunderous#readme",
|
31
31
|
"license": "MIT",
|
32
32
|
"scripts": {
|
33
|
-
"demo": "cd demo &&
|
33
|
+
"demo": "cd demo && npm start",
|
34
|
+
"www": "cd www && npm run dev",
|
34
35
|
"build": "tsup src/index.ts --format cjs,esm --dts --no-clean"
|
35
36
|
},
|
36
37
|
"devDependencies": {
|