@jackuait/blok 0.4.1 → 0.4.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (397) hide show
  1. package/README.md +136 -17
  2. package/codemod/README.md +45 -7
  3. package/codemod/migrate-editorjs-to-blok.js +951 -92
  4. package/codemod/test.js +780 -77
  5. package/dist/blok.mjs +5 -2
  6. package/dist/chunks/blok-8ptWuVZC.mjs +12838 -0
  7. package/dist/chunks/i18next-CugVlwWp.mjs +1292 -0
  8. package/dist/chunks/i18next-loader-bLawSYRV.mjs +43 -0
  9. package/dist/{index-CBkApZKo.mjs → chunks/index-5nYtWZD2.mjs} +2 -2
  10. package/dist/chunks/inline-tool-convert-CvMDAIzb.mjs +1988 -0
  11. package/dist/chunks/messages-2434tVOK.mjs +47 -0
  12. package/dist/chunks/messages-3DcCwXMF.mjs +47 -0
  13. package/dist/chunks/messages-4kMwVAKY.mjs +47 -0
  14. package/dist/chunks/messages-57uL5htT.mjs +47 -0
  15. package/dist/chunks/messages-76-iJV9Q.mjs +47 -0
  16. package/dist/chunks/messages-8p86Eyf2.mjs +47 -0
  17. package/dist/chunks/messages-BBX0p0Pi.mjs +47 -0
  18. package/dist/chunks/messages-BCm2eudQ.mjs +47 -0
  19. package/dist/chunks/messages-BFiUomgG.mjs +47 -0
  20. package/dist/chunks/messages-BIPNHHAV.mjs +47 -0
  21. package/dist/chunks/messages-BUlwu9mo.mjs +47 -0
  22. package/dist/chunks/messages-BX-DPa-z.mjs +47 -0
  23. package/dist/chunks/messages-BextV3Qh.mjs +47 -0
  24. package/dist/chunks/messages-BiPSFlUG.mjs +47 -0
  25. package/dist/chunks/messages-BiXe9G-O.mjs +47 -0
  26. package/dist/chunks/messages-Bl5z_Igo.mjs +47 -0
  27. package/dist/chunks/messages-BnsE97ku.mjs +47 -0
  28. package/dist/chunks/messages-BoO8gsVD.mjs +47 -0
  29. package/dist/chunks/messages-BqWaOGMn.mjs +47 -0
  30. package/dist/chunks/messages-BqkL2_Ro.mjs +47 -0
  31. package/dist/chunks/messages-BvCkXKX-.mjs +47 -0
  32. package/dist/chunks/messages-C6tbPLoj.mjs +47 -0
  33. package/dist/chunks/messages-CA6T3-gQ.mjs +47 -0
  34. package/dist/chunks/messages-CFFPFdWP.mjs +47 -0
  35. package/dist/chunks/messages-CFrKE-TN.mjs +47 -0
  36. package/dist/chunks/messages-CHz8VlG-.mjs +47 -0
  37. package/dist/chunks/messages-CLixzySl.mjs +47 -0
  38. package/dist/chunks/messages-CV7OM_qk.mjs +47 -0
  39. package/dist/chunks/messages-CXHt3eCC.mjs +47 -0
  40. package/dist/chunks/messages-CbmsBrB0.mjs +47 -0
  41. package/dist/chunks/messages-Ceo1KtFx.mjs +47 -0
  42. package/dist/chunks/messages-Cm0LJLtB.mjs +47 -0
  43. package/dist/chunks/messages-CmymP_Ar.mjs +47 -0
  44. package/dist/chunks/messages-D0ohMB5H.mjs +47 -0
  45. package/dist/chunks/messages-D3GrDwXh.mjs +47 -0
  46. package/dist/chunks/messages-D3vTzIpL.mjs +47 -0
  47. package/dist/chunks/messages-D5WeksbV.mjs +47 -0
  48. package/dist/chunks/messages-DGaab4EP.mjs +47 -0
  49. package/dist/chunks/messages-DKha57ZU.mjs +47 -0
  50. package/dist/chunks/messages-DOaujgMW.mjs +47 -0
  51. package/dist/chunks/messages-DVbPLd_0.mjs +47 -0
  52. package/dist/chunks/messages-D_FCyfW6.mjs +47 -0
  53. package/dist/chunks/messages-Dd5iZN3c.mjs +47 -0
  54. package/dist/chunks/messages-DehM7135.mjs +47 -0
  55. package/dist/chunks/messages-Dg1OHftD.mjs +47 -0
  56. package/dist/chunks/messages-Di6Flq-b.mjs +47 -0
  57. package/dist/chunks/messages-Dqhhex6e.mjs +47 -0
  58. package/dist/chunks/messages-DueVe0F1.mjs +47 -0
  59. package/dist/chunks/messages-Dx3eFwI0.mjs +47 -0
  60. package/dist/chunks/messages-FOtiUoKl.mjs +47 -0
  61. package/dist/chunks/messages-FTOZNhRD.mjs +47 -0
  62. package/dist/chunks/messages-IQxGfQIV.mjs +47 -0
  63. package/dist/chunks/messages-JF2fzCkK.mjs +47 -0
  64. package/dist/chunks/messages-MOGl7I5v.mjs +47 -0
  65. package/dist/chunks/messages-QgYhPL-3.mjs +47 -0
  66. package/dist/chunks/messages-WYWIbQwo.mjs +47 -0
  67. package/dist/chunks/messages-a6A_LgDv.mjs +47 -0
  68. package/dist/chunks/messages-bSf31LJi.mjs +47 -0
  69. package/dist/chunks/messages-diGozhTn.mjs +47 -0
  70. package/dist/chunks/messages-er-kd-VO.mjs +47 -0
  71. package/dist/chunks/messages-ez3w5NBn.mjs +47 -0
  72. package/dist/chunks/messages-f3uXjegd.mjs +47 -0
  73. package/dist/chunks/messages-ohwI1UGv.mjs +47 -0
  74. package/dist/chunks/messages-p9BZJaFV.mjs +47 -0
  75. package/dist/chunks/messages-qIQ4L4rw.mjs +47 -0
  76. package/dist/chunks/messages-qWkXPggi.mjs +47 -0
  77. package/dist/chunks/messages-w5foGze_.mjs +47 -0
  78. package/dist/full.mjs +50 -0
  79. package/dist/locales.mjs +227 -0
  80. package/dist/messages-2434tVOK.mjs +47 -0
  81. package/dist/messages-3DcCwXMF.mjs +47 -0
  82. package/dist/messages-4kMwVAKY.mjs +47 -0
  83. package/dist/messages-57uL5htT.mjs +47 -0
  84. package/dist/messages-76-iJV9Q.mjs +47 -0
  85. package/dist/messages-8p86Eyf2.mjs +47 -0
  86. package/dist/messages-BBX0p0Pi.mjs +47 -0
  87. package/dist/messages-BCm2eudQ.mjs +47 -0
  88. package/dist/messages-BFiUomgG.mjs +47 -0
  89. package/dist/messages-BIPNHHAV.mjs +47 -0
  90. package/dist/messages-BUlwu9mo.mjs +47 -0
  91. package/dist/messages-BX-DPa-z.mjs +47 -0
  92. package/dist/messages-BextV3Qh.mjs +47 -0
  93. package/dist/messages-BiPSFlUG.mjs +47 -0
  94. package/dist/messages-BiXe9G-O.mjs +47 -0
  95. package/dist/messages-Bl5z_Igo.mjs +47 -0
  96. package/dist/messages-BnsE97ku.mjs +47 -0
  97. package/dist/messages-BoO8gsVD.mjs +47 -0
  98. package/dist/messages-BqWaOGMn.mjs +47 -0
  99. package/dist/messages-BqkL2_Ro.mjs +47 -0
  100. package/dist/messages-BvCkXKX-.mjs +47 -0
  101. package/dist/messages-C6tbPLoj.mjs +47 -0
  102. package/dist/messages-CA6T3-gQ.mjs +47 -0
  103. package/dist/messages-CFFPFdWP.mjs +47 -0
  104. package/dist/messages-CFrKE-TN.mjs +47 -0
  105. package/dist/messages-CHz8VlG-.mjs +47 -0
  106. package/dist/messages-CLixzySl.mjs +47 -0
  107. package/dist/messages-CV7OM_qk.mjs +47 -0
  108. package/dist/messages-CXHt3eCC.mjs +47 -0
  109. package/dist/messages-CbmsBrB0.mjs +47 -0
  110. package/dist/messages-Ceo1KtFx.mjs +47 -0
  111. package/dist/messages-Cm0LJLtB.mjs +47 -0
  112. package/dist/messages-CmymP_Ar.mjs +47 -0
  113. package/dist/messages-D0ohMB5H.mjs +47 -0
  114. package/dist/messages-D3GrDwXh.mjs +47 -0
  115. package/dist/messages-D3vTzIpL.mjs +47 -0
  116. package/dist/messages-D5WeksbV.mjs +47 -0
  117. package/dist/messages-DGaab4EP.mjs +47 -0
  118. package/dist/messages-DKha57ZU.mjs +47 -0
  119. package/dist/messages-DOaujgMW.mjs +47 -0
  120. package/dist/messages-DVbPLd_0.mjs +47 -0
  121. package/dist/messages-D_FCyfW6.mjs +47 -0
  122. package/dist/messages-Dd5iZN3c.mjs +47 -0
  123. package/dist/messages-DehM7135.mjs +47 -0
  124. package/dist/messages-Dg1OHftD.mjs +47 -0
  125. package/dist/messages-Di6Flq-b.mjs +47 -0
  126. package/dist/messages-Dqhhex6e.mjs +47 -0
  127. package/dist/messages-DueVe0F1.mjs +47 -0
  128. package/dist/messages-Dx3eFwI0.mjs +47 -0
  129. package/dist/messages-FOtiUoKl.mjs +47 -0
  130. package/dist/messages-FTOZNhRD.mjs +47 -0
  131. package/dist/messages-IQxGfQIV.mjs +47 -0
  132. package/dist/messages-JF2fzCkK.mjs +47 -0
  133. package/dist/messages-MOGl7I5v.mjs +47 -0
  134. package/dist/messages-QgYhPL-3.mjs +47 -0
  135. package/dist/messages-WYWIbQwo.mjs +47 -0
  136. package/dist/messages-a6A_LgDv.mjs +47 -0
  137. package/dist/messages-bSf31LJi.mjs +47 -0
  138. package/dist/messages-diGozhTn.mjs +47 -0
  139. package/dist/messages-er-kd-VO.mjs +47 -0
  140. package/dist/messages-ez3w5NBn.mjs +47 -0
  141. package/dist/messages-f3uXjegd.mjs +47 -0
  142. package/dist/messages-ohwI1UGv.mjs +47 -0
  143. package/dist/messages-p9BZJaFV.mjs +47 -0
  144. package/dist/messages-qIQ4L4rw.mjs +47 -0
  145. package/dist/messages-qWkXPggi.mjs +47 -0
  146. package/dist/messages-w5foGze_.mjs +47 -0
  147. package/dist/tools.mjs +3073 -0
  148. package/dist/vendor.LICENSE.txt +59 -156
  149. package/package.json +60 -15
  150. package/src/blok.ts +267 -0
  151. package/src/components/__module.ts +139 -0
  152. package/src/components/block/api.ts +155 -0
  153. package/src/components/block/index.ts +1427 -0
  154. package/src/components/block-tunes/block-tune-delete.ts +51 -0
  155. package/src/components/blocks.ts +338 -0
  156. package/src/components/constants/data-attributes.ts +342 -0
  157. package/src/components/constants.ts +76 -0
  158. package/src/components/core.ts +392 -0
  159. package/src/components/dom.ts +773 -0
  160. package/src/components/domIterator.ts +189 -0
  161. package/src/components/errors/critical.ts +5 -0
  162. package/src/components/events/BlockChanged.ts +16 -0
  163. package/src/components/events/BlockHovered.ts +21 -0
  164. package/src/components/events/BlockSettingsClosed.ts +12 -0
  165. package/src/components/events/BlockSettingsOpened.ts +12 -0
  166. package/src/components/events/BlokMobileLayoutToggled.ts +15 -0
  167. package/src/components/events/FakeCursorAboutToBeToggled.ts +17 -0
  168. package/src/components/events/FakeCursorHaveBeenSet.ts +17 -0
  169. package/src/components/events/HistoryStateChanged.ts +19 -0
  170. package/src/components/events/RedactorDomChanged.ts +14 -0
  171. package/src/components/events/index.ts +46 -0
  172. package/src/components/flipper.ts +481 -0
  173. package/src/components/i18n/i18next-loader.ts +84 -0
  174. package/src/components/i18n/lightweight-i18n.ts +86 -0
  175. package/src/components/i18n/locales/TRANSLATION_GUIDELINES.md +113 -0
  176. package/src/components/i18n/locales/am/messages.json +44 -0
  177. package/src/components/i18n/locales/ar/messages.json +44 -0
  178. package/src/components/i18n/locales/az/messages.json +44 -0
  179. package/src/components/i18n/locales/bg/messages.json +44 -0
  180. package/src/components/i18n/locales/bn/messages.json +44 -0
  181. package/src/components/i18n/locales/bs/messages.json +44 -0
  182. package/src/components/i18n/locales/cs/messages.json +44 -0
  183. package/src/components/i18n/locales/da/messages.json +44 -0
  184. package/src/components/i18n/locales/de/messages.json +44 -0
  185. package/src/components/i18n/locales/dv/messages.json +44 -0
  186. package/src/components/i18n/locales/el/messages.json +44 -0
  187. package/src/components/i18n/locales/en/messages.json +44 -0
  188. package/src/components/i18n/locales/es/messages.json +44 -0
  189. package/src/components/i18n/locales/et/messages.json +44 -0
  190. package/src/components/i18n/locales/fa/messages.json +44 -0
  191. package/src/components/i18n/locales/fi/messages.json +44 -0
  192. package/src/components/i18n/locales/fil/messages.json +44 -0
  193. package/src/components/i18n/locales/fr/messages.json +44 -0
  194. package/src/components/i18n/locales/gu/messages.json +44 -0
  195. package/src/components/i18n/locales/he/messages.json +44 -0
  196. package/src/components/i18n/locales/hi/messages.json +44 -0
  197. package/src/components/i18n/locales/hr/messages.json +44 -0
  198. package/src/components/i18n/locales/hu/messages.json +44 -0
  199. package/src/components/i18n/locales/hy/messages.json +44 -0
  200. package/src/components/i18n/locales/id/messages.json +44 -0
  201. package/src/components/i18n/locales/index.ts +225 -0
  202. package/src/components/i18n/locales/it/messages.json +44 -0
  203. package/src/components/i18n/locales/ja/messages.json +44 -0
  204. package/src/components/i18n/locales/ka/messages.json +44 -0
  205. package/src/components/i18n/locales/km/messages.json +44 -0
  206. package/src/components/i18n/locales/kn/messages.json +44 -0
  207. package/src/components/i18n/locales/ko/messages.json +44 -0
  208. package/src/components/i18n/locales/ku/messages.json +44 -0
  209. package/src/components/i18n/locales/lo/messages.json +44 -0
  210. package/src/components/i18n/locales/lt/messages.json +44 -0
  211. package/src/components/i18n/locales/lv/messages.json +44 -0
  212. package/src/components/i18n/locales/mk/messages.json +44 -0
  213. package/src/components/i18n/locales/ml/messages.json +44 -0
  214. package/src/components/i18n/locales/mn/messages.json +44 -0
  215. package/src/components/i18n/locales/mr/messages.json +44 -0
  216. package/src/components/i18n/locales/ms/messages.json +44 -0
  217. package/src/components/i18n/locales/my/messages.json +44 -0
  218. package/src/components/i18n/locales/ne/messages.json +44 -0
  219. package/src/components/i18n/locales/nl/messages.json +44 -0
  220. package/src/components/i18n/locales/no/messages.json +44 -0
  221. package/src/components/i18n/locales/pa/messages.json +44 -0
  222. package/src/components/i18n/locales/pl/messages.json +44 -0
  223. package/src/components/i18n/locales/ps/messages.json +44 -0
  224. package/src/components/i18n/locales/pt/messages.json +44 -0
  225. package/src/components/i18n/locales/ro/messages.json +44 -0
  226. package/src/components/i18n/locales/ru/messages.json +44 -0
  227. package/src/components/i18n/locales/sd/messages.json +44 -0
  228. package/src/components/i18n/locales/si/messages.json +44 -0
  229. package/src/components/i18n/locales/sk/messages.json +44 -0
  230. package/src/components/i18n/locales/sl/messages.json +44 -0
  231. package/src/components/i18n/locales/sq/messages.json +44 -0
  232. package/src/components/i18n/locales/sr/messages.json +44 -0
  233. package/src/components/i18n/locales/sv/messages.json +44 -0
  234. package/src/components/i18n/locales/sw/messages.json +44 -0
  235. package/src/components/i18n/locales/ta/messages.json +44 -0
  236. package/src/components/i18n/locales/te/messages.json +44 -0
  237. package/src/components/i18n/locales/th/messages.json +44 -0
  238. package/src/components/i18n/locales/tr/messages.json +44 -0
  239. package/src/components/i18n/locales/ug/messages.json +44 -0
  240. package/src/components/i18n/locales/uk/messages.json +44 -0
  241. package/src/components/i18n/locales/ur/messages.json +44 -0
  242. package/src/components/i18n/locales/vi/messages.json +44 -0
  243. package/src/components/i18n/locales/yi/messages.json +44 -0
  244. package/src/components/i18n/locales/zh/messages.json +44 -0
  245. package/src/components/icons/index.ts +242 -0
  246. package/src/components/inline-tools/inline-tool-bold.ts +2213 -0
  247. package/src/components/inline-tools/inline-tool-convert.ts +141 -0
  248. package/src/components/inline-tools/inline-tool-italic.ts +500 -0
  249. package/src/components/inline-tools/inline-tool-link.ts +539 -0
  250. package/src/components/modules/api/blocks.ts +363 -0
  251. package/src/components/modules/api/caret.ts +125 -0
  252. package/src/components/modules/api/events.ts +51 -0
  253. package/src/components/modules/api/history.ts +73 -0
  254. package/src/components/modules/api/i18n.ts +33 -0
  255. package/src/components/modules/api/index.ts +39 -0
  256. package/src/components/modules/api/inlineToolbar.ts +33 -0
  257. package/src/components/modules/api/listeners.ts +56 -0
  258. package/src/components/modules/api/notifier.ts +46 -0
  259. package/src/components/modules/api/readonly.ts +39 -0
  260. package/src/components/modules/api/sanitizer.ts +30 -0
  261. package/src/components/modules/api/saver.ts +52 -0
  262. package/src/components/modules/api/selection.ts +48 -0
  263. package/src/components/modules/api/styles.ts +72 -0
  264. package/src/components/modules/api/toolbar.ts +79 -0
  265. package/src/components/modules/api/tools.ts +16 -0
  266. package/src/components/modules/api/tooltip.ts +67 -0
  267. package/src/components/modules/api/ui.ts +36 -0
  268. package/src/components/modules/blockEvents.ts +1375 -0
  269. package/src/components/modules/blockManager.ts +1348 -0
  270. package/src/components/modules/blockSelection.ts +708 -0
  271. package/src/components/modules/caret.ts +853 -0
  272. package/src/components/modules/crossBlockSelection.ts +329 -0
  273. package/src/components/modules/dragManager.ts +1141 -0
  274. package/src/components/modules/history.ts +1098 -0
  275. package/src/components/modules/i18n.ts +325 -0
  276. package/src/components/modules/index.ts +139 -0
  277. package/src/components/modules/modificationsObserver.ts +147 -0
  278. package/src/components/modules/paste.ts +1092 -0
  279. package/src/components/modules/readonly.ts +136 -0
  280. package/src/components/modules/rectangleSelection.ts +668 -0
  281. package/src/components/modules/renderer.ts +155 -0
  282. package/src/components/modules/saver.ts +283 -0
  283. package/src/components/modules/toolbar/blockSettings.ts +776 -0
  284. package/src/components/modules/toolbar/index.ts +1311 -0
  285. package/src/components/modules/toolbar/inline.ts +956 -0
  286. package/src/components/modules/tools.ts +589 -0
  287. package/src/components/modules/ui.ts +1179 -0
  288. package/src/components/polyfills.ts +113 -0
  289. package/src/components/selection.ts +1189 -0
  290. package/src/components/tools/base.ts +274 -0
  291. package/src/components/tools/block.ts +291 -0
  292. package/src/components/tools/collection.ts +67 -0
  293. package/src/components/tools/factory.ts +85 -0
  294. package/src/components/tools/inline.ts +71 -0
  295. package/src/components/tools/tune.ts +33 -0
  296. package/src/components/ui/toolbox.ts +497 -0
  297. package/src/components/utils/announcer.ts +205 -0
  298. package/src/components/utils/api.ts +20 -0
  299. package/src/components/utils/bem.ts +26 -0
  300. package/src/components/utils/blocks.ts +284 -0
  301. package/src/components/utils/caret.ts +1067 -0
  302. package/src/components/utils/data-model-transform.ts +382 -0
  303. package/src/components/utils/events.ts +117 -0
  304. package/src/components/utils/keyboard.ts +60 -0
  305. package/src/components/utils/listeners.ts +296 -0
  306. package/src/components/utils/mutations.ts +39 -0
  307. package/src/components/utils/notifier/draw.ts +190 -0
  308. package/src/components/utils/notifier/index.ts +66 -0
  309. package/src/components/utils/notifier/types.ts +1 -0
  310. package/src/components/utils/notifier.ts +77 -0
  311. package/src/components/utils/placeholder.ts +140 -0
  312. package/src/components/utils/popover/components/hint/hint.const.ts +10 -0
  313. package/src/components/utils/popover/components/hint/hint.ts +46 -0
  314. package/src/components/utils/popover/components/hint/index.ts +6 -0
  315. package/src/components/utils/popover/components/popover-header/index.ts +2 -0
  316. package/src/components/utils/popover/components/popover-header/popover-header.const.ts +8 -0
  317. package/src/components/utils/popover/components/popover-header/popover-header.ts +80 -0
  318. package/src/components/utils/popover/components/popover-header/popover-header.types.ts +14 -0
  319. package/src/components/utils/popover/components/popover-item/index.ts +13 -0
  320. package/src/components/utils/popover/components/popover-item/popover-item-default/popover-item-default.const.ts +50 -0
  321. package/src/components/utils/popover/components/popover-item/popover-item-default/popover-item-default.ts +666 -0
  322. package/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.const.ts +14 -0
  323. package/src/components/utils/popover/components/popover-item/popover-item-html/popover-item-html.ts +136 -0
  324. package/src/components/utils/popover/components/popover-item/popover-item-separator/popover-item-separator.const.ts +20 -0
  325. package/src/components/utils/popover/components/popover-item/popover-item-separator/popover-item-separator.ts +117 -0
  326. package/src/components/utils/popover/components/popover-item/popover-item.ts +187 -0
  327. package/src/components/utils/popover/components/search-input/index.ts +2 -0
  328. package/src/components/utils/popover/components/search-input/search-input.const.ts +8 -0
  329. package/src/components/utils/popover/components/search-input/search-input.ts +181 -0
  330. package/src/components/utils/popover/components/search-input/search-input.types.ts +30 -0
  331. package/src/components/utils/popover/index.ts +13 -0
  332. package/src/components/utils/popover/popover-abstract.ts +448 -0
  333. package/src/components/utils/popover/popover-desktop.ts +643 -0
  334. package/src/components/utils/popover/popover-inline.ts +338 -0
  335. package/src/components/utils/popover/popover-mobile.ts +201 -0
  336. package/src/components/utils/popover/popover.const.ts +81 -0
  337. package/src/components/utils/popover/utils/popover-states-history.ts +72 -0
  338. package/src/components/utils/promise-queue.ts +43 -0
  339. package/src/components/utils/sanitizer.ts +537 -0
  340. package/src/components/utils/scroll-locker.ts +87 -0
  341. package/src/components/utils/shortcut.ts +231 -0
  342. package/src/components/utils/shortcuts.ts +113 -0
  343. package/src/components/utils/tools.ts +105 -0
  344. package/src/components/utils/tooltip.ts +642 -0
  345. package/src/components/utils/tw.ts +241 -0
  346. package/src/components/utils.ts +1081 -0
  347. package/src/env.d.ts +13 -0
  348. package/src/full.ts +69 -0
  349. package/src/locales.ts +51 -0
  350. package/src/stories/Block.stories.ts +498 -0
  351. package/src/stories/EditorModes.stories.ts +505 -0
  352. package/src/stories/Header.stories.ts +137 -0
  353. package/src/stories/InlineToolbar.stories.ts +498 -0
  354. package/src/stories/List.stories.ts +259 -0
  355. package/src/stories/Notifier.stories.ts +340 -0
  356. package/src/stories/Paragraph.stories.ts +112 -0
  357. package/src/stories/Placeholder.stories.ts +319 -0
  358. package/src/stories/Popover.stories.ts +844 -0
  359. package/src/stories/Selection.stories.ts +250 -0
  360. package/src/stories/StubBlock.stories.ts +156 -0
  361. package/src/stories/Toolbar.stories.ts +223 -0
  362. package/src/stories/Toolbox.stories.ts +166 -0
  363. package/src/stories/Tooltip.stories.ts +198 -0
  364. package/src/stories/helpers.ts +463 -0
  365. package/src/styles/main.css +123 -0
  366. package/src/tools/header/index.ts +570 -0
  367. package/src/tools/index.ts +38 -0
  368. package/src/tools/list/index.ts +1803 -0
  369. package/src/tools/paragraph/index.ts +411 -0
  370. package/src/tools/stub/index.ts +107 -0
  371. package/src/types-internal/blok-modules.d.ts +87 -0
  372. package/src/types-internal/html-janitor.d.ts +28 -0
  373. package/src/types-internal/module-config.d.ts +11 -0
  374. package/src/variants/all-locales.ts +155 -0
  375. package/src/variants/blok-maximum.ts +20 -0
  376. package/src/variants/blok-minimum.ts +243 -0
  377. package/types/api/blocks.d.ts +1 -1
  378. package/types/api/i18n.d.ts +5 -3
  379. package/types/api/selection.d.ts +6 -0
  380. package/types/api/styles.d.ts +0 -5
  381. package/types/configs/blok-config.d.ts +21 -0
  382. package/types/configs/i18n-config.d.ts +52 -2
  383. package/types/configs/i18n-dictionary.d.ts +16 -90
  384. package/types/data-attributes.d.ts +169 -0
  385. package/types/data-formats/output-data.d.ts +15 -0
  386. package/types/full.d.ts +80 -0
  387. package/types/index.d.ts +9 -24
  388. package/types/locales.d.ts +59 -0
  389. package/types/tools/adapters/inline-tool-adapter.d.ts +10 -0
  390. package/types/tools/block-tool.d.ts +9 -0
  391. package/types/tools/list.d.ts +25 -18
  392. package/types/tools/tool-settings.d.ts +8 -1
  393. package/types/tools/tool.d.ts +6 -0
  394. package/types/tools-entry.d.ts +49 -0
  395. package/types/utils/popover/popover-item.d.ts +0 -5
  396. package/dist/blok-BwPfU8ro.mjs +0 -21510
  397. package/dist/blok.umd.js +0 -198
