fix: fix urlsBegin bugs
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "@kevisual/container", | ||||
|   "version": "0.0.2", | ||||
|   "version": "0.0.2-alpha.1", | ||||
|   "description": "", | ||||
|   "main": "dist/index.js", | ||||
|   "publishConfig": { | ||||
|   | ||||
| @@ -82,7 +82,7 @@ export class CodeUrlManager { | ||||
| export const codeUrlManager = new CodeUrlManager(); | ||||
| const handleOneCode = async (data: RenderData) => { | ||||
|   const { code } = data; | ||||
|   const urlsBegin = ['http', 'https', 'blob', '/']; | ||||
|   const urlsBegin = ['http', 'https', 'blob', '//:']; | ||||
|   if (typeof code === 'string' && code && urlsBegin.find((item) => code.startsWith(item))) { | ||||
|     const importContent = await import(/* @vite-ignore */ code); | ||||
|     const { render, unmount, ...rest } = importContent || {}; | ||||
| @@ -174,6 +174,11 @@ export class Container { | ||||
|     } | ||||
|   } | ||||
|   async loadData(data: RenderData[], key: string = '') { | ||||
|     if (data.length === 0) { | ||||
|       this.data = data; | ||||
|       this.loaded = true; | ||||
|       return; | ||||
|     } | ||||
|     this.loading = true; | ||||
|     this.data = await handleCode(data); | ||||
|     this.loading = false; | ||||
| @@ -229,6 +234,7 @@ export class Container { | ||||
|  | ||||
|   renderChildren(cid: string, parentElement?: any, pid?: any): void | HTMLDivElement { | ||||
|     const data = this.data; | ||||
|     console.log('renderChildren', cid, data); | ||||
|     const globalCss = this.globalCss; | ||||
|     if (!parentElement) { | ||||
|       parentElement = this.root; | ||||
| @@ -264,17 +270,18 @@ export class Container { | ||||
|     el.classList.add(cid, 'kv-container'); | ||||
|     const { render, unmount } = (code as RenderCode) || {}; | ||||
|     let renderRoot = node.shadowRoot ? shadowRoot : root; | ||||
|     const ctx = { | ||||
|       root: root, | ||||
|       shadowRoot, | ||||
|       renderRoot, | ||||
|       event, | ||||
|       container: this, | ||||
|       code: code as RenderCode, | ||||
|       data: node, | ||||
|       css: shadowRoot ? css : globalCss, | ||||
|     }; | ||||
|     if (render) { | ||||
|       render({ | ||||
|         root: root, | ||||
|         shadowRoot, | ||||
|         renderRoot, | ||||
|         event, | ||||
|         container: this, | ||||
|         code: code as RenderCode, | ||||
|         data: node, | ||||
|         css: shadowRoot ? css : globalCss, | ||||
|       }); | ||||
|       render(ctx); | ||||
|     } else { | ||||
|       // no render, so no insert | ||||
|     } | ||||
| @@ -283,13 +290,13 @@ export class Container { | ||||
|       const destroy = (id: string) => { | ||||
|         if (id) { | ||||
|           if (id === cid || node?.parents?.find?.((item) => item === id)) { | ||||
|             unmount?.(); // 销毁父亲元素有这个元素的 | ||||
|             unmount?.(ctx); // 销毁父亲元素有这个元素的 | ||||
|             event.off('destroy', destroy); // 移除监听 | ||||
|           } else { | ||||
|             // console.warn('destroy id not found, and not find parentIds', id, 'currentid', cid); | ||||
|           } | ||||
|         } else if (!id) { | ||||
|           unmount?.(); //  所有的都销毁 | ||||
|           unmount?.(ctx); //  所有的都销毁 | ||||
|           event.off('destroy', destroy); | ||||
|         } | ||||
|         // 不需要销毁子元素 | ||||
| @@ -397,10 +404,12 @@ export class ContainerOne extends Container { | ||||
|     super(opts); | ||||
|   } | ||||
|   async renderOne({ code: RenderCode }) { | ||||
|     const newData = { id: 'test-render-one', code: RenderCode }; | ||||
|     const newData = { codeId: 'test-reneder-one-code-id', id: 'test-render-one', code: RenderCode }; | ||||
|     console.log('loading', this.loading); | ||||
|     if (this.loading) { | ||||
|       return; | ||||
|     } | ||||
|     console.log('renderOne', newData); | ||||
|     if (this.data.length === 0) { | ||||
|       await this.loadData([newData]); | ||||
|     } else { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user