@soleil-se/app-util 5.8.0 → 5.8.2
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 +9 -0
- package/README.md +3 -410
- package/client/svelte/index.js +1 -1
- package/package.json +7 -8
- package/server/svelte/5/index.js +1 -1
- package/server/svelte/index.js +1 -1
- package/docs/1.svelte.md +0 -112
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ All notable changes to this project will be documented in this file.
|
|
|
7
7
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
8
8
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
9
9
|
|
|
10
|
+
## [5.8.2] - 2025-02-14
|
|
11
|
+
|
|
12
|
+
- Update README and tagging in `package.json`.
|
|
13
|
+
|
|
14
|
+
## [5.8.1] - 2024-10-28
|
|
15
|
+
|
|
16
|
+
- Pass props properly to Svelte 5 server render function.
|
|
17
|
+
- Update JSDoc to correct new paths for deprecated functions.
|
|
18
|
+
|
|
10
19
|
## [5.8.0] - 2024-10-21
|
|
11
20
|
|
|
12
21
|
- Restructure rendering function for different Svelte versions.
|
package/README.md
CHANGED
|
@@ -1,412 +1,5 @@
|
|
|
1
|
+
# @soleil-se/app-util
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
Utility functions for WebApps, RESTApps and Widgets in Sitevision.
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[GitHub](https://github.com/soleilit/server-monorepo/tree/master/packages/webapp-util)
|
|
7
|
-
[NPM](https://www.npmjs.com/package/@soleil-se/webapp-util)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Requirements
|
|
12
|
-
|
|
13
|
-
* Sitevision 9.1.0 or later.
|
|
14
|
-
* `@soleil-se/sv-app-build@^1.0.0` or `@sitevision/sitevision-scripts@^3.0.0`.
|
|
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
|
-
|
|
34
|
-
## Install
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
> npm install @soleil-se/webapp-util
|
|
38
|
-
> yarn add @soleil-se/webapp-util
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
:::details Integrity check failed
|
|
42
|
-
If the following error occurs when installing with Yarn run `yarn install --update-checksums`.
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
Integrity check failed for "@soleil-se/webapp-util" (computed integrity doesn...
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
:::
|
|
49
|
-
|
|
50
|
-
## Migration
|
|
51
|
-
|
|
52
|
-
Migrating from version 4?
|
|
53
|
-
See [MIGRATION](./MIGRATION.md).
|
|
54
|
-
|
|
55
|
-
## Common
|
|
56
|
-
|
|
57
|
-
All imports from base package are available both on the server and client.
|
|
58
|
-
|
|
59
|
-
### appId : `String`
|
|
60
|
-
|
|
61
|
-
DOM friendly unique identifier for the WebApp.
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
import { appId } from '@soleil-se/webapp-util';
|
|
65
|
-
|
|
66
|
-
console.log(appId); // For example: 12_682d461b1708a9bb1ea13efd
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### isOffline : `Boolean`
|
|
70
|
-
|
|
71
|
-
If the WebApp is running in offline mode or not.
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
import { isOffline } from '@soleil-se/webapp-util';
|
|
75
|
-
|
|
76
|
-
console.log(isOffline); // true or false
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### isOnline : `Boolean`
|
|
80
|
-
|
|
81
|
-
If the WebApp is running in online mode or not.
|
|
82
|
-
|
|
83
|
-
```js
|
|
84
|
-
import { isOnline } from '@soleil-se/webapp-util';
|
|
85
|
-
|
|
86
|
-
console.log(isOnline); // true or false
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### isServer : `Boolean`
|
|
90
|
-
|
|
91
|
-
If the current code is running on the server.
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
import { isServer } from '@soleil-se/webapp-util';
|
|
95
|
-
|
|
96
|
-
console.log(isServer); // true or false
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### isBrowser : `Boolean`
|
|
100
|
-
|
|
101
|
-
If the current code is running in the browser.
|
|
102
|
-
|
|
103
|
-
```js
|
|
104
|
-
import { isBrowser } from '@soleil-se/webapp-util';
|
|
105
|
-
|
|
106
|
-
console.log(isBrowser); // true or false
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### getNamespace([prefix]) ⇒ `String`
|
|
110
|
-
|
|
111
|
-
Get a prefixed namespace unique for app.
|
|
112
|
-
|
|
113
|
-
**Returns**: `String` - Prefixed namespace.
|
|
114
|
-
|
|
115
|
-
| Param | Type | Default |
|
|
116
|
-
| --- | --- | --- |
|
|
117
|
-
| [prefix] | `string` | `"'app'"` |
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
import { getNamespace } from '@soleil-se/webapp-util';
|
|
121
|
-
|
|
122
|
-
console.log(getNamespace());
|
|
123
|
-
// For example: app_12_682d461b1708a9bb1ea13efd
|
|
124
|
-
|
|
125
|
-
console.log(getNamespace('input'));
|
|
126
|
-
// For example: input_12_682d461b1708a9bb1ea13efd
|
|
127
|
-
|
|
128
|
-
// If the app is in a decoration template the Portlet ID is the same for all instances, so the ID of the decorated node is used as well.
|
|
129
|
-
console.log(getNamespace('decoration'));
|
|
130
|
-
// For example: decoration_10_3871c02f1754f3aa8f9d4eb_12_70c3d424173b4900fc550e1c
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### generateId([prefix]) ⇒ `String`
|
|
134
|
-
|
|
135
|
-
Generate a unique identifier with a random UUID without dashes.
|
|
136
|
-
|
|
137
|
-
**Returns**: `String` - Unique identifier.
|
|
138
|
-
|
|
139
|
-
| Param | Type | Default |
|
|
140
|
-
| --- | --- | --- |
|
|
141
|
-
| [prefix] | `string` | `"'id'"` |
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
import { generateId } from '@soleil-se/webapp-util';
|
|
145
|
-
|
|
146
|
-
console.log(generateId());
|
|
147
|
-
// For example: id_550e8400e29b41d4a716446655440000
|
|
148
|
-
|
|
149
|
-
console.log(generateId('input'));
|
|
150
|
-
// For example: input_550e8400e29b41d4a716446655440000
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### getRouteUri(route, [query]) ⇒ `String`
|
|
155
|
-
|
|
156
|
-
Get URI for a route.
|
|
157
|
-
|
|
158
|
-
**Returns**: `String` - URI for route.
|
|
159
|
-
|
|
160
|
-
| Param | Type | Description |
|
|
161
|
-
| --- | --- | --- |
|
|
162
|
-
| route | `String` | A route. |
|
|
163
|
-
| query | `Object` | Object with query string parameters |
|
|
164
|
-
|
|
165
|
-
```js
|
|
166
|
-
import { getRouteUri } from '@soleil-se/webapp-util';
|
|
167
|
-
|
|
168
|
-
console.log(getRouteUri('/items'));
|
|
169
|
-
// URI structure: /appresource/{pageId}/{portletId}>/items
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
```js
|
|
173
|
-
import { getRouteUri } from '@soleil-se/webapp-util';
|
|
174
|
-
|
|
175
|
-
console.log(getRouteUri('/items', { foo: 'bar' }));
|
|
176
|
-
// URI structure: /appresource/{pageId}/{portletId}>/items?foo=bar
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### getResourceUri(resource) ⇒ `String`
|
|
180
|
-
|
|
181
|
-
Get URI for a resource.
|
|
182
|
-
|
|
183
|
-
**Returns**: `String` - URI for a resource.
|
|
184
|
-
|
|
185
|
-
| Param | Type | Description |
|
|
186
|
-
| --- | --- | --- |
|
|
187
|
-
| resource | `String` | A resource. |
|
|
188
|
-
|
|
189
|
-
```js
|
|
190
|
-
import { getResourceUri } from '@soleil-se/webapp-util';
|
|
191
|
-
|
|
192
|
-
console.log(getResourceUri('/image.png'));
|
|
193
|
-
// URI structure: /webapp-files/<webappname>/<webappversion>/image.png
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### getAppProps([key]) ⇒ `*` | `Object`
|
|
197
|
-
|
|
198
|
-
Get props that are passed to app when rendering.
|
|
199
|
-
|
|
200
|
-
**Returns**: `*` | `Object` - Value or object.
|
|
201
|
-
|
|
202
|
-
| Param | Type | Description |
|
|
203
|
-
| --- | --- | --- |
|
|
204
|
-
| [key] | `String` | Key for value. |
|
|
205
|
-
|
|
206
|
-
```js
|
|
207
|
-
import { getAppProps } from '@soleil-se/webapp-util';
|
|
208
|
-
|
|
209
|
-
// Get value with key
|
|
210
|
-
const myValue = getAppProps('myValue');
|
|
211
|
-
// Or with destructuring
|
|
212
|
-
const { myValue } = getAppProps();
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### stringifyParams(params [, options]) ⇒ `String`
|
|
216
|
-
|
|
217
|
-
Stringify an object to a query string compatible with Sitevision.
|
|
218
|
-
|
|
219
|
-
**Returns**: `String` - Stringified parameters.
|
|
220
|
-
|
|
221
|
-
| Param | Type | Default | Description |
|
|
222
|
-
| --- | --- | --- | --- |
|
|
223
|
-
| params | `Object` | | Object with parameters to stringify. |
|
|
224
|
-
| [options] | `Object` | `{}` | Options object. |
|
|
225
|
-
| [options.addQueryPrefix] | `Boolean` | `false` | If a leading `?` should be added to the string. |
|
|
226
|
-
|
|
227
|
-
```js
|
|
228
|
-
import { stringifyParams } from '@soleil-se/webapp-util';
|
|
229
|
-
|
|
230
|
-
const queryString = stringifyParams({ foo: 'bar', num: 1 });
|
|
231
|
-
// foo=bar&num=1
|
|
232
|
-
|
|
233
|
-
const queryString = stringifyParams({ foo: 'bar', num: 1 }, { addQueryPrefix: true });
|
|
234
|
-
// ?foo=bar&num=1
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
### parseParams(url) ⇒ `Object`
|
|
238
|
-
|
|
239
|
-
Parse an URL, URI or query string to an object containing its query parameters.
|
|
240
|
-
|
|
241
|
-
**Returns**: `Object` - Parsed parameters.
|
|
242
|
-
|
|
243
|
-
| Param | Type | Default | Description |
|
|
244
|
-
| --- | --- | --- | --- |
|
|
245
|
-
| url | `String` | | URL, URI or query string to be parsed, must start with or contain "?" |
|
|
246
|
-
|
|
247
|
-
```js
|
|
248
|
-
import { parseParams } from '@soleil-se/webapp-util';
|
|
249
|
-
|
|
250
|
-
const params = parseParams('?foo=bar&arr[]=1&arr[]=2');
|
|
251
|
-
// { foo: 'bar', arr: [1, 2] }
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
## Client
|
|
255
|
-
|
|
256
|
-
Following API:s are available in a client context.
|
|
257
|
-
|
|
258
|
-
### Fetch
|
|
259
|
-
|
|
260
|
-
Fetch wrapper for calling app routes, rest-api or external resources.
|
|
261
|
-
|
|
262
|
-
#### fetchJson() => `Promise<Object>`
|
|
263
|
-
|
|
264
|
-
| Param | Type | Default | Description |
|
|
265
|
-
| --- | --- | --- | --- |
|
|
266
|
-
| uri | `String` | | URI for resource |
|
|
267
|
-
| [options] | `Object` | `{}` | Options object, two custom options rest is standard [fetch options](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) |
|
|
268
|
-
| [options.params] | `Object` | `{}` | Object with parameters to be appended to the URI |
|
|
269
|
-
| [options.retries] | `Number` | `0` | Number of retries if the request times out. |
|
|
270
|
-
|
|
271
|
-
**Returns**: `Promise<Object>` - Promise containing parsed JSON-data.
|
|
272
|
-
**Throws** `Error` - Extended error object with custom properties for `status`, `aborted` and other JSON-data returned by the request.
|
|
273
|
-
|
|
274
|
-
URI:s starting with `/rest-api`, `/appresource`, `/edit-app-config` or a protocol, for example `https://` will be left as is.
|
|
275
|
-
Other URI:s will be converted to match a route in the current app with `getRouteUri`.
|
|
276
|
-
|
|
277
|
-
Most common usage is getting data from a route in the current app.
|
|
278
|
-
|
|
279
|
-
```js
|
|
280
|
-
import { fetchJson } from '@soleil-se/webapp-util/client';
|
|
281
|
-
|
|
282
|
-
async function getItems() {
|
|
283
|
-
const params = { query: 'foo', start: 0, num: 10 };
|
|
284
|
-
const result = await fetchJson('/items', { params });
|
|
285
|
-
console.log(result);
|
|
286
|
-
}
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
Posting form data.
|
|
290
|
-
|
|
291
|
-
```js
|
|
292
|
-
import { fetchJson } from '@soleil-se/webapp-util/client';
|
|
293
|
-
|
|
294
|
-
async function postForm() {
|
|
295
|
-
const body = new FormData();
|
|
296
|
-
body.append('name', 'Foo');
|
|
297
|
-
body.append('mail', 'foo@bar.com');
|
|
298
|
-
|
|
299
|
-
const result = await fetchJson('/create', { method: 'POST', body }));
|
|
300
|
-
console.log(result);
|
|
301
|
-
}
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
Specify number of retries if a request times out.
|
|
305
|
-
|
|
306
|
-
```js
|
|
307
|
-
import { fetchJson } from '@soleil-se/webapp-util/client';
|
|
308
|
-
|
|
309
|
-
async function getItems() {
|
|
310
|
-
const params = { query: 'foo', start: 0, num: 10 };
|
|
311
|
-
const result = await fetchJson('/items', { params, retries: 5 });
|
|
312
|
-
console.log(result);
|
|
313
|
-
}
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
When searching on input you probably want to abort the ongoing request to avoid weird bugs when
|
|
317
|
-
the first request might be completed after the subsequent one.
|
|
318
|
-
Pass an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) signal
|
|
319
|
-
in options and abort the ongoing call.
|
|
320
|
-
|
|
321
|
-
```js
|
|
322
|
-
import { fetchJson } from '@soleil-se/webapp-util/client';
|
|
323
|
-
|
|
324
|
-
let controller;
|
|
325
|
-
|
|
326
|
-
async function onInput() {
|
|
327
|
-
if(controller) controller.abort();
|
|
328
|
-
controller = new AbortController();
|
|
329
|
-
|
|
330
|
-
const params = { query: 'foo' };
|
|
331
|
-
try {
|
|
332
|
-
const result = await fetchJson('/search', { params, signal: controller.signal });
|
|
333
|
-
console.log(result);
|
|
334
|
-
} catch(e) {
|
|
335
|
-
// Ignore aborts due to new search.
|
|
336
|
-
if(e.aborted) return;
|
|
337
|
-
// Handle error as usual.
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
### URL Parameters
|
|
343
|
-
|
|
344
|
-
Helper functions setting, getting, updating and clearing query parameters in the URL-field.
|
|
345
|
-
|
|
346
|
-
#### getUrlParams() ⇒ `Object`
|
|
347
|
-
|
|
348
|
-
Get parameters from the URL-field.
|
|
349
|
-
|
|
350
|
-
**Returns**: `Object` - Parameters in URL-field.
|
|
351
|
-
|
|
352
|
-
```js
|
|
353
|
-
import { getUrlParams } from '@soleil-se/webapp-util/client';
|
|
354
|
-
|
|
355
|
-
const params = getUrlParams();
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
#### getUrlParam() ⇒ `String|Array[String]`
|
|
359
|
-
|
|
360
|
-
Get single parameter from the URL-field.
|
|
361
|
-
|
|
362
|
-
**Returns**: `String|Array[String]` - Parameter value.
|
|
363
|
-
|
|
364
|
-
```js
|
|
365
|
-
import { getUrlParam } from '@soleil-se/webapp-util/client';
|
|
366
|
-
|
|
367
|
-
const param = getUrlParam('name');
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
#### setUrlParams(params)
|
|
371
|
-
|
|
372
|
-
Set parameters in the URL-field, overwriting other parameters.
|
|
373
|
-
|
|
374
|
-
| Param | Type | Default | Description |
|
|
375
|
-
| --- | --- | --- | --- |
|
|
376
|
-
| params | `Object` | | Object with parameters to set in the URL-field. |
|
|
377
|
-
|
|
378
|
-
```js
|
|
379
|
-
import { setUrlParams } from '@soleil-se/webapp-util/client';
|
|
380
|
-
|
|
381
|
-
setUrlParams({ foo: 'bar', arr: [1, 2] });
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
#### updateUrlParams(params)
|
|
385
|
-
|
|
386
|
-
Update parameters in the URL-field, merging with existing parameters
|
|
387
|
-
|
|
388
|
-
**Returns**: `String` - Stringified parameters.
|
|
389
|
-
|
|
390
|
-
| Param | Type | Default | Description |
|
|
391
|
-
| --- | --- | --- | --- |
|
|
392
|
-
| params | `Object` | | Object with parameters to add to the URL-field. |
|
|
393
|
-
|
|
394
|
-
```js
|
|
395
|
-
import { updateUrlParams } from '@soleil-se/webapp-util/client';
|
|
396
|
-
|
|
397
|
-
updateUrlParams({ foo: 'bar', arr: [1, 2] });
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
#### clearUrlParams()
|
|
401
|
-
|
|
402
|
-
Clear parameters in the URL-field
|
|
403
|
-
|
|
404
|
-
```js
|
|
405
|
-
import { clearUrlParams } from '@soleil-se/webapp-util/client';
|
|
406
|
-
|
|
407
|
-
clearUrlParams();
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
## Rendering
|
|
411
|
-
|
|
412
|
-
* [Svelte](./docs/1.svelte.md)
|
|
5
|
+
[Documentation](https://docs.soleil.se/packages/app-util) | [Changelog](https://docs.soleil.se/packages/app-util/changelog)
|
package/client/svelte/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { render as render4 } from './4';
|
|
|
3
3
|
/**
|
|
4
4
|
* Renders a client side Svelte 3 or 4 application.
|
|
5
5
|
* @deprecated Use rendering function for specific Svelte version instead.
|
|
6
|
-
* `import { render } from '@soleil-api/webapp-util/client/{3|4|5}';`
|
|
6
|
+
* `import { render } from '@soleil-api/webapp-util/client/svelte/{3|4|5}';`
|
|
7
7
|
* @param {import('svelte').SvelteComponent} App Svelte app root component.
|
|
8
8
|
* @param {object} [settings={}] Settings object.
|
|
9
9
|
* @param {string} [settings.target] Target where app should be mounted.
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "5.8.
|
|
4
|
-
"description": "Utility
|
|
3
|
+
"version": "5.8.2",
|
|
4
|
+
"description": "Utility functions for WebApps, RESTApps and Widgets in Sitevision.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "UNLICENCED",
|
|
8
8
|
"private": false,
|
|
9
|
-
"homepage": "https://docs.soleil.se/packages/app-util
|
|
9
|
+
"homepage": "https://docs.soleil.se/packages/app-util",
|
|
10
|
+
"keywords": ["sitevision", "webapps", "restapps", "widgets", "svelte"],
|
|
10
11
|
"devDependencies": {
|
|
11
12
|
"@sitevision/api": "^2023.9.2",
|
|
12
13
|
"svelte": "^4.2.18"
|
|
13
14
|
},
|
|
14
15
|
"peerDependencies": {
|
|
15
16
|
"@sitevision/api": "*"
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
"dependencies": {}
|
|
19
|
-
}
|
|
17
|
+
}
|
|
18
|
+
}
|
package/server/svelte/5/index.js
CHANGED
package/server/svelte/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { render as render4 } from './4';
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns HTML for a server rendered Svelte 3 or 4 app.
|
|
5
5
|
* @deprecated Use rendering function for specific Svelte version instead.
|
|
6
|
-
* `import { render } from '@soleil-api/webapp-util/server/{3|4|5}';`
|
|
6
|
+
* `import { render } from '@soleil-api/webapp-util/server/svelte/{3|4|5}';`
|
|
7
7
|
* @param {import('svelte').SvelteComponent} App Svelte component that is root of app.
|
|
8
8
|
* @param {object} props Props passed to root component.
|
|
9
9
|
* @return {string} HTML for the server rendered app.
|
package/docs/1.svelte.md
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Svelte
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Sitevision supports both server and client side rendering with Svelte.
|
|
6
|
-
|
|
7
|
-
## index.js
|
|
8
|
-
|
|
9
|
-
### `render(App, [props])`
|
|
10
|
-
|
|
11
|
-
`@soleil-api/webapp-util/server/svelte`
|
|
12
|
-
|
|
13
|
-
Get a HTML string for rendering a universal Svelte application.
|
|
14
|
-
If a client bundle is available the server rendered HTML will be hydrated and not completely re-rendered.
|
|
15
|
-
|
|
16
|
-
**Returns**: `String` - HTML for rendering a Svelte application.
|
|
17
|
-
|
|
18
|
-
| Param | Type | Default | Description |
|
|
19
|
-
|---------|----------|---------|---------------------------------------|
|
|
20
|
-
| [App] | `Svelte` | | Svelte app to be rendered. |
|
|
21
|
-
| [props] | `Object` | `{}` | Props that will be passed to the app. |
|
|
22
|
-
|
|
23
|
-
### Universal
|
|
24
|
-
|
|
25
|
-
Render an app with both server and client code.
|
|
26
|
-
|
|
27
|
-
```javascript
|
|
28
|
-
// index.js
|
|
29
|
-
import router from '@sitevision/api/common/router';
|
|
30
|
-
import { render } from '@soleil-api/webapp-util/server/svelte';
|
|
31
|
-
|
|
32
|
-
import App from './App.svelte';
|
|
33
|
-
|
|
34
|
-
router.get('/', (req, res) => {
|
|
35
|
-
const props = { foo: 'bar' };
|
|
36
|
-
const html = render(App, props);
|
|
37
|
-
res.agnosticRender(html, props);
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### SSR
|
|
42
|
-
|
|
43
|
-
Render an app with only server side code.
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
// index.js
|
|
47
|
-
import router from '@sitevision/api/common/router';
|
|
48
|
-
import { render } from '@soleil-api/webapp-util/server/svelte';
|
|
49
|
-
|
|
50
|
-
import App from './App.svelte';
|
|
51
|
-
|
|
52
|
-
router.get('/', (req, res) => {
|
|
53
|
-
const props = { foo: 'bar' };
|
|
54
|
-
const html = render(App, props);
|
|
55
|
-
res.send(html);
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### CSR
|
|
60
|
-
|
|
61
|
-
Render an app with only client side code.
|
|
62
|
-
|
|
63
|
-
```javascript
|
|
64
|
-
// index.js
|
|
65
|
-
import router from '@sitevision/api/common/router';
|
|
66
|
-
|
|
67
|
-
router.get('/', (req, res) => {
|
|
68
|
-
const props = { foo: 'bar' };
|
|
69
|
-
res.agnosticRender('', props)
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## main.js
|
|
74
|
-
|
|
75
|
-
### `render(App, { target, props })`
|
|
76
|
-
|
|
77
|
-
`@soleil-api/webapp-util/client/svelte`
|
|
78
|
-
|
|
79
|
-
Renders a client side Svelte application.
|
|
80
|
-
|
|
81
|
-
**Returns**: `SvelteComponent` - Initialized Svelte component.
|
|
82
|
-
|
|
83
|
-
| Param | Type | Default | Description |
|
|
84
|
-
|--------------------|-------------------|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
85
|
-
| App | `SvelteComponent` | | Svelte app root component. |
|
|
86
|
-
| [settings] | `Object` | `{}` | Settings object. |
|
|
87
|
-
| [settings.target] | `Element` | | Target where app should be mounted. |
|
|
88
|
-
| [settings.props] | `Object` | | Root component props. |
|
|
89
|
-
| [settings.intro] | `Boolean` | `false` | If true, will play transitions on initial render, rather than waiting for subsequent state changes. |
|
|
90
|
-
| [settings.hydrate] | `Boolean` | `target.hasChildNodes()` | Instructs Svelte to upgrade existing DOM (usually from server-side rendering) rather than creating new elements. By default the app will hydrate when the target has any child nodes. |
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
// main.js
|
|
94
|
-
import { render } from '@soleil-api/webapp-util/client/svelte';
|
|
95
|
-
import App from './App.svelte';
|
|
96
|
-
|
|
97
|
-
export default (props, target) => {
|
|
98
|
-
render(App, { props, target });
|
|
99
|
-
};
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Mount the app in another element:
|
|
103
|
-
|
|
104
|
-
```javascript
|
|
105
|
-
// main.js
|
|
106
|
-
import { render } from '@soleil-api/webapp-util/client/svelte';
|
|
107
|
-
import App from './App.svelte';
|
|
108
|
-
|
|
109
|
-
export default (props) => {
|
|
110
|
-
render(App, { props, target: document.querySelector('#mount_app_here') });
|
|
111
|
-
};
|
|
112
|
-
```
|