/
index.d.ts
476 lines (436 loc) · 13 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
declare module '*.yml';
interface BoltEditorConfig {
styles?: string[];
scripts?: string[];
}
interface Window {
HTMLLinkElement: typeof HTMLLinkElement;
}
interface GrapeTrait {
type: 'text' | 'select' | 'checkbox' | 'number' | 'color';
label?: string;
name: string;
default?: any;
options?: Array<string | {
value: string;
name: string;
}>;
}
declare module 'grapesjs' {
export function init(config: EditorConfig): Editor;
/**
* @link https://github.com/artf/grapesjs/blob/master/src/editor/config/config.js
*/
export interface EditorConfig {
stylePrefix?: string;
components?: string;
style?: string;
fromElement?: boolean;
/** renders editor on init */
autorender?: boolean;
/** Show an alert before unload the page with unsaved changes */
noticeOnUnload?: boolean;
showOffsets?: boolean;
showOffsetsSelected?: boolean;
forceClass?: boolean;
height?: string;
width?: string;
log?: Array<'debug' | 'info' | 'warning' | 'error'> | Array<string>;
baseCss?: string;
protectedCss?: string;
canvasCss?: string;
defaultCommand?: string;
showToolbar?: boolean;
allowScripts?: boolean;
showDevices?: boolean;
devicePreviewMode?: boolean;
mediaCondition?: string;
tagVarStart?: string;
tagVarEnd?: string;
keepEmptyTextNodes?: boolean;
jsInHtml?: boolean;
nativeDnD?: boolean;
multipleSelection?: boolean;
exportWrapper?: boolean;
wrappesIsBody?: boolean;
avoidInlineStyle?: boolean;
avoidDefaults?: boolean;
clearStyles?: boolean;
container?: HTMLElement | Element | string;
undoManager?: object;
plugins?: Array<(editor: Editor) => void>;
assetManager?: AssetManagerConfig | object;
canvas?: CanvasConfig;
layers?: object;
storageManager?: StorageManagerConfig | object;
// rte?: RichtTextEditorConfig | object;
// domComponents?: DomComponentsConfig | object;
modal?: ModalConfig | object;
// codeManager?: CodeManagerConfig | object;
panels?: PanelsConfig;
// commands?: CommandsConfig | object;
// cssComposer?: CssComposerConfig | object;
// selectorManager?: SelectorManagerConfig | object;
// deviceManager?: DeviceManagerConfig | object;
styleManager?: StyleManagerConfig | object;
blockManager?: {
appendTo?: HTMLElement | string;
blocks: BlockOptions[];
}
traitManager?: TraitManagerConfig | object;
textViewCode?: string;
keepUnusedStyles?: boolean;
multiFrames?: boolean;
}
export class Editor {
DomComponents: DomComponents;
BlockManager: BlockManager;
Panels: Panels;
Modal: Modal;
Canvas: Canvas;
getHtml(): string;
getJs(): string;
destroy(): void;
/** Total unsaved changes */
getDirtyCount(): number;
getContainer(): HTMLElement;
getComponents(): Array<object>;
on(event: GrapesEvent, callback: Function): Editor;
once(event: GrapesEvent, callback: Function): Editor;
/** Returns editor element */
render(): HTMLElement;
/** Returns editor element */
getEl(): HTMLElement;
/**
* Update editor dimensions and refresh data useful for positioning of tools
*
* This method could be useful when you update, for example, some position
* of the editor element (eg. canvas, panels, etc.) with CSS, where without
* refresh you'll get misleading position of tools (eg. rich text editor,
* component highlighter, etc.)
*/
refresh(): void;
}
interface Panels {
removeButton: (panelId: string, buttonId) => void;
addButton: (panelId: string, button: PanelButtonConfig) => void;
}
/**
* @link https://grapesjs.com/docs/api/component.html#component
* */
interface ComponentObject {
type?: string;
tagName?: string;
/** Indicates if it's possible to drag the component inside others. You can also specify a query string to indentify elements, eg. '.some-class[title=Hello], [data-gjs-type=column]' means you can drag the component only inside elements containing some-class class and Hello title, and column components. */
draggable?: boolean | string;
/** Indicates if it's possible to drop other components inside. You can use a query string as with draggable */
droppable?: boolean | string;
/** Indicates if its possible to highlight the component through the gui while editing */
highlightable?: boolean;
resizable?: boolean;
// Allow to edit the content of the component (used on Text components). Default: false
editable?: boolean;
// can copy/paste; default `true`
copyable?: boolean;
// Content of the component (not escaped) which will be appended before children rendering. Default: ''
// If the badge is visible when the component is selected
badgable?: boolean;
content?: string;
script?: string | Function;
// https://grapesjs.com/docs/modules/Traits.html
traits?: Array<string | GrapeTrait>;
// becomes HTML attributes
attributes?: {};
// Set an array of items to show up inside the toolbar when the component is selected (move, clone, delete). Eg. toolbar: [ { attributes: {class: 'fa fa-arrows'}, command: 'tlb-move' }, ... ]. By default, when toolbar property is falsy the editor will add automatically commands like move, delete, etc. based on its properties.
toolbar?: {}[];
components?: Array<ComponentObject | string>;
}
interface DomComponents {
name: string;
addType(
type: string,
methods: {
// name of component to extend. default: `'default'`
extend?: string;
extendView?: string;
isComponent?: (el: HTMLElement) => boolean;
model: {
defaults: ComponentObject;
// executed once the model of the component is initiliazed
init?: () => void;
// executes when some property of the model is updated.
updated?: (
property: string,
value: string,
prevValue: string,
) => void;
// executed when the component is removed.
removed?: () => void;
};
view?: {
// executed once the view of the component is initiliazed
init?: () => void;
// executed once the component is rendered on the canvas
onRender?: () => void;
events?: {
// just an example of a single event, can add any
click?: (event: Event) => void;
// must return `this`
render?: () => void;
};
};
},
): void;
getType(type: string): any;
}
interface BlockOptions {
label: string;
content: string | ComponentObject;
// selects it right after adding it so you can edit traits right away
select?: boolean;
category?: string | object;
// activate it - needs more details. can best be seen by adding the `img` block
activate?: boolean;
attributes?: object;
// https://grapesjs.com/docs/modules/Blocks.html#custom-render
render?: ({
model: {},
className: string,
el: HTMLElement,
}) => string | void;
}
interface BlockManager {
add(id: string, opt: BlockOptions): void;
}
interface StorageManagerConfig {
id?: string;
autosave?: boolean;
autoload?: boolean;
type?: 'local' | 'remote' | 'null';
stepsBeforeSave?: number;
storeComponents?: boolean;
storeStyles?: boolean;
storeHtml?: boolean;
storeCss?: boolean;
checkLocal?: boolean;
params?: object;
headers?: object;
urlStore?: string;
urlLoad?: string;
contentTypeJson?: boolean;
credentials?: RequestCredentials;
beforeSend(jqXHR: any, settings: object): void;
onComplete(jqXHR: any, status: any): void;
}
interface StyleManagerConfig {
stylePrefix?: string;
sectors?: Array<object>;
appendTo?: HTMLElement | string;
textNoElement?: string;
hideNotStylable?: boolean;
highlightChanged?: boolean;
highlightComputed?: boolean;
showComputed?: boolean;
clearProperties?: boolean;
avoidComputed?: Array<string>;
}
interface AssetManagerConfig {
assets?: Array<object | string>;
noAssets?: string;
stylePrefix?: string;
upload?: boolean;
uploadName?: string;
headers?: object;
params?: object;
credentials?: RequestCredentials;
multiUpload?: boolean;
autoAdd?: boolean;
uploadText?: string;
addBtnText?: string;
customFetch?: Function;
uploadFile?: Function;
embedAsBase64?: boolean;
handleAdd?: Function;
dropzone?: boolean;
openAssetsOnDrop?: number;
dropzoneContent?: string;
modalTitle?: string;
inputPlaceholder?: string;
}
interface CanvasConfig {
stylePrefix?: string;
scripts?: Array<string>;
styles?: Array<string>;
customBadgeLabel?: Function;
autoscrollLimit?: number;
notTextable?: Array<string>;
}
interface PanelsConfig {
stylePrefix?: string;
defaults?: {
id: string;
el: string | HTMLElement;
resizable?: Resizable;
buttons?: PanelButtonConfig[];
}[];
em?: object;
delayBtnsShow?: number;
}
type EditorFunction = (editor: Editor) => void;
/**
* @link https://grapesjs.com/docs/api/panels.html#addbutton
*/
interface PanelButtonConfig {
id: string;
className?: string;
command: string | EditorFunction | {
run: EditorFunction;
stop: EditorFunction;
};
active?: boolean;
/** set `title` to get tooltip */
attributes?: {};
togglable?: boolean;
label?: string;
}
/**
* @link https://github.com/artf/grapesjs/blob/master/src/utils/Resizer.js#L4
* Can also be a simple boolean
*/
interface Resizable {
/** Top left */
tl?: boolean;
/** Top center */
tc?: boolean;
/** Top right */
tr?: boolean;
/** Center left */
cl?: boolean;
/** Center right */
cr?: boolean;
/** Bottom left */
bl?: boolean;
/** Bottom center */
bc?: boolean;
/** Bottom right */
br?: boolean;
/** Default is 'width' */
keyWidth?: string;
}
interface ModalConfig {
stylePrefix?: string;
title?: string;
content?: string;
backdrop?: boolean;
}
interface ModalOptions {
title?: HTMLElement | string;
content?: HTMLElement | string;
}
interface Modal {
open(opts?: ModalOptions): Modal
close(): Modal;
isOpen(): Boolean;
setTitle(title: string): Modal;
getTitle(): string;
setContent(content: HTMLElement | string): Modal;
getContent(): string;
}
interface Canvas {
getConfig(): CanvasConfig | object;
getElement(): HTMLElement;
getFrameEl(): HTMLIFrameElement;
getWindow(): Window;
getDocument(): HTMLDocument;
getBody(): HTMLBodyElement;
getWrapperEl(): HTMLElement;
setCustomBadgeLabel(f: Function): void;
hasFocus(): boolean;
// scrollTo(el: HTMLElement | object, opts?: boolean | GrapesScrollIntoViewOptions): void;
}
interface TraitManagerConfig {
stylePrefix?: string;
appendTo?: HTMLElement;
labelContainer?: string;
labelPlhText?: string;
labelPlhRef?: string;
optionsTarget?: Array<object>;
textNoElement?: string;
}
type GrapesEvent =
| ComponentEvent
| BlockEvent
| AssetEvent
| KeymapEvent
| StyleManagerEvent
| StorageEvent
| CanvasEvent
| SelectorEvent
| RichTextEditorEvent
| ModalEvent
| CommandEvent
| GeneralEvent;
type ComponentEvent =
| 'component:create'
| 'component:mount'
| 'component:add'
| 'component:remove'
| 'component:clone'
| 'component:update'
| 'component:update:{propertyName}'
| 'component:styleUpdate'
| 'component:styleUpdate:{propertyName}'
| 'component:selected'
| 'component:deselected'
| 'component:toggled';
type BlockEvent =
| 'block:add'
| 'block:remove'
| 'block:drag:start'
| 'block:drag'
| 'block:drag:stop';
type AssetEvent =
| 'asset:add'
| 'asset:remove'
| 'asset:upload:start'
| 'asset:upload:end'
| 'asset:upload:error'
| 'asset:upload:response';
type KeymapEvent =
| 'keymap:add'
| 'keymap:remove'
| 'keymap:emit'
| 'keymap:emit:{keymapId}';
type StyleManagerEvent =
| 'styleManager:update:target'
| 'styleManager:change'
| 'styleManager:change:{propertyName}';
type StorageEvent =
| 'storage:start'
| 'storage:start:store'
| 'storage:start:load'
| 'storage:load'
| 'storage:store'
| 'storage:end'
| 'storage:end:store'
| 'storage:end:load'
| 'storage:error'
| 'storage:error:store'
| 'storage:error:load';
type CanvasEvent =
| 'canvas:dragenter'
| 'canvas:dragover'
| 'canvas:drop'
| 'canvas:dragend'
| 'canvas:dragdata';
type SelectorEvent = 'selector:add';
type RichTextEditorEvent = 'rte:enable' | 'rte:disable';
type ModalEvent = 'modal:open' | 'modal:close';
type CommandEvent =
| 'run:{commandName}'
| 'stop:{commandName}'
| 'run:{commandName}:before'
| 'stop:{commandName}:before'
| 'abort:{commandName}';
type GeneralEvent = 'canvasScroll' | 'undo' | 'redo' | 'load';
}