@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,392 @@
|
|
|
1
|
+
import { Dom as $ } from './dom';
|
|
2
|
+
import { LogLevels, isEmpty, isFunction, isObject, isString, log, setLogLevel } from './utils';
|
|
3
|
+
import type { BlokConfig, SanitizerConfig } from '../../types';
|
|
4
|
+
import type { BlokModules } from '../types-internal/blok-modules';
|
|
5
|
+
import { CriticalError } from './errors/critical';
|
|
6
|
+
import { EventsDispatcher } from './utils/events';
|
|
7
|
+
import { Modules } from './modules';
|
|
8
|
+
import type { BlokEventMap } from './events';
|
|
9
|
+
import type { Renderer } from './modules/renderer';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Blok core class. Bootstraps modules.
|
|
13
|
+
*/
|
|
14
|
+
export class Core {
|
|
15
|
+
/**
|
|
16
|
+
* Blok configuration passed by user to the constructor
|
|
17
|
+
*/
|
|
18
|
+
public config: BlokConfig;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Object with core modules instances
|
|
22
|
+
*/
|
|
23
|
+
public moduleInstances: BlokModules = {} as BlokModules;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Promise that resolves when all core modules are prepared and UI is rendered on the page
|
|
27
|
+
*/
|
|
28
|
+
public isReady: Promise<void>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Common Blok Event Bus
|
|
32
|
+
*/
|
|
33
|
+
private eventsDispatcher: EventsDispatcher<BlokEventMap> = new EventsDispatcher();
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {BlokConfig} config - user configuration
|
|
37
|
+
*/
|
|
38
|
+
constructor(config?: BlokConfig|string) {
|
|
39
|
+
/**
|
|
40
|
+
* Ready promise. Resolved if Blok is ready to work, rejected otherwise
|
|
41
|
+
*/
|
|
42
|
+
// Initialize config to satisfy TypeScript's definite assignment check
|
|
43
|
+
// The setter will properly assign and process the config
|
|
44
|
+
this.config = {};
|
|
45
|
+
|
|
46
|
+
this.isReady = new Promise((resolve, reject) => {
|
|
47
|
+
Promise.resolve()
|
|
48
|
+
.then(async () => {
|
|
49
|
+
this.configuration = config;
|
|
50
|
+
this.validate();
|
|
51
|
+
this.init();
|
|
52
|
+
await this.start();
|
|
53
|
+
await this.render();
|
|
54
|
+
|
|
55
|
+
const { BlockManager, Caret, UI, ModificationsObserver, History } = this.moduleInstances;
|
|
56
|
+
|
|
57
|
+
UI.checkEmptiness();
|
|
58
|
+
ModificationsObserver.enable();
|
|
59
|
+
|
|
60
|
+
// Capture initial state for undo/redo after rendering
|
|
61
|
+
await History.captureInitialState();
|
|
62
|
+
|
|
63
|
+
if ((this.configuration as BlokConfig).autofocus === true && this.configuration.readOnly !== true) {
|
|
64
|
+
Caret.setToBlock(BlockManager.blocks[0], Caret.positions.START);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
resolve();
|
|
68
|
+
})
|
|
69
|
+
.catch((error) => {
|
|
70
|
+
log(`Blok is not ready because of ${error}`, 'error');
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Reject this.isReady promise
|
|
74
|
+
*/
|
|
75
|
+
reject(error);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Setting for configuration
|
|
82
|
+
* @param {BlokConfig|string|undefined} config - Blok's config to set
|
|
83
|
+
*/
|
|
84
|
+
public set configuration(config: BlokConfig|string|undefined) {
|
|
85
|
+
/**
|
|
86
|
+
* Place config into the class property
|
|
87
|
+
* @type {BlokConfig}
|
|
88
|
+
*/
|
|
89
|
+
if (isObject(config)) {
|
|
90
|
+
this.config = {
|
|
91
|
+
...config,
|
|
92
|
+
};
|
|
93
|
+
} else {
|
|
94
|
+
/**
|
|
95
|
+
* Process zero-configuration or with only holder
|
|
96
|
+
* Make config object
|
|
97
|
+
*/
|
|
98
|
+
this.config = {
|
|
99
|
+
holder: config,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* If holder is empty then set a default value
|
|
105
|
+
*/
|
|
106
|
+
if (this.config.holder == null) {
|
|
107
|
+
this.config.holder = 'blok';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (this.config.logLevel == null) {
|
|
111
|
+
this.config.logLevel = LogLevels.VERBOSE;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setLogLevel(this.config.logLevel);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* If default Block's Tool was not passed, use the Paragraph Tool
|
|
118
|
+
*/
|
|
119
|
+
this.config.defaultBlock = this.config.defaultBlock ?? 'paragraph';
|
|
120
|
+
|
|
121
|
+
const toolsConfig = this.config.tools;
|
|
122
|
+
const defaultBlockName = this.config.defaultBlock;
|
|
123
|
+
const hasDefaultBlockTool = toolsConfig != null &&
|
|
124
|
+
Object.prototype.hasOwnProperty.call(toolsConfig, defaultBlockName ?? '');
|
|
125
|
+
const initialBlocks = this.config.data?.blocks;
|
|
126
|
+
const hasInitialBlocks = Array.isArray(initialBlocks) && initialBlocks.length > 0;
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
defaultBlockName &&
|
|
130
|
+
defaultBlockName !== 'paragraph' &&
|
|
131
|
+
!hasDefaultBlockTool &&
|
|
132
|
+
!hasInitialBlocks
|
|
133
|
+
) {
|
|
134
|
+
log(
|
|
135
|
+
`Default block "${defaultBlockName}" is not configured. Falling back to "paragraph" tool.`,
|
|
136
|
+
'warn'
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
this.config.defaultBlock = 'paragraph';
|
|
140
|
+
|
|
141
|
+
const existingTools = this.config.tools as Record<string, unknown> | undefined;
|
|
142
|
+
const updatedTools: Record<string, unknown> = {
|
|
143
|
+
...(existingTools ?? {}),
|
|
144
|
+
};
|
|
145
|
+
const paragraphEntry = updatedTools.paragraph;
|
|
146
|
+
|
|
147
|
+
updatedTools.paragraph = this.createParagraphToolConfig(paragraphEntry);
|
|
148
|
+
|
|
149
|
+
this.config.tools = updatedTools as BlokConfig['tools'];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Height of Blok's bottom area that allows to set focus on the last Block
|
|
154
|
+
* @type {number}
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
this.config.minHeight = this.config.minHeight !== undefined ? this.config.minHeight : 300;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Default block type
|
|
161
|
+
* Uses in case when there is no blocks passed
|
|
162
|
+
* @type {{type: (*), data: {text: null}}}
|
|
163
|
+
*/
|
|
164
|
+
const defaultBlockData = {
|
|
165
|
+
type: this.config.defaultBlock,
|
|
166
|
+
data: {},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
if (this.config.placeholder === undefined) {
|
|
170
|
+
this.config.placeholder = false;
|
|
171
|
+
}
|
|
172
|
+
this.config.sanitizer = this.config.sanitizer ?? {} as SanitizerConfig;
|
|
173
|
+
|
|
174
|
+
this.config.hideToolbar = this.config.hideToolbar ?? false;
|
|
175
|
+
this.config.tools = this.config.tools || {};
|
|
176
|
+
this.config.i18n = this.config.i18n || {};
|
|
177
|
+
this.config.data = this.config.data || { blocks: [] };
|
|
178
|
+
|
|
179
|
+
this.config.onReady = this.config.onReady || ((): void => {});
|
|
180
|
+
|
|
181
|
+
this.config.onChange = this.config.onChange || ((): void => {});
|
|
182
|
+
this.config.inlineToolbar = this.config.inlineToolbar !== undefined ? this.config.inlineToolbar : true;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Initialize default Block to pass data to the Renderer
|
|
186
|
+
*/
|
|
187
|
+
if (isEmpty(this.config.data) || !this.config.data.blocks || this.config.data.blocks.length === 0) {
|
|
188
|
+
this.config.data = { blocks: [ defaultBlockData ] };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
this.config.readOnly = this.config.readOnly as boolean || false;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Returns private property
|
|
196
|
+
* @returns {BlokConfig}
|
|
197
|
+
*/
|
|
198
|
+
public get configuration(): BlokConfig {
|
|
199
|
+
return this.config;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Checks for required fields in Blok's config
|
|
204
|
+
*/
|
|
205
|
+
public validate(): void {
|
|
206
|
+
const { holder } = this.config;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Check for a holder element's existence
|
|
210
|
+
*/
|
|
211
|
+
if (isString(holder) && !$.get(holder)) {
|
|
212
|
+
throw Error(`element with ID «${holder}» is missing. Pass correct holder's ID.`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (Boolean(holder) && isObject(holder) && !$.isElement(holder)) {
|
|
216
|
+
throw Error('«holder» value must be an Element node');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Initializes modules:
|
|
222
|
+
* - make and save instances
|
|
223
|
+
* - configure
|
|
224
|
+
*/
|
|
225
|
+
public init(): void {
|
|
226
|
+
/**
|
|
227
|
+
* Make modules instances and save it to the @property this.moduleInstances
|
|
228
|
+
*/
|
|
229
|
+
this.constructModules();
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Modules configuration
|
|
233
|
+
*/
|
|
234
|
+
this.configureModules();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Start Blok!
|
|
239
|
+
*
|
|
240
|
+
* Get list of modules that needs to be prepared and return a sequence (Promise)
|
|
241
|
+
* @returns {Promise<void>}
|
|
242
|
+
*/
|
|
243
|
+
public async start(): Promise<void> {
|
|
244
|
+
const modulesToPrepare = [
|
|
245
|
+
'I18n',
|
|
246
|
+
'Tools',
|
|
247
|
+
'UI',
|
|
248
|
+
'BlockManager',
|
|
249
|
+
'Paste',
|
|
250
|
+
'BlockSelection',
|
|
251
|
+
'RectangleSelection',
|
|
252
|
+
'CrossBlockSelection',
|
|
253
|
+
'ReadOnly',
|
|
254
|
+
'History',
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
await modulesToPrepare.reduce(
|
|
258
|
+
(promise, module) => promise.then(async () => {
|
|
259
|
+
// log(`Preparing ${module} module`, 'time');
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
const moduleInstance = this.moduleInstances[module as keyof BlokModules] as { prepare: () => Promise<void> | void };
|
|
263
|
+
|
|
264
|
+
await moduleInstance.prepare();
|
|
265
|
+
} catch (e) {
|
|
266
|
+
/**
|
|
267
|
+
* CriticalError's will not be caught
|
|
268
|
+
* It is used when Blok is rendering in read-only mode with unsupported plugin
|
|
269
|
+
*/
|
|
270
|
+
if (e instanceof CriticalError) {
|
|
271
|
+
throw new Error(e.message);
|
|
272
|
+
}
|
|
273
|
+
log(`Module ${module} was skipped because of %o`, 'warn', e);
|
|
274
|
+
}
|
|
275
|
+
// log(`Preparing ${module} module`, 'timeEnd');
|
|
276
|
+
}),
|
|
277
|
+
Promise.resolve()
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Render initial data
|
|
283
|
+
*/
|
|
284
|
+
private render(): Promise<void> {
|
|
285
|
+
const renderer = this.moduleInstances['Renderer' as keyof BlokModules] as Renderer | undefined;
|
|
286
|
+
|
|
287
|
+
if (!renderer) {
|
|
288
|
+
throw new CriticalError('Renderer module is not initialized');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!this.config.data) {
|
|
292
|
+
throw new CriticalError('Blok data is not initialized');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return renderer.render(this.config.data.blocks);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Make modules instances and save it to the @property this.moduleInstances
|
|
300
|
+
*/
|
|
301
|
+
private constructModules(): void {
|
|
302
|
+
Object.entries(Modules).forEach(([key, module]) => {
|
|
303
|
+
try {
|
|
304
|
+
(this.moduleInstances as unknown as Record<string, BlokModules[keyof BlokModules]>)[key] = new module({
|
|
305
|
+
config: this.configuration,
|
|
306
|
+
eventsDispatcher: this.eventsDispatcher,
|
|
307
|
+
}) as BlokModules[keyof BlokModules];
|
|
308
|
+
} catch (e) {
|
|
309
|
+
log(`[constructModules] Module ${key} skipped because`, 'error', e);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Modules instances configuration:
|
|
316
|
+
* - pass other modules to the 'state' property
|
|
317
|
+
* - ...
|
|
318
|
+
*/
|
|
319
|
+
private configureModules(): void {
|
|
320
|
+
for (const name in this.moduleInstances) {
|
|
321
|
+
if (Object.prototype.hasOwnProperty.call(this.moduleInstances, name)) {
|
|
322
|
+
/**
|
|
323
|
+
* Module does not need self-instance
|
|
324
|
+
*/
|
|
325
|
+
this.moduleInstances[name as keyof BlokModules].state = this.getModulesDiff(name);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Creates paragraph tool configuration with preserveBlank setting
|
|
332
|
+
* @param {unknown} paragraphEntry - existing paragraph entry from tools config
|
|
333
|
+
* @returns {Record<string, unknown>} paragraph tool configuration
|
|
334
|
+
*/
|
|
335
|
+
private createParagraphToolConfig(paragraphEntry: unknown): Record<string, unknown> {
|
|
336
|
+
if (paragraphEntry === undefined) {
|
|
337
|
+
return {
|
|
338
|
+
config: {
|
|
339
|
+
preserveBlank: true,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (isFunction(paragraphEntry)) {
|
|
345
|
+
return {
|
|
346
|
+
class: paragraphEntry,
|
|
347
|
+
config: {
|
|
348
|
+
preserveBlank: true,
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (isObject(paragraphEntry)) {
|
|
354
|
+
const paragraphSettings = paragraphEntry as Record<string, unknown>;
|
|
355
|
+
const existingConfig = paragraphSettings.config;
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
...paragraphSettings,
|
|
359
|
+
config: {
|
|
360
|
+
...(isObject(existingConfig) ? existingConfig as Record<string, unknown> : {}),
|
|
361
|
+
preserveBlank: true,
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
config: {
|
|
368
|
+
preserveBlank: true,
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Return modules without passed name
|
|
375
|
+
* @param {string} name - module for witch modules difference should be calculated
|
|
376
|
+
*/
|
|
377
|
+
private getModulesDiff(name: string): BlokModules {
|
|
378
|
+
const diff = {} as BlokModules;
|
|
379
|
+
|
|
380
|
+
for (const moduleName in this.moduleInstances) {
|
|
381
|
+
/**
|
|
382
|
+
* Skip module with passed name
|
|
383
|
+
*/
|
|
384
|
+
if (moduleName === name) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
(diff as unknown as Record<string, BlokModules[keyof BlokModules]>)[moduleName] = this.moduleInstances[moduleName as keyof BlokModules] as BlokModules[keyof BlokModules];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return diff;
|
|
391
|
+
}
|
|
392
|
+
}
|