@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,642 @@
|
|
|
1
|
+
import { DATA_ATTR, TOOLTIP_INTERFACE_VALUE } from '../constants';
|
|
2
|
+
import { twJoin } from './tw';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tooltip supported content
|
|
6
|
+
*/
|
|
7
|
+
export type TooltipContent = HTMLElement | DocumentFragment | Node | string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Base options interface for tooltips
|
|
11
|
+
*/
|
|
12
|
+
export interface TooltipOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Tooltip placement: top|bottom|left|right
|
|
15
|
+
*/
|
|
16
|
+
placement?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tooltip top margin
|
|
20
|
+
*/
|
|
21
|
+
marginTop?: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tooltip left margin
|
|
25
|
+
*/
|
|
26
|
+
marginLeft?: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Tooltip right margin
|
|
30
|
+
*/
|
|
31
|
+
marginRight?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Tooltip bottom margin
|
|
35
|
+
*/
|
|
36
|
+
marginBottom?: number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Timout before showing
|
|
40
|
+
*/
|
|
41
|
+
delay?: number;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Timout before hiding
|
|
45
|
+
*/
|
|
46
|
+
hidingDelay?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const DEFAULT_OFFSET = 10;
|
|
50
|
+
const TOOLTIP_ROLE = 'tooltip';
|
|
51
|
+
const ARIA_HIDDEN_ATTRIBUTE = 'aria-hidden';
|
|
52
|
+
const ARIA_HIDDEN_FALSE = 'false';
|
|
53
|
+
const ARIA_HIDDEN_TRUE = 'true';
|
|
54
|
+
const VISIBILITY_PROPERTY = 'visibility';
|
|
55
|
+
const VISIBILITY_VISIBLE = 'visible';
|
|
56
|
+
const VISIBILITY_HIDDEN = 'hidden';
|
|
57
|
+
|
|
58
|
+
type CSSTooltipClasses = {
|
|
59
|
+
tooltip: string | string[];
|
|
60
|
+
tooltipContent: string | string[];
|
|
61
|
+
tooltipShown: string | string[];
|
|
62
|
+
placement: {
|
|
63
|
+
left: string | string[];
|
|
64
|
+
bottom: string | string[];
|
|
65
|
+
right: string | string[];
|
|
66
|
+
top: string | string[];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Tiny any beautiful tooltips module.
|
|
72
|
+
*
|
|
73
|
+
* Can be showed near passed Element with any specified HTML content
|
|
74
|
+
*/
|
|
75
|
+
class Tooltip {
|
|
76
|
+
/**
|
|
77
|
+
* Tooltip CSS classes
|
|
78
|
+
* @returns {object} CSS class names
|
|
79
|
+
*/
|
|
80
|
+
private get CSS(): CSSTooltipClasses {
|
|
81
|
+
return {
|
|
82
|
+
tooltip: twJoin(
|
|
83
|
+
'absolute z-overlay top-0 left-0',
|
|
84
|
+
'bg-tooltip-bg opacity-0',
|
|
85
|
+
'select-none pointer-events-none',
|
|
86
|
+
'transition-[opacity,transform] duration-[50ms,70ms] ease-in',
|
|
87
|
+
'rounded-lg shadow-tooltip',
|
|
88
|
+
'will-change-[opacity,top,left]',
|
|
89
|
+
'before:content-[\'\'] before:absolute before:inset-0 before:bg-tooltip-bg before:-z-10 before:rounded-lg',
|
|
90
|
+
'mobile:hidden'
|
|
91
|
+
).split(' '),
|
|
92
|
+
tooltipContent: twJoin(
|
|
93
|
+
'px-2.5 py-1.5',
|
|
94
|
+
'text-tooltip-font text-xs text-center',
|
|
95
|
+
'tracking-[0.02em] leading-[1em]'
|
|
96
|
+
).split(' '),
|
|
97
|
+
tooltipShown: ['opacity-100', 'transform-none'],
|
|
98
|
+
placement: {
|
|
99
|
+
left: ['-translate-x-[5px]'],
|
|
100
|
+
bottom: ['translate-y-[5px]'],
|
|
101
|
+
right: ['translate-x-[5px]'],
|
|
102
|
+
top: ['-translate-y-[5px]'],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Module nodes
|
|
109
|
+
*/
|
|
110
|
+
private nodes: {
|
|
111
|
+
wrapper: HTMLElement | null;
|
|
112
|
+
content: HTMLElement | null;
|
|
113
|
+
} = {
|
|
114
|
+
wrapper: null,
|
|
115
|
+
content: null,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Appearance state
|
|
120
|
+
*/
|
|
121
|
+
private showed: boolean = false;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Offset above the Tooltip
|
|
125
|
+
*/
|
|
126
|
+
private offsetTop: number = DEFAULT_OFFSET;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Offset at the left from the Tooltip
|
|
130
|
+
*/
|
|
131
|
+
private offsetLeft: number = DEFAULT_OFFSET;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Offset at the right from the Tooltip
|
|
135
|
+
*/
|
|
136
|
+
private offsetRight: number = DEFAULT_OFFSET;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Store timeout before showing to clear it on hide
|
|
140
|
+
*/
|
|
141
|
+
private showingTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* How many milliseconds need to wait before hiding
|
|
145
|
+
*/
|
|
146
|
+
private hidingDelay: number = 0;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Store timeout before hiding
|
|
150
|
+
*/
|
|
151
|
+
private hidingTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* MutationObserver for watching tooltip visibility changes
|
|
155
|
+
*/
|
|
156
|
+
private ariaObserver: MutationObserver | null = null;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Static singleton instance
|
|
160
|
+
*/
|
|
161
|
+
private static instance: Tooltip | null = null;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Get singleton instance
|
|
165
|
+
*/
|
|
166
|
+
public static getInstance(): Tooltip {
|
|
167
|
+
if (!Tooltip.instance) {
|
|
168
|
+
Tooltip.instance = new Tooltip();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return Tooltip.instance;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Module constructor
|
|
176
|
+
*/
|
|
177
|
+
private constructor() {
|
|
178
|
+
this.prepare();
|
|
179
|
+
|
|
180
|
+
window.addEventListener('scroll', this.handleWindowScroll, { passive: true });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Show Tooltip near passed element with specified HTML content
|
|
185
|
+
* @param {HTMLElement} element - target element to place Tooltip near that
|
|
186
|
+
* @param {TooltipContent} content — any HTML Element of String that will be used as content
|
|
187
|
+
* @param {TooltipOptions} options — Available options {@link TooltipOptions}
|
|
188
|
+
*/
|
|
189
|
+
public show(element: HTMLElement, content: TooltipContent, options: TooltipOptions = {}): void {
|
|
190
|
+
if (!this.nodes.wrapper) {
|
|
191
|
+
this.prepare();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.hidingTimeout) {
|
|
195
|
+
clearTimeout(this.hidingTimeout);
|
|
196
|
+
this.hidingTimeout = null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const basicOptions = {
|
|
200
|
+
placement: 'bottom',
|
|
201
|
+
marginTop: 0,
|
|
202
|
+
marginLeft: 0,
|
|
203
|
+
marginRight: 0,
|
|
204
|
+
marginBottom: 0,
|
|
205
|
+
delay: 70,
|
|
206
|
+
hidingDelay: 0,
|
|
207
|
+
};
|
|
208
|
+
const showingOptions = Object.assign(basicOptions, options);
|
|
209
|
+
|
|
210
|
+
if (showingOptions.hidingDelay) {
|
|
211
|
+
this.hidingDelay = showingOptions.hidingDelay;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!this.nodes.content) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.nodes.content.innerHTML = '';
|
|
219
|
+
this.nodes.content.appendChild(this.createContentNode(content));
|
|
220
|
+
|
|
221
|
+
if (!this.nodes.wrapper) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Flatten the placement classes (each can be a string or array) before removing
|
|
226
|
+
const placementClasses = Object.values(this.CSS.placement).flatMap(cls => Array.isArray(cls) ? cls : [cls]);
|
|
227
|
+
|
|
228
|
+
this.nodes.wrapper.classList.remove(...placementClasses);
|
|
229
|
+
|
|
230
|
+
switch (showingOptions.placement) {
|
|
231
|
+
case 'top':
|
|
232
|
+
this.placeTop(element, showingOptions);
|
|
233
|
+
break;
|
|
234
|
+
|
|
235
|
+
case 'left':
|
|
236
|
+
this.placeLeft(element, showingOptions);
|
|
237
|
+
break;
|
|
238
|
+
|
|
239
|
+
case 'right':
|
|
240
|
+
this.placeRight(element, showingOptions);
|
|
241
|
+
break;
|
|
242
|
+
|
|
243
|
+
case 'bottom':
|
|
244
|
+
default:
|
|
245
|
+
this.placeBottom(element, showingOptions);
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (showingOptions && showingOptions.delay) {
|
|
250
|
+
this.showingTimeout = setTimeout(() => {
|
|
251
|
+
if (this.nodes.wrapper) {
|
|
252
|
+
const classes = Array.isArray(this.CSS.tooltipShown) ? this.CSS.tooltipShown : [this.CSS.tooltipShown];
|
|
253
|
+
|
|
254
|
+
this.nodes.wrapper.classList.add(...classes);
|
|
255
|
+
this.updateTooltipVisibility();
|
|
256
|
+
}
|
|
257
|
+
this.showed = true;
|
|
258
|
+
}, showingOptions.delay);
|
|
259
|
+
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (this.nodes.wrapper) {
|
|
264
|
+
const classes = Array.isArray(this.CSS.tooltipShown) ? this.CSS.tooltipShown : [this.CSS.tooltipShown];
|
|
265
|
+
|
|
266
|
+
this.nodes.wrapper.classList.add(...classes);
|
|
267
|
+
this.updateTooltipVisibility();
|
|
268
|
+
}
|
|
269
|
+
this.showed = true;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Prepare tooltip content node
|
|
274
|
+
* @param {TooltipContent} content - tooltip content (Node or string)
|
|
275
|
+
*/
|
|
276
|
+
private createContentNode(content: TooltipContent): Node {
|
|
277
|
+
if (typeof content === 'string') {
|
|
278
|
+
return document.createTextNode(content);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (content instanceof Node) {
|
|
282
|
+
return content;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
throw Error('[Blok Tooltip] Wrong type of «content» passed. It should be an instance of Node or String. ' +
|
|
286
|
+
'But ' + typeof content + ' given.');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Hide toolbox tooltip and clean content
|
|
291
|
+
* @param {boolean} skipDelay - forces hiding immediately
|
|
292
|
+
*/
|
|
293
|
+
public hide(skipDelay: boolean = false): void {
|
|
294
|
+
const shouldDelay = Boolean(this.hidingDelay) && !skipDelay;
|
|
295
|
+
|
|
296
|
+
if (shouldDelay && this.hidingTimeout) {
|
|
297
|
+
clearTimeout(this.hidingTimeout);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (shouldDelay) {
|
|
301
|
+
this.hidingTimeout = setTimeout(() => {
|
|
302
|
+
this.hide(true);
|
|
303
|
+
}, this.hidingDelay);
|
|
304
|
+
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (this.nodes.wrapper) {
|
|
309
|
+
const classes = Array.isArray(this.CSS.tooltipShown) ? this.CSS.tooltipShown : [this.CSS.tooltipShown];
|
|
310
|
+
|
|
311
|
+
this.nodes.wrapper.classList.remove(...classes);
|
|
312
|
+
this.updateTooltipVisibility();
|
|
313
|
+
}
|
|
314
|
+
this.showed = false;
|
|
315
|
+
|
|
316
|
+
if (this.showingTimeout) {
|
|
317
|
+
clearTimeout(this.showingTimeout);
|
|
318
|
+
this.showingTimeout = null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Mouseover/Mouseleave decorator
|
|
324
|
+
* @param {HTMLElement} element - target element to place Tooltip near that
|
|
325
|
+
* @param {TooltipContent} content — any HTML Element of String that will be used as content
|
|
326
|
+
* @param {TooltipOptions} options — Available options {@link TooltipOptions}
|
|
327
|
+
*/
|
|
328
|
+
public onHover(element: HTMLElement, content: TooltipContent, options: TooltipOptions = {}): void {
|
|
329
|
+
element.addEventListener('mouseenter', () => {
|
|
330
|
+
/**
|
|
331
|
+
* Don't show tooltip if any Popover is currently open,
|
|
332
|
+
* unless the element is inside the open popover (e.g., inline toolbar items)
|
|
333
|
+
* This prevents tooltips from appearing over open menus while still allowing
|
|
334
|
+
* tooltips on items within the popover itself
|
|
335
|
+
*/
|
|
336
|
+
const openedPopover = document.querySelector('[data-blok-popover-opened="true"]');
|
|
337
|
+
|
|
338
|
+
if (openedPopover !== null && !openedPopover.contains(element)) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
this.show(element, content, options);
|
|
343
|
+
});
|
|
344
|
+
element.addEventListener('mouseleave', () => {
|
|
345
|
+
this.hide();
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Release DOM and event listeners
|
|
351
|
+
*/
|
|
352
|
+
public destroy(): void {
|
|
353
|
+
this.ariaObserver?.disconnect();
|
|
354
|
+
this.ariaObserver = null;
|
|
355
|
+
|
|
356
|
+
if (this.nodes.wrapper) {
|
|
357
|
+
this.nodes.wrapper.remove();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
window.removeEventListener('scroll', this.handleWindowScroll);
|
|
361
|
+
|
|
362
|
+
Tooltip.instance = null;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Hide tooltip when page is scrolled
|
|
367
|
+
*/
|
|
368
|
+
private handleWindowScroll = (): void => {
|
|
369
|
+
if (this.showed) {
|
|
370
|
+
this.hide(true);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Module Preparation method
|
|
376
|
+
*/
|
|
377
|
+
private prepare(): void {
|
|
378
|
+
this.nodes.wrapper = this.make('div', this.CSS.tooltip);
|
|
379
|
+
this.nodes.wrapper.setAttribute(DATA_ATTR.interface, TOOLTIP_INTERFACE_VALUE);
|
|
380
|
+
this.nodes.wrapper.setAttribute('data-blok-testid', 'tooltip');
|
|
381
|
+
this.nodes.content = this.make('div', this.CSS.tooltipContent);
|
|
382
|
+
this.nodes.content.setAttribute('data-blok-testid', 'tooltip-content');
|
|
383
|
+
|
|
384
|
+
if (this.nodes.wrapper && this.nodes.content) {
|
|
385
|
+
this.append(this.nodes.wrapper, this.nodes.content);
|
|
386
|
+
this.append(document.body, this.nodes.wrapper);
|
|
387
|
+
this.ensureTooltipAttributes();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Update tooltip visibility based on shown state
|
|
393
|
+
*/
|
|
394
|
+
private updateTooltipVisibility(): void {
|
|
395
|
+
if (!this.nodes.wrapper) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const shownClass = Array.isArray(this.CSS.tooltipShown) ? this.CSS.tooltipShown[0] : this.CSS.tooltipShown;
|
|
400
|
+
const isShown = this.nodes.wrapper.classList.contains(shownClass);
|
|
401
|
+
|
|
402
|
+
this.nodes.wrapper.style.setProperty(VISIBILITY_PROPERTY, isShown ? VISIBILITY_VISIBLE : VISIBILITY_HIDDEN);
|
|
403
|
+
this.nodes.wrapper.setAttribute(ARIA_HIDDEN_ATTRIBUTE, isShown ? ARIA_HIDDEN_FALSE : ARIA_HIDDEN_TRUE);
|
|
404
|
+
this.nodes.wrapper.setAttribute('data-blok-shown', isShown ? 'true' : 'false');
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Watch tooltip visibility changes for accessibility
|
|
409
|
+
*/
|
|
410
|
+
private watchTooltipVisibility(): void {
|
|
411
|
+
if (!this.nodes.wrapper) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
this.ariaObserver?.disconnect();
|
|
416
|
+
|
|
417
|
+
this.updateTooltipVisibility();
|
|
418
|
+
|
|
419
|
+
this.ariaObserver = new MutationObserver(() => {
|
|
420
|
+
this.updateTooltipVisibility();
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
this.ariaObserver.observe(this.nodes.wrapper, {
|
|
424
|
+
attributes: true,
|
|
425
|
+
attributeFilter: [ 'class' ],
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Ensure tooltip has proper accessibility attributes
|
|
431
|
+
*/
|
|
432
|
+
private ensureTooltipAttributes(): void {
|
|
433
|
+
if (!this.nodes.wrapper) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (!this.nodes.wrapper.hasAttribute(DATA_ATTR.interface) || this.nodes.wrapper.getAttribute(DATA_ATTR.interface) !== TOOLTIP_INTERFACE_VALUE) {
|
|
438
|
+
this.nodes.wrapper.setAttribute(DATA_ATTR.interface, TOOLTIP_INTERFACE_VALUE);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
this.nodes.wrapper.setAttribute('role', TOOLTIP_ROLE);
|
|
442
|
+
this.watchTooltipVisibility();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Calculates element coords and moves tooltip bottom of the element
|
|
449
|
+
* @param {HTMLElement} element - target element
|
|
450
|
+
* @param {TooltipOptions} showingOptions - placement options
|
|
451
|
+
*/
|
|
452
|
+
private placeBottom(element: HTMLElement, showingOptions: TooltipOptions): void {
|
|
453
|
+
if (!this.nodes.wrapper) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const elementCoords = element.getBoundingClientRect();
|
|
458
|
+
const left = elementCoords.left + element.clientWidth / 2 - this.nodes.wrapper.offsetWidth / 2;
|
|
459
|
+
const top = elementCoords.bottom + this.getScrollTop() + this.offsetTop + (showingOptions.marginTop ?? 0);
|
|
460
|
+
|
|
461
|
+
this.applyPlacement('bottom', left, top);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Calculates element coords and moves tooltip top of the element
|
|
466
|
+
* @param {HTMLElement} element - target element
|
|
467
|
+
* @param {TooltipOptions} _showingOptions - placement options (unused for top placement)
|
|
468
|
+
*/
|
|
469
|
+
private placeTop(element: HTMLElement, _showingOptions: TooltipOptions): void {
|
|
470
|
+
if (!this.nodes.wrapper) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const elementCoords = element.getBoundingClientRect();
|
|
475
|
+
const left = elementCoords.left + element.clientWidth / 2 - this.nodes.wrapper.offsetWidth / 2;
|
|
476
|
+
const top = elementCoords.top + this.getScrollTop() - this.nodes.wrapper.clientHeight - this.offsetTop;
|
|
477
|
+
|
|
478
|
+
this.applyPlacement('top', left, top);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Calculates element coords and moves tooltip left of the element
|
|
483
|
+
* @param {HTMLElement} element - target element
|
|
484
|
+
* @param {TooltipOptions} showingOptions - placement options
|
|
485
|
+
*/
|
|
486
|
+
private placeLeft(element: HTMLElement, showingOptions: TooltipOptions): void {
|
|
487
|
+
if (!this.nodes.wrapper) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const elementCoords = element.getBoundingClientRect();
|
|
492
|
+
const left = elementCoords.left - this.nodes.wrapper.offsetWidth - this.offsetLeft - (showingOptions.marginLeft ?? 0);
|
|
493
|
+
const top = elementCoords.top + this.getScrollTop() + element.clientHeight / 2 - this.nodes.wrapper.offsetHeight / 2;
|
|
494
|
+
|
|
495
|
+
this.applyPlacement('left', left, top);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Calculates element coords and moves tooltip right of the element
|
|
500
|
+
* @param {HTMLElement} element - target element
|
|
501
|
+
* @param {TooltipOptions} showingOptions - placement options
|
|
502
|
+
*/
|
|
503
|
+
private placeRight(element: HTMLElement, showingOptions: TooltipOptions): void {
|
|
504
|
+
if (!this.nodes.wrapper) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const elementCoords = element.getBoundingClientRect();
|
|
509
|
+
const left = elementCoords.right + this.offsetRight + (showingOptions.marginRight ?? 0);
|
|
510
|
+
const top = elementCoords.top + this.getScrollTop() + element.clientHeight / 2 - this.nodes.wrapper.offsetHeight / 2;
|
|
511
|
+
|
|
512
|
+
this.applyPlacement('right', left, top);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Set wrapper position
|
|
517
|
+
* @param {string} place - placement direction
|
|
518
|
+
* @param {number} left - left position in pixels
|
|
519
|
+
* @param {number} top - top position in pixels
|
|
520
|
+
*/
|
|
521
|
+
private applyPlacement(place: 'top' | 'bottom' | 'left' | 'right', left: number, top: number): void {
|
|
522
|
+
if (!this.nodes.wrapper) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const classes = Array.isArray(this.CSS.placement[place]) ? this.CSS.placement[place] : [this.CSS.placement[place]];
|
|
527
|
+
|
|
528
|
+
this.nodes.wrapper.classList.add(...classes);
|
|
529
|
+
this.nodes.wrapper.setAttribute('data-blok-placement', place);
|
|
530
|
+
|
|
531
|
+
this.nodes.wrapper.style.left = `${left}px`;
|
|
532
|
+
this.nodes.wrapper.style.top = `${top}px`;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Get current page vertical scroll offset
|
|
537
|
+
*/
|
|
538
|
+
private getScrollTop(): number {
|
|
539
|
+
if (typeof window.scrollY === 'number') {
|
|
540
|
+
return window.scrollY;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return document.documentElement?.scrollTop ?? document.body.scrollTop ?? 0;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Helper for making Elements with classname and attributes
|
|
548
|
+
* @param {string} tagName - new Element tag name
|
|
549
|
+
* @param {Array<string>|string} classNames - list or name of CSS classname(s)
|
|
550
|
+
* @param {object} attributes - any attributes
|
|
551
|
+
* @returns {HTMLElement}
|
|
552
|
+
*/
|
|
553
|
+
private make(tagName: string, classNames: string | string[] | null = null, attributes: Record<string, unknown> = {}): HTMLElement {
|
|
554
|
+
const el = document.createElement(tagName);
|
|
555
|
+
|
|
556
|
+
if (Array.isArray(classNames)) {
|
|
557
|
+
el.classList.add(...classNames);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (typeof classNames === 'string') {
|
|
561
|
+
el.classList.add(classNames);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
for (const attrName in attributes) {
|
|
565
|
+
if (Object.prototype.hasOwnProperty.call(attributes, attrName)) {
|
|
566
|
+
(el as unknown as Record<string, unknown>)[attrName] = attributes[attrName];
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return el;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Append one or several elements to the parent
|
|
575
|
+
* @param {Element|DocumentFragment} parent - where to append
|
|
576
|
+
* @param {Element|Element[]} elements - element or elements list
|
|
577
|
+
*/
|
|
578
|
+
private append(parent: Element | DocumentFragment, elements: Element | Element[] | DocumentFragment): void {
|
|
579
|
+
if (Array.isArray(elements)) {
|
|
580
|
+
elements.forEach((el) => parent.appendChild(el));
|
|
581
|
+
} else {
|
|
582
|
+
parent.appendChild(elements);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Append element or a couple to the beginning of the parent elements
|
|
588
|
+
* @param {Element} parent - where to append
|
|
589
|
+
* @param {Element|Element[]} elements - element or elements list
|
|
590
|
+
*/
|
|
591
|
+
private prepend(parent: Element, elements: Element | Element[]): void {
|
|
592
|
+
if (Array.isArray(elements)) {
|
|
593
|
+
const reversed = elements.reverse();
|
|
594
|
+
|
|
595
|
+
reversed.forEach((el) => parent.prepend(el));
|
|
596
|
+
} else {
|
|
597
|
+
parent.prepend(elements);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Get singleton tooltip instance
|
|
604
|
+
*/
|
|
605
|
+
const getTooltip = (): Tooltip => {
|
|
606
|
+
return Tooltip.getInstance();
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Show tooltip near element with specified content
|
|
611
|
+
* @param {HTMLElement} element - target element to place tooltip near
|
|
612
|
+
* @param {TooltipContent} content - tooltip content
|
|
613
|
+
* @param {TooltipOptions} options - tooltip options
|
|
614
|
+
*/
|
|
615
|
+
export const show = (element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void => {
|
|
616
|
+
getTooltip().show(element, content, options ?? {});
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Hide tooltip
|
|
621
|
+
* @param {boolean} skipHidingDelay - forces hiding immediately
|
|
622
|
+
*/
|
|
623
|
+
export const hide = (skipHidingDelay = false): void => {
|
|
624
|
+
getTooltip().hide(skipHidingDelay);
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Show tooltip on hover (mouseenter/mouseleave)
|
|
629
|
+
* @param {HTMLElement} element - target element to place tooltip near
|
|
630
|
+
* @param {TooltipContent} content - tooltip content
|
|
631
|
+
* @param {TooltipOptions} options - tooltip options
|
|
632
|
+
*/
|
|
633
|
+
export const onHover = (element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void => {
|
|
634
|
+
getTooltip().onHover(element, content, options ?? {});
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Destroy tooltip instance and clean up
|
|
639
|
+
*/
|
|
640
|
+
export const destroy = (): void => {
|
|
641
|
+
getTooltip().destroy();
|
|
642
|
+
};
|