@jackuait/blok 0.4.1-beta.0 → 0.4.1-beta.11
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 +138 -17
- package/codemod/README.md +45 -7
- package/codemod/migrate-editorjs-to-blok.js +960 -92
- package/codemod/test.js +780 -77
- package/dist/blok.mjs +5 -2
- package/dist/chunks/blok-oNSQ3HA6.mjs +13217 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-BdNRw4n4.mjs +43 -0
- package/dist/{index-OwEtDFlk.mjs → chunks/index-DHgXmfki.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-CRqgjRim.mjs +1989 -0
- package/dist/chunks/messages-0tDXLuyH.mjs +48 -0
- package/dist/chunks/messages-2_xedlYw.mjs +48 -0
- package/dist/chunks/messages-AHESHJm_.mjs +48 -0
- package/dist/chunks/messages-B5hdXZwA.mjs +48 -0
- package/dist/chunks/messages-B5jGUnOy.mjs +48 -0
- package/dist/chunks/messages-B5puUm7R.mjs +48 -0
- package/dist/chunks/messages-B66ZSDCJ.mjs +48 -0
- package/dist/chunks/messages-B9Oba7sq.mjs +48 -0
- package/dist/chunks/messages-BA0rcTCY.mjs +48 -0
- package/dist/chunks/messages-BBJgd5jG.mjs +48 -0
- package/dist/chunks/messages-BPqWKx5Z.mjs +48 -0
- package/dist/chunks/messages-Bdv-IkfG.mjs +48 -0
- package/dist/chunks/messages-BeUhMpsr.mjs +48 -0
- package/dist/chunks/messages-Bf6Y3_GI.mjs +48 -0
- package/dist/chunks/messages-BiExzWJv.mjs +48 -0
- package/dist/chunks/messages-BlpqL8vG.mjs +48 -0
- package/dist/chunks/messages-BmKCChWZ.mjs +48 -0
- package/dist/chunks/messages-Bn253WWC.mjs +48 -0
- package/dist/chunks/messages-BrJHUxQL.mjs +48 -0
- package/dist/chunks/messages-C5b7hr_E.mjs +48 -0
- package/dist/chunks/messages-C7I_AVH2.mjs +48 -0
- package/dist/chunks/messages-CJoBtXU6.mjs +48 -0
- package/dist/chunks/messages-CQj2JU2j.mjs +48 -0
- package/dist/chunks/messages-CUZ1x1QD.mjs +48 -0
- package/dist/chunks/messages-CUy1vn-b.mjs +48 -0
- package/dist/chunks/messages-CVeWVKsV.mjs +48 -0
- package/dist/chunks/messages-CXHd9SUK.mjs +48 -0
- package/dist/chunks/messages-CbMyJSzS.mjs +48 -0
- package/dist/chunks/messages-CbhuIWRJ.mjs +48 -0
- package/dist/chunks/messages-CeCjVKMW.mjs +48 -0
- package/dist/chunks/messages-Cj-t1bdy.mjs +48 -0
- package/dist/chunks/messages-CkFT2gle.mjs +48 -0
- package/dist/chunks/messages-Cm9aLHeX.mjs +48 -0
- package/dist/chunks/messages-CnvW8Slp.mjs +48 -0
- package/dist/chunks/messages-Cr-RJ7YB.mjs +48 -0
- package/dist/chunks/messages-CrsJ1TEJ.mjs +48 -0
- package/dist/chunks/messages-Cu08aLS3.mjs +48 -0
- package/dist/chunks/messages-CvaqJFN-.mjs +48 -0
- package/dist/chunks/messages-CyDU5lz9.mjs +48 -0
- package/dist/chunks/messages-CySyfkMU.mjs +48 -0
- package/dist/chunks/messages-Cyi2AMmz.mjs +48 -0
- package/dist/chunks/messages-D00OjS2n.mjs +48 -0
- package/dist/chunks/messages-DDLgIPDF.mjs +48 -0
- package/dist/chunks/messages-DMQIHGRj.mjs +48 -0
- package/dist/chunks/messages-DOlC_Tty.mjs +48 -0
- package/dist/chunks/messages-DV6shA9b.mjs +48 -0
- package/dist/chunks/messages-DY94ykcE.mjs +48 -0
- package/dist/chunks/messages-DbVquYKN.mjs +48 -0
- package/dist/chunks/messages-DcKOuncK.mjs +48 -0
- package/dist/chunks/messages-Dg92dXZ5.mjs +48 -0
- package/dist/chunks/messages-DnbbyJT3.mjs +48 -0
- package/dist/chunks/messages-DteYq0rv.mjs +48 -0
- package/dist/chunks/messages-GC2PhgV3.mjs +48 -0
- package/dist/chunks/messages-JGsXAReJ.mjs +48 -0
- package/dist/chunks/messages-JZUhXTuV.mjs +48 -0
- package/dist/chunks/messages-LvFKBBPa.mjs +48 -0
- package/dist/chunks/messages-NP1myMGI.mjs +48 -0
- package/dist/chunks/messages-Q4kc_ZtL.mjs +48 -0
- package/dist/chunks/messages-RvMHb2Ht.mjs +48 -0
- package/dist/chunks/messages-ftMcCEuO.mjs +48 -0
- package/dist/chunks/messages-o24dK6CU.mjs +48 -0
- package/dist/chunks/messages-pA5TvcAj.mjs +48 -0
- package/dist/chunks/messages-rRSHQDCX.mjs +48 -0
- package/dist/chunks/messages-srxrv8Yh.mjs +48 -0
- package/dist/chunks/messages-wdqp4610.mjs +48 -0
- package/dist/chunks/messages-zS1AXZ0y.mjs +48 -0
- package/dist/chunks/messages-zSzDzXej.mjs +48 -0
- package/dist/full.mjs +50 -0
- package/dist/locales.mjs +228 -0
- package/dist/messages-0tDXLuyH.mjs +48 -0
- package/dist/messages-2_xedlYw.mjs +48 -0
- package/dist/messages-AHESHJm_.mjs +48 -0
- package/dist/messages-B5hdXZwA.mjs +48 -0
- package/dist/messages-B5jGUnOy.mjs +48 -0
- package/dist/messages-B5puUm7R.mjs +48 -0
- package/dist/messages-B66ZSDCJ.mjs +48 -0
- package/dist/messages-B9Oba7sq.mjs +48 -0
- package/dist/messages-BA0rcTCY.mjs +48 -0
- package/dist/messages-BBJgd5jG.mjs +48 -0
- package/dist/messages-BPqWKx5Z.mjs +48 -0
- package/dist/messages-Bdv-IkfG.mjs +48 -0
- package/dist/messages-BeUhMpsr.mjs +48 -0
- package/dist/messages-Bf6Y3_GI.mjs +48 -0
- package/dist/messages-BiExzWJv.mjs +48 -0
- package/dist/messages-BlpqL8vG.mjs +48 -0
- package/dist/messages-BmKCChWZ.mjs +48 -0
- package/dist/messages-Bn253WWC.mjs +48 -0
- package/dist/messages-BrJHUxQL.mjs +48 -0
- package/dist/messages-C5b7hr_E.mjs +48 -0
- package/dist/messages-C7I_AVH2.mjs +48 -0
- package/dist/messages-CJoBtXU6.mjs +48 -0
- package/dist/messages-CQj2JU2j.mjs +48 -0
- package/dist/messages-CUZ1x1QD.mjs +48 -0
- package/dist/messages-CUy1vn-b.mjs +48 -0
- package/dist/messages-CVeWVKsV.mjs +48 -0
- package/dist/messages-CXHd9SUK.mjs +48 -0
- package/dist/messages-CbMyJSzS.mjs +48 -0
- package/dist/messages-CbhuIWRJ.mjs +48 -0
- package/dist/messages-CeCjVKMW.mjs +48 -0
- package/dist/messages-Cj-t1bdy.mjs +48 -0
- package/dist/messages-CkFT2gle.mjs +48 -0
- package/dist/messages-Cm9aLHeX.mjs +48 -0
- package/dist/messages-CnvW8Slp.mjs +48 -0
- package/dist/messages-Cr-RJ7YB.mjs +48 -0
- package/dist/messages-CrsJ1TEJ.mjs +48 -0
- package/dist/messages-Cu08aLS3.mjs +48 -0
- package/dist/messages-CvaqJFN-.mjs +48 -0
- package/dist/messages-CyDU5lz9.mjs +48 -0
- package/dist/messages-CySyfkMU.mjs +48 -0
- package/dist/messages-Cyi2AMmz.mjs +48 -0
- package/dist/messages-D00OjS2n.mjs +48 -0
- package/dist/messages-DDLgIPDF.mjs +48 -0
- package/dist/messages-DMQIHGRj.mjs +48 -0
- package/dist/messages-DOlC_Tty.mjs +48 -0
- package/dist/messages-DV6shA9b.mjs +48 -0
- package/dist/messages-DY94ykcE.mjs +48 -0
- package/dist/messages-DbVquYKN.mjs +48 -0
- package/dist/messages-DcKOuncK.mjs +48 -0
- package/dist/messages-Dg92dXZ5.mjs +48 -0
- package/dist/messages-DnbbyJT3.mjs +48 -0
- package/dist/messages-DteYq0rv.mjs +48 -0
- package/dist/messages-GC2PhgV3.mjs +48 -0
- package/dist/messages-JGsXAReJ.mjs +48 -0
- package/dist/messages-JZUhXTuV.mjs +48 -0
- package/dist/messages-LvFKBBPa.mjs +48 -0
- package/dist/messages-NP1myMGI.mjs +48 -0
- package/dist/messages-Q4kc_ZtL.mjs +48 -0
- package/dist/messages-RvMHb2Ht.mjs +48 -0
- package/dist/messages-ftMcCEuO.mjs +48 -0
- package/dist/messages-o24dK6CU.mjs +48 -0
- package/dist/messages-pA5TvcAj.mjs +48 -0
- package/dist/messages-rRSHQDCX.mjs +48 -0
- package/dist/messages-srxrv8Yh.mjs +48 -0
- package/dist/messages-wdqp4610.mjs +48 -0
- package/dist/messages-zS1AXZ0y.mjs +48 -0
- package/dist/messages-zSzDzXej.mjs +48 -0
- package/dist/tools.mjs +3117 -0
- package/dist/vendor.LICENSE.txt +26 -225
- package/package.json +63 -24
- 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 +1428 -0
- package/src/components/block-tunes/block-tune-delete.ts +51 -0
- package/src/components/blocks.ts +352 -0
- package/src/components/constants/data-attributes.ts +344 -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 +497 -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 +45 -0
- package/src/components/i18n/locales/ar/messages.json +45 -0
- package/src/components/i18n/locales/az/messages.json +45 -0
- package/src/components/i18n/locales/bg/messages.json +45 -0
- package/src/components/i18n/locales/bn/messages.json +45 -0
- package/src/components/i18n/locales/bs/messages.json +45 -0
- package/src/components/i18n/locales/cs/messages.json +45 -0
- package/src/components/i18n/locales/da/messages.json +45 -0
- package/src/components/i18n/locales/de/messages.json +45 -0
- package/src/components/i18n/locales/dv/messages.json +45 -0
- package/src/components/i18n/locales/el/messages.json +45 -0
- package/src/components/i18n/locales/en/messages.json +45 -0
- package/src/components/i18n/locales/es/messages.json +45 -0
- package/src/components/i18n/locales/et/messages.json +45 -0
- package/src/components/i18n/locales/fa/messages.json +45 -0
- package/src/components/i18n/locales/fi/messages.json +45 -0
- package/src/components/i18n/locales/fil/messages.json +45 -0
- package/src/components/i18n/locales/fr/messages.json +45 -0
- package/src/components/i18n/locales/gu/messages.json +45 -0
- package/src/components/i18n/locales/he/messages.json +45 -0
- package/src/components/i18n/locales/hi/messages.json +45 -0
- package/src/components/i18n/locales/hr/messages.json +45 -0
- package/src/components/i18n/locales/hu/messages.json +45 -0
- package/src/components/i18n/locales/hy/messages.json +45 -0
- package/src/components/i18n/locales/id/messages.json +45 -0
- package/src/components/i18n/locales/index.ts +231 -0
- package/src/components/i18n/locales/it/messages.json +45 -0
- package/src/components/i18n/locales/ja/messages.json +45 -0
- package/src/components/i18n/locales/ka/messages.json +45 -0
- package/src/components/i18n/locales/km/messages.json +45 -0
- package/src/components/i18n/locales/kn/messages.json +45 -0
- package/src/components/i18n/locales/ko/messages.json +45 -0
- package/src/components/i18n/locales/ku/messages.json +45 -0
- package/src/components/i18n/locales/lo/messages.json +45 -0
- package/src/components/i18n/locales/lt/messages.json +45 -0
- package/src/components/i18n/locales/lv/messages.json +45 -0
- package/src/components/i18n/locales/mk/messages.json +45 -0
- package/src/components/i18n/locales/ml/messages.json +45 -0
- package/src/components/i18n/locales/mn/messages.json +45 -0
- package/src/components/i18n/locales/mr/messages.json +45 -0
- package/src/components/i18n/locales/ms/messages.json +45 -0
- package/src/components/i18n/locales/my/messages.json +45 -0
- package/src/components/i18n/locales/ne/messages.json +45 -0
- package/src/components/i18n/locales/nl/messages.json +45 -0
- package/src/components/i18n/locales/no/messages.json +45 -0
- package/src/components/i18n/locales/pa/messages.json +45 -0
- package/src/components/i18n/locales/pl/messages.json +45 -0
- package/src/components/i18n/locales/ps/messages.json +45 -0
- package/src/components/i18n/locales/pt/messages.json +45 -0
- package/src/components/i18n/locales/ro/messages.json +45 -0
- package/src/components/i18n/locales/ru/messages.json +45 -0
- package/src/components/i18n/locales/sd/messages.json +45 -0
- package/src/components/i18n/locales/si/messages.json +45 -0
- package/src/components/i18n/locales/sk/messages.json +45 -0
- package/src/components/i18n/locales/sl/messages.json +45 -0
- package/src/components/i18n/locales/sq/messages.json +45 -0
- package/src/components/i18n/locales/sr/messages.json +45 -0
- package/src/components/i18n/locales/sv/messages.json +45 -0
- package/src/components/i18n/locales/sw/messages.json +45 -0
- package/src/components/i18n/locales/ta/messages.json +45 -0
- package/src/components/i18n/locales/te/messages.json +45 -0
- package/src/components/i18n/locales/th/messages.json +45 -0
- package/src/components/i18n/locales/tr/messages.json +45 -0
- package/src/components/i18n/locales/ug/messages.json +45 -0
- package/src/components/i18n/locales/uk/messages.json +45 -0
- package/src/components/i18n/locales/ur/messages.json +45 -0
- package/src/components/i18n/locales/vi/messages.json +45 -0
- package/src/components/i18n/locales/yi/messages.json +45 -0
- package/src/components/i18n/locales/zh/messages.json +45 -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 +377 -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 +35 -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 +1591 -0
- package/src/components/modules/blockManager.ts +1356 -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 +1204 -0
- package/src/components/modules/history.ts +1098 -0
- package/src/components/modules/i18n.ts +332 -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 +711 -0
- package/src/components/modules/renderer.ts +155 -0
- package/src/components/modules/saver.ts +283 -0
- package/src/components/modules/toolbar/blockSettings.ts +781 -0
- package/src/components/modules/toolbar/index.ts +1315 -0
- package/src/components/modules/toolbar/inline.ts +956 -0
- package/src/components/modules/tools.ts +625 -0
- package/src/components/modules/ui.ts +1283 -0
- package/src/components/polyfills.ts +113 -0
- package/src/components/selection.ts +1179 -0
- package/src/components/tools/base.ts +301 -0
- package/src/components/tools/block.ts +339 -0
- package/src/components/tools/collection.ts +67 -0
- package/src/components/tools/factory.ts +138 -0
- package/src/components/tools/inline.ts +71 -0
- package/src/components/tools/tune.ts +33 -0
- package/src/components/ui/toolbox.ts +601 -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 +680 -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 +186 -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 +178 -0
- package/src/components/utils/popover/components/search-input/search-input.types.ts +59 -0
- package/src/components/utils/popover/index.ts +13 -0
- package/src/components/utils/popover/popover-abstract.ts +457 -0
- package/src/components/utils/popover/popover-desktop.ts +676 -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 +110 -0
- package/src/components/utils/tooltip.ts +591 -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 +646 -0
- package/src/tools/index.ts +45 -0
- package/src/tools/list/index.ts +1819 -0
- package/src/tools/paragraph/index.ts +412 -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 +9 -1
- package/types/api/history.d.ts +7 -0
- package/types/api/i18n.d.ts +22 -3
- package/types/api/selection.d.ts +6 -0
- package/types/api/styles.d.ts +23 -10
- package/types/configs/blok-config.d.ts +29 -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 +170 -0
- package/types/data-formats/output-data.d.ts +15 -0
- package/types/full.d.ts +80 -0
- package/types/index.d.ts +30 -13
- 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 +92 -6
- package/types/tools/tool.d.ts +6 -0
- package/types/tools-entry.d.ts +49 -0
- package/types/utils/popover/popover-item.d.ts +18 -5
- package/types/utils/popover/popover.d.ts +7 -0
- package/dist/blok-D_baBvTG.mjs +0 -25795
- package/dist/blok.umd.js +0 -181
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Module } from '../__module';
|
|
2
|
+
import { log, logLabeled } from '../utils';
|
|
3
|
+
import type { BlockId, BlockToolData, OutputBlockData } from '../../../types';
|
|
4
|
+
import type { BlockToolAdapter } from '../tools/block';
|
|
5
|
+
import type { StubData } from '../../tools/stub';
|
|
6
|
+
import type { Block } from '../block';
|
|
7
|
+
import {
|
|
8
|
+
analyzeDataFormat,
|
|
9
|
+
expandToHierarchical,
|
|
10
|
+
shouldExpandToHierarchical,
|
|
11
|
+
type DataFormatAnalysis,
|
|
12
|
+
} from '../utils/data-model-transform';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Module that responsible for rendering Blocks on blok initialization
|
|
16
|
+
*/
|
|
17
|
+
export class Renderer extends Module {
|
|
18
|
+
/**
|
|
19
|
+
* Stores the detected input data format for use during save
|
|
20
|
+
*/
|
|
21
|
+
private detectedInputFormat: DataFormatAnalysis['format'] = 'flat';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get the detected input format
|
|
25
|
+
*/
|
|
26
|
+
public getDetectedInputFormat(): DataFormatAnalysis['format'] {
|
|
27
|
+
return this.detectedInputFormat;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Renders passed blocks as one batch
|
|
32
|
+
* @param blocksData - blocks to render
|
|
33
|
+
*/
|
|
34
|
+
public render(blocksData: OutputBlockData[]): Promise<void> {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const { Tools, BlockManager } = this.Blok;
|
|
37
|
+
|
|
38
|
+
if (blocksData.length === 0) {
|
|
39
|
+
BlockManager.insert();
|
|
40
|
+
} else {
|
|
41
|
+
// Analyze and potentially transform the input data
|
|
42
|
+
const dataModelConfig = this.config.dataModel || 'auto';
|
|
43
|
+
const analysis = analyzeDataFormat(blocksData);
|
|
44
|
+
this.detectedInputFormat = analysis.format;
|
|
45
|
+
|
|
46
|
+
// Transform to hierarchical if config requires it
|
|
47
|
+
const processedBlocks = shouldExpandToHierarchical(dataModelConfig, analysis.format)
|
|
48
|
+
? expandToHierarchical(blocksData)
|
|
49
|
+
: blocksData;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create Blocks instances
|
|
53
|
+
*/
|
|
54
|
+
const blocks = processedBlocks.map((blockData: OutputBlockData) => {
|
|
55
|
+
const { tunes, id, parent, content } = blockData;
|
|
56
|
+
const originalTool = blockData.type;
|
|
57
|
+
const availabilityResult = (() => {
|
|
58
|
+
if (Tools.available.has(originalTool)) {
|
|
59
|
+
return {
|
|
60
|
+
tool: originalTool,
|
|
61
|
+
data: blockData.data,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
logLabeled(`Tool «${originalTool}» is not found. Check 'tools' property at the Blok config.`, 'warn');
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
tool: Tools.stubTool,
|
|
69
|
+
data: this.composeStubDataForTool(originalTool, blockData.data, id),
|
|
70
|
+
};
|
|
71
|
+
})();
|
|
72
|
+
|
|
73
|
+
const buildBlock = (tool: string, data: BlockToolData): Block => {
|
|
74
|
+
try {
|
|
75
|
+
return BlockManager.composeBlock({
|
|
76
|
+
id,
|
|
77
|
+
tool,
|
|
78
|
+
data,
|
|
79
|
+
tunes,
|
|
80
|
+
parentId: parent,
|
|
81
|
+
contentIds: content,
|
|
82
|
+
});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
log(`Block «${tool}» skipped because of plugins error`, 'error', {
|
|
85
|
+
data,
|
|
86
|
+
error,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* If tool throws an error during render, we should render stub instead of it
|
|
91
|
+
*/
|
|
92
|
+
const stubData = this.composeStubDataForTool(tool, data, id);
|
|
93
|
+
|
|
94
|
+
return BlockManager.composeBlock({
|
|
95
|
+
id,
|
|
96
|
+
tool: Tools.stubTool,
|
|
97
|
+
data: stubData,
|
|
98
|
+
tunes,
|
|
99
|
+
parentId: parent,
|
|
100
|
+
contentIds: content,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return buildBlock(availabilityResult.tool, availabilityResult.data);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Insert batch of Blocks
|
|
110
|
+
*/
|
|
111
|
+
BlockManager.insertMany(blocks);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Wait till browser will render inserted Blocks and resolve a promise
|
|
116
|
+
*/
|
|
117
|
+
window.requestIdleCallback(() => {
|
|
118
|
+
resolve();
|
|
119
|
+
}, { timeout: 2000 });
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Create data for the Stub Tool that will be used instead of unavailable tool
|
|
125
|
+
* @param tool - unavailable tool name to stub
|
|
126
|
+
* @param data - data of unavailable block
|
|
127
|
+
* @param [id] - id of unavailable block
|
|
128
|
+
*/
|
|
129
|
+
private composeStubDataForTool(tool: string, data: BlockToolData, id?: BlockId): StubData {
|
|
130
|
+
const { Tools } = this.Blok;
|
|
131
|
+
|
|
132
|
+
const title = (() => {
|
|
133
|
+
if (!Tools.unavailable.has(tool)) {
|
|
134
|
+
return tool;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const toolboxSettings = (Tools.unavailable.get(tool) as BlockToolAdapter).toolbox;
|
|
138
|
+
|
|
139
|
+
if (toolboxSettings !== undefined && toolboxSettings[0].title !== undefined) {
|
|
140
|
+
return toolboxSettings[0].title;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return tool;
|
|
144
|
+
})();
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
savedData: {
|
|
148
|
+
id,
|
|
149
|
+
type: tool,
|
|
150
|
+
data,
|
|
151
|
+
},
|
|
152
|
+
title,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blok Saver
|
|
3
|
+
* @module Saver
|
|
4
|
+
* @author Blok Team
|
|
5
|
+
* @version 2.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { Module } from '../__module';
|
|
8
|
+
import type { BlockToolData, OutputData, SanitizerConfig } from '../../../types';
|
|
9
|
+
import type { SavedData, ValidatedData } from '../../../types/data-formats';
|
|
10
|
+
import type { BlockTuneData } from '../../../types/block-tunes/block-tune-data';
|
|
11
|
+
import type { Block } from '../block';
|
|
12
|
+
import { getBlokVersion, isEmpty, isObject, log, logLabeled } from '../utils';
|
|
13
|
+
import { sanitizeBlocks } from '../utils/sanitizer';
|
|
14
|
+
import { collapseToLegacy, shouldCollapseToLegacy } from '../utils/data-model-transform';
|
|
15
|
+
|
|
16
|
+
type SaverValidatedData = ValidatedData & {
|
|
17
|
+
tunes?: Record<string, BlockTuneData>;
|
|
18
|
+
/**
|
|
19
|
+
* Parent block id for hierarchical structure (Notion-like flat-with-references model)
|
|
20
|
+
*/
|
|
21
|
+
parentId?: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Array of child block ids (Notion-like flat-with-references model)
|
|
24
|
+
*/
|
|
25
|
+
contentIds?: string[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type SanitizableBlockData = SaverValidatedData & Pick<SavedData, 'data' | 'tool'>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @classdesc This method reduces all Blocks asyncronically and calls Block's save method to extract data
|
|
32
|
+
* @typedef {Saver} Saver
|
|
33
|
+
* @property {Element} html - Blok HTML content
|
|
34
|
+
* @property {string} json - Blok JSON output
|
|
35
|
+
*/
|
|
36
|
+
export class Saver extends Module {
|
|
37
|
+
/**
|
|
38
|
+
* Stores the last error raised during save attempt
|
|
39
|
+
*/
|
|
40
|
+
private lastSaveError?: unknown;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Composes new chain of Promises to fire them alternatelly
|
|
44
|
+
* @returns {OutputData | undefined}
|
|
45
|
+
*/
|
|
46
|
+
public async save(): Promise<OutputData | undefined> {
|
|
47
|
+
const { BlockManager, Tools } = this.Blok;
|
|
48
|
+
const blocks = BlockManager.blocks;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* If there is only one block and it is empty, we should return empty blocks array
|
|
52
|
+
*/
|
|
53
|
+
if (blocks.length === 1 && blocks[0].isEmpty) {
|
|
54
|
+
return {
|
|
55
|
+
time: +new Date(),
|
|
56
|
+
blocks: [],
|
|
57
|
+
version: getBlokVersion(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const chainData: Array<Promise<SaverValidatedData>> = blocks.map((block: Block) => {
|
|
62
|
+
return this.getSavedData(block);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this.lastSaveError = undefined;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const extractedData = await Promise.all(chainData);
|
|
69
|
+
const sanitizedData = this.sanitizeExtractedData(
|
|
70
|
+
extractedData,
|
|
71
|
+
(name) => Tools.blockTools.get(name)?.sanitizeConfig,
|
|
72
|
+
this.config.sanitizer as SanitizerConfig
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return this.makeOutput(sanitizedData);
|
|
76
|
+
} catch (error: unknown) {
|
|
77
|
+
this.lastSaveError = error;
|
|
78
|
+
|
|
79
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
80
|
+
|
|
81
|
+
logLabeled(`Saving failed due to the Error %o`, 'error', normalizedError);
|
|
82
|
+
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Saves and validates
|
|
89
|
+
* @param {Block} block - Blok's Tool
|
|
90
|
+
* @returns {ValidatedData} - Tool's validated data
|
|
91
|
+
*/
|
|
92
|
+
private async getSavedData(block: Block): Promise<SaverValidatedData> {
|
|
93
|
+
const blockData = await block.save();
|
|
94
|
+
const toolName = block.name;
|
|
95
|
+
const normalizedData = blockData?.data !== undefined
|
|
96
|
+
? blockData
|
|
97
|
+
: this.getPreservedSavedData(block);
|
|
98
|
+
|
|
99
|
+
if (normalizedData === undefined) {
|
|
100
|
+
return {
|
|
101
|
+
tool: toolName,
|
|
102
|
+
isValid: false,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const isValid = await block.validate(normalizedData.data);
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
...normalizedData,
|
|
110
|
+
isValid,
|
|
111
|
+
parentId: block.parentId,
|
|
112
|
+
contentIds: block.contentIds,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Creates output object with saved data, time and version of blok
|
|
118
|
+
* @param {ValidatedData} allExtractedData - data extracted from Blocks
|
|
119
|
+
* @returns {OutputData}
|
|
120
|
+
*/
|
|
121
|
+
private makeOutput(allExtractedData: SaverValidatedData[]): OutputData {
|
|
122
|
+
const extractedBlocks: OutputData['blocks'] = [];
|
|
123
|
+
|
|
124
|
+
allExtractedData.forEach(({ id, tool, data, tunes, isValid, parentId, contentIds }) => {
|
|
125
|
+
if (!isValid) {
|
|
126
|
+
log(`Block «${tool}» skipped because saved data is invalid`);
|
|
127
|
+
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (tool === undefined || data === undefined) {
|
|
132
|
+
log('Block skipped because saved data is missing required fields');
|
|
133
|
+
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** If it was stub Block, get original data */
|
|
138
|
+
if (tool === this.Blok.Tools.stubTool && this.isStubSavedData(data)) {
|
|
139
|
+
extractedBlocks.push(data);
|
|
140
|
+
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (tool === this.Blok.Tools.stubTool) {
|
|
145
|
+
log('Stub block data is malformed and was skipped');
|
|
146
|
+
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const isTunesEmpty = tunes === undefined || isEmpty(tunes);
|
|
151
|
+
const hasParent = parentId !== undefined && parentId !== null;
|
|
152
|
+
const hasContent = contentIds !== undefined && contentIds.length > 0;
|
|
153
|
+
|
|
154
|
+
const output: OutputData['blocks'][number] = {
|
|
155
|
+
id,
|
|
156
|
+
type: tool,
|
|
157
|
+
data,
|
|
158
|
+
...!isTunesEmpty && {
|
|
159
|
+
tunes,
|
|
160
|
+
},
|
|
161
|
+
...hasParent && {
|
|
162
|
+
parent: parentId,
|
|
163
|
+
},
|
|
164
|
+
...hasContent && {
|
|
165
|
+
content: contentIds,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
extractedBlocks.push(output);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Apply data model transformation if needed
|
|
173
|
+
const dataModelConfig = this.config.dataModel || 'auto';
|
|
174
|
+
const detectedInputFormat = this.Blok.Renderer?.getDetectedInputFormat?.() ?? 'flat';
|
|
175
|
+
|
|
176
|
+
const finalBlocks = shouldCollapseToLegacy(dataModelConfig, detectedInputFormat)
|
|
177
|
+
? collapseToLegacy(extractedBlocks)
|
|
178
|
+
: extractedBlocks;
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
time: +new Date(),
|
|
182
|
+
blocks: finalBlocks,
|
|
183
|
+
version: getBlokVersion(),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Sanitizes extracted block data in-place
|
|
189
|
+
* @param extractedData - collection of saved block data
|
|
190
|
+
* @param getToolSanitizeConfig - resolver for tool-specific sanitize config
|
|
191
|
+
* @param globalSanitizer - global sanitizer config specified in blok settings
|
|
192
|
+
*/
|
|
193
|
+
private sanitizeExtractedData(
|
|
194
|
+
extractedData: SaverValidatedData[],
|
|
195
|
+
getToolSanitizeConfig: (toolName: string) => SanitizerConfig | undefined,
|
|
196
|
+
globalSanitizer: SanitizerConfig
|
|
197
|
+
): SaverValidatedData[] {
|
|
198
|
+
const blocksToSanitize: Array<{ index: number; data: SanitizableBlockData }> = [];
|
|
199
|
+
|
|
200
|
+
extractedData.forEach((blockData, index) => {
|
|
201
|
+
if (this.hasSanitizableData(blockData)) {
|
|
202
|
+
blocksToSanitize.push({
|
|
203
|
+
index,
|
|
204
|
+
data: blockData,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (blocksToSanitize.length === 0) {
|
|
210
|
+
return extractedData;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const sanitizedBlocks = sanitizeBlocks(
|
|
214
|
+
blocksToSanitize.map(({ data }) => data),
|
|
215
|
+
getToolSanitizeConfig,
|
|
216
|
+
globalSanitizer
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const updatedData = extractedData.map((blockData) => ({ ...blockData }));
|
|
220
|
+
|
|
221
|
+
blocksToSanitize.forEach(({ index }, sanitizedIndex) => {
|
|
222
|
+
const sanitized = sanitizedBlocks[sanitizedIndex];
|
|
223
|
+
|
|
224
|
+
updatedData[index] = {
|
|
225
|
+
...updatedData[index],
|
|
226
|
+
data: sanitized.data,
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return updatedData;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Checks whether block data contains fields required for sanitizing procedure
|
|
235
|
+
* @param blockData - data to check
|
|
236
|
+
*/
|
|
237
|
+
private hasSanitizableData(blockData: SaverValidatedData): blockData is SanitizableBlockData {
|
|
238
|
+
return blockData.data !== undefined && typeof blockData.tool === 'string';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Check that stub data matches OutputBlockData format
|
|
243
|
+
* @param data - saved stub data that should represent original block payload
|
|
244
|
+
*/
|
|
245
|
+
private isStubSavedData(data: BlockToolData): data is OutputData['blocks'][number] {
|
|
246
|
+
if (!isObject(data)) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const candidate = data as Record<string, unknown>;
|
|
251
|
+
|
|
252
|
+
return typeof candidate.type === 'string' && candidate.data !== undefined;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Returns the last error raised during save attempt
|
|
257
|
+
*/
|
|
258
|
+
public getLastSaveError(): unknown {
|
|
259
|
+
return this.lastSaveError;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Returns the last successfully extracted data for the provided block, if any.
|
|
264
|
+
* @param block - block whose preserved data should be returned
|
|
265
|
+
*/
|
|
266
|
+
private getPreservedSavedData(block: Block): (SavedData & { tunes?: Record<string, BlockTuneData> }) | undefined {
|
|
267
|
+
const preservedData = block.preservedData;
|
|
268
|
+
|
|
269
|
+
if (isEmpty(preservedData)) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const preservedTunes = block.preservedTunes;
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
id: block.id,
|
|
277
|
+
tool: block.name,
|
|
278
|
+
data: preservedData,
|
|
279
|
+
...( isEmpty(preservedTunes) ? {} : { tunes: preservedTunes }),
|
|
280
|
+
time: 0,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|