Skip to content

Commit

Permalink
Improve typings (GrapesJS#5192)
Browse files Browse the repository at this point in the history
* add component:resize to ComponentEvent type

* limit storageManager type to be 'local' | 'remote' | undefined

* add type to components parameter
  • Loading branch information
Julia-Alberici authored and pety-dc committed Aug 14, 2023
1 parent 5088466 commit 2031719
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/api/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cmp.addType(...);
* `component:drag:start` - Component drag started. Passed an object, to the callback, containing the `target` (component to drag), `parent` (parent of the component) and `index` (component index in the parent)
* `component:drag` - During component drag. Passed the same object as in `component:drag:start` event, but in this case, `parent` and `index` are updated by the current pointer
* `component:drag:end` - Component drag ended. Passed the same object as in `component:drag:start` event, but in this case, `parent` and `index` are updated by the final pointer
* `component:resize` - During component resize.

## Methods

Expand Down
3 changes: 2 additions & 1 deletion src/dom_components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export type ComponentEvent =
| 'component:type:update'
| 'component:drag:start'
| 'component:drag'
| 'component:drag:end';
| 'component:drag:end'
| 'component:resize';

export interface ComponentModelDefinition extends IComponent {
defaults?: ComponentDefinitionDefined;
Expand Down
6 changes: 3 additions & 3 deletions src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import ComponentManager, { ComponentEvent } from '../dom_components';
import Component from '../dom_components/model/Component';
import Components from '../dom_components/model/Components';
import ComponentWrapper from '../dom_components/model/ComponentWrapper';
import { DragMode } from '../dom_components/model/types';
import { ComponentDefinition, DragMode } from '../dom_components/model/types';
import I18nModule from '../i18n';
import KeymapsModule, { KeymapEvent } from '../keymaps';
import ModalModule, { ModalEvent } from '../modal_dialog';
Expand Down Expand Up @@ -322,7 +322,7 @@ export default class Editor implements IBaseModule<EditorConfig> {
* content: 'New component'
* });
*/
setComponents(components: any, opt: any = {}) {
setComponents(components: string | ComponentDefinition, opt: any = {}) {
this.em.setComponents(components, opt);
return this;
}
Expand All @@ -344,7 +344,7 @@ export default class Editor implements IBaseModule<EditorConfig> {
* content: 'New component'
* });
*/
addComponents(components: any, opts?: any): Component[] {
addComponents(components: string | ComponentDefinition, opts?: any): Component[] {
return this.getWrapper()!.append(components, opts);
}

Expand Down
2 changes: 1 addition & 1 deletion src/storage_manager/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface StorageManagerConfig {
* Available by default: 'local' | 'remote'
* @default 'local'
*/
type?: string;
type?: 'local' | 'remote';

/**
* Enable/disable autosaving.
Expand Down
2 changes: 1 addition & 1 deletion src/storage_manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class StorageManager extends Module<
constructor(em: EditorModel) {
super(em, 'StorageManager', defaults);
const { config } = this;
if (config._disable) config.type = '';
if (config._disable) config.type = undefined;
this.storages = {};
this.add(STORAGE_LOCAL, new LocalStorage());
this.add(STORAGE_REMOTE, new RemoteStorage());
Expand Down

0 comments on commit 2031719

Please sign in to comment.