@panomc/sdk 1.0.0-dev.9 → 2.0.0-dev.1

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.
Files changed (166) hide show
  1. package/api/routes.core.json +3702 -0
  2. package/bin/api/__tests__/api-compat.test.mjs +97 -0
  3. package/bin/api/__tests__/check-paths.test.mjs +113 -0
  4. package/bin/api/__tests__/cli.test.mjs +44 -0
  5. package/bin/api/__tests__/extract-routes.test.mjs +132 -0
  6. package/bin/api/__tests__/fixtures/core-new/Pano/api/paths.old-new.json +82 -0
  7. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
  8. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
  9. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
  10. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
  11. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
  12. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
  13. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
  14. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
  15. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
  16. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
  17. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
  18. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
  19. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
  20. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
  21. package/bin/api/__tests__/fixtures/plugin-new/api/paths.old-new.json +66 -0
  22. package/bin/api/__tests__/fixtures/plugin-new/build.gradle.kts +42 -0
  23. package/bin/api/__tests__/fixtures/plugin-new/gradle.properties +4 -0
  24. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
  25. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
  26. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
  27. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
  28. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
  29. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
  30. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
  31. package/bin/api/__tests__/fixtures/plugin-new/src/panel/Things.js +4 -0
  32. package/bin/api/__tests__/fixtures/plugin-new/src/theme/Logo.svelte +9 -0
  33. package/bin/api/__tests__/fixtures/plugin-new/src/theme/api.js +29 -0
  34. package/bin/api/__tests__/fixtures/plugin-old/build.gradle.kts +22 -0
  35. package/bin/api/__tests__/fixtures/plugin-old/gradle.properties +4 -0
  36. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
  37. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
  38. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
  39. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
  40. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
  41. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
  42. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
  43. package/bin/api/__tests__/fixtures/plugin-old/src/panel/Things.js +4 -0
  44. package/bin/api/__tests__/fixtures/plugin-old/src/theme/Logo.svelte +9 -0
  45. package/bin/api/__tests__/fixtures/plugin-old/src/theme/api.js +29 -0
  46. package/bin/api/__tests__/fixtures/refusals/gradle.properties +1 -0
  47. package/bin/api/__tests__/fixtures/refusals/src/main/kotlin/x/Bad.kt +39 -0
  48. package/bin/api/__tests__/fixtures/unresolved/src/main/kotlin/x/Orphan.kt +19 -0
  49. package/bin/api/__tests__/helpers.mjs +48 -0
  50. package/bin/api/__tests__/migrate-v1.test.mjs +377 -0
  51. package/bin/api/__tests__/openapi-snapshot.test.mjs +120 -0
  52. package/bin/api/api-compat.mjs +204 -0
  53. package/bin/api/check-paths.mjs +135 -0
  54. package/bin/api/cli.mjs +83 -0
  55. package/bin/api/extract-routes.mjs +129 -0
  56. package/bin/api/js-scan.mjs +337 -0
  57. package/bin/api/kotlin.mjs +366 -0
  58. package/bin/api/migrate-v1.mjs +330 -0
  59. package/bin/api/openapi-snapshot.mjs +112 -0
  60. package/bin/api/project.mjs +172 -0
  61. package/bin/api/rename-table.mjs +66 -0
  62. package/bin/api/util.mjs +194 -0
  63. package/bin/pano-api.js +5 -0
  64. package/build/plugin-api-rollup.js +46 -0
  65. package/core/css/pano-tokens.css +225 -0
  66. package/core/favicon/apple-touch-icon.png +0 -0
  67. package/core/favicon/favicon-96x96.png +0 -0
  68. package/core/favicon/favicon.ico +0 -0
  69. package/core/favicon/favicon.svg +1 -0
  70. package/core/favicon/site.webmanifest +21 -0
  71. package/core/favicon/web-app-manifest-192x192.png +0 -0
  72. package/core/favicon/web-app-manifest-512x512.png +0 -0
  73. package/core/favicon_old/android-icon-144x144.png +0 -0
  74. package/core/favicon_old/android-icon-192x192.png +0 -0
  75. package/core/favicon_old/android-icon-36x36.png +0 -0
  76. package/core/favicon_old/android-icon-48x48.png +0 -0
  77. package/core/favicon_old/android-icon-72x72.png +0 -0
  78. package/core/favicon_old/android-icon-96x96.png +0 -0
  79. package/core/favicon_old/apple-icon-114x114.png +0 -0
  80. package/core/favicon_old/apple-icon-120x120.png +0 -0
  81. package/core/favicon_old/apple-icon-144x144.png +0 -0
  82. package/core/favicon_old/apple-icon-152x152.png +0 -0
  83. package/core/favicon_old/apple-icon-180x180.png +0 -0
  84. package/core/favicon_old/apple-icon-57x57.png +0 -0
  85. package/core/favicon_old/apple-icon-60x60.png +0 -0
  86. package/core/favicon_old/apple-icon-72x72.png +0 -0
  87. package/core/favicon_old/apple-icon-76x76.png +0 -0
  88. package/core/favicon_old/apple-icon-precomposed.png +0 -0
  89. package/core/favicon_old/apple-icon.png +0 -0
  90. package/core/favicon_old/browserconfig.xml +11 -0
  91. package/core/favicon_old/favicon-16x16.png +0 -0
  92. package/core/favicon_old/favicon-32x32.png +0 -0
  93. package/core/favicon_old/favicon-96x96.png +0 -0
  94. package/core/favicon_old/favicon.ico +0 -0
  95. package/core/favicon_old/manifest.json +41 -0
  96. package/core/favicon_old/ms-icon-144x144.png +0 -0
  97. package/core/favicon_old/ms-icon-150x150.png +0 -0
  98. package/core/favicon_old/ms-icon-310x310.png +0 -0
  99. package/core/favicon_old/ms-icon-70x70.png +0 -0
  100. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.eot +0 -0
  101. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.svg +483 -0
  102. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.ttf +0 -0
  103. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff +0 -0
  104. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff2 +0 -0
  105. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.eot +0 -0
  106. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.svg +486 -0
  107. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.ttf +0 -0
  108. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff +0 -0
  109. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff2 +0 -0
  110. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.eot +0 -0
  111. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.svg +484 -0
  112. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.ttf +0 -0
  113. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff +0 -0
  114. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff2 +0 -0
  115. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.eot +0 -0
  116. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.svg +486 -0
  117. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.ttf +0 -0
  118. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff +0 -0
  119. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff2 +0 -0
  120. package/core/js/ControllerRegistry.js +421 -0
  121. package/core/js/NotificationManager.js +62 -0
  122. package/core/js/PluginAPI.js +39 -0
  123. package/core/js/PluginManager.js +851 -0
  124. package/core/js/RouteMatcher.js +142 -0
  125. package/core/js/__tests__/ControllerRegistry.test.js +378 -0
  126. package/core/js/__tests__/NotificationManager.test.js +57 -0
  127. package/core/js/__tests__/PluginAPI.test.js +25 -0
  128. package/core/js/__tests__/RouteMatcher.test.js +33 -0
  129. package/core/js/__tests__/accessClient.test.js +582 -0
  130. package/core/js/__tests__/api.util.v1.test.js +336 -0
  131. package/core/js/__tests__/appStores.test.js +47 -0
  132. package/core/js/__tests__/devBounce.test.js +28 -0
  133. package/core/js/__tests__/html.util.test.js +18 -0
  134. package/core/js/__tests__/pluginFolder.util.test.js +106 -0
  135. package/core/js/__tests__/pluginPackage.test.js +134 -0
  136. package/core/js/__tests__/pluginUiZip.test.js +47 -0
  137. package/core/js/__tests__/sdkLevel.test.js +34 -0
  138. package/core/js/api.util.js +433 -0
  139. package/core/js/appStores.js +93 -0
  140. package/core/js/basePath.js +10 -0
  141. package/core/js/html.util.js +26 -0
  142. package/core/js/pluginFolder.util.js +95 -0
  143. package/core/js/tooltip.util.js +59 -0
  144. package/core/js/variables.js +95 -0
  145. package/core/js/version.util.js +100 -0
  146. package/core/scss/_pano-tokens.scss +51 -0
  147. package/core/scss/custom-bootstrap.scss +210 -0
  148. package/core/scss/fonts.scss +85 -0
  149. package/core/scss/main.scss +389 -0
  150. package/core/scss/themes.scss +122 -0
  151. package/package.json +63 -11
  152. package/src/__tests__/controllers.test.js +220 -0
  153. package/src/__tests__/views.spike.test.js +472 -0
  154. package/src/components/{index.js → panel.js} +9 -7
  155. package/src/components/theme.js +18 -0
  156. package/src/controllers.js +127 -0
  157. package/src/index.js +1 -1
  158. package/src/runtime-specifiers.js +88 -0
  159. package/src/svelte.js +3 -2
  160. package/src/types.js +5 -3
  161. package/src/utils/api.js +42 -1
  162. package/src/utils/auth.js +8 -0
  163. package/src/utils/component.js +4 -2
  164. package/src/utils/route.js +16 -0
  165. package/src/utils/text.js +8 -0
  166. package/src/views.js +29 -0
