@panomc/sdk 1.0.0-dev.8 → 2.0.0-dev.61
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/api/routes.core.json +3702 -0
- package/bin/api/__tests__/api-compat.test.mjs +97 -0
- package/bin/api/__tests__/check-paths.test.mjs +113 -0
- package/bin/api/__tests__/cli.test.mjs +44 -0
- package/bin/api/__tests__/extract-routes.test.mjs +132 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/api/paths.old-new.json +82 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
- package/bin/api/__tests__/fixtures/plugin-new/api/paths.old-new.json +66 -0
- package/bin/api/__tests__/fixtures/plugin-new/build.gradle.kts +42 -0
- package/bin/api/__tests__/fixtures/plugin-new/gradle.properties +4 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/panel/Things.js +4 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/theme/Logo.svelte +9 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/theme/api.js +29 -0
- package/bin/api/__tests__/fixtures/plugin-old/build.gradle.kts +22 -0
- package/bin/api/__tests__/fixtures/plugin-old/gradle.properties +4 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/panel/Things.js +4 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/theme/Logo.svelte +9 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/theme/api.js +29 -0
- package/bin/api/__tests__/fixtures/refusals/gradle.properties +1 -0
- package/bin/api/__tests__/fixtures/refusals/src/main/kotlin/x/Bad.kt +39 -0
- package/bin/api/__tests__/fixtures/unresolved/src/main/kotlin/x/Orphan.kt +19 -0
- package/bin/api/__tests__/helpers.mjs +48 -0
- package/bin/api/__tests__/migrate-v1.test.mjs +377 -0
- package/bin/api/__tests__/openapi-snapshot.test.mjs +120 -0
- package/bin/api/api-compat.mjs +204 -0
- package/bin/api/check-paths.mjs +135 -0
- package/bin/api/cli.mjs +83 -0
- package/bin/api/extract-routes.mjs +129 -0
- package/bin/api/js-scan.mjs +337 -0
- package/bin/api/kotlin.mjs +366 -0
- package/bin/api/migrate-v1.mjs +330 -0
- package/bin/api/openapi-snapshot.mjs +112 -0
- package/bin/api/project.mjs +172 -0
- package/bin/api/rename-table.mjs +66 -0
- package/bin/api/util.mjs +194 -0
- package/bin/pano-api.js +5 -0
- package/build/plugin-api-rollup.js +46 -0
- package/core/css/pano-tokens.css +225 -0
- package/core/favicon/apple-touch-icon.png +0 -0
- package/core/favicon/favicon-96x96.png +0 -0
- package/core/favicon/favicon.ico +0 -0
- package/core/favicon/favicon.svg +1 -0
- package/core/favicon/site.webmanifest +21 -0
- package/core/favicon/web-app-manifest-192x192.png +0 -0
- package/core/favicon/web-app-manifest-512x512.png +0 -0
- package/core/favicon_old/android-icon-144x144.png +0 -0
- package/core/favicon_old/android-icon-192x192.png +0 -0
- package/core/favicon_old/android-icon-36x36.png +0 -0
- package/core/favicon_old/android-icon-48x48.png +0 -0
- package/core/favicon_old/android-icon-72x72.png +0 -0
- package/core/favicon_old/android-icon-96x96.png +0 -0
- package/core/favicon_old/apple-icon-114x114.png +0 -0
- package/core/favicon_old/apple-icon-120x120.png +0 -0
- package/core/favicon_old/apple-icon-144x144.png +0 -0
- package/core/favicon_old/apple-icon-152x152.png +0 -0
- package/core/favicon_old/apple-icon-180x180.png +0 -0
- package/core/favicon_old/apple-icon-57x57.png +0 -0
- package/core/favicon_old/apple-icon-60x60.png +0 -0
- package/core/favicon_old/apple-icon-72x72.png +0 -0
- package/core/favicon_old/apple-icon-76x76.png +0 -0
- package/core/favicon_old/apple-icon-precomposed.png +0 -0
- package/core/favicon_old/apple-icon.png +0 -0
- package/core/favicon_old/browserconfig.xml +11 -0
- package/core/favicon_old/favicon-16x16.png +0 -0
- package/core/favicon_old/favicon-32x32.png +0 -0
- package/core/favicon_old/favicon-96x96.png +0 -0
- package/core/favicon_old/favicon.ico +0 -0
- package/core/favicon_old/manifest.json +41 -0
- package/core/favicon_old/ms-icon-144x144.png +0 -0
- package/core/favicon_old/ms-icon-150x150.png +0 -0
- package/core/favicon_old/ms-icon-310x310.png +0 -0
- package/core/favicon_old/ms-icon-70x70.png +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.svg +483 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff2 +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.svg +486 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff2 +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.svg +484 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff2 +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.svg +486 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff2 +0 -0
- package/core/js/ControllerRegistry.js +421 -0
- package/core/js/NotificationManager.js +62 -0
- package/core/js/PluginAPI.js +39 -0
- package/core/js/PluginManager.js +851 -0
- package/core/js/RouteMatcher.js +142 -0
- package/core/js/__tests__/ControllerRegistry.test.js +378 -0
- package/core/js/__tests__/NotificationManager.test.js +57 -0
- package/core/js/__tests__/PluginAPI.test.js +25 -0
- package/core/js/__tests__/RouteMatcher.test.js +33 -0
- package/core/js/__tests__/accessClient.test.js +582 -0
- package/core/js/__tests__/api.util.v1.test.js +336 -0
- package/core/js/__tests__/devBounce.test.js +28 -0
- package/core/js/__tests__/html.util.test.js +18 -0
- package/core/js/__tests__/pluginFolder.util.test.js +106 -0
- package/core/js/__tests__/pluginPackage.test.js +134 -0
- package/core/js/__tests__/pluginUiZip.test.js +47 -0
- package/core/js/__tests__/sdkLevel.test.js +34 -0
- package/core/js/api.util.js +433 -0
- package/core/js/html.util.js +26 -0
- package/core/js/pluginFolder.util.js +95 -0
- package/core/js/tooltip.util.js +59 -0
- package/core/js/variables.js +95 -0
- package/core/js/version.util.js +100 -0
- package/core/scss/_pano-tokens.scss +51 -0
- package/core/scss/custom-bootstrap.scss +196 -0
- package/core/scss/fonts.scss +85 -0
- package/core/scss/main.scss +389 -0
- package/core/scss/themes.scss +120 -0
- package/package.json +50 -10
- package/src/__tests__/controllers.test.js +220 -0
- package/src/__tests__/views.spike.test.js +472 -0
- package/src/components/{index.js → panel.js} +9 -6
- package/src/components/theme.js +18 -0
- package/src/controllers.js +127 -0
- package/src/index.js +1 -1
- package/src/svelte.js +3 -2
- package/src/types.js +5 -3
- package/src/utils/api.js +42 -1
- package/src/utils/auth.js +8 -0
- package/src/utils/component.js +4 -2
- package/src/utils/route.js +16 -0
- package/src/utils/text.js +8 -0
- package/src/views.js +29 -0
|
@@ -3,17 +3,20 @@ import { getPanoContext } from '../internal/index.js';
|
|
|
3
3
|
const panoContext = getPanoContext();
|
|
4
4
|
const components = panoContext.context.components;
|
|
5
5
|
|
|
6
|
+
export const NoContent = components.NoContent;
|
|
7
|
+
export const Editor = components.Editor;
|
|
8
|
+
export const DragAndDropZone = components.DragAndDropZone;
|
|
9
|
+
export const Date = components.Date;
|
|
10
|
+
export const Toast = components.Toast;
|
|
11
|
+
|
|
12
|
+
export const PageLoading = components.PageLoading;
|
|
6
13
|
export const PageActions = components.PageActions;
|
|
7
14
|
export const PageLoader = components.PageLoader;
|
|
8
15
|
export const PageNavItem = components.PageNavItem;
|
|
9
16
|
export const PageNav = components.PageNav;
|
|
10
17
|
export const Pagination = components.Pagination;
|
|
11
|
-
|
|
12
|
-
export const Toast = components.Toast;
|
|
18
|
+
|
|
13
19
|
export const CardFilters = components.CardFilters;
|
|
14
20
|
export const CardFiltersItem = components.CardFiltersItem;
|
|
15
21
|
export const CardHeader = components.CardHeader;
|
|
16
|
-
export const
|
|
17
|
-
export const CardMenuItem = components.CardMenuItem;
|
|
18
|
-
export const Date = components.Date;
|
|
19
|
-
export const NoContent = components.NoContent;
|
|
22
|
+
export const SearchInput = components.SearchInput;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getPanoContext } from "../internal/index.js";
|
|
2
|
+
|
|
3
|
+
const panoContext = getPanoContext();
|
|
4
|
+
const components = panoContext.context.components;
|
|
5
|
+
|
|
6
|
+
export const PlayerHead = components.PlayerHead;
|
|
7
|
+
export const NoContent = components.NoContent;
|
|
8
|
+
export const Date = components.Date;
|
|
9
|
+
export const Toast = components.Toast;
|
|
10
|
+
|
|
11
|
+
export const PageTitle = components.PageTitle;
|
|
12
|
+
export const PageActions = components.PageActions;
|
|
13
|
+
export const Pagination = components.Pagination;
|
|
14
|
+
|
|
15
|
+
// Views of other plugins (doc 01 sections 5 and 6): `<PluginBlock id="market:ProductGrid" limit={8} />` places a
|
|
16
|
+
// registered view with its own data, `<PluginSlot id="market:checkout:payment" />` opens a slot for injected views.
|
|
17
|
+
export const PluginBlock = components.PluginBlock;
|
|
18
|
+
export const PluginSlot = components.PluginSlot;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte wrapper over the controller registry (doc 02 §2), exported as `@panomc/sdk/controllers`.
|
|
3
|
+
* Plain JS on `createSubscriber`: rune-style reads without rune compilation.
|
|
4
|
+
*/
|
|
5
|
+
import { createSubscriber } from 'svelte/reactivity';
|
|
6
|
+
import { onMount } from 'svelte';
|
|
7
|
+
import * as registry from '../core/js/ControllerRegistry.js';
|
|
8
|
+
import { getPanoContext } from './internal/index.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {{name:string, version:number, get:()=>any, subscribe:(run:(s:any)=>void)=>(()=>void), actions:any, destroy:()=>void}} Controller
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a controller so `.state` is a tracked getter: reading it inside an effect or a template re-runs on change.
|
|
16
|
+
* @param {Controller} controller
|
|
17
|
+
* @returns {{ state: any, actions: any, controller: Controller }}
|
|
18
|
+
*/
|
|
19
|
+
export function reactive(controller) {
|
|
20
|
+
const track = createSubscriber((update) => {
|
|
21
|
+
let ready = false;
|
|
22
|
+
// subscribe() calls back synchronously once with the current state; that is not a change
|
|
23
|
+
const unsubscribe = controller.subscribe(() => {
|
|
24
|
+
if (ready) update();
|
|
25
|
+
});
|
|
26
|
+
ready = true;
|
|
27
|
+
return unsubscribe;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
controller,
|
|
32
|
+
actions: controller.actions,
|
|
33
|
+
get state() {
|
|
34
|
+
track();
|
|
35
|
+
return controller.get();
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Registry `use` plus `reactive`. Returns null when the controller is unavailable (missing plugin, version mismatch).
|
|
42
|
+
* An `instance` scoped controller is destroyed when the calling component unmounts.
|
|
43
|
+
* @param {string} name `<namespace>/<controller>`
|
|
44
|
+
* @param {{version?:number, params?:object, initial?:object, event?:any}} [opts]
|
|
45
|
+
*/
|
|
46
|
+
export function useController(name, opts) {
|
|
47
|
+
const controller = registry.use(name, opts);
|
|
48
|
+
if (!controller) return null;
|
|
49
|
+
|
|
50
|
+
const isInstance = registry.list().find((c) => c.name === name)?.scope === 'instance';
|
|
51
|
+
|
|
52
|
+
if (isInstance && typeof window !== 'undefined') {
|
|
53
|
+
try {
|
|
54
|
+
onMount(() => () => controller.destroy());
|
|
55
|
+
} catch {
|
|
56
|
+
// called outside a component: the caller owns destroy()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return reactive(controller);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} namespace
|
|
65
|
+
*/
|
|
66
|
+
export function plugin(namespace) {
|
|
67
|
+
const pluginId = () => registry.pluginIdOf(namespace) ?? `pano-plugin-${namespace}`;
|
|
68
|
+
const prefix = () => `plugins.${pluginId()}.`;
|
|
69
|
+
const fullName = (name) => `${namespace}/${name}`;
|
|
70
|
+
const language = () => getPanoContext().context?.utils?.language?._;
|
|
71
|
+
|
|
72
|
+
/** readable store of `(key, values) => string` */
|
|
73
|
+
const _ = {
|
|
74
|
+
subscribe(run) {
|
|
75
|
+
const source = language();
|
|
76
|
+
const p = prefix();
|
|
77
|
+
|
|
78
|
+
if (!source || typeof source.subscribe !== 'function') {
|
|
79
|
+
run((key) => `${p}${key}`);
|
|
80
|
+
return () => {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return source.subscribe(($fn) => {
|
|
84
|
+
run((key, values) => $fn(`${p}${key}`, toI18nOptions(values)));
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
get id() {
|
|
91
|
+
return pluginId();
|
|
92
|
+
},
|
|
93
|
+
namespace,
|
|
94
|
+
get installed() {
|
|
95
|
+
return registry.pluginIdOf(namespace) !== undefined;
|
|
96
|
+
},
|
|
97
|
+
_,
|
|
98
|
+
/**
|
|
99
|
+
* @param {string} key key inside the plugin's text; the `plugins.<pluginId>.` prefix is added
|
|
100
|
+
* @param {{variant?:'success'|'danger'|'warning', values?:object}} [o]
|
|
101
|
+
*/
|
|
102
|
+
toast(key, o) {
|
|
103
|
+
const show = getPanoContext().context?.utils?.toast?.show;
|
|
104
|
+
if (typeof show !== 'function') return;
|
|
105
|
+
const options = o?.variant ? { variant: o.variant } : undefined;
|
|
106
|
+
return show(`${prefix()}${key}`, o?.values ?? {}, undefined, options);
|
|
107
|
+
},
|
|
108
|
+
use(name, opts) {
|
|
109
|
+
return useController(fullName(name), opts);
|
|
110
|
+
},
|
|
111
|
+
require(name, opts) {
|
|
112
|
+
const c = useController(fullName(name), opts);
|
|
113
|
+
if (!c) throw new Error(`${fullName(name)} is not available`);
|
|
114
|
+
return c;
|
|
115
|
+
},
|
|
116
|
+
load(name, opts) {
|
|
117
|
+
return registry.load(fullName(name), opts);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// `values` object (doc 02) or an svelte-i18n options object ({ values, default, ... }) are both accepted
|
|
123
|
+
function toI18nOptions(arg) {
|
|
124
|
+
if (!arg || typeof arg !== 'object') return undefined;
|
|
125
|
+
if ('values' in arg || 'default' in arg || 'locale' in arg || 'format' in arg) return arg;
|
|
126
|
+
return { values: arg };
|
|
127
|
+
}
|
package/src/index.js
CHANGED
package/src/svelte.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getPanoContext } from './internal/index.js';
|
|
2
2
|
|
|
3
3
|
const panoContext = getPanoContext();
|
|
4
|
-
const { page, base, navigating, browser } =
|
|
4
|
+
const { page, base, navigating, browser, goto, invalidate, invalidateAll, error, redirect } =
|
|
5
|
+
panoContext.context;
|
|
5
6
|
|
|
6
|
-
export { page, base, navigating, browser };
|
|
7
|
+
export { page, base, navigating, browser, goto, invalidate, invalidateAll, error, redirect };
|
package/src/types.js
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
* @property {any} utils.api.ApiUtil
|
|
17
17
|
* @property {function(Record<string, any>): string} utils.api.buildQueryParams
|
|
18
18
|
* @property {string} utils.api.NETWORK_ERROR
|
|
19
|
-
* @property {
|
|
20
|
-
*
|
|
21
|
-
* @property {string} utils.api.networkErrorBody
|
|
19
|
+
* @property {function(string): any} utils.api.createPluginApi - `createPluginApi(pluginId)` (the full plugin id): a client scoped
|
|
20
|
+
* to `/api/plugins/<pluginId>/...` (unversioned; `.get`, `.post`, ... and `.panel.*`); same options and same error envelope as `ApiUtil`
|
|
21
|
+
* @property {{ error: { code: string, message?: string, details?: any, fields?: Record<string, string> } }} utils.api.networkErrorBody
|
|
22
|
+
* The body of a failed call, also the one a network failure produces (code `NETWORK_ERROR`):
|
|
23
|
+
* `{ error: { code, message?, details?, fields? } }`. Test `body.error?.code`; a success body has no `error` key.
|
|
22
24
|
* @property {Object} utils.language
|
|
23
25
|
* @property {any} utils.language.init
|
|
24
26
|
* @property {any} utils.language._ - i18n store or function
|
package/src/utils/api.js
CHANGED
|
@@ -9,6 +9,47 @@ const NETWORK_ERROR = apiStuff.NETWORK_ERROR;
|
|
|
9
9
|
const networkErrorBody = apiStuff.networkErrorBody;
|
|
10
10
|
const buildQueryParams = apiStuff.buildQueryParams;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const PLUGIN_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Plugin-scoped client (doc 04 section 9): `createPluginApi('pano-plugin-market').get({ path: '/store/products' })`
|
|
16
|
+
* calls `/api/plugins/pano-plugin-market/store/products`, `.panel.get(...)` the `/api/plugins/<id>/panel/...`
|
|
17
|
+
* twin (decision 81: plugin endpoints are unversioned). Takes the options of the matching `ApiUtil` method. The host's own implementation is used when it provides
|
|
18
|
+
* one (same behaviour); otherwise this one builds the prefixed call on the host's `ApiUtil`, so the module works
|
|
19
|
+
* with every host version.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} pluginId the full plugin id (`pano-plugin-market`), never the short namespace
|
|
22
|
+
*/
|
|
23
|
+
const createPluginApi =
|
|
24
|
+
apiStuff.createPluginApi ??
|
|
25
|
+
function createPluginApi(pluginId) {
|
|
26
|
+
if (typeof pluginId !== 'string' || !PLUGIN_ID_PATTERN.test(pluginId)) {
|
|
27
|
+
throw new Error(`[pano] createPluginApi needs the full plugin id, got ${JSON.stringify(pluginId)}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const scoped = (prefix) => {
|
|
31
|
+
const wrap = (method) => async (options = {}) => {
|
|
32
|
+
let path = String(options.path ?? '');
|
|
33
|
+
if (!path.startsWith('/')) path = `/${path}`;
|
|
34
|
+
if (!import.meta.env?.PROD && /^\/api(?:[/?#]|$)/.test(path)) {
|
|
35
|
+
throw new Error(`[pano] path must not start with /api: write '${path.replace(/^\/api/, '') || '/'}'`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return ApiUtil[method]({ ...options, unversioned: true, path: `${prefix}${path}` });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
get: wrap('get'),
|
|
43
|
+
post: wrap('post'),
|
|
44
|
+
put: wrap('put'),
|
|
45
|
+
delete: wrap('delete'),
|
|
46
|
+
customRequest: wrap('customRequest'),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return { ...scoped(`/plugins/${pluginId}`), panel: scoped(`/plugins/${pluginId}/panel`) };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { ApiUtil, NETWORK_ERROR, networkErrorBody, buildQueryParams, createPluginApi };
|
|
13
54
|
|
|
14
55
|
export default ApiUtil;
|
package/src/utils/component.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mount, unmount
|
|
1
|
+
import { hydrate, mount, unmount } from 'svelte';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Wraps a dynamic component import to include the correct Svelte runtime mount/unmount methods.
|
|
@@ -8,7 +8,7 @@ import { mount, unmount, hydrate } from 'svelte';
|
|
|
8
8
|
* @returns {() => Promise<any>} - Wrapped importer
|
|
9
9
|
*/
|
|
10
10
|
export function viewComponent(importer) {
|
|
11
|
-
|
|
11
|
+
const wrapper = async () => {
|
|
12
12
|
const module = await importer();
|
|
13
13
|
return {
|
|
14
14
|
...module,
|
|
@@ -17,4 +17,6 @@ export function viewComponent(importer) {
|
|
|
17
17
|
hydrate: (options) => hydrate(module.default, options),
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
+
wrapper._importer = importer;
|
|
21
|
+
return wrapper;
|
|
20
22
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getPanoContext } from "../internal/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maps a canonical site path to the path the active theme publishes it under
|
|
5
|
+
* (`@panomc/sdk/utils/route`, doc 01 section 9). A theme that renames a route in
|
|
6
|
+
* `theme.config.js` makes `route("/profile")` answer the new path; outside a theme
|
|
7
|
+
* (or before the theme registered its route map) the path is returned unchanged.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} p canonical path, optionally with a query string or hash
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function route(p) {
|
|
13
|
+
const resolve = getPanoContext().context?.routes?.resolve;
|
|
14
|
+
|
|
15
|
+
return typeof resolve === "function" ? resolve(p) : p;
|
|
16
|
+
}
|
package/src/views.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getPanoContext } from "./internal/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Run-time proxy of a plugin view (`@panomc/sdk/views`, doc 01 section 4).
|
|
5
|
+
*
|
|
6
|
+
* The plugin build rewrites every import of a view file to a proxy module that
|
|
7
|
+
* calls this with the view id (`market:ProductCard`) and the view's own compiled
|
|
8
|
+
* component. At render time the proxy asks the host registry, through the pano
|
|
9
|
+
* context on `globalThis` (the one object the browser copy and both server
|
|
10
|
+
* copies of the SDK share), whether the active theme overrides the view.
|
|
11
|
+
*
|
|
12
|
+
* Outside a theme (panel, widget build) `context.views` is undefined, so the
|
|
13
|
+
* default view always renders. `views.wrap` is the fallback-style hook of doc 03
|
|
14
|
+
* section 4.4; it is the identity in a Bootstrap theme.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} name view id, `<ns>:<Name>`
|
|
17
|
+
* @param {Function} Default the plugin's own compiled Svelte component
|
|
18
|
+
* @returns {Function} a Svelte 5 component function
|
|
19
|
+
*/
|
|
20
|
+
export const createViewProxy = (name, Default) =>
|
|
21
|
+
function PanoView(anchorOrPayload, props) {
|
|
22
|
+
const views = getPanoContext().context?.views;
|
|
23
|
+
const Override = views?.getOverride?.(name);
|
|
24
|
+
const C = Override ?? Default;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
views?.wrap?.(name, C, Override ? "override" : "default") ?? C
|
|
28
|
+
)(anchorOrPayload, props);
|
|
29
|
+
};
|