* Export external API methods * * @param {Core} editor — Editor's instance
(editor: Core)
| 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 | }); |
no test coverage detected