@jackuait/blok 0.4.1 → 0.4.2
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 +859 -92
- package/codemod/test.js +682 -77
- package/dist/blok.mjs +5 -2
- package/dist/chunks/blok-BjgH1REI.mjs +12838 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-DfiUa_gd.mjs +43 -0
- package/dist/{index-CBkApZKo.mjs → chunks/index-5m5JWNey.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-Bx5BVd8I.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 +47 -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,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Announcer
|
|
3
|
+
* @description Provides screen reader announcements via ARIA live regions
|
|
4
|
+
* Following WAI-ARIA best practices for dynamic content updates
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ARIA_LIVE_REGION_ID = 'blok-announcer';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tailwind sr-only pattern for visually hiding content while keeping it accessible
|
|
11
|
+
*/
|
|
12
|
+
const SR_ONLY_CLASSES = [
|
|
13
|
+
'absolute',
|
|
14
|
+
'w-px',
|
|
15
|
+
'h-px',
|
|
16
|
+
'p-0',
|
|
17
|
+
'-m-px',
|
|
18
|
+
'overflow-hidden',
|
|
19
|
+
'[clip:rect(0,0,0,0)]',
|
|
20
|
+
'whitespace-nowrap',
|
|
21
|
+
'border-0',
|
|
22
|
+
].join(' ');
|
|
23
|
+
|
|
24
|
+
interface AnnouncerConfig {
|
|
25
|
+
/** Politeness level: 'polite' for non-critical, 'assertive' for important */
|
|
26
|
+
politeness?: 'polite' | 'assertive';
|
|
27
|
+
/** Clear announcement after this many milliseconds (default: 1000) */
|
|
28
|
+
clearAfter?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Singleton class that manages an ARIA live region for screen reader announcements
|
|
33
|
+
* Supports multiple Blok instances on the same page via reference counting
|
|
34
|
+
*/
|
|
35
|
+
class Announcer {
|
|
36
|
+
/**
|
|
37
|
+
* Singleton instance
|
|
38
|
+
*/
|
|
39
|
+
private static instance: Announcer | null = null;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reference count for multi-instance support
|
|
43
|
+
* Tracks how many Blok instances are using this announcer
|
|
44
|
+
*/
|
|
45
|
+
private static referenceCount = 0;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The ARIA live region element
|
|
49
|
+
*/
|
|
50
|
+
private liveRegion: HTMLElement | null = null;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Timeout for clearing announcement
|
|
54
|
+
*/
|
|
55
|
+
private clearTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Private constructor for singleton
|
|
59
|
+
*/
|
|
60
|
+
private constructor() {
|
|
61
|
+
this.createLiveRegion();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get singleton instance and increment reference count
|
|
66
|
+
*/
|
|
67
|
+
public static getInstance(): Announcer {
|
|
68
|
+
if (!Announcer.instance) {
|
|
69
|
+
Announcer.instance = new Announcer();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return Announcer.instance;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Increment reference count when a Blok instance starts using the announcer
|
|
77
|
+
*/
|
|
78
|
+
public static addReference(): void {
|
|
79
|
+
Announcer.referenceCount++;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Creates the ARIA live region element
|
|
84
|
+
* Uses sr-only pattern to hide from sighted users while remaining accessible
|
|
85
|
+
*/
|
|
86
|
+
private createLiveRegion(): void {
|
|
87
|
+
// Check if already exists (multiple Blok instances on same page)
|
|
88
|
+
const existingRegion = document.getElementById(ARIA_LIVE_REGION_ID);
|
|
89
|
+
|
|
90
|
+
if (existingRegion) {
|
|
91
|
+
this.liveRegion = existingRegion;
|
|
92
|
+
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const region = document.createElement('div');
|
|
97
|
+
|
|
98
|
+
region.id = ARIA_LIVE_REGION_ID;
|
|
99
|
+
region.className = SR_ONLY_CLASSES;
|
|
100
|
+
region.setAttribute('role', 'status');
|
|
101
|
+
region.setAttribute('aria-live', 'polite');
|
|
102
|
+
region.setAttribute('aria-atomic', 'true');
|
|
103
|
+
region.setAttribute('data-blok-announcer', '');
|
|
104
|
+
|
|
105
|
+
document.body.appendChild(region);
|
|
106
|
+
|
|
107
|
+
this.liveRegion = region;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Announce a message to screen readers
|
|
112
|
+
* @param message - The message to announce
|
|
113
|
+
* @param config - Configuration options
|
|
114
|
+
*/
|
|
115
|
+
public announce(message: string, config: AnnouncerConfig = {}): void {
|
|
116
|
+
const { politeness = 'polite', clearAfter = 1000 } = config;
|
|
117
|
+
|
|
118
|
+
// Ensure live region exists (defensive, should always exist after constructor)
|
|
119
|
+
if (!this.liveRegion) {
|
|
120
|
+
this.createLiveRegion();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Guard against edge case where createLiveRegion fails
|
|
124
|
+
if (!this.liveRegion) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Clear any pending timeout
|
|
129
|
+
if (this.clearTimeoutId !== null) {
|
|
130
|
+
clearTimeout(this.clearTimeoutId);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Update politeness level
|
|
134
|
+
this.liveRegion.setAttribute('aria-live', politeness);
|
|
135
|
+
|
|
136
|
+
// Clear then set to ensure announcement triggers even if same message
|
|
137
|
+
this.liveRegion.textContent = '';
|
|
138
|
+
|
|
139
|
+
// Use requestAnimationFrame to ensure DOM update before setting new content
|
|
140
|
+
requestAnimationFrame(() => {
|
|
141
|
+
if (this.liveRegion) {
|
|
142
|
+
this.liveRegion.textContent = message;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Clear after delay to prepare for next announcement
|
|
147
|
+
this.clearTimeoutId = setTimeout(() => {
|
|
148
|
+
if (this.liveRegion) {
|
|
149
|
+
this.liveRegion.textContent = '';
|
|
150
|
+
}
|
|
151
|
+
}, clearAfter);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Clean up the live region
|
|
156
|
+
* Only removes the DOM element when all references are released
|
|
157
|
+
*/
|
|
158
|
+
public destroy(): void {
|
|
159
|
+
Announcer.referenceCount--;
|
|
160
|
+
|
|
161
|
+
// Only clean up when last reference is released
|
|
162
|
+
if (Announcer.referenceCount > 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (this.clearTimeoutId !== null) {
|
|
167
|
+
clearTimeout(this.clearTimeoutId);
|
|
168
|
+
this.clearTimeoutId = null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (this.liveRegion) {
|
|
172
|
+
this.liveRegion.remove();
|
|
173
|
+
this.liveRegion = null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
Announcer.instance = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Announce a message to screen readers
|
|
182
|
+
* @param message - The message to announce
|
|
183
|
+
* @param config - Configuration options
|
|
184
|
+
*/
|
|
185
|
+
export const announce = (message: string, config?: AnnouncerConfig): void => {
|
|
186
|
+
Announcer.getInstance().announce(message, config);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Register a Blok instance as using the announcer
|
|
191
|
+
* Call this when a Blok instance is created
|
|
192
|
+
*/
|
|
193
|
+
export const registerAnnouncer = (): void => {
|
|
194
|
+
Announcer.addReference();
|
|
195
|
+
// Ensure instance is created
|
|
196
|
+
Announcer.getInstance();
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Clean up the announcer and remove the live region
|
|
201
|
+
* Only removes the DOM element when all Blok instances have been destroyed
|
|
202
|
+
*/
|
|
203
|
+
export const destroyAnnouncer = (): void => {
|
|
204
|
+
Announcer.getInstance().destroy();
|
|
205
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BlockAPI } from '../../../types/api/block';
|
|
2
|
+
import type { BlokModules } from '../../types-internal/blok-modules';
|
|
3
|
+
import type { Block } from '../block';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns Block instance by passed Block index or Block id
|
|
7
|
+
* @param attribute - either BlockAPI or Block id or Block index
|
|
8
|
+
* @param blok - Blok instance
|
|
9
|
+
*/
|
|
10
|
+
export const resolveBlock = (attribute: BlockAPI | BlockAPI['id'] | number, blok: BlokModules): Block | undefined => {
|
|
11
|
+
if (typeof attribute === 'number') {
|
|
12
|
+
return blok.BlockManager.getBlockByIndex(attribute);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (typeof attribute === 'string') {
|
|
16
|
+
return blok.BlockManager.getBlockById(attribute);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return blok.BlockManager.getBlockById(attribute.id);
|
|
20
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const ELEMENT_DELIMITER = '__';
|
|
2
|
+
const MODIFIER_DELIMITER = '--';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utility function that allows to construct class names from block and element names
|
|
6
|
+
* @example bem('blok-popover)() -> 'blok-popover'
|
|
7
|
+
* @example bem('blok-popover)('container') -> 'blok-popover__container'
|
|
8
|
+
* @example bem('blok-popover)('container', 'hidden') -> 'blok-popover__container--hidden'
|
|
9
|
+
* @example bem('blok-popover)(null, 'hidden') -> 'blok-popover--hidden'
|
|
10
|
+
* @param blockName - string with block name
|
|
11
|
+
*/
|
|
12
|
+
export const bem = (blockName: string) => {
|
|
13
|
+
/**
|
|
14
|
+
* @param elementName - string with element name
|
|
15
|
+
* @param modifier - modifier to be appended
|
|
16
|
+
*/
|
|
17
|
+
return (elementName?: string | null, modifier?: string) => {
|
|
18
|
+
const className = [blockName, elementName]
|
|
19
|
+
.filter(x => !!x)
|
|
20
|
+
.join(ELEMENT_DELIMITER);
|
|
21
|
+
|
|
22
|
+
return [className, modifier]
|
|
23
|
+
.filter(x => !!x)
|
|
24
|
+
.join(MODIFIER_DELIMITER);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import type { BlockAPI, ToolConfig } from '../../../types';
|
|
2
|
+
import type { ConversionConfig } from '../../../types/configs/conversion-config';
|
|
3
|
+
import type { SavedData } from '../../../types/data-formats';
|
|
4
|
+
import type { BlockToolData } from '../../../types/tools/block-tool-data';
|
|
5
|
+
import type { Block } from '../block';
|
|
6
|
+
import type { BlockToolAdapter } from '../tools/block';
|
|
7
|
+
import { isFunction, isString, log, equals, isEmpty } from '../utils';
|
|
8
|
+
import { isToolConvertable } from './tools';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if block has valid conversion config for export or import.
|
|
13
|
+
* @param block - block to check
|
|
14
|
+
* @param direction - export for block to merge from, import for block to merge to
|
|
15
|
+
*/
|
|
16
|
+
export const isBlockConvertable = (block: Block, direction: 'export' | 'import'): boolean => {
|
|
17
|
+
return isToolConvertable(block.tool, direction);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks that all the properties of the first block data exist in second block data with the same values.
|
|
22
|
+
*
|
|
23
|
+
* Example:
|
|
24
|
+
*
|
|
25
|
+
* data1 = { level: 1 }
|
|
26
|
+
*
|
|
27
|
+
* data2 = {
|
|
28
|
+
* text: "Heading text",
|
|
29
|
+
* level: 1
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* isSameBlockData(data1, data2) => true
|
|
33
|
+
* @param data1 – first block data
|
|
34
|
+
* @param data2 – second block data
|
|
35
|
+
*/
|
|
36
|
+
export const isSameBlockData = (data1: BlockToolData, data2: BlockToolData): boolean => {
|
|
37
|
+
return Object.entries(data1).some((([propName, propValue]) => {
|
|
38
|
+
return data2[propName] && equals(data2[propName], propValue);
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns list of tools you can convert specified block to
|
|
44
|
+
* @param block - block to get conversion items for
|
|
45
|
+
* @param allBlockTools - all block tools available in the blok
|
|
46
|
+
*/
|
|
47
|
+
export const getConvertibleToolsForBlock = async (block: BlockAPI, allBlockTools: BlockToolAdapter[]): Promise<BlockToolAdapter[]> => {
|
|
48
|
+
const savedData = await block.save() as SavedData;
|
|
49
|
+
const blockData = savedData.data;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Checking that the block's tool has an «export» rule
|
|
53
|
+
*/
|
|
54
|
+
const blockTool = allBlockTools.find((tool) => tool.name === block.name);
|
|
55
|
+
|
|
56
|
+
if (blockTool !== undefined && !isToolConvertable(blockTool, 'export')) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return allBlockTools.reduce((result, tool) => {
|
|
61
|
+
/**
|
|
62
|
+
* Skip tools without «import» rule specified
|
|
63
|
+
*/
|
|
64
|
+
if (!isToolConvertable(tool, 'import')) {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Skip tools that does not specify toolbox
|
|
70
|
+
*/
|
|
71
|
+
if (tool.toolbox === undefined) {
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Filter out invalid toolbox entries */
|
|
76
|
+
const actualToolboxItems = tool.toolbox.filter((toolboxItem) => {
|
|
77
|
+
/**
|
|
78
|
+
* Skip items that don't pass 'toolbox' property or do not have an icon
|
|
79
|
+
*/
|
|
80
|
+
if (isEmpty(toolboxItem) || toolboxItem.icon === undefined) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const hasToolboxData = toolboxItem.data !== undefined;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* When a tool has several toolbox entries, we need to make sure we do not add
|
|
88
|
+
* toolbox item with the same data to the resulting array. This helps exclude duplicates
|
|
89
|
+
*/
|
|
90
|
+
if (hasToolboxData && isSameBlockData(toolboxItem.data, blockData)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!hasToolboxData && tool.name === block.name) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
result.push({
|
|
102
|
+
...tool,
|
|
103
|
+
toolbox: actualToolboxItems,
|
|
104
|
+
} as BlockToolAdapter);
|
|
105
|
+
|
|
106
|
+
return result;
|
|
107
|
+
}, [] as BlockToolAdapter[]);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Check if two blocks could be merged.
|
|
113
|
+
*
|
|
114
|
+
* We can merge two blocks if:
|
|
115
|
+
* - they have the same type
|
|
116
|
+
* - they have a merge function (.mergeable = true)
|
|
117
|
+
* - If they have valid conversions config
|
|
118
|
+
* @param targetBlock - block to merge to
|
|
119
|
+
* @param blockToMerge - block to merge from
|
|
120
|
+
*/
|
|
121
|
+
export const areBlocksMergeable = (targetBlock: Block, blockToMerge: Block): boolean => {
|
|
122
|
+
/**
|
|
123
|
+
* If target block has not 'merge' method, we can't merge blocks.
|
|
124
|
+
*
|
|
125
|
+
* Technically we can (through the conversion) but it will lead a target block delete and recreation, which is unexpected behavior.
|
|
126
|
+
*/
|
|
127
|
+
if (!targetBlock.mergeable) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Tool knows how to merge own data format
|
|
133
|
+
*/
|
|
134
|
+
if (targetBlock.name === blockToMerge.name) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* We can merge blocks if they have valid conversion config
|
|
140
|
+
*/
|
|
141
|
+
return isBlockConvertable(blockToMerge, 'export') && isBlockConvertable(targetBlock, 'import');
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Returns list of tools that all specified blocks can be converted to.
|
|
146
|
+
* Only returns tools that are valid conversion targets for ALL blocks.
|
|
147
|
+
* @param blocks - array of blocks to get common conversion items for
|
|
148
|
+
* @param allBlockTools - all block tools available in the blok
|
|
149
|
+
*/
|
|
150
|
+
export const getConvertibleToolsForBlocks = async (blocks: BlockAPI[], allBlockTools: BlockToolAdapter[]): Promise<BlockToolAdapter[]> => {
|
|
151
|
+
if (blocks.length === 0) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* If only one block, use the single block function
|
|
157
|
+
*/
|
|
158
|
+
if (blocks.length === 1) {
|
|
159
|
+
return getConvertibleToolsForBlock(blocks[0], allBlockTools);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Check that all blocks have export conversion config
|
|
164
|
+
*/
|
|
165
|
+
for (const block of blocks) {
|
|
166
|
+
const blockTool = allBlockTools.find((tool) => tool.name === block.name);
|
|
167
|
+
|
|
168
|
+
if (blockTool !== undefined && !isToolConvertable(blockTool, 'export')) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Get the set of tool names that all blocks currently use
|
|
175
|
+
*/
|
|
176
|
+
const blockToolNames = new Set(blocks.map((block) => block.name));
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Filter tools that have import conversion config and valid toolbox
|
|
180
|
+
*/
|
|
181
|
+
return allBlockTools.reduce((result, tool) => {
|
|
182
|
+
/**
|
|
183
|
+
* Skip tools without «import» rule specified
|
|
184
|
+
*/
|
|
185
|
+
if (!isToolConvertable(tool, 'import')) {
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Skip tools that does not specify toolbox
|
|
191
|
+
*/
|
|
192
|
+
if (tool.toolbox === undefined) {
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Filter out invalid toolbox entries */
|
|
197
|
+
const actualToolboxItems = tool.toolbox.filter((toolboxItem) => {
|
|
198
|
+
/**
|
|
199
|
+
* Skip items that don't pass 'toolbox' property or do not have an icon
|
|
200
|
+
*/
|
|
201
|
+
if (isEmpty(toolboxItem) || toolboxItem.icon === undefined) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* For multiple blocks, we skip the tool if ALL selected blocks are already of this type
|
|
207
|
+
* (with no toolbox data override)
|
|
208
|
+
*/
|
|
209
|
+
const hasToolboxData = toolboxItem.data !== undefined;
|
|
210
|
+
|
|
211
|
+
if (!hasToolboxData && blockToolNames.size === 1 && blockToolNames.has(tool.name)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return true;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (actualToolboxItems.length > 0) {
|
|
219
|
+
result.push({
|
|
220
|
+
...tool,
|
|
221
|
+
toolbox: actualToolboxItems,
|
|
222
|
+
} as BlockToolAdapter);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return result;
|
|
226
|
+
}, [] as BlockToolAdapter[]);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Using conversionConfig, convert block data to string.
|
|
231
|
+
* @param blockData - block data to convert
|
|
232
|
+
* @param conversionConfig - tool's conversion config
|
|
233
|
+
*/
|
|
234
|
+
export const convertBlockDataToString = (blockData: BlockToolData, conversionConfig?: ConversionConfig ): string => {
|
|
235
|
+
const exportProp = conversionConfig?.export;
|
|
236
|
+
|
|
237
|
+
if (isFunction(exportProp)) {
|
|
238
|
+
return exportProp(blockData);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (isString(exportProp)) {
|
|
242
|
+
return blockData[exportProp];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Tool developer provides 'export' property, but it is not correct. Warn him.
|
|
247
|
+
*/
|
|
248
|
+
if (exportProp !== undefined) {
|
|
249
|
+
log('Conversion «export» property must be a string or function. ' +
|
|
250
|
+
'String means key of saved data object to export. Function should export processed string to export.');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return '';
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Using conversionConfig, convert string to block data.
|
|
258
|
+
* @param stringToImport - string to convert
|
|
259
|
+
* @param conversionConfig - tool's conversion config
|
|
260
|
+
* @param targetToolConfig - target tool config, used in conversionConfig.import method
|
|
261
|
+
*/
|
|
262
|
+
export const convertStringToBlockData = (stringToImport: string, conversionConfig?: ConversionConfig, targetToolConfig?: ToolConfig): BlockToolData => {
|
|
263
|
+
const importProp = conversionConfig?.import;
|
|
264
|
+
|
|
265
|
+
if (isFunction(importProp)) {
|
|
266
|
+
return importProp(stringToImport, targetToolConfig);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (isString(importProp)) {
|
|
270
|
+
return {
|
|
271
|
+
[importProp]: stringToImport,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Tool developer provides 'import' property, but it is not correct. Warn him.
|
|
277
|
+
*/
|
|
278
|
+
if (importProp !== undefined) {
|
|
279
|
+
log('Conversion «import» property must be a string or function. ' +
|
|
280
|
+
'String means key of tool data to import. Function accepts a imported string and return composed tool data.');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {};
|
|
284
|
+
};
|