@dooboostore/simple-web-component 1.0.35 → 1.0.37
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 +58 -21
- package/dist/cjs/{elements/SwcAppEngine.js → SwcAppEngine.js} +6 -6
- package/dist/cjs/SwcAppEngine.js.map +7 -0
- package/dist/cjs/decorators/addEventListener.js +12 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +19 -18
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +23 -22
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +28 -26
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +122 -0
- package/dist/cjs/decorators/applySlot.js.map +7 -0
- package/dist/cjs/decorators/applyStyle.js +20 -19
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +16 -15
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
- package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +59 -50
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +18 -16
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +2 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +56 -8
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +38 -60
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +31 -63
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +13 -12
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/elements/{SwcAppMixin.js → SwcApp.js} +107 -57
- package/dist/cjs/elements/SwcApp.js.map +7 -0
- package/dist/cjs/elements/index.js +21 -2
- package/dist/cjs/elements/index.js.map +3 -3
- package/dist/cjs/elements/tt/SwcAppMixin.js +1 -0
- package/dist/cjs/elements/tt/SwcAppMixin.js.map +7 -0
- package/dist/cjs/elements/tt/SwcAsync.js +1 -0
- package/dist/cjs/elements/tt/SwcAsync.js.map +7 -0
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcChoose.js +1 -0
- package/dist/cjs/elements/tt/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/tt/SwcChooseTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcIf.js +1 -0
- package/dist/cjs/elements/tt/SwcIf.js.map +7 -0
- package/dist/cjs/elements/tt/SwcIfTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcIfTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcLoop.js +1 -0
- package/dist/cjs/elements/tt/SwcLoop.js.map +7 -0
- package/dist/cjs/elements/tt/SwcLoopTemplate.js +1 -0
- package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +7 -0
- package/dist/cjs/elements/tt/SwcSubTemplates.js +1 -0
- package/dist/cjs/elements/tt/SwcSubTemplates.js.map +7 -0
- package/dist/cjs/elements/tt/register.js +1 -0
- package/dist/cjs/elements/tt/register.js.map +7 -0
- package/dist/cjs/index.js +12 -8
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types/window.d.js +16 -0
- package/dist/cjs/types/window.d.js.map +7 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +22 -19
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/{elements/SwcAppEngine.js → SwcAppEngine.js} +4 -4
- package/dist/esm/SwcAppEngine.js.map +7 -0
- package/dist/esm/decorators/addEventListener.js +12 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +19 -18
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +23 -22
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +28 -26
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +103 -0
- package/dist/esm/decorators/applySlot.js.map +7 -0
- package/dist/esm/decorators/applyStyle.js +20 -19
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +16 -15
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +60 -51
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +18 -16
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +2 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +56 -8
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +38 -60
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +31 -63
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +13 -12
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/elements/{SwcAppMixin.js → SwcApp.js} +102 -53
- package/dist/esm/elements/SwcApp.js.map +7 -0
- package/dist/esm/elements/index.js +7 -1
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/elements/tt/SwcAppMixin.js +1 -0
- package/dist/esm/elements/tt/SwcAppMixin.js.map +7 -0
- package/dist/esm/elements/tt/SwcAsync.js +1 -0
- package/dist/esm/elements/tt/SwcAsync.js.map +7 -0
- package/dist/esm/elements/tt/SwcAsyncTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcChoose.js +1 -0
- package/dist/esm/elements/tt/SwcChoose.js.map +7 -0
- package/dist/esm/elements/tt/SwcChooseTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcChooseTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcIf.js +1 -0
- package/dist/esm/elements/tt/SwcIf.js.map +7 -0
- package/dist/esm/elements/tt/SwcIfTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcIfTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcLoop.js +1 -0
- package/dist/esm/elements/tt/SwcLoop.js.map +7 -0
- package/dist/esm/elements/tt/SwcLoopTemplate.js +1 -0
- package/dist/esm/elements/tt/SwcLoopTemplate.js.map +7 -0
- package/dist/esm/elements/tt/SwcSubTemplates.js +1 -0
- package/dist/esm/elements/tt/SwcSubTemplates.js.map +7 -0
- package/dist/esm/elements/tt/register.js +1 -0
- package/dist/esm/elements/tt/register.js.map +7 -0
- package/dist/esm/index.js +13 -9
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types/window.d.js +1 -0
- package/dist/esm/types/window.d.js.map +7 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +22 -19
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4189 -456
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/{elements/SwcAppEngine.d.ts → SwcAppEngine.d.ts} +9 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -0
- package/dist/types/decorators/addEventListener.d.ts +5 -7
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +4 -4
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +6 -6
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +9 -9
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +27 -0
- package/dist/types/decorators/applySlot.d.ts.map +1 -0
- package/dist/types/decorators/applyStyle.d.ts +4 -4
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -5
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
- package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +4 -9
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +2 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +21 -6
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +17 -63
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +6 -63
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts +7 -0
- package/dist/types/elements/SwcApp.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +2 -1
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts +1 -0
- package/dist/types/elements/tt/SwcAppMixin.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcAsync.d.ts +1 -0
- package/dist/types/elements/tt/SwcAsync.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcChoose.d.ts +1 -0
- package/dist/types/elements/tt/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcIf.d.ts +1 -0
- package/dist/types/elements/{SwcIf.d.ts.map → tt/SwcIf.d.ts.map} +1 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcLoop.d.ts +1 -0
- package/dist/types/elements/tt/SwcLoop.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts +1 -0
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +1 -0
- package/dist/types/elements/tt/SwcSubTemplates.d.ts +1 -0
- package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +1 -0
- package/dist/types/elements/tt/register.d.ts +1 -0
- package/dist/types/elements/tt/register.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +5 -5
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +13 -12
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4189 -456
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/{elements/SwcAppEngine.ts → SwcAppEngine.ts} +12 -7
- package/src/decorators/addEventListener.ts +11 -9
- package/src/decorators/applyAttribute.ts +16 -15
- package/src/decorators/applyClass.ts +18 -17
- package/src/decorators/applyNode.ts +30 -27
- package/src/decorators/applySlot.ts +228 -0
- package/src/decorators/applyStyle.ts +17 -16
- package/src/decorators/attribute.ts +20 -19
- package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +10 -12
- package/src/decorators/elementDefine.ts +80 -57
- package/src/decorators/emitCustomEvent.ts +21 -26
- package/src/decorators/index.ts +2 -1
- package/src/decorators/lifecycles.ts +76 -11
- package/src/decorators/query.ts +51 -124
- package/src/decorators/queryAll.ts +30 -127
- package/src/decorators/setProperty.ts +12 -11
- package/src/elements/{SwcAppMixin.ts → SwcApp.ts} +98 -31
- package/src/elements/index.ts +11 -1
- package/src/elements/tt/SwcAppMixin.ts +13 -0
- package/src/elements/tt/SwcAsync.ts +139 -0
- package/src/elements/tt/SwcAsyncTemplate.ts +126 -0
- package/src/elements/tt/SwcChoose.ts +182 -0
- package/src/elements/tt/SwcChooseTemplate.ts +229 -0
- package/src/elements/tt/SwcIf.ts +145 -0
- package/src/elements/tt/SwcIfTemplate.ts +158 -0
- package/src/elements/tt/SwcLoop.ts +222 -0
- package/src/elements/tt/SwcLoopTemplate.ts +255 -0
- package/src/elements/tt/SwcSubTemplates.ts +6 -0
- package/src/elements/tt/register.ts +720 -0
- package/src/index.ts +13 -9
- package/src/types/window.d.ts +43 -0
- package/src/types.ts +9 -8
- package/src/utils/Utils.ts +28 -24
- package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
- package/dist/cjs/elements/SwcAppEngine.js.map +0 -7
- package/dist/cjs/elements/SwcAppMixin.js.map +0 -7
- package/dist/cjs/elements/SwcAsync.js +0 -129
- package/dist/cjs/elements/SwcAsync.js.map +0 -7
- package/dist/cjs/elements/SwcChoose.js +0 -155
- package/dist/cjs/elements/SwcChoose.js.map +0 -7
- package/dist/cjs/elements/SwcIf.js +0 -117
- package/dist/cjs/elements/SwcIf.js.map +0 -7
- package/dist/cjs/elements/SwcLoop.js +0 -176
- package/dist/cjs/elements/SwcLoop.js.map +0 -7
- package/dist/cjs/elements/SwcSubTemplates.js +0 -13
- package/dist/cjs/elements/SwcSubTemplates.js.map +0 -7
- package/dist/cjs/elements/register.js +0 -1026
- package/dist/cjs/elements/register.js.map +0 -7
- package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
- package/dist/esm/elements/SwcAppEngine.js.map +0 -7
- package/dist/esm/elements/SwcAppMixin.js.map +0 -7
- package/dist/esm/elements/SwcAsync.js +0 -129
- package/dist/esm/elements/SwcAsync.js.map +0 -7
- package/dist/esm/elements/SwcChoose.js +0 -155
- package/dist/esm/elements/SwcChoose.js.map +0 -7
- package/dist/esm/elements/SwcIf.js +0 -117
- package/dist/esm/elements/SwcIf.js.map +0 -7
- package/dist/esm/elements/SwcLoop.js +0 -176
- package/dist/esm/elements/SwcLoop.js.map +0 -7
- package/dist/esm/elements/SwcSubTemplates.js +0 -13
- package/dist/esm/elements/SwcSubTemplates.js.map +0 -7
- package/dist/esm/elements/register.js +0 -1007
- package/dist/esm/elements/register.js.map +0 -7
- package/dist/types/decorators/changedAttributeHost.d.ts +0 -20
- package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +0 -1
- package/dist/types/elements/SwcAppMixin.d.ts +0 -386
- package/dist/types/elements/SwcAppMixin.d.ts.map +0 -1
- package/dist/types/elements/SwcAsync.d.ts +0 -2
- package/dist/types/elements/SwcAsync.d.ts.map +0 -1
- package/dist/types/elements/SwcChoose.d.ts +0 -2
- package/dist/types/elements/SwcChoose.d.ts.map +0 -1
- package/dist/types/elements/SwcIf.d.ts +0 -2
- package/dist/types/elements/SwcLoop.d.ts +0 -2
- package/dist/types/elements/SwcLoop.d.ts.map +0 -1
- package/dist/types/elements/SwcSubTemplates.d.ts +0 -13
- package/dist/types/elements/SwcSubTemplates.d.ts.map +0 -1
- package/dist/types/elements/register.d.ts +0 -4
- package/dist/types/elements/register.d.ts.map +0 -1
- package/src/elements/SwcAsync.ts +0 -126
- package/src/elements/SwcChoose.ts +0 -190
- package/src/elements/SwcIf.ts +0 -124
- package/src/elements/SwcLoop.ts +0 -205
- package/src/elements/SwcSubTemplates.ts +0 -6
- package/src/elements/register.ts +0 -1022
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dooboostore/simple-web-component",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -92,10 +92,10 @@
|
|
|
92
92
|
"webpack": "^5.93.0",
|
|
93
93
|
"webpack-cli": "^5.1.4",
|
|
94
94
|
"webpack-dev-server": "^5.2.0",
|
|
95
|
-
"@dooboostore/simple-boot": "1.0.55",
|
|
96
|
-
"@dooboostore/core-node": "1.0.12",
|
|
97
95
|
"@dooboostore/core": "1.0.31",
|
|
98
|
-
"@dooboostore/core-
|
|
96
|
+
"@dooboostore/core-node": "1.0.12",
|
|
97
|
+
"@dooboostore/core-web": "1.0.11",
|
|
98
|
+
"@dooboostore/simple-boot": "1.0.55"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"clean": "rm -rf dist",
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import { SimpleApplication } from '@dooboostore/simple-boot
|
|
1
|
+
import { SimpleApplication } from '@dooboostore/simple-boot';
|
|
2
2
|
import { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/core-web';
|
|
3
|
-
import { ElementRouter } from '
|
|
4
|
-
import { SimOption } from '@dooboostore/simple-boot
|
|
3
|
+
import { ElementRouter } from './router/ElementRouter';
|
|
4
|
+
import { SimOption } from '@dooboostore/simple-boot';
|
|
5
5
|
import { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';
|
|
6
6
|
|
|
7
|
-
import { SwcAppInterface } from '
|
|
7
|
+
import { SwcAppInterface } from './types';
|
|
8
8
|
import { SimConfig } from '@dooboostore/simple-boot';
|
|
9
9
|
|
|
10
10
|
export type SwcConfigType = {
|
|
11
11
|
routeType: 'path' | 'hash' | 'element';
|
|
12
|
-
connectMode?: 'direct' | 'swap' | 'clear-swap';
|
|
12
|
+
connectMode?: 'direct' | 'swap' | 'clear-swap' | 'hydrate'; // hydrate 아직 개발중
|
|
13
13
|
container?: symbol;
|
|
14
14
|
otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;
|
|
15
15
|
path?: string;
|
|
16
16
|
window: Window;
|
|
17
|
-
onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => void;
|
|
17
|
+
onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => Promise<void> | void;
|
|
18
|
+
onConnectedChildAfter?: (swcEl: HTMLElement) => void;
|
|
19
|
+
onConnectedChildBefore?: (swcEl: HTMLElement) => void;
|
|
20
|
+
onDisconnectedChildAfter?: (swcEl: HTMLElement) => void;
|
|
21
|
+
onDisconnectedChildBefore?: (swcEl: HTMLElement) => void;
|
|
18
22
|
onConnected?: (app: SwcAppInterface) => void;
|
|
19
23
|
onDisconnected?: (app: SwcAppInterface) => void;
|
|
24
|
+
ssr?: boolean;
|
|
20
25
|
|
|
21
26
|
onChildrenConnectedDone?: (app: SwcAppInterface) => void;
|
|
22
27
|
// onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;
|
|
@@ -71,7 +76,7 @@ export class SwcAppEngine {
|
|
|
71
76
|
this.simpleApplication.run(otherInstanceSim);
|
|
72
77
|
|
|
73
78
|
if (this._config.onEngineStarted) {
|
|
74
|
-
this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
|
|
79
|
+
await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
|
|
75
80
|
}
|
|
76
81
|
} catch (e) {
|
|
77
82
|
console.error('[SWC-APP-ENGINE] Init failed:', e, this._config);
|
|
@@ -47,19 +47,21 @@ export const getAddEventListenerMetadata = (target: any): AddEventListenerMetada
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* @
|
|
51
|
-
* Usage: @addEventListenerHost('click')
|
|
52
|
-
* Usage: @addEventListenerHost('click', { stopPropagation: true })
|
|
50
|
+
* @addEventListenerThis decorator - simplified version of @addEventListener for $this selector
|
|
53
51
|
*/
|
|
54
|
-
export function
|
|
55
|
-
return addEventListener('
|
|
52
|
+
export function addEventListenerThis(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
53
|
+
return addEventListener('$this', type, options);
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
/**
|
|
59
|
-
* @addEventListenerAppHost decorator - simplified version of @addEventListener for
|
|
60
|
-
* Usage: @addEventListenerAppHost('click')
|
|
61
|
-
* Usage: @addEventListenerAppHost('click', { stopPropagation: true })
|
|
57
|
+
* @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector
|
|
62
58
|
*/
|
|
63
59
|
export function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
64
|
-
return addEventListener('
|
|
60
|
+
return addEventListener('$appHost', type, options);
|
|
61
|
+
}
|
|
62
|
+
export function addEventListenerWindow(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
63
|
+
return addEventListener('$window', type, options);
|
|
64
|
+
}
|
|
65
|
+
export function addEventListenerDocument(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
66
|
+
return addEventListener('$document', type, options);
|
|
65
67
|
}
|
|
@@ -61,15 +61,16 @@ function createAttributeDecorator(action: AttributeAction) {
|
|
|
61
61
|
targetEls.push(t);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
if (selector === '
|
|
65
|
-
else if (selector === '
|
|
66
|
-
else if (selector === '
|
|
67
|
-
else if (selector === '
|
|
68
|
-
else if (selector === '
|
|
69
|
-
else if (selector === '
|
|
70
|
-
else if (selector === '
|
|
71
|
-
else if (selector === '
|
|
72
|
-
else if (selector === '
|
|
64
|
+
if (selector === '$this' || !selector) applyRoot(host);
|
|
65
|
+
else if (selector === '$host') applyRoot(hostSet.$host);
|
|
66
|
+
else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
|
|
67
|
+
else if (selector === '$appHost') applyRoot(hostSet.$appHost);
|
|
68
|
+
else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
|
|
69
|
+
else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
|
|
70
|
+
else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
71
|
+
else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
72
|
+
else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
|
|
73
|
+
else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
73
74
|
else {
|
|
74
75
|
const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
|
|
75
76
|
if (targetRoot) {
|
|
@@ -140,13 +141,13 @@ export const setAttribute = (selector: string, nameOrOptions?: string | Attribut
|
|
|
140
141
|
export const updateAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(selector, nameOrOptions, options);
|
|
141
142
|
export const removeAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(selector, nameOrOptions, options);
|
|
142
143
|
|
|
143
|
-
//
|
|
144
|
-
export function
|
|
145
|
-
return createAttributeDecorator(action)('
|
|
144
|
+
// This versions
|
|
145
|
+
export function applyAttributeThis(action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {
|
|
146
|
+
return createAttributeDecorator(action)('$this', options);
|
|
146
147
|
}
|
|
147
|
-
export const
|
|
148
|
-
export const
|
|
149
|
-
export const
|
|
148
|
+
export const setAttributeThis = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')('$this', nameOrOptions, options);
|
|
149
|
+
export const updateAttributeThis = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')('$this', nameOrOptions, options);
|
|
150
|
+
export const removeAttributeThis = (nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')('$this', nameOrOptions, options);
|
|
150
151
|
|
|
151
152
|
export const findAllAttributeApplyMetadata = (target: any): Map<string | symbol, AttributeApplyMetadata> => {
|
|
152
153
|
const result = new Map<string | symbol, AttributeApplyMetadata>();
|
|
@@ -57,15 +57,16 @@ function createClassDecorator(action: ClassAction) {
|
|
|
57
57
|
targetEls.push(t);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
if (selector === '
|
|
61
|
-
else if (selector === '
|
|
62
|
-
else if (selector === '
|
|
63
|
-
else if (selector === '
|
|
64
|
-
else if (selector === '
|
|
65
|
-
else if (selector === '
|
|
66
|
-
else if (selector === '
|
|
67
|
-
else if (selector === '
|
|
68
|
-
else if (selector === '
|
|
60
|
+
if (selector === '$this' || !selector) applyRoot(host);
|
|
61
|
+
else if (selector === '$host') applyRoot(hostSet.$host);
|
|
62
|
+
else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
|
|
63
|
+
else if (selector === '$appHost') applyRoot(hostSet.$appHost);
|
|
64
|
+
else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
|
|
65
|
+
else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
|
|
66
|
+
else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
67
|
+
else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
68
|
+
else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
|
|
69
|
+
else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
69
70
|
else {
|
|
70
71
|
const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
|
|
71
72
|
if (targetRoot) {
|
|
@@ -150,15 +151,15 @@ export const addClass = (selector: string, classMapOrOptions?: string | { [class
|
|
|
150
151
|
export const removeClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('remove')(selector, classMapOrOptions, options);
|
|
151
152
|
export const toggleClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('toggle')(selector, classMapOrOptions, options);
|
|
152
153
|
|
|
153
|
-
//
|
|
154
|
-
export function
|
|
155
|
-
return createClassDecorator(action)('
|
|
154
|
+
// This versions
|
|
155
|
+
export function applyClassThis(action: ClassAction = 'update', options: ClassApplyOptions = {}): MethodDecorator {
|
|
156
|
+
return createClassDecorator(action)('$this', options);
|
|
156
157
|
}
|
|
157
|
-
export const
|
|
158
|
-
export const
|
|
159
|
-
export const
|
|
160
|
-
export const
|
|
161
|
-
export const
|
|
158
|
+
export const setClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('set')('$this', classMapOrOptions, options);
|
|
159
|
+
export const updateClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('update')('$this', classMapOrOptions, options);
|
|
160
|
+
export const addClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('add')('$this', classMapOrOptions, options);
|
|
161
|
+
export const removeClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('remove')('$this', classMapOrOptions, options);
|
|
162
|
+
export const toggleClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('toggle')('$this', classMapOrOptions, options);
|
|
162
163
|
|
|
163
164
|
export const findAllClassMetadata = (target: any): Map<string | symbol, ClassApplyMetadata> => {
|
|
164
165
|
const result = new Map<string | symbol, ClassApplyMetadata>();
|
|
@@ -4,7 +4,7 @@ import { HelperHostSet, SwcRootType } from '../types';
|
|
|
4
4
|
import { SwcUtils } from "../utils/Utils";
|
|
5
5
|
/*
|
|
6
6
|
<!-- beforebegin -->
|
|
7
|
-
<p>
|
|
7
|
+
<p> <-- it's me
|
|
8
8
|
<!-- afterbegin -->
|
|
9
9
|
foo
|
|
10
10
|
<!-- beforeend -->
|
|
@@ -43,8 +43,10 @@ const normalizeNodes = (res: any, doc: Document): Node[] => {
|
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition,
|
|
46
|
+
const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {
|
|
47
47
|
if (!targetEl) return;
|
|
48
|
+
|
|
49
|
+
const doc = win.document;
|
|
48
50
|
|
|
49
51
|
if (pos === 'innerHtml') {
|
|
50
52
|
targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
|
|
@@ -58,7 +60,7 @@ const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, doc: Docume
|
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
const isShadowRoot = targetEl instanceof ShadowRoot;
|
|
63
|
+
const isShadowRoot = targetEl instanceof win.ShadowRoot;
|
|
62
64
|
const nodes = normalizeNodes(res, doc);
|
|
63
65
|
if (pos === 'replace') {
|
|
64
66
|
if (!isShadowRoot) targetEl.replaceWith(...nodes);
|
|
@@ -105,11 +107,12 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
|
|
|
105
107
|
return t;
|
|
106
108
|
};
|
|
107
109
|
|
|
108
|
-
if (selector === '
|
|
109
|
-
if (selector === '
|
|
110
|
-
if (selector === '
|
|
111
|
-
if (selector === '
|
|
112
|
-
if (selector === '
|
|
110
|
+
if (selector === '$this') return applyRoot(this);
|
|
111
|
+
if (selector === '$host') return applyRoot(hostSet.$host);
|
|
112
|
+
if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
113
|
+
if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
114
|
+
if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
115
|
+
if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
113
116
|
|
|
114
117
|
const targetRoot = applyRoot(this);
|
|
115
118
|
return targetRoot ? targetRoot.querySelector(selector) : null;
|
|
@@ -123,7 +126,7 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
|
|
|
123
126
|
|
|
124
127
|
// 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
|
|
125
128
|
if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
|
|
126
|
-
applyToDom(target, val, pos,
|
|
129
|
+
applyToDom(target, val, pos, currentWin);
|
|
127
130
|
}
|
|
128
131
|
};
|
|
129
132
|
|
|
@@ -157,38 +160,38 @@ export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, Appl
|
|
|
157
160
|
return result;
|
|
158
161
|
};
|
|
159
162
|
|
|
160
|
-
export function
|
|
161
|
-
export function
|
|
162
|
-
export function
|
|
163
|
-
if (propertyKey !== undefined) return applyNode('
|
|
163
|
+
export function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;
|
|
164
|
+
export function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
165
|
+
export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
166
|
+
if (propertyKey !== undefined) return applyNode('$this', { position: 'beforeEnd' })(targetOrOptions, propertyKey, descriptor);
|
|
164
167
|
const opt = targetOrOptions || {};
|
|
165
|
-
return applyNode('
|
|
168
|
+
return applyNode('$this', { position: 'beforeEnd', ...opt });
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
export function
|
|
169
|
-
export function
|
|
170
|
-
export function
|
|
171
|
-
if (propertyKey !== undefined) return applyNode('
|
|
171
|
+
export function applyNodeThisReplaceChildren(options: ApplyNodeOptions): MethodDecorator;
|
|
172
|
+
export function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
173
|
+
export function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
174
|
+
if (propertyKey !== undefined) return applyNode('$this', { position: 'replaceChildren' })(targetOrOptions, propertyKey, descriptor);
|
|
172
175
|
const opt = targetOrOptions || {};
|
|
173
|
-
return applyNode('
|
|
176
|
+
return applyNode('$this', { position: 'replaceChildren', ...opt });
|
|
174
177
|
}
|
|
175
178
|
|
|
176
|
-
export function
|
|
177
|
-
export function
|
|
178
|
-
export function
|
|
179
|
-
if (propertyKey !== undefined) return applyNode('
|
|
179
|
+
export function applyThisInnerHtmlNode(options: ApplyNodeOptions): MethodDecorator;
|
|
180
|
+
export function applyThisInnerHtmlNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
181
|
+
export function applyThisInnerHtmlNode(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
182
|
+
if (propertyKey !== undefined) return applyNode('$this', { position: 'innerHtml' })(targetOrOptions, propertyKey, descriptor);
|
|
180
183
|
const opt = targetOrOptions || {};
|
|
181
|
-
return applyNode('
|
|
184
|
+
return applyNode('$this', { position: 'innerHtml', ...opt });
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
export function
|
|
187
|
+
export function applyNodeReplaceChildren(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
|
|
185
188
|
return applyNode(selector, { ...options, position: 'replaceChildren' });
|
|
186
189
|
}
|
|
187
190
|
|
|
188
|
-
export function
|
|
191
|
+
export function applyNodeInnerHtml(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
|
|
189
192
|
return applyNode(selector, { ...options, position: 'innerHtml' });
|
|
190
193
|
}
|
|
191
194
|
|
|
192
|
-
export function
|
|
195
|
+
export function applyNodeInnerText(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
|
|
193
196
|
return applyNode(selector, { ...options, position: 'innerText' });
|
|
194
197
|
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
+
import { ensureInit, getElementConfig } from './elementDefine';
|
|
3
|
+
import { HelperHostSet, SwcRootType } from '../types';
|
|
4
|
+
import { SwcUtils } from "../utils/Utils";
|
|
5
|
+
import {NodeSlot} from "@dooboostore/core-web";
|
|
6
|
+
/*
|
|
7
|
+
<!-- beforebegin -->
|
|
8
|
+
<p> <-- it's me
|
|
9
|
+
<!-- afterbegin -->
|
|
10
|
+
foo
|
|
11
|
+
<!-- beforeend -->
|
|
12
|
+
</p>
|
|
13
|
+
<!-- afterend -->
|
|
14
|
+
*/
|
|
15
|
+
export type ApplySlotPosition = 'prependHtml' | 'prependText' | 'appendHtml' | 'appendText' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';
|
|
16
|
+
|
|
17
|
+
export interface ApplySlotOptions {
|
|
18
|
+
position?: ApplySlotPosition;
|
|
19
|
+
// root?: SwcRootType;
|
|
20
|
+
/**
|
|
21
|
+
* Filter function to determine whether to perform DOM operation.
|
|
22
|
+
* If it returns false, the operation is skipped.
|
|
23
|
+
*/
|
|
24
|
+
// filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta:{currentThis: any,helper: HelperHostSet}) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Optional loading content to display while an async method is executing.
|
|
27
|
+
*/
|
|
28
|
+
// loading?: (helper: HelperHostSet) => any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ApplySlotMetadata {
|
|
32
|
+
propertyKey: string | symbol;
|
|
33
|
+
id: string;
|
|
34
|
+
type: 'method' | 'property';
|
|
35
|
+
options: ApplySlotOptions;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-slot');
|
|
39
|
+
|
|
40
|
+
// const normalizeNodes = (res: any, doc: Document): Node[] => {
|
|
41
|
+
// const items = Array.isArray(res) ? res : [res];
|
|
42
|
+
// return items.map(it => {
|
|
43
|
+
// if (it instanceof Node) return it;
|
|
44
|
+
// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');
|
|
45
|
+
// });
|
|
46
|
+
// };
|
|
47
|
+
|
|
48
|
+
// const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {
|
|
49
|
+
// if (!targetEl) return;
|
|
50
|
+
//
|
|
51
|
+
// const doc = win.document;
|
|
52
|
+
//
|
|
53
|
+
// if (pos === 'innerHtml') {
|
|
54
|
+
// targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
|
|
55
|
+
// return;
|
|
56
|
+
// }
|
|
57
|
+
//
|
|
58
|
+
// if (pos === 'innerText') {
|
|
59
|
+
// if (targetEl.innerText !== undefined) {
|
|
60
|
+
// targetEl.innerText = res !== undefined && res !== null ? String(res) : '';
|
|
61
|
+
// }
|
|
62
|
+
// return;
|
|
63
|
+
// }
|
|
64
|
+
//
|
|
65
|
+
// const isShadowRoot = targetEl instanceof win.ShadowRoot;
|
|
66
|
+
// const nodes = normalizeNodes(res, doc);
|
|
67
|
+
// if (pos === 'replace') {
|
|
68
|
+
// if (!isShadowRoot) targetEl.replaceWith(...nodes);
|
|
69
|
+
// } else if (pos === 'replaceChildren') {
|
|
70
|
+
// targetEl.replaceChildren(...nodes);
|
|
71
|
+
// } else {
|
|
72
|
+
// if (pos === 'beforeEnd') targetEl.append(...nodes);
|
|
73
|
+
// else if (pos === 'afterBegin') targetEl.prepend(...nodes);
|
|
74
|
+
// else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
|
|
75
|
+
// else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
|
|
76
|
+
// }
|
|
77
|
+
// };
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @applyNode decorator to surgically add/replace nodes to a target element.
|
|
81
|
+
*/
|
|
82
|
+
export function applySlot(id: string, options: ApplySlotOptions = { position: 'replaceChildrenHtml' }): MethodDecorator & PropertyDecorator {
|
|
83
|
+
return (targetObj: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
|
|
84
|
+
const type = descriptor === undefined ? 'property' : 'method';
|
|
85
|
+
|
|
86
|
+
if (type === 'property') {
|
|
87
|
+
Object.defineProperty(targetObj, propertyKey, {
|
|
88
|
+
get(this: any) {
|
|
89
|
+
const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
|
|
90
|
+
return nodeSlot;
|
|
91
|
+
},
|
|
92
|
+
configurable: true,
|
|
93
|
+
enumerable: true,
|
|
94
|
+
})
|
|
95
|
+
// return nodeSlot;
|
|
96
|
+
// return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const constructor = targetObj.constructor;
|
|
100
|
+
let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor) as ApplySlotMetadata[];
|
|
101
|
+
if (!metaList) {
|
|
102
|
+
metaList = []
|
|
103
|
+
ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
|
|
104
|
+
}
|
|
105
|
+
metaList.push({ propertyKey, id, type, options });
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if (type === 'method') {
|
|
110
|
+
const original = descriptor.value;
|
|
111
|
+
descriptor.value = function (...args: any[]) {
|
|
112
|
+
ensureInit(this);
|
|
113
|
+
|
|
114
|
+
const conf = getElementConfig(this);
|
|
115
|
+
const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
|
|
116
|
+
const currentDoc = currentWin.document;
|
|
117
|
+
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// const getTarget = () => {
|
|
121
|
+
// const r = options.root || 'auto';
|
|
122
|
+
// const applyRoot = (t: any) => {
|
|
123
|
+
// if (!t) return t;
|
|
124
|
+
// if (r === 'auto') return t.shadowRoot || t;
|
|
125
|
+
// if (r === 'shadow') return t.shadowRoot;
|
|
126
|
+
// if (r === 'light') return t;
|
|
127
|
+
// if (r === 'all') return t.shadowRoot || t;
|
|
128
|
+
// return t;
|
|
129
|
+
// };
|
|
130
|
+
//
|
|
131
|
+
// if (selector === '$this') return applyRoot(this);
|
|
132
|
+
// if (selector === '$host') return applyRoot(hostSet.$host);
|
|
133
|
+
// if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
134
|
+
// if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
135
|
+
// if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
136
|
+
// if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
137
|
+
//
|
|
138
|
+
// const targetRoot = applyRoot(this);
|
|
139
|
+
// return targetRoot ? targetRoot.querySelector(selector) : null;
|
|
140
|
+
// };
|
|
141
|
+
|
|
142
|
+
// const targetEl = getTarget();
|
|
143
|
+
const res = original.apply(this, args);
|
|
144
|
+
|
|
145
|
+
// const runApply = (target: any, val: any) => {
|
|
146
|
+
// const pos = options.position || 'beforeEnd';
|
|
147
|
+
//
|
|
148
|
+
// // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
|
|
149
|
+
// if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
|
|
150
|
+
// applyToDom(target, val, pos, currentWin);
|
|
151
|
+
// }
|
|
152
|
+
// };
|
|
153
|
+
|
|
154
|
+
// if (res instanceof Promise) {
|
|
155
|
+
// // 비동기일 때만 로딩 표시
|
|
156
|
+
// if (targetEl && options.loading) {
|
|
157
|
+
// const loadingRes = options.loading.call(this, hostSet);
|
|
158
|
+
// applyToDom(targetEl, loadingRes, options.position || 'beforeEnd', currentDoc);
|
|
159
|
+
// }
|
|
160
|
+
//
|
|
161
|
+
// return res.then(finalRes => {
|
|
162
|
+
// if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
|
|
163
|
+
// return finalRes;
|
|
164
|
+
// });
|
|
165
|
+
// } else {
|
|
166
|
+
// if (res !== undefined && targetEl) runApply(targetEl, res);
|
|
167
|
+
// return res;
|
|
168
|
+
// }
|
|
169
|
+
if (res) {
|
|
170
|
+
const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
|
|
171
|
+
const pos = options.position || 'replaceChildrenHtml';
|
|
172
|
+
const doc = currentWin.document;
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
// const isShadowRoot = targetEl instanceof win.ShadowRoot;
|
|
176
|
+
// const nodes = normalizeNodes(res, doc);
|
|
177
|
+
if (pos === 'replaceChildrenHtml') {
|
|
178
|
+
nodeSlot.replaceChildrenHtml(res);
|
|
179
|
+
} else if (pos === 'replaceChildrenText') {
|
|
180
|
+
nodeSlot.replaceChildrenText(res);
|
|
181
|
+
} else if (pos === 'appendHtml') {
|
|
182
|
+
nodeSlot.appendHtml(res);
|
|
183
|
+
} else if (pos === 'appendText') {
|
|
184
|
+
nodeSlot.appendText(res);
|
|
185
|
+
} else if (pos === 'prependHtml') {
|
|
186
|
+
nodeSlot.prependHtml(res);
|
|
187
|
+
} else if (pos === 'prependText') {
|
|
188
|
+
nodeSlot.prependText(res);
|
|
189
|
+
} else if (pos === 'clear') {
|
|
190
|
+
nodeSlot.clear();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return res;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// export const findAllApplySlotMetadata = (target: any): Map<string | symbol, ApplySlotMetadata> => {
|
|
200
|
+
export const findAllApplySlotMetadata = (target: any): ApplySlotMetadata[] => {
|
|
201
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
202
|
+
return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function applySlotClear(id: string): MethodDecorator {
|
|
206
|
+
return applySlot(id, { position: 'clear' });
|
|
207
|
+
}
|
|
208
|
+
export function applySlotPrependHtml(id: string): MethodDecorator {
|
|
209
|
+
return applySlot(id, { position: 'prependHtml' });
|
|
210
|
+
}
|
|
211
|
+
export const applySlotPrepend = applySlotPrependHtml;
|
|
212
|
+
export function applySlotPrependText(id: string): MethodDecorator {
|
|
213
|
+
return applySlot(id, { position: 'prependText' });
|
|
214
|
+
}
|
|
215
|
+
export function applySlotAppendHtml(id: string): MethodDecorator {
|
|
216
|
+
return applySlot(id, { position: 'appendHtml' });
|
|
217
|
+
}
|
|
218
|
+
export function applySlotAppendText(id: string): MethodDecorator {
|
|
219
|
+
return applySlot(id, { position: 'appendText' });
|
|
220
|
+
}
|
|
221
|
+
export const applySlotAppend = applySlotAppendHtml;
|
|
222
|
+
export function applySlotReplaceChildrenHtml(id: string): MethodDecorator {
|
|
223
|
+
return applySlot(id, { position: 'replaceChildrenHtml' });
|
|
224
|
+
}
|
|
225
|
+
export const applySlotReplaceChildren = applySlotReplaceChildrenHtml;
|
|
226
|
+
export function applySlotReplaceChildrenText(id: string): MethodDecorator {
|
|
227
|
+
return applySlot(id, { position: 'replaceChildrenText' });
|
|
228
|
+
}
|
|
@@ -38,7 +38,7 @@ function createStyleDecorator(action: StyleAction) {
|
|
|
38
38
|
if (resolvedValue !== undefined) {
|
|
39
39
|
const win = (this as any).ownerDocument?.defaultView || window;
|
|
40
40
|
const host = this as unknown as HTMLElement;
|
|
41
|
-
const hostSet = SwcUtils.getHelperAndHostSet(win, host);
|
|
41
|
+
const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
42
42
|
const r = options.root || 'auto';
|
|
43
43
|
const targetEls: HTMLElement[] = [];
|
|
44
44
|
|
|
@@ -47,15 +47,16 @@ function createStyleDecorator(action: StyleAction) {
|
|
|
47
47
|
targetEls.push(t);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
if (selector === '
|
|
51
|
-
else if (selector === '
|
|
52
|
-
else if (selector === '
|
|
53
|
-
else if (selector === '
|
|
54
|
-
else if (selector === '
|
|
55
|
-
else if (selector === '
|
|
56
|
-
else if (selector === '
|
|
57
|
-
else if (selector === '
|
|
58
|
-
else if (selector === '
|
|
50
|
+
if (selector === '$this' || !selector) applyRoot(host);
|
|
51
|
+
else if (selector === '$host') applyRoot(hostSet.$host);
|
|
52
|
+
else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
|
|
53
|
+
else if (selector === '$appHost') applyRoot(hostSet.$appHost);
|
|
54
|
+
else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
|
|
55
|
+
else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
|
|
56
|
+
else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
57
|
+
else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
58
|
+
else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
|
|
59
|
+
else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
59
60
|
else {
|
|
60
61
|
const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
|
|
61
62
|
if (targetRoot) {
|
|
@@ -122,13 +123,13 @@ export const setStyle = (selector: string, options: StyleApplyOptions = {}) => c
|
|
|
122
123
|
export const updateStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('update')(selector, options);
|
|
123
124
|
export const removeStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('remove')(selector, options);
|
|
124
125
|
|
|
125
|
-
//
|
|
126
|
-
export function
|
|
127
|
-
return createStyleDecorator(action)('
|
|
126
|
+
// This versions
|
|
127
|
+
export function applyStyleThis(action: StyleAction = 'update', options: StyleApplyOptions = {}): MethodDecorator {
|
|
128
|
+
return createStyleDecorator(action)('$this', options);
|
|
128
129
|
}
|
|
129
|
-
export const
|
|
130
|
-
export const
|
|
131
|
-
export const
|
|
130
|
+
export const setStyleThis = (options: StyleApplyOptions = {}) => createStyleDecorator('set')('$this', options);
|
|
131
|
+
export const updateStyleThis = (options: StyleApplyOptions = {}) => createStyleDecorator('update')('$this', options);
|
|
132
|
+
export const removeStyleThis = (options: StyleApplyOptions = {}) => createStyleDecorator('remove')('$this', options);
|
|
132
133
|
|
|
133
134
|
export const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {
|
|
134
135
|
const result = new Map<string | symbol, StyleApplyMetadata>();
|