@jackuait/blok 0.4.1-beta.1 → 0.4.1-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -17
- package/codemod/README.md +45 -7
- package/codemod/migrate-editorjs-to-blok.js +960 -92
- package/codemod/test.js +780 -77
- package/dist/blok.mjs +5 -2
- package/dist/chunks/blok-BU6NwVkN.mjs +13239 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-D8GzSwio.mjs +43 -0
- package/dist/{index-CEXLTV6f.mjs → chunks/index-C5e_WLFg.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-CLUxkCe_.mjs +1990 -0
- package/dist/chunks/messages-0tDXLuyH.mjs +48 -0
- package/dist/chunks/messages-2_xedlYw.mjs +48 -0
- package/dist/chunks/messages-AHESHJm_.mjs +48 -0
- package/dist/chunks/messages-B5hdXZwA.mjs +48 -0
- package/dist/chunks/messages-B5jGUnOy.mjs +48 -0
- package/dist/chunks/messages-B5puUm7R.mjs +48 -0
- package/dist/chunks/messages-B66ZSDCJ.mjs +48 -0
- package/dist/chunks/messages-B9Oba7sq.mjs +48 -0
- package/dist/chunks/messages-BA0rcTCY.mjs +48 -0
- package/dist/chunks/messages-BBJgd5jG.mjs +48 -0
- package/dist/chunks/messages-BPqWKx5Z.mjs +48 -0
- package/dist/chunks/messages-Bdv-IkfG.mjs +48 -0
- package/dist/chunks/messages-BeUhMpsr.mjs +48 -0
- package/dist/chunks/messages-Bf6Y3_GI.mjs +48 -0
- package/dist/chunks/messages-BiExzWJv.mjs +48 -0
- package/dist/chunks/messages-BlpqL8vG.mjs +48 -0
- package/dist/chunks/messages-BmKCChWZ.mjs +48 -0
- package/dist/chunks/messages-Bn253WWC.mjs +48 -0
- package/dist/chunks/messages-BrJHUxQL.mjs +48 -0
- package/dist/chunks/messages-C5b7hr_E.mjs +48 -0
- package/dist/chunks/messages-C7I_AVH2.mjs +48 -0
- package/dist/chunks/messages-CJoBtXU6.mjs +48 -0
- package/dist/chunks/messages-CQj2JU2j.mjs +48 -0
- package/dist/chunks/messages-CUZ1x1QD.mjs +48 -0
- package/dist/chunks/messages-CUy1vn-b.mjs +48 -0
- package/dist/chunks/messages-CVeWVKsV.mjs +48 -0
- package/dist/chunks/messages-CXHd9SUK.mjs +48 -0
- package/dist/chunks/messages-CbMyJSzS.mjs +48 -0
- package/dist/chunks/messages-CbhuIWRJ.mjs +48 -0
- package/dist/chunks/messages-CeCjVKMW.mjs +48 -0
- package/dist/chunks/messages-Cj-t1bdy.mjs +48 -0
- package/dist/chunks/messages-CkFT2gle.mjs +48 -0
- package/dist/chunks/messages-Cm9aLHeX.mjs +48 -0
- package/dist/chunks/messages-CnvW8Slp.mjs +48 -0
- package/dist/chunks/messages-Cr-RJ7YB.mjs +48 -0
- package/dist/chunks/messages-CrsJ1TEJ.mjs +48 -0
- package/dist/chunks/messages-Cu08aLS3.mjs +48 -0
- package/dist/chunks/messages-CvaqJFN-.mjs +48 -0
- package/dist/chunks/messages-CyDU5lz9.mjs +48 -0
- package/dist/chunks/messages-CySyfkMU.mjs +48 -0
- package/dist/chunks/messages-Cyi2AMmz.mjs +48 -0
- package/dist/chunks/messages-D00OjS2n.mjs +48 -0
- package/dist/chunks/messages-DDLgIPDF.mjs +48 -0
- package/dist/chunks/messages-DMQIHGRj.mjs +48 -0
- package/dist/chunks/messages-DOlC_Tty.mjs +48 -0
- package/dist/chunks/messages-DV6shA9b.mjs +48 -0
- package/dist/chunks/messages-DY94ykcE.mjs +48 -0
- package/dist/chunks/messages-DbVquYKN.mjs +48 -0
- package/dist/chunks/messages-DcKOuncK.mjs +48 -0
- package/dist/chunks/messages-Dg92dXZ5.mjs +48 -0
- package/dist/chunks/messages-DnbbyJT3.mjs +48 -0
- package/dist/chunks/messages-DteYq0rv.mjs +48 -0
- package/dist/chunks/messages-GC2PhgV3.mjs +48 -0
- package/dist/chunks/messages-JGsXAReJ.mjs +48 -0
- package/dist/chunks/messages-JZUhXTuV.mjs +48 -0
- package/dist/chunks/messages-LvFKBBPa.mjs +48 -0
- package/dist/chunks/messages-NP1myMGI.mjs +48 -0
- package/dist/chunks/messages-Q4kc_ZtL.mjs +48 -0
- package/dist/chunks/messages-RvMHb2Ht.mjs +48 -0
- package/dist/chunks/messages-ftMcCEuO.mjs +48 -0
- package/dist/chunks/messages-o24dK6CU.mjs +48 -0
- package/dist/chunks/messages-pA5TvcAj.mjs +48 -0
- package/dist/chunks/messages-rRSHQDCX.mjs +48 -0
- package/dist/chunks/messages-srxrv8Yh.mjs +48 -0
- package/dist/chunks/messages-wdqp4610.mjs +48 -0
- package/dist/chunks/messages-zS1AXZ0y.mjs +48 -0
- package/dist/chunks/messages-zSzDzXej.mjs +48 -0
- package/dist/full.mjs +50 -0
- package/dist/locales.mjs +228 -0
- package/dist/messages-0tDXLuyH.mjs +48 -0
- package/dist/messages-2_xedlYw.mjs +48 -0
- package/dist/messages-AHESHJm_.mjs +48 -0
- package/dist/messages-B5hdXZwA.mjs +48 -0
- package/dist/messages-B5jGUnOy.mjs +48 -0
- package/dist/messages-B5puUm7R.mjs +48 -0
- package/dist/messages-B66ZSDCJ.mjs +48 -0
- package/dist/messages-B9Oba7sq.mjs +48 -0
- package/dist/messages-BA0rcTCY.mjs +48 -0
- package/dist/messages-BBJgd5jG.mjs +48 -0
- package/dist/messages-BPqWKx5Z.mjs +48 -0
- package/dist/messages-Bdv-IkfG.mjs +48 -0
- package/dist/messages-BeUhMpsr.mjs +48 -0
- package/dist/messages-Bf6Y3_GI.mjs +48 -0
- package/dist/messages-BiExzWJv.mjs +48 -0
- package/dist/messages-BlpqL8vG.mjs +48 -0
- package/dist/messages-BmKCChWZ.mjs +48 -0
- package/dist/messages-Bn253WWC.mjs +48 -0
- package/dist/messages-BrJHUxQL.mjs +48 -0
- package/dist/messages-C5b7hr_E.mjs +48 -0
- package/dist/messages-C7I_AVH2.mjs +48 -0
- package/dist/messages-CJoBtXU6.mjs +48 -0
- package/dist/messages-CQj2JU2j.mjs +48 -0
- package/dist/messages-CUZ1x1QD.mjs +48 -0
- package/dist/messages-CUy1vn-b.mjs +48 -0
- package/dist/messages-CVeWVKsV.mjs +48 -0
- package/dist/messages-CXHd9SUK.mjs +48 -0
- package/dist/messages-CbMyJSzS.mjs +48 -0
- package/dist/messages-CbhuIWRJ.mjs +48 -0
- package/dist/messages-CeCjVKMW.mjs +48 -0
- package/dist/messages-Cj-t1bdy.mjs +48 -0
- package/dist/messages-CkFT2gle.mjs +48 -0
- package/dist/messages-Cm9aLHeX.mjs +48 -0
- package/dist/messages-CnvW8Slp.mjs +48 -0
- package/dist/messages-Cr-RJ7YB.mjs +48 -0
- package/dist/messages-CrsJ1TEJ.mjs +48 -0
- package/dist/messages-Cu08aLS3.mjs +48 -0
- package/dist/messages-CvaqJFN-.mjs +48 -0
- package/dist/messages-CyDU5lz9.mjs +48 -0
- package/dist/messages-CySyfkMU.mjs +48 -0
- package/dist/messages-Cyi2AMmz.mjs +48 -0
- package/dist/messages-D00OjS2n.mjs +48 -0
- package/dist/messages-DDLgIPDF.mjs +48 -0
- package/dist/messages-DMQIHGRj.mjs +48 -0
- package/dist/messages-DOlC_Tty.mjs +48 -0
- package/dist/messages-DV6shA9b.mjs +48 -0
- package/dist/messages-DY94ykcE.mjs +48 -0
- package/dist/messages-DbVquYKN.mjs +48 -0
- package/dist/messages-DcKOuncK.mjs +48 -0
- package/dist/messages-Dg92dXZ5.mjs +48 -0
- package/dist/messages-DnbbyJT3.mjs +48 -0
- package/dist/messages-DteYq0rv.mjs +48 -0
- package/dist/messages-GC2PhgV3.mjs +48 -0
- package/dist/messages-JGsXAReJ.mjs +48 -0
- package/dist/messages-JZUhXTuV.mjs +48 -0
- package/dist/messages-LvFKBBPa.mjs +48 -0
- package/dist/messages-NP1myMGI.mjs +48 -0
- package/dist/messages-Q4kc_ZtL.mjs +48 -0
- package/dist/messages-RvMHb2Ht.mjs +48 -0
- package/dist/messages-ftMcCEuO.mjs +48 -0
- package/dist/messages-o24dK6CU.mjs +48 -0
- package/dist/messages-pA5TvcAj.mjs +48 -0
- package/dist/messages-rRSHQDCX.mjs +48 -0
- package/dist/messages-srxrv8Yh.mjs +48 -0
- package/dist/messages-wdqp4610.mjs +48 -0
- package/dist/messages-zS1AXZ0y.mjs +48 -0
- package/dist/messages-zSzDzXej.mjs +48 -0
- package/dist/tools.mjs +3126 -0
- package/dist/vendor.LICENSE.txt +26 -225
- package/package.json +63 -24
- package/src/blok.ts +267 -0
- package/src/components/__module.ts +139 -0
- package/src/components/block/api.ts +155 -0
- package/src/components/block/index.ts +1428 -0
- package/src/components/block-tunes/block-tune-delete.ts +51 -0
- package/src/components/blocks.ts +352 -0
- package/src/components/constants/data-attributes.ts +344 -0
- package/src/components/constants.ts +76 -0
- package/src/components/core.ts +392 -0
- package/src/components/dom.ts +773 -0
- package/src/components/domIterator.ts +189 -0
- package/src/components/errors/critical.ts +5 -0
- package/src/components/events/BlockChanged.ts +16 -0
- package/src/components/events/BlockHovered.ts +21 -0
- package/src/components/events/BlockSettingsClosed.ts +12 -0
- package/src/components/events/BlockSettingsOpened.ts +12 -0
- package/src/components/events/BlokMobileLayoutToggled.ts +15 -0
- package/src/components/events/FakeCursorAboutToBeToggled.ts +17 -0
- package/src/components/events/FakeCursorHaveBeenSet.ts +17 -0
- package/src/components/events/HistoryStateChanged.ts +19 -0
- package/src/components/events/RedactorDomChanged.ts +14 -0
- package/src/components/events/index.ts +46 -0
- package/src/components/flipper.ts +497 -0
- package/src/components/i18n/i18next-loader.ts +84 -0
- package/src/components/i18n/lightweight-i18n.ts +86 -0
- package/src/components/i18n/locales/TRANSLATION_GUIDELINES.md +113 -0
- package/src/components/i18n/locales/am/messages.json +45 -0
- package/src/components/i18n/locales/ar/messages.json +45 -0
- package/src/components/i18n/locales/az/messages.json +45 -0
- package/src/components/i18n/locales/bg/messages.json +45 -0
- package/src/components/i18n/locales/bn/messages.json +45 -0
- package/src/components/i18n/locales/bs/messages.json +45 -0
- package/src/components/i18n/locales/cs/messages.json +45 -0
- package/src/components/i18n/locales/da/messages.json +45 -0
- package/src/components/i18n/locales/de/messages.json +45 -0
- package/src/components/i18n/locales/dv/messages.json +45 -0
- package/src/components/i18n/locales/el/messages.json +45 -0
- package/src/components/i18n/locales/en/messages.json +45 -0
- package/src/components/i18n/locales/es/messages.json +45 -0
- package/src/components/i18n/locales/et/messages.json +45 -0
- package/src/components/i18n/locales/fa/messages.json +45 -0
- package/src/components/i18n/locales/fi/messages.json +45 -0
- package/src/components/i18n/locales/fil/messages.json +45 -0
- package/src/components/i18n/locales/fr/messages.json +45 -0
- package/src/components/i18n/locales/gu/messages.json +45 -0
- package/src/components/i18n/locales/he/messages.json +45 -0
- package/src/components/i18n/locales/hi/messages.json +45 -0
- package/src/components/i18n/locales/hr/messages.json +45 -0
- package/src/components/i18n/locales/hu/messages.json +45 -0
- package/src/components/i18n/locales/hy/messages.json +45 -0
- package/src/components/i18n/locales/id/messages.json +45 -0
- package/src/components/i18n/locales/index.ts +231 -0
- package/src/components/i18n/locales/it/messages.json +45 -0
- package/src/components/i18n/locales/ja/messages.json +45 -0
- package/src/components/i18n/locales/ka/messages.json +45 -0
- package/src/components/i18n/locales/km/messages.json +45 -0
- package/src/components/i18n/locales/kn/messages.json +45 -0
- package/src/components/i18n/locales/ko/messages.json +45 -0
- package/src/components/i18n/locales/ku/messages.json +45 -0
- package/src/components/i18n/locales/lo/messages.json +45 -0
- package/src/components/i18n/locales/lt/messages.json +45 -0
- package/src/components/i18n/locales/lv/messages.json +45 -0
- package/src/components/i18n/locales/mk/messages.json +45 -0
- package/src/components/i18n/locales/ml/messages.json +45 -0
- package/src/components/i18n/locales/mn/messages.json +45 -0
- package/src/components/i18n/locales/mr/messages.json +45 -0
- package/src/components/i18n/locales/ms/messages.json +45 -0
- package/src/components/i18n/locales/my/messages.json +45 -0
- package/src/components/i18n/locales/ne/messages.json +45 -0
- package/src/components/i18n/locales/nl/messages.json +45 -0
- package/src/components/i18n/locales/no/messages.json +45 -0
- package/src/components/i18n/locales/pa/messages.json +45 -0
- package/src/components/i18n/locales/pl/messages.json +45 -0
- package/src/components/i18n/locales/ps/messages.json +45 -0
- package/src/components/i18n/locales/pt/messages.json +45 -0
- package/src/components/i18n/locales/ro/messages.json +45 -0
- package/src/components/i18n/locales/ru/messages.json +45 -0
- package/src/components/i18n/locales/sd/messages.json +45 -0
- package/src/components/i18n/locales/si/messages.json +45 -0
- package/src/components/i18n/locales/sk/messages.json +45 -0
- package/src/components/i18n/locales/sl/messages.json +45 -0
- package/src/components/i18n/locales/sq/messages.json +45 -0
- package/src/components/i18n/locales/sr/messages.json +45 -0
- package/src/components/i18n/locales/sv/messages.json +45 -0
- package/src/components/i18n/locales/sw/messages.json +45 -0
- package/src/components/i18n/locales/ta/messages.json +45 -0
- package/src/components/i18n/locales/te/messages.json +45 -0
- package/src/components/i18n/locales/th/messages.json +45 -0
- package/src/components/i18n/locales/tr/messages.json +45 -0
- package/src/components/i18n/locales/ug/messages.json +45 -0
- package/src/components/i18n/locales/uk/messages.json +45 -0
- package/src/components/i18n/locales/ur/messages.json +45 -0
- package/src/components/i18n/locales/vi/messages.json +45 -0
- package/src/components/i18n/locales/yi/messages.json +45 -0
- package/src/components/i18n/locales/zh/messages.json +45 -0
- package/src/components/icons/index.ts +242 -0
- package/src/components/inline-tools/inline-tool-bold.ts +2213 -0
- package/src/components/inline-tools/inline-tool-convert.ts +142 -0
- package/src/components/inline-tools/inline-tool-italic.ts +500 -0
- package/src/components/inline-tools/inline-tool-link.ts +540 -0
- package/src/components/modules/api/blocks.ts +377 -0
- package/src/components/modules/api/caret.ts +125 -0
- package/src/components/modules/api/events.ts +51 -0
- package/src/components/modules/api/history.ts +73 -0
- package/src/components/modules/api/i18n.ts +35 -0
- package/src/components/modules/api/index.ts +39 -0
- package/src/components/modules/api/inlineToolbar.ts +33 -0
- package/src/components/modules/api/listeners.ts +56 -0
- package/src/components/modules/api/notifier.ts +46 -0
- package/src/components/modules/api/readonly.ts +39 -0
- package/src/components/modules/api/sanitizer.ts +30 -0
- package/src/components/modules/api/saver.ts +52 -0
- package/src/components/modules/api/selection.ts +48 -0
- package/src/components/modules/api/styles.ts +72 -0
- package/src/components/modules/api/toolbar.ts +79 -0
- package/src/components/modules/api/tools.ts +16 -0
- package/src/components/modules/api/tooltip.ts +67 -0
- package/src/components/modules/api/ui.ts +36 -0
- package/src/components/modules/blockEvents.ts +1591 -0
- package/src/components/modules/blockManager.ts +1356 -0
- package/src/components/modules/blockSelection.ts +708 -0
- package/src/components/modules/caret.ts +853 -0
- package/src/components/modules/crossBlockSelection.ts +329 -0
- package/src/components/modules/dragManager.ts +1204 -0
- package/src/components/modules/history.ts +1098 -0
- package/src/components/modules/i18n.ts +332 -0
- package/src/components/modules/index.ts +139 -0
- package/src/components/modules/modificationsObserver.ts +147 -0
- package/src/components/modules/paste.ts +1092 -0
- package/src/components/modules/readonly.ts +136 -0
- package/src/components/modules/rectangleSelection.ts +711 -0
- package/src/components/modules/renderer.ts +155 -0
- package/src/components/modules/saver.ts +283 -0
- package/src/components/modules/toolbar/blockSettings.ts +782 -0
- package/src/components/modules/toolbar/index.ts +1296 -0
- package/src/components/modules/toolbar/inline.ts +956 -0
- package/src/components/modules/tools.ts +625 -0
- package/src/components/modules/ui.ts +1283 -0
- package/src/components/polyfills.ts +113 -0
- package/src/components/selection.ts +1179 -0
- package/src/components/tools/base.ts +301 -0
- package/src/components/tools/block.ts +339 -0
- package/src/components/tools/collection.ts +67 -0
- package/src/components/tools/factory.ts +138 -0
- package/src/components/tools/inline.ts +71 -0
- package/src/components/tools/tune.ts +33 -0
- package/src/components/ui/toolbox.ts +610 -0
- package/src/components/utils/announcer.ts +205 -0
- package/src/components/utils/api.ts +20 -0
- package/src/components/utils/bem.ts +26 -0
- package/src/components/utils/blocks.ts +284 -0
- package/src/components/utils/caret.ts +1067 -0
- package/src/components/utils/data-model-transform.ts +382 -0
- package/src/components/utils/events.ts +117 -0
- package/src/components/utils/keyboard.ts +60 -0
- package/src/components/utils/listeners.ts +296 -0
- package/src/components/utils/mutations.ts +39 -0
- package/src/components/utils/notifier/draw.ts +190 -0
- package/src/components/utils/notifier/index.ts +66 -0
- package/src/components/utils/notifier/types.ts +1 -0
- package/src/components/utils/notifier.ts +77 -0
- package/src/components/utils/placeholder.ts +140 -0
- package/src/components/utils/popover/components/hint/hint.const.ts +10 -0
- package/src/components/utils/popover/components/hint/hint.ts +46 -0
- package/src/components/utils/popover/components/hint/index.ts +6 -0
- package/src/components/utils/popover/components/popover-header/index.ts +2 -0
- package/src/components/utils/popover/components/popover-header/popover-header.const.ts +8 -0
- package/src/components/utils/popover/components/popover-header/popover-header.ts +80 -0
- package/src/components/utils/popover/components/popover-header/popover-header.types.ts +14 -0
- package/src/components/utils/popover/components/popover-item/index.ts +13 -0
- package/src/components/utils/popover/components/popover-item/popover-item-default/popover-item-default.const.ts +50 -0
- package/src/components/utils/popover/components/popover-item/popover-item-default/popover-item-default.ts +680 -0
- package/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.const.ts +14 -0
- package/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.ts +136 -0
- package/src/components/utils/popover/components/popover-item/popover-item-separator/popover-item-separator.const.ts +20 -0
- package/src/components/utils/popover/components/popover-item/popover-item-separator/popover-item-separator.ts +117 -0
- package/src/components/utils/popover/components/popover-item/popover-item.ts +197 -0
- package/src/components/utils/popover/components/search-input/index.ts +2 -0
- package/src/components/utils/popover/components/search-input/search-input.const.ts +8 -0
- package/src/components/utils/popover/components/search-input/search-input.ts +178 -0
- package/src/components/utils/popover/components/search-input/search-input.types.ts +59 -0
- package/src/components/utils/popover/index.ts +13 -0
- package/src/components/utils/popover/popover-abstract.ts +457 -0
- package/src/components/utils/popover/popover-desktop.ts +682 -0
- package/src/components/utils/popover/popover-inline.ts +338 -0
- package/src/components/utils/popover/popover-mobile.ts +201 -0
- package/src/components/utils/popover/popover.const.ts +81 -0
- package/src/components/utils/popover/utils/popover-states-history.ts +72 -0
- package/src/components/utils/promise-queue.ts +43 -0
- package/src/components/utils/sanitizer.ts +537 -0
- package/src/components/utils/scroll-locker.ts +87 -0
- package/src/components/utils/shortcut.ts +231 -0
- package/src/components/utils/shortcuts.ts +113 -0
- package/src/components/utils/tools.ts +110 -0
- package/src/components/utils/tooltip.ts +591 -0
- package/src/components/utils/tw.ts +241 -0
- package/src/components/utils.ts +1081 -0
- package/src/env.d.ts +13 -0
- package/src/full.ts +69 -0
- package/src/locales.ts +51 -0
- package/src/stories/Block.stories.ts +498 -0
- package/src/stories/EditorModes.stories.ts +505 -0
- package/src/stories/Header.stories.ts +137 -0
- package/src/stories/InlineToolbar.stories.ts +498 -0
- package/src/stories/List.stories.ts +259 -0
- package/src/stories/Notifier.stories.ts +340 -0
- package/src/stories/Paragraph.stories.ts +112 -0
- package/src/stories/Placeholder.stories.ts +319 -0
- package/src/stories/Popover.stories.ts +759 -0
- package/src/stories/Selection.stories.ts +250 -0
- package/src/stories/StubBlock.stories.ts +156 -0
- package/src/stories/Toolbar.stories.ts +223 -0
- package/src/stories/Toolbox.stories.ts +166 -0
- package/src/stories/Tooltip.stories.ts +198 -0
- package/src/stories/helpers.ts +463 -0
- package/src/styles/main.css +126 -0
- package/src/tools/header/index.ts +647 -0
- package/src/tools/index.ts +45 -0
- package/src/tools/list/index.ts +1826 -0
- package/src/tools/paragraph/index.ts +412 -0
- package/src/tools/stub/index.ts +107 -0
- package/src/types-internal/blok-modules.d.ts +87 -0
- package/src/types-internal/html-janitor.d.ts +28 -0
- package/src/types-internal/module-config.d.ts +11 -0
- package/src/variants/all-locales.ts +155 -0
- package/src/variants/blok-maximum.ts +20 -0
- package/src/variants/blok-minimum.ts +243 -0
- package/types/api/blocks.d.ts +9 -1
- package/types/api/history.d.ts +7 -0
- package/types/api/i18n.d.ts +22 -3
- package/types/api/selection.d.ts +6 -0
- package/types/api/styles.d.ts +23 -10
- package/types/configs/blok-config.d.ts +29 -0
- package/types/configs/i18n-config.d.ts +52 -2
- package/types/configs/i18n-dictionary.d.ts +16 -90
- package/types/configs/sanitizer-config.d.ts +25 -1
- package/types/data-attributes.d.ts +170 -0
- package/types/data-formats/output-data.d.ts +15 -0
- package/types/full.d.ts +80 -0
- package/types/index.d.ts +30 -13
- package/types/locales.d.ts +59 -0
- package/types/tools/adapters/inline-tool-adapter.d.ts +10 -0
- package/types/tools/block-tool.d.ts +11 -2
- package/types/tools/header.d.ts +18 -0
- package/types/tools/index.d.ts +1 -0
- package/types/tools/list.d.ts +91 -0
- package/types/tools/paragraph.d.ts +71 -0
- package/types/tools/tool-settings.d.ts +99 -6
- package/types/tools/tool.d.ts +6 -0
- package/types/tools-entry.d.ts +49 -0
- package/types/utils/popover/popover-item.d.ts +24 -5
- package/types/utils/popover/popover.d.ts +13 -0
- package/dist/blok-C8XbyLHh.mjs +0 -25795
- package/dist/blok.umd.js +0 -181
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import { Module } from '../__module';
|
|
2
|
+
import { deepMerge, isFunction, isObject, isUndefined, log } from '../utils';
|
|
3
|
+
import { PromiseQueue } from '../utils/promise-queue';
|
|
4
|
+
import type { SanitizerConfig, ToolConfig, ToolConstructable, ToolSettings } from '../../../types';
|
|
5
|
+
import { Stub } from '../../tools/stub';
|
|
6
|
+
import { ToolsFactory } from '../tools/factory';
|
|
7
|
+
import type { InlineToolAdapter } from '../tools/inline';
|
|
8
|
+
import type { BlockToolAdapter } from '../tools/block';
|
|
9
|
+
import type { BlockTuneAdapter } from '../tools/tune';
|
|
10
|
+
import { DeleteTune } from '../block-tunes/block-tune-delete';
|
|
11
|
+
import { ConvertInlineTool } from '../inline-tools/inline-tool-convert';
|
|
12
|
+
import { ToolsCollection } from '../tools/collection';
|
|
13
|
+
import { CriticalError } from '../errors/critical';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} ChainData
|
|
17
|
+
* @property {object} data - data that will be passed to the success or fallback
|
|
18
|
+
* @property {Function} function - function's that must be called asynchronously
|
|
19
|
+
* @interface ChainData
|
|
20
|
+
*/
|
|
21
|
+
export interface ChainData {
|
|
22
|
+
data?: object;
|
|
23
|
+
function: (data?: object) => unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type ToolPrepareData = {
|
|
27
|
+
toolName: string;
|
|
28
|
+
config: ToolConfig;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ToolPrepareFunction = (data: ToolPrepareData) => void | Promise<void>;
|
|
32
|
+
|
|
33
|
+
const toToolConstructable = (constructable: unknown): ToolConstructable => {
|
|
34
|
+
if (!isFunction(constructable)) {
|
|
35
|
+
throw new Error('Tool constructable must be a function');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return constructable as unknown as ToolConstructable;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @module Blok Tools Submodule
|
|
43
|
+
*
|
|
44
|
+
* Creates Instances from Plugins and binds external config to the instances
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Modules that works with tools classes
|
|
49
|
+
*/
|
|
50
|
+
export class Tools extends Module {
|
|
51
|
+
/**
|
|
52
|
+
* Name of Stub Tool
|
|
53
|
+
* Stub Tool is used to substitute unavailable block Tools and store their data
|
|
54
|
+
* @type {string}
|
|
55
|
+
*/
|
|
56
|
+
public stubTool = 'stub';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns available Tools
|
|
60
|
+
*/
|
|
61
|
+
public get available(): ToolsCollection {
|
|
62
|
+
return this.toolsAvailable;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Returns unavailable Tools
|
|
67
|
+
*/
|
|
68
|
+
public get unavailable(): ToolsCollection {
|
|
69
|
+
return this.toolsUnavailable;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Return Tools for the Inline Toolbar
|
|
74
|
+
*/
|
|
75
|
+
public get inlineTools(): ToolsCollection<InlineToolAdapter> {
|
|
76
|
+
return this.available.inlineTools;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Return blok block tools
|
|
81
|
+
*/
|
|
82
|
+
public get blockTools(): ToolsCollection<BlockToolAdapter> {
|
|
83
|
+
return this.available.blockTools;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Return available Block Tunes
|
|
88
|
+
* @returns {object} - object of Inline Tool's classes
|
|
89
|
+
*/
|
|
90
|
+
public get blockTunes(): ToolsCollection<BlockTuneAdapter> {
|
|
91
|
+
return this.available.blockTunes;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Returns default Tool object
|
|
96
|
+
*/
|
|
97
|
+
public get defaultTool(): BlockToolAdapter {
|
|
98
|
+
const defaultBlockName = this.config.defaultBlock;
|
|
99
|
+
|
|
100
|
+
if (!defaultBlockName) {
|
|
101
|
+
throw new Error('Default block tool name is not configured');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const tool = this.blockTools.get(defaultBlockName);
|
|
105
|
+
|
|
106
|
+
if (!tool) {
|
|
107
|
+
throw new Error(`Default block tool "${defaultBlockName}" not found in available block tools`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return tool;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Tools objects factory
|
|
115
|
+
*/
|
|
116
|
+
private factory: ToolsFactory | null = null;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Tools` classes available to use
|
|
120
|
+
*/
|
|
121
|
+
private readonly toolsAvailable: ToolsCollection = new ToolsCollection();
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Tools` classes not available to use because of preparation failure
|
|
125
|
+
*/
|
|
126
|
+
private readonly toolsUnavailable: ToolsCollection = new ToolsCollection();
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Cache for the sanitizer config
|
|
130
|
+
*/
|
|
131
|
+
private inlineToolsSanitizeConfigCache: SanitizerConfig | null = null;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Returns internal tools
|
|
135
|
+
*/
|
|
136
|
+
public get internal(): ToolsCollection {
|
|
137
|
+
return this.available.internalTools;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Creates instances via passed or default configuration
|
|
142
|
+
* @returns {Promise<void>}
|
|
143
|
+
*/
|
|
144
|
+
public async prepare(): Promise<void> {
|
|
145
|
+
/**
|
|
146
|
+
* Assign internal tools before validation so required fallbacks (like stub) are always present
|
|
147
|
+
*/
|
|
148
|
+
const userTools = this.config.tools ?? {};
|
|
149
|
+
|
|
150
|
+
this.config.tools = deepMerge({}, this.internalTools, userTools);
|
|
151
|
+
|
|
152
|
+
this.validateTools();
|
|
153
|
+
|
|
154
|
+
const toolsConfig = this.config.tools;
|
|
155
|
+
|
|
156
|
+
if (!toolsConfig || Object.keys(toolsConfig).length === 0) {
|
|
157
|
+
throw Error('Can\'t start without tools');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const config = this.prepareConfig(toolsConfig);
|
|
161
|
+
|
|
162
|
+
this.factory = new ToolsFactory(config, this.config, this.Blok.API);
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* getting classes that has prepare method
|
|
166
|
+
*/
|
|
167
|
+
const sequenceData = this.getListOfPrepareFunctions(config);
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* if sequence data contains nothing then resolve current chain and run other module prepare
|
|
171
|
+
*/
|
|
172
|
+
if (sequenceData.length === 0) {
|
|
173
|
+
return Promise.resolve();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const handlePrepareSuccess = (data: object): void => {
|
|
177
|
+
if (!this.isToolPrepareData(data)) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.toolPrepareMethodSuccess({ toolName: data.toolName });
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const handlePrepareFallback = (data: object): void => {
|
|
185
|
+
if (!this.isToolPrepareData(data)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this.toolPrepareMethodFallback({ toolName: data.toolName });
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const queue = new PromiseQueue();
|
|
193
|
+
|
|
194
|
+
sequenceData.forEach(chainData => {
|
|
195
|
+
void queue.add(async () => {
|
|
196
|
+
const callbackData = !isUndefined(chainData.data) ? chainData.data : {};
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
await chainData.function(chainData.data);
|
|
200
|
+
handlePrepareSuccess(callbackData);
|
|
201
|
+
} catch (_error) {
|
|
202
|
+
handlePrepareFallback(callbackData);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await queue.completed;
|
|
208
|
+
|
|
209
|
+
this.prepareBlockTools();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Return general Sanitizer config for all inline tools
|
|
214
|
+
*/
|
|
215
|
+
public getAllInlineToolsSanitizeConfig(): SanitizerConfig {
|
|
216
|
+
if (this.inlineToolsSanitizeConfigCache) {
|
|
217
|
+
return this.inlineToolsSanitizeConfigCache;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const config: SanitizerConfig = {} as SanitizerConfig;
|
|
221
|
+
|
|
222
|
+
Array.from(this.inlineTools.values())
|
|
223
|
+
.forEach(inlineTool => {
|
|
224
|
+
Object.assign(config, inlineTool.sanitizeConfig);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
this.inlineToolsSanitizeConfigCache = config;
|
|
228
|
+
|
|
229
|
+
return config;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Calls each Tool reset method to clean up anything set by Tool
|
|
234
|
+
*/
|
|
235
|
+
public destroy(): void {
|
|
236
|
+
for (const tool of this.available.values()) {
|
|
237
|
+
const resetResult = (() => {
|
|
238
|
+
try {
|
|
239
|
+
return tool.reset();
|
|
240
|
+
} catch (error) {
|
|
241
|
+
log(`Tool "${tool.name}" reset failed`, 'warn', error);
|
|
242
|
+
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
})();
|
|
246
|
+
|
|
247
|
+
if (resetResult instanceof Promise) {
|
|
248
|
+
resetResult.catch(error => {
|
|
249
|
+
log(`Tool "${tool.name}" reset failed`, 'warn', error);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Returns essential internal tools that are always bundled.
|
|
257
|
+
* Includes:
|
|
258
|
+
* - stub: for graceful handling of unknown block types
|
|
259
|
+
* - delete: fundamental block operation in settings menu
|
|
260
|
+
* - convertTo: inline tool for converting blocks between types
|
|
261
|
+
*
|
|
262
|
+
* Other tools (paragraph, header, list, bold, italic, link) are optional
|
|
263
|
+
* and should be imported from '@jackuait/blok/tools' or '@jackuait/blok/full'.
|
|
264
|
+
*/
|
|
265
|
+
private get internalTools(): { [toolName: string]: ToolConstructable | ToolSettings & { isInternal?: boolean } } {
|
|
266
|
+
return {
|
|
267
|
+
stub: {
|
|
268
|
+
class: toToolConstructable(Stub),
|
|
269
|
+
isInternal: true,
|
|
270
|
+
},
|
|
271
|
+
delete: {
|
|
272
|
+
class: toToolConstructable(DeleteTune),
|
|
273
|
+
isInternal: true,
|
|
274
|
+
},
|
|
275
|
+
convertTo: {
|
|
276
|
+
class: toToolConstructable(ConvertInlineTool),
|
|
277
|
+
isInternal: true,
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Tool prepare method success callback
|
|
284
|
+
* @param {object} data - append tool to available list
|
|
285
|
+
*/
|
|
286
|
+
private toolPrepareMethodSuccess(data: { toolName: string }): void {
|
|
287
|
+
const tool = this.getFactory().get(data.toolName);
|
|
288
|
+
|
|
289
|
+
if (!tool.isInline()) {
|
|
290
|
+
this.toolsAvailable.set(tool.name, tool);
|
|
291
|
+
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Some Tools validation
|
|
297
|
+
*/
|
|
298
|
+
const inlineToolRequiredMethods = [ 'render' ];
|
|
299
|
+
const notImplementedMethods = tool.getMissingMethods(inlineToolRequiredMethods);
|
|
300
|
+
|
|
301
|
+
if (notImplementedMethods.length) {
|
|
302
|
+
log(
|
|
303
|
+
`Incorrect Inline Tool: ${tool.name}. Some of required methods is not implemented %o`,
|
|
304
|
+
'warn',
|
|
305
|
+
notImplementedMethods
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
this.toolsUnavailable.set(tool.name, tool);
|
|
309
|
+
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
this.toolsAvailable.set(tool.name, tool);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Tool prepare method fail callback
|
|
318
|
+
* @param {object} data - append tool to unavailable list
|
|
319
|
+
*/
|
|
320
|
+
private toolPrepareMethodFallback(data: { toolName: string }): void {
|
|
321
|
+
const factory = this.getFactory();
|
|
322
|
+
|
|
323
|
+
this.toolsUnavailable.set(data.toolName, factory.get(data.toolName));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Binds prepare function of plugins with user or default config
|
|
328
|
+
* @returns {Array} list of functions that needs to be fired sequentially
|
|
329
|
+
* @param config - tools config
|
|
330
|
+
*/
|
|
331
|
+
private getListOfPrepareFunctions(config: Record<string, ToolSettings>): ChainData[] {
|
|
332
|
+
return Object
|
|
333
|
+
.entries(config)
|
|
334
|
+
.map(([toolName, settings]): ChainData => {
|
|
335
|
+
const toolData: ToolPrepareData = {
|
|
336
|
+
toolName,
|
|
337
|
+
config: this.extractToolConfig(settings),
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const prepareFunction: ChainData['function'] = async (payload?: unknown) => {
|
|
341
|
+
const constructable = settings.class as ToolConstructable | undefined;
|
|
342
|
+
|
|
343
|
+
if (!constructable || !isFunction(constructable.prepare)) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const data = (payload ?? toolData) as ToolPrepareData;
|
|
348
|
+
const prepareMethod = constructable.prepare as ToolPrepareFunction;
|
|
349
|
+
|
|
350
|
+
return prepareMethod.call(constructable, data);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
function: prepareFunction,
|
|
355
|
+
data: toolData,
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Keys that are Blok-level settings (not passed to tool constructor)
|
|
362
|
+
*/
|
|
363
|
+
private static readonly BLOK_SETTINGS_KEYS = new Set([
|
|
364
|
+
'class',
|
|
365
|
+
'inlineToolbar',
|
|
366
|
+
'tunes',
|
|
367
|
+
'shortcut',
|
|
368
|
+
'toolbox',
|
|
369
|
+
'config',
|
|
370
|
+
'isInternal',
|
|
371
|
+
]);
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Extracts tool configuration from settings.
|
|
375
|
+
* Merges nested config with flat tool-specific options (flat takes precedence).
|
|
376
|
+
* @param settings - Tool settings from user config
|
|
377
|
+
* @returns Merged tool configuration
|
|
378
|
+
*/
|
|
379
|
+
private extractToolConfig(settings: ToolSettings): ToolConfig {
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Internal: reading legacy config for backwards compatibility
|
|
381
|
+
const nestedConfig = (settings.config ?? {}) as ToolConfig;
|
|
382
|
+
|
|
383
|
+
// Extract non-Blok keys as tool-specific config
|
|
384
|
+
const flatConfig: Record<string, unknown> = {};
|
|
385
|
+
|
|
386
|
+
for (const key of Object.keys(settings)) {
|
|
387
|
+
if (!Tools.BLOK_SETTINGS_KEYS.has(key)) {
|
|
388
|
+
flatConfig[key] = settings[key as keyof typeof settings];
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Merge: nested config first, flat config overrides
|
|
393
|
+
return { ...nestedConfig, ...flatConfig } as ToolConfig;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Assign enabled Inline Tools and Block Tunes for Block Tool
|
|
398
|
+
*/
|
|
399
|
+
private prepareBlockTools(): void {
|
|
400
|
+
Array.from(this.blockTools.values()).forEach(tool => {
|
|
401
|
+
this.assignInlineToolsToBlockTool(tool);
|
|
402
|
+
this.assignBlockTunesToBlockTool(tool);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Assign enabled Inline Tools for Block Tool
|
|
408
|
+
* @param tool - Block Tool
|
|
409
|
+
*/
|
|
410
|
+
private assignInlineToolsToBlockTool(tool: BlockToolAdapter): void {
|
|
411
|
+
const blockTool = tool;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* If common inlineToolbar property is false no Inline Tools should be assigned
|
|
415
|
+
*/
|
|
416
|
+
if (this.config.inlineToolbar === false) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* If user pass just 'true' for tool, get common inlineToolbar settings
|
|
422
|
+
* - if common settings is an array, use it
|
|
423
|
+
* - if common settings is 'true' or not specified, get default order
|
|
424
|
+
*/
|
|
425
|
+
if (blockTool.enabledInlineTools === true) {
|
|
426
|
+
const inlineTools = Array.isArray(this.config.inlineToolbar)
|
|
427
|
+
? this.createInlineToolsCollection(this.config.inlineToolbar)
|
|
428
|
+
/**
|
|
429
|
+
* If common settings is 'true' or not specified (will be set as true at core.ts), get the default order.
|
|
430
|
+
* Prepend convertTo so it appears first (same as when explicit array is passed).
|
|
431
|
+
*/
|
|
432
|
+
: this.createInlineToolsCollection(['convertTo', ...this.inlineTools.keys()]);
|
|
433
|
+
|
|
434
|
+
blockTool.inlineTools = inlineTools;
|
|
435
|
+
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* If user pass the list of inline tools for the particular tool, return it.
|
|
441
|
+
*/
|
|
442
|
+
if (Array.isArray(blockTool.enabledInlineTools)) {
|
|
443
|
+
/** Prepend ConvertTo Inline Tool */
|
|
444
|
+
const inlineTools = this.createInlineToolsCollection(['convertTo', ...blockTool.enabledInlineTools]);
|
|
445
|
+
|
|
446
|
+
blockTool.inlineTools = inlineTools;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Assign enabled Block Tunes for Block Tool
|
|
452
|
+
* @param tool — Block Tool
|
|
453
|
+
*/
|
|
454
|
+
private assignBlockTunesToBlockTool(tool: BlockToolAdapter): void {
|
|
455
|
+
const blockTool = tool;
|
|
456
|
+
|
|
457
|
+
if (blockTool.enabledBlockTunes === false) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (Array.isArray(blockTool.enabledBlockTunes)) {
|
|
462
|
+
const userTunes = this.createBlockTunesCollection(blockTool.enabledBlockTunes);
|
|
463
|
+
const combinedEntries = [
|
|
464
|
+
...Array.from(userTunes.entries()),
|
|
465
|
+
...Array.from(this.blockTunes.internalTools.entries()),
|
|
466
|
+
];
|
|
467
|
+
|
|
468
|
+
blockTool.tunes = new ToolsCollection<BlockTuneAdapter>(combinedEntries);
|
|
469
|
+
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (Array.isArray(this.config.tunes)) {
|
|
474
|
+
const userTunes = this.createBlockTunesCollection(this.config.tunes);
|
|
475
|
+
const combinedEntries = [
|
|
476
|
+
...Array.from(userTunes.entries()),
|
|
477
|
+
...Array.from(this.blockTunes.internalTools.entries()),
|
|
478
|
+
];
|
|
479
|
+
|
|
480
|
+
blockTool.tunes = new ToolsCollection<BlockTuneAdapter>(combinedEntries);
|
|
481
|
+
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
blockTool.tunes = new ToolsCollection<BlockTuneAdapter>(
|
|
486
|
+
Array.from(this.blockTunes.internalTools.entries())
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Validate Tools configuration objects and throw Error for user if it is invalid
|
|
492
|
+
*/
|
|
493
|
+
private validateTools(): void {
|
|
494
|
+
const toolsConfig = this.config.tools;
|
|
495
|
+
|
|
496
|
+
if (!toolsConfig) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const internalTools = this.internalTools;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Check Tools for a class containing
|
|
504
|
+
*/
|
|
505
|
+
for (const toolName in toolsConfig) {
|
|
506
|
+
if (!Object.prototype.hasOwnProperty.call(toolsConfig, toolName)) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (toolName in internalTools) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const tool = toolsConfig[toolName];
|
|
515
|
+
const isConstructorFunction = isFunction(tool);
|
|
516
|
+
const toolSettings = tool as ToolSettings;
|
|
517
|
+
const hasToolClass = isFunction(toolSettings.class);
|
|
518
|
+
|
|
519
|
+
if (!isConstructorFunction && !hasToolClass) {
|
|
520
|
+
throw new CriticalError(
|
|
521
|
+
`Tool «${toolName}» must be a constructor function or an object with function in the «class» property`
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Unify tools config
|
|
529
|
+
* @param toolsConfig - raw tools configuration
|
|
530
|
+
*/
|
|
531
|
+
private prepareConfig(toolsConfig: Record<string, ToolConstructable | ToolSettings>): Record<string, ToolSettings> {
|
|
532
|
+
const config: Record<string, ToolSettings> = {};
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Save Tools settings to a map
|
|
536
|
+
*/
|
|
537
|
+
for (const toolName in toolsConfig) {
|
|
538
|
+
/**
|
|
539
|
+
* If Tool is an object not a Tool's class then
|
|
540
|
+
* save class and settings separately
|
|
541
|
+
*/
|
|
542
|
+
if (!Object.prototype.hasOwnProperty.call(toolsConfig, toolName)) {
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const tool = toolsConfig[toolName];
|
|
547
|
+
|
|
548
|
+
if (isObject(tool)) {
|
|
549
|
+
config[toolName] = tool as ToolSettings;
|
|
550
|
+
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
config[toolName] = { class: tool as ToolConstructable };
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return config;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Type guard that ensures provided data contains tool preparation metadata.
|
|
562
|
+
* @param data - data passed to prepare sequence callbacks
|
|
563
|
+
*/
|
|
564
|
+
private isToolPrepareData(data: object): data is ToolPrepareData {
|
|
565
|
+
const candidate = data as Partial<ToolPrepareData>;
|
|
566
|
+
|
|
567
|
+
return typeof candidate?.toolName === 'string';
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Returns initialized tools factory instance.
|
|
572
|
+
* @returns tools factory
|
|
573
|
+
*/
|
|
574
|
+
private getFactory(): ToolsFactory {
|
|
575
|
+
if (this.factory === null) {
|
|
576
|
+
throw new Error('Tools factory is not initialized');
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return this.factory;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Builds inline tools collection for provided tool names, skipping unavailable ones.
|
|
584
|
+
* @param toolNames - inline tool names to include
|
|
585
|
+
* @returns tools collection containing available inline tools
|
|
586
|
+
*/
|
|
587
|
+
private createInlineToolsCollection(toolNames: Iterable<string>): ToolsCollection<InlineToolAdapter> {
|
|
588
|
+
const entries: [string, InlineToolAdapter][] = [];
|
|
589
|
+
|
|
590
|
+
for (const name of toolNames) {
|
|
591
|
+
const inlineTool = this.inlineTools.get(name);
|
|
592
|
+
|
|
593
|
+
if (!inlineTool) {
|
|
594
|
+
log(`Inline tool "${name}" is not available and will be skipped`, 'warn');
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
entries.push([name, inlineTool]);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return new ToolsCollection<InlineToolAdapter>(entries);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Builds block tunes collection for provided tune names, skipping unavailable ones.
|
|
606
|
+
* @param tuneNames - block tune names to include
|
|
607
|
+
* @returns tools collection containing available block tunes
|
|
608
|
+
*/
|
|
609
|
+
private createBlockTunesCollection(tuneNames: Iterable<string>): ToolsCollection<BlockTuneAdapter> {
|
|
610
|
+
const entries: [string, BlockTuneAdapter][] = [];
|
|
611
|
+
|
|
612
|
+
for (const name of tuneNames) {
|
|
613
|
+
const tune = this.blockTunes.get(name);
|
|
614
|
+
|
|
615
|
+
if (!tune) {
|
|
616
|
+
log(`Block tune "${name}" is not available and will be skipped`, 'warn');
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
entries.push([name, tune]);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return new ToolsCollection<BlockTuneAdapter>(entries);
|
|
624
|
+
}
|
|
625
|
+
}
|