@@ -0,0 +1,363 @@
1
+ import type { BlockAPI as BlockAPIInterface, Blocks } from '../../../../types/api';
2
+ import type { BlockToolData, OutputBlockData, OutputData, ToolConfig } from '../../../../types';
3
+ import { logLabeled } from './../../utils';
4
+ import { BlockAPI } from '../../block/api';
5
+ import { Module } from '../../__module';
6
+ import { Block } from '../../block';
7
+ import { capitalize } from '../../utils';
8
+ import type { BlockTuneData } from '../../../../types/block-tunes/block-tune-data';
9
+
10
+ /**
11
+ * @class BlocksAPI
12
+ * provides with methods working with Block
13
+ */
14
+ export class BlocksAPI extends Module {
15
+ /**
16
+ * Available methods
17
+ * @returns {Blocks}
18
+ */
19
+ public get methods(): Blocks {
20
+ return {
21
+ clear: (): Promise<void> => this.clear(),
22
+ render: (data: OutputData): Promise<void> => this.render(data),
23
+ renderFromHTML: (data: string): Promise<void> => this.renderFromHTML(data),
24
+ delete: (index?: number): Promise<void> => this.delete(index),
25
+ move: (toIndex: number, fromIndex?: number): void => this.move(toIndex, fromIndex),
26
+ getBlockByIndex: (index: number): BlockAPIInterface | undefined => this.getBlockByIndex(index),
27
+ getById: (id: string): BlockAPIInterface | null => this.getById(id),
28
+ getCurrentBlockIndex: (): number => this.getCurrentBlockIndex(),
29
+ getBlockIndex: (id: string): number | undefined => this.getBlockIndex(id),
30
+ getBlocksCount: (): number => this.getBlocksCount(),
31
+ getBlockByElement: (element: HTMLElement) => this.getBlockByElement(element),
32
+ insert: this.insert,
33
+ insertMany: this.insertMany,
34
+ update: this.update,
35
+ composeBlockData: this.composeBlockData,
36
+ convert: this.convert,
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Returns Blocks count
42
+ * @returns {number}
43
+ */
44
+ public getBlocksCount(): number {
45
+ return this.Blok.BlockManager.blocks.length;
46
+ }
47
+
48
+ /**
49
+ * Returns current block index
50
+ * @returns {number}
51
+ */
52
+ public getCurrentBlockIndex(): number {
53
+ return this.Blok.BlockManager.currentBlockIndex;
54
+ }
55
+
56
+ /**
57
+ * Returns the index of Block by id;
58
+ * @param id - block id
59
+ */
60
+ public getBlockIndex(id: string): number | undefined {
61
+ const block = this.Blok.BlockManager.getBlockById(id);
62
+
63
+ if (!block) {
64
+ logLabeled('There is no block with id `' + id + '`', 'warn');
65
+
66
+ return;
67
+ }
68
+
69
+ return this.Blok.BlockManager.getBlockIndex(block);
70
+ }
71
+
72
+ /**
73
+ * Returns BlockAPI object by Block index
74
+ * @param {number} index - index to get
75
+ */
76
+ public getBlockByIndex(index: number): BlockAPIInterface | undefined {
77
+ const block = this.Blok.BlockManager.getBlockByIndex(index);
78
+
79
+ if (block === undefined) {
80
+ logLabeled('There is no block at index `' + index + '`', 'warn');
81
+
82
+ return;
83
+ }
84
+
85
+ return new BlockAPI(block);
86
+ }
87
+
88
+ /**
89
+ * Returns BlockAPI object by Block id
90
+ * @param id - id of block to get
91
+ */
92
+ public getById(id: string): BlockAPIInterface | null {
93
+ const block = this.Blok.BlockManager.getBlockById(id);
94
+
95
+ if (block === undefined) {
96
+ logLabeled('There is no block with id `' + id + '`', 'warn');
97
+
98
+ return null;
99
+ }
100
+
101
+ return new BlockAPI(block);
102
+ }
103
+
104
+ /**
105
+ * Get Block API object by any child html element
106
+ * @param element - html element to get Block by
107
+ */
108
+ public getBlockByElement(element: HTMLElement): BlockAPIInterface | undefined {
109
+ const block = this.Blok.BlockManager.getBlock(element);
110
+
111
+ if (block === undefined) {
112
+ logLabeled('There is no block corresponding to element `' + element + '`', 'warn');
113
+
114
+ return;
115
+ }
116
+
117
+ return new BlockAPI(block);
118
+ }
119
+
120
+ /**
121
+ * Move block from one index to another
122
+ * @param {number} toIndex - index to move to
123
+ * @param {number} fromIndex - index to move from
124
+ */
125
+ public move(toIndex: number, fromIndex?: number): void {
126
+ this.Blok.BlockManager.move(toIndex, fromIndex);
127
+ }
128
+
129
+ /**
130
+ * Deletes Block
131
+ * @param {number} blockIndex - index of Block to delete
132
+ */
133
+ public async delete(blockIndex: number = this.Blok.BlockManager.currentBlockIndex): Promise<void> {
134
+ const block = this.Blok.BlockManager.getBlockByIndex(blockIndex);
135
+
136
+ if (block === undefined) {
137
+ logLabeled(`There is no block at index \`${blockIndex}\``, 'warn');
138
+
139
+ return;
140
+ }
141
+
142
+ try {
143
+ await this.Blok.BlockManager.removeBlock(block);
144
+ } catch (error: unknown) {
145
+ logLabeled(error as unknown as string, 'warn');
146
+
147
+ return;
148
+ }
149
+
150
+ /**
151
+ * in case of last block deletion
152
+ * Insert the new default empty block
153
+ */
154
+ if (this.Blok.BlockManager.blocks.length === 0) {
155
+ this.Blok.BlockManager.insert();
156
+ }
157
+
158
+ /**
159
+ * After Block deletion currentBlock is updated
160
+ */
161
+ if (this.Blok.BlockManager.currentBlock) {
162
+ this.Blok.Caret.setToBlock(this.Blok.BlockManager.currentBlock, this.Blok.Caret.positions.END);
163
+ }
164
+
165
+ this.Blok.Toolbar.close();
166
+ }
167
+
168
+ /**
169
+ * Clear Blok's area
170
+ */
171
+ public async clear(): Promise<void> {
172
+ await this.Blok.BlockManager.clear(true);
173
+ this.Blok.InlineToolbar.close();
174
+ }
175
+
176
+ /**
177
+ * Fills Blok with Blocks data
178
+ * @param {OutputData} data — Saved Blok data
179
+ */
180
+ public async render(data: OutputData): Promise<void> {
181
+ if (data === undefined || data.blocks === undefined) {
182
+ throw new Error('Incorrect data passed to the render() method');
183
+ }
184
+
185
+ /**
186
+ * Semantic meaning of the "render" method: "Display the new document over the existing one that stays unchanged"
187
+ * So we need to disable modifications observer temporarily
188
+ */
189
+ this.Blok.ModificationsObserver.disable();
190
+
191
+ await this.Blok.BlockManager.clear();
192
+ await this.Blok.Renderer.render(data.blocks);
193
+
194
+ this.Blok.ModificationsObserver.enable();
195
+ }
196
+
197
+ /**
198
+ * Render passed HTML string
199
+ * @param {string} data - HTML string to render
200
+ * @returns {Promise<void>}
201
+ */
202
+ public async renderFromHTML(data: string): Promise<void> {
203
+ await this.Blok.BlockManager.clear();
204
+
205
+ return this.Blok.Paste.processText(data, true);
206
+ }
207
+
208
+ /**
209
+ * Insert new Block and returns it's API
210
+ * @param {string} type — Tool name
211
+ * @param {BlockToolData} data — Tool data to insert
212
+ * @param {ToolConfig} _config — Tool config
213
+ * @param {number?} index — index where to insert new Block
214
+ * @param {boolean?} needToFocus - flag to focus inserted Block
215
+ * @param replace - pass true to replace the Block existed under passed index
216
+ * @param {string} id — An optional id for the new block. If omitted then the new id will be generated
217
+ */
218
+ public insert = (
219
+ type?: string,
220
+ data: BlockToolData = {},
221
+ _config: ToolConfig = {},
222
+ index?: number,
223
+ needToFocus?: boolean,
224
+ replace?: boolean,
225
+ id?: string
226
+ ): BlockAPIInterface => {
227
+ const tool = type ?? (this.config.defaultBlock as string | undefined);
228
+
229
+ const insertedBlock = this.Blok.BlockManager.insert({
230
+ id,
231
+ tool,
232
+ data,
233
+ index,
234
+ needToFocus,
235
+ replace,
236
+ });
237
+
238
+ return new BlockAPI(insertedBlock);
239
+ };
240
+
241
+ /**
242
+ * Creates data of an empty block with a passed type.
243
+ * @param toolName - block tool name
244
+ */
245
+ public composeBlockData = async (toolName: string): Promise<BlockToolData> => {
246
+ const tool = this.Blok.Tools.blockTools.get(toolName);
247
+
248
+ if (tool === undefined) {
249
+ throw new Error(`Block Tool with type "${toolName}" not found`);
250
+ }
251
+
252
+ const block = new Block({
253
+ tool,
254
+ api: this.Blok.API,
255
+ readOnly: true,
256
+ data: {},
257
+ tunesData: {},
258
+ });
259
+
260
+ return block.data;
261
+ };
262
+
263
+ /**
264
+ * Updates block data by id
265
+ * @param id - id of the block to update
266
+ * @param data - (optional) the new data
267
+ * @param tunes - (optional) tune data
268
+ */
269
+ public update = async (id: string, data?: Partial<BlockToolData>, tunes?: {[name: string]: BlockTuneData}): Promise<BlockAPIInterface> => {
270
+ const { BlockManager } = this.Blok;
271
+ const block = BlockManager.getBlockById(id);
272
+
273
+ if (block === undefined) {
274
+ throw new Error(`Block with id "${id}" not found`);
275
+ }
276
+
277
+ const updatedBlock = await BlockManager.update(block, data, tunes);
278
+
279
+ return new BlockAPI(updatedBlock);
280
+ };
281
+
282
+ /**
283
+ * Converts block to another type. Both blocks should provide the conversionConfig.
284
+ * @param id - id of the existing block to convert. Should provide 'conversionConfig.export' method
285
+ * @param newType - new block type. Should provide 'conversionConfig.import' method
286
+ * @param dataOverrides - optional data overrides for the new block
287
+ * @throws Error if conversion is not possible
288
+ */
289
+ private convert = async (id: string, newType: string, dataOverrides?: BlockToolData): Promise<BlockAPIInterface> => {
290
+ const { BlockManager, Tools } = this.Blok;
291
+ const blockToConvert = BlockManager.getBlockById(id);
292
+
293
+ if (!blockToConvert) {
294
+ throw new Error(`Block with id "${id}" not found`);
295
+ }
296
+
297
+ const originalBlockTool = Tools.blockTools.get(blockToConvert.name);
298
+ const targetBlockTool = Tools.blockTools.get(newType);
299
+
300
+ if (!targetBlockTool) {
301
+ throw new Error(`Block Tool with type "${newType}" not found`);
302
+ }
303
+
304
+ const originalBlockConvertable = originalBlockTool?.conversionConfig?.export !== undefined;
305
+ const targetBlockConvertable = targetBlockTool.conversionConfig?.import !== undefined;
306
+
307
+ if (originalBlockConvertable && targetBlockConvertable) {
308
+ const newBlock = await BlockManager.convert(blockToConvert, newType, dataOverrides);
309
+
310
+ return new BlockAPI(newBlock);
311
+ } else {
312
+ const unsupportedBlockTypes = [
313
+ !originalBlockConvertable ? capitalize(blockToConvert.name) : false,
314
+ !targetBlockConvertable ? capitalize(newType) : false,
315
+ ].filter(Boolean).join(' and ');
316
+
317
+ throw new Error(`Conversion from "${blockToConvert.name}" to "${newType}" is not possible. ${unsupportedBlockTypes} tool(s) should provide a "conversionConfig"`);
318
+ }
319
+ };
320
+
321
+
322
+ /**
323
+ * Inserts several Blocks to a specified index
324
+ * @param blocks - blocks data to insert
325
+ * @param index - index to insert the blocks at
326
+ */
327
+ private insertMany = (
328
+ blocks: OutputBlockData[],
329
+ index: number = this.Blok.BlockManager.blocks.length - 1
330
+ ): BlockAPIInterface[] => {
331
+ this.validateIndex(index);
332
+
333
+ const blocksToInsert = blocks.map(({ id, type, data }) => {
334
+ return this.Blok.BlockManager.composeBlock({
335
+ id,
336
+ tool: type || (this.config.defaultBlock as string),
337
+ data,
338
+ });
339
+ });
340
+
341
+ this.Blok.BlockManager.insertMany(blocksToInsert, index);
342
+
343
+ return blocksToInsert.map((block) => new BlockAPI(block));
344
+ };
345
+
346
+ /**
347
+ * Validated block index and throws an error if it's invalid
348
+ * @param index - index to validate
349
+ */
350
+ private validateIndex(index: unknown): void {
351
+ if (typeof index !== 'number') {
352
+ throw new Error('Index should be a number');
353
+ }
354
+
355
+ if (index < 0) {
356
+ throw new Error(`Index should be greater than or equal to 0`);
357
+ }
358
+
359
+ if (index === null) {
360
+ throw new Error(`Index should be greater than or equal to 0`);
361
+ }
362
+ }
363
+ }
@@ -0,0 +1,125 @@
1
+ import type { BlockAPI, Caret } from '../../../../types/api';
2
+ import { Module } from '../../__module';
3
+ import { resolveBlock } from '../../utils/api';
4
+
5
+ /**
6
+ * @class CaretAPI
7
+ * provides with methods to work with caret
8
+ */
9
+ export class CaretAPI extends Module {
10
+ /**
11
+ * Available methods
12
+ * @returns {Caret}
13
+ */
14
+ public get methods(): Caret {
15
+ return {
16
+ setToFirstBlock: this.setToFirstBlock,
17
+ setToLastBlock: this.setToLastBlock,
18
+ setToPreviousBlock: this.setToPreviousBlock,
19
+ setToNextBlock: this.setToNextBlock,
20
+ setToBlock: this.setToBlock,
21
+ focus: this.focus,
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Sets caret to the first Block
27
+ * @param {string} position - position where to set caret
28
+ * @param {number} offset - caret offset
29
+ * @returns {boolean}
30
+ */
31
+ private setToFirstBlock = (position: string = this.Blok.Caret.positions.DEFAULT, offset = 0): boolean => {
32
+ if (!this.Blok.BlockManager.firstBlock) {
33
+ return false;
34
+ }
35
+
36
+ this.Blok.Caret.setToBlock(this.Blok.BlockManager.firstBlock, position, offset);
37
+
38
+ return true;
39
+ };
40
+
41
+ /**
42
+ * Sets caret to the last Block
43
+ * @param {string} position - position where to set caret
44
+ * @param {number} offset - caret offset
45
+ * @returns {boolean}
46
+ */
47
+ private setToLastBlock = (position: string = this.Blok.Caret.positions.DEFAULT, offset = 0): boolean => {
48
+ if (!this.Blok.BlockManager.lastBlock) {
49
+ return false;
50
+ }
51
+
52
+ this.Blok.Caret.setToBlock(this.Blok.BlockManager.lastBlock, position, offset);
53
+
54
+ return true;
55
+ };
56
+
57
+ /**
58
+ * Sets caret to the previous Block
59
+ * @param {string} position - position where to set caret
60
+ * @param {number} offset - caret offset
61
+ * @returns {boolean}
62
+ */
63
+ private setToPreviousBlock = (
64
+ position: string = this.Blok.Caret.positions.DEFAULT,
65
+ offset = 0
66
+ ): boolean => {
67
+ if (!this.Blok.BlockManager.previousBlock) {
68
+ return false;
69
+ }
70
+
71
+ this.Blok.Caret.setToBlock(this.Blok.BlockManager.previousBlock, position, offset);
72
+ return true;
73
+ };
74
+
75
+ /**
76
+ * Sets caret to the next Block
77
+ * @param {string} position - position where to set caret
78
+ * @param {number} offset - caret offset
79
+ * @returns {boolean}
80
+ */
81
+ private setToNextBlock = (position: string = this.Blok.Caret.positions.DEFAULT, offset = 0): boolean => {
82
+ if (!this.Blok.BlockManager.nextBlock) {
83
+ return false;
84
+ }
85
+
86
+ this.Blok.Caret.setToBlock(this.Blok.BlockManager.nextBlock, position, offset);
87
+
88
+ return true;
89
+ };
90
+
91
+ /**
92
+ * Sets caret to the Block by passed index
93
+ * @param blockOrIdOrIndex - either BlockAPI or Block id or Block index
94
+ * @param position - position where to set caret
95
+ * @param offset - caret offset
96
+ * @returns {boolean}
97
+ */
98
+ private setToBlock = (
99
+ blockOrIdOrIndex: BlockAPI | BlockAPI['id'] | number,
100
+ position: string = this.Blok.Caret.positions.DEFAULT,
101
+ offset = 0
102
+ ): boolean => {
103
+ const block = resolveBlock(blockOrIdOrIndex, this.Blok);
104
+ if (block === undefined) {
105
+ return false;
106
+ }
107
+
108
+ this.Blok.Caret.setToBlock(block, position, offset);
109
+
110
+ return true;
111
+ };
112
+
113
+ /**
114
+ * Sets caret to the Blok
115
+ * @param {boolean} atEnd - if true, set Caret to the end of the Blok
116
+ * @returns {boolean}
117
+ */
118
+ private focus = (atEnd = false): boolean => {
119
+ if (atEnd) {
120
+ return this.setToLastBlock(this.Blok.Caret.positions.END);
121
+ }
122
+
123
+ return this.setToFirstBlock(this.Blok.Caret.positions.START);
124
+ };
125
+ }
@@ -0,0 +1,51 @@
1
+ import { Module } from '../../__module';
2
+ import type { Events } from '../../../../types/api';
3
+ import type { BlokEventMap } from '../../events';
4
+
5
+ /**
6
+ * @class EventsAPI
7
+ * provides with methods working with Toolbar
8
+ */
9
+ export class EventsAPI extends Module {
10
+ /**
11
+ * Available methods
12
+ * @returns {Events}
13
+ */
14
+ public get methods(): Events {
15
+ return {
16
+ emit: (eventName: keyof BlokEventMap, data: BlokEventMap[keyof BlokEventMap] | undefined): void => this.emit(eventName, data),
17
+ off: (eventName: keyof BlokEventMap, callback: (data?: unknown) => void): void => this.off(eventName, callback),
18
+ on: (eventName: keyof BlokEventMap, callback: () => void): void => this.on(eventName, callback),
19
+ };
20
+ }
21
+
22
+ /**
23
+ * Subscribe on Events
24
+ * @param {string} eventName - event name to subscribe
25
+ * @param {Function} callback - event handler
26
+ */
27
+ public on(eventName: keyof BlokEventMap, callback: (data?: unknown) => void): void {
28
+ this.eventsDispatcher.on(eventName, callback);
29
+ }
30
+
31
+ /**
32
+ * Emit event with data
33
+ * @param {string} eventName - event to emit
34
+ * @param {object} data - event's data
35
+ */
36
+ public emit(eventName: keyof BlokEventMap, data: BlokEventMap[keyof BlokEventMap] | undefined): void {
37
+ this.eventsDispatcher.emit(
38
+ eventName,
39
+ data
40
+ );
41
+ }
42
+
43
+ /**
44
+ * Unsubscribe from Event
45
+ * @param {string} eventName - event to unsubscribe
46
+ * @param {Function} callback - event handler
47
+ */
48
+ public off(eventName: keyof BlokEventMap, callback: (data?: unknown) => void): void {
49
+ this.eventsDispatcher.off(eventName, callback);
50
+ }
51
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @class HistoryAPI
3
+ * @classdesc Provides public API for history (undo/redo) functionality
4
+ * @module HistoryAPI
5
+ */
6
+ import { Module } from '../../__module';
7
+ import type { History as HistoryInterface } from '../../../../types/api';
8
+
9
+ /**
10
+ * HistoryAPI provides methods for undo/redo operations
11
+ */
12
+ export class HistoryAPI extends Module {
13
+ /**
14
+ * Available methods for public API
15
+ */
16
+ public get methods(): HistoryInterface {
17
+ return {
18
+ undo: (): Promise<boolean> => this.undo(),
19
+ redo: (): Promise<boolean> => this.redo(),
20
+ canUndo: (): boolean => this.canUndo(),
21
+ canRedo: (): boolean => this.canRedo(),
22
+ clear: (): void => this.clear(),
23
+ captureInitialState: (): Promise<void> => this.captureInitialState(),
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Performs undo operation
29
+ * @returns Promise resolving to true if undo was performed
30
+ */
31
+ private async undo(): Promise<boolean> {
32
+ return this.Blok.History.undo();
33
+ }
34
+
35
+ /**
36
+ * Performs redo operation
37
+ * @returns Promise resolving to true if redo was performed
38
+ */
39
+ private async redo(): Promise<boolean> {
40
+ return this.Blok.History.redo();
41
+ }
42
+
43
+ /**
44
+ * Checks if undo is available
45
+ * @returns true if there are states to undo
46
+ */
47
+ private canUndo(): boolean {
48
+ return this.Blok.History.canUndo();
49
+ }
50
+
51
+ /**
52
+ * Checks if redo is available
53
+ * @returns true if there are states to redo
54
+ */
55
+ private canRedo(): boolean {
56
+ return this.Blok.History.canRedo();
57
+ }
58
+
59
+ /**
60
+ * Clears the history stacks
61
+ */
62
+ private clear(): void {
63
+ this.Blok.History.clear();
64
+ }
65
+
66
+ /**
67
+ * Captures the initial document state
68
+ * @returns Promise that resolves when initial state is captured
69
+ */
70
+ private async captureInitialState(): Promise<void> {
71
+ return this.Blok.History.captureInitialState();
72
+ }
73
+ }
@@ -0,0 +1,33 @@
1
+ import type { I18n } from '../../../../types/api';
2
+ import { Module } from '../../__module';
3
+
4
+ /**
5
+ * API module exposing i18n methods to tools.
6
+ *
7
+ * This module follows the standard API module pattern (extend Module, expose `methods` getter).
8
+ * It provides a stable interface for tools while the internal I18n module can evolve.
9
+ *
10
+ * Tools should use full translation keys (e.g., 'tools.link.addLink', 'blockSettings.delete').
11
+ */
12
+ export class I18nAPI extends Module {
13
+ /**
14
+ * Cached methods object to avoid creating new closures on every access.
15
+ */
16
+ private cachedMethods: I18n | null = null;
17
+
18
+ /**
19
+ * Returns the I18n API methods for tools.
20
+ *
21
+ * The methods object is cached to avoid allocating new closures on each property access,
22
+ * which would happen frequently as tools call api.i18n.t() during rendering.
23
+ */
24
+ public get methods(): I18n {
25
+ if (this.cachedMethods === null) {
26
+ this.cachedMethods = {
27
+ t: (dictKey: string): string => this.Blok.I18n.t(dictKey),
28
+ };
29
+ }
30
+
31
+ return this.cachedMethods;
32
+ }
33
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @module API
3
+ * @copyright <CodeX> 2018
4
+ *
5
+ * Each block has a Blok API instance to use provided public methods
6
+ * if you cant to read more about how API works, please see docs
7
+ */
8
+ import { Module } from '../../__module';
9
+ import type { API as APIInterfaces } from '../../../../types';
10
+
11
+ /**
12
+ * @class API
13
+ */
14
+ export class API extends Module {
15
+ /**
16
+ * Blok Core API modules
17
+ */
18
+ public get methods(): APIInterfaces {
19
+ return {
20
+ blocks: this.Blok.BlocksAPI.methods,
21
+ caret: this.Blok.CaretAPI.methods,
22
+ tools: this.Blok.ToolsAPI.methods,
23
+ events: this.Blok.EventsAPI.methods,
24
+ history: this.Blok.HistoryAPI.methods,
25
+ listeners: this.Blok.ListenersAPI.methods,
26
+ notifier: this.Blok.NotifierAPI.methods,
27
+ sanitizer: this.Blok.SanitizerAPI.methods,
28
+ saver: this.Blok.SaverAPI.methods,
29
+ selection: this.Blok.SelectionAPI.methods,
30
+ styles: this.Blok.StylesAPI.classes,
31
+ toolbar: this.Blok.ToolbarAPI.methods,
32
+ inlineToolbar: this.Blok.InlineToolbarAPI.methods,
33
+ tooltip: this.Blok.TooltipAPI.methods,
34
+ i18n: this.Blok.I18nAPI.methods,
35
+ readOnly: this.Blok.ReadOnlyAPI.methods,
36
+ ui: this.Blok.UiAPI.methods,
37
+ };
38
+ }
39
+ }