@supersoniks/concorde 3.1.3 → 3.1.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@supersoniks/concorde",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "",
@@ -1,4 +1,4 @@
1
- import {css} from "lit";
1
+ import { css } from "lit";
2
2
 
3
3
  export const passwordToggle = css`
4
4
  .password-toggle {
@@ -71,11 +71,13 @@ export const formControl = css`
71
71
 
72
72
  line-height: 1.1;
73
73
  color: var(--sc-input-c);
74
- border-radius: var(--sc-item-rounded-tl) var(--sc-item-rounded-tr) var(--sc-item-rounded-br) var(--sc-item-rounded-bl);
74
+ border-radius: var(--sc-item-rounded-tl) var(--sc-item-rounded-tr)
75
+ var(--sc-item-rounded-br) var(--sc-item-rounded-bl);
75
76
 
76
77
  font-family: var(--sc-input-ff);
77
78
  background-color: var(--sc-input-background);
78
- border: var(--sc-input-b-width) solid var(--sc-input-b-color, var(--sc-base-300, #aaa));
79
+ border: var(--sc-input-b-width) solid
80
+ var(--sc-input-b-color, var(--sc-base-300, #aaa));
79
81
  width: 100%;
80
82
  font-size: var(--sc-input-fs);
81
83
 
@@ -84,9 +86,7 @@ export const formControl = css`
84
86
  padding-left: var(--sc-input-px);
85
87
  padding-right: var(--sc-input-px);
86
88
 
87
- transition:
88
- border-color 0.15s ease-in-out,
89
- color 0.15s ease-in-out,
89
+ transition: border-color 0.15s ease-in-out, color 0.15s ease-in-out,
90
90
  box-shadow 0.15s ease-in-out;
91
91
  min-height: var(--sc-input-height);
92
92
  }
@@ -303,7 +303,8 @@ export const formControl = css`
303
303
  }
304
304
  input[type="color"]::-webkit-color-swatch {
305
305
  border: none;
306
- border-radius: var(--sc-item-rounded-tl) var(--sc-item-rounded-tr) var(--sc-item-rounded-br) var(--sc-item-rounded-bl);
306
+ border-radius: var(--sc-item-rounded-tl) var(--sc-item-rounded-tr)
307
+ var(--sc-item-rounded-br) var(--sc-item-rounded-bl);
307
308
  }
308
309
 
309
310
  /*Input Image*/
@@ -380,4 +381,10 @@ export const formControl = css`
380
381
  --sc-input-addon-bg: var(--sc-info);
381
382
  --sc-input-addon-color: var(--sc-info-content);
382
383
  }
384
+ :host([status="primary"]) {
385
+ --sc-input-b-color: var(--sc-primary);
386
+ --sc-input-c: var(--sc-primary);
387
+ --sc-input-addon-bg: var(--sc-primary);
388
+ --sc-input-addon-color: var(--sc-primary-content);
389
+ }
383
390
  `;
@@ -106,6 +106,7 @@ export class Select extends FormElement(Subscriber(LitElement)) {
106
106
  | "success"
107
107
  | "error"
108
108
  | "warning"
109
+ | "primary"
109
110
  | "info" = "default";
110
111
 
111
112
  private _options: Array<SelectOption> = [];
@@ -1,6 +1,7 @@
1
- import {html, LitElement, css} from "lit";
2
- import {customElement, queryAssignedElements} from "lit/decorators.js";
3
- import {Modal} from "@supersoniks/concorde/core/components/ui/modal/modal";
1
+ import { html, LitElement, css } from "lit";
2
+ import { customElement, queryAssignedElements } from "lit/decorators.js";
3
+ import { Modal } from "@supersoniks/concorde/core/components/ui/modal/modal";
4
+ import { HTML } from "@supersoniks/concorde/utils";
4
5
  const tagName = "sonic-modal-actions";
5
6
  @customElement(tagName)
6
7
  export class ModalActions extends LitElement {
@@ -15,14 +16,17 @@ export class ModalActions extends LitElement {
15
16
  `,
16
17
  ];
17
18
 
18
- @queryAssignedElements({selector: "sonic-button"})
19
+ @queryAssignedElements({ selector: "sonic-button" })
19
20
  buttons!: Array<HTMLElement>;
20
21
 
21
22
  firstUpdated(changedProperties: Map<string | number | symbol, unknown>) {
22
23
  this.buttons?.forEach((btn) => {
23
24
  btn.addEventListener("click", () => {
24
25
  if (btn.getAttribute("hideModal") != "false") {
25
- const parentModal = this.closest("sonic-modal") as Modal;
26
+ const parentModal = HTML.getClosestElement(
27
+ this,
28
+ "sonic-modal"
29
+ ) as Modal;
26
30
  parentModal?.hide();
27
31
  }
28
32
  });
@@ -1,9 +1,10 @@
1
- import {html, LitElement, css, nothing} from "lit";
2
- import {customElement, property, state} from "lit/decorators.js";
3
- import {unsafeHTML} from "lit/directives/unsafe-html.js";
1
+ import { html, LitElement, css, nothing } from "lit";
2
+ import { customElement, property, state } from "lit/decorators.js";
3
+ import { unsafeHTML } from "lit/directives/unsafe-html.js";
4
4
  import "@supersoniks/concorde/core/components/ui/toast/types";
5
- import {ToastStatus} from "@supersoniks/concorde/core/components/ui/toast/types";
6
- import {customScroll} from "@supersoniks/concorde/core/components/ui/_css/scroll";
5
+ import { ToastStatus } from "@supersoniks/concorde/core/components/ui/toast/types";
6
+ import { customScroll } from "@supersoniks/concorde/core/components/ui/_css/scroll";
7
+ import { HTML } from "@supersoniks/concorde/utils";
7
8
 
8
9
  const icon: Record<string, string> = {
9
10
  warning: "warning-circled-outline",
@@ -86,7 +87,8 @@ export class SonicToastItem extends LitElement {
86
87
  }
87
88
 
88
89
  ::slotted(:is(p, ul, ol, hr, h1, h2, h3, h4, h5, h6):last-child),
89
- .sonic-toast-text > :is(p, ul, ol, hr, h1, h2, h3, h4, h5, h6):last-child {
90
+ .sonic-toast-text
91
+ > :is(p, ul, ol, hr, h1, h2, h3, h4, h5, h6):last-child {
90
92
  margin-bottom: 0 !important;
91
93
  }
92
94
 
@@ -197,14 +199,14 @@ export class SonicToastItem extends LitElement {
197
199
  `,
198
200
  ];
199
201
 
200
- @property({type: String}) title = "";
201
- @property({type: String}) id = "";
202
- @property({type: String}) text = "";
203
- @property({type: String}) status: ToastStatus = "";
204
- @property({type: Boolean}) ghost = false;
205
- @property({type: Boolean}) preserve = false;
206
- @property({type: Boolean}) dismissForever = false;
207
- @property({type: String}) maxHeight = "10rem";
202
+ @property({ type: String }) title = "";
203
+ @property({ type: String }) id = "";
204
+ @property({ type: String }) text = "";
205
+ @property({ type: String }) status: ToastStatus = "";
206
+ @property({ type: Boolean }) ghost = false;
207
+ @property({ type: Boolean }) preserve = false;
208
+ @property({ type: Boolean }) dismissForever = false;
209
+ @property({ type: String }) maxHeight = "10rem";
208
210
  @state() visible = true;
209
211
 
210
212
  // @queryAssignedElements({flatten: true, slot: main"})
@@ -224,15 +226,32 @@ export class SonicToastItem extends LitElement {
224
226
  return nothing;
225
227
  }
226
228
 
227
- return html`<div class="sonic-toast ${this.status} ${this.ghost ? "ghost" : ""}">
228
- <button aria-label="Close" class="sonic-toast-close" @click=${() => this.hide()}>
229
+ return html`<div
230
+ class="sonic-toast ${this.status} ${this.ghost ? "ghost" : ""}"
231
+ >
232
+ <button
233
+ aria-label="Close"
234
+ class="sonic-toast-close"
235
+ @click=${() => this.hide()}
236
+ >
229
237
  <sonic-icon name="cancel" size="lg"></sonic-icon>
230
238
  </button>
231
- <div class="sonic-toast-content custom-scroll" style="max-height: ${this.maxHeight} ;">
232
- ${this.status && html`<sonic-icon name=${icon[this.status]} class="sonic-toast-icon" size="2xl"></sonic-icon>`}
239
+ <div
240
+ class="sonic-toast-content custom-scroll"
241
+ style="max-height: ${this.maxHeight} ;"
242
+ >
243
+ ${this.status &&
244
+ html`<sonic-icon
245
+ name=${icon[this.status]}
246
+ class="sonic-toast-icon"
247
+ size="2xl"
248
+ ></sonic-icon>`}
233
249
 
234
250
  <div class="sonic-toast-text">
235
- ${this.title ? html`<div class="sonic-toast-title">${this.title}</div>` : ""} ${this.text ? unsafeHTML(this.text) : ""}
251
+ ${this.title
252
+ ? html`<div class="sonic-toast-title">${this.title}</div>`
253
+ : ""}
254
+ ${this.text ? unsafeHTML(this.text) : ""}
236
255
  <slot></slot>
237
256
  </div>
238
257
 
@@ -242,7 +261,7 @@ export class SonicToastItem extends LitElement {
242
261
  }
243
262
 
244
263
  hide() {
245
- if (!this.closest("sonic-toast")) {
264
+ if (!HTML.getClosestElement(this, "sonic-toast")) {
246
265
  this.visible = false;
247
266
  }
248
267
 
@@ -251,9 +270,12 @@ export class SonicToastItem extends LitElement {
251
270
  const dismissed = localStorage.getItem("sonic-toast-dismissed") || "{}";
252
271
  const dismissedObj = JSON.parse(dismissed);
253
272
  dismissedObj[this.id] = true;
254
- localStorage.setItem("sonic-toast-dismissed", JSON.stringify(dismissedObj));
273
+ localStorage.setItem(
274
+ "sonic-toast-dismissed",
275
+ JSON.stringify(dismissedObj)
276
+ );
255
277
  }
256
- this.dispatchEvent(new CustomEvent("hide", {bubbles: true}));
278
+ this.dispatchEvent(new CustomEvent("hide", { bubbles: true }));
257
279
  }
258
280
 
259
281
  show() {
@@ -2,8 +2,8 @@
2
2
  /* eslint no-async-promise-executor: 0 */ // --> OFF
3
3
  import HTML from "@supersoniks/concorde/core/utils/HTML";
4
4
  import Objects from "@supersoniks/concorde/core/utils/Objects";
5
- import {CoreJSType} from "@supersoniks/concorde/core/_types/types";
6
- import {PublisherManager} from "./PublisherProxy";
5
+ import { CoreJSType } from "@supersoniks/concorde/core/_types/types";
6
+ import { PublisherManager } from "./PublisherProxy";
7
7
 
8
8
  export type APIConfiguration = {
9
9
  serviceURL: string | null;
@@ -19,7 +19,10 @@ export type APIConfiguration = {
19
19
  cache?: RequestCache;
20
20
  };
21
21
  export type CallState = "loading" | "done" | "error" | undefined;
22
- export type ResultTypeInterface = CoreJSType & {_sonic_http_response_?: Response; text?: string};
22
+ export type ResultTypeInterface = CoreJSType & {
23
+ _sonic_http_response_?: Response;
24
+ text?: string;
25
+ };
23
26
  export type APICall = {
24
27
  apiMethod: "get" | "send" | "submitFormData";
25
28
  path: string;
@@ -66,7 +69,9 @@ class API {
66
69
  }
67
70
  get token() {
68
71
  // si le token est marqué invalide, on utilise utilise la dernière version valide connue du token pour ce serviceURL
69
- return API.invalidTokens.includes(this._token) ? API.tokens.get(this.serviceURL) : this._token;
72
+ return API.invalidTokens.includes(this._token)
73
+ ? API.tokens.get(this.serviceURL)
74
+ : this._token;
70
75
  }
71
76
  /**
72
77
  * Le endPoint pour obtenir le bearer token qui sera concaténé à l'url du service
@@ -135,7 +140,10 @@ class API {
135
140
  this.credentials = config.credentials;
136
141
  this.cache = config.cache || "default";
137
142
  }
138
- async handleResult(fetchResult: Response, lastCall: APICall): Promise<ResultTypeInterface> {
143
+ async handleResult(
144
+ fetchResult: Response,
145
+ lastCall: APICall
146
+ ): Promise<ResultTypeInterface> {
139
147
  API.firstCallDoneFlags.set(this.serviceURL, "done");
140
148
  this.lastResult = fetchResult;
141
149
  const contentType = fetchResult.headers.get("content-type")?.toLowerCase();
@@ -144,7 +152,7 @@ class API {
144
152
  let result: ResultTypeInterface = {};
145
153
  if (!contentType || contentType.indexOf("text/") == 0) {
146
154
  const str = await fetchResult.text();
147
- result = {text: str} as typeof result;
155
+ result = { text: str } as typeof result;
148
156
  } else {
149
157
  try {
150
158
  result = await fetchResult.json();
@@ -159,9 +167,17 @@ class API {
159
167
  if (httpCode === 498 && !API.failledTokenUpdates.has(this.serviceURL)) {
160
168
  this.handleInvalidToken(this.token);
161
169
  if (lastCall.apiMethod === "get") {
162
- result = await this[lastCall.apiMethod](lastCall.path, lastCall.additionalHeaders);
170
+ result = await this[lastCall.apiMethod](
171
+ lastCall.path,
172
+ lastCall.additionalHeaders
173
+ );
163
174
  } else {
164
- result = await this[lastCall.apiMethod](lastCall.path, lastCall.data, lastCall.method, lastCall.additionalHeaders);
175
+ result = await this[lastCall.apiMethod](
176
+ lastCall.path,
177
+ lastCall.data,
178
+ lastCall.method,
179
+ lastCall.additionalHeaders
180
+ );
165
181
  }
166
182
  }
167
183
 
@@ -182,7 +198,11 @@ class API {
182
198
  let headers = {};
183
199
  if (this.userName && this.password) {
184
200
  headers = {
185
- Authorization: "Basic " + window.btoa(unescape(encodeURIComponent(this.userName + ":" + this.password))),
201
+ Authorization:
202
+ "Basic " +
203
+ window.btoa(
204
+ unescape(encodeURIComponent(this.userName + ":" + this.password))
205
+ ),
186
206
  };
187
207
  } else if (this.authToken) {
188
208
  headers = {
@@ -192,10 +212,15 @@ class API {
192
212
 
193
213
  const serviceURL = new URL(this.serviceURL as string);
194
214
  const serviceHost = serviceURL.protocol + "//" + serviceURL.host;
195
- const result = await fetch(this.computeURL(this.tokenProvider as string, {serviceHost: serviceHost}), {
196
- headers: headers,
197
- credentials: this.credentials,
198
- });
215
+ const result = await fetch(
216
+ this.computeURL(this.tokenProvider as string, {
217
+ serviceHost: serviceHost,
218
+ }),
219
+ {
220
+ headers: headers,
221
+ credentials: this.credentials,
222
+ }
223
+ );
199
224
 
200
225
  try {
201
226
  const json = await result.json();
@@ -221,7 +246,6 @@ class API {
221
246
  async localGet<T>(dataProvider: string, searchString: string) {
222
247
  const publisher = PublisherManager.get(dataProvider);
223
248
 
224
- console.log(publisher);
225
249
  const searchParams = new URLSearchParams(searchString.split("?")[1] || "");
226
250
  const dataObject = publisher.get();
227
251
  let data = [];
@@ -248,18 +272,21 @@ class API {
248
272
  searchParams.delete("limit");
249
273
  searchParams.delete("offset");
250
274
  }
251
- if (searchParams.size === 0) return data.slice(offset, offset + limit) as T & ResultTypeInterface;
275
+ if (searchParams.size === 0)
276
+ return data.slice(offset, offset + limit) as T & ResultTypeInterface;
252
277
  for (const [key, value] of searchParams.entries()) {
253
278
  const values = value.split(",").map((s) => s.trim());
254
279
  for (const v of values) {
255
280
  for (const item of data) {
256
281
  //si l'item est une valeur primitive on regarde si vaue correspond à item simplement
257
282
  if (typeof item !== "object") {
258
- if (!isNaN(+value)) {
259
- if (item == value) {
283
+ if (!isNaN(+item)) {
284
+ if (item === value) {
260
285
  result.push(item);
261
286
  }
262
- } else if (item.toString().includes(value)) {
287
+ } else if (
288
+ item.toString().toLowerCase().includes(value.toLowerCase())
289
+ ) {
263
290
  result.push(item);
264
291
  }
265
292
  } else {
@@ -269,12 +296,14 @@ class API {
269
296
  if (!record[key]) continue;
270
297
 
271
298
  //si la valeur est un nombre, on compare les valeurs directement
272
- if (!isNaN(+v)) {
273
- if (record[key] == v) {
299
+ if (!isNaN(+(record[key] as string))) {
300
+ if (record[key] === v) {
274
301
  result.push(item);
275
302
  }
276
303
  } else {
277
- if (record[key]?.toString().toLowerCase().includes(v.toLowerCase())) {
304
+ if (
305
+ record[key]?.toString().toLowerCase().includes(v.toLowerCase())
306
+ ) {
278
307
  result.push(item);
279
308
  }
280
309
  }
@@ -295,7 +324,11 @@ class API {
295
324
  resolve(true);
296
325
  } else {
297
326
  const loop = () => {
298
- if (![undefined, "loading"].includes(API.firstCallDoneFlags.get(this.serviceURL))) {
327
+ if (
328
+ ![undefined, "loading"].includes(
329
+ API.firstCallDoneFlags.get(this.serviceURL)
330
+ )
331
+ ) {
299
332
  resolve(true);
300
333
  } else {
301
334
  window.requestAnimationFrame(loop);
@@ -331,7 +364,11 @@ class API {
331
364
  if (!API.loadingGetPromises.has(mapKey)) {
332
365
  const promise = new Promise(async (resolve) => {
333
366
  try {
334
- const result = await fetch(url, {headers: headers, credentials: this.credentials, cache: this.cache});
367
+ const result = await fetch(url, {
368
+ headers: headers,
369
+ credentials: this.credentials,
370
+ cache: this.cache,
371
+ });
335
372
  const handledResult = await this.handleResult(result, lastCall);
336
373
  resolve(handledResult);
337
374
  } catch (e) {
@@ -380,7 +417,12 @@ class API {
380
417
  /*
381
418
  * Envoie des données au endPoint passé en paramètre. par défaut en POST
382
419
  */
383
- async send<T, SendType = CoreJSType>(path: string, data: SendType, method = "POST", additionalHeaders?: HeadersInit) {
420
+ async send<T, SendType = CoreJSType>(
421
+ path: string,
422
+ data: SendType,
423
+ method = "POST",
424
+ additionalHeaders?: HeadersInit
425
+ ) {
384
426
  const lastCall: APICall = {
385
427
  apiMethod: "send",
386
428
  path: path,
@@ -398,13 +440,19 @@ class API {
398
440
  method: method,
399
441
  body: JSON.stringify(data),
400
442
  });
401
- return (await this.handleResult(result, lastCall)) as T & ResultTypeInterface;
443
+ return (await this.handleResult(result, lastCall)) as T &
444
+ ResultTypeInterface;
402
445
  }
403
446
 
404
447
  /**
405
448
  * Agit comme une soumission de formulaire, mais attends un json en réponse
406
449
  */
407
- async submitFormData<T, SendType = CoreJSType>(path: string, data: SendType, method = "POST", additionalHeaders?: HeadersInit) {
450
+ async submitFormData<T, SendType = CoreJSType>(
451
+ path: string,
452
+ data: SendType,
453
+ method = "POST",
454
+ additionalHeaders?: HeadersInit
455
+ ) {
408
456
  const lastCall: APICall = {
409
457
  apiMethod: "submitFormData",
410
458
  path: path,
@@ -415,7 +463,7 @@ class API {
415
463
  const headers = await this.createHeaders(additionalHeaders);
416
464
  headers["Accept"] = "application/json";
417
465
  const formData = new FormData();
418
- const dynamicData = data as unknown as {[property: string]: string};
466
+ const dynamicData = data as unknown as { [property: string]: string };
419
467
  for (const z in dynamicData) formData.set(z, dynamicData[z]);
420
468
  const result = await fetch(this.computeURL(path), {
421
469
  headers: headers,
@@ -423,33 +471,50 @@ class API {
423
471
  method: method,
424
472
  body: formData,
425
473
  });
426
- return (await this.handleResult(result, lastCall)) as T & ResultTypeInterface;
474
+ return (await this.handleResult(result, lastCall)) as T &
475
+ ResultTypeInterface;
427
476
  }
428
477
 
429
478
  /**
430
479
  * Appel send en utilisant le méthode PUT
431
480
  */
432
- async put<T, SendType = CoreJSType>(path: string, data: SendType, additionalHeaders?: HeadersInit) {
481
+ async put<T, SendType = CoreJSType>(
482
+ path: string,
483
+ data: SendType,
484
+ additionalHeaders?: HeadersInit
485
+ ) {
433
486
  return this.send<T, SendType>(path, data, "PUT", additionalHeaders);
434
487
  }
435
488
 
436
489
  /**
437
490
  * Appel send en utilisant le méthode POST
438
491
  */
439
- async post<T, SendType = CoreJSType>(path: string, data: SendType, additionalHeaders?: HeadersInit) {
492
+ async post<T, SendType = CoreJSType>(
493
+ path: string,
494
+ data: SendType,
495
+ additionalHeaders?: HeadersInit
496
+ ) {
440
497
  return this.send<T, SendType>(path, data, "POST", additionalHeaders);
441
498
  }
442
499
  /**
443
500
  * Appel send en utilisant le méthode PATCH
444
501
  */
445
- async patch<T, SendType = CoreJSType>(path: string, data: SendType, additionalHeaders?: HeadersInit) {
502
+ async patch<T, SendType = CoreJSType>(
503
+ path: string,
504
+ data: SendType,
505
+ additionalHeaders?: HeadersInit
506
+ ) {
446
507
  return this.send<T, SendType>(path, data, "PATCH", additionalHeaders);
447
508
  }
448
509
 
449
510
  /**
450
511
  * Appel send en utilisant le méthode delete
451
512
  */
452
- async delete<T, SendType = CoreJSType>(path: string, data: SendType, additionalHeaders?: HeadersInit) {
513
+ async delete<T, SendType = CoreJSType>(
514
+ path: string,
515
+ data: SendType,
516
+ additionalHeaders?: HeadersInit
517
+ ) {
453
518
  return this.send<T, SendType>(path, data, "delete", additionalHeaders);
454
519
  }
455
520
  }