@soleil-se/app-util 5.7.1 → 5.8.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 CHANGED
@@ -7,6 +7,16 @@ 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.0] - 2024-10-21
11
+
12
+ - Restructure rendering function for different Svelte versions.
13
+ - Add rendering function for Svelte 5.
14
+ - Deprecate old Svelte rendering functions.
15
+
16
+ ## [5.7.2] - 2024-08-21
17
+
18
+ - Add `?version=0` properly to `getRouteUri` when called in offline mode.
19
+
10
20
  ## [5.7.1] - 2024-08-07
11
21
 
12
22
  - Change widget detection to use `window.sv.PageContext.dashboardId`.
@@ -0,0 +1 @@
1
+ export { render } from '../4';
@@ -0,0 +1,30 @@
1
+ import { setAppProps } from '../../../common';
2
+
3
+ /**
4
+ * Renders a client side Svelte application.
5
+ * @param {import('svelte').SvelteComponent} App Svelte app root component.
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 {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
10
+ * DOM (usually from server-side rendering) rather than creating new elements. By default the app
11
+ * will hydrate when the target has any child nodes.
12
+ * @param {boolean} [settings.intro=false] If true, will play transitions on initial render,
13
+ * rather than waiting for subsequent state changes.
14
+ * @return {import('svelte').SvelteComponent} Initialized Svelte component.
15
+ */
16
+ export function render(App, {
17
+ target,
18
+ props,
19
+ intro = false,
20
+ hydrate = target.hasChildNodes(),
21
+ } = {}) {
22
+ setAppProps(props);
23
+
24
+ return new App({
25
+ hydrate,
26
+ target,
27
+ props,
28
+ intro,
29
+ });
30
+ }
@@ -0,0 +1,31 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import { mount as svelteMount, hydrate as svelteHydrate } from 'svelte';
3
+
4
+ import { setAppProps } from '../../../common';
5
+
6
+ /**
7
+ * Renders a client side Svelte application.
8
+ * @param {import('svelte').Component} App Svelte app root component.
9
+ * @param {object} [settings={}] Settings object.
10
+ * @param {string} [settings.target] Target where app should be mounted.
11
+ * @param {string} [settings.props] Root component props.
12
+ * @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
13
+ * DOM (usually from server-side rendering) rather than creating new elements. By default the app
14
+ * will hydrate when the target has any child nodes.
15
+ * @param {boolean} [settings.intro=false] If true, will play transitions on initial render,
16
+ * rather than waiting for subsequent state changes.
17
+ */
18
+ export function render(App, {
19
+ target,
20
+ props,
21
+ hydrate = target.hasChildNodes(),
22
+ intro = false,
23
+ } = {}) {
24
+ setAppProps(props);
25
+
26
+ if (hydrate) {
27
+ svelteHydrate(App, { target, props, intro });
28
+ } else {
29
+ svelteMount(App, { target, props, intro });
30
+ }
31
+ }
@@ -1,27 +1,20 @@
1
- import { setAppProps } from '../../common';
1
+ import { render as render4 } from './4';
2
2
 
3
3
  /**
4
- * Renders a client side Svelte application.
5
- * @param {*} App Svelte app root component.
4
+ * Renders a client side Svelte 3 or 4 application.
5
+ * @deprecated Use rendering function for specific Svelte version instead.
6
+ * `import { render } from '@soleil-api/webapp-util/client/{3|4|5}';`
7
+ * @param {import('svelte').SvelteComponent} App Svelte app root component.
6
8
  * @param {object} [settings={}] Settings object.
7
9
  * @param {string} [settings.target] Target where app should be mounted.
8
10
  * @param {string} [settings.props] Root component props.
9
- * @param {string} [settings.intro=false] If true, will play transitions on initial render,
11
+ * @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
12
+ * DOM (usually from server-side rendering) rather than creating new elements. By default the app
13
+ * will hydrate when the target has any child nodes.
14
+ * @param {boolean} [settings.intro=false] If true, will play transitions on initial render,
10
15
  * rather than waiting for subsequent state changes.
11
- * @return {*} Initialized Svelte component.
16
+ * @return {import('svelte').SvelteComponent} Initialized Svelte component.
12
17
  */
