@jackuait/blok 0.4.1 → 0.4.3-beta.1
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 +136 -17
- package/codemod/README.md +45 -7
- package/codemod/migrate-editorjs-to-blok.js +951 -92
- package/codemod/test.js +780 -77
- package/dist/blok.mjs +5 -2
- package/dist/chunks/blok-8ptWuVZC.mjs +12838 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-bLawSYRV.mjs +43 -0
- package/dist/{index-CBkApZKo.mjs → chunks/index-5nYtWZD2.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-CvMDAIzb.mjs +1988 -0
- package/dist/chunks/messages-2434tVOK.mjs +47 -0
- package/dist/chunks/messages-3DcCwXMF.mjs +47 -0
- package/dist/chunks/messages-4kMwVAKY.mjs +47 -0
- package/dist/chunks/messages-57uL5htT.mjs +47 -0
- package/dist/chunks/messages-76-iJV9Q.mjs +47 -0
- package/dist/chunks/messages-8p86Eyf2.mjs +47 -0
- package/dist/chunks/messages-BBX0p0Pi.mjs +47 -0
- package/dist/chunks/messages-BCm2eudQ.mjs +47 -0
- package/dist/chunks/messages-BFiUomgG.mjs +47 -0
- package/dist/chunks/messages-BIPNHHAV.mjs +47 -0
- package/dist/chunks/messages-BUlwu9mo.mjs +47 -0
- package/dist/chunks/messages-BX-DPa-z.mjs +47 -0
- package/dist/chunks/messages-BextV3Qh.mjs +47 -0
- package/dist/chunks/messages-BiPSFlUG.mjs +47 -0
- package/dist/chunks/messages-BiXe9G-O.mjs +47 -0
- package/dist/chunks/messages-Bl5z_Igo.mjs +47 -0
- package/dist/chunks/messages-BnsE97ku.mjs +47 -0
- package/dist/chunks/messages-BoO8gsVD.mjs +47 -0
- package/dist/chunks/messages-BqWaOGMn.mjs +47 -0
- package/dist/chunks/messages-BqkL2_Ro.mjs +47 -0
- package/dist/chunks/messages-BvCkXKX-.mjs +47 -0
- package/dist/chunks/messages-C6tbPLoj.mjs +47 -0
- package/dist/chunks/messages-CA6T3-gQ.mjs +47 -0
- package/dist/chunks/messages-CFFPFdWP.mjs +47 -0
- package/dist/chunks/messages-CFrKE-TN.mjs +47 -0
- package/dist/chunks/messages-CHz8VlG-.mjs +47 -0
- package/dist/chunks/messages-CLixzySl.mjs +47 -0
- package/dist/chunks/messages-CV7OM_qk.mjs +47 -0
- package/dist/chunks/messages-CXHt3eCC.mjs +47 -0
- package/dist/chunks/messages-CbmsBrB0.mjs +47 -0
- package/dist/chunks/messages-Ceo1KtFx.mjs +47 -0
- package/dist/chunks/messages-Cm0LJLtB.mjs +47 -0
- package/dist/chunks/messages-CmymP_Ar.mjs +47 -0
- package/dist/chunks/messages-D0ohMB5H.mjs +47 -0
- package/dist/chunks/messages-D3GrDwXh.mjs +47 -0
- package/dist/chunks/messages-D3vTzIpL.mjs +47 -0
- package/dist/chunks/messages-D5WeksbV.mjs +47 -0
- package/dist/chunks/messages-DGaab4EP.mjs +47 -0
- package/dist/chunks/messages-DKha57ZU.mjs +47 -0
- package/dist/chunks/messages-DOaujgMW.mjs +47 -0
- package/dist/chunks/messages-DVbPLd_0.mjs +47 -0
- package/dist/chunks/messages-D_FCyfW6.mjs +47 -0
- package/dist/chunks/messages-Dd5iZN3c.mjs +47 -0
- package/dist/chunks/messages-DehM7135.mjs +47 -0
- package/dist/chunks/messages-Dg1OHftD.mjs +47 -0
- package/dist/chunks/messages-Di6Flq-b.mjs +47 -0
- package/dist/chunks/messages-Dqhhex6e.mjs +47 -0
- package/dist/chunks/messages-DueVe0F1.mjs +47 -0
- package/dist/chunks/messages-Dx3eFwI0.mjs +47 -0
- package/dist/chunks/messages-FOtiUoKl.mjs +47 -0
- package/dist/chunks/messages-FTOZNhRD.mjs +47 -0
- package/dist/chunks/messages-IQxGfQIV.mjs +47 -0
- package/dist/chunks/messages-JF2fzCkK.mjs +47 -0
- package/dist/chunks/messages-MOGl7I5v.mjs +47 -0
- package/dist/chunks/messages-QgYhPL-3.mjs +47 -0
- package/dist/chunks/messages-WYWIbQwo.mjs +47 -0
- package/dist/chunks/messages-a6A_LgDv.mjs +47 -0
- package/dist/chunks/messages-bSf31LJi.mjs +47 -0
- package/dist/chunks/messages-diGozhTn.mjs +47 -0
- package/dist/chunks/messages-er-kd-VO.mjs +47 -0
- package/dist/chunks/messages-ez3w5NBn.mjs +47 -0
- package/dist/chunks/messages-f3uXjegd.mjs +47 -0
- package/dist/chunks/messages-ohwI1UGv.mjs +47 -0
- package/dist/chunks/messages-p9BZJaFV.mjs +47 -0
- package/dist/chunks/messages-qIQ4L4rw.mjs +47 -0
- package/dist/chunks/messages-qWkXPggi.mjs +47 -0
- package/dist/chunks/messages-w5foGze_.mjs +47 -0
- package/dist/full.mjs +50 -0
- package/dist/locales.mjs +227 -0
- package/dist/messages-2434tVOK.mjs +47 -0
- package/dist/messages-3DcCwXMF.mjs +47 -0
- package/dist/messages-4kMwVAKY.mjs +47 -0
- package/dist/messages-57uL5htT.mjs +47 -0
- package/dist/messages-76-iJV9Q.mjs +47 -0
- package/dist/messages-8p86Eyf2.mjs +47 -0
- package/dist/messages-BBX0p0Pi.mjs +47 -0
- package/dist/messages-BCm2eudQ.mjs +47 -0
- package/dist/messages-BFiUomgG.mjs +47 -0
- package/dist/messages-BIPNHHAV.mjs +47 -0
- package/dist/messages-BUlwu9mo.mjs +47 -0
- package/dist/messages-BX-DPa-z.mjs +47 -0
- package/dist/messages-BextV3Qh.mjs +47 -0
- package/dist/messages-BiPSFlUG.mjs +47 -0
- package/dist/messages-BiXe9G-O.mjs +47 -0
- package/dist/messages-Bl5z_Igo.mjs +47 -0
- package/dist/messages-BnsE97ku.mjs +47 -0
- package/dist/messages-BoO8gsVD.mjs +47 -0
- package/dist/messages-BqWaOGMn.mjs +47 -0
- package/dist/messages-BqkL2_Ro.mjs +47 -0
- package/dist/messages-BvCkXKX-.mjs +47 -0
- package/dist/messages-C6tbPLoj.mjs +47 -0
- package/dist/messages-CA6T3-gQ.mjs +47 -0
- package/dist/messages-CFFPFdWP.mjs +47 -0
- package/dist/messages-CFrKE-TN.mjs +47 -0
- package/dist/messages-CHz8VlG-.mjs +47 -0
- package/dist/messages-CLixzySl.mjs +47 -0
- package/dist/messages-CV7OM_qk.mjs +47 -0
- package/dist/messages-CXHt3eCC.mjs +47 -0
- package/dist/messages-CbmsBrB0.mjs +47 -0
- package/dist/messages-Ceo1KtFx.mjs +47 -0
- package/dist/messages-Cm0LJLtB.mjs +47 -0
- package/dist/messages-CmymP_Ar.mjs +47 -0
- package/dist/messages-D0ohMB5H.mjs +47 -0
- package/dist/messages-D3GrDwXh.mjs +47 -0
- package/dist/messages-D3vTzIpL.mjs +47 -0
- package/dist/messages-D5WeksbV.mjs +47 -0
- package/dist/messages-DGaab4EP.mjs +47 -0
- package/dist/messages-DKha57ZU.mjs +47 -0
- package/dist/messages-DOaujgMW.mjs +47 -0
- package/dist/messages-DVbPLd_0.mjs +47 -0
- package/dist/messages-D_FCyfW6.mjs +47 -0
- package/dist/messages-Dd5iZN3c.mjs +47 -0
- package/dist/messages-DehM7135.mjs +47 -0
- package/dist/messages-Dg1OHftD.mjs +47 -0
- package/dist/messages-Di6Flq-b.mjs +47 -0
- package/dist/messages-Dqhhex6e.mjs +47 -0
- package/dist/messages-DueVe0F1.mjs +47 -0
- package/dist/messages-Dx3eFwI0.mjs +47 -0
- package/dist/messages-FOtiUoKl.mjs +47 -0
- package/dist/messages-FTOZNhRD.mjs +47 -0
- package/dist/messages-IQxGfQIV.mjs +47 -0
- package/dist/messages-JF2fzCkK.mjs +47 -0
- package/dist/messages-MOGl7I5v.mjs +47 -0
- package/dist/messages-QgYhPL-3.mjs +47 -0
- package/dist/messages-WYWIbQwo.mjs +47 -0
- package/dist/messages-a6A_LgDv.mjs +47 -0
- package/dist/messages-bSf31LJi.mjs +47 -0
- package/dist/messages-diGozhTn.mjs +47 -0
- package/dist/messages-er-kd-VO.mjs +47 -0
- package/dist/messages-ez3w5NBn.mjs +47 -0
- package/dist/messages-f3uXjegd.mjs +47 -0
- package/dist/messages-ohwI1UGv.mjs +47 -0
- package/dist/messages-p9BZJaFV.mjs +47 -0
- package/dist/messages-qIQ4L4rw.mjs +47 -0
- package/dist/messages-qWkXPggi.mjs +47 -0
- package/dist/messages-w5foGze_.mjs +47 -0
- package/dist/tools.mjs +3073 -0
- package/dist/vendor.LICENSE.txt +59 -156
- package/package.json +60 -15
- 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 +1427 -0
- package/src/components/block-tunes/block-tune-delete.ts +51 -0
- package/src/components/blocks.ts +338 -0
- package/src/components/constants/data-attributes.ts +342 -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 +481 -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 +44 -0
- package/src/components/i18n/locales/ar/messages.json +44 -0
- package/src/components/i18n/locales/az/messages.json +44 -0
- package/src/components/i18n/locales/bg/messages.json +44 -0
- package/src/components/i18n/locales/bn/messages.json +44 -0
- package/src/components/i18n/locales/bs/messages.json +44 -0
- package/src/components/i18n/locales/cs/messages.json +44 -0
- package/src/components/i18n/locales/da/messages.json +44 -0
- package/src/components/i18n/locales/de/messages.json +44 -0
- package/src/components/i18n/locales/dv/messages.json +44 -0
- package/src/components/i18n/locales/el/messages.json +44 -0
- package/src/components/i18n/locales/en/messages.json +44 -0
- package/src/components/i18n/locales/es/messages.json +44 -0
- package/src/components/i18n/locales/et/messages.json +44 -0
- package/src/components/i18n/locales/fa/messages.json +44 -0
- package/src/components/i18n/locales/fi/messages.json +44 -0
- package/src/components/i18n/locales/fil/messages.json +44 -0
- package/src/components/i18n/locales/fr/messages.json +44 -0
- package/src/components/i18n/locales/gu/messages.json +44 -0
- package/src/components/i18n/locales/he/messages.json +44 -0
- package/src/components/i18n/locales/hi/messages.json +44 -0
- package/src/components/i18n/locales/hr/messages.json +44 -0
- package/src/components/i18n/locales/hu/messages.json +44 -0
- package/src/components/i18n/locales/hy/messages.json +44 -0
- package/src/components/i18n/locales/id/messages.json +44 -0
- package/src/components/i18n/locales/index.ts +225 -0
- package/src/components/i18n/locales/it/messages.json +44 -0
- package/src/components/i18n/locales/ja/messages.json +44 -0
- package/src/components/i18n/locales/ka/messages.json +44 -0
- package/src/components/i18n/locales/km/messages.json +44 -0
- package/src/components/i18n/locales/kn/messages.json +44 -0
- package/src/components/i18n/locales/ko/messages.json +44 -0
- package/src/components/i18n/locales/ku/messages.json +44 -0
- package/src/components/i18n/locales/lo/messages.json +44 -0
- package/src/components/i18n/locales/lt/messages.json +44 -0
- package/src/components/i18n/locales/lv/messages.json +44 -0
- package/src/components/i18n/locales/mk/messages.json +44 -0
- package/src/components/i18n/locales/ml/messages.json +44 -0
- package/src/components/i18n/locales/mn/messages.json +44 -0
- package/src/components/i18n/locales/mr/messages.json +44 -0
- package/src/components/i18n/locales/ms/messages.json +44 -0
- package/src/components/i18n/locales/my/messages.json +44 -0
- package/src/components/i18n/locales/ne/messages.json +44 -0
- package/src/components/i18n/locales/nl/messages.json +44 -0
- package/src/components/i18n/locales/no/messages.json +44 -0
- package/src/components/i18n/locales/pa/messages.json +44 -0
- package/src/components/i18n/locales/pl/messages.json +44 -0
- package/src/components/i18n/locales/ps/messages.json +44 -0
- package/src/components/i18n/locales/pt/messages.json +44 -0
- package/src/components/i18n/locales/ro/messages.json +44 -0
- package/src/components/i18n/locales/ru/messages.json +44 -0
- package/src/components/i18n/locales/sd/messages.json +44 -0
- package/src/components/i18n/locales/si/messages.json +44 -0
- package/src/components/i18n/locales/sk/messages.json +44 -0
- package/src/components/i18n/locales/sl/messages.json +44 -0
- package/src/components/i18n/locales/sq/messages.json +44 -0
- package/src/components/i18n/locales/sr/messages.json +44 -0
- package/src/components/i18n/locales/sv/messages.json +44 -0
- package/src/components/i18n/locales/sw/messages.json +44 -0
- package/src/components/i18n/locales/ta/messages.json +44 -0
- package/src/components/i18n/locales/te/messages.json +44 -0
- package/src/components/i18n/locales/th/messages.json +44 -0
- package/src/components/i18n/locales/tr/messages.json +44 -0
- package/src/components/i18n/locales/ug/messages.json +44 -0
- package/src/components/i18n/locales/uk/messages.json +44 -0
- package/src/components/i18n/locales/ur/messages.json +44 -0
- package/src/components/i18n/locales/vi/messages.json +44 -0
- package/src/components/i18n/locales/yi/messages.json +44 -0
- package/src/components/i18n/locales/zh/messages.json +44 -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 +363 -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 +33 -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 +1375 -0
- package/src/components/modules/blockManager.ts +1348 -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 +1141 -0
- package/src/components/modules/history.ts +1098 -0
- package/src/components/modules/i18n.ts +325 -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 +668 -0
- package/src/components/modules/renderer.ts +155 -0
- package/src/components/modules/saver.ts +283 -0
- package/src/components/modules/toolbar/blockSettings.ts +776 -0
- package/src/components/modules/toolbar/index.ts +1311 -0
- package/src/components/modules/toolbar/inline.ts +956 -0
- package/src/components/modules/tools.ts +589 -0
- package/src/components/modules/ui.ts +1179 -0
- package/src/components/polyfills.ts +113 -0
- package/src/components/selection.ts +1189 -0
- package/src/components/tools/base.ts +274 -0
- package/src/components/tools/block.ts +291 -0
- package/src/components/tools/collection.ts +67 -0
- package/src/components/tools/factory.ts +85 -0
- package/src/components/tools/inline.ts +71 -0
- package/src/components/tools/tune.ts +33 -0
- package/src/components/ui/toolbox.ts +497 -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 +666 -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 +187 -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 +181 -0
- package/src/components/utils/popover/components/search-input/search-input.types.ts +30 -0
- package/src/components/utils/popover/index.ts +13 -0
- package/src/components/utils/popover/popover-abstract.ts +448 -0
- package/src/components/utils/popover/popover-desktop.ts +643 -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 +105 -0
- package/src/components/utils/tooltip.ts +642 -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 +570 -0
- package/src/tools/index.ts +38 -0
- package/src/tools/list/index.ts +1803 -0
- package/src/tools/paragraph/index.ts +411 -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 +1 -1
- package/types/api/i18n.d.ts +5 -3
- package/types/api/selection.d.ts +6 -0
- package/types/api/styles.d.ts +0 -5
- package/types/configs/blok-config.d.ts +21 -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 +169 -0
- package/types/data-formats/output-data.d.ts +15 -0
- package/types/full.d.ts +80 -0
- package/types/index.d.ts +9 -24
- 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/list.d.ts +25 -18
- package/types/tools/tool-settings.d.ts +8 -1
- package/types/tools/tool.d.ts +6 -0
- package/types/tools-entry.d.ts +49 -0
- package/types/utils/popover/popover-item.d.ts +0 -5
- package/dist/blok-BwPfU8ro.mjs +0 -21510
- package/dist/blok.umd.js +0 -198
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BaseToolAdapter } from './base';
|
|
2
|
+
import type { InlineTool as IInlineTool, InlineToolConstructable } from '@/types';
|
|
3
|
+
import type { InlineToolAdapter as InlineToolAdapterInterface } from '@/types/tools/adapters/inline-tool-adapter';
|
|
4
|
+
import { ToolType } from '@/types/tools/adapters/tool-type';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* InlineTool object to work with Inline Tools constructables
|
|
8
|
+
*/
|
|
9
|
+
export class InlineToolAdapter extends BaseToolAdapter<ToolType.Inline, IInlineTool> implements InlineToolAdapterInterface {
|
|
10
|
+
/**
|
|
11
|
+
* Tool type — Inline
|
|
12
|
+
*/
|
|
13
|
+
public type: ToolType.Inline = ToolType.Inline;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns list of required methods that are missing on the inline tool prototype
|
|
17
|
+
* @param requiredMethods - method names that must be implemented
|
|
18
|
+
*/
|
|
19
|
+
public getMissingMethods(requiredMethods: string[]): string[] {
|
|
20
|
+
const constructable = this.constructable as InlineToolConstructable | undefined;
|
|
21
|
+
const prototype = constructable?.prototype as Record<string, unknown> | undefined;
|
|
22
|
+
|
|
23
|
+
if (!prototype) {
|
|
24
|
+
return [ ...requiredMethods ];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return requiredMethods.filter((methodName) => typeof prototype[methodName] !== 'function');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Constructs new InlineTool instance from constructable
|
|
32
|
+
*/
|
|
33
|
+
public create(): IInlineTool {
|
|
34
|
+
|
|
35
|
+
const InlineToolClass = this.constructable as InlineToolConstructable;
|
|
36
|
+
|
|
37
|
+
return new InlineToolClass({
|
|
38
|
+
api: this.api,
|
|
39
|
+
config: this.settings,
|
|
40
|
+
}) as IInlineTool;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Allows inline tool to be available in read-only mode
|
|
45
|
+
* Can be used, for example, by comments tool
|
|
46
|
+
*/
|
|
47
|
+
public get isReadOnlySupported(): boolean {
|
|
48
|
+
const constructable = this.constructable as InlineToolConstructable | undefined;
|
|
49
|
+
|
|
50
|
+
return constructable?.isReadOnlySupported ?? false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns title of the tool
|
|
55
|
+
*/
|
|
56
|
+
public get title(): string {
|
|
57
|
+
const constructable = this.constructable as InlineToolConstructable;
|
|
58
|
+
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Backward compatibility: title is deprecated but still needs to be supported
|
|
60
|
+
return constructable['title'] || '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns the translation key for the tool title
|
|
65
|
+
*/
|
|
66
|
+
public get titleKey(): string | undefined {
|
|
67
|
+
const constructable = this.constructable as InlineToolConstructable;
|
|
68
|
+
|
|
69
|
+
return constructable['titleKey'];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseToolAdapter } from './base';
|
|
2
|
+
import type { BlockAPI, BlockTune as IBlockTune, BlockTuneConstructable } from '@/types';
|
|
3
|
+
import type { BlockTuneData } from '@/types/block-tunes/block-tune-data';
|
|
4
|
+
import type { BlockTuneAdapter as BlockTuneAdapterInterface } from '@/types/tools/adapters/block-tune-adapter';
|
|
5
|
+
import { ToolType } from '@/types/tools/adapters/tool-type';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Stub class for BlockTunes
|
|
9
|
+
* @todo Implement
|
|
10
|
+
*/
|
|
11
|
+
export class BlockTuneAdapter extends BaseToolAdapter<ToolType.Tune, IBlockTune> implements BlockTuneAdapterInterface {
|
|
12
|
+
/**
|
|
13
|
+
* Tool type — Tune
|
|
14
|
+
*/
|
|
15
|
+
public type: ToolType.Tune = ToolType.Tune;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constructs new BlockTune instance from constructable
|
|
19
|
+
* @param data - Tune data
|
|
20
|
+
* @param block - Block API object
|
|
21
|
+
*/
|
|
22
|
+
public create(data: BlockTuneData, block: BlockAPI): IBlockTune {
|
|
23
|
+
|
|
24
|
+
const BlockTuneClass = this.constructable as BlockTuneConstructable;
|
|
25
|
+
|
|
26
|
+
return new BlockTuneClass({
|
|
27
|
+
api: this.api,
|
|
28
|
+
config: this.settings,
|
|
29
|
+
block,
|
|
30
|
+
data,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { beautifyShortcut, capitalize, isMobileScreen } from '../utils';
|
|
2
|
+
import { Shortcuts } from '../utils/shortcuts';
|
|
3
|
+
import type { BlockToolAdapter } from '../tools/block';
|
|
4
|
+
import type { ToolsCollection } from '../tools/collection';
|
|
5
|
+
import type { API, BlockToolData, ToolboxConfigEntry, PopoverItemParams, BlockAPI } from '@/types';
|
|
6
|
+
import { EventsDispatcher } from '../utils/events';
|
|
7
|
+
import { translateToolTitle, type I18nInstance } from '../utils/tools';
|
|
8
|
+
import { PopoverEvent } from '@/types/utils/popover/popover-event';
|
|
9
|
+
import { Listeners } from '../utils/listeners';
|
|
10
|
+
import { Dom } from '../dom';
|
|
11
|
+
import type { Popover } from '../utils/popover';
|
|
12
|
+
import { PopoverDesktop, PopoverMobile } from '../utils/popover';
|
|
13
|
+
import { BlokMobileLayoutToggled } from '../events';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @todo the first Tab on the Block — focus Plus Button, the second — focus Block Tunes Toggler, the third — focus next Block
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Event that can be triggered by the Toolbox
|
|
21
|
+
*/
|
|
22
|
+
export enum ToolboxEvent {
|
|
23
|
+
/**
|
|
24
|
+
* When the Toolbox is opened
|
|
25
|
+
*/
|
|
26
|
+
Opened = 'toolbox-opened',
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* When the Toolbox is closed
|
|
30
|
+
*/
|
|
31
|
+
Closed = 'toolbox-closed',
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* When the new Block added by Toolbox
|
|
35
|
+
*/
|
|
36
|
+
BlockAdded = 'toolbox-block-added',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Events fired by the Toolbox
|
|
41
|
+
*
|
|
42
|
+
* Event name -> payload
|
|
43
|
+
*/
|
|
44
|
+
export interface ToolboxEventMap {
|
|
45
|
+
[ToolboxEvent.Opened]: undefined;
|
|
46
|
+
[ToolboxEvent.Closed]: undefined;
|
|
47
|
+
[ToolboxEvent.BlockAdded]: {
|
|
48
|
+
block: BlockAPI
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Available i18n dict keys that should be passed to the constructor
|
|
54
|
+
*/
|
|
55
|
+
type ToolboxTextLabelsKeys = 'filter' | 'nothingFound';
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Toolbox
|
|
59
|
+
* This UI element contains list of Block Tools available to be inserted
|
|
60
|
+
* It appears after click on the Plus Button
|
|
61
|
+
* @implements {EventsDispatcher} with some events, see {@link ToolboxEvent}
|
|
62
|
+
*/
|
|
63
|
+
export class Toolbox extends EventsDispatcher<ToolboxEventMap> {
|
|
64
|
+
/**
|
|
65
|
+
* Returns True if Toolbox is Empty and nothing to show
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
public get isEmpty(): boolean {
|
|
69
|
+
return this.toolsToBeDisplayed.length === 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Opening state
|
|
74
|
+
* @type {boolean}
|
|
75
|
+
*/
|
|
76
|
+
public opened = false;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Listeners util instance
|
|
80
|
+
*/
|
|
81
|
+
protected listeners: Listeners = new Listeners();
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Blok API
|
|
85
|
+
*/
|
|
86
|
+
private api: API;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Popover instance. There is a util for vertical lists.
|
|
90
|
+
* Null until initialized
|
|
91
|
+
*/
|
|
92
|
+
private popover: Popover | null = null;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* List of Tools available. Some of them will be shown in the Toolbox
|
|
96
|
+
*/
|
|
97
|
+
private tools: ToolsCollection<BlockToolAdapter>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Cache for tools to be displayed
|
|
101
|
+
*/
|
|
102
|
+
private _toolsToBeDisplayed: BlockToolAdapter[] | undefined;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Cache for toolbox items to be displayed
|
|
106
|
+
*/
|
|
107
|
+
private _toolboxItemsToBeDisplayed: PopoverItemParams[] | undefined;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Text labels used in the Toolbox. Should be passed from the i18n module
|
|
111
|
+
*/
|
|
112
|
+
private i18nLabels: Record<ToolboxTextLabelsKeys, string>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* I18n instance for translations
|
|
116
|
+
*/
|
|
117
|
+
private i18n: I18nInstance;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Current module HTML Elements
|
|
121
|
+
*/
|
|
122
|
+
private nodes: {
|
|
123
|
+
toolbox: HTMLElement;
|
|
124
|
+
} ;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* CSS styles
|
|
128
|
+
* @deprecated Use data attributes for identification instead
|
|
129
|
+
*/
|
|
130
|
+
private static get CSS(): {
|
|
131
|
+
toolbox: string;
|
|
132
|
+
} {
|
|
133
|
+
return {
|
|
134
|
+
toolbox: '',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Element relative to which the popover should be positioned
|
|
140
|
+
*/
|
|
141
|
+
private triggerElement?: HTMLElement;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Toolbox constructor
|
|
145
|
+
* @param options - available parameters
|
|
146
|
+
* @param options.api - Blok API methods
|
|
147
|
+
* @param options.tools - Tools available to check whether some of them should be displayed at the Toolbox or not
|
|
148
|
+
* @param options.i18n - I18n instance for translations
|
|
149
|
+
* @param options.triggerElement - Element relative to which the popover should be positioned
|
|
150
|
+
*/
|
|
151
|
+
constructor({ api, tools, i18nLabels, i18n, triggerElement }: {
|
|
152
|
+
api: API;
|
|
153
|
+
tools: ToolsCollection<BlockToolAdapter>;
|
|
154
|
+
i18nLabels: Record<ToolboxTextLabelsKeys, string>;
|
|
155
|
+
i18n: I18nInstance;
|
|
156
|
+
triggerElement?: HTMLElement;
|
|
157
|
+
}) {
|
|
158
|
+
super();
|
|
159
|
+
|
|
160
|
+
this.api = api;
|
|
161
|
+
this.tools = tools;
|
|
162
|
+
this.i18nLabels = i18nLabels;
|
|
163
|
+
this.i18n = i18n;
|
|
164
|
+
this.triggerElement = triggerElement;
|
|
165
|
+
|
|
166
|
+
this.enableShortcuts();
|
|
167
|
+
|
|
168
|
+
this.nodes = {
|
|
169
|
+
toolbox: Dom.make('div'),
|
|
170
|
+
};
|
|
171
|
+
this.nodes.toolbox.setAttribute('data-blok-testid', 'toolbox');
|
|
172
|
+
|
|
173
|
+
this.initPopover();
|
|
174
|
+
|
|
175
|
+
this.api.events.on(BlokMobileLayoutToggled, this.handleMobileLayoutToggle);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Returns root block settings element
|
|
180
|
+
*/
|
|
181
|
+
public getElement(): HTMLElement | null {
|
|
182
|
+
return this.nodes.toolbox;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Checks if the element is contained in the Toolbox or its Popover
|
|
187
|
+
* @param element - element to check
|
|
188
|
+
*/
|
|
189
|
+
public contains(element: HTMLElement): boolean {
|
|
190
|
+
if (this.nodes.toolbox.contains(element)) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.popover?.getElement().contains(element)) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Returns true if the Toolbox has the Flipper activated and the Flipper has selected button
|
|
203
|
+
*/
|
|
204
|
+
public hasFocus(): boolean | undefined {
|
|
205
|
+
if (this.popover === null) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return 'hasFocus' in this.popover ? this.popover.hasFocus() : undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Destroy Module
|
|
214
|
+
*/
|
|
215
|
+
public destroy(): void {
|
|
216
|
+
super.destroy();
|
|
217
|
+
|
|
218
|
+
if (this.nodes && this.nodes.toolbox) {
|
|
219
|
+
this.nodes.toolbox.remove();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.removeAllShortcuts();
|
|
223
|
+
this.popover?.off(PopoverEvent.Closed, this.onPopoverClose);
|
|
224
|
+
this.listeners.destroy();
|
|
225
|
+
this.api.events.off(BlokMobileLayoutToggled, this.handleMobileLayoutToggle);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Toolbox Tool's button click handler
|
|
230
|
+
* @param toolName - tool type to be activated
|
|
231
|
+
* @param blockDataOverrides - Block data predefined by the activated Toolbox item
|
|
232
|
+
*/
|
|
233
|
+
public async toolButtonActivated(toolName: string, blockDataOverrides?: BlockToolData): Promise<void> {
|
|
234
|
+
await this.insertNewBlock(toolName, blockDataOverrides);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Open Toolbox with Tools
|
|
239
|
+
*/
|
|
240
|
+
public open(): void {
|
|
241
|
+
if (this.isEmpty) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
this.popover?.show();
|
|
246
|
+
this.opened = true;
|
|
247
|
+
this.emit(ToolboxEvent.Opened);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Close Toolbox
|
|
252
|
+
*/
|
|
253
|
+
public close(): void {
|
|
254
|
+
this.popover?.hide();
|
|
255
|
+
this.opened = false;
|
|
256
|
+
this.emit(ToolboxEvent.Closed);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Close Toolbox
|
|
261
|
+
*/
|
|
262
|
+
public toggle(): void {
|
|
263
|
+
if (!this.opened) {
|
|
264
|
+
this.open();
|
|
265
|
+
} else {
|
|
266
|
+
this.close();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Destroys existing popover instance and contructs the new one.
|
|
272
|
+
*/
|
|
273
|
+
public handleMobileLayoutToggle = (): void => {
|
|
274
|
+
this.destroyPopover();
|
|
275
|
+
this.initPopover();
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Creates toolbox popover and appends it inside wrapper element
|
|
280
|
+
*/
|
|
281
|
+
private initPopover(): void {
|
|
282
|
+
const PopoverClass = isMobileScreen() ? PopoverMobile : PopoverDesktop;
|
|
283
|
+
|
|
284
|
+
this.popover = new PopoverClass({
|
|
285
|
+
scopeElement: this.api.ui.nodes.redactor,
|
|
286
|
+
trigger: this.triggerElement || this.nodes.toolbox,
|
|
287
|
+
messages: {
|
|
288
|
+
nothingFound: this.i18nLabels.nothingFound,
|
|
289
|
+
search: this.i18nLabels.filter,
|
|
290
|
+
},
|
|
291
|
+
items: this.toolboxItemsToBeDisplayed,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
this.popover.on(PopoverEvent.Closed, this.onPopoverClose);
|
|
295
|
+
this.popover.getElement().setAttribute('data-blok-testid', 'toolbox-popover');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Destroys popover instance and removes it from DOM
|
|
300
|
+
*/
|
|
301
|
+
private destroyPopover(): void {
|
|
302
|
+
if (this.popover !== null) {
|
|
303
|
+
this.popover.hide();
|
|
304
|
+
this.popover.off(PopoverEvent.Closed, this.onPopoverClose);
|
|
305
|
+
this.popover.destroy();
|
|
306
|
+
this.popover = null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (this.nodes.toolbox !== null) {
|
|
310
|
+
this.nodes.toolbox.innerHTML = '';
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Handles popover close event
|
|
316
|
+
*/
|
|
317
|
+
private onPopoverClose = (): void => {
|
|
318
|
+
this.opened = false;
|
|
319
|
+
this.emit(ToolboxEvent.Closed);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Returns list of tools that enables the Toolbox (by specifying the 'toolbox' getter)
|
|
324
|
+
*/
|
|
325
|
+
private get toolsToBeDisplayed(): BlockToolAdapter[] {
|
|
326
|
+
if (this._toolsToBeDisplayed) {
|
|
327
|
+
return this._toolsToBeDisplayed;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const result: BlockToolAdapter[] = [];
|
|
331
|
+
|
|
332
|
+
this.tools.forEach((tool) => {
|
|
333
|
+
const toolToolboxSettings = tool.toolbox;
|
|
334
|
+
|
|
335
|
+
if (toolToolboxSettings) {
|
|
336
|
+
result.push(tool);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
this._toolsToBeDisplayed = result;
|
|
341
|
+
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Returns list of items that will be displayed in toolbox
|
|
347
|
+
*/
|
|
348
|
+
private get toolboxItemsToBeDisplayed(): PopoverItemParams[] {
|
|
349
|
+
if (this._toolboxItemsToBeDisplayed) {
|
|
350
|
+
return this._toolboxItemsToBeDisplayed;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Maps tool data to popover item structure
|
|
355
|
+
*/
|
|
356
|
+
const toPopoverItem = (toolboxItem: ToolboxConfigEntry, tool: BlockToolAdapter, displaySecondaryLabel = true): PopoverItemParams => {
|
|
357
|
+
return {
|
|
358
|
+
icon: toolboxItem.icon,
|
|
359
|
+
title: translateToolTitle(this.i18n, toolboxItem, capitalize(tool.name)),
|
|
360
|
+
name: toolboxItem.name ?? tool.name,
|
|
361
|
+
onActivate: (): void => {
|
|
362
|
+
void this.toolButtonActivated(tool.name, toolboxItem.data);
|
|
363
|
+
},
|
|
364
|
+
secondaryLabel: (tool.shortcut && displaySecondaryLabel) ? beautifyShortcut(tool.shortcut) : '',
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const result = this.toolsToBeDisplayed
|
|
369
|
+
.reduce<PopoverItemParams[]>((acc, tool) => {
|
|
370
|
+
const { toolbox } = tool;
|
|
371
|
+
|
|
372
|
+
if (toolbox === undefined) {
|
|
373
|
+
return acc;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const items = Array.isArray(toolbox) ? toolbox : [ toolbox ];
|
|
377
|
+
|
|
378
|
+
items.forEach((item, index) => {
|
|
379
|
+
acc.push(toPopoverItem(item, tool, index === 0));
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
return acc;
|
|
383
|
+
}, []);
|
|
384
|
+
|
|
385
|
+
this._toolboxItemsToBeDisplayed = result;
|
|
386
|
+
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Iterate all tools and enable theirs shortcuts if specified
|
|
392
|
+
*/
|
|
393
|
+
private enableShortcuts(): void {
|
|
394
|
+
this.toolsToBeDisplayed.forEach((tool: BlockToolAdapter) => {
|
|
395
|
+
const shortcut = tool.shortcut;
|
|
396
|
+
|
|
397
|
+
if (shortcut) {
|
|
398
|
+
this.enableShortcutForTool(tool.name, shortcut);
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Enable shortcut Block Tool implemented shortcut
|
|
405
|
+
* @param {string} toolName - Tool name
|
|
406
|
+
* @param {string} shortcut - shortcut according to the ShortcutData Module format
|
|
407
|
+
*/
|
|
408
|
+
private enableShortcutForTool(toolName: string, shortcut: string): void {
|
|
409
|
+
Shortcuts.add({
|
|
410
|
+
name: shortcut,
|
|
411
|
+
on: this.api.ui.nodes.redactor,
|
|
412
|
+
handler: async (event: KeyboardEvent) => {
|
|
413
|
+
event.preventDefault();
|
|
414
|
+
|
|
415
|
+
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
|
|
416
|
+
const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Try to convert current Block to shortcut's tool
|
|
420
|
+
* If conversion is not possible, insert a new Block below
|
|
421
|
+
*/
|
|
422
|
+
if (currentBlock) {
|
|
423
|
+
try {
|
|
424
|
+
const newBlock = await this.api.blocks.convert(currentBlock.id, toolName);
|
|
425
|
+
|
|
426
|
+
this.api.caret.setToBlock(newBlock, 'end');
|
|
427
|
+
|
|
428
|
+
return;
|
|
429
|
+
} catch (_error) {}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
await this.insertNewBlock(toolName);
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Removes all added shortcuts
|
|
439
|
+
* Fired when the Read-Only mode is activated
|
|
440
|
+
*/
|
|
441
|
+
private removeAllShortcuts(): void {
|
|
442
|
+
this.toolsToBeDisplayed.forEach((tool: BlockToolAdapter) => {
|
|
443
|
+
const shortcut = tool.shortcut;
|
|
444
|
+
|
|
445
|
+
if (shortcut) {
|
|
446
|
+
Shortcuts.remove(this.api.ui.nodes.redactor, shortcut);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Inserts new block
|
|
453
|
+
* Can be called when button clicked on Toolbox or by ShortcutData
|
|
454
|
+
* @param {string} toolName - Tool name
|
|
455
|
+
* @param blockDataOverrides - predefined Block data
|
|
456
|
+
*/
|
|
457
|
+
private async insertNewBlock(toolName: string, blockDataOverrides?: BlockToolData): Promise<void> {
|
|
458
|
+
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
|
|
459
|
+
const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
|
|
460
|
+
|
|
461
|
+
if (!currentBlock) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* On mobile version, we see the Plus Button even near non-empty blocks,
|
|
467
|
+
* so if current block is not empty, add the new block below the current
|
|
468
|
+
*/
|
|
469
|
+
const index = currentBlock.isEmpty ? currentBlockIndex : currentBlockIndex + 1;
|
|
470
|
+
|
|
471
|
+
const hasBlockDataOverrides = blockDataOverrides !== undefined && Object.keys(blockDataOverrides as Record<string, unknown>).length > 0;
|
|
472
|
+
|
|
473
|
+
const blockData: BlockToolData | undefined = hasBlockDataOverrides
|
|
474
|
+
? Object.assign(await this.api.blocks.composeBlockData(toolName), blockDataOverrides)
|
|
475
|
+
: undefined;
|
|
476
|
+
|
|
477
|
+
const newBlock = this.api.blocks.insert(
|
|
478
|
+
toolName,
|
|
479
|
+
blockData,
|
|
480
|
+
undefined,
|
|
481
|
+
index,
|
|
482
|
+
undefined,
|
|
483
|
+
currentBlock.isEmpty
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
this.api.caret.setToBlock(index);
|
|
487
|
+
|
|
488
|
+
this.emit(ToolboxEvent.BlockAdded, {
|
|
489
|
+
block: newBlock,
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* close toolbar when node is changed
|
|
494
|
+
*/
|
|
495
|
+
this.api.toolbar.close();
|
|
496
|
+
}
|
|
497
|
+
}
|