@dooboostore/simple-web-component 1.0.15 → 1.0.17

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.
Files changed (108) hide show
  1. package/README.md +275 -91
  2. package/dist/cjs/decorators/addEventListener.js +2 -3
  3. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  4. package/dist/cjs/decorators/elementDefine.js +161 -34
  5. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  6. package/dist/cjs/decorators/emitCustomEvent.js +2 -14
  7. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  8. package/dist/cjs/decorators/query.js +47 -36
  9. package/dist/cjs/decorators/query.js.map +2 -2
  10. package/dist/cjs/decorators/queryAll.js +42 -36
  11. package/dist/cjs/decorators/queryAll.js.map +2 -2
  12. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  13. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  14. package/dist/cjs/elements/SwcAsync.js +188 -0
  15. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  16. package/dist/cjs/elements/SwcChoose.js +155 -0
  17. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  18. package/dist/cjs/elements/SwcIf.js +167 -0
  19. package/dist/cjs/elements/SwcIf.js.map +7 -0
  20. package/dist/cjs/elements/SwcLoop.js +246 -0
  21. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  22. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  23. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  24. package/dist/cjs/elements/index.js +7 -0
  25. package/dist/cjs/elements/index.js.map +2 -2
  26. package/dist/cjs/index.js +1 -1
  27. package/dist/cjs/index.js.map +2 -2
  28. package/dist/cjs/types.js +1 -0
  29. package/dist/cjs/types.js.map +2 -2
  30. package/dist/cjs/utils/Utils.js +92 -162
  31. package/dist/cjs/utils/Utils.js.map +3 -3
  32. package/dist/esm/decorators/addEventListener.js +2 -3
  33. package/dist/esm/decorators/addEventListener.js.map +2 -2
  34. package/dist/esm/decorators/elementDefine.js +161 -34
  35. package/dist/esm/decorators/elementDefine.js.map +3 -3
  36. package/dist/esm/decorators/emitCustomEvent.js +2 -14
  37. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  38. package/dist/esm/decorators/query.js +47 -36
  39. package/dist/esm/decorators/query.js.map +2 -2
  40. package/dist/esm/decorators/queryAll.js +42 -36
  41. package/dist/esm/decorators/queryAll.js.map +2 -2
  42. package/dist/esm/elements/SwcAppEngine.js +2 -1
  43. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  44. package/dist/esm/elements/SwcAsync.js +169 -0
  45. package/dist/esm/elements/SwcAsync.js.map +7 -0
  46. package/dist/esm/elements/SwcChoose.js +136 -0
  47. package/dist/esm/elements/SwcChoose.js.map +7 -0
  48. package/dist/esm/elements/SwcIf.js +148 -0
  49. package/dist/esm/elements/SwcIf.js.map +7 -0
  50. package/dist/esm/elements/SwcLoop.js +227 -0
  51. package/dist/esm/elements/SwcLoop.js.map +7 -0
  52. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  53. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  54. package/dist/esm/elements/index.js +7 -0
  55. package/dist/esm/elements/index.js.map +2 -2
  56. package/dist/esm/index.js +1 -1
  57. package/dist/esm/index.js.map +1 -1
  58. package/dist/esm/types.js +1 -0
  59. package/dist/esm/types.js.map +2 -2
  60. package/dist/esm/utils/Utils.js +92 -162
  61. package/dist/esm/utils/Utils.js.map +3 -3
  62. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1150 -326
  63. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  64. package/dist/types/decorators/addEventListener.d.ts +10 -4
  65. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  66. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  67. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  68. package/dist/types/decorators/query.d.ts +4 -5
  69. package/dist/types/decorators/query.d.ts.map +1 -1
  70. package/dist/types/decorators/queryAll.d.ts +4 -5
  71. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  72. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  73. package/dist/types/elements/SwcAsync.d.ts +16 -0
  74. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  75. package/dist/types/elements/SwcChoose.d.ts +13 -0
  76. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  77. package/dist/types/elements/SwcIf.d.ts +15 -0
  78. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  79. package/dist/types/elements/SwcLoop.d.ts +20 -0
  80. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  81. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  82. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  83. package/dist/types/elements/index.d.ts +7 -0
  84. package/dist/types/elements/index.d.ts.map +1 -1
  85. package/dist/types/index.d.ts +1 -1
  86. package/dist/types/index.d.ts.map +1 -1
  87. package/dist/types/types.d.ts +11 -1
  88. package/dist/types/types.d.ts.map +1 -1
  89. package/dist/types/utils/Utils.d.ts +19 -21
  90. package/dist/types/utils/Utils.d.ts.map +1 -1
  91. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1150 -326
  92. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  93. package/package.json +10 -3
  94. package/src/decorators/addEventListener.ts +11 -7
  95. package/src/decorators/elementDefine.ts +165 -39
  96. package/src/decorators/emitCustomEvent.ts +5 -21
  97. package/src/decorators/query.ts +46 -41
  98. package/src/decorators/queryAll.ts +45 -41
  99. package/src/elements/SwcAppEngine.ts +2 -1
  100. package/src/elements/SwcAsync.ts +163 -0
  101. package/src/elements/SwcChoose.ts +127 -0
  102. package/src/elements/SwcIf.ts +134 -0
  103. package/src/elements/SwcLoop.ts +215 -0
  104. package/src/elements/SwcSubTemplates.ts +19 -0
  105. package/src/elements/index.ts +8 -3
  106. package/src/index.ts +1 -1
  107. package/src/types.ts +15 -5
  108. package/src/utils/Utils.ts +111 -197
