@peteai/presentation-editor 0.0.1 → 0.0.2
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/README.md
CHANGED
|
@@ -1,58 +1,192 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @peteai/presentation-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Introduction
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This project is a Svelte component library which lets you create a customizable presentation editors.
|
|
6
6
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
If you're seeing this, you've probably already done this step. Congrats!
|
|
7
|
+
## Install
|
|
10
8
|
|
|
11
9
|
```bash
|
|
12
|
-
|
|
13
|
-
npx sv create
|
|
14
|
-
|
|
15
|
-
# create a new project in my-app
|
|
16
|
-
npx sv create my-app
|
|
10
|
+
npm install @peteai/presentation-editor
|
|
17
11
|
```
|
|
18
12
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
## Types
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
type Image = {
|
|
17
|
+
id: string;
|
|
18
|
+
src: string;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface BaseLayer {
|
|
24
|
+
id: string;
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
rotate: number | null;
|
|
30
|
+
opacity: number | null;
|
|
31
|
+
sortOrder: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface HtmlLayer extends BaseLayer {
|
|
35
|
+
type: 'html';
|
|
36
|
+
scale: number | null;
|
|
37
|
+
html: JSONContent;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type LayerBorder = {
|
|
41
|
+
borderStyle: 'solid' | 'dashed' | 'dotted' | null;
|
|
42
|
+
borderWidth: number | null;
|
|
43
|
+
borderColor: string | null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
interface ImageLayer extends BaseLayer, LayerBorder {
|
|
47
|
+
type: 'image';
|
|
48
|
+
scale: number | null;
|
|
49
|
+
image: Image;
|
|
50
|
+
offsetX: number | null;
|
|
51
|
+
offsetY: number | null;
|
|
52
|
+
cornerRadius: number | null;
|
|
53
|
+
flipX: boolean;
|
|
54
|
+
flipY: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type Layer = HtmlLayer | ImageLayer;
|
|
58
|
+
|
|
59
|
+
type Slide = {
|
|
60
|
+
id: string;
|
|
61
|
+
backgroundColor: string | null;
|
|
62
|
+
layers: Layer[];
|
|
63
|
+
sortOrder: number;
|
|
64
|
+
};
|
|
28
65
|
```
|
|
29
66
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
## Building
|
|
67
|
+
### Html editor
|
|
33
68
|
|
|
34
|
-
|
|
69
|
+
PresentationEditor is using `Tiptap` editor for `HtmlLayer` content editing.
|
|
35
70
|
|
|
36
|
-
|
|
37
|
-
npm run package
|
|
38
|
-
```
|
|
71
|
+
`JSONContent` type provided by `@tiptap/core` is used for html content of `HtmlLayer` to store data in json format.
|
|
39
72
|
|
|
40
|
-
|
|
73
|
+
## Settings
|
|
41
74
|
|
|
42
|
-
|
|
43
|
-
npm run build
|
|
44
|
-
```
|
|
75
|
+
The PresentationEditor component accepts a bunch of settings. Here is a typescript definition of all available settings:
|
|
45
76
|
|
|
46
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
interface BaseOptions {
|
|
79
|
+
images?: Image[];
|
|
80
|
+
width?: number;
|
|
81
|
+
height?: number;
|
|
82
|
+
generateId?: () => string;
|
|
83
|
+
onImageUpload?: (file: File) => Promise<Image>;
|
|
84
|
+
onLayerAdd?: (slideId: string, layer: Layer) => Promise<Layer>;
|
|
85
|
+
onLayerUpdate?: (slideId: string, layerId: string, layerType: string, changes: object) => void;
|
|
86
|
+
onLayerRemove?: (slideId: string, layerId: string, layerType: string) => Promise<void>;
|
|
87
|
+
}
|
|
47
88
|
|
|
48
|
-
|
|
89
|
+
interface MultipleModeOption extends BaseOptions {
|
|
90
|
+
mode?: 'multiple';
|
|
91
|
+
slides?: Slide[];
|
|
92
|
+
onSlideAdd?: (slide: Slide) => Promise<Slide>;
|
|
93
|
+
onSlideUpdate?: (slideId: string, changes: object) => void;
|
|
94
|
+
onSlideRemove?: (slideId: string) => Promise<void>;
|
|
95
|
+
}
|
|
49
96
|
|
|
50
|
-
|
|
97
|
+
interface SingleModeOption extends BaseOptions {
|
|
98
|
+
mode: 'single';
|
|
99
|
+
slide?: Slide;
|
|
100
|
+
}
|
|
51
101
|
|
|
52
|
-
|
|
102
|
+
export type PresentationEditorOptions = MultipleModeOption | SingleModeOption;
|
|
103
|
+
```
|
|
53
104
|
|
|
54
|
-
|
|
105
|
+
## Getting Started
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { createEditor } from '@peteai/presentation-editor';
|
|
109
|
+
|
|
110
|
+
// images list
|
|
111
|
+
const images: Image[];
|
|
112
|
+
// slides list
|
|
113
|
+
const slides: Slide[];
|
|
114
|
+
|
|
115
|
+
const editor = new createEditor({
|
|
116
|
+
target: document.querySelector('.target'),
|
|
117
|
+
props: {
|
|
118
|
+
// function for new slides and layers ids generation
|
|
119
|
+
generateId: () => crypto.randomUUID(),
|
|
120
|
+
images,
|
|
121
|
+
slides,
|
|
122
|
+
onImageUpload: async (file) => {
|
|
123
|
+
// called when user uploads image
|
|
124
|
+
// callback to store file and return Image
|
|
125
|
+
// which will be added to the images list
|
|
126
|
+
// new ImageLayer gonna be created if image file was dropped on slide
|
|
127
|
+
// ...
|
|
128
|
+
return image;
|
|
129
|
+
},
|
|
130
|
+
onSlideAdd: async (slide) => {
|
|
131
|
+
// called when new slide is added
|
|
132
|
+
// expect Slide to be returned to overwrite newly created slide
|
|
133
|
+
},
|
|
134
|
+
onSlideUpdate: async (slideId, values) => {
|
|
135
|
+
// called when slide is updated
|
|
136
|
+
},
|
|
137
|
+
onSlideRemove: async (slideId) => {
|
|
138
|
+
// called when slide is removed
|
|
139
|
+
},
|
|
140
|
+
onLayerAdd: async (slideId, layer) => {
|
|
141
|
+
// called when new layer is added
|
|
142
|
+
// expect Slide to be returned to overwrite newly created layer
|
|
143
|
+
},
|
|
144
|
+
onLayerUpdate: async (slideId, layerId, layerType, values) => {
|
|
145
|
+
// called when layer is updated
|
|
146
|
+
},
|
|
147
|
+
onLayerRemove: async (slideId, layerId, layerType) => {
|
|
148
|
+
// called when layer is removed
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
```
|
|
55
153
|
|
|
56
|
-
|
|
57
|
-
|
|
154
|
+
## Single Slide Mode
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { createEditor } from '@peteai/presentation-editor';
|
|
158
|
+
|
|
159
|
+
// images list
|
|
160
|
+
const images: Image[];
|
|
161
|
+
// slides list
|
|
162
|
+
const slide: Slide;
|
|
163
|
+
|
|
164
|
+
const editor = new createEditor({
|
|
165
|
+
target: document.querySelector('.target'),
|
|
166
|
+
props: {
|
|
167
|
+
mode: 'single',
|
|
168
|
+
// function for new slides and layers ids generation
|
|
169
|
+
generateId: () => crypto.randomUUID(),
|
|
170
|
+
images,
|
|
171
|
+
slide,
|
|
172
|
+
onImageUpload: async (file) => {
|
|
173
|
+
// called when user uploads image
|
|
174
|
+
// callback to store file and return Image
|
|
175
|
+
// which will be added to the images list
|
|
176
|
+
// new ImageLayer gonna be created if image file was dropped on slide
|
|
177
|
+
// ...
|
|
178
|
+
return image;
|
|
179
|
+
},
|
|
180
|
+
onLayerAdd: async (slideId, layer) => {
|
|
181
|
+
// called when new layer is added
|
|
182
|
+
// expect Slide to be returned to overwrite newly created layer
|
|
183
|
+
},
|
|
184
|
+
onLayerUpdate: async (slideId, layerId, layerType, values) => {
|
|
185
|
+
// called when layer is updated
|
|
186
|
+
},
|
|
187
|
+
onLayerRemove: async (slideId, layerId, layerType) => {
|
|
188
|
+
// called when layer is removed
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
});
|
|
58
192
|
```
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
let editorOptions: PresentationEditorOptions = $props();
|
|
21
21
|
|
|
22
|
-
const presentationEditor = new PresentationEditor(editorOptions);
|
|
22
|
+
export const presentationEditor = new PresentationEditor(editorOptions);
|
|
23
23
|
|
|
24
24
|
let activeSidebarTab: ActiveSidebar = $state('images');
|
|
25
25
|
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
let sliderValue = $state(convertZoomToSlider(presentationEditor.zoom));
|
|
67
|
-
const setZoom = (zoom: number) => {
|
|
67
|
+
export const setZoom = (zoom: number) => {
|
|
68
68
|
sliderValue = convertZoomToSlider(zoom);
|
|
69
69
|
};
|
|
70
70
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { PresentationEditor } from './presentation-editor.svelte.js';
|
|
2
|
-
declare const PresentationEditor:
|
|
3
|
-
fillScreen: () => Promise<void>;
|
|
4
|
-
fitToScreen: () => void;
|
|
5
|
-
}, "">;
|
|
2
|
+
declare const PresentationEditor: any;
|
|
6
3
|
type PresentationEditor = ReturnType<typeof PresentationEditor>;
|
|
7
4
|
export default PresentationEditor;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { PresentationEditor } from './components/presentation-editor/index.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
fillScreen: () => Promise<void>;
|
|
7
|
-
fitToScreen: () => void;
|
|
2
|
+
import type { PresentationEditorOptions } from './components/presentation-editor/presentation-editor.svelte.js';
|
|
3
|
+
type createEditorOptions = {
|
|
4
|
+
target: Document | Element | ShadowRoot;
|
|
5
|
+
props: PresentationEditorOptions;
|
|
8
6
|
};
|
|
7
|
+
declare const createEditor: (options: createEditorOptions) => Record<string, any>;
|
|
9
8
|
export { PresentationEditor, createEditor };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// Reexport your entry components here
|
|
2
2
|
import { mount } from 'svelte';
|
|
3
3
|
import { PresentationEditor } from './components/presentation-editor/index.js';
|
|
4
|
-
const createEditor = (
|
|
5
|
-
target,
|
|
6
|
-
props,
|
|
7
|
-
});
|
|
4
|
+
const createEditor = (options) => mount(PresentationEditor, options);
|
|
8
5
|
export { PresentationEditor, createEditor };
|