From bcd2ab3b010552debd4e8b72ea7f359695712459 Mon Sep 17 00:00:00 2001 From: xiaolaoshi <602936213@qq.com> Date: Sat, 19 Sep 2026 09:02:02 +0800 Subject: [PATCH] docs(inline-tools): document static prepare() and reset() The Inline Tools API listed the optional instance methods but never mentioned the static lifecycle hooks, even though the engine calls them for Inline Tools exactly like it does for Block Tools and Block Tunes: Tools.getListOfPrepareFunctions() walks the whole tools config, and Tools.destroy() resets every available tool. Both hooks are part of the shipped contract (BaseToolConstructable.prepare/reset) and are already covered by test/cypress/tests/tools/InlineTool.cy.ts, so this only fills the documentation gap. The wording mirrors the existing Block Tunes sections. Fixes #2401 --- docs/tools-inline.md | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/docs/tools-inline.md b/docs/tools-inline.md index 604a5e4c8..ad2cd98f1 100644 --- a/docs/tools-inline.md +++ b/docs/tools-inline.md @@ -18,6 +18,8 @@ Also, you can provide optional methods - `renderActions()` — create additional element below the buttons - `clear()` — clear Tool's stuff on opening/closing of Inline Toolbar - `sanitize()` — sanitizer configuration +- `prepare()` — prepare Tool's data on Editor's initialization (static) +- `reset()` — clean up Tool's data on Editor's destroy (static) At the constructor of Tool's class exemplar you will accept an object with the [API](api.md) as a parameter. @@ -104,6 +106,62 @@ Method does not accept any parameters Method should not return a value. +### static prepare() + +If you need to prepare some data for the Tool (eg. load external script, create HTML nodes in the document, etc) you can use the static `prepare()` method. + +It accepts the Tool's config passed on Editor's initialization as an argument: + +```javascript +class MyInlineTool { + static isInline = true; + + static prepare(config) { + loadScript(); + insertNodes(); + ... + } +} +``` + +#### Parameters + +type | description | +-- | -- | +`object` | your Tool configuration | + +#### Return value + +No return value + +--- + +### static reset() + +On Editor destroy you can use an opposite method `reset` to clean up all prepared data: + +```javascript +class MyInlineTool { + static isInline = true; + + static reset() { + cleanUpScripts(); + deleteNodes(); + ... + } +} +``` + +#### Parameters + +No parameters + +#### Return value + +No return value + +--- + ### static get sanitize() We recommend to specify the Sanitizer config that corresponds with inline tags that is used by your Tool.