@jackuait/blok 0.4.1-beta.1 → 0.4.1-beta.11
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-oNSQ3HA6.mjs +13217 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-BdNRw4n4.mjs +43 -0
- package/dist/{index-CEXLTV6f.mjs → chunks/index-DHgXmfki.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-CRqgjRim.mjs +1989 -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 +3117 -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 +141 -0
- package/src/components/inline-tools/inline-tool-italic.ts +500 -0
- package/src/components/inline-tools/inline-tool-link.ts +539 -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 +781 -0
- package/src/components/modules/toolbar/index.ts +1315 -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 +601 -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 +186 -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 +676 -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 +844 -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 +123 -0
- package/src/tools/header/index.ts +646 -0
- package/src/tools/index.ts +45 -0
- package/src/tools/list/index.ts +1819 -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/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 +29 -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 +9 -0
- 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 +92 -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 +18 -5
- package/types/utils/popover/popover.d.ts +7 -0
- package/dist/blok-C8XbyLHh.mjs +0 -25795
- package/dist/blok.umd.js +0 -181
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import type { Tool, ToolConstructable, ToolSettings } from '@/types/tools';
|
|
2
|
+
import type { SanitizerConfig, API as ApiMethods, ToolConfig } from '@/types';
|
|
3
|
+
import { isFunction } from '../utils';
|
|
4
|
+
import { ToolType } from '@/types/tools/adapters/tool-type';
|
|
5
|
+
import type { BaseToolAdapter as BaseToolAdapterInterface } from '@/types/tools/adapters/base-tool-adapter';
|
|
6
|
+
import type { InlineToolAdapter as InlineToolAdapterInterface } from '@/types/tools/adapters/inline-tool-adapter';
|
|
7
|
+
import type { BlockToolAdapter as BlockToolAdapterInterface } from '@/types/tools/adapters/block-tool-adapter';
|
|
8
|
+
import type { BlockTuneAdapter as BlockTuneAdapterInterface } from '@/types/tools/adapters/block-tune-adapter';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Keys that are Blok-level settings (not passed to tool constructor)
|
|
12
|
+
*/
|
|
13
|
+
const BLOK_SETTINGS_KEYS = new Set([
|
|
14
|
+
'class',
|
|
15
|
+
'inlineToolbar',
|
|
16
|
+
'tunes',
|
|
17
|
+
'shortcut',
|
|
18
|
+
'toolbox',
|
|
19
|
+
'config',
|
|
20
|
+
'isInternal',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Enum of Tool options provided by user
|
|
25
|
+
*/
|
|
26
|
+
export enum UserSettings {
|
|
27
|
+
/**
|
|
28
|
+
* Shortcut for Tool
|
|
29
|
+
*/
|
|
30
|
+
Shortcut = 'shortcut',
|
|
31
|
+
/**
|
|
32
|
+
* Toolbox config for Tool
|
|
33
|
+
*/
|
|
34
|
+
Toolbox = 'toolbox',
|
|
35
|
+
/**
|
|
36
|
+
* Enabled Inline Tools for Block Tool
|
|
37
|
+
*/
|
|
38
|
+
EnabledInlineTools = 'inlineToolbar',
|
|
39
|
+
/**
|
|
40
|
+
* Enabled Block Tunes for Block Tool
|
|
41
|
+
*/
|
|
42
|
+
EnabledBlockTunes = 'tunes',
|
|
43
|
+
/**
|
|
44
|
+
* Tool configuration
|
|
45
|
+
*/
|
|
46
|
+
Config = 'config',
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Enum of Tool options provided by Tool
|
|
51
|
+
*/
|
|
52
|
+
export enum CommonInternalSettings {
|
|
53
|
+
/**
|
|
54
|
+
* Shortcut for Tool
|
|
55
|
+
*/
|
|
56
|
+
Shortcut = 'shortcut',
|
|
57
|
+
/**
|
|
58
|
+
* Sanitize configuration for Tool
|
|
59
|
+
*/
|
|
60
|
+
SanitizeConfig = 'sanitize',
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Enum of Tool options provided by Block Tool
|
|
66
|
+
*/
|
|
67
|
+
export enum InternalBlockToolSettings {
|
|
68
|
+
/**
|
|
69
|
+
* Is line breaks enabled for Tool
|
|
70
|
+
*/
|
|
71
|
+
IsEnabledLineBreaks = 'enableLineBreaks',
|
|
72
|
+
/**
|
|
73
|
+
* Tool Toolbox config
|
|
74
|
+
*/
|
|
75
|
+
Toolbox = 'toolbox',
|
|
76
|
+
/**
|
|
77
|
+
* Tool conversion config
|
|
78
|
+
*/
|
|
79
|
+
ConversionConfig = 'conversionConfig',
|
|
80
|
+
/**
|
|
81
|
+
* Is readonly mode supported for Tool
|
|
82
|
+
*/
|
|
83
|
+
IsReadOnlySupported = 'isReadOnlySupported',
|
|
84
|
+
/**
|
|
85
|
+
* Tool paste config
|
|
86
|
+
*/
|
|
87
|
+
PasteConfig = 'pasteConfig'
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Enum of Tool options provided by Inline Tool
|
|
92
|
+
*/
|
|
93
|
+
export enum InternalInlineToolSettings {
|
|
94
|
+
/**
|
|
95
|
+
* Flag specifies Tool is inline
|
|
96
|
+
*/
|
|
97
|
+
IsInline = 'isInline',
|
|
98
|
+
/**
|
|
99
|
+
* Inline Tool title for toolbar
|
|
100
|
+
*/
|
|
101
|
+
Title = 'title', // for Inline Tools. Block Tools can pass title along with icon through the 'toolbox' static prop.
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Allows inline tool to be available in read-only mode
|
|
105
|
+
* Can be used, for example, by comments tool
|
|
106
|
+
*/
|
|
107
|
+
IsReadOnlySupported = 'isReadOnlySupported',
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Enum of Tool options provided by Block Tune
|
|
112
|
+
*/
|
|
113
|
+
export enum InternalTuneSettings {
|
|
114
|
+
/**
|
|
115
|
+
* Flag specifies Tool is Block Tune
|
|
116
|
+
*/
|
|
117
|
+
IsTune = 'isTune',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type ToolOptions = Omit<ToolSettings, 'class'>;
|
|
121
|
+
|
|
122
|
+
type ToolPreparePayload = {
|
|
123
|
+
toolName: string;
|
|
124
|
+
config: ToolConfig;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
interface ConstructorOptions {
|
|
128
|
+
name: string;
|
|
129
|
+
constructable: ToolConstructable;
|
|
130
|
+
config: ToolOptions;
|
|
131
|
+
api: ApiMethods;
|
|
132
|
+
isDefault: boolean;
|
|
133
|
+
isInternal: boolean;
|
|
134
|
+
defaultPlaceholder?: string | false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Base abstract class for Tools
|
|
139
|
+
*/
|
|
140
|
+
export abstract class BaseToolAdapter<Type extends ToolType = ToolType, ToolClass extends Tool = Tool> implements BaseToolAdapterInterface<ToolType, Tool> {
|
|
141
|
+
/**
|
|
142
|
+
* Tool type: Block, Inline or Tune
|
|
143
|
+
*/
|
|
144
|
+
public abstract type: Type;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Tool name specified in Blok config
|
|
148
|
+
*/
|
|
149
|
+
public name: string;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Flag show is current Tool internal (bundled with Blok core) or not
|
|
153
|
+
*/
|
|
154
|
+
public readonly isInternal: boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Flag show is current Tool default or not
|
|
158
|
+
*/
|
|
159
|
+
public readonly isDefault: boolean;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Blok API for current Tool
|
|
163
|
+
*/
|
|
164
|
+
protected api: ApiMethods;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Current tool user configuration
|
|
168
|
+
*/
|
|
169
|
+
protected config: ToolOptions;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Tool's constructable blueprint
|
|
173
|
+
*/
|
|
174
|
+
protected constructable: ToolConstructable;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Default placeholder specified in Blok user configuration
|
|
178
|
+
*/
|
|
179
|
+
protected defaultPlaceholder?: string | false;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @class
|
|
183
|
+
* @param {ConstructorOptions} options - Constructor options
|
|
184
|
+
*/
|
|
185
|
+
constructor({
|
|
186
|
+
name,
|
|
187
|
+
constructable,
|
|
188
|
+
config,
|
|
189
|
+
api,
|
|
190
|
+
isDefault,
|
|
191
|
+
isInternal = false,
|
|
192
|
+
defaultPlaceholder,
|
|
193
|
+
}: ConstructorOptions) {
|
|
194
|
+
this.api = api;
|
|
195
|
+
this.name = name;
|
|
196
|
+
this.constructable = constructable;
|
|
197
|
+
this.config = config;
|
|
198
|
+
this.isDefault = isDefault;
|
|
199
|
+
this.isInternal = isInternal;
|
|
200
|
+
this.defaultPlaceholder = defaultPlaceholder;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Returns Tool user configuration.
|
|
205
|
+
* Extracts tool-specific options from flat config and merges with nested config.
|
|
206
|
+
*/
|
|
207
|
+
public get settings(): ToolConfig {
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Internal: reading legacy config for backwards compatibility
|
|
209
|
+
const nestedConfig = (this.config[UserSettings.Config] ?? {}) as ToolConfig;
|
|
210
|
+
|
|
211
|
+
// Extract non-Blok keys as tool-specific config
|
|
212
|
+
const flatConfig: Record<string, unknown> = {};
|
|
213
|
+
|
|
214
|
+
for (const key of Object.keys(this.config)) {
|
|
215
|
+
if (!BLOK_SETTINGS_KEYS.has(key)) {
|
|
216
|
+
flatConfig[key] = this.config[key as keyof typeof this.config];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Merge: nested config first, flat config overrides
|
|
221
|
+
const config = { ...nestedConfig, ...flatConfig } as ToolConfig;
|
|
222
|
+
|
|
223
|
+
if (this.isDefault && !('placeholder' in config) && this.defaultPlaceholder) {
|
|
224
|
+
config.placeholder = this.defaultPlaceholder;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return config;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Calls Tool's reset method
|
|
232
|
+
*/
|
|
233
|
+
public reset(): void | Promise<void> {
|
|
234
|
+
if (isFunction(this.constructable.reset)) {
|
|
235
|
+
return this.constructable.reset();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Calls Tool's prepare method
|
|
241
|
+
*/
|
|
242
|
+
public prepare(): void | Promise<void> {
|
|
243
|
+
const prepare = this.constructable.prepare;
|
|
244
|
+
|
|
245
|
+
if (!isFunction(prepare)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const payload: ToolPreparePayload = {
|
|
250
|
+
toolName: this.name,
|
|
251
|
+
config: this.settings,
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return (prepare as (data: ToolPreparePayload) => void | Promise<void>).call(this.constructable, payload);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Returns shortcut for Tool (internal or specified by user)
|
|
259
|
+
*/
|
|
260
|
+
public get shortcut(): string | undefined {
|
|
261
|
+
const toolShortcut = this.constructable[CommonInternalSettings.Shortcut];
|
|
262
|
+
const userShortcut = this.config[UserSettings.Shortcut];
|
|
263
|
+
|
|
264
|
+
return userShortcut || toolShortcut;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Returns Tool's sanitizer configuration
|
|
269
|
+
*/
|
|
270
|
+
public get sanitizeConfig(): SanitizerConfig {
|
|
271
|
+
return this.constructable[CommonInternalSettings.SanitizeConfig] || {};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Returns true if Tools is inline
|
|
276
|
+
*/
|
|
277
|
+
public isInline(): this is InlineToolAdapterInterface {
|
|
278
|
+
return this.type === ToolType.Inline;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Returns true if Tools is block
|
|
283
|
+
*/
|
|
284
|
+
public isBlock(): this is BlockToolAdapterInterface {
|
|
285
|
+
return this.type === ToolType.Block;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Returns true if Tools is tune
|
|
290
|
+
*/
|
|
291
|
+
public isTune(): this is BlockTuneAdapterInterface {
|
|
292
|
+
return this.type === ToolType.Tune;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Constructs new Tool instance from constructable blueprint
|
|
297
|
+
* @param args
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
public abstract create(...args: any[]): ToolClass;
|
|
301
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { BaseToolAdapter, InternalBlockToolSettings, UserSettings } from './base';
|
|
2
|
+
import type {
|
|
3
|
+
BlockAPI,
|
|
4
|
+
BlockTool as IBlockTool,
|
|
5
|
+
BlockToolData,
|
|
6
|
+
BlockToolConstructable,
|
|
7
|
+
ConversionConfig,
|
|
8
|
+
PasteConfig, SanitizerConfig, ToolboxConfig,
|
|
9
|
+
ToolboxConfigEntry
|
|
10
|
+
} from '@/types';
|
|
11
|
+
import { isEmpty, isObject } from '../utils';
|
|
12
|
+
import type { InlineToolAdapter } from './inline';
|
|
13
|
+
import type { BlockTuneAdapter } from './tune';
|
|
14
|
+
import { ToolsCollection } from './collection';
|
|
15
|
+
import type { BlockToolAdapter as BlockToolAdapterInterface } from '@/types/tools/adapters/block-tool-adapter';
|
|
16
|
+
import { ToolType } from '@/types/tools/adapters/tool-type';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Class to work with Block tools constructables
|
|
20
|
+
*/
|
|
21
|
+
export class BlockToolAdapter extends BaseToolAdapter<ToolType.Block, IBlockTool> implements BlockToolAdapterInterface {
|
|
22
|
+
/**
|
|
23
|
+
* Tool type — Block
|
|
24
|
+
*/
|
|
25
|
+
public type: ToolType.Block = ToolType.Block;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* InlineTool collection for current Block Tool
|
|
29
|
+
*/
|
|
30
|
+
public inlineTools: ToolsCollection<InlineToolAdapter> = new ToolsCollection<InlineToolAdapter>();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* BlockTune collection for current Block Tool
|
|
34
|
+
*/
|
|
35
|
+
public tunes: ToolsCollection<BlockTuneAdapter> = new ToolsCollection<BlockTuneAdapter>();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Cache for sanitize configuration
|
|
39
|
+
*/
|
|
40
|
+
private _sanitizeConfig: SanitizerConfig | undefined;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Cache for base sanitize configuration
|
|
44
|
+
*/
|
|
45
|
+
private _baseSanitizeConfig: SanitizerConfig | undefined;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates new Tool instance
|
|
49
|
+
* @param data - Tool data
|
|
50
|
+
* @param block - BlockAPI for current Block
|
|
51
|
+
* @param readOnly - True if Blok is in read-only mode
|
|
52
|
+
*/
|
|
53
|
+
public create(data: BlockToolData, block: BlockAPI, readOnly: boolean): IBlockTool {
|
|
54
|
+
const toolboxEntries = this.toolbox;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Inject merged toolbox entries into config so tools can use them in renderSettings().
|
|
58
|
+
* This allows tools like Header to show the same options in block settings as in the toolbox.
|
|
59
|
+
*/
|
|
60
|
+
const configWithToolbox = toolboxEntries !== undefined
|
|
61
|
+
? { ...this.settings, _toolboxEntries: toolboxEntries }
|
|
62
|
+
: this.settings;
|
|
63
|
+
|
|
64
|
+
return new this.constructable({
|
|
65
|
+
data,
|
|
66
|
+
block,
|
|
67
|
+
readOnly,
|
|
68
|
+
api: this.api,
|
|
69
|
+
config: configWithToolbox,
|
|
70
|
+
}) as IBlockTool;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns true if read-only mode is supported by Tool
|
|
75
|
+
*/
|
|
76
|
+
public get isReadOnlySupported(): boolean {
|
|
77
|
+
return (this.constructable as BlockToolConstructable)[InternalBlockToolSettings.IsReadOnlySupported] === true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns true if Tool supports linebreaks
|
|
82
|
+
*/
|
|
83
|
+
public get isLineBreaksEnabled(): boolean {
|
|
84
|
+
return (this.constructable as unknown as Record<string, boolean | undefined>)[InternalBlockToolSettings.IsEnabledLineBreaks] ?? false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns Tool toolbox configuration (internal or user-specified).
|
|
89
|
+
*
|
|
90
|
+
* Merges internal and user-defined toolbox configs based on the following rules:
|
|
91
|
+
*
|
|
92
|
+
* - If both internal and user-defined toolbox configs are arrays their items are merged.
|
|
93
|
+
* Length of the second one is kept.
|
|
94
|
+
*
|
|
95
|
+
* - If both are objects their properties are merged.
|
|
96
|
+
*
|
|
97
|
+
* - If one is an object and another is an array than internal config is replaced with user-defined
|
|
98
|
+
* config. This is made to allow user to override default tool's toolbox representation (single/multiple entries)
|
|
99
|
+
*
|
|
100
|
+
* Additionally, if the tool's config contains a `toolboxStyles` array, only toolbox entries
|
|
101
|
+
* whose `data.style` matches one of the specified styles will be included.
|
|
102
|
+
*/
|
|
103
|
+
public get toolbox(): ToolboxConfigEntry[] | undefined {
|
|
104
|
+
const toolToolboxSettings = (this.constructable as BlockToolConstructable)[InternalBlockToolSettings.Toolbox] as ToolboxConfig | undefined;
|
|
105
|
+
const userToolboxSettings = this.config[UserSettings.Toolbox];
|
|
106
|
+
|
|
107
|
+
if (!toolToolboxSettings || isEmpty(toolToolboxSettings)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (userToolboxSettings === false) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const mergedEntries = this.mergeToolboxSettings(toolToolboxSettings, userToolboxSettings);
|
|
115
|
+
const filteredByStyles = this.filterToolboxEntriesByStyles(mergedEntries);
|
|
116
|
+
|
|
117
|
+
return this.filterToolboxEntriesByLevels(filteredByStyles);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Merges tool's internal toolbox settings with user-defined settings
|
|
122
|
+
*/
|
|
123
|
+
private mergeToolboxSettings(
|
|
124
|
+
toolSettings: ToolboxConfig,
|
|
125
|
+
userSettings: ToolboxConfig | undefined | null
|
|
126
|
+
): ToolboxConfigEntry[] {
|
|
127
|
+
/**
|
|
128
|
+
* Return tool's toolbox settings if user settings are not defined
|
|
129
|
+
*/
|
|
130
|
+
if (userSettings === undefined || userSettings === null) {
|
|
131
|
+
return Array.isArray(toolSettings) ? toolSettings : [ toolSettings ];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* User provided single entry to override array of tool entries
|
|
136
|
+
*/
|
|
137
|
+
if (!Array.isArray(userSettings) && Array.isArray(toolSettings)) {
|
|
138
|
+
return [ userSettings ];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Both are single entries - merge them
|
|
143
|
+
*/
|
|
144
|
+
if (!Array.isArray(userSettings)) {
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
...toolSettings,
|
|
148
|
+
...userSettings,
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* User provided array but tool has single entry
|
|
155
|
+
*/
|
|
156
|
+
if (!Array.isArray(toolSettings)) {
|
|
157
|
+
return userSettings;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Both are arrays - merge item by item
|
|
162
|
+
*/
|
|
163
|
+
return userSettings.map((item, i) => {
|
|
164
|
+
const toolToolboxEntry = toolSettings[i];
|
|
165
|
+
|
|
166
|
+
if (toolToolboxEntry) {
|
|
167
|
+
return {
|
|
168
|
+
...toolToolboxEntry,
|
|
169
|
+
...item,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return item;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Filters toolbox entries based on toolboxStyles config if specified.
|
|
179
|
+
* This allows tools like List to show only specific variants in the toolbox.
|
|
180
|
+
*/
|
|
181
|
+
private filterToolboxEntriesByStyles(entries: ToolboxConfigEntry[]): ToolboxConfigEntry[] {
|
|
182
|
+
const toolboxStyles = this.settings.toolboxStyles as string[] | undefined;
|
|
183
|
+
|
|
184
|
+
if (!toolboxStyles || !Array.isArray(toolboxStyles) || toolboxStyles.length === 0) {
|
|
185
|
+
return entries;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return entries.filter(entry => {
|
|
189
|
+
const entryData = entry.data as { style?: string } | undefined;
|
|
190
|
+
|
|
191
|
+
if (!entryData || !entryData.style) {
|
|
192
|
+
return true; // Keep entries without style data
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return toolboxStyles.includes(entryData.style);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Filters toolbox entries based on levels config if specified.
|
|
201
|
+
* This allows tools like Header to show only configured heading levels in the toolbox.
|
|
202
|
+
*/
|
|
203
|
+
private filterToolboxEntriesByLevels(entries: ToolboxConfigEntry[]): ToolboxConfigEntry[] {
|
|
204
|
+
const levels = this.settings.levels as number[] | undefined;
|
|
205
|
+
|
|
206
|
+
if (!levels || !Array.isArray(levels) || levels.length === 0) {
|
|
207
|
+
return entries;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return entries.filter(entry => {
|
|
211
|
+
const entryData = entry.data as { level?: number } | undefined;
|
|
212
|
+
|
|
213
|
+
if (!entryData || entryData.level === undefined) {
|
|
214
|
+
return true; // Keep entries without level data
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return levels.includes(entryData.level);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Returns Tool conversion configuration
|
|
223
|
+
*/
|
|
224
|
+
public get conversionConfig(): ConversionConfig | undefined {
|
|
225
|
+
return (this.constructable as BlockToolConstructable)[InternalBlockToolSettings.ConversionConfig];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Returns enabled inline tools for Tool.
|
|
230
|
+
* Defaults to true (all inline tools) unless explicitly set to false or array.
|
|
231
|
+
*/
|
|
232
|
+
public get enabledInlineTools(): boolean | string[] {
|
|
233
|
+
const setting = this.config[UserSettings.EnabledInlineTools];
|
|
234
|
+
|
|
235
|
+
// Default to true if not specified
|
|
236
|
+
if (setting === undefined) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return setting;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Returns enabled tunes for Tool
|
|
245
|
+
*/
|
|
246
|
+
public get enabledBlockTunes(): boolean | string[] | undefined {
|
|
247
|
+
return this.config[UserSettings.EnabledBlockTunes];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* User-provided search terms from tool settings.
|
|
252
|
+
* These are merged with library-defined searchTerms in the toolbox config.
|
|
253
|
+
*/
|
|
254
|
+
public get searchTerms(): string[] | undefined {
|
|
255
|
+
return this.settings.searchTerms;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Returns Tool paste configuration
|
|
260
|
+
*/
|
|
261
|
+
public get pasteConfig(): PasteConfig {
|
|
262
|
+
return (this.constructable as BlockToolConstructable)[InternalBlockToolSettings.PasteConfig] ?? {};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Returns true if Tool has onPaste handler
|
|
267
|
+
*/
|
|
268
|
+
public get hasOnPasteHandler(): boolean {
|
|
269
|
+
const prototype = (this.constructable as unknown as { prototype?: { onPaste?: unknown } })?.prototype;
|
|
270
|
+
|
|
271
|
+
return typeof prototype?.onPaste === 'function';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Returns sanitize configuration for Block Tool including configs from related Inline Tools and Block Tunes
|
|
276
|
+
*/
|
|
277
|
+
public get sanitizeConfig(): SanitizerConfig {
|
|
278
|
+
if (this._sanitizeConfig) {
|
|
279
|
+
return this._sanitizeConfig;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const toolRules = super.sanitizeConfig;
|
|
283
|
+
const baseConfig = this.baseSanitizeConfig;
|
|
284
|
+
|
|
285
|
+
if (isEmpty(toolRules)) {
|
|
286
|
+
this._sanitizeConfig = baseConfig;
|
|
287
|
+
|
|
288
|
+
return baseConfig;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const toolConfig = {} as SanitizerConfig;
|
|
292
|
+
|
|
293
|
+
for (const fieldName in toolRules) {
|
|
294
|
+
if (!Object.prototype.hasOwnProperty.call(toolRules, fieldName)) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const rule = toolRules[fieldName];
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* If rule is object, merge it with Inline Tools configuration
|
|
302
|
+
*
|
|
303
|
+
* Otherwise pass as it is
|
|
304
|
+
*/
|
|
305
|
+
if (isObject(rule)) {
|
|
306
|
+
toolConfig[fieldName] = Object.assign({}, baseConfig, rule);
|
|
307
|
+
} else {
|
|
308
|
+
toolConfig[fieldName] = rule;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
this._sanitizeConfig = toolConfig;
|
|
313
|
+
|
|
314
|
+
return toolConfig;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Returns sanitizer configuration composed from sanitize config of Inline Tools enabled for Tool
|
|
319
|
+
*/
|
|
320
|
+
public get baseSanitizeConfig(): SanitizerConfig {
|
|
321
|
+
if (this._baseSanitizeConfig) {
|
|
322
|
+
return this._baseSanitizeConfig;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const baseConfig = {};
|
|
326
|
+
|
|
327
|
+
Array
|
|
328
|
+
.from(this.inlineTools.values())
|
|
329
|
+
.forEach(tool => Object.assign(baseConfig, tool.sanitizeConfig));
|
|
330
|
+
|
|
331
|
+
Array
|
|
332
|
+
.from(this.tunes.values())
|
|
333
|
+
.forEach(tune => Object.assign(baseConfig, tune.sanitizeConfig));
|
|
334
|
+
|
|
335
|
+
this._baseSanitizeConfig = baseConfig;
|
|
336
|
+
|
|
337
|
+
return baseConfig;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { BlockToolAdapter } from './block';
|
|
2
|
+
import type { InlineToolAdapter } from './inline';
|
|
3
|
+
import type { BlockTuneAdapter } from './tune';
|
|
4
|
+
import type { ToolsCollection as ToolsCollectionInterface } from '@/types/tools/adapters/tools-collection';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export type ToolClass = BlockToolAdapter | InlineToolAdapter | BlockTuneAdapter;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Class to store Blok Tools
|
|
11
|
+
*/
|
|
12
|
+
export class ToolsCollection<V extends ToolClass = ToolClass> extends Map<string, V> implements ToolsCollectionInterface<V> {
|
|
13
|
+
/**
|
|
14
|
+
* Returns Block Tools collection
|
|
15
|
+
*/
|
|
16
|
+
public get blockTools(): ToolsCollection<BlockToolAdapter> {
|
|
17
|
+
const tools = Array
|
|
18
|
+
.from(this.entries())
|
|
19
|
+
.filter(([, tool]) => tool.isBlock()) as [string, BlockToolAdapter][];
|
|
20
|
+
|
|
21
|
+
return new ToolsCollection<BlockToolAdapter>(tools);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns Inline Tools collection
|
|
26
|
+
*/
|
|
27
|
+
public get inlineTools(): ToolsCollection<InlineToolAdapter> {
|
|
28
|
+
const tools = Array
|
|
29
|
+
.from(this.entries())
|
|
30
|
+
.filter(([, tool]) => tool.isInline()) as [string, InlineToolAdapter][];
|
|
31
|
+
|
|
32
|
+
return new ToolsCollection<InlineToolAdapter>(tools);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns Block Tunes collection
|
|
37
|
+
*/
|
|
38
|
+
public get blockTunes(): ToolsCollection<BlockTuneAdapter> {
|
|
39
|
+
const tools = Array
|
|
40
|
+
.from(this.entries())
|
|
41
|
+
.filter(([, tool]) => tool.isTune()) as [string, BlockTuneAdapter][];
|
|
42
|
+
|
|
43
|
+
return new ToolsCollection<BlockTuneAdapter>(tools);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns internal Tools collection
|
|
48
|
+
*/
|
|
49
|
+
public get internalTools(): ToolsCollection<V> {
|
|
50
|
+
const tools = Array
|
|
51
|
+
.from(this.entries())
|
|
52
|
+
.filter(([, tool]) => tool.isInternal);
|
|
53
|
+
|
|
54
|
+
return new ToolsCollection<V>(tools);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns Tools collection provided by user
|
|
59
|
+
*/
|
|
60
|
+
public get externalTools(): ToolsCollection<V> {
|
|
61
|
+
const tools = Array
|
|
62
|
+
.from(this.entries())
|
|
63
|
+
.filter(([, tool]) => !tool.isInternal);
|
|
64
|
+
|
|
65
|
+
return new ToolsCollection<V>(tools);
|
|
66
|
+
}
|
|
67
|
+
}
|