yourjs-box 1.4.0 → 1.6.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Christopher West
3
+ Copyright (c) 2023-present Chris West
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -40,6 +40,7 @@ If the editor already has code in it you are asked before it is replaced.
40
40
 
41
41
  ### Toolbar
42
42
 
43
+ - The **⋯** button opens a menu (see below).
43
44
  - **Clear** removes everything from the console. Code can also call
44
45
  `console.clear()`.
45
46
  - The **layout** button switches between showing the editor beside or below
@@ -50,8 +51,20 @@ If the editor already has code in it you are asked before it is replaced.
50
51
  - **Run** runs the next block of code.
51
52
  - Clicking the **logo** opens the About window, which shows the version, this
52
53
  console's settings and keyboard shortcuts.
53
- - The **⋯** button opens a menu with:
54
+ - **History** (or <kbd>Alt</kbd>/<kbd>&#8997;</kbd>+<kbd>H</kbd>) lists the code
55
+ that was run so it can be put back into the editor. Like the browser's
56
+ console, pressing <kbd>&uarr;</kbd> when the cursor is at the very start of
57
+ the editor (with nothing selected) shows the previous code that was run and
58
+ <kbd>&darr;</kbd> at the very end goes forward again and eventually back to
59
+ the code that hasn't been run yet. After running code from the history, the
60
+ code that hasn't been run yet comes back. Hidden blocks aren't in the
61
+ history.
62
+ - The **&#8943;** menu has:
54
63
  - **Text size**, which is remembered for every console on the same site.
64
+ - **Open**, which loads a JavaScript file as the code that the console starts
65
+ with (its hidden blocks are hidden and Reset goes back to it).
66
+ - **Save**, which saves the code that already ran and the code in the editor
67
+ as a JavaScript file that can be opened later.
55
68
  - **Pop out into a window**, which moves the console into a separate window
56
69
  while the code keeps running in the page (so in window mode the code can
57
70
  still change the page). Close the window or click **Bring it back** to
@@ -65,12 +78,29 @@ If the editor already has code in it you are asked before it is replaced.
65
78
  (eg. an infinite loop) by starting a new worker.
66
79
  - **About JS Box**
67
80
 
81
+ ### Right-Clicking Values
82
+
83
+ Right-click any value in the output (including values inside of expanded
84
+ objects and arrays) for a menu with:
85
+
86
+ - **Copy as JSON** and **Save as JSON&hellip;**. Maps and Sets become arrays
87
+ and BigInts become strings. Circular references (an object inside of itself)
88
+ are left out and a message says how many were left out.
89
+ - **Store as global variable**, which stores the actual value (not a copy) as
90
+ `temp1`, `temp2`, etc. so that later code can use it (in window mode it is
91
+ stored on the page's `window`).
92
+ - **Copy property path** (for properties and array items), which copies the
93
+ path from the logged value like `people[0].name`.
94
+ - **Refresh** (for objects, arrays, etc.), which shows the value as it is now
95
+ if the code has changed it. Anything that was expanded stays expanded.
96
+
68
97
  ### Attributes
69
98
 
70
99
  | Attribute | Description |
71
100
  | --- | --- |
72
101
  | `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
102
  | `data-show-results` | `"false"` stops the value of the last expression in each block from being shown. |
103
+ | `data-imports-url` | Where packages imported by name are loaded from. See "Importing Packages" below. |
74
104
  | `data-libraries-url` | Where to load Vue, Ace, Prism and Acorn from. See "Self-Hosting the Libraries" below. |
75
105
  | `data-runner` | `"worker"` (default) runs the code in a Web Worker. `"window"` runs it directly in the page. See below. |
76
106
  | `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 +122,38 @@ one block can be used in the next, but `await` can only be used inside of
92
122
  `<script type="module">` instead:
93
123
 
94
124
  - Top-level `await` works.
95
- - `import` works (eg. `import {camelCase} from 'https://cdn.jsdelivr.net/npm/lodash-es/+esm';`).
125
+ - `import` works (eg. `import {camelCase} from 'lodash-es';`).
96
126
  - Top-level declarations stay inside of their block, just like in a module.
97
127
  Use `globalThis` to share values between blocks.
98
128
 
129
+ ### Importing Packages
130
+
131
+ npm packages can be imported by name. They are loaded from
132
+ [esm.sh](https://esm.sh/), which turns npm packages into modules that work in
133
+ the browser:
134
+
135
+ ```js
136
+ // In module blocks (data-block-type="module")
137
+ import _ from 'lodash';
138
+ import {format} from 'date-fns@4';
139
+
140
+ // In any block (including classic blocks), inside of async code
141
+ const {default: dayjs} = await import('dayjs');
142
+ ```
143
+
144
+ Relative paths (eg. `./utils.js`), URLs (eg. `https://example.com/x.js`) and
145
+ `node:` imports are left alone. Packages that need Node.js (eg. ones that use
146
+ `fs`) can't run in a browser.
147
+
148
+ To load packages from somewhere else set `data-imports-url` to a URL where
149
+ `{specifier}` is replaced with what was imported (eg. `lodash@4/fp`):
150
+
151
+ | Where | `data-imports-url` |
152
+ | --- | --- |
153
+ | esm.sh (the default) | `https://esm.sh/{specifier}` |
154
+ | jsDelivr | `https://cdn.jsdelivr.net/npm/{specifier}/+esm` |
155
+ | Turned off (only URLs and paths can be imported) | `""` |
156
+
99
157
  ### Self-Hosting the Libraries
100
158
 
101
159
  The console's interface uses [Vue](https://vuejs.org/),
@@ -174,7 +232,7 @@ functions). The options are:
174
232
  | `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
233
  | `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
234
  | `code` | The code that the console starts with. |
177
- | `runner`, `blockType`, `showResults`, `hidePrefix`, `dividerOrient`, `theme`, `librariesUrl` | The same as the `data-*` attributes above. |
235
+ | `runner`, `blockType`, `showResults`, `hidePrefix`, `dividerOrient`, `theme`, `importsUrl`, `librariesUrl` | The same as the `data-*` attributes above. |
178
236
 
179
237
  `YourJSBox.version` is the version of JS Box that was loaded.
180
238
 
@@ -201,14 +259,25 @@ between blocks.
201
259
  Install the development dependencies by running `npm install`.
202
260
 
203
261
  - `npm run dev` builds, rebuilds whenever one of the files in `src/` changes
204
- and serves the examples at http://localhost:3000/examples/ with the browser
205
- reloading automatically after each rebuild.
262
+ and serves the examples at http://localhost:3000/examples/ (opening them in
263
+ your default browser) with the browser reloading automatically after each
264
+ rebuild. Use `BROWSER=none npm run dev` to keep it from opening a browser.
206
265
  - `npm run build` builds the files in `dist/` once.
207
266
  - `npm test` builds and then runs the browser tests in `test/run.js` using your
208
267
  installed copy of Google Chrome (set `CHROME_PATH` to use another Chromium
209
268
  based browser). An internet connection is needed because the console loads
210
269
  its libraries from CDNs. Pass part of a test's name to run only matching
211
270
  tests (eg. `node test/run.js module`).
271
+ - `npm run release -- <patch|minor|major>` releases a new version: it checks
272
+ that you're on an up to date, clean `main`, runs the tests, runs
273
+ `npm version`, pushes `main` and then the tag (separately, because GitHub
274
+ Pages doesn't always deploy when they are pushed together), publishes to npm
275
+ and, once npm lists the new version, purges jsDelivr's cache. Add
276
+ `--dry-run` to see what it would do or `--skip-tests` to skip the tests.
277
+ - `npm run purge-cdn` purges jsDelivr's cache so that URLs like
278
+ `yourjs-box@1` point to the latest version right away.
279
+ - In VS Code, **Terminal &rarr; Run Task&hellip;** has tasks for all of these
280
+ (eg. Build, Dev server, Test, Release&hellip; and Redeploy GitHub Pages).
212
281
  - `npm start` builds and then rebuilds whenever one of the files in `src/`
213
282
  changes (without serving anything).
214
283
 
@@ -224,7 +293,6 @@ test `dist/yourjs-box.js` or `dist/yourjs-box.min.js` instead of
224
293
  - 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
294
  - Allow for TypeScript
226
295
  - Allow for CoffeeScript
227
- - Allow code to run in main window.
228
296
 
229
297
  ## License
230
298
 
@@ -232,4 +300,4 @@ Released under the [MIT License](LICENSE). You're free to use, modify and
232
300
  distribute it, including in commercial projects, as long as the copyright and
233
301
  license notice is kept.
234
302
 
235
- Copyright (c) 2023-present Christopher West
303
+ Copyright (c) 2023-present Chris West