@sitecore-feaas/clientside 0.0.2 → 0.0.4
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/README.md +4 -4
- package/dist/browser/index.cjs +83 -3
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.js +83 -3
- package/dist/browser/react.cjs +83 -3
- package/dist/browser/react.d.ts +2 -2
- package/dist/browser/react.js +83 -3
- package/dist/browser/{webcomponent-189a307d.d.ts → webcomponent-6b45b819.d.ts} +26 -9
- package/dist/node/index.cjs +186 -14
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +186 -14
- package/dist/node/react.cjs +188 -16
- package/dist/node/react.d.ts +2 -2
- package/dist/node/react.js +188 -16
- package/dist/node/{webcomponent-189a307d.d.ts → webcomponent-6b45b819.d.ts} +26 -9
- package/examples/index.html +2 -2
- package/index.cjs +83 -3
- package/index.d.ts +2 -2
- package/index.js +83 -3
- package/package.json +7 -1
- package/react.cjs +83 -3
- package/react.d.ts +2 -2
- package/react.js +83 -3
- package/src/cloud.ts +9 -9
- package/src/dom.ts +4 -2
- package/src/react.ts +2 -2
- package/src/webcomponent.ts +212 -9
- package/test/render.ts +4 -1
- package/tsconfig.json +1 -1
- package/{webcomponent-189a307d.d.ts → webcomponent-6b45b819.d.ts} +26 -9
package/src/webcomponent.ts
CHANGED
|
@@ -8,8 +8,8 @@ declare global {
|
|
|
8
8
|
data?: any
|
|
9
9
|
library: string
|
|
10
10
|
component: string
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
version: string
|
|
12
|
+
revision?: string
|
|
13
13
|
hostname?: string
|
|
14
14
|
template?: string
|
|
15
15
|
children?: any
|
|
@@ -19,6 +19,10 @@ declare global {
|
|
|
19
19
|
hostname?: string
|
|
20
20
|
children?: any
|
|
21
21
|
}
|
|
22
|
+
'feaas-picker': {
|
|
23
|
+
library: string
|
|
24
|
+
mode?: string
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
}
|
|
@@ -28,13 +32,14 @@ var WebComponent = typeof HTMLElement == 'undefined' ? (class {} as unknown as t
|
|
|
28
32
|
|
|
29
33
|
export class HTMLFeaasComponent extends WebComponent {
|
|
30
34
|
static get observedAttributes() {
|
|
31
|
-
return ['data', 'library', 'component', '
|
|
35
|
+
return ['data', 'library', 'component', 'version', 'revision', 'hostname', 'template']
|
|
32
36
|
}
|
|
33
37
|
connected = false
|
|
34
38
|
|
|
35
39
|
template: string = null
|
|
36
40
|
data: any = undefined
|
|
37
41
|
isFetching: boolean = false
|
|
42
|
+
rendering: ReturnType<typeof requestAnimationFrame>
|
|
38
43
|
|
|
39
44
|
connectedCallback() {
|
|
40
45
|
this.connected = true
|
|
@@ -47,11 +52,16 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
47
52
|
if (!this.connected) return
|
|
48
53
|
if (name == 'template') {
|
|
49
54
|
this.template = newValue
|
|
55
|
+
} else if (name != 'date') {
|
|
56
|
+
this.template = null
|
|
50
57
|
}
|
|
51
58
|
if (name == 'data' && this.children.length > 0) {
|
|
52
59
|
this.update()
|
|
53
60
|
} else {
|
|
54
|
-
this.
|
|
61
|
+
cancelAnimationFrame(this.rendering)
|
|
62
|
+
this.rendering = requestAnimationFrame(() => {
|
|
63
|
+
this.render()
|
|
64
|
+
})
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
|
|
@@ -101,7 +111,7 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
101
111
|
const newProps = this.getProps()
|
|
102
112
|
if (this.template == null) {
|
|
103
113
|
if (!this.isFetching) {
|
|
104
|
-
if (newProps.component != null && newProps.
|
|
114
|
+
if (newProps.component != null && newProps.version != null) {
|
|
105
115
|
this.isFetching = true
|
|
106
116
|
fetchComponent(newProps, (template) => {
|
|
107
117
|
this.template = template
|
|
@@ -109,7 +119,7 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
109
119
|
renderDOMContent(this, this.template, newProps.data)
|
|
110
120
|
}).catch(() => {
|
|
111
121
|
console.error(
|
|
112
|
-
`FEAAS: Could not fetch component: ${newProps.component}/${newProps.
|
|
122
|
+
`FEAAS: Could not fetch component: ${newProps.component}/${newProps.version}/${newProps.revision}`
|
|
113
123
|
)
|
|
114
124
|
})
|
|
115
125
|
}
|
|
@@ -124,8 +134,8 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
124
134
|
data: this.getData(),
|
|
125
135
|
library: (this.getAttribute('library') || undefined) as string,
|
|
126
136
|
component: (this.getAttribute('component') || undefined) as string,
|
|
127
|
-
variant: (this.getAttribute('variant') || undefined) as string,
|
|
128
137
|
version: (this.getAttribute('version') || undefined) as string,
|
|
138
|
+
revision: (this.getAttribute('revision') || undefined) as string,
|
|
129
139
|
hostname: (this.getAttribute('hostname') || undefined) as string
|
|
130
140
|
}
|
|
131
141
|
}
|
|
@@ -133,7 +143,7 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
133
143
|
|
|
134
144
|
export class HTMLFeaasStylesheet extends WebComponent {
|
|
135
145
|
static get observedAttributes() {
|
|
136
|
-
return ['library', '
|
|
146
|
+
return ['library', 'revision', 'hostname']
|
|
137
147
|
}
|
|
138
148
|
connected = false
|
|
139
149
|
connectedCallback() {
|
|
@@ -157,13 +167,206 @@ export class HTMLFeaasStylesheet extends WebComponent {
|
|
|
157
167
|
getProps() {
|
|
158
168
|
return {
|
|
159
169
|
library: (this.getAttribute('library') || undefined) as string,
|
|
160
|
-
|
|
170
|
+
revision: (this.getAttribute('revision') || undefined) as string,
|
|
161
171
|
hostname: (this.getAttribute('hostname') || undefined) as string
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
174
|
}
|
|
175
|
+
export interface PickerProps<T = HTMLElement> {
|
|
176
|
+
children?: any
|
|
177
|
+
context?: T
|
|
178
|
+
isOpen?: boolean
|
|
179
|
+
mode?: 'library' | 'stylesheet'
|
|
180
|
+
src?: string
|
|
181
|
+
onClose?: () => any
|
|
182
|
+
}
|
|
183
|
+
export interface HTMLFeaasPickerProps extends Omit<PickerProps<HTMLElement>, 'children'> {
|
|
184
|
+
getAccessTokenSilently: (options: any) => Promise<string>
|
|
185
|
+
library: string
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface HTMLFeaasPickerLazy extends HTMLFeaasPickerProps {}
|
|
189
|
+
class HTMLFeaasPickerLazy extends WebComponent {
|
|
190
|
+
static get observedAttributes() {
|
|
191
|
+
return ['library', 'mode', 'hidden', 'src']
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
src = 'https://components.sitecorecloud.io/assets/picker.js'
|
|
195
|
+
|
|
196
|
+
script: HTMLScriptElement
|
|
197
|
+
element: HTMLFeaasPickerLazy
|
|
198
|
+
loader: HTMLFeaasLoader
|
|
199
|
+
|
|
200
|
+
connectedCallback() {
|
|
201
|
+
this.loader = document.createElement('feaas-loader') as HTMLFeaasLoader
|
|
202
|
+
this.loader.style.cssText = 'position: absolute; top: 0; left: 0; right: 0;bottom: 0; '
|
|
203
|
+
this.appendChild(this.loader)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
load() {
|
|
207
|
+
if (!this.script) {
|
|
208
|
+
this.script = document.createElement('script')
|
|
209
|
+
this.script.type = 'module'
|
|
210
|
+
this.script.onload = this.onScriptLoaded
|
|
211
|
+
this.script.src = this.src
|
|
212
|
+
this.appendChild(this.script)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
getProps() {
|
|
217
|
+
return {
|
|
218
|
+
mode: this.getAttribute('mode') as PickerProps['mode'],
|
|
219
|
+
library: this.getAttribute('library'),
|
|
220
|
+
src: this.getAttribute('src')
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
225
|
+
this.set(this.getProps())
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
set(options: Partial<HTMLFeaasPickerProps>) {
|
|
229
|
+
Object.assign(this, options)
|
|
230
|
+
const keys = Object.keys(this.getProps())
|
|
231
|
+
for (var key of keys) {
|
|
232
|
+
const value = this[key as keyof typeof this]
|
|
233
|
+
if (value == null) {
|
|
234
|
+
this.removeAttribute(key)
|
|
235
|
+
this.load()
|
|
236
|
+
} else if (this.getAttribute(key) != String(value)) {
|
|
237
|
+
this.setAttribute(key, String(value))
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (this.mode) {
|
|
241
|
+
this.removeAttribute('hidden')
|
|
242
|
+
} else if (this.getAttribute('hidden') == null) {
|
|
243
|
+
this.setAttribute('hidden', 'hidden')
|
|
244
|
+
}
|
|
245
|
+
if (this.element && this.element.set) {
|
|
246
|
+
this.element.onClose = this.onClose
|
|
247
|
+
this.element.set(options)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
onClose = () => {
|
|
252
|
+
this.set({
|
|
253
|
+
mode: null
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
onScriptLoaded = () => {
|
|
258
|
+
this.element = document.createElement('feaas-picker') as HTMLFeaasPickerLazy
|
|
259
|
+
this.element.style.cssText = 'border: 0; width: 100%; height: 100%; display: block'
|
|
260
|
+
this.appendChild(this.element)
|
|
261
|
+
this.set(this.getProps())
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
class HTMLFeaasLoader extends WebComponent {
|
|
266
|
+
stylesheet: HTMLStyleElement
|
|
267
|
+
root: ShadowRoot
|
|
268
|
+
loader: HTMLDivElement
|
|
269
|
+
|
|
270
|
+
static get observedAttributes() {
|
|
271
|
+
return ['hidden']
|
|
272
|
+
}
|
|
273
|
+
connectedCallback() {
|
|
274
|
+
this.style.opacity = '1'
|
|
275
|
+
this.style.transition = 'opacity 0.2s 0.6s'
|
|
276
|
+
this.stylesheet = document.createElement('style')
|
|
277
|
+
this.stylesheet.textContent = `
|
|
278
|
+
#loader {
|
|
279
|
+
position: absolute;
|
|
280
|
+
top: 0;
|
|
281
|
+
left: 0;
|
|
282
|
+
right: 0;
|
|
283
|
+
bottom: 0;
|
|
284
|
+
display: flex;
|
|
285
|
+
align-items: center;
|
|
286
|
+
justify-content: center;
|
|
287
|
+
background: #f6f6ff;
|
|
288
|
+
z-index: 1000;
|
|
289
|
+
opacity: 1;
|
|
290
|
+
transition: top 0.3s, background-color 0.7s 0.3s;
|
|
291
|
+
}
|
|
292
|
+
@keyframes loader-disappearance {
|
|
293
|
+
100% {
|
|
294
|
+
opacity: 0;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
@keyframes loader-appearance {
|
|
298
|
+
0% {
|
|
299
|
+
opacity: 0;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
@keyframes loader-circular-track {
|
|
303
|
+
0% {
|
|
304
|
+
stroke-dasharray: 1, 400;
|
|
305
|
+
stroke-dashoffset: 0;
|
|
306
|
+
}
|
|
307
|
+
50% {
|
|
308
|
+
stroke-dasharray: 400, 400;
|
|
309
|
+
stroke-dashoffset: -100;
|
|
310
|
+
}
|
|
311
|
+
100% {
|
|
312
|
+
stroke-dasharray: 400, 400;
|
|
313
|
+
stroke-dashoffset: -260;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
@keyframes loader-circular-spinner {
|
|
318
|
+
0% {
|
|
319
|
+
transform: rotate(0deg);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
100% {
|
|
323
|
+
transform: rotate(360deg);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
#loader .spinner {
|
|
327
|
+
animation: loader-disappearance 0.6s both;
|
|
328
|
+
width: 48px;
|
|
329
|
+
height: 48px;
|
|
330
|
+
}
|
|
331
|
+
#loader .spinner {
|
|
332
|
+
animation: loader-appearance 0.6s both;
|
|
333
|
+
}
|
|
334
|
+
`
|
|
335
|
+
this.root = this.attachShadow({ mode: 'open' })
|
|
336
|
+
this.loader = document.createElement('div')
|
|
337
|
+
this.loader.id = 'loader'
|
|
338
|
+
this.loader.innerHTML = `
|
|
339
|
+
<div class="spinner">
|
|
340
|
+
<svg
|
|
341
|
+
viewBox="0 0 100 100"
|
|
342
|
+
style="
|
|
343
|
+
animation: 2s linear 0s infinite normal none running loader-circular-spinner;
|
|
344
|
+
display: block;
|
|
345
|
+
width: 48px;
|
|
346
|
+
height: 48px;
|
|
347
|
+
"
|
|
348
|
+
>
|
|
349
|
+
<circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
|
|
350
|
+
<circle
|
|
351
|
+
fill="transparent"
|
|
352
|
+
stroke="#5548D9"
|
|
353
|
+
cx="50"
|
|
354
|
+
cy="50"
|
|
355
|
+
r="42"
|
|
356
|
+
stroke-width="10px"
|
|
357
|
+
stroke-linecap="round"
|
|
358
|
+
style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
|
|
359
|
+
></circle>
|
|
360
|
+
</svg>
|
|
361
|
+
</div>`
|
|
362
|
+
this.shadowRoot.appendChild(this.stylesheet)
|
|
363
|
+
this.shadowRoot.appendChild(this.loader)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
165
366
|
|
|
166
367
|
if (typeof window != 'undefined' && !window.customElements.get('feaas-stylesheet')) {
|
|
167
368
|
window.customElements.define('feaas-stylesheet', HTMLFeaasStylesheet)
|
|
168
369
|
window.customElements.define('feaas-component', HTMLFeaasComponent)
|
|
370
|
+
window.customElements.define('feaas-picker-lazy', HTMLFeaasPickerLazy)
|
|
371
|
+
window.customElements.define('feaas-loader', HTMLFeaasLoader)
|
|
169
372
|
}
|
package/test/render.ts
CHANGED
|
@@ -7,7 +7,10 @@ const { renderDOMElement } = FEAAS
|
|
|
7
7
|
function assertScriptLoaded(element: HTMLElement, src: string) {
|
|
8
8
|
console.log(element.closest('html').innerHTML)
|
|
9
9
|
assert.equal(
|
|
10
|
-
Array.prototype.find.call(
|
|
10
|
+
Array.prototype.find.call(
|
|
11
|
+
element.closest('html').querySelectorAll('script'),
|
|
12
|
+
(s: HTMLScriptElement) => s.src == src
|
|
13
|
+
)?.src,
|
|
11
14
|
src
|
|
12
15
|
)
|
|
13
16
|
}
|
package/tsconfig.json
CHANGED
|
@@ -2,16 +2,16 @@ interface CloudTemplate {
|
|
|
2
2
|
hostname?: string;
|
|
3
3
|
library: string;
|
|
4
4
|
component: string;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
version: string;
|
|
6
|
+
revision?: string;
|
|
7
7
|
}
|
|
8
8
|
interface CloudStylesheet {
|
|
9
9
|
hostname?: string;
|
|
10
10
|
library: string;
|
|
11
|
-
|
|
11
|
+
revision?: string;
|
|
12
12
|
}
|
|
13
|
-
declare function getComponentURL({ hostname, library, component,
|
|
14
|
-
declare function getStylesheetURL({ hostname, library,
|
|
13
|
+
declare function getComponentURL({ hostname, library, component, version, revision }: CloudTemplate): string;
|
|
14
|
+
declare function getStylesheetURL({ hostname, library, revision }: CloudStylesheet): string;
|
|
15
15
|
declare function fetchComponent(props: CloudTemplate, callback: (html: string) => void): Promise<Response>;
|
|
16
16
|
declare function fetchStylesheet(props: CloudStylesheet, callback: (css: string) => void): Promise<Response>;
|
|
17
17
|
|
|
@@ -51,8 +51,8 @@ declare global {
|
|
|
51
51
|
data?: any;
|
|
52
52
|
library: string;
|
|
53
53
|
component: string;
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
version: string;
|
|
55
|
+
revision?: string;
|
|
56
56
|
hostname?: string;
|
|
57
57
|
template?: string;
|
|
58
58
|
children?: any;
|
|
@@ -62,6 +62,10 @@ declare global {
|
|
|
62
62
|
hostname?: string;
|
|
63
63
|
children?: any;
|
|
64
64
|
};
|
|
65
|
+
'feaas-picker': {
|
|
66
|
+
library: string;
|
|
67
|
+
mode?: string;
|
|
68
|
+
};
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
}
|
|
@@ -75,6 +79,7 @@ declare class HTMLFeaasComponent extends WebComponent {
|
|
|
75
79
|
template: string;
|
|
76
80
|
data: any;
|
|
77
81
|
isFetching: boolean;
|
|
82
|
+
rendering: ReturnType<typeof requestAnimationFrame>;
|
|
78
83
|
connectedCallback(): void;
|
|
79
84
|
disconnectedCallback(): void;
|
|
80
85
|
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
@@ -95,9 +100,21 @@ declare class HTMLFeaasStylesheet extends WebComponent {
|
|
|
95
100
|
render(): void;
|
|
96
101
|
getProps(): {
|
|
97
102
|
library: string;
|
|
98
|
-
|
|
103
|
+
revision: string;
|
|
99
104
|
hostname: string;
|
|
100
105
|
};
|
|
101
106
|
}
|
|
107
|
+
interface PickerProps<T = HTMLElement> {
|
|
108
|
+
children?: any;
|
|
109
|
+
context?: T;
|
|
110
|
+
isOpen?: boolean;
|
|
111
|
+
mode?: 'library' | 'stylesheet';
|
|
112
|
+
src?: string;
|
|
113
|
+
onClose?: () => any;
|
|
114
|
+
}
|
|
115
|
+
interface HTMLFeaasPickerProps extends Omit<PickerProps<HTMLElement>, 'children'> {
|
|
116
|
+
getAccessTokenSilently: (options: any) => Promise<string>;
|
|
117
|
+
library: string;
|
|
118
|
+
}
|
|
102
119
|
|
|
103
|
-
export { CloudStylesheet as C, Datascopes as D, ExplicitTemplate as E, FEAASCustomizations as F, HTMLFeaasComponent as H, HTMLFeaasStylesheet as a, FEAASComponentProps as b, cleanCollectionBit as c, autoloadScripts as d, renderDOMElement as e, renderDOMContent as f, renderStylesheet as g, renderStylesheetPromise as h, renderComponent as i, renderComponentPromise as j,
|
|
120
|
+
export { CloudStylesheet as C, Datascopes as D, ExplicitTemplate as E, FEAASCustomizations as F, HTMLFeaasComponent as H, PickerProps as P, HTMLFeaasStylesheet as a, FEAASComponentProps as b, cleanCollectionBit as c, autoloadScripts as d, renderDOMElement as e, renderDOMContent as f, renderStylesheet as g, renderStylesheetPromise as h, renderComponent as i, renderComponentPromise as j, HTMLFeaasPickerProps as k, loadScript as l, CloudTemplate as m, normalizeCollectionScope as n, observeDOMElement as o, getComponentURL as p, queryScopes as q, renderComponentElement as r, setDOMAttribute as s, getStylesheetURL as t, fetchComponent as u, fetchStylesheet as v };
|