@lobb-js/studio 0.24.1 → 0.25.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.
@@ -11,6 +11,7 @@
11
11
  import { Router, Route, Fallback, init as initRouter } from "@wjfe/n-savant";
12
12
  import {
13
13
  executeExtensionsOnStartup,
14
+ executeExtensionsOnRouteChange,
14
15
  loadExtensions,
15
16
  loadExtensionWorkflows,
16
17
  } from "../extensions/extensionUtils";
@@ -55,6 +56,15 @@
55
56
  console.error(err);
56
57
  status = "error";
57
58
  }
59
+
60
+ // Fire onRouteChange hooks on every navigation
61
+ const onRouteChange = () => executeExtensionsOnRouteChange(lobb, ctx as any, window.location.pathname);
62
+ const originalPushState = history.pushState.bind(history);
63
+ history.pushState = function (...args) {
64
+ originalPushState(...args);
65
+ onRouteChange();
66
+ };
67
+ window.addEventListener("popstate", onRouteChange);
58
68
  });
59
69
 
60
70
  onDestroy(() => {
@@ -99,6 +99,7 @@ export interface StudioWorkflow {
99
99
  export interface Extension {
100
100
  name: string;
101
101
  onStartup?: (utils: ExtensionUtils) => Promise<void>;
102
+ onRouteChange?: (utils: ExtensionUtils, path: string) => void;
102
103
  components?: Partial<Record<ExtensionComponentKey, ExtensionComponent>>;
103
104
  dashboardNavs?: DashboardNavs;
104
105
  workflows?: StudioWorkflow[];
@@ -7,4 +7,5 @@ export declare function loadExtensions(lobb: LobbClient, ctx: CTX, extensionMap?
7
7
  export declare function loadExtensionComponents(ctx: CTX, name: string, filterByExtensions?: string[], props?: Record<string, any>): any[];
8
8
  export declare function loadExtensionWorkflows(ctx: CTX): void;
9
9
  export declare function executeExtensionsOnStartup(lobb: LobbClient, ctx: CTX): Promise<void>;
10
+ export declare function executeExtensionsOnRouteChange(lobb: LobbClient, ctx: CTX, path: string): void;
10
11
  export declare function getDashboardNavs(ctx: CTX): DashboardNavs;
@@ -186,6 +186,16 @@ export function executeExtensionsOnStartup(lobb, ctx) {
186
186
  });
187
187
  });
188
188
  }
189
+ export function executeExtensionsOnRouteChange(lobb, ctx, path) {
190
+ var extensionNames = Object.keys(ctx.extensions);
191
+ for (var index = 0; index < extensionNames.length; index++) {
192
+ var extensionName = extensionNames[index];
193
+ var extension = ctx.extensions[extensionName];
194
+ if (extension === null || extension === void 0 ? void 0 : extension.onRouteChange) {
195
+ extension.onRouteChange(getExtensionUtils(lobb, ctx), path);
196
+ }
197
+ }
198
+ }
189
199
  export function getDashboardNavs(ctx) {
190
200
  var navs = {
191
201
  top: [],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lobb-js/studio",
3
3
  "license": "UNLICENSED",
4
- "version": "0.24.1",
4
+ "version": "0.25.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -42,7 +42,7 @@
42
42
  "postpublish": "./scripts/postpublish.sh"
43
43
  },
44
44
  "devDependencies": {
45
- "@lobb-js/core": "^0.26.2",
45
+ "@lobb-js/core": "^0.28.0",
46
46
  "@chromatic-com/storybook": "^4.1.2",
47
47
  "@storybook/addon-a11y": "^10.0.1",
48
48
  "@storybook/addon-docs": "^10.0.1",
@@ -11,6 +11,7 @@
11
11
  import { Router, Route, Fallback, init as initRouter } from "@wjfe/n-savant";
12
12
  import {
13
13
  executeExtensionsOnStartup,
14
+ executeExtensionsOnRouteChange,
14
15
  loadExtensions,
15
16
  loadExtensionWorkflows,
16
17
  } from "../extensions/extensionUtils";
@@ -55,6 +56,15 @@
55
56
  console.error(err);
56
57
  status = "error";
57
58
  }
59
+
60
+ // Fire onRouteChange hooks on every navigation
61
+ const onRouteChange = () => executeExtensionsOnRouteChange(lobb, ctx as any, window.location.pathname);
62
+ const originalPushState = history.pushState.bind(history);
63
+ history.pushState = function (...args) {
64
+ originalPushState(...args);
65
+ onRouteChange();
66
+ };
67
+ window.addEventListener("popstate", onRouteChange);
58
68
  });
59
69
 
60
70
  onDestroy(() => {
@@ -119,6 +119,7 @@ export interface StudioWorkflow {
119
119
  export interface Extension {
120
120
  name: string;
121
121
  onStartup?: (utils: ExtensionUtils) => Promise<void>;
122
+ onRouteChange?: (utils: ExtensionUtils, path: string) => void;
122
123
  components?: Partial<Record<ExtensionComponentKey, ExtensionComponent>>;
123
124
  dashboardNavs?: DashboardNavs;
124
125
  workflows?: StudioWorkflow[];
@@ -142,6 +142,17 @@ export async function executeExtensionsOnStartup(lobb: LobbClient, ctx: CTX) {
142
142
  }
143
143
  }
144
144
 
145
+ export function executeExtensionsOnRouteChange(lobb: LobbClient, ctx: CTX, path: string) {
146
+ const extensionNames: string[] = Object.keys(ctx.extensions);
147
+ for (let index = 0; index < extensionNames.length; index++) {
148
+ const extensionName = extensionNames[index];
149
+ const extension = ctx.extensions[extensionName];
150
+ if (extension?.onRouteChange) {
151
+ extension.onRouteChange(getExtensionUtils(lobb, ctx), path);
152
+ }
153
+ }
154
+ }
155
+
145
156
  export function getDashboardNavs(ctx: CTX): DashboardNavs {
146
157
  let navs: DashboardNavs = {
147
158
  top: [],