@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,668 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class RectangleSelection
|
|
3
|
+
* @classdesc Manages Block selection with mouse
|
|
4
|
+
* @module RectangleSelection
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { Module } from '../__module';
|
|
8
|
+
import { Dom as $ } from '../dom';
|
|
9
|
+
|
|
10
|
+
import { SelectionUtils } from '../selection';
|
|
11
|
+
import { throttle } from '../utils';
|
|
12
|
+
import {
|
|
13
|
+
INLINE_TOOLBAR_INTERFACE_SELECTOR,
|
|
14
|
+
DATA_ATTR,
|
|
15
|
+
createSelector,
|
|
16
|
+
} from '../constants';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export class RectangleSelection extends Module {
|
|
22
|
+
/**
|
|
23
|
+
* CSS classes for the Block - kept for backward compatibility
|
|
24
|
+
* @returns {{wrapper: string, content: string}}
|
|
25
|
+
* @deprecated Use data attributes via constants instead (BLOK_OVERLAY_ATTR, BLOK_OVERLAY_CONTAINER_ATTR, etc.)
|
|
26
|
+
*/
|
|
27
|
+
public static get CSS(): {[name: string]: string} {
|
|
28
|
+
return {
|
|
29
|
+
overlay: '',
|
|
30
|
+
overlayContainer: '',
|
|
31
|
+
rect: '',
|
|
32
|
+
topScrollZone: '',
|
|
33
|
+
bottomScrollZone: '',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Using the selection rectangle
|
|
39
|
+
* @type {boolean}
|
|
40
|
+
*/
|
|
41
|
+
private isRectSelectionActivated = false;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Speed of Scrolling
|
|
45
|
+
*/
|
|
46
|
+
private readonly SCROLL_SPEED: number = 3;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Height of scroll zone on boundary of screen
|
|
50
|
+
*/
|
|
51
|
+
private readonly HEIGHT_OF_SCROLL_ZONE = 40;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Scroll zone type indicators
|
|
55
|
+
*/
|
|
56
|
+
private readonly BOTTOM_SCROLL_ZONE = 1;
|
|
57
|
+
private readonly TOP_SCROLL_ZONE = 2;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Id of main button for event.button
|
|
61
|
+
*/
|
|
62
|
+
private readonly MAIN_MOUSE_BUTTON = 0;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Mouse is clamped
|
|
66
|
+
*/
|
|
67
|
+
private mousedown = false;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Is scrolling now
|
|
71
|
+
*/
|
|
72
|
+
private isScrolling = false;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Mouse is in scroll zone
|
|
76
|
+
*/
|
|
77
|
+
private inScrollZone: number | null = null;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Coords of rect
|
|
81
|
+
*/
|
|
82
|
+
private startX = 0;
|
|
83
|
+
private startY = 0;
|
|
84
|
+
private mouseX = 0;
|
|
85
|
+
private mouseY = 0;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Selected blocks
|
|
89
|
+
*/
|
|
90
|
+
private stackOfSelected: number[] = [];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Does the rectangle intersect blocks
|
|
94
|
+
*/
|
|
95
|
+
private rectCrossesBlocks = false;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Selection rectangle
|
|
99
|
+
*/
|
|
100
|
+
private overlayRectangle: HTMLDivElement | null = null;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Listener identifiers
|
|
104
|
+
*/
|
|
105
|
+
private listenerIds: string[] = [];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Module Preparation
|
|
109
|
+
* Creating rect and hang handlers
|
|
110
|
+
*/
|
|
111
|
+
public prepare(): void {
|
|
112
|
+
this.enableModuleBindings();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Init rect params
|
|
117
|
+
* @param {number} pageX - X coord of mouse
|
|
118
|
+
* @param {number} pageY - Y coord of mouse
|
|
119
|
+
*/
|
|
120
|
+
public startSelection(pageX: number, pageY: number): void {
|
|
121
|
+
const scrollLeft = this.getScrollLeft();
|
|
122
|
+
const scrollTop = this.getScrollTop();
|
|
123
|
+
const elemWhereSelectionStart = document.elementFromPoint(pageX - scrollLeft, pageY - scrollTop);
|
|
124
|
+
|
|
125
|
+
if (!elemWhereSelectionStart) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Don't clear selected block by clicks on the Block settings
|
|
131
|
+
* because we need to keep highlighting working block
|
|
132
|
+
*/
|
|
133
|
+
const startsInsideToolbar = elemWhereSelectionStart.closest(createSelector(DATA_ATTR.toolbar));
|
|
134
|
+
|
|
135
|
+
if (!startsInsideToolbar) {
|
|
136
|
+
this.Blok.BlockSelection.allBlocksSelected = false;
|
|
137
|
+
this.clearSelection();
|
|
138
|
+
this.stackOfSelected = [];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const selectorsToAvoid = [
|
|
142
|
+
createSelector(DATA_ATTR.elementContent),
|
|
143
|
+
createSelector(DATA_ATTR.toolbar),
|
|
144
|
+
INLINE_TOOLBAR_INTERFACE_SELECTOR,
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
const startsInsideBlok = elemWhereSelectionStart.closest(createSelector(DATA_ATTR.editor));
|
|
148
|
+
const startsInSelectorToAvoid = selectorsToAvoid.some((selector) => !!elemWhereSelectionStart.closest(selector));
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* If selection starts outside of the blok or inside the blocks or on Blok UI elements, do not handle it
|
|
152
|
+
*/
|
|
153
|
+
if (!startsInsideBlok || startsInSelectorToAvoid) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Hide the toolbar immediately so it does not obstruct drag selection.
|
|
159
|
+
*/
|
|
160
|
+
this.Blok.Toolbar.close();
|
|
161
|
+
|
|
162
|
+
this.mousedown = true;
|
|
163
|
+
this.startX = pageX;
|
|
164
|
+
this.startY = pageY;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Clear all params to end selection
|
|
169
|
+
*/
|
|
170
|
+
public endSelection(): void {
|
|
171
|
+
this.mousedown = false;
|
|
172
|
+
this.startX = 0;
|
|
173
|
+
this.startY = 0;
|
|
174
|
+
if (this.overlayRectangle !== null) {
|
|
175
|
+
this.overlayRectangle.style.display = 'none';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* is RectSelection Activated
|
|
181
|
+
*/
|
|
182
|
+
public isRectActivated(): boolean {
|
|
183
|
+
return this.isRectSelectionActivated;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Mark that selection is end
|
|
188
|
+
*/
|
|
189
|
+
public clearSelection(): void {
|
|
190
|
+
this.isRectSelectionActivated = false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Sets Module necessary event handlers
|
|
195
|
+
*/
|
|
196
|
+
private enableModuleBindings(): void {
|
|
197
|
+
const { container } = this.genHTML();
|
|
198
|
+
|
|
199
|
+
this.listeners.on(container, 'mousedown', (event: Event) => {
|
|
200
|
+
this.processMouseDown(event as MouseEvent);
|
|
201
|
+
}, false);
|
|
202
|
+
|
|
203
|
+
const throttledMouseMove = throttle((event: unknown) => {
|
|
204
|
+
if (event instanceof MouseEvent) {
|
|
205
|
+
this.processMouseMove(event);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
}, 10) as EventListener;
|
|
209
|
+
|
|
210
|
+
this.listeners.on(document.body, 'mousemove', throttledMouseMove, {
|
|
211
|
+
passive: true,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
this.listeners.on(document.body, 'mouseleave', () => {
|
|
215
|
+
this.processMouseLeave();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const throttledScroll = throttle((event: unknown) => {
|
|
219
|
+
this.processScroll(event as MouseEvent);
|
|
220
|
+
|
|
221
|
+
}, 10) as EventListener;
|
|
222
|
+
|
|
223
|
+
this.listeners.on(window, 'scroll', throttledScroll, {
|
|
224
|
+
passive: true,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
this.listeners.on(document.body, 'mouseup', () => {
|
|
228
|
+
this.processMouseUp();
|
|
229
|
+
}, false);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Handle mouse down events
|
|
234
|
+
* @param {MouseEvent} mouseEvent - mouse event payload
|
|
235
|
+
*/
|
|
236
|
+
private processMouseDown(mouseEvent: MouseEvent): void {
|
|
237
|
+
if (mouseEvent.button !== this.MAIN_MOUSE_BUTTON) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Do not enable the Rectangle Selection when mouse dragging started some editable input
|
|
243
|
+
* Used to prevent Rectangle Selection on Block Tune wrappers' inputs that also can be inside the Block
|
|
244
|
+
*/
|
|
245
|
+
const startedFromContentEditable = (mouseEvent.target as Element).closest($.allInputsSelector) !== null;
|
|
246
|
+
|
|
247
|
+
if (!startedFromContentEditable) {
|
|
248
|
+
this.startSelection(mouseEvent.pageX, mouseEvent.pageY);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Handle mouse move events
|
|
254
|
+
* @param {MouseEvent} mouseEvent - mouse event payload
|
|
255
|
+
*/
|
|
256
|
+
private processMouseMove(mouseEvent: MouseEvent): void {
|
|
257
|
+
this.changingRectangle(mouseEvent);
|
|
258
|
+
this.scrollByZones(mouseEvent.clientY);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Handle mouse leave
|
|
263
|
+
*/
|
|
264
|
+
private processMouseLeave(): void {
|
|
265
|
+
this.clearSelection();
|
|
266
|
+
this.endSelection();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @param {MouseEvent} mouseEvent - mouse event payload
|
|
271
|
+
*/
|
|
272
|
+
private processScroll(mouseEvent: MouseEvent): void {
|
|
273
|
+
this.changingRectangle(mouseEvent);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Handle mouse up
|
|
278
|
+
*/
|
|
279
|
+
private processMouseUp(): void {
|
|
280
|
+
/**
|
|
281
|
+
* Show toolbar for multi-block selection after mouse up
|
|
282
|
+
*/
|
|
283
|
+
const selectedBlocks = this.Blok.BlockSelection.selectedBlocks;
|
|
284
|
+
|
|
285
|
+
if (selectedBlocks.length > 1) {
|
|
286
|
+
this.Blok.Toolbar.moveAndOpenForMultipleBlocks();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this.clearSelection();
|
|
290
|
+
this.endSelection();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Scroll If mouse in scroll zone
|
|
295
|
+
* @param {number} clientY - Y coord of mouse
|
|
296
|
+
*/
|
|
297
|
+
private scrollByZones(clientY: number): void {
|
|
298
|
+
this.inScrollZone = null;
|
|
299
|
+
if (clientY <= this.HEIGHT_OF_SCROLL_ZONE) {
|
|
300
|
+
this.inScrollZone = this.TOP_SCROLL_ZONE;
|
|
301
|
+
}
|
|
302
|
+
if (document.documentElement.clientHeight - clientY <= this.HEIGHT_OF_SCROLL_ZONE) {
|
|
303
|
+
this.inScrollZone = this.BOTTOM_SCROLL_ZONE;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!this.inScrollZone) {
|
|
307
|
+
this.isScrolling = false;
|
|
308
|
+
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (!this.isScrolling) {
|
|
313
|
+
this.scrollVertical(this.inScrollZone === this.TOP_SCROLL_ZONE ? -this.SCROLL_SPEED : this.SCROLL_SPEED);
|
|
314
|
+
this.isScrolling = true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Generates required HTML elements
|
|
320
|
+
* @returns {Record<string, Element>}
|
|
321
|
+
*/
|
|
322
|
+
private genHTML(): {container: Element; overlay: Element} {
|
|
323
|
+
const { UI } = this.Blok;
|
|
324
|
+
|
|
325
|
+
const container = UI.nodes.holder.querySelector(createSelector(DATA_ATTR.editor));
|
|
326
|
+
const overlay = $.make('div', [
|
|
327
|
+
'fixed',
|
|
328
|
+
'inset-0',
|
|
329
|
+
'z-overlay',
|
|
330
|
+
'pointer-events-none',
|
|
331
|
+
'overflow-hidden',
|
|
332
|
+
], {});
|
|
333
|
+
const overlayContainer = $.make('div', [
|
|
334
|
+
'relative',
|
|
335
|
+
'pointer-events-auto',
|
|
336
|
+
'z-0',
|
|
337
|
+
], {});
|
|
338
|
+
const overlayRectangle = $.make('div', [
|
|
339
|
+
'absolute',
|
|
340
|
+
'pointer-events-none',
|
|
341
|
+
'bg-selection-highlight',
|
|
342
|
+
'border',
|
|
343
|
+
'border-transparent',
|
|
344
|
+
], {});
|
|
345
|
+
|
|
346
|
+
overlay.setAttribute(DATA_ATTR.overlay, '');
|
|
347
|
+
overlayContainer.setAttribute(DATA_ATTR.overlayContainer, '');
|
|
348
|
+
overlayRectangle.setAttribute(DATA_ATTR.overlayRectangle, '');
|
|
349
|
+
overlay.setAttribute('data-blok-testid', 'overlay');
|
|
350
|
+
overlayRectangle.setAttribute('data-blok-testid', 'overlay-rectangle');
|
|
351
|
+
|
|
352
|
+
if (!container) {
|
|
353
|
+
throw new Error('RectangleSelection: blok wrapper not found');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
overlayContainer.appendChild(overlayRectangle);
|
|
357
|
+
overlay.appendChild(overlayContainer);
|
|
358
|
+
container.appendChild(overlay);
|
|
359
|
+
|
|
360
|
+
this.overlayRectangle = overlayRectangle as HTMLDivElement;
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
container,
|
|
364
|
+
overlay,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Activates scrolling if blockSelection is active and mouse is in scroll zone
|
|
370
|
+
* @param {number} speed - speed of scrolling
|
|
371
|
+
*/
|
|
372
|
+
private scrollVertical(speed: number): void {
|
|
373
|
+
if (!(this.inScrollZone && this.mousedown)) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const lastOffset = this.getScrollTop();
|
|
377
|
+
|
|
378
|
+
window.scrollBy(0, speed);
|
|
379
|
+
this.mouseY += this.getScrollTop() - lastOffset;
|
|
380
|
+
setTimeout(() => {
|
|
381
|
+
this.scrollVertical(speed);
|
|
382
|
+
}, 0);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Handles the change in the rectangle and its effect
|
|
387
|
+
* @param {MouseEvent} event - mouse event
|
|
388
|
+
*/
|
|
389
|
+
private changingRectangle(event: MouseEvent): void {
|
|
390
|
+
if (!this.mousedown) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const overlayRectangle = this.overlayRectangle;
|
|
395
|
+
|
|
396
|
+
if (overlayRectangle === null) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (event.pageY !== undefined) {
|
|
401
|
+
this.mouseX = event.pageX;
|
|
402
|
+
this.mouseY = event.pageY;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const { rightPos, leftPos, index } = this.genInfoForMouseSelection();
|
|
406
|
+
// There is not new block in selection
|
|
407
|
+
|
|
408
|
+
const rectIsOnRighSideOfredactor = this.startX > rightPos && this.mouseX > rightPos;
|
|
409
|
+
const rectISOnLeftSideOfRedactor = this.startX < leftPos && this.mouseX < leftPos;
|
|
410
|
+
|
|
411
|
+
this.rectCrossesBlocks = !(rectIsOnRighSideOfredactor || rectISOnLeftSideOfRedactor);
|
|
412
|
+
|
|
413
|
+
if (!this.isRectSelectionActivated) {
|
|
414
|
+
this.rectCrossesBlocks = false;
|
|
415
|
+
this.isRectSelectionActivated = true;
|
|
416
|
+
this.shrinkRectangleToPoint();
|
|
417
|
+
overlayRectangle.style.display = 'block';
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
this.updateRectangleSize();
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Hide Block Settings Toggler (along with the Toolbar) (if showed) when the Rectangle Selection is activated
|
|
424
|
+
*/
|
|
425
|
+
this.Blok.Toolbar.close();
|
|
426
|
+
|
|
427
|
+
if (index === undefined) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
this.trySelectNextBlock(index);
|
|
432
|
+
// For case, when rect is out from blocks
|
|
433
|
+
this.inverseSelection();
|
|
434
|
+
|
|
435
|
+
const selection = SelectionUtils.get();
|
|
436
|
+
|
|
437
|
+
if (selection) {
|
|
438
|
+
selection.removeAllRanges();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Shrink rect to singular point
|
|
444
|
+
*/
|
|
445
|
+
private shrinkRectangleToPoint(): void {
|
|
446
|
+
if (this.overlayRectangle === null) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const scrollLeft = this.getScrollLeft();
|
|
451
|
+
const scrollTop = this.getScrollTop();
|
|
452
|
+
|
|
453
|
+
this.overlayRectangle.style.left = `${this.startX - scrollLeft}px`;
|
|
454
|
+
this.overlayRectangle.style.top = `${this.startY - scrollTop}px`;
|
|
455
|
+
this.overlayRectangle.style.bottom = `calc(100% - ${this.startY - scrollTop}px)`;
|
|
456
|
+
this.overlayRectangle.style.right = `calc(100% - ${this.startX - scrollLeft}px)`;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Select or unselect all of blocks in array if rect is out or in selectable area
|
|
461
|
+
*/
|
|
462
|
+
private inverseSelection(): void {
|
|
463
|
+
if (this.stackOfSelected.length === 0) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const firstBlockInStack = this.Blok.BlockManager.getBlockByIndex(this.stackOfSelected[0]);
|
|
468
|
+
|
|
469
|
+
if (!firstBlockInStack) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const isSelectedMode = firstBlockInStack.selected;
|
|
474
|
+
|
|
475
|
+
if (this.rectCrossesBlocks && !isSelectedMode) {
|
|
476
|
+
for (const it of this.stackOfSelected) {
|
|
477
|
+
this.Blok.BlockSelection.selectBlockByIndex(it);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (!this.rectCrossesBlocks && isSelectedMode) {
|
|
482
|
+
for (const it of this.stackOfSelected) {
|
|
483
|
+
this.Blok.BlockSelection.unSelectBlockByIndex(it);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Updates size of rectangle
|
|
490
|
+
*/
|
|
491
|
+
private updateRectangleSize(): void {
|
|
492
|
+
if (this.overlayRectangle === null) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const scrollLeft = this.getScrollLeft();
|
|
497
|
+
const scrollTop = this.getScrollTop();
|
|
498
|
+
|
|
499
|
+
// Depending on the position of the mouse relative to the starting point,
|
|
500
|
+
// change this.e distance from the desired edge of the screen*/
|
|
501
|
+
if (this.mouseY >= this.startY) {
|
|
502
|
+
this.overlayRectangle.style.top = `${this.startY - scrollTop}px`;
|
|
503
|
+
this.overlayRectangle.style.bottom = `calc(100% - ${this.mouseY - scrollTop}px)`;
|
|
504
|
+
} else {
|
|
505
|
+
this.overlayRectangle.style.bottom = `calc(100% - ${this.startY - scrollTop}px)`;
|
|
506
|
+
this.overlayRectangle.style.top = `${this.mouseY - scrollTop}px`;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (this.mouseX >= this.startX) {
|
|
510
|
+
this.overlayRectangle.style.left = `${this.startX - scrollLeft}px`;
|
|
511
|
+
this.overlayRectangle.style.right = `calc(100% - ${this.mouseX - scrollLeft}px)`;
|
|
512
|
+
} else {
|
|
513
|
+
this.overlayRectangle.style.right = `calc(100% - ${this.startX - scrollLeft}px)`;
|
|
514
|
+
this.overlayRectangle.style.left = `${this.mouseX - scrollLeft}px`;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Collects information needed to determine the behavior of the rectangle
|
|
520
|
+
* @returns {object} index - index next Block, leftPos - start of left border of Block, rightPos - right border
|
|
521
|
+
*/
|
|
522
|
+
private genInfoForMouseSelection(): {index: number | undefined; leftPos: number; rightPos: number} {
|
|
523
|
+
const widthOfRedactor = document.body.offsetWidth;
|
|
524
|
+
const centerOfRedactor = widthOfRedactor / 2;
|
|
525
|
+
const scrollTop = this.getScrollTop();
|
|
526
|
+
const y = this.mouseY - scrollTop;
|
|
527
|
+
const elementUnderMouse = document.elementFromPoint(centerOfRedactor, y);
|
|
528
|
+
const lastBlockHolder = this.Blok.BlockManager.lastBlock?.holder;
|
|
529
|
+
const contentElement = lastBlockHolder?.querySelector(createSelector(DATA_ATTR.elementContent));
|
|
530
|
+
const contentWidth = contentElement ? Number.parseInt(window.getComputedStyle(contentElement).width, 10) : 0;
|
|
531
|
+
const centerOfBlock = contentWidth / 2;
|
|
532
|
+
const leftPos = centerOfRedactor - centerOfBlock;
|
|
533
|
+
const rightPos = centerOfRedactor + centerOfBlock;
|
|
534
|
+
|
|
535
|
+
if (!elementUnderMouse) {
|
|
536
|
+
return {
|
|
537
|
+
index: undefined,
|
|
538
|
+
leftPos,
|
|
539
|
+
rightPos,
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const blockInCurrentPos = this.Blok.BlockManager.getBlockByChildNode(elementUnderMouse);
|
|
543
|
+
|
|
544
|
+
const index = blockInCurrentPos !== undefined
|
|
545
|
+
? this.Blok.BlockManager.blocks.findIndex((block) => block.holder === blockInCurrentPos.holder)
|
|
546
|
+
: undefined;
|
|
547
|
+
|
|
548
|
+
return {
|
|
549
|
+
index,
|
|
550
|
+
leftPos,
|
|
551
|
+
rightPos,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Normalized vertical scroll value that does not rely on deprecated APIs.
|
|
557
|
+
*/
|
|
558
|
+
private getScrollTop(): number {
|
|
559
|
+
if (typeof window.scrollY === 'number') {
|
|
560
|
+
return window.scrollY;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return document.documentElement?.scrollTop ?? document.body?.scrollTop ?? 0;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Normalized horizontal scroll value that does not rely on deprecated APIs.
|
|
568
|
+
*/
|
|
569
|
+
private getScrollLeft(): number {
|
|
570
|
+
if (typeof window.scrollX === 'number') {
|
|
571
|
+
return window.scrollX;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return document.documentElement?.scrollLeft ?? document.body?.scrollLeft ?? 0;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Select block with index index
|
|
579
|
+
* @param index - index of block in redactor
|
|
580
|
+
*/
|
|
581
|
+
private addBlockInSelection(index: number): void {
|
|
582
|
+
if (this.rectCrossesBlocks) {
|
|
583
|
+
this.Blok.BlockSelection.selectBlockByIndex(index);
|
|
584
|
+
}
|
|
585
|
+
this.stackOfSelected.push(index);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Adds a block to the selection and determines which blocks should be selected
|
|
590
|
+
* @param {object} index - index of new block in the reactor
|
|
591
|
+
*/
|
|
592
|
+
private trySelectNextBlock(index: number): void {
|
|
593
|
+
const sizeStack = this.stackOfSelected.length;
|
|
594
|
+
const lastSelected = this.stackOfSelected[sizeStack - 1];
|
|
595
|
+
const sameBlock = lastSelected === index;
|
|
596
|
+
|
|
597
|
+
if (sameBlock) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const previousSelected = this.stackOfSelected[sizeStack - 2];
|
|
602
|
+
const blockNumbersIncrease = previousSelected !== undefined && lastSelected !== undefined
|
|
603
|
+
? lastSelected - previousSelected > 0
|
|
604
|
+
: false;
|
|
605
|
+
const isInitialSelection = sizeStack <= 1;
|
|
606
|
+
const selectionInDownDirection = lastSelected !== undefined && index > lastSelected && blockNumbersIncrease;
|
|
607
|
+
const selectionInUpDirection = lastSelected !== undefined && index < lastSelected && sizeStack > 1 && !blockNumbersIncrease;
|
|
608
|
+
const generalSelection = selectionInDownDirection || selectionInUpDirection || isInitialSelection;
|
|
609
|
+
const reduction = !generalSelection;
|
|
610
|
+
|
|
611
|
+
// When the selection is too fast, some blocks do not have time to be noticed. Fix it.
|
|
612
|
+
if (!reduction && (lastSelected === undefined || index > lastSelected)) {
|
|
613
|
+
const startIndex = lastSelected !== undefined ? lastSelected + 1 : index;
|
|
614
|
+
|
|
615
|
+
Array.from({ length: index - startIndex + 1 }, (_unused, offset) => startIndex + offset)
|
|
616
|
+
.forEach((ind) => {
|
|
617
|
+
this.addBlockInSelection(ind);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// for both directions
|
|
624
|
+
if (!reduction && lastSelected !== undefined && index < lastSelected) {
|
|
625
|
+
Array.from(
|
|
626
|
+
{ length: lastSelected - index },
|
|
627
|
+
(_unused, offset) => lastSelected - 1 - offset
|
|
628
|
+
).forEach((ind) => {
|
|
629
|
+
this.addBlockInSelection(ind);
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (!reduction) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const shouldRemove = (stackIndex: number): boolean => {
|
|
640
|
+
if (lastSelected === undefined) {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if (index > lastSelected) {
|
|
645
|
+
return index > stackIndex;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return index < stackIndex;
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
const indicesToRemove: number[] = [];
|
|
652
|
+
|
|
653
|
+
for (const stackIndex of [ ...this.stackOfSelected ].reverse()) {
|
|
654
|
+
if (!shouldRemove(stackIndex)) {
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
if (this.rectCrossesBlocks) {
|
|
659
|
+
this.Blok.BlockSelection.unSelectBlockByIndex(stackIndex);
|
|
660
|
+
}
|
|
661
|
+
indicesToRemove.push(stackIndex);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (indicesToRemove.length > 0) {
|
|
665
|
+
this.stackOfSelected.splice(this.stackOfSelected.length - indicesToRemove.length, indicesToRemove.length);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|