@mypolis.eu/action-controller 2.0.0 → 3.0.1

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.
@@ -1,38 +1,26 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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_handleAction, _Controller_listenActions, _Controller_updateQueries, _Controller_cleanupActions;
13
1
  import { html, LitElement } from "lit";
14
2
  import { parseActions } from "./action";
15
3
  import { parseAttributes } from "./attributes";
16
4
  import { findElements, targetKey } from "./query";
17
5
  export class Controller extends LitElement {
6
+ #handlers = new Map();
7
+ #observer;
8
+ [targetKey];
18
9
  constructor() {
19
10
  super();
20
- _Controller_instances.add(this);
21
- _Controller_handlers.set(this, new Map());
22
- _Controller_observer.set(this, void 0);
23
- __classPrivateFieldSet(this, _Controller_observer, new MutationObserver(() => {
24
- __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_cleanupActions).call(this); // Clean up existing listeners
25
- __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_listenActions).call(this); // Add new listeners
26
- __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_updateQueries).call(this); // Refresh the queries
27
- }), "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
+ });
28
16
  }
29
17
  connectedCallback() {
30
18
  super.connectedCallback();
31
19
  // Initial setup
32
- __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_updateQueries).call(this);
33
- __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_listenActions).call(this);
20
+ this.#updateQueries();
21
+ this.#listenActions();
34
22
  // Start observing changes
