@supersoniks/concorde 3.0.0 → 3.0.2
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/index.html +124 -36
- package/package.json +16 -5
- package/postcss.config.cjs +6 -0
- package/public/css/docs.css +0 -0
- package/public/img/concorde-logo.svg +1 -0
- package/public/img/concorde.png +0 -0
- package/public/img/concorde_def.png +0 -0
- package/public/svg/regular/plane.svg +1 -0
- package/public/svg/solid/plane.svg +1 -0
- package/scripts/create-search.js +92 -0
- package/scripts/post-build-docs.js +48 -0
- package/scripts/post-build.mjs +14 -0
- package/src/core/components/functional/queue/queue.ts +72 -28
- package/src/core/components/functional/router/router.ts +35 -14
- package/src/core/components/functional/states/states.ts +33 -14
- package/src/core/directives/Wording.ts +68 -26
- package/src/core/mixins/Fetcher.ts +83 -32
- package/src/core/utils/Electron.ts +4 -1
- package/src/docs/code.ts +4 -3
- package/src/docs/example/users.ts +2 -2
- package/src/docs/search/docs-search.json +0 -30
- package/src/docs/search/search.ts +2 -2
- package/src/docs/tailwind/css/tailwind.css +25 -0
- package/src/docs/tailwind/index.ts +6 -0
- package/src/mixins.ts +1 -1
- package/tailwind.config.js +186 -0
- package/vite/config.js +22 -22
- package/vite.config.mts +15 -13
- package/src/core/components/ui/theme/css/tailwind.css +0 -3
- /package/scripts/{prebuild.mjs → pre-build.mjs} +0 -0
- /package/src/{core/components/ui/theme → docs/tailwind}/css/tailwind.d.ts +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {html, LitElement} from "lit";
|
|
2
|
-
import {customElement, property} from "lit/decorators.js";
|
|
1
|
+
import { html, LitElement } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
3
|
import Subscriber from "@supersoniks/concorde/core/mixins/Subscriber";
|
|
4
|
-
import {templateContent} from "lit/directives/template-content.js";
|
|
4
|
+
import { templateContent } from "lit/directives/template-content.js";
|
|
5
5
|
import LocationHandler from "@supersoniks/concorde/core/utils/LocationHandler";
|
|
6
|
-
import {repeat} from "lit/directives/repeat.js";
|
|
7
|
-
import UrlPattern from "url-pattern";
|
|
6
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
7
|
+
import UrlPattern from "@supersoniks/concorde/core/utils/url-pattern";
|
|
8
8
|
import TemplatesContainer from "@supersoniks/concorde/core/mixins/TemplatesContainer";
|
|
9
9
|
const tagName = "sonic-router";
|
|
10
10
|
/**
|
|
@@ -26,7 +26,7 @@ const tagName = "sonic-router";
|
|
|
26
26
|
export class SonicRouter extends Subscriber(TemplatesContainer(LitElement)) {
|
|
27
27
|
templateValueAttribute = "data-route";
|
|
28
28
|
|
|
29
|
-
@property({type: String}) fallBackRoute?: string;
|
|
29
|
+
@property({ type: String }) fallBackRoute?: string;
|
|
30
30
|
|
|
31
31
|
connectedCallback() {
|
|
32
32
|
this.noShadowDom = "";
|
|
@@ -37,7 +37,10 @@ export class SonicRouter extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
37
37
|
LocationHandler.offChange(this);
|
|
38
38
|
super.disconnectedCallback();
|
|
39
39
|
}
|
|
40
|
-
private _location: string = document.location.href.replace(
|
|
40
|
+
private _location: string = document.location.href.replace(
|
|
41
|
+
document.location.origin,
|
|
42
|
+
""
|
|
43
|
+
);
|
|
41
44
|
|
|
42
45
|
@property() set location(value: string) {
|
|
43
46
|
this._location = value;
|
|
@@ -61,7 +64,10 @@ export class SonicRouter extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
61
64
|
templates.push(t);
|
|
62
65
|
}
|
|
63
66
|
} catch (e) {
|
|
64
|
-
if (
|
|
67
|
+
if (
|
|
68
|
+
this.location.indexOf(path.replace(document.location.origin, "")) !=
|
|
69
|
+
-1
|
|
70
|
+
) {
|
|
65
71
|
templates.push(t);
|
|
66
72
|
}
|
|
67
73
|
}
|
|
@@ -71,7 +77,9 @@ export class SonicRouter extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
71
77
|
if (this.fallBackRoute && this.isConnected) {
|
|
72
78
|
document.location.href = this.fallBackRoute;
|
|
73
79
|
}
|
|
74
|
-
const fallback = this.templatePartsList.find((t) =>
|
|
80
|
+
const fallback = this.templatePartsList.find((t) =>
|
|
81
|
+
t.hasAttribute("data-fallback")
|
|
82
|
+
);
|
|
75
83
|
if (fallback) {
|
|
76
84
|
templates.push(fallback);
|
|
77
85
|
}
|
|
@@ -87,19 +95,32 @@ export class SonicRouter extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
87
95
|
if (template.title) document.title = template.title;
|
|
88
96
|
if (template.hasAttribute("dataProviderExpression")) {
|
|
89
97
|
let dataProvider = "";
|
|
90
|
-
const dataProviderExpression =
|
|
98
|
+
const dataProviderExpression =
|
|
99
|
+
template.getAttribute("dataProviderExpression") || "";
|
|
91
100
|
if (template.getAttribute("mode") == "patternMatching") {
|
|
92
|
-
const matcher = new UrlPattern(
|
|
101
|
+
const matcher = new UrlPattern(
|
|
102
|
+
"(/)*" +
|
|
103
|
+
(template.getAttribute(this.templateValueAttribute) || "") +
|
|
104
|
+
"*"
|
|
105
|
+
);
|
|
93
106
|
const filler = new UrlPattern(dataProviderExpression);
|
|
94
107
|
dataProvider = filler.stringify(matcher.match(this.location));
|
|
95
108
|
} else {
|
|
96
|
-
const regexp = new RegExp(
|
|
109
|
+
const regexp = new RegExp(
|
|
110
|
+
template.getAttribute(this.templateValueAttribute) || ""
|
|
111
|
+
);
|
|
97
112
|
const match = (this.location + "").match(regexp);
|
|
98
113
|
if (match) {
|
|
99
|
-
dataProvider =
|
|
114
|
+
dataProvider =
|
|
115
|
+
match.shift()?.replace(regexp, dataProviderExpression) || "";
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
|
-
return html`<div
|
|
118
|
+
return html`<div
|
|
119
|
+
style="display:contents"
|
|
120
|
+
dataProvider="${dataProvider}"
|
|
121
|
+
>
|
|
122
|
+
${templateContent(template)}
|
|
123
|
+
</div>`;
|
|
103
124
|
}
|
|
104
125
|
return templateContent(template);
|
|
105
126
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {LitElement, html} from "lit";
|
|
2
|
-
import {customElement, property} from "lit/decorators.js";
|
|
1
|
+
import { LitElement, html } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
3
|
import Subscriber from "@supersoniks/concorde/core/mixins/Subscriber";
|
|
4
|
-
import {templateContent} from "lit/directives/template-content.js";
|
|
5
|
-
import {repeat} from "lit/directives/repeat.js";
|
|
4
|
+
import { templateContent } from "lit/directives/template-content.js";
|
|
5
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
6
6
|
import Objects from "@supersoniks/concorde/core/utils/Objects";
|
|
7
|
-
import UrlPattern from "url-pattern";
|
|
7
|
+
import UrlPattern from "@supersoniks/concorde/core/utils/url-pattern";
|
|
8
8
|
import TemplatesContainer from "@supersoniks/concorde/core/mixins/TemplatesContainer";
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import {
|
|
10
|
+
PublisherInterface,
|
|
11
|
+
TypeAndRecordOfType,
|
|
12
|
+
} from "@supersoniks/concorde/core/_types/types";
|
|
13
|
+
type UrlPatternExtended = { names: string[] } & UrlPattern;
|
|
11
14
|
|
|
12
15
|
const tagName = "sonic-states";
|
|
13
16
|
/**
|
|
@@ -29,7 +32,7 @@ const tagName = "sonic-states";
|
|
|
29
32
|
@customElement(tagName)
|
|
30
33
|
export class SonicStates extends Subscriber(TemplatesContainer(LitElement)) {
|
|
31
34
|
@property() state = "";
|
|
32
|
-
@property({type: Boolean, reflect: true}) inverted = false;
|
|
35
|
+
@property({ type: Boolean, reflect: true }) inverted = false;
|
|
33
36
|
statePath = "";
|
|
34
37
|
onAssign = (value: string) => {
|
|
35
38
|
this.state = value;
|
|
@@ -46,7 +49,9 @@ export class SonicStates extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
46
49
|
this.statePublisher = this.publisher;
|
|
47
50
|
const split = this.statePath.split(".");
|
|
48
51
|
for (const s of split) {
|
|
49
|
-
this.statePublisher = this.statePublisher[
|
|
52
|
+
this.statePublisher = this.statePublisher[
|
|
53
|
+
s
|
|
54
|
+
] as typeof this.statePublisher;
|
|
50
55
|
}
|
|
51
56
|
this.statePublisher.onAssign(this.onAssign);
|
|
52
57
|
}
|
|
@@ -58,7 +63,10 @@ export class SonicStates extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
58
63
|
render() {
|
|
59
64
|
const templates = [];
|
|
60
65
|
let state = this.state;
|
|
61
|
-
if (
|
|
66
|
+
if (
|
|
67
|
+
(!Array.isArray(state) && Objects.isObject(state)) ||
|
|
68
|
+
state === undefined
|
|
69
|
+
) {
|
|
62
70
|
state = "";
|
|
63
71
|
}
|
|
64
72
|
for (const t of this.templatePartsList) {
|
|
@@ -91,10 +99,14 @@ export class SonicStates extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
91
99
|
(template) => {
|
|
92
100
|
if (template.title) document.title = template.title;
|
|
93
101
|
if (template.hasAttribute("dataProviderExpression")) {
|
|
94
|
-
const dataProviderExpression = template.getAttribute(
|
|
102
|
+
const dataProviderExpression = template.getAttribute(
|
|
103
|
+
"dataProviderExpression"
|
|
104
|
+
) as string;
|
|
95
105
|
let dataProvider = "";
|
|
96
106
|
let stateToMatch = state;
|
|
97
|
-
let path: string = template.getAttribute(
|
|
107
|
+
let path: string = template.getAttribute(
|
|
108
|
+
this.templateValueAttribute
|
|
109
|
+
) as string;
|
|
98
110
|
if (this.inverted) {
|
|
99
111
|
stateToMatch = path;
|
|
100
112
|
path = state;
|
|
@@ -109,10 +121,17 @@ export class SonicStates extends Subscriber(TemplatesContainer(LitElement)) {
|
|
|
109
121
|
|
|
110
122
|
const match = (stateToMatch + "").match(regexp);
|
|
111
123
|
if (match) {
|
|
112
|
-
dataProvider = match
|
|
124
|
+
dataProvider = match
|
|
125
|
+
.shift()
|
|
126
|
+
?.replace(regexp, dataProviderExpression) as string;
|
|
113
127
|
}
|
|
114
128
|
}
|
|
115
|
-
return html`<div
|
|
129
|
+
return html`<div
|
|
130
|
+
style="display:contents"
|
|
131
|
+
dataProvider="${dataProvider}"
|
|
132
|
+
>
|
|
133
|
+
${templateContent(template)}
|
|
134
|
+
</div>`;
|
|
116
135
|
}
|
|
117
136
|
return templateContent(template);
|
|
118
137
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {AsyncDirective} from "lit/async-directive.js";
|
|
2
|
-
import {directive} from "lit/directive.js";
|
|
3
|
-
import {PublisherManager} from "@supersoniks/concorde/core/utils/PublisherProxy";
|
|
4
|
-
import {dp} from "@supersoniks/concorde/core/directives/DataProvider";
|
|
5
|
-
import {noChange} from "lit";
|
|
6
|
-
import {APIConfiguration} from "@supersoniks/concorde/core/utils/api";
|
|
1
|
+
import { AsyncDirective } from "lit/async-directive.js";
|
|
2
|
+
import { directive } from "lit/directive.js";
|
|
3
|
+
import { PublisherManager } from "@supersoniks/concorde/core/utils/PublisherProxy";
|
|
4
|
+
import { dp } from "@supersoniks/concorde/core/directives/DataProvider";
|
|
5
|
+
import { noChange } from "lit";
|
|
6
|
+
import { APIConfiguration } from "@supersoniks/concorde/core/utils/api";
|
|
7
7
|
import API from "@supersoniks/concorde/core/utils/api";
|
|
8
8
|
import Objects from "../utils/Objects";
|
|
9
|
-
import HTML, {SearchableDomElement} from "../utils/HTML";
|
|
10
|
-
import {unsafeHTML} from "lit/directives/unsafe-html.js";
|
|
11
|
-
type ApiCallKey = {
|
|
9
|
+
import HTML, { SearchableDomElement } from "../utils/HTML";
|
|
10
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
11
|
+
type ApiCallKey = {
|
|
12
|
+
apiConfiguration: APIConfiguration;
|
|
13
|
+
wordingProvider: string | null;
|
|
14
|
+
wordingVersionProvider: string | null;
|
|
15
|
+
};
|
|
12
16
|
type ApiCallValue = {
|
|
13
17
|
api: API;
|
|
14
18
|
keysToTranslate: Set<string>;
|
|
@@ -22,9 +26,19 @@ const apiCalls: Map<ApiCallKey, ApiCallValue> = new Map();
|
|
|
22
26
|
const getApiCall = (node: SearchableDomElement | null) => {
|
|
23
27
|
if (!node) return null;
|
|
24
28
|
const configuration = HTML.getApiConfiguration(node);
|
|
25
|
-
const wordingProvider = HTML.getAncestorAttributeValue(
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const wordingProvider = HTML.getAncestorAttributeValue(
|
|
30
|
+
node,
|
|
31
|
+
"wordingProvider"
|
|
32
|
+
);
|
|
33
|
+
const wordingVersionProvider = HTML.getAncestorAttributeValue(
|
|
34
|
+
node,
|
|
35
|
+
"wordingVersionProvider"
|
|
36
|
+
);
|
|
37
|
+
const searchedKey = {
|
|
38
|
+
apiConfiguration: configuration,
|
|
39
|
+
wordingProvider: wordingProvider,
|
|
40
|
+
wordingVersionProvider: wordingVersionProvider,
|
|
41
|
+
};
|
|
28
42
|
//touver une api avec la même configuration en comparant les avec l'utilitaire Objects deepEqual
|
|
29
43
|
let apiCall = null;
|
|
30
44
|
for (const [key, value] of apiCalls) {
|
|
@@ -55,7 +69,9 @@ export const isWordingReady = (key: string) => {
|
|
|
55
69
|
return value !== loadingString && value != null;
|
|
56
70
|
};
|
|
57
71
|
export default class WordingDirective extends AsyncDirective {
|
|
58
|
-
static publisher = PublisherManager.get("sonic-wording", {
|
|
72
|
+
static publisher = PublisherManager.get("sonic-wording", {
|
|
73
|
+
localStorageMode: "enabled",
|
|
74
|
+
});
|
|
59
75
|
unsubscribe(): void {
|
|
60
76
|
WordingDirective.publisher["wording_" + this.key].offAssign(this.onAssign);
|
|
61
77
|
}
|
|
@@ -82,7 +98,12 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
82
98
|
}
|
|
83
99
|
|
|
84
100
|
static firstCall = true;
|
|
85
|
-
static async callApi(
|
|
101
|
+
static async callApi(
|
|
102
|
+
node: SearchableDomElement | null,
|
|
103
|
+
key: string,
|
|
104
|
+
relaunch = true,
|
|
105
|
+
usedApiCall?: ApiCallValue
|
|
106
|
+
) {
|
|
86
107
|
await PublisherManager.getInstance().isLocalStrorageReady;
|
|
87
108
|
|
|
88
109
|
if (WordingDirective.firstCall) {
|
|
@@ -97,13 +118,19 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
97
118
|
}
|
|
98
119
|
|
|
99
120
|
if (node) {
|
|
100
|
-
const wordingVersionProvider = HTML.getAncestorAttributeValue(
|
|
121
|
+
const wordingVersionProvider = HTML.getAncestorAttributeValue(
|
|
122
|
+
node,
|
|
123
|
+
"wordingVersionProvider"
|
|
124
|
+
);
|
|
101
125
|
if (wordingVersionProvider) {
|
|
102
|
-
dp(wordingVersionProvider).onAssign(
|
|
126
|
+
dp(wordingVersionProvider).onAssign(
|
|
127
|
+
WordingDirective.handleVersionProvider(node)
|
|
128
|
+
);
|
|
103
129
|
}
|
|
104
130
|
}
|
|
105
131
|
|
|
106
|
-
let hasWordingForKey =
|
|
132
|
+
let hasWordingForKey =
|
|
133
|
+
WordingDirective.publisher.get()["wording_" + key] != null;
|
|
107
134
|
const apiCall = usedApiCall || getApiCall(node);
|
|
108
135
|
if (!apiCall) return;
|
|
109
136
|
if (hasWordingForKey && key !== "") {
|
|
@@ -126,7 +153,8 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
126
153
|
//
|
|
127
154
|
const api = apiCall.api;
|
|
128
155
|
window.queueMicrotask(async () => {
|
|
129
|
-
hasWordingForKey =
|
|
156
|
+
hasWordingForKey =
|
|
157
|
+
WordingDirective.publisher["wording_" + key].get() != null;
|
|
130
158
|
if (!hasWordingForKey && key !== "") {
|
|
131
159
|
apiCall.keysToTranslate.add(key);
|
|
132
160
|
WordingDirective.publisher["wording_" + key] = loadingString;
|
|
@@ -136,9 +164,15 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
136
164
|
if (!wordings.length) return;
|
|
137
165
|
const splittedUrl = wordingProvider.split("?");
|
|
138
166
|
const locationURL = splittedUrl.shift();
|
|
139
|
-
const queryString =
|
|
167
|
+
const queryString =
|
|
168
|
+
(splittedUrl.length > 0 ? splittedUrl.join("?") + "&" : "") +
|
|
169
|
+
"labels[]=" +
|
|
170
|
+
wordings.join("&labels[]=");
|
|
140
171
|
const calledURL = locationURL + "?" + queryString;
|
|
141
|
-
apiCall.translatedKeys = new Set([
|
|
172
|
+
apiCall.translatedKeys = new Set([
|
|
173
|
+
...apiCall.translatedKeys,
|
|
174
|
+
...apiCall.keysToTranslate,
|
|
175
|
+
]);
|
|
142
176
|
apiCall.keysToTranslate.clear();
|
|
143
177
|
const result = (await api.get(calledURL)) as Record<string, string>;
|
|
144
178
|
for (const key in result) {
|
|
@@ -147,7 +181,8 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
147
181
|
});
|
|
148
182
|
}
|
|
149
183
|
|
|
150
|
-
static versionProviderHandlers: Map<ApiCallValue, (v: number) => void> =
|
|
184
|
+
static versionProviderHandlers: Map<ApiCallValue, (v: number) => void> =
|
|
185
|
+
new Map();
|
|
151
186
|
//check if the wording version has changed
|
|
152
187
|
static handleVersionProvider(node: SearchableDomElement) {
|
|
153
188
|
const apiCall = getApiCall(node);
|
|
@@ -160,20 +195,24 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
160
195
|
const wordingVersionProvider = apiCall.wordingVersionProvider;
|
|
161
196
|
if (!wordingVersionProvider) return;
|
|
162
197
|
//
|
|
163
|
-
const currentVersions: {serviceURL: string | null; version: number}[] =
|
|
198
|
+
const currentVersions: { serviceURL: string | null; version: number }[] =
|
|
199
|
+
WordingDirective.publisher.get().__wording_versions__ ?? [];
|
|
164
200
|
|
|
165
201
|
if (version == null) return;
|
|
166
|
-
const currentVersionData = currentVersions.find(
|
|
202
|
+
const currentVersionData = currentVersions.find(
|
|
203
|
+
(v) => v.serviceURL === apiCall.api.serviceURL
|
|
204
|
+
) || {
|
|
167
205
|
serviceURL: apiCall.api.serviceURL,
|
|
168
206
|
version: 0,
|
|
169
207
|
};
|
|
170
|
-
if (!currentVersions.includes(currentVersionData))
|
|
208
|
+
if (!currentVersions.includes(currentVersionData))
|
|
209
|
+
currentVersions.push(currentVersionData);
|
|
171
210
|
if (version === currentVersionData.version) {
|
|
172
211
|
return;
|
|
173
212
|
}
|
|
174
213
|
|
|
175
214
|
currentVersionData.version = version;
|
|
176
|
-
WordingDirective.publisher.set({__wording_versions__: currentVersions});
|
|
215
|
+
WordingDirective.publisher.set({ __wording_versions__: currentVersions });
|
|
177
216
|
for (const apiCall of apiCalls.values()) {
|
|
178
217
|
apiCall.keysToTranslate = new Set(apiCall.translatedKeys);
|
|
179
218
|
if (apiCall.keysToTranslate.size > 0) {
|
|
@@ -181,7 +220,10 @@ export default class WordingDirective extends AsyncDirective {
|
|
|
181
220
|
}
|
|
182
221
|
}
|
|
183
222
|
};
|
|
184
|
-
WordingDirective.versionProviderHandlers.set(
|
|
223
|
+
WordingDirective.versionProviderHandlers.set(
|
|
224
|
+
apiCall,
|
|
225
|
+
versionProviderHandler
|
|
226
|
+
);
|
|
185
227
|
return versionProviderHandler;
|
|
186
228
|
}
|
|
187
229
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "@supersoniks/concorde/core/components/ui/button/button";
|
|
2
|
-
import {SonicToast} from "@supersoniks/concorde/core/components/ui/toast/toast";
|
|
3
|
-
import {SubscriberInterface} from "@supersoniks/concorde/core/mixins/Subscriber";
|
|
2
|
+
import { SonicToast } from "@supersoniks/concorde/core/components/ui/toast/toast";
|
|
3
|
+
import { SubscriberInterface } from "@supersoniks/concorde/core/mixins/Subscriber";
|
|
4
4
|
import API from "@supersoniks/concorde/core/utils/api";
|
|
5
5
|
import Objects from "@supersoniks/concorde/core/utils/Objects";
|
|
6
|
-
import {PublisherManager} from "@supersoniks/concorde/utils";
|
|
7
|
-
import {property} from "lit/decorators.js";
|
|
8
|
-
import {PublisherContentType} from "../_types/types";
|
|
9
|
-
import {MixinArgsType} from "../_types/types";
|
|
10
|
-
import {ResultTypeInterface} from "@supersoniks/concorde/core/utils/api";
|
|
6
|
+
import { PublisherManager } from "@supersoniks/concorde/utils";
|
|
7
|
+
import { property } from "lit/decorators.js";
|
|
8
|
+
import { PublisherContentType } from "../_types/types";
|
|
9
|
+
import { MixinArgsType } from "../_types/types";
|
|
10
|
+
import { ResultTypeInterface } from "@supersoniks/concorde/core/utils/api";
|
|
11
11
|
type Constructor<T> = new (...args: MixinArgsType[]) => T;
|
|
12
12
|
|
|
13
|
-
const fetchersInError: Set<{_fetchData: () => void}> = new Set();
|
|
13
|
+
const fetchersInError: Set<{ _fetchData: () => void }> = new Set();
|
|
14
14
|
export const invalidateFetchersInError = () => {
|
|
15
15
|
const fetchersInErrorCopy = new Set(fetchersInError);
|
|
16
16
|
fetchersInError.clear();
|
|
@@ -21,11 +21,15 @@ export const invalidateFetchersInError = () => {
|
|
|
21
21
|
|
|
22
22
|
const errorsListeners = new Set<(apiResponse: Response) => void>();
|
|
23
23
|
|
|
24
|
-
export const onFetchError = (
|
|
24
|
+
export const onFetchError = (
|
|
25
|
+
errorListener: (apiResponse: Response) => void
|
|
26
|
+
) => {
|
|
25
27
|
errorsListeners.add(errorListener);
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
export const offFetchError = (
|
|
30
|
+
export const offFetchError = (
|
|
31
|
+
errorListener: (apiResponse: Response) => void
|
|
32
|
+
) => {
|
|
29
33
|
errorsListeners.delete(errorListener);
|
|
30
34
|
};
|
|
31
35
|
const dispatchFetchError = (apiResponse: Response) => {
|
|
@@ -34,7 +38,10 @@ const dispatchFetchError = (apiResponse: Response) => {
|
|
|
34
38
|
}
|
|
35
39
|
};
|
|
36
40
|
|
|
37
|
-
const Fetcher = <
|
|
41
|
+
const Fetcher = <
|
|
42
|
+
T extends Constructor<SubscriberInterface<PropsType>>,
|
|
43
|
+
PropsType extends PublisherContentType = PublisherContentType
|
|
44
|
+
>(
|
|
38
45
|
superClass: T,
|
|
39
46
|
propsType?: PropsType
|
|
40
47
|
) => {
|
|
@@ -85,7 +92,7 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
85
92
|
super.props = value;
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
@property({type: String}) set endPoint(value: string) {
|
|
95
|
+
@property({ type: String }) set endPoint(value: string) {
|
|
89
96
|
this._endPoint = value;
|
|
90
97
|
if (this.isConnected) this._fetchData();
|
|
91
98
|
}
|
|
@@ -94,7 +101,7 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
@property() requestId = 0;
|
|
97
|
-
@property({type: Number}) refetchEveryMs = 0;
|
|
104
|
+
@property({ type: Number }) refetchEveryMs = 0;
|
|
98
105
|
refetchTimeOutId?: ReturnType<typeof setTimeout>;
|
|
99
106
|
|
|
100
107
|
/**
|
|
@@ -110,23 +117,32 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
110
117
|
if (!this.api) return;
|
|
111
118
|
|
|
112
119
|
// if (!this.dataProvider) return;
|
|
113
|
-
this.dispatchEvent(new CustomEvent("loading", {detail: this}));
|
|
120
|
+
this.dispatchEvent(new CustomEvent("loading", { detail: this }));
|
|
114
121
|
|
|
115
122
|
if (this.getAttribute("localStorage") === "enabled") {
|
|
116
123
|
await PublisherManager.getInstance().isLocalStrorageReady;
|
|
117
124
|
}
|
|
118
125
|
if (!this.isConnected) return;
|
|
119
|
-
const headerData = PublisherManager.getInstance()
|
|
126
|
+
const headerData = PublisherManager.getInstance()
|
|
127
|
+
.get(this.getAncestorAttributeValue("headersDataProvider"))
|
|
128
|
+
.get();
|
|
120
129
|
this.isLoading = true;
|
|
121
|
-
if (
|
|
130
|
+
if (
|
|
131
|
+
Objects.isObject(this.props) &&
|
|
132
|
+
Object.keys(this.props || {}).length > 0 &&
|
|
133
|
+
this.isFirstLoad
|
|
134
|
+
) {
|
|
122
135
|
window.requestAnimationFrame(() => {
|
|
123
|
-
this.dispatchEvent(new CustomEvent("load", {detail: this}));
|
|
136
|
+
this.dispatchEvent(new CustomEvent("load", { detail: this }));
|
|
124
137
|
this.isFirstLoad = false;
|
|
125
138
|
this.isLoading = false;
|
|
126
139
|
});
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
let data = await this.api.get<PropsType>(
|
|
142
|
+
let data = await this.api.get<PropsType>(
|
|
143
|
+
this.endPoint || this.dataProvider || "",
|
|
144
|
+
headerData
|
|
145
|
+
);
|
|
130
146
|
|
|
131
147
|
this.fetchedData = data;
|
|
132
148
|
if (this.api.lastResult && !this.api.lastResult.ok) {
|
|
@@ -141,12 +157,19 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
141
157
|
// Cela n'arrive normalement que lorsque l'on quitte une page pendant un fetch on n'affiche donc pas de message
|
|
142
158
|
this.isLoading = false;
|
|
143
159
|
if (this.refetchEveryMs && this.isConnected) {
|
|
144
|
-
this.refetchTimeOutId = setTimeout(
|
|
160
|
+
this.refetchTimeOutId = setTimeout(
|
|
161
|
+
() => this._fetchData(),
|
|
162
|
+
this.refetchEveryMs
|
|
163
|
+
);
|
|
145
164
|
}
|
|
146
165
|
return;
|
|
147
|
-
} else if (
|
|
166
|
+
} else if (
|
|
167
|
+
data._sonic_http_response_ &&
|
|
168
|
+
!data._sonic_http_response_.ok &&
|
|
169
|
+
Object.keys(data).length === 1
|
|
170
|
+
) {
|
|
148
171
|
// Si data ne contient que la réponse HTTP, avec un statut not ok, on affiche un message
|
|
149
|
-
SonicToast.add({text: "Network Error", status: "error"});
|
|
172
|
+
SonicToast.add({ text: "Network Error", status: "error" });
|
|
150
173
|
}
|
|
151
174
|
if (this.key) {
|
|
152
175
|
const response = data._sonic_http_response_;
|
|
@@ -154,17 +177,25 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
154
177
|
* Conserve les autres propriétés de l'objet reçu, en plus des propriétés définies sous "key"
|
|
155
178
|
*/
|
|
156
179
|
const path = this.key.split(".");
|
|
157
|
-
data = Objects.traverse(
|
|
180
|
+
data = Objects.traverse(
|
|
181
|
+
data,
|
|
182
|
+
path,
|
|
183
|
+
this.hasAttribute("preserveOtherKeys")
|
|
184
|
+
);
|
|
158
185
|
|
|
159
|
-
if (data && Objects.isObject(data) && response)
|
|
186
|
+
if (data && Objects.isObject(data) && response)
|
|
187
|
+
data._sonic_http_response_ = response;
|
|
160
188
|
}
|
|
161
189
|
this.props = data;
|
|
162
|
-
this.dispatchEvent(new CustomEvent("load", {detail: this}));
|
|
190
|
+
this.dispatchEvent(new CustomEvent("load", { detail: this }));
|
|
163
191
|
this.isFirstLoad = false;
|
|
164
192
|
this.isLoading = false;
|
|
165
193
|
|
|
166
194
|
if (this.refetchEveryMs && this.isConnected) {
|
|
167
|
-
this.refetchTimeOutId = setTimeout(
|
|
195
|
+
this.refetchTimeOutId = setTimeout(
|
|
196
|
+
() => this._fetchData(),
|
|
197
|
+
this.refetchEveryMs
|
|
198
|
+
);
|
|
168
199
|
}
|
|
169
200
|
}
|
|
170
201
|
|
|
@@ -178,7 +209,10 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
178
209
|
connectedCallback() {
|
|
179
210
|
// this.noShadowDom = "";
|
|
180
211
|
|
|
181
|
-
this.lazyLoad =
|
|
212
|
+
this.lazyLoad =
|
|
213
|
+
this.lazyLoad !== undefined
|
|
214
|
+
? this.lazyLoad
|
|
215
|
+
: this.hasAttribute("lazyload");
|
|
182
216
|
|
|
183
217
|
super.connectedCallback();
|
|
184
218
|
|
|
@@ -208,22 +242,39 @@ const Fetcher = <T extends Constructor<SubscriberInterface<PropsType>>, PropsTyp
|
|
|
208
242
|
return;
|
|
209
243
|
}
|
|
210
244
|
const rect = this.getBoundingClientRect();
|
|
211
|
-
if (
|
|
245
|
+
if (
|
|
246
|
+
rect.x < window.innerWidth &&
|
|
247
|
+
rect.right > 0 &&
|
|
248
|
+
rect.y < window.innerHeight &&
|
|
249
|
+
rect.right > 0
|
|
250
|
+
) {
|
|
212
251
|
this._fetchData();
|
|
213
252
|
return;
|
|
214
253
|
}
|
|
215
254
|
|
|
216
|
-
const boundsRatio = parseFloat(
|
|
255
|
+
const boundsRatio = parseFloat(
|
|
256
|
+
this.getAttribute("lazyBoundsRatio") || "1"
|
|
257
|
+
);
|
|
217
258
|
|
|
218
259
|
const options: IntersectionObserverInit = {
|
|
219
260
|
root: null,
|
|
220
|
-
rootMargin:
|
|
261
|
+
rootMargin:
|
|
262
|
+
Math.max(
|
|
263
|
+
window.innerWidth * boundsRatio,
|
|
264
|
+
window.innerHeight * boundsRatio
|
|
265
|
+
) + "px",
|
|
221
266
|
threshold: 0.9,
|
|
222
267
|
};
|
|
223
268
|
|
|
224
|
-
this.iObserver = new IntersectionObserver(
|
|
225
|
-
|
|
226
|
-
|
|
269
|
+
this.iObserver = new IntersectionObserver(
|
|
270
|
+
(entries) => this.onIntersection(entries),
|
|
271
|
+
options
|
|
272
|
+
);
|
|
273
|
+
let elt = (
|
|
274
|
+
this.shadowRoot ? this.shadowRoot.children[0] : this.children[0]
|
|
275
|
+
) as HTMLElement;
|
|
276
|
+
if (elt?.nodeName.toLocaleLowerCase() == "slot")
|
|
277
|
+
elt = elt.children[0] as HTMLElement;
|
|
227
278
|
if (!elt || elt.nodeName.toLocaleLowerCase() == "template") {
|
|
228
279
|
elt = document.createElement("span");
|
|
229
280
|
const style = elt.style;
|
|
@@ -5,7 +5,10 @@ export default class Electron {
|
|
|
5
5
|
addEventListener: (type: string, callback: (e?: Event) => void) => void;
|
|
6
6
|
}) {
|
|
7
7
|
const electronStr = "electron";
|
|
8
|
-
const electron =
|
|
8
|
+
const electron =
|
|
9
|
+
typeof require == "undefined" || typeof process != "object"
|
|
10
|
+
? null
|
|
11
|
+
: require(electronStr);
|
|
9
12
|
if (typeof electron && link.target == "_blank") {
|
|
10
13
|
link.addEventListener("click", () => {
|
|
11
14
|
electron?.shell.openExternal(link.href);
|
package/src/docs/code.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { html, LitElement, css, nothing, PropertyValues } from "lit";
|
|
2
2
|
import { customElement, property, state } from "lit/decorators.js";
|
|
3
|
-
|
|
3
|
+
import { tailwind } from "./tailwind";
|
|
4
|
+
|
|
4
5
|
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
5
6
|
import { query } from "lit/decorators/query.js";
|
|
6
7
|
|
|
@@ -10,7 +11,7 @@ import "./prism/prism";
|
|
|
10
11
|
import { prismCSS } from "./prism";
|
|
11
12
|
import * as Prism from "prismjs";
|
|
12
13
|
import "prismjs/plugins/normalize-whitespace/prism-normalize-whitespace";
|
|
13
|
-
|
|
14
|
+
import "prismjs/components/prism-json"; // Language
|
|
14
15
|
import "prismjs/components/prism-typescript"; // Language
|
|
15
16
|
import "prismjs/components/prism-javascript"; // Language
|
|
16
17
|
import "prismjs/components/prism-bash"; // Language
|
|
@@ -21,7 +22,7 @@ const tagName = "sonic-code";
|
|
|
21
22
|
@customElement(tagName)
|
|
22
23
|
export class DocsCode extends LitElement {
|
|
23
24
|
static styles = [
|
|
24
|
-
|
|
25
|
+
tailwind,
|
|
25
26
|
prismCSS,
|
|
26
27
|
css`
|
|
27
28
|
:host(:not([inline])) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { html, LitElement } from "lit";
|
|
2
2
|
import { customElement, property } from "lit/decorators.js";
|
|
3
3
|
import Subscriber from "@supersoniks/concorde/core/mixins/Subscriber";
|
|
4
|
-
|
|
4
|
+
import { tailwind } from "../tailwind";
|
|
5
5
|
|
|
6
6
|
@customElement("docs-preview-user-item")
|
|
7
7
|
export class user extends Subscriber(LitElement) {
|
|
8
|
-
|
|
8
|
+
static styles = [tailwind];
|
|
9
9
|
|
|
10
10
|
@property({ type: String }) avatar = "";
|
|
11
11
|
@property({ type: String }) first_name = "";
|