@draftably/solid 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Byron Wall
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 CHANGED
@@ -1,3 +1,12 @@
1
- # Temporary Holding Version
1
+ # `@draftably/solid`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Draftably diagrams in Solid. `DraftDiagram` wraps the `<draft-diagram>` element from
4
+ `@draftably/runtime`, so every framework gets the same viewer: zoom, pan, keyboard outline, and
5
+ cleanup when it unmounts. Any number of diagrams can share a page.
6
+
7
+ ```sh
8
+ pnpm add @draftably/solid
9
+ ```
10
+
11
+ See [Use with your framework](https://draftably.dev/docs/frameworks) for the component, server
12
+ rendering with the `svg` prop, and a complete example.
@@ -0,0 +1,23 @@
1
+ /** `<DraftEditor>` for Solid: drag boxes and lines, and get the `.draft` source back. */
2
+ import type { DraftEditorElement } from '@draftably/editor/element';
3
+ import { type JSX } from 'solid-js';
4
+ export type { DraftEditorElement };
5
+ declare module 'solid-js' {
6
+ namespace JSX {
7
+ interface IntrinsicElements {
8
+ 'draft-editor': JSX.HTMLAttributes<DraftEditorElement> & {
9
+ source?: string;
10
+ };
11
+ }
12
+ }
13
+ }
14
+ export interface DraftEditorProps {
15
+ /** `.draft` source. Passing back the text from `onChange` does not redraw. */
16
+ source: string;
17
+ /** Receives the new source after every kept edit, undo and redo. */
18
+ onChange?: (source: string) => void;
19
+ ref?: (element: DraftEditorElement) => void;
20
+ class?: string;
21
+ style?: JSX.CSSProperties | string;
22
+ }
23
+ export declare function DraftEditor(props: DraftEditorProps): JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { createEffect, onCleanup, onMount } from 'solid-js';
2
+ export function DraftEditor(props) {
3
+ let el;
4
+ // The editor loads in the browser only, so server rendering and viewer-only pages skip it.
5
+ onMount(() => void import('@draftably/editor/element'));
6
+ createEffect(() => {
7
+ const node = el;
8
+ const onChange = props.onChange;
9
+ if (!node || !onChange)
10
+ return;
11
+ const listen = (event) => onChange(event.detail);
12
+ node.addEventListener('draft-change', listen);
13
+ onCleanup(() => node.removeEventListener('draft-change', listen));
14
+ });
15
+ return (<draft-editor ref={(node) => {
16
+ el = node;
17
+ props.ref?.(node);
18
+ }} source={props.source} class={props.class} style={props.style}/>);
19
+ }
@@ -0,0 +1,36 @@
1
+ /** `<DraftDiagram>` for Solid: the `<draft-diagram>` element with Solid props, a ref and `onUpdate`. */
2
+ import '@draftably/runtime/element';
3
+ import type { DraftDiagramElement } from '@draftably/runtime/element';
4
+ import type { UpdateResult, ViewerOptions } from '@draftably/runtime/viewer';
5
+ import { type JSX } from 'solid-js';
6
+ export type { DraftDiagramElement, UpdateResult, ViewerOptions };
7
+ declare module 'solid-js' {
8
+ namespace JSX {
9
+ interface IntrinsicElements {
10
+ 'draft-diagram': JSX.HTMLAttributes<DraftDiagramElement> & {
11
+ source?: string;
12
+ state?: string;
13
+ label?: string;
14
+ };
15
+ }
16
+ }
17
+ }
18
+ export interface DraftDiagramProps {
19
+ /** `.draft` source. A change redraws the diagram and keeps the camera. */
20
+ source: string;
21
+ /** A declared emphasis state to show. */
22
+ state?: string | null;
23
+ /** The accessible name. */
24
+ label?: string;
25
+ /**
26
+ * Static SVG from `renderSvg(source, { target: 'inline', idPrefix })`, shown until the viewer
27
+ * draws. Server rendering and readers without JavaScript see it.
28
+ */
29
+ svg?: string;
30
+ options?: ViewerOptions;
31
+ onUpdate?: (result: UpdateResult) => void;
32
+ ref?: (element: DraftDiagramElement) => void;
33
+ class?: string;
34
+ style?: JSX.CSSProperties | string;
35
+ }
36
+ export declare function DraftDiagram(props: DraftDiagramProps): JSX.Element;
package/dist/index.jsx ADDED
@@ -0,0 +1,25 @@
1
+ /** `<DraftDiagram>` for Solid: the `<draft-diagram>` element with Solid props, a ref and `onUpdate`. */
2
+ import '@draftably/runtime/element';
3
+ import { createEffect, onCleanup, Show } from 'solid-js';
4
+ export function DraftDiagram(props) {
5
+ let el;
6
+ createEffect(() => {
7
+ if (el && props.options)
8
+ el.options = props.options;
9
+ });
10
+ createEffect(() => {
11
+ const node = el;
12
+ const onUpdate = props.onUpdate;
13
+ if (!node || !onUpdate)
14
+ return;
15
+ const listen = (event) => onUpdate(event.detail);
16
+ node.addEventListener('draft-update', listen);
17
+ onCleanup(() => node.removeEventListener('draft-update', listen));
18
+ });
19
+ return (<draft-diagram ref={(node) => {
20
+ el = node;
21
+ props.ref?.(node);
22
+ }} source={props.source} state={props.state ?? undefined} label={props.label} class={props.class} style={props.style}>
23
+ <Show when={props.svg}>{svg => <div innerHTML={svg()}/>}</Show>
24
+ </draft-diagram>);
25
+ }
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@draftably/solid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Solid components for Draftably diagrams.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "solid": "./dist/index.jsx",
15
+ "default": "./dist/index.jsx"
16
+ },
17
+ "./editor": {
18
+ "types": "./dist/editor.d.ts",
19
+ "solid": "./dist/editor.jsx",
20
+ "default": "./dist/editor.jsx"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "sideEffects": false,
25
+ "dependencies": {
26
+ "@draftably/runtime": "0.1.0",
27
+ "@draftably/editor": "0.1.0"
28
+ },
29
+ "peerDependencies": {
30
+ "solid-js": "^1.8"
31
+ },
32
+ "engines": {
33
+ "node": ">=22.21.0"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/byronwall/draftably.git",
38
+ "directory": "packages/solid"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "registry": "https://registry.npmjs.org"
43
+ },
44
+ "scripts": {
45
+ "build": "node ../../scripts/build-frameworks.ts"
46
+ }
6
47
  }