forked from GrapesJS/grapesjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
5660 lines (5322 loc) · 170 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
declare namespace Backbone {
interface ModelProperties { }
class Model<T extends ModelProperties> {
constructor(attr?: T, opt?: any);
attributes: T;
collection: Collection<this>;
cid: string;
get<K extends keyof T>(prop: K): T[K];
set<K extends keyof T>(prop: K, val: T[K]): void;
defaults(): T;
on(eventName: string, callback: (...args: any[]) => void): this;
toJSON(options?: any): any;
}
class Collection<TModel extends Model<ModelProperties>> {
models: TModel[];
length: number;
add(model: {} | TModel): TModel;
add(models: Array<{} | TModel>): TModel[];
find(iterator: (item: TModel) => boolean, context?: any): TModel;
remove(model: {} | TModel): TModel;
remove(models: Array<{} | TModel>): TModel[];
reset(models?: Array<{} | TModel>): TModel[];
forEach(iterator: (item: TModel) => void, context?: any): TModel[];
filter(iterator: (item: TModel) => boolean, context?: any): TModel[];
map(iterator: (item: TModel) => any, context?: any): any[];
each(callback: (item: TModel) => void);
}
interface GenericModel extends Model<{}> { }
}
declare namespace grapesjs {
type PluginOptions = Record<string, any>;
type Plugin<T extends PluginOptions = {}> = (editor: Editor, config: T) => void;
interface EditorConfig {
/** Selector which indicates where render the editor */
container?: string | HTMLElement;
/** If true, auto-render the content */
autorender?: boolean;
/** Array of plugins to execute on start */
plugins?: (string | Plugin)[];
/** Custom options for plugins */
pluginsOpts?: Record<string, any>;
/** Init headless editor */
headless?: boolean;
/** Style prefix */
stylePrefix?: string;
/** HTML string or object of components */
components?: string;
/** CSS string or object of rules */
style?: string;
/** If true, will fetch HTML and CSS from selected container */
fromElement?: boolean;
/** Show an alert before unload the page with unsaved changes */
noticeOnUnload?: number;
/** Show paddings and margins */
showOffsets?: boolean;
/** Show paddings and margins on selected component */
showOffsetsSelected?: boolean;
/** On creation of a new Component (via object), if the 'style' attribute is not
* empty, all those roles will be moved in its new class */
forceClass?: boolean;
/** Height for the editor container */
height?: string;
/** Width for the editor container */
width?: string;
/** Type of logs to print with the logger (by default is used the devtool console).
* Available by default: debug, info, warning, error
* You can use `false` to disable all of them or `true` to print all of them */
log?: ('debug' | 'info' | 'warning' | 'error')[];
/** By default Grapes injects base CSS into the canvas. For example, it sets body margin to 0
* and sets a default background color of white. This CSS is desired in most cases.
* use this property if you wish to overwrite the base CSS to your own CSS. This is most
* useful if for example your template is not based off a document with 0 as body margin.
* @deprecated in favor of `config.canvas.frameStyle`
*/
baseCss?: string;
/** CSS that could only be seen (for instance, inside the code viewer) */
protectedCss?: string;
/** CSS for the iframe which containing the canvas, useful if you need to custom something inside
* (eg. the style of the selected component) */
canvasCss?: string;
/** Default command */
defaultCommand?: string;
/** Show a toolbar when the component is selected */
showToolbar?: boolean;
// Allow script tag importing
// @deprecated in favor of `config.parser.optionsHtml.allowScripts`
// allowScripts: 0,
/** If true render a select of available devices */
showDevices?: boolean;
/** When enabled, on device change media rules won't be created */
devicePreviewMode?: boolean;
/** The condition to use for media queries, eg. 'max-width'
* Comes handy for mobile-first cases */
mediaCondition?: string;
/** Starting tag for variable inside scripts in Components */
tagVarStart?: string;
/** Ending tag for variable inside scripts in Components */
tagVarEnd?: string;
/** When false, removes empty text nodes when parsed, unless they contain a space */
keepEmptyTextNodes?: boolean;
/** Return JS of components inside HTML from 'editor.getHtml()' */
jsInHtml?: boolean;
/** Enable native HTML5 drag and drop */
nativeDnD?: boolean;
/** Enable multiple selection */
multipleSelection?: boolean;
/** Show the wrapper component in the final code, eg. in editor.getHtml() */
exportWrapper?: boolean;
/** The wrapper, if visible, will be shown as a `<body>` */
wrapperIsBody?: boolean;
/** Pass default available options wherever `editor.getHtml()` is called */
optsHtml?: Record<string, any>;
/** Pass default available options wherever `editor.getCss()` is called */
optsCss?: Record<string, any>;
/** Usually when you update the `style` of the component this changes the
* element's `style` attribute. Unfortunately, inline styling doesn't allow
* use of media queries (@media) or even pseudo selectors (eg. :hover).
* When `avoidInlineStyle` is true all styles are inserted inside the css rule
* @deprecated Don't use this option, we don't support inline styling anymore */
avoidInlineStyle?: boolean;
/** Avoid default properties from storable JSON data, like `components` and `styles`.
* With this option enabled your data will be smaller (usefull if need to
* save some storage space) */
avoidDefaults?: boolean;
/** (experimental)
* The structure of components is always on the screen but it's not the same
* for style rules. When you delete a component you might leave a lot of styles
* which will never be used again, therefore they might be removed.
* With this option set to true, styles not used from the CSS generator (so in
* any case where `CssGenerator.build` is used) will be removed automatically.
* But be careful, not always leaving the style not used mean you wouldn't
* use it later, but this option comes really handy when deal with big templates. */
clearStyles?: boolean;
/** Specify the global drag mode of components. By default, components are moved
* following the HTML flow. Two other options are available:
* 'absolute' - Move components absolutely (design tools way)
* 'translate' - Use translate CSS from transform property
* To get more about this feature read: https://github.com/artf/grapesjs/issues/1936 */
dragMode?: 'translate' | 'absolute';
/** When the editor is placed in a scrollable container (eg. modals) this might
* cause elements inside the canvas (eg. floating toolbars) to be misaligned.
* To avoid that, you can specify an array of DOM elements on which their scroll will
* trigger the canvas update.
* Be default, if the array is empty, the first parent element will be appended.
* listenToEl: [document.querySelector('#scrollable-el')], */
listenToEl?: HTMLElement[];
/** Import asynchronously CSS to use as icons */
cssIcons?: string;
/** Dom element */
el?: string;
/** Configurations for I18n */
i18n?: Record<string, any>;
/** Configurations for Undo Manager */
undoManager?: Record<string, any> | boolean;
/** Configurations for Asset Manager */
assetManager?: AssetManagerConfig | boolean;
/** Configurations for Canvas */
canvas?: CanvasConfig | boolean;
/** Configurations for Layers */
layers?: Record<string, any> | boolean;
/** Configurations for Storage Manager */
storageManager?: StorageManagerConfig | boolean;
/** Configurations for Rich Text Editor */
richTextEditor?: RichTextEditorConfig | boolean;
/** Configurations for DomComponents */
domComponents?: DomComponentsConfig | boolean;
/** Configurations for Modal Dialog */
modal?: ModalConfig | boolean;
/** Configurations for Code Manager */
codeManager?: CodeManagerConfig | boolean;
/** Configurations for Panels */
panels?: PanelsConfig | boolean;
/** Configurations for Commands */
commands?: CommandsConfig | boolean;
/** Configurations for Css Composer */
cssComposer?: CssComposerConfig | boolean;
/** Configurations for Selector Manager */
selectorManager?: SelectorManagerConfig | boolean;
/** Configurations for Device Manager */
deviceManager?: DeviceManagerConfig | boolean;
/** Configurations for Style Manager */
styleManager?: StyleManagerConfig | boolean;
/** Configurations for Block Manager */
blockManager?: BlockManagerConfig | boolean;
/** Configurations for Trait Manager */
traitManager?: TraitManagerConfig | boolean;
/** Configurations for Page Manager */
pageManager?: PageManagerConfig;
/** Texts **/
textViewCode?: string;
/** Keep unused styles within the editor **/
keepUnusedStyles?: 0;
layerManager?: LayerManagerConfig;
parser?: ParserConfig;
}
interface AssetManagerConfig {
/**
* Default assets.
* @example
* [
* 'https://...image1.png',
* 'https://...image2.png',
* {type: 'image', src: 'https://...image3.png', someOtherCustomProp: 1}
* ]
*/
assets?: (string | Record<string, any>)[];
/**
* Content to add where there is no assets to show.
* @default ''
* @example 'No <b>assets</b> here, drag to upload'
*/
noAssets?: string;
/**
* Style prefix
* @default 'am-'
*/
stylePrefix?: string;
/**
* Upload endpoint, set `false` to disable upload.
* @example 'https://endpoint/upload/assets'
*/
upload?: false | string;
/**
* The name used in POST to pass uploaded files.
* @default 'files'
*/
uploadName?: string;
/**
* Custom headers to pass with the upload request.
* @default {}
*/
headers?: Record<string, any>;
/**
* Custom parameters to pass with the upload request, eg. csrf token.
* @default {}
*/
params?: Record<string, any>;
/**
* The credentials setting for the upload request, eg. 'include', 'omit'.
* @default 'include'
*/
credentials?: RequestCredentials;
/**
* Allow uploading multiple files per request. If disabled filename will not have '[]' appended.
* @default true
*/
multiUpload?: boolean;
/**
* If true, tries to add automatically uploaded assets. To make it work the server should respond with a JSON containing assets in a data key, eg:
* { data: [ 'https://.../image.png', {src: 'https://.../image2.png'} ]
* @default true
*/
autoAdd?: boolean;
/**
* To upload your assets, the module uses Fetch API. With this option you can overwrite it with your own logic. The custom function should return a Promise.
* @example
* customFetch: (url, options) => axios(url, { data: options.body }),
*/
customFetch?: (url: string, options: Record<string, any>) => Promise<void>;
/**
* Custom uploadFile function.
* Differently from the `customFetch` option, this gives a total control over the uploading process, but you also have to emit all `asset:upload:*` events b
* y yourself (if you need to use them somewhere).
* @example
* uploadFile: (ev) => {
* const files = ev.dataTransfer ? ev.dataTransfer.files : ev.target.files;
* // ...send somewhere
* }
*/
uploadFile?: (ev: DragEvent) => void;
/**
* In the absence of 'uploadFile' or 'upload' assets will be embedded as Base64.
* @default true
*/
embedAsBase64?: boolean;
/**
* Handle the image url submit from the built-in 'Add image' form.
* @example
* handleAdd: (textFromInput) => {
* // some check...
* editor.AssetManager.add(textFromInput);
* }
*/
handleAdd?: (value: string) => void;
/**
* Method called before upload, on return false upload is canceled.
* @example
* beforeUpload: (files) => {
* // logic...
* const stopUpload = true;
* if(stopUpload) return false;
* }
*/
beforeUpload?: (files: any) => void | false;
/**
* Toggles visiblity of assets url input
* @default true
*/
showUrlInput?: boolean;
/**
* Avoid rendering the default asset manager.
* @default false
*/
custom?:
| boolean
| {
open?: (props: any) => void;
close?: (props: any) => void;
};
/**
* Enable an upload dropzone on the entire editor (not document) when dragging files over it.
* If active the dropzone disable/hide the upload dropzone in asset modal, otherwise you will get double drops (#507).
* @deprecated
*/
dropzone?: boolean;
/**
* Open the asset manager once files are been dropped via the dropzone.
* @deprecated
*/
openAssetsOnDrop?: boolean;
/**
* Any dropzone content to append inside dropzone element
* @deprecated
*/
dropzoneContent?: string;
}
interface CanvasConfig {
stylePrefix?: string;
scripts?: Array<string>;
styles?: Array<string>;
customBadgeLabel?: Function;
autoscrollLimit?: number;
notTextable?: Array<string>;
frameStyle?: string;
}
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 BlockManagerConfig {
appendTo?: HTMLElement | string;
blocks: Array<object>;
}
interface RichTextEditorConfig {
stylePrefix?: string;
adjustToolbar?: boolean;
actions?: Array<string>;
}
interface TraitManagerConfig {
stylePrefix?: string;
appendTo?: HTMLElement | string;
labelContainer?: string;
labelPlhText?: string;
labelPlhRef?: string;
optionsTarget?: Array<object>;
textNoElement?: string;
}
interface PageManagerConfig {
pages?: any;
}
interface StorageManagerConfig {
id?: string;
autosave?: boolean;
autoload?: boolean;
type?: string;
stepsBeforeSave?: number;
recovery?: boolean | Function;
onStore?: (data: any, editor: Editor) => any;
onLoad?: (data: any, editor: Editor) => any;
options?: {
local?: LocalStorageConfig;
remote?: RemoteStorageConfig;
[key: string]: any;
};
}
interface LocalStorageConfig {
key?: string;
checkLocal?: boolean;
}
interface RemoteStorageConfig {
headers?: object;
urlStore?: string;
urlLoad?: string;
contentTypeJson?: boolean;
credentials?: RequestCredentials;
fetchOptions?: string | ((opts: object) => object);
onStore?: (data: any, editor: Editor) => any;
onLoad?: (data: any, editor: Editor) => any;
}
interface DomComponentsConfig {
stylePrefix?: string;
wrapperId?: string;
wrapperName?: string;
wrapper?: DomComponentsWrapperConfig;
components?: Array<object>;
imageCompClass?: string;
oAssetsOnCreate?: boolean;
storeWrapper?: boolean;
voidElements?: Array<string>;
}
interface DomComponentsWrapperConfig {
removable?: boolean;
copyable?: boolean;
draggable?: boolean;
// TODO: Type custom blocks and components
components?: Array<object>;
traits?: Array<object>;
stylable?: Array<string>;
}
interface ModalConfig {
stylePrefix?: string;
title?: string;
content?: string;
backdrop?: boolean;
}
interface CodeManagerConfig {
stylePrefix?: string;
inlineCss?: boolean;
}
interface PanelsConfig {
stylePrefix?: string;
defaults?: Array<object>;
em?: object;
delayBtnsShow?: number;
}
interface CommandsConfig {
ESCAPE_KEY?: number;
stylePrefix?: string;
defaults?: Array<object>;
em?: object;
firstCentered?: boolean;
newFixedH?: boolean;
minComponentH?: number;
minComponentW?: number;
}
interface CssComposerConfig {
stylePrefix?: string;
staticRules?: string;
rules?: Array<string>;
}
interface SelectorManagerConfig {
stylePrefix?: string;
appendTo?: HTMLElement | string;
selectors?: Array<string>;
label?: string;
statesLabel?: string;
selectedLabel?: string;
states?: Array<object>;
componentFirst?: boolean;
}
interface DeviceManagerConfig {
devices?: Array<object>;
deviceLabel?: string;
}
interface LayerManagerScrollLayersConfig {
behavior?: string;
block?: string;
}
interface LayerManagerScrollCanvasConfig {
behavior?: string;
block?: string;
}
interface LayerManagerConfig {
/** Specify the element to use as a container, string (query) or HTMLElement
* With the empty value, nothing will be rendered */
appendTo?: HTMLElement | string;
/** Scroll to selected component in Layers when it's selected in Canvas
* true, false or `scrollIntoView`-like options */
scrollLayers?: number | boolean | LayerManagerScrollLayersConfig;
/** Style prefix */
stylePrefix?: string;
/** Enable/Disable globally the possibility to sort layers */
sortable?: boolean;
/** Enable/Disable globally the possibility to hide layers */
hidable?: boolean;
/** Hide textnodes */
hideTextnode?: boolean;
/** Indicate a query string of the element to be selected as the root of layers.
* By default the root is the wrapper */
root?: string;
/** Indicates if the wrapper is visible in layers */
showWrapper?: boolean;
/** Show hovered components in canvas */
showHover?: boolean;
/** Scroll to selected component in Canvas when it's selected in Layers
* true, false or `scrollIntoView`-like options,
* `block: 'nearest'` avoids the issue of window scrolling */
scrollCanvas?: boolean | LayerManagerScrollCanvasConfig;
/** Highlight when a layer component is hovered */
highlightHover?: boolean;
/**
* WARNING: Experimental option
* A callback triggered once the component layer is initialized.
* Useful to trigger updates on some component prop change.
* @example
* onInit({ component, render, listenTo }) {
* listenTo(component, 'change:some-prop', render);
* };
*/
onInit?: () => any;
/**
* WARNING: Experimental option
* A callback triggered once the component layer is rendered.
* A callback useful to update the layer DOM on some component change
* @example
* onRender({ component, el }) { // el is the DOM of the layer
* if (component.get('some-prop')) {
* // do changes using the `el` DOM
* }
* }
*/
onRender?: () => any;
/**
* Extend Layer view object (view/ItemView.js)
* @example
* extend: {
* setName(name) {
* // this.model is the component of the layer
* this.model.set('another-prop-for-name', name);
* },
* },
*/
extend?: any;
}
interface ParserConfig {
optionsHtml?: object;
}
function init(config: EditorConfig): Editor;
interface Trait extends Backbone.Model<TraitOptions> {
target: Component;
/** Return all the properties */
props(): TraitOptions;
targetUpdated(): void;
getValue(): string;
getTargetValue(): string;
setTargetValue(value: any, opts: object): void;
setValueFromInput(value: any, final: boolean, opts: object): void;
/**
* Get the initial value of the trait
*/
getInitValue(): string;
}
type TraitType = 'text' | 'number' | 'checkbox' | 'select' | string;
interface TraitOptions {
type: TraitType;
label: string;
name: string;
min?: string;
max?: string;
unit?: string;
step?: number;
value?: string;
target?: Component;
default?: string;
placeholder?: string;
changeProp?: number;
options?: SelectOption[];
command?: (editor: Editor) => void;
[key: string]: any;
}
interface PanelOptions {
id: string;
content: string;
visible: boolean;
buttons: Button[];
}
interface Panel extends Backbone.Model<PanelOptions> { }
interface Button extends Backbone.Model<ButtonOptions> { }
interface ButtonOptions {
id: string;
label?: string;
tagName?: 'span';
className?: string;
command?: string | ((editor: Editor, opts?: any) => void);
context?: string;
buttons?: any[];
attributes?: { [key:string]: string};
options?: object;
active?: boolean;
dragDrop?: boolean;
togglable?: boolean;
runDefaultCommand?: boolean;
stopDefaultCommand?: boolean;
disable?: boolean;
}
interface ComponentView {
model: Component;
onRender(opts: {
editor?: Editor;
model?: Component;
el?: HTMLElement;
}): void;
}
interface View { }
interface LayerManager {
/**
* Set new root for layers
* @param el Component to be set as the root
*/
setRoot(el: HTMLElement | Component | String): this;
/** Get the root of layers */
getRoot(): Component;
/** Return the view of layers */
getAll(): View;
}
interface TraitView {
noLabel?: boolean;
templateInput?: string | ((options: { trait: Trait }) => string);
eventCapture?: string[];
onEvent?: (options: {
elInput: HTMLElement;
component: Component;
event: any;
}) => void;
onUpdate?: (options: {
elInput: HTMLElement;
component: Component;
}) => void;
createInput?: (options: { trait: Trait }) => HTMLElement;
createLabel?: (options: { label: string }) => string;
}
interface TraitManager {
/**
* Add new trait type
* @param name Type name
* @param methods Object representing the trait
*/
addType(name: string, trait: TraitView): void;
/**
* Get trait type
* @param name Type name
*/
getType(name: string): Object;
/**
* Get all trait types
*/
getTypes(): Object;
}
/**
* Editor contains the top level API which you'll probably use to customize the editor or extend it with plugins.
* You get the Editor instance on init method and you can pass options via its [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/editor/config/config.js)
*
* ```js
* const editor = grapesjs.init({
* // options
* });
* ```
*
* ## Available Events
*
* You can make use of available events in this way
* ```js
* editor.on('EVENT-NAME', (some, argument) => {
* // do something
* })
* ```
*
* * `update` - The structure of the template is updated (its HTML/CSS)
* * `undo` - Undo executed
* * `redo` - Redo executed
* * `load` - Editor is loaded
*
* ### Components
* Check the [Components](/api/components.html) module.
* ### Keymaps
* Check the [Keymaps](/api/keymaps.html) module.
* ### Style Manager
* Check the [Style Manager](/api/style_manager.html) module.
* ### Storage
* Check the [Storage](/api/storage_manager.html) module.
* ### Canvas
* Check the [Canvas](/api/canvas.html) module.
* ### RTE
* Check the [Rich Text Editor](/api/rich_text_editor.html) module.
* ### Commands
* Check the [Commands](/api/commands.html) module.
* ### Selectors
* Check the [Selectors](/api/selector_manager.html) module.
* ### Blocks
* Check the [Blocks](/api/block_manager.html) module.
* ### Assets
* Check the [Assets](/api/assets.html) module.
* ### Modal
* Check the [Modal](/api/modal_dialog.html) module.
* ### Devices
* Check the [Devices](/api/device_manager.html) module.
* ### Parser
* Check the [Parser](/api/parser.html) module.
* ### Pages
* Check the [Pages](/api/pages.html) module.
*
* ## Methods
*/
interface Editor {
Components: Components;
DomComponents: Components;
Layers: LayerManager;
LayerManager: LayerManager;
Css: CssComposer;
CssComposer: CssComposer;
Storage: StorageManager;
StorageManager: StorageManager;
Assets: AssetManager;
AssetManager: AssetManager;
Blocks: BlockManager;
BlockManager: BlockManager;
Traits: TraitManager;
TraitManager: TraitManager;
Selectors: SelectorManager;
SelectorManager: SelectorManager;
Pages: Pages;
PageManager: Pages;
CodeManager: object;
Commands: Commands;
Keymaps: Keymaps;
Modal: Modal;
Panels: Panels;
Styles: StyleManager;
StyleManager: StyleManager;
Canvas: Canvas;
UndoManager: UndoManager;
Devices: Devices;
DeviceManager: Devices;
RichTextEditor: RichTextEditor;
I18n: I18n;
Parser: Parser;
Utils: object;
Config: EditorConfig | object;
/**
* Returns configuration object
* @param [prop] - Property name
* @returns Returns the configuration object or
* the value of the specified property
*/
getConfig(prop?: string): EditorConfig;
/**
* Returns HTML built inside canvas
* @param [opts = {}] - Options
* @param [opts.component] - Return the HTML of a specific Component
* @param [opts.cleanId = false] - Remove unnecessary IDs (eg. those created automatically)
* @returns HTML string
*/
getHtml(opts?: { component?: Component; cleanId?: boolean }): string;
/**
* Returns CSS built inside canvas
* @param [opts = {}] - Options
* @param [opts.component] - Return the CSS of a specific Component
* @param [opts.json = false] - Return an array of CssRules instead of the CSS string
* @param [opts.avoidProtected = false] - Don't include protected CSS
* @param [opts.onlyMatched = false] - Return only rules matched by the passed component.
* @returns CSS string or array of CssRules
*/
getCss(opts?: {
component?: Component;
json?: boolean;
avoidProtected?: boolean;
onlyMatched?: boolean;
}): string | CssRule[];
/**
* Returns JS of all components
* @param [opts = {}] - Options
* @param [opts.component] - Get the JS of a specific component
* @returns JS string
*/
getJs(opts?: { component?: Component }): string;
/**
* Return the complete tree of components. Use `getWrapper` to include also the wrapper
*/
getComponents(): Components;
/**
* Return the wrapper and its all components
*/
getWrapper(): Component;
/**
* Set components inside editor's canvas. This method overrides actual components
* @example
* editor.setComponents('<div class="cls">New component</div>');
* // or
* editor.setComponents({
* type: 'text',
* classes:['cls'],
* content: 'New component'
* });
* @param components - HTML string or components model
* @param opt - the options object to be used by the [setComponents]{@link em#setComponents} method
*/
setComponents(components: object[] | any | string, opt?: any): any;
/**
* Add components
* @example
* editor.addComponents('<div class="cls">New component</div>');
* // or
* editor.addComponents({
* type: 'text',
* classes:['cls'],
* content: 'New component'
* });
* @param components - HTML string or components model
* @param opts - Options
* @param [opts.avoidUpdateStyle = false] - If the HTML string contains styles,
* by default, they will be created and, if already exist, updated. When this option
* is true, styles already created will not be updated.
* @param [opts.at] - If provided, an index to insert these components at.
*/
addComponents(
components: object[] | any | string,
opts?: {
avoidUpdateStyle?: boolean;
at?: number;
}
): Component[];
/**
* Returns style in JSON format object
*/
getStyle(): any;
/**
* Set style inside editor's canvas. This method overrides actual style
* @example
* editor.setStyle('.cls{color: red}');
* //or
* editor.setStyle({
* selectors: ['cls'],
* style: { color: 'red' }
* });
* @param style - CSS string or style model
*/
setStyle(style: object[] | any | string): Editor;
/**
* Add styles to the editor
* @example
* editor.addStyle('.cls{color: red}');
* @param style - CSS string or style model
* @returns Array of created CssRule instances
*/
addStyle(style: object[] | any | string): CssRule[];
/**
* Returns the last selected component, if there is one
*/
getSelected(): Component | null;
/**
* Returns an array of all selected components
*/
getSelectedAll(): Component[];
/**
* Get a stylable entity from the selected component.
* If you select a component without classes the entity is the Component
* itself and all changes will go inside its 'style' attribute. Otherwise,
* if the selected component has one or more classes, the function will
* return the corresponding CSS Rule
*/
getSelectedToStyle(): Component; // TODO: | CSSRule
/**
* Select a component
* @example
* // Select dropped block
* editor.on('block:drag:stop', function(model) {
* editor.select(model);
* });
* @param el - Component to select
* @param [opts] - Options
* @param [opts.scroll] - Scroll canvas to the selected element
*/
select(
el: Component | HTMLElement,
opts?: {
scroll?: boolean;
}