@soleil-se/app-util 4.2.1 → 5.1.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/CHANGELOG.md +21 -0
- package/MIGRATION.md +101 -108
- package/README.md +46 -90
- package/client/svelte/index.js +10 -8
- package/common/index.js +70 -76
- package/common/legacy/getRouteUri.js +1 -8
- package/docs/1.svelte.md +115 -0
- package/docs/2.vue.md +57 -0
- package/package.json +10 -8
- package/server/svelte/index.js +8 -31
- package/client/utils/getCurrentScript.js +0 -56
- package/client/utils/index.js +0 -27
- package/client/vue/index.js +0 -33
- package/common/legacy/getViewUri.js +0 -21
- package/docs/1.render.md +0 -58
- package/docs/2.svelte.md +0 -103
- package/docs/3.vue.md +0 -38
- package/docs/4.underscore.md +0 -57
- package/server/index.js +0 -83
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [5.1.0] - 2021-05-27
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- New function `stringifyParams` to stringify query parameters to a Sitevision compatible format.
|
|
13
|
+
- Possible to pass a parameters object to `getRouteUri`.
|
|
14
|
+
- All common constants and functions are now usable in hooks.
|
|
15
|
+
- Deprecate `getViewUri` since it's not used in WebApps 2.
|
|
16
|
+
|
|
17
|
+
## [5.0.0] - 2021-02-08
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Using WebApps 2 for rendering apps.
|
|
22
|
+
|
|
23
|
+
### Removed
|
|
24
|
+
|
|
25
|
+
- `getAppData`, use `getAppProps` instead.
|
|
26
|
+
- `server/render`, use `res.agnosticRender` for framework agnostic rendering.
|
|
27
|
+
- `server/renderTemplate`, used for rendering underscore templates.
|
|
28
|
+
|
|
8
29
|
## [4.2.1] - 2021-09-06
|
|
9
30
|
|
|
10
31
|
### Fixed
|
package/MIGRATION.md
CHANGED
|
@@ -1,156 +1,149 @@
|
|
|
1
1
|
# Migration
|
|
2
2
|
|
|
3
|
-
Migration from version
|
|
3
|
+
Migration from version 4 to 5.
|
|
4
4
|
|
|
5
5
|
<!-- TOC -->
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
13
|
-
- [Get data](#get-data)
|
|
14
|
-
- [Standard values](#standard-values)
|
|
15
|
-
- [Svelte](#svelte)
|
|
16
|
-
- [Server](#server)
|
|
17
|
-
- [Client](#client)
|
|
18
|
-
- [Vue](#vue)
|
|
7
|
+
- [Manifest](#manifest)
|
|
8
|
+
- [index.js](#indexjs)
|
|
9
|
+
- [Universal app](#universal-app)
|
|
10
|
+
- [SSR app](#ssr-app)
|
|
11
|
+
- [CSR app](#csr-app)
|
|
12
|
+
- [main.js](#mainjs)
|
|
19
13
|
|
|
20
14
|
<!-- /TOC -->
|
|
21
15
|
|
|
22
|
-
##
|
|
23
|
-
### Export
|
|
24
|
-
Export moved and renamed.
|
|
16
|
+
## Manifest
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
```js
|
|
28
|
-
import { renderApp } from '@soleil-api/webapp-util';
|
|
29
|
-
```
|
|
30
|
-
New:
|
|
31
|
-
```js
|
|
32
|
-
import { render } from '@soleil-api/webapp-util/server';
|
|
33
|
-
```
|
|
18
|
+
Add `"bundled": true` to the app manifest file.
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
manifest.json
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"id": "se.soleil.myApp",
|
|
25
|
+
"version": "1.0.0",
|
|
26
|
+
"name": "My app",
|
|
27
|
+
"author": "Soleil AB",
|
|
28
|
+
"description": "",
|
|
29
|
+
"helpUrl": "https://soleil.se/support",
|
|
30
|
+
"type": "WebApp",
|
|
31
|
+
"bundled": true
|
|
32
|
+
}
|
|
37
33
|
|
|
38
|
-
Old (index.js):
|
|
39
|
-
```js
|
|
40
|
-
res.send(renderApp(data, { selector: '#mount_app_here' }));
|
|
41
34
|
```
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
import { render } from '@soleil-api/webapp-util/client/vue';
|
|
46
|
-
import App from './App.vue';
|
|
36
|
+
## index.js
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
```
|
|
38
|
+
Rendering is now using Webapps 2 render functions.
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
Export moved.
|
|
40
|
+
### Universal app
|
|
53
41
|
|
|
54
|
-
Old
|
|
55
|
-
```js
|
|
56
|
-
import { renderTemplate } from '@soleil-api/webapp-util';
|
|
57
|
-
```
|
|
58
|
-
New:
|
|
59
|
-
```js
|
|
60
|
-
import { renderTemplate } from '@soleil-api/webapp-util/server';
|
|
61
|
-
```
|
|
62
|
-
## getRouteUri
|
|
63
|
-
URIs for routes was previously passed as props when rendering an application. This is no longer needed.
|
|
64
|
-
Now you can use `getRouteUri` in a client context as well.
|
|
42
|
+
Old
|
|
65
43
|
|
|
66
|
-
Old:
|
|
67
44
|
```js
|
|
68
|
-
import
|
|
45
|
+
import router from '@sitevision/api/common/router';
|
|
46
|
+
import { render } from '@soleil-api/webapp-util/server/svelte';
|
|
69
47
|
|
|
70
|
-
|
|
71
|
-
return fetch(AppData.itemsRoute)
|
|
72
|
-
.then((res) => res.json());
|
|
73
|
-
};
|
|
74
|
-
```
|
|
75
|
-
New:
|
|
76
|
-
```js
|
|
77
|
-
import { getRouteUri } from '@soleil-api/webapp-util';
|
|
48
|
+
import App from './App.svelte';
|
|
78
49
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
50
|
+
router.get('/', (req, res) => {
|
|
51
|
+
const props = { foo: 'bar' };
|
|
52
|
+
res.send(render(App, props));
|
|
53
|
+
});
|
|
83
54
|
```
|
|
84
|
-
## AppData
|
|
85
55
|
|
|
86
|
-
|
|
87
|
-
The default export as object and `@soleil-api/webapp-util/app-data` import is removed.
|
|
56
|
+
New
|
|
88
57
|
|
|
89
|
-
Old:
|
|
90
58
|
```js
|
|
91
|
-
import
|
|
59
|
+
import router from '@sitevision/api/common/router';
|
|
60
|
+
import { render } from '@soleil-api/webapp-util/server/svelte';
|
|
92
61
|
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
New:
|
|
96
|
-
```js
|
|
97
|
-
import { getAppData } from '@soleil-api/webapp-util';
|
|
62
|
+
import App from './App.svelte';
|
|
98
63
|
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
64
|
+
router.get('/', (req, res) => {
|
|
65
|
+
const props = { foo: 'bar' };
|
|
66
|
+
const html = render(App, props);
|
|
67
|
+
res.agnosticRender(html, props);
|
|
68
|
+
});
|
|
103
69
|
```
|
|
104
|
-
### Standard values
|
|
105
|
-
Values that was set as sandard are now moved.
|
|
106
70
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
71
|
+
### SSR app
|
|
72
|
+
|
|
73
|
+
Old
|
|
110
74
|
|
|
111
|
-
const { isOnline, isOffline, uniqueId } = AppData;
|
|
112
|
-
```
|
|
113
|
-
New:
|
|
114
75
|
```js
|
|
115
|
-
import
|
|
76
|
+
import router from '@sitevision/api/common/router';
|
|
77
|
+
import { renderServer } from '@soleil-api/webapp-util/server/svelte';
|
|
116
78
|
|
|
117
|
-
|
|
79
|
+
import App from './App.svelte';
|
|
80
|
+
|
|
81
|
+
router.get('/', (req, res) => {
|
|
82
|
+
const props = { foo: 'bar' };
|
|
83
|
+
res.send(renderServer(App, props));
|
|
84
|
+
});
|
|
118
85
|
```
|
|
119
86
|
|
|
120
|
-
|
|
121
|
-
### Server
|
|
122
|
-
Export moved.
|
|
123
|
-
Export `renderClient` is removed, use `render` from `'@soleil-api/webapp-util/server`
|
|
87
|
+
New
|
|
124
88
|
|
|
125
|
-
Old:
|
|
126
|
-
```js
|
|
127
|
-
import { render } from '@soleil-api/webapp-util/svelte-server';
|
|
128
|
-
```
|
|
129
|
-
New:
|
|
130
89
|
```js
|
|
90
|
+
import router from '@sitevision/api/common/router';
|
|
131
91
|
import { render } from '@soleil-api/webapp-util/server/svelte';
|
|
92
|
+
|
|
93
|
+
import App from './App.svelte';
|
|
94
|
+
|
|
95
|
+
router.get('/', (req, res) => {
|
|
96
|
+
const props = { foo: 'bar' };
|
|
97
|
+
const html = render(App, props);
|
|
98
|
+
res.send(html);
|
|
99
|
+
});
|
|
132
100
|
```
|
|
133
|
-
### Client
|
|
134
|
-
Export moved.
|
|
135
101
|
|
|
136
|
-
|
|
102
|
+
### CSR app
|
|
103
|
+
|
|
104
|
+
Old
|
|
105
|
+
|
|
137
106
|
```js
|
|
138
|
-
import
|
|
107
|
+
import router from '@sitevision/api/common/router';
|
|
108
|
+
import { render } from '@soleil-api/webapp-util/server';
|
|
109
|
+
|
|
110
|
+
router.get('/', (req, res) => {
|
|
111
|
+
const props = { foo: 'bar' };
|
|
112
|
+
res.send(render(props));
|
|
113
|
+
});
|
|
139
114
|
```
|
|
140
|
-
|
|
115
|
+
|
|
116
|
+
New
|
|
117
|
+
|
|
141
118
|
```js
|
|
142
|
-
import
|
|
119
|
+
import router from '@sitevision/api/common/router';
|
|
120
|
+
|
|
121
|
+
router.get('/', (req, res) => {
|
|
122
|
+
const props = { foo: 'bar' };
|
|
123
|
+
res.agnosticRender('', props)
|
|
124
|
+
});
|
|
143
125
|
```
|
|
144
126
|
|
|
145
|
-
##
|
|
146
|
-
|
|
127
|
+
## main.js
|
|
128
|
+
|
|
129
|
+
Is now expecting a default export containing a function
|
|
130
|
+
|
|
131
|
+
Old
|
|
147
132
|
|
|
148
|
-
Old:
|
|
149
133
|
```js
|
|
150
|
-
import render from '@soleil-api/webapp-util/
|
|
134
|
+
import { render } from '@soleil-api/webapp-util/client/svelte';
|
|
135
|
+
import App from './App.svelte';
|
|
136
|
+
|
|
137
|
+
render(App);
|
|
151
138
|
```
|
|
152
|
-
|
|
139
|
+
|
|
140
|
+
New
|
|
141
|
+
|
|
153
142
|
```js
|
|
154
|
-
import { render } from '@soleil-api/webapp-util/client/
|
|
155
|
-
|
|
143
|
+
import { render } from '@soleil-api/webapp-util/client/svelte';
|
|
144
|
+
import App from './App.svelte';
|
|
156
145
|
|
|
146
|
+
export default (props, target) => {
|
|
147
|
+
render(App, { props, target });
|
|
148
|
+
};
|
|
149
|
+
```
|
package/README.md
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
|
|
2
|
-
# `@soleil-se/webapp-util@^
|
|
2
|
+
# `@soleil-se/webapp-util@^5.0.0`
|
|
3
3
|
|
|
4
|
-
Utility functions for
|
|
4
|
+
Utility functions for WebApps.
|
|
5
5
|
|
|
6
|
-
[GitHub](https://github.com/soleilit/server-monorepo/tree/master/packages/webapp-util)
|
|
6
|
+
[GitHub](https://github.com/soleilit/server-monorepo/tree/master/packages/webapp-util)
|
|
7
7
|
[NPM](https://www.npmjs.com/package/@soleil-se/webapp-util)
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
## Requirements
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
* Sitevision 9.1.0 or later.
|
|
14
|
+
* `@soleil-se/sv-app-build` 1.0.0 or later.
|
|
15
|
+
* WebApps 2 enabled app.
|
|
16
|
+
|
|
17
|
+
### Manifest
|
|
18
|
+
|
|
19
|
+
`bundled` needs to be enabled in [WebApp manifest](https://developer.sitevision.se/docs/webapps/webapps-2/manifest) for WebApps 2.
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"id": "se.soleil.myApp",
|
|
24
|
+
"version": "1.0.0",
|
|
25
|
+
"name": "My app",
|
|
26
|
+
"author": "Soleil AB",
|
|
27
|
+
"description": "",
|
|
28
|
+
"helpUrl": "https://soleil.se/support",
|
|
29
|
+
"type": "WebApp",
|
|
30
|
+
"bundled": true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
```
|
|
14
34
|
|
|
15
35
|
## Install
|
|
16
36
|
|
|
@@ -18,52 +38,13 @@ Utility functions for Webapps.
|
|
|
18
38
|
|
|
19
39
|
## Migration
|
|
20
40
|
|
|
21
|
-
Migrating from version
|
|
41
|
+
Migrating from version 4?
|
|
22
42
|
See [MIGRATION](./MIGRATION.md).
|
|
23
43
|
|
|
24
44
|
## API
|
|
25
45
|
|
|
26
46
|
All imports from base package are available both on the server and client.
|
|
27
47
|
|
|
28
|
-
### Constants
|
|
29
|
-
|
|
30
|
-
<dl>
|
|
31
|
-
<dt><a href="#appId">appId</a> : <code>String</code></dt>
|
|
32
|
-
<dd><p>DOM friendly unique identifier for the WebApp.</p>
|
|
33
|
-
</dd>
|
|
34
|
-
<dt><a href="#isOffline">isOffline</a> : <code>Boolean</code></dt>
|
|
35
|
-
<dd><p>If the WebApp is running in offline mode or not.</p>
|
|
36
|
-
</dd>
|
|
37
|
-
<dt><a href="#isOnline">isOnline</a> : <code>Boolean</code></dt>
|
|
38
|
-
<dd><p>If the WebApp is running in online mode or not.</p>
|
|
39
|
-
</dd>
|
|
40
|
-
</dl>
|
|
41
|
-
|
|
42
|
-
### Functions
|
|
43
|
-
|
|
44
|
-
<dl>
|
|
45
|
-
<dt><a href="#getNamespace">getNamespace([prefix])</a> ⇒ <code>String</code></dt>
|
|
46
|
-
<dd><p>Get a prefixed namespace unique for app.</p>
|
|
47
|
-
</dd>
|
|
48
|
-
<dt><a href="#getRouteUri">getRouteUri(route)</a> ⇒ <code>String</code></dt>
|
|
49
|
-
<dd><p>Get URI for a route.
|
|
50
|
-
</dd>
|
|
51
|
-
<dt><a href="#getViewUri">getViewUri(route)</a> ⇒ <code>String</code></dt>
|
|
52
|
-
<dd><p>Get URI for a view.
|
|
53
|
-
</dd>
|
|
54
|
-
<dt><a href="#getResourceUri">getResourceUri(resource)</a> ⇒ <code>String</code></dt>
|
|
55
|
-
<dd><p>Get URI for a resource.</p>
|
|
56
|
-
</dd>
|
|
57
|
-
<dt><a href="#getAppProps">getAppProps([key])</a> ⇒ <code>*</code> | <code>Object</code></dt>
|
|
58
|
-
<dd><p>Get props that are passed to app when rendering.</p>
|
|
59
|
-
</dd>
|
|
60
|
-
<dt><del><a href="#getAppData">getAppData([key])</a> ⇒ <code>*</code> | <code>Object</code></del></dt>
|
|
61
|
-
<dd><p>Get props that are passed to app when rendering.</p>
|
|
62
|
-
</dd>
|
|
63
|
-
</dl>
|
|
64
|
-
|
|
65
|
-
<a name="appId"></a>
|
|
66
|
-
|
|
67
48
|
### appId : `String`
|
|
68
49
|
|
|
69
50
|
DOM friendly unique identifier for the WebApp.
|
|
@@ -74,8 +55,6 @@ import { appId } from '@soleil-se/webapp-util';
|
|
|
74
55
|
console.log(appId); // For example: 12_682d461b1708a9bb1ea13efd
|
|
75
56
|
```
|
|
76
57
|
|
|
77
|
-
<a name="isOffline"></a>
|
|
78
|
-
|
|
79
58
|
### isOffline : `Boolean`
|
|
80
59
|
|
|
81
60
|
If the WebApp is running in offline mode or not.
|
|
@@ -86,8 +65,6 @@ import { isOffline } from '@soleil-se/webapp-util';
|
|
|
86
65
|
console.log(isOffline); // true or false
|
|
87
66
|
```
|
|
88
67
|
|
|
89
|
-
<a name="isOnline"></a>
|
|
90
|
-
|
|
91
68
|
### isOnline : `Boolean`
|
|
92
69
|
|
|
93
70
|
If the WebApp is running in online mode or not.
|
|
@@ -122,9 +99,7 @@ console.log(getNamespace('decoration'));
|
|
|
122
99
|
// For example: decoration_10_3871c02f1754f3aa8f9d4eb_12_70c3d424173b4900fc550e1c
|
|
123
100
|
```
|
|
124
101
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
### getRouteUri(route) ⇒ `String`
|
|
102
|
+
### getRouteUri(route, [query]) ⇒ `String`
|
|
128
103
|
|
|
129
104
|
Get URI for a route.
|
|
130
105
|
|
|
@@ -133,35 +108,22 @@ Get URI for a route.
|
|
|
133
108
|
| Param | Type | Description |
|
|
134
109
|
| --- | --- | --- |
|
|
135
110
|
| route | `String` | A route. |
|
|
111
|
+
| query | `Object` | Object with query string parameters |
|
|
136
112
|
|
|
137
113
|
```js
|
|
138
114
|
import { getRouteUri } from '@soleil-se/webapp-util';
|
|
139
115
|
|
|
140
116
|
console.log(getRouteUri('/items'));
|
|
141
|
-
// URI structure: /appresource
|
|
117
|
+
// URI structure: /appresource/{pageId}/{portletId}>/items
|
|
142
118
|
```
|
|
143
119
|
|
|
144
|
-
<a name="getViewUri"></a>
|
|
145
|
-
|
|
146
|
-
### getViewUri(route) ⇒ `String`
|
|
147
|
-
|
|
148
|
-
Get URI for a view.
|
|
149
|
-
|
|
150
|
-
**Returns**: `String` - URI for view.
|
|
151
|
-
|
|
152
|
-
| Param | Type | Description |
|
|
153
|
-
| --- | --- | --- |
|
|
154
|
-
| route | `String` | A route. |
|
|
155
|
-
|
|
156
120
|
```js
|
|
157
|
-
import {
|
|
121
|
+
import { getRouteUri } from '@soleil-se/webapp-util';
|
|
158
122
|
|
|
159
|
-
console.log(
|
|
160
|
-
// URI structure: ?
|
|
123
|
+
console.log(getRouteUri('/items', { foo: 'bar' }));
|
|
124
|
+
// URI structure: /appresource/{pageId}/{portletId}>/items?foo=bar
|
|
161
125
|
```
|
|
162
126
|
|
|
163
|
-
<a name="getResourceUri"></a>
|
|
164
|
-
|
|
165
127
|
### getResourceUri(resource) ⇒ `String`
|
|
166
128
|
|
|
167
129
|
Get URI for a resource.
|
|
@@ -179,8 +141,6 @@ console.log(getResourceUri('/image.png'));
|
|
|
179
141
|
// URI structure: /webapp-files/<webappname>/<webappversion>/image.png
|
|
180
142
|
```
|
|
181
143
|
|
|
182
|
-
<a name="getAppProps"></a>
|
|
183
|
-
|
|
184
144
|
### getAppProps([key]) ⇒ `*` | `Object`
|
|
185
145
|
|
|
186
146
|
Get props that are passed to app when rendering.
|
|
@@ -200,32 +160,28 @@ const myValue = getAppProps('myValue');
|
|
|
200
160
|
const { myValue } = getAppProps();
|
|
201
161
|
```
|
|
202
162
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
### getAppData([key]) ⇒ `*` | `Object` (DEPRECATED)
|
|
163
|
+
### stringifyParams(params [, options]) ⇒ `String`
|
|
206
164
|
|
|
207
|
-
|
|
165
|
+
Stringify an object to a query string compatible with Sitevision.
|
|
208
166
|
|
|
209
|
-
|
|
167
|
+
**Returns**: `String` - Stringified parameters.
|
|
210
168
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
| [
|
|
169
|
+
| Param | Type | Default | Description |
|
|
170
|
+
| --- | --- | --- | --- |
|
|
171
|
+
| params | `Object` | | Object with parameters to stringify. |
|
|
172
|
+
| [options] | `Object` | `{}` | Settings object. |
|
|
173
|
+
| [options.addQueryPrefix] | `Boolean` | `false` | If a leading `?` should be added to the string. |
|
|
216
174
|
|
|
217
175
|
```js
|
|
218
|
-
import {
|
|
176
|
+
import { stringifyParams } from '@soleil-se/webapp-util';
|
|
219
177
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const {
|
|
178
|
+
const queryString = stringifyParams({ foo: 'bar', num: 1 });
|
|
179
|
+
// foo=bar&num=1
|
|
180
|
+
|
|
181
|
+
const queryString = stringifyParams({ foo: 'bar', num: 1 }, { addQueryPrefix: true });
|
|
182
|
+
// ?foo=bar&num=1
|
|
224
183
|
```
|
|
225
184
|
|
|
226
185
|
## Rendering
|
|
227
186
|
|
|
228
|
-
|
|
229
|
-
- [Svelte](./docs/2.svelte.md)
|
|
230
|
-
- [Vue](./docs/3.vue.md)
|
|
231
|
-
- [Underscore](./docs/4.underscore.md)
|
|
187
|
+
* [Svelte](./docs/1.svelte.md)
|
package/client/svelte/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import { appId, getAppProps } from '../../common';
|
|
1
|
+
import { setAppProps } from '../../common';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Renders a client side Svelte application.
|
|
6
5
|
* @param {*} App Svelte app root component.
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
6
|
+
* @param {object} [settings={}] Settings object.
|
|
7
|
+
* @param {string} [settings.target] Target where app should be mounted.
|
|
8
|
+
* @param {string} [settings.props] Root component props.
|
|
9
|
+
* @param {string} [settings.intro=false] If true, will play transitions on initial render,
|
|
10
10
|
* rather than waiting for subsequent state changes.
|
|
11
11
|
* @return {*} Initialized Svelte component.
|
|
12
12
|
*/
|
|
13
13
|
export function render(App, {
|
|
14
|
-
|
|
14
|
+
target,
|
|
15
|
+
props,
|
|
15
16
|
intro = false,
|
|
16
17
|
} = {}) {
|
|
17
|
-
|
|
18
|
+
setAppProps(props);
|
|
19
|
+
|
|
18
20
|
const hydrate = target.childElementCount > 0;
|
|
19
|
-
|
|
21
|
+
|
|
20
22
|
return new App({
|
|
21
23
|
hydrate,
|
|
22
24
|
target,
|