@dooboostore/simple-web-component 1.0.28 → 1.0.30
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 +437 -25
- package/dist/cjs/decorators/attribute.js +2 -1
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +8 -2
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +4 -0
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +97 -0
- package/dist/cjs/decorators/setProperty.js.map +7 -0
- package/dist/cjs/elements/SwcAppEngine.js +3 -3
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +44 -6
- package/dist/cjs/elements/SwcAppMixin.js.map +3 -3
- package/dist/cjs/elements/SwcAsync.js +4 -1
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +54 -38
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/register.js +131 -39
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +30 -1
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/attribute.js +2 -1
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +8 -2
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +4 -0
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +78 -0
- package/dist/esm/decorators/setProperty.js.map +7 -0
- package/dist/esm/elements/SwcAppEngine.js +3 -3
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +44 -6
- package/dist/esm/elements/SwcAppMixin.js.map +3 -3
- package/dist/esm/elements/SwcAsync.js +4 -1
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +54 -38
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/register.js +131 -39
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +30 -1
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +118 -4
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +2 -0
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +13 -0
- package/dist/types/decorators/setProperty.d.ts.map +1 -0
- package/dist/types/elements/SwcAppMixin.d.ts +7 -2
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts.map +1 -1
- package/dist/types/elements/SwcChoose.d.ts +1 -1
- package/dist/types/elements/SwcChoose.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts +3 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +13 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +118 -4
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/decorators/attribute.ts +6 -1
- package/src/decorators/elementDefine.ts +12 -4
- package/src/decorators/emitCustomEvent.ts +1 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/lifecycles.ts +3 -0
- package/src/decorators/setProperty.ts +97 -0
- package/src/elements/SwcAppEngine.ts +3 -3
- package/src/elements/SwcAppMixin.ts +77 -14
- package/src/elements/SwcAsync.ts +5 -1
- package/src/elements/SwcChoose.ts +76 -37
- package/src/elements/register.ts +158 -39
- package/src/index.ts +3 -1
- package/src/types.ts +3 -0
- package/src/utils/Utils.ts +55 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAppMixin.ts"],
|
|
4
|
-
"sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';\nimport { SwcAppInterface } from '../types';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, Subscription } from '@dooboostore/core';\nimport { RouterEventType } from '@dooboostore/core-web';\nimport { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n return class extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n _invokeRouteChangeSubscribers(instance: any, re: RouterEventType) {\n const routeChangeSubscribers = getSubscribeSwcAppRouteChangeMetadata(instance);\n if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {\n routeChangeSubscribers.forEach((metadata: any) => {\n const methodName = metadata.propertyKey || metadata;\n const pathPattern = metadata.pathPattern;\n const filter = metadata.filter;\n\n // Path pattern matching (support both string and array)\n let pathMatched = false;\n let pathData: any = null;\n\n if (!pathPattern) {\n // pathPattern
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAA2D;AAEpE,SAAS,gBAAgB;AACzB,SAAS,qBAAmC;AAE5C,SAAS,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';\nimport { SwcAppInterface } from '../types';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, Subscription } from '@dooboostore/core';\nimport { Router, RouterEventType } from '@dooboostore/core-web';\nimport { ON_CONNECTED_SWC_APP_METADATA_KEY, findAllLifecycleMetadata } from '../decorators/lifecycles';\nimport { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n //@ts-ignore\n return class extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n\n /*\n 사파리 is 일경우\n <script src=\"https://unpkg.com/@ungap/custom-elements\"></script>\n 이걸사용하는데 is 대응하는거다 그런데 이때 처리되는 순서가 크롬이나 표준에서는 부모부터 만들어지고 자식들이 만들어지는데\n 저 polyfill에서는 자식부터 만들어지고 부모가 만들어진다 is일때 아 .. 이문제때문에 자식이 _connected_safari 에 강제로 자기자식넣어준다\n */\n _connected_safari = [];\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n // constructor() {\n // super();\n // console.log('cccccccccccccccccccccc');\n // }\n\n _invokeRouteChangeSubscribers(instance: any, re: RouterEventType) {\n const routeChangeSubscribers = getSubscribeSwcAppRouteChangeMetadata(instance);\n if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {\n routeChangeSubscribers.forEach((metadata: any) => {\n const methodName = metadata.propertyKey || metadata;\n const pathPattern = metadata.pathPattern;\n const filter = metadata.filter;\n\n // Path pattern matching (support both string and array)\n let pathMatched = false;\n let pathData: any = null;\n\n if (!pathPattern) {\n // pathPattern이 없으면 모든 경로 매칭 (와일드카드)\n pathMatched = true;\n pathData = {};\n } else if (Array.isArray(pathPattern)) {\n // 배열: 하나라도 매칭되면 OK\n for (const pattern of pathPattern) {\n const data = SwcUtils.parsePathPattern(pattern, re.path || '/');\n if (data !== null) {\n pathMatched = true;\n pathData = data;\n break;\n }\n }\n } else {\n // 문자열\n pathData = SwcUtils.parsePathPattern(pathPattern, re.path || '/');\n pathMatched = pathData !== null;\n }\n\n // Filter validation\n const filterPassed = !filter || filter(this.router!);\n\n // Invoke method if conditions pass\n if (pathMatched && filterPassed) {\n instance[methodName]?.({...re, pathData: pathData});\n }\n });\n }\n }\n\n _connected(instance: any) {\n // console.log('appmixin--> connected', this, instance);\n if (instance) {\n this._swc_connected_instance.add(instance);\n if (this.simpleApplication) {\n this._invokeOnConnectedSwcAppStarted(instance);\n // Notify current route subscribers immediately after connection\n if (this.router && this._lastRouterEvent) {\n this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);\n }\n }\n }\n }\n\n _disconnected(instance: any) {\n if (instance) {\n this._swc_connected_instance.delete(instance);\n }\n }\n\n _handleRouteChange(route: RouterEventType) {\n if (route.triggerPoint === 'end') {\n // Iterate through all connected component instances\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeRouteChangeSubscribers(instance, route);\n });\n }\n\n // Save last router event\n this._lastRouterEvent = route;\n }\n\n async connect(config?: SwcAttributeConfigType) {\n const swcConfig = {\n routeType: 'element',\n window: config.window,\n ...config\n } as SwcConfigType;\n\n const mode = config?.connectMode || 'direct';\n\n if (mode === 'direct') {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n } else if (mode === 'swap' && !this.parentNode) {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n\n const clonedApp = this.cloneNode(true) as any;\n clonedApp.style.display = 'none';\n this.parentNode.insertBefore(clonedApp, this.nextSibling);\n\n try {\n await clonedApp.connect({ ...(config || {}), connectMode: 'direct' });\n if (this.parentNode) {\n this.parentNode.removeChild(this);\n }\n clonedApp.setAttribute('swc-connect-mode', 'swap');\n clonedApp.style.display = '';\n } catch (e) {\n if (clonedApp.parentNode) {\n clonedApp.parentNode.removeChild(clonedApp);\n }\n throw e;\n }\n }\n\n // 사파리일떄 예외이다 is 일때 polyfill되는데 이떄 부모부터 만들어지는게 아니라 자식부터 만들어진다 그래서 부모가 만들어질때 자식들이 이미 만들어져있어서 부모가 자식들을 등록해주는 형태로 강제로 등록해준다\n this._connected_safari.forEach((instance: any) => {\n this._swc_connected_instance.add(instance);\n });\n // Invoke @onConnectedSwcApp lifecycle methods on all connected component instances\n // const hostSet = SwcUtils.getHostSet(this as any);\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeOnConnectedSwcAppStarted(instance);\n });\n\n // Safari fix: Manually scan DOM tree and register any SWC components that couldn't find parent\n // This handles the case where is=\"\" elements get upgraded in child-first order\n // const allElements = (this as any).querySelectorAll('*');\n // for (const el of allElements) {\n // const isConnected = (el as any).__swc_connected;\n // if (!isConnected && typeof (el as any)._resolveWindow === 'function') {\n // // Element is an SWC component but hasn't registered with app yet\n // try {\n // this._connected(el);\n // if ((el as any)._invokeOnConnectedSwcAppStarted) {\n // this._invokeOnConnectedSwcAppStarted(el);\n // }\n // } catch (e) {\n // console.warn('[SWC] Error registering discovered element:', el.tagName, e);\n // }\n // }\n // }\n\n // Subscribe to router changes after connect\n if (!this._routerSubscription && this.router) {\n this._routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n // console.log('Route changed:', route);\n this._handleRouteChange(route);\n });\n // Navigate to initial path if specified\n const config = this.__swc_engine.config;\n if (config?.path) {\n this.router.go(config.path);\n }\n }\n }\n\n _invokeOnConnectedSwcAppStarted(instance: any) {\n const startedMethods = findAllLifecycleMetadata(instance, ON_CONNECTED_SWC_APP_METADATA_KEY);\n if (startedMethods) {\n for (const m of startedMethods) {\n instance._invokeLifecycleMethod(m);\n }\n }\n }\n\n connectedCallback() {\n // @ts-ignore\n if (super.connectedCallback) super.connectedCallback();\n\n const configStr = this.getAttribute('swc-get-application-config');\n const win = this.ownerDocument?.defaultView || window;\n if (configStr && win) {\n try {\n // console.log('vvvvvvvvvvvvvvvv->>>>', SwcUtils.findNearestSwcHost(this.host), SwcUtils.getHostSet(this.host))\n const userConfig = FunctionUtils.executeReturn({\n script: configStr,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, SwcUtils.findNearestSwcHost(this))\n });\n this.connect(userConfig);\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Script execution failed:', e);\n }\n }\n\n this.__swc_engine?.config?.onConnected?.(this);\n }\n\n disconnectedCallback() {\n // @ts-ignore\n if (super.disconnectedCallback) super.disconnectedCallback();\n this._routerSubscription?.unsubscribe();\n this._routerSubscription = undefined;\n this._lastRouterEvent = undefined;\n this.__swc_engine.disconnect();\n this.__swc_engine?.config?.onDisconnected?.(this);\n }\n\n async routing(path: string) {\n await this.router?.go(path);\n }\n\n back(): void {\n this.router?.back();\n }\n\n forward(): void {\n this.router?.forward();\n }\n\n reload(): void {\n this.router?.reload();\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAA2D;AAEpE,SAAS,gBAAgB;AACzB,SAAS,qBAAmC;AAE5C,SAAS,mCAAmC,gCAAgC;AAC5E,SAAS,6CAA6C;AAEhD,SAAU,YAA6D,MAAO;AAElF,SAAO,cAAc,KAAI;IAAlB,cAAA;;AACL,WAAA,eAAe,IAAI,aAAa,IAAW;AAC3C,WAAA,0BAA0B,oBAAI,IAAG;AAUj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|
|
43
|
-
if (!script)
|
|
43
|
+
if (!script) {
|
|
44
|
+
this.render("default");
|
|
44
45
|
return;
|
|
46
|
+
}
|
|
45
47
|
const win = this.ownerDocument?.defaultView || window;
|
|
46
48
|
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
47
49
|
if (result instanceof Promise) {
|
|
@@ -86,6 +88,7 @@ class SwcAsync extends HTMLTemplateElement {
|
|
|
86
88
|
this._nodes = [];
|
|
87
89
|
}
|
|
88
90
|
connectedCallback() {
|
|
91
|
+
console.log("[SwcAsync] connectedCallback called");
|
|
89
92
|
this.refresh();
|
|
90
93
|
}
|
|
91
94
|
disconnectedCallback() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAsync.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) return;\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n\n if (result instanceof Promise) {\n this.render('loading');\n result\n .then(v => {\n this._value = v;\n this.render('success');\n })\n .catch(e => this.render('error'));\n } else {\n this._value = result;\n this.render('success');\n }\n }\n\n private render(state: string) {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const t = this.content.querySelector(`template[is=\"swc-${state}\"]`) as HTMLTemplateElement;\n if (t) {\n const clone = t.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0], $state: state };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAExB,MAAO,iBAAiB,oBAAmB;EAAjD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) {\n this.render('default');\n return;\n }\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n\n if (result instanceof Promise) {\n this.render('loading');\n result\n .then(v => {\n this._value = v;\n this.render('success');\n })\n .catch(e => this.render('error'));\n } else {\n this._value = result;\n this.render('success');\n }\n }\n\n private render(state: string) {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const t = this.content.querySelector(`template[is=\"swc-${state}\"]`) as HTMLTemplateElement;\n if (t) {\n const clone = t.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0], $state: state };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n console.log('[SwcAsync] connectedCallback called');\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAExB,MAAO,iBAAiB,oBAAmB;EAAjD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EA0FxB;EAxFU,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,cAAc,cAAc;MACtC,QAAQ;MACR,SAAS;MACT,MAAM,SAAS,oBAAoB,KAAK,IAAI;KAC7C;AAED,QAAI,eAAe;AAAa,aAAO;AACvC,QAAI,OAAO,QAAQ;AAAU,aAAO,IAAI,SAAS,cAAc,GAAG;AAClE,WAAO,KAAK;EACd;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,kBAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,UAAO;AACb,UAAM,SAAS,KAAK,aAAa,cAAc;AAC/C,QAAI,CAAC,QAAQ;AACX,WAAK,OAAO,SAAS;AACrB;IACF;AACA,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,SAAS,cAAc,cAAc,EAAE,QAAQ,SAAS,MAAM,MAAM,SAAS,oBAAoB,KAAK,IAAI,EAAC,CAAE;AAEnH,QAAI,kBAAkB,SAAS;AAC7B,WAAK,OAAO,SAAS;AACrB,aACG,KAAK,OAAI;AACR,aAAK,SAAS;AACd,aAAK,OAAO,SAAS;MACvB,CAAC,EACA,MAAM,OAAK,KAAK,OAAO,OAAO,CAAC;IACpC,OAAO;AACL,W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MLTemplateElement {
|
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this._nodes = [];
|
|
17
17
|
this._value = null;
|
|
18
|
+
this._previousTemplate = null;
|
|
18
19
|
}
|
|
19
20
|
get value() {
|
|
20
21
|
return this._value;
|
|
@@ -23,70 +24,85 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
23
24
|
this._value = nv;
|
|
24
25
|
this.render();
|
|
25
26
|
}
|
|
26
|
-
_resolvePortal() {
|
|
27
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
28
|
-
if (!portalScript)
|
|
29
|
-
return this.parentElement;
|
|
30
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
31
|
-
const res = FunctionUtils.executeReturn({
|
|
32
|
-
script: portalScript,
|
|
33
|
-
context: this,
|
|
34
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
35
|
-
});
|
|
36
|
-
if (res instanceof HTMLElement)
|
|
37
|
-
return res;
|
|
38
|
-
if (typeof res === "string")
|
|
39
|
-
return win.document.querySelector(res);
|
|
40
|
-
return this.parentElement;
|
|
41
|
-
}
|
|
42
27
|
_executeCloneCallback(attr, args) {
|
|
43
28
|
const script = this.getAttribute(attr);
|
|
44
29
|
if (!script)
|
|
45
30
|
return;
|
|
46
31
|
FunctionUtils.execute({ script, context: this, args });
|
|
47
32
|
}
|
|
48
|
-
refresh() {
|
|
49
|
-
|
|
50
|
-
if (
|
|
33
|
+
refresh(valueAttr) {
|
|
34
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
35
|
+
if (valueAttr === null) {
|
|
51
36
|
this.value = null;
|
|
52
37
|
return;
|
|
53
38
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
40
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
41
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
42
|
+
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
43
|
+
this.value = result;
|
|
44
|
+
} else {
|
|
45
|
+
this.value = valueAttr;
|
|
46
|
+
}
|
|
57
47
|
}
|
|
58
48
|
render() {
|
|
59
|
-
this.cleanup();
|
|
60
|
-
const portal = this._resolvePortal();
|
|
61
|
-
if (!portal)
|
|
62
|
-
return;
|
|
63
49
|
const win = this.ownerDocument?.defaultView || window;
|
|
64
50
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
65
51
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
66
52
|
let selected = null;
|
|
67
53
|
for (const t of templates) {
|
|
68
|
-
if (t.getAttribute("is") === "swc-when"
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
55
|
+
let matches = false;
|
|
56
|
+
const value = t.getAttribute("value") || "";
|
|
57
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
58
|
+
const script = value.slice(2, -2).trim();
|
|
59
|
+
const result = FunctionUtils.executeReturn({
|
|
60
|
+
script,
|
|
61
|
+
context: t,
|
|
62
|
+
args: { ...helperSet, $value: this._value }
|
|
63
|
+
});
|
|
64
|
+
matches = result === true;
|
|
65
|
+
} else {
|
|
66
|
+
matches = String(value) === String(this._value);
|
|
67
|
+
}
|
|
68
|
+
if (matches) {
|
|
69
|
+
selected = t;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
75
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
76
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
77
|
+
if (shouldSkip) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.cleanup();
|
|
81
|
+
this._previousTemplate = target;
|
|
74
82
|
if (target) {
|
|
75
83
|
const clone = target.content.cloneNode(true);
|
|
76
84
|
this._nodes = Array.from(clone.childNodes);
|
|
77
85
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
78
86
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
79
87
|
this._nodes.forEach((n, nodeIdx) => {
|
|
80
|
-
if (n instanceof HTMLElement)
|
|
81
|
-
n.__swc_host = this;
|
|
82
88
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
89
|
+
if (n instanceof HTMLElement) {
|
|
90
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
91
|
+
const value = attr.value || "";
|
|
92
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
93
|
+
const script = value.slice(2, -2).trim();
|
|
94
|
+
const result = FunctionUtils.executeReturn({
|
|
95
|
+
script,
|
|
96
|
+
context: n,
|
|
97
|
+
args: { ...groupArgs, $value: this._value }
|
|
98
|
+
});
|
|
99
|
+
n.setAttribute(attr.name, String(result));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
83
103
|
});
|
|
84
104
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
85
|
-
|
|
86
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
87
|
-
} else {
|
|
88
|
-
portal.appendChild(clone);
|
|
89
|
-
}
|
|
105
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
108
|
cleanup() {
|
|
@@ -101,9 +117,9 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
__decorate([
|
|
104
|
-
changedAttributeHost("
|
|
120
|
+
changedAttributeHost("value"),
|
|
105
121
|
__metadata("design:type", Function),
|
|
106
|
-
__metadata("design:paramtypes", []),
|
|
122
|
+
__metadata("design:paramtypes", [String]),
|
|
107
123
|
__metadata("design:returntype", void 0)
|
|
108
124
|
], SwcChoose.prototype, "refresh", null);
|
|
109
125
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcChoose.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAExB,MAAO,kBAAkB,oBAAmB;EAAlD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('value')\n private refresh(valueAttr?: string | null) {\n valueAttr ??= this.getAttribute('value');\n if (valueAttr === null) {\n this.value = null;\n return;\n }\n\n // {{ }} 브레이스로 감싸진 값은 스크립트 실행\n if (valueAttr.startsWith('{{') && valueAttr.endsWith('}}')) {\n const script = valueAttr.slice(2, -2).trim();\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n this.value = result;\n } else {\n // 일반 문자열 값\n this.value = valueAttr;\n }\n }\n\n private render() {\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when') {\n let matches = false;\n const value = t.getAttribute('value') || '';\n\n // {{ }} 브레이스로 감싸진 값은 스크립트 실행\n if (value.startsWith('{{') && value.endsWith('}}')) {\n const script = value.slice(2, -2).trim();\n const result = FunctionUtils.executeReturn({\n script,\n context: t,\n args: { ...helperSet, $value: this._value }\n });\n // console.log('rrrrrrrrrrrrrr', result);\n matches = result === true;\n } else {\n // 일반 문자열 비교 (기존 방식)\n matches = String(value) === String(this._value);\n }\n\n if (matches) {\n selected = t;\n break;\n }\n }\n }\n\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n // skip-if-same attribute가 있고 이전과 같은 template이면 렌더링 스킵\n // 최상위 skip-if-same 또는 각 when/otherwise의 skip-if-same 체크\n const targetHasSkipIfSame = target?.hasAttribute('skip-if-same');\n const shouldSkip = (this.hasAttribute('skip-if-same') || targetHasSkipIfSame) && this._previousTemplate === target;\n if (shouldSkip) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n const clone = target.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };\n\n // 복제된 최상위 요소들은 SwcChoose의 직접 자식이 될 것이므로 __swc_host 설정 안 함\n this._nodes.forEach((n, nodeIdx) => {\n // if (n instanceof HTMLElement) (n as any).__swc_host = this; // 제거: 부모 체인 유지\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n\n // Attribute {{ }} 치환 - HTML string 차원에서 동적 치환\n if (n instanceof HTMLElement) {\n Array.from(n.attributes).forEach(attr => {\n const value = attr.value || '';\n if (value.startsWith('{{') && value.endsWith('}}')) {\n const script = value.slice(2, -2).trim();\n const result = FunctionUtils.executeReturn({\n script,\n context: n,\n args: { ...groupArgs, $value: this._value }\n });\n n.setAttribute(attr.name, String(result));\n }\n });\n }\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n this.parentElement?.insertBefore(clone, this.nextSibling);\n // if (portal === this.parentElement) {\n // portal.insertBefore(clone, this.nextSibling);\n // } else {\n // portal.appendChild(clone);\n // }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAExB,MAAO,kBAAkB,oBAAmB;EAAlD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;AACd,SAAA,oBAAgD;EAoI1D;EAlIE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EACA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS;AACd,SAAK,OAAM;EACb;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,kBAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,QAAQ,WAAyB;AACvC,kBAAA,YAAc,KAAK,aAAa,OAAO;AACvC,QAAI,cAAc,MAAM;AACtB,WAAK,QAAQ;AACb;IACF;AAGA,QAAI,UAAU,WAAW,IAAI,KAAK,UAAU,SAAS,IAAI,GAAG;AAC1D,YAAM,SAAS,UAAU,MAAM,GAAG,EAAE,EAAE,KA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AAK,EAAE,aAAa,CAAC;AACzD,YAAM,YAAY,EAAE,GAAG,WAAW,QAAQ,KAAK,QAAQ,QAAQ,KAAK,QAAQ,WAAW,UAAU,eAAe,SAAS,CAAC,EAAC;AAG3H,WAAK,OAAO,QAAQ,CAAC,GAAG,YAAW;AAEjC,aAAK,sBAAsB,iBAAiB,EAAE,GAAG,WAAW,OAAO,GAAG,YAAY,SAAS,YAAY,EAAE,aAAa,EAAC,CAAE;AAGzH,YAAI,aAAa,aAAa;AAC5B,gBAAM,KAAK,EAAE,UAAU,EAAE,QAAQ,UAAO;AACtC,kBAAM,QAAQ,KAAK,SAAS;AAC5B,gBAAI,MAAM,WAAW,IAAI,KAAK,MAAM,SAAS,IAAI,GAAG;AAClD,oBAAM,SAAS,MAAM,MAAM,GAAG,EAAE,EAAE,KAAI;AACtC,oBAAM,SAAS,cAAc,cAAc;gBACzC;gBACA,SAAS;gBACT,MAAM,EAAE,GAAG,WAAW,QAAQ,KAAK,OAAM;eAC1C;AACD,gBAAE,aAAa,KAAK,MAAM,OAAO,MAAM,CAAC;YAC1C;UACF,CAAC;QACH;MACF,CAAC;AAED,WAAK,sBAAsB,kBAAkB,SAAS;AAEtD,WAAK,eAAe,aAAa,OAAO,KAAK,WAAW;IAM1D;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAlHQ,WAAA;EADP,qBAAqB,OAAO;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -335,6 +335,7 @@ const registerAllElements = (w) => {
|
|
|
335
335
|
super(...arguments);
|
|
336
336
|
this._nodes = [];
|
|
337
337
|
this._value = null;
|
|
338
|
+
this._previousTemplate = null;
|
|
338
339
|
}
|
|
339
340
|
get value() {
|
|
340
341
|
return this._value;
|
|
@@ -343,70 +344,85 @@ const registerAllElements = (w) => {
|
|
|
343
344
|
this._value = nv;
|
|
344
345
|
this.render();
|
|
345
346
|
}
|
|
346
|
-
_resolvePortal() {
|
|
347
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
348
|
-
if (!portalScript)
|
|
349
|
-
return this.parentElement;
|
|
350
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
351
|
-
const res = FunctionUtils.executeReturn({
|
|
352
|
-
script: portalScript,
|
|
353
|
-
context: this,
|
|
354
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
355
|
-
});
|
|
356
|
-
if (res instanceof HTMLElement)
|
|
357
|
-
return res;
|
|
358
|
-
if (typeof res === "string")
|
|
359
|
-
return win.document.querySelector(res);
|
|
360
|
-
return this.parentElement;
|
|
361
|
-
}
|
|
362
347
|
_executeCloneCallback(attr, args) {
|
|
363
348
|
const script = this.getAttribute(attr);
|
|
364
349
|
if (!script)
|
|
365
350
|
return;
|
|
366
351
|
FunctionUtils.execute({ script, context: this, args });
|
|
367
352
|
}
|
|
368
|
-
refresh() {
|
|
369
|
-
|
|
370
|
-
if (
|
|
353
|
+
refresh(valueAttr) {
|
|
354
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
355
|
+
if (valueAttr === null) {
|
|
371
356
|
this.value = null;
|
|
372
357
|
return;
|
|
373
358
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
359
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
360
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
361
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
362
|
+
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
363
|
+
this.value = result;
|
|
364
|
+
} else {
|
|
365
|
+
this.value = valueAttr;
|
|
366
|
+
}
|
|
377
367
|
}
|
|
378
368
|
render() {
|
|
379
|
-
this.cleanup();
|
|
380
|
-
const portal = this._resolvePortal();
|
|
381
|
-
if (!portal)
|
|
382
|
-
return;
|
|
383
369
|
const win = this.ownerDocument?.defaultView || window;
|
|
384
370
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
385
371
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
386
372
|
let selected = null;
|
|
387
373
|
for (const t of templates) {
|
|
388
|
-
if (t.getAttribute("is") === "swc-when"
|
|
389
|
-
|
|
390
|
-
|
|
374
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
375
|
+
let matches = false;
|
|
376
|
+
const value = t.getAttribute("value") || "";
|
|
377
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
378
|
+
const script = value.slice(2, -2).trim();
|
|
379
|
+
const result = FunctionUtils.executeReturn({
|
|
380
|
+
script,
|
|
381
|
+
context: t,
|
|
382
|
+
args: { ...helperSet, $value: this._value }
|
|
383
|
+
});
|
|
384
|
+
matches = result === true;
|
|
385
|
+
} else {
|
|
386
|
+
matches = String(value) === String(this._value);
|
|
387
|
+
}
|
|
388
|
+
if (matches) {
|
|
389
|
+
selected = t;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
391
392
|
}
|
|
392
393
|
}
|
|
393
394
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
395
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
396
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
397
|
+
if (shouldSkip) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
this.cleanup();
|
|
401
|
+
this._previousTemplate = target;
|
|
394
402
|
if (target) {
|
|
395
403
|
const clone = target.content.cloneNode(true);
|
|
396
404
|
this._nodes = Array.from(clone.childNodes);
|
|
397
405
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
398
406
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
399
407
|
this._nodes.forEach((n, nodeIdx) => {
|
|
400
|
-
if (n instanceof HTMLElement)
|
|
401
|
-
n.__swc_host = this;
|
|
402
408
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
409
|
+
if (n instanceof HTMLElement) {
|
|
410
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
411
|
+
const value = attr.value || "";
|
|
412
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
413
|
+
const script = value.slice(2, -2).trim();
|
|
414
|
+
const result = FunctionUtils.executeReturn({
|
|
415
|
+
script,
|
|
416
|
+
context: n,
|
|
417
|
+
args: { ...groupArgs, $value: this._value }
|
|
418
|
+
});
|
|
419
|
+
n.setAttribute(attr.name, String(result));
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
403
423
|
});
|
|
404
424
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
405
|
-
|
|
406
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
407
|
-
} else {
|
|
408
|
-
portal.appendChild(clone);
|
|
409
|
-
}
|
|
425
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
410
426
|
}
|
|
411
427
|
}
|
|
412
428
|
cleanup() {
|
|
@@ -421,9 +437,9 @@ const registerAllElements = (w) => {
|
|
|
421
437
|
}
|
|
422
438
|
};
|
|
423
439
|
__decorate([
|
|
424
|
-
changedAttributeHost("
|
|
440
|
+
changedAttributeHost("value"),
|
|
425
441
|
__metadata("design:type", Function),
|
|
426
|
-
__metadata("design:paramtypes", []),
|
|
442
|
+
__metadata("design:paramtypes", [String]),
|
|
427
443
|
__metadata("design:returntype", void 0)
|
|
428
444
|
], SwcChoose.prototype, "refresh", null);
|
|
429
445
|
SwcChoose = __decorate([
|
|
@@ -459,8 +475,10 @@ const registerAllElements = (w) => {
|
|
|
459
475
|
}
|
|
460
476
|
refresh() {
|
|
461
477
|
const script = this.getAttribute("on-get-value");
|
|
462
|
-
if (!script)
|
|
478
|
+
if (!script) {
|
|
479
|
+
this.render("default");
|
|
463
480
|
return;
|
|
481
|
+
}
|
|
464
482
|
const win = this.ownerDocument?.defaultView || window;
|
|
465
483
|
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
466
484
|
if (result instanceof Promise) {
|
|
@@ -505,6 +523,7 @@ const registerAllElements = (w) => {
|
|
|
505
523
|
this._nodes = [];
|
|
506
524
|
}
|
|
507
525
|
connectedCallback() {
|
|
526
|
+
console.log("[SwcAsync] connectedCallback called");
|
|
508
527
|
this.refresh();
|
|
509
528
|
}
|
|
510
529
|
disconnectedCallback() {
|
|
@@ -805,6 +824,79 @@ const registerAllElements = (w) => {
|
|
|
805
824
|
SwcAppBody = __decorate([
|
|
806
825
|
elementDefine("swc-app-body", { extends: "body", window: w })
|
|
807
826
|
], SwcAppBody);
|
|
827
|
+
return {
|
|
828
|
+
// Sub Templates
|
|
829
|
+
SwcLoading,
|
|
830
|
+
SwcError,
|
|
831
|
+
SwcSuccess,
|
|
832
|
+
SwcWhen,
|
|
833
|
+
SwcOtherwise,
|
|
834
|
+
SwcDefault,
|
|
835
|
+
// Core Elements
|
|
836
|
+
SwcApp,
|
|
837
|
+
SwcIf,
|
|
838
|
+
SwcLoop,
|
|
839
|
+
SwcChoose,
|
|
840
|
+
SwcAsync,
|
|
841
|
+
// App Elements
|
|
842
|
+
SwcAppAnchor,
|
|
843
|
+
SwcAppArea,
|
|
844
|
+
SwcAppAudio,
|
|
845
|
+
SwcAppBase,
|
|
846
|
+
SwcAppButton,
|
|
847
|
+
SwcAppCanvas,
|
|
848
|
+
SwcAppData,
|
|
849
|
+
SwcAppDataList,
|
|
850
|
+
SwcAppDetails,
|
|
851
|
+
SwcAppDialog,
|
|
852
|
+
SwcAppDiv,
|
|
853
|
+
SwcAppDList,
|
|
854
|
+
SwcAppEmbed,
|
|
855
|
+
SwcAppFieldSet,
|
|
856
|
+
SwcAppForm,
|
|
857
|
+
SwcAppHR,
|
|
858
|
+
SwcAppIFrame,
|
|
859
|
+
SwcAppImage,
|
|
860
|
+
SwcAppInput,
|
|
861
|
+
SwcAppLabel,
|
|
862
|
+
SwcAppLegend,
|
|
863
|
+
SwcAppLI,
|
|
864
|
+
SwcAppLink,
|
|
865
|
+
SwcAppMap,
|
|
866
|
+
SwcAppMeta,
|
|
867
|
+
SwcAppMeter,
|
|
868
|
+
SwcAppMod,
|
|
869
|
+
SwcAppObject,
|
|
870
|
+
SwcAppOList,
|
|
871
|
+
SwcAppOptGroup,
|
|
872
|
+
SwcAppOption,
|
|
873
|
+
SwcAppOutput,
|
|
874
|
+
SwcAppParagraph,
|
|
875
|
+
SwcAppParam,
|
|
876
|
+
SwcAppPicture,
|
|
877
|
+
SwcAppPre,
|
|
878
|
+
SwcAppProgress,
|
|
879
|
+
SwcAppQuote,
|
|
880
|
+
SwcAppScript,
|
|
881
|
+
SwcAppSelect,
|
|
882
|
+
SwcAppSlot,
|
|
883
|
+
SwcAppSource,
|
|
884
|
+
SwcAppSpan,
|
|
885
|
+
SwcAppStyle,
|
|
886
|
+
SwcAppTable,
|
|
887
|
+
SwcAppTableSection,
|
|
888
|
+
SwcAppTableCell,
|
|
889
|
+
SwcAppTemplate,
|
|
890
|
+
SwcAppTextArea,
|
|
891
|
+
SwcAppTime,
|
|
892
|
+
SwcAppTitle,
|
|
893
|
+
SwcAppTableRow,
|
|
894
|
+
SwcAppTrack,
|
|
895
|
+
SwcAppUList,
|
|
896
|
+
SwcAppVideo,
|
|
897
|
+
SwcAppHeading,
|
|
898
|
+
SwcAppBody
|
|
899
|
+
};
|
|
808
900
|
};
|
|
809
901
|
export {
|
|
810
902
|
registerAllElements
|