thunderous 0.3.4 → 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 +27 -17
- package/dist/index.d.cts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +27 -17
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
@@ -350,24 +350,34 @@ var customElement = (render, options) => {
|
|
350
350
|
}
|
351
351
|
}
|
352
352
|
),
|
353
|
-
propSignals: new Proxy(
|
354
|
-
{
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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;
|
369
379
|
}
|
370
|
-
),
|
380
|
+
}),
|
371
381
|
refs: new Proxy(
|
372
382
|
{},
|
373
383
|
{
|
package/dist/index.d.cts
CHANGED
@@ -56,7 +56,8 @@ type ElementResult = {
|
|
56
56
|
eject: () => CustomElementConstructor;
|
57
57
|
};
|
58
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
59
|
-
type
|
59
|
+
type CustomElementProps = Record<PropertyKey, unknown>;
|
60
|
+
type RenderArgs<Props extends CustomElementProps> = {
|
60
61
|
elementRef: HTMLElement;
|
61
62
|
root: ShadowRoot | HTMLElement;
|
62
63
|
internals: ElementInternals;
|
@@ -70,7 +71,9 @@ type RenderProps = {
|
|
70
71
|
formAssociatedCallback: (fn: () => void) => void;
|
71
72
|
customCallback: (fn: () => void) => `{{callback:${string}}}`;
|
72
73
|
attrSignals: Record<string, Signal<string | null>>;
|
73
|
-
propSignals:
|
74
|
+
propSignals: {
|
75
|
+
[K in keyof Props]: Signal<Props[K]>;
|
76
|
+
};
|
74
77
|
refs: Record<string, HTMLElement | null>;
|
75
78
|
adoptStyleSheet: (stylesheet: Styles) => void;
|
76
79
|
};
|
@@ -82,7 +85,7 @@ type RenderOptions = {
|
|
82
85
|
attachShadow: boolean;
|
83
86
|
shadowRootOptions: ShadowRootInit;
|
84
87
|
};
|
85
|
-
type RenderFunction = (
|
88
|
+
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
86
89
|
/**
|
87
90
|
* Create a custom element that can be defined for use in the DOM.
|
88
91
|
* @example
|
@@ -93,7 +96,7 @@ type RenderFunction = (props: RenderProps) => DocumentFragment;
|
|
93
96
|
* MyElement.define('my-element');
|
94
97
|
* ```
|
95
98
|
*/
|
96
|
-
declare const customElement: (render: RenderFunction
|
99
|
+
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
97
100
|
type Registry = {
|
98
101
|
register: (tagName: string, element: CustomElementConstructor) => void;
|
99
102
|
getTagName: (element: CustomElementConstructor) => string | undefined;
|
@@ -110,4 +113,4 @@ type Registry = {
|
|
110
113
|
*/
|
111
114
|
declare const createRegistry: () => Registry;
|
112
115
|
|
113
|
-
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
@@ -56,7 +56,8 @@ type ElementResult = {
|
|
56
56
|
eject: () => CustomElementConstructor;
|
57
57
|
};
|
58
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
59
|
-
type
|
59
|
+
type CustomElementProps = Record<PropertyKey, unknown>;
|
60
|
+
type RenderArgs<Props extends CustomElementProps> = {
|
60
61
|
elementRef: HTMLElement;
|
61
62
|
root: ShadowRoot | HTMLElement;
|
62
63
|
internals: ElementInternals;
|
@@ -70,7 +71,9 @@ type RenderProps = {
|
|
70
71
|
formAssociatedCallback: (fn: () => void) => void;
|
71
72
|
customCallback: (fn: () => void) => `{{callback:${string}}}`;
|
72
73
|
attrSignals: Record<string, Signal<string | null>>;
|
73
|
-
propSignals:
|
74
|
+
propSignals: {
|
75
|
+
[K in keyof Props]: Signal<Props[K]>;
|
76
|
+
};
|
74
77
|
refs: Record<string, HTMLElement | null>;
|
75
78
|
adoptStyleSheet: (stylesheet: Styles) => void;
|
76
79
|
};
|
@@ -82,7 +85,7 @@ type RenderOptions = {
|
|
82
85
|
attachShadow: boolean;
|
83
86
|
shadowRootOptions: ShadowRootInit;
|
84
87
|
};
|
85
|
-
type RenderFunction = (
|
88
|
+
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
86
89
|
/**
|
87
90
|
* Create a custom element that can be defined for use in the DOM.
|
88
91
|
* @example
|
@@ -93,7 +96,7 @@ type RenderFunction = (props: RenderProps) => DocumentFragment;
|
|
93
96
|
* MyElement.define('my-element');
|
94
97
|
* ```
|
95
98
|
*/
|
96
|
-
declare const customElement: (render: RenderFunction
|
99
|
+
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
97
100
|
type Registry = {
|
98
101
|
register: (tagName: string, element: CustomElementConstructor) => void;
|
99
102
|
getTagName: (element: CustomElementConstructor) => string | undefined;
|
@@ -110,4 +113,4 @@ type Registry = {
|
|
110
113
|
*/
|
111
114
|
declare const createRegistry: () => Registry;
|
112
115
|
|
113
|
-
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
@@ -308,24 +308,34 @@ var customElement = (render, options) => {
|
|
308
308
|
}
|
309
309
|
}
|
310
310
|
),
|
311
|
-
propSignals: new Proxy(
|
312
|
-
{
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
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;
|
327
337
|
}
|
328
|
-
),
|
338
|
+
}),
|
329
339
|
refs: new Proxy(
|
330
340
|
{},
|
331
341
|
{
|
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": {
|