@soleil-se/app-util 5.2.1 → 5.3.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 +14 -77
- package/README.md +73 -1
- package/client/index.js +7 -0
- package/client/url-params/index.js +52 -0
- package/common/index.js +4 -5
- package/package.json +2 -2
- package/client/.eslintrc.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,23 +5,25 @@ 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.
|
|
8
|
+
## [5.3.0] - 2023-07-06
|
|
9
|
+
|
|
10
|
+
- Added helper functions for managing parameters in the URL-field.
|
|
11
|
+
|
|
12
|
+
## [5.2.2] - 2023-01-31
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
- Fix `parseParams` export.
|
|
15
|
+
|
|
16
|
+
## [5.2.1] - 2023-01-31
|
|
11
17
|
|
|
12
18
|
- Fix homepage url.
|
|
13
19
|
- More lenient with peerDependency `@sitevision/api`.
|
|
14
20
|
|
|
15
21
|
## [5.2.0] - 2023-01-31
|
|
16
22
|
|
|
17
|
-
### Changed
|
|
18
|
-
|
|
19
23
|
- New function `parseParams` to parse query parameters from an URL, URI or query string.
|
|
20
24
|
|
|
21
25
|
## [5.1.0] - 2022-05-27
|
|
22
26
|
|
|
23
|
-
### Changed
|
|
24
|
-
|
|
25
27
|
- New function `stringifyParams` to stringify query parameters to a Sitevision compatible format.
|
|
26
28
|
- Possible to pass a parameters object to `getRouteUri`.
|
|
27
29
|
- All common constants and functions are now usable in hooks.
|
|
@@ -29,74 +31,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
29
31
|
|
|
30
32
|
## [5.0.0] - 2022-02-08
|
|
31
33
|
|
|
32
|
-
### Changed
|
|
33
|
-
|
|
34
34
|
- Using WebApps 2 for rendering apps.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- `getAppData`, use `getAppProps` instead.
|
|
39
|
-
- `server/render`, use `res.agnosticRender` for framework agnostic rendering.
|
|
40
|
-
- `server/renderTemplate`, used for rendering underscore templates.
|
|
35
|
+
- Removed `getAppData`, use `getAppProps` instead.
|
|
36
|
+
- Removed `server/render`, use `res.agnosticRender` for framework agnostic rendering.
|
|
37
|
+
- Removed `server/renderTemplate`, used for rendering underscore templates.
|
|
41
38
|
|
|
42
39
|
## [4.2.1] - 2021-09-06
|
|
43
40
|
|
|
44
|
-
### Fixed
|
|
45
|
-
|
|
46
41
|
- Underscore is misspelled in `renderTemplate`.
|
|
47
42
|
|
|
48
43
|
## [4.2.0] - 2021-08-20
|
|
49
44
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- `getAppProps` for getting props passed to the app when rendering.
|
|
53
|
-
|
|
54
|
-
### Changed
|
|
55
|
-
|
|
45
|
+
- Added `getAppProps` for getting props passed to the app when rendering.
|
|
56
46
|
- `getAppData` deprecated due to confusion, use `getAppProps` instead.
|
|
57
47
|
|
|
58
48
|
## [4.1.4] - 2021-05-25
|
|
59
49
|
|
|
60
|
-
### Fixed
|
|
61
|
-
|
|
62
50
|
- Return empty object instead of undefined when app data isn't set.
|
|
63
|
-
|
|
64
|
-
### Removed
|
|
65
|
-
|
|
66
51
|
- Remove `vue` as optional dependency.
|
|
67
52
|
|
|
68
53
|
## [4.1.3] - 2021-03-31
|
|
69
54
|
|
|
70
|
-
### Fixed
|
|
71
|
-
|
|
72
55
|
- Consistent rendering when using `serverServer` and `render` for Svelte.
|
|
73
|
-
|
|
74
|
-
### Added
|
|
75
|
-
|
|
76
56
|
- Docs for Svelte `renderServer` function.
|
|
77
57
|
|
|
78
58
|
## [4.1.2] - 2021-02-24
|
|
79
59
|
|
|
80
|
-
### Fixed
|
|
81
|
-
|
|
82
60
|
- Escape tags when parsing data to prevent closure of script tags.
|
|
83
61
|
|
|
84
62
|
## [4.1.1] - 2021-02-17
|
|
85
63
|
|
|
86
|
-
### Fixed
|
|
87
|
-
|
|
88
64
|
- Validation error for `id` on script tags, even though it's allowed.
|
|
89
65
|
|
|
90
66
|
## [4.1.0] - 2021-02-17
|
|
91
67
|
|
|
92
|
-
### Changed
|
|
93
|
-
|
|
94
68
|
- Put app data and metadata in script elements instead of data attributes.
|
|
95
69
|
|
|
96
70
|
## [4.0.1] - 2021-01-28
|
|
97
71
|
|
|
98
|
-
### Fixed
|
|
99
|
-
|
|
100
72
|
- Crashes when no data is passed to app and then trying to call `getAppData`.
|
|
101
73
|
|
|
102
74
|
## [4.0.0] - 2021-01-27
|
|
@@ -104,17 +76,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
104
76
|
A much needed major overhaul of the package.
|
|
105
77
|
See [MIGRATION](./MIGRATION.md).
|
|
106
78
|
|
|
107
|
-
### Changed
|
|
108
|
-
|
|
109
79
|
- Major refactoring of package.
|
|
110
80
|
- Exports for render functions are moved.
|
|
111
81
|
- All documented constants and functions from base import (`@soleil-api/webapp-util`) now works both in a server and client context.
|
|
112
82
|
- Settings for selector is moved from server to client rendering functions.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
- `noScript` option in `render` (formerly `renderApp`) has been removed. If a no script message is needed use the `html` option wrapped in `<noscript>`.
|
|
117
|
-
- `@soleil-api/webapp-util/app-data` has been removed, use [getAppData](./README.md#getAppData) from `@soleil-api/webapp-util`.
|
|
83
|
+
- Removed `noScript` option in `render` (formerly `renderApp`) has been removed. If a no script message is needed use the `html` option wrapped in `<noscript>`.
|
|
84
|
+
- Removed `@soleil-api/webapp-util/app-data` has been removed, use [getAppData](./README.md#getAppData) from `@soleil-api/webapp-util`.
|
|
118
85
|
|
|
119
86
|
## [3.0.3] - 2020-11-03
|
|
120
87
|
|
|
@@ -126,86 +93,56 @@ See [MIGRATION](./MIGRATION.md).
|
|
|
126
93
|
|
|
127
94
|
## [3.0.1] - 2020-09-28
|
|
128
95
|
|
|
129
|
-
### Added
|
|
130
|
-
|
|
131
96
|
- Homepage link
|
|
132
97
|
|
|
133
98
|
## [3.0.0] - 2020-09-28
|
|
134
99
|
|
|
135
|
-
### Added
|
|
136
|
-
|
|
137
100
|
- Svelte support.
|
|
138
101
|
- New exports:
|
|
139
102
|
- `uniqueId` - A unique id for the app instance.
|
|
140
103
|
|
|
141
104
|
## [2.4.1] - 2020-09-01
|
|
142
105
|
|
|
143
|
-
### Fixed
|
|
144
|
-
|
|
145
106
|
- App data with single quotes crashes app in edit mode, use double quotes instead.
|
|
146
107
|
|
|
147
108
|
## [2.4.0] - 2020-05-26
|
|
148
109
|
|
|
149
|
-
### Fixed
|
|
150
|
-
|
|
151
110
|
- `getViewUri` returns correct URI when in offline mode and in the Addons view.
|
|
152
111
|
|
|
153
112
|
## [2.3.0] - 2020-05-22
|
|
154
113
|
|
|
155
|
-
### Added
|
|
156
|
-
|
|
157
114
|
- `renderApp` now accepts `req` as a setting to opimize script loading when multiple instances of the app exists. If `req` is present the script will only be loaded once in all browsers except IE11 that needs a unique script src for the currentScript polyfill to work.
|
|
158
|
-
|
|
159
|
-
### Fixed
|
|
160
|
-
|
|
161
115
|
- `noScript` in `renderApp` was not wrapped in a `<noscript>` tag.
|
|
162
116
|
|
|
163
117
|
## [2.2.0] - 2020-05-20
|
|
164
118
|
|
|
165
|
-
### Added
|
|
166
|
-
|
|
167
119
|
- `renderTemplate` function is now available inside templates rendered by the function.
|
|
168
120
|
|
|
169
121
|
## [2.1.4] - 2020-04-07
|
|
170
122
|
|
|
171
|
-
### Fixed
|
|
172
|
-
|
|
173
123
|
- `getViewUri` had incorrect portlet ID.
|
|
174
124
|
|
|
175
125
|
## [2.1.3] - 2020-02-25
|
|
176
126
|
|
|
177
|
-
### Fixed
|
|
178
|
-
|
|
179
127
|
- Add timestamp to script url in edit mode as well.
|
|
180
128
|
|
|
181
129
|
## [2.1.2] - 2020-02-21
|
|
182
130
|
|
|
183
|
-
### Fixed
|
|
184
|
-
|
|
185
131
|
- Wrapped `renderApp` script in svDocReady in edit mode to be sure it executes when other bundles are loaded.
|
|
186
132
|
|
|
187
133
|
## [2.1.1] - 2020-02-14
|
|
188
134
|
|
|
189
|
-
### Changed
|
|
190
|
-
|
|
191
135
|
- Updated readme, heading levels and examples.
|
|
192
136
|
|
|
193
137
|
## [2.1.0] - 2020-02-14
|
|
194
138
|
|
|
195
|
-
### Added
|
|
196
|
-
|
|
197
139
|
- App data import in client, `@soleil-api/webapp-util/app-data`.
|
|
198
140
|
- `getViewUri` to get the URI that also renders the page.
|
|
199
141
|
- `isOnline` to see if the app is online.
|
|
200
|
-
|
|
201
|
-
### Changed
|
|
202
|
-
|
|
203
142
|
- `vue` is now an optional depedency.
|
|
204
143
|
|
|
205
144
|
## [2.0.0] - 2020-02-12
|
|
206
145
|
|
|
207
|
-
### Changed
|
|
208
|
-
|
|
209
146
|
- Now using `currentScript` to reference the script element the app is running in to pass data when using `renderApp`.
|
|
210
147
|
- `renderApp` is no longer using appName.
|
|
211
148
|
- `render` is now called directly in `./app_src/client/index.js`.
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Integrity check failed for "@soleil-se/webapp-util" (computed integrity doesn...
|
|
|
52
52
|
Migrating from version 4?
|
|
53
53
|
See [MIGRATION](./MIGRATION.md).
|
|
54
54
|
|
|
55
|
-
##
|
|
55
|
+
## Common
|
|
56
56
|
|
|
57
57
|
All imports from base package are available both on the server and client.
|
|
58
58
|
|
|
@@ -210,6 +210,78 @@ const params = parseParams('?foo=bar&arr[]=1&arr[]=2');
|
|
|
210
210
|
// { foo: 'bar', arr: [1, 2] }
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
+
## Client
|
|
214
|
+
|
|
215
|
+
Following API:s are available in a client context.
|
|
216
|
+
|
|
217
|
+
### URL Parameters
|
|
218
|
+
|
|
219
|
+
Helper functions setting, getting, updating and clearing query parameters in the URL-field.
|
|
220
|
+
|
|
221
|
+
#### getUrlParams() ⇒ `Object`
|
|
222
|
+
|
|
223
|
+
Get parameters from the URL-field.
|
|
224
|
+
|
|
225
|
+
**Returns**: `Object` - Parameters in URL-field.
|
|
226
|
+
|
|
227
|
+
```js
|
|
228
|
+
import { getUrlParams } from '@soleil-se/webapp-util/client';
|
|
229
|
+
|
|
230
|
+
const params = getUrlParams();
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### getUrlParam() ⇒ `String|Array[String]`
|
|
234
|
+
|
|
235
|
+
Get single parameter from the URL-field.
|
|
236
|
+
|
|
237
|
+
**Returns**: `String|Array[String]` - Parameter value.
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
import { getUrlParam } from '@soleil-se/webapp-util/client';
|
|
241
|
+
|
|
242
|
+
const param = getUrlParam('name');
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### setUrlParams(params)
|
|
246
|
+
|
|
247
|
+
Set parameters in the URL-field, overwriting other parameters.
|
|
248
|
+
|
|
249
|
+
| Param | Type | Default | Description |
|
|
250
|
+
| --- | --- | --- | --- |
|
|
251
|
+
| params | `Object` | | Object with parameters to set in the URL-field. |
|
|
252
|
+
|
|
253
|
+
```js
|
|
254
|
+
import { setUrlParams } from '@soleil-se/webapp-util/client';
|
|
255
|
+
|
|
256
|
+
setUrlParams({ foo: 'bar', arr: [1, 2] });
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
#### updateUrlParams(params)
|
|
260
|
+
|
|
261
|
+
Update parameters in the URL-field, merging with existing parameters
|
|
262
|
+
|
|
263
|
+
**Returns**: `String` - Stringified parameters.
|
|
264
|
+
|
|
265
|
+
| Param | Type | Default | Description |
|
|
266
|
+
| --- | --- | --- | --- |
|
|
267
|
+
| params | `Object` | | Object with parameters to add to the URL-field. |
|
|
268
|
+
|
|
269
|
+
```js
|
|
270
|
+
import { updateUrlParams } from '@soleil-se/webapp-util/client';
|
|
271
|
+
|
|
272
|
+
updateUrlParams({ foo: 'bar', arr: [1, 2] });
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### clearUrlParams()
|
|
276
|
+
|
|
277
|
+
Clear parameters in the URL-field
|
|
278
|
+
|
|
279
|
+
```js
|
|
280
|
+
import { clearUrlParams } from '@soleil-se/webapp-util/client';
|
|
281
|
+
|
|
282
|
+
clearUrlParams();
|
|
283
|
+
```
|
|
284
|
+
|
|
213
285
|
## Rendering
|
|
214
286
|
|
|
215
287
|
* [Svelte](./docs/1.svelte.md)
|
package/client/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { stringifyParams, parseParams } from '../../common';
|
|
2
|
+
|
|
3
|
+
const isEmpty = (obj) => Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set query parameters in the url-field.
|
|
7
|
+
* @param {Object} obj - Values to be set.
|
|
8
|
+
* @param {Object} [options] Optional options.
|
|
9
|
+
* @param {Boolean} [options.scoped = false] If parameter keys should be scoped to current app.
|
|
10
|
+
*/
|
|
11
|
+
export function setUrlParams(params) {
|
|
12
|
+
window.history.replaceState({}, '', (isEmpty(params) ? window.location.pathname : `?${stringifyParams(params)}`));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get query parameter from the url-field.
|
|
17
|
+
*/
|
|
18
|
+
export function getUrlParam(key) {
|
|
19
|
+
const params = parseParams(window.location.search.substring(1));
|
|
20
|
+
return params[key];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get query parameters from the url-field.
|
|
25
|
+
*/
|
|
26
|
+
export function getUrlParams() {
|
|
27
|
+
const params = parseParams(window.location.search.substring(1));
|
|
28
|
+
return params;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Clear query parameters in the url-field.
|
|
33
|
+
*/
|
|
34
|
+
export function clearUrlParams() {
|
|
35
|
+
window.history.replaceState({}, '', window.location.pathname);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Updates query parameters in the url-field.
|
|
40
|
+
* @param {Object} params - Values to be updated.
|
|
41
|
+
*/
|
|
42
|
+
export function updateUrlParams(params) {
|
|
43
|
+
setUrlParams(Object.assign(getUrlParams(), params));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
getUrlParam,
|
|
48
|
+
setUrlParams,
|
|
49
|
+
getUrlParams,
|
|
50
|
+
clearUrlParams,
|
|
51
|
+
updateUrlParams,
|
|
52
|
+
};
|
package/common/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* global document console */
|
|
2
1
|
/* eslint-disable global-require */
|
|
3
2
|
import router from '@sitevision/api/common/router';
|
|
4
3
|
import app from '@sitevision/api/common/app';
|
|
@@ -84,7 +83,7 @@ export function stringifyParams(params = {}, { addQueryPrefix = false } = {}) {
|
|
|
84
83
|
* @param {String} url URL or URI to be parsed, must start with or contain "?".
|
|
85
84
|
* @returns Object with parsed parameters.
|
|
86
85
|
*/
|
|
87
|
-
export
|
|
86
|
+
export function parseParams(url = '') {
|
|
88
87
|
const hasQuestion = url.indexOf('?') > -1;
|
|
89
88
|
if (!hasQuestion) return {};
|
|
90
89
|
|
|
@@ -116,7 +115,7 @@ export default function parseParams(url = '') {
|
|
|
116
115
|
* @param {object} params Query parameters.
|
|
117
116
|
* @returns {string} URI for route.
|
|
118
117
|
*/
|
|
119
|
-
export function getRouteUri(route = '', params) {
|
|
118
|
+
export function getRouteUri(route = '', params = undefined) {
|
|
120
119
|
const path = route.replace(leadingSlashes, '');
|
|
121
120
|
const qs = stringifyParams(params, { addQueryPrefix: true });
|
|
122
121
|
if (router?.getStandaloneUrl) {
|
|
@@ -133,13 +132,13 @@ export function getRouteUri(route = '', params) {
|
|
|
133
132
|
* @param {string} route A route.
|
|
134
133
|
* @returns {string} URI for view.
|
|
135
134
|
*/
|
|
136
|
-
export function getViewUri(route = '',
|
|
135
|
+
export function getViewUri(route = '', params = undefined) {
|
|
137
136
|
if (!router?.getUrl) {
|
|
138
137
|
console.warn('[@soleil-api/webapp-util] getViewUri requires router.getUrl support.');
|
|
139
138
|
return undefined;
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
return router.getUrl(route,
|
|
141
|
+
return router.getUrl(route, params);
|
|
143
142
|
}
|
|
144
143
|
|
|
145
144
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Utility and rendering functions for WebApps.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@sitevision/api": "*"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "1928f2e710e25b16b0e3a792bb8d6b9254d72084",
|
|
18
18
|
"dependencies": {}
|
|
19
19
|
}
|
package/client/.eslintrc.js
DELETED