@sun-panel/micro-app 1.0.9 → 1.0.10

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.
@@ -20,4 +20,4 @@ const b=globalThis,E=t=>t,C=b.trustedTypes,w=C?C.createPolicy("lit-html",{create
20
20
  * @license
21
21
  * Copyright 2017 Google LLC
22
22
  * SPDX-License-Identifier: BSD-3-Clause
23
- */class ot extends v{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=s?.renderBefore??e;let n=i._$litPart$;if(void 0===n){const t=s?.renderBefore??null;i._$litPart$=n=new X(e.insertBefore(O(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return B}}ot._$litElement$=!0,ot.finalized=!0,rt.litElementHydrateSupport?.({LitElement:ot});const at=rt.litElementPolyfillSupport;at?.({LitElement:ot}),(rt.litElementVersions??=[]).push("4.2.2");class ht extends ot{constructor(){super(),this._initialized=!1,this._eventListeners=new Map}initializeMicroApp(){this._initialized||(this._setupEventListeners(),this._initialized=!0)}connectedCallback(){super.connectedCallback(),this.initializeMicroApp(),this.onConnected()}disconnectedCallback(){super.disconnectedCallback(),this._cleanupEventListeners(),this.onDisconnected()}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.onAttributeChanged(t,e,s)}_setupEventListeners(){}_cleanupEventListeners(){const t=Array.from(this._eventListeners.entries());for(const[e,s]of t)s.forEach(t=>{window.removeEventListener(e,t)});this._eventListeners.clear()}addEventListener(t,e,s){super.addEventListener(t,e,s)}dispatchCustomEvent(t,e){const s=new CustomEvent(t,{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}onConnected(){}onDisconnected(){}onAttributeChanged(t,e,s){}render(){return V``}}class lt extends ht{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,widgetInfo:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.widgetInfo!==e.widgetInfo&&this.onWidgetInfoChanged(s.widgetInfo,e.widgetInfo),s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized()}onInitialized(){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}onWidgetInfoChanged(t,e){}render(){return V``}}lt.properties={spCtx:{type:Object,attribute:!1}};class dt extends ht{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,background:"",widgetInfo:{},customParam:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized({widgetInfo:this.spCtx.widgetInfo,customParam:this.spCtx.customParam})}onInitialized(t){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}render(){return V``}}dt.properties={spCtx:{type:Object,attribute:!1}};class ct extends Error{constructor(t){super(`Validation failed: ${t.map(t=>t.message).join(", ")}`),this.name="ValidationError",this.errors=t}}class pt{static async validateField(t,e,s="field"){const i=[];if(e.required&&(null==t||""===t))return i.push({field:s,message:e.message||`${s} is required`,value:t}),i;if(null==t||""===t)return i;if(e.type){let n=!1;switch(e.type){case"string":n="string"==typeof t;break;case"number":n="number"==typeof t&&!isNaN(t);break;case"boolean":n="boolean"==typeof t;break;case"object":n="object"==typeof t&&null!==t&&!Array.isArray(t);break;case"array":n=Array.isArray(t);break;case"date":n=t instanceof Date||!isNaN(Date.parse(t));break;case"email":n="string"==typeof t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);break;case"url":try{new URL(t),n=!0}catch{n=!1}break;default:n=!0}n||i.push({field:s,message:e.message||`${s} must be of type ${e.type}`,value:t})}if(void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&i.push({field:s,message:e.message||`${s} must be at least ${e.minLength} characters`,value:t}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&i.push({field:s,message:e.message||`${s} must be no more than ${e.maxLength} characters`,value:t}),void 0!==e.min&&"number"==typeof t&&t<e.min&&i.push({field:s,message:e.message||`${s} must be at least ${e.min}`,value:t}),void 0!==e.max&&"number"==typeof t&&t>e.max&&i.push({field:s,message:e.message||`${s} must be no more than ${e.max}`,value:t}),e.pattern&&"string"==typeof t&&!e.pattern.test(t)&&i.push({field:s,message:e.message||`${s} format is invalid`,value:t}),e.validator)try{const n=await Promise.resolve(e.validator(t));"string"==typeof n?i.push({field:s,message:n,value:t}):!1===n&&i.push({field:s,message:e.message||`${s} is invalid`,value:t})}catch(n){i.push({field:s,message:e.message||`Validation failed for ${s}: ${n instanceof Error?n.message:String(n)}`,value:t})}return i}static async validateObject(t,e){const s=[];for(const i of Object.keys(e)){const n=e[i],r=t[i],o=await this.validateField(r,n,i);s.push(...o)}return s}static async validateArray(t,e){if(!Array.isArray(t))return[{field:"array",message:"Value must be an array",value:t}];const s=[];if(void 0!==e.min&&t.length<e.min&&s.push({field:"array",message:e.message||`Array must have at least ${e.min} items`,value:t}),void 0!==e.max&&t.length>e.max&&s.push({field:"array",message:e.message||`Array must have no more than ${e.max} items`,value:t}),e.validator)for(let i=0;i<t.length;i++){const n=t[i],r=await this.validateField(n,e,`array[${i}]`);s.push(...r)}return s}}t.FormValidator=class{constructor(t){this.rules=t}async validate(t){return await pt.validateObject(t,this.rules)}async validateOrThrow(t){const e=await this.validate(t);if(e.length>0)throw new ct(e)}},t.SunPanelElement=ht,t.SunPanelPageElement=dt,t.SunPanelWidgetElement=lt,t.VERSION='"1.0.9"',t.ValidationError=ct,t.Validator=pt}(this.SunPanelMicroApp=this.SunPanelMicroApp||{});
23
+ */class ot extends v{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=s?.renderBefore??e;let n=i._$litPart$;if(void 0===n){const t=s?.renderBefore??null;i._$litPart$=n=new X(e.insertBefore(O(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return B}}ot._$litElement$=!0,ot.finalized=!0,rt.litElementHydrateSupport?.({LitElement:ot});const at=rt.litElementPolyfillSupport;at?.({LitElement:ot}),(rt.litElementVersions??=[]).push("4.2.2");class ht extends ot{constructor(){super(),this._initialized=!1,this._eventListeners=new Map}initializeMicroApp(){this._initialized||(this._setupEventListeners(),this._initialized=!0)}connectedCallback(){super.connectedCallback(),this.initializeMicroApp(),this.onConnected()}disconnectedCallback(){super.disconnectedCallback(),this._cleanupEventListeners(),this.onDisconnected()}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.onAttributeChanged(t,e,s)}_setupEventListeners(){}_cleanupEventListeners(){const t=Array.from(this._eventListeners.entries());for(const[e,s]of t)s.forEach(t=>{window.removeEventListener(e,t)});this._eventListeners.clear()}addEventListener(t,e,s){super.addEventListener(t,e,s)}dispatchCustomEvent(t,e){const s=new CustomEvent(t,{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}onConnected(){}onDisconnected(){}onAttributeChanged(t,e,s){}render(){return V``}}class lt extends ht{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,widgetInfo:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.widgetInfo!==e.widgetInfo&&this.onWidgetInfoChanged(s.widgetInfo,e.widgetInfo),s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized()}onInitialized(){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}onWidgetInfoChanged(t,e){}render(){return V``}}lt.properties={spCtx:{type:Object,attribute:!1}};class dt extends ht{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,background:"",widgetInfo:{},customParam:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized({widgetInfo:this.spCtx.widgetInfo,customParam:this.spCtx.customParam})}onInitialized(t){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}render(){return V``}}dt.properties={spCtx:{type:Object,attribute:!1}};class ct extends Error{constructor(t){super(`Validation failed: ${t.map(t=>t.message).join(", ")}`),this.name="ValidationError",this.errors=t}}class pt{static async validateField(t,e,s="field"){const i=[];if(e.required&&(null==t||""===t))return i.push({field:s,message:e.message||`${s} is required`,value:t}),i;if(null==t||""===t)return i;if(e.type){let n=!1;switch(e.type){case"string":n="string"==typeof t;break;case"number":n="number"==typeof t&&!isNaN(t);break;case"boolean":n="boolean"==typeof t;break;case"object":n="object"==typeof t&&null!==t&&!Array.isArray(t);break;case"array":n=Array.isArray(t);break;case"date":n=t instanceof Date||!isNaN(Date.parse(t));break;case"email":n="string"==typeof t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);break;case"url":try{new URL(t),n=!0}catch{n=!1}break;default:n=!0}n||i.push({field:s,message:e.message||`${s} must be of type ${e.type}`,value:t})}if(void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&i.push({field:s,message:e.message||`${s} must be at least ${e.minLength} characters`,value:t}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&i.push({field:s,message:e.message||`${s} must be no more than ${e.maxLength} characters`,value:t}),void 0!==e.min&&"number"==typeof t&&t<e.min&&i.push({field:s,message:e.message||`${s} must be at least ${e.min}`,value:t}),void 0!==e.max&&"number"==typeof t&&t>e.max&&i.push({field:s,message:e.message||`${s} must be no more than ${e.max}`,value:t}),e.pattern&&"string"==typeof t&&!e.pattern.test(t)&&i.push({field:s,message:e.message||`${s} format is invalid`,value:t}),e.validator)try{const n=await Promise.resolve(e.validator(t));"string"==typeof n?i.push({field:s,message:n,value:t}):!1===n&&i.push({field:s,message:e.message||`${s} is invalid`,value:t})}catch(n){i.push({field:s,message:e.message||`Validation failed for ${s}: ${n instanceof Error?n.message:String(n)}`,value:t})}return i}static async validateObject(t,e){const s=[];for(const i of Object.keys(e)){const n=e[i],r=t[i],o=await this.validateField(r,n,i);s.push(...o)}return s}static async validateArray(t,e){if(!Array.isArray(t))return[{field:"array",message:"Value must be an array",value:t}];const s=[];if(void 0!==e.min&&t.length<e.min&&s.push({field:"array",message:e.message||`Array must have at least ${e.min} items`,value:t}),void 0!==e.max&&t.length>e.max&&s.push({field:"array",message:e.message||`Array must have no more than ${e.max} items`,value:t}),e.validator)for(let i=0;i<t.length;i++){const n=t[i],r=await this.validateField(n,e,`array[${i}]`);s.push(...r)}return s}}t.FormValidator=class{constructor(t){this.rules=t}async validate(t){return await pt.validateObject(t,this.rules)}async validateOrThrow(t){const e=await this.validate(t);if(e.length>0)throw new ct(e)}},t.SunPanelElement=ht,t.SunPanelPageElement=dt,t.SunPanelWidgetElement=lt,t.VERSION='"1.0.10"',t.ValidationError=ct,t.Validator=pt}(this.SunPanelMicroApp=this.SunPanelMicroApp||{});
package/dist/index.d.ts CHANGED
@@ -1,72 +1,28 @@
1
1
  /**
2
- * Sun Panel Micro App - 主类型定义文件
2
+ * Sun Panel Micro App - 主入口文件
3
3
  */
4
-
5
- import { LitElement, TemplateResult } from 'lit';
6
-
7
- // ============ Global Declarations ============
8
-
4
+ export { SunPanelElement } from './SunPanelElement.js';
5
+ export { SunPanelWidgetElement } from './SunPanelWidgetElement.js';
6
+ export { SunPanelPageElement } from './SunPanelPageElement.js';
7
+ export { Validator, FormValidator, ValidationError } from './validation.js';
8
+ export type { ValidationRule, ValidationErrorItem } from './validation.js';
9
+ export type { MicroAppAPI, MicroAppNetworkRequestError, MicroDataNodeError, TemplateReplacementRule, WindowConfig, OpenWindowOptions, WindowInitializedParam, RequestOptions } from './types/api.js';
10
+ export type { SpContext, SpContextWidget, SpContextPage, WidgetInfo, PageInitializedParam, NetworkMode, RoleType, GridSizeType, BackgroundType, ChangedProperties } from './types/common.js';
11
+ export type Theme = 'light' | 'dark';
12
+ export declare const VERSION = "__VERSION__";
9
13
  declare global {
10
- interface HTMLElement {
11
- /** 应用ID */
12
- appId?: string;
13
-
14
- /** 应用版本 */
15
- appVersion?: string;
16
-
17
- /** 配置对象 */
18
- config?: Record<string, any>;
19
-
20
- /** 主题 */
21
- theme?: 'light' | 'dark';
22
-
23
- /** 语言 */
24
- language?: string;
25
-
26
- /** 是否激活 */
27
- isActive?: boolean;
28
- }
14
+ interface HTMLElement {
15
+ /** 应用ID */
16
+ appId?: string;
17
+ /** 应用版本 */
18
+ appVersion?: string;
19
+ /** 配置对象 */
20
+ config?: Record<string, any>;
21
+ /** 主题 */
22
+ theme?: 'light' | 'dark';
23
+ /** 语言 */
24
+ language?: string;
25
+ /** 是否激活 */
26
+ isActive?: boolean;
27
+ }
29
28
  }
30
-
31
- // ============ Re-exports ============
32
-
33
- // API 类型
34
- export {
35
- WindowConfig,
36
- OpenWindowOptions,
37
- WindowInitializedParam,
38
- RequestOptions,
39
- MicroAppAPI
40
- } from './types/api';
41
-
42
- // 元素类型
43
- export type Theme = 'light' | 'dark';
44
- export {
45
- SunPanelElement
46
- } from './SunPanelElement';
47
- export {
48
- SunPanelWidgetElement
49
- } from './SunPanelWidgetElement';
50
- export {
51
- SunPanelPageElement
52
- } from './SunPanelPageElement';
53
-
54
- // 上下文类型
55
- export type {
56
- SpContext,
57
- SpContextWidget,
58
- SpContextPage,
59
- WidgetInfo
60
- } from './types/common';
61
-
62
- // 验证类型
63
- export {
64
- ValidationRule,
65
- ValidationErrorItem,
66
- ValidationError,
67
- Validator,
68
- FormValidator
69
- } from './validation';
70
-
71
- // 版本号
72
- export declare const VERSION: string;
package/dist/index.esm.js CHANGED
@@ -19,4 +19,4 @@ const v=globalThis,b=t=>t,C=v.trustedTypes,E=C?C.createPolicy("lit-html",{create
19
19
  * @license
20
20
  * Copyright 2017 Google LLC
21
21
  * SPDX-License-Identifier: BSD-3-Clause
22
- */class rt extends A{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=s?.renderBefore??e;let n=i._$litPart$;if(void 0===n){const t=s?.renderBefore??null;i._$litPart$=n=new Q(e.insertBefore(P(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return B}}rt._$litElement$=!0,rt.finalized=!0,nt.litElementHydrateSupport?.({LitElement:rt});const ot=nt.litElementPolyfillSupport;ot?.({LitElement:rt}),(nt.litElementVersions??=[]).push("4.2.2");class at extends rt{constructor(){super(),this._initialized=!1,this._eventListeners=new Map}initializeMicroApp(){this._initialized||(this._setupEventListeners(),this._initialized=!0)}connectedCallback(){super.connectedCallback(),this.initializeMicroApp(),this.onConnected()}disconnectedCallback(){super.disconnectedCallback(),this._cleanupEventListeners(),this.onDisconnected()}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.onAttributeChanged(t,e,s)}_setupEventListeners(){}_cleanupEventListeners(){const t=Array.from(this._eventListeners.entries());for(const[e,s]of t)s.forEach(t=>{window.removeEventListener(e,t)});this._eventListeners.clear()}addEventListener(t,e,s){super.addEventListener(t,e,s)}dispatchCustomEvent(t,e){const s=new CustomEvent(t,{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}onConnected(){}onDisconnected(){}onAttributeChanged(t,e,s){}render(){return D``}}class ht extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,widgetInfo:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.widgetInfo!==e.widgetInfo&&this.onWidgetInfoChanged(s.widgetInfo,e.widgetInfo),s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized()}onInitialized(){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}onWidgetInfoChanged(t,e){}render(){return D``}}ht.properties={spCtx:{type:Object,attribute:!1}};class dt extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,background:"",widgetInfo:{},customParam:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized({widgetInfo:this.spCtx.widgetInfo,customParam:this.spCtx.customParam})}onInitialized(t){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}render(){return D``}}dt.properties={spCtx:{type:Object,attribute:!1}};class lt extends Error{constructor(t){super(`Validation failed: ${t.map(t=>t.message).join(", ")}`),this.name="ValidationError",this.errors=t}}class ct{static async validateField(t,e,s="field"){const i=[];if(e.required&&(null==t||""===t))return i.push({field:s,message:e.message||`${s} is required`,value:t}),i;if(null==t||""===t)return i;if(e.type){let n=!1;switch(e.type){case"string":n="string"==typeof t;break;case"number":n="number"==typeof t&&!isNaN(t);break;case"boolean":n="boolean"==typeof t;break;case"object":n="object"==typeof t&&null!==t&&!Array.isArray(t);break;case"array":n=Array.isArray(t);break;case"date":n=t instanceof Date||!isNaN(Date.parse(t));break;case"email":n="string"==typeof t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);break;case"url":try{new URL(t),n=!0}catch{n=!1}break;default:n=!0}n||i.push({field:s,message:e.message||`${s} must be of type ${e.type}`,value:t})}if(void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&i.push({field:s,message:e.message||`${s} must be at least ${e.minLength} characters`,value:t}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&i.push({field:s,message:e.message||`${s} must be no more than ${e.maxLength} characters`,value:t}),void 0!==e.min&&"number"==typeof t&&t<e.min&&i.push({field:s,message:e.message||`${s} must be at least ${e.min}`,value:t}),void 0!==e.max&&"number"==typeof t&&t>e.max&&i.push({field:s,message:e.message||`${s} must be no more than ${e.max}`,value:t}),e.pattern&&"string"==typeof t&&!e.pattern.test(t)&&i.push({field:s,message:e.message||`${s} format is invalid`,value:t}),e.validator)try{const n=await Promise.resolve(e.validator(t));"string"==typeof n?i.push({field:s,message:n,value:t}):!1===n&&i.push({field:s,message:e.message||`${s} is invalid`,value:t})}catch(n){i.push({field:s,message:e.message||`Validation failed for ${s}: ${n instanceof Error?n.message:String(n)}`,value:t})}return i}static async validateObject(t,e){const s=[];for(const i of Object.keys(e)){const n=e[i],r=t[i],o=await this.validateField(r,n,i);s.push(...o)}return s}static async validateArray(t,e){if(!Array.isArray(t))return[{field:"array",message:"Value must be an array",value:t}];const s=[];if(void 0!==e.min&&t.length<e.min&&s.push({field:"array",message:e.message||`Array must have at least ${e.min} items`,value:t}),void 0!==e.max&&t.length>e.max&&s.push({field:"array",message:e.message||`Array must have no more than ${e.max} items`,value:t}),e.validator)for(let i=0;i<t.length;i++){const n=t[i],r=await this.validateField(n,e,`array[${i}]`);s.push(...r)}return s}}class pt{constructor(t){this.rules=t}async validate(t){return await ct.validateObject(t,this.rules)}async validateOrThrow(t){const e=await this.validate(t);if(e.length>0)throw new lt(e)}}const ut='"1.0.9"';export{pt as FormValidator,at as SunPanelElement,dt as SunPanelPageElement,ht as SunPanelWidgetElement,ut as VERSION,lt as ValidationError,ct as Validator};
22
+ */class rt extends A{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=s?.renderBefore??e;let n=i._$litPart$;if(void 0===n){const t=s?.renderBefore??null;i._$litPart$=n=new Q(e.insertBefore(P(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return B}}rt._$litElement$=!0,rt.finalized=!0,nt.litElementHydrateSupport?.({LitElement:rt});const ot=nt.litElementPolyfillSupport;ot?.({LitElement:rt}),(nt.litElementVersions??=[]).push("4.2.2");class at extends rt{constructor(){super(),this._initialized=!1,this._eventListeners=new Map}initializeMicroApp(){this._initialized||(this._setupEventListeners(),this._initialized=!0)}connectedCallback(){super.connectedCallback(),this.initializeMicroApp(),this.onConnected()}disconnectedCallback(){super.disconnectedCallback(),this._cleanupEventListeners(),this.onDisconnected()}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.onAttributeChanged(t,e,s)}_setupEventListeners(){}_cleanupEventListeners(){const t=Array.from(this._eventListeners.entries());for(const[e,s]of t)s.forEach(t=>{window.removeEventListener(e,t)});this._eventListeners.clear()}addEventListener(t,e,s){super.addEventListener(t,e,s)}dispatchCustomEvent(t,e){const s=new CustomEvent(t,{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}onConnected(){}onDisconnected(){}onAttributeChanged(t,e,s){}render(){return D``}}class ht extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,widgetInfo:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.widgetInfo!==e.widgetInfo&&this.onWidgetInfoChanged(s.widgetInfo,e.widgetInfo),s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized()}onInitialized(){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}onWidgetInfoChanged(t,e){}render(){return D``}}ht.properties={spCtx:{type:Object,attribute:!1}};class dt extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,background:"",widgetInfo:{},customParam:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized({widgetInfo:this.spCtx.widgetInfo,customParam:this.spCtx.customParam})}onInitialized(t){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}render(){return D``}}dt.properties={spCtx:{type:Object,attribute:!1}};class lt extends Error{constructor(t){super(`Validation failed: ${t.map(t=>t.message).join(", ")}`),this.name="ValidationError",this.errors=t}}class ct{static async validateField(t,e,s="field"){const i=[];if(e.required&&(null==t||""===t))return i.push({field:s,message:e.message||`${s} is required`,value:t}),i;if(null==t||""===t)return i;if(e.type){let n=!1;switch(e.type){case"string":n="string"==typeof t;break;case"number":n="number"==typeof t&&!isNaN(t);break;case"boolean":n="boolean"==typeof t;break;case"object":n="object"==typeof t&&null!==t&&!Array.isArray(t);break;case"array":n=Array.isArray(t);break;case"date":n=t instanceof Date||!isNaN(Date.parse(t));break;case"email":n="string"==typeof t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);break;case"url":try{new URL(t),n=!0}catch{n=!1}break;default:n=!0}n||i.push({field:s,message:e.message||`${s} must be of type ${e.type}`,value:t})}if(void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&i.push({field:s,message:e.message||`${s} must be at least ${e.minLength} characters`,value:t}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&i.push({field:s,message:e.message||`${s} must be no more than ${e.maxLength} characters`,value:t}),void 0!==e.min&&"number"==typeof t&&t<e.min&&i.push({field:s,message:e.message||`${s} must be at least ${e.min}`,value:t}),void 0!==e.max&&"number"==typeof t&&t>e.max&&i.push({field:s,message:e.message||`${s} must be no more than ${e.max}`,value:t}),e.pattern&&"string"==typeof t&&!e.pattern.test(t)&&i.push({field:s,message:e.message||`${s} format is invalid`,value:t}),e.validator)try{const n=await Promise.resolve(e.validator(t));"string"==typeof n?i.push({field:s,message:n,value:t}):!1===n&&i.push({field:s,message:e.message||`${s} is invalid`,value:t})}catch(n){i.push({field:s,message:e.message||`Validation failed for ${s}: ${n instanceof Error?n.message:String(n)}`,value:t})}return i}static async validateObject(t,e){const s=[];for(const i of Object.keys(e)){const n=e[i],r=t[i],o=await this.validateField(r,n,i);s.push(...o)}return s}static async validateArray(t,e){if(!Array.isArray(t))return[{field:"array",message:"Value must be an array",value:t}];const s=[];if(void 0!==e.min&&t.length<e.min&&s.push({field:"array",message:e.message||`Array must have at least ${e.min} items`,value:t}),void 0!==e.max&&t.length>e.max&&s.push({field:"array",message:e.message||`Array must have no more than ${e.max} items`,value:t}),e.validator)for(let i=0;i<t.length;i++){const n=t[i],r=await this.validateField(n,e,`array[${i}]`);s.push(...r)}return s}}class pt{constructor(t){this.rules=t}async validate(t){return await ct.validateObject(t,this.rules)}async validateOrThrow(t){const e=await this.validate(t);if(e.length>0)throw new lt(e)}}const ut='"1.0.10"';export{pt as FormValidator,at as SunPanelElement,dt as SunPanelPageElement,ht as SunPanelWidgetElement,ut as VERSION,lt as ValidationError,ct as Validator};
package/dist/index.js CHANGED
@@ -19,4 +19,4 @@ const v=globalThis,b=t=>t,E=v.trustedTypes,C=E?E.createPolicy("lit-html",{create
19
19
  * @license
20
20
  * Copyright 2017 Google LLC
21
21
  * SPDX-License-Identifier: BSD-3-Clause
22
- */class rt extends A{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=s?.renderBefore??e;let n=i._$litPart$;if(void 0===n){const t=s?.renderBefore??null;i._$litPart$=n=new Q(e.insertBefore(P(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return V}}rt._$litElement$=!0,rt.finalized=!0,nt.litElementHydrateSupport?.({LitElement:rt});const ot=nt.litElementPolyfillSupport;ot?.({LitElement:rt}),(nt.litElementVersions??=[]).push("4.2.2");class at extends rt{constructor(){super(),this._initialized=!1,this._eventListeners=new Map}initializeMicroApp(){this._initialized||(this._setupEventListeners(),this._initialized=!0)}connectedCallback(){super.connectedCallback(),this.initializeMicroApp(),this.onConnected()}disconnectedCallback(){super.disconnectedCallback(),this._cleanupEventListeners(),this.onDisconnected()}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.onAttributeChanged(t,e,s)}_setupEventListeners(){}_cleanupEventListeners(){const t=Array.from(this._eventListeners.entries());for(const[e,s]of t)s.forEach(t=>{window.removeEventListener(e,t)});this._eventListeners.clear()}addEventListener(t,e,s){super.addEventListener(t,e,s)}dispatchCustomEvent(t,e){const s=new CustomEvent(t,{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}onConnected(){}onDisconnected(){}onAttributeChanged(t,e,s){}render(){return D``}}class ht extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,widgetInfo:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.widgetInfo!==e.widgetInfo&&this.onWidgetInfoChanged(s.widgetInfo,e.widgetInfo),s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized()}onInitialized(){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}onWidgetInfoChanged(t,e){}render(){return D``}}ht.properties={spCtx:{type:Object,attribute:!1}};class dt extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,background:"",widgetInfo:{},customParam:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized({widgetInfo:this.spCtx.widgetInfo,customParam:this.spCtx.customParam})}onInitialized(t){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}render(){return D``}}dt.properties={spCtx:{type:Object,attribute:!1}};class lt extends Error{constructor(t){super(`Validation failed: ${t.map(t=>t.message).join(", ")}`),this.name="ValidationError",this.errors=t}}class ct{static async validateField(t,e,s="field"){const i=[];if(e.required&&(null==t||""===t))return i.push({field:s,message:e.message||`${s} is required`,value:t}),i;if(null==t||""===t)return i;if(e.type){let n=!1;switch(e.type){case"string":n="string"==typeof t;break;case"number":n="number"==typeof t&&!isNaN(t);break;case"boolean":n="boolean"==typeof t;break;case"object":n="object"==typeof t&&null!==t&&!Array.isArray(t);break;case"array":n=Array.isArray(t);break;case"date":n=t instanceof Date||!isNaN(Date.parse(t));break;case"email":n="string"==typeof t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);break;case"url":try{new URL(t),n=!0}catch{n=!1}break;default:n=!0}n||i.push({field:s,message:e.message||`${s} must be of type ${e.type}`,value:t})}if(void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&i.push({field:s,message:e.message||`${s} must be at least ${e.minLength} characters`,value:t}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&i.push({field:s,message:e.message||`${s} must be no more than ${e.maxLength} characters`,value:t}),void 0!==e.min&&"number"==typeof t&&t<e.min&&i.push({field:s,message:e.message||`${s} must be at least ${e.min}`,value:t}),void 0!==e.max&&"number"==typeof t&&t>e.max&&i.push({field:s,message:e.message||`${s} must be no more than ${e.max}`,value:t}),e.pattern&&"string"==typeof t&&!e.pattern.test(t)&&i.push({field:s,message:e.message||`${s} format is invalid`,value:t}),e.validator)try{const n=await Promise.resolve(e.validator(t));"string"==typeof n?i.push({field:s,message:n,value:t}):!1===n&&i.push({field:s,message:e.message||`${s} is invalid`,value:t})}catch(n){i.push({field:s,message:e.message||`Validation failed for ${s}: ${n instanceof Error?n.message:String(n)}`,value:t})}return i}static async validateObject(t,e){const s=[];for(const i of Object.keys(e)){const n=e[i],r=t[i],o=await this.validateField(r,n,i);s.push(...o)}return s}static async validateArray(t,e){if(!Array.isArray(t))return[{field:"array",message:"Value must be an array",value:t}];const s=[];if(void 0!==e.min&&t.length<e.min&&s.push({field:"array",message:e.message||`Array must have at least ${e.min} items`,value:t}),void 0!==e.max&&t.length>e.max&&s.push({field:"array",message:e.message||`Array must have no more than ${e.max} items`,value:t}),e.validator)for(let i=0;i<t.length;i++){const n=t[i],r=await this.validateField(n,e,`array[${i}]`);s.push(...r)}return s}}exports.FormValidator=class{constructor(t){this.rules=t}async validate(t){return await ct.validateObject(t,this.rules)}async validateOrThrow(t){const e=await this.validate(t);if(e.length>0)throw new lt(e)}},exports.SunPanelElement=at,exports.SunPanelPageElement=dt,exports.SunPanelWidgetElement=ht,exports.VERSION='"1.0.9"',exports.ValidationError=lt,exports.Validator=ct;
22
+ */class rt extends A{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=s?.renderBefore??e;let n=i._$litPart$;if(void 0===n){const t=s?.renderBefore??null;i._$litPart$=n=new Q(e.insertBefore(P(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return V}}rt._$litElement$=!0,rt.finalized=!0,nt.litElementHydrateSupport?.({LitElement:rt});const ot=nt.litElementPolyfillSupport;ot?.({LitElement:rt}),(nt.litElementVersions??=[]).push("4.2.2");class at extends rt{constructor(){super(),this._initialized=!1,this._eventListeners=new Map}initializeMicroApp(){this._initialized||(this._setupEventListeners(),this._initialized=!0)}connectedCallback(){super.connectedCallback(),this.initializeMicroApp(),this.onConnected()}disconnectedCallback(){super.disconnectedCallback(),this._cleanupEventListeners(),this.onDisconnected()}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.onAttributeChanged(t,e,s)}_setupEventListeners(){}_cleanupEventListeners(){const t=Array.from(this._eventListeners.entries());for(const[e,s]of t)s.forEach(t=>{window.removeEventListener(e,t)});this._eventListeners.clear()}addEventListener(t,e,s){super.addEventListener(t,e,s)}dispatchCustomEvent(t,e){const s=new CustomEvent(t,{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}onConnected(){}onDisconnected(){}onAttributeChanged(t,e,s){}render(){return D``}}class ht extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,widgetInfo:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.widgetInfo!==e.widgetInfo&&this.onWidgetInfoChanged(s.widgetInfo,e.widgetInfo),s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized()}onInitialized(){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}onWidgetInfoChanged(t,e){}render(){return D``}}ht.properties={spCtx:{type:Object,attribute:!1}};class dt extends at{constructor(){super(),this.spCtx={api:{},darkMode:!1,language:"zh-CN",networkMode:"wan",staticPath:"",role:0,background:"",widgetInfo:{},customParam:{}}}updateContext(t){if(!t||"object"!=typeof t)return;const e=Object.fromEntries(Object.entries(t).filter(([t,e])=>void 0!==e));this.spCtx={...this.spCtx,...e}}firstUpdated(t){super.firstUpdated?.(t),this.onFirstRendered()}updated(t){if(super.updated(t),t.has("spCtx")){const e=t.get("spCtx")||{},s=this.spCtx;s.darkMode!==e.darkMode&&this.onDarkModeChanged(s.darkMode,e.darkMode),s.language!==e.language&&this.onLanguageChanged(s.language,e.language),s.networkMode!==e.networkMode&&this.onNetworkModeChanged(s.networkMode,e.networkMode)}}onConnected(){super.onConnected(),this.onInitialized({widgetInfo:this.spCtx.widgetInfo,customParam:this.spCtx.customParam})}onInitialized(t){}onFirstRendered(){}onDarkModeChanged(t,e){}onLanguageChanged(t,e){}onNetworkModeChanged(t,e){}render(){return D``}}dt.properties={spCtx:{type:Object,attribute:!1}};class lt extends Error{constructor(t){super(`Validation failed: ${t.map(t=>t.message).join(", ")}`),this.name="ValidationError",this.errors=t}}class ct{static async validateField(t,e,s="field"){const i=[];if(e.required&&(null==t||""===t))return i.push({field:s,message:e.message||`${s} is required`,value:t}),i;if(null==t||""===t)return i;if(e.type){let n=!1;switch(e.type){case"string":n="string"==typeof t;break;case"number":n="number"==typeof t&&!isNaN(t);break;case"boolean":n="boolean"==typeof t;break;case"object":n="object"==typeof t&&null!==t&&!Array.isArray(t);break;case"array":n=Array.isArray(t);break;case"date":n=t instanceof Date||!isNaN(Date.parse(t));break;case"email":n="string"==typeof t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);break;case"url":try{new URL(t),n=!0}catch{n=!1}break;default:n=!0}n||i.push({field:s,message:e.message||`${s} must be of type ${e.type}`,value:t})}if(void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&i.push({field:s,message:e.message||`${s} must be at least ${e.minLength} characters`,value:t}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&i.push({field:s,message:e.message||`${s} must be no more than ${e.maxLength} characters`,value:t}),void 0!==e.min&&"number"==typeof t&&t<e.min&&i.push({field:s,message:e.message||`${s} must be at least ${e.min}`,value:t}),void 0!==e.max&&"number"==typeof t&&t>e.max&&i.push({field:s,message:e.message||`${s} must be no more than ${e.max}`,value:t}),e.pattern&&"string"==typeof t&&!e.pattern.test(t)&&i.push({field:s,message:e.message||`${s} format is invalid`,value:t}),e.validator)try{const n=await Promise.resolve(e.validator(t));"string"==typeof n?i.push({field:s,message:n,value:t}):!1===n&&i.push({field:s,message:e.message||`${s} is invalid`,value:t})}catch(n){i.push({field:s,message:e.message||`Validation failed for ${s}: ${n instanceof Error?n.message:String(n)}`,value:t})}return i}static async validateObject(t,e){const s=[];for(const i of Object.keys(e)){const n=e[i],r=t[i],o=await this.validateField(r,n,i);s.push(...o)}return s}static async validateArray(t,e){if(!Array.isArray(t))return[{field:"array",message:"Value must be an array",value:t}];const s=[];if(void 0!==e.min&&t.length<e.min&&s.push({field:"array",message:e.message||`Array must have at least ${e.min} items`,value:t}),void 0!==e.max&&t.length>e.max&&s.push({field:"array",message:e.message||`Array must have no more than ${e.max} items`,value:t}),e.validator)for(let i=0;i<t.length;i++){const n=t[i],r=await this.validateField(n,e,`array[${i}]`);s.push(...r)}return s}}exports.FormValidator=class{constructor(t){this.rules=t}async validate(t){return await ct.validateObject(t,this.rules)}async validateOrThrow(t){const e=await this.validate(t);if(e.length>0)throw new lt(e)}},exports.SunPanelElement=at,exports.SunPanelPageElement=dt,exports.SunPanelWidgetElement=ht,exports.VERSION='"1.0.10"',exports.ValidationError=lt,exports.Validator=ct;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sun-panel/micro-app",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Sun Panel Micro App - A Lit-based framework for developing micro applications with built-in event binding and validation support",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -13,8 +13,7 @@
13
13
  }
14
14
  },
15
15
  "scripts": {
16
- "build": "rm -rf dist && rollup -c && tsc -p tsconfig.types.json && cp -r src/types dist/ && sed -i '' 's|../types/common.js|../types/common.js|g' dist/types/api.d.ts 2>/dev/null || sed -i 's|../types/common.js|../types/common.js|g' dist/types/api.d.ts 2>/dev/null || true",
17
- "postbuild": "node build-postprocess.js",
16
+ "build": "rm -rf dist && rollup -c && tsc -p tsconfig.types.json && cp -r src/types dist/",
18
17
  "dev": "rollup -c rollup.dev.config.js -w",
19
18
  "lint": "eslint src --ext .js,.ts",
20
19
  "test": "jest",