@sitecore-feaas/clientside 0.0.2 → 0.0.3
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 +2 -2
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.js +2 -2
- package/dist/browser/react.cjs +3 -3
- package/dist/browser/react.d.ts +2 -2
- package/dist/browser/react.js +3 -3
- package/dist/browser/{webcomponent-189a307d.d.ts → webcomponent-7a0e7c34.d.ts} +8 -8
- package/dist/node/index.cjs +15 -13
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +15 -13
- package/dist/node/react.cjs +17 -15
- package/dist/node/react.d.ts +2 -2
- package/dist/node/react.js +17 -15
- package/dist/node/{webcomponent-189a307d.d.ts → webcomponent-7a0e7c34.d.ts} +8 -8
- package/examples/index.html +2 -2
- package/index.cjs +2 -2
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +7 -1
- package/react.cjs +3 -3
- package/react.d.ts +2 -2
- package/react.js +3 -3
- package/src/cloud.ts +9 -9
- package/src/dom.ts +4 -2
- package/src/react.ts +2 -2
- package/src/webcomponent.ts +8 -8
- package/test/render.ts +4 -1
- package/tsconfig.json +1 -1
- package/{webcomponent-189a307d.d.ts → webcomponent-7a0e7c34.d.ts} +8 -8
package/src/cloud.ts
CHANGED
|
@@ -4,31 +4,31 @@ export interface CloudTemplate {
|
|
|
4
4
|
hostname?: string
|
|
5
5
|
library: string
|
|
6
6
|
component: string
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
version: string
|
|
8
|
+
revision?: string
|
|
9
9
|
}
|
|
10
10
|
export interface CloudStylesheet {
|
|
11
11
|
hostname?: string
|
|
12
12
|
library: string
|
|
13
|
-
|
|
13
|
+
revision?: string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function getComponentURL({
|
|
17
17
|
hostname = 'https://feaascomponentsapidev.blob.core.windows.net',
|
|
18
18
|
library,
|
|
19
19
|
component,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
version,
|
|
21
|
+
revision = 'published'
|
|
22
22
|
}: CloudTemplate) {
|
|
23
|
-
return `${hostname}/components/${library}/${component}/${
|
|
23
|
+
return `${hostname}/components/${library}/${component}/${version}/${revision}.html`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function getStylesheetURL({
|
|
27
27
|
hostname = `https://feaascomponentsapidev.blob.core.windows.net`,
|
|
28
28
|
library,
|
|
29
|
-
|
|
29
|
+
revision = 'published'
|
|
30
30
|
}: CloudStylesheet) {
|
|
31
|
-
return `${hostname}/styles/${library}/${
|
|
31
|
+
return `${hostname}/styles/${library}/${revision}.css`
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export async function fetchComponent(props: CloudTemplate, callback: (html: string) => void) {
|
|
@@ -36,7 +36,7 @@ export async function fetchComponent(props: CloudTemplate, callback: (html: stri
|
|
|
36
36
|
getComponentURL(props),
|
|
37
37
|
{},
|
|
38
38
|
(response) => {
|
|
39
|
-
return response.headers.get('x-ms-meta-
|
|
39
|
+
return response.headers.get('x-ms-meta-versionDeletedAt') == null
|
|
40
40
|
},
|
|
41
41
|
(response) => {
|
|
42
42
|
response.text().then(callback)
|
package/src/dom.ts
CHANGED
|
@@ -115,7 +115,7 @@ export function queryScopes(scopes: any, datapath: string, singleValue = false,
|
|
|
115
115
|
path: path,
|
|
116
116
|
json: json
|
|
117
117
|
})
|
|
118
|
-
if (singleValue && collection) {
|
|
118
|
+
if (singleValue && collection && Array.isArray(collection)) {
|
|
119
119
|
return collection[0]
|
|
120
120
|
} else {
|
|
121
121
|
return collection
|
|
@@ -133,6 +133,8 @@ export function setDOMAttribute(element: HTMLElement, attribute: string, value:
|
|
|
133
133
|
target = element.tagName == 'IMG' ? element : <HTMLElement>element.querySelector('img, video')
|
|
134
134
|
} else if (attribute == 'data-path-href') {
|
|
135
135
|
target = element.querySelector('a') || element.closest('a')
|
|
136
|
+
} else if (attribute == 'data-path-alt') {
|
|
137
|
+
target = element.querySelector('img, picture')
|
|
136
138
|
} else if (attribute == 'data-path-hidden') {
|
|
137
139
|
value = !value ? true : null
|
|
138
140
|
} else if (attribute == 'data-path' || attribute == 'data-embed-html' || attribute == 'html') {
|
|
@@ -258,7 +260,7 @@ export function renderDOMElement(
|
|
|
258
260
|
[normalizeCollectionScope(datascope)]: collection[index]
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
|
-
const attrs = Array.prototype.slice.call(element.attributes).sort((a, b) => {
|
|
263
|
+
const attrs = Array.prototype.slice.call(element.attributes).sort((a: Attr, b: Attr) => {
|
|
262
264
|
return sortOrder.indexOf(a.name) - sortOrder.indexOf(b.name)
|
|
263
265
|
})
|
|
264
266
|
for (var i = 0; i < attrs.length; i++) {
|
package/src/react.ts
CHANGED
|
@@ -17,14 +17,14 @@ export function Component(props: FEAASComponentProps) {
|
|
|
17
17
|
if (template == null && !('template' in props)) {
|
|
18
18
|
fetchComponent(props, setTemplate).catch(() => {
|
|
19
19
|
console.error(
|
|
20
|
-
`FEAAS: Could not fetch component: ${props.library}/${props.component}/${props.
|
|
20
|
+
`FEAAS: Could not fetch component: ${props.library}/${props.component}/${props.version}/${props.revision}`
|
|
21
21
|
)
|
|
22
22
|
})
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
'template' in props
|
|
26
26
|
? [props.template, null, null, null]
|
|
27
|
-
: [props.library, props.component, props.
|
|
27
|
+
: [props.library, props.component, props.version, props.revision, props.hostname]
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
React.useEffect(() => {
|
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
|
|
@@ -28,7 +28,7 @@ var WebComponent = typeof HTMLElement == 'undefined' ? (class {} as unknown as t
|
|
|
28
28
|
|
|
29
29
|
export class HTMLFeaasComponent extends WebComponent {
|
|
30
30
|
static get observedAttributes() {
|
|
31
|
-
return ['data', 'library', 'component', '
|
|
31
|
+
return ['data', 'library', 'component', 'version', 'revision', 'hostname', 'template']
|
|
32
32
|
}
|
|
33
33
|
connected = false
|
|
34
34
|
|
|
@@ -101,7 +101,7 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
101
101
|
const newProps = this.getProps()
|
|
102
102
|
if (this.template == null) {
|
|
103
103
|
if (!this.isFetching) {
|
|
104
|
-
if (newProps.component != null && newProps.
|
|
104
|
+
if (newProps.component != null && newProps.version != null) {
|
|
105
105
|
this.isFetching = true
|
|
106
106
|
fetchComponent(newProps, (template) => {
|
|
107
107
|
this.template = template
|
|
@@ -109,7 +109,7 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
109
109
|
renderDOMContent(this, this.template, newProps.data)
|
|
110
110
|
}).catch(() => {
|
|
111
111
|
console.error(
|
|
112
|
-
`FEAAS: Could not fetch component: ${newProps.component}/${newProps.
|
|
112
|
+
`FEAAS: Could not fetch component: ${newProps.component}/${newProps.version}/${newProps.revision}`
|
|
113
113
|
)
|
|
114
114
|
})
|
|
115
115
|
}
|
|
@@ -124,8 +124,8 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
124
124
|
data: this.getData(),
|
|
125
125
|
library: (this.getAttribute('library') || undefined) as string,
|
|
126
126
|
component: (this.getAttribute('component') || undefined) as string,
|
|
127
|
-
variant: (this.getAttribute('variant') || undefined) as string,
|
|
128
127
|
version: (this.getAttribute('version') || undefined) as string,
|
|
128
|
+
revision: (this.getAttribute('revision') || undefined) as string,
|
|
129
129
|
hostname: (this.getAttribute('hostname') || undefined) as string
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -133,7 +133,7 @@ export class HTMLFeaasComponent extends WebComponent {
|
|
|
133
133
|
|
|
134
134
|
export class HTMLFeaasStylesheet extends WebComponent {
|
|
135
135
|
static get observedAttributes() {
|
|
136
|
-
return ['library', '
|
|
136
|
+
return ['library', 'revision', 'hostname']
|
|
137
137
|
}
|
|
138
138
|
connected = false
|
|
139
139
|
connectedCallback() {
|
|
@@ -157,7 +157,7 @@ export class HTMLFeaasStylesheet extends WebComponent {
|
|
|
157
157
|
getProps() {
|
|
158
158
|
return {
|
|
159
159
|
library: (this.getAttribute('library') || undefined) as string,
|
|
160
|
-
|
|
160
|
+
revision: (this.getAttribute('revision') || undefined) as string,
|
|
161
161
|
hostname: (this.getAttribute('hostname') || undefined) as string
|
|
162
162
|
}
|
|
163
163
|
}
|
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;
|
|
@@ -95,7 +95,7 @@ declare class HTMLFeaasStylesheet extends WebComponent {
|
|
|
95
95
|
render(): void;
|
|
96
96
|
getProps(): {
|
|
97
97
|
library: string;
|
|
98
|
-
|
|
98
|
+
revision: string;
|
|
99
99
|
hostname: string;
|
|
100
100
|
};
|
|
101
101
|
}
|