13
- export function render(App, {
14
- target,
15
- props,
16
- intro = false,
17
- hydrate = target.hasChildNodes(),
18
- } = {}) {
19
- setAppProps(props);
20
-
21
- return new App({
22
- hydrate,
23
- target,
24
- props,
25
- intro,
26
- });
18
+ export function render(App, settings) {
19
+ return render4(App, settings);
27
20
  }
package/common/index.js CHANGED
@@ -129,9 +129,13 @@ export function parseParams(url = '') {
129
129
  */
130
130
  export function getRouteUri(route = '', params = undefined) {
131
131
  const path = route.replace(leadingSlashes, '');
132
- const qs = stringifyParams(params, { addQueryPrefix: true });
132
+ const qs = stringifyParams({
133
+ version: isOffline ? '0' : undefined,
134
+ ...params,
135
+ }, { addQueryPrefix: true });
133
136
  if (router?.getStandaloneUrl) {
134
- return router.getStandaloneUrl((path !== '' ? `/${path}` : path).replace(trailingSlashes, '')) + qs;
137
+ return router.getStandaloneUrl((path !== '' ? `/${path}` : path).replace(trailingSlashes, ''))
138
+ .replace('?version=0', '') + qs;
135
139
  }
136
140
  /* Import of @sitevision/api/common/router is not avaliable in hooks, need to build the route URI
137
141
  * manually instead of using router.getStandaloneUri */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/app-util",
3
- "version": "5.7.1",
3
+ "version": "5.8.0",
4
4
  "description": "Utility and rendering functions for WebApps.",
5
5
  "main": "./common/index.js",
6
6
  "author": "Soleil AB",
@@ -9,11 +9,11 @@
9
9
  "homepage": "https://docs.soleil.se/packages/app-util/",
10
10
  "devDependencies": {
11
11
  "@sitevision/api": "^2023.9.2",
12
- "svelte": "^3.59.2"
12
+ "svelte": "^4.2.18"
13
13
  },
14
14
  "peerDependencies": {
15
15
  "@sitevision/api": "*"
16
16
  },
17
- "gitHead": "c16a10d52ce59fe1cfa51fb270549c1655f81db3",
17
+ "gitHead": "cb815ee398e467bc9440e1b4e98640e12462dd41",
18
18
  "dependencies": {}
19
19
  }
@@ -0,0 +1 @@
1
+ export { render } from '../4';
@@ -0,0 +1,13 @@
1
+ import { setAppProps } from '../../../common';
2
+
3
+ /**
4
+ * Returns HTML for a server rendered Svelte app.
5
+ * @param {import('svelte').SvelteComponent} App Svelte component that is root of app.
6
+ * @param {object} props Props passed to root component.
7
+ * @return {string} HTML for the server rendered app.
8
+ */
9
+ export function render(App, props) {
10
+ setAppProps(props);
11
+ const { html } = App.render(props);
12
+ return html;
13
+ }
@@ -0,0 +1,15 @@
1
+ import { render as svelteRender } from 'svelte/server';
2
+ import { setAppProps } from '../../../common';
3
+
4
+ /**
5
+ * Returns HTML for a server rendered Svelte app.
6
+ * @param {import('svelte').Component} App Svelte component that is root of app.
7
+ * @param {object} props Props passed to root component.
8
+ * @return {string} HTML for the server rendered app.
9
+ */
10
+ export function render(App, props) {
11
+ setAppProps(props);
12
+
13
+ const { body } = svelteRender(App, props);
14
+ return body;
15
+ }
@@ -1,13 +1,13 @@
1
- import { setAppProps } from '../../common';
1
+ import { render as render4 } from './4';
2
2
 
3
3
  /**
4
- * Returns HTML for a server rendered Svelte app.
5
- * @param {SvelteComponent} App - Svelte component that is root of app.
6
- * @param {object} props - Props passed to root component.
7
- * @return {string} - HTML for the server rendered app.
4
+ * Returns HTML for a server rendered Svelte 3 or 4 app.
5
+ * @deprecated Use rendering function for specific Svelte version instead.
6
+ * `import { render } from '@soleil-api/webapp-util/server/{3|4|5}';`
7
+ * @param {import('svelte').SvelteComponent} App Svelte component that is root of app.
8
+ * @param {object} props Props passed to root component.
9
+ * @return {string} HTML for the server rendered app.
8
10
  */
9
11
  export function render(App, props) {
10
- setAppProps(props);
11
- const { html } = App.render(props);
12
- return html;
12
+ return render4(App, props);
13
13
  }