@unicom-cloud/ui 0.8.112 → 0.8.113

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 (413) hide show
  1. package/Affix.js +1 -1
  2. package/Alert.js +1 -1
  3. package/AutoComplete.js +1 -1
  4. package/BackTop.js +1 -1
  5. package/Badge.js +1 -1
  6. package/Breadcrumb.js +2 -2
  7. package/Button.js +1 -1
  8. package/Calendar.js +1 -1
  9. package/Card.js +1 -1
  10. package/Carousel.js +1 -1
  11. package/Cascader.js +1 -1
  12. package/Checkbox.js +1 -1
  13. package/ColorPicker.js +1 -1
  14. package/Comment.js +1 -1
  15. package/ConfigProvider.js +1 -1
  16. package/Copy.js +3 -47
  17. package/Countdown.js +16 -50
  18. package/DatePicker.js +1 -1
  19. package/Descriptions.js +1 -1
  20. package/Details.js +14 -50
  21. package/Development.js +1 -1
  22. package/Divider.js +1 -1
  23. package/Draggable.js +1 -1
  24. package/Dropdown.js +1 -1
  25. package/Empty.js +1 -1
  26. package/Flex.js +15 -51
  27. package/Form.js +1 -1
  28. package/Icon.js +1 -1
  29. package/IconHover.js +1 -1
  30. package/Image.js +1 -1
  31. package/InputNumber.js +1 -1
  32. package/Layout.js +1 -1
  33. package/Link.js +1 -1
  34. package/LiquidFill.js +16 -51
  35. package/List.js +1 -1
  36. package/Loading.js +14 -50
  37. package/Marquee.js +23 -46
  38. package/Mentions.js +1 -1
  39. package/Menu.js +1 -1
  40. package/Message.js +1 -1
  41. package/Modal.js +1 -1
  42. package/Notice.js +13 -49
  43. package/Notification.js +1 -1
  44. package/OverflowEllipsis.js +1 -1
  45. package/PageHeader.js +1 -1
  46. package/Popconfirm.js +1 -1
  47. package/Popover.js +1 -1
  48. package/Progress.js +1 -1
  49. package/QrCode.js +14 -51
  50. package/Radio.js +1 -1
  51. package/Rate.js +1 -1
  52. package/ResizeBox.js +1 -1
  53. package/Result.js +1 -1
  54. package/RichText.js +12 -13
  55. package/Segmented.js +15 -50
  56. package/Skeleton.js +1 -1
  57. package/Slider.js +1 -1
  58. package/Space.js +15 -51
  59. package/Spin.js +1 -1
  60. package/Statistic.js +1 -1
  61. package/Steps.js +1 -1
  62. package/Switch.js +1 -1
  63. package/Table.js +1 -1
  64. package/Tabs.js +1 -1
  65. package/Tag.js +1 -1
  66. package/Tooltip.js +1 -1
  67. package/Tour.js +17 -53
  68. package/Transfer.js +1 -1
  69. package/Tree.js +1 -1
  70. package/TreeSelect.js +1 -1
  71. package/Trigger.js +1 -1
  72. package/affix/index.js +1 -1
  73. package/alert/index.js +1 -1
  74. package/anchor/Anchor.js +2 -2
  75. package/anchor/Link.js +1 -1
  76. package/app/App.js +2 -2
  77. package/auto-complete/index.js +1 -1
  78. package/avatar/Avatar.js +1 -1
  79. package/avatar/Group.js +1 -1
  80. package/back-top/index.js +1 -1
  81. package/badge/index.js +1 -1
  82. package/breadcrumb/index.js +2 -2
  83. package/button/Group.js +1 -1
  84. package/button/index.js +1 -1
  85. package/calendar/index.js +2 -2
  86. package/card/Grid.js +1 -1
  87. package/card/Meta.js +1 -1
  88. package/card/index.js +1 -1
  89. package/carousel/Arrow.js +1 -1
  90. package/carousel/Indicator.js +1 -1
  91. package/carousel/index.js +1 -1
  92. package/cascader/Cascader.js +3 -3
  93. package/cascader/index.js +1 -1
  94. package/cascader/util.js +1 -1
  95. package/checkbox/Checkbox.js +2 -2
  96. package/checkbox/Group.js +2 -2
  97. package/checkbox/GroupBlock.js +2 -2
  98. package/checkbox/index.js +2 -2
  99. package/chunk/{0BhDjhcd.js → 3t4FwEoB.js} +1 -1
  100. package/chunk/{KPBMJlOB.js → BHAu6wbC.js} +1 -1
  101. package/chunk/{DhAvt6tJ.js → Bcl7dWlJ.js} +2 -2
  102. package/chunk/{CrOzsnI0.js → Bl3hZtxi.js} +1 -1
  103. package/chunk/{BfVlSL8A.js → Bzx5BueA.js} +3 -3
  104. package/chunk/CVMFAeSw.js +39 -0
  105. package/chunk/{C1vY8016.js → CYDaUML7.js} +77 -108
  106. package/chunk/{CYssV-zz.js → CbXCgtzv.js} +65 -99
  107. package/chunk/ClNkxEcR.js +154 -0
  108. package/chunk/{DfUcAhyT.js → CwLSam2p.js} +2 -2
  109. package/chunk/Cy26_CKq.js +33 -0
  110. package/chunk/{BiZSULcr.js → D0dVE1v1.js} +317 -350
  111. package/chunk/{CtCFA4ht.js → DA5AMZwY.js} +3 -3
  112. package/chunk/{DfbO4QTS.js → DB0hUIM1.js} +1 -1
  113. package/chunk/{DMv8Hn4u.js → De8RLlOK.js} +1 -1
  114. package/chunk/{C3kH2ES3.js → DrYaod6k.js} +1 -1
  115. package/chunk/{CylbdYce.js → DzlfiVe2.js} +1 -1
  116. package/chunk/gJsdBcpG.js +10 -0
  117. package/chunk/{Cx92e1S8.js → yWKJUe_w.js} +3 -3
  118. package/collapse/Collapse.js +1 -1
  119. package/collapse/Item.js +1 -1
  120. package/color-picker/ControlBar.js +1 -1
  121. package/color-picker/InputAlpha.js +1 -1
  122. package/color-picker/InputHex.js +1 -1
  123. package/color-picker/InputRgb.js +1 -1
  124. package/color-picker/Palette.js +1 -1
  125. package/color-picker/Panel.js +2 -2
  126. package/color-picker/index.js +1 -1
  127. package/comment/index.js +1 -1
  128. package/config-provider/ConfigProvider.js +1 -1
  129. package/config-provider/context.js +1 -1
  130. package/config-provider/index.js +2 -2
  131. package/copy/index.js +22 -66
  132. package/countdown/index.js +41 -75
  133. package/date-picker/Picker.js +1 -1
  134. package/date-picker/RangePicker.js +2 -2
  135. package/date-picker/index.js +1 -1
  136. package/descriptions/index.js +1 -1
  137. package/details/index.js +46 -82
  138. package/development/index.js +1 -1
  139. package/divider/index.js +1 -1
  140. package/draggable/index.js +1 -1
  141. package/drawer/Drawer.js +1 -1
  142. package/dropdown/Button.js +1 -1
  143. package/dropdown/index.js +1 -1
  144. package/empty/index.js +1 -1
  145. package/flex/index.js +37 -71
  146. package/form/Form.js +2 -2
  147. package/form/FormItem.js +1 -1
  148. package/form/index.js +1 -1
  149. package/grid/Grid.js +1 -1
  150. package/grid/Item.js +1 -1
  151. package/hooks/index.js +6 -6
  152. package/hooks/useId.js +1 -1
  153. package/hooks/useResizeObserver.js +7 -50
  154. package/hooks/useStateWithPromise.js +1 -1
  155. package/hooks/useWindowSize.js +1 -1
  156. package/icon/index.js +1 -1
  157. package/icon-hover/index.js +1 -1
  158. package/icons/file.js +1 -1
  159. package/image/Image.js +2 -2
  160. package/image/ImagePreview.js +17 -52
  161. package/image/ImagePreviewArrow.js +1 -1
  162. package/image/ImagePreviewGroup.js +1 -1
  163. package/image/index.js +1 -1
  164. package/index.js +379 -378
  165. package/input/Button.js +1 -1
  166. package/input/Group.js +1 -1
  167. package/input/Input.js +1 -1
  168. package/input/InputElement.js +1 -1
  169. package/input/Password.js +1 -1
  170. package/input/Search.js +1 -1
  171. package/input/Textarea.js +1 -1
  172. package/input-number/index.js +1 -1
  173. package/input-tag/InputTag.js +1 -1
  174. package/layout/Content.js +1 -1
  175. package/layout/Footer.js +1 -1
  176. package/layout/Header.js +1 -1
  177. package/layout/Sider.js +1 -1
  178. package/layout/index.js +1 -1
  179. package/link/index.js +1 -1
  180. package/liquid-fill/index.js +56 -91
  181. package/list/Item.js +1 -1
  182. package/list/Meta.js +1 -1
  183. package/list/index.js +1 -1
  184. package/loading/index.js +26 -62
  185. package/marquee/index.js +70 -93
  186. package/marquee-/index.js +73 -96
  187. package/mentions/index.js +1 -1
  188. package/menu/Menu.js +3 -3
  189. package/menu/OverflowWrap.js +1 -1
  190. package/menu/index.js +2 -2
  191. package/message/index.js +1 -1
  192. package/message/useMessage.js +1 -1
  193. package/modal/Confirm.js +2 -2
  194. package/modal/Modal.js +2 -2
  195. package/modal/index.js +2 -2
  196. package/notice/index.js +13 -49
  197. package/notification/index.js +1 -1
  198. package/notification/useNotification.js +1 -1
  199. package/overflow-ellipsis/OverflowItem.js +1 -1
  200. package/overflow-ellipsis/index.js +1 -1
  201. package/package.json +1 -1
  202. package/page-header/index.js +1 -1
  203. package/pagination/PageItem.js +1 -1
  204. package/pagination/PageJumper.js +1 -1
  205. package/pagination/PageOption.js +1 -1
  206. package/pagination/Pagination.js +1 -1
  207. package/picker/Input.js +1 -1
  208. package/picker/InputRange.js +1 -1
  209. package/popconfirm/index.js +1 -1
  210. package/popover/index.js +1 -1
  211. package/progress/CircleProgress.js +1 -1
  212. package/progress/index.js +1 -1
  213. package/qr-code/index.js +26 -63
  214. package/radio/Group.js +2 -2
  215. package/radio/GroupBlock.js +2 -2
  216. package/radio/Radio.js +2 -2
  217. package/radio/index.js +2 -2
  218. package/rate/index.js +1 -1
  219. package/resize-box/ResizeTrigger.js +1 -1
  220. package/resize-box/Split.js +1 -1
  221. package/resize-box/SplitGroup.js +1 -1
  222. package/resize-box/index.js +1 -1
  223. package/result/index.js +1 -1
  224. package/rich-text/index.js +6332 -77
  225. package/rich-text/lib/diff/index.d.ts +21 -0
  226. package/row-col/Col-.js +1 -1
  227. package/row-col/Col.js +1 -1
  228. package/row-col/Row.js +1 -1
  229. package/segmented/index.js +118 -153
  230. package/select/Option.js +44 -41
  231. package/select/Select.js +10 -12
  232. package/select-view/Core.js +1 -1
  233. package/skeleton/index.js +1 -1
  234. package/slider/Button.js +1 -1
  235. package/slider/index.js +1 -1
  236. package/space/index.js +23 -59
  237. package/spin/DotLoading.js +1 -1
  238. package/spin/index.js +1 -1
  239. package/splitter/Panel.js +1 -1
  240. package/splitter/SplitBar.js +2 -2
  241. package/splitter/Splitter.js +2 -2
  242. package/statistic/index.js +1 -1
  243. package/steps/index.js +1 -1
  244. package/style.css +1 -1
  245. package/switch/index.js +1 -1
  246. package/table/Table.js +14 -53
  247. package/table/index.js +77 -120
  248. package/tabs/Tab.js +3 -3
  249. package/tabs/TabContent.js +2 -2
  250. package/tabs/TabPane.js +1 -1
  251. package/tabs/index.js +2 -2
  252. package/tag/index.js +1 -1
  253. package/time-picker/Picker.js +1 -1
  254. package/time-picker/TimePicker.js +1 -1
  255. package/timeline/Item.js +1 -1
  256. package/timeline/Timeline.js +1 -1
  257. package/tooltip/index.js +1 -1
  258. package/tour/index.js +80 -116
  259. package/transfer/Item.js +2 -2
  260. package/transfer/List.js +2 -2
  261. package/transfer/index.js +1 -1
  262. package/tree/Animation.js +2 -2
  263. package/tree/Node.js +3 -3
  264. package/tree/NodeList.js +1 -1
  265. package/tree/Tree.js +2 -2
  266. package/tree/index.js +1 -1
  267. package/tree-select/Select.js +3 -3
  268. package/tree-select/index.js +1 -1
  269. package/trigger/index.js +1 -1
  270. package/types/common/hooks/src/use-theme/index.d.ts +2 -2
  271. package/types/common/hooks/useStateWithPromise.d.ts +1 -1
  272. package/types/common/utils/dom.d.ts +12 -0
  273. package/types/pc/carousel/interface.d.ts +2 -2
  274. package/types/pc/color-picker/Panel.d.ts +1 -1
  275. package/types/pc/date-picker/RangePicker.d.ts +1 -1
  276. package/types/pc/index.d.ts +1 -1
  277. package/types/pc/list/interface.d.ts +2 -2
  278. package/types/pc/menu/context.d.ts +1 -1
  279. package/types/pc/rich-text/index.d.ts +7 -4
  280. package/types/pc/rich-text/interface.d.ts +3 -2
  281. package/types/pc/rich-text/{core → lib/core}/editor.d.ts +1 -1
  282. package/types/pc/rich-text/{core → lib/core}/rich.d.ts +3 -7
  283. package/types/pc/rich-text/{core → lib/core}/selection.d.ts +1 -0
  284. package/types/pc/rich-text/{core.d.ts → lib/core.d.ts} +1 -1
  285. package/types/pc/rich-text/lib/delta/AttributeMap.d.ts +15 -0
  286. package/types/pc/rich-text/lib/delta/Op.d.ts +13 -0
  287. package/types/pc/rich-text/lib/delta/OpIterator.d.ts +14 -0
  288. package/types/pc/rich-text/lib/delta/index.d.ts +53 -0
  289. package/types/pc/rich-text/lib/diff/index.d.ts +40 -0
  290. package/types/pc/rich-text/{formats → lib/formats}/bold.d.ts +1 -1
  291. package/types/pc/rich-text/{formats → lib/formats}/font.d.ts +1 -1
  292. package/types/pc/rich-text/lib/formats/hr.d.ts +5 -0
  293. package/types/pc/rich-text/lib/formats/image-resize/index.d.ts +27 -0
  294. package/types/pc/rich-text/lib/formats/image-resize/modules/BaseModule.d.ts +10 -0
  295. package/types/pc/rich-text/lib/formats/image-resize/modules/DisplaySize.d.ts +5 -0
  296. package/types/pc/rich-text/lib/formats/image-resize/modules/Resize.d.ts +13 -0
  297. package/types/pc/rich-text/lib/formats/image-resize/options.d.ts +7 -0
  298. package/types/pc/rich-text/lib/formats/liOl.d.ts +10 -0
  299. package/types/pc/rich-text/lib/formats/liUl.d.ts +10 -0
  300. package/types/pc/rich-text/lib/formats/lineHeight.d.ts +3 -0
  301. package/types/pc/rich-text/{formats → lib/formats}/list.d.ts +1 -0
  302. package/types/pc/rich-text/{formats → lib/formats}/table.d.ts +3 -3
  303. package/types/pc/rich-text/{modules → lib/modules}/clipboard.d.ts +2 -2
  304. package/types/pc/rich-text/{modules → lib/modules}/history.d.ts +1 -1
  305. package/types/pc/rich-text/{modules → lib/modules}/keyboard.d.ts +1 -1
  306. package/types/pc/rich-text/{modules → lib/modules}/syntax.d.ts +2 -2
  307. package/types/pc/rich-text/{modules → lib/modules}/tableEmbed.d.ts +3 -3
  308. package/types/pc/rich-text/{modules → lib/modules}/toolbar.d.ts +1 -1
  309. package/types/pc/rich-text/{parchment → lib/parchment}/attributor/attributor.d.ts +3 -3
  310. package/types/pc/rich-text/{parchment → lib/parchment}/attributor/style.d.ts +2 -2
  311. package/types/pc/rich-text/{ui → lib/ui}/icons.d.ts +5 -1
  312. package/types/pc/rich-text/{ui → lib/ui}/picker.d.ts +1 -0
  313. package/types/pc/tabs/hook/useDomSize.d.ts +2 -2
  314. package/types/pc/tabs/hook/useHeaderScroll.d.ts +2 -2
  315. package/types/pc/tree-select/hook/useStateValue.d.ts +2 -2
  316. package/types/pc/utils/date.d.ts +1 -0
  317. package/types/pc/utils/index.d.ts +2 -2
  318. package/typography/Base.js +1 -1
  319. package/typography/Ellipsis.js +70 -114
  320. package/typography/Operations.js +29 -74
  321. package/typography/Paragraph.js +1 -1
  322. package/typography/Typography.js +1 -1
  323. package/upload/TriggerNode.js +1 -1
  324. package/upload/Upload.js +1 -1
  325. package/utils/contextHolder.js +1 -1
  326. package/utils/date.js +1 -0
  327. package/utils/index.js +70 -70
  328. package/verification-code/VerificationCode.js +1 -1
  329. package/version/index.js +1 -1
  330. package/virtual-list/VirtualList.js +218 -217
  331. package/watermark/Watermark.js +1 -1
  332. package/chunk/BCmfDFV4.js +0 -4237
  333. package/chunk/BG6j6Ct7.js +0 -30
  334. package/chunk/C5CbL5ku.js +0 -56
  335. package/chunk/DsuIQH0F.js +0 -200
  336. package/chunk/vP3qfmKM.js +0 -84
  337. package/rich-text/core.js +0 -11
  338. package/rich-text/rich.js +0 -1347
  339. package/types/common/utils/index.d.ts +0 -47
  340. package/types/common/utils/keyboardCode.d.ts +0 -4
  341. package/types/common/utils/math.d.ts +0 -1
  342. package/types/common/utils/reactTransitionGroup.d.ts +0 -1
  343. package/types/common/utils/uuid.d.ts +0 -1
  344. package/types/common/utils/validate.d.ts +0 -1
  345. package/types/pc/rich-text/delta/AttributeMap.d.ts +0 -10
  346. package/types/pc/rich-text/delta/Op.d.ts +0 -11
  347. package/types/pc/rich-text/delta/OpIterator.d.ts +0 -13
  348. package/types/pc/rich-text/delta/index.d.ts +0 -45
  349. package/types/common/hooks/src/utils/{index.d.ts → is.d.ts} +0 -0
  350. package/types/pc/rich-text/{blots → lib/blots}/block.d.ts +0 -0
  351. package/types/pc/rich-text/{blots → lib/blots}/break.d.ts +0 -0
  352. package/types/pc/rich-text/{blots → lib/blots}/container.d.ts +0 -0
  353. package/types/pc/rich-text/{blots → lib/blots}/cursor.d.ts +0 -0
  354. package/types/pc/rich-text/{blots → lib/blots}/embed.d.ts +0 -0
  355. package/types/pc/rich-text/{blots → lib/blots}/inline.d.ts +0 -0
  356. package/types/pc/rich-text/{blots → lib/blots}/scroll.d.ts +0 -0
  357. package/types/pc/rich-text/{blots → lib/blots}/text.d.ts +0 -0
  358. package/types/pc/rich-text/{core → lib/core}/composition.d.ts +0 -0
  359. package/types/pc/rich-text/{core → lib/core}/emitter.d.ts +0 -0
  360. package/types/pc/rich-text/{core → lib/core}/instances.d.ts +0 -0
  361. package/types/pc/rich-text/{core → lib/core}/logger.d.ts +0 -0
  362. package/types/pc/rich-text/{core → lib/core}/module.d.ts +0 -0
  363. package/types/pc/rich-text/{core → lib/core}/theme.d.ts +0 -0
  364. package/types/pc/rich-text/{core → lib/core}/utils/createRegistryWithFormats.d.ts +0 -0
  365. package/types/pc/rich-text/{core → lib/core}/utils/scrollRectIntoView.d.ts +0 -0
  366. package/types/pc/rich-text/{formats → lib/formats}/align.d.ts +0 -0
  367. package/types/pc/rich-text/{formats → lib/formats}/background.d.ts +0 -0
  368. package/types/pc/rich-text/{formats → lib/formats}/blockquote.d.ts +0 -0
  369. package/types/pc/rich-text/{formats → lib/formats}/code.d.ts +0 -0
  370. package/types/pc/rich-text/{formats → lib/formats}/color.d.ts +0 -0
  371. package/types/pc/rich-text/{formats → lib/formats}/direction.d.ts +0 -0
  372. package/types/pc/rich-text/{formats → lib/formats}/formula.d.ts +0 -0
  373. package/types/pc/rich-text/{formats → lib/formats}/header.d.ts +0 -0
  374. package/types/pc/rich-text/{formats → lib/formats}/image.d.ts +0 -0
  375. package/types/pc/rich-text/{formats → lib/formats}/indent.d.ts +0 -0
  376. package/types/pc/rich-text/{formats → lib/formats}/italic.d.ts +0 -0
  377. package/types/pc/rich-text/{formats → lib/formats}/link.d.ts +0 -0
  378. package/types/pc/rich-text/{formats → lib/formats}/script.d.ts +0 -0
  379. package/types/pc/rich-text/{formats → lib/formats}/size.d.ts +0 -0
  380. package/types/pc/rich-text/{formats → lib/formats}/strike.d.ts +0 -0
  381. package/types/pc/rich-text/{formats → lib/formats}/underline.d.ts +0 -0
  382. package/types/pc/rich-text/{formats → lib/formats}/video.d.ts +0 -0
  383. package/types/pc/rich-text/{rich.d.ts → lib/index.d.ts} +0 -0
  384. package/types/pc/rich-text/{modules → lib/modules}/input.d.ts +0 -0
  385. package/types/pc/rich-text/{modules → lib/modules}/normalizeExternalHTML/index.d.ts +0 -0
  386. package/types/pc/rich-text/{modules → lib/modules}/normalizeExternalHTML/normalizers/googleDocs.d.ts +0 -0
  387. package/types/pc/rich-text/{modules → lib/modules}/normalizeExternalHTML/normalizers/msWord.d.ts +0 -0
  388. package/types/pc/rich-text/{modules → lib/modules}/table.d.ts +0 -0
  389. package/types/pc/rich-text/{modules → lib/modules}/uiNode.d.ts +0 -0
  390. package/types/pc/rich-text/{modules → lib/modules}/uploader.d.ts +0 -0
  391. package/types/pc/rich-text/{parchment → lib/parchment}/attributor/class.d.ts +0 -0
  392. package/types/pc/rich-text/{parchment → lib/parchment}/attributor/store.d.ts +0 -0
  393. package/types/pc/rich-text/{parchment → lib/parchment}/blot/abstract/blot.d.ts +0 -0
  394. package/types/pc/rich-text/{parchment → lib/parchment}/blot/abstract/container.d.ts +0 -0
  395. package/types/pc/rich-text/{parchment → lib/parchment}/blot/abstract/leaf.d.ts +0 -0
  396. package/types/pc/rich-text/{parchment → lib/parchment}/blot/abstract/parent.d.ts +0 -0
  397. package/types/pc/rich-text/{parchment → lib/parchment}/blot/abstract/shadow.d.ts +0 -0
  398. package/types/pc/rich-text/{parchment → lib/parchment}/blot/block.d.ts +0 -0
  399. package/types/pc/rich-text/{parchment → lib/parchment}/blot/embed.d.ts +0 -0
  400. package/types/pc/rich-text/{parchment → lib/parchment}/blot/inline.d.ts +0 -0
  401. package/types/pc/rich-text/{parchment → lib/parchment}/blot/scroll.d.ts +0 -0
  402. package/types/pc/rich-text/{parchment → lib/parchment}/blot/text.d.ts +0 -0
  403. package/types/pc/rich-text/{parchment → lib/parchment}/collection/linked-list.d.ts +0 -0
  404. package/types/pc/rich-text/{parchment → lib/parchment}/collection/linked-node.d.ts +0 -0
  405. package/types/pc/rich-text/{parchment → lib/parchment}/error.d.ts +0 -0
  406. package/types/pc/rich-text/{parchment → lib/parchment}/index.d.ts +1 -1
  407. /package/types/pc/rich-text/{parchment → lib/parchment}/registry.d.ts +0 -0
  408. /package/types/pc/rich-text/{parchment → lib/parchment}/scope.d.ts +0 -0
  409. /package/types/pc/rich-text/{themes → lib/themes}/base.d.ts +0 -0
  410. /package/types/pc/rich-text/{themes → lib/themes}/pqb.d.ts +0 -0
  411. /package/types/pc/rich-text/{ui → lib/ui}/color-picker.d.ts +0 -0
  412. /package/types/pc/rich-text/{ui → lib/ui}/icon-picker.d.ts +0 -0
  413. /package/types/pc/rich-text/{ui → lib/ui}/tooltip.d.ts +0 -0
