yourjs-box 1.1.2 → 1.2.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 +63 -0
- package/dist/yourjs-box.full.js +361 -66
- package/dist/yourjs-box.js +57 -14
- package/dist/yourjs-box.min.js +5 -4
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -58,11 +58,69 @@ If the editor already has code in it you are asked before it is replaced.
|
|
|
58
58
|
|
|
59
59
|
| Attribute | Description |
|
|
60
60
|
| --- | --- |
|
|
61
|
+
| `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. |
|
|
62
|
+
| `data-show-results` | `"false"` stops the value of the last expression in each block from being shown. |
|
|
63
|
+
| `data-libraries-url` | Where to load Vue, Ace, Prism and Acorn from. See "Self-Hosting the Libraries" below. |
|
|
61
64
|
| `data-runner` | `"worker"` (default) runs the code in a Web Worker. `"window"` runs it directly in the page. See below. |
|
|
62
65
|
| `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
66
|
| `data-hide-prefix` | Any block whose header starts with this prefix is hidden. See below. |
|
|
64
67
|
| `data-theme` | `"light"` or `"dark"`. Defaults to following the system's color scheme like the browser's dev tools. |
|
|
65
68
|
|
|
69
|
+
### Results
|
|
70
|
+
|
|
71
|
+
Like the browser's console, if the last statement in a block is an expression
|
|
72
|
+
(eg. `2 + 2` or `numbers.map(n => n * 2)`) its value is shown after the block
|
|
73
|
+
runs, unless it is `undefined`. Results aren't shown for hidden blocks. Use
|
|
74
|
+
`data-show-results="false"` to turn this off.
|
|
75
|
+
|
|
76
|
+
### Module Blocks
|
|
77
|
+
|
|
78
|
+
By default each block runs like a regular `<script>`, so variables declared in
|
|
79
|
+
one block can be used in the next, but `await` can only be used inside of
|
|
80
|
+
`async` functions. With `data-block-type="module"` each block runs like a
|
|
81
|
+
`<script type="module">` instead:
|
|
82
|
+
|
|
83
|
+
- Top-level `await` works.
|
|
84
|
+
- `import` works (eg. `import {camelCase} from 'https://cdn.jsdelivr.net/npm/lodash-es/+esm';`).
|
|
85
|
+
- Top-level declarations stay inside of their block, just like in a module.
|
|
86
|
+
Use `globalThis` to share values between blocks.
|
|
87
|
+
|
|
88
|
+
### Self-Hosting the Libraries
|
|
89
|
+
|
|
90
|
+
The console's interface uses [Vue](https://vuejs.org/),
|
|
91
|
+
[Ace](https://ace.c9.io/), [Prism](https://prismjs.com/) and
|
|
92
|
+
[Acorn](https://github.com/acornjs/acorn), which are loaded from unpkg by
|
|
93
|
+
default. Exact versions are always used so that a new release of one of them
|
|
94
|
+
can't change how the console works.
|
|
95
|
+
|
|
96
|
+
To load them from somewhere else (eg. your own site, an intranet or another
|
|
97
|
+
CDN) set `data-libraries-url` to a URL where `{name}` and `{version}` are
|
|
98
|
+
replaced with each library's package name and version. Relative URLs are
|
|
99
|
+
relative to the page.
|
|
100
|
+
|
|
101
|
+
| Where | `data-libraries-url` |
|
|
102
|
+
| --- | --- |
|
|
103
|
+
| unpkg (the default) | `https://unpkg.com/{name}@{version}/` |
|
|
104
|
+
| jsDelivr | `https://cdn.jsdelivr.net/npm/{name}@{version}/` |
|
|
105
|
+
| Your own copy of `node_modules` | `/node_modules/{name}/` |
|
|
106
|
+
|
|
107
|
+
To host them yourself, install these exact versions and serve the whole
|
|
108
|
+
package folders (Ace and Prism load other files, such as language modes, from
|
|
109
|
+
next to their main files):
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npm install vue@3.5.43 ace-builds@1.44.0 prismjs@1.30.0 prism-themes@1.9.0 acorn@8.18.0
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The About window lists the versions that each version of JS Box uses.
|
|
116
|
+
|
|
117
|
+
### Console Functions
|
|
118
|
+
|
|
119
|
+
`console.log()`, `info()`, `warn()`, `error()`, `debug()`, `dir()`,
|
|
120
|
+
`dirxml()`, `table()`, `assert()`, `count()`, `countReset()`, `time()`,
|
|
121
|
+
`timeLog()`, `timeEnd()`, `trace()`, `group()`, `groupCollapsed()`,
|
|
122
|
+
`groupEnd()` and `clear()` are all shown in the console.
|
|
123
|
+
|
|
66
124
|
### Hidden Code
|
|
67
125
|
|
|
68
126
|
If `data-hide-prefix="HIDE"` is specified then a block with a header like
|
|
@@ -98,6 +156,11 @@ Install the development dependencies by running `npm install`.
|
|
|
98
156
|
and serves the examples at http://localhost:3000/examples/ with the browser
|
|
99
157
|
reloading automatically after each rebuild.
|
|
100
158
|
- `npm run build` builds the files in `dist/` once.
|
|
159
|
+
- `npm test` builds and then runs the browser tests in `test/run.js` using your
|
|
160
|
+
installed copy of Google Chrome (set `CHROME_PATH` to use another Chromium
|
|
161
|
+
based browser). An internet connection is needed because the console loads
|
|
162
|
+
its libraries from CDNs. Pass part of a test's name to run only matching
|
|
163
|
+
tests (eg. `node test/run.js module`).
|
|
101
164
|
- `npm start` builds and then rebuilds whenever one of the files in `src/`
|
|
102
165
|
changes (without serving anything).
|
|
103
166
|
|