@jlab-enhanced/favorites 3.2.2 → 3.3.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.
package/README.md CHANGED
@@ -37,6 +37,12 @@ To remove the extension, execute:
37
37
  pip uninstall jupyterlab_favorites
38
38
  ```
39
39
 
40
+ ## History
41
+
42
+ This extension was orginally developed by [National Energy Research Scientific Computing Center](https://github.com/NERSC/).
43
+
44
+ The original (archived) repository can be found here: [NERSC/jupyterlab-favorites](https://github.com/NERSC/jupyterlab-favorites).
45
+
40
46
  ## Contributing
41
47
 
42
48
  ### Development install
package/lib/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { JupyterFrontEndPlugin } from '@jupyterlab/application';
2
+ import { NotebookPanel } from '@jupyterlab/notebook';
2
3
  import { IFavorites } from './token';
3
- export { IFavorites } from './token';
4
+ export { IFavorites, FAVORITE_TAG } from './token';
4
5
  /**
5
- * Initialization data for the jupyterlab-favorites extension.
6
+ * Plugin that provides the custom notebook factory with star icons
6
7
  */
7
- declare const favorites: JupyterFrontEndPlugin<IFavorites>;
8
- export default favorites;
8
+ export declare const notebookFactoryPlugin: JupyterFrontEndPlugin<NotebookPanel.IContentFactory>;
9
+ declare const _default: (JupyterFrontEndPlugin<IFavorites> | JupyterFrontEndPlugin<NotebookPanel.IContentFactory>)[];
10
+ export default _default;
package/lib/index.js CHANGED
@@ -1,41 +1,61 @@
1
1
  import { PageConfig } from '@jupyterlab/coreutils';
2
2
  import { IDefaultFileBrowser, IFileBrowserFactory } from '@jupyterlab/filebrowser';
3
+ import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
3
4
  import { IMainMenu } from '@jupyterlab/mainmenu';
4
5
  import { ISettingRegistry } from '@jupyterlab/settingregistry';
5
- import { ReactWidget, UseSignal, folderIcon } from '@jupyterlab/ui-components';
6
+ import { ReactWidget, ToolbarButton, UseSignal, folderIcon } from '@jupyterlab/ui-components';
6
7
  import { Widget } from '@lumino/widgets';
7
8
  import React from 'react';
8
9
  import { FavoritesBreadCrumbs, FavoritesWidget } from './components';
9
10
  import { starIcon } from './icons';
10
11
  import { FavoritesManager } from './manager';
11
- import { IFavorites, PluginIDs, CommandIDs } from './token';
12
- import { getFavoritesIcon, getPinnerActionDescription, mergePaths } from './utils';
13
- import { InputDialog } from '@jupyterlab/apputils';
14
- export { IFavorites } from './token';
12
+ import { IFavorites, PluginIDs, CommandIDs, SettingIDs, FAVORITE_TAG } from './token';
13
+ import { changeShowStarsOnCells, getFavoritesIcon, getPinnerActionDescription, mergePaths, toggleCellFavorite, updateCellClasses, updateCellFavoriteButton, updateSingleCellClass } from './utils';
14
+ import { ICommandPalette, InputDialog, IToolbarWidgetRegistry } from '@jupyterlab/apputils';
15
+ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
16
+ import { IEditorServices } from '@jupyterlab/codeeditor';
17
+ import { StarredNotebookContentFactory } from './starPrompt';
18
+ export { IFavorites, FAVORITE_TAG } from './token';
15
19
  const BREADCRUMBS_CLASS = 'jp-FileBrowser-crumbs';
16
20
  /**
17
21
  * The class name for the node containing the FileBrowser BreadCrumbs favorite icon.
18
22
  */
19
23
  const FAVORITE_ITEM_PINNER_CLASS = 'jp-Favorites-pinner';
20
24
  /**
21
- * Modifier class added to breadcrumbs to ensure the favourite icon has enough spacing.
25
+ * Modifier class added to breadcrumbs to ensure the favorite icon has enough spacing.
22
26
  */
23
27
  const BREADCUMBS_FAVORITES_CLASS = 'jp-Favorites-crumbs';
28
+ /**
29
+ * Class set to notebook when filtering cells by favorite is enabled
30
+ */
31
+ const FAVORITE_FILTER_CLASS = 'jp-favorites-filter-active';
32
+ /**
33
+ * Setting key for toggling the visibility of star icons on cells.
34
+ */
35
+ const SHOW_STARS_ON_CELLS = 'showStarsOnCells';
24
36
  /**
25
37
  * Initialization data for the jupyterlab-favorites extension.
26
38
  */
27
39
  const favorites = {
28
40
  id: PluginIDs.favorites,
29
41
  autoStart: true,
30
- requires: [IFileBrowserFactory, ISettingRegistry],
42
+ requires: [IFileBrowserFactory, ISettingRegistry, INotebookTracker],
31
43
  provides: IFavorites,
32
- optional: [IDefaultFileBrowser, IMainMenu],
33
- activate: (app, factory, settingsRegistry, filebrowser, mainMenu) => {
44
+ optional: [
45
+ ITranslator,
46
+ IDefaultFileBrowser,
47
+ IMainMenu,
48
+ IToolbarWidgetRegistry,
49
+ ICommandPalette
50
+ ],
51
+ activate: async (app, factory, settingsRegistry, notebookTracker, translator, filebrowser, mainMenu, toolbarRegistry, palette) => {
34
52
  console.log('JupyterLab extension jupyterlab-favorites is activated!');
53
+ const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
35
54
  const docRegistry = app.docRegistry;
36
55
  const { commands, serviceManager } = app;
37
56
  const favoritesManager = new FavoritesManager(PageConfig.getOption('serverRoot') || 'Jupyter Server Root', commands, settingsRegistry, serviceManager.contents);
38
57
  favoritesManager.init();
58
+ const favoriteSettings = await settingsRegistry.load(SettingIDs.favorites);
39
59
  if (filebrowser) {
40
60
  const favoritesWidget = new FavoritesWidget(favoritesManager, filebrowser);
41
61
  const layout = filebrowser.layout;
@@ -80,6 +100,21 @@ const favorites = {
80
100
  return Array.from(widget.selectedItems());
81
101
  };
82
102
  const { tracker } = factory;
103
+ toolbarRegistry === null || toolbarRegistry === void 0 ? void 0 : toolbarRegistry.addFactory('Cell', 'cellFavoriteToggle', args => {
104
+ const cell = args.model;
105
+ const tags = cell.getMetadata('tags');
106
+ const isFavorite = Array.isArray(tags) && tags.includes(FAVORITE_TAG);
107
+ const button = new ToolbarButton({
108
+ tooltip: isFavorite ? 'Unfavorite cell' : 'Favorite cell',
109
+ icon: getFavoritesIcon(isFavorite),
110
+ onClick: () => toggleCellFavorite(cell)
111
+ });
112
+ // Connect metadataChanged signal to update the icon and tooltip dynamically
113
+ cell.metadataChanged.connect(() => {
114
+ updateCellFavoriteButton(button, args);
115
+ });
116
+ return button;
117
+ });
83
118
  commands.addCommand(CommandIDs.addOrRemoveFavorite, {
84
119
  execute: () => {
85
120
  var _a;
@@ -127,6 +162,79 @@ const favorites = {
127
162
  icon: starIcon,
128
163
  label: 'Remove Favorite'
129
164
  });
165
+ commands.addCommand(CommandIDs.toggleCellFavorite, {
166
+ execute: () => {
167
+ const notebookPanel = notebookTracker.currentWidget;
168
+ if (!notebookPanel || !notebookPanel.content) {
169
+ return;
170
+ }
171
+ const notebook = notebookPanel.content;
172
+ const activeCell = notebook.activeCell;
173
+ if (!activeCell) {
174
+ console.warn('No active cell found to toggle favorite');
175
+ return;
176
+ }
177
+ toggleCellFavorite(activeCell.model);
178
+ }
179
+ });
180
+ const attachViewportListener = (notebook) => {
181
+ if (!notebook || !notebook.content) {
182
+ return;
183
+ }
184
+ changeShowStarsOnCells(favoriteSettings.get(SHOW_STARS_ON_CELLS).composite, notebook);
185
+ notebook.content.cellInViewportChanged.connect((_, cell) => {
186
+ updateSingleCellClass(cell);
187
+ });
188
+ notebook.disposed.connect(() => {
189
+ notebook.content.cellInViewportChanged.disconnect((_, cell) => {
190
+ updateSingleCellClass(cell);
191
+ });
192
+ });
193
+ };
194
+ // Attach to currently open notebooks
195
+ notebookTracker.forEach(notebook => {
196
+ attachViewportListener(notebook);
197
+ });
198
+ // Attach to any newly opened notebooks
199
+ notebookTracker.widgetAdded.connect((_, notebook) => {
200
+ attachViewportListener(notebook);
201
+ });
202
+ notebookTracker.currentChanged.connect((_, notebook) => {
203
+ changeShowStarsOnCells(favoriteSettings.get(SHOW_STARS_ON_CELLS).composite, notebook);
204
+ });
205
+ favoriteSettings.changed.connect(() => {
206
+ changeShowStarsOnCells(favoriteSettings.get(SHOW_STARS_ON_CELLS).composite, notebookTracker.currentWidget);
207
+ });
208
+ commands.addCommand(CommandIDs.toggleCellsVisibility, {
209
+ isToggled: () => {
210
+ const notebookPanel = notebookTracker.currentWidget;
211
+ if (!notebookPanel || !notebookPanel.content) {
212
+ return false;
213
+ }
214
+ return notebookPanel.content.node.classList.contains(FAVORITE_FILTER_CLASS);
215
+ },
216
+ label: 'Show Only Favorite Cells',
217
+ execute: () => {
218
+ const notebookPanel = notebookTracker.currentWidget;
219
+ if (!notebookPanel || !notebookPanel.content) {
220
+ return;
221
+ }
222
+ const notebook = notebookPanel.content;
223
+ const isFavoriteMode = notebook.node.classList.contains(FAVORITE_FILTER_CLASS);
224
+ if (isFavoriteMode) {
225
+ notebook.node.classList.remove(FAVORITE_FILTER_CLASS);
226
+ }
227
+ else {
228
+ notebook.node.classList.add(FAVORITE_FILTER_CLASS);
229
+ }
230
+ updateCellClasses(notebook);
231
+ },
232
+ isEnabled: () => {
233
+ const currentWidget = app.shell.currentWidget;
234
+ const notebook = notebookTracker.currentWidget;
235
+ return !!(notebook !== null && notebook === currentWidget);
236
+ }
237
+ });
130
238
  commands.addCommand(CommandIDs.renameFavorite, {
131
239
  execute: async (args) => {
132
240
  var _a;
@@ -185,6 +293,11 @@ const favorites = {
185
293
  execute: () => favoritesManager.clearFavorites(),
186
294
  label: 'Clear Favorites'
187
295
  });
296
+ // Add commands to palette
297
+ palette === null || palette === void 0 ? void 0 : palette.addItem({
298
+ command: CommandIDs.toggleCellsVisibility,
299
+ category: trans.__('Notebook Operations')
300
+ });
188
301
  // Main Menu
189
302
  if (mainMenu) {
190
303
  mainMenu.fileMenu.addGroup([
@@ -238,4 +351,22 @@ const favorites = {
238
351
  return favoritesManager;
239
352
  }
240
353
  };
241
- export default favorites;
354
+ /**
355
+ * Plugin that provides the custom notebook factory with star icons
356
+ */
357
+ export const notebookFactoryPlugin = {
358
+ id: PluginIDs.notebookFactory,
359
+ description: 'Provides notebook cell factory with star icons',
360
+ provides: NotebookPanel.IContentFactory,
361
+ requires: [IEditorServices],
362
+ autoStart: true,
363
+ activate: (app, editorServices) => {
364
+ const editorFactory = editorServices.factoryService.newInlineEditor;
365
+ const factory = new StarredNotebookContentFactory({
366
+ editorFactory,
367
+ app
368
+ });
369
+ return factory;
370
+ }
371
+ };
372
+ export default [favorites, notebookFactoryPlugin];
@@ -0,0 +1,24 @@
1
+ import { JupyterFrontEnd } from '@jupyterlab/application';
2
+ import { Widget } from '@lumino/widgets';
3
+ import { Cell, IInputPrompt } from '@jupyterlab/cells';
4
+ import { NotebookPanel } from '@jupyterlab/notebook';
5
+ export declare class StarredInputPrompt extends Widget implements IInputPrompt {
6
+ private _app;
7
+ private _executionCount;
8
+ private _promptIndicator;
9
+ private _favoriteIconOn;
10
+ private _favoriteIconOff;
11
+ constructor(_app: JupyterFrontEnd);
12
+ get executionCount(): string | null;
13
+ set executionCount(value: string | null);
14
+ }
15
+ export declare namespace StarredNotebookContentFactory {
16
+ interface IOptions extends Cell.ContentFactory.IOptions {
17
+ app: JupyterFrontEnd;
18
+ }
19
+ }
20
+ export declare class StarredNotebookContentFactory extends NotebookPanel.ContentFactory {
21
+ private _app;
22
+ constructor(options: StarredNotebookContentFactory.IOptions);
23
+ createInputPrompt(): StarredInputPrompt;
24
+ }
@@ -0,0 +1,61 @@
1
+ import { BoxLayout, Widget } from '@lumino/widgets';
2
+ import { CommandIDs } from './token';
3
+ import { InputPrompt } from '@jupyterlab/cells';
4
+ import { ToolbarButton } from '@jupyterlab/ui-components';
5
+ import { filledStarIcon, starIcon } from './icons';
6
+ import { NotebookPanel } from '@jupyterlab/notebook';
7
+ const INPUT_PROMPT_CLASS = 'jp-InputPrompt';
8
+ const INPUT_PROMPT_NUMBER_CLASS = 'jp-Favorites-InputPromptNumber';
9
+ const FAVORITE_ICON_ON_CLASS = 'jp-Favorites-star-class';
10
+ const FAVORITE_ICON_OFF_CLASS = 'jp-Favorites-star-class-off';
11
+ const FAVORITE_ICON_BASE_CLASS = 'jp-Favorites-base-star-class';
12
+ export class StarredInputPrompt extends Widget {
13
+ constructor(_app) {
14
+ super();
15
+ this._app = _app;
16
+ this._executionCount = null;
17
+ this.addClass(INPUT_PROMPT_CLASS);
18
+ const layout = (this.layout = new BoxLayout({
19
+ direction: 'right-to-left'
20
+ }));
21
+ this._promptIndicator = new InputPrompt();
22
+ this._promptIndicator.node.classList.add(INPUT_PROMPT_NUMBER_CLASS);
23
+ layout.addWidget(this._promptIndicator);
24
+ this._favoriteIconOff = new ToolbarButton({
25
+ icon: starIcon,
26
+ onClick: () => {
27
+ this._app.commands.execute(CommandIDs.toggleCellFavorite);
28
+ },
29
+ tooltip: 'Mark as favorite'
30
+ });
31
+ this._favoriteIconOff.addClass(FAVORITE_ICON_OFF_CLASS);
32
+ this._favoriteIconOff.addClass(FAVORITE_ICON_BASE_CLASS);
33
+ this._favoriteIconOn = new ToolbarButton({
34
+ icon: filledStarIcon,
35
+ onClick: () => {
36
+ this._app.commands.execute(CommandIDs.toggleCellFavorite);
37
+ },
38
+ tooltip: 'Remove from favorites'
39
+ });
40
+ this._favoriteIconOn.addClass(FAVORITE_ICON_ON_CLASS);
41
+ this._favoriteIconOn.addClass(FAVORITE_ICON_BASE_CLASS);
42
+ layout.addWidget(this._favoriteIconOff);
43
+ layout.addWidget(this._favoriteIconOn);
44
+ }
45
+ get executionCount() {
46
+ return this._executionCount;
47
+ }
48
+ set executionCount(value) {
49
+ this._executionCount = value;
50
+ this._promptIndicator.executionCount = value;
51
+ }
52
+ }
53
+ export class StarredNotebookContentFactory extends NotebookPanel.ContentFactory {
54
+ constructor(options) {
55
+ super(options);
56
+ this._app = options.app;
57
+ }
58
+ createInputPrompt() {
59
+ return new StarredInputPrompt(this._app);
60
+ }
61
+ }
package/lib/token.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { Token } from '@lumino/coreutils';
2
2
  export declare namespace PluginIDs {
3
3
  const favorites = "jupyterlab-favorites";
4
+ const notebookFactory = "favorites-notebook-factory";
4
5
  }
6
+ export type ShowStarsTypes = 'allCells' | 'onlyFavoriteCells' | 'never';
5
7
  export declare namespace CommandIDs {
6
8
  const addOrRemoveFavorite: string;
7
9
  const removeFavorite: string;
@@ -10,6 +12,9 @@ export declare namespace CommandIDs {
10
12
  const toggleFavoritesWidget: string;
11
13
  const restoreDefaults: string;
12
14
  const clearFavorites: string;
15
+ const toggleCellsVisibility: string;
16
+ const addFavoriteClasses: string;
17
+ const toggleCellFavorite: string;
13
18
  }
14
19
  export declare namespace SettingIDs {
15
20
  const themes = "@jupyterlab/apputils-extension:themes";
@@ -34,3 +39,7 @@ export declare const IFavorites: Token<IFavorites>;
34
39
  export interface IFavorites {
35
40
  readonly favorites: IFavorites.Favorite[];
36
41
  }
42
+ /**
43
+ * Cell tag used to mark cell as favorite
44
+ */
45
+ export declare const FAVORITE_TAG = "favorite";
package/lib/token.js CHANGED
@@ -2,6 +2,7 @@ import { Token } from '@lumino/coreutils';
2
2
  export var PluginIDs;
3
3
  (function (PluginIDs) {
4
4
  PluginIDs.favorites = 'jupyterlab-favorites';
5
+ PluginIDs.notebookFactory = 'favorites-notebook-factory';
5
6
  })(PluginIDs || (PluginIDs = {}));
6
7
  export var CommandIDs;
7
8
  (function (CommandIDs) {
@@ -12,6 +13,9 @@ export var CommandIDs;
12
13
  CommandIDs.toggleFavoritesWidget = `${PluginIDs.favorites}:toggle-favorites-widget`;
13
14
  CommandIDs.restoreDefaults = `${PluginIDs.favorites}:restore-defaults`;
14
15
  CommandIDs.clearFavorites = `${PluginIDs.favorites}:clear-favorites`;
16
+ CommandIDs.toggleCellsVisibility = `${PluginIDs.favorites}:toggle-cell-visibility`;
17
+ CommandIDs.addFavoriteClasses = `${PluginIDs.favorites}:toggle-favorite-classes`;
18
+ CommandIDs.toggleCellFavorite = `${PluginIDs.favorites}:toggle-cell-favorite`;
15
19
  })(CommandIDs || (CommandIDs = {}));
16
20
  export var SettingIDs;
17
21
  (function (SettingIDs) {
@@ -19,3 +23,7 @@ export var SettingIDs;
19
23
  SettingIDs.favorites = '@jlab-enhanced/favorites:favorites';
20
24
  })(SettingIDs || (SettingIDs = {}));
21
25
  export const IFavorites = new Token('jupyterlab-favorites:IFavorites');
26
+ /**
27
+ * Cell tag used to mark cell as favorite
28
+ */
29
+ export const FAVORITE_TAG = 'favorite';
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { LabIcon } from '@jupyterlab/ui-components';
1
+ import { LabIcon, ToolbarButton } from '@jupyterlab/ui-components';
2
+ import { Cell, ICellModel } from '@jupyterlab/cells';
3
+ import { Notebook, NotebookPanel } from '@jupyterlab/notebook';
4
+ import { ShowStarsTypes } from './token';
2
5
  export declare function getFavoritesIcon(filled: boolean): LabIcon;
3
6
  /**
4
7
  * Split the file path in two parts: the name and the folder
@@ -9,3 +12,8 @@ export declare function getName(path: string): [string, string];
9
12
  export declare function getPinnerActionDescription(showRemove: boolean): string;
10
13
  export declare function mergePaths(root: string, path: string): string;
11
14
  export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
15
+ export declare function updateCellFavoriteButton(button: ToolbarButton, cell: Cell<ICellModel>): void;
16
+ export declare function toggleCellFavorite(cell: ICellModel): void;
17
+ export declare function updateCellClasses(notebook: Notebook): void;
18
+ export declare function updateSingleCellClass(cell: Cell<ICellModel>): void;
19
+ export declare function changeShowStarsOnCells(type: ShowStarsTypes, notebookPanel: NotebookPanel | null): void;
package/lib/utils.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { filledStarIcon, starIcon } from './icons';
2
2
  import { PathExt } from '@jupyterlab/coreutils';
3
+ import { FAVORITE_TAG } from './token';
4
+ const FAVORITE_CELL_CLASS = 'jp-favorite-cell';
5
+ const SHOW_ALL_STARS = 'jp-Favorites-show-all-stars';
6
+ const NEVER_SHOW_STARS = 'jp-Favorites-never-show-stars';
3
7
  export function getFavoritesIcon(filled) {
4
8
  return filled ? filledStarIcon : starIcon;
5
9
  }
@@ -17,3 +21,104 @@ export function getPinnerActionDescription(showRemove) {
17
21
  export function mergePaths(root, path) {
18
22
  return PathExt.join(root, path);
19
23
  }
24
+ export function updateCellFavoriteButton(button, cell) {
25
+ const tags = cell.model.getMetadata('tags');
26
+ const isFavorite = Array.isArray(tags) && tags.includes(FAVORITE_TAG);
27
+ if (isFavorite) {
28
+ cell.addClass(FAVORITE_CELL_CLASS);
29
+ }
30
+ else {
31
+ cell.removeClass(FAVORITE_CELL_CLASS);
32
+ }
33
+ // Update tooltip
34
+ const tooltip = isFavorite ? 'Unfavorite cell' : 'Favorite cell';
35
+ const jpButton = button.node.querySelector('jp-button');
36
+ if (jpButton) {
37
+ jpButton.setAttribute('aria-label', tooltip);
38
+ jpButton.setAttribute('title', tooltip);
39
+ }
40
+ button.node.setAttribute('title', tooltip);
41
+ // Replace the SVG in the button
42
+ const icon = getFavoritesIcon(isFavorite);
43
+ const svgElement = button.node.querySelector('svg');
44
+ if (svgElement) {
45
+ svgElement.outerHTML = icon.svgstr;
46
+ }
47
+ else {
48
+ button.node.innerHTML = icon.svgstr;
49
+ }
50
+ }
51
+ export function toggleCellFavorite(cell) {
52
+ let tags = cell.getMetadata('tags');
53
+ if (Array.isArray(tags)) {
54
+ const favIndex = tags.indexOf(FAVORITE_TAG);
55
+ if (favIndex === -1) {
56
+ tags = [...tags, FAVORITE_TAG];
57
+ }
58
+ else {
59
+ tags = tags.filter(tag => tag !== FAVORITE_TAG);
60
+ }
61
+ if (tags.length === 0) {
62
+ cell.deleteMetadata('tags');
63
+ }
64
+ else {
65
+ cell.setMetadata('tags', tags);
66
+ }
67
+ }
68
+ else {
69
+ cell.setMetadata('tags', [FAVORITE_TAG]);
70
+ }
71
+ }
72
+ export function updateCellClasses(notebook) {
73
+ notebook.widgets.forEach(widget => {
74
+ const cell = widget;
75
+ const tags = cell.model.getMetadata('tags');
76
+ const isFav = Array.isArray(tags) && tags.includes(FAVORITE_TAG);
77
+ if (isFav) {
78
+ cell.node.classList.add(FAVORITE_CELL_CLASS);
79
+ }
80
+ else {
81
+ cell.node.classList.remove(FAVORITE_CELL_CLASS);
82
+ }
83
+ });
84
+ }
85
+ export function updateSingleCellClass(cell) {
86
+ const tags = cell.model.getMetadata('tags');
87
+ const isFav = Array.isArray(tags) && tags.includes(FAVORITE_TAG);
88
+ if (isFav) {
89
+ cell.addClass(FAVORITE_CELL_CLASS);
90
+ }
91
+ else {
92
+ cell.removeClass(FAVORITE_CELL_CLASS);
93
+ }
94
+ }
95
+ export function changeShowStarsOnCells(type, notebookPanel) {
96
+ if (!notebookPanel || !notebookPanel.content) {
97
+ return;
98
+ }
99
+ const notebook = notebookPanel.content;
100
+ const toggleClass = (className, shouldAdd) => {
101
+ if (shouldAdd) {
102
+ if (!notebook.node.classList.contains(className)) {
103
+ notebook.node.classList.add(className);
104
+ }
105
+ }
106
+ else {
107
+ if (notebook.node.classList.contains(className)) {
108
+ notebook.node.classList.remove(className);
109
+ }
110
+ }
111
+ };
112
+ if (type === 'allCells') {
113
+ toggleClass(NEVER_SHOW_STARS, false);
114
+ toggleClass(SHOW_ALL_STARS, true);
115
+ }
116
+ else if (type === 'onlyFavoriteCells') {
117
+ toggleClass(NEVER_SHOW_STARS, false);
118
+ toggleClass(SHOW_ALL_STARS, false);
119
+ }
120
+ else if (type === 'never') {
121
+ toggleClass(SHOW_ALL_STARS, false);
122
+ toggleClass(NEVER_SHOW_STARS, true);
123
+ }
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jlab-enhanced/favorites",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "Add the ability to save favorite folders to JupyterLab for quicker browsing",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -70,10 +70,12 @@
70
70
  "dependencies": {
71
71
  "@jupyterlab/application": "^4.0.5",
72
72
  "@jupyterlab/apputils": "^4.1.5",
73
+ "@jupyterlab/cells": "^4.0.5",
73
74
  "@jupyterlab/coreutils": "^6.0.5",
74
75
  "@jupyterlab/docregistry": "^4.0.5",
75
76
  "@jupyterlab/filebrowser": "^4.0.5",
76
77
  "@jupyterlab/mainmenu": "^4.0.5",
78
+ "@jupyterlab/notebook": "^4.0.5",
77
79
  "@jupyterlab/services": "^7.0.5",
78
80
  "@jupyterlab/settingregistry": "^4.0.5",
79
81
  "@jupyterlab/ui-components": "^4.0.5",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "root": {
25
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
+ "description": "Root path used for filtering out favorites from instances of JupyterLab launched in a different root directory. If not given the favorite will be shown if the associated file exists."
27
27
  }
28
28
  },
29
29
  "required": ["path"],
@@ -48,6 +48,25 @@
48
48
  "rank": 3,
49
49
  "selector": ".jp-DirListing-item[data-isdir]"
50
50
  }
51
+ ],
52
+ "main": [
53
+ {
54
+ "id": "jp-mainmenu-view",
55
+ "rank": 10,
56
+ "items": [
57
+ {
58
+ "command": "jupyterlab-favorites:toggle-cell-visibility"
59
+ }
60
+ ]
61
+ }
62
+ ]
63
+ },
64
+ "jupyter.lab.toolbars": {
65
+ "Cell": [
66
+ {
67
+ "name": "cellFavoriteToggle",
68
+ "rank": 110
69
+ }
51
70
  ]
52
71
  },
53
72
  "jupyter.lab.setting-icon": "jupyterlab-favorites:filledStar",
@@ -67,6 +86,17 @@
67
86
  "description": "Toggles the favorites widget above the filebrowser breadcrumbs.",
68
87
  "title": "Show Widget",
69
88
  "type": "boolean"
89
+ },
90
+ "showStarsOnCells": {
91
+ "type": "string",
92
+ "title": "Show Stars on Cells",
93
+ "description": "Controls the visibility of star icons on cells.",
94
+ "default": "onlyFavoriteCells",
95
+ "oneOf": [
96
+ { "const": "allCells", "title": "All Cells" },
97
+ { "const": "onlyFavoriteCells", "title": "Only favorite Cells" },
98
+ { "const": "never", "title": "Never" }
99
+ ]
70
100
  }
71
101
  },
72
102
  "title": "Favorites",
package/style/base.css CHANGED
@@ -12,6 +12,13 @@
12
12
  margin-top: -5px;
13
13
  }
14
14
 
15
+ .jp-Favorites-InputPromptNumber {
16
+ left: 12px !important;
17
+ width: 51px !important;
18
+ top: 0 !important;
19
+ height: 23px !important;
20
+ }
21
+
15
22
  .jp-Favorites-crumbs {
16
23
  margin-right: 40px;
17
24
  }
@@ -77,3 +84,54 @@
77
84
  font-size: var(--jp-ui-font-size0);
78
85
  margin: 0 4px;
79
86
  }
87
+
88
+ .jp-Notebook.jp-favorites-filter-active .jp-Cell:not(.jp-favorite-cell) {
89
+ display: none !important;
90
+ }
91
+
92
+ .jp-Favorites-base-star-class {
93
+ top: -2px !important;
94
+ left: -6px !important;
95
+ height: 23px !important;
96
+ width: 24px !important;
97
+ }
98
+
99
+ .jp-Cell.jp-favorite-cell .jp-Favorites-star-class {
100
+ display: block !important;
101
+ }
102
+
103
+ .jp-Cell.jp-favorite-cell .jp-Favorites-star-class-off {
104
+ display: none !important;
105
+ }
106
+
107
+ .jp-Notebook.jp-Favorites-show-all-stars
108
+ .jp-Cell:not(.jp-favorite-cell)
109
+ .jp-Favorites-star-class-off {
110
+ display: block !important;
111
+ }
112
+
113
+ .jp-Notebook:not(.jp-Favorites-show-all-stars)
114
+ .jp-Cell:not(.jp-favorite-cell)
115
+ .jp-Favorites-star-class-off {
116
+ display: none !important;
117
+ }
118
+
119
+ .jp-Cell:not(.jp-favorite-cell) .jp-Favorites-star-class {
120
+ display: none !important;
121
+ }
122
+
123
+ .jp-Notebook .jp-Cell.jp-mod-dirty .jp-InputPrompt::before {
124
+ content: none !important;
125
+ }
126
+
127
+ .jp-Notebook.jp-Favorites-never-show-stars .jp-Favorites-base-star-class {
128
+ display: none !important;
129
+ }
130
+
131
+ @media only screen and (width <= 760px) {
132
+ .jp-InputPrompt {
133
+ flex: 0 0 var(--jp-cell-prompt-width) !important;
134
+ margin-bottom: -30px !important;
135
+ text-align: left;
136
+ }
137
+ }
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.