@fusion.dev/helix-sandbox 0.0.0-dev

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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -0
  3. package/api.json +1 -0
  4. package/custom-elements.json +1182 -0
  5. package/dist/code-block/code-block-highlight.d.ts +16 -0
  6. package/dist/code-block/code-block-highlight.d.ts.map +1 -0
  7. package/dist/code-block/code-block-highlight.js +10 -0
  8. package/dist/code-block/code-block-highlight.js.map +1 -0
  9. package/dist/code-block/index.d.ts +2 -0
  10. package/dist/code-block/index.d.ts.map +1 -0
  11. package/dist/code-block/index.js +5 -0
  12. package/dist/code-block/index.js.map +1 -0
  13. package/dist/editor/index.d.ts +2 -0
  14. package/dist/editor/index.d.ts.map +1 -0
  15. package/dist/editor/index.js +2 -0
  16. package/dist/editor/index.js.map +1 -0
  17. package/dist/editor/root/editor-root.css.d.ts +2 -0
  18. package/dist/editor/root/editor-root.css.d.ts.map +1 -0
  19. package/dist/editor/root/editor-root.css.js +3 -0
  20. package/dist/editor/root/editor-root.css.js.map +1 -0
  21. package/dist/editor/root/editor-root.d.ts +146 -0
  22. package/dist/editor/root/editor-root.d.ts.map +1 -0
  23. package/dist/editor/root/editor-root.js +199 -0
  24. package/dist/editor/root/editor-root.js.map +1 -0
  25. package/dist/highlight/highlight.d.ts +25 -0
  26. package/dist/highlight/highlight.d.ts.map +1 -0
  27. package/dist/highlight/highlight.js +97 -0
  28. package/dist/highlight/highlight.js.map +1 -0
  29. package/dist/highlight/index.d.ts +4 -0
  30. package/dist/highlight/index.d.ts.map +1 -0
  31. package/dist/highlight/index.js +4 -0
  32. package/dist/highlight/index.js.map +1 -0
  33. package/dist/highlight/language.d.ts +26 -0
  34. package/dist/highlight/language.d.ts.map +1 -0
  35. package/dist/highlight/language.js +21 -0
  36. package/dist/highlight/language.js.map +1 -0
  37. package/dist/highlight/shell.d.ts +10 -0
  38. package/dist/highlight/shell.d.ts.map +1 -0
  39. package/dist/highlight/shell.js +31 -0
  40. package/dist/highlight/shell.js.map +1 -0
  41. package/dist/highlight/stream.d.ts +10 -0
  42. package/dist/highlight/stream.d.ts.map +1 -0
  43. package/dist/highlight/stream.js +178 -0
  44. package/dist/highlight/stream.js.map +1 -0
  45. package/dist/highlight/syntax.d.ts +10 -0
  46. package/dist/highlight/syntax.d.ts.map +1 -0
  47. package/dist/highlight/syntax.js +100 -0
  48. package/dist/highlight/syntax.js.map +1 -0
  49. package/dist/index.d.ts +20 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +2 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/sandbox/editor/sandbox-editor.css.d.ts +2 -0
  54. package/dist/sandbox/editor/sandbox-editor.css.d.ts.map +1 -0
  55. package/dist/sandbox/editor/sandbox-editor.css.js +3 -0
  56. package/dist/sandbox/editor/sandbox-editor.css.js.map +1 -0
  57. package/dist/sandbox/editor/sandbox-editor.d.ts +147 -0
  58. package/dist/sandbox/editor/sandbox-editor.d.ts.map +1 -0
  59. package/dist/sandbox/editor/sandbox-editor.js +199 -0
  60. package/dist/sandbox/editor/sandbox-editor.js.map +1 -0
  61. package/examples.json +1 -0
  62. package/lint.json +1 -0
  63. package/package.json +116 -0
  64. package/types/jsx.d.ts +638 -0
  65. package/types/svelte.d.ts +36 -0
  66. package/types/vue.d.ts +134 -0
  67. package/types/words.d.ts +22 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fusion Development Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @fusion.dev/helix-sandbox
