From 5825b5e3d3a14187a7eb41c51b48998c0282f2ab Mon Sep 17 00:00:00 2001 From: Ju99ernaut <48953676+Ju99ernaut@users.noreply.github.com> Date: Fri, 1 Apr 2022 23:11:40 +0200 Subject: [PATCH 1/5] Fix typo in storage_manager --- src/storage_manager/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/storage_manager/index.js b/src/storage_manager/index.js index 48d8f5bf8..fc3edfc12 100644 --- a/src/storage_manager/index.js +++ b/src/storage_manager/index.js @@ -193,7 +193,7 @@ export default () => { * @returns {Object} * */ getStorageOptions(type) { - return this.getCurrentOptons(type); + return this.getCurrentOptions(type); }, /** @@ -207,9 +207,9 @@ export default () => { * */ async store(data, options = {}) { const st = this.getCurrentStorage(); - const opts = { ...this.getCurrentOptons(), ...options }; + const opts = { ...this.getCurrentOptions(), ...options }; const recovery = this.getRecoveryStorage(); - const recoveryOpts = this.getCurrentOptons(STORAGE_LOCAL); + const recoveryOpts = this.getCurrentOptions(STORAGE_LOCAL); try { await this.__exec(st, opts, data); @@ -235,12 +235,12 @@ export default () => { * */ async load(options = {}) { const st = this.getCurrentStorage(); - const opts = { ...this.getCurrentOptons(), ...options }; + const opts = { ...this.getCurrentOptions(), ...options }; const recoveryStorage = this.getRecoveryStorage(); let result; if (recoveryStorage) { - const recoveryData = await this.__exec(recoveryStorage, this.getCurrentOptons(STORAGE_LOCAL)); + const recoveryData = await this.__exec(recoveryStorage, this.getCurrentOptions(STORAGE_LOCAL)); if (!isEmpty(recoveryData)) { try { await this.__askRecovery(); @@ -326,7 +326,7 @@ export default () => { return result; }, - getCurrentOptons(type) { + getCurrentOptions(type) { const config = this.getConfig(); const current = type || this.getCurrent(); return config.options[current] || {}; @@ -395,6 +395,6 @@ export default () => { destroy() { this.__destroy(); this.storages = {}; - }, + } }; }; From a4f101af0b3000853e19db50742137c577a8bfbf Mon Sep 17 00:00:00 2001 From: Ju99ernaut <48953676+Ju99ernaut@users.noreply.github.com> Date: Sat, 2 Apr 2022 00:13:05 +0200 Subject: [PATCH 2/5] Update storage manager types --- index.d.ts | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index 700332f00..cbce7afcd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ declare namespace Backbone { - interface ModelProperties {} + interface ModelProperties { } class Model { constructor(attr?: T, opt?: any); @@ -25,7 +25,7 @@ declare namespace Backbone { reset(models?: Array<{} | TModel>): TModel[]; } - interface GenericModel extends Model<{}> {} + interface GenericModel extends Model<{}> { } } declare module grapesjs { @@ -319,22 +319,33 @@ declare module grapesjs { id?: string; autosave?: boolean; autoload?: boolean; - type?: "local" | "remote"; + type?: string; stepsBeforeSave?: number; - storeComponents?: boolean; - storeStyles?: boolean; - storeHtml?: boolean; - storeCss?: boolean; + recovery?: boolean | Function; + onStore?: (data: any) => any; + onLoad?: (data: any) => any; + options: { + local: LocalStorageConfig; + remote: RemoteStorageConfig; + [key: string]: any; + }; + } + + interface LocalStorageConfig { + key?: string; checkLocal?: boolean; + } + + interface RemoteStorageConfig { params?: object; headers?: object; urlStore?: string; urlLoad?: string; contentTypeJson?: boolean; credentials?: RequestCredentials; - - beforeSend(jqXHR: any, settings: object): void; - onComplete(jqXHR: any, status: any): void; + fetchOptions: string | ((opts: object) => object); + onStore?: (data: any) => any; + onLoad?: (data: any) => any; } interface DomComponentsConfig { @@ -454,9 +465,9 @@ declare module grapesjs { buttons: Button[]; } - interface Panel extends Backbone.Model {} + interface Panel extends Backbone.Model { } - interface Button extends Backbone.Model {} + interface Button extends Backbone.Model { } interface ButtonOptions { id: string; @@ -486,7 +497,7 @@ declare module grapesjs { }): void; } - interface View {} + interface View { } interface LayerManager { /** @@ -3642,6 +3653,12 @@ declare module grapesjs { * Get current storage */ getCurrentStorage(): IStorage; + /** + * Get storage options by type. + * @param type Storage type + * @returns Storage Options + * */ + getStorageOptions(type: string): StorageOptions; } interface ProjectData { @@ -4993,7 +5010,7 @@ declare module grapesjs { y?: number; } - interface Frame extends Backbone.Model {} + interface Frame extends Backbone.Model { } /** * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/i18n/config.js) From 8faff73c1a69bc0c498381c32581c7ccea52de46 Mon Sep 17 00:00:00 2001 From: Ju99ernaut <48953676+Ju99ernaut@users.noreply.github.com> Date: Sat, 2 Apr 2022 00:50:40 +0200 Subject: [PATCH 3/5] Update editor types --- index.d.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index cbce7afcd..a4029883f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -603,23 +603,35 @@ declare module grapesjs { * ## 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; - DeviceManager: object; + Devices: Devices; + DeviceManager: Devices; RichTextEditor: RichTextEditor; Parser: Parser; Utils: object; @@ -830,10 +842,12 @@ declare module grapesjs { stopCommand(id: string, options: any): any; /** * Store data to the current storage - * @param clb - Callback function + * @param options - Storage options * @returns Stored data + * @example + * const storedData = await editor.store(); */ - store(clb: (...params: any[]) => any): any; + store(options: StorageOptions): Promise; /** * Get the JSON data object, which could be stored and loaded back with `editor.loadData(json)` * @example @@ -843,10 +857,12 @@ declare module grapesjs { storeData(): any; /** * Load data from the current storage - * @param clb - Callback function - * @returns Stored data + * @param options - Storage options + * @returns Loaded data + * @example + * const data = await editor.load(); */ - load(clb: (...params: any[]) => any): any; + load(options: StorageOptions): Promise; /** * Load data from the JSON data object * @example From e805abef2ba81d689b783e5fb009b4ee87a09e73 Mon Sep 17 00:00:00 2001 From: Ju99ernaut <48953676+Ju99ernaut@users.noreply.github.com> Date: Sat, 2 Apr 2022 09:37:11 +0200 Subject: [PATCH 4/5] Update storage options types --- index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index a4029883f..606824f54 100644 --- a/index.d.ts +++ b/index.d.ts @@ -324,9 +324,9 @@ declare module grapesjs { recovery?: boolean | Function; onStore?: (data: any) => any; onLoad?: (data: any) => any; - options: { - local: LocalStorageConfig; - remote: RemoteStorageConfig; + options?: { + local?: LocalStorageConfig; + remote?: RemoteStorageConfig; [key: string]: any; }; } @@ -343,7 +343,7 @@ declare module grapesjs { urlLoad?: string; contentTypeJson?: boolean; credentials?: RequestCredentials; - fetchOptions: string | ((opts: object) => object); + fetchOptions?: string | ((opts: object) => object); onStore?: (data: any) => any; onLoad?: (data: any) => any; } From f5c525f4bf4a955cf4ffa18eaa25a59d94ef1331 Mon Sep 17 00:00:00 2001 From: Ju99ernaut <48953676+Ju99ernaut@users.noreply.github.com> Date: Sat, 2 Apr 2022 11:51:16 +0200 Subject: [PATCH 5/5] Remove params --- index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 606824f54..eade409e2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -337,7 +337,6 @@ declare module grapesjs { } interface RemoteStorageConfig { - params?: object; headers?: object; urlStore?: string; urlLoad?: string;