@supersoniks/concorde 3.0.7 → 3.0.9
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/build-infos.json +1 -1
- package/concorde-core.bundle.js +119 -119
- package/concorde-core.es.js +1181 -1135
- package/dist/concorde-core.bundle.js +119 -119
- package/dist/concorde-core.es.js +1181 -1135
- package/package.json +6 -4
- package/src/core/components/ui/toast/toast.ts +48 -26
- package/src/core/core.ts +1 -5
- package/src/core/mixins/Fetcher.ts +5 -1
- package/src/core/mixins/Subscriber.ts +63 -27
- package/src/core/utils/PublisherProxy.ts +65 -13
- package/vite/config.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supersoniks/concorde",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "",
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@jest/globals": "^29.7.0",
|
|
24
|
-
"@lit-labs/motion": "^1.0.7",
|
|
25
|
-
"@lit-labs/observers": "^2.0.2",
|
|
26
24
|
"@tailwindcss/typography": "^0.5.12",
|
|
27
25
|
"@types/intl": "^1.2.2",
|
|
28
26
|
"@types/jest": "^29.5.12",
|
|
@@ -37,7 +35,11 @@
|
|
|
37
35
|
"rollup-plugin-postcss-lit": "^2.1.0",
|
|
38
36
|
"tailwindcss": "^3.4.3",
|
|
39
37
|
"typescript": "^5.4.3",
|
|
40
|
-
"url-pattern": "^1.0.3",
|
|
41
38
|
"vite": "^5.2.8"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@lit-labs/motion": "^1.0.7",
|
|
42
|
+
"@lit-labs/observers": "^2.0.2",
|
|
43
|
+
"url-pattern": "^1.0.3"
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {html, LitElement, nothing} from "lit";
|
|
2
|
-
import {customElement, property} from "lit/decorators.js";
|
|
3
|
-
import {repeat} from "lit/directives/repeat.js";
|
|
4
|
-
import {animate} from "@lit-labs/motion";
|
|
1
|
+
import { html, LitElement, nothing } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
4
|
+
import { animate } from "@lit-labs/motion";
|
|
5
5
|
import Objects from "@supersoniks/concorde/core/utils/Objects";
|
|
6
6
|
import "@supersoniks/concorde/core/components/ui/icon/icon";
|
|
7
|
-
import {ifDefined} from "lit/directives/if-defined.js";
|
|
8
|
-
import {unsafeHTML} from "lit/directives/unsafe-html.js";
|
|
9
|
-
import {styleMap, StyleInfo} from "lit/directives/style-map.js";
|
|
7
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
8
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
9
|
+
import { styleMap, StyleInfo } from "lit/directives/style-map.js";
|
|
10
10
|
import "@supersoniks/concorde/core/components/ui/toast/toast-item";
|
|
11
|
-
import {Toast} from "@supersoniks/concorde/core/components/ui/toast/types";
|
|
12
|
-
import {ConcordeWindow} from "@supersoniks/concorde/core/_types/types";
|
|
13
|
-
import {Theme} from "@supersoniks/concorde/core/components/ui/theme/theme";
|
|
11
|
+
import { Toast } from "@supersoniks/concorde/core/components/ui/toast/types";
|
|
12
|
+
import { ConcordeWindow } from "@supersoniks/concorde/core/_types/types";
|
|
13
|
+
import { Theme } from "@supersoniks/concorde/core/components/ui/theme/theme";
|
|
14
14
|
|
|
15
15
|
declare const window: ConcordeWindow;
|
|
16
16
|
|
|
@@ -18,7 +18,7 @@ const tagName = "sonic-toast";
|
|
|
18
18
|
|
|
19
19
|
@customElement(tagName)
|
|
20
20
|
export class SonicToast extends LitElement {
|
|
21
|
-
@property({type: Array}) toasts: Toast[] = [];
|
|
21
|
+
@property({ type: Array }) toasts: Toast[] = [];
|
|
22
22
|
static delegateToasts = false;
|
|
23
23
|
|
|
24
24
|
createRenderRoot() {
|
|
@@ -71,7 +71,13 @@ export class SonicToast extends LitElement {
|
|
|
71
71
|
duration: 250,
|
|
72
72
|
easing: `cubic-bezier(0.250, 0.250, 0.420, 1.225)`,
|
|
73
73
|
},
|
|
74
|
-
in: [
|
|
74
|
+
in: [
|
|
75
|
+
{
|
|
76
|
+
transform: "translateY(0) scale(1.25)",
|
|
77
|
+
boxShadow: "0 0 0 rgba(0,0,0,0)",
|
|
78
|
+
opacity: 0,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
75
81
|
out: [
|
|
76
82
|
{
|
|
77
83
|
transform: "scale(.90) ",
|
|
@@ -94,7 +100,7 @@ export class SonicToast extends LitElement {
|
|
|
94
100
|
static removeAll() {
|
|
95
101
|
if (SonicToast.delegateToasts) {
|
|
96
102
|
SonicToast.handleExistingToastDelegation();
|
|
97
|
-
window.parent.postMessage({type: "removeAllToasts"}, "*");
|
|
103
|
+
window.parent.postMessage({ type: "removeAllToasts" }, "*");
|
|
98
104
|
return;
|
|
99
105
|
}
|
|
100
106
|
const toastComponent: SonicToast = SonicToast.getInstance();
|
|
@@ -114,7 +120,7 @@ export class SonicToast extends LitElement {
|
|
|
114
120
|
static add(conf: Toast) {
|
|
115
121
|
if (SonicToast.delegateToasts) {
|
|
116
122
|
SonicToast.handleExistingToastDelegation();
|
|
117
|
-
window.parent.postMessage({type: "addToast", toast: conf}, "*");
|
|
123
|
+
window.parent.postMessage({ type: "addToast", toast: conf }, "*");
|
|
118
124
|
return;
|
|
119
125
|
}
|
|
120
126
|
// Init toast area si absente (au <sonic-theme> ou <body< à défaut)
|
|
@@ -123,7 +129,9 @@ export class SonicToast extends LitElement {
|
|
|
123
129
|
// Ajoute le toast à la liste
|
|
124
130
|
const nextId = conf.id ?? new Date().valueOf();
|
|
125
131
|
|
|
126
|
-
const interactiveRegExp = new RegExp(
|
|
132
|
+
const interactiveRegExp = new RegExp(
|
|
133
|
+
"</a>|</.*?button>|</.*?input>|</.*?textarea>|</.*?select>"
|
|
134
|
+
);
|
|
127
135
|
const hasInteractive = interactiveRegExp.test(conf.text);
|
|
128
136
|
|
|
129
137
|
const currentToast = {
|
|
@@ -146,11 +154,13 @@ export class SonicToast extends LitElement {
|
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
if (toastComponent?.toasts.length) {
|
|
149
|
-
const toastA = {...currentToast};
|
|
157
|
+
const toastA = { ...currentToast };
|
|
150
158
|
for (const toast of toastComponent.toasts) {
|
|
151
|
-
const toastB = {...toast};
|
|
159
|
+
const toastB = { ...toast };
|
|
152
160
|
toastA.id = toastB.id = 0;
|
|
153
|
-
if (
|
|
161
|
+
if (
|
|
162
|
+
/*!currentToast.preserve && */ Objects.shallowEqual(toastA, toastB)
|
|
163
|
+
) {
|
|
154
164
|
return null;
|
|
155
165
|
}
|
|
156
166
|
}
|
|
@@ -164,14 +174,20 @@ export class SonicToast extends LitElement {
|
|
|
164
174
|
static handleExistingToastDelegation() {
|
|
165
175
|
if (!this.delegateToasts) return;
|
|
166
176
|
const toastComponent: SonicToast = SonicToast.getInstance();
|
|
167
|
-
window.parent.postMessage(
|
|
177
|
+
window.parent.postMessage(
|
|
178
|
+
{ type: "addToasts", toasts: toastComponent.toasts },
|
|
179
|
+
"*"
|
|
180
|
+
);
|
|
168
181
|
toastComponent.toasts = [];
|
|
169
182
|
}
|
|
170
183
|
|
|
171
184
|
static removeItem(toastToRemove?: Toast) {
|
|
172
185
|
if (SonicToast.delegateToasts) {
|
|
173
186
|
SonicToast.handleExistingToastDelegation();
|
|
174
|
-
window.parent.postMessage(
|
|
187
|
+
window.parent.postMessage(
|
|
188
|
+
{ type: "removeToast", toast: toastToRemove },
|
|
189
|
+
"*"
|
|
190
|
+
);
|
|
175
191
|
return;
|
|
176
192
|
}
|
|
177
193
|
const toastComponent: SonicToast = SonicToast.getInstance();
|
|
@@ -182,15 +198,18 @@ export class SonicToast extends LitElement {
|
|
|
182
198
|
removeItem(toastToRemove?: Toast) {
|
|
183
199
|
if (!toastToRemove) return;
|
|
184
200
|
this.toasts = this.toasts.filter((toast) => {
|
|
185
|
-
toast = {...toast};
|
|
201
|
+
toast = { ...toast };
|
|
186
202
|
delete toast.id;
|
|
187
203
|
return !Objects.shallowEqual(toast, toastToRemove, false);
|
|
188
204
|
});
|
|
189
205
|
}
|
|
190
206
|
}
|
|
191
207
|
|
|
208
|
+
declare const __SONIC_PREFIX__: string;
|
|
192
209
|
if (typeof window !== "undefined") {
|
|
193
|
-
|
|
210
|
+
if (__SONIC_PREFIX__ == "sonic") {
|
|
211
|
+
window.SonicToast = window.SonicToast || SonicToast;
|
|
212
|
+
}
|
|
194
213
|
}
|
|
195
214
|
|
|
196
215
|
/**
|
|
@@ -199,14 +218,17 @@ if (typeof window !== "undefined") {
|
|
|
199
218
|
function handleIframeContexts() {
|
|
200
219
|
const onPostMessage = (e: MessageEvent) => {
|
|
201
220
|
if (e.data.type == "querySonicToastAvailability") {
|
|
202
|
-
(e.source as Window).postMessage({type: "sonicToastAvailable"}, "*");
|
|
221
|
+
(e.source as Window).postMessage({ type: "sonicToastAvailable" }, "*");
|
|
203
222
|
}
|
|
204
223
|
if (e.data.type == "sonicToastAvailable") {
|
|
205
224
|
SonicToast.delegateToasts = true;
|
|
206
225
|
SonicToast.handleExistingToastDelegation();
|
|
207
226
|
}
|
|
208
227
|
if (e.data.type == "addToasts") {
|
|
209
|
-
SonicToast.getInstance().toasts = [
|
|
228
|
+
SonicToast.getInstance().toasts = [
|
|
229
|
+
...SonicToast.getInstance().toasts,
|
|
230
|
+
...e.data.toasts,
|
|
231
|
+
];
|
|
210
232
|
}
|
|
211
233
|
if (e.data.type == "removeAllToasts") {
|
|
212
234
|
SonicToast.removeAll();
|
|
@@ -223,14 +245,14 @@ function handleIframeContexts() {
|
|
|
223
245
|
window.addEventListener("message", onPostMessage, false);
|
|
224
246
|
|
|
225
247
|
if (isIframe) {
|
|
226
|
-
window.parent.postMessage({type: "querySonicToastAvailability"}, "*");
|
|
248
|
+
window.parent.postMessage({ type: "querySonicToastAvailability" }, "*");
|
|
227
249
|
}
|
|
228
250
|
|
|
229
251
|
// tell iframes that sonic-toast is available
|
|
230
252
|
|
|
231
253
|
if (!isIframe) {
|
|
232
254
|
for (const iframe of document.querySelectorAll("iframe")) {
|
|
233
|
-
iframe.contentWindow?.postMessage({type: "sonicToastAvailable"}, "*");
|
|
255
|
+
iframe.contentWindow?.postMessage({ type: "sonicToastAvailable" }, "*");
|
|
234
256
|
}
|
|
235
257
|
}
|
|
236
258
|
}
|
package/src/core/core.ts
CHANGED
|
@@ -2,13 +2,9 @@ import "./components/functional/functional";
|
|
|
2
2
|
import "./components/ui/ui";
|
|
3
3
|
import "./mixins/mixins";
|
|
4
4
|
import "./utils/url-pattern";
|
|
5
|
-
import {
|
|
6
|
-
import DataBindObserver from "./utils/DataBindObserver";
|
|
7
|
-
import {ConcordeWindow} from "./_types/types";
|
|
5
|
+
import { ConcordeWindow } from "./_types/types";
|
|
8
6
|
|
|
9
7
|
declare const window: ConcordeWindow;
|
|
10
|
-
if (!window.SonicPublisherManager) window.SonicPublisherManager = PublisherManager;
|
|
11
|
-
if (!window.SonicDataBindObserver) window.SonicDataBindObserver = DataBindObserver;
|
|
12
8
|
window.queueMicrotask =
|
|
13
9
|
window.queueMicrotask ||
|
|
14
10
|
function (callback) {
|
|
@@ -85,6 +85,8 @@ const Fetcher = <
|
|
|
85
85
|
}
|
|
86
86
|
_endPoint = "";
|
|
87
87
|
|
|
88
|
+
@property() noErrorsRecordings = false;
|
|
89
|
+
|
|
88
90
|
@property() get props(): (PropsType & ResultTypeInterface) | null {
|
|
89
91
|
return super.props as (PropsType & ResultTypeInterface) | null;
|
|
90
92
|
}
|
|
@@ -146,7 +148,9 @@ const Fetcher = <
|
|
|
146
148
|
|
|
147
149
|
this.fetchedData = data;
|
|
148
150
|
if (this.api.lastResult && !this.api.lastResult.ok) {
|
|
149
|
-
|
|
151
|
+
if (!this.noErrorsRecordings) {
|
|
152
|
+
fetchersInError.add(this);
|
|
153
|
+
}
|
|
150
154
|
dispatchFetchError(this.api.lastResult);
|
|
151
155
|
}
|
|
152
156
|
if (!this.isConnected) {
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {APIConfiguration} from "@supersoniks/concorde/core/utils/api";
|
|
1
|
+
import { APIConfiguration } from "@supersoniks/concorde/core/utils/api";
|
|
2
2
|
import DataBindObserver from "@supersoniks/concorde/core/utils/DataBindObserver";
|
|
3
3
|
import HTML from "@supersoniks/concorde/core/utils/HTML";
|
|
4
4
|
import Objects from "@supersoniks/concorde/core/utils/Objects";
|
|
5
|
-
import {PublisherManager} from "@supersoniks/concorde/core/utils/PublisherProxy";
|
|
6
|
-
import {LitElement, PropertyValues} from "lit";
|
|
7
|
-
import {property} from "lit/decorators.js";
|
|
5
|
+
import { PublisherManager } from "@supersoniks/concorde/core/utils/PublisherProxy";
|
|
6
|
+
import { LitElement, PropertyValues } from "lit";
|
|
7
|
+
import { property } from "lit/decorators.js";
|
|
8
8
|
import WordingDirective from "../directives/Wording";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
PublisherInterface,
|
|
11
|
+
TypeAndRecordOfType,
|
|
12
|
+
ConcordeWindow,
|
|
13
|
+
MixinArgsType,
|
|
14
|
+
CoreJSType,
|
|
15
|
+
} from "@supersoniks/concorde/core/_types/types";
|
|
10
16
|
declare const window: ConcordeWindow;
|
|
11
17
|
type Constructor<T> = new (...args: MixinArgsType[]) => T;
|
|
12
18
|
let keepDebugOnMouseOut = false;
|
|
@@ -29,8 +35,16 @@ export interface SubscriberInterface<PropsType = CoreJSType> {
|
|
|
29
35
|
shadowRoot?: ShadowRoot;
|
|
30
36
|
dispatchEvent(event: Event): void;
|
|
31
37
|
setAttribute(name: string, value: string): void;
|
|
32
|
-
addEventListener(
|
|
33
|
-
|
|
38
|
+
addEventListener(
|
|
39
|
+
type: string,
|
|
40
|
+
listener: EventListenerOrEventListenerObject,
|
|
41
|
+
options?: boolean | AddEventListenerOptions
|
|
42
|
+
): void;
|
|
43
|
+
removeEventListener(
|
|
44
|
+
type: string,
|
|
45
|
+
listener: EventListenerOrEventListenerObject,
|
|
46
|
+
options?: boolean | EventListenerOptions
|
|
47
|
+
): void;
|
|
34
48
|
removeAttribute(name: string): void;
|
|
35
49
|
initPublisher(): void;
|
|
36
50
|
getApiConfiguration(): APIConfiguration;
|
|
@@ -42,7 +56,10 @@ export interface SubscriberInterface<PropsType = CoreJSType> {
|
|
|
42
56
|
getBoundingClientRect(): DOMRect;
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
const Subscriber = <
|
|
59
|
+
const Subscriber = <
|
|
60
|
+
PropsType = CoreJSType,
|
|
61
|
+
T extends Constructor<LitElement> = Constructor<LitElement>
|
|
62
|
+
>(
|
|
46
63
|
superClass: T,
|
|
47
64
|
type?: PropsType
|
|
48
65
|
) => {
|
|
@@ -62,16 +79,16 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
62
79
|
args;
|
|
63
80
|
}
|
|
64
81
|
|
|
65
|
-
@property({type: Number}) collectDependenciesVersion = 0;
|
|
82
|
+
@property({ type: Number }) collectDependenciesVersion = 0;
|
|
66
83
|
|
|
67
|
-
@property({type: Boolean}) displayContents = false;
|
|
84
|
+
@property({ type: Boolean }) displayContents = false;
|
|
68
85
|
|
|
69
86
|
/**
|
|
70
87
|
* noAutoFill permet de désactiver le remplissage automatique des propriétés par le publisher dans le cas ou on utilise "props" seulement ou le dataBinding par exemple
|
|
71
88
|
*/
|
|
72
|
-
@property({type: Boolean}) noAutoFill = false;
|
|
89
|
+
@property({ type: Boolean }) noAutoFill = false;
|
|
73
90
|
|
|
74
|
-
@property({type: Boolean}) forceAutoFill = false;
|
|
91
|
+
@property({ type: Boolean }) forceAutoFill = false;
|
|
75
92
|
|
|
76
93
|
/**
|
|
77
94
|
* Passer ce paramètre à true permet de ne pas mettre à jour le composant lors d'un changement de interne de la propriété nommé props.
|
|
@@ -88,8 +105,8 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
88
105
|
* Permet de mapper un nom de propriété de donnée source vars une propriété du subscriber à la volée
|
|
89
106
|
*/
|
|
90
107
|
|
|
91
|
-
@property({type: Object}) propertyMap: object | null = null;
|
|
92
|
-
@property({type: String, attribute: "data-title"}) title = "";
|
|
108
|
+
@property({ type: Object }) propertyMap: object | null = null;
|
|
109
|
+
@property({ type: String, attribute: "data-title" }) title = "";
|
|
93
110
|
|
|
94
111
|
/**
|
|
95
112
|
* va de parent en parent pour trouver un attribut
|
|
@@ -111,13 +128,14 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
111
128
|
/**
|
|
112
129
|
* L'id / l'adresse du publisher accessible via PublisherManager.get(dataProvider)
|
|
113
130
|
*/
|
|
114
|
-
@property({reflect: true}) dataProvider: string | null = null;
|
|
131
|
+
@property({ reflect: true }) dataProvider: string | null = null;
|
|
115
132
|
|
|
116
133
|
/**
|
|
117
134
|
* On peut utiliser cette fonction pour lier un publisher spécifique au composant si besoin.
|
|
118
135
|
* voir l'utilisation dans list.ts
|
|
119
136
|
*/
|
|
120
|
-
@property() bindPublisher: (() => PublisherInterface<PropsType>) | null =
|
|
137
|
+
@property() bindPublisher: (() => PublisherInterface<PropsType>) | null =
|
|
138
|
+
null;
|
|
121
139
|
|
|
122
140
|
/**
|
|
123
141
|
* Les props du composant.
|
|
@@ -131,7 +149,10 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
131
149
|
return this.publisher.get();
|
|
132
150
|
}
|
|
133
151
|
set props(value) {
|
|
134
|
-
if (
|
|
152
|
+
if (
|
|
153
|
+
typeof value == "string" &&
|
|
154
|
+
["{", "["].includes(value.trim().charAt(0))
|
|
155
|
+
) {
|
|
135
156
|
value = JSON.parse(value);
|
|
136
157
|
}
|
|
137
158
|
if (value == this._props) return;
|
|
@@ -148,8 +169,14 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
148
169
|
protected updated(_changedProperties: PropertyValues): void {
|
|
149
170
|
super.updated(_changedProperties);
|
|
150
171
|
const ref = this.shadowRoot || this;
|
|
151
|
-
const children = [...ref.children].filter(
|
|
152
|
-
|
|
172
|
+
const children = [...ref.children].filter(
|
|
173
|
+
(child) => child.tagName != "STYLE"
|
|
174
|
+
);
|
|
175
|
+
const display = this.displayContents
|
|
176
|
+
? "contents"
|
|
177
|
+
: children.length == 0
|
|
178
|
+
? "none"
|
|
179
|
+
: null;
|
|
153
180
|
if (display) this.style.display = display;
|
|
154
181
|
else this.style.removeProperty("display");
|
|
155
182
|
}
|
|
@@ -243,7 +270,11 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
243
270
|
if (!keepDebugOnMouseOut) this.removeDebugger();
|
|
244
271
|
});
|
|
245
272
|
this.publisher?.onInternalMutation(() => {
|
|
246
|
-
(
|
|
273
|
+
(
|
|
274
|
+
this.debug as HTMLElement
|
|
275
|
+
).innerHTML = `🤖 DataProvider : "<b style="font-weight:bold;color:#fff;">${
|
|
276
|
+
this.dataProvider
|
|
277
|
+
}</b>"<br>
|
|
247
278
|
<div style="font-size:10px;border-top:1px dashed;margin-top:5px;padding-left:23px;opacity:.6;padding-top:5px;">
|
|
248
279
|
Variable disponible dans la console<br>
|
|
249
280
|
ctrl + Clique : épingler / désépingler
|
|
@@ -313,21 +344,27 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
313
344
|
if (this.onAssign) this.publisher.offAssign(this.onAssign);
|
|
314
345
|
}
|
|
315
346
|
const mng = PublisherManager.getInstance();
|
|
316
|
-
if (!this.dataProvider)
|
|
347
|
+
if (!this.dataProvider)
|
|
348
|
+
this.dataProvider = this.getAncestorAttributeValue("dataProvider");
|
|
317
349
|
let publisherId = this.dataProvider;
|
|
318
350
|
if (!publisherId && this._props) {
|
|
319
|
-
this.dataProvider = publisherId =
|
|
351
|
+
this.dataProvider = publisherId =
|
|
352
|
+
"__subscriber__" + SubscriberElement.instanceCounter;
|
|
320
353
|
}
|
|
321
354
|
if (publisherId) {
|
|
322
355
|
if (this.bindPublisher) {
|
|
323
356
|
mng.set(publisherId, this.bindPublisher());
|
|
324
357
|
}
|
|
325
358
|
|
|
326
|
-
let pub = mng.get(publisherId, {
|
|
359
|
+
let pub = mng.get(publisherId, {
|
|
360
|
+
localStorageMode: this.getAttribute("localStorage") || "disabled",
|
|
361
|
+
});
|
|
327
362
|
this.dataProvider = publisherId;
|
|
328
363
|
|
|
329
364
|
if (this.hasAttribute("subDataProvider")) {
|
|
330
|
-
const dataPath: string = this.getAttribute(
|
|
365
|
+
const dataPath: string = this.getAttribute(
|
|
366
|
+
"subDataProvider"
|
|
367
|
+
) as string;
|
|
331
368
|
this.dataProvider = publisherId + "/" + dataPath;
|
|
332
369
|
pub = Objects.traverse(pub, dataPath.split("."));
|
|
333
370
|
mng.set(this.dataProvider, pub);
|
|
@@ -340,7 +377,8 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
340
377
|
this.publisher.set(this._props);
|
|
341
378
|
}
|
|
342
379
|
if (!this.noAutoFill) this.publisher.startTemplateFilling(this);
|
|
343
|
-
if (this.renderOnPropsInternalChange)
|
|
380
|
+
if (this.renderOnPropsInternalChange)
|
|
381
|
+
this.publisher.onInternalMutation(this.requestUpdate);
|
|
344
382
|
this.publisher.onAssign(this.onAssign);
|
|
345
383
|
}
|
|
346
384
|
}
|
|
@@ -348,5 +386,3 @@ const Subscriber = <PropsType = CoreJSType, T extends Constructor<LitElement> =
|
|
|
348
386
|
return SubscriberElement as Constructor<SubscriberInterface<PropsType>> & T;
|
|
349
387
|
};
|
|
350
388
|
export default Subscriber;
|
|
351
|
-
|
|
352
|
-
if (!window.SonicPublisherManager) window.SonicPublisherManager = PublisherManager;
|
|
@@ -24,6 +24,22 @@ const queueTaskPromise = async () => {
|
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
declare const __BUILD_DATE__: string;
|
|
28
|
+
declare const __SONIC_PREFIX__: string;
|
|
29
|
+
|
|
30
|
+
if (typeof __BUILD_DATE__ === "undefined") {
|
|
31
|
+
(window as any).__BUILD_DATE__ = "No build date";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof __SONIC_PREFIX__ === "undefined") {
|
|
35
|
+
(window as any).__SONIC_PREFIX__ = "sonic";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const localStorageDataKey =
|
|
39
|
+
__SONIC_PREFIX__ == "sonic"
|
|
40
|
+
? "publisher-proxies-data"
|
|
41
|
+
: __SONIC_PREFIX__ + "-publisher-proxies-data";
|
|
42
|
+
|
|
27
43
|
/**
|
|
28
44
|
* Custom Proxy contient les méthodes des publishers retournés par PublisherManager.get(publisherId) qui seront utilisées couramment
|
|
29
45
|
*/
|
|
@@ -348,9 +364,13 @@ export class PublisherProxy<T = any> {
|
|
|
348
364
|
}
|
|
349
365
|
PublisherProxy.instances.set(this._instanceCounter_, this);
|
|
350
366
|
const str =
|
|
351
|
-
|
|
367
|
+
"<" +
|
|
368
|
+
__SONIC_PREFIX__ +
|
|
369
|
+
'-publisher-proxy publisher="' +
|
|
352
370
|
this._instanceCounter_ +
|
|
353
|
-
'"></
|
|
371
|
+
'"></' +
|
|
372
|
+
__SONIC_PREFIX__ +
|
|
373
|
+
"-publisher-proxy>";
|
|
354
374
|
return str;
|
|
355
375
|
}
|
|
356
376
|
}
|
|
@@ -361,17 +381,13 @@ export class PublisherProxy<T = any> {
|
|
|
361
381
|
*
|
|
362
382
|
*/
|
|
363
383
|
|
|
364
|
-
declare const __BUILD_DATE__: string;
|
|
365
|
-
if (typeof __BUILD_DATE__ === "undefined") {
|
|
366
|
-
(window as any).__BUILD_DATE__ = "No build date";
|
|
367
|
-
}
|
|
368
|
-
|
|
369
384
|
export class PublisherManager {
|
|
370
385
|
static buildDate = __BUILD_DATE__;
|
|
371
386
|
static changed = false;
|
|
372
387
|
static saving = false;
|
|
373
388
|
static saveId = 0;
|
|
374
389
|
static instance: PublisherManager | null = null;
|
|
390
|
+
static instances: Map<string, PublisherManager> = new Map();
|
|
375
391
|
enabledLocaStorageProxies: string[] = [];
|
|
376
392
|
publishers = new Map<string, Publisher>();
|
|
377
393
|
localStorageData: Record<
|
|
@@ -389,7 +405,7 @@ export class PublisherManager {
|
|
|
389
405
|
return new Promise((resolve) => {
|
|
390
406
|
const doiIt = async () => {
|
|
391
407
|
try {
|
|
392
|
-
let compressedData = localStorage.getItem(
|
|
408
|
+
let compressedData = localStorage.getItem(localStorageDataKey);
|
|
393
409
|
|
|
394
410
|
let localStorageJSON = null;
|
|
395
411
|
if (compressedData)
|
|
@@ -403,7 +419,7 @@ export class PublisherManager {
|
|
|
403
419
|
}
|
|
404
420
|
} else {
|
|
405
421
|
compressedData = await this.compress("{}", "gzip");
|
|
406
|
-
localStorage.setItem(
|
|
422
|
+
localStorage.setItem(localStorageDataKey, compressedData);
|
|
407
423
|
this.localStorageData = {};
|
|
408
424
|
}
|
|
409
425
|
const expires = new Date().getTime() - 1000 * 60 * 60 * 12;
|
|
@@ -415,7 +431,7 @@ export class PublisherManager {
|
|
|
415
431
|
}
|
|
416
432
|
resolve(true);
|
|
417
433
|
// compressedData = await this.compress(JSON.stringify(this.localStorageData), "gzip");
|
|
418
|
-
// localStorage.setItem("publisher-proxies-data", compressedData);
|
|
434
|
+
// localStorage.setItem(__SONIC_PREFIX__+"-publisher-proxies-data", compressedData);
|
|
419
435
|
} catch (e) {
|
|
420
436
|
window.requestAnimationFrame(() => {
|
|
421
437
|
resolve(false);
|
|
@@ -430,10 +446,34 @@ export class PublisherManager {
|
|
|
430
446
|
/**
|
|
431
447
|
* PublisherManager est un singleton
|
|
432
448
|
*/
|
|
433
|
-
static getInstance() {
|
|
449
|
+
static getInstance(id?: string): PublisherManager {
|
|
450
|
+
if (id) {
|
|
451
|
+
const pm = PublisherManager.instances.get(id);
|
|
452
|
+
if (pm) {
|
|
453
|
+
return pm;
|
|
454
|
+
} else {
|
|
455
|
+
console.warn(
|
|
456
|
+
"No PublisherManager instance registered with id:",
|
|
457
|
+
id,
|
|
458
|
+
"creating new one"
|
|
459
|
+
);
|
|
460
|
+
return new PublisherManager();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
434
463
|
if (PublisherManager.instance == null) return new PublisherManager();
|
|
435
464
|
return PublisherManager.instance;
|
|
436
465
|
}
|
|
466
|
+
|
|
467
|
+
static registerInstance(id: string, instance: PublisherManager) {
|
|
468
|
+
if (PublisherManager.instances.has(id)) {
|
|
469
|
+
console.warn(
|
|
470
|
+
"PublisherManager instance already registered with id: ",
|
|
471
|
+
id
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
PublisherManager.instances.set(id, instance);
|
|
475
|
+
}
|
|
476
|
+
|
|
437
477
|
/**
|
|
438
478
|
* shortcut static pour obtenir un publisher vias sont id/adresse sans taper getInstance.
|
|
439
479
|
* Si le publisher n'existe pas, il est créé.
|
|
@@ -539,7 +579,7 @@ export class PublisherManager {
|
|
|
539
579
|
JSON.stringify(this.localStorageData),
|
|
540
580
|
"gzip"
|
|
541
581
|
);
|
|
542
|
-
localStorage.setItem(
|
|
582
|
+
localStorage.setItem(localStorageDataKey, compressedData);
|
|
543
583
|
}
|
|
544
584
|
PublisherManager.saving = false;
|
|
545
585
|
if (PublisherManager.changed) {
|
|
@@ -584,6 +624,15 @@ export class PublisherManager {
|
|
|
584
624
|
}
|
|
585
625
|
}
|
|
586
626
|
|
|
627
|
+
const customWin: { SonicPublisherManager?: any } = window as any;
|
|
628
|
+
|
|
629
|
+
if (!customWin.SonicPublisherManager) {
|
|
630
|
+
customWin.SonicPublisherManager = PublisherManager;
|
|
631
|
+
}
|
|
632
|
+
customWin.SonicPublisherManager.registerInstance(
|
|
633
|
+
PublisherManager.getInstance()
|
|
634
|
+
);
|
|
635
|
+
|
|
587
636
|
const internalProps: Set<string> = new Set([
|
|
588
637
|
"invalidate",
|
|
589
638
|
"onInvalidate",
|
|
@@ -783,4 +832,7 @@ class PublisherWebComponent extends HTMLElement {
|
|
|
783
832
|
this.innerHTML = value.toString();
|
|
784
833
|
};
|
|
785
834
|
}
|
|
786
|
-
customElements.define(
|
|
835
|
+
customElements.define(
|
|
836
|
+
__SONIC_PREFIX__ + "-publisher-proxy",
|
|
837
|
+
PublisherWebComponent
|
|
838
|
+
);
|
package/vite/config.js
CHANGED
|
@@ -107,11 +107,13 @@ const config = (
|
|
|
107
107
|
];
|
|
108
108
|
|
|
109
109
|
const __BUILD_DATE__ = new Date();
|
|
110
|
+
const __SONIC_PREFIX__ = prefix;
|
|
110
111
|
|
|
111
112
|
result.define = {
|
|
112
113
|
...(result.define || {}),
|
|
113
114
|
// Définir une constante contenant la date de build
|
|
114
115
|
__BUILD_DATE__: JSON.stringify(__BUILD_DATE__.toString()),
|
|
116
|
+
__SONIC_PREFIX__: __SONIC_PREFIX__,
|
|
115
117
|
};
|
|
116
118
|
|
|
117
119
|
if (tsConfig) {
|