2
+
3
+ A source editor for the Helix sandbox, and a code highlighter for Code Block.
4
+ The editor is CodeMirror in a custom element. The highlighter is Lezer's
5
+ grammars with no editor, so it also runs on a server.
6
+
7
+ ```sh
8
+ npm install @fusion.dev/helix @fusion.dev/helix-styles @fusion.dev/helix-sandbox
9
+ ```
10
+
11
+ | Entry | What it does |
12
+ |---|---|
13
+ | `@fusion.dev/helix-sandbox` | Exports what `/highlight` exports, and the editor's types. Registers nothing |
14
+ | `@fusion.dev/helix-sandbox/code-block` | Colors every Code Block on the page |
15
+ | `@fusion.dev/helix-sandbox/editor` | Registers `helix-sandbox-editor` |
16
+ | `@fusion.dev/helix-sandbox/highlight` | Turns a snippet into highlighted HTML |
17
+
18
+ The editor and the highlighter color code from the `--helix-color-syntax-*`
19
+ tokens, which `@fusion.dev/helix-styles` defines, so load its `helix.css` on
20
+ the page.
21
+
22
+ ## The editor
23
+
24
+ `helix-sandbox-editor` is a source pane for the sandbox in
25
+ `@fusion.dev/helix/sandbox`. Put it in the sandbox's `source` slot and name the
26
+ source it holds, `html` or `css`, as you would a `helix-sandbox-source`:
27
+
28
+ ```html
29
+ <helix-sandbox>
30
+ <helix-sandbox-editor
31
+ language="html"
32
+ name="html"
33
+ slot="source"
34
+ value="<p>Hello</p>"
35
+ ></helix-sandbox-editor>
36
+ <helix-sandbox-preview slot="preview"></helix-sandbox-preview>
37
+ </helix-sandbox>
38
+ ```
39
+
40
+ ```js
41
+ import '@fusion.dev/helix/sandbox'
42
+ import '@fusion.dev/helix-sandbox/editor'
43
+ ```
44
+
45
+ - `language` is `css`, `html`, `js`, `jsx`, `mjs`, `sh`, `ts`, or `tsx`. A
46
+ name the editor does not read draws the source plain, and the console says
47
+ so once.
48
+ - `value` is the source. Setting it replaces the source and sends no edit
49
+ event.
50
+ - `readonly` stops typing. A reader can still select and scroll.
51
+ - `field-label` names the editable region for a screen reader.
52
+
53
+ Each edit is `helix-before-edit` first, which you can cancel to refuse it, and
54
+ `helix-edit` once the editor holds it. `helix-caret` reports the line and
55
+ column for the sandbox's status bar. The editor is `:state(modified)` while it
56
+ holds an edit, and `reset()` puts back the source it was given.
57
+
58
+ Tab indents by two spaces. Escape, then Tab, moves focus out of the editor.
59
+
60
+ The [Sandbox reference](https://fusion.dev/helix/components/sandbox#helix-sandbox-editor)
61
+ lists every property, event, method, and state of the editor. The package
62
+ ships its own `api.json` and `lint.json`, so `helix api family sandbox` lists
63
+ the editor beside the shell, and `helix scan` checks the attributes you write
64
+ on it.
65
+
66
+ ## The highlighter
67
+
68
+ `highlight` turns a snippet into HTML with a span for each token. It runs
69
+ anywhere, on a server included, so a static page can ship colored code with no
70
+ script:
71
+
72
+ ```js
73
+ import { highlight, syntaxHighlighter, syntaxRules } from '@fusion.dev/helix-sandbox/highlight'
74
+
75
+ const markup = highlight('const total = 1', 'ts', syntaxHighlighter)
76
+ ```
77
+
78
+ It reads `css`, `html`, `js`, `sh`, `ts`, and `tsx`, and `languageOf` reads the
79
+ names a page writes for them, such as `TypeScript`, `jsx`, or `bash`. Each span
80
+ carries Lezer's `tok-` classes unless you pass a highlighter of your own.
81
+ `syntaxHighlighter` gives the editor's classes, and `syntaxRules` is the CSS
82
+ that colors them.
83
+
84
+ To color every Code Block on the page, import the `code-block` entry beside
85
+ the block's:
86
+
87
+ ```js
88
+ import '@fusion.dev/helix/code-block'
89
+ import '@fusion.dev/helix-sandbox/code-block'
90
+ ```
91
+
92
+ A block reads its `language` by any name `languageOf` reads, and a language it
93
+ does not read is drawn plain. A block's own `highlight` wins.
94
+
95
+ ## With the sandbox
96
+
97
+ The sandbox shell, its preview, and `helix-sandbox-source` are in
98
+ `@fusion.dev/helix/sandbox`, and they work without this package. The preview
99
+ runs each example in a frame of its own. The
100
+ [sandbox guide](https://fusion.dev/helix/docs/sandbox) says how to give it a
101
+ frame that loads your components.
102
+
103
+ ## Working on it
104
+
105
+ ```sh
106
+ bunx turbo run build --filter @fusion.dev/helix-sandbox # styles, analyze, tsc
107
+ bun run --filter @fusion.dev/helix-sandbox test # dom, then ssr
108
+ ```
109
+
110
+ `helix/CONVENTIONS.md` applies here, and `helix component` holds the editor to
111
+ it. The spec runner and `jsxToHtml`, which the sandbox page on fusion.dev
112
+ uses, are in `helix/workbench`.
package/api.json ADDED
@@ -0,0 +1 @@
1
+ {"families":[{"contributes":true,"elements":[{"attributes":[{"description":"Accessible name for the editable region.","name":"field-label","type":"string"},{"description":"The language of the source, which decides how it is highlighted. A name\nthe editor does not read draws the source plain.","name":"language","type":"'css' | 'html' | 'javascript' | 'js' | 'jsx' | 'mjs' | 'sh' | 'ts' | 'tsx'"},{"description":"Which source this pane holds, echoed in every change.","name":"name","type":"string"},{"description":"Whether the text can be changed.\n\n`EditorState.readOnly` rather than removing the editor's focus or its\nkeymap: a reader still needs to select the text, scroll it, and put a\ncursor in it to read a long line. What it stops is the typing.","name":"readonly","type":"boolean"},{"description":"The source being edited.","name":"value","type":"string"}],"cssParts":[{"description":"The element CodeMirror is mounted into.","name":"editor","type":""}],"cssProperties":[],"cssStates":[{"description":"While the source differs from the source the editor was given, until `reset()` or a new `value`.","name":"modified","type":""},{"description":"Set one frame after the first render. Transitions wait for it, so an element does not animate its own arrival.","name":"settled","type":""}],"description":"CodeMirror, not a `<textarea>`. A textarea cannot highlight what it holds,\nnumber its lines, or say where the cursor is, and a status bar reading line\nand column has to ask something.\n\n**On its own path.** This is `@fusion.dev/helix-sandbox/editor`, and the\npackage's root exports its class as a type only, because CodeMirror is most\nof what the package weighs over the wire. A sandbox with no editable pane\npays for none, and neither does a site that registers its elements once.\n\n`language` names the grammar by the name a file or a sandbox pane carries:\n`css`, `html`, `js`, `jsx`, `mjs`, `sh`, `ts` or `tsx`. A name the editor\ndoes not read draws the source plain, and the console says so once.\n\nEach edit a reader makes is `helix-before-edit` first, which you can cancel\nto refuse the edit, and `helix-edit` once the source holds it, as\n`helix-sandbox-source` sends them. A `value` set from outside is the source the editor is given, and\nsends neither. **The editor is `:state(modified)` while its source differs\nfrom the source it was given**, the first `value` or the last one set from\noutside, and `reset()` puts that source back as an edit.\n\nThe view is built once and reconfigured, not rebuilt. Replacing it on every\nchange would throw away the undo history, the scroll position, and the\nselection, which is most of what an editor is.","entry":"editor","events":[{"bubbles":true,"description":"Fired before the source is edited. Cancelable: refusing it takes the decision and nothing moves.","name":"helix-before-edit","reactProp":"onhelix-before-edit","type":"HelixBeforeEditEvent"},{"bubbles":true,"description":"Fired when the cursor moves, with its line and column.","name":"helix-caret","reactProp":"onhelix-caret","type":"HelixCaretEvent"},{"bubbles":true,"description":"Fired after the source was edited, with the new source.","name":"helix-edit","reactProp":"onhelix-edit","type":"HelixEditEvent"}],"label":"Sandbox Editor","methods":[{"description":"Puts back the source the editor was given, as an edit: `helix-before-edit`\nis sent first and can refuse it, and a sandbox passes it to its preview.","name":"reset","type":"() => void"},{"description":"Moves focus into the text, not onto the host.\n\nThe host is not focusable: what a reader types into is CodeMirror's\ncontenteditable, several nodes down inside this shadow root. Without this,\n`editor.focus()` from outside silently does nothing.","name":"focus","type":"() => void"}],"package":"@fusion.dev/helix-sandbox","part":"Editor","properties":[{"default":"'Example source'","description":"Accessible name for the editable region.","name":"fieldLabel","readonly":false,"references":[],"type":"string"},{"default":"'html'","description":"The language of the source, which decides how it is highlighted. A name\nthe editor does not read draws the source plain.","name":"language","readonly":false,"references":[],"type":"'css' | 'html' | 'javascript' | 'js' | 'jsx' | 'mjs' | 'sh' | 'ts' | 'tsx'"},{"default":"'html'","description":"Which source this pane holds, echoed in every change.","name":"name","readonly":false,"references":[],"type":"string"},{"default":"false","description":"Whether the text can be changed.\n\n`EditorState.readOnly` rather than removing the editor's focus or its\nkeymap: a reader still needs to select the text, scroll it, and put a\ncursor in it to read a long line. What it stops is the typing.","name":"readOnly","readonly":false,"references":[],"type":"boolean"},{"default":"''","description":"The source being edited.","name":"value","readonly":false,"references":[],"type":"string"},{"default":"","description":"Whether the source differs from the source the editor was given: its\nfirst `value`, or the last one set from outside.","name":"modified","readonly":true,"references":[],"type":"boolean"},{"default":"","description":"Where the cursor is, counted from one, as an editor reports it.","name":"caret","readonly":true,"references":[],"type":"CaretDetail"},{"default":"new Promise<void>((resolve) => { this.resolveSettled = resolve })","description":"Resolves a frame after the first update, when transitions are switched on.\n\n**Named `whenSettled` because `settled` is taken four times over**, by\nImage, Splitter and both color controls, none of them about transitions. A\nbase class takes the name every subclass then cannot use.\n\n**The state it reports cannot be watched, which is why this exists.** A\ncustom state is deliberately not in the DOM, so there is no\n`MutationObserver` equivalent for `ElementInternals.states`. Await this\ninstead.\n\nSeparate from `updateComplete`, which resolves in the microtask checkpoint\nthe suppression is still active in. That is the distinction `readyToMove`\nin `@fusion.dev/helix-testing` is written around.\n\nIt never resolves where `requestAnimationFrame` never fires, which is a\nserver, a hidden tab, and happy-dom. Callers that must not hang there race\nit against a timeout, as the happy-dom harness's `readyToMove` does. The\nbrowser harness's awaits it alone: a browser always runs the frame, and a\ntimer beside it was a bet on how long one takes, which a busy run lost.","name":"whenSettled","readonly":true,"references":[],"type":"Promise<void>"}],"slots":[],"specifier":"@fusion.dev/helix-sandbox/editor","status":"experimental","summary":"An editable pane of source, with highlighting and line numbers.","tagName":"helix-sandbox-editor","tier":"styled","words":["fieldLabel"]}],"label":"Sandbox","package":"@fusion.dev/helix","slug":"sandbox"}],"package":"@fusion.dev/helix-sandbox"}