@merkur/create-widget 0.34.6 → 0.35.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/bin/createWidget.mjs +1 -1
- package/package.json +2 -2
- package/template/jest.config.js +4 -0
- package/template/merkur.config.mjs +3 -0
- package/template/package.json +16 -21
- package/template/server/__integration__/appSpec.js +1 -7
- package/template/server/app.js +8 -17
- package/template/server/config/default.json +0 -4
- package/template/server/config/production.json +0 -3
- package/template/server/routes/widgetAPI/widgetAPI.js +14 -8
- package/template/server/server.js +6 -7
- package/template/src/widget.js +4 -6
- package/views/preact/template/jest.config.js +3 -0
- package/views/preact/template/merkur.config.mjs +5 -0
- package/views/preact/template/src/slots/HeadlineSlot.jsx +0 -8
- package/views/preact/template/src/views/View.jsx +1 -19
- package/views/preact/template/src/views/__tests__/ViewSpec.jsx +1 -1
- package/views/preact/template/src/widget.js +56 -0
- package/views/preact/template.json +3 -5
- package/views/svelte/template/merkur.config.mjs +5 -0
- package/views/svelte/template/src/widget.js +56 -0
- package/views/svelte/template/webpack.config.js +18 -42
- package/views/svelte/template.json +3 -4
- package/views/uhtml/template/merkur.config.mjs +5 -0
- package/views/uhtml/template/src/slots/HeadlineSlot.js +0 -8
- package/views/uhtml/template/src/views/View.js +0 -18
- package/views/uhtml/template/src/widget.js +56 -0
- package/views/uhtml/template/webpack.config.js +9 -3
- package/views/uhtml/template.json +2 -3
- package/views/vanilla/template/src/{client.js → entries/client.js} +4 -4
- package/views/vanilla/template/src/{server.js → entries/server.js} +2 -2
- package/template/nodemon.json +0 -14
- package/template/server/routes/playground/index.js +0 -3
- package/template/server/routes/playground/playground.ejs +0 -46
- package/template/server/routes/playground/playground.js +0 -48
- package/template/server/routes/utils.js +0 -14
- package/template/src/lib/utils.js +0 -39
- package/template/src/polyfill.es5.js +0 -0
- package/template/src/polyfill.es9.js +0 -0
- package/views/preact/template/babel.config.js +0 -13
- package/views/preact/template/src/client.js +0 -56
- package/views/preact/template/src/server.js +0 -31
- package/views/preact/template/webpack.config.js +0 -60
- package/views/svelte/template/src/client.js +0 -65
- package/views/svelte/template/src/server.js +0 -32
- package/views/svelte/template/src/slots/headlineSlotFactory.js +0 -10
- package/views/svelte/template/src/views/viewFactory.js +0 -19
- package/views/uhtml/template/src/client.js +0 -51
- package/views/uhtml/template/src/server.js +0 -31
- package/views/vanilla/template/webpack.config.js +0 -16
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import Counter from '../components/Counter';
|
|
2
|
-
import { headlineSlotFactory } from '../slots/HeadlineSlot';
|
|
3
2
|
import ErrorView from './ErrorView';
|
|
4
3
|
|
|
5
|
-
async function viewFactory(widget) {
|
|
6
|
-
const slot = (await Promise.all([headlineSlotFactory(widget)])).reduce(
|
|
7
|
-
(acc, cur) => {
|
|
8
|
-
acc[cur.name] = cur;
|
|
9
|
-
|
|
10
|
-
return acc;
|
|
11
|
-
},
|
|
12
|
-
{},
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
View,
|
|
17
|
-
slot,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
4
|
function View(widget) {
|
|
22
5
|
if (widget.error && widget.error.status) {
|
|
23
6
|
return ErrorView(widget);
|
|
@@ -32,5 +15,4 @@ function View(widget) {
|
|
|
32
15
|
`;
|
|
33
16
|
}
|
|
34
17
|
|
|
35
|
-
export { viewFactory };
|
|
36
18
|
export default View;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import { defineWidget } from '@merkur/core';
|
|
3
|
+
import {
|
|
4
|
+
componentPlugin,
|
|
5
|
+
createViewFactory,
|
|
6
|
+
createSlotFactory,
|
|
7
|
+
} from '@merkur/plugin-component';
|
|
8
|
+
import { errorPlugin } from '@merkur/plugin-error';
|
|
9
|
+
import { eventEmitterPlugin } from '@merkur/plugin-event-emitter';
|
|
10
|
+
|
|
11
|
+
import HeadlineSlot from './slots/HeadlineSlot';
|
|
12
|
+
import View from './views/View';
|
|
13
|
+
|
|
14
|
+
import pkg from '../package.json';
|
|
15
|
+
|
|
16
|
+
import './style.css';
|
|
17
|
+
|
|
18
|
+
export default defineWidget({
|
|
19
|
+
name: pkg.name,
|
|
20
|
+
version: pkg.version,
|
|
21
|
+
viewFactory: createViewFactory((widget) => ({
|
|
22
|
+
View,
|
|
23
|
+
slotFactories: [
|
|
24
|
+
createSlotFactory((widget) => ({
|
|
25
|
+
name: 'headline',
|
|
26
|
+
View: HeadlineSlot,
|
|
27
|
+
})),
|
|
28
|
+
],
|
|
29
|
+
})),
|
|
30
|
+
$plugins: [componentPlugin, eventEmitterPlugin, errorPlugin],
|
|
31
|
+
assets: [
|
|
32
|
+
{
|
|
33
|
+
name: 'widget.js',
|
|
34
|
+
type: 'script',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'widget.css',
|
|
38
|
+
type: 'stylesheet',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
onClick(widget) {
|
|
42
|
+
widget.setState({ counter: widget.state.counter + 1 });
|
|
43
|
+
},
|
|
44
|
+
onReset(widget) {
|
|
45
|
+
widget.setState({ counter: 0 });
|
|
46
|
+
},
|
|
47
|
+
load(widget) {
|
|
48
|
+
// We don't want to set environment into app state
|
|
49
|
+
const { environment, ...restProps } = widget.props;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
counter: 0,
|
|
53
|
+
...restProps,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { applyUHtmlConfig } = require('@merkur/uhtml/webpack');
|
|
1
2
|
const {
|
|
2
3
|
createLiveReloadServer,
|
|
3
4
|
createWebConfig,
|
|
@@ -9,8 +10,13 @@ const {
|
|
|
9
10
|
|
|
10
11
|
module.exports = createLiveReloadServer().then(() =>
|
|
11
12
|
Promise.all([
|
|
12
|
-
pipe(createWebConfig, applyStyleLoaders)(),
|
|
13
|
-
pipe(
|
|
14
|
-
|
|
13
|
+
pipe(createWebConfig, applyUHtmlConfig, applyStyleLoaders)(),
|
|
14
|
+
pipe(
|
|
15
|
+
createWebConfig,
|
|
16
|
+
applyUHtmlConfig,
|
|
17
|
+
applyStyleLoaders,
|
|
18
|
+
applyES9Transformation,
|
|
19
|
+
)(),
|
|
20
|
+
pipe(createNodeConfig, applyUHtmlConfig, applyStyleLoaders)(),
|
|
15
21
|
]),
|
|
16
22
|
);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createMerkurWidget, createMerkur } from '@merkur/core';
|
|
2
2
|
|
|
3
|
-
import { mapViews } from '
|
|
4
|
-
import { viewFactory } from '
|
|
5
|
-
import widgetProperties from '
|
|
3
|
+
import { mapViews } from '@merkur/plugin-component/helpers';
|
|
4
|
+
import { viewFactory } from '../views/View';
|
|
5
|
+
import widgetProperties from '@widget';
|
|
6
6
|
|
|
7
|
-
import '
|
|
7
|
+
import '../style.css';
|
|
8
8
|
|
|
9
9
|
function createWidget(widgetParams) {
|
|
10
10
|
return createMerkurWidget({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createMerkurWidget } from '@merkur/core';
|
|
2
2
|
|
|
3
|
-
import { viewFactory } from '
|
|
4
|
-
import widgetProperties from '
|
|
3
|
+
import { viewFactory } from '../views/View';
|
|
4
|
+
import widgetProperties from '@widget';
|
|
5
5
|
|
|
6
6
|
export function createWidget(widgetParams) {
|
|
7
7
|
return createMerkurWidget({
|
package/template/nodemon.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
7
|
-
<script>
|
|
8
|
-
window.__merkur_dev__ = window.__merkur_dev__ || {};
|
|
9
|
-
window.__merkur_dev__.webSocketOptions = {
|
|
10
|
-
url: `ws://localhost:${<%- process.env.MERKUR_PLAYGROUND_LIVERELOAD_PORT %>}`
|
|
11
|
-
};
|
|
12
|
-
</script>
|
|
13
|
-
<script src="/@merkur/tools/static/livereload.js"></script>
|
|
14
|
-
<% assets.forEach((asset) => { %>
|
|
15
|
-
<%if (asset.type === 'stylesheet') { %>
|
|
16
|
-
<link rel='stylesheet' href='<%= asset.source %>' />
|
|
17
|
-
<% } %>
|
|
18
|
-
<%if (asset.type === 'script') { %>
|
|
19
|
-
<%if (typeof asset.source === 'string') { %>
|
|
20
|
-
<script src='<%= asset.source %>' defer='true'></script>
|
|
21
|
-
<% } %>
|
|
22
|
-
<%if (typeof asset.source === 'object') { %>
|
|
23
|
-
<script src='<%= asset.source.es11 %>' defer='true'></script>
|
|
24
|
-
<% } %>
|
|
25
|
-
<% } %>
|
|
26
|
-
<% }); %>
|
|
27
|
-
<title>MERKUR - widget</title>
|
|
28
|
-
</head>
|
|
29
|
-
|
|
30
|
-
<body>
|
|
31
|
-
<div class="headline-view"><%- widgetProperties && widgetProperties.slot && widgetProperties.slot.headline.html %></div>
|
|
32
|
-
<div class="merkur-view"><%- html %></div>
|
|
33
|
-
<script>
|
|
34
|
-
window.addEventListener('load', function () {
|
|
35
|
-
__merkur__.create(<%- JSON.stringify(widgetProperties) %>)
|
|
36
|
-
.then(function (widget) {
|
|
37
|
-
widget.containerSelector = '.merkur-view';
|
|
38
|
-
widget.slot.headline.containerSelector = '.headline-view';
|
|
39
|
-
|
|
40
|
-
widget.mount();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
</script>
|
|
44
|
-
</body>
|
|
45
|
-
|
|
46
|
-
</html>
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const ejs = require('ejs');
|
|
5
|
-
const express = require('express');
|
|
6
|
-
const got = require('got');
|
|
7
|
-
|
|
8
|
-
const { playgroundErrorMiddleware } = require('@merkur/plugin-error/server');
|
|
9
|
-
|
|
10
|
-
const { asyncMiddleware, getServerUrl } = require('../utils');
|
|
11
|
-
|
|
12
|
-
const playgroundTemplate = ejs.compile(
|
|
13
|
-
fs.readFileSync(path.join(__dirname, '/playground.ejs'), 'utf8'),
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const router = express.Router();
|
|
17
|
-
|
|
18
|
-
router
|
|
19
|
-
.get(
|
|
20
|
-
'/',
|
|
21
|
-
asyncMiddleware(async (req, res) => {
|
|
22
|
-
const widgetProperties = await got(`${getServerUrl(req)}/widget`, {
|
|
23
|
-
retry: 0,
|
|
24
|
-
responseType: 'json',
|
|
25
|
-
searchParams: {
|
|
26
|
-
name: 'merkur',
|
|
27
|
-
counter: 0,
|
|
28
|
-
},
|
|
29
|
-
}).json();
|
|
30
|
-
|
|
31
|
-
const { html, assets, ...restProperties } = widgetProperties;
|
|
32
|
-
|
|
33
|
-
res.status(200).send(
|
|
34
|
-
playgroundTemplate({
|
|
35
|
-
widgetProperties: restProperties,
|
|
36
|
-
assets,
|
|
37
|
-
html,
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
}),
|
|
41
|
-
)
|
|
42
|
-
.use(
|
|
43
|
-
playgroundErrorMiddleware({
|
|
44
|
-
renderPlayground: playgroundTemplate,
|
|
45
|
-
}),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
module.exports = () => ({ router });
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
function asyncMiddleware(fn) {
|
|
2
|
-
return (req, res, next) => {
|
|
3
|
-
Promise.resolve(fn(req, res, next)).catch(next);
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function getServerUrl(req) {
|
|
8
|
-
return (req.secure ? 'https' : 'http') + '://' + req.headers.host;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
asyncMiddleware,
|
|
13
|
-
getServerUrl,
|
|
14
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
function mapViews(widget, factoryFn, callback) {
|
|
2
|
-
if (widget.$external.resolvedViews) {
|
|
3
|
-
return mapResolvedViews(widget, callback);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return factoryFn(widget).then(({ View, slot = {} }) => {
|
|
7
|
-
const { containerSelector } = widget;
|
|
8
|
-
// Add container selectors defined on widget instance after creation
|
|
9
|
-
Object.keys(widget.slot).forEach((slotName) => {
|
|
10
|
-
slot[slotName].isSlot = true;
|
|
11
|
-
slot[slotName].containerSelector =
|
|
12
|
-
widget.slot[slotName].containerSelector;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
widget.$external.resolvedViews = [
|
|
16
|
-
{ View, containerSelector, isSlot: false },
|
|
17
|
-
...Object.values(slot),
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
return mapResolvedViews(widget, callback);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function mapResolvedViews(widget, callback) {
|
|
25
|
-
return widget.$external.resolvedViews.map(
|
|
26
|
-
({ View, containerSelector, isSlot }) => {
|
|
27
|
-
callback({
|
|
28
|
-
View,
|
|
29
|
-
isSlot,
|
|
30
|
-
containerSelector,
|
|
31
|
-
container:
|
|
32
|
-
(containerSelector && document?.querySelector(containerSelector)) ||
|
|
33
|
-
widget.container,
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { mapViews };
|
|
File without changes
|
|
File without changes
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { render, hydrate } from 'preact';
|
|
2
|
-
import { unmountComponentAtNode } from 'preact/compat';
|
|
3
|
-
|
|
4
|
-
import { createMerkurWidget, createMerkur } from '@merkur/core';
|
|
5
|
-
|
|
6
|
-
import { mapViews } from './lib/utils';
|
|
7
|
-
import { viewFactory } from './views/View.jsx';
|
|
8
|
-
import widgetProperties from './widget';
|
|
9
|
-
|
|
10
|
-
import './style.css';
|
|
11
|
-
|
|
12
|
-
function createWidget(widgetParams) {
|
|
13
|
-
return createMerkurWidget({
|
|
14
|
-
...widgetProperties,
|
|
15
|
-
...widgetParams,
|
|
16
|
-
$dependencies: {
|
|
17
|
-
render,
|
|
18
|
-
hydrate,
|
|
19
|
-
unmountComponentAtNode,
|
|
20
|
-
},
|
|
21
|
-
async mount(widget) {
|
|
22
|
-
return mapViews(widget, viewFactory, ({ View, container, isSlot }) => {
|
|
23
|
-
if (!container) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
container?.children?.length && !isSlot
|
|
29
|
-
? widget.$dependencies.hydrate
|
|
30
|
-
: widget.$dependencies.render
|
|
31
|
-
)(View(widget), container);
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
async unmount(widget) {
|
|
35
|
-
mapViews(widget, viewFactory, ({ container }) => {
|
|
36
|
-
if (container) {
|
|
37
|
-
widget.$dependencies.unmountComponentAtNode(container);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
async update(widget) {
|
|
42
|
-
return mapViews(
|
|
43
|
-
widget,
|
|
44
|
-
viewFactory,
|
|
45
|
-
({ View, container }) =>
|
|
46
|
-
container && widget.$dependencies.render(View(widget), container),
|
|
47
|
-
);
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const merkur = createMerkur();
|
|
53
|
-
merkur.register({
|
|
54
|
-
...widgetProperties,
|
|
55
|
-
createWidget,
|
|
56
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import render from 'preact-render-to-string';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import { viewFactory } from './views/View';
|
|
6
|
-
import widgetProperties from './widget';
|
|
7
|
-
|
|
8
|
-
export function createWidget(widgetParams) {
|
|
9
|
-
return createMerkurWidget({
|
|
10
|
-
...widgetProperties,
|
|
11
|
-
...widgetParams,
|
|
12
|
-
$dependencies: {
|
|
13
|
-
render,
|
|
14
|
-
},
|
|
15
|
-
async mount(widget) {
|
|
16
|
-
const { View, slot = {} } = await viewFactory(widget);
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
html: widget.$dependencies.render(View(widget)),
|
|
20
|
-
slot: Object.keys(slot).reduce((acc, cur) => {
|
|
21
|
-
acc[cur] = {
|
|
22
|
-
name: slot[cur].name,
|
|
23
|
-
html: widget.$dependencies.render(slot[cur].View(widget)),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return acc;
|
|
27
|
-
}, {}),
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
createLiveReloadServer,
|
|
3
|
-
createWebConfig,
|
|
4
|
-
createNodeConfig,
|
|
5
|
-
applyES9Transformation,
|
|
6
|
-
applyStyleLoaders,
|
|
7
|
-
createCacheKey,
|
|
8
|
-
pipe,
|
|
9
|
-
} = require('@merkur/tool-webpack');
|
|
10
|
-
|
|
11
|
-
function applyBabelLoader(config, { isProduction, environment, cache }) {
|
|
12
|
-
config.module.rules.push({
|
|
13
|
-
test: /\.(js|ts|tsx|mjs|jsx)$/,
|
|
14
|
-
exclude: (modulePath) =>
|
|
15
|
-
/node_modules/.test(modulePath) &&
|
|
16
|
-
!/node_modules\/(abort-controller|event-target-shim)/.test(modulePath),
|
|
17
|
-
use: {
|
|
18
|
-
loader: 'babel-loader',
|
|
19
|
-
options: {
|
|
20
|
-
presets: [
|
|
21
|
-
[
|
|
22
|
-
'@babel/preset-react',
|
|
23
|
-
{
|
|
24
|
-
runtime: 'automatic',
|
|
25
|
-
importSource: 'preact',
|
|
26
|
-
development: !isProduction,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
],
|
|
30
|
-
cacheIdentifier: createCacheKey(
|
|
31
|
-
environment,
|
|
32
|
-
config?.name,
|
|
33
|
-
...(cache?.versionDependencies ?? []),
|
|
34
|
-
),
|
|
35
|
-
cacheDirectory: true,
|
|
36
|
-
cacheCompression: false,
|
|
37
|
-
compact: isProduction,
|
|
38
|
-
sourceMaps: !isProduction,
|
|
39
|
-
inputSourceMap: !isProduction,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return config;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = createLiveReloadServer().then(() =>
|
|
48
|
-
Promise.all([
|
|
49
|
-
pipe(createWebConfig, applyStyleLoaders, applyBabelLoader)(),
|
|
50
|
-
pipe(
|
|
51
|
-
createWebConfig,
|
|
52
|
-
applyStyleLoaders,
|
|
53
|
-
applyBabelLoader,
|
|
54
|
-
applyES9Transformation,
|
|
55
|
-
)(),
|
|
56
|
-
pipe(createNodeConfig, applyStyleLoaders, applyBabelLoader)(),
|
|
57
|
-
]),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
module.exports.applyBabelLoader = applyBabelLoader;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { createMerkurWidget, createMerkur } from '@merkur/core';
|
|
2
|
-
|
|
3
|
-
import { mapViews } from './lib/utils';
|
|
4
|
-
import { viewFactory } from './views/viewFactory';
|
|
5
|
-
import widgetProperties from './widget';
|
|
6
|
-
|
|
7
|
-
import './style.css';
|
|
8
|
-
|
|
9
|
-
function createWidget(widgetParams) {
|
|
10
|
-
return createMerkurWidget({
|
|
11
|
-
...widgetProperties,
|
|
12
|
-
...widgetParams,
|
|
13
|
-
$dependencies: {},
|
|
14
|
-
async mount(widget) {
|
|
15
|
-
widget.$external.app = {};
|
|
16
|
-
|
|
17
|
-
mapViews(
|
|
18
|
-
widget,
|
|
19
|
-
viewFactory,
|
|
20
|
-
({ containerSelector, container, View }) => {
|
|
21
|
-
if (!container) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
widget.$external.app[containerSelector] = new View({
|
|
26
|
-
target: document.querySelector(containerSelector),
|
|
27
|
-
props: {
|
|
28
|
-
widget,
|
|
29
|
-
state: widget.state,
|
|
30
|
-
props: widget.props,
|
|
31
|
-
},
|
|
32
|
-
hydrate: !!container?.children?.length,
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
},
|
|
37
|
-
async unmount(widget) {
|
|
38
|
-
mapViews(widget, viewFactory, ({ containerSelector }) => {
|
|
39
|
-
if (!widget.$external.app[containerSelector]) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
widget.$external.app[containerSelector].$destroy();
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
async update(widget) {
|
|
47
|
-
mapViews(widget, viewFactory, ({ containerSelector }) => {
|
|
48
|
-
if (!widget.$external.app[containerSelector]) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
widget.$external.app[containerSelector].$set({
|
|
53
|
-
state: widget.state,
|
|
54
|
-
props: widget.props,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const merkur = createMerkur();
|
|
62
|
-
merkur.register({
|
|
63
|
-
...widgetProperties,
|
|
64
|
-
createWidget,
|
|
65
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createMerkurWidget } from '@merkur/core';
|
|
2
|
-
|
|
3
|
-
import { viewFactory } from './views/viewFactory';
|
|
4
|
-
import widgetProperties from './widget';
|
|
5
|
-
|
|
6
|
-
export function createWidget(widgetParams) {
|
|
7
|
-
return createMerkurWidget({
|
|
8
|
-
...widgetProperties,
|
|
9
|
-
...widgetParams,
|
|
10
|
-
$dependencies: {},
|
|
11
|
-
async mount(widget) {
|
|
12
|
-
const { View, slot = {} } = await viewFactory(widget);
|
|
13
|
-
const renderParams = {
|
|
14
|
-
widget,
|
|
15
|
-
state: widget.state,
|
|
16
|
-
props: widget.props,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
html: View.render(renderParams)?.html,
|
|
21
|
-
slot: Object.keys(slot).reduce((acc, cur) => {
|
|
22
|
-
acc[cur] = {
|
|
23
|
-
name: slot[cur].name,
|
|
24
|
-
html: slot[cur].View.render(renderParams)?.html,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return acc;
|
|
28
|
-
}, {}),
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { headlineSlotFactory } from '../slots/headlineSlotFactory';
|
|
2
|
-
import View from './View.svelte';
|
|
3
|
-
|
|
4
|
-
async function viewFactory(widget) {
|
|
5
|
-
const slot = (await Promise.all([headlineSlotFactory(widget)])).reduce(
|
|
6
|
-
(acc, cur) => {
|
|
7
|
-
acc[cur.name] = cur;
|
|
8
|
-
|
|
9
|
-
return acc;
|
|
10
|
-
},
|
|
11
|
-
{},
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
View,
|
|
16
|
-
slot,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export { viewFactory };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { render, html } from 'uhtml';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget, createMerkur } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import { mapViews } from './lib/utils';
|
|
6
|
-
import { viewFactory } from './views/View';
|
|
7
|
-
import widgetProperties from './widget';
|
|
8
|
-
|
|
9
|
-
import './style.css';
|
|
10
|
-
|
|
11
|
-
function createWidget(widgetParams) {
|
|
12
|
-
return createMerkurWidget({
|
|
13
|
-
...widgetProperties,
|
|
14
|
-
...widgetParams,
|
|
15
|
-
$dependencies: {
|
|
16
|
-
render,
|
|
17
|
-
html,
|
|
18
|
-
},
|
|
19
|
-
async mount(widget) {
|
|
20
|
-
return mapViews(
|
|
21
|
-
widget,
|
|
22
|
-
viewFactory,
|
|
23
|
-
({ View, container }) =>
|
|
24
|
-
container && widget.$dependencies.render(container, View(widget)),
|
|
25
|
-
);
|
|
26
|
-
},
|
|
27
|
-
async unmount(widget) {
|
|
28
|
-
return mapViews(
|
|
29
|
-
widget,
|
|
30
|
-
viewFactory,
|
|
31
|
-
({ container }) =>
|
|
32
|
-
container &&
|
|
33
|
-
widget.$dependencies.render(container, widget.$dependencies.html``),
|
|
34
|
-
);
|
|
35
|
-
},
|
|
36
|
-
async update(widget) {
|
|
37
|
-
return mapViews(
|
|
38
|
-
widget,
|
|
39
|
-
viewFactory,
|
|
40
|
-
({ View, container }) =>
|
|
41
|
-
container && widget.$dependencies.render(container, View(widget)),
|
|
42
|
-
);
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const merkur = createMerkur();
|
|
48
|
-
merkur.register({
|
|
49
|
-
...widgetProperties,
|
|
50
|
-
createWidget,
|
|
51
|
-
});
|