@o.z/zui 0.4.4 → 0.4.6
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 +1 -24
- package/dist/_constants-CnGtrSkM.cjs +7 -0
- package/dist/_constants-DXNZF5so.js +3 -0
- package/dist/decorators/defineElement.cjs +4 -4
- package/dist/decorators/defineElement.d.ts +48 -0
- package/dist/decorators/defineElement.js +4 -4
- package/dist/decorators/event.cjs +3 -2
- package/dist/decorators/event.d.ts +48 -0
- package/dist/decorators/event.js +3 -2
- package/dist/decorators/mixin.d.ts +61 -0
- package/dist/decorators/property.cjs +4 -4
- package/dist/decorators/property.d.ts +60 -0
- package/dist/decorators/property.js +4 -4
- package/dist/decorators/refs.cjs +2 -2
- package/dist/decorators/refs.d.ts +44 -0
- package/dist/decorators/refs.js +2 -2
- package/dist/decorators/state.cjs +2 -2
- package/dist/decorators/state.d.ts +54 -3
- package/dist/decorators/state.js +1 -1
- package/dist/decorators/types.d.ts +103 -0
- package/dist/dom.d.ts +40 -4
- package/dist/html.d.ts +93 -5
- package/dist/index.cjs +8 -5
- package/dist/index.d.ts +18 -0
- package/dist/index.js +4 -1
- package/dist/utilities/delay.cjs +7 -0
- package/dist/utilities/delay.d.ts +18 -0
- package/dist/utilities/delay.js +3 -0
- package/dist/utilities/index.cjs +15 -0
- package/dist/utilities/index.d.ts +10 -0
- package/dist/utilities/index.js +4 -0
- package/dist/utilities/isBrowser.cjs +7 -0
- package/dist/utilities/isBrowser.d.ts +22 -0
- package/dist/utilities/isBrowser.js +3 -0
- package/dist/utilities/makeReactive.cjs +7 -0
- package/dist/utilities/makeReactive.d.ts +41 -0
- package/dist/utilities/makeReactive.js +3 -0
- package/dist/utilities/toKebabCase.cjs +7 -0
- package/dist/utilities/toKebabCase.d.ts +26 -0
- package/dist/utilities/toKebabCase.js +3 -0
- package/package.json +34 -10
- package/dist/_constants-D8uytuQc.cjs +0 -6
- package/dist/_constants-DLywjTCf.js +0 -3
- package/dist/utilities.cjs +0 -10
- package/dist/utilities.d.ts +0 -4
- package/dist/utilities.js +0 -3
- /package/dist/{_helper-B0T4FTYh.js → index-B0T4FTYh.js} +0 -0
- /package/dist/{_helper-YcE1MU2f.cjs → index-YcE1MU2f.cjs} +0 -0
package/README.md
CHANGED
|
@@ -106,30 +106,7 @@ Since we extended the native `div`, we use the `is` attribute:
|
|
|
106
106
|
---
|
|
107
107
|
|
|
108
108
|
## 📚 API Reference
|
|
109
|
-
|
|
110
|
-
### ```@defineElement(config)```
|
|
111
|
-
Class decorator to register the custom element.
|
|
112
|
-
* **tagName**: The kebab-case name for your component.
|
|
113
|
-
* **html**: Raw HTML string for the template.
|
|
114
|
-
* **css**: (Optional) CSS string to be injected into the Shadow Root.
|
|
115
|
-
* **options**: (Optional) Standard `ElementDefinitionOptions` (e.g., `{ extends: 'button' }`).
|
|
116
|
-
|
|
117
|
-
### ```@property(options)```
|
|
118
|
-
Used on `accessor` fields to create reactive attributes.
|
|
119
|
-
* **type**: `"string" | "number" | "boolean"`. If omitted, it's inferred from the initial value.
|
|
120
|
-
* **name**: Custom attribute name (defaults to kebab-case of the property).
|
|
121
|
-
* **Hook**: Automatically calls `[propertyName]Update(old, new)` on change.
|
|
122
|
-
|
|
123
|
-
### ```@ref(selector)```
|
|
124
|
-
Field decorator that automatically assigns a child element from the Shadow Root to the property using `querySelector`.
|
|
125
|
-
|
|
126
|
-
### ```@event(options)```
|
|
127
|
-
Field decorator that initializes an `EventEmitter`.
|
|
128
|
-
* **name**: Custom event name (defaults to kebab-case of the property).
|
|
129
|
-
* **Usage**: Call `this.propertyName.emit(payload)` to dispatch a `CustomEvent`.
|
|
130
|
-
|
|
131
|
-
### ```Zui(BaseClass)```
|
|
132
|
-
A class mixin that enhances the base element (like `HTMLElement` or `HTMLDivElement`) with improved TypeScript definitions for `addEventListener`, ensuring custom events have correct payload types.
|
|
109
|
+
[API Docs](docs/api/README.md)
|
|
133
110
|
|
|
134
111
|
---
|
|
135
112
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var REF_CONSTRUCTOR_KEY=Symbol("constructor");var EVENT_CONSTRUCTOR_KEY=Symbol("constructor");var OBSERVED_ATTRS_KEY=Symbol("observedAttributes");
|
|
4
|
+
|
|
5
|
+
exports.EVENT_CONSTRUCTOR_KEY = EVENT_CONSTRUCTOR_KEY;
|
|
6
|
+
exports.OBSERVED_ATTRS_KEY = OBSERVED_ATTRS_KEY;
|
|
7
|
+
exports.REF_CONSTRUCTOR_KEY = REF_CONSTRUCTOR_KEY;
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const html = require('../html.cjs');
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const _constants = require('../_constants-
|
|
6
|
+
const utilities_isBrowser = require('../utilities/isBrowser.cjs');
|
|
7
|
+
const index = require('../index-YcE1MU2f.cjs');
|
|
8
|
+
const _constants = require('../_constants-CnGtrSkM.cjs');
|
|
9
9
|
|
|
10
|
-
function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_without_holes(arr){if(Array.isArray(arr))return _array_like_to_array(arr)}function _assert_this_initialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _call_super(_this,derived,args){derived=_get_prototype_of(derived);return _possible_constructor_return(_this,_is_native_reflect_construct()?Reflect.construct(derived,args||[],_get_prototype_of(_this).constructor):derived.apply(_this,args))}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _create_class(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);return Constructor}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}function _get_prototype_of(o){_get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _get_prototype_of(o)}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_set_prototype_of(subClass,superClass);}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return !!right[Symbol.hasInstance](left)}else {return left instanceof right}}function _iterable_to_array(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _possible_constructor_return(self,call){if(call&&(_type_of(call)==="object"||typeof call==="function")){return call}return _assert_this_initialized(self)}function _set_prototype_of(o,p){_set_prototype_of=Object.setPrototypeOf||function setPrototypeOf(o,p){o.__proto__=p;return o};return _set_prototype_of(o,p)}function _to_consumable_array(arr){return _array_without_holes(arr)||_iterable_to_array(arr)||_unsupported_iterable_to_array(arr)||_non_iterable_spread()}function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _is_native_reflect_construct(){try{var result=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(_){}return (_is_native_reflect_construct=function(){return !!result})()}var defineElement=function(param){var tagName=param.tagName,html$1=param.html,_param_css=param.css,css=_param_css===void 0?"":_param_css,options=param.options;return function(originalClass,context){var attributes=context.metadata[_constants.OBSERVED_ATTRS_KEY];var htmlString=_instanceof(html$1,html.SafeHTML)?html$1.value:html$1;if(!htmlString)throw "Html is empty!";var template=document.createElement("template");template.innerHTML="<style>".concat(css,"</style>").concat(htmlString);var NewClass=/*#__PURE__*/function(originalClass){_inherits(NewClass,originalClass);function NewClass(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_class_call_check(this,NewClass);var _this;_this=_call_super(this,NewClass,_to_consumable_array(args)),_define_property(_this,"shadowRoot",void 0);_this.setAttribute("z-is",tagName);_this.shadowRoot=_this.attachShadow({mode:"closed"});_this.shadowRoot.appendChild(template.content.cloneNode(true));return _this}_create_class(NewClass,[{key:"connectedCallback",value:function connectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_connected;var zuiThis=_this;(_zuiThis_connected=zuiThis.connected)===null||_zuiThis_connected===void 0?void 0:_zuiThis_connected.call(zuiThis);});}},{key:"disconnectedCallback",value:function disconnectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_disconnected;var zuiThis=_this;(_zuiThis_disconnected=zuiThis.disconnected)===null||_zuiThis_disconnected===void 0?void 0:_zuiThis_disconnected.call(zuiThis);});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(attributeName,oldValue,newValue){var zuiThis=this;if(oldValue!==newValue){var _zuiThis_attributeChanged;(_zuiThis_attributeChanged=zuiThis.attributeChanged)===null||_zuiThis_attributeChanged===void 0?void 0:_zuiThis_attributeChanged.call(zuiThis,attributeName,oldValue,newValue);
|
|
10
|
+
function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_without_holes(arr){if(Array.isArray(arr))return _array_like_to_array(arr)}function _assert_this_initialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _call_super(_this,derived,args){derived=_get_prototype_of(derived);return _possible_constructor_return(_this,_is_native_reflect_construct()?Reflect.construct(derived,args||[],_get_prototype_of(_this).constructor):derived.apply(_this,args))}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _create_class(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);return Constructor}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}function _get_prototype_of(o){_get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _get_prototype_of(o)}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_set_prototype_of(subClass,superClass);}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return !!right[Symbol.hasInstance](left)}else {return left instanceof right}}function _iterable_to_array(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _possible_constructor_return(self,call){if(call&&(_type_of(call)==="object"||typeof call==="function")){return call}return _assert_this_initialized(self)}function _set_prototype_of(o,p){_set_prototype_of=Object.setPrototypeOf||function setPrototypeOf(o,p){o.__proto__=p;return o};return _set_prototype_of(o,p)}function _to_consumable_array(arr){return _array_without_holes(arr)||_iterable_to_array(arr)||_unsupported_iterable_to_array(arr)||_non_iterable_spread()}function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _is_native_reflect_construct(){try{var result=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(_){}return (_is_native_reflect_construct=function(){return !!result})()}var defineElement=function(param){var tagName=param.tagName,html$1=param.html,_param_css=param.css,css=_param_css===void 0?"":_param_css,options=param.options;return function(originalClass,context){var attributes=context.metadata[_constants.OBSERVED_ATTRS_KEY];var htmlString=_instanceof(html$1,html.SafeHTML)?html$1.value:html$1;if(!htmlString)throw "Html is empty!";var template=document.createElement("template");template.innerHTML="<style>".concat(css,"</style>").concat(htmlString);var NewClass=/*#__PURE__*/function(originalClass){_inherits(NewClass,originalClass);function NewClass(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_class_call_check(this,NewClass);var _this;var _this_EVENT_CONSTRUCTOR_KEY,_this1,_this_REF_CONSTRUCTOR_KEY,_this2;_this=_call_super(this,NewClass,_to_consumable_array(args)),_define_property(_this,"shadowRoot",void 0);_this.setAttribute("z-is",tagName);_this.shadowRoot=_this.attachShadow({mode:"closed"});_this.shadowRoot.appendChild(template.content.cloneNode(true));(_this1=_this)===null||_this1===void 0?void 0:(_this_EVENT_CONSTRUCTOR_KEY=_this1[_constants.EVENT_CONSTRUCTOR_KEY])===null||_this_EVENT_CONSTRUCTOR_KEY===void 0?void 0:_this_EVENT_CONSTRUCTOR_KEY.call(_this1);(_this2=_this)===null||_this2===void 0?void 0:(_this_REF_CONSTRUCTOR_KEY=_this2[_constants.REF_CONSTRUCTOR_KEY])===null||_this_REF_CONSTRUCTOR_KEY===void 0?void 0:_this_REF_CONSTRUCTOR_KEY.call(_this2);return _this}_create_class(NewClass,[{key:"connectedCallback",value:function connectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_connected;var zuiThis=_this;(_zuiThis_connected=zuiThis.connected)===null||_zuiThis_connected===void 0?void 0:_zuiThis_connected.call(zuiThis);});}},{key:"disconnectedCallback",value:function disconnectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_disconnected;var zuiThis=_this;(_zuiThis_disconnected=zuiThis.disconnected)===null||_zuiThis_disconnected===void 0?void 0:_zuiThis_disconnected.call(zuiThis);});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(attributeName,oldValue,newValue){var zuiThis=this;if(oldValue!==newValue){var _zuiThis_attributeChanged;zuiThis===null||zuiThis===void 0?void 0:(_zuiThis_attributeChanged=zuiThis.attributeChanged)===null||_zuiThis_attributeChanged===void 0?void 0:_zuiThis_attributeChanged.call(zuiThis,attributeName,oldValue,newValue);index.callFun(attributes.find(function(i){return i.name===attributeName}),oldValue,newValue,zuiThis);}}}]);return NewClass}(originalClass);NewClass.observedAttributes=attributes.map(function(i){return i.name});if(utilities_isBrowser.isBrowser&&!customElements.get(tagName)){customElements.define(tagName,NewClass,options);}return NewClass}};
|
|
11
11
|
|
|
12
12
|
exports.defineElement = defineElement;
|
|
@@ -1,11 +1,59 @@
|
|
|
1
1
|
import { SafeHTML } from '../html';
|
|
2
2
|
import { UpdateMethods } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for defining a custom element.
|
|
5
|
+
*
|
|
6
|
+
* @interface DefineElementOptions
|
|
7
|
+
* @property {string} tagName - The custom element tag name (must contain hyphen, e.g., 'my-counter')
|
|
8
|
+
* @property {string|SafeHTML} html - HTML template string or SafeHTML object for the element's shadow DOM
|
|
9
|
+
* @property {string} [css] - Optional CSS string to inject into the shadow DOM
|
|
10
|
+
* @property {ElementDefinitionOptions} [options] - Custom element definition options including extension support
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* @defineElement({
|
|
14
|
+
* tagName: 'my-counter',
|
|
15
|
+
* html: '<div>Count: <span class="count"></span></div>',
|
|
16
|
+
* css: ':host { display: block; }',
|
|
17
|
+
* options: { extends: 'div' }
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
3
20
|
export interface DefineElementOptions {
|
|
4
21
|
tagName: string;
|
|
5
22
|
html: string | SafeHTML;
|
|
6
23
|
css?: string;
|
|
7
24
|
options?: ElementDefinitionOptions;
|
|
8
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Class decorator that registers a custom element with the browser's Custom Elements registry.
|
|
28
|
+
*
|
|
29
|
+
* This decorator:
|
|
30
|
+
* 1. Creates a Shadow DOM for the element
|
|
31
|
+
* 2. Injects HTML and CSS templates
|
|
32
|
+
* 3. Sets up lifecycle callbacks (connected/disconnected)
|
|
33
|
+
* 4. Handles attribute change observation
|
|
34
|
+
* 5. Registers the element with customElements.define()
|
|
35
|
+
*
|
|
36
|
+
* @template T - Constructor type extending CustomElementConstructor
|
|
37
|
+
* @param {DefineElementOptions} config - Element configuration object
|
|
38
|
+
* @returns {ClassDecorator} A class decorator function
|
|
39
|
+
*
|
|
40
|
+
* @throws {string} If HTML template is empty
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* @defineElement({
|
|
44
|
+
* tagName: 'my-counter',
|
|
45
|
+
* html: counterTemplate,
|
|
46
|
+
* css: counterStyles,
|
|
47
|
+
* options: { extends: 'div' }
|
|
48
|
+
* })
|
|
49
|
+
* class Counter extends Zui(HTMLDivElement) {
|
|
50
|
+
* // class implementation
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define}
|
|
55
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow}
|
|
56
|
+
*/
|
|
9
57
|
export declare const defineElement: ({ tagName, html, css, options }: DefineElementOptions) => <T extends CustomElementConstructor>(originalClass: T & {
|
|
10
58
|
prototype: UpdateMethods<InstanceType<T>>;
|
|
11
59
|
}, context: ClassDecoratorContext<T>) => T;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SafeHTML } from '../html.js';
|
|
2
|
-
import { isBrowser } from '../utilities.js';
|
|
3
|
-
import { c as callFun } from '../
|
|
4
|
-
import { O as OBSERVED_ATTRS_KEY } from '../_constants-
|
|
2
|
+
import { isBrowser } from '../utilities/isBrowser.js';
|
|
3
|
+
import { c as callFun } from '../index-B0T4FTYh.js';
|
|
4
|
+
import { O as OBSERVED_ATTRS_KEY, E as EVENT_CONSTRUCTOR_KEY, R as REF_CONSTRUCTOR_KEY } from '../_constants-DXNZF5so.js';
|
|
5
5
|
|
|
6
|
-
function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_without_holes(arr){if(Array.isArray(arr))return _array_like_to_array(arr)}function _assert_this_initialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _call_super(_this,derived,args){derived=_get_prototype_of(derived);return _possible_constructor_return(_this,_is_native_reflect_construct()?Reflect.construct(derived,args||[],_get_prototype_of(_this).constructor):derived.apply(_this,args))}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _create_class(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);return Constructor}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}function _get_prototype_of(o){_get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _get_prototype_of(o)}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_set_prototype_of(subClass,superClass);}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return !!right[Symbol.hasInstance](left)}else {return left instanceof right}}function _iterable_to_array(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _possible_constructor_return(self,call){if(call&&(_type_of(call)==="object"||typeof call==="function")){return call}return _assert_this_initialized(self)}function _set_prototype_of(o,p){_set_prototype_of=Object.setPrototypeOf||function setPrototypeOf(o,p){o.__proto__=p;return o};return _set_prototype_of(o,p)}function _to_consumable_array(arr){return _array_without_holes(arr)||_iterable_to_array(arr)||_unsupported_iterable_to_array(arr)||_non_iterable_spread()}function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _is_native_reflect_construct(){try{var result=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(_){}return (_is_native_reflect_construct=function(){return !!result})()}var defineElement=function(param){var tagName=param.tagName,html=param.html,_param_css=param.css,css=_param_css===void 0?"":_param_css,options=param.options;return function(originalClass,context){var attributes=context.metadata[OBSERVED_ATTRS_KEY];var htmlString=_instanceof(html,SafeHTML)?html.value:html;if(!htmlString)throw "Html is empty!";var template=document.createElement("template");template.innerHTML="<style>".concat(css,"</style>").concat(htmlString);var NewClass=/*#__PURE__*/function(originalClass){_inherits(NewClass,originalClass);function NewClass(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_class_call_check(this,NewClass);var _this;_this=_call_super(this,NewClass,_to_consumable_array(args)),_define_property(_this,"shadowRoot",void 0);_this.setAttribute("z-is",tagName);_this.shadowRoot=_this.attachShadow({mode:"closed"});_this.shadowRoot.appendChild(template.content.cloneNode(true));return _this}_create_class(NewClass,[{key:"connectedCallback",value:function connectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_connected;var zuiThis=_this;(_zuiThis_connected=zuiThis.connected)===null||_zuiThis_connected===void 0?void 0:_zuiThis_connected.call(zuiThis);});}},{key:"disconnectedCallback",value:function disconnectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_disconnected;var zuiThis=_this;(_zuiThis_disconnected=zuiThis.disconnected)===null||_zuiThis_disconnected===void 0?void 0:_zuiThis_disconnected.call(zuiThis);});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(attributeName,oldValue,newValue){var zuiThis=this;if(oldValue!==newValue){var _zuiThis_attributeChanged;(_zuiThis_attributeChanged=zuiThis.attributeChanged)===null||_zuiThis_attributeChanged===void 0?void 0:_zuiThis_attributeChanged.call(zuiThis,attributeName,oldValue,newValue);
|
|
6
|
+
function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_without_holes(arr){if(Array.isArray(arr))return _array_like_to_array(arr)}function _assert_this_initialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _call_super(_this,derived,args){derived=_get_prototype_of(derived);return _possible_constructor_return(_this,_is_native_reflect_construct()?Reflect.construct(derived,args||[],_get_prototype_of(_this).constructor):derived.apply(_this,args))}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _create_class(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);return Constructor}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}function _get_prototype_of(o){_get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _get_prototype_of(o)}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_set_prototype_of(subClass,superClass);}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return !!right[Symbol.hasInstance](left)}else {return left instanceof right}}function _iterable_to_array(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter)}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _possible_constructor_return(self,call){if(call&&(_type_of(call)==="object"||typeof call==="function")){return call}return _assert_this_initialized(self)}function _set_prototype_of(o,p){_set_prototype_of=Object.setPrototypeOf||function setPrototypeOf(o,p){o.__proto__=p;return o};return _set_prototype_of(o,p)}function _to_consumable_array(arr){return _array_without_holes(arr)||_iterable_to_array(arr)||_unsupported_iterable_to_array(arr)||_non_iterable_spread()}function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _is_native_reflect_construct(){try{var result=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(_){}return (_is_native_reflect_construct=function(){return !!result})()}var defineElement=function(param){var tagName=param.tagName,html=param.html,_param_css=param.css,css=_param_css===void 0?"":_param_css,options=param.options;return function(originalClass,context){var attributes=context.metadata[OBSERVED_ATTRS_KEY];var htmlString=_instanceof(html,SafeHTML)?html.value:html;if(!htmlString)throw "Html is empty!";var template=document.createElement("template");template.innerHTML="<style>".concat(css,"</style>").concat(htmlString);var NewClass=/*#__PURE__*/function(originalClass){_inherits(NewClass,originalClass);function NewClass(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_class_call_check(this,NewClass);var _this;var _this_EVENT_CONSTRUCTOR_KEY,_this1,_this_REF_CONSTRUCTOR_KEY,_this2;_this=_call_super(this,NewClass,_to_consumable_array(args)),_define_property(_this,"shadowRoot",void 0);_this.setAttribute("z-is",tagName);_this.shadowRoot=_this.attachShadow({mode:"closed"});_this.shadowRoot.appendChild(template.content.cloneNode(true));(_this1=_this)===null||_this1===void 0?void 0:(_this_EVENT_CONSTRUCTOR_KEY=_this1[EVENT_CONSTRUCTOR_KEY])===null||_this_EVENT_CONSTRUCTOR_KEY===void 0?void 0:_this_EVENT_CONSTRUCTOR_KEY.call(_this1);(_this2=_this)===null||_this2===void 0?void 0:(_this_REF_CONSTRUCTOR_KEY=_this2[REF_CONSTRUCTOR_KEY])===null||_this_REF_CONSTRUCTOR_KEY===void 0?void 0:_this_REF_CONSTRUCTOR_KEY.call(_this2);return _this}_create_class(NewClass,[{key:"connectedCallback",value:function connectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_connected;var zuiThis=_this;(_zuiThis_connected=zuiThis.connected)===null||_zuiThis_connected===void 0?void 0:_zuiThis_connected.call(zuiThis);});}},{key:"disconnectedCallback",value:function disconnectedCallback(){var _this=this;queueMicrotask(function(){var _zuiThis_disconnected;var zuiThis=_this;(_zuiThis_disconnected=zuiThis.disconnected)===null||_zuiThis_disconnected===void 0?void 0:_zuiThis_disconnected.call(zuiThis);});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(attributeName,oldValue,newValue){var zuiThis=this;if(oldValue!==newValue){var _zuiThis_attributeChanged;zuiThis===null||zuiThis===void 0?void 0:(_zuiThis_attributeChanged=zuiThis.attributeChanged)===null||_zuiThis_attributeChanged===void 0?void 0:_zuiThis_attributeChanged.call(zuiThis,attributeName,oldValue,newValue);callFun(attributes.find(function(i){return i.name===attributeName}),oldValue,newValue,zuiThis);}}}]);return NewClass}(originalClass);NewClass.observedAttributes=attributes.map(function(i){return i.name});if(isBrowser&&!customElements.get(tagName)){customElements.define(tagName,NewClass,options);}return NewClass}};
|
|
7
7
|
|
|
8
8
|
export { defineElement };
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const utilities_toKebabCase = require('../utilities/toKebabCase.cjs');
|
|
6
|
+
const _constants = require('../_constants-CnGtrSkM.cjs');
|
|
6
7
|
const decorators_types = require('./types.cjs');
|
|
7
8
|
|
|
8
|
-
var event=function(){var options=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return function(_target,context){var _options_name;var eventName=(_options_name=options.name)!==null&&_options_name!==void 0?_options_name:
|
|
9
|
+
var event=function(){var options=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return function(_target,context){var _options_name;var eventName=(_options_name=options.name)!==null&&_options_name!==void 0?_options_name:utilities_toKebabCase.toKebabCase(context.name.toString());context.addInitializer(function(){var zuiThis=this;var refInit=zuiThis===null||zuiThis===void 0?void 0:zuiThis[_constants.EVENT_CONSTRUCTOR_KEY];zuiThis[_constants.EVENT_CONSTRUCTOR_KEY]=function(){if(typeof refInit==="function")refInit.call(this);zuiThis[context.name.toString()]=new decorators_types.EventEmitter(zuiThis,eventName);};});}};
|
|
9
10
|
|
|
10
11
|
exports.event = event;
|
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
import { EventEmitter } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the @event decorator.
|
|
4
|
+
*
|
|
5
|
+
* @interface EventOptions
|
|
6
|
+
* @property {string} [name] - Custom event name (defaults to kebab-case of property name)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* @event({ name: 'count-changed' })
|
|
10
|
+
* onChange!: EventEmitter<number>;
|
|
11
|
+
*/
|
|
2
12
|
export interface EventOptions {
|
|
3
13
|
name?: string;
|
|
4
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Field decorator that creates a typed EventEmitter instance for dispatching custom events.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Automatic event naming (camelCase → kebab-case)
|
|
20
|
+
* - Type-safe event payloads
|
|
21
|
+
* - Bubbles and composed by default
|
|
22
|
+
* - Asynchronous initialization via queueMicrotask
|
|
23
|
+
*
|
|
24
|
+
* @template T - Element type extending HTMLElement
|
|
25
|
+
* @template V - Event detail type
|
|
26
|
+
* @param {EventOptions} [options={}] - Event configuration options
|
|
27
|
+
* @returns {ClassFieldDecorator} A field decorator function
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Basic usage with automatic naming
|
|
32
|
+
* @event()
|
|
33
|
+
* counterClick!: EventEmitter<{ count: number }>;
|
|
34
|
+
* // Dispatches 'counter-click' event
|
|
35
|
+
*
|
|
36
|
+
* // With custom event name
|
|
37
|
+
* @event({ name: 'value-changed' })
|
|
38
|
+
* onChange!: EventEmitter<number>;
|
|
39
|
+
* // Dispatches 'value-changed' event
|
|
40
|
+
*
|
|
41
|
+
* // Usage in component
|
|
42
|
+
* this.counterClick.emit({ count: this.count });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* - Events bubble up the DOM tree by default
|
|
47
|
+
* - Events can cross shadow DOM boundaries (composed: true)
|
|
48
|
+
* - Event name is converted to kebab-case automatically
|
|
49
|
+
*
|
|
50
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent}
|
|
51
|
+
* @see {@link EventEmitter}
|
|
52
|
+
*/
|
|
5
53
|
export declare const event: (options?: EventOptions) => <T extends HTMLElement, V>(_target: undefined, context: ClassFieldDecoratorContext<T, EventEmitter<V>>) => void;
|
package/dist/decorators/event.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { toKebabCase } from '../utilities.js';
|
|
1
|
+
import { toKebabCase } from '../utilities/toKebabCase.js';
|
|
2
|
+
import { E as EVENT_CONSTRUCTOR_KEY } from '../_constants-DXNZF5so.js';
|
|
2
3
|
import { EventEmitter } from './types.js';
|
|
3
4
|
|
|
4
|
-
var event=function(){var options=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return function(_target,context){var _options_name;var eventName=(_options_name=options.name)!==null&&_options_name!==void 0?_options_name:toKebabCase(context.name.toString());context.addInitializer(function(){var
|
|
5
|
+
var event=function(){var options=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return function(_target,context){var _options_name;var eventName=(_options_name=options.name)!==null&&_options_name!==void 0?_options_name:toKebabCase(context.name.toString());context.addInitializer(function(){var zuiThis=this;var refInit=zuiThis===null||zuiThis===void 0?void 0:zuiThis[EVENT_CONSTRUCTOR_KEY];zuiThis[EVENT_CONSTRUCTOR_KEY]=function(){if(typeof refInit==="function")refInit.call(this);zuiThis[context.name.toString()]=new EventEmitter(zuiThis,eventName);};});}};
|
|
5
6
|
|
|
6
7
|
export { event };
|
|
@@ -1,9 +1,70 @@
|
|
|
1
1
|
import { ZuiEventMap } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Mixin function that enhances base HTML elements with ZUI capabilities.
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Type-safe event listeners for custom events
|
|
7
|
+
* - Abstract lifecycle methods (connected, disconnected, attributeChanged)
|
|
8
|
+
* - Proper inheritance chain for customized built-in elements
|
|
9
|
+
*
|
|
10
|
+
* @template TBase - Base constructor type (extends HTMLElement)
|
|
11
|
+
* @param {TBase} Base - Base class constructor to enhance
|
|
12
|
+
* @returns {abstract class} Enhanced class with ZUI capabilities
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Extend native div element
|
|
17
|
+
* class Counter extends Zui(HTMLDivElement) {
|
|
18
|
+
* connected() {
|
|
19
|
+
* console.log('Counter connected to DOM');
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Extend button element
|
|
24
|
+
* class CustomButton extends Zui(HTMLButtonElement) {
|
|
25
|
+
* @event()
|
|
26
|
+
* customClick!: EventEmitter<void>;
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* - Must be used as a base class for all ZUI components
|
|
32
|
+
* - Provides abstract methods that should be implemented
|
|
33
|
+
* - Enables type inference for custom event maps
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements}
|
|
36
|
+
*/
|
|
2
37
|
export declare function Zui<TBase extends new (...args: any[]) => HTMLElement>(Base: TBase): (abstract new (...args: any[]) => {
|
|
38
|
+
/**
|
|
39
|
+
* Called when the element is connected to the DOM.
|
|
40
|
+
* Override to perform setup operations.
|
|
41
|
+
*/
|
|
3
42
|
connected?(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Called when the element is disconnected from the DOM.
|
|
45
|
+
* Override to perform cleanup operations.
|
|
46
|
+
*/
|
|
4
47
|
disconnected?(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Called when an observed attribute changes.
|
|
50
|
+
* @param attributeName - Name of the changed attribute
|
|
51
|
+
* @param oldValue - Previous attribute value
|
|
52
|
+
* @param newValue - New attribute value
|
|
53
|
+
*/
|
|
5
54
|
attributeChanged?(attributeName: string, oldValue: string, newValue: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Type-safe overload for adding event listeners.
|
|
57
|
+
* Supports both custom ZUI events and standard DOM events.
|
|
58
|
+
*
|
|
59
|
+
* @template K - Event type key
|
|
60
|
+
* @param {K} type - Event type to listen for
|
|
61
|
+
* @param {(ev: CustomEvent<ZuiEventMap<this>[K]>) => void} listener - Event handler function
|
|
62
|
+
* @param {boolean | AddEventListenerOptions} [options] - Event listener options
|
|
63
|
+
*/
|
|
6
64
|
addEventListener<K extends never>(type: K, listener: (ev: CustomEvent<ZuiEventMap</*elided*/ any>[K]>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
65
|
+
/**
|
|
66
|
+
* Standard DOM event listener.
|
|
67
|
+
*/
|
|
7
68
|
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
8
69
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
9
70
|
accessKey: string;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const _constants = require('../_constants-
|
|
5
|
+
const utilities_toKebabCase = require('../utilities/toKebabCase.cjs');
|
|
6
|
+
const index = require('../index-YcE1MU2f.cjs');
|
|
7
|
+
const _constants = require('../_constants-CnGtrSkM.cjs');
|
|
8
8
|
|
|
9
|
-
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var property=function(){var _ref=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},type=_ref.type,name=_ref.name,callbackName=_ref.callbackName;return function(_accessor,context){var _context_metadata,_OBSERVED_ATTRS_KEY,_;var attributName=name!==null&&name!==void 0?name:
|
|
9
|
+
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var property=function(){var _ref=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},type=_ref.type,name=_ref.name,callbackName=_ref.callbackName;return function(_accessor,context){var _context_metadata,_OBSERVED_ATTRS_KEY,_;var attributName=name!==null&&name!==void 0?name:utilities_toKebabCase.toKebabCase(context.name.toString());var attributCallbackName=callbackName!==null&&callbackName!==void 0?callbackName:"".concat(context.name.toString(),"Update");var attribute={type:type,name:attributName,callbackName:attributCallbackName};(_=(_context_metadata=context.metadata)[_OBSERVED_ATTRS_KEY=_constants.OBSERVED_ATTRS_KEY])!==null&&_!==void 0?_:_context_metadata[_OBSERVED_ATTRS_KEY]=[];var attributes=context.metadata[_constants.OBSERVED_ATTRS_KEY];attributes.push(attribute);return {init:function init(initialValue){attribute.type=type!==null&&type!==void 0?type:typeof initialValue==="undefined"?"undefined":_type_of(initialValue);var zuiThis=this;var defaultValue=index.getConvertor(attribute,zuiThis);if(defaultValue===undefined||defaultValue===null){zuiThis.setAttribute(attribute.name,String(initialValue));queueMicrotask(function(){index.callFun(attribute,initialValue,initialValue,zuiThis);});}return initialValue},get:function get(){var zuiThis=this;return index.getConvertor(attribute,zuiThis)},set:function set(value){var _this=this;queueMicrotask(function(){var zuiThis=_this;var oldValue=index.getConvertor(attribute,zuiThis);if(attribute.type==="string"||attribute.type==="number"){zuiThis.setAttribute(attributName,String(value));}else if(attribute.type==="boolean"){zuiThis.setAttribute(attributName,value?"true":"false");}else throw 'Only accept type of "string", "number", "boolean"';if(oldValue!==value)index.callFun(attribute,oldValue,value,zuiThis);});}}}};
|
|
10
10
|
|
|
11
11
|
exports.property = property;
|
|
@@ -1,10 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Property decorator for reactive attributes in ZUI components.
|
|
3
|
+
* Creates two-way binding between JavaScript properties and DOM attributes.
|
|
4
|
+
*
|
|
5
|
+
* @module property
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Supported property types for attribute reflection.
|
|
9
|
+
*/
|
|
1
10
|
export type PropertyType = "string" | "number" | "boolean";
|
|
11
|
+
/**
|
|
12
|
+
* Suffix for update callback methods.
|
|
13
|
+
*/
|
|
2
14
|
export type PropertyCallback = "Update" | "Changed";
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for the @property decorator.
|
|
17
|
+
*
|
|
18
|
+
* @interface PropertyOptions
|
|
19
|
+
* @property {PropertyType} [type] - Type of the property for attribute conversion
|
|
20
|
+
* @property {string} [name] - Custom attribute name (defaults to kebab-case of property name)
|
|
21
|
+
* @property {`${string}${PropertyCallback}`} [callbackName] - Custom update callback method name
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* @property({ type: 'number', name: 'count-value' })
|
|
25
|
+
* accessor count = 0;
|
|
26
|
+
*/
|
|
3
27
|
export interface PropertyOptions {
|
|
4
28
|
type?: PropertyType;
|
|
5
29
|
name?: string;
|
|
6
30
|
callbackName?: `${string}${PropertyCallback}`;
|
|
7
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Accessor decorator that creates reactive properties synchronized with DOM attributes.
|
|
34
|
+
*
|
|
35
|
+
* Features:
|
|
36
|
+
* - Automatic attribute reflection (property ↔ attribute)
|
|
37
|
+
* - Type conversion (string, number, boolean)
|
|
38
|
+
* - Lifecycle hooks with automatic update callbacks
|
|
39
|
+
* - Default values from initializer
|
|
40
|
+
*
|
|
41
|
+
* @template T - Element type extending HTMLElement
|
|
42
|
+
* @template V - Property value type (number | string | boolean)
|
|
43
|
+
* @param {PropertyOptions} [options={}] - Property configuration options
|
|
44
|
+
* @returns {ClassAccessorDecorator} An accessor decorator function
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Basic usage with type inference
|
|
49
|
+
* @property()
|
|
50
|
+
* accessor count = 0; // Creates 'count' attribute, calls countUpdate()
|
|
51
|
+
*
|
|
52
|
+
* // With custom attribute name
|
|
53
|
+
* @property({ name: 'is-enabled' })
|
|
54
|
+
* accessor enabled = true; // Creates 'is-enabled' attribute
|
|
55
|
+
*
|
|
56
|
+
* // With explicit type
|
|
57
|
+
* @property({ type: 'boolean' })
|
|
58
|
+
* accessor disabled = false;
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* - Boolean attributes are set as "true"/"false" strings
|
|
63
|
+
* - Empty string for boolean attributes evaluates to true
|
|
64
|
+
* - Update methods are called asynchronously via queueMicrotask
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute}
|
|
67
|
+
*/
|
|
8
68
|
export declare const property: ({ type, name, callbackName }?: PropertyOptions) => <T extends HTMLElement, V extends number | string | boolean>(_accessor: {
|
|
9
69
|
get: (this: T) => V;
|
|
10
70
|
set: (this: T, value: V) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { toKebabCase } from '../utilities.js';
|
|
2
|
-
import { g as getConvertor, c as callFun } from '../
|
|
3
|
-
import { O as OBSERVED_ATTRS_KEY } from '../_constants-
|
|
1
|
+
import { toKebabCase } from '../utilities/toKebabCase.js';
|
|
2
|
+
import { g as getConvertor, c as callFun } from '../index-B0T4FTYh.js';
|
|
3
|
+
import { O as OBSERVED_ATTRS_KEY } from '../_constants-DXNZF5so.js';
|
|
4
4
|
|
|
5
|
-
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var property=function(){var _ref=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},type=_ref.type,name=_ref.name,callbackName=_ref.callbackName;return function(_accessor,context){var _context_metadata,_OBSERVED_ATTRS_KEY,_;var attributName=name!==null&&name!==void 0?name:toKebabCase(context.name.toString());var attributCallbackName=callbackName!==null&&callbackName!==void 0?callbackName:"".concat(context.name.toString(),"Update");var attribute={type:type,name:attributName,callbackName:attributCallbackName};(_=(_context_metadata=context.metadata)[_OBSERVED_ATTRS_KEY=OBSERVED_ATTRS_KEY])!==null&&_!==void 0?_:_context_metadata[_OBSERVED_ATTRS_KEY]=[];var attributes=context.metadata[OBSERVED_ATTRS_KEY];attributes.push(attribute);return {init:function init(initialValue){attribute.type=type!==null&&type!==void 0?type:typeof initialValue==="undefined"?"undefined":_type_of(initialValue);var zuiThis=this;zuiThis.setAttribute(attribute.name,String(initialValue));queueMicrotask(function(){callFun(attribute,initialValue,initialValue,zuiThis);});return initialValue},get:function get(){var zuiThis=this;return getConvertor(attribute,zuiThis)},set:function set(value){var _this=this;queueMicrotask(function(){var zuiThis=_this;var oldValue=getConvertor(attribute,zuiThis);if(attribute.type==="string"||attribute.type==="number"){zuiThis.setAttribute(attributName,String(value));}else if(attribute.type==="boolean"){zuiThis.setAttribute(attributName,value?"true":"false");}else throw 'Only accept type of "string", "number", "boolean"';if(oldValue!==value)callFun(attribute,oldValue,value,zuiThis);});}}}};
|
|
5
|
+
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var property=function(){var _ref=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},type=_ref.type,name=_ref.name,callbackName=_ref.callbackName;return function(_accessor,context){var _context_metadata,_OBSERVED_ATTRS_KEY,_;var attributName=name!==null&&name!==void 0?name:toKebabCase(context.name.toString());var attributCallbackName=callbackName!==null&&callbackName!==void 0?callbackName:"".concat(context.name.toString(),"Update");var attribute={type:type,name:attributName,callbackName:attributCallbackName};(_=(_context_metadata=context.metadata)[_OBSERVED_ATTRS_KEY=OBSERVED_ATTRS_KEY])!==null&&_!==void 0?_:_context_metadata[_OBSERVED_ATTRS_KEY]=[];var attributes=context.metadata[OBSERVED_ATTRS_KEY];attributes.push(attribute);return {init:function init(initialValue){attribute.type=type!==null&&type!==void 0?type:typeof initialValue==="undefined"?"undefined":_type_of(initialValue);var zuiThis=this;var defaultValue=getConvertor(attribute,zuiThis);if(defaultValue===undefined||defaultValue===null){zuiThis.setAttribute(attribute.name,String(initialValue));queueMicrotask(function(){callFun(attribute,initialValue,initialValue,zuiThis);});}return initialValue},get:function get(){var zuiThis=this;return getConvertor(attribute,zuiThis)},set:function set(value){var _this=this;queueMicrotask(function(){var zuiThis=_this;var oldValue=getConvertor(attribute,zuiThis);if(attribute.type==="string"||attribute.type==="number"){zuiThis.setAttribute(attributName,String(value));}else if(attribute.type==="boolean"){zuiThis.setAttribute(attributName,value?"true":"false");}else throw 'Only accept type of "string", "number", "boolean"';if(oldValue!==value)callFun(attribute,oldValue,value,zuiThis);});}}}};
|
|
6
6
|
|
|
7
7
|
export { property };
|
package/dist/decorators/refs.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const _constants = require('../_constants-
|
|
5
|
+
const _constants = require('../_constants-CnGtrSkM.cjs');
|
|
6
6
|
|
|
7
|
-
var ref=function(selector){return function(_target,context){var
|
|
7
|
+
var ref=function(selector){return function(_target,context){context.addInitializer(function(){var zuiThis=this;var refInit=zuiThis===null||zuiThis===void 0?void 0:zuiThis[_constants.REF_CONSTRUCTOR_KEY];zuiThis[_constants.REF_CONSTRUCTOR_KEY]=function(){if(typeof refInit==="function")refInit.call(this);zuiThis[context.name.toString()]=zuiThis.shadowRoot.querySelector(selector);};});}};
|
|
8
8
|
|
|
9
9
|
exports.ref = ref;
|
|
@@ -1 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Refs decorator for type-safe DOM element references in ZUI components.
|
|
3
|
+
* Provides automatic element querying from Shadow DOM with proper typing.
|
|
4
|
+
*
|
|
5
|
+
* @module refs
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Field decorator that automatically queries and assigns DOM elements from the shadow root.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Type-safe element references
|
|
12
|
+
* - Automatic query on component initialization
|
|
13
|
+
* - Works with any CSS selector
|
|
14
|
+
* - Asynchronous resolution via queueMicrotask
|
|
15
|
+
*
|
|
16
|
+
* @template T - Element type extending HTMLElement
|
|
17
|
+
* @template V - Reference element type extending HTMLElement
|
|
18
|
+
* @param {string} selector - CSS selector to query the element in shadow DOM
|
|
19
|
+
* @returns {ClassFieldDecorator} A field decorator function
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} If selector doesn't match any element (returns null)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Query by class
|
|
26
|
+
* @ref('.counter-display')
|
|
27
|
+
* displayRef!: HTMLDivElement;
|
|
28
|
+
*
|
|
29
|
+
* // Query by ID
|
|
30
|
+
* @ref('#submit-btn')
|
|
31
|
+
* submitButton!: HTMLButtonElement;
|
|
32
|
+
*
|
|
33
|
+
* // Query with complex selector
|
|
34
|
+
* @ref('form input[type="text"]')
|
|
35
|
+
* textInput!: HTMLInputElement;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* - References are resolved after the element is connected to DOM
|
|
40
|
+
* - Uses shadowRoot.querySelector() internally
|
|
41
|
+
* - Non-null assertion is used, ensure selector matches
|
|
42
|
+
*
|
|
43
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector}
|
|
44
|
+
*/
|
|
1
45
|
export declare const ref: (selector: string) => <T extends HTMLElement, V extends HTMLElement>(_target: undefined, context: ClassFieldDecoratorContext<T, V>) => void;
|
package/dist/decorators/refs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as
|
|
1
|
+
import { R as REF_CONSTRUCTOR_KEY } from '../_constants-DXNZF5so.js';
|
|
2
2
|
|
|
3
|
-
var ref=function(selector){return function(_target,context){var
|
|
3
|
+
var ref=function(selector){return function(_target,context){context.addInitializer(function(){var zuiThis=this;var refInit=zuiThis===null||zuiThis===void 0?void 0:zuiThis[REF_CONSTRUCTOR_KEY];zuiThis[REF_CONSTRUCTOR_KEY]=function(){if(typeof refInit==="function")refInit.call(this);zuiThis[context.name.toString()]=zuiThis.shadowRoot.querySelector(selector);};});}};
|
|
4
4
|
|
|
5
5
|
export { ref };
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const utilities_makeReactive = require('../utilities/makeReactive.cjs');
|
|
6
6
|
|
|
7
|
-
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var state=function(){var callbackName=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).callbackName;return function(accessor,context){var propName=context.name.toString();var updateMethodName=callbackName!==null&&callbackName!==void 0?callbackName:"".concat(propName,"Update");return {init:function init(initialValue){var zuiThis=this;var triggerUpdate=function(){queueMicrotask(function(){if(typeof zuiThis[updateMethodName]==="function"){zuiThis[updateMethodName](initialValue,initialValue);}});};var finalValue=initialValue;if(initialValue&&(typeof initialValue==="undefined"?"undefined":_type_of(initialValue))==="object"){finalValue=
|
|
7
|
+
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var state=function(){var callbackName=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).callbackName;return function(accessor,context){var propName=context.name.toString();var updateMethodName=callbackName!==null&&callbackName!==void 0?callbackName:"".concat(propName,"Update");return {init:function init(initialValue){var zuiThis=this;var triggerUpdate=function(){queueMicrotask(function(){if(typeof zuiThis[updateMethodName]==="function"){zuiThis[updateMethodName](initialValue,initialValue);}});};var finalValue=initialValue;if(initialValue&&(typeof initialValue==="undefined"?"undefined":_type_of(initialValue))==="object"){finalValue=utilities_makeReactive.makeReactive(initialValue,triggerUpdate);}triggerUpdate();return finalValue},get:function get(){return accessor.get.call(this)},set:function set(newValue){var zuiThis=this;var triggerUpdate=function(){queueMicrotask(function(){if(typeof zuiThis[updateMethodName]==="function"){zuiThis[updateMethodName](newValue,newValue);}});};var finalValue=newValue;if(newValue&&(typeof newValue==="undefined"?"undefined":_type_of(newValue))==="object"){finalValue=utilities_makeReactive.makeReactive(newValue,triggerUpdate);}accessor.set.call(this,finalValue);triggerUpdate();}}}};
|
|
8
8
|
|
|
9
9
|
exports.state = state;
|
|
@@ -1,10 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview State decorator for reactive internal state management in ZUI components.
|
|
3
|
+
* Provides reactive state that triggers updates without reflecting to DOM attributes.
|
|
4
|
+
*
|
|
5
|
+
* @module state
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the @state decorator.
|
|
9
|
+
*
|
|
10
|
+
* @interface StateOptions
|
|
11
|
+
* @property {string} [callbackName] - Custom update callback method name
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* @state({ callbackName: 'onHistoryChange' })
|
|
15
|
+
* accessor history: number[] = [];
|
|
16
|
+
*/
|
|
1
17
|
export interface StateOptions {
|
|
2
18
|
callbackName?: string;
|
|
3
19
|
}
|
|
4
20
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
21
|
+
* Accessor decorator for internal reactive state that doesn't reflect to DOM attributes.
|
|
22
|
+
*
|
|
23
|
+
* Features:
|
|
24
|
+
* - Reactive state for objects and arrays
|
|
25
|
+
* - Automatic update callbacks on state changes
|
|
26
|
+
* - Deep reactivity with Proxy
|
|
27
|
+
* - No attribute reflection (unlike @property)
|
|
28
|
+
*
|
|
29
|
+
* @template T - Element type extending HTMLElement
|
|
30
|
+
* @template V - State value type
|
|
31
|
+
* @param {StateOptions} [options={}] - State configuration options
|
|
32
|
+
* @returns {ClassAccessorDecorator} An accessor decorator function
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Reactive array state
|
|
37
|
+
* @state()
|
|
38
|
+
* accessor items: string[] = [];
|
|
39
|
+
* // Calls itemsUpdate() on array mutations
|
|
40
|
+
*
|
|
41
|
+
* // Reactive object state
|
|
42
|
+
* @state()
|
|
43
|
+
* accessor user = { name: '', age: 0 };
|
|
44
|
+
* // Calls userUpdate() on property changes
|
|
45
|
+
*
|
|
46
|
+
* // With custom callback
|
|
47
|
+
* @state({ callbackName: 'onDataChange' })
|
|
48
|
+
* accessor data = {};
|
|
49
|
+
* // Calls onDataChange() instead of dataUpdate()
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* - Best for complex objects, arrays, or private data
|
|
54
|
+
* - Uses Proxy for deep reactivity
|
|
55
|
+
* - Update callbacks receive (oldValue, newValue)
|
|
56
|
+
* - Changes are batched with queueMicrotask
|
|
57
|
+
*
|
|
58
|
+
* @see {@link makeReactive}
|
|
8
59
|
*/
|
|
9
60
|
export declare const state: ({ callbackName }?: StateOptions) => <T extends HTMLElement, V>(accessor: {
|
|
10
61
|
get: (this: T) => V;
|
package/dist/decorators/state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { makeReactive } from '../utilities.js';
|
|
1
|
+
import { makeReactive } from '../utilities/makeReactive.js';
|
|
2
2
|
|
|
3
3
|
function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}var state=function(){var callbackName=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).callbackName;return function(accessor,context){var propName=context.name.toString();var updateMethodName=callbackName!==null&&callbackName!==void 0?callbackName:"".concat(propName,"Update");return {init:function init(initialValue){var zuiThis=this;var triggerUpdate=function(){queueMicrotask(function(){if(typeof zuiThis[updateMethodName]==="function"){zuiThis[updateMethodName](initialValue,initialValue);}});};var finalValue=initialValue;if(initialValue&&(typeof initialValue==="undefined"?"undefined":_type_of(initialValue))==="object"){finalValue=makeReactive(initialValue,triggerUpdate);}triggerUpdate();return finalValue},get:function get(){return accessor.get.call(this)},set:function set(newValue){var zuiThis=this;var triggerUpdate=function(){queueMicrotask(function(){if(typeof zuiThis[updateMethodName]==="function"){zuiThis[updateMethodName](newValue,newValue);}});};var finalValue=newValue;if(newValue&&(typeof newValue==="undefined"?"undefined":_type_of(newValue))==="object"){finalValue=makeReactive(newValue,triggerUpdate);}accessor.set.call(this,finalValue);triggerUpdate();}}}};
|
|
4
4
|
|