8 |
9 |
10 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/config/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from '@rollup/plugin-babel';
2 | import resolve from '@rollup/plugin-node-resolve';
3 |
4 | export default {
5 | input: 'src/main.js',
6 | output: {
7 | format: 'umd',
8 | exports: 'named',
9 | file: 'dist/wolfram-notebook-embedder.js',
10 | name: 'WolframNotebookEmbedder',
11 | sourcemap: true,
12 | strict: true
13 | },
14 | plugins: [
15 | babel({
16 | sourceMap: true,
17 | exclude: 'node_modules/**',
18 | babelrc: false,
19 | comments: false,
20 | presets: [
21 | ['@babel/env', {
22 | modules: false,
23 | loose: true,
24 | targets: {
25 | browsers: ['last 2 versions']
26 | }
27 | }]
28 | ]
29 | }),
30 | resolve()
31 | ]
32 | };
33 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 0.3
2 |
3 | * Embedding of external notebooks at a given URL (`{url: ...}`) or with a given `Notebook` expression (`{expr: ...}`)
4 | * New option `showBorder` to control whether to show a border around the embedded notebook
5 | * Officially dropped support for IE11
6 | * Add a default export, but encourage named imports
7 |
8 | ## 0.2.2
9 |
10 | * Pass through extra data from the initial server call to the cloud JS code, for better forward-compatibility
11 |
12 | ## 0.2.1
13 |
14 | * Fix issues with `useShadowDOM` when there are existing notebook-related style definitions on the page
15 |
16 | ## 0.2.0
17 |
18 | * New option `useShadowDOM` for better encapsulation of styling (still experimental and off by default)
19 |
20 | ## 0.1.5
21 |
22 | * First official release
23 | * Change the default for `allowInteract` from `false` to `true`
24 | * Improve documentation
25 | * Add website, built with [Docusaurus](https://docusaurus.io)
26 |
27 | ## 0.1.4
28 |
29 | * First proper release
30 |
31 | ## 0.1.0
32 |
33 | * Initial release
34 |
--------------------------------------------------------------------------------
/examples/url.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Notebook URL example
5 |
6 |
7 |
8 |
Notebook expression example
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2018 Wolfram Research Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 |
--------------------------------------------------------------------------------
/examples/expr.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Notebook expression example
5 |
11 |
12 |
13 |
14 |
37 | );
38 | }
39 | }
40 |
41 | module.exports = Users;
42 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wolfram-notebook-embedder",
3 | "version": "0.3.0",
4 | "description": "Library to embed Wolfram Cloud notebooks on websites.",
5 | "main": "dist/wolfram-notebook-embedder.js",
6 | "keywords": [
7 | "wolfram",
8 | "cloud",
9 | "notebook",
10 | "embedding"
11 | ],
12 | "license": "MIT",
13 | "files": [
14 | "dist/",
15 | "LICENSE",
16 | "README.md"
17 | ],
18 | "repository": {
19 | "type": "git",
20 | "url": "https://github.com/WolframResearch/wolfram-notebook-embedder.git"
21 | },
22 | "scripts": {
23 | "prepublishOnly": "npm-run-all build",
24 | "build": "npm-run-all transpile minify",
25 | "transpile": "rollup -c config/rollup.config.js",
26 | "copy-dist-to-examples": "cp -r ./dist ./examples",
27 | "serve-examples": "serve examples",
28 | "minify": "uglifyjs dist/wolfram-notebook-embedder.js --compress --mangle --output dist/wolfram-notebook-embedder.min.js",
29 | "run-examples": "npm-run-all build copy-dist-to-examples serve-examples"
30 | },
31 | "devDependencies": {
32 | "@babel/core": "^7.15.5",
33 | "@babel/preset-env": "^7.15.6",
34 | "@rollup/plugin-babel": "^5.3.0",
35 | "@rollup/plugin-node-resolve": "^13.0.5",
36 | "npm-run-all": "^4.1.5",
37 | "rollup": "^2.58.0",
38 | "serve": "^12.0.1",
39 | "uglify-js": "^3.14.2"
40 | },
41 | "dependencies": {}
42 | }
43 |
--------------------------------------------------------------------------------
/docs/Troubleshooting.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: Troubleshooting
3 | title: Troubleshooting
4 | ---
5 |
6 | ## Loading
7 |
8 | **The embedded notebook does not load.**
9 |
10 | Please double-check that the embedded cloud notebook is *public*, e.g. by opening its URL in an incognito window of your browser (where you are not logged in to the Wolfram Cloud). In the Wolfram Language, you can determine permissions of a cloud object using
11 |
12 | ```wl
13 | CloudObjectInformation[CloudObject["..."], "Permissions"]
14 | ```
15 |
16 | and you can make a cloud object public by evaluating the following:
17 |
18 | ```wl
19 | SetPermissions[CloudObject["..."], All -> {"Read", "Interact"}]
20 | ```
21 |
22 | ## Styling
23 |
24 | **As soon as I embed a notebook, some styling on my page (outside the notebook) changes.**
25 |
26 | This might be a bug in our (notebook) CSS. We try to isolate CSS selectors as much as possible, but there might still be cases where styling "leaks out" of the notebook. Please file an issue with reproducible steps.
27 |
28 | **The styling of the notebook seems wrong.**
29 |
30 | This could be because your CSS definitions "leak into" the notebook. Since the notebook is just another DOM node on your page, it inherits any global CSS. Try to make your CSS selectors more specific so they do not affect the notebook container node. If isolating styles is a problem, you can always fall back to embedding your cloud notebook using an iframe, e.g.:
31 |
32 | ```html
33 |
34 | ```
35 |
36 | If you think there is an issue on the notebook side, please file an issue.
37 |
--------------------------------------------------------------------------------
/examples/manipulate.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Manipulate example
4 |
9 |
10 |
11 |
12 |
Manipulate example
13 |
14 | Enter the URL of a cloud object:
15 |
16 |
17 |
18 |
19 | If the notebook's last cell contains a Manipulate with a variable x, this will reset it to 0:
20 |
21 |
22 |
23 |
24 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Wolfram®
2 |
3 | Thank you for taking the time to contribute to the [Wolfram Research](https://github.com/wolframresearch) repos on GitHub.
4 |
5 | ## Licensing of Contributions
6 |
7 | By contributing to Wolfram, you agree and affirm that:
8 |
9 | > Wolfram may release your contribution under the terms of the [MIT license](https://opensource.org/licenses/MIT); and
10 |
11 | > You have read and agreed to the [Developer Certificate of Origin](http://developercertificate.org/), version 1.1 or later.
12 |
13 | Please see [LICENSE](LICENSE) for licensing conditions pertaining
14 | to individual repositories.
15 |
16 |
17 | ## Bug reports
18 |
19 | ### Security Bugs
20 |
21 | Please **DO NOT** file a public issue regarding a security issue.
22 | Rather, send your report privately to security@wolfram.com. Security
23 | reports are appreciated and we will credit you for it. We do not offer
24 | a security bounty, but the forecast in your neighborhood will be cloudy
25 | with a chance of Wolfram schwag!
26 |
27 | ### General Bugs
28 |
29 | Please use the repository issues page to submit general bug issues.
30 |
31 | Please do not duplicate issues.
32 |
33 | Please do send a complete and well-written report to us. Note: **the
34 | thoroughness of your report will positively correlate to our willingness
35 | and ability to address it**.
36 |
37 | When reporting issues, always include:
38 |
39 | * Your version of *Mathematica*® or the Wolfram Language™.
40 | * Your version of the Wolfram Cloud™.
41 | * Your operating system.
42 | * Your web browser, including version number.
43 |
--------------------------------------------------------------------------------
/docs/ContributingAgreement.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: ContributingAgreement
3 | title: Contributing to Wolfram®
4 | ---
5 |
6 | Thank you for taking the time to contribute to the [Wolfram Research](https://github.com/wolframresearch) repos on GitHub.
7 |
8 | ## Licensing of Contributions
9 |
10 | By contributing to Wolfram, you agree and affirm that:
11 |
12 | > Wolfram may release your contribution under the terms of the [MIT license](https://opensource.org/licenses/MIT); and
13 |
14 | > You have read and agreed to the [Developer Certificate of Origin](http://developercertificate.org/), version 1.1 or later.
15 |
16 | Please see [LICENSE](../LICENSE) for licensing conditions pertaining
17 | to individual repositories.
18 |
19 |
20 | ## Bug reports
21 |
22 | ### Security Bugs
23 |
24 | Please **DO NOT** file a public issue regarding a security issue.
25 | Rather, send your report privately to security@wolfram.com. Security
26 | reports are appreciated and we will credit you for it. We do not offer
27 | a security bounty, but the forecast in your neighborhood will be cloudy
28 | with a chance of Wolfram schwag!
29 |
30 | ### General Bugs
31 |
32 | Please use the repository issues page to submit general bug issues.
33 |
34 | Please do not duplicate issues.
35 |
36 | Please do send a complete and well-written report to us. Note: **the
37 | thoroughness of your report will positively correlate to our willingness
38 | and ability to address it**.
39 |
40 | When reporting issues, always include:
41 |
42 | * Your version of *Mathematica*® or the Wolfram Language™.
43 | * Your version of the Wolfram Cloud™.
44 | * Your operating system.
45 | * Your web browser, including version number.
46 |
--------------------------------------------------------------------------------
/website/i18n/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "_comment": "This file is auto-generated by write-translations.js",
3 | "localized-strings": {
4 | "next": "Next",
5 | "previous": "Previous",
6 | "tagline": "A library to embed Wolfram Cloud notebooks on websites",
7 | "docs": {
8 | "ContributingAgreement": {
9 | "title": "Contributing to Wolfram®"
10 | },
11 | "Development": {
12 | "title": "Development"
13 | },
14 | "GettingStarted": {
15 | "title": "Getting Started"
16 | },
17 | "LibraryInterface": {
18 | "title": "Library Interface"
19 | },
20 | "NotebookAPI-Internal": {
21 | "title": "NotebookAPI-Internal"
22 | },
23 | "NotebookAPI-Unsupported": {
24 | "title": "NotebookAPI-Unsupported"
25 | },
26 | "NotebookAPI": {
27 | "title": "Notebook API"
28 | },
29 | "NotebookLoadingPhases": {
30 | "title": "Notebook Loading Phases"
31 | },
32 | "ServerSideRendering": {
33 | "title": "Server-Side Rendering"
34 | },
35 | "Troubleshooting": {
36 | "title": "Troubleshooting"
37 | }
38 | },
39 | "links": {
40 | "Docs": "Docs",
41 | "Examples": "Examples"
42 | },
43 | "categories": {
44 | "Getting Started": "Getting Started",
45 | "API Documentation": "API Documentation",
46 | "More Information": "More Information",
47 | "Contributing": "Contributing"
48 | }
49 | },
50 | "pages-strings": {
51 | "Help Translate|recruit community translators for your project": "Help Translate",
52 | "Edit this Doc|recruitment message asking to edit the doc source": "Edit",
53 | "Translate this Doc|recruitment message asking to translate the docs": "Translate"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/docs/Development.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: Development
3 | title: Development
4 | ---
5 |
6 | Please read the [Contributing Agreement](./ContributingAgreement.md) first. By contributing to this repository, you agree to the licensing terms herein.
7 |
8 | To install all required dependencies for development of this library, run:
9 |
10 | yarn install
11 |
12 | ## Examples
13 |
14 | To manually test embedded notebooks, run
15 |
16 | yarn run-examples
17 |
18 | and visit the resulting localhost URL (usually http://localhost:5000). On that page, you can enter the path of a notebook on your localhost cloud to embed it.
19 |
20 | ## Documentation
21 |
22 | The library's website is built using [Docusaurus](https://docusaurus.io). In the `website` directory, run
23 |
24 | yarn install
25 |
26 | to install all necessary dependencies, and then either
27 |
28 | yarn start
29 |
30 | to start a live-updating build process or
31 |
32 | yarn build
33 |
34 | to generate static HTML in `website/build`.
35 |
36 | ## Releasing a new version
37 |
38 | To release a new version, log in to npm using
39 |
40 | yarn login
41 |
42 | as an owner of the [wolfram-notebook-embedder](https://www.npmjs.com/package/wolfram-notebook-embedder) package.
43 |
44 | Check out the `master` branch and make sure there are no uncommitted changes:
45 |
46 | git checkout master
47 |
48 | Then run
49 |
50 | yarn publish
51 |
52 | which asks for the new package version, updates `package.json` accordingly, runs a build, creates a Git tag, and publishes the package.
53 |
54 | If publishing fails due to missing authentication even though you have run `yarn login`, you might have to delete `~/.npmrc` and log in again (see [this Yarn issue](https://github.com/yarnpkg/yarn/issues/4709)).
55 |
56 | If [two-factor authentication](https://docs.npmjs.com/configuring-two-factor-authentication) is enabled for your account, you will be asked for a one-time password during the publishing process.
57 |
--------------------------------------------------------------------------------
/examples/ssr.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Server-side rendering example
5 |
10 |
11 |
12 |
13 |
Server-side rendering example
14 |
15 |
16 | Enter the URL of a cloud object:
17 |
18 |
19 |
20 |
21 | (this would usually happen in your server-side code)
22 |
23 |
24 |
25 | (this always happens in the JavaScript code running on the client)
26 |
27 |
28 |
29 | Render state:
30 |
31 |
32 |
33 |
34 |
35 |
36 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/docs/GettingStarted.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: GettingStarted
3 | title: Getting Started
4 | ---
5 |
6 | 1. Create a notebook in the [Wolfram Cloud](https://www.wolframcloud.com/) and make it public.
7 | * In the cloud UI, use the New Notebook button and then use the Share dialog to make it public.
8 | * From the [Wolfram Language](https://www.wolfram.com/language/), you could publish notebook content like so:
9 |
10 | ```wl
11 | CloudPublish[Manipulate[Plot[Sin[a x], {x, 0, 2 Pi}], {a, 1, 3}]]
12 | ```
13 | 2. Install this library in your JavaScript project using
14 |
15 | ```bash
16 | npm install wolfram-notebook-embedder
17 | ```
18 |
19 | so you can import it in JavaScript as
20 |
21 | ```js
22 | import * as WolframNotebookEmbedder from 'wolfram-notebook-embedder';
23 | ```
24 |
25 | or import it as a `
29 | ```
30 | 3. In your HTML, create a container where you want the notebook to be rendered (say ``) and add the following JavaScript code:
31 |
32 | ```js
33 | var embedding = WolframNotebookEmbedder.embed('url', document.getElementById('notebookContainer'));
34 | ```
35 |
36 | where `url` is the URL of your cloud object from step 1. More details about `embed` are described in the [library interface documentation](./LibraryInterface.md).
37 | 4. If you want to control the notebook from your JavaScript code, wait for the `embed` result (a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)) to resolve, and then use various [notebook API methods](./NotebookAPI.md):
38 |
39 | ```js
40 | embedding.then(function (nb) {
41 | // This will reset the DynamicModule variable x$$
42 | // in the first cell of the notebook.
43 | return nb.getCells().then(function (cells) {
44 | nb.setDynamicModuleVariable({
45 | cellId: cells[0].id,
46 | name: 'x$$',
47 | value: 0
48 | });
49 | });
50 | })
51 | ```
52 | 5. If you want to serve static HTML from your server so the notebook can be rendered before JavaScript code is loaded (which also helps with SEO), take a look at [server-side rendering](./ServerSideRendering.md).
53 | 6. If you run into any issues, take a look at the [troubleshooting guide](./Troubleshooting.md). If you think you found a bug, please report it.
54 |
--------------------------------------------------------------------------------
/website/static/img/icon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # wolfram-notebook-embedder
2 |
3 | A library to embed [Wolfram Cloud](https://www.wolframcloud.com/) notebooks on websites. It does *not* use an `