-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically load IPyWidgets 7 #21
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1676124
WIP
DonJayamanne 5402175
misc
DonJayamanne 9c13547
wip
DonJayamanne 5fe9189
Misc
DonJayamanne fbe39b8
try
DonJayamanne 3790852
Misc
DonJayamanne fa66a84
wip
DonJayamanne 3f969c0
Misc
DonJayamanne 5c91442
Misc
DonJayamanne 6611e28
Misc
DonJayamanne 1b0e65c
Misc
DonJayamanne 782cf60
Misc
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ trigger: | |
branches: | ||
include: | ||
- main | ||
- release/ipywidgets7.2 | ||
pr: none | ||
|
||
resources: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ npm-debug.log | |
bin/** | ||
obj/** | ||
tmp/** | ||
tsconfig.tsbuildinfo |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,50 +4,60 @@ | |
import * as base from '@jupyter-widgets/base'; | ||
import * as widgets from '@jupyter-widgets/controls'; | ||
import * as outputWidgets from '@jupyter-widgets/jupyterlab-manager/lib/output'; | ||
import * as embed from './embed'; | ||
import { WidgetManager } from './manager'; | ||
import './widgets.css'; | ||
|
||
type KernelMessagingApi = { | ||
postKernelMessage: (data: unknown) => void; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
|
||
// Default logger is console.log | ||
let logger = console.log; | ||
let loaded = false; | ||
function load() { | ||
if (loaded) { | ||
console.warn('Already loaded ipywidgets7'); | ||
return; | ||
} | ||
require('./widgets.css'); | ||
require('../node_modules/@fortawesome/fontawesome-free/css/all.min.css'); | ||
// Export the following for `requirejs`. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-empty,@typescript-eslint/no-empty-function | ||
const define = (window as any).define || function () {}; | ||
define('@jupyter-widgets/controls', () => widgets); | ||
define('@jupyter-widgets/base', () => base); | ||
define('@jupyter-widgets/output', () => outputWidgets); | ||
|
||
// Export the following for `requirejs`. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-empty,@typescript-eslint/no-empty-function | ||
const define = (window as any).define || function () {}; | ||
define('@jupyter-widgets/controls', () => widgets); | ||
define('@jupyter-widgets/base', () => base); | ||
define('@jupyter-widgets/output', () => outputWidgets); | ||
// Create our window export. Necessary for the ipywidget code loading in the output to find our widget manager | ||
// Jupyter extension will look for the WidgetManager in this object. | ||
|
||
// Render existing widgets without a kernel and pull in the correct css files | ||
// This is not done yet. See this issue here: https://github.com/microsoft/vscode-python/issues/10794 | ||
// Likely we'll do this in a different spot. | ||
if (document.readyState === 'complete') { | ||
embed.renderWidgets(document.documentElement, logger); | ||
} else { | ||
window.addEventListener('load', () => { | ||
embed.renderWidgets(document.documentElement, logger); | ||
}); | ||
// tslint:disable-next-line: no-any | ||
(window as any).vscIPyWidgets = { | ||
WidgetManager | ||
}; | ||
loaded = true; | ||
} | ||
function unload() { | ||
if (!loaded) { | ||
return; | ||
} | ||
|
||
// Create our window export. Necessary for the ipywidget code loading in the output to find our widget manager | ||
// tslint:disable-next-line: no-any | ||
(window as any).vscIPyWidgets = { | ||
WidgetManager | ||
}; | ||
try { | ||
const undef = (window as any).undef || function () {}; | ||
undef('@jupyter-widgets/controls'); | ||
undef('@jupyter-widgets/base'); | ||
undef('@jupyter-widgets/output'); | ||
loaded = false; | ||
} catch (e) { | ||
console.warn(`Failed to unload IPYWidgets 7`, e); | ||
} | ||
} | ||
|
||
// Has to be this form for VS code to load it correctly | ||
export function activate(context?: KernelMessagingApi) { | ||
// Setup the logger function | ||
if (context) { | ||
logger = (msg) => { | ||
context.postKernelMessage({ | ||
type: 'IPyWidgets_logMessage', | ||
payload: msg | ||
}); | ||
/** | ||
* Activate function is required by VS Code. | ||
*/ | ||
export function activate() { | ||
// Expose an object with load and unload functions. | ||
// So that we can dynamically load and unload them. | ||
// This script file along with the ipywidgets 8 version will be loaded into the same webpage | ||
// However depending on the version of IPyWidgets we load only one of them. | ||
if (!(window as any).vscIPyWidgets7) { | ||
(window as any).vscIPyWidgets7 = { | ||
load, | ||
unload | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduced some API changes (changes to how the script is loaded an the API to communicate with this)
Hence the major bump