@jackuait/blok 0.4.1-beta.5 → 0.4.1-beta.6
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 +16 -0
- package/codemod/migrate-editorjs-to-blok.js +868 -92
- package/codemod/test.js +682 -77
- package/dist/blok.mjs +5 -2
- package/dist/chunks/blok-B5qs7C5l.mjs +12838 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-CTrK3HzG.mjs +43 -0
- package/dist/{index-Cl_5rkKS.mjs → chunks/index-DDpzQn-0.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-RBcopmCh.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 +48 -16
- 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 -12
- 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 +16 -2
- 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-DvN73wsH.mjs +0 -19922
- package/dist/blok.umd.js +0 -166
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class BlockSelection
|
|
3
|
+
* @classdesc Manages Block selection with shortcut CMD+A
|
|
4
|
+
* @module BlockSelection
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { Module } from '../__module';
|
|
8
|
+
import type { Block } from '../block';
|
|
9
|
+
import { delay } from '../utils';
|
|
10
|
+
import { Dom as $ } from '../dom';
|
|
11
|
+
import { Shortcuts } from '../utils/shortcuts';
|
|
12
|
+
|
|
13
|
+
import { SelectionUtils } from '../selection';
|
|
14
|
+
import type { SanitizerConfig } from '../../../types/configs';
|
|
15
|
+
import { clean, composeSanitizerConfig } from '../utils/sanitizer';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export class BlockSelection extends Module {
|
|
21
|
+
/**
|
|
22
|
+
* Sometimes .anyBlockSelected can be called frequently,
|
|
23
|
+
* for example at ui@selectionChange (to clear native browser selection in CBS)
|
|
24
|
+
* We use cache to prevent multiple iterations through all the blocks
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private anyBlockSelectedCache: boolean | null = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Flag indicating whether navigation mode is active.
|
|
31
|
+
* In navigation mode, user can navigate between blocks using arrow keys
|
|
32
|
+
* and press Enter to start editing the focused block.
|
|
33
|
+
*/
|
|
34
|
+
private _navigationModeEnabled = false;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Index of the currently focused block in navigation mode
|
|
38
|
+
*/
|
|
39
|
+
private navigationFocusIndex = -1;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Sanitizer Config
|
|
43
|
+
* @returns {SanitizerConfig}
|
|
44
|
+
*/
|
|
45
|
+
private get sanitizerConfig(): SanitizerConfig {
|
|
46
|
+
const baseConfig: SanitizerConfig = {
|
|
47
|
+
p: {},
|
|
48
|
+
h1: {},
|
|
49
|
+
h2: {},
|
|
50
|
+
h3: {},
|
|
51
|
+
h4: {},
|
|
52
|
+
h5: {},
|
|
53
|
+
h6: {},
|
|
54
|
+
ol: {},
|
|
55
|
+
ul: {},
|
|
56
|
+
li: {},
|
|
57
|
+
br: true,
|
|
58
|
+
img: {
|
|
59
|
+
src: true,
|
|
60
|
+
width: true,
|
|
61
|
+
height: true,
|
|
62
|
+
},
|
|
63
|
+
a: {
|
|
64
|
+
href: true,
|
|
65
|
+
},
|
|
66
|
+
b: {},
|
|
67
|
+
i: {},
|
|
68
|
+
u: {},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return composeSanitizerConfig(this.config.sanitizer as SanitizerConfig, baseConfig);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Flag that identifies all Blocks selection
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
public get allBlocksSelected(): boolean {
|
|
79
|
+
const { BlockManager } = this.Blok;
|
|
80
|
+
|
|
81
|
+
return BlockManager.blocks.every((block) => block.selected === true);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Set selected all blocks
|
|
86
|
+
* @param {boolean} state - state to set
|
|
87
|
+
*/
|
|
88
|
+
public set allBlocksSelected(state: boolean) {
|
|
89
|
+
const { BlockManager } = this.Blok;
|
|
90
|
+
|
|
91
|
+
for (const block of BlockManager.blocks) {
|
|
92
|
+
block.selected = state;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.clearCache();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Flag that identifies any Block selection
|
|
100
|
+
* @returns {boolean}
|
|
101
|
+
*/
|
|
102
|
+
public get anyBlockSelected(): boolean {
|
|
103
|
+
const { BlockManager } = this.Blok;
|
|
104
|
+
|
|
105
|
+
if (this.anyBlockSelectedCache === null) {
|
|
106
|
+
this.anyBlockSelectedCache = BlockManager.blocks.some((block) => block.selected === true);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this.anyBlockSelectedCache;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Return selected Blocks array
|
|
114
|
+
* @returns {Block[]}
|
|
115
|
+
*/
|
|
116
|
+
public get selectedBlocks(): Block[] {
|
|
117
|
+
return this.Blok.BlockManager.blocks.filter((block: Block) => block.selected);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns true if navigation mode is currently active
|
|
122
|
+
* @returns {boolean}
|
|
123
|
+
*/
|
|
124
|
+
public get navigationModeEnabled(): boolean {
|
|
125
|
+
return this._navigationModeEnabled;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Returns the currently focused block in navigation mode
|
|
130
|
+
* @returns {Block | undefined}
|
|
131
|
+
*/
|
|
132
|
+
public get navigationFocusedBlock(): Block | undefined {
|
|
133
|
+
if (!this._navigationModeEnabled || this.navigationFocusIndex < 0) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return this.Blok.BlockManager.getBlockByIndex(this.navigationFocusIndex);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Flag used to define block selection
|
|
142
|
+
* First CMD+A defines it as true and then second CMD+A selects all Blocks
|
|
143
|
+
* @type {boolean}
|
|
144
|
+
*/
|
|
145
|
+
private needToSelectAll = false;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Flag used to define native input selection
|
|
149
|
+
* In this case we allow double CMD+A to select Block
|
|
150
|
+
* @type {boolean}
|
|
151
|
+
*/
|
|
152
|
+
private nativeInputSelected = false;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Flag identifies any input selection
|
|
156
|
+
* That means we can select whole Block
|
|
157
|
+
* @type {boolean}
|
|
158
|
+
*/
|
|
159
|
+
private readyToBlockSelection = false;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* SelectionUtils instance
|
|
163
|
+
* @type {SelectionUtils}
|
|
164
|
+
*/
|
|
165
|
+
private selection: SelectionUtils = new SelectionUtils();
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Module Preparation
|
|
169
|
+
* Registers Shortcuts CMD+A and CMD+C
|
|
170
|
+
* to select all and copy them
|
|
171
|
+
*/
|
|
172
|
+
public prepare(): void {
|
|
173
|
+
/**
|
|
174
|
+
* Re-create SelectionUtils instance to ensure fresh state.
|
|
175
|
+
*/
|
|
176
|
+
this.selection = new SelectionUtils();
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* CMD/CTRL+A selection shortcut
|
|
180
|
+
*/
|
|
181
|
+
Shortcuts.add({
|
|
182
|
+
name: 'CMD+A',
|
|
183
|
+
handler: (event: KeyboardEvent) => {
|
|
184
|
+
const { BlockManager, ReadOnly } = this.Blok;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* We use Blok's Block selection on CMD+A ShortCut instead of Browsers
|
|
188
|
+
*/
|
|
189
|
+
if (ReadOnly.isEnabled) {
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
this.selectAllBlocks();
|
|
192
|
+
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* When one page consist of two or more Blok instances
|
|
198
|
+
* Shortcut module tries to handle all events.
|
|
199
|
+
* Thats why Blok's selection works inside the target Blok, but
|
|
200
|
+
* for others error occurs because nothing to select.
|
|
201
|
+
*
|
|
202
|
+
* Prevent such actions if focus is not inside the Blok
|
|
203
|
+
*/
|
|
204
|
+
if (!BlockManager.currentBlock) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.handleCommandA(event);
|
|
209
|
+
},
|
|
210
|
+
on: this.Blok.UI.nodes.redactor,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Toggle read-only state
|
|
216
|
+
*
|
|
217
|
+
* - Remove all ranges
|
|
218
|
+
* - Unselect all Blocks
|
|
219
|
+
*/
|
|
220
|
+
public toggleReadOnly(): void {
|
|
221
|
+
const selection = SelectionUtils.get();
|
|
222
|
+
|
|
223
|
+
selection?.removeAllRanges();
|
|
224
|
+
|
|
225
|
+
this.allBlocksSelected = false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Remove selection of Block
|
|
230
|
+
* @param {number?} index - Block index according to the BlockManager's indexes
|
|
231
|
+
*/
|
|
232
|
+
public unSelectBlockByIndex(index?: number): void {
|
|
233
|
+
const { BlockManager } = this.Blok;
|
|
234
|
+
|
|
235
|
+
const block = typeof index === 'number'
|
|
236
|
+
? BlockManager.getBlockByIndex(index)
|
|
237
|
+
: BlockManager.currentBlock;
|
|
238
|
+
|
|
239
|
+
if (!block) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
block.selected = false;
|
|
244
|
+
|
|
245
|
+
this.clearCache();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Clear selection from Blocks
|
|
250
|
+
* @param {Event} reason - event caused clear of selection
|
|
251
|
+
* @param {boolean} restoreSelection - if true, restore saved selection
|
|
252
|
+
*/
|
|
253
|
+
public clearSelection(reason?: Event, restoreSelection = false): void {
|
|
254
|
+
const { RectangleSelection } = this.Blok;
|
|
255
|
+
|
|
256
|
+
this.needToSelectAll = false;
|
|
257
|
+
this.nativeInputSelected = false;
|
|
258
|
+
this.readyToBlockSelection = false;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Disable navigation mode when selection is cleared
|
|
262
|
+
*/
|
|
263
|
+
if (this._navigationModeEnabled) {
|
|
264
|
+
this.disableNavigationMode();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const isKeyboard = reason && (reason instanceof KeyboardEvent);
|
|
268
|
+
const keyboardEvent = reason as KeyboardEvent;
|
|
269
|
+
const isPrintableKey = isKeyboard && keyboardEvent.key && keyboardEvent.key.length === 1;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* If reason caused clear of the selection was printable key and any block is selected,
|
|
273
|
+
* remove selected blocks and insert pressed key
|
|
274
|
+
*/
|
|
275
|
+
if (this.anyBlockSelected && isKeyboard && isPrintableKey && !SelectionUtils.isSelectionExists) {
|
|
276
|
+
this.replaceSelectedBlocksWithPrintableKey(reason as KeyboardEvent);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.Blok.CrossBlockSelection.clear(reason);
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Restore selection when Block is already selected
|
|
283
|
+
* but someone tries to write something.
|
|
284
|
+
*/
|
|
285
|
+
if (restoreSelection) {
|
|
286
|
+
this.selection.restore();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Always clear rectangle selection state
|
|
291
|
+
*/
|
|
292
|
+
if (RectangleSelection.isRectActivated()) {
|
|
293
|
+
this.Blok.RectangleSelection.clearSelection();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (!this.anyBlockSelected) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Now all blocks cleared */
|
|
301
|
+
this.allBlocksSelected = false;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Reduce each Block and copy its content
|
|
306
|
+
* @param {ClipboardEvent} e - copy/cut event
|
|
307
|
+
* @returns {Promise<void>}
|
|
308
|
+
*/
|
|
309
|
+
public async copySelectedBlocks(e: ClipboardEvent): Promise<void> {
|
|
310
|
+
/**
|
|
311
|
+
* Prevent default copy
|
|
312
|
+
*/
|
|
313
|
+
e.preventDefault();
|
|
314
|
+
|
|
315
|
+
const clipboardData = e.clipboardData;
|
|
316
|
+
|
|
317
|
+
if (!clipboardData) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const fakeClipboard = $.make('div');
|
|
322
|
+
const textPlainChunks: string[] = [];
|
|
323
|
+
|
|
324
|
+
this.selectedBlocks.forEach((block) => {
|
|
325
|
+
const cleanHTML = clean(block.holder.innerHTML, this.sanitizerConfig);
|
|
326
|
+
const wrapper = $.make('div');
|
|
327
|
+
|
|
328
|
+
wrapper.innerHTML = cleanHTML;
|
|
329
|
+
|
|
330
|
+
const textContent = wrapper.textContent ?? '';
|
|
331
|
+
|
|
332
|
+
textPlainChunks.push(textContent);
|
|
333
|
+
|
|
334
|
+
const hasElementChildren = Array.from(wrapper.childNodes).some((node) => node.nodeType === Node.ELEMENT_NODE);
|
|
335
|
+
const shouldWrapWithParagraph = !hasElementChildren && textContent.trim().length > 0;
|
|
336
|
+
|
|
337
|
+
if (shouldWrapWithParagraph) {
|
|
338
|
+
const paragraph = $.make('p');
|
|
339
|
+
|
|
340
|
+
paragraph.innerHTML = wrapper.innerHTML;
|
|
341
|
+
fakeClipboard.appendChild(paragraph);
|
|
342
|
+
} else {
|
|
343
|
+
while (wrapper.firstChild) {
|
|
344
|
+
fakeClipboard.appendChild(wrapper.firstChild);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const textPlain = textPlainChunks.join('\n\n');
|
|
350
|
+
const textHTML = fakeClipboard.innerHTML;
|
|
351
|
+
|
|
352
|
+
clipboardData.setData('text/plain', textPlain);
|
|
353
|
+
clipboardData.setData('text/html', textHTML);
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
const savedData = await Promise.all(this.selectedBlocks.map((block) => block.save()));
|
|
357
|
+
|
|
358
|
+
clipboardData.setData(this.Blok.Paste.MIME_TYPE, JSON.stringify(savedData));
|
|
359
|
+
} catch {
|
|
360
|
+
// In Firefox we can't set data in async function
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Select Block by its index
|
|
366
|
+
* @param {number?} index - Block index according to the BlockManager's indexes
|
|
367
|
+
*/
|
|
368
|
+
public selectBlockByIndex(index: number): void {
|
|
369
|
+
const { BlockManager } = this.Blok;
|
|
370
|
+
|
|
371
|
+
const block = BlockManager.getBlockByIndex(index);
|
|
372
|
+
|
|
373
|
+
if (block === undefined) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
this.selectBlock(block);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Select passed Block
|
|
382
|
+
* @param {Block} block - Block to select
|
|
383
|
+
*/
|
|
384
|
+
public selectBlock(block: Block): void {
|
|
385
|
+
/** Save selection */
|
|
386
|
+
this.selection.save();
|
|
387
|
+
const selection = SelectionUtils.get();
|
|
388
|
+
|
|
389
|
+
selection?.removeAllRanges();
|
|
390
|
+
|
|
391
|
+
const blockToSelect = block;
|
|
392
|
+
|
|
393
|
+
blockToSelect.selected = true;
|
|
394
|
+
|
|
395
|
+
this.clearCache();
|
|
396
|
+
|
|
397
|
+
/** close InlineToolbar when we selected any Block */
|
|
398
|
+
this.Blok.InlineToolbar.close();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Remove selection from passed Block
|
|
403
|
+
* @param {Block} block - Block to unselect
|
|
404
|
+
*/
|
|
405
|
+
public unselectBlock(block: Block): void {
|
|
406
|
+
const blockToUnselect = block;
|
|
407
|
+
|
|
408
|
+
blockToUnselect.selected = false;
|
|
409
|
+
|
|
410
|
+
this.clearCache();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Clear anyBlockSelected cache
|
|
415
|
+
*/
|
|
416
|
+
public clearCache(): void {
|
|
417
|
+
this.anyBlockSelectedCache = null;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Enables navigation mode starting from the current block.
|
|
422
|
+
* In this mode, user can navigate between blocks using arrow keys.
|
|
423
|
+
*/
|
|
424
|
+
public enableNavigationMode(): void {
|
|
425
|
+
const { BlockManager } = this.Blok;
|
|
426
|
+
|
|
427
|
+
if (this._navigationModeEnabled) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
this._navigationModeEnabled = true;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Start navigation from current block or first block
|
|
435
|
+
*/
|
|
436
|
+
const startIndex = BlockManager.currentBlockIndex >= 0
|
|
437
|
+
? BlockManager.currentBlockIndex
|
|
438
|
+
: 0;
|
|
439
|
+
|
|
440
|
+
this.setNavigationFocus(startIndex);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Disables navigation mode and optionally focuses the block for editing
|
|
445
|
+
* @param {boolean} focusForEditing - if true, set caret to the focused block
|
|
446
|
+
*/
|
|
447
|
+
public disableNavigationMode(focusForEditing = false): void {
|
|
448
|
+
if (!this._navigationModeEnabled) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const focusedBlock = this.navigationFocusedBlock;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Remove navigation highlight from current block
|
|
456
|
+
*/
|
|
457
|
+
if (focusedBlock) {
|
|
458
|
+
focusedBlock.holder.removeAttribute('data-blok-navigation-focused');
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
this._navigationModeEnabled = false;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* If requested, focus the block for editing
|
|
465
|
+
*/
|
|
466
|
+
if (focusForEditing && focusedBlock) {
|
|
467
|
+
const { Caret, BlockManager } = this.Blok;
|
|
468
|
+
|
|
469
|
+
BlockManager.currentBlockIndex = this.navigationFocusIndex;
|
|
470
|
+
Caret.setToBlock(focusedBlock, Caret.positions.END);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
this.navigationFocusIndex = -1;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Navigate to the next block in navigation mode
|
|
478
|
+
* @returns {boolean} - true if navigation was successful
|
|
479
|
+
*/
|
|
480
|
+
public navigateNext(): boolean {
|
|
481
|
+
if (!this._navigationModeEnabled) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const { BlockManager } = this.Blok;
|
|
486
|
+
const nextIndex = this.navigationFocusIndex + 1;
|
|
487
|
+
|
|
488
|
+
if (nextIndex >= BlockManager.blocks.length) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
this.setNavigationFocus(nextIndex);
|
|
493
|
+
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Navigate to the previous block in navigation mode
|
|
499
|
+
* @returns {boolean} - true if navigation was successful
|
|
500
|
+
*/
|
|
501
|
+
public navigatePrevious(): boolean {
|
|
502
|
+
if (!this._navigationModeEnabled) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const prevIndex = this.navigationFocusIndex - 1;
|
|
507
|
+
|
|
508
|
+
if (prevIndex < 0) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
this.setNavigationFocus(prevIndex);
|
|
513
|
+
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Sets navigation focus to a specific block index
|
|
519
|
+
* @param {number} index - block index to focus
|
|
520
|
+
*/
|
|
521
|
+
private setNavigationFocus(index: number): void {
|
|
522
|
+
const { BlockManager } = this.Blok;
|
|
523
|
+
const block = BlockManager.getBlockByIndex(index);
|
|
524
|
+
|
|
525
|
+
if (!block) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Remove highlight from previous block
|
|
531
|
+
*/
|
|
532
|
+
const previousBlock = this.navigationFocusedBlock;
|
|
533
|
+
|
|
534
|
+
if (previousBlock) {
|
|
535
|
+
previousBlock.holder.removeAttribute('data-blok-navigation-focused');
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Update focus index and highlight new block
|
|
540
|
+
*/
|
|
541
|
+
this.navigationFocusIndex = index;
|
|
542
|
+
block.holder.setAttribute('data-blok-navigation-focused', 'true');
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Remove text selection and blur active element to hide caret
|
|
546
|
+
*/
|
|
547
|
+
const selection = SelectionUtils.get();
|
|
548
|
+
|
|
549
|
+
selection?.removeAllRanges();
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Blur the active element to remove caret from contenteditable
|
|
553
|
+
*/
|
|
554
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
555
|
+
document.activeElement.blur();
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Scroll block into view if needed
|
|
560
|
+
*/
|
|
561
|
+
block.holder.scrollIntoView({
|
|
562
|
+
behavior: 'smooth',
|
|
563
|
+
block: 'nearest',
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Module destruction
|
|
569
|
+
* De-registers Shortcut CMD+A
|
|
570
|
+
*/
|
|
571
|
+
public destroy(): void {
|
|
572
|
+
/** Selection shortcut */
|
|
573
|
+
Shortcuts.remove(this.Blok.UI.nodes.redactor, 'CMD+A');
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* First CMD+A selects all input content by native behaviour,
|
|
578
|
+
* next CMD+A keypress selects all blocks
|
|
579
|
+
* @param {KeyboardEvent} event - keyboard event
|
|
580
|
+
*/
|
|
581
|
+
private handleCommandA(event: KeyboardEvent): void {
|
|
582
|
+
this.Blok.RectangleSelection.clearSelection();
|
|
583
|
+
|
|
584
|
+
/** allow default selection on native inputs */
|
|
585
|
+
if ($.isNativeInput(event.target) && !this.readyToBlockSelection) {
|
|
586
|
+
this.readyToBlockSelection = true;
|
|
587
|
+
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const workingBlock = this.Blok.BlockManager.getBlock(event.target as HTMLElement);
|
|
592
|
+
|
|
593
|
+
if (!workingBlock) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const inputs = workingBlock.inputs;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* If Block has more than one editable element allow native selection
|
|
601
|
+
* Second cmd+a will select whole Block
|
|
602
|
+
*/
|
|
603
|
+
if (inputs.length > 1 && !this.readyToBlockSelection) {
|
|
604
|
+
this.readyToBlockSelection = true;
|
|
605
|
+
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (inputs.length === 1 && !this.needToSelectAll) {
|
|
610
|
+
this.needToSelectAll = true;
|
|
611
|
+
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (this.needToSelectAll) {
|
|
616
|
+
/**
|
|
617
|
+
* Prevent default selection
|
|
618
|
+
*/
|
|
619
|
+
event.preventDefault();
|
|
620
|
+
|
|
621
|
+
this.selectAllBlocks();
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Disable any selection after all Blocks selected
|
|
625
|
+
*/
|
|
626
|
+
this.needToSelectAll = false;
|
|
627
|
+
this.readyToBlockSelection = false;
|
|
628
|
+
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (!this.readyToBlockSelection) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* prevent default selection when we use custom selection
|
|
638
|
+
*/
|
|
639
|
+
event.preventDefault();
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* select working Block
|
|
643
|
+
*/
|
|
644
|
+
this.selectBlock(workingBlock);
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Enable all Blocks selection if current Block is selected
|
|
648
|
+
*/
|
|
649
|
+
this.needToSelectAll = true;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Select All Blocks
|
|
654
|
+
* Each Block has selected setter that makes Block copyable
|
|
655
|
+
*/
|
|
656
|
+
private selectAllBlocks(): void {
|
|
657
|
+
/**
|
|
658
|
+
* Save selection
|
|
659
|
+
* Will be restored when closeSelection fired
|
|
660
|
+
*/
|
|
661
|
+
this.selection.save();
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Remove Ranges from Selection
|
|
665
|
+
*/
|
|
666
|
+
const selection = SelectionUtils.get();
|
|
667
|
+
|
|
668
|
+
selection?.removeAllRanges();
|
|
669
|
+
|
|
670
|
+
this.allBlocksSelected = true;
|
|
671
|
+
|
|
672
|
+
/** close InlineToolbar if we selected all Blocks */
|
|
673
|
+
this.Blok.InlineToolbar.close();
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Remove selected blocks and insert pressed printable key
|
|
678
|
+
* @param event - keyboard event that triggers replacement
|
|
679
|
+
*/
|
|
680
|
+
private replaceSelectedBlocksWithPrintableKey(event: KeyboardEvent): void {
|
|
681
|
+
const { BlockManager, Caret } = this.Blok;
|
|
682
|
+
const indexToInsert = BlockManager.removeSelectedBlocks();
|
|
683
|
+
|
|
684
|
+
if (indexToInsert === undefined) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
BlockManager.insertDefaultBlockAtIndex(indexToInsert, true);
|
|
689
|
+
|
|
690
|
+
const currentBlock = BlockManager.currentBlock;
|
|
691
|
+
|
|
692
|
+
if (currentBlock) {
|
|
693
|
+
Caret.setToBlock(currentBlock);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
delay(() => {
|
|
697
|
+
const eventKey = event.key;
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* If event.key length >1 that means key is special (e.g. Enter or Dead or Unidentified).
|
|
701
|
+
* So we use empty string
|
|
702
|
+
* @see https://developer.mozilla.org/ru/docs/Web/API/KeyboardEvent/key
|
|
703
|
+
*/
|
|
704
|
+
Caret.insertContentAtCaretPosition(eventKey.length > 1 ? '' : eventKey);
|
|
705
|
+
|
|
706
|
+
}, 20)();
|
|
707
|
+
}
|
|
708
|
+
}
|