@supersoniks/concorde 1.1.45 → 1.1.46

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.
Files changed (44) hide show
  1. package/concorde-core.bundle.js +39 -24
  2. package/concorde-core.es.js +701 -231
  3. package/core/components/functional/fetch/fetch.d.ts +2 -1
  4. package/core/components/functional/list/list.d.ts +3 -1
  5. package/core/components/functional/list/list.js +3 -1
  6. package/core/components/functional/queue/queue.d.ts +8 -1
  7. package/core/components/functional/queue/queue.js +126 -62
  8. package/core/components/functional/sdui/sdui.d.ts +2 -1
  9. package/core/components/ui/alert/alert.d.ts +3 -0
  10. package/core/components/ui/alert/alert.js +33 -1
  11. package/core/components/ui/badge/badge.d.ts +1 -1
  12. package/core/components/ui/badge/badge.js +9 -3
  13. package/core/components/ui/button/button.d.ts +1 -0
  14. package/core/components/ui/form/checkbox/checkbox.d.ts +3 -0
  15. package/core/components/ui/form/checkbox/checkbox.js +14 -3
  16. package/core/components/ui/form/css/form-control.d.ts +1 -0
  17. package/core/components/ui/form/css/form-control.js +17 -0
  18. package/core/components/ui/form/input/input.d.ts +5 -3
  19. package/core/components/ui/form/input/input.js +47 -3
  20. package/core/components/ui/form/input-autocomplete/input-autocomplete.d.ts +93 -13
  21. package/core/components/ui/form/input-autocomplete/input-autocomplete.js +181 -52
  22. package/core/components/ui/form/textarea/textarea.d.ts +1 -0
  23. package/core/components/ui/icon/icon.js +1 -1
  24. package/core/components/ui/modal/modal-close.js +2 -3
  25. package/core/components/ui/modal/modal-content.js +1 -0
  26. package/core/components/ui/modal/modal.d.ts +8 -0
  27. package/core/components/ui/modal/modal.js +34 -6
  28. package/core/components/ui/pop/pop.js +18 -7
  29. package/core/components/ui/theme/theme-collection/core-variables.js +18 -9
  30. package/core/components/ui/theme/theme.js +8 -3
  31. package/core/mixins/Fetcher.d.ts +2 -1
  32. package/core/mixins/Fetcher.js +42 -10
  33. package/core/mixins/FormCheckable.d.ts +1 -0
  34. package/core/mixins/FormElement.d.ts +1 -0
  35. package/core/mixins/FormElement.js +6 -2
  36. package/core/mixins/FormInput.d.ts +1 -0
  37. package/core/mixins/Subscriber.d.ts +1 -0
  38. package/core/mixins/Subscriber.js +12 -7
  39. package/core/utils/PublisherProxy.d.ts +30 -3
  40. package/core/utils/PublisherProxy.js +218 -6
  41. package/core/utils/api.d.ts +3 -0
  42. package/core/utils/api.js +3 -1
  43. package/mixins.d.ts +4 -1
  44. package/package.json +5 -1
@@ -1,4 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any*/
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  function isComplex(value) {
3
12
  return typeof value === "object" && value != null;
4
13
  }
