forked from GrapesJS/grapesjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
5288 lines (4982 loc) · 169 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)
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[];
}
interface GenericModel extends Model<{}> {}
}
declare module grapesjs {
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? : []
/** 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. */
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?: boolean,
/** 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,
/** Texts **/
textViewCode?: string,
/** Keep unused styles within the editor **/
keepUnusedStyles?: 0,
}
interface AssetManagerConfig {
assets?: Array<object>;
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 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 StorageManagerConfig {
id?: string;
autosave?: boolean;
autoload?: boolean;
type?: "local" | "remote";
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 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>;
}
interface DeviceManagerConfig {
devices?: Array<object>;
deviceLabel?: string;
}
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[]
[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: object,
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 {
DomComponents: Components;
LayerManager: LayerManager;
CssComposer: CssComposer;
StorageManager: StorageManager;
AssetManager: AssetManager;
BlockManager: BlockManager;
TraitManager: TraitManager;
SelectorManager: SelectorManager;
CodeManager: object;
Commands: Commands;
Keymaps: Keymaps;
Modal: Modal;
Panels: Panels;
StyleManager: StyleManager;
Canvas: Canvas;
UndoManager: UndoManager;
DeviceManager: object;
RichTextEditor: RichTextEditor;
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 | object;
/**
* 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.
*/
addComponents(components: object[] | any | string, opts: {
avoidUpdateStyle?: boolean;
}): 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;
}): Editor;
/**
* Add component to selection
* @example
* editor.selectAdd(model);
* @param el - Component to select
*/
selectAdd(el: Component | HTMLElement | any[]): Editor;
/**
* Remove component from selection
* @example
* editor.selectRemove(model);
* @param el - Component to select
*/
selectRemove(el: Component | HTMLElement | any[]): Editor;
/**
* Toggle component selection
* @example
* editor.selectToggle(model);
* @param el - Component to select
*/
selectToggle(el: Component | HTMLElement | any[]): Editor;
/**
* Returns, if active, the Component enabled in rich text editing mode.
* @example
* const textComp = editor.getEditing();
* if (textComp) {
* console.log('HTML: ', textComp.toHTML());
* }
*/
getEditing(): Component | null;
/**
* Set device to the editor. If the device exists it will
* change the canvas to the proper width
* @example
* editor.setDevice('Tablet');
* @param name - Name of the device
*/
setDevice(name: string): Editor;
/**
* Return the actual active device
* @example
* var device = editor.getDevice();
* console.log(device);
* // 'Tablet'
* @returns Device name
*/
getDevice(): string;
/**
* Execute command
* @example
* editor.runCommand('myCommand', {someValue: 1});
* @param id - Command ID
* @param options - Custom options
* @returns The return is defined by the command
*/
runCommand(id: string, options: any): any;
/**
* Stop the command if stop method was provided
* @example
* editor.stopCommand('myCommand', {someValue: 1});
* @param id - Command ID
* @param options - Custom options
* @returns The return is defined by the command
*/
stopCommand(id: string, options: any): any;
/**
* Store data to the current storage
* @param clb - Callback function
* @returns Stored data
*/
store(clb: (...params: any[]) => any): any;
/**
* Get the JSON data object, which could be stored and loaded back with `editor.loadData(json)`
* @example
* console.log(editor.storeData());
* // { pages: [...], styles: [...], ... }
*/
storeData(): any;
/**
* Load data from the current storage
* @param clb - Callback function
* @returns Stored data
*/
load(clb: (...params: any[]) => any): any;
/**
* Load data from the JSON data object
* @example
* editor.loadData({ pages: [...], styles: [...], ... })
* @param data - Data to load
* @returns Loaded object
*/
loadData(data: any): any;
/**
* Returns container element. The one which was indicated as 'container'
* on init method
*/
getContainer(): HTMLElement;
/**
* Return the count of changes made to the content and not yet stored.
* This count resets at any `store()`
*/
getDirtyCount(): number;
/**
* Update editor dimension offsets
*
* 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
* @param [options] - Options
* @param [options.tools = false] - Update the position of tools (eg. rich text editor, component highlighter, etc.)
*/
refresh(options?: {
tools?: boolean;
}): void;
/**
* Replace the built-in Rich Text Editor with a custom one.
* @example
* editor.setCustomRte({
* // Function for enabling custom RTE
* // el is the HTMLElement of the double clicked Text Component
* // rte is the same instance you have returned the first time you call
* // enable(). This is useful if need to check if the RTE is already enabled so
* // ion this case you'll need to return the RTE and the end of the function
* enable: function(el, rte) {
* rte = new MyCustomRte(el, {}); // this depends on the Custom RTE API
* ...
* return rte; // return the RTE instance
* },
*
* // Disable the editor, called for example when you unfocus the Text Component
* disable: function(el, rte) {
* rte.blur(); // this depends on the Custom RTE API
* }
*
* // Called when the Text Component is focused again. If you returned the RTE instance
* // from the enable function, the enable won't be called again instead will call focus,
* // in this case to avoid double binding of the editor
* focus: function (el, rte) {
* rte.focus(); // this depends on the Custom RTE API
* }
* });
* @param obj - Custom RTE Interface
*/
setCustomRte(obj: any): void;
/**
* Replace the default CSS parser with a custom one.
* The parser function receives a CSS string as a parameter and expects
* an array of CSSRule objects as a result. If you need to remove the
* custom parser, pass `null` as the argument
* @example
* editor.setCustomParserCss(css => {
* const result = [];
* // ... parse the CSS string
* result.push({
* selectors: '.someclass, div .otherclass',
* style: { color: 'red' }
* })
* // ...
* return result;
* });
* @param parser - Parser function
*/
setCustomParserCss(parser: ((...params: any[]) => any) | null): Editor;
/**
* Change the global drag mode of components.
* To get more about this feature read: https://github.com/artf/grapesjs/issues/1936
* @param value - Drag mode, options: 'absolute' | 'translate'
*/
setDragMode(value: string): Editor;
/**
* Trigger event log message
* @example
* editor.log('Something done!', { ns: 'from-plugin-x', level: 'info' });
* // This will trigger following events
* // `log`, `log:info`, `log-from-plugin-x`, `log-from-plugin-x:info`
* // Callbacks of those events will always receive the message and
* // options, as arguments, eg:
* // editor.on('log:info', (msg, opts) => console.info(msg, opts))
* @param msg - Message to log
* @param [opts = {}] - Custom options
* @param [opts.ns = ''] - Namespace of the log (eg. to use in plugins)
* @param [opts.level = 'debug'] - Level of the log, `debug`, `info`, `warning`, `error`
*/
log(msg: any, opts?: {
ns?: string;
level?: string;
}): Editor;
/**
* Translate label
* @example
* editor.t('msg');
* // use params
* editor.t('msg2', { params: { test: 'hello' } });
* // custom local
* editor.t('msg2', { params: { test: 'hello' }, l: 'it' });
* @param key - Label to translate
* @param [opts] - Options for the translation
* @param [opts.params] - Params for the translation
* @param [opts.noWarn] - Avoid warnings in case of missing resources
*/
t(key: string, opts?: {
params?: any;
noWarn?: boolean;
}): string;
/**
* Attach event
* @param event - Event name
* @param callback - Callback function
*/
on(event: GrapesEvent, callback: (...params: any[]) => any): Editor;
/**
* Attach event and detach it after the first run
* @param event - Event name
* @param callback - Callback function
*/
once(event: GrapesEvent, callback: (...params: any[]) => any): Editor;
/**
* Detach event
* @param event - Event name
* @param callback - Callback function
*/
off(event: GrapesEvent, callback: (...params: any[]) => any): Editor;
/**
* Trigger event
* @param event - Event to trigger
*/
trigger(event: GrapesEvent): Editor;
/**
* Destroy the editor
*/
destroy(): void;
/**
* Render editor