import { ApplicationRef, NgZone } from '@angular/core'; import EditorJS, { OutputData } from '@editorjs/editorjs'; import { NgxEditorJSPluginService } from '@tinynodes/ngx-editorjs-plugins'; import { Observable } from 'rxjs'; import { NgxEditorJSModuleConfig } from '../types/config'; import { CreateEditorJSOptions } from '../types/editorjs-service'; import { EditorJSClass, InjectorApiCallOptions, InjectorApiCallResponse, InjectorMethodOption } from '../types/injector'; /** * This handles the management of {@link https://editorjs.io/api | EditorJS} instances and their lifecycle. * * All `EditorJS` instances are created outside of Angular using {@link https://angular.io/api/core/NgZone | NgZone } to ensure change detection is not triggered. * Once an instance is created, several {@link https://angular.io/guide/observables | Observable} values are also set up: * * - {@link #isReady | isReady } Set when the editor instance is ready in the DOM * - {@link #hasSaved | hasSaved } Set when the editor `.save()` method has been called. * - {@link #lastChange | lastChange } Set when a change happens, contains the `OutputData` from the Editor. * * After setup, {@link #isReady | isReady } is set to true and the editor can be used within Angular. There are some methods provided * for {@link #save | save }, {@link #update | update } and {@link #clear | clear } - and an {@link #apiCall | apiCall } method which allows * for any call to be made to EditorJS that matches it's API. */ export declare class NgxEditorJSService { private readonly editorJs; private readonly config; private readonly plugins; private readonly zone; private readonly ref; /** * Internal destroy subject for the service */ private readonly onDestroy$; /** * Internal map of all {@link https://editorjs.io/api | EditorJS} instances */ private readonly editorMap; /** * Internal map of all {@link https://editorjs.io/api | EditorJS} ready states */ private readonly isReadyMap; /** * Internal map of when {@link https://editorjs.io/api | EditorJS} save is called */ private readonly hasSavedMap; /** * Internal map of all {@link https://editorjs.io/api | EditorJS} change states */ private readonly lastChangeMap; /** * @param editorJs The EditorJS class injected into the application and used to create new editor instances * @param config The configuration provided from the NgxEditorJSModule.forRoot method * @param plugins The plugin service which provides all plugins injected into the application * @param zone The Angular Zone service that allows the EditorJS methods to be run outside of Angular * @param ref The ApplicationRef provided by Angular, used to trigger an application tick */ constructor(editorJs: EditorJSClass, config: NgxEditorJSModuleConfig, plugins: NgxEditorJSPluginService, zone: NgZone, ref: ApplicationRef); /** * Creates a new {@link https://editorjs.io/api | EditorJS} instance outside of the Angular zone and then adds it to the editor instances * * @remark * This method uses `async/await` * * @param options A configuration passed to create an EditorJS instance * @returns A Promise when the editor has been created */ createInstance(options: CreateEditorJSOptions): Promise; /** * A helper method to make calls to the {@link https://editorjs.io/api | EditorJS API } of any instance. * The first argument is an object that you must pass the `method` name, and the `holder` ID of the container. * An optional `namespace` can be added for API calls such as `blocks`, `caret`, etc. * * The second argument is any additional arguments as required by the API. * * @remarks * Unlike other methods an API call be made with a `.subscribe`, the result will be an observable value. * If the value is a Promise it will be resolved first * * @param options The options for the API call to be made * @param args Any arguments to be passed to the API call * @returns An Observable of the API response */ apiCall(options: InjectorApiCallOptions, ...args: any[]): Observable>; /** * Call the `save` method of an {@link https://editorjs.io/api | EditorJS} instance and sets the current value of the service to the result * @param options Options for the method call */ save(options: InjectorMethodOption): Observable>; /** * Gets the {@link https://editorjs.io/api | EditorJS} instance for the passed holder and calls the `clear` method. * @param options Options to configure a method call against the EditorJS core API */ clear(options: InjectorMethodOption): Observable>; /** * Gets the {@link https://editorjs.io/api | EditorJS} instance for the passed holder and calls the render method if blocks * are passed. Optionally can disable the `lastChange` update - useful if doing actions * such as resetting data. * @param options Options to configure a method call against the EditorJS core API */ update(options: InjectorMethodOption): Observable>; /** * Returns the underlying {@link https://editorjs.io/api | EditorJS} instance * @param options Options to configure a method call against the EditorJS core API */ getEditor(options: InjectorMethodOption): Observable; /** * Subscribe to the `isReady` state change for the editor passed in the options * @param options Options to configure a method call against the EditorJS core API */ isReady(options: InjectorMethodOption): Observable; /** * Subscribe to the `lastChange` state change for the editor passed in the options * @param options Options to configure a method call against the EditorJS core API */ lastChange(options: InjectorMethodOption): Observable; /** * Subscribe to the `hasSaved` state change for the editor passed in the options * @param options Options to configure a method call against the EditorJS core API */ hasSaved(options: InjectorMethodOption): Observable; /** * Destroys a single instance of {@link https://editorjs.io/api | EditorJS} and all the subject values created for it * @param options Options to configure a method call against the EditorJS core API */ destroyInstance(options: InjectorMethodOption): void; /** * Call this to destroy all subscriptions within the service */ destroy(): void; /** * Internal method to create an default onChange method for {@link https://editorjs.io/api | EditorJS} * @param options The InjectorMethodOption for this request */ private createOnChange; /** * Internal method to create an default onReady method for {@link https://editorjs.io/api | EditorJS} * @param options The InjectorMethodOption for this request */ private createOnReady; /** * Sets up the `BehaviorSubject` values when an {@link https://editorjs.io/api | EditorJS} instance is created. All the subjects are first created and set * to default values. * Once an EditorJS instance is ready these values can provide change and save state information * @param options Options to configure a method call against the EditorJS core API */ private setupSubjects; /** * Handles cleaning up all the `BehaviorSubject` values once an {@link https://editorjs.io/api | EditorJS} instance has been destroyed * @param options The options to pass to clean up the subjects */ private cleanupSubjects; /** * Returns a map of {@link https://editorjs.io/api | EditorJS} tools to be initialized by the editor * @param excludeTools Optional array of tools to exclude, if not passed all tools */ private getTools; }