@panomc/sdk 2.0.0-dev.64 → 2.0.0-dev.65
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/core/js/PluginAPI.js +1 -1
- package/core/js/PluginManager.js +2 -2
- package/core/js/__tests__/accessClient.test.js +2 -2
- package/core/js/__tests__/api.util.v1.test.js +2 -2
- package/core/js/__tests__/appStores.test.js +47 -0
- package/core/js/__tests__/pluginUiZip.test.js +1 -1
- package/core/js/__tests__/sdkLevel.test.js +1 -1
- package/core/js/api.util.js +2 -2
- package/core/js/appStores.js +93 -0
- package/core/js/basePath.js +10 -0
- package/core/js/tooltip.util.js +1 -1
- package/package.json +4 -4
package/core/js/PluginAPI.js
CHANGED
package/core/js/PluginManager.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
|
|
3
3
|
import { error as httpError } from "@sveltejs/kit";
|
|
4
|
-
import { browser, dev } from "$app/
|
|
4
|
+
import { browser, dev } from "$app/env";
|
|
5
5
|
import { get, writable } from "svelte/store";
|
|
6
6
|
import ApiUtil from "$lib/api.util.js";
|
|
7
|
-
import { base } from "
|
|
7
|
+
import { base } from "./basePath.js";
|
|
8
8
|
|
|
9
9
|
import { init as initPluginAPI, panoApiClient, panoApiServer } from "$lib/PluginAPI.js";
|
|
10
10
|
import { PanoPlugin } from "@panomc/sdk";
|
|
@@ -17,13 +17,13 @@ function mockHost() {
|
|
|
17
17
|
},
|
|
18
18
|
CSRF_HEADER: 'X-CSRF-Token',
|
|
19
19
|
}));
|
|
20
|
-
mock.module('$app/
|
|
20
|
+
mock.module('$app/env', () => ({
|
|
21
21
|
dev: false,
|
|
22
22
|
get browser() {
|
|
23
23
|
return state.browser;
|
|
24
24
|
},
|
|
25
25
|
}));
|
|
26
|
-
mock.module('
|
|
26
|
+
mock.module('../appStores.js', () => ({ page: pageStore }));
|
|
27
27
|
mock.module('$app/paths', () => ({ base: '' }));
|
|
28
28
|
mock.module('$lib/Store.js', () => ({ initialized: writable(true) }));
|
|
29
29
|
mock.module('$lib/components/ToastContainer.svelte', () => ({ show: async () => {} }));
|
|
@@ -12,12 +12,12 @@ function mockHost() {
|
|
|
12
12
|
},
|
|
13
13
|
CSRF_HEADER: 'X-CSRF-Token',
|
|
14
14
|
}));
|
|
15
|
-
mock.module('$app/
|
|
15
|
+
mock.module('$app/env', () => ({
|
|
16
16
|
get browser() {
|
|
17
17
|
return state.browser;
|
|
18
18
|
},
|
|
19
19
|
}));
|
|
20
|
-
mock.module('
|
|
20
|
+
mock.module('../appStores.js', () => ({ page: readable({ data: {} }) }));
|
|
21
21
|
mock.module('$lib/Store.js', () => ({ initialized: writable(true) }));
|
|
22
22
|
mock.module('$lib/components/ToastContainer.svelte', () => ({ show: async () => {} }));
|
|
23
23
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from 'bun:test';
|
|
2
|
+
import { get } from 'svelte/store';
|
|
3
|
+
|
|
4
|
+
// The server side of the `$app/stores` shapes over `$app/state`. A flag stands for "the host's component context is
|
|
5
|
+
// current": SvelteKit's server `page` throws when it is not.
|
|
6
|
+
const state = { rendering: true, url: new URL('https://pano.example/store') };
|
|
7
|
+
|
|
8
|
+
mock.module('$app/env', () => ({ browser: false, dev: false }));
|
|
9
|
+
mock.module('$app/state', () => {
|
|
10
|
+
const read = (name) => {
|
|
11
|
+
if (!state.rendering) throw new Error(`Can only read \`page.${name}\` on the server during rendering`);
|
|
12
|
+
return name === 'url' ? state.url : name === 'data' ? { from: state.url.pathname } : null;
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
page: new Proxy({}, { get: (_, name) => read(String(name)) }),
|
|
16
|
+
navigating: { from: null, to: null, type: null, willUnload: null, delta: null, complete: null },
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const stores = await import('../appStores.js');
|
|
21
|
+
|
|
22
|
+
describe('appStores on the server', () => {
|
|
23
|
+
test('a read outside the host render throws while no request was captured', () => {
|
|
24
|
+
state.rendering = false;
|
|
25
|
+
expect(() => get(stores.page)).toThrow('during rendering');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('during the host render the page is read from $app/state', () => {
|
|
29
|
+
state.rendering = true;
|
|
30
|
+
expect(get(stores.page).url.pathname).toBe('/store');
|
|
31
|
+
expect(get(stores.page).data).toEqual({ from: '/store' });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('a read outside it gets the page captured by the host app layout', () => {
|
|
35
|
+
state.rendering = true;
|
|
36
|
+
state.url = new URL('https://pano.example/support');
|
|
37
|
+
stores.captureRequestState();
|
|
38
|
+
|
|
39
|
+
state.rendering = false;
|
|
40
|
+
expect(get(stores.page).url.pathname).toBe('/support');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('navigating is null while the server renders', () => {
|
|
44
|
+
state.rendering = false;
|
|
45
|
+
expect(get(stores.navigating)).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -17,7 +17,7 @@ mock.module('$lib/PluginAPI.js', () => ({
|
|
|
17
17
|
panoApiClient: {},
|
|
18
18
|
panoApiServer: {},
|
|
19
19
|
}));
|
|
20
|
-
mock.module('$app/
|
|
20
|
+
mock.module('$app/env', () => ({ browser: false, dev: false }));
|
|
21
21
|
mock.module('$app/paths', () => ({ base: '' }));
|
|
22
22
|
mock.module('@sveltejs/kit', () => ({
|
|
23
23
|
error: (status, message) => Object.assign(new Error(`HTTP ${status} ${message ?? ''}`), { status }),
|
|
@@ -5,7 +5,7 @@ import { get } from 'svelte/store';
|
|
|
5
5
|
|
|
6
6
|
mock.module('$lib/api.util.js', () => ({ default: {} }));
|
|
7
7
|
mock.module('$lib/PluginAPI.js', () => ({ init: () => {}, panoApiClient: {}, panoApiServer: {} }));
|
|
8
|
-
mock.module('$app/
|
|
8
|
+
mock.module('$app/env', () => ({ browser: false, dev: false }));
|
|
9
9
|
mock.module('$app/paths', () => ({ base: '' }));
|
|
10
10
|
mock.module('@sveltejs/kit', () => ({ error: (status) => new Error(`HTTP ${status}`) }));
|
|
11
11
|
|
package/core/js/api.util.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { API_URL, CSRF_HEADER } from "$lib/variables.js";
|
|
2
2
|
import { get } from "svelte/store";
|
|
3
|
-
import { page } from "
|
|
4
|
-
import { browser } from "$app/
|
|
3
|
+
import { page } from "./appStores.js";
|
|
4
|
+
import { browser } from "$app/env";
|
|
5
5
|
import { initialized } from "$lib/Store.js";
|
|
6
6
|
import { show } from "$lib/components/ToastContainer.svelte";
|
|
7
7
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `page` and `navigating` as stores, in the shape SvelteKit 2's `$app/stores` had.
|
|
3
|
+
*
|
|
4
|
+
* SvelteKit 3 removed `$app/stores`; `$app/state` replaces it with rune-based objects whose changes the legacy
|
|
5
|
+
* (non-runes) syntax never sees. These stores read `$app/state`, so `$page` / `$navigating`, `get(page)` and `$:`
|
|
6
|
+
* statements keep working in legacy components and plain modules.
|
|
7
|
+
*
|
|
8
|
+
* On the server `$app/state` can only be read while rendering: a subscription (what `$page` makes during render) takes
|
|
9
|
+
* a snapshot then and never updates. In the browser the store follows the state.
|
|
10
|
+
*
|
|
11
|
+
* A plugin component is compiled with its own copy of Svelte's server runtime, and its `$page` can be read where the
|
|
12
|
+
* host's component context is not current (`$app/state` then throws). The host's app layout calls
|
|
13
|
+
* `captureRequestState()` while it renders, so such a read gets the page of the request being rendered (server
|
|
14
|
+
* rendering is synchronous: no other request runs in between).
|
|
15
|
+
*/
|
|
16
|
+
import { navigating as navigatingState, page as pageState } from "$app/state";
|
|
17
|
+
import { browser } from "$app/env";
|
|
18
|
+
import { toStore } from "svelte/store";
|
|
19
|
+
|
|
20
|
+
function pageSnapshot() {
|
|
21
|
+
return {
|
|
22
|
+
url: pageState.url,
|
|
23
|
+
params: pageState.params,
|
|
24
|
+
route: pageState.route,
|
|
25
|
+
status: pageState.status,
|
|
26
|
+
error: pageState.error,
|
|
27
|
+
data: pageState.data,
|
|
28
|
+
form: pageState.form,
|
|
29
|
+
state: pageState.state,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `null` while no navigation runs, as the SvelteKit 2 store was. */
|
|
34
|
+
function navigatingSnapshot() {
|
|
35
|
+
const navigation = navigatingState;
|
|
36
|
+
|
|
37
|
+
if (!navigation.type) return null;
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
from: navigation.from,
|
|
41
|
+
to: navigation.to,
|
|
42
|
+
type: navigation.type,
|
|
43
|
+
willUnload: navigation.willUnload,
|
|
44
|
+
delta: navigation.delta,
|
|
45
|
+
complete: navigation.complete,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The page of the request the server renders now (see `captureRequestState`). */
|
|
50
|
+
let requestPage = null;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Takes the page of the request being rendered; called by the host's app layout during its render on the server.
|
|
54
|
+
* A no-op in the browser.
|
|
55
|
+
*/
|
|
56
|
+
export function captureRequestState() {
|
|
57
|
+
if (!browser) requestPage = pageSnapshot();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @template T
|
|
62
|
+
* @param {() => T} snapshot
|
|
63
|
+
* @param {() => T | null} fallback the server value when `$app/state` cannot be read here
|
|
64
|
+
* @returns {import("svelte/store").Readable<T>}
|
|
65
|
+
*/
|
|
66
|
+
function stateStore(snapshot, fallback) {
|
|
67
|
+
/** @type {import("svelte/store").Readable<T> | undefined} */
|
|
68
|
+
let clientStore;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
subscribe(run, invalidate) {
|
|
72
|
+
if (!browser) {
|
|
73
|
+
let value;
|
|
74
|
+
try {
|
|
75
|
+
value = snapshot();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
value = fallback();
|
|
78
|
+
if (value === null) throw error;
|
|
79
|
+
}
|
|
80
|
+
run(value);
|
|
81
|
+
return () => {};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
clientStore ??= toStore(snapshot);
|
|
85
|
+
|
|
86
|
+
return clientStore.subscribe(run, invalidate);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const page = stateStore(pageSnapshot, () => requestPage);
|
|
92
|
+
// never navigating while the server renders
|
|
93
|
+
export const navigating = stateStore(navigatingSnapshot, () => null);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's base path: "" for a theme, "/panel" for panel-ui.
|
|
3
|
+
*
|
|
4
|
+
* SvelteKit 3 removed `base` from `$app/paths`. The engine's vite config (`createViteConfig`) defines
|
|
5
|
+
* `__PANO_BASE_PATH__` at build time with the value it gives SvelteKit as `paths.base`, so this is always the absolute
|
|
6
|
+
* path, on the server too (Pano serves every UI at a fixed path, so an absolute and a relative link point at the same
|
|
7
|
+
* place).
|
|
8
|
+
*/
|
|
9
|
+
/* global __PANO_BASE_PATH__ */
|
|
10
|
+
export const base = typeof __PANO_BASE_PATH__ === "string" ? __PANO_BASE_PATH__ : "";
|
package/core/js/tooltip.util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import tippy from 'tippy.js';
|
|
2
2
|
import 'tippy.js/dist/tippy.css';
|
|
3
|
-
import { page } from '
|
|
3
|
+
import { page } from './appStores.js';
|
|
4
4
|
|
|
5
5
|
function setTooltip(element, [value, options]) {
|
|
6
6
|
const instance = typeof element._tippy === 'undefined' ? tippy(element) : element._tippy;
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panomc/sdk",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.65",
|
|
4
4
|
"sdkLine": "2.0.0",
|
|
5
5
|
"author": "PanoMC",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://github.com/PanoMC/sdk"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"svelte": "5.
|
|
10
|
+
"svelte": "5.57.2",
|
|
11
11
|
"tippy.js": "^6.3.7",
|
|
12
12
|
"adm-zip": "^0.6.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"svelte": "5.
|
|
15
|
+
"svelte": "5.57.2"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"svelte": "./src/index.js",
|
|
108
108
|
"type": "module",
|
|
109
109
|
"peerDependencies": {
|
|
110
|
-
"@sveltejs/kit": "^
|
|
110
|
+
"@sveltejs/kit": "^3.1.0"
|
|
111
111
|
},
|
|
112
112
|
"peerDependenciesMeta": {
|
|
113
113
|
"@sveltejs/kit": {
|