MCPcopy Index your code
hub / github.com/codex-team/editor.js / constructor

Method constructor

src/codex.ts:44–76  ·  view source on GitHub ↗

* @param {EditorConfig|string|undefined} [configuration] - user configuration

(configuration?: EditorConfig|string)

Source from the content-addressed store, hash-verified

42 * @param {EditorConfig|string|undefined} [configuration] - user configuration
43 */
44 constructor(configuration?: EditorConfig|string) {
45 /**
46 * Set default onReady function
47 */
48 // eslint-disable-next-line @typescript-eslint/no-empty-function
49 let onReady = (): void => {};
50
51 /**
52 * If `onReady` was passed in `configuration` then redefine onReady function
53 */
54 if (_.isObject(configuration) && _.isFunction(configuration.onReady)) {
55 onReady = configuration.onReady;
56 }
57
58 /**
59 * Create a Editor.js instance
60 */
61 const editor = new Core(configuration);
62
63 /**
64 * We need to export isReady promise in the constructor
65 * as it can be used before other API methods are exported
66 *
67 * @type {Promise<void>}
68 */
69 this.isReady = editor.isReady.then(() => {
70 this.exportAPI(editor);
71 /**
72 * @todo pass API as an argument. It will allow to use Editor's API when editor is ready
73 */
74 onReady();
75 });
76 }
77
78 /**
79 * Export external API methods

Callers

nothing calls this directly

Calls 1

exportAPIMethod · 0.95

Tested by

no test coverage detected