@jupyterlite/application 0.7.0-alpha.2 → 0.7.0-alpha.4

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/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from './router';
1
2
  export * from './singleWidgetApp';
2
3
  export * from './singleWidgetShell';
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
+ export * from './router';
3
4
  export * from './singleWidgetApp';
4
5
  export * from './singleWidgetShell';
5
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { IRouter, Router } from '@jupyterlab/application';
2
+ import { Token } from '@lumino/coreutils';
3
+ /**
4
+ * An interface for URL transformers
5
+ */
6
+ export interface IURLTransformer {
7
+ id: string;
8
+ transform: (args: {
9
+ url: URL;
10
+ options: {
11
+ skipRouting?: boolean;
12
+ hard?: boolean;
13
+ };
14
+ }) => {
15
+ url: URL;
16
+ options: {
17
+ skipRouting?: boolean;
18
+ hard?: boolean;
19
+ };
20
+ };
21
+ }
22
+ /**
23
+ * An interface for the custom URL router provider.
24
+ *
25
+ * Provides IRouter, plus the additional methods to transform `/path/`-based routes
26
+ */
27
+ export interface ILiteRouter extends IRouter {
28
+ /**
29
+ * Add a URL transformer
30
+ */
31
+ addTransformer: (transformer: IURLTransformer) => void;
32
+ }
33
+ /**
34
+ * A token for the ILiteRouter interface
35
+ */
36
+ export declare const ILiteRouter: Token<ILiteRouter>;
37
+ /**
38
+ * A custom router that extends the standard Router with URL transformation capabilities
39
+ */
40
+ export declare class LiteRouter extends Router implements ILiteRouter {
41
+ constructor(options: Router.IOptions);
42
+ /**
43
+ * Add a URL transformer
44
+ */
45
+ addTransformer(transformer: IURLTransformer): void;
46
+ /**
47
+ * Navigate to a new path within the application.
48
+ */
49
+ navigate(url: string, options?: {
50
+ skipRouting?: boolean;
51
+ hard?: boolean;
52
+ }): void;
53
+ private _transformers;
54
+ }
package/lib/router.js ADDED
@@ -0,0 +1,44 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { Router } from '@jupyterlab/application';
4
+ import { Token } from '@lumino/coreutils';
5
+ /**
6
+ * A token for the ILiteRouter interface
7
+ */
8
+ export const ILiteRouter = new Token('@jupyterlite/application:ILiteRouter');
9
+ /**
10
+ * A custom router that extends the standard Router with URL transformation capabilities
11
+ */
12
+ export class LiteRouter extends Router {
13
+ constructor(options) {
14
+ super(options);
15
+ this._transformers = [];
16
+ this._transformers = [];
17
+ }
18
+ /**
19
+ * Add a URL transformer
20
+ */
21
+ addTransformer(transformer) {
22
+ this._transformers.push(transformer);
23
+ }
24
+ /**
25
+ * Navigate to a new path within the application.
26
+ */
27
+ navigate(url, options = {}) {
28
+ const urlObj = new URL(url, window.location.href);
29
+ // Apply all transformers
30
+ let transformedUrl = urlObj;
31
+ let transformedOptions = options;
32
+ for (const transformer of this._transformers) {
33
+ const result = transformer.transform({
34
+ url: transformedUrl,
35
+ options: transformedOptions,
36
+ });
37
+ transformedUrl = result.url;
38
+ transformedOptions = result.options;
39
+ }
40
+ // Call the parent navigate method with transformed values
41
+ super.navigate(transformedUrl.pathname + transformedUrl.search + transformedUrl.hash, transformedOptions);
42
+ }
43
+ }
44
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @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E,kBAAkB,CACnB,CAAC;IACJ,CAAC;CAGF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/application",
3
- "version": "0.7.0-alpha.2",
3
+ "version": "0.7.0-alpha.4",
4
4
  "description": "JupyterLite - Application",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -38,11 +38,11 @@
38
38
  "watch": "tsc -b --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@jupyterlab/application": "~4.5.0-alpha.2",
