yourjs-box 1.4.0 → 1.5.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
@@ -52,6 +52,10 @@ If the editor already has code in it you are asked before it is replaced.
52
52
  console's settings and keyboard shortcuts.
53
53
  - The **⋯** button opens a menu with:
54
54
  - **Text size**, which is remembered for every console on the same site.
55
+ - **Open**, which loads a JavaScript file as the code that the console starts
56
+ with (its hidden blocks are hidden and Reset goes back to it).
57
+ - **Save**, which saves the code that already ran and the code in the editor
58
+ as a JavaScript file that can be opened later.
55
59
  - **Pop out into a window**, which moves the console into a separate window
56
60
  while the code keeps running in the page (so in window mode the code can
57
61
  still change the page). Close the window or click **Bring it back** to
@@ -71,6 +75,7 @@ If the editor already has code in it you are asked before it is replaced.
71
75
  | --- | --- |
72
76
  | `data-block-type` | `"classic"` (default) runs each block like a regular `<script>` so top-level declarations are shared between blocks. `"module"` runs each block like a `<script type="module">`. See below. |
73
77
  | `data-show-results` | `"false"` stops the value of the last expression in each block from being shown. |
78
+ | `data-imports-url` | Where packages imported by name are loaded from. See "Importing Packages" below. |
74
79
  | `data-libraries-url` | Where to load Vue, Ace, Prism and Acorn from. See "Self-Hosting the Libraries" below. |
75
80
  | `data-runner` | `"worker"` (default) runs the code in a Web Worker. `"window"` runs it directly in the page. See below. |
76
81
  | `data-divider-orient` | `"vertical"` puts the editor beside the output and `"horizontal"` puts it below. If not specified the editor is beside the output unless the console is narrower than 600px. |
@@ -92,10 +97,38 @@ one block can be used in the next, but `await` can only be used inside of
92
97
  `<script type="module">` instead:
93
98
 
94
99
  - Top-level `await` works.
95
- - `import` works (eg. `import {camelCase} from 'https://cdn.jsdelivr.net/npm/lodash-es/+esm';`).
100
+ - `import` works (eg. `import {camelCase} from 'lodash-es';`).
96
101
  - Top-level declarations stay inside of their block, just like in a module.
97
102
  Use `globalThis` to share values between blocks.
98
103
 
104
+ ### Importing Packages
105
+
106
+ npm packages can be imported by name. They are loaded from
107
+ [esm.sh](https://esm.sh/), which turns npm packages into modules that work in
108
+ the browser:
109
+
110
+ ```js
111
+ // In module blocks (data-block-type="module")
112
+ import _ from 'lodash';
113
+ import {format} from 'date-fns@4';
114
+
115
+ // In any block (including classic blocks), inside of async code
116
+ const {default: dayjs} = await import('dayjs');
117
+ ```
118
+
119
+ Relative paths (eg. `./utils.js`), URLs (eg. `https://example.com/x.js`) and
120
+ `node:` imports are left alone. Packages that need Node.js (eg. ones that use
121
+ `fs`) can't run in a browser.
122
+
123
+ To load packages from somewhere else set `data-imports-url` to a URL where
124
+ `{specifier}` is replaced with what was imported (eg. `lodash@4/fp`):
125
+
126
+ | Where | `data-imports-url` |
127
+ | --- | --- |
128
+ | esm.sh (the default) | `https://esm.sh/{specifier}` |
129
+ | jsDelivr | `https://cdn.jsdelivr.net/npm/{specifier}/+esm` |
130
+ | Turned off (only URLs and paths can be imported) | `""` |
131
+
99
132
  ### Self-Hosting the Libraries
100
133
 
101
134
  The console's interface uses [Vue](https://vuejs.org/),
@@ -174,7 +207,7 @@ functions). The options are:
174
207
  | `placement` | Where the console goes: `"fill"` (default) replaces the target's contents, `"append"` and `"prepend"` add it inside of the target, `"replace"` replaces the target itself and `"before"` and `"after"` add it next to the target. |
175
208
  | `height` | The CSS height of the console (a number is treated as pixels). Defaults to `"100%"` so the console fills its container. It is never less than 150px. |
176
209
  | `code` | The code that the console starts with. |
177
- | `runner`, `blockType`, `showResults`, `hidePrefix`, `dividerOrient`, `theme`, `librariesUrl` | The same as the `data-*` attributes above. |
210
+ | `runner`, `blockType`, `showResults`, `hidePrefix`, `dividerOrient`, `theme`, `importsUrl`, `librariesUrl` | The same as the `data-*` attributes above. |
178
211
 
179
212
  `YourJSBox.version` is the version of JS Box that was loaded.
180
213
 
@@ -209,6 +242,16 @@ Install the development dependencies by running `npm install`.
209
242
  based browser). An internet connection is needed because the console loads
210
243
  its libraries from CDNs. Pass part of a test's name to run only matching
211
244
  tests (eg. `node test/run.js module`).
245
+ - `npm run release -- <patch|minor|major>` releases a new version: it checks
246
+ that you're on an up to date, clean `main`, runs the tests, runs
247
+ `npm version`, pushes `main` and then the tag (separately, because GitHub
248
+ Pages doesn't always deploy when they are pushed together), publishes to npm
249
+ and, once npm lists the new version, purges jsDelivr's cache. Add
250
+ `--dry-run` to see what it would do or `--skip-tests` to skip the tests.
251
+ - `npm run purge-cdn` purges jsDelivr's cache so that URLs like
252
+ `yourjs-box@1` point to the latest version right away.
253
+ - In VS Code, **Terminal &rarr; Run Task&hellip;** has tasks for all of these
254
+ (eg. Build, Dev server, Test, Release&hellip; and Redeploy GitHub Pages).
212
255
  - `npm start` builds and then rebuilds whenever one of the files in `src/`
213
256
  changes (without serving anything).
214
257
 
@@ -224,7 +267,6 @@ test `dist/yourjs-box.js` or `dist/yourjs-box.min.js` instead of
224
267
  - Add `@timeout` annotation to the special comments that will allow you to input the amount of seconds to wait since the last call to a console logging function before automatically running the next comment segmented block.
225
268
  - Allow for TypeScript
226
269
  - Allow for CoffeeScript
227
- - Allow code to run in main window.
228
270
 
229
271
  ## License
230
272