@@ -23,49 +23,55 @@ __export(queryAll_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(queryAll_exports);
25
25
  var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
26
+ var import_elementDefine = require("./elementDefine");
27
+ var import_Utils = require("../utils/Utils");
26
28
  const QUERY_ALL_METADATA_KEY = Symbol("simple-web-component:query-all");
27
- function queryAll(arg1, arg2) {
28
- const decorator = (selector, options, target, propertyKey, descriptor) => {
29
- const isMethod = !!descriptor;
29
+ function queryAll(selector, options = {}) {
30
+ return (target, propertyKey, descriptor) => {
31
+ if (descriptor !== void 0) {
32
+ throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
33
+ }
30
34
  const constructor = target.constructor;
31
35
  let queries = import_ReflectUtils.ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
32
36
  if (!queries) {
33
37
  queries = [];
34
38
  import_ReflectUtils.ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
35
39
  }
36
- queries.push({ selector, options, propertyKey, isMethod });
37
- if (!isMethod) {
38
- Object.defineProperty(target, propertyKey, {
39
- get() {
40
- if (!selector)
41
- return [this];
42
- let searchRoot = this;
43
- if (options.root === "shadow")
44
- searchRoot = this.shadowRoot || this;
45
- else if (options.root === "light")
46
- searchRoot = this;
47
- else
48
- searchRoot = this.shadowRoot || this;
49
- return searchRoot.querySelectorAll(selector);
50
- },
51
- enumerable: true,
52
- configurable: true
53
- });
54
- }
55
- };
56
- if (arg1 && typeof arg2 === "string") {
57
- return decorator("", {}, arg1, arg2);
58
- }
59
- return (target, propertyKey, descriptor) => {
60
- let selector = "";
61
- let options = {};
62
- if (typeof arg1 === "string") {
63
- selector = arg1;
64
- } else if (typeof arg1 === "object") {
65
- options = arg1;
66
- selector = options.selector || "";
67
- }
68
- decorator(selector, options, target, propertyKey, descriptor);
40
+ queries.push({ selector, options, propertyKey });
41
+ Object.defineProperty(target, propertyKey, {
42
+ get() {
43
+ const hostSet = import_Utils.SwcUtils.getHostSet(this);
44
+ if (selector === ":hosts")
45
+ return hostSet.$hosts;
46
+ if (selector === ":appHosts")
47
+ return hostSet.$appHosts;
48
+ const config = (0, import_elementDefine.getElementConfig)(this);
49
+ const win = config?.window || window;
50
+ const doc = win.document;
51
+ if (selector === ":window")
52
+ return [win];
53
+ if (selector === ":document")
54
+ return [doc];
55
+ if (!selector || selector === ":host")
56
+ return [this];
57
+ const r = options.root || "auto";
58
+ if (r === "shadow") {
59
+ return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];
60
+ }
61
+ if (r === "light") {
62
+ return this.querySelectorAll(selector);
63
+ }
64
+ if (r === "all") {
65
+ const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
66
+ const lNodes = Array.from(this.querySelectorAll(selector));
67
+ return [...sNodes, ...lNodes];
68
+ }
69
+ const root = this.shadowRoot || this;
70
+ return root.querySelectorAll(selector);
71
+ },
72
+ enumerable: true,
73
+ configurable: true
74
+ });
69
75
  };
70
76
  }
71
77
  const getQueryAllMetadata = (target) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/decorators/queryAll.ts"],
4
- "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport interface QueryAllOptions {\n selector?: string;\n root?: 'light' | 'shadow' | 'all' | 'auto';\n}\n\nexport interface QueryAllMetadata {\n selector: string;\n options: QueryAllOptions;\n propertyKey: string | symbol;\n isMethod: boolean;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');\n\nexport function queryAll(selector: string): any;\nexport function queryAll(options: QueryAllOptions): any;\nexport function queryAll(target: Object, propertyKey: string | symbol): void;\nexport function queryAll(arg1?: string | QueryAllOptions | Object, arg2?: string | symbol): any {\n const decorator = (selector: string, options: QueryAllOptions, target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n const isMethod = !!descriptor;\n const constructor = target.constructor;\n\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ selector, options, propertyKey, isMethod });\n\n if (!isMethod) {\n Object.defineProperty(target, propertyKey, {\n get(this: HTMLElement) {\n if (!selector) return [this];\n let searchRoot: Node = this;\n if (options.root === 'shadow') searchRoot = this.shadowRoot || this;\n else if (options.root === 'light') searchRoot = this;\n else searchRoot = this.shadowRoot || this; // Default: Auto (Shadow-First)\n\n return (searchRoot as HTMLElement).querySelectorAll(selector);\n },\n enumerable: true,\n configurable: true\n });\n }\n };\n\n // Case: @queryAll (parameterless decorator)\n if (arg1 && typeof arg2 === 'string') {\n return decorator('', {}, arg1 as Object, arg2 as string | symbol);\n }\n\n // Case: @queryAll('selector') or @queryAll({ selector: '...', ... })\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n let selector = '';\n let options: QueryAllOptions = {};\n\n if (typeof arg1 === 'string') {\n selector = arg1;\n } else if (typeof arg1 === 'object') {\n options = arg1 as QueryAllOptions;\n selector = options.selector || '';\n }\n\n decorator(selector, options, target, propertyKey, descriptor);\n };\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;;;0BAA6B;AActB,MAAM,yBAAyB,OAAO,gCAAgC;AAKvE,SAAU,SAAS,MAA0C,MAAsB;AACvF,QAAM,YAAY,CAAC,UAAkB,SAA0B,QAAgB,aAA8B,eAAmC;AAC9I,UAAM,WAAW,CAAC,CAAC;AACnB,UAAM,cAAc,OAAO;AAE3B,QAAI,UAAU,iCAAa,YAAgC,wBAAwB,WAAW;AAC9F,QAAI,CAAC,SAAS;AACZ,gBAAU,CAAA;AACV,uCAAa,eAAe,wBAAwB,SAAS,WAAW;IAC1E;AACA,YAAQ,KAAK,EAAE,UAAU,SAAS,aAAa,SAAQ,CAAE;AAEzD,QAAI,CAAC,UAAU;AACb,aAAO,eAAe,QAAQ,aAAa;QACzC,MAAG;AACD,cAAI,CAAC;AAAU,mBAAO,CAAC,IAAI;AAC3B,cAAI,aAAmB;AACvB,cAAI,QAAQ,SAAS;AAAU,yBAAa,KAAK,cAAc;mBACtD,QAAQ,SAAS;AAAS,yBAAa;;AAC3C,yBAAa,KAAK,cAAc;AAErC,iBAAQ,WAA2B,iBAAiB,QAAQ;QAC9D;QACA,YAAY;QACZ,cAAc;OACf;IACH;EACF;AAGA,MAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,WAAO,UAAU,IAAI,CAAA,GAAI,MAAgB,IAAuB;EAClE;AAGA,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,QAAI,WAAW;AACf,QAAI,UAA2B,CAAA;AAE/B,QAAI,OAAO,SAAS,UAAU;AAC5B,iBAAW;IACb,WAAW,OAAO,SAAS,UAAU;AACnC,gBAAU;AACV,iBAAW,QAAQ,YAAY;IACjC;AAEA,cAAU,UAAU,SAAS,QAAQ,aAAa,UAAU;EAC9D;AACF;AAEO,MAAM,sBAAsB,CAAC,WAA+C;AACjF,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,wBAAwB,WAAW;AACrE;",
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\nimport { getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\n\nexport interface QueryAllOptions {\n root?: 'light' | 'shadow' | 'all' | 'auto';\n}\n\nexport interface QueryAllMetadata {\n selector: string;\n options: QueryAllOptions;\n propertyKey: string | symbol;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');\n\n/**\n * @queryAll decorator to inject a list of elements into a class property.\n */\nexport function queryAll(selector: string, options: QueryAllOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = target.constructor;\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ selector, options, propertyKey });\n\n Object.defineProperty(target, propertyKey, {\n get(this: HTMLElement) {\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':hosts') return hostSet.$hosts;\n if (selector === ':appHosts') return hostSet.$appHosts;\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n const doc = win.document;\n\n if (selector === ':window') return [win];\n if (selector === ':document') return [doc];\n if (!selector || selector === ':host') return [this];\n\n // --- Standard Selectors ---\n const r = options.root || 'auto';\n\n if (r === 'shadow') {\n return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];\n }\n if (r === 'light') {\n return this.querySelectorAll(selector);\n }\n if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n return [...sNodes, ...lNodes];\n }\n // auto\n const root = this.shadowRoot || this;\n return root.querySelectorAll(selector);\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;;;0BAA6B;AAC7B,2BAA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,MAAM;QAC9B;AAEA,cAAM,OAAO,KAAK,cAAc;AAChC,eAAO,KAAK,iBAAiB,QAAQ;MACvC;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,sBAAsB,CAAC,WAA+C;AACjF,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,wBAAwB,WAAW;AACrE;",
6
6
  "names": []
7
7
  }
@@ -26,6 +26,7 @@ var import_HashRouter = require("@dooboostore/core-web/routers/HashRouter");
26
26
  var import_ElementRouter = require("../router/ElementRouter");
27
27
  var import_SimOption = require("@dooboostore/simple-boot/SimOption");
28
28
  var import_Router = require("@dooboostore/core-web/routers/Router");
29
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
29
30
  class SwcAppEngine {
30
31
  constructor(host) {
31
32
  this.host = host;
@@ -38,7 +39,7 @@ class SwcAppEngine {
38
39
  const configStr = this.host.getAttribute("swc-get-application-config");
39
40
  if (!configStr) return;
40
41
  try {
41
- const userConfig = new Function(`return ${configStr}`).apply(this.host);
42
+ const userConfig = import_FunctionUtils.FunctionUtils.executeReturn({ script: configStr, context: this.host });
42
43
  if (userConfig && userConfig.rootRouter) {
43
44
  const _config = {
44
45
  routeType: "element",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcAppEngine.ts"],
4
- "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { PathRouter } from '@dooboostore/core-web/routers/PathRouter';\nimport { HashRouter } from '@dooboostore/core-web/routers/HashRouter';\nimport { ElementRouter } from '../router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot/SimOption';\nimport { Router, RouterEventType } from '@dooboostore/core-web/routers/Router';\nimport { Subscription } from '@dooboostore/core/message/Subscription';\nimport { ConstructorType, Optional } from '@dooboostore/core/types';\n\nexport type SwcConfigType = {\n rootRouter: ConstructorType<any>;\n routeType: 'path' | 'hash' | 'element';\n path?: string;\n window: Window;\n};\n\nexport type SwcAttributeConfigType = Optional<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _isInitialized = false;\n\n constructor(private host: HTMLElement) {}\n\n async connect() {\n if (this._isInitialized) return;\n this._isInitialized = true;\n\n // Wait for event loop to ensure attributes and global scripts are ready\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const configStr = this.host.getAttribute('swc-get-application-config');\n if (!configStr) return;\n\n try {\n const userConfig: SwcAttributeConfigType = new Function(`return ${configStr}`).apply(this.host);\n if (userConfig && userConfig.rootRouter) {\n const _config: SwcConfigType = {\n routeType: 'element',\n window: window,\n ...userConfig\n } as SwcConfigType;\n\n // Router Selection\n if (_config.routeType === 'path') {\n this.router = new PathRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'hash') {\n this.router = new HashRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'element') {\n this.router = new ElementRouter({ window: _config.window, firstUrl: _config.path });\n }\n\n // Routing sync\n if (this.router) {\n this.routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n if (route.triggerPoint === 'end') {\n this.simpleApplication?.routing(route.path);\n }\n });\n }\n\n // App start\n this.simpleApplication = new SimpleApplication(new SimOption({ excludeProxys: [Node], rootRouter: _config.rootRouter }));\n\n const otherInstanceSim = new Map<any, any>();\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n // Rendering\n const data = this.simpleApplication.sim(_config.rootRouter);\n if (data instanceof Node) {\n if (this.host.shadowRoot) this.host.shadowRoot.replaceChildren(data);\n else this.host.replaceChildren(data);\n }\n\n if (_config.path) await this.router?.go(_config.path);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
5
- "mappings": ";;;;;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EAAE,eAAe,CAAC,IAAI,GAAG,YAAY,QAAQ,WAAW,CAAC,CAAC;AAEvH,cAAM,mBAAmB,oBAAI,IAAc;AAC3C,YAAI,KAAK,OAAQ,kBAAiB,IAAI,sBAAQ,KAAK,MAAM;AACzD,aAAK,kBAAkB,IAAI,gBAAgB;AAG3C,cAAM,OAAO,KAAK,kBAAkB,IAAI,QAAQ,UAAU;AAC1D,YAAI,gBAAgB,MAAM;AACxB,cAAI,KAAK,KAAK,WAAY,MAAK,KAAK,WAAW,gBAAgB,IAAI;AAAA,cAC9D,MAAK,KAAK,gBAAgB,IAAI;AAAA,QACrC;AAEA,YAAI,QAAQ,KAAM,OAAM,KAAK,QAAQ,GAAG,QAAQ,IAAI;AAAA,MACtD;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,iCAAiC,CAAC;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,aAAa;AACX,SAAK,oBAAoB,YAAY;AAAA,EACvC;AACF;",
4
+ "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { PathRouter } from '@dooboostore/core-web/routers/PathRouter';\nimport { HashRouter } from '@dooboostore/core-web/routers/HashRouter';\nimport { ElementRouter } from '../router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot/SimOption';\nimport { Router, RouterEventType } from '@dooboostore/core-web/routers/Router';\nimport { Subscription } from '@dooboostore/core/message/Subscription';\nimport { ConstructorType, Optional } from '@dooboostore/core/types';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\n\nexport type SwcConfigType = {\n rootRouter: ConstructorType<any>;\n routeType: 'path' | 'hash' | 'element';\n path?: string;\n window: Window;\n};\n\nexport type SwcAttributeConfigType = Optional<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _isInitialized = false;\n\n constructor(private host: HTMLElement) {}\n\n async connect() {\n if (this._isInitialized) return;\n this._isInitialized = true;\n\n // Wait for event loop to ensure attributes and global scripts are ready\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const configStr = this.host.getAttribute('swc-get-application-config');\n if (!configStr) return;\n\n try {\n const userConfig: SwcAttributeConfigType = FunctionUtils.executeReturn({ script: configStr, context: this.host });\n if (userConfig && userConfig.rootRouter) {\n const _config: SwcConfigType = {\n routeType: 'element',\n window: window,\n ...userConfig\n } as SwcConfigType;\n\n // Router Selection\n if (_config.routeType === 'path') {\n this.router = new PathRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'hash') {\n this.router = new HashRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'element') {\n this.router = new ElementRouter({ window: _config.window, firstUrl: _config.path });\n }\n\n // Routing sync\n if (this.router) {\n this.routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n if (route.triggerPoint === 'end') {\n this.simpleApplication?.routing(route.path);\n }\n });\n }\n\n // App start\n this.simpleApplication = new SimpleApplication(new SimOption({ excludeProxys: [Node], rootRouter: _config.rootRouter }));\n\n const otherInstanceSim = new Map<any, any>();\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n // Rendering\n const data = this.simpleApplication.sim(_config.rootRouter);\n if (data instanceof Node) {\n if (this.host.shadowRoot) this.host.shadowRoot.replaceChildren(data);\n else this.host.replaceChildren(data);\n }\n\n if (_config.path) await this.router?.go(_config.path);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAkC;AAClC,wBAA2B;AAC3B,wBAA2B;AAC3B,2BAA8B;AAC9B,uBAA0B;AAC1B,oBAAwC;AAGxC,2BAA8B;AAWvB,MAAM,aAAa;AAAA,EAMxB,YAAoB,MAAmB;AAAnB;AAF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;AAG3C,cAAM,OAAO,KAAK,kBAAkB,IAAI,QAAQ,UAAU;AAC1D,YAAI,gBAAgB,MAAM;AACxB,cAAI,KAAK,KAAK,WAAY,MAAK,KAAK,WAAW,gBAAgB,IAAI;AAAA,cAC9D,MAAK,KAAK,gBAAgB,IAAI;AAAA,QACrC;AAEA,YAAI,QAAQ,KAAM,OAAM,KAAK,QAAQ,GAAG,QAAQ,IAAI;AAAA,MACtD;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,iCAAiC,CAAC;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,aAAa;AACX,SAAK,oBAAoB,YAAY;AAAA,EACvC;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,188 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var SwcAsync_exports = {};
19
+ __export(SwcAsync_exports, {
20
+ SwcAsync: () => SwcAsync
21
+ });
22
+ module.exports = __toCommonJS(SwcAsync_exports);
23
+ var import_elementDefine = require("../decorators/elementDefine");
24
+ var import_changedAttribute = require("../decorators/changedAttribute");
25
+ var import_Utils = require("../utils/Utils");
26
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
27
+ var __decorate = function(decorators, target, key, desc) {
28
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
29
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
30
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
32
+ };
33
+ var __metadata = function(k, v) {
34
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
+ };
36
+ let SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
37
+ constructor() {
38
+ super(...arguments);
39
+ this._nodes = [];
40
+ this._currentPromise = null;
41
+ this._value = null;
42
+ }
43
+ get value() {
44
+ return this._value;
45
+ }
46
+ set value(nv) {
47
+ if (nv instanceof Promise) {
48
+ this.handlePromise(nv);
49
+ } else {
50
+ this._value = nv;
51
+ this.render(nv === null ? "default" : "success", nv);
52
+ }
53
+ }
54
+ refresh(newValue) {
55
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
56
+ if (!script) {
57
+ this.value = null;
58
+ return;
59
+ }
60
+ if (!this.parentElement)
61
+ return;
62
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
63
+ try {
64
+ const result = import_FunctionUtils.FunctionUtils.executeReturn({
65
+ script,
66
+ context: this,
67
+ args: helperHostSet
68
+ });
69
+ if (result instanceof Promise) {
70
+ this.handlePromise(result);
71
+ } else {
72
+ this.value = result;
73
+ }
74
+ } catch (e) {
75
+ this.render("error", e);
76
+ }
77
+ }
78
+ async handlePromise(promise) {
79
+ this._currentPromise = promise;
80
+ this.render("loading");
81
+ try {
82
+ const result = await promise;
83
+ if (this._currentPromise !== promise)
84
+ return;
85
+ this._value = result;
86
+ this.render("success", result);
87
+ } catch (e) {
88
+ if (this._currentPromise !== promise)
89
+ return;
90
+ this.render("error", e);
91
+ }
92
+ }
93
+ render(state, data) {
94
+ this.cleanup();
95
+ if (!this.parentElement)
96
+ return;
97
+ let fragment;
98
+ const ctx = {
99
+ $nodes: [],
100
+ $elements: [],
101
+ $state: state,
102
+ $value: null,
103
+ $error: null
104
+ };
105
+ if (state === "default") {
106
+ const t = this.content.querySelector('template[is="swc-default"]');
107
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
108
+ } else if (state === "loading") {
109
+ const t = this.content.querySelector('template[is="swc-loading"]');
110
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
111
+ } else if (state === "error") {
112
+ const t = this.content.querySelector('template[is="swc-error"]');
113
+ ctx.$error = data;
114
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
115
+ } else {
116
+ const t = this.content.querySelector('template[is="swc-success"]');
117
+ ctx.$value = data;
118
+ if (t) {
119
+ fragment = t.content.cloneNode(true);
120
+ } else {
121
+ const clone = this.content.cloneNode(true);
122
+ Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
123
+ fragment = clone;
124
+ }
125
+ }
126
+ this.mount(fragment, ctx);
127
+ }
128
+ mount(fragment, ctx) {
129
+ const nodes = Array.from(fragment.childNodes);
130
+ const elements = nodes.filter((n) => n.nodeType === 1);
131
+ Object.assign(ctx, {
132
+ $nodes: nodes,
133
+ $elements: elements,
134
+ $firstNode: nodes[0],
135
+ $lastNode: nodes[nodes.length - 1],
136
+ $firstElement: elements[0],
137
+ $lastElement: elements[elements.length - 1]
138
+ });
139
+ this._executeCallback("on-clone-nodes", ctx);
140
+ nodes.forEach((node, nodeIndex) => {
141
+ if (node instanceof HTMLElement) {
142
+ node.__swc_host = this;
143
+ }
144
+ this._executeCallback("on-clone-node", {
145
+ ...ctx,
146
+ $node: node,
147
+ $nodeIndex: nodeIndex,
148
+ $isElement: node.nodeType === 1
149
+ });
150
+ });
151
+ this._nodes = nodes;
152
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
153
+ }
154
+ _executeCallback(attrName, extraArgs) {
155
+ const script = this.getAttribute(attrName);
156
+ if (!script)
157
+ return;
158
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
159
+ try {
160
+ import_FunctionUtils.FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
161
+ } catch (e) {
162
+ console.error(`[SwcAsync] Error in ${attrName}:`, e);
163
+ }
164
+ }
165
+ cleanup() {
166
+ this._nodes.forEach((n) => {
167
+ if (n.parentElement)
168
+ n.parentElement.removeChild(n);
169
+ });
170
+ this._nodes = [];
171
+ }
172
+ connectedCallback() {
173
+ this.refresh();
174
+ }
175
+ disconnectedCallback() {
176
+ this.cleanup();
177
+ }
178
+ };
179
+ __decorate([
180
+ (0, import_changedAttribute.changedAttribute)("on-get-value"),
181
+ __metadata("design:type", Function),
182
+ __metadata("design:paramtypes", [String]),
183
+ __metadata("design:returntype", void 0)
184
+ ], SwcAsync.prototype, "refresh", null);
185
+ SwcAsync = __decorate([
186
+ (0, import_elementDefine.elementDefine)({ name: "swc-async", extends: "template" })
187
+ ], SwcAsync);
188
+ //# sourceMappingURL=SwcAsync.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcAsync.ts"],
4
+ "sourcesContent": ["import { elementDefine } from '../decorators/elementDefine';\nimport { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\nimport { SwcLoading, SwcError, SwcSuccess, SwcDefault } from './SwcSubTemplates';\n\n@elementDefine({ name: 'swc-async', extends: 'template' })\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _currentPromise: Promise<any> | null = null;\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n if (nv instanceof Promise) {\n this.handlePromise(nv);\n } else {\n this._value = nv;\n this.render(nv === null ? 'default' : 'success', nv);\n }\n }\n\n @changedAttribute('on-get-value')\n private refresh(newValue?: string | null) {\n const script = newValue !== undefined ? newValue : this.getAttribute('on-get-value');\n if (!script) {\n this.value = null; // Triggers default render\n return;\n }\n if (!this.parentElement) return;\n\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n const result = FunctionUtils.executeReturn({\n script,\n context: this,\n args: helperHostSet\n });\n\n if (result instanceof Promise) {\n this.handlePromise(result);\n } else {\n this.value = result;\n }\n } catch (e) {\n this.render('error', e);\n }\n }\n\n private async handlePromise(promise: Promise<any>) {\n this._currentPromise = promise;\n this.render('loading');\n\n try {\n const result = await promise;\n if (this._currentPromise !== promise) return;\n this._value = result;\n this.render('success', result);\n } catch (e) {\n if (this._currentPromise !== promise) return;\n this.render('error', e);\n }\n }\n\n private render(state: 'loading' | 'error' | 'success' | 'default', data?: any) {\n this.cleanup();\n if (!this.parentElement) return;\n\n let fragment: DocumentFragment;\n const ctx: any = {\n $nodes: [],\n $elements: [],\n $state: state,\n $value: null,\n $error: null\n };\n\n if (state === 'default') {\n const t = this.content.querySelector('template[is=\"swc-default\"]') as HTMLTemplateElement;\n fragment = t ? (t.content.cloneNode(true) as DocumentFragment) : document.createDocumentFragment();\n } else if (state === 'loading') {\n const t = this.content.querySelector('template[is=\"swc-loading\"]') as HTMLTemplateElement;\n fragment = t ? (t.content.cloneNode(true) as DocumentFragment) : document.createDocumentFragment();\n } else if (state === 'error') {\n const t = this.content.querySelector('template[is=\"swc-error\"]') as HTMLTemplateElement;\n ctx.$error = data;\n fragment = t ? (t.content.cloneNode(true) as DocumentFragment) : document.createDocumentFragment();\n } else {\n // Success\n const t = this.content.querySelector('template[is=\"swc-success\"]') as HTMLTemplateElement;\n ctx.$value = data;\n if (t) {\n fragment = t.content.cloneNode(true) as DocumentFragment;\n } else {\n const clone = this.content.cloneNode(true) as DocumentFragment;\n Array.from(clone.querySelectorAll('template[is=\"swc-loading\"], template[is=\"swc-error\"], template[is=\"swc-success\"], template[is=\"swc-default\"]')).forEach(tmp => tmp.remove());\n fragment = clone;\n }\n }\n\n this.mount(fragment, ctx);\n }\n\n private mount(fragment: DocumentFragment, ctx: any) {\n const nodes = Array.from(fragment.childNodes);\n const elements = nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n\n Object.assign(ctx, {\n $nodes: nodes,\n $elements: elements,\n $firstNode: nodes[0],\n $lastNode: nodes[nodes.length - 1],\n $firstElement: elements[0],\n $lastElement: elements[elements.length - 1]\n });\n\n // Execution Callbacks\n this._executeCallback('on-clone-nodes', ctx);\n nodes.forEach((node, nodeIndex) => {\n if (node instanceof HTMLElement) {\n (node as any).__swc_host = this;\n }\n this._executeCallback('on-clone-node', {\n ...ctx,\n $node: node,\n $nodeIndex: nodeIndex,\n $isElement: node.nodeType === 1\n });\n });\n\n this._nodes = nodes;\n this.parentElement?.insertBefore(fragment, this.nextSibling);\n }\n\n private _executeCallback(attrName: string, extraArgs: Record<string, any>) {\n const script = this.getAttribute(attrName);\n if (!script) return;\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });\n } catch (e) {\n console.error(`[SwcAsync] Error in ${attrName}:`, e);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => {\n if (n.parentElement) n.parentElement.removeChild(n);\n });\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8B;AAC9B,8BAAiC;AACjC,mBAAyB;AACzB,2BAA8B;;;;;;;;;;AAIvB,IAAM,WAAN,MAAMA,kBAAiB,oBAAmB;EAA1C,cAAA;;AACG,SAAA,SAAiB,CAAA;AACjB,SAAA,kBAAuC;AACvC,SAAA,SAAc;EAwJxB;EAtJE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AACf,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b,UAAM,gBAAgB,sBAAS,oBAAoB,QAAQ,IAAI;AAC/D,QAAI;AACF,yCAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,MAAM,EAAE,GAAG,eAAe,GAAG,UAAS,EAAE,CAAE;IAC3F,SAAS,GAAG;AACV,cAAQ,MAAM,uBAAuB,QAAQ,KAAK,CAAC;IACrD;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAI;AACtB,UAAI,EAAE;AAAe,UAAE,cAAc,YAAY,CAAC;IACpD,CAAC;AACD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAvIQ,WAAA;MADP,0CAAiB,cAAc;;;;;AAlBrB,WAAQ,WAAA;MADpB,oCAAc,EAAE,MAAM,aAAa,SAAS,WAAU,CAAE;GAC5C,QAAQ;",
6
+ "names": ["SwcAsync"]
7
+ }
@@ -0,0 +1,155 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var SwcChoose_exports = {};
19
+ __export(SwcChoose_exports, {
20
+ SwcChoose: () => SwcChoose
21
+ });
22
+ module.exports = __toCommonJS(SwcChoose_exports);
23
+ var import_elementDefine = require("../decorators/elementDefine");
24
+ var import_changedAttribute = require("../decorators/changedAttribute");
25
+ var import_Utils = require("../utils/Utils");
26
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
27
+ var __decorate = function(decorators, target, key, desc) {
28
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
29
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
30
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
32
+ };
33
+ var __metadata = function(k, v) {
34
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
+ };
36
+ let SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
37
+ constructor() {
38
+ super(...arguments);
39
+ this._nodes = [];
40
+ this._value = null;
41
+ }
42
+ get value() {
43
+ return this._value;
44
+ }
45
+ set value(nv) {
46
+ this._value = nv;
47
+ this.render();
48
+ }
49
+ _executeCallback(attrName, extraArgs) {
50
+ const script = this.getAttribute(attrName);
51
+ if (!script)
52
+ return;
53
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
54
+ try {
55
+ import_FunctionUtils.FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
56
+ } catch (e) {
57
+ console.error(`[SwcChoose] Error in ${attrName}:`, e);
58
+ }
59
+ }
60
+ refresh(newValue) {
61
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
62
+ if (!script) {
63
+ this.value = null;
64
+ return;
65
+ }
66
+ if (!this.parentElement)
67
+ return;
68
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
69
+ try {
70
+ const result = import_FunctionUtils.FunctionUtils.executeReturn({
71
+ script,
72
+ context: this,
73
+ args: helperHostSet
74
+ });
75
+ this.value = result;
76
+ } catch (e) {
77
+ console.error("[SwcChoose] Error in on-get-value:", e);
78
+ }
79
+ }
80
+ render() {
81
+ this.cleanup();
82
+ if (!this.parentElement)
83
+ return;
84
+ const templates = Array.from(this.content.querySelectorAll("template"));
85
+ let selected = null;
86
+ let otherwise = null;
87
+ let defaultTmp = null;
88
+ for (const t of templates) {
89
+ const is = t.getAttribute("is");
90
+ if (is === "swc-when") {
91
+ const whenVal = t.getAttribute("value");
92
+ if (String(whenVal) === String(this._value)) {
93
+ selected = t;
94
+ break;
95
+ }
96
+ } else if (is === "swc-otherwise") {
97
+ otherwise = t;
98
+ } else if (is === "swc-default") {
99
+ defaultTmp = t;
100
+ }
101
+ }
102
+ const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
103
+ if (targetTemplate) {
104
+ const clone = targetTemplate.content.cloneNode(true);
105
+ const nodes = Array.from(clone.childNodes);
106
+ const elements = nodes.filter((n) => n.nodeType === 1);
107
+ const ctx = {
108
+ $value: this._value,
109
+ $nodes: nodes,
110
+ $elements: elements,
111
+ $firstNode: nodes[0],
112
+ $lastNode: nodes[nodes.length - 1],
113
+ $firstElement: elements[0],
114
+ $lastElement: elements[elements.length - 1]
115
+ };
116
+ this._executeCallback("on-clone-nodes", ctx);
117
+ nodes.forEach((node, nodeIndex) => {
118
+ if (node instanceof HTMLElement) {
119
+ node.__swc_host = this;
120
+ }
121
+ this._executeCallback("on-clone-node", {
122
+ ...ctx,
123
+ $node: node,
124
+ $nodeIndex: nodeIndex,
125
+ $isElement: node.nodeType === 1
126
+ });
127
+ });
128
+ this._nodes = nodes;
129
+ this.parentElement.insertBefore(clone, this.nextSibling);
130
+ }
131
+ }
132
+ cleanup() {
133
+ this._nodes.forEach((n) => {
134
+ if (n.parentElement)
135
+ n.parentElement.removeChild(n);
136
+ });
137
+ this._nodes = [];
138
+ }
139
+ connectedCallback() {
140
+ this.refresh();
141
+ }
142
+ disconnectedCallback() {
143
+ this.cleanup();
144
+ }
145
+ };
146
+ __decorate([
147
+ (0, import_changedAttribute.changedAttribute)("on-get-value"),
148
+ __metadata("design:type", Function),
149
+ __metadata("design:paramtypes", [String]),
150
+ __metadata("design:returntype", void 0)
151
+ ], SwcChoose.prototype, "refresh", null);
152
+ SwcChoose = __decorate([
153
+ (0, import_elementDefine.elementDefine)({ name: "swc-choose", extends: "template" })
154
+ ], SwcChoose);
155
+ //# sourceMappingURL=SwcChoose.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcChoose.ts"],
4
+ "sourcesContent": ["import { elementDefine } from '../decorators/elementDefine';\nimport { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\nimport { SwcWhen, SwcOtherwise } from './SwcSubTemplates';\n\n@elementDefine({ name: 'swc-choose', extends: 'template' })\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\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _executeCallback(attrName: string, extraArgs: Record<string, any>) {\n const script = this.getAttribute(attrName);\n if (!script) return;\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });\n } catch (e) {\n console.error(`[SwcChoose] Error in ${attrName}:`, e);\n }\n }\n\n @changedAttribute('on-get-value')\n private refresh(newValue?: string | null) {\n const script = newValue !== undefined ? newValue : this.getAttribute('on-get-value');\n if (!script) {\n this.value = null;\n return;\n }\n if (!this.parentElement) return;\n\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n const result = FunctionUtils.executeReturn({\n script,\n context: this,\n args: helperHostSet\n });\n this.value = result;\n } catch (e) {\n console.error('[SwcChoose] Error in on-get-value:', e);\n }\n }\n\n private render() {\n this.cleanup();\n if (!this.parentElement) return;\n\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n let otherwise: HTMLTemplateElement | null = null;\n let defaultTmp: HTMLTemplateElement | null = null;\n\n for (const t of templates) {\n const is = t.getAttribute('is');\n if (is === 'swc-when') {\n const whenVal = t.getAttribute('value');\n if (String(whenVal) === String(this._value)) {\n selected = t;\n break;\n }\n } else if (is === 'swc-otherwise') {\n otherwise = t;\n } else if (is === 'swc-default') {\n defaultTmp = t;\n }\n }\n\n const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;\n if (targetTemplate) {\n const clone = targetTemplate.content.cloneNode(true) as DocumentFragment;\n const nodes = Array.from(clone.childNodes);\n const elements = nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n\n const ctx = {\n $value: this._value,\n $nodes: nodes,\n $elements: elements,\n $firstNode: nodes[0],\n $lastNode: nodes[nodes.length - 1],\n $firstElement: elements[0],\n $lastElement: elements[elements.length - 1]\n };\n\n // Execution Callbacks\n this._executeCallback('on-clone-nodes', ctx);\n nodes.forEach((node, nodeIndex) => {\n if (node instanceof HTMLElement) {\n (node as any).__swc_host = this;\n }\n this._executeCallback('on-clone-node', {\n ...ctx,\n $node: node,\n $nodeIndex: nodeIndex,\n $isElement: node.nodeType === 1\n });\n });\n\n this._nodes = nodes;\n this.parentElement.insertBefore(clone, this.nextSibling);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => {\n if (n.parentElement) n.parentElement.removeChild(n);\n });\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8B;AAC9B,8BAAiC;AACjC,mBAAyB;AACzB,2BAA8B;;;;;;;;;;AAIvB,IAAM,YAAN,MAAMA,mBAAkB,oBAAmB;EAA3C,cAAA;;AACG,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EAqHxB;EAnHE,IAAI,QAAK;AACP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