@jackuait/blok 0.4.1 → 0.4.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -17
- package/codemod/README.md +45 -7
- package/codemod/migrate-editorjs-to-blok.js +951 -92
- package/codemod/test.js +780 -77
- package/dist/blok.mjs +5 -2
- package/dist/chunks/blok-8ptWuVZC.mjs +12838 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-bLawSYRV.mjs +43 -0
- package/dist/{index-CBkApZKo.mjs → chunks/index-5nYtWZD2.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-CvMDAIzb.mjs +1988 -0
- package/dist/chunks/messages-2434tVOK.mjs +47 -0
- package/dist/chunks/messages-3DcCwXMF.mjs +47 -0
- package/dist/chunks/messages-4kMwVAKY.mjs +47 -0
- package/dist/chunks/messages-57uL5htT.mjs +47 -0
- package/dist/chunks/messages-76-iJV9Q.mjs +47 -0
- package/dist/chunks/messages-8p86Eyf2.mjs +47 -0
- package/dist/chunks/messages-BBX0p0Pi.mjs +47 -0
- package/dist/chunks/messages-BCm2eudQ.mjs +47 -0
- package/dist/chunks/messages-BFiUomgG.mjs +47 -0
- package/dist/chunks/messages-BIPNHHAV.mjs +47 -0
- package/dist/chunks/messages-BUlwu9mo.mjs +47 -0
- package/dist/chunks/messages-BX-DPa-z.mjs +47 -0
- package/dist/chunks/messages-BextV3Qh.mjs +47 -0
- package/dist/chunks/messages-BiPSFlUG.mjs +47 -0
- package/dist/chunks/messages-BiXe9G-O.mjs +47 -0
- package/dist/chunks/messages-Bl5z_Igo.mjs +47 -0
- package/dist/chunks/messages-BnsE97ku.mjs +47 -0
- package/dist/chunks/messages-BoO8gsVD.mjs +47 -0
- package/dist/chunks/messages-BqWaOGMn.mjs +47 -0
- package/dist/chunks/messages-BqkL2_Ro.mjs +47 -0
- package/dist/chunks/messages-BvCkXKX-.mjs +47 -0
- package/dist/chunks/messages-C6tbPLoj.mjs +47 -0
- package/dist/chunks/messages-CA6T3-gQ.mjs +47 -0
- package/dist/chunks/messages-CFFPFdWP.mjs +47 -0
- package/dist/chunks/messages-CFrKE-TN.mjs +47 -0
- package/dist/chunks/messages-CHz8VlG-.mjs +47 -0
- package/dist/chunks/messages-CLixzySl.mjs +47 -0
- package/dist/chunks/messages-CV7OM_qk.mjs +47 -0
- package/dist/chunks/messages-CXHt3eCC.mjs +47 -0
- package/dist/chunks/messages-CbmsBrB0.mjs +47 -0
- package/dist/chunks/messages-Ceo1KtFx.mjs +47 -0
- package/dist/chunks/messages-Cm0LJLtB.mjs +47 -0
- package/dist/chunks/messages-CmymP_Ar.mjs +47 -0
- package/dist/chunks/messages-D0ohMB5H.mjs +47 -0
- package/dist/chunks/messages-D3GrDwXh.mjs +47 -0
- package/dist/chunks/messages-D3vTzIpL.mjs +47 -0
- package/dist/chunks/messages-D5WeksbV.mjs +47 -0
- package/dist/chunks/messages-DGaab4EP.mjs +47 -0
- package/dist/chunks/messages-DKha57ZU.mjs +47 -0
- package/dist/chunks/messages-DOaujgMW.mjs +47 -0
- package/dist/chunks/messages-DVbPLd_0.mjs +47 -0
- package/dist/chunks/messages-D_FCyfW6.mjs +47 -0
- package/dist/chunks/messages-Dd5iZN3c.mjs +47 -0
- package/dist/chunks/messages-DehM7135.mjs +47 -0
- package/dist/chunks/messages-Dg1OHftD.mjs +47 -0
- package/dist/chunks/messages-Di6Flq-b.mjs +47 -0
- package/dist/chunks/messages-Dqhhex6e.mjs +47 -0
- package/dist/chunks/messages-DueVe0F1.mjs +47 -0
- package/dist/chunks/messages-Dx3eFwI0.mjs +47 -0
- package/dist/chunks/messages-FOtiUoKl.mjs +47 -0
- package/dist/chunks/messages-FTOZNhRD.mjs +47 -0
- package/dist/chunks/messages-IQxGfQIV.mjs +47 -0
- package/dist/chunks/messages-JF2fzCkK.mjs +47 -0
- package/dist/chunks/messages-MOGl7I5v.mjs +47 -0
- package/dist/chunks/messages-QgYhPL-3.mjs +47 -0
- package/dist/chunks/messages-WYWIbQwo.mjs +47 -0
- package/dist/chunks/messages-a6A_LgDv.mjs +47 -0
- package/dist/chunks/messages-bSf31LJi.mjs +47 -0
- package/dist/chunks/messages-diGozhTn.mjs +47 -0
- package/dist/chunks/messages-er-kd-VO.mjs +47 -0
- package/dist/chunks/messages-ez3w5NBn.mjs +47 -0
- package/dist/chunks/messages-f3uXjegd.mjs +47 -0
- package/dist/chunks/messages-ohwI1UGv.mjs +47 -0
- package/dist/chunks/messages-p9BZJaFV.mjs +47 -0
- package/dist/chunks/messages-qIQ4L4rw.mjs +47 -0
- package/dist/chunks/messages-qWkXPggi.mjs +47 -0
- package/dist/chunks/messages-w5foGze_.mjs +47 -0
- package/dist/full.mjs +50 -0
- package/dist/locales.mjs +227 -0
- package/dist/messages-2434tVOK.mjs +47 -0
- package/dist/messages-3DcCwXMF.mjs +47 -0
- package/dist/messages-4kMwVAKY.mjs +47 -0
- package/dist/messages-57uL5htT.mjs +47 -0
- package/dist/messages-76-iJV9Q.mjs +47 -0
- package/dist/messages-8p86Eyf2.mjs +47 -0
- package/dist/messages-BBX0p0Pi.mjs +47 -0
- package/dist/messages-BCm2eudQ.mjs +47 -0
- package/dist/messages-BFiUomgG.mjs +47 -0
- package/dist/messages-BIPNHHAV.mjs +47 -0
- package/dist/messages-BUlwu9mo.mjs +47 -0
- package/dist/messages-BX-DPa-z.mjs +47 -0
- package/dist/messages-BextV3Qh.mjs +47 -0
- package/dist/messages-BiPSFlUG.mjs +47 -0
- package/dist/messages-BiXe9G-O.mjs +47 -0
- package/dist/messages-Bl5z_Igo.mjs +47 -0
- package/dist/messages-BnsE97ku.mjs +47 -0
- package/dist/messages-BoO8gsVD.mjs +47 -0
- package/dist/messages-BqWaOGMn.mjs +47 -0
- package/dist/messages-BqkL2_Ro.mjs +47 -0
- package/dist/messages-BvCkXKX-.mjs +47 -0
- package/dist/messages-C6tbPLoj.mjs +47 -0
- package/dist/messages-CA6T3-gQ.mjs +47 -0
- package/dist/messages-CFFPFdWP.mjs +47 -0
- package/dist/messages-CFrKE-TN.mjs +47 -0
- package/dist/messages-CHz8VlG-.mjs +47 -0
- package/dist/messages-CLixzySl.mjs +47 -0
- package/dist/messages-CV7OM_qk.mjs +47 -0
- package/dist/messages-CXHt3eCC.mjs +47 -0
- package/dist/messages-CbmsBrB0.mjs +47 -0
- package/dist/messages-Ceo1KtFx.mjs +47 -0
- package/dist/messages-Cm0LJLtB.mjs +47 -0
- package/dist/messages-CmymP_Ar.mjs +47 -0
- package/dist/messages-D0ohMB5H.mjs +47 -0
- package/dist/messages-D3GrDwXh.mjs +47 -0
- package/dist/messages-D3vTzIpL.mjs +47 -0
- package/dist/messages-D5WeksbV.mjs +47 -0
- package/dist/messages-DGaab4EP.mjs +47 -0
- package/dist/messages-DKha57ZU.mjs +47 -0
- package/dist/messages-DOaujgMW.mjs +47 -0
- package/dist/messages-DVbPLd_0.mjs +47 -0
- package/dist/messages-D_FCyfW6.mjs +47 -0
- package/dist/messages-Dd5iZN3c.mjs +47 -0
- package/dist/messages-DehM7135.mjs +47 -0
- package/dist/messages-Dg1OHftD.mjs +47 -0
- package/dist/messages-Di6Flq-b.mjs +47 -0
- package/dist/messages-Dqhhex6e.mjs +47 -0
- package/dist/messages-DueVe0F1.mjs +47 -0
- package/dist/messages-Dx3eFwI0.mjs +47 -0
- package/dist/messages-FOtiUoKl.mjs +47 -0
- package/dist/messages-FTOZNhRD.mjs +47 -0
- package/dist/messages-IQxGfQIV.mjs +47 -0
- package/dist/messages-JF2fzCkK.mjs +47 -0
- package/dist/messages-MOGl7I5v.mjs +47 -0
- package/dist/messages-QgYhPL-3.mjs +47 -0
- package/dist/messages-WYWIbQwo.mjs +47 -0
- package/dist/messages-a6A_LgDv.mjs +47 -0
- package/dist/messages-bSf31LJi.mjs +47 -0
- package/dist/messages-diGozhTn.mjs +47 -0
- package/dist/messages-er-kd-VO.mjs +47 -0
- package/dist/messages-ez3w5NBn.mjs +47 -0
- package/dist/messages-f3uXjegd.mjs +47 -0
- package/dist/messages-ohwI1UGv.mjs +47 -0
- package/dist/messages-p9BZJaFV.mjs +47 -0
- package/dist/messages-qIQ4L4rw.mjs +47 -0
- package/dist/messages-qWkXPggi.mjs +47 -0
- package/dist/messages-w5foGze_.mjs +47 -0
- package/dist/tools.mjs +3073 -0
- package/dist/vendor.LICENSE.txt +59 -156
- package/package.json +60 -15
- package/src/blok.ts +267 -0
- package/src/components/__module.ts +139 -0
- package/src/components/block/api.ts +155 -0
- package/src/components/block/index.ts +1427 -0
- package/src/components/block-tunes/block-tune-delete.ts +51 -0
- package/src/components/blocks.ts +338 -0
- package/src/components/constants/data-attributes.ts +342 -0
- package/src/components/constants.ts +76 -0
- package/src/components/core.ts +392 -0
- package/src/components/dom.ts +773 -0
- package/src/components/domIterator.ts +189 -0
- package/src/components/errors/critical.ts +5 -0
- package/src/components/events/BlockChanged.ts +16 -0
- package/src/components/events/BlockHovered.ts +21 -0
- package/src/components/events/BlockSettingsClosed.ts +12 -0
- package/src/components/events/BlockSettingsOpened.ts +12 -0
- package/src/components/events/BlokMobileLayoutToggled.ts +15 -0
- package/src/components/events/FakeCursorAboutToBeToggled.ts +17 -0
- package/src/components/events/FakeCursorHaveBeenSet.ts +17 -0
- package/src/components/events/HistoryStateChanged.ts +19 -0
- package/src/components/events/RedactorDomChanged.ts +14 -0
- package/src/components/events/index.ts +46 -0
- package/src/components/flipper.ts +481 -0
- package/src/components/i18n/i18next-loader.ts +84 -0
- package/src/components/i18n/lightweight-i18n.ts +86 -0
- package/src/components/i18n/locales/TRANSLATION_GUIDELINES.md +113 -0
- package/src/components/i18n/locales/am/messages.json +44 -0
- package/src/components/i18n/locales/ar/messages.json +44 -0
- package/src/components/i18n/locales/az/messages.json +44 -0
- package/src/components/i18n/locales/bg/messages.json +44 -0
- package/src/components/i18n/locales/bn/messages.json +44 -0
- package/src/components/i18n/locales/bs/messages.json +44 -0
- package/src/components/i18n/locales/cs/messages.json +44 -0
- package/src/components/i18n/locales/da/messages.json +44 -0
- package/src/components/i18n/locales/de/messages.json +44 -0
- package/src/components/i18n/locales/dv/messages.json +44 -0
- package/src/components/i18n/locales/el/messages.json +44 -0
- package/src/components/i18n/locales/en/messages.json +44 -0
- package/src/components/i18n/locales/es/messages.json +44 -0
- package/src/components/i18n/locales/et/messages.json +44 -0
- package/src/components/i18n/locales/fa/messages.json +44 -0
- package/src/components/i18n/locales/fi/messages.json +44 -0
- package/src/components/i18n/locales/fil/messages.json +44 -0
- package/src/components/i18n/locales/fr/messages.json +44 -0
- package/src/components/i18n/locales/gu/messages.json +44 -0
- package/src/components/i18n/locales/he/messages.json +44 -0
- package/src/components/i18n/locales/hi/messages.json +44 -0
- package/src/components/i18n/locales/hr/messages.json +44 -0
- package/src/components/i18n/locales/hu/messages.json +44 -0
- package/src/components/i18n/locales/hy/messages.json +44 -0
- package/src/components/i18n/locales/id/messages.json +44 -0
- package/src/components/i18n/locales/index.ts +225 -0
- package/src/components/i18n/locales/it/messages.json +44 -0
- package/src/components/i18n/locales/ja/messages.json +44 -0
- package/src/components/i18n/locales/ka/messages.json +44 -0
- package/src/components/i18n/locales/km/messages.json +44 -0
- package/src/components/i18n/locales/kn/messages.json +44 -0
- package/src/components/i18n/locales/ko/messages.json +44 -0
- package/src/components/i18n/locales/ku/messages.json +44 -0
- package/src/components/i18n/locales/lo/messages.json +44 -0
- package/src/components/i18n/locales/lt/messages.json +44 -0
- package/src/components/i18n/locales/lv/messages.json +44 -0
- package/src/components/i18n/locales/mk/messages.json +44 -0
- package/src/components/i18n/locales/ml/messages.json +44 -0
- package/src/components/i18n/locales/mn/messages.json +44 -0
- package/src/components/i18n/locales/mr/messages.json +44 -0
- package/src/components/i18n/locales/ms/messages.json +44 -0
- package/src/components/i18n/locales/my/messages.json +44 -0
- package/src/components/i18n/locales/ne/messages.json +44 -0
- package/src/components/i18n/locales/nl/messages.json +44 -0
- package/src/components/i18n/locales/no/messages.json +44 -0
- package/src/components/i18n/locales/pa/messages.json +44 -0
- package/src/components/i18n/locales/pl/messages.json +44 -0
- package/src/components/i18n/locales/ps/messages.json +44 -0
- package/src/components/i18n/locales/pt/messages.json +44 -0
- package/src/components/i18n/locales/ro/messages.json +44 -0
- package/src/components/i18n/locales/ru/messages.json +44 -0
- package/src/components/i18n/locales/sd/messages.json +44 -0
- package/src/components/i18n/locales/si/messages.json +44 -0
- package/src/components/i18n/locales/sk/messages.json +44 -0
- package/src/components/i18n/locales/sl/messages.json +44 -0
- package/src/components/i18n/locales/sq/messages.json +44 -0
- package/src/components/i18n/locales/sr/messages.json +44 -0
- package/src/components/i18n/locales/sv/messages.json +44 -0
- package/src/components/i18n/locales/sw/messages.json +44 -0
- package/src/components/i18n/locales/ta/messages.json +44 -0
- package/src/components/i18n/locales/te/messages.json +44 -0
- package/src/components/i18n/locales/th/messages.json +44 -0
- package/src/components/i18n/locales/tr/messages.json +44 -0
- package/src/components/i18n/locales/ug/messages.json +44 -0
- package/src/components/i18n/locales/uk/messages.json +44 -0
- package/src/components/i18n/locales/ur/messages.json +44 -0
- package/src/components/i18n/locales/vi/messages.json +44 -0
- package/src/components/i18n/locales/yi/messages.json +44 -0
- package/src/components/i18n/locales/zh/messages.json +44 -0
- package/src/components/icons/index.ts +242 -0
- package/src/components/inline-tools/inline-tool-bold.ts +2213 -0
- package/src/components/inline-tools/inline-tool-convert.ts +141 -0
- package/src/components/inline-tools/inline-tool-italic.ts +500 -0
- package/src/components/inline-tools/inline-tool-link.ts +539 -0
- package/src/components/modules/api/blocks.ts +363 -0
- package/src/components/modules/api/caret.ts +125 -0
- package/src/components/modules/api/events.ts +51 -0
- package/src/components/modules/api/history.ts +73 -0
- package/src/components/modules/api/i18n.ts +33 -0
- package/src/components/modules/api/index.ts +39 -0
- package/src/components/modules/api/inlineToolbar.ts +33 -0
- package/src/components/modules/api/listeners.ts +56 -0
- package/src/components/modules/api/notifier.ts +46 -0
- package/src/components/modules/api/readonly.ts +39 -0
- package/src/components/modules/api/sanitizer.ts +30 -0
- package/src/components/modules/api/saver.ts +52 -0
- package/src/components/modules/api/selection.ts +48 -0
- package/src/components/modules/api/styles.ts +72 -0
- package/src/components/modules/api/toolbar.ts +79 -0
- package/src/components/modules/api/tools.ts +16 -0
- package/src/components/modules/api/tooltip.ts +67 -0
- package/src/components/modules/api/ui.ts +36 -0
- package/src/components/modules/blockEvents.ts +1375 -0
- package/src/components/modules/blockManager.ts +1348 -0
- package/src/components/modules/blockSelection.ts +708 -0
- package/src/components/modules/caret.ts +853 -0
- package/src/components/modules/crossBlockSelection.ts +329 -0
- package/src/components/modules/dragManager.ts +1141 -0
- package/src/components/modules/history.ts +1098 -0
- package/src/components/modules/i18n.ts +325 -0
- package/src/components/modules/index.ts +139 -0
- package/src/components/modules/modificationsObserver.ts +147 -0
- package/src/components/modules/paste.ts +1092 -0
- package/src/components/modules/readonly.ts +136 -0
- package/src/components/modules/rectangleSelection.ts +668 -0
- package/src/components/modules/renderer.ts +155 -0
- package/src/components/modules/saver.ts +283 -0
- package/src/components/modules/toolbar/blockSettings.ts +776 -0
- package/src/components/modules/toolbar/index.ts +1311 -0
- package/src/components/modules/toolbar/inline.ts +956 -0
- package/src/components/modules/tools.ts +589 -0
- package/src/components/modules/ui.ts +1179 -0
- package/src/components/polyfills.ts +113 -0
- package/src/components/selection.ts +1189 -0
- package/src/components/tools/base.ts +274 -0
- package/src/components/tools/block.ts +291 -0
- package/src/components/tools/collection.ts +67 -0
- package/src/components/tools/factory.ts +85 -0
- package/src/components/tools/inline.ts +71 -0
- package/src/components/tools/tune.ts +33 -0
- package/src/components/ui/toolbox.ts +497 -0
- package/src/components/utils/announcer.ts +205 -0
- package/src/components/utils/api.ts +20 -0
- package/src/components/utils/bem.ts +26 -0
- package/src/components/utils/blocks.ts +284 -0
- package/src/components/utils/caret.ts +1067 -0
- package/src/components/utils/data-model-transform.ts +382 -0
- package/src/components/utils/events.ts +117 -0
- package/src/components/utils/keyboard.ts +60 -0
- package/src/components/utils/listeners.ts +296 -0
- package/src/components/utils/mutations.ts +39 -0
- package/src/components/utils/notifier/draw.ts +190 -0
- package/src/components/utils/notifier/index.ts +66 -0
- package/src/components/utils/notifier/types.ts +1 -0
- package/src/components/utils/notifier.ts +77 -0
- package/src/components/utils/placeholder.ts +140 -0
- package/src/components/utils/popover/components/hint/hint.const.ts +10 -0
- package/src/components/utils/popover/components/hint/hint.ts +46 -0
- package/src/components/utils/popover/components/hint/index.ts +6 -0
- package/src/components/utils/popover/components/popover-header/index.ts +2 -0
- package/src/components/utils/popover/components/popover-header/popover-header.const.ts +8 -0
- package/src/components/utils/popover/components/popover-header/popover-header.ts +80 -0
- package/src/components/utils/popover/components/popover-header/popover-header.types.ts +14 -0
- package/src/components/utils/popover/components/popover-item/index.ts +13 -0
- package/src/components/utils/popover/components/popover-item/popover-item-default/popover-item-default.const.ts +50 -0
- package/src/components/utils/popover/components/popover-item/popover-item-default/popover-item-default.ts +666 -0
- package/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.const.ts +14 -0
- package/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.ts +136 -0
- package/src/components/utils/popover/components/popover-item/popover-item-separator/popover-item-separator.const.ts +20 -0
- package/src/components/utils/popover/components/popover-item/popover-item-separator/popover-item-separator.ts +117 -0
- package/src/components/utils/popover/components/popover-item/popover-item.ts +187 -0
- package/src/components/utils/popover/components/search-input/index.ts +2 -0
- package/src/components/utils/popover/components/search-input/search-input.const.ts +8 -0
- package/src/components/utils/popover/components/search-input/search-input.ts +181 -0
- package/src/components/utils/popover/components/search-input/search-input.types.ts +30 -0
- package/src/components/utils/popover/index.ts +13 -0
- package/src/components/utils/popover/popover-abstract.ts +448 -0
- package/src/components/utils/popover/popover-desktop.ts +643 -0
- package/src/components/utils/popover/popover-inline.ts +338 -0
- package/src/components/utils/popover/popover-mobile.ts +201 -0
- package/src/components/utils/popover/popover.const.ts +81 -0
- package/src/components/utils/popover/utils/popover-states-history.ts +72 -0
- package/src/components/utils/promise-queue.ts +43 -0
- package/src/components/utils/sanitizer.ts +537 -0
- package/src/components/utils/scroll-locker.ts +87 -0
- package/src/components/utils/shortcut.ts +231 -0
- package/src/components/utils/shortcuts.ts +113 -0
- package/src/components/utils/tools.ts +105 -0
- package/src/components/utils/tooltip.ts +642 -0
- package/src/components/utils/tw.ts +241 -0
- package/src/components/utils.ts +1081 -0
- package/src/env.d.ts +13 -0
- package/src/full.ts +69 -0
- package/src/locales.ts +51 -0
- package/src/stories/Block.stories.ts +498 -0
- package/src/stories/EditorModes.stories.ts +505 -0
- package/src/stories/Header.stories.ts +137 -0
- package/src/stories/InlineToolbar.stories.ts +498 -0
- package/src/stories/List.stories.ts +259 -0
- package/src/stories/Notifier.stories.ts +340 -0
- package/src/stories/Paragraph.stories.ts +112 -0
- package/src/stories/Placeholder.stories.ts +319 -0
- package/src/stories/Popover.stories.ts +844 -0
- package/src/stories/Selection.stories.ts +250 -0
- package/src/stories/StubBlock.stories.ts +156 -0
- package/src/stories/Toolbar.stories.ts +223 -0
- package/src/stories/Toolbox.stories.ts +166 -0
- package/src/stories/Tooltip.stories.ts +198 -0
- package/src/stories/helpers.ts +463 -0
- package/src/styles/main.css +123 -0
- package/src/tools/header/index.ts +570 -0
- package/src/tools/index.ts +38 -0
- package/src/tools/list/index.ts +1803 -0
- package/src/tools/paragraph/index.ts +411 -0
- package/src/tools/stub/index.ts +107 -0
- package/src/types-internal/blok-modules.d.ts +87 -0
- package/src/types-internal/html-janitor.d.ts +28 -0
- package/src/types-internal/module-config.d.ts +11 -0
- package/src/variants/all-locales.ts +155 -0
- package/src/variants/blok-maximum.ts +20 -0
- package/src/variants/blok-minimum.ts +243 -0
- package/types/api/blocks.d.ts +1 -1
- package/types/api/i18n.d.ts +5 -3
- package/types/api/selection.d.ts +6 -0
- package/types/api/styles.d.ts +0 -5
- package/types/configs/blok-config.d.ts +21 -0
- package/types/configs/i18n-config.d.ts +52 -2
- package/types/configs/i18n-dictionary.d.ts +16 -90
- package/types/data-attributes.d.ts +169 -0
- package/types/data-formats/output-data.d.ts +15 -0
- package/types/full.d.ts +80 -0
- package/types/index.d.ts +9 -24
- package/types/locales.d.ts +59 -0
- package/types/tools/adapters/inline-tool-adapter.d.ts +10 -0
- package/types/tools/block-tool.d.ts +9 -0
- package/types/tools/list.d.ts +25 -18
- package/types/tools/tool-settings.d.ts +8 -1
- package/types/tools/tool.d.ts +6 -0
- package/types/tools-entry.d.ts +49 -0
- package/types/utils/popover/popover-item.d.ts +0 -5
- package/dist/blok-BwPfU8ro.mjs +0 -21510
- package/dist/blok.umd.js +0 -198
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PopoverItemDefaultParams,
|
|
3
|
+
PopoverItemRenderParamsMap,
|
|
4
|
+
PopoverItemType
|
|
5
|
+
} from '@/types/utils/popover/popover-item';
|
|
6
|
+
import { PopoverItem } from '../popover-item';
|
|
7
|
+
import { css, cssInline, cssNestedInline } from './popover-item-default.const';
|
|
8
|
+
import { DATA_ATTR } from '../../../../../constants/data-attributes';
|
|
9
|
+
import { twMerge } from '../../../../tw';
|
|
10
|
+
import { IconChevronRight } from '../../../../../icons';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represents single popover item node
|
|
14
|
+
* @todo replace multiple make() usages with constructing separate instances
|
|
15
|
+
* @todo split regular popover item and popover item with confirmation to separate classes
|
|
16
|
+
* @todo display icon on the right side of the item for rtl languages
|
|
17
|
+
*/
|
|
18
|
+
export class PopoverItemDefault extends PopoverItem {
|
|
19
|
+
/**
|
|
20
|
+
* True if item is disabled and hence not clickable
|
|
21
|
+
*/
|
|
22
|
+
public get isDisabled(): boolean {
|
|
23
|
+
return this.params.isDisabled === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Exposes popover item toggle parameter
|
|
28
|
+
*/
|
|
29
|
+
public get toggle(): boolean | string | undefined {
|
|
30
|
+
return this.params.toggle;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Item title
|
|
35
|
+
*/
|
|
36
|
+
public get title(): string | undefined {
|
|
37
|
+
return this.params.title;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* True if confirmation state is enabled for popover item
|
|
42
|
+
*/
|
|
43
|
+
public get isConfirmationStateEnabled(): boolean {
|
|
44
|
+
return this.confirmationState !== null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* True if item is focused in keyboard navigation process
|
|
49
|
+
*/
|
|
50
|
+
public get isFocused(): boolean {
|
|
51
|
+
if (this.nodes.root === null) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return this.nodes.root.hasAttribute(DATA_ATTR.focused);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Item html elements
|
|
61
|
+
*/
|
|
62
|
+
private nodes: {
|
|
63
|
+
root: null | HTMLElement;
|
|
64
|
+
icon: null | HTMLElement;
|
|
65
|
+
titleEl: null | HTMLElement;
|
|
66
|
+
secondaryLabelEl: null | HTMLElement;
|
|
67
|
+
chevron: null | HTMLElement;
|
|
68
|
+
} = {
|
|
69
|
+
root: null,
|
|
70
|
+
icon: null,
|
|
71
|
+
titleEl: null,
|
|
72
|
+
secondaryLabelEl: null,
|
|
73
|
+
chevron: null,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* If item is in confirmation state, stores confirmation params such as icon, label, onActivate callback and so on
|
|
78
|
+
*/
|
|
79
|
+
private confirmationState: PopoverItemDefaultParams | null = null;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Render params passed during construction, stored for re-rendering
|
|
83
|
+
*/
|
|
84
|
+
private readonly renderParams: PopoverItemRenderParamsMap[PopoverItemType.Default] | undefined;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Constructs popover item instance
|
|
88
|
+
* @param params - popover item construction params
|
|
89
|
+
* @param renderParams - popover item render params.
|
|
90
|
+
* The parameters that are not set by user via popover api but rather depend on technical implementation
|
|
91
|
+
*/
|
|
92
|
+
constructor(protected readonly params: PopoverItemDefaultParams, renderParams?: PopoverItemRenderParamsMap[PopoverItemType.Default]) {
|
|
93
|
+
super(params);
|
|
94
|
+
|
|
95
|
+
this.renderParams = renderParams;
|
|
96
|
+
this.nodes.root = this.createRootElement(params, renderParams);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns popover item root element
|
|
101
|
+
*/
|
|
102
|
+
public getElement(): HTMLElement | null {
|
|
103
|
+
return this.nodes.root;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Called on popover item click
|
|
108
|
+
*/
|
|
109
|
+
public handleClick(): void {
|
|
110
|
+
if (this.isConfirmationStateEnabled && this.confirmationState !== null) {
|
|
111
|
+
this.activateOrEnableConfirmationMode(this.confirmationState);
|
|
112
|
+
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.activateOrEnableConfirmationMode(this.params);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Toggles item active state
|
|
121
|
+
* @param isActive - true if item should strictly should become active
|
|
122
|
+
*/
|
|
123
|
+
public toggleActive(isActive?: boolean): void {
|
|
124
|
+
if (this.nodes.root === null) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const currentlyActive = this.nodes.root.hasAttribute(DATA_ATTR.popoverItemActive);
|
|
129
|
+
const shouldBeActive = isActive !== undefined ? isActive : !currentlyActive;
|
|
130
|
+
|
|
131
|
+
this.setActive(shouldBeActive);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Toggles item hidden state
|
|
136
|
+
* @param isHidden - true if item should be hidden
|
|
137
|
+
*/
|
|
138
|
+
public override toggleHidden(isHidden: boolean): void {
|
|
139
|
+
this.setHidden(isHidden);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Resets popover item to its original state
|
|
144
|
+
*/
|
|
145
|
+
public reset(): void {
|
|
146
|
+
if (this.isConfirmationStateEnabled) {
|
|
147
|
+
this.disableConfirmationMode();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Method called once item becomes focused during keyboard navigation
|
|
153
|
+
*/
|
|
154
|
+
public onFocus(): void {
|
|
155
|
+
this.disableSpecialHoverAndFocusBehavior();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Creates the root container element
|
|
161
|
+
* @param params - item construction params
|
|
162
|
+
* @param renderParams - popover item render params
|
|
163
|
+
*/
|
|
164
|
+
private createRootElement(
|
|
165
|
+
params: PopoverItemDefaultParams,
|
|
166
|
+
renderParams?: PopoverItemRenderParamsMap[PopoverItemType.Default]
|
|
167
|
+
): HTMLElement {
|
|
168
|
+
const wrapperTag = renderParams?.wrapperTag ?? 'div';
|
|
169
|
+
const root = document.createElement(wrapperTag);
|
|
170
|
+
|
|
171
|
+
if (wrapperTag === 'button') {
|
|
172
|
+
root.setAttribute('type', 'button');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Set classes
|
|
176
|
+
root.className = this.getContainerClass();
|
|
177
|
+
|
|
178
|
+
// Set data attributes
|
|
179
|
+
root.setAttribute(DATA_ATTR.popoverItem, '');
|
|
180
|
+
root.setAttribute('data-blok-testid', 'popover-item');
|
|
181
|
+
|
|
182
|
+
if (params.name) {
|
|
183
|
+
root.setAttribute('data-blok-item-name', params.name);
|
|
184
|
+
}
|
|
185
|
+
if (params.dataset) {
|
|
186
|
+
Object.entries(params.dataset).forEach(([key, value]) => {
|
|
187
|
+
root.setAttribute(`data-${key}`, value);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (params.isDisabled) {
|
|
191
|
+
root.setAttribute(DATA_ATTR.disabled, 'true');
|
|
192
|
+
}
|
|
193
|
+
if (this.isActive) {
|
|
194
|
+
root.setAttribute(DATA_ATTR.popoverItemActive, 'true');
|
|
195
|
+
}
|
|
196
|
+
if (this.hasChildren) {
|
|
197
|
+
root.setAttribute(DATA_ATTR.hasChildren, 'true');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Create content elements
|
|
201
|
+
this.createContentElements(root, params, renderParams);
|
|
202
|
+
|
|
203
|
+
// Add hint if configured
|
|
204
|
+
const shouldAddHint = params.hint !== undefined && renderParams?.hint?.enabled !== false;
|
|
205
|
+
|
|
206
|
+
if (shouldAddHint && params.hint !== undefined) {
|
|
207
|
+
this.addHint(root, {
|
|
208
|
+
...params.hint,
|
|
209
|
+
position: renderParams?.hint?.position || 'right',
|
|
210
|
+
alignment: renderParams?.hint?.alignment || 'center',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return root;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Creates the content elements (icon, title, secondary label, chevron)
|
|
219
|
+
*/
|
|
220
|
+
private createContentElements(
|
|
221
|
+
root: HTMLElement,
|
|
222
|
+
params: PopoverItemDefaultParams,
|
|
223
|
+
renderParams?: PopoverItemRenderParamsMap[PopoverItemType.Default]
|
|
224
|
+
): void {
|
|
225
|
+
const iconWithGap = renderParams?.iconWithGap ?? true;
|
|
226
|
+
const isInline = renderParams?.isInline ?? false;
|
|
227
|
+
const isNestedInline = renderParams?.isNestedInline ?? false;
|
|
228
|
+
|
|
229
|
+
const title = params.title;
|
|
230
|
+
|
|
231
|
+
// Icon
|
|
232
|
+
if (params.icon) {
|
|
233
|
+
this.nodes.icon = this.createIconElement(params.icon, iconWithGap, isInline, isNestedInline);
|
|
234
|
+
root.appendChild(this.nodes.icon);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Title
|
|
238
|
+
if (title !== undefined) {
|
|
239
|
+
const titleEl = document.createElement('div');
|
|
240
|
+
|
|
241
|
+
titleEl.className = 'mr-auto truncate text-sm font-medium leading-5';
|
|
242
|
+
titleEl.setAttribute(DATA_ATTR.popoverItemTitle, '');
|
|
243
|
+
titleEl.setAttribute('data-blok-testid', 'popover-item-title');
|
|
244
|
+
titleEl.textContent = title;
|
|
245
|
+
|
|
246
|
+
root.appendChild(titleEl);
|
|
247
|
+
this.nodes.titleEl = titleEl;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Secondary label
|
|
251
|
+
if (params.secondaryLabel) {
|
|
252
|
+
const secondaryEl = document.createElement('div');
|
|
253
|
+
|
|
254
|
+
secondaryEl.className = 'whitespace-nowrap pr-1.5 text-xs -tracking-widest text-text-secondary opacity-60';
|
|
255
|
+
secondaryEl.setAttribute(DATA_ATTR.popoverItemSecondaryTitle, '');
|
|
256
|
+
secondaryEl.setAttribute('data-blok-testid', 'popover-item-secondary-title');
|
|
257
|
+
secondaryEl.textContent = params.secondaryLabel;
|
|
258
|
+
|
|
259
|
+
root.appendChild(secondaryEl);
|
|
260
|
+
this.nodes.secondaryLabelEl = secondaryEl;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Chevron
|
|
264
|
+
const showChevron = this.hasChildren && !this.isChevronHidden;
|
|
265
|
+
|
|
266
|
+
if (showChevron) {
|
|
267
|
+
const chevronEl = document.createElement('div');
|
|
268
|
+
|
|
269
|
+
chevronEl.className = this.getChevronClass(isInline);
|
|
270
|
+
chevronEl.setAttribute(DATA_ATTR.popoverItemIcon, '');
|
|
271
|
+
chevronEl.setAttribute(DATA_ATTR.popoverItemIconChevronRight, '');
|
|
272
|
+
chevronEl.setAttribute('data-blok-testid', 'popover-item-chevron-right');
|
|
273
|
+
chevronEl.innerHTML = IconChevronRight;
|
|
274
|
+
|
|
275
|
+
root.appendChild(chevronEl);
|
|
276
|
+
this.nodes.chevron = chevronEl;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Creates an icon element
|
|
283
|
+
*/
|
|
284
|
+
private createIconElement(icon: string, iconWithGap: boolean, isInline: boolean, isNestedInline: boolean): HTMLElement {
|
|
285
|
+
const iconEl = document.createElement('div');
|
|
286
|
+
|
|
287
|
+
iconEl.className = this.getIconClass(iconWithGap, isInline, isNestedInline, false);
|
|
288
|
+
iconEl.setAttribute(DATA_ATTR.popoverItemIcon, '');
|
|
289
|
+
iconEl.setAttribute('data-blok-testid', 'popover-item-icon');
|
|
290
|
+
iconEl.innerHTML = icon;
|
|
291
|
+
|
|
292
|
+
if (iconWithGap) {
|
|
293
|
+
iconEl.setAttribute(DATA_ATTR.tool, '');
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return iconEl;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Gets the container class based on current state
|
|
301
|
+
*/
|
|
302
|
+
private getContainerClass(): string {
|
|
303
|
+
const isInline = this.renderParams?.isInline ?? false;
|
|
304
|
+
const isNestedInline = this.renderParams?.isNestedInline ?? false;
|
|
305
|
+
|
|
306
|
+
return twMerge(
|
|
307
|
+
css.item,
|
|
308
|
+
isInline && cssInline.item,
|
|
309
|
+
isNestedInline && cssNestedInline.item,
|
|
310
|
+
this.params.isDisabled && css.itemDisabled
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Gets the icon class based on context
|
|
316
|
+
*/
|
|
317
|
+
private getIconClass(iconWithGap: boolean, isInline: boolean, isNestedInline: boolean, isWobbling: boolean): string {
|
|
318
|
+
return twMerge(
|
|
319
|
+
css.icon,
|
|
320
|
+
isInline && 'w-auto h-auto [&_svg]:w-icon [&_svg]:h-icon mobile:[&_svg]:w-icon-mobile mobile:[&_svg]:h-icon-mobile',
|
|
321
|
+
isNestedInline && 'w-toolbox-btn h-toolbox-btn',
|
|
322
|
+
iconWithGap && 'mr-2',
|
|
323
|
+
iconWithGap && isInline && 'shadow-none bg-transparent !mr-0',
|
|
324
|
+
iconWithGap && isNestedInline && '!mr-2',
|
|
325
|
+
isWobbling && 'animate-wobble'
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Gets the chevron class based on context
|
|
331
|
+
*/
|
|
332
|
+
private getChevronClass(isInline: boolean): string {
|
|
333
|
+
return twMerge(
|
|
334
|
+
css.icon,
|
|
335
|
+
isInline && 'rotate-90'
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Sets the active state of the item
|
|
341
|
+
*/
|
|
342
|
+
private setActive(isActive: boolean): void {
|
|
343
|
+
if (!this.nodes.root) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (isActive) {
|
|
348
|
+
this.nodes.root.setAttribute(DATA_ATTR.popoverItemActive, 'true');
|
|
349
|
+
} else {
|
|
350
|
+
this.nodes.root.removeAttribute(DATA_ATTR.popoverItemActive);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Sets the hidden state of the item
|
|
356
|
+
*/
|
|
357
|
+
private setHidden(isHidden: boolean): void {
|
|
358
|
+
if (!this.nodes.root) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (isHidden) {
|
|
363
|
+
this.nodes.root.setAttribute(DATA_ATTR.hidden, 'true');
|
|
364
|
+
this.nodes.root.classList.add('!hidden');
|
|
365
|
+
} else {
|
|
366
|
+
this.nodes.root.removeAttribute(DATA_ATTR.hidden);
|
|
367
|
+
this.nodes.root.classList.remove('!hidden');
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Sets the focused state of the item
|
|
373
|
+
* @param isFocused - true if item should be focused
|
|
374
|
+
*/
|
|
375
|
+
public setFocused(isFocused: boolean): void {
|
|
376
|
+
if (!this.nodes.root) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (isFocused) {
|
|
381
|
+
this.nodes.root.setAttribute(DATA_ATTR.focused, 'true');
|
|
382
|
+
this.nodes.root.classList.add('!bg-item-focus-bg');
|
|
383
|
+
} else {
|
|
384
|
+
this.nodes.root.removeAttribute(DATA_ATTR.focused);
|
|
385
|
+
this.nodes.root.classList.remove('!bg-item-focus-bg');
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Sets the no-hover state
|
|
391
|
+
*/
|
|
392
|
+
private setNoHover(noHover: boolean): void {
|
|
393
|
+
if (!this.nodes.root) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (noHover) {
|
|
398
|
+
this.nodes.root.setAttribute(DATA_ATTR.popoverItemNoHover, 'true');
|
|
399
|
+
} else {
|
|
400
|
+
this.nodes.root.removeAttribute(DATA_ATTR.popoverItemNoHover);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Sets the no-focus state
|
|
406
|
+
*/
|
|
407
|
+
private setNoFocus(noFocus: boolean): void {
|
|
408
|
+
if (!this.nodes.root) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (noFocus) {
|
|
413
|
+
this.nodes.root.setAttribute(DATA_ATTR.popoverItemNoFocus, 'true');
|
|
414
|
+
} else {
|
|
415
|
+
this.nodes.root.removeAttribute(DATA_ATTR.popoverItemNoFocus);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Activates confirmation mode for the item.
|
|
422
|
+
* @param newState - new popover item params that should be applied
|
|
423
|
+
*/
|
|
424
|
+
private enableConfirmationMode(newState: PopoverItemDefaultParams): void {
|
|
425
|
+
if (this.nodes.root === null) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const params = {
|
|
430
|
+
...this.params,
|
|
431
|
+
...newState,
|
|
432
|
+
confirmation: 'confirmation' in newState ? newState.confirmation : undefined,
|
|
433
|
+
} as PopoverItemDefaultParams;
|
|
434
|
+
|
|
435
|
+
// Update confirmation state
|
|
436
|
+
this.setConfirmation(params);
|
|
437
|
+
this.confirmationState = newState;
|
|
438
|
+
|
|
439
|
+
this.enableSpecialHoverAndFocusBehavior();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Sets the confirmation state with new params
|
|
444
|
+
*/
|
|
445
|
+
private setConfirmation(params: PopoverItemDefaultParams | null): void {
|
|
446
|
+
if (!this.nodes.root) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (params === null) {
|
|
451
|
+
this.clearConfirmationState();
|
|
452
|
+
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
this.applyConfirmationState(params);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Clears confirmation state and restores original content
|
|
461
|
+
*/
|
|
462
|
+
private clearConfirmationState(): void {
|
|
463
|
+
if (!this.nodes.root) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
this.nodes.root.removeAttribute(DATA_ATTR.popoverItemConfirmation);
|
|
468
|
+
this.nodes.root.classList.remove('!bg-item-confirm-bg', '!text-white');
|
|
469
|
+
|
|
470
|
+
this.restoreOriginalIcon();
|
|
471
|
+
this.restoreOriginalTitle();
|
|
472
|
+
this.restoreOriginalSecondaryLabel();
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Applies confirmation state with new params
|
|
477
|
+
*/
|
|
478
|
+
private applyConfirmationState(params: PopoverItemDefaultParams): void {
|
|
479
|
+
if (!this.nodes.root) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
this.nodes.root.setAttribute(DATA_ATTR.popoverItemConfirmation, 'true');
|
|
484
|
+
this.nodes.root.classList.add('!bg-item-confirm-bg', '!text-white');
|
|
485
|
+
|
|
486
|
+
this.updateIcon(params.icon);
|
|
487
|
+
this.updateTitle(params);
|
|
488
|
+
this.updateSecondaryLabel(params.secondaryLabel);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Restores the original icon
|
|
493
|
+
*/
|
|
494
|
+
private restoreOriginalIcon(): void {
|
|
495
|
+
if (!this.nodes.icon || !this.params.icon) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
this.nodes.icon.innerHTML = this.params.icon;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Restores the original title
|
|
504
|
+
*/
|
|
505
|
+
private restoreOriginalTitle(): void {
|
|
506
|
+
if (!this.nodes.titleEl || this.params.title === undefined) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
this.nodes.titleEl.textContent = this.params.title;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Restores the original secondary label
|
|
515
|
+
*/
|
|
516
|
+
private restoreOriginalSecondaryLabel(): void {
|
|
517
|
+
if (!this.nodes.secondaryLabelEl) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
this.nodes.secondaryLabelEl.textContent = this.params.secondaryLabel ?? '';
|
|
522
|
+
this.nodes.secondaryLabelEl.style.display = this.params.secondaryLabel ? '' : 'none';
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Updates the icon with new content
|
|
527
|
+
*/
|
|
528
|
+
private updateIcon(icon: string | undefined): void {
|
|
529
|
+
if (!this.nodes.icon || !icon) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
this.nodes.icon.innerHTML = icon;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Updates the title with new content
|
|
538
|
+
*/
|
|
539
|
+
private updateTitle(params: PopoverItemDefaultParams): void {
|
|
540
|
+
if (!this.nodes.titleEl || params.title === undefined) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
this.nodes.titleEl.textContent = params.title;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Updates the secondary label with new content
|
|
549
|
+
*/
|
|
550
|
+
private updateSecondaryLabel(secondaryLabel: string | undefined): void {
|
|
551
|
+
if (!this.nodes.secondaryLabelEl) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
this.nodes.secondaryLabelEl.textContent = secondaryLabel ?? '';
|
|
556
|
+
this.nodes.secondaryLabelEl.style.display = secondaryLabel ? '' : 'none';
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Returns item to its original state
|
|
561
|
+
*/
|
|
562
|
+
private disableConfirmationMode(): void {
|
|
563
|
+
if (this.nodes.root === null) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// Clear confirmation state
|
|
568
|
+
this.setConfirmation(null);
|
|
569
|
+
this.confirmationState = null;
|
|
570
|
+
|
|
571
|
+
this.disableSpecialHoverAndFocusBehavior();
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Enables special focus and hover behavior for item in confirmation state.
|
|
576
|
+
* This is needed to prevent item from being highlighted as hovered/focused just after click.
|
|
577
|
+
*/
|
|
578
|
+
private enableSpecialHoverAndFocusBehavior(): void {
|
|
579
|
+
this.setNoHover(true);
|
|
580
|
+
this.setNoFocus(true);
|
|
581
|
+
|
|
582
|
+
this.nodes.root?.addEventListener('mouseleave', this.removeSpecialHoverBehavior, { once: true });
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Disables special focus and hover behavior
|
|
587
|
+
*/
|
|
588
|
+
private disableSpecialHoverAndFocusBehavior(): void {
|
|
589
|
+
this.removeSpecialFocusBehavior();
|
|
590
|
+
this.removeSpecialHoverBehavior();
|
|
591
|
+
|
|
592
|
+
this.nodes.root?.removeEventListener('mouseleave', this.removeSpecialHoverBehavior);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Removes class responsible for special focus behavior on an item
|
|
597
|
+
*/
|
|
598
|
+
private removeSpecialFocusBehavior = (): void => {
|
|
599
|
+
this.setNoFocus(false);
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Removes class responsible for special hover behavior on an item
|
|
604
|
+
*/
|
|
605
|
+
private removeSpecialHoverBehavior = (): void => {
|
|
606
|
+
this.setNoHover(false);
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Executes item's onActivate callback if the item has no confirmation configured
|
|
611
|
+
* @param item - item to activate or bring to confirmation mode
|
|
612
|
+
*/
|
|
613
|
+
private activateOrEnableConfirmationMode(item: PopoverItemDefaultParams): void {
|
|
614
|
+
if (!('confirmation' in item) || item.confirmation === undefined) {
|
|
615
|
+
try {
|
|
616
|
+
item.onActivate?.(item);
|
|
617
|
+
this.disableConfirmationMode();
|
|
618
|
+
} catch {
|
|
619
|
+
this.animateError();
|
|
620
|
+
}
|
|
621
|
+
} else {
|
|
622
|
+
this.enableConfirmationMode(item.confirmation);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Animates item which symbolizes that error occurred while executing 'onActivate()' callback
|
|
628
|
+
*/
|
|
629
|
+
private animateError(): void {
|
|
630
|
+
this.triggerWobble();
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Triggers wobble animation on the icon
|
|
635
|
+
*/
|
|
636
|
+
private triggerWobble(): void {
|
|
637
|
+
if (!this.nodes.icon) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const isInline = this.renderParams?.isInline ?? false;
|
|
642
|
+
const isNestedInline = this.renderParams?.isNestedInline ?? false;
|
|
643
|
+
const iconWithGap = this.renderParams?.iconWithGap ?? true;
|
|
644
|
+
|
|
645
|
+
// Add wobble class
|
|
646
|
+
this.nodes.icon.setAttribute(DATA_ATTR.popoverItemWobble, 'true');
|
|
647
|
+
this.nodes.icon.className = this.getIconClass(iconWithGap, isInline, isNestedInline, true);
|
|
648
|
+
|
|
649
|
+
// Remove wobble after animation ends
|
|
650
|
+
const handleAnimationEnd = (): void => {
|
|
651
|
+
if (this.nodes.icon) {
|
|
652
|
+
this.nodes.icon.removeAttribute(DATA_ATTR.popoverItemWobble);
|
|
653
|
+
this.nodes.icon.className = this.getIconClass(iconWithGap, isInline, isNestedInline, false);
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
this.nodes.icon.addEventListener('animationend', handleAnimationEnd, { once: true });
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Gets reference to the icon element
|
|
662
|
+
*/
|
|
663
|
+
public getIconElement(): HTMLElement | null {
|
|
664
|
+
return this.nodes.icon;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tailwind CSS classes for popover item HTML component
|
|
3
|
+
*/
|
|
4
|
+
export const css = {
|
|
5
|
+
root: '',
|
|
6
|
+
rootHidden: 'hidden',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tailwind CSS classes for inline popover item HTML
|
|
11
|
+
*/
|
|
12
|
+
export const cssInline = {
|
|
13
|
+
root: 'flex items-center',
|
|
14
|
+
};
|