@deckedout/visual-editor 1.0.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 +228 -0
- package/dist/index.d.mts +1045 -0
- package/dist/index.d.ts +1045 -0
- package/dist/index.js +4037 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3992 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DeckedOut Team
|
|
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,228 @@
|
|
|
1
|
+
# @deckedout/visual-editor
|
|
2
|
+
|
|
3
|
+
A flexible, drag-and-drop visual editor built with React and Konva for creating interactive canvases with customizable elements.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **Visual Canvas Editor**: Drag, resize, and rotate elements on a canvas
|
|
8
|
+
- 🔧 **Extensible Element System**: Create custom element types with renderers
|
|
9
|
+
- 📐 **Smart Snapping**: Automatic alignment guides and grid snapping
|
|
10
|
+
- 🎯 **Inspector Panel**: Dynamic property editing for selected elements
|
|
11
|
+
- 📦 **Layer Management**: Organize elements with a layer panel
|
|
12
|
+
- 🎭 **Multiple Modes**: Edit and preview modes
|
|
13
|
+
- 📸 **Export Support**: Export canvas to JSON or image formats
|
|
14
|
+
- 🎨 **Asset Management**: Built-in asset picker for images
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @deckedout/visual-editor
|
|
20
|
+
# or
|
|
21
|
+
yarn add @deckedout/visual-editor
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @deckedout/visual-editor
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Peer Dependencies
|
|
27
|
+
|
|
28
|
+
Make sure you have the required peer dependencies installed:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install react react-dom
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Tailwind CSS (Optional)
|
|
35
|
+
|
|
36
|
+
This package uses Tailwind CSS. If you're using Tailwind in your project, add the package to your `tailwind.config.js`:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
module.exports = {
|
|
40
|
+
content: [
|
|
41
|
+
// ... your other content
|
|
42
|
+
'./node_modules/@deckedout/visual-editor/dist/**/*.{js,mjs}',
|
|
43
|
+
],
|
|
44
|
+
// ... rest of config
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you're not using Tailwind, you can import the pre-built styles:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import '@deckedout/visual-editor/styles';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { VisualEditorWorkspace } from '@deckedout/visual-editor';
|
|
58
|
+
import { useState } from 'react';
|
|
59
|
+
|
|
60
|
+
function App() {
|
|
61
|
+
const [mode, setMode] = useState('edit');
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div style={{ width: '100vw', height: '100vh' }}>
|
|
65
|
+
<VisualEditorWorkspace
|
|
66
|
+
canvasWidth={800}
|
|
67
|
+
canvasHeight={600}
|
|
68
|
+
mode={mode}
|
|
69
|
+
showInspector={true}
|
|
70
|
+
showLayers={true}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Core Components
|
|
78
|
+
|
|
79
|
+
### VisualEditorWorkspace
|
|
80
|
+
|
|
81
|
+
The main workspace component that includes the canvas, inspector, and layers panel.
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
<VisualEditorWorkspace
|
|
85
|
+
canvasWidth={800}
|
|
86
|
+
canvasHeight={600}
|
|
87
|
+
mode="edit" // 'edit' | 'preview'
|
|
88
|
+
showInspector={true}
|
|
89
|
+
showLayers={true}
|
|
90
|
+
backgroundColor="#ffffff"
|
|
91
|
+
onExport={(data) => console.log(data)}
|
|
92
|
+
/>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### VisualEditor
|
|
96
|
+
|
|
97
|
+
The core editor component without the workspace UI.
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { VisualEditor } from '@deckedout/visual-editor';
|
|
101
|
+
|
|
102
|
+
<VisualEditor
|
|
103
|
+
canvasWidth={800}
|
|
104
|
+
canvasHeight={600}
|
|
105
|
+
mode="edit"
|
|
106
|
+
elements={elements}
|
|
107
|
+
onElementsChange={setElements}
|
|
108
|
+
/>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Custom Elements
|
|
112
|
+
|
|
113
|
+
Create custom element types by implementing the `ElementRenderer` interface:
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { ElementRenderer, EditorElement } from '@deckedout/visual-editor';
|
|
117
|
+
|
|
118
|
+
export const customElementRenderer: ElementRenderer = {
|
|
119
|
+
type: 'custom',
|
|
120
|
+
name: 'Custom Element',
|
|
121
|
+
icon: '🎨',
|
|
122
|
+
|
|
123
|
+
// Default props when creating new element
|
|
124
|
+
defaultProps: {
|
|
125
|
+
color: '#000000',
|
|
126
|
+
text: 'Hello World',
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
// Inspector fields for property editing
|
|
130
|
+
inspectorFields: [
|
|
131
|
+
{
|
|
132
|
+
name: 'text',
|
|
133
|
+
label: 'Text',
|
|
134
|
+
type: 'text',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'color',
|
|
138
|
+
label: 'Color',
|
|
139
|
+
type: 'color',
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
|
|
143
|
+
// Render function for the element
|
|
144
|
+
render: (element, isSelected, isPreview) => {
|
|
145
|
+
return (
|
|
146
|
+
<div style={{ color: element.props.color }}>
|
|
147
|
+
{element.props.text}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Register your custom element:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { globalElementRegistry } from '@deckedout/visual-editor';
|
|
158
|
+
|
|
159
|
+
globalElementRegistry.register(customElementRenderer);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## API Reference
|
|
163
|
+
|
|
164
|
+
### Types
|
|
165
|
+
|
|
166
|
+
- `EditorElement`: Base element type with position, size, rotation, etc.
|
|
167
|
+
- `ElementRenderer`: Interface for custom element renderers
|
|
168
|
+
- `EditorAPI`: API for programmatic control
|
|
169
|
+
- `EditorMode`: 'edit' | 'preview'
|
|
170
|
+
- `InspectorFieldSchema`: Field configuration for the inspector
|
|
171
|
+
|
|
172
|
+
### Hooks
|
|
173
|
+
|
|
174
|
+
- `useEditorState()`: Access editor state and actions
|
|
175
|
+
- `useElementRegistry()`: Access element registry
|
|
176
|
+
|
|
177
|
+
### Utilities
|
|
178
|
+
|
|
179
|
+
- `globalElementRegistry`: Global registry for element types
|
|
180
|
+
- Built-in elements: `textElementRenderer`, `imageElementRenderer`
|
|
181
|
+
|
|
182
|
+
## Examples
|
|
183
|
+
|
|
184
|
+
### Basic Editor
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import { VisualEditorWorkspace } from '@deckedout/visual-editor';
|
|
188
|
+
|
|
189
|
+
function BasicEditor() {
|
|
190
|
+
return (
|
|
191
|
+
<div style={{ width: '100%', height: '600px' }}>
|
|
192
|
+
<VisualEditorWorkspace
|
|
193
|
+
canvasWidth={800}
|
|
194
|
+
canvasHeight={600}
|
|
195
|
+
/>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### With Custom Elements
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
import {
|
|
205
|
+
VisualEditorWorkspace,
|
|
206
|
+
globalElementRegistry,
|
|
207
|
+
textElementRenderer,
|
|
208
|
+
imageElementRenderer
|
|
209
|
+
} from '@deckedout/visual-editor';
|
|
210
|
+
import { myCustomElement } from './elements';
|
|
211
|
+
|
|
212
|
+
// Register elements
|
|
213
|
+
globalElementRegistry.register(textElementRenderer);
|
|
214
|
+
globalElementRegistry.register(imageElementRenderer);
|
|
215
|
+
globalElementRegistry.register(myCustomElement);
|
|
216
|
+
|
|
217
|
+
function EditorWithCustomElements() {
|
|
218
|
+
return <VisualEditorWorkspace canvasWidth={800} canvasHeight={600} />;
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT
|
|
225
|
+
|
|
226
|
+
## Contributing
|
|
227
|
+
|
|
228
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|