@@ -9,15 +18,18 @@ export class PublisherProxy {
9
18
  constructor(target, parentProxPub) {
10
19
  this._proxies_ = new Map();
11
20
  this._key_ = "";
21
+ this._is_savable_ = false;
12
22
  this._invalidateListeners_ = new Set();
13
23
  this._assignListeners_ = new Set();
14
24
  this._mutationListeners_ = new Set();
15
25
  this._fillListeners_ = new Set();
16
26
  this._templateFillListeners_ = new Set();
17
27
  this._lockInternalMutationPublishing_ = false;
28
+ this._instanceCounter_ = 0;
18
29
  this._value_ = target;
19
30
  this.parent = parentProxPub || null;
20
31
  this.root = this;
32
+ this._instanceCounter_ = 0;
21
33
  while (this.root.parent) {
22
34
  this.root = this.root.parent;
23
35
  }
@@ -36,6 +48,7 @@ export class PublisherProxy {
36
48
  this._fillListeners_.clear();
37
49
  this._templateFillListeners_.clear();
38
50
  this._proxies_.clear();
51
+ PublisherProxy.instances.delete(this._instanceCounter_);
39
52
  }
40
53
  /**
41
54
  * Utile pour savoir si quelque chose est en écoute d'une modification sur le proxy via une des methodes associées
@@ -51,6 +64,12 @@ export class PublisherProxy {
51
64
  this._mutationListeners_.forEach((handler) => handler());
52
65
  if (lockInternalMutationsTransmission)
53
66
  return;
67
+ if (!PublisherManager.changed && this._is_savable_) {
68
+ PublisherManager.changed = true;
69
+ PublisherManager.saveId++;
70
+ const saveId = PublisherManager.saveId;
71
+ setTimeout(() => PublisherManager.getInstance().saveToLocalStorage(saveId), 1000);
72
+ }
54
73
  if (this.parent) {
55
74
  this.parent._publishInternalMutation_();
56
75
  }
@@ -273,7 +292,21 @@ export class PublisherProxy {
273
292
  }
274
293
  return this._value_;
275
294
  }
295
+ /**
296
+ * retourner le webcomponent auquel le proxy est associé
297
+ */
298
+ get $tag() {
299
+ if (!this._instanceCounter_) {
300
+ PublisherProxy.instancesCounter++;
301
+ this._instanceCounter_ = PublisherProxy.instancesCounter;
302
+ }
303
+ PublisherProxy.instances.set(this._instanceCounter_, this);
304
+ const str = '<reactive-publisher-proxy publisher="' + this._instanceCounter_ + '"></reactive-publisher-proxy>';
305
+ return str;
306
+ }
276
307
  }
308
+ PublisherProxy.instances = new Map();
309
+ PublisherProxy.instancesCounter = 0;
277
310
  /**
278
311
  * Utilitaires de gestion des Publisher
279
312
  * Obtenir, replacer ou supprimer un Publisher
@@ -281,10 +314,59 @@ export class PublisherProxy {
281
314
  */
282
315
  export class PublisherManager {
283
316
  constructor() {
317
+ this.enabledLocaStorageProxies = [];
284
318
  this.publishers = new Map();
319
+ this.localStorageData = {};
320
+ this.isLocalStrorageReady = null;
321
+ this.initialisedData = [];
285
322
  if (PublisherManager.instance != null)
286
323
  throw "Singleton / use getInstance";
287
324
  PublisherManager.instance = this;
325
+ this.isLocalStrorageReady = this.cleanStorageData();
326
+ }
327
+ cleanStorageData() {
328
+ return __awaiter(this, void 0, void 0, function* () {
329
+ return new Promise((resolve) => {
330
+ const doiIt = () => __awaiter(this, void 0, void 0, function* () {
331
+ try {
332
+ let compressedData = localStorage.getItem("publisher-proxies-data");
333
+ let localStorageJSON = null;
334
+ if (compressedData)
335
+ localStorageJSON = yield this.decompress(compressedData, "gzip");
336
+ if (localStorageJSON) {
337
+ try {
338
+ this.localStorageData = JSON.parse(localStorageJSON);
339
+ }
340
+ catch (e) {
341
+ this.localStorageData = {};
342
+ }
343
+ }
344
+ else {
345
+ compressedData = yield this.compress("{}", "gzip");
346
+ localStorage.setItem("publisher-proxies-data", compressedData);
347
+ this.localStorageData = {};
348
+ }
349
+ const expires = new Date().getTime() - 1000 * 60 * 60 * 12;
350
+ for (const key in this.localStorageData) {
351
+ const item = this.localStorageData[key];
352
+ if (item.lastModifiationMS < expires) {
353
+ delete this.localStorageData[key];
354
+ }
355
+ }
356
+ resolve(true);
357
+ // compressedData = await this.compress(JSON.stringify(this.localStorageData), "gzip");
358
+ // localStorage.setItem("publisher-proxies-data", compressedData);
359
+ }
360
+ catch (e) {
361
+ window.requestAnimationFrame(() => {
362
+ resolve(false);
363
+ });
364
+ console.log("no publisher cache in this browser");
365
+ }
366
+ });
367
+ doiIt();
368
+ });
369
+ });
288
370
  }
289
371
  /**
290
372
  * PublisherManager est un singleton
@@ -298,8 +380,8 @@ export class PublisherManager {
298
380
  * shortcut static pour obtenir un publisher vias sont id/adresse sans taper getInstance.
299
381
  * Si le publisher n'existe pas, il est créé.
300
382
  */
301
- static get(id) {
302
- return PublisherManager.getInstance().get(id);
383
+ static get(id, options) {
384
+ return PublisherManager.getInstance().get(id, options);
303
385
  }
304
386
  /**
305
387
  * shortcut static pour supprimer un publisher de la liste et appel également delete sur le publisher ce qui le supprime, de même que ses sous publishers
@@ -311,9 +393,26 @@ export class PublisherManager {
311
393
  * Obtenir un publisher vias sont id/adresse
312
394
  * Si le publisher n'existe pas, il est créé.
313
395
  */
314
- get(id) {
315
- if (!this.publishers.has(id))
316
- this.publishers.set(id, new Publisher({}));
396
+ setLocalData(publisher, id) {
397
+ var _a;
398
+ return __awaiter(this, void 0, void 0, function* () {
399
+ yield this.isLocalStrorageReady;
400
+ publisher.set(((_a = this.localStorageData[id + "¤page:>" + document.location.pathname]) === null || _a === void 0 ? void 0 : _a.data) || publisher.get());
401
+ });
402
+ }
403
+ get(id, options) {
404
+ const hasLocalStorage = (options === null || options === void 0 ? void 0 : options.localStorageMode) === "enabled";
405
+ if (!this.publishers.has(id)) {
406
+ const data = {};
407
+ const publisher = new Publisher(data);
408
+ this.set(id, publisher);
409
+ }
410
+ const publisher = this.publishers.get(id);
411
+ if (hasLocalStorage && this.initialisedData.indexOf(id) === -1) {
412
+ publisher._is_savable_ = true;
413
+ this.initialisedData.push(id);
414
+ this.setLocalData(publisher, id);
415
+ }
317
416
  return this.publishers.get(id);
318
417
  }
319
418
  /**
@@ -332,7 +431,86 @@ export class PublisherManager {
332
431
  this.publishers.delete(id);
333
432
  return true;
334
433
  }
434
+ saveToLocalStorage(saveId = 0) {
435
+ return __awaiter(this, void 0, void 0, function* () {
436
+ /**
437
+ * si l'id a changé et que ce n'est pas un multiple de 10, on ne sauve pas
438
+ * on sauvegarde quand même tous les 10 au cas ou on aurrait des changements en continue, par exemple à chaque frame
439
+ */
440
+ if (saveId !== PublisherManager.saveId && saveId % 10 != 0)
441
+ return;
442
+ try {
443
+ if (!PublisherManager.changed || PublisherManager.saving)
444
+ return;
445
+ PublisherManager.saving = true;
446
+ PublisherManager.changed = false;
447
+ const keys = Array.from(this.publishers.keys());
448
+ let hasChanged = false;
449
+ for (const key of keys) {
450
+ const publisher = this.publishers.get(key);
451
+ if (!(publisher === null || publisher === void 0 ? void 0 : publisher._is_savable_))
452
+ continue;
453
+ const data = publisher === null || publisher === void 0 ? void 0 : publisher.get();
454
+ if (!data)
455
+ continue;
456
+ this.localStorageData[key + "¤page:>" + document.location.pathname] = {
457
+ lastModifiationMS: new Date().getTime(),
458
+ data: data,
459
+ };
460
+ hasChanged = true;
461
+ }
462
+ // on enregistre les données
463
+ if (hasChanged) {
464
+ const compressedData = yield this.compress(JSON.stringify(this.localStorageData), "gzip");
465
+ localStorage.setItem("publisher-proxies-data", compressedData);
466
+ }
467
+ PublisherManager.saving = false;
468
+ if (PublisherManager.changed) {
469
+ PublisherManager.saveId++;
470
+ const saveId = PublisherManager.saveId;
471
+ setTimeout(() => this.saveToLocalStorage(saveId), 1000);
472
+ }
473
+ }
474
+ catch (e) {
475
+ PublisherManager.saving = false;
476
+ }
477
+ });
478
+ }
479
+ compress(string, encoding) {
480
+ return __awaiter(this, void 0, void 0, function* () {
481
+ const byteArray = new TextEncoder().encode(string);
482
+ const win = window;
483
+ const cs = new win.CompressionStream(encoding);
484
+ const writer = cs.writable.getWriter();
485
+ writer.write(byteArray);
486
+ writer.close();
487
+ const result = yield new Response(cs.readable).arrayBuffer();
488
+ const arrayBufferView = new Uint8Array(result);
489
+ let str = "";
490
+ for (let i = 0; i < arrayBufferView.length; i++) {
491
+ str += String.fromCharCode(arrayBufferView[i]);
492
+ }
493
+ return btoa(str);
494
+ });
495
+ }
496
+ decompress(str, encoding) {
497
+ return __awaiter(this, void 0, void 0, function* () {
498
+ const decodedString = atob(str);
499
+ const arrayBufferViewFromLocalStorage = Uint8Array.from(decodedString, (c) => c.charCodeAt(0));
500
+ const byteArray = arrayBufferViewFromLocalStorage.buffer;
501
+ const win = window;
502
+ const cs = new win.DecompressionStream(encoding);
503
+ const writer = cs.writable.getWriter();
504
+ writer.write(byteArray);
505
+ writer.close();
506
+ const result = yield new Response(cs.readable).arrayBuffer();
507
+ return new TextDecoder().decode(result);
508
+ });
509
+ }
335
510
  }
