@getdraft/plugin 1.15.1 → 1.16.1
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/.turbo/turbo-dev-tsc.log +6 -0
- package/.turbo/turbo-eslint.log +12 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +297 -339
- package/dist/index.es.js.map +1 -1
- package/dist/index.iife.js +2 -2
- package/dist/index.iife.js.map +1 -1
- package/dist/types/index.d.ts +337 -16
- package/package.json +5 -5
- package/src/plugin.ts +1 -1
- package/src/types.ts +39 -23
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.ts +4 -3
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/plugin.d.ts +0 -39
- package/dist/types/plugin.d.ts.map +0 -1
- package/dist/types/routes.d.ts +0 -3
- package/dist/types/routes.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -221
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utils.d.ts +0 -5
- package/dist/types/utils.d.ts.map +0 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1,16 +1,337 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
export declare type AnalyticsParams = DuplicateEvent | DestroyEvent | EditEvent | HistoryEvent | PreviewEvent | ToolbarMoveEvent | BlockInsertEvent | BlockSaveEvent | BlockDestroyEvent | DropEvent;
|
|
2
|
+
|
|
3
|
+
export declare type AsyncEventHandler<P, R> = (params: P) => Promise<R>;
|
|
4
|
+
|
|
5
|
+
export declare interface AutosaveParams {
|
|
6
|
+
json: TemplateJSON;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare interface BlockDestroyEvent {
|
|
10
|
+
name: 'block-destroy';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare interface BlockInsertEvent {
|
|
14
|
+
name: 'block-insert';
|
|
15
|
+
context: 'double-click';
|
|
16
|
+
blockType: BlockType;
|
|
17
|
+
blockName: string;
|
|
18
|
+
blockCategory: string | number;
|
|
19
|
+
blockId: string | number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export declare interface BlockSaveEvent {
|
|
23
|
+
name: 'block-save';
|
|
24
|
+
blockType: 'user';
|
|
25
|
+
blockName: string;
|
|
26
|
+
blockCategory: string | number;
|
|
27
|
+
blockId: string | number;
|
|
28
|
+
elements: Record<string, number> & {
|
|
29
|
+
sum: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export declare type BlockType = 'system' | 'user';
|
|
34
|
+
|
|
35
|
+
export declare interface DestroyEvent {
|
|
36
|
+
name: 'destroy';
|
|
37
|
+
context: HotkeyContext | ToolbarContext | UnitSettingsContext;
|
|
38
|
+
unitType: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare type DndDragContext = 'canvas' | 'list' | 'palette';
|
|
42
|
+
|
|
43
|
+
export declare type DndDropContext = 'dropline' | 'placeholder' | 'empty-placeholder';
|
|
44
|
+
|
|
45
|
+
export declare type DndDropTarget = 'root' | 'section' | 'column' | 'element';
|
|
46
|
+
|
|
47
|
+
export declare class DraftError extends Error {
|
|
48
|
+
readonly code: string;
|
|
49
|
+
constructor(code: string, message: string);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare const DraftPlugin: PluginWrapper;
|
|
53
|
+
export default DraftPlugin;
|
|
54
|
+
|
|
55
|
+
export declare interface DropEvent {
|
|
56
|
+
name: 'drop';
|
|
57
|
+
drag?: DropEventDragMeta;
|
|
58
|
+
dropzone?: DropEventDropzoneMeta;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare interface DropEventDragMeta {
|
|
62
|
+
context?: DndDragContext;
|
|
63
|
+
layer?: 'element' | 'section' | 'column' | 'root';
|
|
64
|
+
type?: string | string[];
|
|
65
|
+
blockCategory?: string | number;
|
|
66
|
+
blockId?: string | number;
|
|
67
|
+
blockName?: string;
|
|
68
|
+
blockType?: BlockType;
|
|
69
|
+
alt?: boolean;
|
|
70
|
+
dropKind?: 'create' | 'move';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export declare interface DropEventDropzoneMeta {
|
|
74
|
+
context?: DndDropContext;
|
|
75
|
+
dropTarget?: DndDropTarget;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare interface DuplicateEvent {
|
|
79
|
+
name: 'duplicate';
|
|
80
|
+
context: HotkeyContext | ToolbarContext | UnitSettingsContext;
|
|
81
|
+
unitType: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare interface EditEvent {
|
|
85
|
+
name: 'edit';
|
|
86
|
+
context: OverlayContext | ToolbarContext;
|
|
87
|
+
unitType: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare enum EditorMenu {
|
|
91
|
+
Audit = "audit",
|
|
92
|
+
Guide = "guide",
|
|
93
|
+
Style = "style",
|
|
94
|
+
Blocks = "blocks"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export declare interface ErrorParams {
|
|
98
|
+
message: string;
|
|
99
|
+
code?: string;
|
|
100
|
+
details?: unknown;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export declare type EventHandler<T> = (data: T) => void;
|
|
104
|
+
|
|
105
|
+
export declare interface ExitParams extends SaveParams {
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export declare interface ExportAsFileParams {
|
|
109
|
+
blob: Blob;
|
|
110
|
+
fileName: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export declare type HandlerParams<H> = H extends EventHandler<infer P> | AsyncEventHandler<infer P, unknown> ? P : never;
|
|
114
|
+
|
|
115
|
+
export declare interface Handlers {
|
|
116
|
+
ready: EventHandler<ReadyParams>;
|
|
117
|
+
error: EventHandler<ErrorParams>;
|
|
118
|
+
save: EventHandler<SaveParams>;
|
|
119
|
+
exit: EventHandler<ExitParams>;
|
|
120
|
+
notification: EventHandler<NotificationParams>;
|
|
121
|
+
autosave: EventHandler<AutosaveParams>;
|
|
122
|
+
toggleGrid: EventHandler<ToggleGridParams>;
|
|
123
|
+
togglePreview: EventHandler<TogglePreviewParams>;
|
|
124
|
+
toggleViewMode: EventHandler<ToggleViewModeParams>;
|
|
125
|
+
toggleMenu: EventHandler<ToggleMenuParams>;
|
|
126
|
+
history: EventHandler<HistoryParams>;
|
|
127
|
+
analytics: EventHandler<AnalyticsParams>;
|
|
128
|
+
openGallery: EventHandler<(url?: string) => Promise<void>>;
|
|
129
|
+
uploadImage: AsyncEventHandler<UploadImageParams, string>;
|
|
130
|
+
loadPersonalization: AsyncEventHandler<void, PersonalizationDictionary>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare interface HistoryEvent {
|
|
134
|
+
name: 'history';
|
|
135
|
+
type: 'undo' | 'redo';
|
|
136
|
+
context: HotkeyContext;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export declare interface HistoryParams {
|
|
140
|
+
hasUndos: boolean;
|
|
141
|
+
hasRedos: boolean;
|
|
142
|
+
currentStep: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export declare type HotkeyContext = 'hotkey';
|
|
146
|
+
|
|
147
|
+
export declare interface ImageParams {
|
|
148
|
+
url: string;
|
|
149
|
+
originalWidth: number;
|
|
150
|
+
originalHeight: number;
|
|
151
|
+
ratio: number;
|
|
152
|
+
fileSize: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export declare type MessageData = {
|
|
156
|
+
source: string;
|
|
157
|
+
event: string;
|
|
158
|
+
ok?: boolean;
|
|
159
|
+
code?: string;
|
|
160
|
+
message?: string;
|
|
161
|
+
action?: string;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
declare interface Notification_2 {
|
|
165
|
+
intent: 'error' | 'info' | 'success' | 'warning';
|
|
166
|
+
errorDetails?: object;
|
|
167
|
+
message?: string;
|
|
168
|
+
title: string;
|
|
169
|
+
}
|
|
170
|
+
export { Notification_2 as Notification }
|
|
171
|
+
|
|
172
|
+
export declare type NotificationParams = Notification_2;
|
|
173
|
+
|
|
174
|
+
export declare type OnInitParams = MessageEvent<{
|
|
175
|
+
source: string;
|
|
176
|
+
event: 'loaded' | unknown;
|
|
177
|
+
}>;
|
|
178
|
+
|
|
179
|
+
export declare interface OpenGalleryParams {
|
|
180
|
+
id: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export declare type OverlayContext = 'overlay-click' | 'overlay-double-click';
|
|
184
|
+
|
|
185
|
+
export declare type PersonalizationDictionary = PersonalizationDictionaryItems;
|
|
186
|
+
|
|
187
|
+
declare type PersonalizationDictionaryEntry = {
|
|
188
|
+
name: string;
|
|
189
|
+
value: string;
|
|
190
|
+
} | {
|
|
191
|
+
groupName: string;
|
|
192
|
+
items: Array<{
|
|
193
|
+
name: string;
|
|
194
|
+
value: string;
|
|
195
|
+
}>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export declare type PersonalizationDictionaryItems = PersonalizationDictionaryEntry[];
|
|
199
|
+
|
|
200
|
+
export declare interface PluginConfig {
|
|
201
|
+
container: string;
|
|
202
|
+
locale?: string;
|
|
203
|
+
autosave?: boolean | {
|
|
204
|
+
interval: number;
|
|
205
|
+
};
|
|
206
|
+
token: string;
|
|
207
|
+
authData?: {
|
|
208
|
+
orgId: number;
|
|
209
|
+
projectId?: number;
|
|
210
|
+
};
|
|
211
|
+
pluginId: string;
|
|
212
|
+
apiUrl: string;
|
|
213
|
+
disableHotkeysPassing?: boolean;
|
|
214
|
+
__config?: object;
|
|
215
|
+
on: Partial<Handlers>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export declare class PluginInstance {
|
|
219
|
+
config: PluginConfig;
|
|
220
|
+
iframe: HTMLIFrameElement | null;
|
|
221
|
+
private hotkeysAttached;
|
|
222
|
+
private iframeOrigin;
|
|
223
|
+
constructor(config: PluginConfig);
|
|
224
|
+
private captureHotkeysEnabled;
|
|
225
|
+
private onHostHotkey;
|
|
226
|
+
private static HEARTBEAT_TIMEOUT;
|
|
227
|
+
private promisedIframeMethod;
|
|
228
|
+
private postEvent;
|
|
229
|
+
private onImageUpload;
|
|
230
|
+
private onLoadPersonalization;
|
|
231
|
+
private onGalleryOpen;
|
|
232
|
+
private triggerEvent;
|
|
233
|
+
private onMessage;
|
|
234
|
+
start({ template, templateName, uid, }: {
|
|
235
|
+
template: string | TemplateJSON;
|
|
236
|
+
uid: string | number;
|
|
237
|
+
templateName?: string;
|
|
238
|
+
}): void;
|
|
239
|
+
destroy: () => void;
|
|
240
|
+
changeTemplate(template: string | TemplateJSON, options?: {
|
|
241
|
+
templateName?: string;
|
|
242
|
+
uid?: string;
|
|
243
|
+
}): void;
|
|
244
|
+
toggleGrid(state?: boolean): void;
|
|
245
|
+
togglePreview(state?: boolean): void;
|
|
246
|
+
toggleMenu(menu?: EditorMenu | null): void;
|
|
247
|
+
toggleViewMode(viewMode: ViewMode): void;
|
|
248
|
+
undo(): void;
|
|
249
|
+
redo(): void;
|
|
250
|
+
save(): Promise<SaveParams>;
|
|
251
|
+
exit(): Promise<ExitParams>;
|
|
252
|
+
exportContent(): Promise<SaveParams>;
|
|
253
|
+
exportAsFile(): Promise<ExportAsFileParams>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
declare class PluginWrapper {
|
|
257
|
+
version: string;
|
|
258
|
+
create(config: PluginConfig): PluginInstance;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export declare interface PreviewEvent {
|
|
262
|
+
name: 'preview';
|
|
263
|
+
context: HotkeyContext;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export declare interface ReadyParams extends SaveParams {
|
|
267
|
+
lastSavedTemplate?: {
|
|
268
|
+
template: TemplateJSON;
|
|
269
|
+
date: Date;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export declare interface SaveParams {
|
|
274
|
+
json: TemplateJSON;
|
|
275
|
+
html: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export declare interface SerializedTemplate {
|
|
279
|
+
[key: string]: unknown;
|
|
280
|
+
parentId: string | null;
|
|
281
|
+
id: string;
|
|
282
|
+
parameters: object;
|
|
283
|
+
layer: string;
|
|
284
|
+
type: string;
|
|
285
|
+
children?: SerializedTemplate[];
|
|
286
|
+
meta?: {
|
|
287
|
+
[key: string]: unknown;
|
|
288
|
+
version: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export declare type TemplateJSON = SerializedTemplate;
|
|
293
|
+
|
|
294
|
+
export declare interface ToggleGridParams extends ToggleParams {
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export declare interface ToggleMenuParams {
|
|
298
|
+
menu: EditorMenu | null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
declare interface ToggleParams {
|
|
302
|
+
state: boolean;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export declare interface TogglePreviewParams extends ToggleParams {
|
|
306
|
+
json: TemplateJSON;
|
|
307
|
+
html: string;
|
|
308
|
+
darkHTML: string;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export declare interface ToggleViewModeParams {
|
|
312
|
+
mode: ViewMode;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export declare type ToolbarActionName = 'duplicate' | 'destroy' | 'edit' | 'up' | 'down';
|
|
316
|
+
|
|
317
|
+
export declare type ToolbarContext = 'toolbar';
|
|
318
|
+
|
|
319
|
+
export declare interface ToolbarMoveEvent {
|
|
320
|
+
name: 'up' | 'down';
|
|
321
|
+
context: ToolbarContext;
|
|
322
|
+
unitType: string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export declare type UnitSettingsContext = 'unit-settings';
|
|
326
|
+
|
|
327
|
+
export declare interface UploadImageParams {
|
|
328
|
+
file: string;
|
|
329
|
+
name: string;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export declare enum ViewMode {
|
|
333
|
+
Desktop = "desktop",
|
|
334
|
+
Mobile = "mobile"
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getdraft/plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
9
10
|
"import": "./dist/index.es.js",
|
|
10
|
-
"require": "./dist/index.cjs.js"
|
|
11
|
-
"types": "./dist/types/index.d.ts"
|
|
11
|
+
"require": "./dist/index.cjs.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"vite-plugin-dts": "4.
|
|
17
|
-
"@types
|
|
16
|
+
"vite-plugin-dts": "4.5.4",
|
|
17
|
+
"@getdraft/types": "^1.0.0",
|
|
18
18
|
"@getdraft/eslint-config-ts": "^1.0.0",
|
|
19
19
|
"@getdraft/prettier": "^1.0.0"
|
|
20
20
|
},
|
package/src/plugin.ts
CHANGED
|
@@ -121,7 +121,7 @@ export class PluginInstance {
|
|
|
121
121
|
private static HEARTBEAT_TIMEOUT = 4000;
|
|
122
122
|
|
|
123
123
|
private promisedIframeMethod<T>(eventName: string) {
|
|
124
|
-
let timer:
|
|
124
|
+
let timer: Timeout | null = null;
|
|
125
125
|
let listener: ((e: MessageEvent<MessageData>) => void) | null = null;
|
|
126
126
|
|
|
127
127
|
const cleanup = () => {
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
export enum EditorMenu {
|
|
2
|
+
Audit = 'audit',
|
|
3
|
+
Guide = 'guide',
|
|
4
|
+
Style = 'style',
|
|
5
|
+
Blocks = 'blocks',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export enum ViewMode {
|
|
9
|
+
Desktop = 'desktop',
|
|
10
|
+
Mobile = 'mobile',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Notification {
|
|
14
|
+
intent: 'error' | 'info' | 'success' | 'warning';
|
|
15
|
+
errorDetails?: object;
|
|
16
|
+
message?: string;
|
|
17
|
+
title: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PersonalizationDictionaryEntry =
|
|
21
|
+
| { name: string; value: string }
|
|
22
|
+
| { groupName: string; items: Array<{ name: string; value: string }> };
|
|
23
|
+
|
|
24
|
+
export type PersonalizationDictionaryItems = PersonalizationDictionaryEntry[];
|
|
25
|
+
|
|
26
|
+
export interface SerializedTemplate {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
parentId: string | null;
|
|
29
|
+
id: string;
|
|
30
|
+
parameters: object;
|
|
31
|
+
layer: string;
|
|
32
|
+
type: string;
|
|
33
|
+
children?: SerializedTemplate[];
|
|
34
|
+
meta?: { [key: string]: unknown; version: string };
|
|
35
|
+
}
|
|
36
|
+
|
|
1
37
|
export type EventHandler<T> = (data: T) => void;
|
|
2
38
|
|
|
3
39
|
export type AsyncEventHandler<P, R> = (params: P) => Promise<R>;
|
|
@@ -36,18 +72,6 @@ export type OnInitParams = MessageEvent<{
|
|
|
36
72
|
event: 'loaded' | unknown;
|
|
37
73
|
}>;
|
|
38
74
|
|
|
39
|
-
export enum EditorMenu {
|
|
40
|
-
Audit = 'audit',
|
|
41
|
-
Guide = 'guide',
|
|
42
|
-
Style = 'style',
|
|
43
|
-
Blocks = 'blocks',
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export enum ViewMode {
|
|
47
|
-
Desktop = 'desktop',
|
|
48
|
-
Mobile = 'mobile',
|
|
49
|
-
}
|
|
50
|
-
|
|
51
75
|
export interface ReadyParams extends SaveParams {
|
|
52
76
|
lastSavedTemplate?: {
|
|
53
77
|
template: TemplateJSON;
|
|
@@ -63,12 +87,7 @@ export interface ErrorParams {
|
|
|
63
87
|
|
|
64
88
|
export interface ExitParams extends SaveParams {}
|
|
65
89
|
|
|
66
|
-
export
|
|
67
|
-
intent: 'error' | 'info' | 'success' | 'warning';
|
|
68
|
-
errorDetails?: object;
|
|
69
|
-
message?: string;
|
|
70
|
-
title: string;
|
|
71
|
-
}
|
|
90
|
+
export type NotificationParams = Notification;
|
|
72
91
|
|
|
73
92
|
export interface OpenGalleryParams {
|
|
74
93
|
id: string;
|
|
@@ -117,12 +136,9 @@ export interface HistoryParams {
|
|
|
117
136
|
currentStep: number;
|
|
118
137
|
}
|
|
119
138
|
|
|
120
|
-
export type TemplateJSON =
|
|
139
|
+
export type TemplateJSON = SerializedTemplate;
|
|
121
140
|
|
|
122
|
-
export type PersonalizationDictionary =
|
|
123
|
-
| { name: string; value: string }
|
|
124
|
-
| { groupName: string; items: Array<{ name: string; value: string }> }
|
|
125
|
-
>;
|
|
141
|
+
export type PersonalizationDictionary = PersonalizationDictionaryItems;
|
|
126
142
|
|
|
127
143
|
export type ToolbarActionName =
|
|
128
144
|
| 'duplicate'
|