MCPcopy
hub / github.com/codex-team/editor.js / exportAPI

Method exportAPI

src/codex.ts:83–142  ·  view source on GitHub ↗

* Export external API methods * * @param {Core} editor — Editor's instance

(editor: Core)

Source from the content-addressed store, hash-verified

81 * @param {Core} editor — Editor's instance
82 */
83 public exportAPI(editor: Core): void {
84 const fieldsToExport = [ 'configuration' ];
85 const destroy = (): void => {
86 Object.values(editor.moduleInstances)
87 .forEach((moduleInstance) => {
88 if (_.isFunction(moduleInstance.destroy)) {
89 moduleInstance.destroy();
90 }
91 moduleInstance.listeners.removeAll();
92 });
93
94 destroyTooltip();
95
96 editor = null;
97
98 for (const field in this) {
99 if (Object.prototype.hasOwnProperty.call(this, field)) {
100 delete this[field];
101 }
102 }
103
104 Object.setPrototypeOf(this, null);
105 };
106
107 fieldsToExport.forEach((field) => {
108 this[field] = editor[field];
109 });
110
111 this.destroy = destroy;
112
113 Object.setPrototypeOf(this, editor.moduleInstances.API.methods);
114
115 delete this.exportAPI;
116
117 const shorthands = {
118 blocks: {
119 clear: 'clear',
120 render: 'render',
121 },
122 caret: {
123 focus: 'focus',
124 },
125 events: {
126 on: 'on',
127 off: 'off',
128 emit: 'emit',
129 },
130 saver: {
131 save: 'save',
132 },
133 };
134
135 Object.entries(shorthands)
136 .forEach(([key, methods]) => {
137 Object.entries(methods)
138 .forEach(([name, alias]) => {
139 this[alias] = editor.moduleInstances.API.methods[key][name];
140 });

Callers 1

constructorMethod · 0.95

Calls 2

forEachMethod · 0.80
entriesMethod · 0.80

Tested by

no test coverage detected