@jlab-enhanced/favorites 3.2.0 → 3.2.2

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/README.md CHANGED
@@ -2,18 +2,24 @@
2
2
 
3
3
  [![Extension status](https://img.shields.io/badge/status-ready-success 'ready to be used')](https://jupyterlab-contrib.github.io/)
4
4
  [![Github Actions Status](https://github.com/jupyterlab-contrib/jupyterlab-favorites/workflows/Build/badge.svg)](https://github.com/jupyterlab-contrib/jupyterlab-favorites/actions?query=workflow%3ABuild)
5
- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab-contrib/jupyterlab-favorites/master?urlpath=lab)
5
+ [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab-contrib/jupyterlab-favorites/main?urlpath=lab)
6
6
  [![npm](https://img.shields.io/npm/v/@jlab-enhanced/favorites)](https://www.npmjs.com/package/@jlab-enhanced/favorites)
7
7
  [![PyPI](https://img.shields.io/pypi/v/jupyterlab-favorites)](https://pypi.org/project/jupyterlab-favorites)
8
8
  [![conda-forge](https://img.shields.io/conda/vn/conda-forge/jupyterlab-favorites)](https://anaconda.org/conda-forge/jupyterlab-favorites)
9
9
 
10
10
  Add the ability to save favorite folders to JupyterLab for quicker browsing.
11
11
 
12
- ![JupyterLab Favorites extension demonstration](https://raw.githubusercontent.com/jupyterlab-contrib/jupyterlab-favorites/master/jupyterlab-favorites.gif)
12
+ ![JupyterLab Favorites extension demonstration](https://raw.githubusercontent.com/jupyterlab-contrib/jupyterlab-favorites/main/jupyterlab-favorites.gif)
13
13
 
14
14
  ## Requirements
15
15
 
16
- - JupyterLab >= 3.0.0 or Notebook >= 7.0.0
16
+ - JupyterLab >= 4.0.0 or Notebook >= 7.0.0
17
+
18
+ > For JupyterLab 3, you can install jupyterlab-favorites 3.1.x using pip for example:
19
+
20
+ ```sh
21
+ pip install "jupyterlab-favorites~=3.1.1"
22
+ ```
17
23
 
18
24
  ## Install
19
25
 
package/lib/components.js CHANGED
@@ -79,7 +79,7 @@ export const FavoritesBreadCrumbs = (props) => {
79
79
  var _a;
80
80
  const isFavorite = (_a = manager === null || manager === void 0 ? void 0 : manager.hasFavorite(currentPath)) !== null && _a !== void 0 ? _a : false;
81
81
  const icon = getFavoritesIcon(isFavorite);
82
- return (React.createElement("button", { className: "jp-ToolbarButtonComponent", title: getPinnerActionDescription(isFavorite), onClick: e => {
82
+ return (React.createElement("button", { className: "jp-ToolbarButtonComponent jp-Button jp-mod-minimal", title: getPinnerActionDescription(isFavorite), onClick: e => {
83
83
  props.handleClick(currentPath);
84
84
  } },
85
85
  React.createElement(icon.react, { className: FAVORITE_BREADCRUMB_ICON_CLASS, tag: "span" })));
package/lib/index.js CHANGED
@@ -3,8 +3,6 @@ import { IDefaultFileBrowser, IFileBrowserFactory } from '@jupyterlab/filebrowse
3
3
  import { IMainMenu } from '@jupyterlab/mainmenu';
4
4
  import { ISettingRegistry } from '@jupyterlab/settingregistry';
5
5
  import { ReactWidget, UseSignal, folderIcon } from '@jupyterlab/ui-components';
6
- import { toArray } from '@lumino/algorithm';
7
- import { Throttler } from '@lumino/polling';
8
6
  import { Widget } from '@lumino/widgets';
9
7
  import React from 'react';
10
8
  import { FavoritesBreadCrumbs, FavoritesWidget } from './components';
@@ -16,10 +14,13 @@ import { InputDialog } from '@jupyterlab/apputils';
16
14
  export { IFavorites } from './token';
17
15
  const BREADCRUMBS_CLASS = 'jp-FileBrowser-crumbs';
18
16
  /**
19
- * The class name for the node containing the FileBrowser BreadCrumbs favorite icon. This node
20
- * is also responsible for click actions on the icon.
17
+ * The class name for the node containing the FileBrowser BreadCrumbs favorite icon.
21
18
  */
22
19
  const FAVORITE_ITEM_PINNER_CLASS = 'jp-Favorites-pinner';
20
+ /**
21
+ * Modifier class added to breadcrumbs to ensure the favourite icon has enough spacing.
22
+ */
23
+ const BREADCUMBS_FAVORITES_CLASS = 'jp-Favorites-crumbs';
23
24
  /**
24
25
  * Initialization data for the jupyterlab-favorites extension.
25
26
  */
@@ -63,17 +64,8 @@ const favorites = {
63
64
  } }))));
64
65
  favoriteIcon.addClass(FAVORITE_ITEM_PINNER_CLASS);
65
66
  Widget.attach(favoriteIcon, breadcrumbs);
66
- const throttler = new Throttler(() => {
67
- breadcrumbs.insertAdjacentElement('beforeend', favoriteIcon.node);
68
- });
69
- const observer = new MutationObserver(() => {
70
- throttler.invoke();
71
- });
72
- observer.observe(breadcrumbs, { childList: true });
73
- filebrowser.disposed.connect(() => {
74
- throttler.dispose();
75
- observer.disconnect();
76
- });
67
+ breadcrumbs.insertAdjacentElement('beforebegin', favoriteIcon.node);
68
+ breadcrumbs.classList.add(BREADCUMBS_FAVORITES_CLASS);
77
69
  };
78
70
  filebrowser.model.pathChanged.connect(initializeBreadcrumbsIcon);
79
71
  initializeBreadcrumbsIcon();
@@ -85,7 +77,7 @@ const favorites = {
85
77
  if (!widget) {
86
78
  return [];
87
79
  }
88
- return toArray(widget.selectedItems());
80
+ return Array.from(widget.selectedItems());
89
81
  };
90
82
  const { tracker } = factory;
91
83
  commands.addCommand(CommandIDs.addOrRemoveFavorite, {
package/lib/manager.d.ts CHANGED
@@ -29,7 +29,7 @@ export declare class FavoritesManager {
29
29
  removeFavoriteIfInvalid(favorite: IFavorites.Favorite): Promise<void>;
30
30
  restoreDefaults(): void;
31
31
  saveSettings(settings: IFavorites.FavoritesSettings): Promise<void>;
32
- visibleFavorites(): IFavorites.Favorite[];
32
+ visibleFavorites(sort?: boolean): IFavorites.Favorite[];
33
33
  private clearFavoritesOrRestoreDefaults;
34
34
  private loadFavorites;
35
35
  private loadShowWidget;
package/lib/manager.js CHANGED
@@ -62,10 +62,10 @@ export class FavoritesManager {
62
62
  this.loadFavorites();
63
63
  }
64
64
  isVisible() {
65
- return this._showWidget && this.visibleFavorites().length > 0;
65
+ return this._showWidget && this.visibleFavorites(false).length > 0;
66
66
  }
67
67
  hasFavorite(path) {
68
- return this.visibleFavorites().findIndex(f => f.path === path) >= 0;
68
+ return this.visibleFavorites(false).findIndex(f => f.path === path) >= 0;
69
69
  }
70
70
  handleClick(favorite) {
71
71
  this._commandRegistry.execute(CommandIDs.openFavorite, { favorite });
@@ -122,10 +122,12 @@ export class FavoritesManager {
122
122
  this._settingsRegistry.set(SettingIDs.favorites, 'showWidget', settings.showWidget);
123
123
  }
124
124
  }
125
- visibleFavorites() {
126
- return this.favorites
127
- .filter(f => !f.hidden)
128
- .sort((a, b) => {
125
+ visibleFavorites(sort = true) {
126
+ const filtered = this.favorites.filter(f => !f.hidden);
127
+ if (!sort) {
128
+ return filtered;
129
+ }
130
+ return filtered.sort((a, b) => {
129
131
  if (a.contentType === b.contentType) {
130
132
  return getName(a.path) <= getName(b.path) ? -1 : 1;
131
133
  }
@@ -147,8 +149,12 @@ export class FavoritesManager {
147
149
  }
148
150
  async loadFavorites() {
149
151
  var _a;
150
- const favorites = await this._settingsRegistry.get(SettingIDs.favorites, 'favorites');
151
- this.favorites = ((_a = favorites.composite) !== null && _a !== void 0 ? _a : []);
152
+ const setting = await this._settingsRegistry.get(SettingIDs.favorites, 'favorites');
153
+ const favorites = ((_a = setting.composite) !== null && _a !== void 0 ? _a : []);
154
+ this.favorites = favorites.map(favorite => {
155
+ var _a;
156
+ return { ...favorite, root: (_a = favorite.root) !== null && _a !== void 0 ? _a : this.serverRoot };
157
+ });
152
158
  }
153
159
  async loadShowWidget() {
154
160
  var _a;
package/lib/utils.d.ts CHANGED
@@ -8,3 +8,4 @@ export declare function getFavoritesIcon(filled: boolean): LabIcon;
8
8
  export declare function getName(path: string): [string, string];
9
9
  export declare function getPinnerActionDescription(showRemove: boolean): string;
10
10
  export declare function mergePaths(root: string, path: string): string;
11
+ export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jlab-enhanced/favorites",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "Add the ability to save favorite folders to JupyterLab for quicker browsing",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -77,10 +77,8 @@
77
77
  "@jupyterlab/services": "^7.0.5",
78
78
  "@jupyterlab/settingregistry": "^4.0.5",
79
79
  "@jupyterlab/ui-components": "^4.0.5",
80
- "@lumino/algorithm": "^2.0.0",
81
80
  "@lumino/commands": "^2.0.1",
82
81
  "@lumino/coreutils": "^2.0.1",
83
- "@lumino/polling": "^2.0.0",
84
82
  "@lumino/signaling": "^2.0.0",
85
83
  "@lumino/widgets": "^2.0.1"
86
84
  },
@@ -22,10 +22,11 @@
22
22
  "type": "string"
23
23
  },
24
24
  "root": {
25
- "type": "string"
25
+ "type": "string",
26
+ "description": "Root path used for filtering out favourites from instances of JupyterLab launched in a different root directory. If not given the favourite will be shown if the associated file exists."
26
27
  }
27
28
  },
28
- "required": ["root", "path"],
29
+ "required": ["path"],
29
30
  "type": "object"
30
31
  }
31
32
  },
package/style/base.css CHANGED
@@ -1,15 +1,24 @@
1
1
  .jp-Favorites-pinner {
2
- float: right;
3
- cursor: pointer;
2
+ position: absolute;
3
+ right: 0;
4
+ overflow: visible;
5
+
6
+ /* aimed to match the upstream breadcrumbs */
7
+ margin: 8px 12px;
4
8
  }
5
9
 
6
- .jp-Favorites-BreadCrumbs-Icon svg {
7
- border-radius: var(--jp-border-radius);
8
- cursor: pointer;
10
+ .jp-Favorites-pinner > .jp-ToolbarButtonComponent {
11
+ height: 24px;
12
+ margin-top: -5px;
13
+ }
14
+
15
+ .jp-Favorites-crumbs {
16
+ margin-right: 40px;
17
+ }
18
+
19
+ .jp-Favorites-BreadCrumbs-Icon,
20
+ .jp-Favorites-BreadCrumbs-Icon > svg {
9
21
  height: 16px;
10
- margin: 0 2px;
11
- padding: 0 2px;
12
- vertical-align: middle;
13
22
  width: 16px;
14
23
  }
15
24
 
@@ -45,7 +54,7 @@
45
54
  background-color: var(--jp-layout-color2);
46
55
  }
47
56
 
48
- .jp-Favorites-itemIcon svg {
57
+ .jp-Favorites-itemIcon > svg {
49
58
  display: block;
50
59
  height: 16px;
51
60
  margin: 0 5px;