package/chunk/BCmfDFV4.js DELETED
@@ -1,4237 +0,0 @@
1
- import it from "lodash/merge";
2
- import { RICH_TEXT_CLASS_NAME_PREFIX as L } from "../rich-text/constant.js";
3
- import lt from "@unicom-cloud/utils/diff";
4
- import W from "lodash/cloneDeep";
5
- import X from "lodash/isEqual";
6
- import ue from "@unicom-cloud/utils/emitter";
7
- import { isMacOS as fe } from "@unicom-cloud/utils/constant/platform";
8
- var kt;
9
- ((r) => {
10
- function t(n = {}, o = {}, l = !1) {
11
- typeof n != "object" && (n = {}), typeof o != "object" && (o = {});
12
- let a = W(o);
13
- l || (a = Object.keys(a).reduce((c, h) => (a[h] != null && (c[h] = a[h]), c), {}));
14
- for (const c in n)
15
- n[c] !== void 0 && o[c] === void 0 && (a[c] = n[c]);
16
- return Object.keys(a).length > 0 ? a : void 0;
17
- }
18
- r.compose = t;
19
- function e(n = {}, o = {}) {
20
- typeof n != "object" && (n = {}), typeof o != "object" && (o = {});
21
- const l = Object.keys(n).concat(Object.keys(o)).reduce((a, c) => (X(n[c], o[c]) || (a[c] = o[c] === void 0 ? null : o[c]), a), {});
22
- return Object.keys(l).length > 0 ? l : void 0;
23
- }
24
- r.diff = e;
25
- function s(n = {}, o = {}) {
26
- n = n || {};
27
- const l = Object.keys(o).reduce((a, c) => (o[c] !== n[c] && n[c] !== void 0 && (a[c] = o[c]), a), {});
28
- return Object.keys(n).reduce((a, c) => (n[c] !== o[c] && o[c] === void 0 && (a[c] = null), a), l);
29
- }
30
- r.invert = s;
31
- function i(n, o, l = !1) {
32
- if (typeof n != "object")
33
- return o;
34
- if (typeof o != "object")
35
- return;
36
- if (!l)
37
- return o;
38
- const a = Object.keys(o).reduce((c, h) => (n[h] === void 0 && (c[h] = o[h]), c), {});
39
- return Object.keys(a).length > 0 ? a : void 0;
40
- }
41
- r.transform = i;
42
- })(kt || (kt = {}));
43
- const C = kt;
44
- var Ot;
45
- ((r) => {
46
- function t(e) {
47
- return typeof e.delete == "number" ? e.delete : typeof e.retain == "number" ? e.retain : typeof e.retain == "object" && e.retain !== null ? 1 : typeof e.insert == "string" ? e.insert.length : 1;
48
- }
49
- r.length = t;
50
- })(Ot || (Ot = {}));
51
- const k = Ot;
52
- class R {
53
- constructor(t) {
54
- this.ops = t, this.index = 0, this.offset = 0;
55
- }
56
- hasNext() {
57
- return this.peekLength() < 1 / 0;
58
- }
59
- next(t) {
60
- t || (t = 1 / 0);
61
- const e = this.ops[this.index];
62
- if (e) {
63
- const s = this.offset, i = k.length(e);
64
- if (t >= i - s ? (t = i - s, this.index += 1, this.offset = 0) : this.offset += t, typeof e.delete == "number")
65
- return { delete: t };
66
- {
67
- const n = {};
68
- return e.attributes && (n.attributes = e.attributes), typeof e.retain == "number" ? n.retain = t : typeof e.retain == "object" && e.retain !== null ? n.retain = e.retain : typeof e.insert == "string" ? n.insert = e.insert.substr(s, t) : n.insert = e.insert, n;
69
- }
70
- } else
71
- return { retain: 1 / 0 };
72
- }
73
- peek() {
74
- return this.ops[this.index];
75
- }
76
- peekLength() {
77
- return this.ops[this.index] ? k.length(this.ops[this.index]) - this.offset : 1 / 0;
78
- }
79
- peekType() {
80
- const t = this.ops[this.index];
81
- return t ? typeof t.delete == "number" ? "delete" : typeof t.retain == "number" || typeof t.retain == "object" && t.retain !== null ? "retain" : "insert" : "retain";
82
- }
83
- rest() {
84
- if (this.hasNext()) {
85
- if (this.offset === 0)
86
- return this.ops.slice(this.index);
87
- {
88
- const t = this.offset, e = this.index, s = this.next(), i = this.ops.slice(this.index);
89
- return this.offset = t, this.index = e, [s].concat(i);
90
- }
91
- } else return [];
92
- }
93
- }
94
- const de = "\0", jt = (r, t) => {
95
- if (typeof r != "object" || r === null)
96
- throw new Error(`cannot retain a ${typeof r}`);
97
- if (typeof t != "object" || t === null)
98
- throw new Error(`cannot retain a ${typeof t}`);
99
- const e = Object.keys(r)[0];
100
- if (!e || e !== Object.keys(t)[0])
101
- throw new Error(
102
- `embed types not matched: ${e} != ${Object.keys(t)[0]}`
103
- );
104
- return [e, r[e], t[e]];
105
- };
106
- class f {
107
- static {
108
- this.Op = k;
109
- }
110
- static {
111
- this.OpIterator = R;
112
- }
113
- static {
114
- this.AttributeMap = C;
115
- }
116
- static {
117
- this.handlers = {};
118
- }
119
- static registerEmbed(t, e) {
120
- this.handlers[t] = e;
121
- }
122
- static unregisterEmbed(t) {
123
- delete this.handlers[t];
124
- }
125
- static getHandler(t) {
126
- const e = this.handlers[t];
127
- if (!e)
128
- throw new Error(`no handlers for embed type "${t}"`);
129
- return e;
130
- }
131
- constructor(t) {
132
- Array.isArray(t) ? this.ops = t : t != null && Array.isArray(t.ops) ? this.ops = t.ops : this.ops = [];
133
- }
134
- insert(t, e) {
135
- const s = {};
136
- return typeof t == "string" && t.length === 0 ? this : (s.insert = t, e != null && typeof e == "object" && Object.keys(e).length > 0 && (s.attributes = e), this.push(s));
137
- }
138
- delete(t) {
139
- return t <= 0 ? this : this.push({ delete: t });
140
- }
141
- retain(t, e) {
142
- if (typeof t == "number" && t <= 0)
143
- return this;
144
- const s = { retain: t };
145
- return e != null && typeof e == "object" && Object.keys(e).length > 0 && (s.attributes = e), this.push(s);
146
- }
147
- push(t) {
148
- let e = this.ops.length, s = this.ops[e - 1];
149
- if (t = W(t), typeof s == "object") {
150
- if (typeof t.delete == "number" && typeof s.delete == "number")
151
- return this.ops[e - 1] = { delete: s.delete + t.delete }, this;
152
- if (typeof s.delete == "number" && t.insert != null && (e -= 1, s = this.ops[e - 1], typeof s != "object"))
153
- return this.ops.unshift(t), this;
154
- if (X(t.attributes, s.attributes)) {
155
- if (typeof t.insert == "string" && typeof s.insert == "string")
156
- return this.ops[e - 1] = { insert: s.insert + t.insert }, typeof t.attributes == "object" && (this.ops[e - 1].attributes = t.attributes), this;
157
- if (typeof t.retain == "number" && typeof s.retain == "number")
158
- return this.ops[e - 1] = { retain: s.retain + t.retain }, typeof t.attributes == "object" && (this.ops[e - 1].attributes = t.attributes), this;
159
- }
160
- }
161
- return e === this.ops.length ? this.ops.push(t) : this.ops.splice(e, 0, t), this;
162
- }
163
- chop() {
164
- const t = this.ops[this.ops.length - 1];
165
- return t && typeof t.retain == "number" && !t.attributes && this.ops.pop(), this;
166
- }
167
- filter(t) {
168
- return this.ops.filter(t);
169
- }
170
- forEach(t) {
171
- this.ops.forEach(t);
172
- }
173
- map(t) {
174
- return this.ops.map(t);
175
- }
176
- partition(t) {
177
- const e = [], s = [];
178
- return this.forEach((i) => {
179
- (t(i) ? e : s).push(i);
180
- }), [e, s];
181
- }
182
- reduce(t, e) {
183
- return this.ops.reduce(t, e);
184
- }
185
- changeLength() {
186
- return this.reduce((t, e) => e.insert ? t + k.length(e) : e.delete ? t - e.delete : t, 0);
187
- }
188
- length() {
189
- return this.reduce((t, e) => t + k.length(e), 0);
190
- }
191
- slice(t = 0, e = 1 / 0) {
192
- const s = [], i = new R(this.ops);
193
- let n = 0;
194
- for (; n < e && i.hasNext(); ) {
195
- let o;
196
- n < t ? o = i.next(t - n) : (o = i.next(e - n), s.push(o)), n += k.length(o);
197
- }
198
- return new f(s);
199
- }
200
- compose(t) {
201
- const e = new R(this.ops), s = new R(t.ops), i = [], n = s.peek();
202
- if (n != null && typeof n.retain == "number" && n.attributes == null) {
203
- let l = n.retain;
204
- for (; e.peekType() === "insert" && e.peekLength() <= l; )
205
- l -= e.peekLength(), i.push(e.next());
206
- n.retain - l > 0 && s.next(n.retain - l);
207
- }
208
- const o = new f(i);
209
- for (; e.hasNext() || s.hasNext(); )
210
- if (s.peekType() === "insert")
211
- o.push(s.next());
212
- else if (e.peekType() === "delete")
213
- o.push(e.next());
214
- else {
215
- const l = Math.min(e.peekLength(), s.peekLength()), a = e.next(l), c = s.next(l);
216
- if (c.retain) {
217
- const h = {};
218
- if (typeof a.retain == "number")
219
- h.retain = typeof c.retain == "number" ? l : c.retain;
220
- else if (typeof c.retain == "number")
221
- a.retain == null ? h.insert = a.insert : h.retain = a.retain;
222
- else {
223
- const g = a.retain == null ? "insert" : "retain", [b, N, E] = jt(
224
- a[g],
225
- c.retain
226
- ), w = f.getHandler(b);
227
- h[g] = {
228
- [b]: w.compose(
229
- N,
230
- E,
231
- g === "retain"
232
- )
233
- };
234
- }
235
- const d = C.compose(
236
- a.attributes,
237
- c.attributes,
238
- typeof a.retain == "number"
239
- );
240
- if (d && (h.attributes = d), o.push(h), !s.hasNext() && X(o.ops[o.ops.length - 1], h)) {
241
- const g = new f(e.rest());
242
- return o.concat(g).chop();
243
- }
244
- } else typeof c.delete == "number" && (typeof a.retain == "number" || typeof a.retain == "object" && a.retain !== null) && o.push(c);
245
- }
246
- return o.chop();
247
- }
248
- concat(t) {
249
- const e = new f(this.ops.slice());
250
- return t.ops.length > 0 && (e.push(t.ops[0]), e.ops = e.ops.concat(t.ops.slice(1))), e;
251
- }
252
- diff(t, e) {
253
- if (this.ops === t.ops)
254
- return new f();
255
- const s = [this, t].map((a) => a.map((c) => {
256
- if (c.insert != null)
257
- return typeof c.insert == "string" ? c.insert : de;
258
- const h = a === t ? "on" : "with";
259
- throw new Error("diff() called " + h + " non-document");
260
- }).join("")), i = new f(), n = lt(s[0], s[1], e, !0), o = new R(this.ops), l = new R(t.ops);
261
- return n.forEach((a) => {
262
- let c = a[1].length;
263
- for (; c > 0; ) {
264
- let h = 0;
265
- switch (a[0]) {
266
- case lt.INSERT:
267
- h = Math.min(l.peekLength(), c), i.push(l.next(h));
268
- break;
269
- case lt.DELETE:
270
- h = Math.min(c, o.peekLength()), o.next(h), i.delete(h);
271
- break;
272
- case lt.EQUAL:
273
- h = Math.min(
274
- o.peekLength(),
275
- l.peekLength(),
276
- c
277
- );
278
- const d = o.next(h), g = l.next(h);
279
- X(d.insert, g.insert) ? i.retain(
280
- h,
281
- C.diff(d.attributes, g.attributes)
282
- ) : i.push(g).delete(h);
283
- break;
284
- }
285
- c -= h;
286
- }
287
- }), i.chop();
288
- }
289
- eachLine(t, e = `
290
- `) {
291
- const s = new R(this.ops);
292
- let i = new f(), n = 0;
293
- for (; s.hasNext(); ) {
294
- if (s.peekType() !== "insert")
295
- return;
296
- const o = s.peek(), l = k.length(o) - s.peekLength(), a = typeof o.insert == "string" ? o.insert.indexOf(e, l) - l : -1;
297
- if (a < 0)
298
- i.push(s.next());
299
- else if (a > 0)
300
- i.push(s.next(a));
301
- else {
302
- if (t(i, s.next(1).attributes || {}, n) === !1)
303
- return;
304
- n += 1, i = new f();
305
- }
306
- }
307
- i.length() > 0 && t(i, {}, n);
308
- }
309
- invert(t) {
310
- const e = new f();
311
- return this.reduce((s, i) => {
312
- if (i.insert)
313
- e.delete(k.length(i));
314
- else {
315
- if (typeof i.retain == "number" && i.attributes == null)
316
- return e.retain(i.retain), s + i.retain;
317
- if (i.delete || typeof i.retain == "number") {
318
- const n = i.delete || i.retain;
319
- return t.slice(s, s + n).forEach((l) => {
320
- i.delete ? e.push(l) : i.retain && i.attributes && e.retain(
321
- k.length(l),
322
- C.invert(i.attributes, l.attributes)
323
- );
324
- }), s + n;
325
- } else if (typeof i.retain == "object" && i.retain !== null) {
326
- const n = t.slice(s, s + 1), o = new R(n.ops).next(), [l, a, c] = jt(
327
- i.retain,
328
- o.insert
329
- ), h = f.getHandler(l);
330
- return e.retain(
331
- { [l]: h.invert(a, c) },
332
- C.invert(i.attributes, o.attributes)
333
- ), s + 1;
334
- }
335
- }
336
- return s;
337
- }, 0), e.chop();
338
- }
339
- transform(t, e = !1) {
340
- if (e = !!e, typeof t == "number")
341
- return this.transformPosition(t, e);
342
- const s = t, i = new R(this.ops), n = new R(s.ops), o = new f();
343
- for (; i.hasNext() || n.hasNext(); )
344
- if (i.peekType() === "insert" && (e || n.peekType() !== "insert"))
345
- o.retain(k.length(i.next()));
346
- else if (n.peekType() === "insert")
347
- o.push(n.next());
348
- else {
349
- const l = Math.min(i.peekLength(), n.peekLength()), a = i.next(l), c = n.next(l);
350
- if (a.delete)
351
- continue;
352
- if (c.delete)
353
- o.push(c);
354
- else {
355
- const h = a.retain, d = c.retain;
356
- let g = typeof d == "object" && d !== null ? d : l;
357
- if (typeof h == "object" && h !== null && typeof d == "object" && d !== null) {
358
- const b = Object.keys(h)[0];
359
- if (b === Object.keys(d)[0]) {
360
- const N = f.getHandler(b);
361
- N && (g = {
362
- [b]: N.transform(
363
- h[b],
364
- d[b],
365
- e
366
- )
367
- });
368
- }
369
- }
370
- o.retain(
371
- g,
372
- C.transform(
373
- a.attributes,
374
- c.attributes,
375
- e
376
- )
377
- );
378
- }
379
- }
380
- return o.chop();
381
- }
382
- transformPosition(t, e = !1) {
383
- e = !!e;
384
- const s = new R(this.ops);
385
- let i = 0;
386
- for (; s.hasNext() && i <= t; ) {
387
- const n = s.peekLength(), o = s.peekType();
388
- if (s.next(), o === "delete") {
389
- t -= Math.min(n, t - i);
390
- continue;
391
- } else o === "insert" && (i < t || !e) && (t += n);
392
- i += n;
393
- }
394
- return t;
395
- }
396
- }
397
- var p = /* @__PURE__ */ ((r) => (r[r.TYPE = 3] = "TYPE", r[r.LEVEL = 12] = "LEVEL", r[r.ATTRIBUTE = 13] = "ATTRIBUTE", r[r.BLOT = 14] = "BLOT", r[r.INLINE = 7] = "INLINE", r[r.BLOCK = 11] = "BLOCK", r[r.BLOCK_BLOT = 10] = "BLOCK_BLOT", r[r.INLINE_BLOT = 6] = "INLINE_BLOT", r[r.BLOCK_ATTRIBUTE = 9] = "BLOCK_ATTRIBUTE", r[r.INLINE_ATTRIBUTE = 5] = "INLINE_ATTRIBUTE", r[r.ANY = 15] = "ANY", r))(p || {});
398
- class pe {
399
- constructor() {
400
- this.head = null, this.tail = null, this.length = 0;
401
- }
402
- append(...t) {
403
- if (this.insertBefore(t[0], null), t.length > 1) {
404
- const e = t.slice(1);
405
- this.append(...e);
406
- }
407
- }
408
- at(t) {
409
- const e = this.iterator();
410
- let s = e();
411
- for (; s && t > 0; )
412
- t -= 1, s = e();
413
- return s;
414
- }
415
- contains(t) {
416
- const e = this.iterator();
417
- let s = e();
418
- for (; s; ) {
419
- if (s === t)
420
- return !0;
421
- s = e();
422
- }
423
- return !1;
424
- }
425
- indexOf(t) {
426
- const e = this.iterator();
427
- let s = e(), i = 0;
428
- for (; s; ) {
429
- if (s === t)
430
- return i;
431
- i += 1, s = e();
432
- }
433
- return -1;
434
- }
435
- insertBefore(t, e) {
436
- t != null && (this.remove(t), t.next = e, e != null ? (t.prev = e.prev, e.prev != null && (e.prev.next = t), e.prev = t, e === this.head && (this.head = t)) : this.tail != null ? (this.tail.next = t, t.prev = this.tail, this.tail = t) : (t.prev = null, this.head = this.tail = t), this.length += 1);
437
- }
438
- offset(t) {
439
- let e = 0, s = this.head;
440
- for (; s != null; ) {
441
- if (s === t)
442
- return e;
443
- e += s.length(), s = s.next;
444
- }
445
- return -1;
446
- }
447
- remove(t) {
448
- this.contains(t) && (t.prev != null && (t.prev.next = t.next), t.next != null && (t.next.prev = t.prev), t === this.head && (this.head = t.next), t === this.tail && (this.tail = t.prev), this.length -= 1);
449
- }
450
- iterator(t = this.head) {
451
- return () => {
452
- const e = t;
453
- return t != null && (t = t.next), e;
454
- };
455
- }
456
- find(t, e = !1) {
457
- const s = this.iterator();
458
- let i = s();
459
- for (; i; ) {
460
- const n = i.length();
461
- if (t < n || e && t === n && (i.next == null || i.next.length() !== 0))
462
- return [i, t];
463
- t -= n, i = s();
464
- }
465
- return [null, 0];
466
- }
467
- forEach(t) {
468
- const e = this.iterator();
469
- let s = e();
470
- for (; s; )
471
- t(s), s = e();
472
- }
473
- forEachAt(t, e, s) {
474
- if (e <= 0)
475
- return;
476
- const [i, n] = this.find(t);
477
- let o = t - n;
478
- const l = this.iterator(i);
479
- let a = l();
480
- for (; a && o < t + e; ) {
481
- const c = a.length();
482
- t > o ? s(
483
- a,
484
- t - o,
485
- Math.min(e, o + c - t)
486
- ) : s(a, 0, Math.min(c, t + e - o)), o += c, a = l();
487
- }
488
- }
489
- map(t) {
490
- return this.reduce((e, s) => (e.push(t(s)), e), []);
491
- }
492
- reduce(t, e) {
493
- const s = this.iterator();
494
- let i = s();
495
- for (; i; )
496
- e = t(e, i), i = s();
497
- return e;
498
- }
499
- }
500
- class J extends Error {
501
- constructor(t) {
502
- t = "[Parchment] " + t, super(t), this.message = t, this.name = this.constructor.name;
503
- }
504
- }
505
- class K {
506
- constructor() {
507
- this.attributes = {}, this.classes = {}, this.tags = {}, this.types = {};
508
- }
509
- static {
510
- this.blots = /* @__PURE__ */ new WeakMap();
511
- }
512
- static find(t, e = !1) {
513
- if (t == null)
514
- return null;
515
- if (this.blots.has(t))
516
- return this.blots.get(t) || null;
517
- if (e) {
518
- let s = null;
519
- try {
520
- s = t.parentNode;
521
- } catch {
522
- return null;
523
- }
524
- return this.find(s, e);
525
- }
526
- return null;
527
- }
528
- create(t, e, s) {
529
- const i = this.query(e);
530
- if (i == null)
531
- throw new J(`Unable to create ${e} blot`);
532
- const n = i, o = e instanceof Node || e.nodeType === Node.TEXT_NODE ? e : n.create(s), l = new n(t, o, s);
533
- return K.blots.set(l.domNode, l), l;
534
- }
535
- find(t, e = !1) {
536
- return K.find(t, e);
537
- }
538
- query(t, e = p.ANY) {
539
- let s;
540
- return typeof t == "string" ? s = this.types[t] || this.attributes[t] : t instanceof Text || t.nodeType === Node.TEXT_NODE ? s = this.types.text : typeof t == "number" ? t & p.LEVEL & p.BLOCK ? s = this.types.block : t & p.LEVEL & p.INLINE && (s = this.types.inline) : t instanceof Element && ((t.getAttribute("class") || "").split(/\s+/).some((n) => (s = this.classes[n], !!s)), s = s || this.tags[t.tagName]), s == null ? null : "scope" in s && e & p.LEVEL & s.scope && e & p.TYPE & s.scope ? s : null;
541
- }
542
- register(...t) {
543
- return t.map((e) => {
544
- const s = "blotName" in e, i = "attrName" in e;
545
- if (!s && !i)
546
- throw new J("Invalid definition");
547
- if (s && e.blotName === "abstract")
548
- throw new J("Cannot register abstract class");
549
- const n = s ? e.blotName : i ? e.attrName : void 0;
550
- return this.types[n] = e, i ? typeof e.keyName == "string" && (this.attributes[e.keyName] = e) : s && (e.className && (this.classes[e.className] = e), e.tagName && (Array.isArray(e.tagName) ? e.tagName = e.tagName.map((l) => l.toUpperCase()) : e.tagName = e.tagName.toUpperCase(), (Array.isArray(e.tagName) ? e.tagName : [e.tagName]).forEach((l) => {
551
- (this.tags[l] == null || e.className == null) && (this.tags[l] = e);
552
- }))), e;
553
- });
554
- }
555
- }
556
- class ee {
557
- constructor(t, e) {
558
- this.scroll = t, this.domNode = e, K.blots.set(e, this), this.prev = null, this.next = null;
559
- }
560
- static {
561
- this.blotName = "abstract";
562
- }
563
- static create(t) {
564
- if (this.tagName == null)
565
- throw new J("Blot definition missing tagName");
566
- let e, s;
567
- return Array.isArray(this.tagName) ? (typeof t == "string" ? (s = t.toUpperCase(), parseInt(s, 10).toString() === s && (s = parseInt(s, 10))) : typeof t == "number" && (s = t), typeof s == "number" ? e = document.createElement(this.tagName[s - 1]) : s && this.tagName.indexOf(s) > -1 ? e = document.createElement(s) : e = document.createElement(this.tagName[0])) : e = document.createElement(this.tagName), this.className && e.classList.add(this.className), e;
568
- }
569
- // Hack for accessing inherited static methods
570
- get statics() {
571
- return this.constructor;
572
- }
573
- attach() {
574
- }
575
- clone() {
576
- const t = this.domNode.cloneNode(!1);
577
- return this.scroll.create(t);
578
- }
579
- detach() {
580
- this.parent != null && this.parent.removeChild(this), K.blots.delete(this.domNode);
581
- }
582
- deleteAt(t, e) {
583
- this.isolate(t, e).remove();
584
- }
585
- formatAt(t, e, s, i) {
586
- const n = this.isolate(t, e);
587
- if (this.scroll.query(s, p.BLOT) != null && i)
588
- n.wrap(s, i);
589
- else if (this.scroll.query(s, p.ATTRIBUTE) != null) {
590
- const o = this.scroll.create(this.statics.scope);
591
- n.wrap(o), o.format(s, i);
592
- }
593
- }
594
- insertAt(t, e, s) {
595
- const i = s == null ? this.scroll.create("text", e) : this.scroll.create(e, s), n = this.split(t);
596
- this.parent.insertBefore(i, n || void 0);
597
- }
598
- isolate(t, e) {
599
- const s = this.split(t);
600
- if (s == null)
601
- throw new Error("Attempt to isolate at end");
602
- return s.split(e), s;
603
- }
604
- length() {
605
- return 1;
606
- }
607
- offset(t = this.parent) {
608
- return this.parent == null || this === t ? 0 : this.parent.children.offset(this) + this.parent.offset(t);
609
- }
610
- optimize(t) {
611
- this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer) && this.wrap(this.statics.requiredContainer.blotName);
612
- }
613
- remove() {
614
- this.domNode.parentNode != null && this.domNode.parentNode.removeChild(this.domNode), this.detach();
615
- }
616
- replaceWith(t, e) {
617
- const s = typeof t == "string" ? this.scroll.create(t, e) : t;
618
- return this.parent != null && (this.parent.insertBefore(s, this.next || void 0), this.remove()), s;
619
- }
620
- split(t, e) {
621
- return t === 0 ? this : this.next;
622
- }
623
- update(t, e) {
624
- }
625
- wrap(t, e) {
626
- const s = typeof t == "string" ? this.scroll.create(t, e) : t;
627
- if (this.parent != null && this.parent.insertBefore(s, this.next || void 0), typeof s.appendChild != "function")
628
- throw new J(`Cannot wrap ${t}`);
629
- return s.appendChild(this), s;
630
- }
631
- }
632
- function $t(r, t) {
633
- const e = t.find(r);
634
- if (e) return e;
635
- try {
636
- return t.create(r);
637
- } catch {
638
- const i = t.create(p.INLINE);
639
- return Array.from(r.childNodes).forEach((n) => {
640
- i.domNode.appendChild(n);
641
- }), r.parentNode && r.parentNode.replaceChild(i.domNode, r), i.attach(), i;
642
- }
643
- }
644
- class T extends ee {
645
- constructor(t, e) {
646
- super(t, e), this.uiNode = null, this.build();
647
- }
648
- static {
649
- this.uiClass = "";
650
- }
651
- appendChild(t) {
652
- this.insertBefore(t);
653
- }
654
- attach() {
655
- super.attach(), this.children.forEach((t) => {
656
- t.attach();
657
- });
658
- }
659
- attachUI(t) {
660
- this.uiNode != null && this.uiNode.remove(), this.uiNode = t, T.uiClass && this.uiNode.classList.add(T.uiClass), this.uiNode.setAttribute("contenteditable", "false"), this.domNode.insertBefore(this.uiNode, this.domNode.firstChild);
661
- }
662
- /**
663
- * Called during construction, should fill its own children LinkedList.
664
- */
665
- build() {
666
- this.children = new pe(), Array.from(this.domNode.childNodes).filter((t) => t !== this.uiNode).reverse().forEach((t) => {
667
- try {
668
- const e = $t(t, this.scroll);
669
- this.insertBefore(e, this.children.head || void 0);
670
- } catch (e) {
671
- if (e instanceof J)
672
- return;
673
- throw e;
674
- }
675
- });
676
- }
677
- deleteAt(t, e) {
678
- if (t === 0 && e === this.length())
679
- return this.remove();
680
- this.children.forEachAt(t, e, (s, i, n) => {
681
- s.deleteAt(i, n);
682
- });
683
- }
684
- descendant(t, e = 0) {
685
- const [s, i] = this.children.find(e);
686
- return t.blotName == null && t(s) || t.blotName != null && s instanceof t ? [s, i] : s instanceof T ? s.descendant(t, i) : [null, -1];
687
- }
688
- descendants(t, e = 0, s = Number.MAX_VALUE) {
689
- let i = [], n = s;
690
- return this.children.forEachAt(
691
- e,
692
- s,
693
- (o, l, a) => {
694
- (t.blotName == null && t(o) || t.blotName != null && o instanceof t) && i.push(o), o instanceof T && (i = i.concat(
695
- o.descendants(t, l, n)
696
- )), n -= a;
697
- }
698
- ), i;
699
- }
700
- detach() {
701
- this.children.forEach((t) => {
702
- t.detach();
703
- }), super.detach();
704
- }
705
- enforceAllowedChildren() {
706
- let t = !1;
707
- this.children.forEach((e) => {
708
- t || this.statics.allowedChildren.some(
709
- (i) => e instanceof i
710
- ) || (e.statics.scope === p.BLOCK_BLOT ? (e.next != null && this.splitAfter(e), e.prev != null && this.splitAfter(e.prev), e.parent.unwrap(), t = !0) : e instanceof T ? e.unwrap() : e.remove());
711
- });
712
- }
713
- formatAt(t, e, s, i) {
714
- this.children.forEachAt(t, e, (n, o, l) => {
715
- n.formatAt(o, l, s, i);
716
- });
717
- }
718
- insertAt(t, e, s) {
719
- const [i, n] = this.children.find(t);
720
- if (i)
721
- i.insertAt(n, e, s);
722
- else {
723
- const o = s == null ? this.scroll.create("text", e) : this.scroll.create(e, s);
724
- this.appendChild(o);
725
- }
726
- }
727
- insertBefore(t, e) {
728
- t.parent != null && t.parent.children.remove(t);
729
- let s = null;
730
- this.children.insertBefore(t, e || null), t.parent = this, e != null && (s = e.domNode), (this.domNode.parentNode !== t.domNode || this.domNode.nextSibling !== s) && this.domNode.insertBefore(t.domNode, s), t.attach();
731
- }
732
- length() {
733
- return this.children.reduce((t, e) => t + e.length(), 0);
734
- }
735
- moveChildren(t, e) {
736
- this.children.forEach((s) => {
737
- t.insertBefore(s, e);
738
- });
739
- }
740
- optimize(t) {
741
- if (super.optimize(t), this.enforceAllowedChildren(), this.uiNode != null && this.uiNode !== this.domNode.firstChild && this.domNode.insertBefore(this.uiNode, this.domNode.firstChild), this.children.length === 0)
742
- if (this.statics.defaultChild != null) {
743
- const e = this.scroll.create(this.statics.defaultChild.blotName);
744
- this.appendChild(e);
745
- } else
746
- this.remove();
747
- }
748
- path(t, e = !1) {
749
- const [s, i] = this.children.find(t, e), n = [[this, t]];
750
- return s instanceof T ? n.concat(s.path(i, e)) : (s != null && n.push([s, i]), n);
751
- }
752
- removeChild(t) {
753
- this.children.remove(t);
754
- }
755
- replaceWith(t, e) {
756
- const s = typeof t == "string" ? this.scroll.create(t, e) : t;
757
- return s instanceof T && this.moveChildren(s), super.replaceWith(s);
758
- }
759
- split(t, e = !1) {
760
- if (!e) {
761
- if (t === 0)
762
- return this;
763
- if (t === this.length())
764
- return this.next;
765
- }
766
- const s = this.clone();
767
- return this.parent && this.parent.insertBefore(s, this.next || void 0), this.children.forEachAt(t, this.length(), (i, n, o) => {
768
- const l = i.split(n, e);
769
- l != null && s.appendChild(l);
770
- }), s;
771
- }
772
- splitAfter(t) {
773
- const e = this.clone();
774
- for (; t.next != null; )
775
- e.appendChild(t.next);
776
- return this.parent && this.parent.insertBefore(e, this.next || void 0), e;
777
- }
778
- unwrap() {
779
- this.parent && this.moveChildren(this.parent, this.next || void 0), this.remove();
780
- }
781
- update(t, e) {
782
- const s = [], i = [];
783
- t.forEach((n) => {
784
- n.target === this.domNode && n.type === "childList" && (s.push(...n.addedNodes), i.push(...n.removedNodes));
785
- }), i.forEach((n) => {
786
- if (n.parentNode != null && n.tagName !== "IFRAME" && document.body.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_CONTAINED_BY)
787
- return;
788
- const o = this.scroll.find(n);
789
- o != null && (o.domNode.parentNode == null || o.domNode.parentNode === this.domNode) && o.detach();
790
- }), s.filter((n) => n.parentNode === this.domNode && n !== this.uiNode).sort((n, o) => n === o ? 0 : n.compareDocumentPosition(o) & Node.DOCUMENT_POSITION_FOLLOWING ? 1 : -1).forEach((n) => {
791
- let o = null;
792
- n.nextSibling != null && (o = this.scroll.find(n.nextSibling));
793
- const l = $t(n, this.scroll);
794
- (l.next !== o || l.next == null) && (l.parent != null && l.parent.removeChild(this), this.insertBefore(l, o || void 0));
795
- }), this.enforceAllowedChildren();
796
- }
797
- }
798
- class dt extends T {
799
- static {
800
- this.blotName = "container";
801
- }
802
- static {
803
- this.scope = p.BLOCK_BLOT;
804
- }
805
- checkMerge() {
806
- return this.next !== null && this.next.statics.blotName === this.statics.blotName;
807
- }
808
- deleteAt(t, e) {
809
- super.deleteAt(t, e), this.enforceAllowedChildren();
810
- }
811
- formatAt(t, e, s, i) {
812
- super.formatAt(t, e, s, i), this.enforceAllowedChildren();
813
- }
814
- insertAt(t, e, s) {
815
- super.insertAt(t, e, s), this.enforceAllowedChildren();
816
- }
817
- optimize(t) {
818
- super.optimize(t), this.children.length > 0 && this.next != null && this.checkMerge() && (this.next.moveChildren(this), this.next.remove());
819
- }
820
- }
821
- class A extends ee {
822
- static {
823
- this.scope = p.INLINE_BLOT;
824
- }
825
- /**
826
- * Returns the value represented by domNode if it is this Blot's type
827
- * No checking that domNode can represent this Blot type is required so
828
- * applications needing it should check externally before calling.
829
- */
830
- static value(t) {
831
- return !0;
832
- }
833
- /**
834
- * Given location represented by node and offset from DOM Selection Range,
835
- * return index to that location.
836
- */
837
- index(t, e) {
838
- return this.domNode === t || this.domNode.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_CONTAINED_BY ? Math.min(e, 1) : -1;
839
- }
840
- /**
841
- * Given index to location within blot, return node and offset representing
842
- * that location, consumable by DOM Selection Range
843
- */
844
- position(t, e) {
845
- let i = Array.from(this.parent.domNode.childNodes).indexOf(this.domNode);
846
- return t > 0 && (i += 1), [this.parent.domNode, i];
847
- }
848
- /**
849
- * Return value represented by this blot
850
- * Should not change without interaction from API or
851
- * user change detectable by update()
852
- */
853
- value() {
854
- return {
855
- [this.statics.blotName]: this.statics.value(this.domNode) || !0
856
- };
857
- }
858
- }
859
- class j {
860
- constructor(t, e, s = {}) {
861
- this.attrName = t, this.keyName = e;
862
- const i = p.TYPE & p.ATTRIBUTE;
863
- this.scope = s.scope != null ? (
864
- // Ignore type bits, force attribute bit
865
- s.scope & p.LEVEL | i
866
- ) : p.ATTRIBUTE, s.whitelist != null && (this.whitelist = s.whitelist);
867
- }
868
- static keys(t) {
869
- return Array.from(t.attributes).map((e) => e.name);
870
- }
871
- add(t, e) {
872
- return this.canAdd(t, e) ? (t.setAttribute(this.keyName, e), !0) : !1;
873
- }
874
- canAdd(t, e) {
875
- return this.whitelist == null ? !0 : typeof e == "string" ? this.whitelist.indexOf(e.replace(/["']/g, "")) > -1 : this.whitelist.indexOf(e) > -1;
876
- }
877
- remove(t) {
878
- t.removeAttribute(this.keyName);
879
- }
880
- value(t) {
881
- const e = t.getAttribute(this.keyName);
882
- return this.canAdd(t, e) && e ? e : "";
883
- }
884
- }
885
- function Ft(r, t) {
886
- return (r.getAttribute("class") || "").split(/\s+/).filter((s) => s.indexOf(`${t}-`) === 0);
887
- }
888
- class q extends j {
889
- static keys(t) {
890
- return (t.getAttribute("class") || "").split(/\s+/).map((e) => e.split("-").slice(0, -1).join("-"));
891
- }
892
- add(t, e) {
893
- return this.canAdd(t, e) ? (this.remove(t), t.classList.add(`${this.keyName}-${e}`), !0) : !1;
894
- }
895
- remove(t) {
896
- Ft(t, this.keyName).forEach((s) => {
897
- t.classList.remove(s);
898
- }), t.classList.length === 0 && t.removeAttribute("class");
899
- }
900
- value(t) {
901
- const s = (Ft(t, this.keyName)[0] || "").slice(this.keyName.length + 1);
902
- return this.canAdd(t, s) ? s : "";
903
- }
904
- }
905
- function bt(r) {
906
- const t = r.split("-"), e = t.slice(1).map((s) => s[0].toUpperCase() + s.slice(1)).join("");
907
- return t[0] + e;
908
- }
909
- class V extends j {
910
- static keys(t) {
911
- return (t.getAttribute("style") || "").split(";").map((e) => e.split(":")[0].trim());
912
- }
913
- add(t, e) {
914
- return this.canAdd(t, e) ? (t.style[bt(this.keyName)] = e, !0) : !1;
915
- }
916
- remove(t) {
917
- t.style[bt(this.keyName)] = "", t.getAttribute("style") || t.removeAttribute("style");
918
- }
919
- value(t) {
920
- const e = t.style[bt(this.keyName)];
921
- return this.canAdd(t, e) ? e : "";
922
- }
923
- }
924
- class pt {
925
- constructor(t) {
926
- this.attributes = {}, this.domNode = t, this.build();
927
- }
928
- attribute(t, e) {
929
- e ? t.add(this.domNode, e) && (t.value(this.domNode) != null ? this.attributes[t.attrName] = t : delete this.attributes[t.attrName]) : (t.remove(this.domNode), delete this.attributes[t.attrName]);
930
- }
931
- build() {
932
- this.attributes = {};
933
- const t = K.find(this.domNode);
934
- if (t == null)
935
- return;
936
- const e = j.keys(this.domNode), s = q.keys(this.domNode), i = V.keys(this.domNode);
937
- e.concat(s).concat(i).forEach((n) => {
938
- const o = t.scroll.query(n, p.ATTRIBUTE);
939
- o instanceof j && (this.attributes[o.attrName] = o);
940
- });
941
- }
942
- copy(t) {
943
- Object.keys(this.attributes).forEach((e) => {
944
- const s = this.attributes[e].value(this.domNode);
945
- t.format(e, s);
946
- });
947
- }
948
- move(t) {
949
- this.copy(t), Object.keys(this.attributes).forEach((e) => {
950
- this.attributes[e].remove(this.domNode);
951
- }), this.attributes = {};
952
- }
953
- values() {
954
- return Object.keys(this.attributes).reduce(
955
- (t, e) => (t[e] = this.attributes[e].value(this.domNode), t),
956
- {}
957
- );
958
- }
959
- }
960
- function me(r, t) {
961
- if (Object.keys(r).length !== Object.keys(t).length)
962
- return !1;
963
- for (const e in r)
964
- if (r[e] !== t[e])
965
- return !1;
966
- return !0;
967
- }
968
- class D extends T {
969
- static {
970
- this.allowedChildren = [D, A];
971
- }
972
- static {
973
- this.blotName = "inline";
974
- }
975
- static {
976
- this.scope = p.INLINE_BLOT;
977
- }
978
- static {
979
- this.tagName = "SPAN";
980
- }
981
- static create(t) {
982
- return super.create(t);
983
- }
984
- static formats(t, e) {
985
- const s = e.query(D.blotName);
986
- if (!(s != null && t.tagName === s.tagName)) {
987
- if (typeof this.tagName == "string")
988
- return !0;
989
- if (Array.isArray(this.tagName))
990
- return t.tagName.toLowerCase();
991
- }
992
- }
993
- constructor(t, e) {
994
- super(t, e), this.attributes = new pt(this.domNode);
995
- }
996
- format(t, e) {
997
- if (t === this.statics.blotName && !e)
998
- this.children.forEach((s) => {
999
- s instanceof D || (s = s.wrap(D.blotName, !0)), this.attributes.copy(s);
1000
- }), this.unwrap();
1001
- else {
1002
- const s = this.scroll.query(t, p.INLINE);
1003
- if (s == null)
1004
- return;
1005
- s instanceof j ? this.attributes.attribute(s, e) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e);
1006
- }
1007
- }
1008
- formats() {
1009
- const t = this.attributes.values(), e = this.statics.formats(this.domNode, this.scroll);
1010
- return e != null && (t[this.statics.blotName] = e), t;
1011
- }
1012
- formatAt(t, e, s, i) {
1013
- this.formats()[s] != null || this.scroll.query(s, p.ATTRIBUTE) ? this.isolate(t, e).format(s, i) : super.formatAt(t, e, s, i);
1014
- }
1015
- optimize(t) {
1016
- super.optimize(t);
1017
- const e = this.formats();
1018
- if (Object.keys(e).length === 0)
1019
- return this.unwrap();
1020
- const s = this.next;
1021
- s instanceof D && s.prev === this && me(e, s.formats()) && (s.moveChildren(this), s.remove());
1022
- }
1023
- replaceWith(t, e) {
1024
- const s = super.replaceWith(t, e);
1025
- return this.attributes.copy(s), s;
1026
- }
1027
- update(t, e) {
1028
- super.update(t, e), t.some(
1029
- (i) => i.target === this.domNode && i.type === "attributes"
1030
- ) && this.attributes.build();
1031
- }
1032
- wrap(t, e) {
1033
- const s = super.wrap(t, e);
1034
- return s instanceof D && this.attributes.move(s), s;
1035
- }
1036
- }
1037
- class _ extends T {
1038
- static {
1039
- this.blotName = "block";
1040
- }
1041
- static {
1042
- this.scope = p.BLOCK_BLOT;
1043
- }
1044
- static {
1045
- this.tagName = "P";
1046
- }
1047
- static {
1048
- this.allowedChildren = [
1049
- D,
1050
- _,
1051
- A
1052
- ];
1053
- }
1054
- static create(t) {
1055
- return super.create(t);
1056
- }
1057
- static formats(t, e) {
1058
- const s = e.query(_.blotName);
1059
- if (!(s != null && t.tagName === s.tagName)) {
1060
- if (typeof this.tagName == "string")
1061
- return !0;
1062
- if (Array.isArray(this.tagName))
1063
- return t.tagName.toLowerCase();
1064
- }
1065
- }
1066
- constructor(t, e) {
1067
- super(t, e), this.attributes = new pt(this.domNode);
1068
- }
1069
- format(t, e) {
1070
- const s = this.scroll.query(t, p.BLOCK);
1071
- s != null && (s instanceof j ? this.attributes.attribute(s, e) : t === this.statics.blotName && !e ? this.replaceWith(_.blotName) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e));
1072
- }
1073
- formats() {
1074
- const t = this.attributes.values(), e = this.statics.formats(this.domNode, this.scroll);
1075
- return e != null && (t[this.statics.blotName] = e), t;
1076
- }
1077
- formatAt(t, e, s, i) {
1078
- this.scroll.query(s, p.BLOCK) != null ? this.format(s, i) : super.formatAt(t, e, s, i);
1079
- }
1080
- insertAt(t, e, s) {
1081
- if (s == null || this.scroll.query(e, p.INLINE) != null)
1082
- super.insertAt(t, e, s);
1083
- else {
1084
- const i = this.split(t);
1085
- if (i != null) {
1086
- const n = this.scroll.create(e, s);
1087
- i.parent.insertBefore(n, i);
1088
- } else
1089
- throw new Error("Attempt to insertAt after block boundaries");
1090
- }
1091
- }
1092
- replaceWith(t, e) {
1093
- const s = super.replaceWith(t, e);
1094
- return this.attributes.copy(s), s;
1095
- }
1096
- update(t, e) {
1097
- super.update(t, e), t.some(
1098
- (i) => i.target === this.domNode && i.type === "attributes"
1099
- ) && this.attributes.build();
1100
- }
1101
- }
1102
- class B extends A {
1103
- static formats(t, e) {
1104
- }
1105
- format(t, e) {
1106
- super.formatAt(0, this.length(), t, e);
1107
- }
1108
- formatAt(t, e, s, i) {
1109
- t === 0 && e === this.length() ? this.format(s, i) : super.formatAt(t, e, s, i);
1110
- }
1111
- formats() {
1112
- return this.statics.formats(this.domNode, this.scroll);
1113
- }
1114
- }
1115
- const ge = {
1116
- attributes: !0,
1117
- characterData: !0,
1118
- characterDataOldValue: !0,
1119
- childList: !0,
1120
- subtree: !0
1121
- }, be = 100;
1122
- class It extends T {
1123
- constructor(t, e) {
1124
- super(null, e), this.registry = t, this.scroll = this, this.build(), this.observer = new MutationObserver((s) => {
1125
- this.update(s);
1126
- }), this.observer.observe(this.domNode, ge), this.attach();
1127
- }
1128
- static {
1129
- this.blotName = "scroll";
1130
- }
1131
- static {
1132
- this.defaultChild = _;
1133
- }
1134
- static {
1135
- this.allowedChildren = [_, dt];
1136
- }
1137
- static {
1138
- this.scope = p.BLOCK_BLOT;
1139
- }
1140
- static {
1141
- this.tagName = "DIV";
1142
- }
1143
- create(t, e) {
1144
- return this.registry.create(this, t, e);
1145
- }
1146
- find(t, e = !1) {
1147
- const s = this.registry.find(t, e);
1148
- return s ? s.scroll === this ? s : e ? this.find(s.scroll.domNode.parentNode, !0) : null : null;
1149
- }
1150
- query(t, e = p.ANY) {
1151
- return this.registry.query(t, e);
1152
- }
1153
- register(...t) {
1154
- return this.registry.register(...t);
1155
- }
1156
- build() {
1157
- this.scroll != null && super.build();
1158
- }
1159
- detach() {
1160
- super.detach(), this.observer.disconnect();
1161
- }
1162
- deleteAt(t, e) {
1163
- this.update(), t === 0 && e === this.length() ? this.children.forEach((s) => {
1164
- s.remove();
1165
- }) : super.deleteAt(t, e);
1166
- }
1167
- formatAt(t, e, s, i) {
1168
- this.update(), super.formatAt(t, e, s, i);
1169
- }
1170
- insertAt(t, e, s) {
1171
- this.update(), super.insertAt(t, e, s);
1172
- }
1173
- optimize(t = [], e = {}) {
1174
- super.optimize(e);
1175
- const s = e.mutationsMap || /* @__PURE__ */ new WeakMap();
1176
- let i = Array.from(this.observer.takeRecords());
1177
- for (; i.length > 0; )
1178
- t.push(i.pop());
1179
- const n = (a, c = !0) => {
1180
- a == null || a === this || a.domNode.parentNode != null && (s.has(a.domNode) || s.set(a.domNode, []), c && n(a.parent));
1181
- }, o = (a) => {
1182
- s.has(a.domNode) && (a instanceof T && a.children.forEach(o), s.delete(a.domNode), a.optimize(e));
1183
- };
1184
- let l = t;
1185
- for (let a = 0; l.length > 0; a += 1) {
1186
- if (a >= be)
1187
- throw new Error("[Parchment] Maximum optimize iterations reached");
1188
- for (l.forEach((c) => {
1189
- const h = this.find(c.target, !0);
1190
- h != null && (h.domNode === c.target && (c.type === "childList" ? (n(this.find(c.previousSibling, !1)), Array.from(c.addedNodes).forEach((d) => {
1191
- const g = this.find(d, !1);
1192
- n(g, !1), g instanceof T && g.children.forEach((b) => {
1193
- n(b, !1);
1194
- });
1195
- })) : c.type === "attributes" && n(h.prev)), n(h));
1196
- }), this.children.forEach(o), l = Array.from(this.observer.takeRecords()), i = l.slice(); i.length > 0; )
1197
- t.push(i.pop());
1198
- }
1199
- }
1200
- update(t, e = {}) {
1201
- t = t || this.observer.takeRecords();
1202
- const s = /* @__PURE__ */ new WeakMap();
1203
- t.map((i) => {
1204
- const n = this.find(i.target, !0);
1205
- return n == null ? null : s.has(n.domNode) ? (s.get(n.domNode).push(i), null) : (s.set(n.domNode, [i]), n);
1206
- }).forEach((i) => {
1207
- i != null && i !== this && s.has(i.domNode) && i.update(s.get(i.domNode) || [], e);
1208
- }), e.mutationsMap = s, s.has(this.domNode) && super.update(s.get(this.domNode), e), this.optimize(t, e);
1209
- }
1210
- }
1211
- class et extends A {
1212
- static {
1213
- this.blotName = "text";
1214
- }
1215
- static {
1216
- this.scope = p.INLINE_BLOT;
1217
- }
1218
- static create(t) {
1219
- return document.createTextNode(t);
1220
- }
1221
- static value(t) {
1222
- return t.data;
1223
- }
1224
- constructor(t, e) {
1225
- super(t, e), this.text = this.statics.value(this.domNode);
1226
- }
1227
- deleteAt(t, e) {
1228
- this.domNode.data = this.text = this.text.slice(0, t) + this.text.slice(t + e);
1229
- }
1230
- index(t, e) {
1231
- return this.domNode === t ? e : -1;
1232
- }
1233
- insertAt(t, e, s) {
1234
- s == null ? (this.text = this.text.slice(0, t) + e + this.text.slice(t), this.domNode.data = this.text) : super.insertAt(t, e, s);
1235
- }
1236
- length() {
1237
- return this.text.length;
1238
- }
1239
- optimize(t) {
1240
- super.optimize(t), this.text = this.statics.value(this.domNode), this.text.length === 0 ? this.remove() : this.next instanceof et && this.next.prev === this && (this.insertAt(this.length(), this.next.value()), this.next.remove());
1241
- }
1242
- position(t, e = !1) {
1243
- return [this.domNode, t];
1244
- }
1245
- split(t, e = !1) {
1246
- if (!e) {
1247
- if (t === 0)
1248
- return this;
1249
- if (t === this.length())
1250
- return this.next;
1251
- }
1252
- const s = this.scroll.create(this.domNode.splitText(t));
1253
- return this.parent.insertBefore(s, this.next || void 0), this.text = this.statics.value(this.domNode), s;
1254
- }
1255
- update(t, e) {
1256
- t.some((s) => s.type === "characterData" && s.target === this.domNode) && (this.text = this.statics.value(this.domNode));
1257
- }
1258
- value() {
1259
- return this.text;
1260
- }
1261
- }
1262
- const Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1263
- __proto__: null,
1264
- Attributor: j,
1265
- AttributorStore: pt,
1266
- BlockBlot: _,
1267
- ClassAttributor: q,
1268
- ContainerBlot: dt,
1269
- EmbedBlot: B,
1270
- InlineBlot: D,
1271
- LeafBlot: A,
1272
- ParentBlot: T,
1273
- Registry: K,
1274
- Scope: p,
1275
- ScrollBlot: It,
1276
- StyleAttributor: V,
1277
- TextBlot: et
1278
- }, Symbol.toStringTag, { value: "Module" }));
1279
- let $ = class extends et {
1280
- };
1281
- const ye = {
1282
- "&": "&amp;",
1283
- "<": "&lt;",
1284
- ">": "&gt;",
1285
- '"': "&quot;",
1286
- "'": "&#39;"
1287
- };
1288
- function se(r) {
1289
- return r.replace(/[&<>"']/g, (t) => ye[t]);
1290
- }
1291
- const at = "\uFEFF";
1292
- class ie extends B {
1293
- constructor(t, e) {
1294
- super(t, e), this.contentNode = document.createElement("span"), this.contentNode.setAttribute("contenteditable", "false"), Array.from(this.domNode.childNodes).forEach((s) => {
1295
- this.contentNode.appendChild(s);
1296
- }), this.leftGuard = document.createTextNode(at), this.rightGuard = document.createTextNode(at), this.domNode.appendChild(this.leftGuard), this.domNode.appendChild(this.contentNode), this.domNode.appendChild(this.rightGuard);
1297
- }
1298
- index(t, e) {
1299
- return t === this.leftGuard ? 0 : t === this.rightGuard ? 1 : super.index(t, e);
1300
- }
1301
- restore(t) {
1302
- let e = null, s;
1303
- const i = t.data.split(at).join("");
1304
- if (t === this.leftGuard)
1305
- if (this.prev instanceof $) {
1306
- const n = this.prev.length();
1307
- this.prev.insertAt(n, i), e = {
1308
- startNode: this.prev.domNode,
1309
- startOffset: n + i.length
1310
- };
1311
- } else
1312
- s = document.createTextNode(i), this.parent.insertBefore(this.scroll.create(s), this), e = {
1313
- startNode: s,
1314
- startOffset: i.length
1315
- };
1316
- else t === this.rightGuard && (this.next instanceof $ ? (this.next.insertAt(0, i), e = {
1317
- startNode: this.next.domNode,
1318
- startOffset: i.length
1319
- }) : (s = document.createTextNode(i), this.parent.insertBefore(this.scroll.create(s), this.next), e = {
1320
- startNode: s,
1321
- startOffset: i.length
1322
- }));
1323
- return t.data = at, e;
1324
- }
1325
- update(t, e) {
1326
- t.forEach((s) => {
1327
- if (s.type === "characterData" && (s.target === this.leftGuard || s.target === this.rightGuard)) {
1328
- const i = this.restore(s.target);
1329
- i && (e.range = i);
1330
- }
1331
- });
1332
- }
1333
- }
1334
- const vt = /* @__PURE__ */ new WeakMap(), xt = ["error", "warn", "log", "info"];
1335
- let Rt = "warn";
1336
- function re(r, ...t) {
1337
- Rt && xt.indexOf(r) <= xt.indexOf(Rt) && console[r](...t);
1338
- }
1339
- function G(r) {
1340
- return xt.reduce(
1341
- (t, e) => (t[e] = re.bind(console, e, r), t),
1342
- {}
1343
- );
1344
- }
1345
- G.level = (r) => {
1346
- Rt = r;
1347
- };
1348
- re.level = G.level;
1349
- const Nt = G("rich:events"), Ee = ["selectionchange", "mousedown", "mouseup", "click"];
1350
- Ee.forEach((r) => {
1351
- document.addEventListener(r, (...t) => {
1352
- Array.from(
1353
- document.querySelectorAll(`.${L}-container`)
1354
- ).forEach((e) => {
1355
- const s = vt.get(e);
1356
- s && s.emitter && s.emitter.handleDOM(...t);
1357
- });
1358
- });
1359
- });
1360
- class m extends ue {
1361
- static {
1362
- this.events = {
1363
- EDITOR_CHANGE: "editor-change",
1364
- SCROLL_BEFORE_UPDATE: "scroll-before-update",
1365
- SCROLL_BLOT_MOUNT: "scroll-blot-mount",
1366
- SCROLL_BLOT_UNMOUNT: "scroll-blot-unmount",
1367
- SCROLL_OPTIMIZE: "scroll-optimize",
1368
- SCROLL_UPDATE: "scroll-update",
1369
- SCROLL_EMBED_UPDATE: "scroll-embed-update",
1370
- SELECTION_CHANGE: "selection-change",
1371
- TEXT_CHANGE: "text-change",
1372
- COMPOSITION_BEFORE_START: "composition-before-start",
1373
- COMPOSITION_START: "composition-start",
1374
- COMPOSITION_BEFORE_END: "composition-before-end",
1375
- COMPOSITION_END: "composition-end"
1376
- };
1377
- }
1378
- static {
1379
- this.sources = {
1380
- API: "api",
1381
- SILENT: "silent",
1382
- USER: "user"
1383
- };
1384
- }
1385
- constructor() {
1386
- super(), this.domListeners = {}, this.on("error", Nt.error);
1387
- }
1388
- on(...t) {
1389
- return super.on(...t);
1390
- }
1391
- once(...t) {
1392
- return super.once(...t);
1393
- }
1394
- emit(...t) {
1395
- return Nt.log.call(Nt, ...t), super.emit(...t);
1396
- }
1397
- off(...t) {
1398
- return super.off(...t);
1399
- }
1400
- handleDOM(t, ...e) {
1401
- (this.domListeners[t.type] || []).forEach(({ node: s, handler: i }) => {
1402
- (t.target === s || s.contains(t.target)) && i(t, ...e);
1403
- });
1404
- }
1405
- listenDOM(t, e, s) {
1406
- this.domListeners[t] || (this.domListeners[t] = []), this.domListeners[t].push({ node: e, handler: s });
1407
- }
1408
- }
1409
- class Te {
1410
- constructor(t, e) {
1411
- this.scroll = t, this.emitter = e, this.isComposing = !1, this.setupListeners();
1412
- }
1413
- setupListeners() {
1414
- this.scroll.domNode.addEventListener("compositionstart", (t) => {
1415
- this.isComposing || this.handleCompositionStart(t);
1416
- }), this.scroll.domNode.addEventListener("compositionend", (t) => {
1417
- this.isComposing && queueMicrotask(() => {
1418
- this.handleCompositionEnd(t);
1419
- });
1420
- });
1421
- }
1422
- handleCompositionStart(t) {
1423
- const e = t.target instanceof Node ? this.scroll.find(t.target, !0) : null;
1424
- e && !(e instanceof ie) && (this.emitter.emit(m.events.COMPOSITION_BEFORE_START, t), this.scroll.batchStart(), this.emitter.emit(m.events.COMPOSITION_START, t), this.isComposing = !0);
1425
- }
1426
- handleCompositionEnd(t) {
1427
- this.emitter.emit(m.events.COMPOSITION_BEFORE_END, t), this.scroll.batchEnd(), this.emitter.emit(m.events.COMPOSITION_END, t), this.isComposing = !1;
1428
- }
1429
- }
1430
- class F extends B {
1431
- static value() {
1432
- }
1433
- optimize() {
1434
- (this.prev || this.next) && this.remove();
1435
- }
1436
- length() {
1437
- return 0;
1438
- }
1439
- value() {
1440
- return "";
1441
- }
1442
- }
1443
- F.blotName = "break";
1444
- F.tagName = "BR";
1445
- class M extends D {
1446
- static {
1447
- this.allowedChildren = [M, F, B, $];
1448
- }
1449
- static {
1450
- this.order = [
1451
- "cursor",
1452
- "inline",
1453
- // Must be lower
1454
- "link",
1455
- // Chrome wants <a> to be lower
1456
- "underline",
1457
- "strike",
1458
- "italic",
1459
- "bold",
1460
- "script",
1461
- "code"
1462
- // Must be higher
1463
- ];
1464
- }
1465
- static compare(t, e) {
1466
- const s = M.order.indexOf(t), i = M.order.indexOf(e);
1467
- return s >= 0 || i >= 0 ? s - i : t === e ? 0 : t < e ? -1 : 1;
1468
- }
1469
- formatAt(t, e, s, i) {
1470
- if (M.compare(this.statics.blotName, s) < 0 && this.scroll.query(s, p.BLOT)) {
1471
- const n = this.isolate(t, e);
1472
- i && n.wrap(s, i);
1473
- } else
1474
- super.formatAt(t, e, s, i);
1475
- }
1476
- optimize(t) {
1477
- if (super.optimize(t), this.parent instanceof M && M.compare(this.statics.blotName, this.parent.statics.blotName) > 0) {
1478
- const e = this.parent.isolate(this.offset(), this.length());
1479
- this.moveChildren(e), e.wrap(this);
1480
- }
1481
- }
1482
- }
1483
- const Pt = 1;
1484
- class O extends _ {
1485
- constructor() {
1486
- super(...arguments), this.cache = {};
1487
- }
1488
- delta() {
1489
- return this.cache.delta == null && (this.cache.delta = Le(this)), this.cache.delta;
1490
- }
1491
- deleteAt(t, e) {
1492
- super.deleteAt(t, e), this.cache = {};
1493
- }
1494
- formatAt(t, e, s, i) {
1495
- e <= 0 || (this.scroll.query(s, p.BLOCK) ? t + e === this.length() && this.format(s, i) : super.formatAt(
1496
- t,
1497
- Math.min(e, this.length() - t - 1),
1498
- s,
1499
- i
1500
- ), this.cache = {});
1501
- }
1502
- insertAt(t, e, s) {
1503
- if (s != null) {
1504
- super.insertAt(t, e, s), this.cache = {};
1505
- return;
1506
- }
1507
- if (e.length === 0) return;
1508
- const i = e.split(`
1509
- `), n = i.shift();
1510
- n.length > 0 && (t < this.length() - 1 || this.children.tail == null ? super.insertAt(Math.min(t, this.length() - 1), n) : this.children.tail.insertAt(this.children.tail.length(), n), this.cache = {});
1511
- let o = this;
1512
- i.reduce((l, a) => (o = o.split(l, !0), o.insertAt(0, a), a.length), t + n.length);
1513
- }
1514
- insertBefore(t, e) {
1515
- const { head: s } = this.children;
1516
- super.insertBefore(t, e), s instanceof F && s.remove(), this.cache = {};
1517
- }
1518
- length() {
1519
- return this.cache.length == null && (this.cache.length = super.length() + Pt), this.cache.length;
1520
- }
1521
- moveChildren(t, e) {
1522
- super.moveChildren(t, e), this.cache = {};
1523
- }
1524
- optimize(t) {
1525
- super.optimize(t), this.cache = {};
1526
- }
1527
- path(t) {
1528
- return super.path(t, !0);
1529
- }
1530
- removeChild(t) {
1531
- super.removeChild(t), this.cache = {};
1532
- }
1533
- split(t, e = !1) {
1534
- if (e && (t === 0 || t >= this.length() - Pt)) {
1535
- const i = this.clone();
1536
- return t === 0 ? (this.parent.insertBefore(i, this), this) : (this.parent.insertBefore(i, this.next), i);
1537
- }
1538
- const s = super.split(t, e);
1539
- return this.cache = {}, s;
1540
- }
1541
- }
1542
- O.blotName = "block";
1543
- O.tagName = "P";
1544
- O.defaultChild = F;
1545
- O.allowedChildren = [F, M, B, $];
1546
- class I extends B {
1547
- attach() {
1548
- super.attach(), this.attributes = new pt(this.domNode);
1549
- }
1550
- delta() {
1551
- return new f().insert(this.value(), {
1552
- ...this.formats(),
1553
- ...this.attributes.values()
1554
- });
1555
- }
1556
- format(t, e) {
1557
- const s = this.scroll.query(t, p.BLOCK_ATTRIBUTE);
1558
- s != null && this.attributes.attribute(s, e);
1559
- }
1560
- formatAt(t, e, s, i) {
1561
- this.format(s, i);
1562
- }
1563
- insertAt(t, e, s) {
1564
- if (s != null) {
1565
- super.insertAt(t, e, s);
1566
- return;
1567
- }
1568
- const i = e.split(`
1569
- `), n = i.pop(), o = i.map((a) => {
1570
- const c = this.scroll.create(O.blotName);
1571
- return c.insertAt(0, a), c;
1572
- }), l = this.split(t);
1573
- o.forEach((a) => {
1574
- this.parent.insertBefore(a, l);
1575
- }), n && this.parent.insertBefore(this.scroll.create("text", n), l);
1576
- }
1577
- }
1578
- I.scope = p.BLOCK_BLOT;
1579
- function Le(r, t = !0) {
1580
- return r.descendants(A).reduce((e, s) => s.length() === 0 ? e : e.insert(s.value(), x(s, {}, t)), new f()).insert(`
1581
- `, x(r));
1582
- }
1583
- function x(r, t = {}, e = !0) {
1584
- return r == null || ("formats" in r && typeof r.formats == "function" && (t = {
1585
- ...t,
1586
- ...r.formats()
1587
- }, e && delete t["code-token"]), r.parent == null || r.parent.statics.blotName === "scroll" || r.parent.statics.scope !== r.statics.scope) ? t : x(r.parent, t, e);
1588
- }
1589
- class U extends B {
1590
- static {
1591
- this.blotName = "cursor";
1592
- }
1593
- static {
1594
- this.className = `${L}-cursor`;
1595
- }
1596
- static {
1597
- this.tagName = "span";
1598
- }
1599
- static {
1600
- this.CONTENTS = "\uFEFF";
1601
- }
1602
- // Zero width no break space
1603
- static value() {
1604
- }
1605
- constructor(t, e, s) {
1606
- super(t, e), this.selection = s, this.textNode = document.createTextNode(U.CONTENTS), this.domNode.appendChild(this.textNode), this.savedLength = 0;
1607
- }
1608
- detach() {
1609
- this.parent != null && this.parent.removeChild(this);
1610
- }
1611
- format(t, e) {
1612
- if (this.savedLength !== 0) {
1613
- super.format(t, e);
1614
- return;
1615
- }
1616
- let s = this, i = 0;
1617
- for (; s != null && s.statics.scope !== p.BLOCK_BLOT; )
1618
- i += s.offset(s.parent), s = s.parent;
1619
- s != null && (this.savedLength = U.CONTENTS.length, s.optimize(), s.formatAt(i, U.CONTENTS.length, t, e), this.savedLength = 0);
1620
- }
1621
- index(t, e) {
1622
- return t === this.textNode ? 0 : super.index(t, e);
1623
- }
1624
- length() {
1625
- return this.savedLength;
1626
- }
1627
- position() {
1628
- return [this.textNode, this.textNode.data.length];
1629
- }
1630
- remove() {
1631
- super.remove(), this.parent = null;
1632
- }
1633
- restore() {
1634
- if (this.selection.composing || this.parent == null) return null;
1635
- const t = this.selection.getNativeRange();
1636
- for (; this.domNode.lastChild != null && this.domNode.lastChild !== this.textNode; )
1637
- this.domNode.parentNode.insertBefore(
1638
- this.domNode.lastChild,
1639
- this.domNode
1640
- );
1641
- const e = this.prev instanceof $ ? this.prev : null, s = e ? e.length() : 0, i = this.next instanceof $ ? this.next : null, n = i ? i.text : "", { textNode: o } = this, l = o.data.split(U.CONTENTS).join("");
1642
- o.data = U.CONTENTS;
1643
- let a;
1644
- if (e)
1645
- a = e, (l || i) && (e.insertAt(e.length(), l + n), i && i.remove());
1646
- else if (i)
1647
- a = i, i.insertAt(0, l);
1648
- else {
1649
- const c = document.createTextNode(l);
1650
- a = this.scroll.create(c), this.parent.insertBefore(a, this);
1651
- }
1652
- if (this.remove(), t) {
1653
- const c = (g, b) => e && g === e.domNode ? b : g === o ? s + b - 1 : i && g === i.domNode ? s + l.length + b : null, h = c(t.start.node, t.start.offset), d = c(t.end.node, t.end.offset);
1654
- if (h !== null && d !== null)
1655
- return {
1656
- startNode: a.domNode,
1657
- startOffset: h,
1658
- endNode: a.domNode,
1659
- endOffset: d
1660
- };
1661
- }
1662
- return null;
1663
- }
1664
- update(t, e) {
1665
- if (t.some((s) => s.type === "characterData" && s.target === this.textNode)) {
1666
- const s = this.restore();
1667
- s && (e.range = s);
1668
- }
1669
- }
1670
- // Avoid .${RICH_TEXT_CLASS_NAME_PREFIX}-cursor being a descendant of `<a/>`.
1671
- // The reason is Safari pushes down `<a/>` on text insertion.
1672
- // That will cause DOM nodes not sync with the model.
1673
- //
1674
- // For example ({I} is the caret), given the markup:
1675
- // <a><span class=`${RICH_TEXT_CLASS_NAME_PREFIX}-cursor`>\uFEFF{I}</span></a>
1676
- // When typing a char "x", `<a/>` will be pushed down inside the `<span>` first:
1677
- // <span class=`${RICH_TEXT_CLASS_NAME_PREFIX}-cursor`><a>\uFEFF{I}</a></span>
1678
- // And then "x" will be inserted after `<a/>`:
1679
- // <span class=`${RICH_TEXT_CLASS_NAME_PREFIX}-cursor`><a>\uFEFF</a>d{I}</span>
1680
- optimize(t) {
1681
- super.optimize(t);
1682
- let { parent: e } = this;
1683
- for (; e; ) {
1684
- if (e.domNode.tagName === "A") {
1685
- this.savedLength = U.CONTENTS.length, e.isolate(this.offset(e), this.length()).unwrap(), this.savedLength = 0;
1686
- break;
1687
- }
1688
- e = e.parent;
1689
- }
1690
- }
1691
- value() {
1692
- return "";
1693
- }
1694
- }
1695
- const yt = G("rich:selection");
1696
- class rt {
1697
- constructor(t, e = 0) {
1698
- this.index = t, this.length = e;
1699
- }
1700
- }
1701
- class Ae {
1702
- constructor(t, e) {
1703
- this.emitter = e, this.scroll = t, this.composing = !1, this.mouseDown = !1, this.root = this.scroll.domNode, this.cursor = this.scroll.create("cursor", this), this.savedRange = new rt(0, 0), this.lastRange = this.savedRange, this.lastNative = null, this.handleComposition(), this.handleDragging(), this.emitter.listenDOM("selectionchange", document, () => {
1704
- !this.mouseDown && !this.composing && setTimeout(this.update.bind(this, m.sources.USER), 1);
1705
- }), this.emitter.on(m.events.SCROLL_BEFORE_UPDATE, () => {
1706
- if (!this.hasFocus()) return;
1707
- const s = this.getNativeRange();
1708
- s != null && s.start.node !== this.cursor.textNode && this.emitter.once(
1709
- m.events.SCROLL_UPDATE,
1710
- (i, n) => {
1711
- try {
1712
- this.root.contains(s.start.node) && this.root.contains(s.end.node) && this.setNativeRange(
1713
- s.start.node,
1714
- s.start.offset,
1715
- s.end.node,
1716
- s.end.offset
1717
- );
1718
- const o = n.some(
1719
- (l) => l.type === "characterData" || l.type === "childList" || l.type === "attributes" && l.target === this.root
1720
- );
1721
- this.update(o ? m.sources.SILENT : i);
1722
- } catch {
1723
- }
1724
- }
1725
- );
1726
- }), this.emitter.on(m.events.SCROLL_OPTIMIZE, (s, i) => {
1727
- if (i.range) {
1728
- const { startNode: n, startOffset: o, endNode: l, endOffset: a } = i.range;
1729
- this.setNativeRange(n, o, l, a), this.update(m.sources.SILENT);
1730
- }
1731
- }), this.update(m.sources.SILENT);
1732
- }
1733
- handleComposition() {
1734
- this.emitter.on(m.events.COMPOSITION_BEFORE_START, () => {
1735
- this.composing = !0;
1736
- }), this.emitter.on(m.events.COMPOSITION_END, () => {
1737
- if (this.composing = !1, this.cursor.parent) {
1738
- const t = this.cursor.restore();
1739
- if (!t) return;
1740
- setTimeout(() => {
1741
- this.setNativeRange(
1742
- t.startNode,
1743
- t.startOffset,
1744
- t.endNode,
1745
- t.endOffset
1746
- );
1747
- }, 1);
1748
- }
1749
- });
1750
- }
1751
- handleDragging() {
1752
- this.emitter.listenDOM("mousedown", document.body, () => {
1753
- this.mouseDown = !0;
1754
- }), this.emitter.listenDOM("mouseup", document.body, () => {
1755
- this.mouseDown = !1, this.update(m.sources.USER);
1756
- });
1757
- }
1758
- focus() {
1759
- this.hasFocus() || (this.root.focus({ preventScroll: !0 }), this.setRange(this.savedRange));
1760
- }
1761
- format(t, e) {
1762
- this.scroll.update();
1763
- const s = this.getNativeRange();
1764
- if (!(s == null || !s.native.collapsed || this.scroll.query(t, p.BLOCK))) {
1765
- if (s.start.node !== this.cursor.textNode) {
1766
- const i = this.scroll.find(s.start.node, !1);
1767
- if (i == null) return;
1768
- if (i instanceof A) {
1769
- const n = i.split(s.start.offset);
1770
- i.parent.insertBefore(this.cursor, n);
1771
- } else
1772
- i.insertBefore(this.cursor, s.start.node);
1773
- this.cursor.attach();
1774
- }
1775
- this.cursor.format(t, e), this.scroll.optimize(), this.setNativeRange(this.cursor.textNode, this.cursor.textNode.data.length), this.update();
1776
- }
1777
- }
1778
- getBounds(t, e = 0) {
1779
- const s = this.scroll.length();
1780
- t = Math.min(t, s - 1), e = Math.min(t + e, s - 1) - t;
1781
- let i, [n, o] = this.scroll.leaf(t);
1782
- if (n == null) return null;
1783
- if (e > 0 && o === n.length()) {
1784
- const [h] = this.scroll.leaf(t + 1);
1785
- if (h) {
1786
- const [d] = this.scroll.line(t), [g] = this.scroll.line(t + 1);
1787
- d === g && (n = h, o = 0);
1788
- }
1789
- }
1790
- [i, o] = n.position(o, !0);
1791
- const l = document.createRange();
1792
- if (e > 0)
1793
- return l.setStart(i, o), [n, o] = this.scroll.leaf(t + e), n == null ? null : ([i, o] = n.position(o, !0), l.setEnd(i, o), l.getBoundingClientRect());
1794
- let a = "left", c;
1795
- if (i instanceof Text) {
1796
- if (!i.data.length)
1797
- return null;
1798
- o < i.data.length ? (l.setStart(i, o), l.setEnd(i, o + 1)) : (l.setStart(i, o - 1), l.setEnd(i, o), a = "right"), c = l.getBoundingClientRect();
1799
- } else {
1800
- if (!(n.domNode instanceof Element)) return null;
1801
- c = n.domNode.getBoundingClientRect(), o > 0 && (a = "right");
1802
- }
1803
- return {
1804
- bottom: c.top + c.height,
1805
- height: c.height,
1806
- left: c[a],
1807
- right: c[a],
1808
- top: c.top,
1809
- width: 0
1810
- };
1811
- }
1812
- getNativeRange() {
1813
- const t = document.getSelection();
1814
- if (t == null || t.rangeCount <= 0) return null;
1815
- const e = t.getRangeAt(0);
1816
- if (e == null) return null;
1817
- const s = this.normalizeNative(e);
1818
- return yt.info("getNativeRange", s), s;
1819
- }
1820
- getRange() {
1821
- const t = this.scroll.domNode;
1822
- if ("isConnected" in t && !t.isConnected)
1823
- return [null, null];
1824
- const e = this.getNativeRange();
1825
- return e == null ? [null, null] : [this.normalizedToRange(e), e];
1826
- }
1827
- hasFocus() {
1828
- return document.activeElement === this.root || document.activeElement != null && Et(this.root, document.activeElement);
1829
- }
1830
- normalizedToRange(t) {
1831
- const e = [
1832
- [t.start.node, t.start.offset]
1833
- ];
1834
- t.native.collapsed || e.push([t.end.node, t.end.offset]);
1835
- const s = e.map((o) => {
1836
- const [l, a] = o, c = this.scroll.find(l, !0), h = c.offset(this.scroll);
1837
- return a === 0 ? h : c instanceof A ? h + c.index(l, a) : h + c.length();
1838
- }), i = Math.min(Math.max(...s), this.scroll.length() - 1), n = Math.min(i, ...s);
1839
- return new rt(n, i - n);
1840
- }
1841
- normalizeNative(t) {
1842
- if (!Et(this.root, t.startContainer) || !t.collapsed && !Et(this.root, t.endContainer))
1843
- return null;
1844
- const e = {
1845
- start: {
1846
- node: t.startContainer,
1847
- offset: t.startOffset
1848
- },
1849
- end: { node: t.endContainer, offset: t.endOffset },
1850
- native: t
1851
- };
1852
- return [e.start, e.end].forEach((s) => {
1853
- let { node: i, offset: n } = s;
1854
- for (; !(i instanceof Text) && i.childNodes.length > 0; )
1855
- if (i.childNodes.length > n)
1856
- i = i.childNodes[n], n = 0;
1857
- else if (i.childNodes.length === n)
1858
- i = i.lastChild, i instanceof Text ? n = i.data.length : i.childNodes.length > 0 ? n = i.childNodes.length : n = i.childNodes.length + 1;
1859
- else
1860
- break;
1861
- s.node = i, s.offset = n;
1862
- }), e;
1863
- }
1864
- rangeToNative(t) {
1865
- const e = this.scroll.length(), s = (i, n) => {
1866
- i = Math.min(e - 1, i);
1867
- const [o, l] = this.scroll.leaf(i);
1868
- return o ? o.position(l, n) : [null, -1];
1869
- };
1870
- return [
1871
- ...s(t.index, !1),
1872
- ...s(t.index + t.length, !0)
1873
- ];
1874
- }
1875
- setNativeRange(t, e, s = t, i = e, n = !1) {
1876
- if (yt.info("setNativeRange", t, e, s, i), t != null && (this.root.parentNode == null || t.parentNode == null || s.parentNode == null))
1877
- return;
1878
- const o = document.getSelection();
1879
- if (o != null)
1880
- if (t != null) {
1881
- this.hasFocus() || this.root.focus({ preventScroll: !0 });
1882
- const { native: l } = this.getNativeRange() || {};
1883
- if (l == null || n || t !== l.startContainer || e !== l.startOffset || s !== l.endContainer || i !== l.endOffset) {
1884
- t instanceof Element && t.tagName === "BR" && (e = Array.from(t.parentNode.childNodes).indexOf(
1885
- t
1886
- ), t = t.parentNode), s instanceof Element && s.tagName === "BR" && (i = Array.from(s.parentNode.childNodes).indexOf(
1887
- s
1888
- ), s = s.parentNode);
1889
- const a = document.createRange();
1890
- a.setStart(t, e), a.setEnd(s, i), o.removeAllRanges(), o.addRange(a);
1891
- }
1892
- } else
1893
- o.removeAllRanges(), this.root.blur();
1894
- }
1895
- setRange(t, e = !1, s = m.sources.API) {
1896
- if (typeof e == "string" && (s = e, e = !1), yt.info("setRange", t), t != null) {
1897
- const i = this.rangeToNative(t);
1898
- this.setNativeRange(...i, e);
1899
- } else
1900
- this.setNativeRange(null);
1901
- this.update(s);
1902
- }
1903
- update(t = m.sources.USER) {
1904
- const e = this.lastRange, [s, i] = this.getRange();
1905
- if (this.lastRange = s, this.lastNative = i, this.lastRange != null && (this.savedRange = this.lastRange), !X(e, this.lastRange)) {
1906
- if (!this.composing && i != null && i.native.collapsed && i.start.node !== this.cursor.textNode) {
1907
- const o = this.cursor.restore();
1908
- o && this.setNativeRange(
1909
- o.startNode,
1910
- o.startOffset,
1911
- o.endNode,
1912
- o.endOffset
1913
- );
1914
- }
1915
- const n = [
1916
- m.events.SELECTION_CHANGE,
1917
- W(this.lastRange),
1918
- W(e),
1919
- t
1920
- ];
1921
- this.emitter.emit(m.events.EDITOR_CHANGE, ...n), t !== m.sources.SILENT && this.emitter.emit(...n);
1922
- }
1923
- }
1924
- }
1925
- function Et(r, t) {
1926
- try {
1927
- t.parentNode;
1928
- } catch {
1929
- return !1;
1930
- }
1931
- return r.contains(t);
1932
- }
1933
- const we = /^[ -~]*$/;
1934
- class Ce {
1935
- constructor(t) {
1936
- this.scroll = t, this.delta = this.getDelta();
1937
- }
1938
- applyDelta(t) {
1939
- this.scroll.update();
1940
- let e = this.scroll.length();
1941
- this.scroll.batchStart();
1942
- const s = _t(t), i = new f();
1943
- return Oe(s.ops.slice()).reduce((o, l) => {
1944
- const a = k.length(l);
1945
- let c = l.attributes || {}, h = !1, d = !1;
1946
- if (l.insert != null) {
1947
- if (i.retain(a), typeof l.insert == "string") {
1948
- const N = l.insert;
1949
- d = !N.endsWith(`
1950
- `) && (e <= o || !!this.scroll.descendant(I, o)[0]), this.scroll.insertAt(o, N);
1951
- const [E, w] = this.scroll.line(o);
1952
- let y = it({}, x(E));
1953
- if (E instanceof O) {
1954
- const [v] = E.descendant(A, w);
1955
- v && (y = it(y, x(v)));
1956
- }
1957
- c = C.diff(y, c) || {};
1958
- } else if (typeof l.insert == "object") {
1959
- const N = Object.keys(l.insert)[0];
1960
- if (N == null) return o;
1961
- const E = this.scroll.query(N, p.INLINE) != null;
1962
- if (E)
1963
- (e <= o || this.scroll.descendant(I, o)[0]) && (d = !0);
1964
- else if (o > 0) {
1965
- const [w, y] = this.scroll.descendant(A, o - 1);
1966
- w instanceof $ ? w.value()[y] !== `
1967
- ` && (h = !0) : w instanceof B && w.statics.scope === p.INLINE_BLOT && (h = !0);
1968
- }
1969
- if (this.scroll.insertAt(o, N, l.insert[N]), E) {
1970
- const [w] = this.scroll.descendant(A, o);
1971
- if (w) {
1972
- const y = it({}, x(w));
1973
- c = C.diff(y, c) || {};
1974
- }
1975
- }
1976
- }
1977
- e += a;
1978
- } else if (i.push(l), l.retain !== null && typeof l.retain == "object") {
1979
- const N = Object.keys(l.retain)[0];
1980
- if (N == null) return o;
1981
- this.scroll.updateEmbedAt(o, N, l.retain[N]);
1982
- }
1983
- Object.keys(c).forEach((N) => {
1984
- this.scroll.formatAt(o, a, N, c[N]);
1985
- });
1986
- const g = h ? 1 : 0, b = d ? 1 : 0;
1987
- return e += g + b, i.retain(g), i.delete(b), o + a + g + b;
1988
- }, 0), i.reduce((o, l) => typeof l.delete == "number" ? (this.scroll.deleteAt(o, l.delete), o) : o + k.length(l), 0), this.scroll.batchEnd(), this.scroll.optimize(), this.update(s);
1989
- }
1990
- deleteText(t, e) {
1991
- return this.scroll.deleteAt(t, e), this.update(new f().retain(t).delete(e));
1992
- }
1993
- formatLine(t, e, s = {}) {
1994
- this.scroll.update(), Object.keys(s).forEach((n) => {
1995
- this.scroll.lines(t, Math.max(e, 1)).forEach((o) => {
1996
- o.format(n, s[n]);
1997
- });
1998
- }), this.scroll.optimize();
1999
- const i = new f().retain(t).retain(e, W(s));
2000
- return this.update(i);
2001
- }
2002
- formatText(t, e, s = {}) {
2003
- Object.keys(s).forEach((n) => {
2004
- this.scroll.formatAt(t, e, n, s[n]);
2005
- });
2006
- const i = new f().retain(t).retain(e, W(s));
2007
- return this.update(i);
2008
- }
2009
- getContents(t, e) {
2010
- return this.delta.slice(t, t + e);
2011
- }
2012
- getDelta() {
2013
- return this.scroll.lines().reduce((t, e) => t.concat(e.delta()), new f());
2014
- }
2015
- getFormat(t, e = 0) {
2016
- let s = [], i = [];
2017
- e === 0 ? this.scroll.path(t).forEach((l) => {
2018
- const [a] = l;
2019
- a instanceof O ? s.push(a) : a instanceof A && i.push(a);
2020
- }) : (s = this.scroll.lines(t, e), i = this.scroll.descendants(A, t, e));
2021
- const [n, o] = [s, i].map((l) => {
2022
- const a = l.shift();
2023
- if (a == null) return {};
2024
- let c = x(a);
2025
- for (; Object.keys(c).length > 0; ) {
2026
- const h = l.shift();
2027
- if (h == null) return c;
2028
- c = ke(x(h), c);
2029
- }
2030
- return c;
2031
- });
2032
- return { ...n, ...o };
2033
- }
2034
- getHTML(t, e) {
2035
- const [s, i] = this.scroll.line(t);
2036
- if (s) {
2037
- const n = s.length();
2038
- return s.length() >= i + e && !(i === 0 && e === n) ? nt(s, i, e, !0) : nt(this.scroll, t, e, !0);
2039
- }
2040
- return "";
2041
- }
2042
- getText(t, e) {
2043
- return this.getContents(t, e).filter((s) => typeof s.insert == "string").map((s) => s.insert).join("");
2044
- }
2045
- insertContents(t, e) {
2046
- const s = _t(e), i = new f().retain(t).concat(s);
2047
- return this.scroll.insertContents(t, s), this.update(i);
2048
- }
2049
- insertEmbed(t, e, s) {
2050
- return this.scroll.insertAt(t, e, s), this.update(new f().retain(t).insert({ [e]: s }));
2051
- }
2052
- insertText(t, e, s = {}) {
2053
- return e = e.replace(/\r\n/g, `
2054
- `).replace(/\r/g, `
2055
- `), this.scroll.insertAt(t, e), Object.keys(s).forEach((i) => {
2056
- this.scroll.formatAt(t, e.length, i, s[i]);
2057
- }), this.update(
2058
- new f().retain(t).insert(e, W(s))
2059
- );
2060
- }
2061
- isBlank() {
2062
- if (this.scroll.children.length === 0) return !0;
2063
- if (this.scroll.children.length > 1) return !1;
2064
- const t = this.scroll.children.head;
2065
- if (t?.statics.blotName !== O.blotName) return !1;
2066
- const e = t;
2067
- return e.children.length > 1 ? !1 : e.children.head instanceof F;
2068
- }
2069
- removeFormat(t, e) {
2070
- const s = this.getText(t, e), [i, n] = this.scroll.line(t + e);
2071
- let o = 0, l = new f();
2072
- i != null && (o = i.length() - n, l = i.delta().slice(n, n + o - 1).insert(`
2073
- `));
2074
- const c = this.getContents(t, e + o).diff(new f().insert(s).concat(l)), h = new f().retain(t).concat(c);
2075
- return this.applyDelta(h);
2076
- }
2077
- update(t, e = [], s = void 0) {
2078
- const i = this.delta;
2079
- if (e.length === 1 && e[0].type === "characterData" && e[0].target.data.match(we) && this.scroll.find(e[0].target)) {
2080
- const n = this.scroll.find(e[0].target), o = x(n), l = n.offset(this.scroll), a = e[0].oldValue.replace(U.CONTENTS, ""), c = new f().insert(a), h = new f().insert(n.value()), d = s && {
2081
- oldRange: zt(s.oldRange, -l),
2082
- newRange: zt(s.newRange, -l)
2083
- };
2084
- t = new f().retain(l).concat(c.diff(h, d)).reduce((b, N) => N.insert ? b.insert(N.insert, o) : b.push(N), new f()), this.delta = i.compose(t);
2085
- } else
2086
- this.delta = this.getDelta(), (!t || !X(i.compose(t), this.delta)) && (t = i.diff(this.delta, s));
2087
- return t;
2088
- }
2089
- }
2090
- function Q(r, t, e) {
2091
- if (r.length === 0) {
2092
- const [b] = Tt(e.pop());
2093
- return t <= 0 ? `</li></${b}>` : `</li></${b}>${Q([], t - 1, e)}`;
2094
- }
2095
- const [{ child: s, offset: i, length: n, indent: o, type: l }, ...a] = r, [c, h] = Tt(l);
2096
- if (o > t)
2097
- return e.push(l), o === t + 1 ? `<${c}><li${h}>${nt(
2098
- s,
2099
- i,
2100
- n
2101
- )}${Q(a, o, e)}` : `<${c}><li>${Q(r, t + 1, e)}`;
2102
- const d = e[e.length - 1];
2103
- if (o === t && l === d)
2104
- return `</li><li${h}>${nt(
2105
- s,
2106
- i,
2107
- n
2108
- )}${Q(a, o, e)}`;
2109
- const [g] = Tt(e.pop());
2110
- return `</li></${g}>${Q(r, t - 1, e)}`;
2111
- }
2112
- function nt(r, t, e, s = !1) {
2113
- if ("html" in r && typeof r.html == "function")
2114
- return r.html(t, e);
2115
- if (r instanceof $)
2116
- return se(r.value().slice(t, t + e)).replaceAll(" ", "&nbsp;");
2117
- if (r instanceof T) {
2118
- if (r.statics.blotName === "list-container") {
2119
- const c = [];
2120
- return r.children.forEachAt(t, e, (h, d, g) => {
2121
- const b = "formats" in h && typeof h.formats == "function" ? h.formats() : {};
2122
- c.push({
2123
- child: h,
2124
- offset: d,
2125
- length: g,
2126
- indent: b.indent || 0,
2127
- type: b.list
2128
- });
2129
- }), Q(c, -1, []);
2130
- }
2131
- const i = [];
2132
- if (r.children.forEachAt(t, e, (c, h, d) => {
2133
- i.push(nt(c, h, d));
2134
- }), s || r.statics.blotName === "list")
2135
- return i.join("");
2136
- const { outerHTML: n, innerHTML: o } = r.domNode, [l, a] = n.split(`>${o}<`);
2137
- return l === "<table" ? `<table style="border: 1px solid #000;">${i.join("")}<${a}` : `${l}>${i.join("")}<${a}`;
2138
- }
2139
- return r.domNode instanceof Element ? r.domNode.outerHTML : "";
2140
- }
2141
- function ke(r, t) {
2142
- return Object.keys(t).reduce(
2143
- (e, s) => {
2144
- if (r[s] == null) return e;
2145
- const i = t[s];
2146
- return i === r[s] ? e[s] = i : Array.isArray(i) ? i.indexOf(r[s]) < 0 ? e[s] = i.concat([r[s]]) : e[s] = i : e[s] = [i, r[s]], e;
2147
- },
2148
- {}
2149
- );
2150
- }
2151
- function Tt(r) {
2152
- const t = r === "ordered" ? "ol" : "ul";
2153
- switch (r) {
2154
- case "checked":
2155
- return [t, ' data-list="checked"'];
2156
- case "unchecked":
2157
- return [t, ' data-list="unchecked"'];
2158
- default:
2159
- return [t, ""];
2160
- }
2161
- }
2162
- function _t(r) {
2163
- return r.reduce((t, e) => {
2164
- if (typeof e.insert == "string") {
2165
- const s = e.insert.replace(/\r\n/g, `
2166
- `).replace(/\r/g, `
2167
- `);
2168
- return t.insert(s, e.attributes);
2169
- }
2170
- return t.push(e);
2171
- }, new f());
2172
- }
2173
- function zt({ index: r, length: t }, e) {
2174
- return new rt(r + e, t);
2175
- }
2176
- function Oe(r) {
2177
- const t = [];
2178
- return r.forEach((e) => {
2179
- typeof e.insert == "string" ? e.insert.split(`
2180
- `).forEach((i, n) => {
2181
- n && t.push({ insert: `
2182
- `, attributes: e.attributes }), i && t.push({ insert: i, attributes: e.attributes });
2183
- }) : t.push(e);
2184
- }), t;
2185
- }
2186
- class Y {
2187
- constructor(t, e = {}) {
2188
- this.rich = t, this.options = e;
2189
- }
2190
- static {
2191
- this.DEFAULTS = {};
2192
- }
2193
- }
2194
- class mt {
2195
- constructor(t, e) {
2196
- this.rich = t, this.options = e, this.modules = {};
2197
- }
2198
- static {
2199
- this.DEFAULTS = {
2200
- modules: {}
2201
- };
2202
- }
2203
- static {
2204
- this.themes = {
2205
- default: mt
2206
- };
2207
- }
2208
- init() {
2209
- Object.keys(this.options.modules).forEach((t) => {
2210
- this.modules[t] == null && this.addModule(t);
2211
- });
2212
- }
2213
- addModule(t) {
2214
- const e = this.rich.constructor.import(`modules/${t}`);
2215
- return this.modules[t] = new e(
2216
- this.rich,
2217
- this.options.modules[t] || {}
2218
- ), this.modules[t];
2219
- }
2220
- }
2221
- const ve = 100, xe = ["block", "break", "cursor", "inline", "scroll", "text"], Re = (r, t, e) => {
2222
- const s = new K();
2223
- return xe.forEach((i) => {
2224
- const n = t.query(i);
2225
- n && s.register(n);
2226
- }), r.forEach((i) => {
2227
- let n = t.query(i);
2228
- n || e.error(
2229
- `Cannot register "${i}" specified in "formats" config. Are you sure it was registered?`
2230
- );
2231
- let o = 0;
2232
- for (; n; )
2233
- if (s.register(n), n = "blotName" in n ? n.requiredContainer ?? null : null, o += 1, o > ve) {
2234
- e.error(
2235
- `Cycle detected in registering blot requiredContainer: "${i}"`
2236
- );
2237
- break;
2238
- }
2239
- }), s;
2240
- }, Se = (r) => r.parentElement || r.getRootNode().host || null, Ie = (r) => {
2241
- const t = r.getBoundingClientRect(), e = "offsetWidth" in r && Math.abs(t.width) / r.offsetWidth || 1, s = "offsetHeight" in r && Math.abs(t.height) / r.offsetHeight || 1;
2242
- return {
2243
- top: t.top,
2244
- right: t.left + r.clientWidth * e,
2245
- bottom: t.top + r.clientHeight * s,
2246
- left: t.left
2247
- };
2248
- }, ct = (r) => {
2249
- const t = parseInt(r, 10);
2250
- return Number.isNaN(t) ? 0 : t;
2251
- }, Kt = (r, t, e, s, i, n) => r < e && t > s ? 0 : r < e ? -(e - r + i) : t > s ? t - r > s - e ? r + i - e : t - s + n : 0, Be = (r, t, e = {}) => {
2252
- const s = r.ownerDocument;
2253
- let i = t;
2254
- const n = [];
2255
- let o = r;
2256
- for (; o; ) {
2257
- const l = o === s.body, a = l ? {
2258
- top: 0,
2259
- right: window.visualViewport?.width ?? s.documentElement.clientWidth,
2260
- bottom: window.visualViewport?.height ?? s.documentElement.clientHeight,
2261
- left: 0
2262
- } : Ie(o), c = getComputedStyle(o), h = Kt(
2263
- i.left,
2264
- i.right,
2265
- a.left,
2266
- a.right,
2267
- ct(c.scrollPaddingLeft),
2268
- ct(c.scrollPaddingRight)
2269
- ), d = Kt(
2270
- i.top,
2271
- i.bottom,
2272
- a.top,
2273
- a.bottom,
2274
- ct(c.scrollPaddingTop),
2275
- ct(c.scrollPaddingBottom)
2276
- );
2277
- if (h || d)
2278
- if (l)
2279
- s.defaultView && (n.push({
2280
- element: s.defaultView,
2281
- left: h,
2282
- top: d
2283
- }), s.defaultView.scrollBy(h, d));
2284
- else {
2285
- const { scrollLeft: g, scrollTop: b } = o;
2286
- d && (o.scrollTop += d), h && (o.scrollLeft += h), n.push({
2287
- element: o,
2288
- left: h,
2289
- top: d
2290
- });
2291
- const N = o.scrollLeft - g, E = o.scrollTop - b;
2292
- i = {
2293
- left: i.left - N,
2294
- top: i.top - E,
2295
- right: i.right - N,
2296
- bottom: i.bottom - E
2297
- };
2298
- }
2299
- o = l || c.position === "fixed" ? null : Se(o);
2300
- }
2301
- e.smooth && n.forEach(({ element: l, top: a, left: c }) => {
2302
- l.scrollBy({ top: -a, left: -c, behavior: "instant" }), l.scrollBy({ top: a, left: c, behavior: "smooth" });
2303
- });
2304
- }, tt = G("rich"), ht = new K();
2305
- T.uiClass = `${L}-ui`;
2306
- class u {
2307
- static {
2308
- this.DEFAULTS = {
2309
- bounds: null,
2310
- modules: {
2311
- clipboard: !0,
2312
- keyboard: !0,
2313
- history: !0,
2314
- uploader: !0
2315
- },
2316
- placeholder: "",
2317
- readOnly: !1,
2318
- registry: ht,
2319
- theme: "default"
2320
- };
2321
- }
2322
- static {
2323
- this.events = m.events;
2324
- }
2325
- static {
2326
- this.sources = m.sources;
2327
- }
2328
- static {
2329
- this.imports = {
2330
- delta: f,
2331
- parchment: Ne,
2332
- "core/module": Y,
2333
- "core/theme": mt
2334
- };
2335
- }
2336
- static debug(t) {
2337
- t === !0 && (t = "log"), G.level(t);
2338
- }
2339
- static find(t, e = !1) {
2340
- return vt.get(t) || ht.find(t, e);
2341
- }
2342
- static import(t) {
2343
- return this.imports[t] == null && tt.error(`Cannot import ${t}. Are you sure it was registered?`), this.imports[t];
2344
- }
2345
- static register(...t) {
2346
- if (typeof t[0] == "string") {
2347
- const e = t[0], s = t[1], i = !!t[2];
2348
- this.imports[e] != null && !i && tt.warn(`Overwriting ${e} with`, s), this.imports[e] = s, (e.startsWith("blots/") || e.startsWith("formats/")) && s && typeof s != "boolean" && s.blotName !== "abstract" && ht.register(s), typeof s.register == "function" && s.register(ht);
2349
- } else {
2350
- const e = t[0], s = !!t[1], i = "attrName" in e ? e.attrName : e.blotName;
2351
- typeof i == "string" ? this.register(`formats/${i}`, e, s) : Object.entries(e).forEach(([n, o], l, a) => {
2352
- this.register(n, o, s);
2353
- });
2354
- }
2355
- }
2356
- constructor(t, e = {}) {
2357
- if (this.options = De(t, e), this.container = this.options.container, this.container == null) {
2358
- tt.error("Invalid Rich container", t);
2359
- return;
2360
- }
2361
- this.options.debug && u.debug(this.options.debug);
2362
- const s = this.container.innerHTML.trim();
2363
- this.container.classList.add(`${L}-container`), this.container.innerHTML = "", vt.set(this.container, this), this.root = this.addContainer(`${L}-editor`), this.root.classList.add(`${L}-blank`), this.emitter = new m();
2364
- const i = It.blotName, n = this.options.registry.query(i);
2365
- if (!n || !("blotName" in n))
2366
- throw new Error(
2367
- `Cannot initialize Rich without "${i}" blot`
2368
- );
2369
- if (this.scroll = new n(this.options.registry, this.root, {
2370
- emitter: this.emitter
2371
- }), this.editor = new Ce(this.scroll), this.selection = new Ae(this.scroll, this.emitter), this.composition = new Te(this.scroll, this.emitter), this.theme = new this.options.theme(this, this.options), this.keyboard = this.theme.addModule("keyboard"), this.clipboard = this.theme.addModule("clipboard"), this.history = this.theme.addModule("history"), this.uploader = this.theme.addModule("uploader"), this.theme.addModule("input"), this.theme.addModule("uiNode"), this.theme.init(), this.emitter.on(m.events.EDITOR_CHANGE, (o) => {
2372
- o === m.events.TEXT_CHANGE && this.root.classList.toggle(
2373
- `${L}-blank`,
2374
- this.editor.isBlank()
2375
- );
2376
- }), this.emitter.on(m.events.SCROLL_UPDATE, (o, l) => {
2377
- const a = this.selection.lastRange, [c] = this.selection.getRange(), h = a && c ? { oldRange: a, newRange: c } : void 0;
2378
- S.call(
2379
- this,
2380
- () => this.editor.update(null, l, h),
2381
- o
2382
- );
2383
- }), this.emitter.on(m.events.SCROLL_EMBED_UPDATE, (o, l) => {
2384
- const a = this.selection.lastRange, [c] = this.selection.getRange(), h = a && c ? { oldRange: a, newRange: c } : void 0;
2385
- S.call(
2386
- this,
2387
- () => {
2388
- const d = new f().retain(o.offset(this)).retain({ [o.statics.blotName]: l });
2389
- return this.editor.update(d, [], h);
2390
- },
2391
- u.sources.USER
2392
- );
2393
- }), s) {
2394
- const o = this.clipboard.convert({
2395
- html: `${s}<p><br></p>`,
2396
- text: `
2397
- `
2398
- });
2399
- this.setContents(o);
2400
- }
2401
- this.history.clear(), this.options.placeholder && this.root.setAttribute("data-placeholder", this.options.placeholder), this.options.readOnly && this.disable(), this.allowReadOnlyEdits = !1;
2402
- }
2403
- addContainer(t, e = null, s) {
2404
- if (typeof t == "string") {
2405
- const i = t;
2406
- t = document.createElement("div"), t.classList.add(i);
2407
- }
2408
- return s instanceof HTMLElement ? s.appendChild(t) : this.container.insertBefore(t, e), t;
2409
- }
2410
- blur() {
2411
- this.selection.setRange(null);
2412
- }
2413
- deleteText(t, e, s) {
2414
- return [t, e, , s] = P(t, e, s), S.call(
2415
- this,
2416
- () => this.editor.deleteText(t, e),
2417
- s,
2418
- t,
2419
- -1 * e
2420
- );
2421
- }
2422
- disable() {
2423
- this.enable(!1);
2424
- }
2425
- editReadOnly(t) {
2426
- this.allowReadOnlyEdits = !0;
2427
- const e = t();
2428
- return this.allowReadOnlyEdits = !1, e;
2429
- }
2430
- enable(t = !0) {
2431
- this.scroll.enable(t), this.container.classList.toggle(
2432
- `${L}-disabled`,
2433
- !t
2434
- );
2435
- }
2436
- focus(t = {}) {
2437
- this.selection.focus(), t.preventScroll || this.scrollSelectionIntoView();
2438
- }
2439
- format(t, e, s = m.sources.API) {
2440
- return S.call(
2441
- this,
2442
- () => {
2443
- const n = this.getSelection(!0);
2444
- let o = new f();
2445
- if (n == null)
2446
- return o;
2447
- if (this.scroll.query(t, p.BLOCK))
2448
- o = this.editor.formatLine(n.index, n.length, {
2449
- [t]: e
2450
- });
2451
- else {
2452
- if (n.length === 0)
2453
- return this.selection.format(t, e), o;
2454
- o = this.editor.formatText(n.index, n.length, {
2455
- [t]: e
2456
- });
2457
- }
2458
- return this.setSelection(n, m.sources.SILENT), o;
2459
- },
2460
- s
2461
- );
2462
- }
2463
- formatLine(t, e, s, i, n) {
2464
- let o;
2465
- return [t, e, o, n] = P(
2466
- t,
2467
- e,
2468
- s,
2469
- i,
2470
- n
2471
- ), S.call(
2472
- this,
2473
- () => this.editor.formatLine(t, e, o),
2474
- n,
2475
- t,
2476
- 0
2477
- );
2478
- }
2479
- formatText(t, e, s, i, n) {
2480
- let o;
2481
- return [t, e, o, n] = P(
2482
- t,
2483
- e,
2484
- s,
2485
- i,
2486
- n
2487
- ), S.call(
2488
- this,
2489
- () => this.editor.formatText(t, e, o),
2490
- n,
2491
- t,
2492
- 0
2493
- );
2494
- }
2495
- getBounds(t, e = 0) {
2496
- let s = null;
2497
- if (typeof t == "number" ? s = this.selection.getBounds(t, e) : s = this.selection.getBounds(t.index, t.length), !s) return null;
2498
- const i = this.container.getBoundingClientRect();
2499
- return {
2500
- bottom: s.bottom - i.top,
2501
- height: s.height,
2502
- left: s.left - i.left,
2503
- right: s.right - i.left,
2504
- top: s.top - i.top,
2505
- width: s.width
2506
- };
2507
- }
2508
- getContents(t = 0, e = this.getLength() - t) {
2509
- return [t, e] = P(t, e), this.editor.getContents(t, e);
2510
- }
2511
- getFormat(t = this.getSelection(!0), e = 0) {
2512
- return typeof t == "number" ? this.editor.getFormat(t, e) : this.editor.getFormat(t.index, t.length);
2513
- }
2514
- getIndex(t) {
2515
- return t.offset(this.scroll);
2516
- }
2517
- getLength() {
2518
- return this.scroll.length();
2519
- }
2520
- getLeaf(t) {
2521
- return this.scroll.leaf(t);
2522
- }
2523
- getLine(t) {
2524
- return this.scroll.line(t);
2525
- }
2526
- getLines(t = 0, e = Number.MAX_VALUE) {
2527
- return typeof t != "number" ? this.scroll.lines(t.index, t.length) : this.scroll.lines(t, e);
2528
- }
2529
- getModule(t) {
2530
- return this.theme.modules[t];
2531
- }
2532
- getSelection(t = !1) {
2533
- return t && this.focus(), this.update(), this.selection.getRange()[0];
2534
- }
2535
- getSemanticHTML(t = 0, e) {
2536
- return typeof t == "number" && (e = e ?? this.getLength() - t), [t, e] = P(t, e), this.editor.getHTML(t, e);
2537
- }
2538
- getText(t = 0, e) {
2539
- return typeof t == "number" && (e = e ?? this.getLength() - t), [t, e] = P(t, e), this.editor.getText(t, e);
2540
- }
2541
- hasFocus() {
2542
- return this.selection.hasFocus();
2543
- }
2544
- insertEmbed(t, e, s, i = u.sources.API) {
2545
- return S.call(
2546
- this,
2547
- () => this.editor.insertEmbed(t, e, s),
2548
- i,
2549
- t
2550
- );
2551
- }
2552
- insertText(t, e, s, i, n) {
2553
- let o;
2554
- return [t, , o, n] = P(t, 0, s, i, n), S.call(
2555
- this,
2556
- () => this.editor.insertText(t, e, o),
2557
- n,
2558
- t,
2559
- e.length
2560
- );
2561
- }
2562
- isEnabled() {
2563
- return this.scroll.isEnabled();
2564
- }
2565
- off(...t) {
2566
- return this.emitter.off(...t);
2567
- }
2568
- on(...t) {
2569
- return this.emitter.on(...t);
2570
- }
2571
- once(...t) {
2572
- return this.emitter.once(...t);
2573
- }
2574
- removeFormat(t, e, s) {
2575
- return [t, e, , s] = P(t, e, s), S.call(
2576
- this,
2577
- () => this.editor.removeFormat(t, e),
2578
- s,
2579
- t
2580
- );
2581
- }
2582
- scrollRectIntoView(t, e = {}) {
2583
- Be(this.root, t, e);
2584
- }
2585
- /**
2586
- * @deprecated Use Rich#scrollSelectionIntoView() instead.
2587
- */
2588
- scrollIntoView() {
2589
- console.warn(
2590
- "Rich#scrollIntoView() has been deprecated and will be removed in the near future. Please use Rich#scrollSelectionIntoView() instead."
2591
- ), this.scrollSelectionIntoView();
2592
- }
2593
- /**
2594
- * Scroll the current selection into the visible area.
2595
- * If the selection is already visible, no scrolling will occur.
2596
- */
2597
- scrollSelectionIntoView(t = {}) {
2598
- const e = this.selection.lastRange, s = e && this.selection.getBounds(e.index, e.length);
2599
- s && this.scrollRectIntoView(s, t);
2600
- }
2601
- setContents(t, e = m.sources.API) {
2602
- return S.call(
2603
- this,
2604
- () => {
2605
- t = new f(t);
2606
- const s = this.getLength(), i = this.editor.deleteText(0, s), n = this.editor.insertContents(0, t), o = this.editor.deleteText(this.getLength() - 1, 1);
2607
- return i.compose(n).compose(o);
2608
- },
2609
- e
2610
- );
2611
- }
2612
- setSelection(t, e, s) {
2613
- t == null ? this.selection.setRange(null, e || u.sources.API) : ([t, e, , s] = P(t, e, s), this.selection.setRange(new rt(Math.max(0, t), e), s), s !== m.sources.SILENT && this.scrollSelectionIntoView());
2614
- }
2615
- setText(t, e = m.sources.API) {
2616
- const s = new f().insert(t);
2617
- return this.setContents(s, e);
2618
- }
2619
- update(t = m.sources.USER) {
2620
- const e = this.scroll.update(t);
2621
- return this.selection.update(t), e;
2622
- }
2623
- updateContents(t, e = m.sources.API) {
2624
- return S.call(
2625
- this,
2626
- () => (t = new f(t), this.editor.applyDelta(t)),
2627
- e,
2628
- !0
2629
- );
2630
- }
2631
- }
2632
- function qt(r) {
2633
- return typeof r == "string" ? document.querySelector(r) : r;
2634
- }
2635
- function Lt(r) {
2636
- return Object.entries(r ?? {}).reduce(
2637
- (t, [e, s]) => ({
2638
- ...t,
2639
- [e]: s === !0 ? {} : s
2640
- }),
2641
- {}
2642
- );
2643
- }
2644
- function Ht(r) {
2645
- return Object.fromEntries(
2646
- Object.entries(r).filter((t) => t[1] !== void 0)
2647
- );
2648
- }
2649
- function De(r, t) {
2650
- const e = qt(r);
2651
- if (!e)
2652
- throw new Error("Invalid Rich container");
2653
- const i = !t.theme || t.theme === u.DEFAULTS.theme ? mt : u.import(`themes/${t.theme}`);
2654
- if (!i)
2655
- throw new Error(`Invalid theme ${t.theme}. Did you register it?`);
2656
- const { modules: n, ...o } = u.DEFAULTS, { modules: l, ...a } = i.DEFAULTS;
2657
- let c = Lt(t.modules);
2658
- c != null && c.toolbar && c.toolbar.constructor !== Object && (c = {
2659
- ...c,
2660
- toolbar: { container: c.toolbar }
2661
- });
2662
- const h = it(
2663
- {},
2664
- Lt(n),
2665
- Lt(l),
2666
- c
2667
- ), d = {
2668
- ...o,
2669
- ...Ht(a),
2670
- ...Ht(t)
2671
- };
2672
- let g = t.registry;
2673
- return g ? t.formats && tt.warn('Ignoring "formats" option because "registry" is specified') : g = t.formats ? Re(t.formats, d.registry, tt) : d.registry, {
2674
- ...d,
2675
- registry: g,
2676
- container: e,
2677
- theme: i,
2678
- modules: Object.entries(h).reduce(
2679
- (b, [N, E]) => {
2680
- if (!E) return b;
2681
- const w = u.import(`modules/${N}`);
2682
- return w == null ? (tt.error(
2683
- `Cannot load ${N} module. Are you sure you registered it?`
2684
- ), b) : {
2685
- ...b,
2686
- [N]: it({}, w.DEFAULTS || {}, E)
2687
- };
2688
- },
2689
- {}
2690
- ),
2691
- bounds: qt(d.bounds)
2692
- };
2693
- }
2694
- function S(r, t, e, s) {
2695
- if (!this.isEnabled() && t === m.sources.USER && !this.allowReadOnlyEdits)
2696
- return new f();
2697
- let i = e == null ? null : this.getSelection();
2698
- const n = this.editor.delta, o = r();
2699
- if (i != null && (e === !0 && (e = i.index), s == null ? i = Wt(i, o, t) : s !== 0 && (i = Wt(i, e, s, t)), this.setSelection(i, m.sources.SILENT)), o.length() > 0) {
2700
- const l = [m.events.TEXT_CHANGE, o, n, t];
2701
- this.emitter.emit(m.events.EDITOR_CHANGE, ...l), t !== m.sources.SILENT && this.emitter.emit(...l);
2702
- }
2703
- return o;
2704
- }
2705
- function P(r, t, e, s, i) {
2706
- let n = {};
2707
- return typeof r.index == "number" && typeof r.length == "number" ? typeof t != "number" ? (i = s, s = e, e = t, t = r.length, r = r.index) : (t = r.length, r = r.index) : typeof t != "number" && (i = s, s = e, e = t, t = 0), typeof e == "object" ? (n = e, i = s) : typeof e == "string" && (s != null ? n[e] = s : i = e), i = i || m.sources.API, [r, t, n, i];
2708
- }
2709
- function Wt(r, t, e, s) {
2710
- const i = typeof e == "number" ? e : 0;
2711
- if (r == null) return null;
2712
- let n, o;
2713
- return t && typeof t.transformPosition == "function" ? [n, o] = [r.index, r.index + r.length].map(
2714
- (l) => t.transformPosition(l, s !== m.sources.USER)
2715
- ) : [n, o] = [r.index, r.index + r.length].map((l) => l < t || l === t && s === m.sources.USER ? l : i >= 0 ? l + i : Math.max(t, l + i)), new rt(n, o - n);
2716
- }
2717
- class Bt extends dt {
2718
- }
2719
- function Vt(r) {
2720
- return r instanceof O || r instanceof I;
2721
- }
2722
- function Gt(r) {
2723
- return typeof r.updateContent == "function";
2724
- }
2725
- class Me extends It {
2726
- static {
2727
- this.blotName = "scroll";
2728
- }
2729
- static {
2730
- this.className = `${L}-editor`;
2731
- }
2732
- static {
2733
- this.tagName = "DIV";
2734
- }
2735
- static {
2736
- this.defaultChild = O;
2737
- }
2738
- static {
2739
- this.allowedChildren = [O, I, Bt];
2740
- }
2741
- constructor(t, e, { emitter: s }) {
2742
- super(t, e), this.emitter = s, this.batch = !1, this.optimize(), this.enable(), this.domNode.addEventListener("dragstart", (i) => this.handleDragStart(i));
2743
- }
2744
- batchStart() {
2745
- Array.isArray(this.batch) || (this.batch = []);
2746
- }
2747
- batchEnd() {
2748
- if (!this.batch) return;
2749
- const t = this.batch;
2750
- this.batch = !1, this.update(t);
2751
- }
2752
- emitMount(t) {
2753
- this.emitter.emit(m.events.SCROLL_BLOT_MOUNT, t);
2754
- }
2755
- emitUnmount(t) {
2756
- this.emitter.emit(m.events.SCROLL_BLOT_UNMOUNT, t);
2757
- }
2758
- emitEmbedUpdate(t, e) {
2759
- this.emitter.emit(m.events.SCROLL_EMBED_UPDATE, t, e);
2760
- }
2761
- deleteAt(t, e) {
2762
- const [s, i] = this.line(t), [n] = this.line(t + e);
2763
- if (super.deleteAt(t, e), n != null && s !== n && i > 0) {
2764
- if (s instanceof I || n instanceof I) {
2765
- this.optimize();
2766
- return;
2767
- }
2768
- const o = n.children.head instanceof F ? null : n.children.head;
2769
- s.moveChildren(n, o), s.remove();
2770
- }
2771
- this.optimize();
2772
- }
2773
- enable(t = !0) {
2774
- this.domNode.setAttribute("contenteditable", t ? "true" : "false");
2775
- }
2776
- formatAt(t, e, s, i) {
2777
- super.formatAt(t, e, s, i), this.optimize();
2778
- }
2779
- insertAt(t, e, s) {
2780
- if (t >= this.length())
2781
- if (s == null || this.scroll.query(e, p.BLOCK) == null) {
2782
- const i = this.scroll.create(this.statics.defaultChild.blotName);
2783
- this.appendChild(i), s == null && e.endsWith(`
2784
- `) ? i.insertAt(0, e.slice(0, -1), s) : i.insertAt(0, e, s);
2785
- } else {
2786
- const i = this.scroll.create(e, s);
2787
- this.appendChild(i);
2788
- }
2789
- else
2790
- super.insertAt(t, e, s);
2791
- this.optimize();
2792
- }
2793
- insertBefore(t, e) {
2794
- if (t.statics.scope === p.INLINE_BLOT) {
2795
- const s = this.scroll.create(
2796
- this.statics.defaultChild.blotName
2797
- );
2798
- s.appendChild(t), super.insertBefore(s, e);
2799
- } else
2800
- super.insertBefore(t, e);
2801
- }
2802
- insertContents(t, e) {
2803
- const s = this.deltaToRenderBlocks(
2804
- e.concat(new f().insert(`
2805
- `))
2806
- ), i = s.pop();
2807
- if (i == null) return;
2808
- this.batchStart();
2809
- const n = s.shift();
2810
- if (n) {
2811
- const a = n.type === "block" && (n.delta.length() === 0 || !this.descendant(I, t)[0] && t < this.length()), c = n.type === "block" ? n.delta : new f().insert({ [n.key]: n.value });
2812
- At(this, t, c);
2813
- const h = n.type === "block" ? 1 : 0, d = t + c.length() + h;
2814
- a && this.insertAt(d - 1, `
2815
- `);
2816
- const g = x(this.line(t)[0]), b = C.diff(g, n.attributes) || {};
2817
- Object.keys(b).forEach((N) => {
2818
- this.formatAt(d - 1, 1, N, b[N]);
2819
- }), t = d;
2820
- }
2821
- let [o, l] = this.children.find(t);
2822
- if (s.length && (o && (o = o.split(l), l = 0), s.forEach((a) => {
2823
- if (a.type === "block") {
2824
- const c = this.createBlock(
2825
- a.attributes,
2826
- o || void 0
2827
- );
2828
- At(c, 0, a.delta);
2829
- } else {
2830
- const c = this.create(
2831
- a.key,
2832
- a.value
2833
- );
2834
- this.insertBefore(c, o || void 0), Object.keys(a.attributes).forEach((h) => {
2835
- c.format(h, a.attributes[h]);
2836
- });
2837
- }
2838
- })), i.type === "block" && i.delta.length()) {
2839
- const a = o ? o.offset(o.scroll) + l : this.length();
2840
- At(this, a, i.delta);
2841
- }
2842
- this.batchEnd(), this.optimize();
2843
- }
2844
- isEnabled() {
2845
- return this.domNode.getAttribute("contenteditable") === "true";
2846
- }
2847
- leaf(t) {
2848
- const e = this.path(t).pop();
2849
- if (!e)
2850
- return [null, -1];
2851
- const [s, i] = e;
2852
- return s instanceof A ? [s, i] : [null, -1];
2853
- }
2854
- line(t) {
2855
- return t === this.length() ? this.line(t - 1) : this.descendant(Vt, t);
2856
- }
2857
- lines(t = 0, e = Number.MAX_VALUE) {
2858
- const s = (i, n, o) => {
2859
- let l = [], a = o;
2860
- return i.children.forEachAt(
2861
- n,
2862
- o,
2863
- (c, h, d) => {
2864
- Vt(c) ? l.push(c) : c instanceof dt && (l = l.concat(s(c, h, a))), a -= d;
2865
- }
2866
- ), l;
2867
- };
2868
- return s(this, t, e);
2869
- }
2870
- optimize(t = [], e = {}) {
2871
- this.batch || (super.optimize(t, e), t.length > 0 && this.emitter.emit(m.events.SCROLL_OPTIMIZE, t, e));
2872
- }
2873
- path(t) {
2874
- return super.path(t).slice(1);
2875
- }
2876
- remove() {
2877
- }
2878
- update(t) {
2879
- if (this.batch) {
2880
- Array.isArray(t) && (this.batch = this.batch.concat(t));
2881
- return;
2882
- }
2883
- let e = m.sources.USER;
2884
- typeof t == "string" && (e = t), Array.isArray(t) || (t = this.observer.takeRecords()), t = t.filter(({ target: s }) => {
2885
- const i = this.find(s, !0);
2886
- return i && !Gt(i);
2887
- }), t.length > 0 && this.emitter.emit(m.events.SCROLL_BEFORE_UPDATE, e, t), super.update(t.concat([])), t.length > 0 && this.emitter.emit(m.events.SCROLL_UPDATE, e, t);
2888
- }
2889
- updateEmbedAt(t, e, s) {
2890
- const [i] = this.descendant((n) => n instanceof I, t);
2891
- i && i.statics.blotName === e && Gt(i) && i.updateContent(s);
2892
- }
2893
- handleDragStart(t) {
2894
- t.preventDefault();
2895
- }
2896
- deltaToRenderBlocks(t) {
2897
- const e = [];
2898
- let s = new f();
2899
- return t.forEach((i) => {
2900
- const n = i?.insert;
2901
- if (n)
2902
- if (typeof n == "string") {
2903
- const o = n.split(`
2904
- `);
2905
- o.slice(0, -1).forEach((a) => {
2906
- s.insert(a, i.attributes), e.push({
2907
- type: "block",
2908
- delta: s,
2909
- attributes: i.attributes ?? {}
2910
- }), s = new f();
2911
- });
2912
- const l = o[o.length - 1];
2913
- l && s.insert(l, i.attributes);
2914
- } else {
2915
- const o = Object.keys(n)[0];
2916
- if (!o) return;
2917
- this.query(o, p.INLINE) ? s.push(i) : (s.length() && e.push({
2918
- type: "block",
2919
- delta: s,
2920
- attributes: {}
2921
- }), s = new f(), e.push({
2922
- type: "blockEmbed",
2923
- key: o,
2924
- value: n[o],
2925
- attributes: i.attributes ?? {}
2926
- }));
2927
- }
2928
- }), s.length() && e.push({
2929
- type: "block",
2930
- delta: s,
2931
- attributes: {}
2932
- }), e;
2933
- }
2934
- createBlock(t, e) {
2935
- let s;
2936
- const i = {};
2937
- Object.entries(t).forEach(([l, a]) => {
2938
- this.query(l, p.BLOCK & p.BLOT) != null ? s = l : i[l] = a;
2939
- });
2940
- const n = this.create(
2941
- s || this.statics.defaultChild.blotName,
2942
- s ? t[s] : void 0
2943
- );
2944
- this.insertBefore(n, e || void 0);
2945
- const o = n.length();
2946
- return Object.entries(i).forEach(([l, a]) => {
2947
- n.formatAt(0, o, l, a);
2948
- }), n;
2949
- }
2950
- }
2951
- function At(r, t, e) {
2952
- e.reduce((s, i) => {
2953
- const n = k.length(i);
2954
- let o = i.attributes || {};
2955
- if (i.insert != null) {
2956
- if (typeof i.insert == "string") {
2957
- const l = i.insert;
2958
- r.insertAt(s, l);
2959
- const [a] = r.descendant(A, s), c = x(a);
2960
- o = C.diff(c, o) || {};
2961
- } else if (typeof i.insert == "object") {
2962
- const l = Object.keys(i.insert)[0];
2963
- if (l == null) return s;
2964
- if (r.insertAt(s, l, i.insert[l]), r.scroll.query(l, p.INLINE) != null) {
2965
- const [c] = r.descendant(A, s), h = x(c);
2966
- o = C.diff(h, o) || {};
2967
- }
2968
- }
2969
- }
2970
- return Object.keys(o).forEach((l) => {
2971
- r.formatAt(s, n, l, o[l]);
2972
- }), s + n;
2973
- }, t);
2974
- }
2975
- const Dt = {
2976
- scope: p.BLOCK,
2977
- whitelist: ["right", "center", "justify"]
2978
- }, Ue = new j("align", "align", Dt), zs = new q(
2979
- "align",
2980
- `${L}-align`,
2981
- Dt
2982
- ), je = new V("align", "text-align", Dt);
2983
- class ne extends V {
2984
- value(t) {
2985
- let e = super.value(t);
2986
- return e.startsWith("rgb(") ? (e = e.replace(/^[^\d]+/, "").replace(/[^\d]+$/, ""), `#${e.split(",").map((i) => `00${parseInt(i, 10).toString(16)}`.slice(-2)).join("")}`) : e;
2987
- }
2988
- }
2989
- const Ks = new q(
2990
- "color",
2991
- `${L}-color`,
2992
- {
2993
- scope: p.INLINE
2994
- }
2995
- ), $e = new ne("color", "color", {
2996
- scope: p.INLINE
2997
- }), qs = new q(
2998
- "background",
2999
- `${L}-bg`,
3000
- {
3001
- scope: p.INLINE
3002
- }
3003
- ), Fe = new ne("background", "background-color", {
3004
- scope: p.INLINE
3005
- });
3006
- class st extends Bt {
3007
- static create(t) {
3008
- const e = super.create(t);
3009
- return e.setAttribute("spellcheck", "false"), e;
3010
- }
3011
- code(t, e) {
3012
- return this.children.map((s) => s.length() <= 1 ? "" : s.domNode.innerText).join(`
3013
- `).slice(t, t + e);
3014
- }
3015
- html(t, e) {
3016
- return `<pre>
3017
- ${se(this.code(t, e))}
3018
- </pre>`;
3019
- }
3020
- }
3021
- class z extends O {
3022
- static {
3023
- this.TAB = " ";
3024
- }
3025
- static register() {
3026
- u.register(st);
3027
- }
3028
- }
3029
- class oe extends M {
3030
- }
3031
- oe.blotName = "code";
3032
- oe.tagName = "CODE";
3033
- z.blotName = "code-block";
3034
- z.className = `${L}-code-block`;
3035
- z.tagName = "DIV";
3036
- st.blotName = "code-block-container";
3037
- st.className = `${L}-code-block-container`;
3038
- st.tagName = "DIV";
3039
- st.allowedChildren = [z];
3040
- z.allowedChildren = [$, F, U];
3041
- z.requiredContainer = st;
3042
- const Mt = {
3043
- scope: p.BLOCK,
3044
- whitelist: ["rtl"]
3045
- }, Pe = new j("direction", "dir", Mt), Hs = new q(
3046
- "direction",
3047
- `${L}-direction`,
3048
- Mt
3049
- ), _e = new V("direction", "direction", Mt), le = {
3050
- scope: p.INLINE,
3051
- whitelist: ["serif", "monospace"]
3052
- }, Ws = new q(
3053
- "font",
3054
- `${L}-font`,
3055
- le
3056
- );
3057
- class ze extends V {
3058
- value(t) {
3059
- return super.value(t).replace(/["']/g, "");
3060
- }
3061
- }
3062
- const Ke = new ze("font", "font-family", le), Vs = new q(
3063
- "size",
3064
- `${L}-size`,
3065
- {
3066
- scope: p.INLINE,
3067
- whitelist: ["small", "large", "huge"]
3068
- }
3069
- ), qe = new V("size", "font-size", {
3070
- scope: p.INLINE,
3071
- whitelist: ["10px", "18px", "32px"]
3072
- }), He = G("rich:keyboard"), We = /Mac/i.test(navigator.platform) ? "metaKey" : "ctrlKey";
3073
- class gt extends Y {
3074
- static match(t, e) {
3075
- return ["altKey", "ctrlKey", "metaKey", "shiftKey"].some((s) => !!e[s] !== t[s] && e[s] !== null) ? !1 : e.key === t.key || e.key === t.which;
3076
- }
3077
- constructor(t, e) {
3078
- super(t, e), this.bindings = {}, Object.keys(this.options.bindings).forEach((s) => {
3079
- this.options.bindings[s] && this.addBinding(this.options.bindings[s]);
3080
- }), this.addBinding({ key: "Enter", shiftKey: null }, this.handleEnter), this.addBinding(
3081
- { key: "Enter", metaKey: null, ctrlKey: null, altKey: null },
3082
- () => {
3083
- }
3084
- ), /Firefox/i.test(navigator.userAgent) ? (this.addBinding(
3085
- { key: "Backspace" },
3086
- { collapsed: !0 },
3087
- this.handleBackspace
3088
- ), this.addBinding(
3089
- { key: "Delete" },
3090
- { collapsed: !0 },
3091
- this.handleDelete
3092
- )) : (this.addBinding(
3093
- { key: "Backspace" },
3094
- { collapsed: !0, prefix: /^.?$/ },
3095
- this.handleBackspace
3096
- ), this.addBinding(
3097
- { key: "Delete" },
3098
- { collapsed: !0, suffix: /^.?$/ },
3099
- this.handleDelete
3100
- )), this.addBinding(
3101
- { key: "Backspace" },
3102
- { collapsed: !1 },
3103
- this.handleDeleteRange
3104
- ), this.addBinding(
3105
- { key: "Delete" },
3106
- { collapsed: !1 },
3107
- this.handleDeleteRange
3108
- ), this.addBinding(
3109
- {
3110
- key: "Backspace",
3111
- altKey: null,
3112
- ctrlKey: null,
3113
- metaKey: null,
3114
- shiftKey: null
3115
- },
3116
- { collapsed: !0, offset: 0 },
3117
- this.handleBackspace
3118
- ), this.listen();
3119
- }
3120
- addBinding(t, e = {}, s = {}) {
3121
- const i = Ge(t);
3122
- if (i == null) {
3123
- He.warn("Attempted to add invalid keyboard binding", i);
3124
- return;
3125
- }
3126
- typeof e == "function" && (e = { handler: e }), typeof s == "function" && (s = { handler: s }), (Array.isArray(i.key) ? i.key : [i.key]).forEach((o) => {
3127
- const l = {
3128
- ...i,
3129
- key: o,
3130
- ...e,
3131
- ...s
3132
- };
3133
- this.bindings[l.key] = this.bindings[l.key] || [], this.bindings[l.key].push(l);
3134
- });
3135
- }
3136
- listen() {
3137
- this.rich.root.addEventListener("keydown", (t) => {
3138
- if (t.defaultPrevented || t.isComposing || t.keyCode === 229 && (t.key === "Enter" || t.key === "Backspace")) return;
3139
- const i = (this.bindings[t.key] || []).concat(
3140
- this.bindings[t.which] || []
3141
- ).filter(
3142
- (y) => gt.match(t, y)
3143
- );
3144
- if (i.length === 0) return;
3145
- const n = u.find(t.target, !0);
3146
- if (n && n.scroll !== this.rich.scroll) return;
3147
- const o = this.rich.getSelection();
3148
- if (o == null || !this.rich.hasFocus()) return;
3149
- const [l, a] = this.rich.getLine(o.index), [c, h] = this.rich.getLeaf(o.index), [d, g] = o.length === 0 ? [c, h] : this.rich.getLeaf(o.index + o.length), b = c instanceof et ? c.value().slice(0, h) : "", N = d instanceof et ? d.value().slice(g) : "", E = {
3150
- collapsed: o.length === 0,
3151
- empty: o.length === 0 && l.length() <= 1,
3152
- format: this.rich.getFormat(o),
3153
- line: l,
3154
- offset: a,
3155
- prefix: b,
3156
- suffix: N,
3157
- event: t
3158
- };
3159
- i.some((y) => {
3160
- if (y.collapsed != null && y.collapsed !== E.collapsed || y.empty != null && y.empty !== E.empty || y.offset != null && y.offset !== E.offset)
3161
- return !1;
3162
- if (Array.isArray(y.format)) {
3163
- if (y.format.every((v) => E.format[v] == null))
3164
- return !1;
3165
- } else if (typeof y.format == "object" && !Object.keys(y.format).every((v) => y.format[v] === !0 ? E.format[v] != null : y.format[v] === !1 ? E.format[v] == null : X(y.format[v], E.format[v])))
3166
- return !1;
3167
- return y.prefix != null && !y.prefix.test(E.prefix) || y.suffix != null && !y.suffix.test(E.suffix) ? !1 : y.handler.call(this, o, E, y) !== !0;
3168
- }) && t.preventDefault();
3169
- });
3170
- }
3171
- handleBackspace(t, e) {
3172
- const s = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(e.prefix) ? 2 : 1;
3173
- if (t.index === 0 || this.rich.getLength() <= 1) return;
3174
- let i = {};
3175
- const [n] = this.rich.getLine(t.index);
3176
- let o = new f().retain(t.index - s).delete(s);
3177
- if (e.offset === 0) {
3178
- const [l] = this.rich.getLine(t.index - 1);
3179
- if (l && !(l.statics.blotName === "block" && l.length() <= 1)) {
3180
- const c = n.formats(), h = this.rich.getFormat(t.index - 1, 1);
3181
- if (i = C.diff(c, h) || {}, Object.keys(i).length > 0) {
3182
- const d = new f().retain(t.index + n.length() - 2).retain(1, i);
3183
- o = o.compose(d);
3184
- }
3185
- }
3186
- }
3187
- this.rich.updateContents(o, u.sources.USER), this.rich.focus();
3188
- }
3189
- handleDelete(t, e) {
3190
- const s = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(e.suffix) ? 2 : 1;
3191
- if (t.index >= this.rich.getLength() - s) return;
3192
- let i = {};
3193
- const [n] = this.rich.getLine(t.index);
3194
- let o = new f().retain(t.index).delete(s);
3195
- if (e.offset >= n.length() - 1) {
3196
- const [l] = this.rich.getLine(t.index + 1);
3197
- if (l) {
3198
- const a = n.formats(), c = this.rich.getFormat(t.index, 1);
3199
- i = C.diff(a, c) || {}, Object.keys(i).length > 0 && (o = o.retain(l.length() - 1).retain(1, i));
3200
- }
3201
- }
3202
- this.rich.updateContents(o, u.sources.USER), this.rich.focus();
3203
- }
3204
- handleDeleteRange(t) {
3205
- Ut({ range: t, rich: this.rich }), this.rich.focus();
3206
- }
3207
- handleEnter(t, e) {
3208
- const s = Object.keys(e.format).reduce(
3209
- (n, o) => (this.rich.scroll.query(o, p.BLOCK) && !Array.isArray(e.format[o]) && (n[o] = e.format[o]), n),
3210
- {}
3211
- ), i = new f().retain(t.index).delete(t.length).insert(`
3212
- `, s);
3213
- this.rich.updateContents(i, u.sources.USER), this.rich.setSelection(t.index + 1, u.sources.SILENT), this.rich.focus();
3214
- }
3215
- }
3216
- const Ve = {
3217
- bindings: {
3218
- bold: wt("bold"),
3219
- italic: wt("italic"),
3220
- underline: wt("underline"),
3221
- indent: {
3222
- // highlight tab or tab at beginning of list, indent or blockquote
3223
- key: "Tab",
3224
- format: ["blockquote", "indent", "list"],
3225
- handler(r, t) {
3226
- return t.collapsed && t.offset !== 0 ? !0 : (this.rich.format("indent", "+1", u.sources.USER), !1);
3227
- }
3228
- },
3229
- outdent: {
3230
- key: "Tab",
3231
- shiftKey: !0,
3232
- format: ["blockquote", "indent", "list"],
3233
- // highlight tab or tab at beginning of list, indent or blockquote
3234
- handler(r, t) {
3235
- return t.collapsed && t.offset !== 0 ? !0 : (this.rich.format("indent", "-1", u.sources.USER), !1);
3236
- }
3237
- },
3238
- "outdent backspace": {
3239
- key: "Backspace",
3240
- collapsed: !0,
3241
- shiftKey: null,
3242
- metaKey: null,
3243
- ctrlKey: null,
3244
- altKey: null,
3245
- format: ["indent", "list"],
3246
- offset: 0,
3247
- handler(r, t) {
3248
- t.format.indent != null ? this.rich.format("indent", "-1", u.sources.USER) : t.format.list != null && this.rich.format("list", !1, u.sources.USER);
3249
- }
3250
- },
3251
- "indent code-block": Xt(!0),
3252
- "outdent code-block": Xt(!1),
3253
- "remove tab": {
3254
- key: "Tab",
3255
- shiftKey: !0,
3256
- collapsed: !0,
3257
- prefix: /\t$/,
3258
- handler(r) {
3259
- this.rich.deleteText(r.index - 1, 1, u.sources.USER);
3260
- }
3261
- },
3262
- tab: {
3263
- key: "Tab",
3264
- handler(r, t) {
3265
- if (t.format.table) return !0;
3266
- this.rich.history.cutoff();
3267
- const e = new f().retain(r.index).delete(r.length).insert(" ");
3268
- return this.rich.updateContents(e, u.sources.USER), this.rich.history.cutoff(), this.rich.setSelection(r.index + 1, u.sources.SILENT), !1;
3269
- }
3270
- },
3271
- "blockquote empty enter": {
3272
- key: "Enter",
3273
- collapsed: !0,
3274
- format: ["blockquote"],
3275
- empty: !0,
3276
- handler() {
3277
- this.rich.format("blockquote", !1, u.sources.USER);
3278
- }
3279
- },
3280
- "list empty enter": {
3281
- key: "Enter",
3282
- collapsed: !0,
3283
- format: ["list"],
3284
- empty: !0,
3285
- handler(r, t) {
3286
- const e = { list: !1 };
3287
- t.format.indent && (e.indent = !1), this.rich.formatLine(
3288
- r.index,
3289
- r.length,
3290
- e,
3291
- u.sources.USER
3292
- );
3293
- }
3294
- },
3295
- "checklist enter": {
3296
- key: "Enter",
3297
- collapsed: !0,
3298
- format: { list: "checked" },
3299
- handler(r) {
3300
- const [t, e] = this.rich.getLine(r.index), s = {
3301
- ...t.formats(),
3302
- list: "checked"
3303
- }, i = new f().retain(r.index).insert(`
3304
- `, s).retain(t.length() - e - 1).retain(1, { list: "unchecked" });
3305
- this.rich.updateContents(i, u.sources.USER), this.rich.setSelection(r.index + 1, u.sources.SILENT), this.rich.scrollSelectionIntoView();
3306
- }
3307
- },
3308
- "header enter": {
3309
- key: "Enter",
3310
- collapsed: !0,
3311
- format: ["header"],
3312
- suffix: /^$/,
3313
- handler(r, t) {
3314
- const [e, s] = this.rich.getLine(r.index), i = new f().retain(r.index).insert(`
3315
- `, t.format).retain(e.length() - s - 1).retain(1, { header: null });
3316
- this.rich.updateContents(i, u.sources.USER), this.rich.setSelection(r.index + 1, u.sources.SILENT), this.rich.scrollSelectionIntoView();
3317
- }
3318
- },
3319
- "table backspace": {
3320
- key: "Backspace",
3321
- format: ["table"],
3322
- collapsed: !0,
3323
- offset: 0,
3324
- handler() {
3325
- }
3326
- },
3327
- "table delete": {
3328
- key: "Delete",
3329
- format: ["table"],
3330
- collapsed: !0,
3331
- suffix: /^$/,
3332
- handler() {
3333
- }
3334
- },
3335
- "table enter": {
3336
- key: "Enter",
3337
- shiftKey: null,
3338
- format: ["table"],
3339
- handler(r) {
3340
- const t = this.rich.getModule("table");
3341
- if (t) {
3342
- const [e, s, i, n] = t.getTable(r), o = Xe(e, s, i, n);
3343
- if (o == null) return;
3344
- let l = e.offset();
3345
- if (o < 0) {
3346
- const a = new f().retain(l).insert(`
3347
- `);
3348
- this.rich.updateContents(a, u.sources.USER), this.rich.setSelection(
3349
- r.index + 1,
3350
- r.length,
3351
- u.sources.SILENT
3352
- );
3353
- } else if (o > 0) {
3354
- l += e.length();
3355
- const a = new f().retain(l).insert(`
3356
- `);
3357
- this.rich.updateContents(a, u.sources.USER), this.rich.setSelection(l, u.sources.USER);
3358
- }
3359
- }
3360
- }
3361
- },
3362
- "table tab": {
3363
- key: "Tab",
3364
- shiftKey: null,
3365
- format: ["table"],
3366
- handler(r, t) {
3367
- const { event: e, line: s } = t, i = s.offset(this.rich.scroll);
3368
- e.shiftKey ? this.rich.setSelection(i - 1, u.sources.USER) : this.rich.setSelection(i + s.length(), u.sources.USER);
3369
- }
3370
- },
3371
- "list autofill": {
3372
- key: " ",
3373
- shiftKey: null,
3374
- collapsed: !0,
3375
- format: {
3376
- "code-block": !1,
3377
- blockquote: !1,
3378
- table: !1
3379
- },
3380
- prefix: /^\s*?(\d+\.|-|\*|\[ ?\]|\[x\])$/,
3381
- handler(r, t) {
3382
- if (this.rich.scroll.query("list") == null) return !0;
3383
- const { length: e } = t.prefix, [s, i] = this.rich.getLine(r.index);
3384
- if (i > e) return !0;
3385
- let n;
3386
- switch (t.prefix.trim()) {
3387
- case "[]":
3388
- case "[ ]":
3389
- n = "unchecked";
3390
- break;
3391
- case "[x]":
3392
- n = "checked";
3393
- break;
3394
- case "-":
3395
- case "*":
3396
- n = "bullet";
3397
- break;
3398
- default:
3399
- n = "ordered";
3400
- }
3401
- this.rich.insertText(r.index, " ", u.sources.USER), this.rich.history.cutoff();
3402
- const o = new f().retain(r.index - i).delete(e + 1).retain(s.length() - 2 - i).retain(1, { list: n });
3403
- return this.rich.updateContents(o, u.sources.USER), this.rich.history.cutoff(), this.rich.setSelection(r.index - e, u.sources.SILENT), !1;
3404
- }
3405
- },
3406
- "code exit": {
3407
- key: "Enter",
3408
- collapsed: !0,
3409
- format: ["code-block"],
3410
- prefix: /^$/,
3411
- suffix: /^\s*$/,
3412
- handler(r) {
3413
- const [t, e] = this.rich.getLine(r.index);
3414
- let s = 2, i = t;
3415
- for (; i != null && i.length() <= 1 && i.formats()["code-block"]; )
3416
- if (i = i.prev, s -= 1, s <= 0) {
3417
- const n = new f().retain(r.index + t.length() - e - 2).retain(1, { "code-block": null }).delete(1);
3418
- return this.rich.updateContents(n, u.sources.USER), this.rich.setSelection(r.index - 1, u.sources.SILENT), !1;
3419
- }
3420
- return !0;
3421
- }
3422
- },
3423
- "embed left": ut("ArrowLeft", !1),
3424
- "embed left shift": ut("ArrowLeft", !0),
3425
- "embed right": ut("ArrowRight", !1),
3426
- "embed right shift": ut("ArrowRight", !0),
3427
- "table down": Yt(!1),
3428
- "table up": Yt(!0)
3429
- }
3430
- };
3431
- gt.DEFAULTS = Ve;
3432
- function Xt(r) {
3433
- return {
3434
- key: "Tab",
3435
- shiftKey: !r,
3436
- format: { "code-block": !0 },
3437
- handler(t, { event: e }) {
3438
- const s = this.rich.scroll.query("code-block"), { TAB: i } = s;
3439
- if (t.length === 0 && !e.shiftKey) {
3440
- this.rich.insertText(t.index, i, u.sources.USER), this.rich.setSelection(t.index + i.length, u.sources.SILENT);
3441
- return;
3442
- }
3443
- const n = t.length === 0 ? this.rich.getLines(t.index, 1) : this.rich.getLines(t);
3444
- let { index: o, length: l } = t;
3445
- n.forEach((a, c) => {
3446
- r ? (a.insertAt(0, i), c === 0 ? o += i.length : l += i.length) : a.domNode.textContent.startsWith(i) && (a.deleteAt(0, i.length), c === 0 ? o -= i.length : l -= i.length);
3447
- }), this.rich.update(u.sources.USER), this.rich.setSelection(o, l, u.sources.SILENT);
3448
- }
3449
- };
3450
- }
3451
- function ut(r, t) {
3452
- return {
3453
- key: r,
3454
- shiftKey: t,
3455
- altKey: null,
3456
- [r === "ArrowLeft" ? "prefix" : "suffix"]: /^$/,
3457
- handler(s) {
3458
- let { index: i } = s;
3459
- r === "ArrowRight" && (i += s.length + 1);
3460
- const [n] = this.rich.getLeaf(i);
3461
- return n instanceof B ? (r === "ArrowLeft" ? t ? this.rich.setSelection(
3462
- s.index - 1,
3463
- s.length + 1,
3464
- u.sources.USER
3465
- ) : this.rich.setSelection(s.index - 1, u.sources.USER) : t ? this.rich.setSelection(
3466
- s.index,
3467
- s.length + 1,
3468
- u.sources.USER
3469
- ) : this.rich.setSelection(
3470
- s.index + s.length + 1,
3471
- u.sources.USER
3472
- ), !1) : !0;
3473
- }
3474
- };
3475
- }
3476
- function wt(r) {
3477
- return {
3478
- key: r[0],
3479
- shortKey: !0,
3480
- handler(t, e) {
3481
- this.rich.format(r, !e.format[r], u.sources.USER);
3482
- }
3483
- };
3484
- }
3485
- function Yt(r) {
3486
- return {
3487
- key: r ? "ArrowUp" : "ArrowDown",
3488
- collapsed: !0,
3489
- format: ["table"],
3490
- handler(t, e) {
3491
- const s = r ? "prev" : "next", i = e.line, n = i.parent[s];
3492
- if (n != null) {
3493
- if (n.statics.blotName === "table-row") {
3494
- let o = n.children.head, l = i;
3495
- for (; l.prev != null; )
3496
- l = l.prev, o = o.next;
3497
- const a = o.offset(this.rich.scroll) + Math.min(e.offset, o.length() - 1);
3498
- this.rich.setSelection(a, 0, u.sources.USER);
3499
- }
3500
- } else {
3501
- const o = i.table()[s];
3502
- o != null && (r ? this.rich.setSelection(
3503
- o.offset(this.rich.scroll) + o.length() - 1,
3504
- 0,
3505
- u.sources.USER
3506
- ) : this.rich.setSelection(
3507
- o.offset(this.rich.scroll),
3508
- 0,
3509
- u.sources.USER
3510
- ));
3511
- }
3512
- return !1;
3513
- }
3514
- };
3515
- }
3516
- function Ge(r) {
3517
- if (typeof r == "string" || typeof r == "number")
3518
- r = { key: r };
3519
- else if (typeof r == "object")
3520
- r = W(r);
3521
- else
3522
- return null;
3523
- return r.shortKey && (r[We] = r.shortKey, delete r.shortKey), r;
3524
- }
3525
- function Ut({ rich: r, range: t }) {
3526
- const e = r.getLines(t);
3527
- let s = {};
3528
- if (e.length > 1) {
3529
- const i = e[0].formats(), n = e[e.length - 1].formats();
3530
- s = C.diff(n, i) || {};
3531
- }
3532
- r.deleteText(t, u.sources.USER), Object.keys(s).length > 0 && r.formatLine(t.index, 1, s, u.sources.USER), r.setSelection(t.index, u.sources.SILENT);
3533
- }
3534
- function Xe(r, t, e, s) {
3535
- return t.prev == null && t.next == null ? e.prev == null && e.next == null ? s === 0 ? -1 : 1 : e.prev == null ? -1 : 1 : t.prev == null ? -1 : t.next == null ? 1 : null;
3536
- }
3537
- const Ye = /font-weight:\s*normal/, Ze = ["P", "OL", "UL"], Zt = (r) => r && Ze.includes(r.tagName), Qe = (r) => {
3538
- Array.from(r.querySelectorAll("br")).filter(
3539
- (t) => Zt(t.previousElementSibling) && Zt(t.nextElementSibling)
3540
- ).forEach((t) => {
3541
- t.parentNode?.removeChild(t);
3542
- });
3543
- }, Je = (r) => {
3544
- Array.from(r.querySelectorAll('b[style*="font-weight"]')).filter((t) => t.getAttribute("style")?.match(Ye)).forEach((t) => {
3545
- const e = r.createDocumentFragment();
3546
- e.append(...t.childNodes), t.parentNode?.replaceChild(e, t);
3547
- });
3548
- };
3549
- function ts(r) {
3550
- r.querySelector('[id^="docs-internal-guid-"]') && (Je(r), Qe(r));
3551
- }
3552
- const es = /\bmso-list:[^;]*ignore/i, ss = /\bmso-list:[^;]*\bl(\d+)/i, is = /\bmso-list:[^;]*\blevel(\d+)/i, rs = (r, t) => {
3553
- const e = r.getAttribute("style"), s = e?.match(ss);
3554
- if (!s)
3555
- return null;
3556
- const i = Number(s[1]), n = e?.match(is), o = n ? Number(n[1]) : 1, l = new RegExp(
3557
- `@list l${i}:level${o}\\s*\\{[^\\}]*mso-level-number-format:\\s*([\\w-]+)`,
3558
- "i"
3559
- ), a = t.match(l), c = a && a[1] === "bullet" ? "bullet" : "ordered";
3560
- return { id: i, indent: o, type: c, element: r };
3561
- }, ns = (r) => {
3562
- const t = Array.from(r.querySelectorAll("[style*=mso-list]")), e = [], s = [];
3563
- t.forEach((o) => {
3564
- (o.getAttribute("style") || "").match(es) ? e.push(o) : s.push(o);
3565
- }), e.forEach((o) => o.parentNode?.removeChild(o));
3566
- const i = r.documentElement.innerHTML, n = s.map((o) => rs(o, i)).filter((o) => o);
3567
- for (; n.length; ) {
3568
- const o = [];
3569
- let l = n.shift();
3570
- for (; l; )
3571
- o.push(l), l = n.length && n[0]?.element === l.element.nextElementSibling && // Different id means the next item doesn't belong to this group.
3572
- n[0].id === l.id ? n.shift() : null;
3573
- const a = document.createElement("ul");
3574
- o.forEach((d) => {
3575
- const g = document.createElement("li");
3576
- g.setAttribute("data-list", d.type), d.indent > 1 && g.setAttribute(
3577
- "class",
3578
- `${L}-indent-${d.indent - 1}`
3579
- ), g.innerHTML = d.element.innerHTML, a.appendChild(g);
3580
- });
3581
- const c = o[0]?.element, { parentNode: h } = c ?? {};
3582
- c && h?.replaceChild(a, c), o.slice(1).forEach(({ element: d }) => {
3583
- h?.removeChild(d);
3584
- });
3585
- }
3586
- };
3587
- function os(r) {
3588
- r.documentElement.getAttribute("xmlns:w") === "urn:schemas-microsoft-com:office:word" && ns(r);
3589
- }
3590
- const ls = [os, ts], as = (r) => {
3591
- r.documentElement && ls.forEach((t) => {
3592
- t(r);
3593
- });
3594
- }, cs = G("rich:clipboard"), hs = [
3595
- [Node.TEXT_NODE, As],
3596
- [Node.TEXT_NODE, Jt],
3597
- ["br", gs],
3598
- [Node.ELEMENT_NODE, Jt],
3599
- [Node.ELEMENT_NODE, ms],
3600
- [Node.ELEMENT_NODE, ps],
3601
- [Node.ELEMENT_NODE, Ts],
3602
- ["li", ys],
3603
- ["ol, ul", Es],
3604
- ["pre", bs],
3605
- ["tr", Ls],
3606
- ["b", Ct("bold")],
3607
- ["i", Ct("italic")],
3608
- ["strike", Ct("strike")],
3609
- ["style", Ns]
3610
- ], us = [Ue, Pe].reduce(
3611
- (r, t) => (r[t.keyName] = t, r),
3612
- {}
3613
- ), Qt = [
3614
- je,
3615
- Fe,
3616
- $e,
3617
- _e,
3618
- Ke,
3619
- qe
3620
- ].reduce((r, t) => (r[t.keyName] = t, r), {});
3621
- class fs extends Y {
3622
- static {
3623
- this.DEFAULTS = {
3624
- matchers: []
3625
- };
3626
- }
3627
- constructor(t, e) {
3628
- super(t, e), this.rich.root.addEventListener(
3629
- "copy",
3630
- (s) => this.onCaptureCopy(s, !1)
3631
- ), this.rich.root.addEventListener("cut", (s) => this.onCaptureCopy(s, !0)), this.rich.root.addEventListener("paste", this.onCapturePaste.bind(this)), this.matchers = [], hs.concat(this.options.matchers ?? []).forEach(
3632
- ([s, i]) => {
3633
- this.addMatcher(s, i);
3634
- }
3635
- );
3636
- }
3637
- addMatcher(t, e) {
3638
- this.matchers.push([t, e]);
3639
- }
3640
- convert({ html: t, text: e }, s = {}) {
3641
- if (s[z.blotName])
3642
- return new f().insert(e || "", {
3643
- [z.blotName]: s[z.blotName]
3644
- });
3645
- if (!t)
3646
- return new f().insert(e || "", s);
3647
- const i = this.convertHTML(t);
3648
- return ot(i, `
3649
- `) && (i.ops[i.ops.length - 1].attributes == null || s.table) ? i.compose(new f().retain(i.length() - 1).delete(1)) : i;
3650
- }
3651
- normalizeHTML(t) {
3652
- as(t);
3653
- }
3654
- convertHTML(t) {
3655
- const e = new DOMParser().parseFromString(t, "text/html");
3656
- this.normalizeHTML(e);
3657
- const s = e.body, i = /* @__PURE__ */ new WeakMap(), [n, o] = this.prepareMatching(
3658
- s,
3659
- i
3660
- );
3661
- return ce(
3662
- this.rich.scroll,
3663
- s,
3664
- n,
3665
- o,
3666
- i
3667
- );
3668
- }
3669
- dangerouslyPasteHTML(t, e, s = u.sources.API) {
3670
- if (typeof t == "string") {
3671
- const i = this.convert({ html: t, text: "" });
3672
- this.rich.setContents(i, e), this.rich.setSelection(0, u.sources.SILENT);
3673
- } else {
3674
- const i = this.convert({ html: e, text: "" });
3675
- this.rich.updateContents(new f().retain(t).concat(i), s), this.rich.setSelection(t + i.length(), u.sources.SILENT);
3676
- }
3677
- }
3678
- onCaptureCopy(t, e = !1) {
3679
- if (t.defaultPrevented) return;
3680
- t.preventDefault();
3681
- const [s] = this.rich.selection.getRange();
3682
- if (s == null) return;
3683
- const { html: i, text: n } = this.onCopy(s, e);
3684
- t.clipboardData?.setData("text/plain", n), t.clipboardData?.setData("text/html", i), e && Ut({ range: s, rich: this.rich });
3685
- }
3686
- /*
3687
- * https://www.iana.org/assignments/media-types/text/uri-list
3688
- */
3689
- normalizeURIList(t) {
3690
- return t.split(/\r?\n/).filter((e) => e[0] !== "#").join(`
3691
- `);
3692
- }
3693
- onCapturePaste(t) {
3694
- if (t.defaultPrevented || !this.rich.isEnabled()) return;
3695
- t.preventDefault();
3696
- const e = this.rich.getSelection(!0);
3697
- if (e == null) return;
3698
- const s = t.clipboardData?.getData("text/html");
3699
- let i = t.clipboardData?.getData("text/plain");
3700
- if (!s && !i) {
3701
- const o = t.clipboardData?.getData("text/uri-list");
3702
- o && (i = this.normalizeURIList(o));
3703
- }
3704
- const n = Array.from(t.clipboardData?.files || []);
3705
- if (!s && n.length > 0) {
3706
- this.rich.uploader.upload(e, n);
3707
- return;
3708
- }
3709
- if (s && n.length > 0) {
3710
- const o = new DOMParser().parseFromString(s, "text/html");
3711
- if (o.body.childElementCount === 1 && o.body.firstElementChild?.tagName === "IMG") {
3712
- this.rich.uploader.upload(e, n);
3713
- return;
3714
- }
3715
- }
3716
- this.onPaste(e, { html: s, text: i });
3717
- }
3718
- onCopy(t) {
3719
- const e = this.rich.getText(t);
3720
- return { html: this.rich.getSemanticHTML(t), text: e };
3721
- }
3722
- onPaste(t, { text: e, html: s }) {
3723
- const i = this.rich.getFormat(t.index), n = this.convert({ text: e, html: s }, i);
3724
- cs.log("onPaste", n, { text: e, html: s });
3725
- const o = new f().retain(t.index).delete(t.length).concat(n);
3726
- this.rich.updateContents(o, u.sources.USER), this.rich.setSelection(o.length() - t.length, u.sources.SILENT), this.rich.scrollSelectionIntoView();
3727
- }
3728
- prepareMatching(t, e) {
3729
- const s = [], i = [];
3730
- return this.matchers.forEach((n) => {
3731
- const [o, l] = n;
3732
- switch (o) {
3733
- case Node.TEXT_NODE:
3734
- i.push(l);
3735
- break;
3736
- case Node.ELEMENT_NODE:
3737
- s.push(l);
3738
- break;
3739
- default:
3740
- Array.from(t.querySelectorAll(o)).forEach((a) => {
3741
- e.has(a) ? e.get(a)?.push(l) : e.set(a, [l]);
3742
- });
3743
- break;
3744
- }
3745
- }), [s, i];
3746
- }
3747
- }
3748
- function Z(r, t, e, s) {
3749
- return s.query(t) ? r.reduce((i, n) => {
3750
- if (!n.insert) return i;
3751
- if (n.attributes && n.attributes[t])
3752
- return i.push(n);
3753
- const o = e ? { [t]: e } : {};
3754
- return i.insert(n.insert, { ...o, ...n.attributes });
3755
- }, new f()) : r;
3756
- }
3757
- function ot(r, t) {
3758
- let e = "";
3759
- for (let s = r.ops.length - 1; s >= 0 && e.length < t.length; --s) {
3760
- const i = r.ops[s];
3761
- if (typeof i.insert != "string") break;
3762
- e = i.insert + e;
3763
- }
3764
- return e.slice(-1 * t.length) === t;
3765
- }
3766
- function H(r, t) {
3767
- if (!(r instanceof Element)) return !1;
3768
- const e = t.query(r);
3769
- return e && e.prototype instanceof B ? !1 : [
3770
- "address",
3771
- "article",
3772
- "blockquote",
3773
- "canvas",
3774
- "dd",
3775
- "div",
3776
- "dl",
3777
- "dt",
3778
- "fieldset",
3779
- "figcaption",
3780
- "figure",
3781
- "footer",
3782
- "form",
3783
- "h1",
3784
- "h2",
3785
- "h3",
3786
- "h4",
3787
- "h5",
3788
- "h6",
3789
- "header",
3790
- "iframe",
3791
- "li",
3792
- "main",
3793
- "nav",
3794
- "ol",
3795
- "output",
3796
- "p",
3797
- "pre",
3798
- "section",
3799
- "table",
3800
- "td",
3801
- "tr",
3802
- "ul",
3803
- "video"
3804
- ].includes(r.tagName.toLowerCase());
3805
- }
3806
- function ds(r, t) {
3807
- return r.previousElementSibling && r.nextElementSibling && !H(r.previousElementSibling, t) && !H(r.nextElementSibling, t);
3808
- }
3809
- const ft = /* @__PURE__ */ new WeakMap();
3810
- function ae(r) {
3811
- return r == null ? !1 : (ft.has(r) || (r.tagName === "PRE" ? ft.set(r, !0) : ft.set(r, ae(r.parentNode))), ft.get(r));
3812
- }
3813
- function ce(r, t, e, s, i) {
3814
- return t.nodeType === t.TEXT_NODE ? s.reduce((n, o) => o(t, n, r), new f()) : t.nodeType === t.ELEMENT_NODE ? Array.from(t.childNodes || []).reduce((n, o) => {
3815
- let l = ce(
3816
- r,
3817
- o,
3818
- e,
3819
- s,
3820
- i
3821
- );
3822
- return o.nodeType === t.ELEMENT_NODE && (l = e.reduce((a, c) => c(o, a, r), l), l = (i.get(o) || []).reduce(
3823
- (a, c) => c(o, a, r),
3824
- l
3825
- )), n.concat(l);
3826
- }, new f()) : new f();
3827
- }
3828
- function Ct(r) {
3829
- return (t, e, s) => Z(e, r, !0, s);
3830
- }
3831
- function ps(r, t, e) {
3832
- const s = j.keys(r), i = q.keys(r), n = V.keys(r), o = {};
3833
- return s.concat(i).concat(n).forEach((l) => {
3834
- let a = e.query(l, p.ATTRIBUTE);
3835
- a != null && (o[a.attrName] = a.value(r), o[a.attrName]) || (a = us[l], a != null && (a.attrName === l || a.keyName === l) && (o[a.attrName] = a.value(r) || void 0), a = Qt[l], a != null && (a.attrName === l || a.keyName === l) && (a = Qt[l], o[a.attrName] = a.value(r) || void 0));
3836
- }), Object.entries(o).reduce(
3837
- (l, [a, c]) => Z(l, a, c, e),
3838
- t
3839
- );
3840
- }
3841
- function ms(r, t, e) {
3842
- const s = e.query(r);
3843
- if (s == null) return t;
3844
- if (s.prototype instanceof B) {
3845
- const i = {}, n = s.value(r);
3846
- if (n != null)
3847
- return i[s.blotName] = n, new f().insert(i, s.formats(r, e));
3848
- } else if (s.prototype instanceof _ && !ot(t, `
3849
- `) && t.insert(`
3850
- `), "blotName" in s && "formats" in s && typeof s.formats == "function")
3851
- return Z(
3852
- t,
3853
- s.blotName,
3854
- s.formats(r, e),
3855
- e
3856
- );
3857
- return t;
3858
- }
3859
- function gs(r, t) {
3860
- return ot(t, `
3861
- `) || t.insert(`
3862
- `), t;
3863
- }
3864
- function bs(r, t, e) {
3865
- const s = e.query("code-block"), i = s && "formats" in s && typeof s.formats == "function" ? s.formats(r, e) : !0;
3866
- return Z(t, "code-block", i, e);
3867
- }
3868
- function Ns() {
3869
- return new f();
3870
- }
3871
- function ys(r, t, e) {
3872
- const s = e.query(r);
3873
- if (s == null || s.blotName !== "list" || !ot(t, `
3874
- `))
3875
- return t;
3876
- let i = -1, n = r.parentNode;
3877
- for (; n != null; )
3878
- ["OL", "UL"].includes(n.tagName) && (i += 1), n = n.parentNode;
3879
- return i <= 0 ? t : t.reduce((o, l) => l.insert ? l.attributes && typeof l.attributes.indent == "number" ? o.push(l) : o.insert(l.insert, { indent: i, ...l.attributes || {} }) : o, new f());
3880
- }
3881
- function Es(r, t, e) {
3882
- const s = r;
3883
- let i = s.tagName === "OL" ? "ordered" : "bullet";
3884
- const n = s.getAttribute("data-checked");
3885
- return n && (i = n === "true" ? "checked" : "unchecked"), Z(t, "list", i, e);
3886
- }
3887
- function Jt(r, t, e) {
3888
- if (!ot(t, `
3889
- `)) {
3890
- if (H(r, e) && (r.childNodes.length > 0 || r instanceof HTMLParagraphElement))
3891
- return t.insert(`
3892
- `);
3893
- if (t.length() > 0 && r.nextSibling) {
3894
- let s = r.nextSibling;
3895
- for (; s != null; ) {
3896
- if (H(s, e))
3897
- return t.insert(`
3898
- `);
3899
- const i = e.query(s);
3900
- if (i && i.prototype instanceof I)
3901
- return t.insert(`
3902
- `);
3903
- s = s.firstChild;
3904
- }
3905
- }
3906
- }
3907
- return t;
3908
- }
3909
- function Ts(r, t, e) {
3910
- const s = {}, i = r.style || {};
3911
- return i.fontStyle === "italic" && (s.italic = !0), i.textDecoration === "underline" && (s.underline = !0), i.textDecoration === "line-through" && (s.strike = !0), (i.fontWeight?.startsWith("bold") || parseInt(i.fontWeight, 10) >= 700) && (s.bold = !0), t = Object.entries(s).reduce(
3912
- (n, [o, l]) => Z(n, o, l, e),
3913
- t
3914
- ), parseFloat(i.textIndent || 0) > 0 ? new f().insert(" ").concat(t) : t;
3915
- }
3916
- function Ls(r, t, e) {
3917
- const s = r.parentElement?.tagName === "TABLE" ? r.parentElement : r.parentElement?.parentElement;
3918
- if (s != null) {
3919
- const n = Array.from(s.querySelectorAll("tr")).indexOf(r) + 1;
3920
- return Z(t, "table", n, e);
3921
- }
3922
- return t;
3923
- }
3924
- function As(r, t, e) {
3925
- let s = r.data;
3926
- if (r.parentElement?.tagName === "O:P")
3927
- return t.insert(s.trim());
3928
- if (!ae(r)) {
3929
- if (s.trim().length === 0 && s.includes(`
3930
- `) && !ds(r, e))
3931
- return t;
3932
- s = s.replace(/[^\S\u00a0]/g, " "), s = s.replace(/ {2,}/g, " "), (r.previousSibling == null && r.parentElement != null && H(r.parentElement, e) || r.previousSibling instanceof Element && H(r.previousSibling, e)) && (s = s.replace(/^ /, "")), (r.nextSibling == null && r.parentElement != null && H(r.parentElement, e) || r.nextSibling instanceof Element && H(r.nextSibling, e)) && (s = s.replace(/ $/, "")), s = s.replaceAll(" ", " ");
3933
- }
3934
- return t.insert(s);
3935
- }
3936
- class ws extends Y {
3937
- constructor(t, e) {
3938
- super(t, e), this.lastRecorded = 0, this.ignoreChange = !1, this.stack = { undo: [], redo: [] }, this.currentRange = null, this.rich.on(
3939
- u.events.EDITOR_CHANGE,
3940
- (s, i, n, o) => {
3941
- s === u.events.SELECTION_CHANGE ? i && o !== u.sources.SILENT && (this.currentRange = i) : s === u.events.TEXT_CHANGE && (this.ignoreChange || (!this.options.userOnly || o === u.sources.USER ? this.record(i, n) : this.transform(i)), this.currentRange = St(this.currentRange, i));
3942
- }
3943
- ), this.rich.keyboard.addBinding(
3944
- { key: "z", shortKey: !0 },
3945
- this.undo.bind(this)
3946
- ), this.rich.keyboard.addBinding(
3947
- { key: ["z", "Z"], shortKey: !0, shiftKey: !0 },
3948
- this.redo.bind(this)
3949
- ), /Win/i.test(navigator.platform) && this.rich.keyboard.addBinding(
3950
- { key: "y", shortKey: !0 },
3951
- this.redo.bind(this)
3952
- ), this.rich.root.addEventListener("beforeinput", (s) => {
3953
- s.inputType === "historyUndo" ? (this.undo(), s.preventDefault()) : s.inputType === "historyRedo" && (this.redo(), s.preventDefault());
3954
- });
3955
- }
3956
- static {
3957
- this.DEFAULTS = {
3958
- delay: 1e3,
3959
- maxStack: 100,
3960
- userOnly: !1
3961
- };
3962
- }
3963
- change(t, e) {
3964
- if (this.stack[t].length === 0) return;
3965
- const s = this.stack[t].pop();
3966
- if (!s) return;
3967
- const i = this.rich.getContents(), n = s.delta.invert(i);
3968
- this.stack[e].push({
3969
- delta: n,
3970
- range: St(s.range, n)
3971
- }), this.lastRecorded = 0, this.ignoreChange = !0, this.rich.updateContents(s.delta, u.sources.USER), this.ignoreChange = !1, this.restoreSelection(s);
3972
- }
3973
- clear() {
3974
- this.stack = { undo: [], redo: [] };
3975
- }
3976
- cutoff() {
3977
- this.lastRecorded = 0;
3978
- }
3979
- record(t, e) {
3980
- if (t.ops.length === 0) return;
3981
- this.stack.redo = [];
3982
- let s = t.invert(e), i = this.currentRange;
3983
- const n = Date.now();
3984
- if (this.lastRecorded + this.options.delay > n && this.stack.undo.length > 0) {
3985
- const o = this.stack.undo.pop();
3986
- o && (s = s.compose(o.delta), i = o.range);
3987
- } else
3988
- this.lastRecorded = n;
3989
- s.length() !== 0 && (this.stack.undo.push({ delta: s, range: i }), this.stack.undo.length > this.options.maxStack && this.stack.undo.shift());
3990
- }
3991
- redo() {
3992
- this.change("redo", "undo");
3993
- }
3994
- transform(t) {
3995
- te(this.stack.undo, t), te(this.stack.redo, t);
3996
- }
3997
- undo() {
3998
- this.change("undo", "redo");
3999
- }
4000
- restoreSelection(t) {
4001
- if (t.range)
4002
- this.rich.setSelection(t.range, u.sources.USER);
4003
- else {
4004
- const e = ks(this.rich.scroll, t.delta);
4005
- this.rich.setSelection(e, u.sources.USER);
4006
- }
4007
- }
4008
- }
4009
- function te(r, t) {
4010
- let e = t;
4011
- for (let s = r.length - 1; s >= 0; s -= 1) {
4012
- const i = r[s];
4013
- r[s] = {
4014
- delta: e.transform(i.delta, !0),
4015
- range: i.range && St(i.range, e)
4016
- }, e = i.delta.transform(e), r[s].delta.length() === 0 && r.splice(s, 1);
4017
- }
4018
- }
4019
- function Cs(r, t) {
4020
- const e = t.ops[t.ops.length - 1];
4021
- return e == null ? !1 : e.insert != null ? typeof e.insert == "string" && e.insert.endsWith(`
4022
- `) : e.attributes != null ? Object.keys(e.attributes).some((s) => r.query(s, p.BLOCK) != null) : !1;
4023
- }
4024
- function ks(r, t) {
4025
- const e = t.reduce((i, n) => i + (n.delete || 0), 0);
4026
- let s = t.length() - e;
4027
- return Cs(r, t) && (s -= 1), s;
4028
- }
4029
- function St(r, t) {
4030
- if (!r) return r;
4031
- const e = t.transformPosition(r.index), s = t.transformPosition(r.index + r.length);
4032
- return { index: e, length: s - e };
4033
- }
4034
- const Os = ["insertText", "insertReplacementText"];
4035
- class vs extends Y {
4036
- constructor(t, e) {
4037
- super(t, e), t.root.addEventListener("beforeinput", (s) => {
4038
- this.handleBeforeInput(s);
4039
- }), /Android/i.test(navigator.userAgent) || t.on(u.events.COMPOSITION_BEFORE_START, () => {
4040
- this.handleCompositionStart();
4041
- });
4042
- }
4043
- deleteRange(t) {
4044
- Ut({ range: t, rich: this.rich });
4045
- }
4046
- replaceText(t, e = "") {
4047
- if (t.length === 0) return !1;
4048
- if (e) {
4049
- const s = this.rich.getFormat(t.index, 1);
4050
- this.deleteRange(t), this.rich.updateContents(
4051
- new f().retain(t.index).insert(e, s),
4052
- u.sources.USER
4053
- );
4054
- } else
4055
- this.deleteRange(t);
4056
- return this.rich.setSelection(t.index + e.length, 0, u.sources.SILENT), !0;
4057
- }
4058
- handleBeforeInput(t) {
4059
- if (this.rich.composition.isComposing || t.defaultPrevented || !Os.includes(t.inputType))
4060
- return;
4061
- const e = t.getTargetRanges ? t.getTargetRanges()[0] : null;
4062
- if (!e || e.collapsed === !0)
4063
- return;
4064
- const s = xs(t);
4065
- if (s == null)
4066
- return;
4067
- const i = this.rich.selection.normalizeNative(e), n = i ? this.rich.selection.normalizedToRange(i) : null;
4068
- n && this.replaceText(n, s) && t.preventDefault();
4069
- }
4070
- handleCompositionStart() {
4071
- const t = this.rich.getSelection();
4072
- t && this.replaceText(t);
4073
- }
4074
- }
4075
- function xs(r) {
4076
- return typeof r.data == "string" ? r.data : r.dataTransfer?.types.includes("text/plain") ? r.dataTransfer.getData("text/plain") : null;
4077
- }
4078
- const Rs = fe, Ss = 100, Is = (r) => !!(r.key === "ArrowLeft" || r.key === "ArrowRight" || // RTL scripts or moving from the end of the previous line
4079
- r.key === "ArrowUp" || r.key === "ArrowDown" || r.key === "Home" || Rs && r.key === "a" && r.ctrlKey === !0);
4080
- class Bs extends Y {
4081
- constructor(t, e) {
4082
- super(t, e), this.isListening = !1, this.selectionChangeDeadline = 0, this.handleArrowKeys(), this.handleNavigationShortcuts();
4083
- }
4084
- handleArrowKeys() {
4085
- this.rich.keyboard.addBinding({
4086
- key: ["ArrowLeft", "ArrowRight"],
4087
- offset: 0,
4088
- shiftKey: null,
4089
- handler(t, { line: e, event: s }) {
4090
- if (!(e instanceof T) || !e.uiNode)
4091
- return !0;
4092
- const i = getComputedStyle(e.domNode).direction === "rtl";
4093
- return i && s.key !== "ArrowRight" || !i && s.key !== "ArrowLeft" ? !0 : (this.rich.setSelection(
4094
- t.index - 1,
4095
- t.length + (s.shiftKey ? 1 : 0),
4096
- u.sources.USER
4097
- ), !1);
4098
- }
4099
- });
4100
- }
4101
- handleNavigationShortcuts() {
4102
- this.rich.root.addEventListener("keydown", (t) => {
4103
- !t.defaultPrevented && Is(t) && this.ensureListeningToSelectionChange();
4104
- });
4105
- }
4106
- /**
4107
- * We only listen to the `selectionchange` event when
4108
- * there is an intention of moving the caret to the beginning using shortcuts.
4109
- * This is primarily implemented to prevent infinite loops, as we are changing
4110
- * the selection within the handler of a `selectionchange` event.
4111
- */
4112
- ensureListeningToSelectionChange() {
4113
- if (this.selectionChangeDeadline = Date.now() + Ss, this.isListening) return;
4114
- this.isListening = !0;
4115
- const t = () => {
4116
- this.isListening = !1, Date.now() <= this.selectionChangeDeadline && this.handleSelectionChange();
4117
- };
4118
- document.addEventListener("selectionchange", t, {
4119
- once: !0
4120
- });
4121
- }
4122
- handleSelectionChange() {
4123
- const t = document.getSelection();
4124
- if (!t) return;
4125
- const e = t.getRangeAt(0);
4126
- if (e.collapsed !== !0 || e.startOffset !== 0) return;
4127
- const s = this.rich.scroll.find(e.startContainer);
4128
- if (!(s instanceof T) || !s.uiNode) return;
4129
- const i = document.createRange();
4130
- i.setStartAfter(s.uiNode), i.setEndAfter(s.uiNode), t.removeAllRanges(), t.addRange(i);
4131
- }
4132
- }
4133
- class he extends Y {
4134
- constructor(t, e) {
4135
- super(t, e), t.root.addEventListener("drop", (s) => {
4136
- s.preventDefault();
4137
- let i = null;
4138
- if (document.caretRangeFromPoint)
4139
- i = document.caretRangeFromPoint(s.clientX, s.clientY);
4140
- else if (document.caretPositionFromPoint) {
4141
- const o = document.caretPositionFromPoint(s.clientX, s.clientY);
4142
- i = document.createRange(), i.setStart(o.offsetNode, o.offset), i.setEnd(o.offsetNode, o.offset);
4143
- }
4144
- const n = i && t.selection.normalizeNative(i);
4145
- if (n) {
4146
- const o = t.selection.normalizedToRange(n);
4147
- s.dataTransfer?.files && this.upload(o, s.dataTransfer.files);
4148
- }
4149
- });
4150
- }
4151
- upload(t, e) {
4152
- const s = [];
4153
- Array.from(e).forEach((i) => {
4154
- i && this.options.mimetypes?.includes(i.type) && s.push(i);
4155
- }), s.length > 0 && this.options.handler.call(this, t, s);
4156
- }
4157
- }
4158
- he.DEFAULTS = {
4159
- mimetypes: ["image/png", "image/jpeg"],
4160
- handler(r, t) {
4161
- if (!this.rich.scroll.query("image"))
4162
- return;
4163
- const e = t.map((s) => new Promise((i) => {
4164
- const n = new FileReader();
4165
- n.onload = () => {
4166
- i(n.result);
4167
- }, n.readAsDataURL(s);
4168
- }));
4169
- Promise.all(e).then((s) => {
4170
- const i = s.reduce((n, o) => n.insert({ image: o }), new f().retain(r.index).delete(r.length));
4171
- this.rich.updateContents(i, m.sources.USER), this.rich.setSelection(
4172
- r.index + s.length,
4173
- m.sources.SILENT
4174
- );
4175
- });
4176
- }
4177
- };
4178
- u.register({
4179
- "blots/block": O,
4180
- "blots/block/embed": I,
4181
- "blots/break": F,
4182
- "blots/container": Bt,
4183
- "blots/cursor": U,
4184
- "blots/embed": ie,
4185
- "blots/inline": M,
4186
- "blots/scroll": Me,
4187
- "blots/text": $,
4188
- "modules/clipboard": fs,
4189
- "modules/history": ws,
4190
- "modules/keyboard": gt,
4191
- "modules/uploader": he,
4192
- "modules/input": vs,
4193
- "modules/uiNode": Bs
4194
- });
4195
- export {
4196
- C as A,
4197
- O as B,
4198
- q as C,
4199
- f as D,
4200
- ie as E,
4201
- Ke as F,
4202
- Pe as G,
4203
- oe as H,
4204
- R as I,
4205
- Y as M,
4206
- k as O,
4207
- Ne as P,
4208
- u as R,
4209
- p as S,
4210
- $ as T,
4211
- rt as a,
4212
- Bt as b,
4213
- M as c,
4214
- B as d,
4215
- I as e,
4216
- U as f,
4217
- F as g,
4218
- z as h,
4219
- st as i,
4220
- Le as j,
4221
- se as k,
4222
- mt as l,
4223
- m,
4224
- G as n,
4225
- qe as o,
4226
- _e as p,
4227
- $e as q,
4228
- Fe as r,
4229
- je as s,
4230
- ce as t,
4231
- Vs as u,
4232
- Ws as v,
4233
- Hs as w,
4234
- Ks as x,
4235
- qs as y,
4236
- zs as z
4237
- };