42
- "@jupyterlab/coreutils": "~6.5.0-alpha.2",
43
- "@jupyterlab/docregistry": "~4.5.0-alpha.2",
44
- "@jupyterlab/rendermime-interfaces": "~3.13.0-alpha.2",
45
- "@jupyterlite/server": "^0.7.0-alpha.2",
41
+ "@jupyterlab/application": "~4.5.0-alpha.3",
42
+ "@jupyterlab/coreutils": "~6.5.0-alpha.3",
43
+ "@jupyterlab/docregistry": "~4.5.0-alpha.3",
44
+ "@jupyterlab/rendermime-interfaces": "~3.13.0-alpha.3",
45
+ "@jupyterlite/server": "^0.7.0-alpha.4",
46
46
  "@lumino/coreutils": "^2.2.1",
47
47
  "@lumino/signaling": "^2.1.4",
48
48
  "@lumino/widgets": "^2.7.1"
@@ -50,7 +50,7 @@
50
50
  "devDependencies": {
51
51
  "@babel/core": "^7.11.6",
52
52
  "@babel/preset-env": "^7.12.1",
53
- "@jupyterlab/testutils": "~4.5.0-alpha.2",
53
+ "@jupyterlab/testutils": "~4.5.0-alpha.3",
54
54
  "@types/jest": "^29.5.3",
55
55
  "jest": "^29.6.2",
56
56
  "rimraf": "~5.0.1",
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
+ export * from './router';
4
5
  export * from './singleWidgetApp';
5
6
  export * from './singleWidgetShell';
package/src/router.ts ADDED
@@ -0,0 +1,83 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { IRouter, Router } from '@jupyterlab/application';
5
+ import { Token } from '@lumino/coreutils';
6
+
7
+ /**
8
+ * An interface for URL transformers
9
+ */
10
+ export interface IURLTransformer {
11
+ id: string;
12
+ transform: (args: {
13
+ url: URL;
14
+ options: { skipRouting?: boolean; hard?: boolean };
15
+ }) => {
16
+ url: URL;
17
+ options: { skipRouting?: boolean; hard?: boolean };
18
+ };
19
+ }
20
+
21
+ /**
22
+ * An interface for the custom URL router provider.
23
+ *
24
+ * Provides IRouter, plus the additional methods to transform `/path/`-based routes
25
+ */
26
+ export interface ILiteRouter extends IRouter {
27
+ /**
28
+ * Add a URL transformer
29
+ */
30
+ addTransformer: (transformer: IURLTransformer) => void;
31
+ }
32
+
33
+ /**
34
+ * A token for the ILiteRouter interface
35
+ */
36
+ export const ILiteRouter = new Token<ILiteRouter>(
37
+ '@jupyterlite/application:ILiteRouter',
38
+ );
39
+
40
+ /**
41
+ * A custom router that extends the standard Router with URL transformation capabilities
42
+ */
43
+ export class LiteRouter extends Router implements ILiteRouter {
44
+ constructor(options: Router.IOptions) {
45
+ super(options);
46
+ this._transformers = [];
47
+ }
48
+
49
+ /**
50
+ * Add a URL transformer
51
+ */
52
+ addTransformer(transformer: IURLTransformer): void {
53
+ this._transformers.push(transformer);
54
+ }
55
+
56
+ /**
57
+ * Navigate to a new path within the application.
58
+ */
59
+ navigate(url: string, options: { skipRouting?: boolean; hard?: boolean } = {}): void {
60
+ const urlObj = new URL(url, window.location.href);
61
+
62
+ // Apply all transformers
63
+ let transformedUrl = urlObj;
64
+ let transformedOptions = options;
65
+
66
+ for (const transformer of this._transformers) {
67
+ const result = transformer.transform({
68
+ url: transformedUrl,
69
+ options: transformedOptions,
70
+ });
71
+ transformedUrl = result.url;
72
+ transformedOptions = result.options;
73
+ }
74
+
75
+ // Call the parent navigate method with transformed values
76
+ super.navigate(
77
+ transformedUrl.pathname + transformedUrl.search + transformedUrl.hash,
78
+ transformedOptions,
79
+ );
80
+ }
81
+
82
+ private _transformers: IURLTransformer[] = [];
83
+ }