@merkur/plugin-component 0.36.0 → 0.37.0
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/helpers.d.ts +31 -0
- package/lib/helpers.cjs +47 -36
- package/lib/helpers.es9.cjs +47 -39
- package/lib/helpers.es9.mjs +47 -39
- package/lib/helpers.js +47 -36
- package/lib/helpers.mjs +47 -36
- package/lib/helpers.umd.js +1 -0
- package/lib/index.umd.js +1 -1
- package/package.json +4 -4
- package/rollup.config.mjs +10 -8
- package/types.d.ts +2 -1
- package/lib/helpers.d.ts +0 -20
- package/lib/helpers.es9.js +0 -52
package/helpers.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Widget } from '@merkur/core';
|
|
2
|
+
import {
|
|
3
|
+
ViewFactory,
|
|
4
|
+
ViewFactorySlotType,
|
|
5
|
+
ViewType,
|
|
6
|
+
} from '@merkur/plugin-component';
|
|
7
|
+
export type MapViewArgs = {
|
|
8
|
+
View: ViewType;
|
|
9
|
+
ErrorView?: ViewType;
|
|
10
|
+
containerSelector: string;
|
|
11
|
+
container: Element | null;
|
|
12
|
+
isSlot: boolean;
|
|
13
|
+
slot?: Record<
|
|
14
|
+
string,
|
|
15
|
+
{
|
|
16
|
+
isSlot: boolean;
|
|
17
|
+
containerSelector?: string;
|
|
18
|
+
container?: Element;
|
|
19
|
+
} & ViewFactorySlotType
|
|
20
|
+
>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Utility function to iterate thorugh views returned from
|
|
24
|
+
* view factory and call callback function with view arguments
|
|
25
|
+
* on each them.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mapViews<T>(
|
|
28
|
+
widget: Widget,
|
|
29
|
+
viewFactory: ViewFactory,
|
|
30
|
+
callback: (viewArgs: MapViewArgs) => T,
|
|
31
|
+
): Promise<void[]>;
|
package/lib/helpers.cjs
CHANGED
|
@@ -6,45 +6,56 @@
|
|
|
6
6
|
* on each them.
|
|
7
7
|
*/
|
|
8
8
|
async function mapViews(widget, viewFactory, callback) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
if (widget.$in.component.resolvedViews.has(viewFactory)) {
|
|
10
|
+
return mapResolvedViews(
|
|
11
|
+
widget.$in.component.resolvedViews.get(viewFactory) ?? [],
|
|
12
|
+
callback,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { containerSelector } = widget;
|
|
17
|
+
const { View, ErrorView, slot = {} } = await viewFactory(widget);
|
|
18
|
+
|
|
19
|
+
// Add additional slot information to slot views
|
|
20
|
+
const slots = Object.keys(widget.slot ?? {}).reduce((acc, cur) => {
|
|
21
|
+
acc[cur] = {
|
|
22
|
+
...slot[cur],
|
|
23
|
+
isSlot: true,
|
|
24
|
+
containerSelector: widget.slot[cur]?.containerSelector,
|
|
25
|
+
container: widget.slot[cur]?.container,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
|
|
31
|
+
const views = [
|
|
32
|
+
{
|
|
33
|
+
View,
|
|
34
|
+
ErrorView,
|
|
35
|
+
containerSelector,
|
|
36
|
+
isSlot: false,
|
|
37
|
+
container: widget.container,
|
|
38
|
+
},
|
|
39
|
+
...Object.values(slots),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
widget.$in.component.resolvedViews.set(viewFactory, views);
|
|
43
|
+
|
|
44
|
+
return mapResolvedViews(views, callback);
|
|
36
45
|
}
|
|
46
|
+
|
|
37
47
|
function mapResolvedViews(views, callback) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
return views.map(({ View, containerSelector, isSlot, container }) => {
|
|
49
|
+
callback({
|
|
50
|
+
View,
|
|
51
|
+
isSlot,
|
|
52
|
+
containerSelector,
|
|
53
|
+
container:
|
|
54
|
+
(containerSelector && document?.querySelector(containerSelector)) ||
|
|
55
|
+
container ||
|
|
56
|
+
null,
|
|
47
57
|
});
|
|
58
|
+
});
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
exports.mapViews = mapViews;
|
package/lib/helpers.es9.cjs
CHANGED
|
@@ -6,47 +6,55 @@
|
|
|
6
6
|
* on each them.
|
|
7
7
|
*/
|
|
8
8
|
async function mapViews(widget, viewFactory, callback) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
9
|
+
var _widget$slot;
|
|
10
|
+
if (widget.$in.component.resolvedViews.has(viewFactory)) {
|
|
11
|
+
var _widget$$in$component;
|
|
12
|
+
return mapResolvedViews((_widget$$in$component = widget.$in.component.resolvedViews.get(viewFactory)) !== null && _widget$$in$component !== void 0 ? _widget$$in$component : [], callback);
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
containerSelector
|
|
16
|
+
} = widget;
|
|
17
|
+
const {
|
|
18
|
+
View,
|
|
19
|
+
ErrorView,
|
|
20
|
+
slot = {}
|
|
21
|
+
} = await viewFactory(widget);
|
|
22
|
+
|
|
23
|
+
// Add additional slot information to slot views
|
|
24
|
+
const slots = Object.keys((_widget$slot = widget.slot) !== null && _widget$slot !== void 0 ? _widget$slot : {}).reduce((acc, cur) => {
|
|
25
|
+
var _widget$slot$cur, _widget$slot$cur2;
|
|
26
|
+
acc[cur] = {
|
|
27
|
+
...slot[cur],
|
|
28
|
+
isSlot: true,
|
|
29
|
+
containerSelector: (_widget$slot$cur = widget.slot[cur]) === null || _widget$slot$cur === void 0 ? void 0 : _widget$slot$cur.containerSelector,
|
|
30
|
+
container: (_widget$slot$cur2 = widget.slot[cur]) === null || _widget$slot$cur2 === void 0 ? void 0 : _widget$slot$cur2.container
|
|
31
|
+
};
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
const views = [{
|
|
35
|
+
View,
|
|
36
|
+
ErrorView,
|
|
37
|
+
containerSelector,
|
|
38
|
+
isSlot: false,
|
|
39
|
+
container: widget.container
|
|
40
|
+
}, ...Object.values(slots)];
|
|
41
|
+
widget.$in.component.resolvedViews.set(viewFactory, views);
|
|
42
|
+
return mapResolvedViews(views, callback);
|
|
38
43
|
}
|
|
39
44
|
function mapResolvedViews(views, callback) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
return views.map(({
|
|
46
|
+
View,
|
|
47
|
+
containerSelector,
|
|
48
|
+
isSlot,
|
|
49
|
+
container
|
|
50
|
+
}) => {
|
|
51
|
+
var _document;
|
|
52
|
+
callback({
|
|
53
|
+
View,
|
|
54
|
+
isSlot,
|
|
55
|
+
containerSelector,
|
|
56
|
+
container: containerSelector && ((_document = document) === null || _document === void 0 ? void 0 : _document.querySelector(containerSelector)) || container || null
|
|
49
57
|
});
|
|
58
|
+
});
|
|
50
59
|
}
|
|
51
|
-
|
|
52
60
|
exports.mapViews = mapViews;
|
package/lib/helpers.es9.mjs
CHANGED
|
@@ -4,47 +4,55 @@
|
|
|
4
4
|
* on each them.
|
|
5
5
|
*/
|
|
6
6
|
async function mapViews(widget, viewFactory, callback) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
7
|
+
var _widget$slot;
|
|
8
|
+
if (widget.$in.component.resolvedViews.has(viewFactory)) {
|
|
9
|
+
var _widget$$in$component;
|
|
10
|
+
return mapResolvedViews((_widget$$in$component = widget.$in.component.resolvedViews.get(viewFactory)) !== null && _widget$$in$component !== void 0 ? _widget$$in$component : [], callback);
|
|
11
|
+
}
|
|
12
|
+
const {
|
|
13
|
+
containerSelector
|
|
14
|
+
} = widget;
|
|
15
|
+
const {
|
|
16
|
+
View,
|
|
17
|
+
ErrorView,
|
|
18
|
+
slot = {}
|
|
19
|
+
} = await viewFactory(widget);
|
|
20
|
+
|
|
21
|
+
// Add additional slot information to slot views
|
|
22
|
+
const slots = Object.keys((_widget$slot = widget.slot) !== null && _widget$slot !== void 0 ? _widget$slot : {}).reduce((acc, cur) => {
|
|
23
|
+
var _widget$slot$cur, _widget$slot$cur2;
|
|
24
|
+
acc[cur] = {
|
|
25
|
+
...slot[cur],
|
|
26
|
+
isSlot: true,
|
|
27
|
+
containerSelector: (_widget$slot$cur = widget.slot[cur]) === null || _widget$slot$cur === void 0 ? void 0 : _widget$slot$cur.containerSelector,
|
|
28
|
+
container: (_widget$slot$cur2 = widget.slot[cur]) === null || _widget$slot$cur2 === void 0 ? void 0 : _widget$slot$cur2.container
|
|
29
|
+
};
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
const views = [{
|
|
33
|
+
View,
|
|
34
|
+
ErrorView,
|
|
35
|
+
containerSelector,
|
|
36
|
+
isSlot: false,
|
|
37
|
+
container: widget.container
|
|
38
|
+
}, ...Object.values(slots)];
|
|
39
|
+
widget.$in.component.resolvedViews.set(viewFactory, views);
|
|
40
|
+
return mapResolvedViews(views, callback);
|
|
36
41
|
}
|
|
37
42
|
function mapResolvedViews(views, callback) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
return views.map(({
|
|
44
|
+
View,
|
|
45
|
+
containerSelector,
|
|
46
|
+
isSlot,
|
|
47
|
+
container
|
|
48
|
+
}) => {
|
|
49
|
+
var _document;
|
|
50
|
+
callback({
|
|
51
|
+
View,
|
|
52
|
+
isSlot,
|
|
53
|
+
containerSelector,
|
|
54
|
+
container: containerSelector && ((_document = document) === null || _document === void 0 ? void 0 : _document.querySelector(containerSelector)) || container || null
|
|
47
55
|
});
|
|
56
|
+
});
|
|
48
57
|
}
|
|
49
|
-
|
|
50
58
|
export { mapViews };
|
package/lib/helpers.js
CHANGED
|
@@ -6,45 +6,56 @@
|
|
|
6
6
|
* on each them.
|
|
7
7
|
*/
|
|
8
8
|
async function mapViews(widget, viewFactory, callback) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
if (widget.$in.component.resolvedViews.has(viewFactory)) {
|
|
10
|
+
return mapResolvedViews(
|
|
11
|
+
widget.$in.component.resolvedViews.get(viewFactory) ?? [],
|
|
12
|
+
callback,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { containerSelector } = widget;
|
|
17
|
+
const { View, ErrorView, slot = {} } = await viewFactory(widget);
|
|
18
|
+
|
|
19
|
+
// Add additional slot information to slot views
|
|
20
|
+
const slots = Object.keys(widget.slot ?? {}).reduce((acc, cur) => {
|
|
21
|
+
acc[cur] = {
|
|
22
|
+
...slot[cur],
|
|
23
|
+
isSlot: true,
|
|
24
|
+
containerSelector: widget.slot[cur]?.containerSelector,
|
|
25
|
+
container: widget.slot[cur]?.container,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
|
|
31
|
+
const views = [
|
|
32
|
+
{
|
|
33
|
+
View,
|
|
34
|
+
ErrorView,
|
|
35
|
+
containerSelector,
|
|
36
|
+
isSlot: false,
|
|
37
|
+
container: widget.container,
|
|
38
|
+
},
|
|
39
|
+
...Object.values(slots),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
widget.$in.component.resolvedViews.set(viewFactory, views);
|
|
43
|
+
|
|
44
|
+
return mapResolvedViews(views, callback);
|
|
36
45
|
}
|
|
46
|
+
|
|
37
47
|
function mapResolvedViews(views, callback) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
return views.map(({ View, containerSelector, isSlot, container }) => {
|
|
49
|
+
callback({
|
|
50
|
+
View,
|
|
51
|
+
isSlot,
|
|
52
|
+
containerSelector,
|
|
53
|
+
container:
|
|
54
|
+
(containerSelector && document?.querySelector(containerSelector)) ||
|
|
55
|
+
container ||
|
|
56
|
+
null,
|
|
47
57
|
});
|
|
58
|
+
});
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
exports.mapViews = mapViews;
|
package/lib/helpers.mjs
CHANGED
|
@@ -4,45 +4,56 @@
|
|
|
4
4
|
* on each them.
|
|
5
5
|
*/
|
|
6
6
|
async function mapViews(widget, viewFactory, callback) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
if (widget.$in.component.resolvedViews.has(viewFactory)) {
|
|
8
|
+
return mapResolvedViews(
|
|
9
|
+
widget.$in.component.resolvedViews.get(viewFactory) ?? [],
|
|
10
|
+
callback,
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { containerSelector } = widget;
|
|
15
|
+
const { View, ErrorView, slot = {} } = await viewFactory(widget);
|
|
16
|
+
|
|
17
|
+
// Add additional slot information to slot views
|
|
18
|
+
const slots = Object.keys(widget.slot ?? {}).reduce((acc, cur) => {
|
|
19
|
+
acc[cur] = {
|
|
20
|
+
...slot[cur],
|
|
21
|
+
isSlot: true,
|
|
22
|
+
containerSelector: widget.slot[cur]?.containerSelector,
|
|
23
|
+
container: widget.slot[cur]?.container,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
|
|
29
|
+
const views = [
|
|
30
|
+
{
|
|
31
|
+
View,
|
|
32
|
+
ErrorView,
|
|
33
|
+
containerSelector,
|
|
34
|
+
isSlot: false,
|
|
35
|
+
container: widget.container,
|
|
36
|
+
},
|
|
37
|
+
...Object.values(slots),
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
widget.$in.component.resolvedViews.set(viewFactory, views);
|
|
41
|
+
|
|
42
|
+
return mapResolvedViews(views, callback);
|
|
34
43
|
}
|
|
44
|
+
|
|
35
45
|
function mapResolvedViews(views, callback) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
return views.map(({ View, containerSelector, isSlot, container }) => {
|
|
47
|
+
callback({
|
|
48
|
+
View,
|
|
49
|
+
isSlot,
|
|
50
|
+
containerSelector,
|
|
51
|
+
container:
|
|
52
|
+
(containerSelector && document?.querySelector(containerSelector)) ||
|
|
53
|
+
container ||
|
|
54
|
+
null,
|
|
45
55
|
});
|
|
56
|
+
});
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
export { mapViews };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,r){if("function"==typeof define&&define.amd)define("@merkur/plugin-component",["exports"],r);else if("undefined"!=typeof exports)r(exports);else{var t={exports:{}};r(t.exports),e.Merkur=e.Merkur||{},e.Merkur.Plugin=e.Merkur.Plugin||{},e.Merkur.Plugin.Component=t.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e){function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function t(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return n(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?o(Object(t),!0).forEach((function(r){u(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function u(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==r(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,r,t,n,o,i,u){try{var c=e[i](u),l=c.value}catch(e){return void t(e)}c.done?r(l):Promise.resolve(l).then(n,o)}function l(){var e;return e=function*(e,r,n){var o,u;if(e.$in.component.resolvedViews.has(r))return a(null!==(u=e.$in.component.resolvedViews.get(r))&&void 0!==u?u:[],n);var c=e.containerSelector,l=yield r(e),f=l.View,s=l.ErrorView,p=l.slot,y=void 0===p?{}:p,v=Object.keys(null!==(o=e.slot)&&void 0!==o?o:{}).reduce((function(r,t){var n,o;return r[t]=i(i({},y[t]),{},{isSlot:!0,containerSelector:null===(n=e.slot[t])||void 0===n?void 0:n.containerSelector,container:null===(o=e.slot[t])||void 0===o?void 0:o.container}),r}),{}),b=[{View:f,ErrorView:s,containerSelector:c,isSlot:!1,container:e.container}].concat(t(Object.values(v)));return e.$in.component.resolvedViews.set(r,b),a(b,n)},l=function(){var r=this,t=arguments;return new Promise((function(n,o){var i=e.apply(r,t);function u(e){c(i,n,o,u,l,"next",e)}function l(e){c(i,n,o,u,l,"throw",e)}u(void 0)}))},l.apply(this,arguments)}function a(e,r){return e.map((function(e){var t,n=e.View,o=e.containerSelector,i=e.isSlot,u=e.container;r({View:n,isSlot:i,containerSelector:o,container:o&&(null===(t=document)||void 0===t?void 0:t.querySelector(o))||u||null})}))}Object.defineProperty(e,"__esModule",{value:!0}),e.mapViews=function(e,r,t){return l.apply(this,arguments)}}));
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},n(t)}!function(n,t){if("function"==typeof define&&define.amd)define("@merkur/plugin-component",["exports","@merkur/core"],t);else if("undefined"!=typeof exports)t(exports,require("@merkur/core"));else{var e={exports:{}};t(e.exports,n.Merkur.Core),n.Merkur=n.Merkur||{},n.Merkur.Plugin=n.Merkur.Plugin||{},n.Merkur.Plugin.Component=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t,e){Object.defineProperty(t,"__esModule",{value:!0}),t.componentPlugin=function(){return{setup:function(n,t){return y((function*(){var o=t.info,u=t.bootstrap,a=t.load,f=t.mount,l=t.unmount,p=t.update,m=s(t,r),v={info:o,bootstrap:u,load:a,mount:f,unmount:l,update:p};return n.$in.component={lifeCycle:v,isMounted:!1,isHydrated:!1,suspendedTasks:[],resolvedViews:new Map},(0,e.assignMissingKeys)(n,{info:function(n){var t=arguments;return y((function*(){for(var e=n.name,r=n.version,o=n.props,u=n.state,i=n.assets,a=n.containerSelector,f=t.length,l=new Array(f>1?f-1:0),s=1;s<f;s++)l[s-1]=t[s];return c({name:e,version:r,props:o,state:u,assets:i,containerSelector:a},(yield d(n,"info",l))||{})}))()},mount:function(n){var t=arguments;return y((function*(){for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];yield n.bootstrap.apply(n,r),yield n.load.apply(n,r);var u=yield d(n,"mount",r);n.$in.component.isMounted=!0;var a,f=function(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(!e){if(Array.isArray(n)||(e=i(n))||t&&n&&"number"==typeof n.length){e&&(n=e);var r=0,o=function(){};return{s:o,n:function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}},e:function(n){throw n},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,a=!0,f=!1;return{s:function(){e=e.call(n)},n:function(){var n=e.next();return a=n.done,n},e:function(n){f=!0,u=n},f:function(){try{a||null==e.return||e.return()}finally{if(f)throw u}}}}(n.$in.component.suspendedTasks);try{for(f.s();!(a=f.n()).done;){var c=a.value;yield c()}}catch(n){f.e(n)}finally{f.f()}return u}))()},unmount:function(n){var t=arguments;return y((function*(){n.$in.component.isMounted=!1,n.$in.component.isHydrated=!1;for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];return d(n,"unmount",r)}))()},bootstrap:function(n){var t=arguments;return y((function*(){for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];return d(n,"bootstrap",r)}))()},load:function(n){var t=arguments;return y((function*(){var e=n.$in,r=n.state;if(!1===e.component.isMounted&&!1===e.component.isHydrated&&r&&0!==Object.keys(r).length)e.component.isHydrated=!0;else{for(var o=t.length,u=new Array(o>1?o-1:0),i=1;i<o;i++)u[i-1]=t[i];n.state=yield d(n,"load",u)}}))()},update:function(n){var t=arguments;return y((function*(){for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];if(n.$in.component.isMounted)return d(n,"update",r);n.$in.component.suspendedTasks.push((function(){return n.update.apply(n,r)}))}))()},setState:function(n,t){return y((function*(){return n.state=c(c({},n.state),"function"==typeof t?t(n.state):t),n.update()}))()},setProps:function(n,t){return y((function*(){if(n.$in.component.isMounted)return n.props=c(c({},n.props),"function"==typeof t?t(n.props):t),yield n.load(),n.update();n.$in.component.suspendedTasks.push((function(){return n.setProps(t)}))}))()}},m),n=(0,e.setDefaultValueForUndefined)(n,["props","state"]),n=(0,e.setDefaultValueForUndefined)(n,["assets"],[]),n=(0,e.setDefaultValueForUndefined)(n,["containerSelector"],null)}))()},create:function(n){return n}}},t.createSlotFactory=function(n){return function(){var t=y((function*(t){return n(t)}));return function(n){return t.apply(this,arguments)}}()},t.createViewFactory=function(n){return function(){var t=y((function*(t){var e=yield n(t),r=e.slotFactories,u=s(e,o);if(!r)return c({},u);var i=(yield Promise.all(r.map((function(n){return n(t)})))).reduce((function(n,t){return n[t.name]=t,n}),{});return c(c({},u),{},{slot:i})}));return function(n){return t.apply(this,arguments)}}()};var r=["info","bootstrap","load","mount","unmount","update"],o=["slotFactories"];function u(n){return function(n){if(Array.isArray(n))return a(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||i(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(n,t){if(n){if("string"==typeof n)return a(n,t);var e=
|
|
1
|
+
function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},n(t)}!function(n,t){if("function"==typeof define&&define.amd)define("@merkur/plugin-component",["exports","@merkur/core"],t);else if("undefined"!=typeof exports)t(exports,require("@merkur/core"));else{var e={exports:{}};t(e.exports,n.Merkur.Core),n.Merkur=n.Merkur||{},n.Merkur.Plugin=n.Merkur.Plugin||{},n.Merkur.Plugin.Component=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t,e){Object.defineProperty(t,"__esModule",{value:!0}),t.componentPlugin=function(){return{setup:function(n,t){return y((function*(){var o=t.info,u=t.bootstrap,a=t.load,f=t.mount,l=t.unmount,p=t.update,m=s(t,r),v={info:o,bootstrap:u,load:a,mount:f,unmount:l,update:p};return n.$in.component={lifeCycle:v,isMounted:!1,isHydrated:!1,suspendedTasks:[],resolvedViews:new Map},(0,e.assignMissingKeys)(n,{info:function(n){var t=arguments;return y((function*(){for(var e=n.name,r=n.version,o=n.props,u=n.state,i=n.assets,a=n.containerSelector,f=t.length,l=new Array(f>1?f-1:0),s=1;s<f;s++)l[s-1]=t[s];return c({name:e,version:r,props:o,state:u,assets:i,containerSelector:a},(yield d(n,"info",l))||{})}))()},mount:function(n){var t=arguments;return y((function*(){for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];yield n.bootstrap.apply(n,r),yield n.load.apply(n,r);var u=yield d(n,"mount",r);n.$in.component.isMounted=!0;var a,f=function(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(!e){if(Array.isArray(n)||(e=i(n))||t&&n&&"number"==typeof n.length){e&&(n=e);var r=0,o=function(){};return{s:o,n:function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}},e:function(n){throw n},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,a=!0,f=!1;return{s:function(){e=e.call(n)},n:function(){var n=e.next();return a=n.done,n},e:function(n){f=!0,u=n},f:function(){try{a||null==e.return||e.return()}finally{if(f)throw u}}}}(n.$in.component.suspendedTasks);try{for(f.s();!(a=f.n()).done;){var c=a.value;yield c()}}catch(n){f.e(n)}finally{f.f()}return u}))()},unmount:function(n){var t=arguments;return y((function*(){n.$in.component.isMounted=!1,n.$in.component.isHydrated=!1;for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];return d(n,"unmount",r)}))()},bootstrap:function(n){var t=arguments;return y((function*(){for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];return d(n,"bootstrap",r)}))()},load:function(n){var t=arguments;return y((function*(){var e=n.$in,r=n.state;if(!1===e.component.isMounted&&!1===e.component.isHydrated&&r&&0!==Object.keys(r).length)e.component.isHydrated=!0;else{for(var o=t.length,u=new Array(o>1?o-1:0),i=1;i<o;i++)u[i-1]=t[i];n.state=yield d(n,"load",u)}}))()},update:function(n){var t=arguments;return y((function*(){for(var e=t.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=t[o];if(n.$in.component.isMounted)return d(n,"update",r);n.$in.component.suspendedTasks.push((function(){return n.update.apply(n,r)}))}))()},setState:function(n,t){return y((function*(){return n.state=c(c({},n.state),"function"==typeof t?t(n.state):t),n.update()}))()},setProps:function(n,t){return y((function*(){if(n.$in.component.isMounted)return n.props=c(c({},n.props),"function"==typeof t?t(n.props):t),yield n.load(),n.update();n.$in.component.suspendedTasks.push((function(){return n.setProps(t)}))}))()}},m),n=(0,e.setDefaultValueForUndefined)(n,["props","state"]),n=(0,e.setDefaultValueForUndefined)(n,["assets"],[]),n=(0,e.setDefaultValueForUndefined)(n,["containerSelector"],null)}))()},create:function(n){return n}}},t.createSlotFactory=function(n){return function(){var t=y((function*(t){return n(t)}));return function(n){return t.apply(this,arguments)}}()},t.createViewFactory=function(n){return function(){var t=y((function*(t){var e=yield n(t),r=e.slotFactories,u=s(e,o);if(!r)return c({},u);var i=(yield Promise.all(r.map((function(n){return n(t)})))).reduce((function(n,t){return n[t.name]=t,n}),{});return c(c({},u),{},{slot:i})}));return function(n){return t.apply(this,arguments)}}()};var r=["info","bootstrap","load","mount","unmount","update"],o=["slotFactories"];function u(n){return function(n){if(Array.isArray(n))return a(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||i(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(n,t){if(n){if("string"==typeof n)return a(n,t);var e={}.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(n,t):void 0}}function a(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=Array(t);e<t;e++)r[e]=n[e];return r}function f(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),e.push.apply(e,r)}return e}function c(n){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?f(Object(e),!0).forEach((function(t){l(n,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):f(Object(e)).forEach((function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(e,t))}))}return n}function l(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(n,t){if(null==n)return{};var e,r,o=function(n,t){if(null==n)return{};var e={};for(var r in n)if({}.hasOwnProperty.call(n,r)){if(t.includes(r))continue;e[r]=n[r]}return e}(n,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(n);for(r=0;r<u.length;r++)e=u[r],t.includes(e)||{}.propertyIsEnumerable.call(n,e)&&(o[e]=n[e])}return o}function p(n,t,e,r,o,u,i){try{var a=n[u](i),f=a.value}catch(n){return void e(n)}a.done?t(f):Promise.resolve(f).then(r,o)}function y(n){return function(){var t=this,e=arguments;return new Promise((function(r,o){var u=n.apply(t,e);function i(n){p(u,r,o,i,a,"next",n)}function a(n){p(u,r,o,i,a,"throw",n)}i(void 0)}))}}function d(n,t,e){return m.apply(this,arguments)}function m(){return(m=y((function*(n,t,e){var r=n.$in.component.lifeCycle;if("function"==typeof r[t])return r[t].apply(r,[n].concat(u(e)))}))).apply(this,arguments)}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/plugin-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Merkur component plugin.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"require": "./lib/index.cjs"
|
|
15
15
|
},
|
|
16
16
|
"./helpers": {
|
|
17
|
-
"types": "./
|
|
17
|
+
"types": "./helpers.d.ts",
|
|
18
18
|
"import": "./lib/helpers.mjs",
|
|
19
19
|
"require": "./lib/helpers.cjs"
|
|
20
20
|
},
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://merkur.js.org/",
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@merkur/core": "^0.
|
|
64
|
+
"@merkur/core": "^0.37.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@merkur/core": "*"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "af826493e5ed4b37602dd43ce89a59baeeb1bada"
|
|
70
70
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -2,22 +2,24 @@ import {
|
|
|
2
2
|
createRollupESConfig,
|
|
3
3
|
createRollupES9Config,
|
|
4
4
|
createRollupUMDConfig,
|
|
5
|
-
createRollupTypescriptES9Config,
|
|
6
|
-
createRollupTypescriptConfig,
|
|
7
5
|
} from '../../createRollupConfig.mjs';
|
|
8
6
|
|
|
9
7
|
let esConfig = createRollupESConfig();
|
|
10
8
|
let es9Config = createRollupES9Config();
|
|
11
9
|
let umdConfig = createRollupUMDConfig();
|
|
12
10
|
|
|
11
|
+
let helpersConfig = createRollupESConfig();
|
|
12
|
+
let helpersES9Config = createRollupES9Config();
|
|
13
|
+
let umdHelpersConfig = createRollupUMDConfig();
|
|
14
|
+
helpersConfig.input = './src/helpers.js';
|
|
15
|
+
helpersES9Config.input = './src/helpers.js';
|
|
16
|
+
umdHelpersConfig.input = './src/helpers.js';
|
|
17
|
+
|
|
13
18
|
export default [
|
|
14
19
|
esConfig,
|
|
15
20
|
es9Config,
|
|
16
21
|
umdConfig,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
createRollupTypescriptES9Config({
|
|
21
|
-
input: './src/helpers.ts',
|
|
22
|
-
}),
|
|
22
|
+
helpersConfig,
|
|
23
|
+
helpersES9Config,
|
|
24
|
+
umdHelpersConfig,
|
|
23
25
|
];
|
package/types.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type MapViewArgs = {
|
|
|
22
22
|
|
|
23
23
|
export type SSRMountResult = {
|
|
24
24
|
html: string;
|
|
25
|
-
slot: Record<string, { name: string; html: string }>;
|
|
25
|
+
slot: Record<string, { name: string; html: string, containerSelector?: string }>;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export interface WidgetState {}
|
|
@@ -91,6 +91,7 @@ export interface ViewFactoryResult {
|
|
|
91
91
|
|
|
92
92
|
export interface ViewFactorySlotType {
|
|
93
93
|
name: string;
|
|
94
|
+
containerSelector?: string,
|
|
94
95
|
View: ViewType;
|
|
95
96
|
}
|
|
96
97
|
|
package/lib/helpers.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Widget } from '@merkur/core';
|
|
2
|
-
import { ViewFactory, ViewFactorySlotType, ViewType } from '@merkur/plugin-component';
|
|
3
|
-
export type MapViewArgs = {
|
|
4
|
-
View: ViewType;
|
|
5
|
-
ErrorView?: ViewType;
|
|
6
|
-
containerSelector: string;
|
|
7
|
-
container: Element | null;
|
|
8
|
-
isSlot: boolean;
|
|
9
|
-
slot?: Record<string, {
|
|
10
|
-
isSlot: boolean;
|
|
11
|
-
containerSelector?: string;
|
|
12
|
-
container?: Element;
|
|
13
|
-
} & ViewFactorySlotType>;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Utility function to iterate thorugh views returned from
|
|
17
|
-
* view factory and call callback function with view arguments
|
|
18
|
-
* on each them.
|
|
19
|
-
*/
|
|
20
|
-
export declare function mapViews<T>(widget: Widget, viewFactory: ViewFactory, callback: (viewArgs: MapViewArgs) => T): Promise<void[]>;
|
package/lib/helpers.es9.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Utility function to iterate thorugh views returned from
|
|
5
|
-
* view factory and call callback function with view arguments
|
|
6
|
-
* on each them.
|
|
7
|
-
*/
|
|
8
|
-
async function mapViews(widget, viewFactory, callback) {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
if (widget.$in.component.resolvedViews.has(viewFactory)) {
|
|
11
|
-
return mapResolvedViews((_a = widget.$in.component.resolvedViews.get(viewFactory)) !== null && _a !== void 0 ? _a : [], callback);
|
|
12
|
-
}
|
|
13
|
-
const { containerSelector } = widget;
|
|
14
|
-
const { View, ErrorView, slot = {} } = await viewFactory(widget);
|
|
15
|
-
// Add additional slot information to slot views
|
|
16
|
-
const slots = Object.keys((_b = widget.slot) !== null && _b !== void 0 ? _b : {}).reduce((acc, cur) => {
|
|
17
|
-
var _a, _b;
|
|
18
|
-
acc[cur] = {
|
|
19
|
-
...slot[cur],
|
|
20
|
-
isSlot: true,
|
|
21
|
-
containerSelector: (_a = widget.slot[cur]) === null || _a === void 0 ? void 0 : _a.containerSelector,
|
|
22
|
-
container: (_b = widget.slot[cur]) === null || _b === void 0 ? void 0 : _b.container,
|
|
23
|
-
};
|
|
24
|
-
return acc;
|
|
25
|
-
}, {});
|
|
26
|
-
const views = [
|
|
27
|
-
{
|
|
28
|
-
View,
|
|
29
|
-
ErrorView,
|
|
30
|
-
containerSelector,
|
|
31
|
-
isSlot: false,
|
|
32
|
-
container: widget.container,
|
|
33
|
-
},
|
|
34
|
-
...Object.values(slots),
|
|
35
|
-
];
|
|
36
|
-
widget.$in.component.resolvedViews.set(viewFactory, views);
|
|
37
|
-
return mapResolvedViews(views, callback);
|
|
38
|
-
}
|
|
39
|
-
function mapResolvedViews(views, callback) {
|
|
40
|
-
return views.map(({ View, containerSelector, isSlot, container }) => {
|
|
41
|
-
callback({
|
|
42
|
-
View,
|
|
43
|
-
isSlot,
|
|
44
|
-
containerSelector,
|
|
45
|
-
container: (containerSelector && (document === null || document === void 0 ? void 0 : document.querySelector(containerSelector))) ||
|
|
46
|
-
container ||
|
|
47
|
-
null,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
exports.mapViews = mapViews;
|