@geogirafe/lib-geoportal 1.3.0-dev.2930448000 → 1.3.0-dev.2937711922

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "GeoGirafe PSC",
6
6
  "url": "https://doc.geogirafe.org"
7
7
  },
8
- "version": "1.3.0-dev.2930448000",
8
+ "version": "1.3.0-dev.2937711922",
9
9
  "type": "module",
10
10
  "engines": {
11
11
  "node": ">=20.19.0"
@@ -1 +1 @@
1
- {"version":"1.3.0-dev.2930448000", "build":"2930448000", "date":"09/10/2026"}
1
+ {"version":"1.3.0-dev.2937711922", "build":"2937711922", "date":"12/10/2026"}
@@ -50,16 +50,16 @@ class FeedbackManager extends GirafeSingleton {
50
50
  }
51
51
  initializeFeedbackOnComponents() {
52
52
  this.config.feedback?.components?.forEach((component) => {
53
+ // Do nothing if a feedback was already given
53
54
  if (this.gaveFeedbackFor[component.name]) {
54
55
  return;
55
56
  }
56
- const componentsByName = this.context.componentManager.getComponentsByName(component.name);
57
- for (const girafeHTMLElement of componentsByName) {
57
+ this.context.componentManager.registerComponentCallback(component.name, (girafeHTMLElement) => {
58
58
  girafeHTMLElement.insertFeedbackTemplate(HTML_TEMPLATE.replace('${component-name}', component.name)
59
59
  .replace('${question}', component.question)
60
60
  .replace('${placement}', component.placement)
61
61
  .replace('${margins}', component.margins ?? ''));
62
- }
62
+ });
63
63
  });
64
64
  }
65
65
  }
@@ -4,10 +4,11 @@ type Callback = (elem: GirafeHTMLElement) => unknown;
4
4
  type Constructor<T> = new (...args: never[]) => T;
5
5
  export default class ComponentManager extends GirafeSingleton {
6
6
  private readonly components;
7
- private readonly registeredCallbacks;
8
- private readonly registeredCallbacksClasses;
7
+ private readonly componentsCallbacks;
9
8
  registerComponent(component: GirafeHTMLElement): void;
9
+ registerComponentCallback(componentName: string, callback: Callback): void;
10
10
  registerComponentCallback(component: Constructor<GirafeHTMLElement>, callback: Callback): void;
11
+ private getRegisteredComponentsForEntry;
11
12
  getComponents<T extends GirafeHTMLElement>(type: Constructor<T>): T[];
12
13
  getComponentsByName(name: string): GirafeHTMLElement[];
13
14
  }
@@ -1,20 +1,41 @@
1
1
  import GirafeSingleton from '../../base/GirafeSingleton.js';
2
2
  export default class ComponentManager extends GirafeSingleton {
3
3
  components = {};
4
- registeredCallbacks = [];
5
- registeredCallbacksClasses = [];
4
+ componentsCallbacks = [];
6
5
  registerComponent(component) {
7
6
  this.components[component.name] ??= [];
8
7
  this.components[component.name].push(component);
9
- for (let i = 0; i < this.registeredCallbacksClasses.length; i++) {
10
- if (component instanceof this.registeredCallbacksClasses[i]) {
11
- this.registeredCallbacks[i].forEach((callback) => callback(component));
8
+ for (const componentCallbacks of this.componentsCallbacks) {
9
+ if ((componentCallbacks.componentType && component instanceof componentCallbacks.componentType) ||
10
+ (componentCallbacks.componentName && componentCallbacks.componentName === component.name)) {
11
+ componentCallbacks.callbacks.forEach((callback) => callback(component));
12
12
  }
13
13
  }
14
14
  }
15
- registerComponentCallback(component, callback) {
16
- this.registeredCallbacksClasses.push(component);
17
- this.registeredCallbacks.push([callback]);
15
+ registerComponentCallback(componentOrName, callback) {
16
+ const componentType = typeof componentOrName !== 'string' ? componentOrName : undefined;
17
+ const componentName = typeof componentOrName === 'string' ? componentOrName : undefined;
18
+ let entry = this.componentsCallbacks.find((c) => c.componentType === componentType && c.componentName === componentName);
19
+ if (entry) {
20
+ entry.callbacks.push(callback);
21
+ }
22
+ else {
23
+ entry = { componentType, componentName, callbacks: [callback] };
24
+ this.componentsCallbacks.push(entry);
25
+ }
26
+ // If some components were already registered, the callback is called directly on them.
27
+ for (const registeredComponent of this.getRegisteredComponentsForEntry(componentType, componentName)) {
28
+ callback(registeredComponent);
29
+ }
30
+ }
31
+ getRegisteredComponentsForEntry(componentType, componentName) {
32
+ if (componentName) {
33
+ return this.components[componentName] ?? [];
34
+ }
35
+ if (componentType) {
36
+ return this.getComponents(componentType);
37
+ }
38
+ return [];
18
39
  }
19
40
  getComponents(type) {
20
41
  return Object.values(this.components)