@draftably/react 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 +21 -0
- package/README.md +11 -2
- package/dist/editor.d.ts +13 -0
- package/dist/editor.js +17 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +21 -0
- package/package.json +44 -3
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
|
-
#
|
|
1
|
+
# `@draftably/react`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Draftably diagrams in React. `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/react
|
|
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.
|
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** `<DraftEditor>` for React 19: drag boxes and lines, and get the `.draft` source back. */
|
|
2
|
+
import type { DraftEditorElement } from '@draftably/editor/element';
|
|
3
|
+
import { type CSSProperties } from 'react';
|
|
4
|
+
export type { DraftEditorElement };
|
|
5
|
+
export interface DraftEditorProps {
|
|
6
|
+
/** `.draft` source. Passing back the text from `onChange` does not redraw. */
|
|
7
|
+
source: string;
|
|
8
|
+
/** Receives the new source after every kept edit, undo and redo. */
|
|
9
|
+
onChange?: (source: string) => void;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
}
|
|
13
|
+
export declare const DraftEditor: import("react").ForwardRefExoticComponent<DraftEditorProps & import("react").RefAttributes<DraftEditorElement | null>>;
|
package/dist/editor.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createElement, forwardRef, useEffect, useImperativeHandle, useRef, } from 'react';
|
|
3
|
+
export const DraftEditor = forwardRef(function DraftEditor({ source, onChange, className, style }, ref) {
|
|
4
|
+
const el = useRef(null);
|
|
5
|
+
useImperativeHandle(ref, () => el.current, []);
|
|
6
|
+
// The editor loads in the browser only, so server rendering and viewer-only pages skip it.
|
|
7
|
+
useEffect(() => void import('@draftably/editor/element'), []);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const node = el.current;
|
|
10
|
+
if (!node || !onChange)
|
|
11
|
+
return;
|
|
12
|
+
const listen = (event) => onChange(event.detail);
|
|
13
|
+
node.addEventListener('draft-change', listen);
|
|
14
|
+
return () => node.removeEventListener('draft-change', listen);
|
|
15
|
+
}, [onChange]);
|
|
16
|
+
return createElement('draft-editor', { ref: el, source, className, style });
|
|
17
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** `<DraftDiagram>` for React 19: the `<draft-diagram>` element with React 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 CSSProperties } from 'react';
|
|
6
|
+
export type { DraftDiagramElement, UpdateResult, ViewerOptions };
|
|
7
|
+
export interface DraftDiagramProps {
|
|
8
|
+
/** `.draft` source. A change redraws the diagram and keeps the camera. */
|
|
9
|
+
source: string;
|
|
10
|
+
/** A declared emphasis state to show. */
|
|
11
|
+
state?: string | null;
|
|
12
|
+
/** The accessible name. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Static SVG from `renderSvg(source, { target: 'inline', idPrefix })`, shown until the viewer
|
|
16
|
+
* draws. Server rendering and readers without JavaScript see it.
|
|
17
|
+
*/
|
|
18
|
+
svg?: string;
|
|
19
|
+
options?: ViewerOptions;
|
|
20
|
+
onUpdate?: (result: UpdateResult) => void;
|
|
21
|
+
className?: string;
|
|
22
|
+
style?: CSSProperties;
|
|
23
|
+
}
|
|
24
|
+
export declare const DraftDiagram: import("react").ForwardRefExoticComponent<DraftDiagramProps & import("react").RefAttributes<DraftDiagramElement | null>>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/** `<DraftDiagram>` for React 19: the `<draft-diagram>` element with React props, a ref and `onUpdate`. */
|
|
3
|
+
import '@draftably/runtime/element';
|
|
4
|
+
import { createElement, forwardRef, useEffect, useImperativeHandle, useRef, } from 'react';
|
|
5
|
+
export const DraftDiagram = forwardRef(function DraftDiagram({ source, state, label, svg, options, onUpdate, className, style }, ref) {
|
|
6
|
+
const el = useRef(null);
|
|
7
|
+
useImperativeHandle(ref, () => el.current, []);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (el.current && options)
|
|
10
|
+
el.current.options = options;
|
|
11
|
+
}, [options]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const node = el.current;
|
|
14
|
+
if (!node || !onUpdate)
|
|
15
|
+
return;
|
|
16
|
+
const listen = (event) => onUpdate(event.detail);
|
|
17
|
+
node.addEventListener('draft-update', listen);
|
|
18
|
+
return () => node.removeEventListener('draft-update', listen);
|
|
19
|
+
}, [onUpdate]);
|
|
20
|
+
return createElement('draft-diagram', { ref: el, source, state: state ?? undefined, label, className, style }, svg ? createElement('div', { dangerouslySetInnerHTML: { __html: svg } }) : null);
|
|
21
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftably/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React 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
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./editor": {
|
|
18
|
+
"types": "./dist/editor.d.ts",
|
|
19
|
+
"import": "./dist/editor.js",
|
|
20
|
+
"default": "./dist/editor.js"
|
|
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
|
+
"react": ">=19"
|
|
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/react"
|
|
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
|
}
|