35
- __classPrivateFieldGet(this, _Controller_observer, "f").observe(this, {
23
+ this.#observer.observe(this, {
36
24
  childList: true,
37
25
  subtree: true,
38
26
  attributes: true,
@@ -42,9 +30,9 @@ export class Controller extends LitElement {
42
30
  disconnectedCallback() {
43
31
  super.disconnectedCallback();
44
32
  // Clean up existing listeners
45
- __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_cleanupActions).call(this);
33
+ this.#cleanupActions();
46
34
  // Stop observing
47
- __classPrivateFieldGet(this, _Controller_observer, "f").disconnect();
35
+ this.#observer.disconnect();
48
36
  }
49
37
  render() {
50
38
  return html `<slot />`;
@@ -60,73 +48,77 @@ export class Controller extends LitElement {
60
48
  return {};
61
49
  return parseAttributes(target);
62
50
  }
63
- }
64
- _Controller_handlers = new WeakMap(), _Controller_observer = new WeakMap(), _Controller_instances = new WeakSet(), _Controller_handleAction = function _Controller_handleAction(event, element, action) {
65
- // look for the nearest controller matching the action's controller name
66
- const controller = element.closest(action.controller);
67
- if (!controller) {
68
- console.warn(`Controller ${action.controller} not found`);
69
- return;
70
- }
71
- // the method should exist on the controller, not the element
72
- const method = controller[action.method];
73
- if (typeof method !== "function") {
74
- console.warn(`Method ${action.method} not found on controller ${action.controller}`);
75
- return;
76
- }
77
- method.call(controller, event);
78
- }, _Controller_listenActions = function _Controller_listenActions() {
79
- findElements(this, "[data-action]").forEach((element) => {
80
- const str = element.dataset.action;
81
- if (!str)
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`);
82
56
  return;
83
- const handlers = [];
84
- for (const action of parseActions(str)) {
85
- if (action.controller !== this.tagName.toLowerCase())
86
- continue;
87
- const handler = (event) => __classPrivateFieldGet(this, _Controller_instances, "m", _Controller_handleAction).call(this, event, element, action);
88
- element.addEventListener(action.event, handler);
89
- handlers.push({ event: action.event, handler });
90
57
  }
91
- if (handlers.length) {
92
- __classPrivateFieldGet(this, _Controller_handlers, "f").set(element, handlers);
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;
93
63
  }
94
- });
95
- }, _Controller_updateQueries = function _Controller_updateQueries() {
96
- if (!this[targetKey] || this[targetKey].length === 0)
97
- return;
98
- let needsUpdate = false;
99
- for (const target of this[targetKey]) {
100
- const propertyKey = target.propertyKey;
101
- const nextElement = target.query;
102
- const current = this[propertyKey];
103
- let hasChanged = false;
104
- if (Array.isArray(nextElement)) {
105
- const currentElements = (current || []);
106
- if (currentElements.length !== nextElement.length ||
107
- nextElement.some((el) => !currentElements.includes(el))) {
108
- hasChanged = true;
64
+ method.call(controller, event);
65
+ }
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 });
109
78
  }
110
- }
111
- else {
112
- if (current !== nextElement) {
113
- hasChanged = true;
79
+ if (handlers.length) {
80
+ this.#handlers.set(element, handlers);
81
+ }
82
+ });
83
+ }
84
+ #updateQueries() {
85
+ if (!this[targetKey] || this[targetKey].length === 0)
86
+ return;
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 ||
96
+ currentElements.length !== nextElement.length ||
97
+ nextElement.some((el) => !currentElements.includes(el))) {
98
+ hasChanged = true;
99
+ }
100
+ }
101
+ else {
102
+ if (current !== nextElement) {
103
+ hasChanged = true;
104
+ }
105
+ }
106
+ if (hasChanged) {
107
+ this[propertyKey] = nextElement;
108
+ needsUpdate = true;
114
109
  }
115
110
  }
116
- if (hasChanged) {
117
- this[propertyKey] = nextElement;
118
- needsUpdate = true;
111
+ if (needsUpdate) {
112
+ this.requestUpdate();
119
113
  }
120
114
  }
121
- if (needsUpdate) {
122
- this.requestUpdate();
123
- }
124
- }, _Controller_cleanupActions = function _Controller_cleanupActions() {
125
- for (const [element, handlers] of __classPrivateFieldGet(this, _Controller_handlers, "f").entries()) {
126
- for (const { event, handler } of handlers) {
127
- element.removeEventListener(event, handler);
115
+ #cleanupActions() {
116
+ for (const [element, handlers] of this.#handlers.entries()) {
117
+ for (const { event, handler } of handlers) {
118
+ element.removeEventListener(event, handler);
119
+ }
128
120
  }
121
+ this.#handlers.clear();
129
122
  }
130
- __classPrivateFieldGet(this, _Controller_handlers, "f").clear();
131
- };
123
+ }
132
124
  //# sourceMappingURL=controller.js.map
@@ -1 +1 @@
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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AmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC7C,CAAC;QACF,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACD"}
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 classObject;
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
@@ -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,CAC9C,MAAM,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;KACpD,OAAO,CAAC,mBAAmB,EAAE,KAAK,CAAC;KACnC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;KACnB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;KACpB,WAAW,EAAE,CAAC;AAEnB,MAAM,UAAU,QAAQ,CACtB,WAAc;IAEd,MAAM,IAAI,GAA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c,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"}
@@ -1 +1 @@
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"}
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;CAgGrF"}
@@ -1,6 +1,6 @@
1
1
  export type Target<T extends Element = Element> = {
2
2
  propertyKey: string;
3
- query: T | T[];
3
+ query: T[] | T | undefined;
4
4
  };
5
5
  export declare function findElements<T extends Element>(controller: HTMLElement, query: string): T[];
6
6
  export declare const targetKey: unique symbol;
@@ -1 +1 @@
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"}
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,EAAE,GAAG,CAAC,GAAG,SAAS,CAAA;CAAC,CAAC;AAEpG,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"}
@@ -1,3 +1,3 @@
1
1
  export declare const slugify: (str: unknown) => string;
2
- export declare function register<T extends CustomElementConstructor>(classObject: T): T;
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,MAKrB,CAAC;AAEnB,wBAAgB,QAAQ,CAAC,CAAC,SAAS,wBAAwB,EACzD,WAAW,EAAE,CAAC,GACb,CAAC,CAaH"}
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": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {