| 96 | }; |
| 97 | |
| 98 | export const usePlugin = <P extends Plugin<any> | string>(plugin: P, opts?: P extends Plugin<infer C> ? C : {}) => { |
| 99 | const options = opts || {}; |
| 100 | const wrapped: PluginWithMeta<any> = (editor: Editor) => { |
| 101 | const pluginResult = getPlugin(plugin); |
| 102 | |
| 103 | if (pluginResult) { |
| 104 | pluginResult(editor, options); |
| 105 | } else { |
| 106 | logPluginWarn(editor, plugin as string); |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | const id = typeof plugin === 'string' ? plugin : plugin.__gjsPluginId; |
| 111 | wrapped.__gjsPluginMeta = { id, plugin, options }; |
| 112 | |
| 113 | return wrapped; |
| 114 | }; |