yourjs-box 1.1.2 → 1.3.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 +83 -11
- package/dist/yourjs-box.full.js +1812 -1139
- package/dist/yourjs-box.js +233 -51
- package/dist/yourjs-box.min.js +5 -4
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -39,30 +39,97 @@ If the editor already has code in it you are asked before it is replaced.
|
|
|
39
39
|
|
|
40
40
|
### Toolbar
|
|
41
41
|
|
|
42
|
-
- Clicking the **logo** opens the About window, which
|
|
43
|
-
shows the version, this console's settings and keyboard shortcuts. Its
|
|
44
|
-
**Copy as HTML** tab gives you the HTML for this console (with its current
|
|
45
|
-
code, its original code or no code) as an embed snippet or a full page that
|
|
46
|
-
you can copy or download. Only the `data-*` attributes that were set on the
|
|
47
|
-
script tag are included.
|
|
48
42
|
- **Clear** removes everything from the console. Code can also call
|
|
49
43
|
`console.clear()`.
|
|
50
|
-
- **
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- The layout button switches between showing the editor below or beside the
|
|
54
|
-
console.
|
|
44
|
+
- **Full screen** shows the console using the whole screen. If the browser
|
|
45
|
+
doesn't allow that (eg. on an iPhone) the console fills the browser window
|
|
46
|
+
instead. Press <kbd>Esc</kbd> to exit.
|
|
55
47
|
- **Run** runs the next block of code.
|
|
48
|
+
- Clicking the **logo** opens the About window, which shows the version, this
|
|
49
|
+
console's settings and keyboard shortcuts.
|
|
50
|
+
- The **⋯** button opens a menu with:
|
|
51
|
+
- **Text size**, which is remembered for every console on the same site.
|
|
52
|
+
- **Editor beside / below the console** to change the layout.
|
|
53
|
+
- **Pop out into a window**, which moves the console into a separate window
|
|
54
|
+
while the code keeps running in the page (so in window mode the code can
|
|
55
|
+
still change the page). Close the window or click **Bring it back** to
|
|
56
|
+
move the console back into the page.
|
|
57
|
+
- **Copy as HTML**, which gives you the HTML for this console (with its
|
|
58
|
+
current code, its original code or no code) as an embed snippet or a full
|
|
59
|
+
page that you can copy or download. Only the `data-*` attributes that were
|
|
60
|
+
set on the script tag are included.
|
|
61
|
+
- **Reset**, which clears the console and puts the original code back into
|
|
62
|
+
the editor. In worker mode this also stops any code that is still running
|
|
63
|
+
(eg. an infinite loop) by starting a new worker.
|
|
64
|
+
- **About JS Box**
|
|
56
65
|
|
|
57
66
|
### Attributes
|
|
58
67
|
|
|
59
68
|
| Attribute | Description |
|
|
60
69
|
| --- | --- |
|
|
70
|
+
| `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. |
|
|
71
|
+
| `data-show-results` | `"false"` stops the value of the last expression in each block from being shown. |
|
|
72
|
+
| `data-libraries-url` | Where to load Vue, Ace, Prism and Acorn from. See "Self-Hosting the Libraries" below. |
|
|
61
73
|
| `data-runner` | `"worker"` (default) runs the code in a Web Worker. `"window"` runs it directly in the page. See below. |
|
|
62
74
|
| `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. |
|
|
63
75
|
| `data-hide-prefix` | Any block whose header starts with this prefix is hidden. See below. |
|
|
64
76
|
| `data-theme` | `"light"` or `"dark"`. Defaults to following the system's color scheme like the browser's dev tools. |
|
|
65
77
|
|
|
78
|
+
### Results
|
|
79
|
+
|
|
80
|
+
Like the browser's console, if the last statement in a block is an expression
|
|
81
|
+
(eg. `2 + 2` or `numbers.map(n => n * 2)`) its value is shown after the block
|
|
82
|
+
runs, unless it is `undefined`. Results aren't shown for hidden blocks. Use
|
|
83
|
+
`data-show-results="false"` to turn this off.
|
|
84
|
+
|
|
85
|
+
### Module Blocks
|
|
86
|
+
|
|
87
|
+
By default each block runs like a regular `<script>`, so variables declared in
|
|
88
|
+
one block can be used in the next, but `await` can only be used inside of
|
|
89
|
+
`async` functions. With `data-block-type="module"` each block runs like a
|
|
90
|
+
`<script type="module">` instead:
|
|
91
|
+
|
|
92
|
+
- Top-level `await` works.
|
|
93
|
+
- `import` works (eg. `import {camelCase} from 'https://cdn.jsdelivr.net/npm/lodash-es/+esm';`).
|
|
94
|
+
- Top-level declarations stay inside of their block, just like in a module.
|
|
95
|
+
Use `globalThis` to share values between blocks.
|
|
96
|
+
|
|
97
|
+
### Self-Hosting the Libraries
|
|
98
|
+
|
|
99
|
+
The console's interface uses [Vue](https://vuejs.org/),
|
|
100
|
+
[Ace](https://ace.c9.io/), [Prism](https://prismjs.com/) and
|
|
101
|
+
[Acorn](https://github.com/acornjs/acorn), which are loaded from unpkg by
|
|
102
|
+
default. Exact versions are always used so that a new release of one of them
|
|
103
|
+
can't change how the console works.
|
|
104
|
+
|
|
105
|
+
To load them from somewhere else (eg. your own site, an intranet or another
|
|
106
|
+
CDN) set `data-libraries-url` to a URL where `{name}` and `{version}` are
|
|
107
|
+
replaced with each library's package name and version. Relative URLs are
|
|
108
|
+
relative to the page.
|
|
109
|
+
|
|
110
|
+
| Where | `data-libraries-url` |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| unpkg (the default) | `https://unpkg.com/{name}@{version}/` |
|
|
113
|
+
| jsDelivr | `https://cdn.jsdelivr.net/npm/{name}@{version}/` |
|
|
114
|
+
| Your own copy of `node_modules` | `/node_modules/{name}/` |
|
|
115
|
+
|
|
116
|
+
To host them yourself, install these exact versions and serve the whole
|
|
117
|
+
package folders (Ace and Prism load other files, such as language modes, from
|
|
118
|
+
next to their main files):
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npm install vue@3.5.43 ace-builds@1.44.0 prismjs@1.30.0 prism-themes@1.9.0 acorn@8.18.0
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The About window lists the versions that each version of JS Box uses.
|
|
125
|
+
|
|
126
|
+
### Console Functions
|
|
127
|
+
|
|
128
|
+
`console.log()`, `info()`, `warn()`, `error()`, `debug()`, `dir()`,
|
|
129
|
+
`dirxml()`, `table()`, `assert()`, `count()`, `countReset()`, `time()`,
|
|
130
|
+
`timeLog()`, `timeEnd()`, `trace()`, `group()`, `groupCollapsed()`,
|
|
131
|
+
`groupEnd()` and `clear()` are all shown in the console.
|
|
132
|
+
|
|
66
133
|
### Hidden Code
|
|
67
134
|
|
|
68
135
|
If `data-hide-prefix="HIDE"` is specified then a block with a header like
|
|
@@ -98,6 +165,11 @@ Install the development dependencies by running `npm install`.
|
|
|
98
165
|
and serves the examples at http://localhost:3000/examples/ with the browser
|
|
99
166
|
reloading automatically after each rebuild.
|
|
100
167
|
- `npm run build` builds the files in `dist/` once.
|
|
168
|
+
- `npm test` builds and then runs the browser tests in `test/run.js` using your
|
|
169
|
+
installed copy of Google Chrome (set `CHROME_PATH` to use another Chromium
|
|
170
|
+
based browser). An internet connection is needed because the console loads
|
|
171
|
+
its libraries from CDNs. Pass part of a test's name to run only matching
|
|
172
|
+
tests (eg. `node test/run.js module`).
|
|
101
173
|
- `npm start` builds and then rebuilds whenever one of the files in `src/`
|
|
102
174
|
changes (without serving anything).
|
|
103
175
|
|