@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/types/jsx.d.ts ADDED
@@ -0,0 +1,638 @@
1
+ import type {
2
+ HelixBeforeEditEvent,
3
+ HelixCaretEvent,
4
+ HelixEditEvent,
5
+ HelixSandboxEditor,
6
+ } from '@fusion.dev/helix-sandbox';
7
+
8
+ /**
9
+ * This type can be used to create scoped tags for your components.
10
+ *
11
+ * Usage:
12
+ *
13
+ * ```ts
14
+ * import type { ScopedElements } from "path/to/library/jsx-integration";
15
+ *
16
+ * declare module "my-library" {
17
+ * namespace JSX {
18
+ * interface IntrinsicElements
19
+ * extends ScopedElements<'test-', ''> {}
20
+ * }
21
+ * }
22
+ * ```
23
+ *
24
+ * @deprecated Runtime scoped elements result in duplicate types and can confusing for developers. It is recommended to use the `prefix` and `suffix` options to generate new types instead.
25
+ */
26
+ export type ScopedElements<
27
+ Prefix extends string = "",
28
+ Suffix extends string = "",
29
+ > = {
30
+ [Key in keyof CustomElements as `${Prefix}${Key}${Suffix}`]: CustomElements[Key];
31
+ };
32
+
33
+ /**
34
+ * A generic type for strongly typing custom events with their targets
35
+ * @template T - The type of the event target (extends EventTarget)
36
+ * @template D - The type of the detail payload for the custom event
37
+ */
38
+ type TypedEvent<T extends EventTarget, E = Event> = E & {
39
+ target: T;
40
+ };
41
+
42
+ /**
43
+ * The JSX a tag is written in. React, Preact, and Solid each read a tag map
44
+ * with their own name, and every other framework reads it as `"other"`.
45
+ *
46
+ * **Each framework's types are imported only on its own branch below.** Every
47
+ * framework loads this file, the Svelte typings included, and a project has
48
+ * only its own framework's types installed. A reference to a module that is
49
+ * not installed is an error in any file the program loads, under
50
+ * `skipLibCheck: false`, so the comment above each import keeps a project
51
+ * without that module compiling. Where the module is installed, the import
52
+ * resolves as written.
53
+ */
54
+ type Framework = "other" | "preact" | "react" | "solid";
55
+
56
+ /**
57
+ * `ref` as each framework types it, and the generator's shape for the rest,
58
+ * which is Solid's own.
59
+ */
60
+ type FrameworkRef<T extends HTMLElement, F extends Framework> = F extends "react"
61
+ ? // @ts-ignore: React's types, read only by React's JSX.
62
+ import('react').Ref<T>
63
+ : F extends "preact"
64
+ ? // @ts-ignore: Preact's types, read only by Preact's JSX.
65
+ import('preact').Ref<T>
66
+ : T | ((e: T) => void);
67
+
68
+ /** `style` as each framework types it on a `<div>`, and any object for the rest. */
69
+ type FrameworkStyle<F extends Framework> = F extends "react"
70
+ ? // @ts-ignore: React's types, read only by React's JSX.
71
+ import('react').CSSProperties
72
+ : F extends "preact"
73
+ ? // @ts-ignore: Preact's types, read only by Preact's JSX.
74
+ import('preact').JSX.IntrinsicElements["div"]["style"]
75
+ : F extends "solid"
76
+ ? // @ts-ignore: Solid's types, read only by Solid's JSX.
77
+ import('solid-js').JSX.IntrinsicElements["div"]["style"]
78
+ : Record<string, string | number>;
79
+
80
+ type BaseProps<T extends HTMLElement, F extends Framework = "other"> = {
81
+ /** Skips the hydration check for an element whose DOM is written by something other than React, which a custom element writing its own state attributes is. React takes it, and no other framework does. */
82
+ suppressHydrationWarning?: (F extends "react" ? boolean : never) | undefined;
83
+ /** Content added between the opening and closing tags of the element */
84
+ children?: any;
85
+ /** Used for declaratively styling one or more elements using CSS (Cascading Stylesheets) */
86
+ class?: (string) | undefined;
87
+ /** Used for declaratively styling one or more elements using CSS (Cascading Stylesheets) */
88
+ className?: (string) | undefined;
89
+ /** Takes an object where the key is the class name(s) and the value is a boolean expression. When true, the class is applied, and when false, it is removed. */
90
+ classList?: (Record<string, boolean | undefined>) | undefined;
91
+ /** Specifies the text direction of the element. */
92
+ dir?: ("ltr" | "rtl") | undefined;
93
+ /** Contains a space-separated list of the part names of the element that should be exposed on the host element. */
94
+ exportparts?: (string) | undefined;
95
+ /** For <label> and <output>, lets you associate the label with some control. */
96
+ htmlFor?: (string) | undefined;
97
+ /** Specifies whether the element should be hidden. */
98
+ hidden?: (boolean | string) | undefined;
99
+ /** A unique identifier for the element. */
100
+ id?: (string) | undefined;
101
+ /** Keys tell React which array item each component corresponds to */
102
+ key?: (string | number) | undefined;
103
+ /** Specifies the language of the element. */
104
+ lang?: (string) | undefined;
105
+ /** Defines the element's semantic role for accessibility APIs. */
106
+ role?: (string) | undefined;
107
+ /** Contains a space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the ::part pseudo-element. */
108
+ part?: (string) | undefined;
109
+ /** Use the ref attribute with a variable to assign a DOM element to the variable once the element is rendered. */
110
+ ref?: (FrameworkRef<T, F>) | undefined;
111
+ /** Adds a reference for a custom element slot */
112
+ slot?: (string) | undefined;
113
+ /** Prop for setting inline styles */
114
+ style?: (FrameworkStyle<F>) | undefined;
115
+ /** Overrides the default Tab button behavior. Avoid using values other than -1 and 0. */
116
+ tabIndex?: (number) | undefined;
117
+ /** Specifies the tooltip text for the element. */
118
+ title?: (string) | undefined;
119
+ /** Passing 'no' excludes the element content from being translated. */
120
+ translate?: ("yes" | "no") | undefined;
121
+ /** The popover global attribute is used to designate an element as a popover element. */
122
+ popover?: ("auto" | "hint" | "manual") | undefined;
123
+ /** Turns an element element into a popover control button; takes the ID of the popover element to control as its value. */
124
+ popovertarget?: (string) | undefined;
125
+ /** Specifies the action to be performed on a popover element being controlled by a control element. */
126
+ popovertargetaction?: ("show" | "hide" | "toggle") | undefined;
127
+ };
128
+
129
+ type BaseEvents<T = HTMLElement> = {
130
+ // Mouse Events
131
+
132
+ /** Triggered when the element is clicked by the user by mouse or keyboard. */
133
+ onClick?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
134
+ /** Fired when the context menu is triggered, often by right-clicking. */
135
+ onContextMenu?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
136
+ /** Fired when the element is double-clicked. */
137
+ onDoubleClick?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
138
+ /** Fired repeatedly as the draggable element is being dragged. */
139
+ onDrag?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
140
+ /** Fired when the dragging of a draggable element is finished. */
141
+ onDragEnd?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
142
+ /** Fired when a dragged element or text selection enters a valid drop target. */
143
+ onDragEnter?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
144
+ /** Fired when a dragged element or text selection leaves a valid drop target. */
145
+ onDragExit?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
146
+ /** Fired when a dragged element or text selection leaves a valid drop target. */
147
+ onDragLeave?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
148
+ /** Fired when an element or text selection is being dragged over a valid drop target (every few hundred milliseconds). */
149
+ onDragOver?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
150
+ /** Fired when a draggable element starts being dragged. */
151
+ onDragStart?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
152
+ /** Fired when a dragged element is dropped onto a drop target. */
153
+ onDrop?: ((event: DragEvent & { currentTarget: T }) => void) | undefined;
154
+ /** Fired when a mouse button is pressed down on the element. */
155
+ onMouseDown?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
156
+ /** Fired when the mouse cursor enters the element. */
157
+ onMouseEnter?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
158
+ /** Triggered when the mouse cursor leaves the element. */
159
+ onMouseLeave?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
160
+ /** Fired at an element when a pointing device (usually a mouse) is moved while the cursor's hotspot is inside it. */
161
+ onMouseMove?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
162
+ /** Fired at an Element when a pointing device (usually a mouse) is used to move the cursor so that it is no longer contained within the element or one of its children. */
163
+ onMouseOut?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
164
+ /** Fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements. */
165
+ onMouseOver?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
166
+ /** Fired when a mouse button is released on the element. */
167
+ onMouseUp?: ((event: MouseEvent & { currentTarget: T }) => void) | undefined;
168
+
169
+ // Keyboard Events
170
+
171
+ /** Fired when a key is pressed down. */
172
+ onKeyDown?: ((event: KeyboardEvent & { currentTarget: T }) => void) | undefined;
173
+ /** Fired when a key is released.. */
174
+ onKeyUp?: ((event: KeyboardEvent & { currentTarget: T }) => void) | undefined;
175
+
176
+ // Focus Events
177
+
178
+ /** Fired when the element receives focus, often triggered by tab navigation. */
179
+ onFocus?: ((event: FocusEvent & { currentTarget: T }) => void) | undefined;
180
+ /** Fired when the element loses focus. */
181
+ onBlur?: ((event: FocusEvent & { currentTarget: T }) => void) | undefined;
182
+
183
+ // Form Events
184
+
185
+ /** Fired when the value of an input element changes, such as with text inputs or select elements. */
186
+ onChange?: ((event: Event & { currentTarget: T }) => void) | undefined;
187
+ /** Fires when the value of an <input>, <select>, or <textarea> element has been changed. */
188
+ onInput?: ((event: Event & { currentTarget: T }) => void) | undefined;
189
+ /** Fired when a form is submitted, usually on pressing Enter in a text input. */
190
+ onSubmit?: ((event: Event & { currentTarget: T }) => void) | undefined;
191
+ /** Fired when a form is reset. */
192
+ onReset?: ((event: Event & { currentTarget: T }) => void) | undefined;
193
+
194
+ // UI Events
195
+
196
+ /** Fired when the content of an element is scrolled. */
197
+ onScroll?: ((event: UIEvent & { currentTarget: T }) => void) | undefined;
198
+
199
+ // Wheel Events
200
+
201
+ /** Fired when the mouse wheel is scrolled while the element is focused. */
202
+ onWheel?: ((event: WheelEvent & { currentTarget: T }) => void) | undefined;
203
+
204
+ // Animation Events
205
+
206
+ /** Fired when a CSS animation starts. */
207
+ onAnimationStart?: ((event: AnimationEvent & { currentTarget: T }) => void) | undefined;
208
+ /** Fired when a CSS animation completes. */
209
+ onAnimationEnd?: ((event: AnimationEvent & { currentTarget: T }) => void) | undefined;
210
+ /** Fired when a CSS animation completes one iteration. */
211
+ onAnimationIteration?: ((event: AnimationEvent & { currentTarget: T }) => void) | undefined;
212
+
213
+ // Transition Events
214
+
215
+ /** Fired when a CSS transition has completed. */
216
+ onTransitionEnd?: ((event: TransitionEvent & { currentTarget: T }) => void) | undefined;
217
+
218
+ // Media Events
219
+
220
+ /** Fired when an element (usually an image) finishes loading */
221
+ onLoad?: ((event: Event & { currentTarget: T }) => void) | undefined;
222
+ /** Fired when an error occurs during the loading of an element, like an image not being found. */
223
+ onError?: ((event: Event & { currentTarget: T }) => void) | undefined;
224
+
225
+ // Clipboard Events
226
+
227
+ /** Fires when the user initiates a copy action through the browser's user interface. */
228
+ onCopy?: ((event: ClipboardEvent & { currentTarget: T }) => void) | undefined;
229
+ /** Fired when the user has initiated a "cut" action through the browser's user interface. */
230
+ onCut?: ((event: ClipboardEvent & { currentTarget: T }) => void) | undefined;
231
+ /** Fired when the user has initiated a "paste" action through the browser's user interface. */
232
+ onPaste?: ((event: ClipboardEvent & { currentTarget: T }) => void) | undefined;
233
+ };
234
+
235
+ /** `HelixSandboxEditor` component event */
236
+ export type HelixSandboxEditorElementEvent<E = Event> = TypedEvent<
237
+ HelixSandboxEditor,
238
+ E
239
+ >;
240
+ /** `helix-before-edit` event type */
241
+ export type HelixSandboxEditorHelixBeforeEditElementEvent =
242
+ HelixSandboxEditorElementEvent<HelixBeforeEditEvent>;
243
+ /** `helix-caret` event type */
244
+ export type HelixSandboxEditorHelixCaretElementEvent =
245
+ HelixSandboxEditorElementEvent<HelixCaretEvent>;
246
+ /** `helix-edit` event type */
247
+ export type HelixSandboxEditorHelixEditElementEvent =
248
+ HelixSandboxEditorElementEvent<HelixEditEvent>;
249
+
250
+ export type HelixSandboxEditorProps = {
251
+ /** Accessible name for the editable region. */
252
+ "field-label"?: (HelixSandboxEditor["fieldLabel"]) | undefined;
253
+ /** Accessible name for the editable region. */
254
+ fieldLabel?: (HelixSandboxEditor["fieldLabel"]) | undefined;
255
+ /** The language of the source, which decides how it is highlighted. A name
256
+ the editor does not read draws the source plain. */
257
+ language?: (HelixSandboxEditor["language"]) | undefined;
258
+ /** Which source this pane holds, echoed in every change. */
259
+ name?: (HelixSandboxEditor["name"]) | undefined;
260
+ /** Whether the text can be changed.
261
+
262
+ `EditorState.readOnly` rather than removing the editor's focus or its
263
+ keymap: a reader still needs to select the text, scroll it, and put a
264
+ cursor in it to read a long line. What it stops is the typing. */
265
+ readonly?: (HelixSandboxEditor["readOnly"]) | undefined;
266
+ /** Whether the text can be changed.
267
+
268
+ `EditorState.readOnly` rather than removing the editor's focus or its
269
+ keymap: a reader still needs to select the text, scroll it, and put a
270
+ cursor in it to read a long line. What it stops is the typing. */
271
+ readOnly?: (HelixSandboxEditor["readOnly"]) | undefined;
272
+ /** The source being edited. */
273
+ value?: (HelixSandboxEditor["value"]) | undefined;
274
+
275
+ /** Fired before the source is edited. Cancelable: refusing it takes the decision and nothing moves. */
276
+ "onhelix-before-edit"?: ((
277
+ e: HelixSandboxEditorHelixBeforeEditElementEvent,
278
+ ) => void) | undefined;
279
+ /** Fired when the cursor moves, with its line and column. */
280
+ "onhelix-caret"?: ((e: HelixSandboxEditorHelixCaretElementEvent) => void) | undefined;
281
+ /** Fired after the source was edited, with the new source. */
282
+ "onhelix-edit"?: ((e: HelixSandboxEditorHelixEditElementEvent) => void) | undefined;
283
+ };
284
+
285
+ export type HelixSandboxEditorSolidJsProps = {
286
+ /** Accessible name for the editable region. */
287
+ "attr:field-label"?: (HelixSandboxEditor["fieldLabel"]) | undefined;
288
+ /** Accessible name for the editable region. */
289
+ "prop:fieldLabel"?: (HelixSandboxEditor["fieldLabel"]) | undefined;
290
+ /** The language of the source, which decides how it is highlighted. A name
291
+ the editor does not read draws the source plain. */
292
+ "prop:language"?: (HelixSandboxEditor["language"]) | undefined;
293
+ /** Which source this pane holds, echoed in every change. */
294
+ "prop:name"?: (HelixSandboxEditor["name"]) | undefined;
295
+ /** Whether the text can be changed.
296
+
297
+ `EditorState.readOnly` rather than removing the editor's focus or its
298
+ keymap: a reader still needs to select the text, scroll it, and put a
299
+ cursor in it to read a long line. What it stops is the typing. */
300
+ "bool:readonly"?: (HelixSandboxEditor["readOnly"]) | undefined;
301
+ /** Whether the text can be changed.
302
+
303
+ `EditorState.readOnly` rather than removing the editor's focus or its
304
+ keymap: a reader still needs to select the text, scroll it, and put a
305
+ cursor in it to read a long line. What it stops is the typing. */
306
+ "prop:readOnly"?: (HelixSandboxEditor["readOnly"]) | undefined;
307
+ /** The source being edited. */
308
+ "prop:value"?: (HelixSandboxEditor["value"]) | undefined;
309
+ /** Fired before the source is edited. Cancelable: refusing it takes the decision and nothing moves. */
310
+ "on:helix-before-edit"?: ((
311
+ e: HelixSandboxEditorHelixBeforeEditElementEvent,
312
+ ) => void) | undefined;
313
+ /** Fired when the cursor moves, with its line and column. */
314
+ "on:helix-caret"?: ((e: HelixSandboxEditorHelixCaretElementEvent) => void) | undefined;
315
+ /** Fired after the source was edited, with the new source. */
316
+ "on:helix-edit"?: ((e: HelixSandboxEditorHelixEditElementEvent) => void) | undefined;
317
+
318
+ /** Set the innerHTML of the element */
319
+ innerHTML?: (string) | undefined;
320
+ /** Set the textContent of the element */
321
+ textContent?: (string | number) | undefined;
322
+ };
323
+
324
+ export type CustomElements<F extends Framework = "other"> = {
325
+ /**
326
+ * CodeMirror, not a `<textarea>`. A textarea cannot highlight what it holds,
327
+ * number its lines, or say where the cursor is, and a status bar reading line
328
+ * and column has to ask something.
329
+ *
330
+ * **On its own path.** This is `@fusion.dev/helix-sandbox/editor`, and the
331
+ * package's root exports its class as a type only, because CodeMirror is most
332
+ * of what the package weighs over the wire. A sandbox with no editable pane
333
+ * pays for none, and neither does a site that registers its elements once.
334
+ *
335
+ * `language` names the grammar by the name a file or a sandbox pane carries:
336
+ * `css`, `html`, `js`, `jsx`, `mjs`, `sh`, `ts` or `tsx`. A name the editor
337
+ * does not read draws the source plain, and the console says so once.
338
+ *
339
+ * Each edit a reader makes is `helix-before-edit` first, which you can cancel
340
+ * to refuse the edit, and `helix-edit` once the source holds it, as
341
+ * `helix-sandbox-source` sends them. A `value` set from outside is the source the editor is given, and
342
+ * sends neither. **The editor is `:state(modified)` while its source differs
343
+ * from the source it was given**, the first `value` or the last one set from
344
+ * outside, and `reset()` puts that source back as an edit.
345
+ *
346
+ * The view is built once and reconfigured, not rebuilt. Replacing it on every
347
+ * change would throw away the undo history, the scroll position, and the
348
+ * selection, which is most of what an editor is.
349
+ *
350
+ * ## Attributes & Properties
351
+ *
352
+ * Component attributes and properties that can be applied to the element or by using JavaScript.
353
+ *
354
+ * - `field-label`/`fieldLabel`: Accessible name for the editable region.
355
+ * - `language`: The language of the source, which decides how it is highlighted. A name
356
+ * the editor does not read draws the source plain.
357
+ * - `name`: Which source this pane holds, echoed in every change.
358
+ * - `readonly`/`readOnly`: Whether the text can be changed.
359
+ *
360
+ * `EditorState.readOnly` rather than removing the editor's focus or its
361
+ * keymap: a reader still needs to select the text, scroll it, and put a
362
+ * cursor in it to read a long line. What it stops is the typing.
363
+ * - `value`: The source being edited.
364
+ * - `modified`: Whether the source differs from the source the editor was given: its
365
+ * first `value`, or the last one set from outside. (property only) (readonly)
366
+ * - `caret`: Where the cursor is, counted from one, as an editor reports it. (property only) (readonly)
367
+ * - `whenSettled`: Resolves a frame after the first update, when transitions are switched on.
368
+ *
369
+ * **Named `whenSettled` because `settled` is taken four times over**, by
370
+ * Image, Splitter and both color controls, none of them about transitions. A
371
+ * base class takes the name every subclass then cannot use.
372
+ *
373
+ * **The state it reports cannot be watched, which is why this exists.** A
374
+ * custom state is deliberately not in the DOM, so there is no
375
+ * `MutationObserver` equivalent for `ElementInternals.states`. Await this
376
+ * instead.
377
+ *
378
+ * Separate from `updateComplete`, which resolves in the microtask checkpoint
379
+ * the suppression is still active in. That is the distinction `readyToMove`
380
+ * in `@fusion.dev/helix-testing` is written around.
381
+ *
382
+ * It never resolves where `requestAnimationFrame` never fires, which is a
383
+ * server, a hidden tab, and happy-dom. Callers that must not hang there race
384
+ * it against a timeout, as the happy-dom harness's `readyToMove` does. The
385
+ * browser harness's awaits it alone: a browser always runs the frame, and a
386
+ * timer beside it was a bet on how long one takes, which a busy run lost. (property only) (readonly)
387
+ *
388
+ * ## Events
389
+ *
390
+ * Events that will be emitted by the component.
391
+ *
392
+ * - `helix-before-edit`: Fired before the source is edited. Cancelable: refusing it takes the decision and nothing moves.
393
+ * - `helix-caret`: Fired when the cursor moves, with its line and column.
394
+ * - `helix-edit`: Fired after the source was edited, with the new source.
395
+ *
396
+ * ## Methods
397
+ *
398
+ * Methods that can be called to access component functionality.
399
+ *
400
+ * - `reset() => void`: Puts back the source the editor was given, as an edit: `helix-before-edit`
401
+ * is sent first and can refuse it, and a sandbox passes it to its preview.
402
+ * - `focus() => void`: Moves focus into the text, not onto the host.
403
+ *
404
+ * The host is not focusable: what a reader types into is CodeMirror's
405
+ * contenteditable, several nodes down inside this shadow root. Without this,
406
+ * `editor.focus()` from outside silently does nothing.
407
+ *
408
+ * ## CSS Parts
409
+ *
410
+ * Custom selectors for styling elements within the component.
411
+ *
412
+ * - `editor`: The element CodeMirror is mounted into.
413
+ *
414
+ * ## CSS States
415
+ *
416
+ * These can be used to apply styling when a component is in a given state.
417
+ *
418
+ * - `modified`: While the source differs from the source the editor was given, until `reset()` or a new `value`.
419
+ * - `settled`: Set one frame after the first render. Transitions wait for it, so an element does not animate its own arrival.
420
+ */
421
+ "helix-sandbox-editor": Partial<
422
+ HelixSandboxEditorProps & BaseProps<HelixSandboxEditor, F> & BaseEvents<HelixSandboxEditor>
423
+ >;
424
+ };
425
+
426
+ export type CustomElementsSolidJs = {
427
+ /**
428
+ * CodeMirror, not a `<textarea>`. A textarea cannot highlight what it holds,
429
+ * number its lines, or say where the cursor is, and a status bar reading line
430
+ * and column has to ask something.
431
+ *
432
+ * **On its own path.** This is `@fusion.dev/helix-sandbox/editor`, and the
433
+ * package's root exports its class as a type only, because CodeMirror is most
434
+ * of what the package weighs over the wire. A sandbox with no editable pane
435
+ * pays for none, and neither does a site that registers its elements once.
436
+ *
437
+ * `language` names the grammar by the name a file or a sandbox pane carries:
438
+ * `css`, `html`, `js`, `jsx`, `mjs`, `sh`, `ts` or `tsx`. A name the editor
439
+ * does not read draws the source plain, and the console says so once.
440
+ *
441
+ * Each edit a reader makes is `helix-before-edit` first, which you can cancel
442
+ * to refuse the edit, and `helix-edit` once the source holds it, as
443
+ * `helix-sandbox-source` sends them. A `value` set from outside is the source the editor is given, and
444
+ * sends neither. **The editor is `:state(modified)` while its source differs
445
+ * from the source it was given**, the first `value` or the last one set from
446
+ * outside, and `reset()` puts that source back as an edit.
447
+ *
448
+ * The view is built once and reconfigured, not rebuilt. Replacing it on every
449
+ * change would throw away the undo history, the scroll position, and the
450
+ * selection, which is most of what an editor is.
451
+ *
452
+ * ## Attributes & Properties
453
+ *
454
+ * Component attributes and properties that can be applied to the element or by using JavaScript.
455
+ *
456
+ * - `field-label`/`fieldLabel`: Accessible name for the editable region.
457
+ * - `language`: The language of the source, which decides how it is highlighted. A name
458
+ * the editor does not read draws the source plain.
459
+ * - `name`: Which source this pane holds, echoed in every change.
460
+ * - `readonly`/`readOnly`: Whether the text can be changed.
461
+ *
462
+ * `EditorState.readOnly` rather than removing the editor's focus or its
463
+ * keymap: a reader still needs to select the text, scroll it, and put a
464
+ * cursor in it to read a long line. What it stops is the typing.
465
+ * - `value`: The source being edited.
466
+ * - `modified`: Whether the source differs from the source the editor was given: its
467
+ * first `value`, or the last one set from outside. (property only) (readonly)
468
+ * - `caret`: Where the cursor is, counted from one, as an editor reports it. (property only) (readonly)
469
+ * - `whenSettled`: Resolves a frame after the first update, when transitions are switched on.
470
+ *
471
+ * **Named `whenSettled` because `settled` is taken four times over**, by
472
+ * Image, Splitter and both color controls, none of them about transitions. A
473
+ * base class takes the name every subclass then cannot use.
474
+ *
475
+ * **The state it reports cannot be watched, which is why this exists.** A
476
+ * custom state is deliberately not in the DOM, so there is no
477
+ * `MutationObserver` equivalent for `ElementInternals.states`. Await this
478
+ * instead.
479
+ *
480
+ * Separate from `updateComplete`, which resolves in the microtask checkpoint
481
+ * the suppression is still active in. That is the distinction `readyToMove`
482
+ * in `@fusion.dev/helix-testing` is written around.
483
+ *
484
+ * It never resolves where `requestAnimationFrame` never fires, which is a
485
+ * server, a hidden tab, and happy-dom. Callers that must not hang there race
486
+ * it against a timeout, as the happy-dom harness's `readyToMove` does. The
487
+ * browser harness's awaits it alone: a browser always runs the frame, and a
488
+ * timer beside it was a bet on how long one takes, which a busy run lost. (property only) (readonly)
489
+ *
490
+ * ## Events
491
+ *
492
+ * Events that will be emitted by the component.
493
+ *
494
+ * - `helix-before-edit`: Fired before the source is edited. Cancelable: refusing it takes the decision and nothing moves.
495
+ * - `helix-caret`: Fired when the cursor moves, with its line and column.
496
+ * - `helix-edit`: Fired after the source was edited, with the new source.
497
+ *
498
+ * ## Methods
499
+ *
500
+ * Methods that can be called to access component functionality.
501
+ *
502
+ * - `reset() => void`: Puts back the source the editor was given, as an edit: `helix-before-edit`
503
+ * is sent first and can refuse it, and a sandbox passes it to its preview.
504
+ * - `focus() => void`: Moves focus into the text, not onto the host.
505
+ *
506
+ * The host is not focusable: what a reader types into is CodeMirror's
507
+ * contenteditable, several nodes down inside this shadow root. Without this,
508
+ * `editor.focus()` from outside silently does nothing.
509
+ *
510
+ * ## CSS Parts
511
+ *
512
+ * Custom selectors for styling elements within the component.
513
+ *
514
+ * - `editor`: The element CodeMirror is mounted into.
515
+ *
516
+ * ## CSS States
517
+ *
518
+ * These can be used to apply styling when a component is in a given state.
519
+ *
520
+ * - `modified`: While the source differs from the source the editor was given, until `reset()` or a new `value`.
521
+ * - `settled`: Set one frame after the first render. Transitions wait for it, so an element does not animate its own arrival.
522
+ */
523
+ "helix-sandbox-editor": Partial<
524
+ HelixSandboxEditorProps &
525
+ HelixSandboxEditorSolidJsProps &
526
+ BaseProps<HelixSandboxEditor, "solid"> &
527
+ BaseEvents<HelixSandboxEditor>
528
+ >;
529
+ };
530
+
531
+ export type CustomCssProperties = {};
532
+
533
+ declare module "react" {
534
+ namespace JSX {
535
+ interface IntrinsicElements extends CustomElements<"react"> {}
536
+ }
537
+ export interface CSSProperties extends CustomCssProperties {}
538
+ }
539
+
540
+ declare module "react/jsx-runtime" {
541
+ namespace JSX {
542
+ interface IntrinsicElements extends CustomElements<"react"> {}
543
+ }
544
+ export interface CSSProperties extends CustomCssProperties {}
545
+ }
546
+
547
+ declare module "react/jsx-dev-runtime" {
548
+ namespace JSX {
549
+ interface IntrinsicElements extends CustomElements<"react"> {}
550
+ }
551
+ export interface CSSProperties extends CustomCssProperties {}
552
+ }
553
+
554
+ declare module "preact" {
555
+ namespace JSX {
556
+ interface IntrinsicElements extends CustomElements<"preact"> {}
557
+ }
558
+ export interface CSSProperties extends CustomCssProperties {}
559
+ }
560
+
561
+ declare module "@builder.io/qwik" {
562
+ namespace JSX {
563
+ interface IntrinsicElements extends CustomElements {}
564
+ }
565
+ export interface CSSProperties extends CustomCssProperties {}
566
+ }
567
+
568
+ declare module "@stencil/core" {
569
+ namespace JSX {
570
+ interface IntrinsicElements extends CustomElements {}
571
+ }
572
+ export interface CSSProperties extends CustomCssProperties {}
573
+ }
574
+
575
+ declare module "hono/jsx" {
576
+ namespace JSX {
577
+ interface IntrinsicElements extends CustomElements {}
578
+ }
579
+ export interface CSSProperties extends CustomCssProperties {}
580
+ }
581
+
582
+ declare module "react-native" {
583
+ namespace JSX {
584
+ interface IntrinsicElements extends CustomElements {}
585
+ }
586
+ export interface CSSProperties extends CustomCssProperties {}
587
+ }
588
+
589
+ declare module "solid-js" {
590
+ namespace JSX {
591
+ interface IntrinsicElements extends CustomElementsSolidJs {}
592
+ }
593
+ export interface CSSProperties extends CustomCssProperties {}
594
+ }
595
+
596
+ declare module "solid-js/jsx-runtime" {
597
+ namespace JSX {
598
+ interface IntrinsicElements extends CustomElementsSolidJs {}
599
+ }
600
+ }
601
+
602
+ /**
603
+ * A prop as Solid's JSX takes it without the compiler, with
604
+ * `jsxImportSource: "solid-js/h"`. `h` calls a function given to a prop for
605
+ * the prop's value, and calls it again when a signal it read changes, so each
606
+ * prop takes its value or a function that returns it. `ref`, `children`, and
607
+ * the props named `on…` are taken as they are, as `h` takes them. A property
608
+ * whose value is a function takes only a function that returns it, because
609
+ * `h` calls any function it is given. A prop typed `any` stays `any`.
610
+ */
611
+ type SolidHProp<K, V> = K extends "children" | "ref" | `on${string}`
612
+ ? V
613
+ : 0 extends 1 & V
614
+ ? V
615
+ : [Exclude<V, undefined>] extends [(...args: never[]) => unknown]
616
+ ? (() => V) | undefined
617
+ : V | (() => V);
618
+
619
+ /** One tag's props as Solid's JSX takes them without the compiler. */
620
+ type SolidHProps<P> = { [K in keyof P]: SolidHProp<K, P[K]> };
621
+
622
+ /** The tag map Solid's JSX reads without the compiler: `CustomElementsSolidJs`, each prop as `SolidHProp` takes it. */
623
+ export type CustomElementsSolidH = {
624
+ [Tag in keyof CustomElementsSolidJs]: SolidHProps<CustomElementsSolidJs[Tag]>;
625
+ };
626
+
627
+ declare module "solid-js/h/jsx-runtime" {
628
+ namespace JSX {
629
+ interface IntrinsicElements extends CustomElementsSolidH {}
630
+ }
631
+ }
632
+
633
+ declare global {
634
+ namespace JSX {
635
+ interface IntrinsicElements extends CustomElements {}
636
+ }
637
+ export interface CSSProperties extends CustomCssProperties {}
638
+ }
@@ -0,0 +1,36 @@
1
+ // Generated by `helix-svelte-types`. Do not edit.
2
+ //
3
+ // Svelte binds a handler as `onhelix-input={…}`, which is the shape the JSX
4
+ // types already describe, so this augments `SvelteHTMLElements` with them
5
+ // rather than emitting a second copy that could disagree.
6
+ import type { CustomElements } from '@fusion.dev/helix-sandbox/jsx'
7
+ import type { HTMLAttributes } from 'svelte/elements'
8
+
9
+ // React's spellings, which Svelte reads another way or not at all.
10
+ type ReactOnly = 'className' | 'htmlFor' | 'key' | 'ref' | 'suppressHydrationWarning'
11
+
12
+ // The element a tag makes, where the DOM lib knows it.
13
+ type ElementOf<Tag extends string> = Tag extends keyof HTMLElementTagNameMap
14
+ ? HTMLElementTagNameMap[Tag]
15
+ : HTMLElement
16
+
17
+ // Svelte's attributes and lowercase events, then the Helix props and
18
+ // `onhelix-*` handlers Svelte's do not name. `onClick` and the other
19
+ // camel-case handlers are React's, and Svelte would read each as an event
20
+ // with a capital letter.
21
+ type Helix<Tag extends keyof CustomElements> = HTMLAttributes<ElementOf<Tag>> & {
22
+ [Key in keyof CustomElements[Tag] as Key extends
23
+ | keyof HTMLAttributes<ElementOf<Tag>>
24
+ | ReactOnly
25
+ | `on${Uppercase<string>}${string}`
26
+ ? never
27
+ : Key]: CustomElements[Tag][Key]
28
+ }
29
+
30
+ declare module 'svelte/elements' {
31
+ interface SvelteHTMLElements {
32
+ 'helix-sandbox-editor': Helix<'helix-sandbox-editor'>
33
+ }
34
+ }
35
+
36
+ export {}