@hkdigital/lib-sveltekit 0.1.44 → 0.1.46
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/README.md +8 -2
- package/dist/classes/svelte/image/index.d.ts +2 -2
- package/dist/classes/svelte/image/index.js +2 -2
- package/dist/classes/svelte/network-loader/index.d.ts +1 -1
- package/dist/classes/svelte/network-loader/index.js +1 -1
- package/dist/components/buttons/button/Button.svelte +4 -1
- package/dist/components/buttons/button/Button.svelte.d.ts +1 -0
- package/dist/util/http/http-request.d.ts +9 -4
- package/dist/util/http/http-request.js +32 -11
- package/dist/util/http/response.js +20 -9
- package/dist/util/http/typedef.d.ts +0 -0
- package/dist/util/http/typedef.js +0 -0
- package/dist/widgets/presenter/Presenter.state.svelte.d.ts +2 -2
- package/dist/widgets/presenter/Presenter.state.svelte.js +3 -3
- package/dist/widgets/presenter/typedef.d.ts +14 -5
- package/dist/widgets/presenter/typedef.js +15 -4
- package/package.json +1 -1
package/README.md
CHANGED
@@ -11,6 +11,10 @@ It contains common code and components that we use to create our projects.
|
|
11
11
|
This package is incomplete and not fully tested.
|
12
12
|
Do not use in production environments yet.
|
13
13
|
|
14
|
+
### TODO
|
15
|
+
|
16
|
+
Add information about Skeleton, theming and imagetools
|
17
|
+
|
14
18
|
## A note about tailwindcss
|
15
19
|
|
16
20
|
Components in this package use [tailwindcss](https://tailwindcss.com/).
|
@@ -46,7 +50,7 @@ We use a wildcard to upgrade all installed `node_modules` in the scope `@hkdigit
|
|
46
50
|
You can also add this command to your project. To do so, add the lines to the bottom of the `scripts` section of your `package.json`.
|
47
51
|
|
48
52
|
```bash
|
49
|
-
"upgrade:
|
53
|
+
"upgrade:hk": "ncu --dep dev,optional,peer,prod '@hkdigital/*' -u && pnpm install",
|
50
54
|
"upgrade:all": "ncu -u && pnpm install"
|
51
55
|
```
|
52
56
|
|
@@ -83,7 +87,7 @@ export default {
|
|
83
87
|
'./src/**/*.{html,js,svelte,ts}',
|
84
88
|
```
|
85
89
|
|
86
|
-
## Building the
|
90
|
+
## Building the library
|
87
91
|
|
88
92
|
To build your library:
|
89
93
|
|
@@ -91,6 +95,8 @@ To build your library:
|
|
91
95
|
npm run package
|
92
96
|
```
|
93
97
|
|
98
|
+
## Building the showcase app
|
99
|
+
|
94
100
|
To create a production version of your showcase app:
|
95
101
|
|
96
102
|
```bash
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { default as ImageLoader } from "./ImageLoader.svelte";
|
2
|
-
export { default as ImageVariantsLoader } from "./ImageVariantsLoader.svelte";
|
1
|
+
export { default as ImageLoader } from "./ImageLoader.svelte.js";
|
2
|
+
export { default as ImageVariantsLoader } from "./ImageVariantsLoader.svelte.js";
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export { default as ImageLoader } from './ImageLoader.svelte';
|
2
|
-
export { default as ImageVariantsLoader } from './ImageVariantsLoader.svelte';
|
1
|
+
export { default as ImageLoader } from './ImageLoader.svelte.js';
|
2
|
+
export { default as ImageVariantsLoader } from './ImageVariantsLoader.svelte.js';
|
3
3
|
|
4
4
|
// export * from './constants.js';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { default as NetworkLoader } from "./NetworkLoader.svelte";
|
1
|
+
export { default as NetworkLoader } from "./NetworkLoader.svelte.js";
|
2
2
|
export * from "./constants.js";
|
@@ -11,6 +11,7 @@
|
|
11
11
|
* size?: 'sm' | 'md' | 'lg',
|
12
12
|
* variant?: string,
|
13
13
|
* mode?: 'light'|'dark'
|
14
|
+
* buttonType?: 'button' | 'submit' | 'reset',
|
14
15
|
* active?: boolean,
|
15
16
|
* selected?: boolean,
|
16
17
|
* loading?: boolean,
|
@@ -34,6 +35,8 @@
|
|
34
35
|
variant = '',
|
35
36
|
mode = 'light',
|
36
37
|
|
38
|
+
buttonType = 'button',
|
39
|
+
|
37
40
|
// States
|
38
41
|
active = $bindable(false),
|
39
42
|
selected = $bindable(false),
|
@@ -62,7 +65,7 @@
|
|
62
65
|
data-size={size}
|
63
66
|
data-variant={variant}
|
64
67
|
data-mode={mode}
|
65
|
-
type=
|
68
|
+
type={buttonType}
|
66
69
|
class="{base} {bg} {classes} {stateClasses}"
|
67
70
|
disabled={disabled || loading}
|
68
71
|
aria-busy={loading}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
/**
|
2
2
|
* @callback requestHandler
|
3
|
-
* @param {
|
4
|
-
* @param {
|
5
|
-
* @param {(
|
3
|
+
* @param {Object} _
|
4
|
+
* @param {AbortController} _.controller
|
5
|
+
* @param {( reason?: Error ) => void} _.abort
|
6
|
+
* @param {( delayMs: number) => void} _.timeout
|
6
7
|
*/
|
7
8
|
/**
|
8
9
|
* Make GET request
|
@@ -105,4 +106,8 @@ export function httpRequest({ method, url, urlSearchParams, body, headers, reque
|
|
105
106
|
requestHandler?: requestHandler;
|
106
107
|
timeoutMs?: number;
|
107
108
|
}): Promise<Response>;
|
108
|
-
export type requestHandler = (
|
109
|
+
export type requestHandler = (_: {
|
110
|
+
controller: AbortController;
|
111
|
+
abort: (reason?: Error) => void;
|
112
|
+
timeout: (delayMs: number) => void;
|
113
|
+
}) => any;
|
@@ -13,9 +13,10 @@ import { waitForAndCheckResponse } from './response.js';
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* @callback requestHandler
|
16
|
-
* @param {
|
17
|
-
* @param {
|
18
|
-
* @param {(
|
16
|
+
* @param {Object} _
|
17
|
+
* @param {AbortController} _.controller
|
18
|
+
* @param {( reason?: Error ) => void} _.abort
|
19
|
+
* @param {( delayMs: number) => void} _.timeout
|
19
20
|
*/
|
20
21
|
|
21
22
|
/**
|
@@ -41,7 +42,13 @@ import { waitForAndCheckResponse } from './response.js';
|
|
41
42
|
*
|
42
43
|
* @returns {Promise<Response>} responsePromise
|
43
44
|
*/
|
44
|
-
export async function httpGet({
|
45
|
+
export async function httpGet({
|
46
|
+
url,
|
47
|
+
urlSearchParams,
|
48
|
+
headers,
|
49
|
+
requestHandler,
|
50
|
+
timeoutMs
|
51
|
+
}) {
|
45
52
|
const responsePromise = httpRequest({
|
46
53
|
method: METHOD_GET,
|
47
54
|
url,
|
@@ -76,7 +83,13 @@ export async function httpGet({ url, urlSearchParams, headers, requestHandler, t
|
|
76
83
|
*
|
77
84
|
* @returns {Promise<Response>} responsePromise
|
78
85
|
*/
|
79
|
-
export async function httpPost({
|
86
|
+
export async function httpPost({
|
87
|
+
url,
|
88
|
+
body = null,
|
89
|
+
headers,
|
90
|
+
requestHandler,
|
91
|
+
timeoutMs
|
92
|
+
}) {
|
80
93
|
const responsePromise = httpRequest({
|
81
94
|
method: METHOD_POST,
|
82
95
|
url,
|
@@ -142,7 +155,10 @@ export async function httpRequest({
|
|
142
155
|
if (headers) {
|
143
156
|
setRequestHeaders(requestHeaders, headers);
|
144
157
|
|
145
|
-
if (
|
158
|
+
if (
|
159
|
+
headers[CONTENT_TYPE] === APPLICATION_JSON &&
|
160
|
+
typeof body !== 'string'
|
161
|
+
) {
|
146
162
|
throw new Error(
|
147
163
|
`Trying to send request with [content-type:${APPLICATION_JSON}], ` +
|
148
164
|
'but body is not a (JSON encoded) string.'
|
@@ -151,6 +167,7 @@ export async function httpRequest({
|
|
151
167
|
// IDEA: try to decode the body to catch errors on client side
|
152
168
|
}
|
153
169
|
|
170
|
+
/** @type {RequestInit} */
|
154
171
|
const init = {
|
155
172
|
mode: 'cors',
|
156
173
|
cache: 'no-cache',
|
@@ -165,7 +182,8 @@ export async function httpRequest({
|
|
165
182
|
if (urlSearchParams) {
|
166
183
|
if (!(urlSearchParams instanceof URLSearchParams)) {
|
167
184
|
throw new Error(
|
168
|
-
'Invalid parameter [urlSearchParams] ' +
|
185
|
+
'Invalid parameter [urlSearchParams] ' +
|
186
|
+
'(expected instanceof URLSearchParams)'
|
169
187
|
);
|
170
188
|
}
|
171
189
|
|
@@ -174,7 +192,8 @@ export async function httpRequest({
|
|
174
192
|
for (const [name, value] of urlSearchParams.entries()) {
|
175
193
|
if (existingParams.has(name)) {
|
176
194
|
throw new Error(
|
177
|
-
`Cannot set URL search parameter [${name}] ` +
|
195
|
+
`Cannot set URL search parameter [${name}] ` +
|
196
|
+
`in url [${url.href}] (already set)`
|
178
197
|
);
|
179
198
|
}
|
180
199
|
|
@@ -246,10 +265,12 @@ export async function httpRequest({
|
|
246
265
|
* @param {number} delayMs
|
247
266
|
*/
|
248
267
|
const timeout = (delayMs = 10000) => {
|
249
|
-
expect.positiveNumber(delayMs
|
268
|
+
expect.positiveNumber(delayMs);
|
250
269
|
|
251
270
|
const timerId = setTimeout(() => {
|
252
|
-
controller.abort(
|
271
|
+
controller.abort(
|
272
|
+
new TimeoutError(`Request [${url.href}] timed out [${delayMs}]`)
|
273
|
+
);
|
253
274
|
}, delayMs);
|
254
275
|
|
255
276
|
promise.finally(() => {
|
@@ -262,7 +283,7 @@ export async function httpRequest({
|
|
262
283
|
}
|
263
284
|
|
264
285
|
if (requestHandler) {
|
265
|
-
expect.function(requestHandler
|
286
|
+
expect.function(requestHandler);
|
266
287
|
|
267
288
|
requestHandler({ controller, abort, timeout });
|
268
289
|
}
|
@@ -2,7 +2,10 @@ import { ResponseError } from '../../constants/errors/index.js';
|
|
2
2
|
import * as expect from '../expect/index.js';
|
3
3
|
import { toURL } from './url.js';
|
4
4
|
|
5
|
-
import {
|
5
|
+
import {
|
6
|
+
WWW_AUTHENTICATE,
|
7
|
+
CONTENT_LENGTH
|
8
|
+
} from '../../constants/http/headers.js';
|
6
9
|
|
7
10
|
import { href } from './url.js';
|
8
11
|
|
@@ -69,7 +72,8 @@ export async function expectResponseOk(response, url) {
|
|
69
72
|
const error = await getErrorFromResponse(response);
|
70
73
|
|
71
74
|
throw new ResponseError(
|
72
|
-
`Server returned - ${response.status} ${response.statusText} ` +
|
75
|
+
`Server returned - ${response.status} ${response.statusText} ` +
|
76
|
+
`[url=${href(url)}]`,
|
73
77
|
{ cause: error }
|
74
78
|
);
|
75
79
|
}
|
@@ -120,9 +124,12 @@ export async function waitForAndCheckResponse(responsePromise, url) {
|
|
120
124
|
}
|
121
125
|
} catch (e) {
|
122
126
|
if (e instanceof TypeError || response?.ok === false) {
|
123
|
-
throw new ResponseError(
|
124
|
-
|
125
|
-
|
127
|
+
throw new ResponseError(
|
128
|
+
`A network error occurred for request [${href(url)}]`,
|
129
|
+
{
|
130
|
+
cause: e
|
131
|
+
}
|
132
|
+
);
|
126
133
|
} else {
|
127
134
|
throw e;
|
128
135
|
}
|
@@ -148,7 +155,7 @@ export function loadResponseBuffer(response, onProgress) {
|
|
148
155
|
|
149
156
|
let bytesLoaded = 0;
|
150
157
|
|
151
|
-
if (onProgress
|
158
|
+
if (onProgress /*&& size*/) {
|
152
159
|
onProgress({ bytesLoaded, size });
|
153
160
|
}
|
154
161
|
|
@@ -182,12 +189,14 @@ export function loadResponseBuffer(response, onProgress) {
|
|
182
189
|
// console.log({ size, bytesLoaded, value });
|
183
190
|
|
184
191
|
if (size && bytesLoaded > size) {
|
185
|
-
throw new Error(
|
192
|
+
throw new Error(
|
193
|
+
`Received more bytes that specified by header content-length`
|
194
|
+
);
|
186
195
|
}
|
187
196
|
|
188
197
|
chunks.push(value);
|
189
198
|
|
190
|
-
if (onProgress
|
199
|
+
if (onProgress /*&& size*/) {
|
191
200
|
onProgress({ bytesLoaded, size });
|
192
201
|
}
|
193
202
|
}
|
@@ -199,7 +208,9 @@ export function loadResponseBuffer(response, onProgress) {
|
|
199
208
|
} // end while
|
200
209
|
|
201
210
|
if (size && bytesLoaded !== size) {
|
202
|
-
throw new Error(
|
211
|
+
throw new Error(
|
212
|
+
`Received [${bytesLoaded}], but expected [${size}] bytes`
|
213
|
+
);
|
203
214
|
}
|
204
215
|
|
205
216
|
// Concat the chinks into a single array
|
File without changes
|
File without changes
|
@@ -68,6 +68,6 @@ export class PresenterState {
|
|
68
68
|
export type Slide = import("./typedef").Slide;
|
69
69
|
export type Transition = import("./typedef").Transition;
|
70
70
|
export type Layer = import("./typedef").Layer;
|
71
|
-
export type PresenterRef = import("./typedef").
|
72
|
-
export type LoadController = import("./typedef").
|
71
|
+
export type PresenterRef = import("./typedef").PresenterRef;
|
72
|
+
export type LoadController = import("./typedef").LoadController;
|
73
73
|
import { HkPromise } from '../../classes/promise/index.js';
|
@@ -21,11 +21,11 @@ import { STAGE_BEFORE, STAGE_SHOW } from './constants.js';
|
|
21
21
|
*/
|
22
22
|
|
23
23
|
/**
|
24
|
-
* @typedef {import("./typedef").
|
24
|
+
* @typedef {import("./typedef").PresenterRef} PresenterRef
|
25
25
|
*/
|
26
26
|
|
27
27
|
/**
|
28
|
-
* @typedef {import("./typedef").
|
28
|
+
* @typedef {import("./typedef").LoadController} LoadController
|
29
29
|
*/
|
30
30
|
|
31
31
|
const Z_BACK = 0;
|
@@ -589,7 +589,7 @@ export class PresenterState {
|
|
589
589
|
this.onBeforeListeners.delete(key);
|
590
590
|
};
|
591
591
|
},
|
592
|
-
|
592
|
+
onShow: (callback) => {
|
593
593
|
const key = Symbol();
|
594
594
|
this.onShowListeners.set(key, callback);
|
595
595
|
|
@@ -25,10 +25,6 @@ export type FadeOutTransition = {
|
|
25
25
|
duration?: number;
|
26
26
|
timing?: string;
|
27
27
|
};
|
28
|
-
export type ListenerParams = {
|
29
|
-
stage: string;
|
30
|
-
slideName: string;
|
31
|
-
};
|
32
28
|
export type LoadController = {
|
33
29
|
/**
|
34
30
|
* - Function to call when loading is complete
|
@@ -39,6 +35,12 @@ export type LoadController = {
|
|
39
35
|
*/
|
40
36
|
cancel: () => void;
|
41
37
|
};
|
38
|
+
export type ListenerParams = {
|
39
|
+
stage: string;
|
40
|
+
slideName: string;
|
41
|
+
};
|
42
|
+
export type ListenerCallback = (params: ListenerParams) => () => void;
|
43
|
+
export type UnregisterFn = () => void;
|
42
44
|
export type PresenterRef = {
|
43
45
|
/**
|
44
46
|
* - Navigate to a slide by name
|
@@ -48,7 +50,14 @@ export type PresenterRef = {
|
|
48
50
|
* - Get the current slide name
|
49
51
|
*/
|
50
52
|
getCurrentSlideName: () => string;
|
51
|
-
|
53
|
+
/**
|
54
|
+
* Register listener that is called when a slide enters state 'before'
|
55
|
+
*/
|
56
|
+
onBefore: (callback: ListenerCallback) => UnregisterFn;
|
57
|
+
/**
|
58
|
+
* Register listener that is called when a slide enters state 'show'
|
59
|
+
*/
|
60
|
+
onShow: (callback: ListenerCallback) => UnregisterFn;
|
52
61
|
};
|
53
62
|
export type Transition = CssTransition | FadeInTransition | FadeOutTransition;
|
54
63
|
export type SlideData = {
|
@@ -32,6 +32,12 @@
|
|
32
32
|
* }} FadeOutTransition
|
33
33
|
*/
|
34
34
|
|
35
|
+
/**
|
36
|
+
* @typedef {Object} LoadController
|
37
|
+
* @property {() => void} loaded - Function to call when loading is complete
|
38
|
+
* @property {() => void} cancel - Function to return to the previous slide
|
39
|
+
*/
|
40
|
+
|
35
41
|
/**
|
36
42
|
* @typedef {{
|
37
43
|
* stage: string,
|
@@ -40,16 +46,21 @@
|
|
40
46
|
*/
|
41
47
|
|
42
48
|
/**
|
43
|
-
* @typedef {
|
44
|
-
|
45
|
-
|
49
|
+
* @typedef {( params: ListenerParams) => () => void } ListenerCallback
|
50
|
+
*/
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @typedef {() => void } UnregisterFn
|
46
54
|
*/
|
47
55
|
|
48
56
|
/**
|
49
57
|
* @typedef {Object} PresenterRef
|
50
58
|
* @property {(name: string) => void} gotoSlide - Navigate to a slide by name
|
51
59
|
* @property {() => string} getCurrentSlideName - Get the current slide name
|
52
|
-
* @property {(callback)=>
|
60
|
+
* @property {( callback: ListenerCallback ) => UnregisterFn} onBefore
|
61
|
+
* Register listener that is called when a slide enters state 'before'
|
62
|
+
* @property {( callback: ListenerCallback ) => UnregisterFn} onShow
|
63
|
+
* Register listener that is called when a slide enters state 'show'
|
53
64
|
*/
|
54
65
|
|
55
66
|
/**
|