511
+ PublisherManager.changed = false;
512
+ PublisherManager.saving = false;
513
+ PublisherManager.saveId = 0;
336
514
  PublisherManager.instance = null;
337
515
  /**
338
516
  * Le Proxy Javascript
@@ -361,6 +539,7 @@ export default class Publisher extends PublisherProxy {
361
539
  "offInternalMutation",
362
540
  "set",
363
541
  "get",
542
+ "$tag",
364
543
  "_templateFillListeners_",
365
544
  "_fillListeners_",
366
545
  "_assignListeners_",
@@ -376,7 +555,9 @@ export default class Publisher extends PublisherProxy {
376
555
  "_proxies_",
377
556
  "parent",
378
557
  "_value_",
558
+ "_is_savable_",
379
559
  "_lockInternalMutationPublishing_",
560
+ "_instanceCounter_",
380
561
  ].includes(sKey))
381
562
  return publisherInstance[sKey];
382
563
  if (!publisherInstance._proxies_.has(sKey)) {
@@ -396,7 +577,14 @@ export default class Publisher extends PublisherProxy {
396
577
  //Fonctionnement pour la donnée interne pas de dispatch;
397
578
  if (sKey == "_value_") {
398
579
  publisherInstance._value_ = vValue;
399
- // return publisherInstance._value_;
580
+ return true;
581
+ }
582
+ if (sKey == "_is_savable_") {
583
+ publisherInstance._is_savable_ = vValue;
584
+ return true;
585
+ }
586
+ if (sKey == "_instanceCounter_") {
587
+ publisherInstance._instanceCounter_ = vValue;
400
588
  return true;
401
589
  }
402
590
  //Création du publisher si il n'existe pas
@@ -463,3 +651,27 @@ export default class Publisher extends PublisherProxy {
463
651
  }
464
652
  if (typeof module != "undefined")
465
653
  module.exports = { Publisher: Publisher, PublisherManager: PublisherManager };
654
+ // /**
655
+ // * A custom webcomponent wich will be linked to a publisher via its attribute "publisher"
656
+ // * the publisher will be found via PublisherManager.get(publisherId) and will be used to fill the component using the onAssign method
657
+ // */
658
+ class PublisherWebComponent extends HTMLElement {
659
+ constructor() {
660
+ super();
661
+ this.publisherId = "";
662
+ this.onAssign = (value) => {
663
+ this.innerHTML = value.toString();
664
+ };
665
+ }
666
+ connectedCallback() {
667
+ var _a;
668
+ this.publisherId = this.getAttribute("publisher") || "";
669
+ this.publisher = PublisherProxy.instances.get(parseInt(this.publisherId));
670
+ (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.onAssign(this.onAssign);
671
+ }
672
+ disconnectedCallback() {
673
+ var _a;
674
+ (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.offAssign(this.onAssign);
675
+ }
676
+ }
677
+ customElements.define("reactive-publisher-proxy", PublisherWebComponent);
@@ -8,6 +8,7 @@ export type APIConfiguration = {
8
8
  tokenProvider: string | null;
9
9
  addHTTPResponse?: boolean;
10
10
  credentials?: RequestCredentials;
11
+ cache?: RequestCache;
11
12
  };
12
13
  export type ResultTypeInterface = CoreJSType & {
13
14
  _sonic_http_response_?: Response;
@@ -19,6 +20,7 @@ export type APICall = {
19
20
  additionalHeaders: HeadersInit | undefined;
20
21
  method?: string | undefined;
21
22
  data?: unknown;
23
+ cache?: RequestCache;
22
24
  };
23
25
  declare class API {
24
26
  /**
@@ -72,6 +74,7 @@ declare class API {
72
74
  * Le endPoint pour obtenir le bearer token qui sera concaténé à l'url du service
73
75
  */
74
76
  addHTTPResponse: boolean;
77
+ cache: RequestCache;
75
78
  lastResult?: Response;
76
79
  constructor(config: APIConfiguration);
77
80
  handleResult(fetchResult: Response, lastCall: APICall): Promise<ResultTypeInterface>;
package/core/utils/api.js CHANGED
@@ -39,6 +39,7 @@ class API {
39
39
  * Le endPoint pour obtenir le bearer token qui sera concaténé à l'url du service
40
40
  */
41
41
  this.addHTTPResponse = false;
42
+ this.cache = "default";
42
43
  this.serviceURL = config.serviceURL;
43
44
  if (!this.serviceURL)
44
45
  this.serviceURL = document.location.origin;
@@ -50,6 +51,7 @@ class API {
50
51
  this.authToken = config.authToken;
51
52
  this.addHTTPResponse = config.addHTTPResponse || false;
52
53
  this.credentials = config.credentials;
54
+ this.cache = config.cache || "default";
53
55
  }
54
56
  handleResult(fetchResult, lastCall) {
55
57
  var _a;
@@ -145,7 +147,7 @@ class API {
145
147
  });
146
148
  if (!API.loadingGetPromises.has(mapKey)) {
147
149
  const promise = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
148
- const result = yield fetch(url, { headers: headers, credentials: this.credentials });
150
+ const result = yield fetch(url, { headers: headers, credentials: this.credentials, cache: this.cache });
149
151
  const handledResult = yield this.handleResult(result, lastCall);
150
152
  resolve(handledResult);
151
153
  }));
package/mixins.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare const Fetcher: <T extends new (...args: any[]) => mySubscriber.Su
18
18
  onInvalidate?: (() => void) | undefined;
19
19
  disconnectedCallback(): void;
20
20
  connectedCallback(): void;
21
- firstUpdated(): void;
21
+ handleLazyLoad(): void;
22
22
  onIntersection(entries: IntersectionObserverEntry[]): void;
23
23
  propertyMap: object;
24
24
  isConnected: boolean;
@@ -44,6 +44,7 @@ export declare const Fetcher: <T extends new (...args: any[]) => mySubscriber.Su
44
44
  requestUpdate(): void;
45
45
  getAttribute(name: string): string;
46
46
  hasAttribute(attributeName: string): boolean;
47
+ getBoundingClientRect(): DOMRect;
47
48
  };
48
49
  } & T;
49
50
  export declare const FormCheckable: <T extends new (...args: any[]) => myFormElement.FormElementInterface>(superClass: T) => {
@@ -105,6 +106,7 @@ export declare const FormCheckable: <T extends new (...args: any[]) => myFormEle
105
106
  requestUpdate(): void;
106
107
  getAttribute(name: string): string;
107
108
  hasAttribute(attributeName: string): boolean;
109
+ getBoundingClientRect(): DOMRect;
108
110
  };
109
111
  } & T;
