@jackuait/blok 0.4.1-beta.1 → 0.4.1-beta.12
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-BU6NwVkN.mjs +13239 -0
- package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
- package/dist/chunks/i18next-loader-D8GzSwio.mjs +43 -0
- package/dist/{index-CEXLTV6f.mjs → chunks/index-C5e_WLFg.mjs} +2 -2
- package/dist/chunks/inline-tool-convert-CLUxkCe_.mjs +1990 -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 +3126 -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 +142 -0
- package/src/components/inline-tools/inline-tool-italic.ts +500 -0
- package/src/components/inline-tools/inline-tool-link.ts +540 -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 +782 -0
- package/src/components/modules/toolbar/index.ts +1296 -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 +610 -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 +197 -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 +682 -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 +759 -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 +126 -0
- package/src/tools/header/index.ts +647 -0
- package/src/tools/index.ts +45 -0
- package/src/tools/list/index.ts +1826 -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/configs/sanitizer-config.d.ts +25 -1
- 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 +11 -2
- 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 +99 -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 +24 -5
- package/types/utils/popover/popover.d.ts +13 -0
- package/dist/blok-C8XbyLHh.mjs +0 -25795
- package/dist/blok.umd.js +0 -181
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { SelectionUtils } from '../selection';
|
|
2
|
+
import { log } from '../utils';
|
|
3
|
+
import type {
|
|
4
|
+
InlineTool,
|
|
5
|
+
InlineToolConstructorOptions,
|
|
6
|
+
SanitizerConfig
|
|
7
|
+
} from '../../../types';
|
|
8
|
+
import { PopoverItemType } from '../utils/popover';
|
|
9
|
+
import type { Notifier, Toolbar, I18n, InlineToolbar } from '../../../types/api';
|
|
10
|
+
import type { MenuConfig } from '../../../types/tools';
|
|
11
|
+
import { IconLink } from '../icons';
|
|
12
|
+
import { DATA_ATTR, createSelector, INLINE_TOOLBAR_INTERFACE_VALUE } from '../constants';
|
|
13
|
+
import { twMerge } from '../utils/tw';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Link Tool
|
|
17
|
+
*
|
|
18
|
+
* Inline Toolbar Tool
|
|
19
|
+
*
|
|
20
|
+
* Wrap selected text with <a> tag
|
|
21
|
+
*/
|
|
22
|
+
export class LinkInlineTool implements InlineTool {
|
|
23
|
+
/**
|
|
24
|
+
* Specifies Tool as Inline Toolbar Tool
|
|
25
|
+
* @returns {boolean}
|
|
26
|
+
*/
|
|
27
|
+
public static isInline = true;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Title for the Inline Tool
|
|
31
|
+
*/
|
|
32
|
+
public static title = 'Link';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Translation key for i18n
|
|
36
|
+
*/
|
|
37
|
+
public static titleKey = 'link';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sanitizer Rule
|
|
41
|
+
* Leave <a> tags
|
|
42
|
+
* @returns {object}
|
|
43
|
+
*/
|
|
44
|
+
public static get sanitize(): SanitizerConfig {
|
|
45
|
+
return {
|
|
46
|
+
a: {
|
|
47
|
+
href: true,
|
|
48
|
+
target: '_blank',
|
|
49
|
+
rel: 'nofollow',
|
|
50
|
+
},
|
|
51
|
+
} as SanitizerConfig;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Tailwind classes for input
|
|
56
|
+
*/
|
|
57
|
+
private readonly INPUT_BASE_CLASSES = 'hidden w-full m-0 px-2 py-1 text-sm leading-[22px] font-medium bg-item-hover-bg border border-[rgba(226,226,229,0.2)] rounded-md outline-none box-border appearance-none font-[inherit] placeholder:text-gray-text mobile:text-[15px] mobile:font-medium';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Data attributes for e2e selectors
|
|
61
|
+
*/
|
|
62
|
+
private readonly DATA_ATTRIBUTES = {
|
|
63
|
+
buttonActive: 'data-blok-link-tool-active',
|
|
64
|
+
buttonUnlink: 'data-blok-link-tool-unlink',
|
|
65
|
+
inputOpened: 'data-blok-link-tool-input-opened',
|
|
66
|
+
} as const;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Elements
|
|
70
|
+
*/
|
|
71
|
+
private nodes: {
|
|
72
|
+
input: HTMLInputElement | null;
|
|
73
|
+
button: HTMLButtonElement | null;
|
|
74
|
+
} = {
|
|
75
|
+
input: null,
|
|
76
|
+
button: null,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* SelectionUtils instance
|
|
81
|
+
*/
|
|
82
|
+
private selection: SelectionUtils;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Input opening state
|
|
86
|
+
*/
|
|
87
|
+
private inputOpened = false;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Tracks whether unlink action is available via toolbar button toggle
|
|
91
|
+
*/
|
|
92
|
+
private unlinkAvailable = false;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Available Toolbar methods (open/close)
|
|
96
|
+
*/
|
|
97
|
+
private toolbar: Toolbar;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Available inline toolbar methods (open/close)
|
|
101
|
+
*/
|
|
102
|
+
private inlineToolbar: InlineToolbar;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Notifier API methods
|
|
106
|
+
*/
|
|
107
|
+
private notifier: Notifier;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* I18n API
|
|
111
|
+
*/
|
|
112
|
+
private i18n: I18n;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param api - Blok API
|
|
116
|
+
*/
|
|
117
|
+
constructor({ api }: InlineToolConstructorOptions) {
|
|
118
|
+
this.toolbar = api.toolbar;
|
|
119
|
+
this.inlineToolbar = api.inlineToolbar;
|
|
120
|
+
this.notifier = api.notifier;
|
|
121
|
+
this.i18n = api.i18n;
|
|
122
|
+
this.selection = new SelectionUtils();
|
|
123
|
+
this.nodes.input = this.createInput();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Create button for Inline Toolbar
|
|
128
|
+
*/
|
|
129
|
+
public render(): MenuConfig {
|
|
130
|
+
return {
|
|
131
|
+
icon: IconLink,
|
|
132
|
+
name: 'link',
|
|
133
|
+
isActive: () => !!this.selection.findParentTag('A'),
|
|
134
|
+
children: {
|
|
135
|
+
hideChevron: true,
|
|
136
|
+
width: '200px',
|
|
137
|
+
items: [
|
|
138
|
+
{
|
|
139
|
+
type: PopoverItemType.Html,
|
|
140
|
+
element: this.nodes.input!,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
onOpen: () => {
|
|
144
|
+
this.openActions(true);
|
|
145
|
+
},
|
|
146
|
+
onClose: () => {
|
|
147
|
+
this.closeActions();
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Input for the link
|
|
155
|
+
*/
|
|
156
|
+
private createInput(): HTMLInputElement {
|
|
157
|
+
const input = document.createElement('input') as HTMLInputElement;
|
|
158
|
+
|
|
159
|
+
input.placeholder = this.i18n.t('tools.link.addLink');
|
|
160
|
+
input.enterKeyHint = 'done';
|
|
161
|
+
input.className = this.INPUT_BASE_CLASSES;
|
|
162
|
+
input.setAttribute('data-blok-testid', 'inline-tool-input');
|
|
163
|
+
this.setBooleanStateAttribute(input, this.DATA_ATTRIBUTES.inputOpened, false);
|
|
164
|
+
input.addEventListener('keydown', (event: KeyboardEvent) => {
|
|
165
|
+
if (event.key === 'Enter') {
|
|
166
|
+
this.enterPressed(event);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return input;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Shortcut for the link tool
|
|
175
|
+
*/
|
|
176
|
+
public static shortcut = 'CMD+K';
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {boolean} needFocus - on link creation we need to focus input. On editing - nope.
|
|
180
|
+
*/
|
|
181
|
+
private openActions(needFocus = false): void {
|
|
182
|
+
if (!this.nodes.input) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const anchorTag = this.selection.findParentTag('A');
|
|
187
|
+
|
|
188
|
+
const hasAnchor = Boolean(anchorTag);
|
|
189
|
+
|
|
190
|
+
this.updateButtonStateAttributes(hasAnchor);
|
|
191
|
+
this.unlinkAvailable = hasAnchor;
|
|
192
|
+
|
|
193
|
+
if (anchorTag) {
|
|
194
|
+
/**
|
|
195
|
+
* Fill input value with link href
|
|
196
|
+
*/
|
|
197
|
+
const hrefAttr = anchorTag.getAttribute('href');
|
|
198
|
+
|
|
199
|
+
this.nodes.input.value = hrefAttr !== null ? hrefAttr : '';
|
|
200
|
+
} else {
|
|
201
|
+
this.nodes.input.value = '';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
this.nodes.input.className = twMerge(this.INPUT_BASE_CLASSES, 'block');
|
|
205
|
+
this.setBooleanStateAttribute(this.nodes.input, this.DATA_ATTRIBUTES.inputOpened, true);
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Set fake background to visually indicate selection when focus moves to input
|
|
209
|
+
*/
|
|
210
|
+
this.selection.setFakeBackground();
|
|
211
|
+
this.selection.save();
|
|
212
|
+
|
|
213
|
+
if (needFocus) {
|
|
214
|
+
this.focusInputWithRetry();
|
|
215
|
+
}
|
|
216
|
+
this.inputOpened = true;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Ensures the link input receives focus even if other listeners steal it
|
|
220
|
+
*/
|
|
221
|
+
private focusInputWithRetry(): void {
|
|
222
|
+
if (!this.nodes.input) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this.nodes.input.focus();
|
|
227
|
+
|
|
228
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
window.setTimeout(() => {
|
|
233
|
+
if (document.activeElement !== this.nodes.input) {
|
|
234
|
+
this.nodes.input?.focus();
|
|
235
|
+
}
|
|
236
|
+
}, 0);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Resolve the current inline toolbar button element
|
|
241
|
+
*/
|
|
242
|
+
private getButtonElement(): HTMLButtonElement | null {
|
|
243
|
+
// Always query fresh to ensure we have the latest DOM element
|
|
244
|
+
const button = document.querySelector<HTMLButtonElement>(
|
|
245
|
+
`${createSelector(DATA_ATTR.interface, INLINE_TOOLBAR_INTERFACE_VALUE)} [data-blok-item-name="link"]`
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// Only add click listener if this is a new button element
|
|
249
|
+
if (button && button !== this.nodes.button) {
|
|
250
|
+
button.addEventListener('click', this.handleButtonClick, true);
|
|
251
|
+
this.nodes.button = button;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return button;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Update button state attributes for e2e hooks
|
|
259
|
+
* @param hasAnchor - Optional override for anchor presence
|
|
260
|
+
*/
|
|
261
|
+
private updateButtonStateAttributes(hasAnchor?: boolean): void {
|
|
262
|
+
const button = this.getButtonElement();
|
|
263
|
+
|
|
264
|
+
if (!button) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const anchorPresent = typeof hasAnchor === 'boolean' ? hasAnchor : Boolean(this.selection.findParentTag('A'));
|
|
269
|
+
|
|
270
|
+
this.setBooleanStateAttribute(button, this.DATA_ATTRIBUTES.buttonActive, anchorPresent);
|
|
271
|
+
this.setBooleanStateAttribute(button, this.DATA_ATTRIBUTES.buttonUnlink, anchorPresent);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Handles toggling the inline tool button while actions menu is open
|
|
276
|
+
* @param event - Click event emitted by the inline tool button
|
|
277
|
+
*/
|
|
278
|
+
private handleButtonClick = (event: MouseEvent): void => {
|
|
279
|
+
if (!this.inputOpened || !this.unlinkAvailable) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
event.preventDefault();
|
|
284
|
+
event.stopPropagation();
|
|
285
|
+
event.stopImmediatePropagation();
|
|
286
|
+
|
|
287
|
+
this.restoreSelection();
|
|
288
|
+
this.unlink();
|
|
289
|
+
this.inlineToolbar.close();
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Close input
|
|
295
|
+
* @param {boolean} clearSavedSelection — we don't need to clear saved selection
|
|
296
|
+
* on toggle-clicks on the icon of opened Toolbar
|
|
297
|
+
*/
|
|
298
|
+
private closeActions(clearSavedSelection = true): void {
|
|
299
|
+
const shouldRestoreSelection = this.selection.isFakeBackgroundEnabled ||
|
|
300
|
+
(clearSavedSelection && !!this.selection.savedSelectionRange);
|
|
301
|
+
|
|
302
|
+
if (shouldRestoreSelection) {
|
|
303
|
+
this.restoreSelection();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!this.nodes.input) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
this.nodes.input.className = this.INPUT_BASE_CLASSES;
|
|
310
|
+
this.setBooleanStateAttribute(this.nodes.input, this.DATA_ATTRIBUTES.inputOpened, false);
|
|
311
|
+
this.nodes.input.value = '';
|
|
312
|
+
this.updateButtonStateAttributes(false);
|
|
313
|
+
this.unlinkAvailable = false;
|
|
314
|
+
if (clearSavedSelection) {
|
|
315
|
+
this.selection.clearSaved();
|
|
316
|
+
}
|
|
317
|
+
this.inputOpened = false;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Restore selection after closing actions
|
|
322
|
+
*/
|
|
323
|
+
private restoreSelection(): void {
|
|
324
|
+
// if actions is broken by other selection We need to save new selection
|
|
325
|
+
const currentSelection = new SelectionUtils();
|
|
326
|
+
const isSelectionInBlok = SelectionUtils.isAtBlok;
|
|
327
|
+
|
|
328
|
+
if (isSelectionInBlok) {
|
|
329
|
+
currentSelection.save();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
this.selection.removeFakeBackground();
|
|
333
|
+
this.selection.restore();
|
|
334
|
+
|
|
335
|
+
// and recover new selection after removing fake background
|
|
336
|
+
if (!isSelectionInBlok && this.selection.savedSelectionRange) {
|
|
337
|
+
const range = this.selection.savedSelectionRange;
|
|
338
|
+
const container = range.commonAncestorContainer;
|
|
339
|
+
const element = container.nodeType === Node.ELEMENT_NODE ? container as HTMLElement : container.parentElement;
|
|
340
|
+
|
|
341
|
+
element?.focus();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (!isSelectionInBlok) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
currentSelection.restore();
|
|
349
|
+
|
|
350
|
+
const range = currentSelection.savedSelectionRange;
|
|
351
|
+
|
|
352
|
+
if (range) {
|
|
353
|
+
const container = range.commonAncestorContainer;
|
|
354
|
+
const element = container.nodeType === Node.ELEMENT_NODE ? container as HTMLElement : container.parentElement;
|
|
355
|
+
|
|
356
|
+
element?.focus();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Enter pressed on input
|
|
362
|
+
* @param {KeyboardEvent} event - enter keydown event
|
|
363
|
+
*/
|
|
364
|
+
private enterPressed(event: KeyboardEvent): void {
|
|
365
|
+
if (!this.nodes.input) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const value = this.nodes.input.value || '';
|
|
369
|
+
|
|
370
|
+
if (!value.trim()) {
|
|
371
|
+
this.selection.restore();
|
|
372
|
+
this.unlink();
|
|
373
|
+
event.preventDefault();
|
|
374
|
+
this.closeActions();
|
|
375
|
+
// Explicitly close inline toolbar as well, similar to legacy behavior
|
|
376
|
+
this.inlineToolbar.close();
|
|
377
|
+
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (!this.validateURL(value)) {
|
|
382
|
+
this.notifier.show({
|
|
383
|
+
message: this.i18n.t('tools.link.invalidLink'),
|
|
384
|
+
style: 'error',
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
log('Incorrect Link pasted', 'warn', value);
|
|
388
|
+
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const preparedValue = this.prepareLink(value);
|
|
393
|
+
|
|
394
|
+
this.selection.removeFakeBackground();
|
|
395
|
+
this.selection.restore();
|
|
396
|
+
|
|
397
|
+
this.insertLink(preparedValue);
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Preventing events that will be able to happen
|
|
401
|
+
*/
|
|
402
|
+
event.preventDefault();
|
|
403
|
+
event.stopPropagation();
|
|
404
|
+
event.stopImmediatePropagation();
|
|
405
|
+
this.selection.collapseToEnd();
|
|
406
|
+
this.inlineToolbar.close();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Detects if passed string is URL
|
|
411
|
+
* @param {string} str - string to validate
|
|
412
|
+
* @returns {boolean}
|
|
413
|
+
*/
|
|
414
|
+
private validateURL(str: string): boolean {
|
|
415
|
+
/**
|
|
416
|
+
* Don't allow spaces
|
|
417
|
+
*/
|
|
418
|
+
return !/\s/.test(str);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Process link before injection
|
|
423
|
+
* - sanitize
|
|
424
|
+
* - add protocol for links like 'google.com'
|
|
425
|
+
* @param {string} link - raw user input
|
|
426
|
+
*/
|
|
427
|
+
private prepareLink(link: string): string {
|
|
428
|
+
return this.addProtocol(link.trim());
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Add 'http' protocol to the links like 'vc.ru', 'google.com'
|
|
433
|
+
* @param {string} link - string to process
|
|
434
|
+
*/
|
|
435
|
+
private addProtocol(link: string): string {
|
|
436
|
+
/**
|
|
437
|
+
* If protocol already exists, do nothing
|
|
438
|
+
*/
|
|
439
|
+
if (/^(\w+):(\/\/)?/.test(link)) {
|
|
440
|
+
return link;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* We need to add missed HTTP protocol to the link, but skip 2 cases:
|
|
445
|
+
* 1) Internal links like "/general"
|
|
446
|
+
* 2) Anchors looks like "#results"
|
|
447
|
+
* 3) Protocol-relative URLs like "//google.com"
|
|
448
|
+
*/
|
|
449
|
+
const isInternal = /^\/[^/\s]/.test(link);
|
|
450
|
+
const isAnchor = link.substring(0, 1) === '#';
|
|
451
|
+
const isProtocolRelative = /^\/\/[^/\s]/.test(link);
|
|
452
|
+
|
|
453
|
+
if (!isInternal && !isAnchor && !isProtocolRelative) {
|
|
454
|
+
return 'http://' + link;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return link;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Inserts <a> tag with "href"
|
|
462
|
+
* @param {string} link - "href" value
|
|
463
|
+
*/
|
|
464
|
+
private insertLink(link: string): void {
|
|
465
|
+
/**
|
|
466
|
+
* Edit all link, not selected part
|
|
467
|
+
*/
|
|
468
|
+
const anchorTag = this.selection.findParentTag('A') as HTMLAnchorElement;
|
|
469
|
+
|
|
470
|
+
if (anchorTag) {
|
|
471
|
+
this.selection.expandToTag(anchorTag);
|
|
472
|
+
|
|
473
|
+
anchorTag.href = link;
|
|
474
|
+
anchorTag.target = '_blank';
|
|
475
|
+
anchorTag.rel = 'nofollow';
|
|
476
|
+
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const range = SelectionUtils.range;
|
|
481
|
+
|
|
482
|
+
if (!range) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const anchor = document.createElement('a');
|
|
487
|
+
|
|
488
|
+
anchor.href = link;
|
|
489
|
+
anchor.target = '_blank';
|
|
490
|
+
anchor.rel = 'nofollow';
|
|
491
|
+
|
|
492
|
+
anchor.appendChild(range.extractContents());
|
|
493
|
+
|
|
494
|
+
range.insertNode(anchor);
|
|
495
|
+
|
|
496
|
+
this.selection.expandToTag(anchor);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Removes <a> tag
|
|
501
|
+
*/
|
|
502
|
+
private unlink(): void {
|
|
503
|
+
const anchorTag = this.selection.findParentTag('A');
|
|
504
|
+
|
|
505
|
+
if (anchorTag) {
|
|
506
|
+
this.unwrap(anchorTag);
|
|
507
|
+
this.updateButtonStateAttributes(false);
|
|
508
|
+
this.unlinkAvailable = false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Unwrap passed node
|
|
514
|
+
* @param term - node to unwrap
|
|
515
|
+
*/
|
|
516
|
+
private unwrap(term: HTMLElement): void {
|
|
517
|
+
const docFrag = document.createDocumentFragment();
|
|
518
|
+
|
|
519
|
+
while (term.firstChild) {
|
|
520
|
+
docFrag.appendChild(term.firstChild);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
term.parentNode?.replaceChild(docFrag, term);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Persist state as data attributes for testing hooks
|
|
528
|
+
* @param element - The HTML element to set the attribute on, or null
|
|
529
|
+
* @param attributeName - The name of the attribute to set
|
|
530
|
+
* @param state - The boolean state value to persist
|
|
531
|
+
*/
|
|
532
|
+
private setBooleanStateAttribute(element: HTMLElement | null, attributeName: string, state: boolean): void {
|
|
533
|
+
if (!element) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
element.setAttribute(attributeName, state ? 'true' : 'false');
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|