@react-fabric/lexical 1.0.0-beta.60 → 1.0.0-beta.62

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 (450) hide show
  1. package/css/_lexical.css +61 -0
  2. package/dist/cjs/node_modules/date-fns/_lib/addLeadingZeros.js +9 -0
  3. package/dist/cjs/node_modules/date-fns/_lib/defaultOptions.js +9 -0
  4. package/dist/cjs/node_modules/date-fns/_lib/format/formatters.js +779 -0
  5. package/dist/cjs/node_modules/date-fns/_lib/format/lightFormatters.js +96 -0
  6. package/dist/cjs/node_modules/date-fns/_lib/format/longFormatters.js +68 -0
  7. package/dist/cjs/node_modules/date-fns/_lib/getRoundingMethod.js +12 -0
  8. package/dist/cjs/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +33 -0
  9. package/dist/cjs/node_modules/date-fns/_lib/normalizeDates.js +13 -0
  10. package/dist/cjs/node_modules/date-fns/_lib/normalizeInterval.js +10 -0
  11. package/dist/cjs/node_modules/date-fns/_lib/protectedTokens.js +29 -0
  12. package/dist/cjs/node_modules/date-fns/add.js +73 -0
  13. package/dist/cjs/node_modules/date-fns/addDays.js +46 -0
  14. package/dist/cjs/node_modules/date-fns/addHours.js +39 -0
  15. package/dist/cjs/node_modules/date-fns/addMilliseconds.js +39 -0
  16. package/dist/cjs/node_modules/date-fns/addMinutes.js +41 -0
  17. package/dist/cjs/node_modules/date-fns/addMonths.js +80 -0
  18. package/dist/cjs/node_modules/date-fns/addQuarters.js +38 -0
  19. package/dist/cjs/node_modules/date-fns/addWeeks.js +38 -0
  20. package/dist/cjs/node_modules/date-fns/addYears.js +38 -0
  21. package/dist/cjs/node_modules/date-fns/compareAsc.js +50 -0
  22. package/dist/cjs/node_modules/date-fns/constants.js +66 -0
  23. package/dist/cjs/node_modules/date-fns/constructFrom.js +54 -0
  24. package/dist/cjs/node_modules/date-fns/differenceInCalendarDays.js +67 -0
  25. package/dist/cjs/node_modules/date-fns/differenceInCalendarMonths.js +47 -0
  26. package/dist/cjs/node_modules/date-fns/differenceInCalendarYears.js +43 -0
  27. package/dist/cjs/node_modules/date-fns/differenceInDays.js +112 -0
  28. package/dist/cjs/node_modules/date-fns/differenceInHours.js +46 -0
  29. package/dist/cjs/node_modules/date-fns/differenceInMilliseconds.js +34 -0
  30. package/dist/cjs/node_modules/date-fns/differenceInMinutes.js +50 -0
  31. package/dist/cjs/node_modules/date-fns/differenceInMonths.js +65 -0
  32. package/dist/cjs/node_modules/date-fns/differenceInSeconds.js +41 -0
  33. package/dist/cjs/node_modules/date-fns/differenceInYears.js +67 -0
  34. package/dist/cjs/node_modules/date-fns/endOfDay.js +40 -0
  35. package/dist/cjs/node_modules/date-fns/endOfDecade.js +45 -0
  36. package/dist/cjs/node_modules/date-fns/endOfHour.js +40 -0
  37. package/dist/cjs/node_modules/date-fns/endOfMinute.js +40 -0
  38. package/dist/cjs/node_modules/date-fns/endOfMonth.js +42 -0
  39. package/dist/cjs/node_modules/date-fns/endOfQuarter.js +43 -0
  40. package/dist/cjs/node_modules/date-fns/endOfWeek.js +58 -0
  41. package/dist/cjs/node_modules/date-fns/endOfYear.js +42 -0
  42. package/dist/cjs/node_modules/date-fns/format.js +431 -0
  43. package/dist/cjs/node_modules/date-fns/getDayOfYear.js +39 -0
  44. package/dist/cjs/node_modules/date-fns/getISOWeek.js +45 -0
  45. package/dist/cjs/node_modules/date-fns/getISOWeekYear.js +57 -0
  46. package/dist/cjs/node_modules/date-fns/getWeek.js +59 -0
  47. package/dist/cjs/node_modules/date-fns/getWeekYear.js +80 -0
  48. package/dist/cjs/node_modules/date-fns/intervalToDuration.js +70 -0
  49. package/dist/cjs/node_modules/date-fns/isAfter.js +30 -0
  50. package/dist/cjs/node_modules/date-fns/isBefore.js +30 -0
  51. package/dist/cjs/node_modules/date-fns/isDate.js +46 -0
  52. package/dist/cjs/node_modules/date-fns/isLastDayOfMonth.js +33 -0
  53. package/dist/cjs/node_modules/date-fns/isSameMonth.js +48 -0
  54. package/dist/cjs/node_modules/date-fns/isSameWeek.js +56 -0
  55. package/dist/cjs/node_modules/date-fns/isSameYear.js +40 -0
  56. package/dist/cjs/node_modules/date-fns/isValid.js +44 -0
  57. package/dist/cjs/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +12 -0
  58. package/dist/cjs/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +66 -0
  59. package/dist/cjs/node_modules/date-fns/locale/_lib/buildMatchFn.js +61 -0
  60. package/dist/cjs/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +24 -0
  61. package/dist/cjs/node_modules/date-fns/locale/ar-SA/_lib/formatDistance.js +139 -0
  62. package/dist/cjs/node_modules/date-fns/locale/ar-SA/_lib/formatLong.js +43 -0
  63. package/dist/cjs/node_modules/date-fns/locale/ar-SA/_lib/formatRelative.js +15 -0
  64. package/dist/cjs/node_modules/date-fns/locale/ar-SA/_lib/localize.js +166 -0
  65. package/dist/cjs/node_modules/date-fns/locale/ar-SA/_lib/match.js +146 -0
  66. package/dist/cjs/node_modules/date-fns/locale/ar-SA.js +32 -0
  67. package/dist/cjs/node_modules/date-fns/locale/de/_lib/formatDistance.js +200 -0
  68. package/dist/cjs/node_modules/date-fns/locale/de/_lib/formatLong.js +44 -0
  69. package/dist/cjs/node_modules/date-fns/locale/de/_lib/formatRelative.js +15 -0
  70. package/dist/cjs/node_modules/date-fns/locale/de/_lib/localize.js +195 -0
  71. package/dist/cjs/node_modules/date-fns/locale/de/_lib/match.js +138 -0
  72. package/dist/cjs/node_modules/date-fns/locale/de.js +36 -0
  73. package/dist/cjs/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +105 -0
  74. package/dist/cjs/node_modules/date-fns/locale/en-US/_lib/formatLong.js +43 -0
  75. package/dist/cjs/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +15 -0
  76. package/dist/cjs/node_modules/date-fns/locale/en-US/_lib/localize.js +191 -0
  77. package/dist/cjs/node_modules/date-fns/locale/en-US/_lib/match.js +136 -0
  78. package/dist/cjs/node_modules/date-fns/locale/en-US.js +33 -0
  79. package/dist/cjs/node_modules/date-fns/locale/es/_lib/formatDistance.js +105 -0
  80. package/dist/cjs/node_modules/date-fns/locale/es/_lib/formatLong.js +43 -0
  81. package/dist/cjs/node_modules/date-fns/locale/es/_lib/formatRelative.js +29 -0
  82. package/dist/cjs/node_modules/date-fns/locale/es/_lib/localize.js +168 -0
  83. package/dist/cjs/node_modules/date-fns/locale/es/_lib/match.js +142 -0
  84. package/dist/cjs/node_modules/date-fns/locale/es.js +36 -0
  85. package/dist/cjs/node_modules/date-fns/locale/fr/_lib/formatDistance.js +104 -0
  86. package/dist/cjs/node_modules/date-fns/locale/fr/_lib/formatLong.js +43 -0
  87. package/dist/cjs/node_modules/date-fns/locale/fr/_lib/formatRelative.js +15 -0
  88. package/dist/cjs/node_modules/date-fns/locale/fr/_lib/localize.js +169 -0
  89. package/dist/cjs/node_modules/date-fns/locale/fr/_lib/match.js +137 -0
  90. package/dist/cjs/node_modules/date-fns/locale/fr.js +33 -0
  91. package/dist/cjs/node_modules/date-fns/locale/hi/_lib/formatDistance.js +109 -0
  92. package/dist/cjs/node_modules/date-fns/locale/hi/_lib/formatLong.js +43 -0
  93. package/dist/cjs/node_modules/date-fns/locale/hi/_lib/formatRelative.js +15 -0
  94. package/dist/cjs/node_modules/date-fns/locale/hi/_lib/localize.js +233 -0
  95. package/dist/cjs/node_modules/date-fns/locale/hi/_lib/match.js +141 -0
  96. package/dist/cjs/node_modules/date-fns/locale/hi.js +32 -0
  97. package/dist/cjs/node_modules/date-fns/locale/it/_lib/formatDistance.js +105 -0
  98. package/dist/cjs/node_modules/date-fns/locale/it/_lib/formatLong.js +43 -0
  99. package/dist/cjs/node_modules/date-fns/locale/it/_lib/formatRelative.js +70 -0
  100. package/dist/cjs/node_modules/date-fns/locale/it/_lib/localize.js +168 -0
  101. package/dist/cjs/node_modules/date-fns/locale/it/_lib/match.js +137 -0
  102. package/dist/cjs/node_modules/date-fns/locale/it.js +34 -0
  103. package/dist/cjs/node_modules/date-fns/locale/ja/_lib/formatDistance.js +119 -0
  104. package/dist/cjs/node_modules/date-fns/locale/ja/_lib/formatLong.js +43 -0
  105. package/dist/cjs/node_modules/date-fns/locale/ja/_lib/formatRelative.js +16 -0
  106. package/dist/cjs/node_modules/date-fns/locale/ja/_lib/localize.js +181 -0
  107. package/dist/cjs/node_modules/date-fns/locale/ja/_lib/match.js +122 -0
  108. package/dist/cjs/node_modules/date-fns/locale/ja.js +36 -0
  109. package/dist/cjs/node_modules/date-fns/locale/ko/_lib/formatDistance.js +105 -0
  110. package/dist/cjs/node_modules/date-fns/locale/ko/_lib/formatLong.js +43 -0
  111. package/dist/cjs/node_modules/date-fns/locale/ko/_lib/formatRelative.js +15 -0
  112. package/dist/cjs/node_modules/date-fns/locale/ko/_lib/localize.js +171 -0
  113. package/dist/cjs/node_modules/date-fns/locale/ko/_lib/match.js +119 -0
  114. package/dist/cjs/node_modules/date-fns/locale/ko.js +34 -0
  115. package/dist/cjs/node_modules/date-fns/locale/pt/_lib/formatDistance.js +105 -0
  116. package/dist/cjs/node_modules/date-fns/locale/pt/_lib/formatLong.js +43 -0
  117. package/dist/cjs/node_modules/date-fns/locale/pt/_lib/formatRelative.js +26 -0
  118. package/dist/cjs/node_modules/date-fns/locale/pt/_lib/localize.js +168 -0
  119. package/dist/cjs/node_modules/date-fns/locale/pt/_lib/match.js +141 -0
  120. package/dist/cjs/node_modules/date-fns/locale/pt.js +33 -0
  121. package/dist/cjs/node_modules/date-fns/locale/ru/_lib/formatDistance.js +250 -0
  122. package/dist/cjs/node_modules/date-fns/locale/ru/_lib/formatLong.js +40 -0
  123. package/dist/cjs/node_modules/date-fns/locale/ru/_lib/formatRelative.js +92 -0
  124. package/dist/cjs/node_modules/date-fns/locale/ru/_lib/localize.js +214 -0
  125. package/dist/cjs/node_modules/date-fns/locale/ru/_lib/match.js +142 -0
  126. package/dist/cjs/node_modules/date-fns/locale/ru.js +33 -0
  127. package/dist/cjs/node_modules/date-fns/locale/zh-CN/_lib/formatDistance.js +105 -0
  128. package/dist/cjs/node_modules/date-fns/locale/zh-CN/_lib/formatLong.js +43 -0
  129. package/dist/cjs/node_modules/date-fns/locale/zh-CN/_lib/formatRelative.js +35 -0
  130. package/dist/cjs/node_modules/date-fns/locale/zh-CN/_lib/localize.js +187 -0
  131. package/dist/cjs/node_modules/date-fns/locale/zh-CN/_lib/match.js +134 -0
  132. package/dist/cjs/node_modules/date-fns/locale/zh-CN.js +36 -0
  133. package/dist/cjs/node_modules/date-fns/startOfDay.js +40 -0
  134. package/dist/cjs/node_modules/date-fns/startOfDecade.js +45 -0
  135. package/dist/cjs/node_modules/date-fns/startOfHour.js +40 -0
  136. package/dist/cjs/node_modules/date-fns/startOfISOWeek.js +40 -0
  137. package/dist/cjs/node_modules/date-fns/startOfISOWeekYear.js +47 -0
  138. package/dist/cjs/node_modules/date-fns/startOfMinute.js +40 -0
  139. package/dist/cjs/node_modules/date-fns/startOfMonth.js +42 -0
  140. package/dist/cjs/node_modules/date-fns/startOfQuarter.js +43 -0
  141. package/dist/cjs/node_modules/date-fns/startOfWeek.js +58 -0
  142. package/dist/cjs/node_modules/date-fns/startOfWeekYear.js +69 -0
  143. package/dist/cjs/node_modules/date-fns/startOfYear.js +41 -0
  144. package/dist/cjs/node_modules/date-fns/toDate.js +51 -0
  145. package/dist/cjs/packages/date/dist/esm/display/DateDuration.js +178 -0
  146. package/dist/cjs/packages/date/dist/esm/hijri/DateConverter.js +154 -0
  147. package/dist/cjs/packages/date/dist/esm/hijri/FormatDate.js +116 -0
  148. package/dist/cjs/packages/date/dist/esm/hijri/HijriDate.js +531 -0
  149. package/dist/cjs/packages/date/dist/esm/hijri/StringDateParser.js +74 -0
  150. package/dist/cjs/packages/date/dist/esm/hijri/index.js +21 -0
  151. package/dist/cjs/packages/date/dist/esm/hijri/initializer.js +113 -0
  152. package/dist/cjs/packages/date/dist/esm/hijri/locales.js +19 -0
  153. package/dist/cjs/packages/date/dist/esm/hijri/safe.js +17 -0
  154. package/dist/cjs/packages/date/dist/esm/i18n/ar/date.json.js +213 -0
  155. package/dist/cjs/packages/date/dist/esm/i18n/en/date.json.js +83 -0
  156. package/{src/plugins/StickyPlugin.ts → dist/cjs/packages/date/dist/esm/i18n/index.js} +10 -15
  157. package/dist/cjs/packages/date/dist/esm/types/index.js +46 -0
  158. package/dist/cjs/packages/date/dist/esm/utils/dateUtil.js +472 -0
  159. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +36 -13
  160. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +101 -95
  161. package/dist/cjs/packages/lexical/src/i18n/ar/lexical.json.js +30 -0
  162. package/dist/cjs/packages/lexical/src/i18n/en/lexical.json.js +30 -0
  163. package/dist/cjs/packages/lexical/src/i18n/index.js +33 -0
  164. package/dist/cjs/packages/lexical/src/index.js +1 -0
  165. package/dist/cjs/packages/lexical/src/plugins/CommentPlugin.js +477 -0
  166. package/dist/cjs/packages/lexical/src/plugins/DraggableBlockPlugin.js +13 -16
  167. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +35 -22
  168. package/dist/esm/node_modules/date-fns/_lib/addLeadingZeros.js +9 -0
  169. package/dist/esm/node_modules/date-fns/_lib/defaultOptions.js +9 -0
  170. package/dist/esm/node_modules/date-fns/_lib/format/formatters.js +779 -0
  171. package/dist/esm/node_modules/date-fns/_lib/format/lightFormatters.js +96 -0
  172. package/dist/esm/node_modules/date-fns/_lib/format/longFormatters.js +68 -0
  173. package/dist/esm/node_modules/date-fns/_lib/getRoundingMethod.js +12 -0
  174. package/dist/esm/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +33 -0
  175. package/dist/esm/node_modules/date-fns/_lib/normalizeDates.js +13 -0
  176. package/dist/esm/node_modules/date-fns/_lib/normalizeInterval.js +10 -0
  177. package/dist/esm/node_modules/date-fns/_lib/protectedTokens.js +27 -0
  178. package/dist/esm/node_modules/date-fns/add.js +70 -0
  179. package/dist/esm/node_modules/date-fns/addDays.js +43 -0
  180. package/dist/esm/node_modules/date-fns/addHours.js +36 -0
  181. package/dist/esm/node_modules/date-fns/addMilliseconds.js +36 -0
  182. package/dist/esm/node_modules/date-fns/addMinutes.js +38 -0
  183. package/dist/esm/node_modules/date-fns/addMonths.js +77 -0
  184. package/dist/esm/node_modules/date-fns/addQuarters.js +35 -0
  185. package/dist/esm/node_modules/date-fns/addWeeks.js +35 -0
  186. package/dist/esm/node_modules/date-fns/addYears.js +35 -0
  187. package/dist/esm/node_modules/date-fns/compareAsc.js +47 -0
  188. package/dist/esm/node_modules/date-fns/constants.js +62 -0
  189. package/dist/esm/node_modules/date-fns/constructFrom.js +51 -0
  190. package/dist/esm/node_modules/date-fns/differenceInCalendarDays.js +64 -0
  191. package/dist/esm/node_modules/date-fns/differenceInCalendarMonths.js +44 -0
  192. package/dist/esm/node_modules/date-fns/differenceInCalendarYears.js +40 -0
  193. package/dist/esm/node_modules/date-fns/differenceInDays.js +109 -0
  194. package/dist/esm/node_modules/date-fns/differenceInHours.js +43 -0
  195. package/dist/esm/node_modules/date-fns/differenceInMilliseconds.js +31 -0
  196. package/dist/esm/node_modules/date-fns/differenceInMinutes.js +47 -0
  197. package/dist/esm/node_modules/date-fns/differenceInMonths.js +62 -0
  198. package/dist/esm/node_modules/date-fns/differenceInSeconds.js +38 -0
  199. package/dist/esm/node_modules/date-fns/differenceInYears.js +64 -0
  200. package/dist/esm/node_modules/date-fns/endOfDay.js +37 -0
  201. package/dist/esm/node_modules/date-fns/endOfDecade.js +42 -0
  202. package/dist/esm/node_modules/date-fns/endOfHour.js +37 -0
  203. package/dist/esm/node_modules/date-fns/endOfMinute.js +37 -0
  204. package/dist/esm/node_modules/date-fns/endOfMonth.js +39 -0
  205. package/dist/esm/node_modules/date-fns/endOfQuarter.js +40 -0
  206. package/dist/esm/node_modules/date-fns/endOfWeek.js +55 -0
  207. package/dist/esm/node_modules/date-fns/endOfYear.js +39 -0
  208. package/dist/esm/node_modules/date-fns/format.js +425 -0
  209. package/dist/esm/node_modules/date-fns/getDayOfYear.js +36 -0
  210. package/dist/esm/node_modules/date-fns/getISOWeek.js +42 -0
  211. package/dist/esm/node_modules/date-fns/getISOWeekYear.js +54 -0
  212. package/dist/esm/node_modules/date-fns/getWeek.js +56 -0
  213. package/dist/esm/node_modules/date-fns/getWeekYear.js +77 -0
  214. package/dist/esm/node_modules/date-fns/intervalToDuration.js +67 -0
  215. package/dist/esm/node_modules/date-fns/isAfter.js +27 -0
  216. package/dist/esm/node_modules/date-fns/isBefore.js +27 -0
  217. package/dist/esm/node_modules/date-fns/isDate.js +43 -0
  218. package/dist/esm/node_modules/date-fns/isLastDayOfMonth.js +30 -0
  219. package/dist/esm/node_modules/date-fns/isSameMonth.js +45 -0
  220. package/dist/esm/node_modules/date-fns/isSameWeek.js +53 -0
  221. package/dist/esm/node_modules/date-fns/isSameYear.js +37 -0
  222. package/dist/esm/node_modules/date-fns/isValid.js +41 -0
  223. package/dist/esm/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +12 -0
  224. package/dist/esm/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +66 -0
  225. package/dist/esm/node_modules/date-fns/locale/_lib/buildMatchFn.js +61 -0
  226. package/dist/esm/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +24 -0
  227. package/dist/esm/node_modules/date-fns/locale/ar-SA/_lib/formatDistance.js +139 -0
  228. package/dist/esm/node_modules/date-fns/locale/ar-SA/_lib/formatLong.js +43 -0
  229. package/dist/esm/node_modules/date-fns/locale/ar-SA/_lib/formatRelative.js +15 -0
  230. package/dist/esm/node_modules/date-fns/locale/ar-SA/_lib/localize.js +166 -0
  231. package/dist/esm/node_modules/date-fns/locale/ar-SA/_lib/match.js +146 -0
  232. package/dist/esm/node_modules/date-fns/locale/ar-SA.js +29 -0
  233. package/dist/esm/node_modules/date-fns/locale/de/_lib/formatDistance.js +200 -0
  234. package/dist/esm/node_modules/date-fns/locale/de/_lib/formatLong.js +44 -0
  235. package/dist/esm/node_modules/date-fns/locale/de/_lib/formatRelative.js +15 -0
  236. package/dist/esm/node_modules/date-fns/locale/de/_lib/localize.js +195 -0
  237. package/dist/esm/node_modules/date-fns/locale/de/_lib/match.js +138 -0
  238. package/dist/esm/node_modules/date-fns/locale/de.js +33 -0
  239. package/dist/esm/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +105 -0
  240. package/dist/esm/node_modules/date-fns/locale/en-US/_lib/formatLong.js +43 -0
  241. package/dist/esm/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +15 -0
  242. package/dist/esm/node_modules/date-fns/locale/en-US/_lib/localize.js +191 -0
  243. package/dist/esm/node_modules/date-fns/locale/en-US/_lib/match.js +136 -0
  244. package/dist/esm/node_modules/date-fns/locale/en-US.js +30 -0
  245. package/dist/esm/node_modules/date-fns/locale/es/_lib/formatDistance.js +105 -0
  246. package/dist/esm/node_modules/date-fns/locale/es/_lib/formatLong.js +43 -0
  247. package/dist/esm/node_modules/date-fns/locale/es/_lib/formatRelative.js +29 -0
  248. package/dist/esm/node_modules/date-fns/locale/es/_lib/localize.js +168 -0
  249. package/dist/esm/node_modules/date-fns/locale/es/_lib/match.js +142 -0
  250. package/dist/esm/node_modules/date-fns/locale/es.js +33 -0
  251. package/dist/esm/node_modules/date-fns/locale/fr/_lib/formatDistance.js +104 -0
  252. package/dist/esm/node_modules/date-fns/locale/fr/_lib/formatLong.js +43 -0
  253. package/dist/esm/node_modules/date-fns/locale/fr/_lib/formatRelative.js +15 -0
  254. package/dist/esm/node_modules/date-fns/locale/fr/_lib/localize.js +169 -0
  255. package/dist/esm/node_modules/date-fns/locale/fr/_lib/match.js +137 -0
  256. package/dist/esm/node_modules/date-fns/locale/fr.js +30 -0
  257. package/dist/esm/node_modules/date-fns/locale/hi/_lib/formatDistance.js +109 -0
  258. package/dist/esm/node_modules/date-fns/locale/hi/_lib/formatLong.js +43 -0
  259. package/dist/esm/node_modules/date-fns/locale/hi/_lib/formatRelative.js +15 -0
  260. package/dist/esm/node_modules/date-fns/locale/hi/_lib/localize.js +231 -0
  261. package/dist/esm/node_modules/date-fns/locale/hi/_lib/match.js +141 -0
  262. package/dist/esm/node_modules/date-fns/locale/hi.js +29 -0
  263. package/dist/esm/node_modules/date-fns/locale/it/_lib/formatDistance.js +105 -0
  264. package/dist/esm/node_modules/date-fns/locale/it/_lib/formatLong.js +43 -0
  265. package/dist/esm/node_modules/date-fns/locale/it/_lib/formatRelative.js +70 -0
  266. package/dist/esm/node_modules/date-fns/locale/it/_lib/localize.js +168 -0
  267. package/dist/esm/node_modules/date-fns/locale/it/_lib/match.js +137 -0
  268. package/dist/esm/node_modules/date-fns/locale/it.js +31 -0
  269. package/dist/esm/node_modules/date-fns/locale/ja/_lib/formatDistance.js +119 -0
  270. package/dist/esm/node_modules/date-fns/locale/ja/_lib/formatLong.js +43 -0
  271. package/dist/esm/node_modules/date-fns/locale/ja/_lib/formatRelative.js +16 -0
  272. package/dist/esm/node_modules/date-fns/locale/ja/_lib/localize.js +181 -0
  273. package/dist/esm/node_modules/date-fns/locale/ja/_lib/match.js +122 -0
  274. package/dist/esm/node_modules/date-fns/locale/ja.js +33 -0
  275. package/dist/esm/node_modules/date-fns/locale/ko/_lib/formatDistance.js +105 -0
  276. package/dist/esm/node_modules/date-fns/locale/ko/_lib/formatLong.js +43 -0
  277. package/dist/esm/node_modules/date-fns/locale/ko/_lib/formatRelative.js +15 -0
  278. package/dist/esm/node_modules/date-fns/locale/ko/_lib/localize.js +171 -0
  279. package/dist/esm/node_modules/date-fns/locale/ko/_lib/match.js +119 -0
  280. package/dist/esm/node_modules/date-fns/locale/ko.js +31 -0
  281. package/dist/esm/node_modules/date-fns/locale/pt/_lib/formatDistance.js +105 -0
  282. package/dist/esm/node_modules/date-fns/locale/pt/_lib/formatLong.js +43 -0
  283. package/dist/esm/node_modules/date-fns/locale/pt/_lib/formatRelative.js +26 -0
  284. package/dist/esm/node_modules/date-fns/locale/pt/_lib/localize.js +168 -0
  285. package/dist/esm/node_modules/date-fns/locale/pt/_lib/match.js +141 -0
  286. package/dist/esm/node_modules/date-fns/locale/pt.js +30 -0
  287. package/dist/esm/node_modules/date-fns/locale/ru/_lib/formatDistance.js +250 -0
  288. package/dist/esm/node_modules/date-fns/locale/ru/_lib/formatLong.js +40 -0
  289. package/dist/esm/node_modules/date-fns/locale/ru/_lib/formatRelative.js +92 -0
  290. package/dist/esm/node_modules/date-fns/locale/ru/_lib/localize.js +214 -0
  291. package/dist/esm/node_modules/date-fns/locale/ru/_lib/match.js +142 -0
  292. package/dist/esm/node_modules/date-fns/locale/ru.js +30 -0
  293. package/dist/esm/node_modules/date-fns/locale/zh-CN/_lib/formatDistance.js +105 -0
  294. package/dist/esm/node_modules/date-fns/locale/zh-CN/_lib/formatLong.js +43 -0
  295. package/dist/esm/node_modules/date-fns/locale/zh-CN/_lib/formatRelative.js +35 -0
  296. package/dist/esm/node_modules/date-fns/locale/zh-CN/_lib/localize.js +187 -0
  297. package/dist/esm/node_modules/date-fns/locale/zh-CN/_lib/match.js +134 -0
  298. package/dist/esm/node_modules/date-fns/locale/zh-CN.js +33 -0
  299. package/dist/esm/node_modules/date-fns/startOfDay.js +37 -0
  300. package/dist/esm/node_modules/date-fns/startOfDecade.js +42 -0
  301. package/dist/esm/node_modules/date-fns/startOfHour.js +37 -0
  302. package/dist/esm/node_modules/date-fns/startOfISOWeek.js +37 -0
  303. package/dist/esm/node_modules/date-fns/startOfISOWeekYear.js +44 -0
  304. package/dist/esm/node_modules/date-fns/startOfMinute.js +37 -0
  305. package/dist/esm/node_modules/date-fns/startOfMonth.js +39 -0
  306. package/dist/esm/node_modules/date-fns/startOfQuarter.js +40 -0
  307. package/dist/esm/node_modules/date-fns/startOfWeek.js +55 -0
  308. package/dist/esm/node_modules/date-fns/startOfWeekYear.js +66 -0
  309. package/dist/esm/node_modules/date-fns/startOfYear.js +38 -0
  310. package/dist/esm/node_modules/date-fns/toDate.js +48 -0
  311. package/dist/esm/packages/date/dist/esm/display/DateDuration.js +178 -0
  312. package/dist/esm/packages/date/dist/esm/hijri/DateConverter.js +152 -0
  313. package/dist/esm/packages/date/dist/esm/hijri/FormatDate.js +113 -0
  314. package/dist/esm/packages/date/dist/esm/hijri/HijriDate.js +528 -0
  315. package/dist/esm/packages/date/dist/esm/hijri/StringDateParser.js +74 -0
  316. package/dist/esm/packages/date/dist/esm/hijri/index.js +21 -0
  317. package/dist/esm/packages/date/dist/esm/hijri/initializer.js +113 -0
  318. package/dist/esm/packages/date/dist/esm/hijri/locales.js +18 -0
  319. package/dist/esm/packages/date/dist/esm/hijri/safe.js +14 -0
  320. package/dist/esm/packages/date/dist/esm/i18n/ar/date.json.js +209 -0
  321. package/dist/esm/packages/date/dist/esm/i18n/en/date.json.js +79 -0
  322. package/dist/esm/packages/date/dist/esm/i18n/index.js +33 -0
  323. package/dist/esm/packages/date/dist/esm/types/index.js +45 -0
  324. package/dist/esm/packages/date/dist/esm/utils/dateUtil.js +474 -0
  325. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +37 -14
  326. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +43 -37
  327. package/dist/esm/packages/lexical/src/i18n/ar/lexical.json.js +25 -0
  328. package/dist/esm/packages/lexical/src/i18n/en/lexical.json.js +25 -0
  329. package/dist/esm/packages/lexical/src/i18n/index.js +33 -0
  330. package/dist/esm/packages/lexical/src/index.js +1 -0
  331. package/dist/esm/packages/lexical/src/plugins/CommentPlugin.js +477 -0
  332. package/dist/esm/packages/lexical/src/plugins/DraggableBlockPlugin.js +11 -14
  333. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +36 -23
  334. package/dist/types/editor/LexicalEditor.d.ts +12 -3
  335. package/dist/types/hooks/useFormatWatcher.d.ts +2 -1
  336. package/dist/types/i18n/index.d.ts +1 -0
  337. package/dist/types/index.d.ts +1 -0
  338. package/dist/types/plugins/CommentPlugin.d.ts +5 -0
  339. package/dist/types/plugins/DraggableBlockPlugin.d.ts +2 -1
  340. package/package.json +5 -5
  341. package/src/editor/LexicalEditor.tsx +65 -18
  342. package/src/hooks/useFormatWatcher.ts +3 -0
  343. package/src/i18n/ar/lexical.json +18 -0
  344. package/src/i18n/en/lexical.json +18 -0
  345. package/src/i18n/index.ts +28 -0
  346. package/src/index.ts +2 -0
  347. package/src/plugins/CommentPlugin.tsx +554 -0
  348. package/src/plugins/DraggableBlockPlugin.tsx +5 -10
  349. package/src/plugins/ToolbarPlugin.tsx +34 -23
  350. package/dist/cjs/_virtual/prism.js +0 -5
  351. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -474
  352. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
  353. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
  354. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1537
  355. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
  356. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -57
  357. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -252
  358. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
  359. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
  360. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -572
  361. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
  362. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -25
  363. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1614
  364. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
  365. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -36
  366. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -838
  367. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
  368. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
  369. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1057
  370. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -39
  371. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -45
  372. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -4207
  373. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
  374. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -68
  375. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1166
  376. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -47
  377. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -81
  378. package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
  379. package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
  380. package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
  381. package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
  382. package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
  383. package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
  384. package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
  385. package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
  386. package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
  387. package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
  388. package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
  389. package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
  390. package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
  391. package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
  392. package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
  393. package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
  394. package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
  395. package/dist/cjs/packages/lexical/src/components/StickyComponent.js +0 -221
  396. package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +0 -218
  397. package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +0 -20
  398. package/dist/esm/_virtual/prism.js +0 -5
  399. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -465
  400. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
  401. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
  402. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1512
  403. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
  404. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
  405. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -251
  406. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
  407. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
  408. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -563
  409. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
  410. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
  411. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1595
  412. package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
  413. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -17
  414. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -830
  415. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
  416. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
  417. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1028
  418. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -28
  419. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
  420. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -4156
  421. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
  422. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
  423. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1102
  424. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -32
  425. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
  426. package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
  427. package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
  428. package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
  429. package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
  430. package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
  431. package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
  432. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
  433. package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
  434. package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
  435. package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
  436. package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
  437. package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
  438. package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
  439. package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
  440. package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
  441. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
  442. package/dist/esm/node_modules/prismjs/prism.js +0 -1951
  443. package/dist/esm/packages/lexical/src/components/StickyComponent.js +0 -221
  444. package/dist/esm/packages/lexical/src/nodes/StickyNode.js +0 -216
  445. package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +0 -20
  446. package/dist/types/components/StickyComponent.d.ts +0 -9
  447. package/dist/types/nodes/StickyNode.d.ts +0 -34
  448. package/dist/types/plugins/StickyPlugin.d.ts +0 -1
  449. package/src/components/StickyComponent.tsx +0 -271
  450. package/src/nodes/StickyNode.tsx +0 -249
