@ecopages/radiant 0.1.7 → 0.2.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/context/context-provider.js +3 -279
- package/dist/context/context-provider.js.map +4 -6
- package/dist/context/create-context.js +3 -6
- package/dist/context/create-context.js.map +2 -2
- package/dist/context/decorators/consume-context.d.ts +3 -3
- package/dist/context/decorators/consume-context.js +3 -64
- package/dist/context/decorators/consume-context.js.map +4 -5
- package/dist/context/decorators/context-selector.d.ts +5 -8
- package/dist/context/decorators/context-selector.js +3 -71
- package/dist/context/decorators/context-selector.js.map +4 -5
- package/dist/context/decorators/legacy/consume-context.d.ts +3 -0
- package/dist/context/decorators/legacy/consume-context.js +4 -0
- package/dist/context/decorators/legacy/consume-context.js.map +10 -0
- package/dist/context/decorators/legacy/context-selector.d.ts +4 -0
- package/dist/context/decorators/legacy/context-selector.js +4 -0
- package/dist/context/decorators/legacy/context-selector.js.map +10 -0
- package/dist/context/decorators/legacy/provide-context.d.ts +4 -0
- package/dist/context/decorators/legacy/provide-context.js +4 -0
- package/dist/context/decorators/legacy/provide-context.js.map +10 -0
- package/dist/context/decorators/provide-context.d.ts +6 -7
- package/dist/context/decorators/provide-context.js +3 -291
- package/dist/context/decorators/provide-context.js.map +4 -7
- package/dist/context/decorators/standard/consume-context.d.ts +3 -0
- package/dist/context/decorators/standard/consume-context.js +4 -0
- package/dist/context/decorators/standard/consume-context.js.map +10 -0
- package/dist/context/decorators/standard/context-selector.d.ts +4 -0
- package/dist/context/decorators/standard/context-selector.js +4 -0
- package/dist/context/decorators/standard/context-selector.js.map +10 -0
- package/dist/context/decorators/standard/provide-context.d.ts +4 -0
- package/dist/context/decorators/standard/provide-context.js +4 -0
- package/dist/context/decorators/standard/provide-context.js.map +10 -0
- package/dist/context/events.d.ts +3 -2
- package/dist/context/events.js +3 -53
- package/dist/context/events.js.map +3 -3
- package/dist/core/radiant-element.d.ts +72 -20
- package/dist/core/radiant-element.js +3 -82
- package/dist/core/radiant-element.js.map +3 -3
- package/dist/decorators/bound.d.ts +5 -0
- package/dist/decorators/bound.js +3 -0
- package/dist/decorators/bound.js.map +10 -0
- package/dist/decorators/custom-element.d.ts +3 -1
- package/dist/decorators/custom-element.js +3 -14
- package/dist/decorators/custom-element.js.map +3 -3
- package/dist/decorators/debounce.d.ts +6 -1
- package/dist/decorators/debounce.js +2 -20
- package/dist/decorators/debounce.js.map +3 -3
- package/dist/decorators/event.d.ts +3 -2
- package/dist/decorators/event.js +3 -46
- package/dist/decorators/event.js.map +4 -5
- package/dist/decorators/legacy/bound.d.ts +9 -0
- package/dist/decorators/legacy/bound.js +4 -0
- package/dist/decorators/legacy/bound.js.map +10 -0
- package/dist/decorators/legacy/custom-element.d.ts +6 -0
- package/dist/decorators/legacy/custom-element.js +4 -0
- package/dist/decorators/legacy/custom-element.js.map +10 -0
- package/dist/decorators/legacy/debounce.d.ts +1 -0
- package/dist/decorators/legacy/debounce.js +4 -0
- package/dist/decorators/legacy/debounce.js.map +10 -0
- package/dist/decorators/legacy/event.d.ts +9 -0
- package/dist/decorators/legacy/event.js +3 -0
- package/dist/decorators/legacy/event.js.map +10 -0
- package/dist/decorators/legacy/on-event.d.ts +26 -0
- package/dist/decorators/legacy/on-event.js +4 -0
- package/dist/decorators/legacy/on-event.js.map +10 -0
- package/dist/decorators/legacy/on-updated.d.ts +6 -0
- package/dist/decorators/legacy/on-updated.js +4 -0
- package/dist/decorators/legacy/on-updated.js.map +10 -0
- package/dist/decorators/legacy/query.d.ts +23 -0
- package/dist/decorators/legacy/query.js +4 -0
- package/dist/decorators/legacy/query.js.map +10 -0
- package/dist/decorators/legacy/reactive-field.d.ts +10 -0
- package/dist/decorators/legacy/reactive-field.js +4 -0
- package/dist/decorators/legacy/reactive-field.js.map +10 -0
- package/dist/decorators/legacy/reactive-prop.d.ts +19 -0
- package/dist/decorators/legacy/reactive-prop.js +4 -0
- package/dist/decorators/legacy/reactive-prop.js.map +10 -0
- package/dist/decorators/on-event.d.ts +4 -7
- package/dist/decorators/on-event.js +3 -47
- package/dist/decorators/on-event.js.map +3 -3
- package/dist/decorators/on-updated.d.ts +3 -4
- package/dist/decorators/on-updated.js +3 -29
- package/dist/decorators/on-updated.js.map +3 -3
- package/dist/decorators/query.d.ts +9 -28
- package/dist/decorators/query.js +3 -36
- package/dist/decorators/query.js.map +3 -3
- package/dist/decorators/reactive-field.d.ts +3 -7
- package/dist/decorators/reactive-field.js +3 -26
- package/dist/decorators/reactive-field.js.map +3 -3
- package/dist/decorators/reactive-prop.d.ts +4 -15
- package/dist/decorators/reactive-prop.js +3 -214
- package/dist/decorators/reactive-prop.js.map +4 -5
- package/dist/decorators/standard/bound.d.ts +2 -0
- package/dist/decorators/standard/bound.js +4 -0
- package/dist/decorators/standard/bound.js.map +10 -0
- package/dist/decorators/standard/custom-element.d.ts +1 -0
- package/dist/decorators/standard/custom-element.js +4 -0
- package/dist/decorators/standard/custom-element.js.map +10 -0
- package/dist/decorators/standard/debounce.d.ts +2 -0
- package/dist/decorators/standard/debounce.js +4 -0
- package/dist/decorators/standard/debounce.js.map +10 -0
- package/dist/decorators/standard/event.d.ts +9 -0
- package/dist/decorators/standard/event.js +4 -0
- package/dist/decorators/standard/event.js.map +10 -0
- package/dist/decorators/standard/on-event.d.ts +27 -0
- package/dist/decorators/standard/on-event.js +4 -0
- package/dist/decorators/standard/on-event.js.map +10 -0
- package/dist/decorators/standard/on-updated.d.ts +2 -0
- package/dist/decorators/standard/on-updated.js +4 -0
- package/dist/decorators/standard/on-updated.js.map +10 -0
- package/dist/decorators/standard/query.d.ts +2 -0
- package/dist/decorators/standard/query.js +4 -0
- package/dist/decorators/standard/query.js.map +10 -0
- package/dist/decorators/standard/reactive-field.d.ts +2 -0
- package/dist/decorators/standard/reactive-field.js +4 -0
- package/dist/decorators/standard/reactive-field.js.map +10 -0
- package/dist/decorators/standard/reactive-prop.d.ts +2 -0
- package/dist/decorators/standard/reactive-prop.js +4 -0
- package/dist/decorators/standard/reactive-prop.js.map +10 -0
- package/dist/index.d.ts +14 -4
- package/dist/index.js +2 -716
- package/dist/index.js.map +3 -21
- package/dist/mixins/index.js +2 -23
- package/dist/mixins/index.js.map +3 -4
- package/dist/mixins/with-kita.js +3 -23
- package/dist/mixins/with-kita.js.map +3 -3
- package/dist/tools/event-emitter.d.ts +1 -1
- package/dist/tools/event-emitter.js +3 -22
- package/dist/tools/event-emitter.js.map +3 -3
- package/dist/tools/index.js +2 -28
- package/dist/tools/index.js.map +3 -5
- package/dist/tools/stringify-typed.js +3 -8
- package/dist/tools/stringify-typed.js.map +2 -2
- package/dist/types.d.ts +79 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +10 -0
- package/dist/utils/attribute-utils.d.ts +2 -0
- package/dist/utils/attribute-utils.js +3 -137
- package/dist/utils/attribute-utils.js.map +3 -3
- package/dist/utils/index.js +2 -137
- package/dist/utils/index.js.map +3 -4
- package/package.json +26 -34
- package/dist/context/index.d.ts +0 -7
- package/dist/context/index.js +0 -338
- package/dist/context/index.js.map +0 -16
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -83
- package/dist/core/index.js.map +0 -10
- package/dist/decorators.d.ts +0 -7
- package/dist/decorators.js +0 -401
- package/dist/decorators.js.map +0 -18
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
3
|
+
"sources": ["../src/decorators/event.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { RadiantElement } from '
|
|
6
|
-
"import { EventEmitter, type EventEmitterConfig } from '@/tools/event-emitter';\n\nconst eventEmitters = new WeakMap();\n\n/**\n * Decorator that attaches an EventEmitter to the class field property.\n * The EventEmitter can be used to dispatch custom events from the target element.\n * @param eventConfig Configuration for the event emitter.\n * @see {@link EventEmitter} for more details about how the EventEmitter works.\n */\nexport function event(eventConfig: EventEmitterConfig) {\n return (target: any, propertyKey: string) => {\n if (!propertyKey) {\n throw new Error('The propertyKey is missing for the event decorator.');\n }\n\n if (!eventConfig || !eventConfig.name) {\n throw new Error('Invalid eventConfig provided.');\n }\n\n const uniqueKey = Symbol(eventConfig.name);\n\n Object.defineProperty(target, propertyKey, {\n get() {\n const emittersMap: Map<symbol, EventEmitter> = eventEmitters.get(this) || new Map();\n if (!emittersMap.has(uniqueKey)) {\n emittersMap.set(uniqueKey, new EventEmitter(this, eventConfig));\n eventEmitters.set(this, emittersMap);\n }\n\n return emittersMap.get(uniqueKey);\n },\n });\n };\n}\n"
|
|
5
|
+
"import type { RadiantElement } from '../core/radiant-element';\nimport { EventEmitter, type EventEmitterConfig } from '../tools/event-emitter';\nimport type {\n LegacyFieldDecoratorArgs,\n StandardFieldDecoratorArgs,\n StandardOrLegacyFieldDecoratorArgs,\n} from '../types';\nimport { event as legacyEvent } from './legacy/event';\nimport { event as standardEvent } from './standard/event';\n\n/**\n * Decorator that attaches an EventEmitter to the class field property.\n * The EventEmitter can be used to dispatch custom events from the target element.\n * @param eventConfig {@link EventEmitterConfig} Configuration for the event emitter.\n * @see {@link EventEmitter} for more details about how the EventEmitter works.\n */\nexport function event(eventConfig: EventEmitterConfig) {\n return function (\n protoOrTarget: StandardOrLegacyFieldDecoratorArgs['protoOrTarget'],\n nameOrContext: StandardOrLegacyFieldDecoratorArgs['nameOrContext'],\n ): any {\n if (typeof nameOrContext === 'object') {\n return standardEvent(eventConfig)(\n protoOrTarget as StandardFieldDecoratorArgs['protoOrTarget'],\n nameOrContext as StandardFieldDecoratorArgs['nameOrContext'],\n );\n }\n return legacyEvent(eventConfig)(\n protoOrTarget as LegacyFieldDecoratorArgs['protoOrTarget'],\n nameOrContext as LegacyFieldDecoratorArgs['nameOrContext'],\n );\n };\n}\n"
|
|
7
6
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
7
|
+
"mappings": "sHAgBO,GAAS,CAAK,CAAC,EAAiC,CACrD,eAAgB,CACd,EACA,EACK,CACL,UAAW,IAAkB,SAC3B,OAAO,EAAc,CAAW,EAC9B,EACA,CACF,EAEF,OAAO,EAAY,CAAW,EAC5B,EACA,CACF",
|
|
8
|
+
"debugId": "62A3A1A3C1E660BA64756E2164756E21",
|
|
10
9
|
"names": []
|
|
11
10
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RadiantElement } from '../../core/radiant-element';
|
|
2
|
+
/**
|
|
3
|
+
* A decorator to bind a method to the instance.
|
|
4
|
+
* @param target {@link RadiantElement}
|
|
5
|
+
* @param propertyKey string
|
|
6
|
+
* @param descriptor {@link PropertyDescriptor}
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function bound(target: RadiantElement, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function x(v,f,w){const j=w.value;return{configurable:!0,get(){if(this===v.prototype||Object.hasOwn(this,f))return j;const q=j.bind(this);return Object.defineProperty(this,f,{value:q,configurable:!0,writable:!0}),q}}}export{x as bound};
|
|
2
|
+
export{x as a};
|
|
3
|
+
|
|
4
|
+
//# debugId=7BFFC3AD057E7D7F64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/bound.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\n\n/**\n * A decorator to bind a method to the instance.\n * @param target {@link RadiantElement}\n * @param propertyKey string\n * @param descriptor {@link PropertyDescriptor}\n * @returns\n */\nexport function bound(target: RadiantElement, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor {\n const originalMethod = descriptor.value;\n\n return {\n configurable: true,\n get() {\n if (this === (target as any).prototype || Object.hasOwn(this, propertyKey)) {\n return originalMethod;\n }\n\n const boundMethod = originalMethod.bind(this);\n Object.defineProperty(this, propertyKey, {\n value: boundMethod,\n configurable: true,\n writable: true,\n });\n return boundMethod;\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AASO,SAAS,CAAK,CAAC,EAAwB,EAAqB,EAAoD,CACrH,MAAM,EAAiB,EAAW,MAElC,MAAO,CACL,aAAc,GACd,GAAG,EAAG,CACJ,GAAI,OAAU,EAAe,WAAa,OAAO,OAAO,KAAM,CAAW,EACvE,OAAO,EAGT,MAAM,EAAc,EAAe,KAAK,IAAI,EAM5C,OALA,OAAO,eAAe,KAAM,EAAa,CACvC,MAAO,EACP,aAAc,GACd,SAAU,EACZ,CAAC,EACM,EAEX",
|
|
8
|
+
"debugId": "7BFFC3AD057E7D7F64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a web component with the given name on the global `window.customElements` registry.
|
|
3
|
+
* @param name selector name.
|
|
4
|
+
* @param options {@link ElementDefinitionOptions}
|
|
5
|
+
*/
|
|
6
|
+
export declare function customElement(name: string, options?: ElementDefinitionOptions): (target: CustomElementConstructor) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/custom-element.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Registers a web component with the given name on the global `window.customElements` registry.\n * @param name selector name.\n * @param options {@link ElementDefinitionOptions}\n */\nexport function customElement(name: string, options?: ElementDefinitionOptions) {\n return (target: CustomElementConstructor) => {\n if (!window.customElements.get(name)) {\n window.customElements.define(name, target, options);\n }\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAKO,SAAS,CAAa,CAAC,EAAc,EAAoC,CAC9E,MAAO,CAAC,IAAqC,CAC3C,IAAK,OAAO,eAAe,IAAI,CAAI,EACjC,OAAO,eAAe,OAAO,EAAM,EAAQ,CAAO",
|
|
8
|
+
"debugId": "5E280D51F48A195B64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce(timeout: number): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/debounce.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\n\nexport function debounce(\n timeout: number,\n): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor {\n let timeoutRef: ReturnType<typeof setTimeout> | null = null;\n\n return (_target: RadiantElement, _propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor => {\n const originalMethod = descriptor.value;\n\n descriptor.value = function debounce(...args: any[]) {\n if (timeoutRef !== null) {\n clearTimeout(timeoutRef);\n }\n\n timeoutRef = setTimeout(() => {\n originalMethod.apply(this, args);\n }, timeout);\n };\n\n return descriptor;\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAEO,SAAS,CAAQ,CACtB,EAC0F,CAC1F,IAAI,EAAmD,KAEvD,MAAO,CAAC,EAAyB,EAAsB,IAAuD,CAC5G,MAAM,EAAiB,EAAW,MAYlC,OAVA,EAAW,eAAiB,CAAQ,IAAI,EAAa,CACnD,GAAI,IAAe,KACjB,aAAa,CAAU,EAGzB,EAAa,WAAW,IAAM,CAC5B,EAAe,MAAM,KAAM,CAAI,GAC9B,CAAO,GAGL",
|
|
8
|
+
"debugId": "DBCB7592DFBF05B764756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RadiantElement } from '../../core/radiant-element';
|
|
2
|
+
import { type EventEmitterConfig } from '../../tools/event-emitter';
|
|
3
|
+
/**
|
|
4
|
+
* Decorator that attaches an EventEmitter to the class field property.
|
|
5
|
+
* The EventEmitter can be used to dispatch custom events from the target element.
|
|
6
|
+
* @param eventConfig Configuration for the event emitter.
|
|
7
|
+
* @see {@link EventEmitter} for more details about how the EventEmitter works.
|
|
8
|
+
*/
|
|
9
|
+
export declare function event(eventConfig: EventEmitterConfig): (proto: RadiantElement, propertyKey: string) => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{U as x}from"../../tools/event-emitter.js";function F(j){return(q,z)=>{const A=q.connectedCallback;q.connectedCallback=function(){this.registerEventEmitter(j.name,new x(this,j)),Object.defineProperty(this,z,{get(){return this.eventEmitters.get(j.name)},enumerable:!0,configurable:!0}),A.call(this)}}}export{F as event};export{F as S};
|
|
2
|
+
|
|
3
|
+
//# debugId=E179404ACF9F267A64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/event.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\nimport { EventEmitter, type EventEmitterConfig } from '../../tools/event-emitter';\n\nconst eventEmitters = new WeakMap();\n\n/**\n * Decorator that attaches an EventEmitter to the class field property.\n * The EventEmitter can be used to dispatch custom events from the target element.\n * @param eventConfig Configuration for the event emitter.\n * @see {@link EventEmitter} for more details about how the EventEmitter works.\n */\nexport function event(eventConfig: EventEmitterConfig) {\n return (proto: RadiantElement, propertyKey: string) => {\n const originalConnectedCallback = proto.connectedCallback;\n proto.connectedCallback = function () {\n this.registerEventEmitter(eventConfig.name, new EventEmitter(this, eventConfig));\n\n Object.defineProperty(this, propertyKey, {\n get() {\n return this.eventEmitters.get(eventConfig.name);\n },\n enumerable: true,\n configurable: true,\n });\n originalConnectedCallback.call(this);\n };\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "iDAWO,SAAS,CAAK,CAAC,EAAiC,CACrD,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAA4B,EAAM,kBACxC,EAAM,0BAA6B,EAAG,CACpC,KAAK,qBAAqB,EAAY,KAAM,IAAI,EAAa,KAAM,CAAW,CAAC,EAE/E,OAAO,eAAe,KAAM,EAAa,CACvC,GAAG,EAAG,CACJ,OAAO,KAAK,cAAc,IAAI,EAAY,IAAI,GAEhD,WAAY,GACZ,aAAc,EAChB,CAAC,EACD,EAA0B,KAAK,IAAI",
|
|
8
|
+
"debugId": "E179404ACF9F267A64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RadiantElement, RadiantElementEventListener } from '../../core/radiant-element';
|
|
2
|
+
type OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> & ({
|
|
3
|
+
selector: string;
|
|
4
|
+
} | {
|
|
5
|
+
ref: string;
|
|
6
|
+
} | {
|
|
7
|
+
window: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
document: boolean;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* A decorator to subscribe to an event on the target element.
|
|
13
|
+
* The event listener will be automatically unsubscribed when the element is disconnected.
|
|
14
|
+
*
|
|
15
|
+
* Note: This decorator uses event delegation, which means it relies on event bubbling.
|
|
16
|
+
* Therefore, it will not work with events that do not bubble, such as `focus`, `blur`, `load`, `unload`, `scroll`, etc.
|
|
17
|
+
* For focus and blur events, consider using `focusin` and `focusout` which are similar but do bubble.
|
|
18
|
+
*
|
|
19
|
+
* @param eventConfig The event configuration.
|
|
20
|
+
* @param eventConfig.selectors The CSS selector(s) of the target element(s).
|
|
21
|
+
* @param eventConfig.ref The data-ref attribute of the target element.
|
|
22
|
+
* @param eventConfig.type The type of the event to listen for.
|
|
23
|
+
* @param eventConfig.options Optional. An options object that specifies characteristics about the event listener.
|
|
24
|
+
*/
|
|
25
|
+
export declare function onEvent(eventConfig: OnEventConfig): (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function J(q){return(z,I,x)=>{const{connectedCallback:B,disconnectedCallback:E}=z;if("window"in q)return z.connectedCallback=function(){window.addEventListener(q.type,x.value.bind(this),q.options),B.call(this)},z.disconnectedCallback=function(){window.removeEventListener(q.type,x.value.bind(this),q.options),E.call(this)},x;if("document"in q)return z.connectedCallback=function(){document.addEventListener(q.type,x.value.bind(this),q.options),B.call(this)},z.disconnectedCallback=function(){document.removeEventListener(q.type,x.value.bind(this),q.options),E.call(this)},x;const G="selector"in q?q.selector:`[data-ref="${q.ref}"]`,H=x.value;return z.connectedCallback=function(){this.subscribeEvent({selector:G,type:q.type,listener:H.bind(this),options:q?.options??void 0}),B.call(this)},x}}export{J as onEvent};
|
|
2
|
+
export{J as P};
|
|
3
|
+
|
|
4
|
+
//# debugId=8E819BD7790B062364756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/on-event.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement, RadiantElementEventListener } from '../../core/radiant-element';\n\ntype OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> &\n (\n | {\n selector: string;\n }\n | {\n ref: string;\n }\n | {\n window: boolean;\n }\n | {\n document: boolean;\n }\n );\n\n/**\n * A decorator to subscribe to an event on the target element.\n * The event listener will be automatically unsubscribed when the element is disconnected.\n *\n * Note: This decorator uses event delegation, which means it relies on event bubbling.\n * Therefore, it will not work with events that do not bubble, such as `focus`, `blur`, `load`, `unload`, `scroll`, etc.\n * For focus and blur events, consider using `focusin` and `focusout` which are similar but do bubble.\n *\n * @param eventConfig The event configuration.\n * @param eventConfig.selectors The CSS selector(s) of the target element(s).\n * @param eventConfig.ref The data-ref attribute of the target element.\n * @param eventConfig.type The type of the event to listen for.\n * @param eventConfig.options Optional. An options object that specifies characteristics about the event listener.\n */\nexport function onEvent(eventConfig: OnEventConfig) {\n return (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => {\n const originalConnectedCallback = proto.connectedCallback;\n const originalDisconnectedCallback = proto.disconnectedCallback;\n\n if ('window' in eventConfig) {\n proto.connectedCallback = function (this: RadiantElement) {\n window.addEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalConnectedCallback.call(this);\n };\n\n proto.disconnectedCallback = function (this: RadiantElement) {\n window.removeEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalDisconnectedCallback.call(this);\n };\n\n return descriptor;\n }\n\n if ('document' in eventConfig) {\n proto.connectedCallback = function (this: RadiantElement) {\n document.addEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalConnectedCallback.call(this);\n };\n\n proto.disconnectedCallback = function (this: RadiantElement) {\n document.removeEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalDisconnectedCallback.call(this);\n };\n\n return descriptor;\n }\n\n const selector = 'selector' in eventConfig ? eventConfig.selector : `[data-ref=\"${eventConfig.ref}\"]`;\n\n const originalMethod = descriptor.value;\n\n proto.connectedCallback = function (this: RadiantElement) {\n this.subscribeEvent({\n selector: selector,\n type: eventConfig.type,\n listener: originalMethod.bind(this),\n options: eventConfig?.options ?? undefined,\n });\n\n originalConnectedCallback.call(this);\n };\n\n return descriptor;\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAgCO,SAAS,CAAO,CAAC,EAA4B,CAClD,MAAO,CAAC,EAAuB,EAAW,IAAmC,CAC3E,MAAwC,kBAAlC,EACqC,qBAArC,GAA+B,EAErC,GAAI,WAAY,EAWd,OAVA,EAAM,0BAA6B,EAAuB,CACxD,OAAO,iBAAiB,EAAY,KAAM,EAAW,MAAM,KAAK,IAAI,EAAG,EAAY,OAAO,EAC1F,EAA0B,KAAK,IAAI,GAGrC,EAAM,6BAAgC,EAAuB,CAC3D,OAAO,oBAAoB,EAAY,KAAM,EAAW,MAAM,KAAK,IAAI,EAAG,EAAY,OAAO,EAC7F,EAA6B,KAAK,IAAI,GAGjC,EAGT,GAAI,aAAc,EAWhB,OAVA,EAAM,0BAA6B,EAAuB,CACxD,SAAS,iBAAiB,EAAY,KAAM,EAAW,MAAM,KAAK,IAAI,EAAG,EAAY,OAAO,EAC5F,EAA0B,KAAK,IAAI,GAGrC,EAAM,6BAAgC,EAAuB,CAC3D,SAAS,oBAAoB,EAAY,KAAM,EAAW,MAAM,KAAK,IAAI,EAAG,EAAY,OAAO,EAC/F,EAA6B,KAAK,IAAI,GAGjC,EAGT,MAAM,EAAW,aAAc,EAAc,EAAY,SAAW,cAAc,EAAY,QAExF,EAAiB,EAAW,MAalC,OAXA,EAAM,0BAA6B,EAAuB,CACxD,KAAK,eAAe,CAClB,SAAU,EACV,KAAM,EAAY,KAClB,SAAU,EAAe,KAAK,IAAI,EAClC,QAAS,GAAa,SAAW,MACnC,CAAC,EAED,EAA0B,KAAK,IAAI,GAG9B",
|
|
8
|
+
"debugId": "8E819BD7790B062364756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RadiantElement } from '../../core/radiant-element';
|
|
2
|
+
/**
|
|
3
|
+
* A decorator to subscribe to an updated callback when a reactive field or property changes.
|
|
4
|
+
* @param eventConfig The event configuration.
|
|
5
|
+
*/
|
|
6
|
+
export declare function onUpdated(keyOrKeys: string | string[]): (target: RadiantElement, methodName: string) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function E(j){return(q,z)=>{const B=q.connectedCallback;q.connectedCallback=function(){const x=this[z].bind(this);if(Array.isArray(j))for(let D of j)this.registerUpdateCallback(D,x);else if(typeof j==="string")this.registerUpdateCallback(j,x);B.call(this)}}}export{E as onUpdated};
|
|
2
|
+
export{E as W};
|
|
3
|
+
|
|
4
|
+
//# debugId=2219BCA8CDC27CB464756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/on-updated.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\n\n/**\n * A decorator to subscribe to an updated callback when a reactive field or property changes.\n * @param eventConfig The event configuration.\n */\nexport function onUpdated(keyOrKeys: string | string[]) {\n return (target: RadiantElement, methodName: string) => {\n const originalConnectedCallback = target.connectedCallback;\n\n target.connectedCallback = function (this: RadiantElement) {\n const boundedMethod = (this as any)[methodName].bind(this);\n if (Array.isArray(keyOrKeys)) {\n for (const key of keyOrKeys) {\n (this as RadiantElement).registerUpdateCallback(key, boundedMethod);\n }\n } else if (typeof keyOrKeys === 'string') {\n (this as RadiantElement).registerUpdateCallback(keyOrKeys, boundedMethod);\n }\n originalConnectedCallback.call(this);\n };\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAMO,SAAS,CAAS,CAAC,EAA8B,CACtD,MAAO,CAAC,EAAwB,IAAuB,CACrD,MAAM,EAA4B,EAAO,kBAEzC,EAAO,0BAA6B,EAAuB,CACzD,MAAM,EAAiB,KAAa,GAAY,KAAK,IAAI,EACzD,GAAI,MAAM,QAAQ,CAAS,EACzB,QAAW,KAAO,EAChB,AAAC,KAAwB,uBAAuB,EAAK,CAAa,iBAEpD,IAAc,SAC9B,AAAC,KAAwB,uBAAuB,EAAW,CAAa,EAE1E,EAA0B,KAAK,IAAI",
|
|
8
|
+
"debugId": "2219BCA8CDC27CB464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RadiantElement } from '../../core/radiant-element';
|
|
2
|
+
import type { QueryConfig } from '../query';
|
|
3
|
+
/**
|
|
4
|
+
* A decorator to query by CSS selector or data-ref attribute.
|
|
5
|
+
* By default it queries for the first element that matches the selector, but it can be configured to query for all elements.
|
|
6
|
+
*
|
|
7
|
+
* @param {QueryConfig} options - The configuration object for the query.
|
|
8
|
+
* @param {boolean} [options.all] - A flag to query for all elements that match the selector. Defaults to `false`.
|
|
9
|
+
* @param {boolean} [options.cache] - A flag to cache the query result. Defaults to `true`.
|
|
10
|
+
* @param {string} [options.selector] - A CSS selector to match elements against. This property is mutually exclusive with `options.ref`.
|
|
11
|
+
* @param {string} [options.ref] - A reference to an element. This property is mutually exclusive with `options.selector`.
|
|
12
|
+
*
|
|
13
|
+
* @returns {Function} A decorator function that, when applied to a class property, will replace it with a getter. The getter will return the result of the query when accessed.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* class MyElement extends HTMLElement {
|
|
17
|
+
* @query({ selector: '.my-class' })
|
|
18
|
+
* myElement;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // Now, `myElement` will return the first element in the light DOM of `MyElement` that matches the selector '.my-class'.
|
|
22
|
+
*/
|
|
23
|
+
export declare function query<T extends Element | Element[]>({ cache: shouldBeCached, ...options }: QueryConfig): (proto: RadiantElement, propertyName: string | symbol) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function _({cache:Y=!0,...z}){return(I,J)=>{const G=Symbol(`__${String(J)}__cache`),R="selector"in z?z.selector:`[data-ref="${z.ref}"]`,U=(V)=>{let W=[];if(z?.all){const X=V.querySelectorAll(R);return W=X.length?Array.from(X):[],W}return V.querySelector(R)},Z=I.connectedCallback;I.connectedCallback=function(){Object.defineProperty(this,J,{get(){if(Y){if(!this[G]||z?.all&&!this[G].length)this[G]=U(this);return this[G]}return U(this)},enumerable:!0,configurable:!0}),Z.call(this)}}}export{_ as query};
|
|
2
|
+
export{_ as u};
|
|
3
|
+
|
|
4
|
+
//# debugId=DCAE23F5E699731A64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/query.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\nimport type { QueryConfig } from '../query';\n\n/**\n * A decorator to query by CSS selector or data-ref attribute.\n * By default it queries for the first element that matches the selector, but it can be configured to query for all elements.\n *\n * @param {QueryConfig} options - The configuration object for the query.\n * @param {boolean} [options.all] - A flag to query for all elements that match the selector. Defaults to `false`.\n * @param {boolean} [options.cache] - A flag to cache the query result. Defaults to `true`.\n * @param {string} [options.selector] - A CSS selector to match elements against. This property is mutually exclusive with `options.ref`.\n * @param {string} [options.ref] - A reference to an element. This property is mutually exclusive with `options.selector`.\n *\n * @returns {Function} A decorator function that, when applied to a class property, will replace it with a getter. The getter will return the result of the query when accessed.\n *\n * @example\n * class MyElement extends HTMLElement {\n * @query({ selector: '.my-class' })\n * myElement;\n * }\n *\n * // Now, `myElement` will return the first element in the light DOM of `MyElement` that matches the selector '.my-class'.\n */\nexport function query<T extends Element | Element[]>({\n cache: shouldBeCached = true,\n ...options\n}: QueryConfig): (proto: RadiantElement, propertyName: string | symbol) => void {\n return (proto: RadiantElement, propertyKey: string | symbol) => {\n const privatePropertyKey = Symbol(`__${String(propertyKey)}__cache`);\n\n const selector = 'selector' in options ? options.selector : `[data-ref=\"${options.ref}\"]`;\n\n const executeQuery = (instance: RadiantElement) => {\n let result: T | T[] = [];\n if (options?.all) {\n const queried = instance.querySelectorAll(selector);\n result = queried.length ? (Array.from(queried) as T) : [];\n return result;\n }\n\n return instance.querySelector(selector);\n };\n\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n Object.defineProperty(this, propertyKey, {\n get() {\n if (shouldBeCached) {\n if (!this[privatePropertyKey] || (options?.all && !this[privatePropertyKey].length)) {\n this[privatePropertyKey] = executeQuery(this);\n }\n return this[privatePropertyKey];\n }\n return executeQuery(this) as T;\n },\n enumerable: true,\n configurable: true,\n });\n originalConnectedCallback.call(this);\n };\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAuBO,SAAS,CAAoC,EAClD,MAAO,EAAiB,MACrB,GAC2E,CAC9E,MAAO,CAAC,EAAuB,IAAiC,CAC9D,MAAM,EAAqB,OAAO,KAAK,OAAO,CAAW,UAAU,EAE7D,EAAW,aAAc,EAAU,EAAQ,SAAW,cAAc,EAAQ,QAE5E,EAAe,CAAC,IAA6B,CACjD,IAAI,EAAkB,CAAC,EACvB,GAAI,GAAS,IAAK,CAChB,MAAM,EAAU,EAAS,iBAAiB,CAAQ,EAElD,OADA,EAAS,EAAQ,OAAU,MAAM,KAAK,CAAO,EAAU,CAAC,EACjD,EAGT,OAAO,EAAS,cAAc,CAAQ,GAGlC,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,OAAO,eAAe,KAAM,EAAa,CACvC,GAAG,EAAG,CACJ,GAAI,EAAgB,CAClB,IAAK,KAAK,IAAwB,GAAS,MAAQ,KAAK,GAAoB,OAC1E,KAAK,GAAsB,EAAa,IAAI,EAE9C,OAAO,KAAK,GAEd,OAAO,EAAa,IAAI,GAE1B,WAAY,GACZ,aAAc,EAChB,CAAC,EACD,EAA0B,KAAK,IAAI",
|
|
8
|
+
"debugId": "DCAE23F5E699731A64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RadiantElement } from '../../core/radiant-element';
|
|
2
|
+
/**
|
|
3
|
+
* A decorator to define a reactive field.
|
|
4
|
+
* Every time the property changes, the `updated` method will be called.
|
|
5
|
+
* Due the fact the value is always undefined before the first update,
|
|
6
|
+
* we are adding a `isDefined` WeakSet to track if the property has been defined.
|
|
7
|
+
* @param target The target element.
|
|
8
|
+
* @param propertyKey The property key.
|
|
9
|
+
*/
|
|
10
|
+
export declare function reactiveField(target: RadiantElement, propertyKey: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/reactive-field.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\n\n/**\n * A decorator to define a reactive field.\n * Every time the property changes, the `updated` method will be called.\n * Due the fact the value is always undefined before the first update,\n * we are adding a `isDefined` WeakSet to track if the property has been defined.\n * @param target The target element.\n * @param propertyKey The property key.\n */\nexport function reactiveField(target: RadiantElement, propertyKey: string) {\n const originalConnectedCallback = target.connectedCallback;\n\n target.connectedCallback = function (this: RadiantElement) {\n this.createReactiveField(propertyKey, this[propertyKey as keyof typeof this]);\n originalConnectedCallback.call(this);\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAUO,SAAS,CAAa,CAAC,EAAwB,EAAqB,CACzE,MAAM,EAA4B,EAAO,kBAEzC,EAAO,0BAA6B,EAAuB,CACzD,KAAK,oBAAoB,EAAa,KAAK,EAAiC,EAC5E,EAA0B,KAAK,IAAI",
|
|
8
|
+
"debugId": "B28B1690767276A564756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RadiantElement } from '../../core/radiant-element';
|
|
2
|
+
import { type AttributeTypeConstant } from '../../utils/attribute-utils';
|
|
3
|
+
type ReactivePropertyOptions<T> = {
|
|
4
|
+
type: AttributeTypeConstant;
|
|
5
|
+
reflect?: boolean;
|
|
6
|
+
attribute?: string;
|
|
7
|
+
defaultValue?: T;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A decorator to define a reactive property.
|
|
11
|
+
* Every time the property changes, the `updated` method will be called.
|
|
12
|
+
* @param options The options for the reactive property.
|
|
13
|
+
* @param options.type The type of the property value.
|
|
14
|
+
* @param options.reflect Whether to reflect the property to the attribute.
|
|
15
|
+
* @param options.attribute The name of the attribute.
|
|
16
|
+
* @param options.defaultValue The default value of the property.
|
|
17
|
+
*/
|
|
18
|
+
export declare function reactiveProp<T = unknown>({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions<T>): (target: RadiantElement, propertyName: string) => void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{L as B}from"../../utils/attribute-utils.js";function J({type:j,attribute:D,reflect:F,defaultValue:q}){if(q!==void 0&&!B(j,q))throw new Error(`defaultValue does not match the expected type for ${j.name}`);return(x,z)=>{const G=D??z,H=x.connectedCallback;x.connectedCallback=function(){H.call(this),this.createReactiveProp(z,{type:j,reflect:F,attribute:G,defaultValue:q})}}}export{J as reactiveProp};
|
|
2
|
+
export{J as F};
|
|
3
|
+
|
|
4
|
+
//# debugId=C3ADC88FB8E83F1D64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/legacy/reactive-prop.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '../../core/radiant-element';\nimport { type AttributeTypeConstant, isValueOfType } from '../../utils/attribute-utils';\n\ntype ReactivePropertyOptions<T> = {\n type: AttributeTypeConstant;\n reflect?: boolean;\n attribute?: string;\n defaultValue?: T;\n};\n\n/**\n * A decorator to define a reactive property.\n * Every time the property changes, the `updated` method will be called.\n * @param options The options for the reactive property.\n * @param options.type The type of the property value.\n * @param options.reflect Whether to reflect the property to the attribute.\n * @param options.attribute The name of the attribute.\n * @param options.defaultValue The default value of the property.\n */\nexport function reactiveProp<T = unknown>({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions<T>) {\n if (defaultValue !== undefined && !isValueOfType(type, defaultValue)) {\n throw new Error(`defaultValue does not match the expected type for ${type.name}`);\n }\n\n return (target: RadiantElement, propertyName: string) => {\n const attributeKey = attribute ?? propertyName;\n\n const originalConnectedCallback = target.connectedCallback;\n\n target.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n this.createReactiveProp(propertyName, {\n type,\n reflect,\n attribute: attributeKey,\n defaultValue,\n });\n };\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "mDAmBO,SAAS,CAAyB,EAAG,OAAM,YAAW,UAAS,gBAA4C,CAChH,GAAI,IAAiB,SAAc,EAAc,EAAM,CAAY,EACjE,MAAM,IAAI,MAAM,qDAAqD,EAAK,MAAM,EAGlF,MAAO,CAAC,EAAwB,IAAyB,CACvD,MAAM,EAAe,GAAa,EAE5B,EAA4B,EAAO,kBAEzC,EAAO,0BAA6B,EAAuB,CACzD,EAA0B,KAAK,IAAI,EACnC,KAAK,mBAAmB,EAAc,CACpC,OACA,UACA,UAAW,EACX,cACF,CAAC",
|
|
8
|
+
"debugId": "C3ADC88FB8E83F1D64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RadiantElementEventListener } from '../core/radiant-element';
|
|
2
|
+
import type { StandardOrLegacyMethodDecoratorArgs } from '../types';
|
|
2
3
|
type OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> & ({
|
|
3
4
|
selector: string;
|
|
4
5
|
} | {
|
|
@@ -16,11 +17,7 @@ type OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> & ({
|
|
|
16
17
|
* Therefore, it will not work with events that do not bubble, such as `focus`, `blur`, `load`, `unload`, `scroll`, etc.
|
|
17
18
|
* For focus and blur events, consider using `focusin` and `focusout` which are similar but do bubble.
|
|
18
19
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param eventConfig.selectors The CSS selector(s) of the target element(s).
|
|
21
|
-
* @param eventConfig.ref The data-ref attribute of the target element.
|
|
22
|
-
* @param eventConfig.type The type of the event to listen for.
|
|
23
|
-
* @param eventConfig.options Optional. An options object that specifies characteristics about the event listener.
|
|
20
|
+
* @param options {@link OnEventConfig} The event configuration.
|
|
24
21
|
*/
|
|
25
|
-
export declare function onEvent(
|
|
22
|
+
export declare function onEvent(options: OnEventConfig): (protoOrTarget: StandardOrLegacyMethodDecoratorArgs["protoOrTarget"], nameOrContext: StandardOrLegacyMethodDecoratorArgs["nameOrContext"], descriptor?: StandardOrLegacyMethodDecoratorArgs["descriptor"]) => any;
|
|
26
23
|
export {};
|
|
@@ -1,48 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (proto, _, descriptor) => {
|
|
4
|
-
const originalConnectedCallback = proto.connectedCallback;
|
|
5
|
-
const originalDisconnectedCallback = proto.disconnectedCallback;
|
|
6
|
-
if ("window" in eventConfig) {
|
|
7
|
-
proto.connectedCallback = function() {
|
|
8
|
-
window.addEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);
|
|
9
|
-
originalConnectedCallback.call(this);
|
|
10
|
-
};
|
|
11
|
-
proto.disconnectedCallback = function() {
|
|
12
|
-
window.removeEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);
|
|
13
|
-
originalDisconnectedCallback.call(this);
|
|
14
|
-
};
|
|
15
|
-
return descriptor;
|
|
16
|
-
}
|
|
17
|
-
if ("document" in eventConfig) {
|
|
18
|
-
proto.connectedCallback = function() {
|
|
19
|
-
document.addEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);
|
|
20
|
-
originalConnectedCallback.call(this);
|
|
21
|
-
};
|
|
22
|
-
proto.disconnectedCallback = function() {
|
|
23
|
-
document.removeEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);
|
|
24
|
-
originalDisconnectedCallback.call(this);
|
|
25
|
-
};
|
|
26
|
-
return descriptor;
|
|
27
|
-
}
|
|
28
|
-
const selector = "selector" in eventConfig ? eventConfig.selector : `[data-ref="${eventConfig.ref}"]`;
|
|
29
|
-
const originalMethod = descriptor.value;
|
|
30
|
-
const subscriptionId = `${eventConfig.type}-${selector}`;
|
|
31
|
-
proto.connectedCallback = function() {
|
|
32
|
-
this.subscribeEvent({
|
|
33
|
-
id: subscriptionId,
|
|
34
|
-
selector,
|
|
35
|
-
type: eventConfig.type,
|
|
36
|
-
listener: originalMethod.bind(this),
|
|
37
|
-
options: eventConfig?.options ?? undefined
|
|
38
|
-
});
|
|
39
|
-
originalConnectedCallback.call(this);
|
|
40
|
-
};
|
|
41
|
-
return descriptor;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
onEvent
|
|
46
|
-
};
|
|
1
|
+
import{P as B}from"./legacy/on-event.js";import{Q as D}from"./standard/on-event.js";function J(q){return function(z,j,G){if(typeof j==="object")return D(q)(z,j);return B(q)(z,j,G)}}export{J as onEvent};
|
|
2
|
+
export{J as O};
|
|
47
3
|
|
|
48
|
-
//# debugId=
|
|
4
|
+
//# debugId=EC8F79E3191830C064756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/decorators/on-event.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type {
|
|
5
|
+
"import type { RadiantElementEventListener } from '../core/radiant-element';\nimport type {\n LegacyMethodDecoratorArgs,\n StandardMethodDecoratorArgs,\n StandardOrLegacyMethodDecoratorArgs,\n} from '../types';\nimport { onEvent as legacyOnEvent } from './legacy/on-event';\nimport { onEvent as standardOnEvent } from './standard/on-event';\n\ntype OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> &\n (\n | {\n selector: string;\n }\n | {\n ref: string;\n }\n | {\n window: boolean;\n }\n | {\n document: boolean;\n }\n );\n\n/**\n * A decorator to subscribe to an event on the target element.\n * The event listener will be automatically unsubscribed when the element is disconnected.\n *\n * Note: This decorator uses event delegation, which means it relies on event bubbling.\n * Therefore, it will not work with events that do not bubble, such as `focus`, `blur`, `load`, `unload`, `scroll`, etc.\n * For focus and blur events, consider using `focusin` and `focusout` which are similar but do bubble.\n *\n * @param options {@link OnEventConfig} The event configuration.\n */\nexport function onEvent(options: OnEventConfig) {\n return function (\n protoOrTarget: StandardOrLegacyMethodDecoratorArgs['protoOrTarget'],\n nameOrContext: StandardOrLegacyMethodDecoratorArgs['nameOrContext'],\n descriptor?: StandardOrLegacyMethodDecoratorArgs['descriptor'],\n ): any {\n if (typeof nameOrContext === 'object') {\n return standardOnEvent(options)(\n protoOrTarget as StandardMethodDecoratorArgs['protoOrTarget'],\n nameOrContext as StandardMethodDecoratorArgs['nameOrContext'],\n );\n }\n return legacyOnEvent(options)(\n protoOrTarget as LegacyMethodDecoratorArgs['protoOrTarget'],\n nameOrContext as LegacyMethodDecoratorArgs['nameOrContext'],\n descriptor as LegacyMethodDecoratorArgs['descriptor'],\n );\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "uFAmCO,MAAS,CAAO,CAAC,EAAwB,CAC9C,eAAgB,CACd,EACA,EACA,EACK,CACL,UAAW,IAAkB,SAC3B,OAAO,EAAgB,CAAO,EAC5B,EACA,CACF,EAEF,OAAO,EAAc,CAAO,EAC1B,EACA,EACA,CACF",
|
|
8
|
+
"debugId": "EC8F79E3191830C064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StandardOrLegacyMethodDecoratorArgs } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* A decorator to
|
|
4
|
-
* @param eventConfig The event configuration.
|
|
3
|
+
* A decorator to bind a method to the instance.
|
|
5
4
|
*/
|
|
6
|
-
export declare function onUpdated(keyOrKeys: string | string[]): (
|
|
5
|
+
export declare function onUpdated(keyOrKeys: string | string[]): (protoOrTarget: StandardOrLegacyMethodDecoratorArgs["protoOrTarget"], nameOrContext: StandardOrLegacyMethodDecoratorArgs["nameOrContext"], descriptor?: StandardOrLegacyMethodDecoratorArgs["descriptor"]) => any;
|
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (proto, methodName) => {
|
|
4
|
-
if (!("updatesRegistry" in proto)) {
|
|
5
|
-
Object.defineProperty(proto, "updatesRegistry", {
|
|
6
|
-
value: new Map,
|
|
7
|
-
configurable: true
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
const updatesRegistry = proto.updatesRegistry;
|
|
11
|
-
if (Array.isArray(keyOrKeys)) {
|
|
12
|
-
for (const key of keyOrKeys) {
|
|
13
|
-
if (!updatesRegistry.has(key)) {
|
|
14
|
-
updatesRegistry.set(key, new Set);
|
|
15
|
-
}
|
|
16
|
-
updatesRegistry.get(key)?.add(methodName);
|
|
17
|
-
}
|
|
18
|
-
} else if (typeof keyOrKeys === "string") {
|
|
19
|
-
if (!updatesRegistry.has(keyOrKeys)) {
|
|
20
|
-
updatesRegistry.set(keyOrKeys, new Set);
|
|
21
|
-
}
|
|
22
|
-
updatesRegistry.get(keyOrKeys)?.add(methodName);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
onUpdated
|
|
28
|
-
};
|
|
1
|
+
import{W as v}from"./legacy/on-updated.js";import{X as w}from"./standard/on-updated.js";function E(j){return function(q,f,z){if(typeof f==="object")return w(j)(q,f);return v(j)(q,f)}}export{E as onUpdated};
|
|
2
|
+
export{E as V};
|
|
29
3
|
|
|
30
|
-
//# debugId=
|
|
4
|
+
//# debugId=D7596CDDF700FE1B64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/decorators/on-updated.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type {
|
|
5
|
+
"import type {\n LegacyMethodDecoratorArgs,\n StandardMethodDecoratorArgs,\n StandardOrLegacyMethodDecoratorArgs,\n} from '../types';\nimport { onUpdated as legacyOnUpdated } from './legacy/on-updated';\nimport { onUpdated as standardOnUpdated } from './standard/on-updated';\n\n/**\n * A decorator to bind a method to the instance.\n */\nexport function onUpdated(keyOrKeys: string | string[]) {\n return function (\n protoOrTarget: StandardOrLegacyMethodDecoratorArgs['protoOrTarget'],\n nameOrContext: StandardOrLegacyMethodDecoratorArgs['nameOrContext'],\n descriptor?: StandardOrLegacyMethodDecoratorArgs['descriptor'],\n ): any {\n if (typeof nameOrContext === 'object') {\n return standardOnUpdated(keyOrKeys)(\n protoOrTarget as StandardMethodDecoratorArgs['protoOrTarget'],\n nameOrContext as StandardMethodDecoratorArgs['nameOrContext'],\n );\n }\n return legacyOnUpdated(keyOrKeys)(\n protoOrTarget as LegacyMethodDecoratorArgs['protoOrTarget'],\n nameOrContext as LegacyMethodDecoratorArgs['nameOrContext'],\n );\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "yFAWO,QAAS,CAAS,CAAC,EAA8B,CACtD,eAAgB,CACd,EACA,EACA,EACK,CACL,UAAW,IAAkB,SAC3B,OAAO,EAAkB,CAAS,EAChC,EACA,CACF,EAEF,OAAO,EAAgB,CAAS,EAC9B,EACA,CACF",
|
|
8
|
+
"debugId": "D7596CDDF700FE1B64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,39 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* The base configuration object for the query.
|
|
4
|
-
*/
|
|
1
|
+
import type { StandardOrLegacyFieldDecoratorArgs } from '../types';
|
|
5
2
|
type BaseQueryConfig = {
|
|
6
3
|
all?: boolean;
|
|
7
4
|
cache?: boolean;
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
* The configuration object for the query.
|
|
11
|
-
* It can be configured to query by CSS selector or data-ref attribute.
|
|
12
|
-
*/
|
|
13
|
-
export type QueryConfig = BaseQueryConfig & ({
|
|
6
|
+
type QueryBySelector = {
|
|
14
7
|
selector: string;
|
|
15
|
-
}
|
|
8
|
+
};
|
|
9
|
+
type QueryByRef = {
|
|
16
10
|
ref: string;
|
|
17
|
-
}
|
|
11
|
+
};
|
|
12
|
+
export type QueryConfig = BaseQueryConfig & (QueryBySelector | QueryByRef);
|
|
18
13
|
/**
|
|
19
14
|
* A decorator to query by CSS selector or data-ref attribute.
|
|
20
15
|
* By default it queries for the first element that matches the selector, but it can be configured to query for all elements.
|
|
21
|
-
*
|
|
22
|
-
* @param {QueryConfig}
|
|
23
|
-
* @param {boolean} [options.all] - A flag to query for all elements that match the selector. Defaults to `false`.
|
|
24
|
-
* @param {boolean} [options.cache] - A flag to cache the query result. Defaults to `true`.
|
|
25
|
-
* @param {string} [options.selector] - A CSS selector to match elements against. This property is mutually exclusive with `options.ref`.
|
|
26
|
-
* @param {string} [options.ref] - A reference to an element. This property is mutually exclusive with `options.selector`.
|
|
27
|
-
*
|
|
28
|
-
* @returns {Function} A decorator function that, when applied to a class property, will replace it with a getter. The getter will return the result of the query when accessed.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* class MyElement extends HTMLElement {
|
|
32
|
-
* @query({ selector: '.my-class' })
|
|
33
|
-
* myElement;
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* // Now, `myElement` will return the first element in the light DOM of `MyElement` that matches the selector '.my-class'.
|
|
16
|
+
* It cache the result by default, but it can be configured to not cache it.
|
|
17
|
+
* @param options {@link QueryConfig} The options for the reactive property.
|
|
37
18
|
*/
|
|
38
|
-
export declare function query
|
|
19
|
+
export declare function query<T extends Element | Element[]>(options: QueryConfig): (protoOrTarget: StandardOrLegacyFieldDecoratorArgs["protoOrTarget"], nameOrContext: StandardOrLegacyFieldDecoratorArgs["nameOrContext"]) => any;
|
|
39
20
|
export {};
|
package/dist/decorators/query.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
cache: shouldBeCached = true,
|
|
4
|
-
...options
|
|
5
|
-
}) {
|
|
6
|
-
const cache = new WeakMap;
|
|
7
|
-
return (proto, propertyKey) => {
|
|
8
|
-
const doQuery = function() {
|
|
9
|
-
if (shouldBeCached) {
|
|
10
|
-
const cachedResult = cache.get(this);
|
|
11
|
-
if (cachedResult !== undefined) {
|
|
12
|
-
return cachedResult;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const selector = "selector" in options ? options.selector : `[data-ref="${options.ref}"]`;
|
|
16
|
-
const queryResult = options.all ? this.querySelectorAll(selector) : this.querySelector(selector);
|
|
17
|
-
if (shouldBeCached) {
|
|
18
|
-
cache.set(this, queryResult);
|
|
19
|
-
}
|
|
20
|
-
return queryResult;
|
|
21
|
-
};
|
|
22
|
-
const originalConnectedCallback = proto.connectedCallback;
|
|
23
|
-
proto.connectedCallback = function() {
|
|
24
|
-
Object.defineProperty(this, propertyKey, {
|
|
25
|
-
get: doQuery,
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true
|
|
28
|
-
});
|
|
29
|
-
originalConnectedCallback.call(this);
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
query
|
|
35
|
-
};
|
|
1
|
+
import{u as D}from"./legacy/query.js";import{v as E}from"./standard/query.js";function H(w){return function(z,j){if(typeof j==="object")return E(w)(z,j);return D(w)(z,j)}}export{H as query};
|
|
2
|
+
export{H as t};
|
|
36
3
|
|
|
37
|
-
//# debugId=
|
|
4
|
+
//# debugId=0DD98124DFF9C20D64756E2164756E21
|