110
112
  import * as myFormElement from "@supersoniks/concorde/core/mixins/FormElement";
@@ -165,6 +167,7 @@ export declare const FormInput: <T extends new (...args: any[]) => myFormElement
165
167
  getAttribute(name: string): string;
166
168
  hasAttribute(attributeName: string): boolean;
167
169
  disconnectedCallback(): void;
170
+ getBoundingClientRect(): DOMRect;
168
171
  };
169
172
  } & T;
170
173
  import * as mySubscriber from "@supersoniks/concorde/core/mixins/Subscriber";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supersoniks/concorde",
3
- "version": "1.1.45",
3
+ "version": "1.1.46",
4
4
  "customElements": "custom-elements.json",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -9,8 +9,10 @@
9
9
  "dependencies": {
10
10
  "@lit-labs/motion": "^1.0.1",
11
11
  "@lit-labs/observers": "^1.0.1",
12
+ "@tailwindcss/container-queries": "^0.1.1",
12
13
  "@types/prismjs": "^1.26.0",
13
14
  "chart.js": "^3.9.1",
15
+ "iframe-resizer": "^4.3.6",
14
16
  "intl": "^1.2.5",
15
17
  "jsbarcode": "^3.11.5",
16
18
  "lit": "^2.2.3",
@@ -20,6 +22,7 @@
20
22
  },
21
23
  "devDependencies": {
22
24
  "@tailwindcss/typography": "^0.5.2",
25
+ "@types/iframe-resizer": "^3.5.9",
23
26
  "@types/intl": "^1.2.0",
24
27
  "@types/jest": "^29.2.6",
25
28
  "@types/node": "^18.11.18",
@@ -268,6 +271,7 @@
268
271
  "./docs/search/search": "./docs/search/search.js",
269
272
  "./docs/search": "./docs/search/search.js",
270
273
  "./index-billetterie": "./index-billetterie.js",
274
+ "./index-customer": "./index-customer.js",
271
275
  "./index-shared": "./index-shared.js",
272
276
  "./index": "./index.js",
273
277
  "./test-utils/TestUtils": "./test-utils/TestUtils.js",