@@ -1,1102 +0,0 @@
1
- 'use client';
2
-
3
- import { $getRoot, $isElementNode, $getChildCaret, $getSiblingCaret, $getAdjacentChildCaret, $getChildCaretOrSelf, makeStepwiseIterator, $isChildCaret, $cloneWithProperties, $setSelection, $getSelection, $getPreviousSelection, $isRangeSelection, $caretFromPoint, $createParagraphNode, $normalizeCaret, $setSelectionFromCaretRange, $getCollapsedCaretRange, $getCaretInDirection, $splitAtPointCaretNext, $isTextPointCaret, $isSiblingCaret, $rewindSiblingCaret, isHTMLElement, $getState, $setState, getDOMTextNode } from 'lexical';
4
- export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode } from 'lexical';
5
- import { createRectsFromDOMRange } from '../selection/LexicalSelection.js';
6
-
7
- /**
8
- * Copyright (c) Meta Platforms, Inc. and affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- */
14
-
15
-
16
- /**
17
- * Copyright (c) Meta Platforms, Inc. and affiliates.
18
- *
19
- * This source code is licensed under the MIT license found in the
20
- * LICENSE file in the root directory of this source tree.
21
- *
22
- */
23
-
24
- // Do not require this module directly! Use normal `invariant` calls.
25
-
26
- function formatDevErrorMessage(message) {
27
- throw new Error(message);
28
- }
29
-
30
- /**
31
- * Copyright (c) Meta Platforms, Inc. and affiliates.
32
- *
33
- * This source code is licensed under the MIT license found in the
34
- * LICENSE file in the root directory of this source tree.
35
- *
36
- */
37
-
38
- const CAN_USE_DOM$1 = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
39
-
40
- /**
41
- * Copyright (c) Meta Platforms, Inc. and affiliates.
42
- *
43
- * This source code is licensed under the MIT license found in the
44
- * LICENSE file in the root directory of this source tree.
45
- *
46
- */
47
-
48
- const documentMode = CAN_USE_DOM$1 && 'documentMode' in document ? document.documentMode : null;
49
- const IS_APPLE$1 = CAN_USE_DOM$1 && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
50
- const IS_FIREFOX$1 = CAN_USE_DOM$1 && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
51
- const CAN_USE_BEFORE_INPUT$1 = CAN_USE_DOM$1 && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
52
- const IS_SAFARI$1 = CAN_USE_DOM$1 && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
53
- const IS_IOS$1 = CAN_USE_DOM$1 && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
54
- const IS_ANDROID$1 = CAN_USE_DOM$1 && /Android/.test(navigator.userAgent);
55
-
56
- // Keep these in case we need to use them in the future.
57
- // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
58
- const IS_CHROME$1 = CAN_USE_DOM$1 && /^(?=.*Chrome).*/i.test(navigator.userAgent);
59
- // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
60
-
61
- const IS_ANDROID_CHROME$1 = CAN_USE_DOM$1 && IS_ANDROID$1 && IS_CHROME$1;
62
- const IS_APPLE_WEBKIT$1 = CAN_USE_DOM$1 && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME$1;
63
-
64
- /**
65
- * Copyright (c) Meta Platforms, Inc. and affiliates.
66
- *
67
- * This source code is licensed under the MIT license found in the
68
- * LICENSE file in the root directory of this source tree.
69
- *
70
- */
71
-
72
- function normalizeClassNames(...classNames) {
73
- const rval = [];
74
- for (const className of classNames) {
75
- if (className && typeof className === 'string') {
76
- for (const [s] of className.matchAll(/\S+/g)) {
77
- rval.push(s);
78
- }
79
- }
80
- }
81
- return rval;
82
- }
83
-
84
- /**
85
- * Copyright (c) Meta Platforms, Inc. and affiliates.
86
- *
87
- * This source code is licensed under the MIT license found in the
88
- * LICENSE file in the root directory of this source tree.
89
- *
90
- */
91
-
92
- /**
93
- * Returns a function that will execute all functions passed when called. It is generally used
94
- * to register multiple lexical listeners and then tear them down with a single function call, such
95
- * as React's useEffect hook.
96
- * @example
97
- * ```ts
98
- * useEffect(() => {
99
- * return mergeRegister(
100
- * editor.registerCommand(...registerCommand1 logic),
101
- * editor.registerCommand(...registerCommand2 logic),
102
- * editor.registerCommand(...registerCommand3 logic)
103
- * )
104
- * }, [editor])
105
- * ```
106
- * In this case, useEffect is returning the function returned by mergeRegister as a cleanup
107
- * function to be executed after either the useEffect runs again (due to one of its dependencies
108
- * updating) or the component it resides in unmounts.
109
- * Note the functions don't necessarily need to be in an array as all arguments
110
- * are considered to be the func argument and spread from there.
111
- * The order of cleanup is the reverse of the argument order. Generally it is
112
- * expected that the first "acquire" will be "released" last (LIFO order),
113
- * because a later step may have some dependency on an earlier one.
114
- * @param func - An array of cleanup functions meant to be executed by the returned function.
115
- * @returns the function which executes all the passed cleanup functions.
116
- */
117
- function mergeRegister(...func) {
118
- return () => {
119
- for (let i = func.length - 1; i >= 0; i--) {
120
- func[i]();
121
- }
122
- // Clean up the references and make future calls a no-op
123
- func.length = 0;
124
- };
125
- }
126
-
127
- /**
128
- * Copyright (c) Meta Platforms, Inc. and affiliates.
129
- *
130
- * This source code is licensed under the MIT license found in the
131
- * LICENSE file in the root directory of this source tree.
132
- *
133
- */
134
-
135
- function px(value) {
136
- return `${value}px`;
137
- }
138
-
139
- const mutationObserverConfig = {
140
- attributes: true,
141
- characterData: true,
142
- childList: true,
143
- subtree: true
144
- };
145
- function prependDOMNode(parent, node) {
146
- parent.insertBefore(node, parent.firstChild);
147
- }
148
-
149
- /**
150
- * Place one or multiple newly created Nodes at the passed Range's position.
151
- * Multiple nodes will only be created when the Range spans multiple lines (aka
152
- * client rects).
153
- *
154
- * This function can come particularly useful to highlight particular parts of
155
- * the text without interfering with the EditorState, that will often replicate
156
- * the state across collab and clipboard.
157
- *
158
- * This function accounts for DOM updates which can modify the passed Range.
159
- * Hence, the function return to remove the listener.
160
- */
161
- function mlcPositionNodeOnRange(editor, range, onReposition) {
162
- let rootDOMNode = null;
163
- let parentDOMNode = null;
164
- let observer = null;
165
- let lastNodes = [];
166
- const wrapperNode = document.createElement('div');
167
- wrapperNode.style.position = 'relative';
168
- function position() {
169
- if (!(rootDOMNode !== null)) {
170
- formatDevErrorMessage(`Unexpected null rootDOMNode`);
171
- }
172
- if (!(parentDOMNode !== null)) {
173
- formatDevErrorMessage(`Unexpected null parentDOMNode`);
174
- }
175
- const {
176
- left: parentLeft,
177
- top: parentTop
178
- } = parentDOMNode.getBoundingClientRect();
179
- const rects = createRectsFromDOMRange(editor, range);
180
- if (!wrapperNode.isConnected) {
181
- prependDOMNode(parentDOMNode, wrapperNode);
182
- }
183
- let hasRepositioned = false;
184
- for (let i = 0; i < rects.length; i++) {
185
- const rect = rects[i];
186
- // Try to reuse the previously created Node when possible, no need to
187
- // remove/create on the most common case reposition case
188
- const rectNode = lastNodes[i] || document.createElement('div');
189
- const rectNodeStyle = rectNode.style;
190
- if (rectNodeStyle.position !== 'absolute') {
191
- rectNodeStyle.position = 'absolute';
192
- hasRepositioned = true;
193
- }
194
- const left = px(rect.left - parentLeft);
195
- if (rectNodeStyle.left !== left) {
196
- rectNodeStyle.left = left;
197
- hasRepositioned = true;
198
- }
199
- const top = px(rect.top - parentTop);
200
- if (rectNodeStyle.top !== top) {
201
- rectNode.style.top = top;
202
- hasRepositioned = true;
203
- }
204
- const width = px(rect.width);
205
- if (rectNodeStyle.width !== width) {
206
- rectNode.style.width = width;
207
- hasRepositioned = true;
208
- }
209
- const height = px(rect.height);
210
- if (rectNodeStyle.height !== height) {
211
- rectNode.style.height = height;
212
- hasRepositioned = true;
213
- }
214
- if (rectNode.parentNode !== wrapperNode) {
215
- wrapperNode.append(rectNode);
216
- hasRepositioned = true;
217
- }
218
- lastNodes[i] = rectNode;
219
- }
220
- while (lastNodes.length > rects.length) {
221
- lastNodes.pop();
222
- }
223
- if (hasRepositioned) {
224
- onReposition(lastNodes);
225
- }
226
- }
227
- function stop() {
228
- parentDOMNode = null;
229
- rootDOMNode = null;
230
- if (observer !== null) {
231
- observer.disconnect();
232
- }
233
- observer = null;
234
- wrapperNode.remove();
235
- for (const node of lastNodes) {
236
- node.remove();
237
- }
238
- lastNodes = [];
239
- }
240
- function restart() {
241
- const currentRootDOMNode = editor.getRootElement();
242
- if (currentRootDOMNode === null) {
243
- return stop();
244
- }
245
- const currentParentDOMNode = currentRootDOMNode.parentElement;
246
- if (!isHTMLElement(currentParentDOMNode)) {
247
- return stop();
248
- }
249
- stop();
250
- rootDOMNode = currentRootDOMNode;
251
- parentDOMNode = currentParentDOMNode;
252
- observer = new MutationObserver(mutations => {
253
- const nextRootDOMNode = editor.getRootElement();
254
- const nextParentDOMNode = nextRootDOMNode && nextRootDOMNode.parentElement;
255
- if (nextRootDOMNode !== rootDOMNode || nextParentDOMNode !== parentDOMNode) {
256
- return restart();
257
- }
258
- for (const mutation of mutations) {
259
- if (!wrapperNode.contains(mutation.target)) {
260
- // TODO throttle
261
- return position();
262
- }
263
- }
264
- });
265
- observer.observe(currentParentDOMNode, mutationObserverConfig);
266
- position();
267
- }
268
- const removeRootListener = editor.registerRootListener(restart);
269
- return () => {
270
- removeRootListener();
271
- stop();
272
- };
273
- }
274
-
275
- /**
276
- * Copyright (c) Meta Platforms, Inc. and affiliates.
277
- *
278
- * This source code is licensed under the MIT license found in the
279
- * LICENSE file in the root directory of this source tree.
280
- *
281
- */
282
-
283
- function $getOrderedSelectionPoints(selection) {
284
- const points = selection.getStartEndPoints();
285
- return selection.isBackward() ? [points[1], points[0]] : points;
286
- }
287
- function rangeTargetFromPoint(point, node, dom) {
288
- if (point.type === 'text' || !$isElementNode(node)) {
289
- const textDOM = getDOMTextNode(dom) || dom;
290
- return [textDOM, point.offset];
291
- } else {
292
- const slot = node.getDOMSlot(dom);
293
- return [slot.element, slot.getFirstChildOffset() + point.offset];
294
- }
295
- }
296
- function rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
297
- const editorDocument = editor._window ? editor._window.document : document;
298
- const range = editorDocument.createRange();
299
- range.setStart(...rangeTargetFromPoint(start, startNode, startDOM));
300
- range.setEnd(...rangeTargetFromPoint(end, endNode, endDOM));
301
- return range;
302
- }
303
- /**
304
- * Place one or multiple newly created Nodes at the current selection. Multiple
305
- * nodes will only be created when the selection spans multiple lines (aka
306
- * client rects).
307
- *
308
- * This function can come useful when you want to show the selection but the
309
- * editor has been focused away.
310
- */
311
- function markSelection(editor, onReposition) {
312
- let previousAnchorNode = null;
313
- let previousAnchorNodeDOM = null;
314
- let previousAnchorOffset = null;
315
- let previousFocusNode = null;
316
- let previousFocusNodeDOM = null;
317
- let previousFocusOffset = null;
318
- let removeRangeListener = () => {};
319
- function compute(editorState) {
320
- editorState.read(() => {
321
- const selection = $getSelection();
322
- if (!$isRangeSelection(selection)) {
323
- // TODO
324
- previousAnchorNode = null;
325
- previousAnchorOffset = null;
326
- previousFocusNode = null;
327
- previousFocusOffset = null;
328
- removeRangeListener();
329
- removeRangeListener = () => {};
330
- return;
331
- }
332
- const [start, end] = $getOrderedSelectionPoints(selection);
333
- const currentStartNode = start.getNode();
334
- const currentStartNodeKey = currentStartNode.getKey();
335
- const currentStartOffset = start.offset;
336
- const currentEndNode = end.getNode();
337
- const currentEndNodeKey = currentEndNode.getKey();
338
- const currentEndOffset = end.offset;
339
- const currentStartNodeDOM = editor.getElementByKey(currentStartNodeKey);
340
- const currentEndNodeDOM = editor.getElementByKey(currentEndNodeKey);
341
- const differentStartDOM = previousAnchorNode === null || currentStartNodeDOM !== previousAnchorNodeDOM || currentStartOffset !== previousAnchorOffset || currentStartNodeKey !== previousAnchorNode.getKey();
342
- const differentEndDOM = previousFocusNode === null || currentEndNodeDOM !== previousFocusNodeDOM || currentEndOffset !== previousFocusOffset || currentEndNodeKey !== previousFocusNode.getKey();
343
- if ((differentStartDOM || differentEndDOM) && currentStartNodeDOM !== null && currentEndNodeDOM !== null) {
344
- const range = rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
345
- removeRangeListener();
346
- removeRangeListener = mlcPositionNodeOnRange(editor, range, domNodes => {
347
- if (onReposition === undefined) {
348
- for (const domNode of domNodes) {
349
- const domNodeStyle = domNode.style;
350
- if (domNodeStyle.background !== 'Highlight') {
351
- domNodeStyle.background = 'Highlight';
352
- }
353
- if (domNodeStyle.color !== 'HighlightText') {
354
- domNodeStyle.color = 'HighlightText';
355
- }
356
- if (domNodeStyle.marginTop !== px(-1.5)) {
357
- domNodeStyle.marginTop = px(-1.5);
358
- }
359
- if (domNodeStyle.paddingTop !== px(4)) {
360
- domNodeStyle.paddingTop = px(4);
361
- }
362
- if (domNodeStyle.paddingBottom !== px(0)) {
363
- domNodeStyle.paddingBottom = px(0);
364
- }
365
- }
366
- } else {
367
- onReposition(domNodes);
368
- }
369
- });
370
- }
371
- previousAnchorNode = currentStartNode;
372
- previousAnchorNodeDOM = currentStartNodeDOM;
373
- previousAnchorOffset = currentStartOffset;
374
- previousFocusNode = currentEndNode;
375
- previousFocusNodeDOM = currentEndNodeDOM;
376
- previousFocusOffset = currentEndOffset;
377
- });
378
- }
379
- compute(editor.getEditorState());
380
- return mergeRegister(editor.registerUpdateListener(({
381
- editorState
382
- }) => compute(editorState)), () => {
383
- removeRangeListener();
384
- });
385
- }
386
-
387
- /**
388
- * Copyright (c) Meta Platforms, Inc. and affiliates.
389
- *
390
- * This source code is licensed under the MIT license found in the
391
- * LICENSE file in the root directory of this source tree.
392
- *
393
- */
394
-
395
- function selectionAlwaysOnDisplay(editor) {
396
- let removeSelectionMark = null;
397
- const onSelectionChange = () => {
398
- const domSelection = getSelection();
399
- const domAnchorNode = domSelection && domSelection.anchorNode;
400
- const editorRootElement = editor.getRootElement();
401
- const isSelectionInsideEditor = domAnchorNode !== null && editorRootElement !== null && editorRootElement.contains(domAnchorNode);
402
- if (isSelectionInsideEditor) {
403
- if (removeSelectionMark !== null) {
404
- removeSelectionMark();
405
- removeSelectionMark = null;
406
- }
407
- } else {
408
- if (removeSelectionMark === null) {
409
- removeSelectionMark = markSelection(editor);
410
- }
411
- }
412
- };
413
- document.addEventListener('selectionchange', onSelectionChange);
414
- return () => {
415
- if (removeSelectionMark !== null) {
416
- removeSelectionMark();
417
- }
418
- document.removeEventListener('selectionchange', onSelectionChange);
419
- };
420
- }
421
-
422
- // Hotfix to export these with inlined types #5918
423
- const CAN_USE_BEFORE_INPUT = CAN_USE_BEFORE_INPUT$1;
424
- const CAN_USE_DOM = CAN_USE_DOM$1;
425
- const IS_ANDROID = IS_ANDROID$1;
426
- const IS_ANDROID_CHROME = IS_ANDROID_CHROME$1;
427
- const IS_APPLE = IS_APPLE$1;
428
- const IS_APPLE_WEBKIT = IS_APPLE_WEBKIT$1;
429
- const IS_CHROME = IS_CHROME$1;
430
- const IS_FIREFOX = IS_FIREFOX$1;
431
- const IS_IOS = IS_IOS$1;
432
- const IS_SAFARI = IS_SAFARI$1;
433
-
434
- /**
435
- * Takes an HTML element and adds the classNames passed within an array,
436
- * ignoring any non-string types. A space can be used to add multiple classes
437
- * eg. addClassNamesToElement(element, ['element-inner active', true, null])
438
- * will add both 'element-inner' and 'active' as classes to that element.
439
- * @param element - The element in which the classes are added
440
- * @param classNames - An array defining the class names to add to the element
441
- */
442
- function addClassNamesToElement(element, ...classNames) {
443
- const classesToAdd = normalizeClassNames(...classNames);
444
- if (classesToAdd.length > 0) {
445
- element.classList.add(...classesToAdd);
446
- }
447
- }
448
-
449
- /**
450
- * Takes an HTML element and removes the classNames passed within an array,
451
- * ignoring any non-string types. A space can be used to remove multiple classes
452
- * eg. removeClassNamesFromElement(element, ['active small', true, null])
453
- * will remove both the 'active' and 'small' classes from that element.
454
- * @param element - The element in which the classes are removed
455
- * @param classNames - An array defining the class names to remove from the element
456
- */
457
- function removeClassNamesFromElement(element, ...classNames) {
458
- const classesToRemove = normalizeClassNames(...classNames);
459
- if (classesToRemove.length > 0) {
460
- element.classList.remove(...classesToRemove);
461
- }
462
- }
463
-
464
- /**
465
- * Returns true if the file type matches the types passed within the acceptableMimeTypes array, false otherwise.
466
- * The types passed must be strings and are CASE-SENSITIVE.
467
- * eg. if file is of type 'text' and acceptableMimeTypes = ['TEXT', 'IMAGE'] the function will return false.
468
- * @param file - The file you want to type check.
469
- * @param acceptableMimeTypes - An array of strings of types which the file is checked against.
470
- * @returns true if the file is an acceptable mime type, false otherwise.
471
- */
472
- function isMimeType(file, acceptableMimeTypes) {
473
- for (const acceptableType of acceptableMimeTypes) {
474
- if (file.type.startsWith(acceptableType)) {
475
- return true;
476
- }
477
- }
478
- return false;
479
- }
480
-
481
- /**
482
- * Lexical File Reader with:
483
- * 1. MIME type support
484
- * 2. batched results (HistoryPlugin compatibility)
485
- * 3. Order aware (respects the order when multiple Files are passed)
486
- *
487
- * const filesResult = await mediaFileReader(files, ['image/']);
488
- * filesResult.forEach(file => editor.dispatchCommand('INSERT_IMAGE', \\{
489
- * src: file.result,
490
- * \\}));
491
- */
492
- function mediaFileReader(files, acceptableMimeTypes) {
493
- const filesIterator = files[Symbol.iterator]();
494
- return new Promise((resolve, reject) => {
495
- const processed = [];
496
- const handleNextFile = () => {
497
- const {
498
- done,
499
- value: file
500
- } = filesIterator.next();
501
- if (done) {
502
- return resolve(processed);
503
- }
504
- const fileReader = new FileReader();
505
- fileReader.addEventListener('error', reject);
506
- fileReader.addEventListener('load', () => {
507
- const result = fileReader.result;
508
- if (typeof result === 'string') {
509
- processed.push({
510
- file,
511
- result
512
- });
513
- }
514
- handleNextFile();
515
- });
516
- if (isMimeType(file, acceptableMimeTypes)) {
517
- fileReader.readAsDataURL(file);
518
- } else {
519
- handleNextFile();
520
- }
521
- };
522
- handleNextFile();
523
- });
524
- }
525
- /**
526
- * "Depth-First Search" starts at the root/top node of a tree and goes as far as it can down a branch end
527
- * before backtracking and finding a new path. Consider solving a maze by hugging either wall, moving down a
528
- * branch until you hit a dead-end (leaf) and backtracking to find the nearest branching path and repeat.
529
- * It will then return all the nodes found in the search in an array of objects.
530
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
531
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
532
- * @returns An array of objects of all the nodes found by the search, including their depth into the tree.
533
- * \\{depth: number, node: LexicalNode\\} It will always return at least 1 node (the start node).
534
- */
535
- function $dfs(startNode, endNode) {
536
- return Array.from($dfsIterator(startNode, endNode));
537
- }
538
-
539
- /**
540
- * Get the adjacent caret in the same direction
541
- *
542
- * @param caret A caret or null
543
- * @returns `caret.getAdjacentCaret()` or `null`
544
- */
545
- function $getAdjacentCaret(caret) {
546
- return caret ? caret.getAdjacentCaret() : null;
547
- }
548
-
549
- /**
550
- * $dfs iterator (right to left). Tree traversal is done on the fly as new values are requested with O(1) memory.
551
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
552
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
553
- * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
554
- */
555
- function $reverseDfs(startNode, endNode) {
556
- return Array.from($reverseDfsIterator(startNode, endNode));
557
- }
558
-
559
- /**
560
- * $dfs iterator (left to right). Tree traversal is done on the fly as new values are requested with O(1) memory.
561
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
562
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
563
- * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
564
- */
565
- function $dfsIterator(startNode, endNode) {
566
- return $dfsCaretIterator('next', startNode, endNode);
567
- }
568
- function $getEndCaret(startNode, direction) {
569
- const rval = $getAdjacentSiblingOrParentSiblingCaret($getSiblingCaret(startNode, direction));
570
- return rval && rval[0];
571
- }
572
- function $dfsCaretIterator(direction, startNode, endNode) {
573
- const root = $getRoot();
574
- const start = startNode || root;
575
- const startCaret = $isElementNode(start) ? $getChildCaret(start, direction) : $getSiblingCaret(start, direction);
576
- const startDepth = $getDepth(start);
577
- const endCaret = endNode ? $getAdjacentChildCaret($getChildCaretOrSelf($getSiblingCaret(endNode, direction))) : $getEndCaret(start, direction);
578
- let depth = startDepth;
579
- return makeStepwiseIterator({
580
- hasNext: state => state !== null,
581
- initial: startCaret,
582
- map: state => ({
583
- depth,
584
- node: state.origin
585
- }),
586
- step: state => {
587
- if (state.isSameNodeCaret(endCaret)) {
588
- return null;
589
- }
590
- if ($isChildCaret(state)) {
591
- depth++;
592
- }
593
- const rval = $getAdjacentSiblingOrParentSiblingCaret(state);
594
- if (!rval || rval[0].isSameNodeCaret(endCaret)) {
595
- return null;
596
- }
597
- depth += rval[1];
598
- return rval[0];
599
- }
600
- });
601
- }
602
-
603
- /**
604
- * Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
605
- * R -> P -> T1, T2
606
- * -> P2
607
- * returns T2 for node T1, P2 for node T2, and null for node P2.
608
- * @param node LexicalNode.
609
- * @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
610
- */
611
- function $getNextSiblingOrParentSibling(node) {
612
- const rval = $getAdjacentSiblingOrParentSiblingCaret($getSiblingCaret(node, 'next'));
613
- return rval && [rval[0].origin, rval[1]];
614
- }
615
- function $getDepth(node) {
616
- let depth = -1;
617
- for (let innerNode = node; innerNode !== null; innerNode = innerNode.getParent()) {
618
- depth++;
619
- }
620
- return depth;
621
- }
622
-
623
- /**
624
- * Performs a right-to-left preorder tree traversal.
625
- * From the starting node it goes to the rightmost child, than backtracks to parent and finds new rightmost path.
626
- * It will return the next node in traversal sequence after the startingNode.
627
- * The traversal is similar to $dfs functions above, but the nodes are visited right-to-left, not left-to-right.
628
- * @param startingNode - The node to start the search.
629
- * @returns The next node in pre-order right to left traversal sequence or `null`, if the node does not exist
630
- */
631
- function $getNextRightPreorderNode(startingNode) {
632
- const startCaret = $getChildCaretOrSelf($getSiblingCaret(startingNode, 'previous'));
633
- const next = $getAdjacentSiblingOrParentSiblingCaret(startCaret, 'root');
634
- return next && next[0].origin;
635
- }
636
-
637
- /**
638
- * $dfs iterator (right to left). Tree traversal is done on the fly as new values are requested with O(1) memory.
639
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
640
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
641
- * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
642
- */
643
- function $reverseDfsIterator(startNode, endNode) {
644
- return $dfsCaretIterator('previous', startNode, endNode);
645
- }
646
-
647
- /**
648
- * Takes a node and traverses up its ancestors (toward the root node)
649
- * in order to find a specific type of node.
650
- * @param node - the node to begin searching.
651
- * @param klass - an instance of the type of node to look for.
652
- * @returns the node of type klass that was passed, or null if none exist.
653
- */
654
- function $getNearestNodeOfType(node, klass) {
655
- let parent = node;
656
- while (parent != null) {
657
- if (parent instanceof klass) {
658
- return parent;
659
- }
660
- parent = parent.getParent();
661
- }
662
- return null;
663
- }
664
-
665
- /**
666
- * Returns the element node of the nearest ancestor, otherwise throws an error.
667
- * @param startNode - The starting node of the search
668
- * @returns The ancestor node found
669
- */
670
- function $getNearestBlockElementAncestorOrThrow(startNode) {
671
- const blockNode = $findMatchingParent(startNode, node => $isElementNode(node) && !node.isInline());
672
- if (!$isElementNode(blockNode)) {
673
- {
674
- formatDevErrorMessage(`Expected node ${startNode.__key} to have closest block element node.`);
675
- }
676
- }
677
- return blockNode;
678
- }
679
- /**
680
- * Starts with a node and moves up the tree (toward the root node) to find a matching node based on
681
- * the search parameters of the findFn. (Consider JavaScripts' .find() function where a testing function must be
682
- * passed as an argument. eg. if( (node) => node.__type === 'div') ) return true; otherwise return false
683
- * @param startingNode - The node where the search starts.
684
- * @param findFn - A testing function that returns true if the current node satisfies the testing parameters.
685
- * @returns A parent node that matches the findFn parameters, or null if one wasn't found.
686
- */
687
- const $findMatchingParent = (startingNode, findFn) => {
688
- let curr = startingNode;
689
- while (curr !== $getRoot() && curr != null) {
690
- if (findFn(curr)) {
691
- return curr;
692
- }
693
- curr = curr.getParent();
694
- }
695
- return null;
696
- };
697
-
698
- /**
699
- * Attempts to resolve nested element nodes of the same type into a single node of that type.
700
- * It is generally used for marks/commenting
701
- * @param editor - The lexical editor
702
- * @param targetNode - The target for the nested element to be extracted from.
703
- * @param cloneNode - See {@link $createMarkNode}
704
- * @param handleOverlap - Handles any overlap between the node to extract and the targetNode
705
- * @returns The lexical editor
706
- */
707
- function registerNestedElementResolver(editor, targetNode, cloneNode, handleOverlap) {
708
- const $isTargetNode = node => {
709
- return node instanceof targetNode;
710
- };
711
- const $findMatch = node => {
712
- // First validate we don't have any children that are of the target,
713
- // as we need to handle them first.
714
- const children = node.getChildren();
715
- for (let i = 0; i < children.length; i++) {
716
- const child = children[i];
717
- if ($isTargetNode(child)) {
718
- return null;
719
- }
720
- }
721
- let parentNode = node;
722
- let childNode = node;
723
- while (parentNode !== null) {
724
- childNode = parentNode;
725
- parentNode = parentNode.getParent();
726
- if ($isTargetNode(parentNode)) {
727
- return {
728
- child: childNode,
729
- parent: parentNode
730
- };
731
- }
732
- }
733
- return null;
734
- };
735
- const $elementNodeTransform = node => {
736
- const match = $findMatch(node);
737
- if (match !== null) {
738
- const {
739
- child,
740
- parent
741
- } = match;
742
-
743
- // Simple path, we can move child out and siblings into a new parent.
744
-
745
- if (child.is(node)) {
746
- handleOverlap(parent, node);
747
- const nextSiblings = child.getNextSiblings();
748
- const nextSiblingsLength = nextSiblings.length;
749
- parent.insertAfter(child);
750
- if (nextSiblingsLength !== 0) {
751
- const newParent = cloneNode(parent);
752
- child.insertAfter(newParent);
753
- for (let i = 0; i < nextSiblingsLength; i++) {
754
- newParent.append(nextSiblings[i]);
755
- }
756
- }
757
- if (!parent.canBeEmpty() && parent.getChildrenSize() === 0) {
758
- parent.remove();
759
- }
760
- }
761
- }
762
- };
763
- return editor.registerNodeTransform(targetNode, $elementNodeTransform);
764
- }
765
-
766
- /**
767
- * Clones the editor and marks it as dirty to be reconciled. If there was a selection,
768
- * it would be set back to its previous state, or null otherwise.
769
- * @param editor - The lexical editor
770
- * @param editorState - The editor's state
771
- */
772
- function $restoreEditorState(editor, editorState) {
773
- const FULL_RECONCILE = 2;
774
- const nodeMap = new Map();
775
- const activeEditorState = editor._pendingEditorState;
776
- for (const [key, node] of editorState._nodeMap) {
777
- nodeMap.set(key, $cloneWithProperties(node));
778
- }
779
- if (activeEditorState) {
780
- activeEditorState._nodeMap = nodeMap;
781
- }
782
- editor._dirtyType = FULL_RECONCILE;
783
- const selection = editorState._selection;
784
- $setSelection(selection === null ? null : selection.clone());
785
- }
786
-
787
- /**
788
- * If the selected insertion area is the root/shadow root node (see {@link lexical!$isRootOrShadowRoot}),
789
- * the node will be appended there, otherwise, it will be inserted before the insertion area.
790
- * If there is no selection where the node is to be inserted, it will be appended after any current nodes
791
- * within the tree, as a child of the root node. A paragraph will then be added after the inserted node and selected.
792
- * @param node - The node to be inserted
793
- * @returns The node after its insertion
794
- */
795
- function $insertNodeToNearestRoot(node) {
796
- const selection = $getSelection() || $getPreviousSelection();
797
- let initialCaret;
798
- if ($isRangeSelection(selection)) {
799
- initialCaret = $caretFromPoint(selection.focus, 'next');
800
- } else {
801
- if (selection != null) {
802
- const nodes = selection.getNodes();
803
- const lastNode = nodes[nodes.length - 1];
804
- if (lastNode) {
805
- initialCaret = $getSiblingCaret(lastNode, 'next');
806
- }
807
- }
808
- initialCaret = initialCaret || $getChildCaret($getRoot(), 'previous').getFlipped().insert($createParagraphNode());
809
- }
810
- const insertCaret = $insertNodeToNearestRootAtCaret(node, initialCaret);
811
- const adjacent = $getAdjacentChildCaret(insertCaret);
812
- const selectionCaret = $isChildCaret(adjacent) ? $normalizeCaret(adjacent) : insertCaret;
813
- $setSelectionFromCaretRange($getCollapsedCaretRange(selectionCaret));
814
- return node.getLatest();
815
- }
816
-
817
- /**
818
- * If the insertion caret is the root/shadow root node (see {@link lexical!$isRootOrShadowRoot}),
819
- * the node will be inserted there, otherwise the parent nodes will be split according to the
820
- * given options.
821
- * @param node - The node to be inserted
822
- * @param caret - The location to insert or split from
823
- * @returns The node after its insertion
824
- */
825
- function $insertNodeToNearestRootAtCaret(node, caret, options) {
826
- let insertCaret = $getCaretInDirection(caret, 'next');
827
- for (let nextCaret = insertCaret; nextCaret; nextCaret = $splitAtPointCaretNext(nextCaret, options)) {
828
- insertCaret = nextCaret;
829
- }
830
- if (!!$isTextPointCaret(insertCaret)) {
831
- formatDevErrorMessage(`$insertNodeToNearestRootAtCaret: An unattached TextNode can not be split`);
832
- }
833
- insertCaret.insert(node.isInline() ? $createParagraphNode().append(node) : node);
834
- return $getCaretInDirection($getSiblingCaret(node.getLatest(), 'next'), caret.direction);
835
- }
836
-
837
- /**
838
- * Wraps the node into another node created from a createElementNode function, eg. $createParagraphNode
839
- * @param node - Node to be wrapped.
840
- * @param createElementNode - Creates a new lexical element to wrap the to-be-wrapped node and returns it.
841
- * @returns A new lexical element with the previous node appended within (as a child, including its children).
842
- */
843
- function $wrapNodeInElement(node, createElementNode) {
844
- const elementNode = createElementNode();
845
- node.replace(elementNode);
846
- elementNode.append(node);
847
- return elementNode;
848
- }
849
-
850
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
851
-
852
- /**
853
- * @param object = The instance of the type
854
- * @param objectClass = The class of the type
855
- * @returns Whether the object is has the same Klass of the objectClass, ignoring the difference across window (e.g. different iframes)
856
- */
857
- function objectKlassEquals(object, objectClass) {
858
- return object !== null ? Object.getPrototypeOf(object).constructor.name === objectClass.name : false;
859
- }
860
-
861
- /**
862
- * Filter the nodes
863
- * @param nodes Array of nodes that needs to be filtered
864
- * @param filterFn A filter function that returns node if the current node satisfies the condition otherwise null
865
- * @returns Array of filtered nodes
866
- */
867
-
868
- function $filter(nodes, filterFn) {
869
- const result = [];
870
- for (let i = 0; i < nodes.length; i++) {
871
- const node = filterFn(nodes[i]);
872
- if (node !== null) {
873
- result.push(node);
874
- }
875
- }
876
- return result;
877
- }
878
- /**
879
- * Appends the node before the first child of the parent node
880
- * @param parent A parent node
881
- * @param node Node that needs to be appended
882
- */
883
- function $insertFirst(parent, node) {
884
- $getChildCaret(parent, 'next').insert(node);
885
- }
886
- let NEEDS_MANUAL_ZOOM = IS_FIREFOX || !CAN_USE_DOM ? false : undefined;
887
- function needsManualZoom() {
888
- if (NEEDS_MANUAL_ZOOM === undefined) {
889
- // If the browser implements standardized CSS zoom, then the client rect
890
- // will be wider after zoom is applied
891
- // https://chromestatus.com/feature/5198254868529152
892
- // https://github.com/facebook/lexical/issues/6863
893
- const div = document.createElement('div');
894
- div.style.cssText = 'position: absolute; opacity: 0; width: 100px; left: -1000px;';
895
- document.body.appendChild(div);
896
- const noZoom = div.getBoundingClientRect();
897
- div.style.setProperty('zoom', '2');
898
- NEEDS_MANUAL_ZOOM = div.getBoundingClientRect().width === noZoom.width;
899
- document.body.removeChild(div);
900
- }
901
- return NEEDS_MANUAL_ZOOM;
902
- }
903
-
904
- /**
905
- * Calculates the zoom level of an element as a result of using
906
- * css zoom property. For browsers that implement standardized CSS
907
- * zoom (Firefox, Chrome >= 128), this will always return 1.
908
- * @param element
909
- */
910
- function calculateZoomLevel(element) {
911
- let zoom = 1;
912
- if (needsManualZoom()) {
913
- while (element) {
914
- zoom *= Number(window.getComputedStyle(element).getPropertyValue('zoom'));
915
- element = element.parentElement;
916
- }
917
- }
918
- return zoom;
919
- }
920
-
921
- /**
922
- * Checks if the editor is a nested editor created by LexicalNestedComposer
923
- */
924
- function $isEditorIsNestedEditor(editor) {
925
- return editor._parentEditor !== null;
926
- }
927
-
928
- /**
929
- * A depth first last-to-first traversal of root that stops at each node that matches
930
- * $predicate and ensures that its parent is root. This is typically used to discard
931
- * invalid or unsupported wrapping nodes. For example, a TableNode must only have
932
- * TableRowNode as children, but an importer might add invalid nodes based on
933
- * caption, tbody, thead, etc. and this will unwrap and discard those.
934
- *
935
- * @param root The root to start the traversal
936
- * @param $predicate Should return true for nodes that are permitted to be children of root
937
- * @returns true if this unwrapped or removed any nodes
938
- */
939
- function $unwrapAndFilterDescendants(root, $predicate) {
940
- return $unwrapAndFilterDescendantsImpl(root, $predicate, null);
941
- }
942
- function $unwrapAndFilterDescendantsImpl(root, $predicate, $onSuccess) {
943
- let didMutate = false;
944
- for (const node of $lastToFirstIterator(root)) {
945
- if ($predicate(node)) {
946
- if ($onSuccess !== null) {
947
- $onSuccess(node);
948
- }
949
- continue;
950
- }
951
- didMutate = true;
952
- if ($isElementNode(node)) {
953
- $unwrapAndFilterDescendantsImpl(node, $predicate, $onSuccess || (child => node.insertAfter(child)));
954
- }
955
- node.remove();
956
- }
957
- return didMutate;
958
- }
959
-
960
- /**
961
- * A depth first traversal of the children array that stops at and collects
962
- * each node that `$predicate` matches. This is typically used to discard
963
- * invalid or unsupported wrapping nodes on a children array in the `after`
964
- * of an {@link lexical!DOMConversionOutput}. For example, a TableNode must only have
965
- * TableRowNode as children, but an importer might add invalid nodes based on
966
- * caption, tbody, thead, etc. and this will unwrap and discard those.
967
- *
968
- * This function is read-only and performs no mutation operations, which makes
969
- * it suitable for import and export purposes but likely not for any in-place
970
- * mutation. You should use {@link $unwrapAndFilterDescendants} for in-place
971
- * mutations such as node transforms.
972
- *
973
- * @param children The children to traverse
974
- * @param $predicate Should return true for nodes that are permitted to be children of root
975
- * @returns The children or their descendants that match $predicate
976
- */
977
-
978
- function $descendantsMatching(children, $predicate) {
979
- const result = [];
980
- const stack = Array.from(children).reverse();
981
- for (let child = stack.pop(); child !== undefined; child = stack.pop()) {
982
- if ($predicate(child)) {
983
- result.push(child);
984
- } else if ($isElementNode(child)) {
985
- for (const grandchild of $lastToFirstIterator(child)) {
986
- stack.push(grandchild);
987
- }
988
- }
989
- }
990
- return result;
991
- }
992
-
993
- /**
994
- * Return an iterator that yields each child of node from first to last, taking
995
- * care to preserve the next sibling before yielding the value in case the caller
996
- * removes the yielded node.
997
- *
998
- * @param node The node whose children to iterate
999
- * @returns An iterator of the node's children
1000
- */
1001
- function $firstToLastIterator(node) {
1002
- return $childIterator($getChildCaret(node, 'next'));
1003
- }
1004
-
1005
- /**
1006
- * Return an iterator that yields each child of node from last to first, taking
1007
- * care to preserve the previous sibling before yielding the value in case the caller
1008
- * removes the yielded node.
1009
- *
1010
- * @param node The node whose children to iterate
1011
- * @returns An iterator of the node's children
1012
- */
1013
- function $lastToFirstIterator(node) {
1014
- return $childIterator($getChildCaret(node, 'previous'));
1015
- }
1016
- function $childIterator(startCaret) {
1017
- const seen = new Set() ;
1018
- return makeStepwiseIterator({
1019
- hasNext: $isSiblingCaret,
1020
- initial: startCaret.getAdjacentCaret(),
1021
- map: caret => {
1022
- const origin = caret.origin.getLatest();
1023
- if (seen !== null) {
1024
- const key = origin.getKey();
1025
- if (!!seen.has(key)) {
1026
- formatDevErrorMessage(`$childIterator: Cycle detected, node with key ${String(key)} has already been traversed`);
1027
- }
1028
- seen.add(key);
1029
- }
1030
- return origin;
1031
- },
1032
- step: caret => caret.getAdjacentCaret()
1033
- });
1034
- }
1035
-
1036
- /**
1037
- * Replace this node with its children
1038
- *
1039
- * @param node The ElementNode to unwrap and remove
1040
- */
1041
- function $unwrapNode(node) {
1042
- $rewindSiblingCaret($getSiblingCaret(node, 'next')).splice(1, node.getChildren());
1043
- }
1044
-
1045
- /**
1046
- * Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
1047
- * R -> P -> T1, T2
1048
- * -> P2
1049
- * returns T2 for node T1, P2 for node T2, and null for node P2.
1050
- * @param node LexicalNode.
1051
- * @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
1052
- */
1053
- function $getAdjacentSiblingOrParentSiblingCaret(startCaret, rootMode = 'root') {
1054
- let depthDiff = 0;
1055
- let caret = startCaret;
1056
- let nextCaret = $getAdjacentChildCaret(caret);
1057
- while (nextCaret === null) {
1058
- depthDiff--;
1059
- nextCaret = caret.getParentCaret(rootMode);
1060
- if (!nextCaret) {
1061
- return null;
1062
- }
1063
- caret = nextCaret;
1064
- nextCaret = $getAdjacentChildCaret(caret);
1065
- }
1066
- return nextCaret && [nextCaret, depthDiff];
1067
- }
1068
-
1069
- /**
1070
- * A wrapper that creates bound functions and methods for the
1071
- * StateConfig to save some boilerplate when defining methods
1072
- * or exporting only the accessors from your modules rather
1073
- * than exposing the StateConfig directly.
1074
- */
1075
-
1076
- /**
1077
- * EXPERIMENTAL
1078
- *
1079
- * A convenience interface for working with {@link $getState} and
1080
- * {@link $setState}.
1081
- *
1082
- * @param stateConfig The stateConfig to wrap with convenience functionality
1083
- * @returns a StateWrapper
1084
- */
1085
- function makeStateWrapper(stateConfig) {
1086
- const $get = node => $getState(node, stateConfig);
1087
- const $set = (node, valueOrUpdater) => $setState(node, stateConfig, valueOrUpdater);
1088
- return {
1089
- $get,
1090
- $set,
1091
- accessors: [$get, $set],
1092
- makeGetterMethod: () => function $getter() {
1093
- return $get(this);
1094
- },
1095
- makeSetterMethod: () => function $setter(valueOrUpdater) {
1096
- return $set(this, valueOrUpdater);
1097
- },
1098
- stateConfig
1099
- };
1100
- }
1101
-
1102
- export { $descendantsMatching, $dfs, $dfsIterator, $filter, $findMatchingParent, $firstToLastIterator, $getAdjacentCaret, $getAdjacentSiblingOrParentSiblingCaret, $getDepth, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $getNextRightPreorderNode, $getNextSiblingOrParentSibling, $insertFirst, $insertNodeToNearestRoot, $insertNodeToNearestRootAtCaret, $isEditorIsNestedEditor, $lastToFirstIterator, $restoreEditorState, $reverseDfs, $reverseDfsIterator, $unwrapAndFilterDescendants, $unwrapNode, $wrapNodeInElement, CAN_USE_BEFORE_INPUT, CAN_USE_DOM, IS_ANDROID, IS_ANDROID_CHROME, IS_APPLE, IS_APPLE_WEBKIT, IS_CHROME, IS_FIREFOX, IS_IOS, IS_SAFARI, addClassNamesToElement, calculateZoomLevel, isMimeType, makeStateWrapper, markSelection, mediaFileReader, mergeRegister, objectKlassEquals, mlcPositionNodeOnRange as positionNodeOnRange, registerNestedElementResolver, removeClassNamesFromElement, selectionAlwaysOnDisplay };