@@ -3,18 +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
- export const PageLoading = components.PageLoading;
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 CardMenu = components.CardMenu;
17
- export const CardMenuItem = components.CardMenuItem;
18
- export const Date = components.Date;
19
- export const NoContent = components.NoContent;
20
- export const Editor = components.Editor;
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
@@ -1,4 +1,4 @@
1
- export { getPanoContext } from './internal';
1
+ export { getPanoContext } from "./internal/index.js";
2
2
 
3
3
  export * from './api/plugin.js';
4
4
 
@@ -0,0 +1,88 @@
1
+ /**
2
+ * THE single source of truth for the plugin runtime module surface (owned by @panomc/sdk: the theme engine, the plugin
3
+ * kit and the widget host all depend on the sdk, so none of them has to depend on another to read this table).
4
+ *
5
+ * Every bare specifier a plugin build may import is listed here, mapped to the
6
+ * stable shim file the theme serves under /runtime/. This list drives:
7
+ * - bin/generate-runtime-shims.js (emits static/runtime/<shimFile> per entry)
8
+ * - createThemeHooks() (the <script type="importmap"> in every page)
9
+ * - the runtime registry in kit/hooks-client.js (which must keep literal
10
+ * import() calls for bundler static analysis — its keys are asserted
11
+ * against this list in dev so the two can never drift)
12
+ *
13
+ * FROZEN CONTRACT: shipped plugin client builds resolve these exact names via
14
+ * the import map forever. Never rename or remove an entry; additions are a
15
+ * core minor version.
16
+ */
17
+ export const RUNTIME_SPECIFIERS = {
18
+ "svelte": "svelte/index.js",
19
+ "svelte/animate": "svelte/animate.js",
20
+ "svelte/easing": "svelte/easing.js",
21
+ "svelte/motion": "svelte/motion.js",
22
+ "svelte/store": "svelte/store.js",
23
+ "svelte/transition": "svelte/transition.js",
24
+ "svelte/internal": "svelte/internal.js",
25
+ "svelte/internal/client": "svelte/internal-client.js",
26
+ "svelte/internal/disclose-version": "svelte/internal-disclose-version.js",
27
+ "svelte/internal/flags/legacy": "svelte/internal-flags-legacy.js",
28
+ "svelte/internal/flags/async": "svelte/internal-flags-async.js",
29
+ "svelte/internal/flags/tracing": "svelte/internal-flags-tracing.js",
30
+ "svelte/legacy": "svelte/legacy.js",
31
+ "svelte/events": "svelte/events.js",
32
+ "svelte/attachments": "svelte/attachments.js",
33
+ "svelte/reactivity": "svelte/reactivity.js",
34
+ "svelte/reactivity/window": "svelte/reactivity-window.js",
35
+ "svelte-i18n": "svelte/i18n.js",
36
+ "@panomc/sdk": "sdk/index.js",
37
+ "@panomc/sdk/components/theme": "sdk/components-theme.js",
38
+ "@panomc/sdk/components/panel": "sdk/components-panel.js",
39
+ "@panomc/sdk/toasts": "sdk/toasts.js",
40
+ "@panomc/sdk/utils/api": "sdk/utils-api.js",
41
+ "@panomc/sdk/utils/auth": "sdk/utils-auth.js",
42
+ "@panomc/sdk/utils/tooltip": "sdk/utils-tooltip.js",
43
+ "@panomc/sdk/utils/language": "sdk/utils-language.js",
44
+ "@panomc/sdk/utils/component": "sdk/utils-component.js",
45
+ "@panomc/sdk/utils/text": "sdk/utils-text.js",
46
+ "@panomc/sdk/variables": "sdk/variables.js",
47
+ "@panomc/sdk/svelte": "sdk/svelte.js",
48
+ "@panomc/sdk/internal": "sdk/internal.js",
49
+ "@panomc/sdk/views": "sdk/views.js",
50
+ "@panomc/sdk/controllers": "sdk/controllers.js",
51
+ "@panomc/sdk/utils/route": "sdk/utils-route.js",
52
+ };
53
+
54
+ /** Entries whose shim re-exports come from the svelte/svelte-i18n packages. */
55
+ export const SVELTE_SPECIFIERS = Object.fromEntries(
56
+ Object.entries(RUNTIME_SPECIFIERS).filter(([, file]) =>
57
+ file.startsWith("svelte/"),
58
+ ),
59
+ );
60
+
61
+ /** Entries whose shim re-exports come from @panomc/sdk. */
62
+ export const SDK_SPECIFIERS = Object.fromEntries(
63
+ Object.entries(RUNTIME_SPECIFIERS).filter(([, file]) =>
64
+ file.startsWith("sdk/"),
65
+ ),
66
+ );
67
+
68
+ /** Specifier -> file of the widget runtime directory (`dist/runtime/` of @panomc/widget-host), for every `svelte*` name and every `@panomc/sdk` facade. */
69
+ export const RUNTIME_FILES = Object.freeze(
70
+ Object.fromEntries(
71
+ Object.entries(RUNTIME_SPECIFIERS).map(([specifier, file]) => {
72
+ if (specifier === "svelte-i18n") return [specifier, "svelte-i18n.js"];
73
+ if (file.startsWith("sdk/")) return [specifier, `host/${file.slice("sdk/".length)}`];
74
+ return [specifier, file];
75
+ }),
76
+ ),
77
+ );
78
+
79
+ /**
80
+ * Relative URL of a runtime file seen from a widget module that sits in `.../_/ui/widgets/` of a plugin
81
+ * (`/api/v1/plugins/<id>/_/ui/widgets/` -> five levels up is `/api/v1/`, doc 06 section 3.3).
82
+ * @param {string} specifier
83
+ */
84
+ export function widgetImportPath(specifier) {
85
+ const file = RUNTIME_FILES[specifier];
86
+ if (!file) throw new Error(`no runtime file for ${specifier}`);
87
+ return `../../../../../widgets/runtime/${file}`;
88
+ }
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 } = panoContext.context;
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 {Object} utils.api.networkErrorBody
20
- * @property {string} utils.api.networkErrorBody.result
21
- * @property {string} utils.api.networkErrorBody.error
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
- export { ApiUtil, NETWORK_ERROR, networkErrorBody, buildQueryParams };
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;
@@ -0,0 +1,8 @@
1
+ import { getPanoContext } from '../internal/index.js';
2
+
3
+ const panoContext = getPanoContext();
4
+ const authStuff = panoContext.context.utils.auth;
5
+
6
+ const hasPermission = authStuff.hasPermission;
7
+
8
+ export { hasPermission };
@@ -1,4 +1,4 @@
1
- import { mount, unmount, hydrate } from 'svelte';
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
- return async () => {
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
+ }
@@ -0,0 +1,8 @@
1
+ import { getPanoContext } from '../internal/index.js';
2
+
3
+ const panoContext = getPanoContext();
4
+ const textStuff = panoContext.context.utils.text;
5
+
6
+ const copy = textStuff.copy;
7
+
8
+ export { copy };
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
+ };