@mypolis.eu/action-controller 0.1.0 → 1.0.0
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/query.js +28 -50
- package/dist/query.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/query.d.ts +10 -5
- package/dist/types/query.d.ts.map +1 -1
- package/package.json +10 -6
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Controller } from "./controller";
|
|
2
|
-
export {
|
|
2
|
+
export { target, targets } from "./query";
|
|
3
3
|
export { register } from "./register";
|
|
4
4
|
export { parseAttributes } from "./attributes";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAc,MAAM,cAAc,CAAC;AAErD,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAc,MAAM,cAAc,CAAC;AAErD,OAAO,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,SAAS,CAAC;AAExC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC"}
|
package/dist/query.js
CHANGED
|
@@ -21,63 +21,41 @@ export function findElements(controller, query) {
|
|
|
21
21
|
}
|
|
22
22
|
return elements;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Decorator to find a single element with data-target.
|
|
26
|
+
* @example @target myTarget;
|
|
27
|
+
*/
|
|
28
|
+
export function target(_value, context) {
|
|
29
|
+
const propertyKey = context.name;
|
|
30
|
+
context.addInitializer(function () {
|
|
31
|
+
const instance = this;
|
|
32
32
|
Object.defineProperty(instance, propertyKey, {
|
|
33
|
-
get:
|
|
33
|
+
get: function () {
|
|
34
|
+
const controller = this.tagName.toLowerCase();
|
|
35
|
+
const query = `[data-target~="${controller}.${propertyKey}"]`;
|
|
36
|
+
return findElements(this, query)?.[0];
|
|
37
|
+
},
|
|
34
38
|
enumerable: true,
|
|
35
|
-
configurable: true
|
|
39
|
+
configurable: true
|
|
36
40
|
});
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Decorator to find all elements with data-target.
|
|
45
|
+
* @example @targets myTargets;
|
|
46
|
+
*/
|
|
47
|
+
export function targets(_value, context) {
|
|
48
|
+
const propertyKey = context.name;
|
|
49
|
+
context.addInitializer(function () {
|
|
50
|
+
const instance = this;
|
|
47
51
|
Object.defineProperty(instance, propertyKey, {
|
|
48
|
-
get:
|
|
52
|
+
get: function () {
|
|
53
|
+
const controller = this.tagName.toLowerCase();
|
|
54
|
+
const query = `[data-target~="${controller}.${propertyKey}"]`;
|
|
55
|
+
return findElements(this, query);
|
|
56
|
+
},
|
|
49
57
|
enumerable: true,
|
|
50
|
-
configurable: true
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
export function target(target, propertyKey) {
|
|
55
|
-
const ctor = target.constructor;
|
|
56
|
-
ctor.addInitializer((instance) => {
|
|
57
|
-
const getter = function () {
|
|
58
|
-
const controller = this.tagName.toLowerCase();
|
|
59
|
-
const query = `[data-target~="${controller}.${propertyKey}"]`;
|
|
60
|
-
return findElements(this, query)?.[0];
|
|
61
|
-
};
|
|
62
|
-
Object.defineProperty(instance, propertyKey, {
|
|
63
|
-
get: getter,
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
export function targets(target, propertyKey) {
|
|
70
|
-
const ctor = target.constructor;
|
|
71
|
-
ctor.addInitializer((instance) => {
|
|
72
|
-
const getter = function () {
|
|
73
|
-
const controller = this.tagName.toLowerCase();
|
|
74
|
-
const query = `[data-target~="${controller}.${propertyKey}"]`;
|
|
75
|
-
return findElements(this, query);
|
|
76
|
-
};
|
|
77
|
-
Object.defineProperty(instance, propertyKey, {
|
|
78
|
-
get: getter,
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
58
|
+
configurable: true
|
|
81
59
|
});
|
|
82
60
|
});
|
|
83
61
|
}
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAoB,UAAuB,EAAE,KAAa;IACrF,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAC7C,MAAM,QAAQ,GAAQ,EAAE,CAAC;IAEzB,oBAAoB;IACpB,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC3B,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACrE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,MAAM,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,QAAQ,CAAC,IAAI,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AmB,CAAC;QAErC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE;YAC5C,GAAG,EAAE;gBACJ,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBAC9C,MAAM,KAAK,GAAG,kBAAkB,UAAU,IAAI,WAAW,IAAI,CAAC;gBAC9D,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SAClB,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Controller, type Action } from "./controller";
|
|
2
|
-
export {
|
|
2
|
+
export { target, targets } from "./query";
|
|
3
3
|
export { register } from "./register";
|
|
4
4
|
export { parseAttributes } from "./attributes";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,KAAK,MAAM,EAAC,MAAM,cAAc,CAAC;AAErD,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,KAAK,MAAM,EAAC,MAAM,cAAc,CAAC;AAErD,OAAO,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,SAAS,CAAC;AAExC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC"}
|
package/dist/types/query.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { Controller } from "./controller";
|
|
2
1
|
export declare function findElements<T extends Element>(controller: HTMLElement, query: string): T[];
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to find a single element with data-target.
|
|
4
|
+
* @example @target myTarget;
|
|
5
|
+
*/
|
|
6
|
+
export declare function target(_value: undefined, context: ClassFieldDecoratorContext): void;
|
|
7
|
+
/**
|
|
8
|
+
* Decorator to find all elements with data-target.
|
|
9
|
+
* @example @targets myTargets;
|
|
10
|
+
*/
|
|
11
|
+
export declare function targets(_value: undefined, context: ClassFieldDecoratorContext): void;
|
|
7
12
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/query.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAyB3F;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,QAgB5E;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,QAgB7E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mypolis.eu/action-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -24,14 +24,18 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@open-wc/testing": "^4.0.0",
|
|
27
|
-
"@tsconfig/node22": "^22.0.2",
|
|
28
27
|
"@types/mocha": "^10.0.10",
|
|
29
28
|
"@web/dev-server-esbuild": "^1.0.4",
|
|
30
|
-
"@web/test-runner": "^0.20.
|
|
31
|
-
"
|
|
32
|
-
"
|
|
29
|
+
"@web/test-runner": "^0.20.2",
|
|
30
|
+
"lit": "^3.3.1",
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"vite": "^7.2.2"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@tsconfig/node24": "^24.0.1"
|
|
33
36
|
},
|
|
34
37
|
"scripts": {
|
|
35
|
-
"build": "tsc -p tsconfig.json"
|
|
38
|
+
"build": "tsc -p tsconfig.json",
|
|
39
|
+
"dev": "vite ./playground"
|
|
36
40
|
}
|
|
37
41
|
}
|