From bf34f0e1aa9a1cfc5104b7a00eba2385e3c0320f Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Tue, 13 Jun 2023 09:55:34 +0100 Subject: [PATCH 01/11] thebe upgrade & bundle core provider strategy --- .changeset/quick-sheep-prove.md | 6 + package-lock.json | 553 +++++++++++++++++- package.json | 5 +- packages/jupyter/package.json | 5 +- packages/jupyter/src/core.tsx | 84 +++ packages/jupyter/src/index.tsx | 1 + packages/jupyter/src/jupyter.tsx | 4 +- packages/jupyter/src/providers.tsx | 22 +- packages/site/package.json | 2 +- .../site/src/components/EnableCompute.tsx | 6 +- packages/site/src/pages/Root.tsx | 16 +- 11 files changed, 668 insertions(+), 36 deletions(-) create mode 100644 .changeset/quick-sheep-prove.md create mode 100644 packages/jupyter/src/core.tsx diff --git a/.changeset/quick-sheep-prove.md b/.changeset/quick-sheep-prove.md new file mode 100644 index 000000000..99413ce16 --- /dev/null +++ b/.changeset/quick-sheep-prove.md @@ -0,0 +1,6 @@ +--- +'@myst-theme/jupyter': patch +'@myst-theme/site': patch +--- + +upgraded to thebe 0.2.2 diff --git a/package-lock.json b/package-lock.json index a602a6706..5a9d8e3c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "docs" ], "devDependencies": { - "@changesets/cli": "^2.26.0", + "@changesets/cli": "^2.26.1", "@remix-run/node": "^1.12.0", "@remix-run/react": "^1.12.0", "@tailwindcss/typography": "^0.5.9", @@ -6801,6 +6801,466 @@ "object-assign": "^4.1.1" } }, + "node_modules/@jupyterlite/contents": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/contents/-/contents-0.1.0.tgz", + "integrity": "sha512-SWm72liUhfFrFHcyqxbV+jGRoKJk0JK6cjbYZMOsG0r3E3l7rDtne176MsvD4vIipf7UQeE3lk++dAAst6TnFA==", + "dependencies": { + "@jupyterlab/nbformat": "~3.5.3", + "@jupyterlab/services": "~6.5.3", + "@jupyterlite/localforage": "^0.1.0", + "@lumino/coreutils": "^1.12.0", + "@types/emscripten": "^1.39.6", + "localforage": "^1.9.0", + "mime": "^3.0.0" + } + }, + "node_modules/@jupyterlite/contents/node_modules/@jupyterlab/nbformat": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/nbformat/-/nbformat-3.5.3.tgz", + "integrity": "sha512-7HIdRXrm5BKrP4P1cT+b34BFiqmEcr5fJyyBW6nIm3DXh9ZNTKhQUN8vGvkL7qTXZFXmdhc//eTSZUPQ3F3JcA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0" + } + }, + "node_modules/@jupyterlite/contents/node_modules/@jupyterlab/services": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/services/-/services-6.5.3.tgz", + "integrity": "sha512-9wIVzKeAvgx9J0g9DoG96yauG+HU4/ms28DM+7iS34/akoHSM17czWGGnmKY0Y3MyZ22up7aZelCthP+WiAQxQ==", + "dependencies": { + "@jupyterlab/coreutils": "^5.5.3", + "@jupyterlab/nbformat": "^3.5.3", + "@jupyterlab/observables": "^4.5.3", + "@jupyterlab/settingregistry": "^3.5.3", + "@jupyterlab/statedb": "^3.5.3", + "@lumino/algorithm": "^1.9.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/polling": "^1.9.0", + "@lumino/signaling": "^1.10.0", + "node-fetch": "^2.6.0", + "ws": "^7.4.6" + } + }, + "node_modules/@jupyterlite/contents/node_modules/mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/@jupyterlite/kernel": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/kernel/-/kernel-0.1.0.tgz", + "integrity": "sha512-94nybVipEz+YrBOxe6wN7oqbe1hLPY1GLkWCeOAUu5NyZQk/eiVozJMY+ukt08SvcUtwTi0yNZZl+5thNzwneA==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@jupyterlab/observables": "~4.5.3", + "@jupyterlab/services": "~6.5.3", + "@lumino/coreutils": "^1.12.0", + "@lumino/disposable": "^1.10.1", + "@lumino/signaling": "^1.10.1", + "async-mutex": "^0.3.1", + "comlink": "^4.3.1", + "mock-socket": "^9.1.0" + } + }, + "node_modules/@jupyterlite/kernel/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/kernel/node_modules/@jupyterlab/observables": { + "version": "4.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/observables/-/observables-4.5.3.tgz", + "integrity": "sha512-WERivf/gr2ZMGCXEiJpgv4AGVG8ovKzdg/tIgzrf72eB4Jq5WXMy4r5GLvM+g3PkiiG8o50C2t/SXcUlvNDTaw==", + "dependencies": { + "@lumino/algorithm": "^1.9.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/messaging": "^1.10.0", + "@lumino/signaling": "^1.10.0" + } + }, + "node_modules/@jupyterlite/kernel/node_modules/@jupyterlab/services": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/services/-/services-6.5.3.tgz", + "integrity": "sha512-9wIVzKeAvgx9J0g9DoG96yauG+HU4/ms28DM+7iS34/akoHSM17czWGGnmKY0Y3MyZ22up7aZelCthP+WiAQxQ==", + "dependencies": { + "@jupyterlab/coreutils": "^5.5.3", + "@jupyterlab/nbformat": "^3.5.3", + "@jupyterlab/observables": "^4.5.3", + "@jupyterlab/settingregistry": "^3.5.3", + "@jupyterlab/statedb": "^3.5.3", + "@lumino/algorithm": "^1.9.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/polling": "^1.9.0", + "@lumino/signaling": "^1.10.0", + "node-fetch": "^2.6.0", + "ws": "^7.4.6" + } + }, + "node_modules/@jupyterlite/licenses": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/licenses/-/licenses-0.1.0.tgz", + "integrity": "sha512-+yo+L82cH/pvlCtHxpUAoh5RHH6BjxXgJvbJ7UsIVW7VGakhB+vaIfAeNU9UGxk045dYzdREtG618iZVX12XDA==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3" + } + }, + "node_modules/@jupyterlite/licenses/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/localforage": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/localforage/-/localforage-0.1.0.tgz", + "integrity": "sha512-D639O93OLBnGEjIq5PCthB2BMJqvNpKndIKcYCwTeR4+h2PLHfOmvN+Vw6T3IzJU29ylykiFgN5AZ8nNKfkxOQ==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@lumino/coreutils": "^1.5.3", + "localforage": "^1.9.0", + "localforage-memoryStorageDriver": "^0.9.2" + } + }, + "node_modules/@jupyterlite/localforage/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/pyodide-kernel": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@jupyterlite/pyodide-kernel/-/pyodide-kernel-0.0.8.tgz", + "integrity": "sha512-SoRa+b+1sb5nu/To8zp8BehAD+76OaPJkBb7KpeGyTbbcXSG89c0P/2Ny7rLWlgjCEE81m/PVTh5rlj2J7CFFQ==", + "dependencies": { + "@jupyterlite/contents": "^0.1.0-beta.18", + "@jupyterlite/kernel": "^0.1.0-beta.18", + "comlink": "^4.3.1" + } + }, + "node_modules/@jupyterlite/pyodide-kernel-extension": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@jupyterlite/pyodide-kernel-extension/-/pyodide-kernel-extension-0.0.8.tgz", + "integrity": "sha512-dsTI011Nn+76ClC9eST+XSK/d5ZSaVuoFJkIhVDA6DTE15ouKfjbZOkkatLdjtKYa3Bi1B/aVmNpokiB0cl2nw==", + "dependencies": { + "@jupyterlab/coreutils": "^5.5.2", + "@jupyterlite/contents": "^0.1.0-beta.18", + "@jupyterlite/kernel": "^0.1.0-beta.18", + "@jupyterlite/pyodide-kernel": "^0.0.8", + "@jupyterlite/server": "^0.1.0-beta.18" + } + }, + "node_modules/@jupyterlite/server": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/server/-/server-0.1.0.tgz", + "integrity": "sha512-BUOVs6kLxDpHgtg3PcUtuGvoixjVFRLUNiiL/ywY56LA22KI1+D5Yp85K9k8IalGkc3FbH0wMblEsmkTUKvAsg==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@jupyterlab/nbformat": "~3.5.3", + "@jupyterlab/observables": "~4.5.3", + "@jupyterlab/services": "~6.5.3", + "@jupyterlab/settingregistry": "~3.5.3", + "@jupyterlab/statedb": "~3.5.3", + "@jupyterlite/contents": "^0.1.0", + "@jupyterlite/kernel": "^0.1.0", + "@jupyterlite/session": "^0.1.0", + "@jupyterlite/settings": "^0.1.0", + "@jupyterlite/translation": "^0.1.0", + "@lumino/application": "^1.27.0", + "@lumino/coreutils": "^1.12.0", + "mock-socket": "^9.1.0" + } + }, + "node_modules/@jupyterlite/server-extension": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/server-extension/-/server-extension-0.1.0.tgz", + "integrity": "sha512-m88Kx+a6FdftWCC/F5Rnk7Vv/sRbDeBzI2YPy/qwyFnYQwLlpLYd/2hDse3zvsv1nP+Y8eWRnxO1s4m0jSg37g==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@jupyterlite/kernel": "^0.1.0", + "@jupyterlite/licenses": "^0.1.0", + "@jupyterlite/localforage": "^0.1.0", + "@jupyterlite/server": "^0.1.0", + "@jupyterlite/session": "^0.1.0", + "@jupyterlite/settings": "^0.1.0", + "@jupyterlite/translation": "^0.1.0" + } + }, + "node_modules/@jupyterlite/server-extension/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/server/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/server/node_modules/@jupyterlab/nbformat": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/nbformat/-/nbformat-3.5.3.tgz", + "integrity": "sha512-7HIdRXrm5BKrP4P1cT+b34BFiqmEcr5fJyyBW6nIm3DXh9ZNTKhQUN8vGvkL7qTXZFXmdhc//eTSZUPQ3F3JcA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0" + } + }, + "node_modules/@jupyterlite/server/node_modules/@jupyterlab/observables": { + "version": "4.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/observables/-/observables-4.5.3.tgz", + "integrity": "sha512-WERivf/gr2ZMGCXEiJpgv4AGVG8ovKzdg/tIgzrf72eB4Jq5WXMy4r5GLvM+g3PkiiG8o50C2t/SXcUlvNDTaw==", + "dependencies": { + "@lumino/algorithm": "^1.9.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/messaging": "^1.10.0", + "@lumino/signaling": "^1.10.0" + } + }, + "node_modules/@jupyterlite/server/node_modules/@jupyterlab/services": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/services/-/services-6.5.3.tgz", + "integrity": "sha512-9wIVzKeAvgx9J0g9DoG96yauG+HU4/ms28DM+7iS34/akoHSM17czWGGnmKY0Y3MyZ22up7aZelCthP+WiAQxQ==", + "dependencies": { + "@jupyterlab/coreutils": "^5.5.3", + "@jupyterlab/nbformat": "^3.5.3", + "@jupyterlab/observables": "^4.5.3", + "@jupyterlab/settingregistry": "^3.5.3", + "@jupyterlab/statedb": "^3.5.3", + "@lumino/algorithm": "^1.9.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/polling": "^1.9.0", + "@lumino/signaling": "^1.10.0", + "node-fetch": "^2.6.0", + "ws": "^7.4.6" + } + }, + "node_modules/@jupyterlite/server/node_modules/@jupyterlab/settingregistry": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/settingregistry/-/settingregistry-3.5.3.tgz", + "integrity": "sha512-PWkISgGHikSaOEOiPVIDCcnLdiuXAcFdI7ZPLWoaq0v+NykemenQ5+MXOEaEOgf3KUAE8PFAGNr+3indbwFXNw==", + "dependencies": { + "@jupyterlab/statedb": "^3.5.3", + "@lumino/commands": "^1.19.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "ajv": "^6.12.3", + "json5": "^2.1.1" + } + }, + "node_modules/@jupyterlite/server/node_modules/@jupyterlab/statedb": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/statedb/-/statedb-3.5.3.tgz", + "integrity": "sha512-QlFLcSzOJUjjwiXjgv5dQVHTRXXBT5+e/kJKVLddi80li/p0hBmKQHP+9e15Ql+i599uyoE6zE7lyMRPHrO98w==", + "dependencies": { + "@lumino/commands": "^1.19.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/properties": "^1.8.0", + "@lumino/signaling": "^1.10.0" + } + }, + "node_modules/@jupyterlite/server/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@jupyterlite/server/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, + "node_modules/@jupyterlite/session": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/session/-/session-0.1.0.tgz", + "integrity": "sha512-LBpWZlJvfo+o/L0Py6LGamv8bqqJlGG9dYD3Td/gn/o/BwE04ORiEdLK5BKuN9w10cH9lAUrmU+OkFU/lBXYlQ==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@jupyterlab/services": "~6.5.3", + "@jupyterlite/kernel": "^0.1.0", + "@lumino/algorithm": "^1.9.1", + "@lumino/coreutils": "^1.12.0" + } + }, + "node_modules/@jupyterlite/session/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/session/node_modules/@jupyterlab/services": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/services/-/services-6.5.3.tgz", + "integrity": "sha512-9wIVzKeAvgx9J0g9DoG96yauG+HU4/ms28DM+7iS34/akoHSM17czWGGnmKY0Y3MyZ22up7aZelCthP+WiAQxQ==", + "dependencies": { + "@jupyterlab/coreutils": "^5.5.3", + "@jupyterlab/nbformat": "^3.5.3", + "@jupyterlab/observables": "^4.5.3", + "@jupyterlab/settingregistry": "^3.5.3", + "@jupyterlab/statedb": "^3.5.3", + "@lumino/algorithm": "^1.9.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/polling": "^1.9.0", + "@lumino/signaling": "^1.10.0", + "node-fetch": "^2.6.0", + "ws": "^7.4.6" + } + }, + "node_modules/@jupyterlite/settings": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/settings/-/settings-0.1.0.tgz", + "integrity": "sha512-SjW+Vyqw5V+s44QaYruDOShwdMsmFxp3YaVkZpfdUbuCW9FEZbZvIFiKy2T+SkgKV0Gqw5UzyneNP7t9nh5X9w==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@jupyterlab/settingregistry": "~3.5.3", + "@jupyterlite/localforage": "^0.1.0", + "@lumino/coreutils": "^1.12.0", + "json5": "^2.2.0", + "localforage": "^1.9.0" + } + }, + "node_modules/@jupyterlite/settings/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, + "node_modules/@jupyterlite/settings/node_modules/@jupyterlab/settingregistry": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/settingregistry/-/settingregistry-3.5.3.tgz", + "integrity": "sha512-PWkISgGHikSaOEOiPVIDCcnLdiuXAcFdI7ZPLWoaq0v+NykemenQ5+MXOEaEOgf3KUAE8PFAGNr+3indbwFXNw==", + "dependencies": { + "@jupyterlab/statedb": "^3.5.3", + "@lumino/commands": "^1.19.0", + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "ajv": "^6.12.3", + "json5": "^2.1.1" + } + }, + "node_modules/@jupyterlite/settings/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@jupyterlite/settings/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, + "node_modules/@jupyterlite/translation": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@jupyterlite/translation/-/translation-0.1.0.tgz", + "integrity": "sha512-eNN+zSaz+baqKbB2ve/Ng1zJLc85L4OKf+G5sOOTRFUHvMNylIJkOq+xwlsTFh3QZr/97GEgg79GHg+4h31xHQ==", + "dependencies": { + "@jupyterlab/coreutils": "~5.5.3", + "@lumino/coreutils": "^1.12.0" + } + }, + "node_modules/@jupyterlite/translation/node_modules/@jupyterlab/coreutils": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-5.5.3.tgz", + "integrity": "sha512-GCAymoQAwscE8MGH7eb366bRxvWawOXKFeyq642SAtl0/xWty8Kem56UfdUdyTCRzxwYW5r1sJuRHBvbTjnvUA==", + "dependencies": { + "@lumino/coreutils": "^1.11.0", + "@lumino/disposable": "^1.10.0", + "@lumino/signaling": "^1.10.0", + "minimist": "~1.2.0", + "moment": "^2.24.0", + "path-browserify": "^1.0.0", + "url-parse": "~1.5.1" + } + }, "node_modules/@lumino/algorithm": { "version": "1.9.2", "resolved": "https://registry.npmjs.org/@lumino/algorithm/-/algorithm-1.9.2.tgz", @@ -11908,6 +12368,11 @@ "integrity": "sha512-ZmiaE3wglXVWBM9fyVC17aGPkLo/UgaOjEiI2FXQfyczrCefORPxIe+2dVmnmk3zkVIbizjrlQzmPGhSYGXG5g==", "dev": true }, + "node_modules/@types/emscripten": { + "version": "1.39.6", + "resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-1.39.6.tgz", + "integrity": "sha512-H90aoynNhhkQP6DRweEjJp5vfUVdIj7tdPLsu7pq89vODD/lcugKfZOsfgwpvM6XUewEp2N5dCg1Uf3Qe55Dcg==" + }, "node_modules/@types/escodegen": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/@types/escodegen/-/escodegen-0.0.6.tgz", @@ -13778,6 +14243,14 @@ "node": ">= 14" } }, + "node_modules/async-mutex": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.3.2.tgz", + "integrity": "sha512-HuTK7E7MT7jZEh1P9GtRW9+aTWiDWWi9InbZ5hjxrnRa39KS4BW04+xLBhYNS2aXhHUIKZSw3gj4Pn1pj+qGAA==", + "dependencies": { + "tslib": "^2.3.1" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -15614,6 +16087,11 @@ "node": ">= 0.8" } }, + "node_modules/comlink": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/comlink/-/comlink-4.4.1.tgz", + "integrity": "sha512-+1dlx0aY5Jo1vHy/tSsIGpSkN4tS9rZSW8FIhG0JH/crs9wwweswIo/POr451r7bZww3hFbPAKnTpimzL/mm4Q==" + }, "node_modules/comma-separated-tokens": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz", @@ -21973,6 +22451,11 @@ "node": "*" } }, + "node_modules/hook-shell-script-webpack-plugin": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/hook-shell-script-webpack-plugin/-/hook-shell-script-webpack-plugin-0.1.4.tgz", + "integrity": "sha512-LDv0JiHW9GqYpMJuvn9DuNkGbuzOegEo/M2IJTDsJWZjHF+XlJyeXHq2lVf75m6GkSFKQKFMCk7nbqNUSio4mQ==" + }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -27550,6 +28033,30 @@ "node": ">= 12.13.0" } }, + "node_modules/localforage": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz", + "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==", + "dependencies": { + "lie": "3.1.1" + } + }, + "node_modules/localforage-memoryStorageDriver": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/localforage-memoryStorageDriver/-/localforage-memoryStorageDriver-0.9.2.tgz", + "integrity": "sha512-DRB4BkkW9o5HIetbsuvtcg98GP7J1JBRDyDMJK13hfr9QsNpnMW6UUWmU9c6bcRg99akR1mGZ/ubUV1Ek0fbpg==", + "dependencies": { + "localforage": ">=1.4.0" + } + }, + "node_modules/localforage/node_modules/lie": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", + "integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==", + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -29612,6 +30119,14 @@ "ufo": "^1.1.2" } }, + "node_modules/mock-socket": { + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/mock-socket/-/mock-socket-9.2.1.tgz", + "integrity": "sha512-aw9F9T9G2zpGipLLhSNh6ZpgUyUl4frcVmRN08uE1NWPWg43Wx6+sGPDbQ7E5iFZZDJW5b5bypMeAEHqTbIFag==", + "engines": { + "node": ">= 8" + } + }, "node_modules/moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", @@ -36071,9 +36586,9 @@ "dev": true }, "node_modules/thebe-core": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/thebe-core/-/thebe-core-0.1.6.tgz", - "integrity": "sha512-nzoym5Fx76k31AR56hjQS2u3smovR0LLjstdvqfocvgRLf5+F+TR8kLI/GQmCTedO3S/IEPGmxr0CeaqK2zBhw==", + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/thebe-core/-/thebe-core-0.2.2.tgz", + "integrity": "sha512-B4wJ5fM1SHNQcU4hCBOQafujpf3m1WX87eJb89pxX0/KueDOPrxuy78tkpeJX5EDID1CfIt4r0TcqzgQRd0hkQ==", "dependencies": { "@jupyter-widgets/base": "^6.0.1", "@jupyter-widgets/controls": "^5.0.1", @@ -36095,7 +36610,7 @@ "nanoid": "^3.2.0" }, "peerDependencies": { - "thebe-lite": "0.1.0" + "thebe-lite": "^0.2.2" } }, "node_modules/thebe-core/node_modules/nanoid": { @@ -36115,15 +36630,28 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/thebe-lite": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/thebe-lite/-/thebe-lite-0.2.2.tgz", + "integrity": "sha512-ekpGzWf66BiE4AYYN7BAmHVUJpKacfw0qSkIp9zcSJRgJJkA2m8awAF0jzCqWjzKQwZ9tDUWsfpkfE40KZXynA==", + "dependencies": { + "@jupyterlab/coreutils": "^5.6.3", + "@jupyterlite/pyodide-kernel": "0.0.8", + "@jupyterlite/pyodide-kernel-extension": "0.0.8", + "@jupyterlite/server": "0.1.0", + "@jupyterlite/server-extension": "0.1.0", + "hook-shell-script-webpack-plugin": "^0.1.4" + } + }, "node_modules/thebe-react": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/thebe-react/-/thebe-react-0.0.7.tgz", - "integrity": "sha512-xcZYtdq8LpI4GA9PsTnsBP3ZDG83m2I1Px4GU8HusgyB6Sn5R4R6gLHoA2SMW5AgiobpJVGBi9McpQmb1eh8eQ==", + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/thebe-react/-/thebe-react-0.2.2.tgz", + "integrity": "sha512-Xpv/vxzIBKhHO9qm1WXmKM9u8y9An4FO/RRnkPr7OkRfRLspVcwkCkmcPRKN3Too/hAfCbY0V29LxBSGh5aHag==", "dependencies": { "@jupyterlab/nbformat": "^3.5.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "thebe-core": "^0.1.6" + "thebe-core": "^0.2.2" } }, "node_modules/thenify": { @@ -38810,8 +39338,9 @@ "nbtx": "^0.2.3", "react-syntax-highlighter": "^15.5.0", "swr": "^1.3.0", - "thebe-core": "^0.1.6", - "thebe-react": "^0.0.7", + "thebe-core": "^0.2.2", + "thebe-lite": "^0.2.2", + "thebe-react": "^0.2.2", "unist-util-select": "^4.0.3" }, "devDependencies": { @@ -39066,7 +39595,7 @@ "nbtx": "^0.2.3", "node-cache": "^5.1.2", "node-fetch": "^2.6.7", - "thebe-react": "^0.0.7", + "thebe-react": "^0.2.2", "unist-util-select": "^4.0.1" }, "devDependencies": { diff --git a/package.json b/package.json index 8a35bb882..d87e1cfdc 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "publish": "npm run clean && npm run build -- --force && changeset publish && git push --follow-tags" }, "devDependencies": { - "@changesets/cli": "^2.26.0", + "@changesets/cli": "^2.26.1", "@remix-run/node": "^1.12.0", "@remix-run/react": "^1.12.0", "@tailwindcss/typography": "^0.5.9", @@ -56,6 +56,5 @@ "react-dom": "^18.2.0" } }, - "packageManager": "npm@8.10.0", - "dependencies": {} + "packageManager": "npm@8.10.0" } diff --git a/packages/jupyter/package.json b/packages/jupyter/package.json index 9be88295b..89b3784a0 100644 --- a/packages/jupyter/package.json +++ b/packages/jupyter/package.json @@ -33,8 +33,9 @@ "nbtx": "^0.2.3", "react-syntax-highlighter": "^15.5.0", "swr": "^1.3.0", - "thebe-core": "^0.1.6", - "thebe-react": "^0.0.7", + "thebe-core": "^0.2.2", + "thebe-lite": "^0.2.2", + "thebe-react": "^0.2.2", "unist-util-select": "^4.0.3" }, "peerDependencies": { diff --git a/packages/jupyter/src/core.tsx b/packages/jupyter/src/core.tsx new file mode 100644 index 000000000..be780816b --- /dev/null +++ b/packages/jupyter/src/core.tsx @@ -0,0 +1,84 @@ +import React, { useEffect, useState } from 'react'; + +// eslint-disable-next-line @typescript-eslint/consistent-type-imports +export type ThebeCore = typeof import('thebe-core'); + +// Don't know how to get rid of the undefined here in the case of an async provider +const ThebeCoreContext = React.createContext< + { core?: ThebeCore; error?: string; loading: boolean; load: () => void } | undefined +>(undefined); + +export function ThebeCoreBundleProvider({ + start, + loadThebeLite, + children, +}: React.PropsWithChildren<{ start?: boolean; loadThebeLite: boolean }>) { + const [startLoad, setStartLoad] = useState(start); + const [loading, setLoading] = useState(false); + const [core, setCore] = useState(); + const [error, setError] = useState(); + + useEffect(() => { + // if already loaded do nothing + if (!startLoad || core) return; + setLoading(true); + console.debug('importing thebe-core...'); + + if (typeof document !== 'undefined' && typeof window !== 'undefined') { + try { + if (!window.thebeCore) { + const script = document.createElement('script'); + script.setAttribute('src', '/thebe-core.min.js'); + script.setAttribute('async', 'true'); + script.setAttribute('type', 'text/javascript'); + document.head.appendChild(script); + + const styles = document.createElement('link'); + styles.setAttribute('rel', 'stylesheet'); + styles.setAttribute('href', '/thebe-core.css'); + document.head.appendChild(styles); + } + + if (loadThebeLite) { + const liteScript = document.createElement('script'); + liteScript.setAttribute('src', '/thebe-lite.min.js'); + liteScript.setAttribute('async', 'true'); + liteScript.setAttribute('type', 'text/javascript'); + document.head.appendChild(liteScript); + } + + let attempts = 0; + const timer = setInterval(() => { + if (window.thebeCore && (window.thebeLite || !loadThebeLite)) { + setLoading(false); + setCore((window as any).thebeCore?.module); + clearInterval(timer); + } + if (attempts > 10) { + setError('thebe-core load failed'); + setLoading(false); + clearInterval(timer); + } + attempts += 1; + }, 300); + } catch (err: any) { + setError(err); + setLoading(false); + } + } + }, [startLoad]); + + return ( + setStartLoad(true) }}> + <>{children} + + ); +} + +export function useThebeCoreBundle() { + const context = React.useContext(ThebeCoreContext); + if (context === undefined) { + throw new Error('useThebeCoreBundle must be used inside a ThebeCoreBundleProvider'); + } + return context; +} diff --git a/packages/jupyter/src/index.tsx b/packages/jupyter/src/index.tsx index 8dbd11c41..e98550d8e 100644 --- a/packages/jupyter/src/index.tsx +++ b/packages/jupyter/src/index.tsx @@ -6,5 +6,6 @@ const OUTPUT_RENDERERS = { export * from './BinderBadge'; export * from './providers'; +export * from './core'; export default OUTPUT_RENDERERS; diff --git a/packages/jupyter/src/jupyter.tsx b/packages/jupyter/src/jupyter.tsx index 2a6c1302c..f72311061 100644 --- a/packages/jupyter/src/jupyter.tsx +++ b/packages/jupyter/src/jupyter.tsx @@ -5,10 +5,10 @@ import type { MinifiedOutput } from 'nbtx'; import { convertToIOutputs } from 'nbtx'; import { fetchAndEncodeOutputImages } from './convertImages'; import type { ThebeCore } from 'thebe-core'; -import { useThebeCore } from 'thebe-react'; import { useCellRef, useCellRefRegistry, useNotebookCellExecution } from './providers'; import { SourceFileKind } from 'myst-common'; import { useXRefState } from '@myst-theme/providers'; +import { useThebeCoreBundle } from './core'; function ActiveOutputRenderer({ id, data }: { id: string; data: IOutput[] }) { const ref = useCellRef(id); @@ -54,7 +54,7 @@ function PassiveOutputRenderer({ const MemoPassiveOutputRenderer = React.memo(PassiveOutputRenderer); export const JupyterOutputs = ({ id, outputs }: { id: string; outputs: MinifiedOutput[] }) => { - const { core, load } = useThebeCore(); + const { core, load } = useThebeCoreBundle(); const { inCrossRef } = useXRefState(); const { data, error } = useFetchAnyTruncatedContent(outputs); const [loaded, setLoaded] = useState(false); diff --git a/packages/jupyter/src/providers.tsx b/packages/jupyter/src/providers.tsx index b20ca9ce5..a0e2d0677 100644 --- a/packages/jupyter/src/providers.tsx +++ b/packages/jupyter/src/providers.tsx @@ -4,17 +4,19 @@ import React, { useContext, useEffect, useRef, useState } from 'react'; import type { Config, CoreOptions, + IRenderMimeRegistry, IThebeCell, IThebeCellExecuteReturn, RepoProvider, ThebeCore, ThebeNotebook, } from 'thebe-core'; -import type { IThebeNotebookError, NotebookExecuteOptions } from 'thebe-react'; -import { useNotebookBase, useThebeConfig, useThebeCore, ThebeServerProvider } from 'thebe-react'; +import { IThebeNotebookError, NotebookExecuteOptions, useRenderMimeRegistry } from 'thebe-react'; +import { useNotebookBase, useThebeConfig, ThebeServerProvider } from 'thebe-react'; import type { Root } from 'mdast'; import type { Thebe, ThebeServerOptions, ThebeLocalOptions } from 'myst-frontmatter'; import { useComputeOptions } from '@myst-theme/providers'; +import { useThebeCoreBundle } from './core'; function getThebeOptions(): CoreOptions { const { thebe, binderUrl } = useComputeOptions(); @@ -66,8 +68,9 @@ function getThebeOptions(): CoreOptions { export function ConfiguredThebeServerProvider({ children }: React.PropsWithChildren) { const thebe = getThebeOptions(); + const { core } = useThebeCoreBundle(); return ( - + {children} ); @@ -86,8 +89,8 @@ export function notebookFromMdast( config: Config, mdast: GenericParent, idkMap: Record, + rendermime: IRenderMimeRegistry, ) { - const rendermime = undefined; // share rendermime beyond notebook scope? const notebook = new core.ThebeNotebook(mdast.key, config, rendermime); // no metadata included in mdast yet @@ -163,8 +166,9 @@ export function NotebookProvider({ // so at some point this gets the whole site config and can // be use to lookup notebooks and recover ThebeNotebooks that // can be used to execute notebook pages or blocks in articles - const { core } = useThebeCore(); + const { core } = useThebeCoreBundle(); const { config } = useThebeConfig(); + const rendermime = useRenderMimeRegistry(); const { ready, @@ -188,7 +192,13 @@ export function NotebookProvider({ registry.current = {}; idkMap.current = {}; if (page.kind === SourceFileKind.Notebook) { - const nb = notebookFromMdast(core, config, page.mdast as GenericParent, idkMap.current); + const nb = notebookFromMdast( + core, + config, + page.mdast as GenericParent, + idkMap.current, + rendermime, + ); setNotebook(nb); } else { // TODO will need do article relative notebook loading as appropriate once that is supported diff --git a/packages/site/package.json b/packages/site/package.json index 1d6053874..b36ae7f3a 100644 --- a/packages/site/package.json +++ b/packages/site/package.json @@ -29,7 +29,7 @@ "nbtx": "^0.2.3", "node-cache": "^5.1.2", "node-fetch": "^2.6.7", - "thebe-react": "^0.0.7", + "thebe-react": "^0.2.2", "unist-util-select": "^4.0.1" }, "peerDependencies": { diff --git a/packages/site/src/components/EnableCompute.tsx b/packages/site/src/components/EnableCompute.tsx index b8f90e03e..256f2f2d6 100644 --- a/packages/site/src/components/EnableCompute.tsx +++ b/packages/site/src/components/EnableCompute.tsx @@ -1,6 +1,6 @@ -import { useThebeCore, useThebeServer, useThebeSession } from 'thebe-react'; +import { useThebeServer, useThebeSession } from 'thebe-react'; import PowerIcon from '@heroicons/react/24/outline/PowerIcon'; -import { useHasNotebookProvider } from '@myst-theme/jupyter'; +import { useHasNotebookProvider, useThebeCoreBundle } from '@myst-theme/jupyter'; import { useNavigation } from '@remix-run/react'; import { useEffect, useState } from 'react'; @@ -8,7 +8,7 @@ export function EnableCompute({ canCompute, children, }: React.PropsWithChildren<{ canCompute: boolean }>) { - const { load, loading, core } = useThebeCore(); + const { load, loading, core } = useThebeCoreBundle(); const { connect, connecting, ready: serverReady, error: serverError } = useThebeServer(); const { start, diff --git a/packages/site/src/pages/Root.tsx b/packages/site/src/pages/Root.tsx index 01a252185..01d4819b4 100644 --- a/packages/site/src/pages/Root.tsx +++ b/packages/site/src/pages/Root.tsx @@ -16,8 +16,8 @@ import { ContentReload, renderers } from '../components'; import { Analytics } from '../seo'; import { Error404 } from './Error404'; import classNames from 'classnames'; -import { ThebeCoreProvider } from 'thebe-react'; -import { ConfiguredThebeServerProvider } from '@myst-theme/jupyter'; +import { ConfiguredThebeServerProvider, ThebeCoreBundleProvider } from '@myst-theme/jupyter'; +import { ThebeRenderMimeRegistryProvider } from 'thebe-react'; export function Document({ children, @@ -63,11 +63,13 @@ export function Document({ - - - {children} - - + + + + {children} + + + From 3d0213d5ad87d247d01759ef48843f0368d60c30 Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Tue, 13 Jun 2023 11:36:00 +0100 Subject: [PATCH 02/11] async loading thebe to page using tags --- bin/copy-thebe-assets.cjs | 53 ++++++++++++ packages/jupyter/src/core.tsx | 84 ------------------- packages/jupyter/src/index.tsx | 1 - packages/jupyter/src/jupyter.tsx | 4 +- packages/jupyter/src/providers.tsx | 16 ++-- .../site/src/components/EnableCompute.tsx | 6 +- packages/site/src/pages/Article.tsx | 42 +++++----- packages/site/src/pages/Root.tsx | 16 ++-- test/index.js | 26 ++++++ themes/book/.gitignore | 1 + themes/book/package.json | 5 +- 11 files changed, 127 insertions(+), 127 deletions(-) create mode 100644 bin/copy-thebe-assets.cjs delete mode 100644 packages/jupyter/src/core.tsx create mode 100755 test/index.js diff --git a/bin/copy-thebe-assets.cjs b/bin/copy-thebe-assets.cjs new file mode 100644 index 000000000..59b2a2d50 --- /dev/null +++ b/bin/copy-thebe-assets.cjs @@ -0,0 +1,53 @@ +const fs = require('fs'); +const path = require('path'); + +if (process.argv.length < 3) { + console.error('Usage: node copyThebeAssets.cjs '); + process.exit(1); +} + +const outputDir = process.argv[2]; + +if (!fs.existsSync(outputDir)) { + console.log(`Output directory ${outputDir} does not exist, creating...`); + fs.mkdirSync(outputDir, { recursive: true }); +} + +console.log('Copying thebe assets...'); + +try { + require.resolve('thebe-core'); +} catch (err) { + console.error('thebe-core not found, please run `npm install` in the theme directory.'); + process.exit(1); +} + +try { + require.resolve('thebe-lite'); +} catch (err) { + console.error('thebe-lite not found, please run `npm install` in the theme directory.'); + process.exit(1); +} + +const pathToThebeCore = path.resolve( + path.join(path.dirname(require.resolve('thebe-core')), '..', 'lib', 'thebe-core.min.js'), +); + +const assets = [ + pathToThebeCore, + path.join(path.dirname(pathToThebeCore), 'thebe-core.css'), + require.resolve('thebe-lite'), +]; + +console.log('Found thebe assets:'); +console.log(assets); +console.log(`Copying assets to ${outputDir} now...`); + +for (const asset of assets) { + const basename = path.basename(asset); + const dest = path.join(outputDir, basename); + fs.copyFileSync(asset, dest); + console.log(`Copied ${basename} to ${dest}`); +} + +console.log('Done.'); diff --git a/packages/jupyter/src/core.tsx b/packages/jupyter/src/core.tsx deleted file mode 100644 index be780816b..000000000 --- a/packages/jupyter/src/core.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import React, { useEffect, useState } from 'react'; - -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -export type ThebeCore = typeof import('thebe-core'); - -// Don't know how to get rid of the undefined here in the case of an async provider -const ThebeCoreContext = React.createContext< - { core?: ThebeCore; error?: string; loading: boolean; load: () => void } | undefined ->(undefined); - -export function ThebeCoreBundleProvider({ - start, - loadThebeLite, - children, -}: React.PropsWithChildren<{ start?: boolean; loadThebeLite: boolean }>) { - const [startLoad, setStartLoad] = useState(start); - const [loading, setLoading] = useState(false); - const [core, setCore] = useState(); - const [error, setError] = useState(); - - useEffect(() => { - // if already loaded do nothing - if (!startLoad || core) return; - setLoading(true); - console.debug('importing thebe-core...'); - - if (typeof document !== 'undefined' && typeof window !== 'undefined') { - try { - if (!window.thebeCore) { - const script = document.createElement('script'); - script.setAttribute('src', '/thebe-core.min.js'); - script.setAttribute('async', 'true'); - script.setAttribute('type', 'text/javascript'); - document.head.appendChild(script); - - const styles = document.createElement('link'); - styles.setAttribute('rel', 'stylesheet'); - styles.setAttribute('href', '/thebe-core.css'); - document.head.appendChild(styles); - } - - if (loadThebeLite) { - const liteScript = document.createElement('script'); - liteScript.setAttribute('src', '/thebe-lite.min.js'); - liteScript.setAttribute('async', 'true'); - liteScript.setAttribute('type', 'text/javascript'); - document.head.appendChild(liteScript); - } - - let attempts = 0; - const timer = setInterval(() => { - if (window.thebeCore && (window.thebeLite || !loadThebeLite)) { - setLoading(false); - setCore((window as any).thebeCore?.module); - clearInterval(timer); - } - if (attempts > 10) { - setError('thebe-core load failed'); - setLoading(false); - clearInterval(timer); - } - attempts += 1; - }, 300); - } catch (err: any) { - setError(err); - setLoading(false); - } - } - }, [startLoad]); - - return ( - setStartLoad(true) }}> - <>{children} - - ); -} - -export function useThebeCoreBundle() { - const context = React.useContext(ThebeCoreContext); - if (context === undefined) { - throw new Error('useThebeCoreBundle must be used inside a ThebeCoreBundleProvider'); - } - return context; -} diff --git a/packages/jupyter/src/index.tsx b/packages/jupyter/src/index.tsx index e98550d8e..8dbd11c41 100644 --- a/packages/jupyter/src/index.tsx +++ b/packages/jupyter/src/index.tsx @@ -6,6 +6,5 @@ const OUTPUT_RENDERERS = { export * from './BinderBadge'; export * from './providers'; -export * from './core'; export default OUTPUT_RENDERERS; diff --git a/packages/jupyter/src/jupyter.tsx b/packages/jupyter/src/jupyter.tsx index f72311061..a6b60c804 100644 --- a/packages/jupyter/src/jupyter.tsx +++ b/packages/jupyter/src/jupyter.tsx @@ -8,7 +8,7 @@ import type { ThebeCore } from 'thebe-core'; import { useCellRef, useCellRefRegistry, useNotebookCellExecution } from './providers'; import { SourceFileKind } from 'myst-common'; import { useXRefState } from '@myst-theme/providers'; -import { useThebeCoreBundle } from './core'; +import { useThebeLoader } from 'thebe-react'; function ActiveOutputRenderer({ id, data }: { id: string; data: IOutput[] }) { const ref = useCellRef(id); @@ -54,7 +54,7 @@ function PassiveOutputRenderer({ const MemoPassiveOutputRenderer = React.memo(PassiveOutputRenderer); export const JupyterOutputs = ({ id, outputs }: { id: string; outputs: MinifiedOutput[] }) => { - const { core, load } = useThebeCoreBundle(); + const { core, load } = useThebeLoader(); const { inCrossRef } = useXRefState(); const { data, error } = useFetchAnyTruncatedContent(outputs); const [loaded, setLoaded] = useState(false); diff --git a/packages/jupyter/src/providers.tsx b/packages/jupyter/src/providers.tsx index a0e2d0677..a9820168e 100644 --- a/packages/jupyter/src/providers.tsx +++ b/packages/jupyter/src/providers.tsx @@ -11,12 +11,16 @@ import type { ThebeCore, ThebeNotebook, } from 'thebe-core'; -import { IThebeNotebookError, NotebookExecuteOptions, useRenderMimeRegistry } from 'thebe-react'; -import { useNotebookBase, useThebeConfig, ThebeServerProvider } from 'thebe-react'; +import { IThebeNotebookError, NotebookExecuteOptions, useThebeLoader } from 'thebe-react'; +import { + useRenderMimeRegistry, + useNotebookBase, + useThebeConfig, + ThebeServerProvider, +} from 'thebe-react'; import type { Root } from 'mdast'; import type { Thebe, ThebeServerOptions, ThebeLocalOptions } from 'myst-frontmatter'; import { useComputeOptions } from '@myst-theme/providers'; -import { useThebeCoreBundle } from './core'; function getThebeOptions(): CoreOptions { const { thebe, binderUrl } = useComputeOptions(); @@ -68,9 +72,9 @@ function getThebeOptions(): CoreOptions { export function ConfiguredThebeServerProvider({ children }: React.PropsWithChildren) { const thebe = getThebeOptions(); - const { core } = useThebeCoreBundle(); + return ( - + {children} ); @@ -166,7 +170,7 @@ export function NotebookProvider({ // so at some point this gets the whole site config and can // be use to lookup notebooks and recover ThebeNotebooks that // can be used to execute notebook pages or blocks in articles - const { core } = useThebeCoreBundle(); + const { core } = useThebeLoader(); const { config } = useThebeConfig(); const rendermime = useRenderMimeRegistry(); diff --git a/packages/site/src/components/EnableCompute.tsx b/packages/site/src/components/EnableCompute.tsx index 256f2f2d6..f8503ca71 100644 --- a/packages/site/src/components/EnableCompute.tsx +++ b/packages/site/src/components/EnableCompute.tsx @@ -1,6 +1,6 @@ -import { useThebeServer, useThebeSession } from 'thebe-react'; +import { useThebeLoader, useThebeServer, useThebeSession } from 'thebe-react'; import PowerIcon from '@heroicons/react/24/outline/PowerIcon'; -import { useHasNotebookProvider, useThebeCoreBundle } from '@myst-theme/jupyter'; +import { useHasNotebookProvider } from '@myst-theme/jupyter'; import { useNavigation } from '@remix-run/react'; import { useEffect, useState } from 'react'; @@ -8,7 +8,7 @@ export function EnableCompute({ canCompute, children, }: React.PropsWithChildren<{ canCompute: boolean }>) { - const { load, loading, core } = useThebeCoreBundle(); + const { load, loading, core } = useThebeLoader(); const { connect, connecting, ready: serverReady, error: serverError } = useThebeServer(); const { start, diff --git a/packages/site/src/pages/Article.tsx b/packages/site/src/pages/Article.tsx index d38c110f2..bd20e70a3 100644 --- a/packages/site/src/pages/Article.tsx +++ b/packages/site/src/pages/Article.tsx @@ -5,7 +5,7 @@ import { Bibliography, ContentBlocks, FooterLinksBlock } from '../components'; import { ErrorDocumentNotFound } from './ErrorDocumentNotFound'; import { ErrorProjectNotFound } from './ErrorProjectNotFound'; import type { PageLoader } from '../types'; -import { ThebeSessionProvider } from 'thebe-react'; +import { ThebeRenderMimeRegistryProvider, ThebeSessionProvider } from 'thebe-react'; import type { GenericParent } from 'myst-common'; import { SourceFileKind } from 'myst-common'; import { EnableCompute } from '../components/EnableCompute'; @@ -23,25 +23,27 @@ export const ArticlePage = React.memo(function ({ article }: { article: PageLoad references={{ ...article.references, article: article.mdast }} frontmatter={article.frontmatter} > - - {!hide_title_block && ( - - )} - -
-
- {binder && } - {canCompute && isJupyter && ( - - - - )} -
- - - {!hide_footer_links && } -
-
+ + + {!hide_title_block && ( + + )} + +
+
+ {binder && } + {canCompute && isJupyter && ( + + + + )} +
+ + + {!hide_footer_links && } +
+
+
); }); diff --git a/packages/site/src/pages/Root.tsx b/packages/site/src/pages/Root.tsx index 01d4819b4..25c6ce842 100644 --- a/packages/site/src/pages/Root.tsx +++ b/packages/site/src/pages/Root.tsx @@ -16,8 +16,8 @@ import { ContentReload, renderers } from '../components'; import { Analytics } from '../seo'; import { Error404 } from './Error404'; import classNames from 'classnames'; -import { ConfiguredThebeServerProvider, ThebeCoreBundleProvider } from '@myst-theme/jupyter'; -import { ThebeRenderMimeRegistryProvider } from 'thebe-react'; +import { ConfiguredThebeServerProvider } from '@myst-theme/jupyter'; +import { ThebeBundleLoaderProvider } from 'thebe-react'; export function Document({ children, @@ -63,13 +63,11 @@ export function Document({ - - - - {children} - - - + + + {children} + + diff --git a/test/index.js b/test/index.js new file mode 100755 index 000000000..1f0736502 --- /dev/null +++ b/test/index.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PassiveCellRenderer = exports.ThebeNonExecutableCell = exports.ThebeCell = exports.ThebeNotebook = exports.ThebeSession = exports.ThebeServer = void 0; +const tslib_1 = require("tslib"); +var server_1 = require("./server"); +Object.defineProperty(exports, "ThebeServer", { enumerable: true, get: function () { return tslib_1.__importDefault(server_1).default; } }); +var session_1 = require("./session"); +Object.defineProperty(exports, "ThebeSession", { enumerable: true, get: function () { return tslib_1.__importDefault(session_1).default; } }); +var notebook_1 = require("./notebook"); +Object.defineProperty(exports, "ThebeNotebook", { enumerable: true, get: function () { return tslib_1.__importDefault(notebook_1).default; } }); +var cell_1 = require("./cell"); +Object.defineProperty(exports, "ThebeCell", { enumerable: true, get: function () { return tslib_1.__importDefault(cell_1).default; } }); +var cell_noexec_1 = require("./cell_noexec"); +Object.defineProperty(exports, "ThebeNonExecutableCell", { enumerable: true, get: function () { return tslib_1.__importDefault(cell_noexec_1).default; } }); +var passive_1 = require("./passive"); +Object.defineProperty(exports, "PassiveCellRenderer", { enumerable: true, get: function () { return tslib_1.__importDefault(passive_1).default; } }); +tslib_1.__exportStar(require("./options"), exports); +tslib_1.__exportStar(require("./events"), exports); +tslib_1.__exportStar(require("./thebe/api"), exports); +tslib_1.__exportStar(require("./thebe/entrypoint"), exports); +tslib_1.__exportStar(require("./utils"), exports); +tslib_1.__exportStar(require("./manager"), exports); +tslib_1.__exportStar(require("./rendermime"), exports); +tslib_1.__exportStar(require("./types"), exports); +tslib_1.__exportStar(require("./config"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/themes/book/.gitignore b/themes/book/.gitignore index ed8f0fc38..d4d6bfd54 100644 --- a/themes/book/.gitignore +++ b/themes/book/.gitignore @@ -9,6 +9,7 @@ node_modules yalc.lock /public/build +/public/thebe-* /api/* /build/* diff --git a/themes/book/package.json b/themes/book/package.json index d033eeeae..74f540a92 100644 --- a/themes/book/package.json +++ b/themes/book/package.json @@ -8,9 +8,10 @@ "dev:copy": "cp remix.config.dev.js remix.config.js", "prod:copy": "cp remix.config.prod.js remix.config.js", "clean": "rimraf public/build build api", - "prod:build": "npm run prod:copy && npm run build:css && remix build", + "build:thebe": "node ../../bin/copy-thebe-assets.cjs ./public", + "prod:build": "npm run prod:copy && npm run build:thebe && npm run build:css && remix build", "dev:css": "tailwindcss -w -i ./styles/app.css -o app/styles/app.css", - "dev": "npm run dev:copy && concurrently \"npm run dev:css\" \"remix dev\"", + "dev": "npm run dev:copy && npm run build:thebe && concurrently \"npm run dev:css\" \"remix dev\"", "start": "npm run build:css && remix dev" }, "dependencies": { From 3cebdcb5fb23d0c8905dc2cf24d01012f4705094 Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Tue, 13 Jun 2023 11:56:47 +0100 Subject: [PATCH 03/11] =?UTF-8?q?=F0=9F=A7=B9=20clear=20outputs=20on=20Run?= =?UTF-8?q?All?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/site/src/components/ComputeControls.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/site/src/components/ComputeControls.tsx b/packages/site/src/components/ComputeControls.tsx index 68cc6e778..e91fc9784 100644 --- a/packages/site/src/components/ComputeControls.tsx +++ b/packages/site/src/components/ComputeControls.tsx @@ -99,7 +99,14 @@ export function NotebookRunAll() { return (
- + { + clear(); + return executeAll(options); + }} + />