@mypolis.eu/action-controller 1.0.0 → 3.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/action.js +13 -0
- package/dist/action.js.map +1 -0
- package/dist/action.test.js +31 -0
- package/dist/action.test.js.map +1 -0
- package/dist/attributes.test.js +7 -7
- package/dist/attributes.test.js.map +1 -1
- package/dist/controller.js +81 -103
- package/dist/controller.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/query.js +19 -22
- package/dist/query.js.map +1 -1
- package/dist/register.js +8 -4
- package/dist/register.js.map +1 -1
- package/dist/types/action.d.ts +7 -0
- package/dist/types/action.d.ts.map +1 -0
- package/dist/types/action.test.d.ts +2 -0
- package/dist/types/action.test.d.ts.map +1 -0
- package/dist/types/controller.d.ts +2 -5
- package/dist/types/controller.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/query.d.ts +11 -10
- package/dist/types/query.d.ts.map +1 -1
- package/dist/types/register.d.ts +1 -1
- package/dist/types/register.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/action.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const pattern = /(.+?)->(.+?)#(.+)/;
|
|
2
|
+
export function parseActions(action) {
|
|
3
|
+
const rawActions = action.split(/\s+/).filter((s) => s.length > 0);
|
|
4
|
+
return rawActions.map((str) => {
|
|
5
|
+
const match = str.match(pattern);
|
|
6
|
+
if (!match) {
|
|
7
|
+
throw new Error(`invalid action format: ${str}`);
|
|
8
|
+
}
|
|
9
|
+
const [_, event, controller, method] = match;
|
|
10
|
+
return { event, controller, method };
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAEpC,MAAM,UAAU,YAAY,CAAC,MAAc;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;QAC7C,OAAO,EAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assert } from "@open-wc/testing";
|
|
2
|
+
import { parseActions } from "./action";
|
|
3
|
+
describe("parseActions", () => {
|
|
4
|
+
it("can parse an action from a string", () => {
|
|
5
|
+
const str = "htmx:beforeRequest->loading-state#start";
|
|
6
|
+
const actions = parseActions(str);
|
|
7
|
+
assert.strictEqual(actions[0].event, "htmx:beforeRequest");
|
|
8
|
+
assert.strictEqual(actions[0].controller, "loading-state");
|
|
9
|
+
assert.strictEqual(actions[0].method, "start");
|
|
10
|
+
});
|
|
11
|
+
it("can parse multiple actions from a string", () => {
|
|
12
|
+
const str = `
|
|
13
|
+
htmx:beforeRequest->loading-state#start
|
|
14
|
+
htmx:afterRequest->loading-state#stop
|
|
15
|
+
`;
|
|
16
|
+
const actions = parseActions(str);
|
|
17
|
+
assert.strictEqual(actions[0].event, "htmx:beforeRequest");
|
|
18
|
+
assert.strictEqual(actions[0].controller, "loading-state");
|
|
19
|
+
assert.strictEqual(actions[0].method, "start");
|
|
20
|
+
assert.strictEqual(actions[1].event, "htmx:afterRequest");
|
|
21
|
+
assert.strictEqual(actions[1].controller, "loading-state");
|
|
22
|
+
assert.strictEqual(actions[1].method, "stop");
|
|
23
|
+
});
|
|
24
|
+
it("throws an error if action if not valid", () => {
|
|
25
|
+
const badStrs = ["foo", "->loading-state#start", "foo->bar", "foo#bar"];
|
|
26
|
+
for (const str of badStrs) {
|
|
27
|
+
assert.throws(() => parseActions(str), "invalid action format: " + str);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=action.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.test.js","sourceRoot":"","sources":["../src/action.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAEtC,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC5C,MAAM,GAAG,GAAG,yCAAyC,CAAC;QAEtD,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAElC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;QAC3D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAC3D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAG;;;GAGX,CAAC;QAEF,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAElC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;QAC3D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAC3D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;QAC1D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAC3D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QACjD,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QACxE,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC3B,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,yBAAyB,GAAG,GAAG,CAAC,CAAC;QACzE,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/attributes.test.js
CHANGED
|
@@ -5,11 +5,11 @@ describe("parseAttributes", () => {
|
|
|
5
5
|
beforeEach(() => {
|
|
6
6
|
element = document.createElement("div");
|
|
7
7
|
});
|
|
8
|
-
|
|
8
|
+
it("parses string attributes", () => {
|
|
9
9
|
element.setAttribute("data-url", "/products");
|
|
10
10
|
assert.deepStrictEqual(parseAttributes(element), { url: "/products" });
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
it("parses boolean attributes", () => {
|
|
13
13
|
element.setAttribute("data-active", "true");
|
|
14
14
|
element.setAttribute("data-disabled", "false");
|
|
15
15
|
assert.deepStrictEqual(parseAttributes(element), {
|
|
@@ -17,23 +17,23 @@ describe("parseAttributes", () => {
|
|
|
17
17
|
disabled: false
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
it("parses number attributes", () => {
|
|
21
21
|
element.setAttribute("data-count", "42");
|
|
22
22
|
assert.deepStrictEqual(parseAttributes(element), { count: 42 });
|
|
23
23
|
});
|
|
24
|
-
|
|
24
|
+
it("parses array attributes", () => {
|
|
25
25
|
element.setAttribute("data-tags", "one,two,three");
|
|
26
26
|
assert.deepStrictEqual(parseAttributes(element), {
|
|
27
27
|
tags: ["one", "two", "three"]
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
|
-
|
|
30
|
+
it("parses JSON attributes", () => {
|
|
31
31
|
element.setAttribute("data-config", '{"foo": "bar", "num": 123}');
|
|
32
32
|
assert.deepStrictEqual(parseAttributes(element), {
|
|
33
33
|
config: { foo: "bar", num: 123 }
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
it("handles kebab-case attributes", () => {
|
|
37
37
|
element.setAttribute("data-user-name", "John");
|
|
38
38
|
element.setAttribute("data-last-login-date", "2024-01-21");
|
|
39
39
|
assert.deepStrictEqual(parseAttributes(element), {
|
|
@@ -41,7 +41,7 @@ describe("parseAttributes", () => {
|
|
|
41
41
|
lastLoginDate: "2024-01-21"
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
-
|
|
44
|
+
it("ignores non-data attributes", () => {
|
|
45
45
|
element.setAttribute("id", "test");
|
|
46
46
|
element.setAttribute("data-name", "John");
|
|
47
47
|
assert.deepStrictEqual(parseAttributes(element), { name: "John" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.test.js","sourceRoot":"","sources":["../src/attributes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,kB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Ae,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/controller.js
CHANGED
|
@@ -1,47 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _Controller_instances, _Controller_handlers, _Controller_observer, _Controller_parseActions, _Controller_handleAction, _Controller_listenActions, _Controller_cleanupActions;
|
|
13
|
-
import { LitElement, html } from "lit";
|
|
14
|
-
import { findElements } from "./query";
|
|
1
|
+
import { html, LitElement } from "lit";
|
|
2
|
+
import { parseActions } from "./action";
|
|
15
3
|
import { parseAttributes } from "./attributes";
|
|
4
|
+
import { findElements, targetKey } from "./query";
|
|
16
5
|
export class Controller extends LitElement {
|
|
6
|
+
#handlers = new Map();
|
|
7
|
+
#observer;
|
|
8
|
+
[targetKey];
|
|
17
9
|
constructor() {
|
|
18
10
|
super();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
__classPrivateFieldGet(this, _Controller_instances, "m", _Controller_listenActions).call(this); // Add new listeners
|
|
25
|
-
}), "f");
|
|
11
|
+
this.#observer = new MutationObserver(() => {
|
|
12
|
+
this.#cleanupActions(); // Clean up existing listeners
|
|
13
|
+
this.#listenActions(); // Add new listeners
|
|
14
|
+
this.#updateQueries(); // Refresh the queries
|
|
15
|
+
});
|
|
26
16
|
}
|
|
27
17
|
connectedCallback() {
|
|
28
18
|
super.connectedCallback();
|
|
29
19
|
// Initial setup
|
|
30
|
-
|
|
20
|
+
this.#updateQueries();
|
|
21
|
+
this.#listenActions();
|
|
31
22
|
// Start observing changes
|
|
32
|
-
|
|
23
|
+
this.#observer.observe(this, {
|
|
33
24
|
childList: true,
|
|
34
25
|
subtree: true,
|
|
35
26
|
attributes: true,
|
|
36
|
-
attributeFilter: ["data-action", "data-
|
|
27
|
+
attributeFilter: ["data-action", "data-target"]
|
|
37
28
|
});
|
|
38
29
|
}
|
|
39
30
|
disconnectedCallback() {
|
|
40
31
|
super.disconnectedCallback();
|
|
41
32
|
// Clean up existing listeners
|
|
42
|
-
|
|
33
|
+
this.#cleanupActions();
|
|
43
34
|
// Stop observing
|
|
44
|
-
|
|
35
|
+
this.#observer.disconnect();
|
|
45
36
|
}
|
|
46
37
|
render() {
|
|
47
38
|
return html `<slot />`;
|
|
@@ -57,89 +48,76 @@ export class Controller extends LitElement {
|
|
|
57
48
|
return {};
|
|
58
49
|
return parseAttributes(target);
|
|
59
50
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.split(/\s+/) // Split multiple actions defined in the string
|
|
67
|
-
.map((action) => {
|
|
68
|
-
// 1. Find the method separator first
|
|
69
|
-
const hashIndex = action.indexOf("#");
|
|
70
|
-
let eventAndControllerPart;
|
|
71
|
-
let method;
|
|
72
|
-
if (hashIndex === -1) {
|
|
73
|
-
// No '#' found, method defaults to 'handleEvent'
|
|
74
|
-
eventAndControllerPart = action;
|
|
75
|
-
method = "handleEvent";
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
eventAndControllerPart = action.substring(0, hashIndex);
|
|
79
|
-
method = action.substring(hashIndex + 1) || "handleEvent";
|
|
80
|
-
}
|
|
81
|
-
// 2. Find the LAST colon in the remaining part to separate event type from controller
|
|
82
|
-
const lastColonIndex = eventAndControllerPart.lastIndexOf(":");
|
|
83
|
-
// Check if a colon exists and separates non-empty parts
|
|
84
|
-
if (lastColonIndex <= 0 || lastColonIndex === eventAndControllerPart.length - 1) {
|
|
85
|
-
console.warn(`[Controller] Invalid action format: Could not determine event and controller in "${action}". Skipping.`);
|
|
86
|
-
return null; // Invalid format
|
|
51
|
+
#handleAction(event, element, action) {
|
|
52
|
+
// look for the nearest controller matching the action's controller name
|
|
53
|
+
const controller = element.closest(action.controller);
|
|
54
|
+
if (!controller) {
|
|
55
|
+
console.warn(`Controller ${action.controller} not found`);
|
|
56
|
+
return;
|
|
87
57
|
}
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return null;
|
|
58
|
+
// the method should exist on the controller, not the element
|
|
59
|
+
const method = controller[action.method];
|
|
60
|
+
if (typeof method !== "function") {
|
|
61
|
+
console.warn(`Method ${action.method} not found on controller ${action.controller}`);
|
|
62
|
+
return;
|
|
94
63
|
}
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
.filter((action) => action !== null);
|
|
98
|
-
}, _Controller_handleAction = function _Controller_handleAction(event, element, action) {
|
|
99
|
-
// look for the nearest controller matching the action's controller name
|
|
100
|
-
const controller = element.closest(action.controller);
|
|
101
|
-
if (!controller) {
|
|
102
|
-
console.warn(`Controller ${action.controller} not found`);
|
|
103
|
-
return;
|
|
64
|
+
method.call(controller, event);
|
|
104
65
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
66
|
+
#listenActions() {
|
|
67
|
+
findElements(this, "[data-action]").forEach((element) => {
|
|
68
|
+
const str = element.dataset.action;
|
|
69
|
+
if (!str)
|
|
70
|
+
return;
|
|
71
|
+
const handlers = [];
|
|
72
|
+
for (const action of parseActions(str)) {
|
|
73
|
+
if (action.controller !== this.tagName.toLowerCase())
|
|
74
|
+
continue;
|
|
75
|
+
const handler = (event) => this.#handleAction(event, element, action);
|
|
76
|
+
element.addEventListener(action.event, handler);
|
|
77
|
+
handlers.push({ event: action.event, handler });
|
|
78
|
+
}
|
|
79
|
+
if (handlers.length) {
|
|
80
|
+
this.#handlers.set(element, handlers);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
110
83
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
findElements(this, "[data-action]").forEach((element) => {
|
|
114
|
-
const actionString = element.dataset.action;
|
|
115
|
-
if (!actionString)
|
|
84
|
+
#updateQueries() {
|
|
85
|
+
if (!this[targetKey] || this[targetKey].length === 0)
|
|
116
86
|
return;
|
|
117
|
-
|
|
118
|
-
for (const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
87
|
+
let needsUpdate = false;
|
|
88
|
+
for (const target of this[targetKey]) {
|
|
89
|
+
const propertyKey = target.propertyKey;
|
|
90
|
+
const nextElement = target.query;
|
|
91
|
+
const current = this[propertyKey];
|
|
92
|
+
let hasChanged = false;
|
|
93
|
+
if (Array.isArray(nextElement)) {
|
|
94
|
+
const currentElements = (current || []);
|
|
95
|
+
if (currentElements.length !== nextElement.length ||
|
|
96
|
+
nextElement.some((el) => !currentElements.includes(el))) {
|
|
97
|
+
hasChanged = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (current !== nextElement) {
|
|
102
|
+
hasChanged = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (hasChanged) {
|
|
106
|
+
this[propertyKey] = nextElement;
|
|
107
|
+
needsUpdate = true;
|
|
108
|
+
}
|
|
124
109
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
110
|
+
if (needsUpdate) {
|
|
111
|
+
this.requestUpdate();
|
|
127
112
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const actionString = element.dataset.action;
|
|
135
|
-
if (!actionString)
|
|
136
|
-
return;
|
|
137
|
-
for (const action of __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_parseActions).call(this, actionString)) {
|
|
138
|
-
handlers.forEach((handler) => {
|
|
139
|
-
element.removeEventListener(action.type, handler);
|
|
140
|
-
});
|
|
113
|
+
}
|
|
114
|
+
#cleanupActions() {
|
|
115
|
+
for (const [element, handlers] of this.#handlers.entries()) {
|
|
116
|
+
for (const { event, handler } of handlers) {
|
|
117
|
+
element.removeEventListener(event, handler);
|
|
118
|
+
}
|
|
141
119
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
120
|
+
this.#handlers.clear();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
145
123
|
//# sourceMappingURL=controller.js.map
|
package/dist/controller.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../src/controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../src/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,UAAU,EAAC,MAAM,KAAK,CAAC;AACrC,OAAO,EAAC,YAAY,EAAc,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAU,SAAS,EAAC,MAAM,SAAS,CAAC;AAIxD,MAAM,OAAO,UAAW,SAAQ,UAAU;IACzC,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC1C,SAAS,CAAmB;IAE5B,CAAC,SAAS,CAAC,CAAY;IAEvB;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,gBA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ACd,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5D,KAAK,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,IAAI,QAAQ,EAAE,CAAC;gBACzC,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC7C,CAAC;QACF,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACD"}
|
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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAIxC,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,41 +21,38 @@ export function findElements(controller, query) {
|
|
|
21
21
|
}
|
|
22
22
|
return elements;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
* Decorator to find a single element with data-target.
|
|
26
|
-
* @example @target myTarget;
|
|
27
|
-
*/
|
|
24
|
+
export const targetKey = Symbol("targets");
|
|
28
25
|
export function target(_value, context) {
|
|
29
26
|
const propertyKey = context.name;
|
|
30
27
|
context.addInitializer(function () {
|
|
31
28
|
const instance = this;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if (!instance[targetKey]) {
|
|
30
|
+
instance[targetKey] = [];
|
|
31
|
+
}
|
|
32
|
+
instance[targetKey].push({
|
|
33
|
+
propertyKey,
|
|
34
|
+
get query() {
|
|
35
|
+
const controller = instance.tagName.toLowerCase();
|
|
35
36
|
const query = `[data-target~="${controller}.${propertyKey}"]`;
|
|
36
|
-
return findElements(
|
|
37
|
-
}
|
|
38
|
-
enumerable: true,
|
|
39
|
-
configurable: true
|
|
37
|
+
return findElements(instance, query)?.[0];
|
|
38
|
+
}
|
|
40
39
|
});
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Decorator to find all elements with data-target.
|
|
45
|
-
* @example @targets myTargets;
|
|
46
|
-
*/
|
|
47
42
|
export function targets(_value, context) {
|
|
48
43
|
const propertyKey = context.name;
|
|
49
44
|
context.addInitializer(function () {
|
|
50
45
|
const instance = this;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
if (!instance[targetKey]) {
|
|
47
|
+
instance[targetKey] = [];
|
|
48
|
+
}
|
|
49
|
+
instance[targetKey].push({
|
|
50
|
+
propertyKey,
|
|
51
|
+
get query() {
|
|
52
|
+
const controller = instance.tagName.toLowerCase();
|
|
54
53
|
const query = `[data-target~="${controller}.${propertyKey}"]`;
|
|
55
|
-
return findElements(
|
|
56
|
-
}
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true
|
|
54
|
+
return findElements(instance, query);
|
|
55
|
+
}
|
|
59
56
|
});
|
|
60
57
|
});
|
|
61
58
|
}
|
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":"AAEA,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,C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X,IAAI,KAAK;gBACR,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBAClD,MAAM,KAAK,GAAG,kBAAkB,UAAU,IAAI,WAAW,IAAI,CAAC;gBAC9D,OAAO,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3C,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,MAAiB,EAAE,OAAoD;IAC9F,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IACjC,OAAO,CAAC,cAAc,CAAC;QACtB,MAAM,QAAQ,GAAG,IAA8C,CAAC;QAChE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QAC1B,CAAC;QACD,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;YACxB,WAAW;YACX,IAAI,KAAK;gBACR,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBAClD,MAAM,KAAK,GAAG,kBAAkB,UAAU,IAAI,WAAW,IAAI,CAAC;gBAC9D,OAAO,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/register.js
CHANGED
|
@@ -3,7 +3,11 @@ export const slugify = (str) => String(typeof str === "symbol" ? str.description
|
|
|
3
3
|
.replace(/--/g, "-")
|
|
4
4
|
.replace(/^-|-$/, "")
|
|
5
5
|
.toLowerCase();
|
|
6
|
-
export function register(classObject) {
|
|
6
|
+
export function register(classObject, context) {
|
|
7
|
+
// Ensure the decorator is only used on classes.
|
|
8
|
+
if (context.kind !== "class") {
|
|
9
|
+
throw new Error("The @register decorator can only be applied to classes.");
|
|
10
|
+
}
|
|
7
11
|
const name = slugify(classObject.name).replace(/-element$/, "");
|
|
8
12
|
try {
|
|
9
13
|
window.customElements.define(name, classObject);
|
|
@@ -11,11 +15,11 @@ export function register(classObject) {
|
|
|
11
15
|
window[classObject.name] = customElements.get(name);
|
|
12
16
|
}
|
|
13
17
|
catch (e) {
|
|
14
|
-
// The only reason for window.customElements.define to throw a `NotSupportedError`
|
|
15
|
-
// is if the element has already been defined.
|
|
16
18
|
if (!(e instanceof DOMException && e.name === "NotSupportedError"))
|
|
17
19
|
throw e;
|
|
18
20
|
}
|
|
19
|
-
return
|
|
21
|
+
// With modern decorators, you don't need to return the class
|
|
22
|
+
// if you are not replacing it with a new one. This decorator's
|
|
23
|
+
// purpose is the side-effect of registration.
|
|
20
24
|
}
|
|
21
25
|
//# sourceMappingURL=register.js.map
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAY,EAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAY,EAAU,EAAE,CAC/C,MAAM,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;KACrD,OAAO,CAAC,mBAAmB,EAAE,KAAK,CAAC;KACnC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;KACnB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;KACpB,WAAW,EAAE,CAAC;AAEjB,MAAM,UAAU,QAAQ,CAAC,WAAqC,EAAE,OAA8B;IAC7F,gDAAgD;IAChD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEhE,IAAI,CAAC;QACJ,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAChD,aAAa;QACb,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QACrB,IAAI,CAAC,CAAC,CAAC,YAAY,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,CAAC;YAAE,MAAM,CAAC,CAAC;IAC7E,CAAC;IAED,6DAA6D;IAC7D,+DAA+D;IAC/D,8CAA8C;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/action.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAIF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.test.d.ts","sourceRoot":"","sources":["../../src/action.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { LitElement } from "lit";
|
|
2
|
-
|
|
3
|
-
type: string;
|
|
4
|
-
controller: string;
|
|
5
|
-
method: string;
|
|
6
|
-
};
|
|
2
|
+
import { Target, targetKey } from "./query";
|
|
7
3
|
export declare class Controller extends LitElement {
|
|
8
4
|
#private;
|
|
5
|
+
[targetKey]?: Target[];
|
|
9
6
|
constructor();
|
|
10
7
|
connectedCallback(): void;
|
|
11
8
|
disconnectedCallback(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,UAAU,EAAC,MAAM,KAAK,CAAC;AAGrC,OAAO,EAAe,MAAM,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAIxD,qBAAa,UAAW,SAAQ,UAAU;;IAIzC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;;IAWvB,iBAAiB;IAgBjB,oBAAoB;IAQpB,MAAM;IAIN,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;CA+FrF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Controller
|
|
1
|
+
export { Controller } from "./controller";
|
|
2
|
+
export { type Action } from "./action";
|
|
2
3
|
export { target, targets } from "./query";
|
|
3
4
|
export { register } from "./register";
|
|
4
5
|
export { parseAttributes } from "./attributes";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC,OAAO,EAAC,KAAK,MAAM,EAAC,MAAM,UAAU,CAAC;AAErC,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,12 +1,13 @@
|
|
|
1
|
+
export type Target<T extends Element = Element> = {
|
|
2
|
+
propertyKey: string;
|
|
3
|
+
query: T | T[];
|
|
4
|
+
};
|
|
1
5
|
export declare function findElements<T extends Element>(controller: HTMLElement, query: string): T[];
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @example @targets myTargets;
|
|
10
|
-
*/
|
|
11
|
-
export declare function targets(_value: undefined, context: ClassFieldDecoratorContext): void;
|
|
6
|
+
export declare const targetKey: unique symbol;
|
|
7
|
+
export declare function target(_value: undefined, context: ClassFieldDecoratorContext & {
|
|
8
|
+
name: string;
|
|
9
|
+
}): void;
|
|
10
|
+
export declare function targets(_value: undefined, context: ClassFieldDecoratorContext & {
|
|
11
|
+
name: string;
|
|
12
|
+
}): void;
|
|
12
13
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/query.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAA;CAAC,CAAC;AAExF,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAyB3F;AAED,eAAO,MAAM,SAAS,eAAoB,CAAC;AAE3C,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,GAAG;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,QAgB7F;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,GAAG;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,QAgB9F"}
|
package/dist/types/register.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const slugify: (str: unknown) => string;
|
|
2
|
-
export declare function register
|
|
2
|
+
export declare function register(classObject: CustomElementConstructor, context: ClassDecoratorContext): void;
|
|
3
3
|
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/register.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,GAAI,KAAK,OAAO,KAAG,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/register.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,GAAI,KAAK,OAAO,KAAG,MAKvB,CAAC;AAEjB,wBAAgB,QAAQ,CAAC,WAAW,EAAE,wBAAwB,EAAE,OAAO,EAAE,qBAAqB,QAmB7F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mypolis.eu/action-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"@tsconfig/node24": "^24.0.1"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"dev": "vite ./playground",
|
|
39
|
+
"test": "wtr ./src/**/*.test.ts --node-resolve",
|
|
40
|
+
"build": "tsc -p tsconfig.json"
|
|
40
41
|
}
|
|
41
42
|
}
|