@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.3.0-dev.
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
5
|
-
registeredCallbacksClasses = [];
|
|
4
|
+
componentsCallbacks = [];
|
|
6
5
|
registerComponent(component) {
|
|
7
6
|
this.components[component.name] ??= [];
|
|
8
7
|
this.components[component.name].push(component);
|
|
9
|
-
for (
|
|
10
|
-
if (component instanceof
|
|
11
|
-
|
|
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(
|
|
16
|
-
|
|
17
|
-
|
|
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)
|