@vonage/vivid 5.16.0 → 5.18.0

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 (564) hide show
  1. package/accordion/definition.cjs +6 -6
  2. package/accordion/definition.js +1 -1
  3. package/accordion/index.cjs +1 -1
  4. package/accordion/index.js +2 -2
  5. package/accordion-item/definition.cjs +5 -5
  6. package/accordion-item/definition.js +1 -1
  7. package/accordion-item/index.cjs +1 -1
  8. package/accordion-item/index.js +2 -2
  9. package/action-group/index.cjs +3 -3
  10. package/action-group/index.js +5 -5
  11. package/alert/definition.cjs +5 -5
  12. package/alert/definition.js +1 -1
  13. package/alert/index.cjs +3 -3
  14. package/alert/index.js +15 -14
  15. package/audio-player/definition.cjs +5 -5
  16. package/audio-player/definition.js +1 -1
  17. package/audio-player/index.cjs +16 -16
  18. package/audio-player/index.js +29 -28
  19. package/avatar/definition.cjs +5 -5
  20. package/avatar/definition.js +1 -1
  21. package/avatar/index.cjs +4 -4
  22. package/avatar/index.js +12 -11
  23. package/badge/definition.cjs +5 -5
  24. package/badge/definition.js +1 -1
  25. package/badge/index.cjs +1 -4
  26. package/badge/index.js +4 -20
  27. package/banner/definition.cjs +5 -5
  28. package/banner/definition.js +1 -1
  29. package/banner/index.cjs +3 -3
  30. package/banner/index.js +14 -13
  31. package/breadcrumb-item/definition.cjs +4 -4
  32. package/breadcrumb-item/definition.js +1 -1
  33. package/breadcrumb-item/index.cjs +1 -1
  34. package/breadcrumb-item/index.js +1 -0
  35. package/bundled/affix.cjs +1 -1
  36. package/bundled/affix.js +5 -5
  37. package/bundled/base-color-picker.cjs +2 -2
  38. package/bundled/base-color-picker.js +5 -5
  39. package/bundled/button.cjs +1 -1
  40. package/bundled/button.js +2 -2
  41. package/bundled/calendar-picker.template.cjs +2 -2
  42. package/bundled/calendar-picker.template.js +498 -498
  43. package/bundled/definition10.cjs +18 -30
  44. package/bundled/definition10.js +53 -155
  45. package/bundled/definition11.cjs +10 -19
  46. package/bundled/definition11.js +25 -74
  47. package/bundled/definition12.cjs +72 -18
  48. package/bundled/definition12.js +171 -107
  49. package/bundled/definition13.cjs +18 -17
  50. package/bundled/definition13.js +46 -66
  51. package/bundled/definition14.cjs +5 -10
  52. package/bundled/definition14.js +9 -27
  53. package/bundled/definition15.cjs +17 -71
  54. package/bundled/definition15.js +64 -181
  55. package/bundled/definition16.cjs +12 -4
  56. package/bundled/definition16.js +79 -14
  57. package/bundled/definition17.cjs +19 -13
  58. package/bundled/definition17.js +118 -69
  59. package/bundled/definition18.cjs +87 -12
  60. package/bundled/definition18.js +409 -52
  61. package/bundled/definition19.cjs +5 -87
  62. package/bundled/definition19.js +14 -422
  63. package/bundled/definition2.cjs +3 -14
  64. package/bundled/definition2.js +16 -49
  65. package/bundled/definition20.cjs +30 -5
  66. package/bundled/definition20.js +159 -9
  67. package/bundled/definition21.cjs +28 -19
  68. package/bundled/definition21.js +164 -47
  69. package/bundled/definition22.cjs +4 -24
  70. package/bundled/definition22.js +18 -88
  71. package/bundled/definition23.cjs +12 -0
  72. package/bundled/definition23.js +37 -0
  73. package/bundled/definition24.cjs +39 -0
  74. package/bundled/definition24.js +72 -0
  75. package/bundled/definition3.cjs +1 -1
  76. package/bundled/definition3.js +24 -21
  77. package/bundled/definition4.cjs +23 -38
  78. package/bundled/definition4.js +81 -63
  79. package/bundled/definition5.cjs +2 -2
  80. package/bundled/definition5.js +5 -5
  81. package/bundled/definition6.cjs +11 -11
  82. package/bundled/definition6.js +57 -41
  83. package/bundled/definition9.cjs +12 -30
  84. package/bundled/definition9.js +55 -148
  85. package/bundled/divider.cjs +1 -1
  86. package/bundled/divider.js +5 -5
  87. package/bundled/listbox.cjs +1 -1
  88. package/bundled/listbox.js +1 -1
  89. package/bundled/localized.cjs +1 -1
  90. package/bundled/localized.js +1 -0
  91. package/bundled/mixins.cjs +5 -5
  92. package/bundled/mixins.js +49 -49
  93. package/bundled/numberConverter.cjs +12 -0
  94. package/bundled/numberConverter.js +38 -0
  95. package/bundled/picker-field.template.cjs +8 -7
  96. package/bundled/picker-field.template.js +16 -15
  97. package/bundled/slider.template.cjs +7 -7
  98. package/bundled/slider.template.js +12 -12
  99. package/bundled/slottable-request.cjs +1 -1
  100. package/bundled/slottable-request.js +8 -38
  101. package/bundled/time-selection-picker.template.cjs +4 -4
  102. package/bundled/time-selection-picker.template.js +35 -35
  103. package/bundled/utils.cjs +1 -0
  104. package/bundled/utils.js +1420 -0
  105. package/bundled/vivid-element.cjs +1 -1
  106. package/bundled/vivid-element.js +1 -1
  107. package/button/definition.cjs +5 -5
  108. package/button/definition.js +1 -1
  109. package/button/index.cjs +1 -1
  110. package/button/index.js +1 -1
  111. package/calendar/index.cjs +11 -11
  112. package/calendar/index.js +30 -237
  113. package/calendar-event/index.cjs +3 -3
  114. package/calendar-event/index.js +4 -4
  115. package/card/definition.cjs +5 -5
  116. package/card/definition.js +1 -1
  117. package/card/index.cjs +15 -12
  118. package/card/index.js +17 -13
  119. package/checkbox/definition.cjs +5 -5
  120. package/checkbox/definition.js +1 -1
  121. package/checkbox/index.cjs +1 -1
  122. package/checkbox/index.js +2 -2
  123. package/color-picker/definition.cjs +5 -5
  124. package/color-picker/definition.js +2 -2
  125. package/color-picker/index.cjs +10 -10
  126. package/color-picker/index.js +58 -57
  127. package/combobox/definition.cjs +5 -5
  128. package/combobox/definition.js +2 -2
  129. package/combobox/index.cjs +9 -8
  130. package/combobox/index.js +40 -35
  131. package/contextual-help/definition.cjs +5 -5
  132. package/contextual-help/definition.js +2 -2
  133. package/contextual-help/index.cjs +1 -1
  134. package/contextual-help/index.js +2 -2
  135. package/country/definition.cjs +5 -5
  136. package/country/definition.js +1 -1
  137. package/country/index.cjs +1 -12
  138. package/country/index.js +4 -1216
  139. package/country-group/definition.cjs +6 -0
  140. package/country-group/definition.js +3 -0
  141. package/country-group/index.cjs +43 -0
  142. package/country-group/index.js +166 -0
  143. package/custom-elements.json +1274 -200
  144. package/data-grid/definition.cjs +9 -9
  145. package/data-grid/definition.js +2 -2
  146. package/data-grid/index.cjs +18 -18
  147. package/data-grid/index.js +260 -262
  148. package/date-picker/definition.cjs +5 -5
  149. package/date-picker/definition.js +2 -2
  150. package/date-picker/index.cjs +1 -1
  151. package/date-picker/index.js +13 -13
  152. package/date-range-picker/definition.cjs +5 -5
  153. package/date-range-picker/definition.js +2 -2
  154. package/date-range-picker/index.cjs +1 -1
  155. package/date-range-picker/index.js +8 -8
  156. package/date-time-picker/definition.cjs +5 -5
  157. package/date-time-picker/definition.js +2 -2
  158. package/date-time-picker/index.cjs +4 -4
  159. package/date-time-picker/index.js +25 -25
  160. package/dial-pad/definition.cjs +5 -5
  161. package/dial-pad/definition.js +2 -2
  162. package/dial-pad/index.cjs +6 -5
  163. package/dial-pad/index.js +14 -12
  164. package/dialog/definition.cjs +5 -5
  165. package/dialog/definition.js +2 -2
  166. package/dialog/index.cjs +6 -6
  167. package/dialog/index.js +17 -16
  168. package/divider/definition.cjs +1 -1
  169. package/divider/definition.js +1 -1
  170. package/divider/index.cjs +1 -1
  171. package/divider/index.js +1 -1
  172. package/empty-state/definition.cjs +5 -5
  173. package/empty-state/definition.js +2 -2
  174. package/empty-state/index.cjs +2 -2
  175. package/empty-state/index.js +6 -5
  176. package/fab/definition.cjs +5 -5
  177. package/fab/definition.js +2 -2
  178. package/fab/index.cjs +4 -4
  179. package/fab/index.js +13 -12
  180. package/file-picker/definition.cjs +5 -5
  181. package/file-picker/definition.js +2 -2
  182. package/file-picker/index.cjs +20 -17
  183. package/file-picker/index.js +40 -36
  184. package/flag/definition.cjs +6 -0
  185. package/flag/definition.js +3 -0
  186. package/flag/index.cjs +10 -0
  187. package/flag/index.js +61 -0
  188. package/header/definition.cjs +1 -1
  189. package/header/definition.js +1 -1
  190. package/header/index.cjs +4 -4
  191. package/header/index.js +5 -5
  192. package/icon/definition.cjs +1 -0
  193. package/icon/definition.js +1 -0
  194. package/icon/index.cjs +1 -1
  195. package/icon/index.js +1 -0
  196. package/index.cjs +204 -192
  197. package/index.js +55 -52
  198. package/layout/definition.cjs +1 -1
  199. package/layout/definition.js +1 -1
  200. package/lib/button/button.d.ts +1 -0
  201. package/lib/combobox/combobox.d.ts +0 -3
  202. package/lib/components.d.ts +2 -0
  203. package/lib/country/countries-data.d.ts +1 -0
  204. package/lib/country/{country-code-to-flag-icon.d.ts → utils.d.ts} +0 -3
  205. package/lib/country-group/country-group.d.ts +829 -0
  206. package/lib/country-group/country-group.template.d.ts +3 -0
  207. package/lib/country-group/definition.d.ts +3 -0
  208. package/lib/country-group/index.d.ts +1 -0
  209. package/lib/country-group/locale.d.ts +3 -0
  210. package/lib/date-picker/date-picker.d.ts +4 -0
  211. package/lib/date-range-picker/date-range-picker.d.ts +2 -0
  212. package/lib/date-time-picker/date-time-picker.d.ts +4 -4
  213. package/lib/dial-pad/dial-pad.d.ts +6 -2
  214. package/lib/dialog/dialog.d.ts +0 -1
  215. package/lib/flag/definition.d.ts +3 -0
  216. package/lib/flag/flag.d.ts +8 -0
  217. package/lib/flag/flag.template.d.ts +3 -0
  218. package/lib/flag/index.d.ts +1 -0
  219. package/lib/icon/icon.d.ts +1 -2
  220. package/lib/menu/menu.d.ts +0 -1
  221. package/lib/option/option.d.ts +0 -1
  222. package/lib/rich-text-editor/rte/exports.d.ts +1 -0
  223. package/lib/rich-text-editor/rte/features/alignment.d.ts +1 -1
  224. package/lib/rich-text-editor/rte/features/character-count.d.ts +21 -0
  225. package/lib/rich-text-editor/rte/features/font-size-picker.d.ts +1 -1
  226. package/lib/rich-text-editor/rte/features/internal/basic-text-blocks.d.ts +1 -1
  227. package/lib/rich-text-editor/rte/features/keyboard-shortcuts.d.ts +1 -1
  228. package/lib/rich-text-editor/rte/features/text-color-picker.d.ts +1 -1
  229. package/lib/rich-text-editor/rte/public-interface.d.ts +6 -0
  230. package/lib/searchable-select/option-tag.d.ts +3 -2
  231. package/lib/searchable-select/searchable-select.d.ts +3 -1
  232. package/lib/table/definition.d.ts +2 -1
  233. package/lib/table/table-header-cell.d.ts +3 -0
  234. package/lib/table/table-sorting-button.d.ts +415 -0
  235. package/lib/table/table-sorting-button.template.d.ts +3 -0
  236. package/lib/tag-name-map.d.ts +2 -1
  237. package/lib/time-picker/time-picker.d.ts +2 -0
  238. package/locales/de-DE.cjs +5 -178
  239. package/locales/de-DE.js +3 -179
  240. package/locales/en-GB.cjs +5 -9
  241. package/locales/en-GB.js +3 -10
  242. package/locales/en-US.cjs +269 -2
  243. package/locales/en-US.js +266 -1
  244. package/locales/ja-JP.cjs +5 -171
  245. package/locales/ja-JP.js +3 -172
  246. package/locales/zh-CN.cjs +5 -172
  247. package/locales/zh-CN.js +3 -173
  248. package/menu/definition.cjs +5 -5
  249. package/menu/definition.js +1 -1
  250. package/menu/index.cjs +1 -1
  251. package/menu/index.js +2 -2
  252. package/menu-item/definition.cjs +6 -6
  253. package/menu-item/definition.js +1 -1
  254. package/menu-item/index.cjs +1 -1
  255. package/menu-item/index.js +2 -2
  256. package/nav/definition.cjs +1 -1
  257. package/nav/definition.js +1 -1
  258. package/nav-disclosure/definition.cjs +5 -5
  259. package/nav-disclosure/definition.js +2 -2
  260. package/nav-disclosure/index.cjs +4 -4
  261. package/nav-disclosure/index.js +13 -12
  262. package/nav-item/definition.cjs +5 -5
  263. package/nav-item/definition.js +2 -2
  264. package/nav-item/index.cjs +2 -2
  265. package/nav-item/index.js +12 -11
  266. package/note/definition.cjs +5 -5
  267. package/note/definition.js +2 -2
  268. package/note/index.cjs +3 -3
  269. package/note/index.js +11 -10
  270. package/number-field/definition.cjs +5 -5
  271. package/number-field/definition.js +2 -2
  272. package/number-field/index.cjs +4 -4
  273. package/number-field/index.js +29 -28
  274. package/option/definition.cjs +5 -5
  275. package/option/definition.js +2 -2
  276. package/option/index.cjs +1 -1
  277. package/option/index.js +2 -2
  278. package/package.json +9 -10
  279. package/pagination/definition.cjs +5 -5
  280. package/pagination/definition.js +2 -2
  281. package/pagination/index.cjs +3 -3
  282. package/pagination/index.js +16 -16
  283. package/popover/definition.cjs +5 -5
  284. package/popover/definition.js +2 -2
  285. package/popover/index.cjs +7 -7
  286. package/popover/index.js +12 -11
  287. package/popup/definition.cjs +4 -4
  288. package/popup/definition.js +1 -1
  289. package/popup/index.cjs +1 -1
  290. package/popup/index.js +1 -1
  291. package/progress/definition.cjs +1 -1
  292. package/progress/definition.js +1 -1
  293. package/progress/index.cjs +2 -2
  294. package/progress/index.js +5 -5
  295. package/radio/definition.cjs +1 -1
  296. package/radio/definition.js +1 -1
  297. package/radio/index.cjs +1 -1
  298. package/radio/index.js +1 -1
  299. package/radio-group/definition.cjs +5 -5
  300. package/radio-group/definition.js +2 -2
  301. package/radio-group/index.cjs +4 -4
  302. package/radio-group/index.js +11 -11
  303. package/range-slider/definition.cjs +5 -5
  304. package/range-slider/definition.js +2 -2
  305. package/range-slider/index.cjs +4 -4
  306. package/range-slider/index.js +39 -36
  307. package/rich-text-editor/definition.cjs +32 -31
  308. package/rich-text-editor/definition.js +3 -3
  309. package/rich-text-editor/index.cjs +13 -13
  310. package/rich-text-editor/index.js +1887 -1830
  311. package/rich-text-view/definition.cjs +1 -1
  312. package/rich-text-view/definition.js +1 -1
  313. package/rich-text-view/index.cjs +1 -1
  314. package/rich-text-view/index.js +8 -8
  315. package/searchable-select/definition.cjs +4 -4
  316. package/searchable-select/definition.js +2 -2
  317. package/searchable-select/index.cjs +15 -13
  318. package/searchable-select/index.js +75 -72
  319. package/select/definition.cjs +5 -5
  320. package/select/definition.js +2 -2
  321. package/select/index.cjs +1 -1
  322. package/select/index.js +2 -2
  323. package/selectable-box/definition.cjs +5 -5
  324. package/selectable-box/definition.js +2 -2
  325. package/selectable-box/index.cjs +7 -7
  326. package/selectable-box/index.js +12 -12
  327. package/shared/foundation/test-utilities/fixture.d.ts +1 -1
  328. package/shared/icon/utils.d.ts +1 -0
  329. package/shared/localization/Locale.d.ts +2 -0
  330. package/shared/patterns/linkable.d.ts +1 -1
  331. package/shared/picker-field/mixins/calendar-picker.d.ts +1 -0
  332. package/shared/picker-field/mixins/calendar-picker.template.d.ts +1 -0
  333. package/shared/picker-field/mixins/min-max-calendar-picker.d.ts +1 -0
  334. package/shared/picker-field/mixins/single-date-picker.d.ts +1 -0
  335. package/shared/picker-field/mixins/single-value-picker.d.ts +1 -0
  336. package/shared/picker-field/mixins/time-selection-picker.d.ts +1 -0
  337. package/shared/picker-field/mixins/time-selection-picker.template.d.ts +2 -0
  338. package/shared/picker-field/picker-field.d.ts +2 -0
  339. package/side-drawer/definition.cjs +1 -1
  340. package/side-drawer/definition.js +1 -1
  341. package/simple-color-picker/definition.cjs +5 -5
  342. package/simple-color-picker/definition.js +2 -2
  343. package/simple-color-picker/index.cjs +3 -3
  344. package/simple-color-picker/index.js +15 -14
  345. package/slider/definition.cjs +5 -5
  346. package/slider/definition.js +1 -1
  347. package/slider/index.cjs +1 -1
  348. package/slider/index.js +1 -1
  349. package/split-button/definition.cjs +5 -5
  350. package/split-button/definition.js +2 -2
  351. package/split-button/index.cjs +6 -6
  352. package/split-button/index.js +17 -16
  353. package/status/definition.cjs +5 -5
  354. package/status/definition.js +2 -2
  355. package/status/index.cjs +2 -2
  356. package/status/index.js +11 -10
  357. package/switch/definition.cjs +5 -5
  358. package/switch/definition.js +2 -2
  359. package/switch/index.cjs +4 -4
  360. package/switch/index.js +11 -10
  361. package/tab/definition.cjs +5 -5
  362. package/tab/definition.js +2 -2
  363. package/tab/index.cjs +1 -1
  364. package/tab/index.js +2 -2
  365. package/tab-panel/definition.cjs +1 -1
  366. package/tab-panel/definition.js +1 -1
  367. package/tab-panel/index.cjs +1 -1
  368. package/tab-panel/index.js +1 -1
  369. package/table/definition.cjs +4 -1
  370. package/table/definition.js +3 -2
  371. package/table/index.cjs +19 -10
  372. package/table/index.js +70 -21
  373. package/tabs/definition.cjs +6 -6
  374. package/tabs/definition.js +2 -2
  375. package/tabs/index.cjs +2 -2
  376. package/tabs/index.js +5 -5
  377. package/tag/definition.cjs +5 -5
  378. package/tag/definition.js +2 -2
  379. package/tag/index.cjs +8 -8
  380. package/tag/index.js +14 -13
  381. package/tag-group/definition.cjs +1 -1
  382. package/tag-group/definition.js +1 -1
  383. package/tag-group/index.cjs +3 -3
  384. package/tag-group/index.js +5 -5
  385. package/text-area/definition.cjs +5 -5
  386. package/text-area/definition.js +2 -2
  387. package/text-area/index.cjs +2 -2
  388. package/text-area/index.js +13 -13
  389. package/text-field/definition.cjs +5 -5
  390. package/text-field/definition.js +2 -2
  391. package/text-field/index.cjs +1 -1
  392. package/text-field/index.js +2 -2
  393. package/time-picker/definition.cjs +4 -4
  394. package/time-picker/definition.js +2 -2
  395. package/time-picker/index.cjs +1 -1
  396. package/time-picker/index.js +2 -2
  397. package/toggletip/definition.cjs +5 -5
  398. package/toggletip/definition.js +2 -2
  399. package/toggletip/index.cjs +1 -1
  400. package/toggletip/index.js +2 -2
  401. package/tooltip/definition.cjs +5 -5
  402. package/tooltip/definition.js +2 -2
  403. package/tooltip/index.cjs +1 -1
  404. package/tooltip/index.js +2 -2
  405. package/tree-item/definition.cjs +5 -5
  406. package/tree-item/definition.js +2 -2
  407. package/tree-item/index.cjs +1 -1
  408. package/tree-item/index.js +2 -2
  409. package/tree-view/definition.cjs +5 -5
  410. package/tree-view/definition.js +2 -2
  411. package/tree-view/index.cjs +3 -3
  412. package/tree-view/index.js +18 -18
  413. package/unbundled/button.cjs +2 -2
  414. package/unbundled/button.js +2 -2
  415. package/unbundled/calendar-picker.template.cjs +4347 -9
  416. package/unbundled/calendar-picker.template.js +4345 -7
  417. package/unbundled/chunk.cjs +0 -22
  418. package/unbundled/definition11.cjs +6 -0
  419. package/unbundled/definition11.js +6 -0
  420. package/unbundled/definition13.cjs +1 -8
  421. package/unbundled/definition13.js +1 -8
  422. package/unbundled/definition14.cjs +3 -2
  423. package/unbundled/definition14.js +3 -2
  424. package/unbundled/definition2.cjs +5 -75
  425. package/unbundled/definition2.js +1 -71
  426. package/unbundled/definition21.cjs +1 -2
  427. package/unbundled/definition21.js +1 -2
  428. package/unbundled/definition22.cjs +7 -2
  429. package/unbundled/definition22.js +7 -2
  430. package/unbundled/definition24.cjs +98 -979
  431. package/unbundled/definition24.js +93 -974
  432. package/unbundled/definition25.cjs +37 -322
  433. package/unbundled/definition25.js +33 -318
  434. package/unbundled/definition26.cjs +317 -91
  435. package/unbundled/definition26.js +313 -87
  436. package/unbundled/definition27.cjs +94 -192
  437. package/unbundled/definition27.js +91 -183
  438. package/unbundled/definition28.cjs +388 -395
  439. package/unbundled/definition28.js +388 -395
  440. package/unbundled/definition29.cjs +189 -110
  441. package/unbundled/definition29.js +180 -107
  442. package/unbundled/definition30.cjs +520 -36
  443. package/unbundled/definition30.js +519 -35
  444. package/unbundled/definition31.cjs +2 -1189
  445. package/unbundled/definition31.js +1 -1188
  446. package/unbundled/definition32.cjs +207 -1835
  447. package/unbundled/definition32.js +203 -1807
  448. package/unbundled/definition33.cjs +85 -228
  449. package/unbundled/definition33.js +82 -165
  450. package/unbundled/definition34.cjs +1887 -25
  451. package/unbundled/definition34.js +1857 -24
  452. package/unbundled/definition35.cjs +315 -121
  453. package/unbundled/definition35.js +236 -114
  454. package/unbundled/definition36.cjs +25 -405
  455. package/unbundled/definition36.js +22 -397
  456. package/unbundled/definition37.cjs +49 -140
  457. package/unbundled/definition37.js +46 -137
  458. package/unbundled/definition38.cjs +346 -329
  459. package/unbundled/definition38.js +343 -326
  460. package/unbundled/definition39.cjs +183 -234
  461. package/unbundled/definition39.js +181 -232
  462. package/unbundled/definition40.cjs +377 -47
  463. package/unbundled/definition40.js +372 -42
  464. package/unbundled/definition41.cjs +256 -57
  465. package/unbundled/definition41.js +255 -56
  466. package/unbundled/definition42.cjs +45 -421
  467. package/unbundled/definition42.js +41 -417
  468. package/unbundled/definition43.cjs +63 -49
  469. package/unbundled/definition43.js +61 -47
  470. package/unbundled/definition44.cjs +438 -30
  471. package/unbundled/definition44.js +434 -25
  472. package/unbundled/definition45.cjs +46 -84
  473. package/unbundled/definition45.js +43 -81
  474. package/unbundled/definition46.cjs +29 -54
  475. package/unbundled/definition46.js +24 -50
  476. package/unbundled/definition47.cjs +93 -21
  477. package/unbundled/definition47.js +91 -16
  478. package/unbundled/definition48.cjs +49 -33
  479. package/unbundled/definition48.js +46 -30
  480. package/unbundled/definition49.cjs +22 -347
  481. package/unbundled/definition49.js +16 -344
  482. package/unbundled/definition50.cjs +34 -211
  483. package/unbundled/definition50.js +30 -207
  484. package/unbundled/definition51.cjs +282 -242
  485. package/unbundled/definition51.js +275 -235
  486. package/unbundled/definition52.cjs +211 -51
  487. package/unbundled/definition52.js +209 -48
  488. package/unbundled/definition53.cjs +275 -131
  489. package/unbundled/definition53.js +272 -127
  490. package/unbundled/definition54.cjs +50 -261
  491. package/unbundled/definition54.js +48 -260
  492. package/unbundled/definition55.cjs +126 -443
  493. package/unbundled/definition55.js +123 -441
  494. package/unbundled/definition56.cjs +238 -12669
  495. package/unbundled/definition56.js +232 -12506
  496. package/unbundled/definition57.cjs +408 -729
  497. package/unbundled/definition57.js +406 -727
  498. package/unbundled/definition58.cjs +3619 -106
  499. package/unbundled/definition58.js +3449 -99
  500. package/unbundled/definition59.cjs +625 -868
  501. package/unbundled/definition59.js +620 -863
  502. package/unbundled/definition60.cjs +106 -108
  503. package/unbundled/definition60.js +102 -104
  504. package/unbundled/definition61.cjs +1040 -71
  505. package/unbundled/definition61.js +1035 -65
  506. package/unbundled/definition62.cjs +105 -169
  507. package/unbundled/definition62.js +101 -165
  508. package/unbundled/definition63.cjs +70 -113
  509. package/unbundled/definition63.js +65 -109
  510. package/unbundled/definition64.cjs +181 -53
  511. package/unbundled/definition64.js +178 -50
  512. package/unbundled/definition65.cjs +109 -76
  513. package/unbundled/definition65.js +109 -75
  514. package/unbundled/definition66.cjs +58 -21
  515. package/unbundled/definition66.js +55 -15
  516. package/unbundled/definition67.cjs +81 -74
  517. package/unbundled/definition67.js +79 -73
  518. package/unbundled/definition68.cjs +19 -344
  519. package/unbundled/definition68.js +14 -335
  520. package/unbundled/definition69.cjs +88 -26
  521. package/unbundled/definition69.js +85 -22
  522. package/unbundled/definition7.cjs +18 -3
  523. package/unbundled/definition7.js +18 -3
  524. package/unbundled/definition70.cjs +330 -111
  525. package/unbundled/definition70.js +320 -108
  526. package/unbundled/definition71.cjs +26 -271
  527. package/unbundled/definition71.js +21 -267
  528. package/unbundled/definition72.cjs +134 -28
  529. package/unbundled/definition72.js +125 -26
  530. package/unbundled/definition73.cjs +245 -113
  531. package/unbundled/definition73.js +242 -104
  532. package/unbundled/definition74.cjs +28 -212
  533. package/unbundled/definition74.js +26 -202
  534. package/unbundled/definition75.cjs +120 -52190
  535. package/unbundled/definition75.js +112 -52188
  536. package/unbundled/definition76.cjs +232 -0
  537. package/unbundled/definition76.js +213 -0
  538. package/unbundled/definition77.cjs +533 -0
  539. package/unbundled/definition77.js +513 -0
  540. package/unbundled/listbox.cjs +1 -1
  541. package/unbundled/listbox.js +1 -1
  542. package/unbundled/localized.cjs +2 -2
  543. package/unbundled/localized.js +1 -1
  544. package/unbundled/numberConverter.cjs +91 -0
  545. package/unbundled/numberConverter.js +74 -0
  546. package/unbundled/picker-field.template.cjs +3 -1
  547. package/unbundled/picker-field.template.js +3 -1
  548. package/unbundled/slottable-request.cjs +2 -3168
  549. package/unbundled/slottable-request.js +3 -3097
  550. package/unbundled/time-selection-picker.template.cjs +1 -1
  551. package/unbundled/time-selection-picker.template.js +1 -1
  552. package/unbundled/utils.cjs +1439 -0
  553. package/unbundled/utils.js +1428 -0
  554. package/unbundled/vivid-element.cjs +1 -1
  555. package/unbundled/vivid-element.js +1 -1
  556. package/video-player/definition.cjs +1 -1
  557. package/video-player/definition.js +1 -1
  558. package/video-player/index.cjs +3 -3
  559. package/video-player/index.js +9 -9
  560. package/vivid.api.json +860 -409
  561. package/unbundled/chunk.js +0 -33
  562. package/unbundled/en-US.cjs +0 -447
  563. package/unbundled/en-US.js +0 -443
  564. /package/{lib/icon/icon.placeholder.d.ts → shared/icon/icon-placeholder.d.ts} +0 -0
@@ -1,3096 +1,5 @@
1
- //#region ../../node_modules/.pnpm/orderedmap@2.1.1/node_modules/orderedmap/dist/index.js
2
- function OrderedMap(content) {
3
- this.content = content;
4
- }
5
- OrderedMap.prototype = {
6
- constructor: OrderedMap,
7
- find: function(key) {
8
- for (var i = 0; i < this.content.length; i += 2) if (this.content[i] === key) return i;
9
- return -1;
10
- },
11
- get: function(key) {
12
- var found = this.find(key);
13
- return found == -1 ? void 0 : this.content[found + 1];
14
- },
15
- update: function(key, value, newKey) {
16
- var self = newKey && newKey != key ? this.remove(newKey) : this;
17
- var found = self.find(key), content = self.content.slice();
18
- if (found == -1) content.push(newKey || key, value);
19
- else {
20
- content[found + 1] = value;
21
- if (newKey) content[found] = newKey;
22
- }
23
- return new OrderedMap(content);
24
- },
25
- remove: function(key) {
26
- var found = this.find(key);
27
- if (found == -1) return this;
28
- var content = this.content.slice();
29
- content.splice(found, 2);
30
- return new OrderedMap(content);
31
- },
32
- addToStart: function(key, value) {
33
- return new OrderedMap([key, value].concat(this.remove(key).content));
34
- },
35
- addToEnd: function(key, value) {
36
- var content = this.remove(key).content.slice();
37
- content.push(key, value);
38
- return new OrderedMap(content);
39
- },
40
- addBefore: function(place, key, value) {
41
- var without = this.remove(key), content = without.content.slice();
42
- var found = without.find(place);
43
- content.splice(found == -1 ? content.length : found, 0, key, value);
44
- return new OrderedMap(content);
45
- },
46
- forEach: function(f) {
47
- for (var i = 0; i < this.content.length; i += 2) f(this.content[i], this.content[i + 1]);
48
- },
49
- prepend: function(map) {
50
- map = OrderedMap.from(map);
51
- if (!map.size) return this;
52
- return new OrderedMap(map.content.concat(this.subtract(map).content));
53
- },
54
- append: function(map) {
55
- map = OrderedMap.from(map);
56
- if (!map.size) return this;
57
- return new OrderedMap(this.subtract(map).content.concat(map.content));
58
- },
59
- subtract: function(map) {
60
- var result = this;
61
- map = OrderedMap.from(map);
62
- for (var i = 0; i < map.content.length; i += 2) result = result.remove(map.content[i]);
63
- return result;
64
- },
65
- toObject: function() {
66
- var result = {};
67
- this.forEach(function(key, value) {
68
- result[key] = value;
69
- });
70
- return result;
71
- },
72
- get size() {
73
- return this.content.length >> 1;
74
- }
75
- };
76
- OrderedMap.from = function(value) {
77
- if (value instanceof OrderedMap) return value;
78
- var content = [];
79
- if (value) for (var prop in value) content.push(prop, value[prop]);
80
- return new OrderedMap(content);
81
- };
82
- //#endregion
83
- //#region ../../node_modules/.pnpm/prosemirror-model@1.25.4/node_modules/prosemirror-model/dist/index.js
84
- function findDiffStart(a, b, pos) {
85
- for (let i = 0;; i++) {
86
- if (i == a.childCount || i == b.childCount) return a.childCount == b.childCount ? null : pos;
87
- let childA = a.child(i), childB = b.child(i);
88
- if (childA == childB) {
89
- pos += childA.nodeSize;
90
- continue;
91
- }
92
- if (!childA.sameMarkup(childB)) return pos;
93
- if (childA.isText && childA.text != childB.text) {
94
- for (let j = 0; childA.text[j] == childB.text[j]; j++) pos++;
95
- return pos;
96
- }
97
- if (childA.content.size || childB.content.size) {
98
- let inner = findDiffStart(childA.content, childB.content, pos + 1);
99
- if (inner != null) return inner;
100
- }
101
- pos += childA.nodeSize;
102
- }
103
- }
104
- function findDiffEnd(a, b, posA, posB) {
105
- for (let iA = a.childCount, iB = b.childCount;;) {
106
- if (iA == 0 || iB == 0) return iA == iB ? null : {
107
- a: posA,
108
- b: posB
109
- };
110
- let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
111
- if (childA == childB) {
112
- posA -= size;
113
- posB -= size;
114
- continue;
115
- }
116
- if (!childA.sameMarkup(childB)) return {
117
- a: posA,
118
- b: posB
119
- };
120
- if (childA.isText && childA.text != childB.text) {
121
- let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
122
- while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
123
- same++;
124
- posA--;
125
- posB--;
126
- }
127
- return {
128
- a: posA,
129
- b: posB
130
- };
131
- }
132
- if (childA.content.size || childB.content.size) {
133
- let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
134
- if (inner) return inner;
135
- }
136
- posA -= size;
137
- posB -= size;
138
- }
139
- }
140
- /**
141
- A fragment represents a node's collection of child nodes.
142
-
143
- Like nodes, fragments are persistent data structures, and you
144
- should not mutate them or their content. Rather, you create new
145
- instances whenever needed. The API tries to make this easy.
146
- */
147
- var Fragment = class Fragment {
148
- /**
149
- @internal
150
- */
151
- constructor(content, size) {
152
- this.content = content;
153
- this.size = size || 0;
154
- if (size == null) for (let i = 0; i < content.length; i++) this.size += content[i].nodeSize;
155
- }
156
- /**
157
- Invoke a callback for all descendant nodes between the given two
158
- positions (relative to start of this fragment). Doesn't descend
159
- into a node when the callback returns `false`.
160
- */
161
- nodesBetween(from, to, f, nodeStart = 0, parent) {
162
- for (let i = 0, pos = 0; pos < to; i++) {
163
- let child = this.content[i], end = pos + child.nodeSize;
164
- if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
165
- let start = pos + 1;
166
- child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
167
- }
168
- pos = end;
169
- }
170
- }
171
- /**
172
- Call the given callback for every descendant node. `pos` will be
173
- relative to the start of the fragment. The callback may return
174
- `false` to prevent traversal of a given node's children.
175
- */
176
- descendants(f) {
177
- this.nodesBetween(0, this.size, f);
178
- }
179
- /**
180
- Extract the text between `from` and `to`. See the same method on
181
- [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
182
- */
183
- textBetween(from, to, blockSeparator, leafText) {
184
- let text = "", first = true;
185
- this.nodesBetween(from, to, (node, pos) => {
186
- let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : "";
187
- if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) if (first) first = false;
188
- else text += blockSeparator;
189
- text += nodeText;
190
- }, 0);
191
- return text;
192
- }
193
- /**
194
- Create a new fragment containing the combined content of this
195
- fragment and the other.
196
- */
197
- append(other) {
198
- if (!other.size) return this;
199
- if (!this.size) return other;
200
- let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
201
- if (last.isText && last.sameMarkup(first)) {
202
- content[content.length - 1] = last.withText(last.text + first.text);
203
- i = 1;
204
- }
205
- for (; i < other.content.length; i++) content.push(other.content[i]);
206
- return new Fragment(content, this.size + other.size);
207
- }
208
- /**
209
- Cut out the sub-fragment between the two given positions.
210
- */
211
- cut(from, to = this.size) {
212
- if (from == 0 && to == this.size) return this;
213
- let result = [], size = 0;
214
- if (to > from) for (let i = 0, pos = 0; pos < to; i++) {
215
- let child = this.content[i], end = pos + child.nodeSize;
216
- if (end > from) {
217
- if (pos < from || end > to) if (child.isText) child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
218
- else child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
219
- result.push(child);
220
- size += child.nodeSize;
221
- }
222
- pos = end;
223
- }
224
- return new Fragment(result, size);
225
- }
226
- /**
227
- @internal
228
- */
229
- cutByIndex(from, to) {
230
- if (from == to) return Fragment.empty;
231
- if (from == 0 && to == this.content.length) return this;
232
- return new Fragment(this.content.slice(from, to));
233
- }
234
- /**
235
- Create a new fragment in which the node at the given index is
236
- replaced by the given node.
237
- */
238
- replaceChild(index, node) {
239
- let current = this.content[index];
240
- if (current == node) return this;
241
- let copy = this.content.slice();
242
- let size = this.size + node.nodeSize - current.nodeSize;
243
- copy[index] = node;
244
- return new Fragment(copy, size);
245
- }
246
- /**
247
- Create a new fragment by prepending the given node to this
248
- fragment.
249
- */
250
- addToStart(node) {
251
- return new Fragment([node].concat(this.content), this.size + node.nodeSize);
252
- }
253
- /**
254
- Create a new fragment by appending the given node to this
255
- fragment.
256
- */
257
- addToEnd(node) {
258
- return new Fragment(this.content.concat(node), this.size + node.nodeSize);
259
- }
260
- /**
261
- Compare this fragment to another one.
262
- */
263
- eq(other) {
264
- if (this.content.length != other.content.length) return false;
265
- for (let i = 0; i < this.content.length; i++) if (!this.content[i].eq(other.content[i])) return false;
266
- return true;
267
- }
268
- /**
269
- The first child of the fragment, or `null` if it is empty.
270
- */
271
- get firstChild() {
272
- return this.content.length ? this.content[0] : null;
273
- }
274
- /**
275
- The last child of the fragment, or `null` if it is empty.
276
- */
277
- get lastChild() {
278
- return this.content.length ? this.content[this.content.length - 1] : null;
279
- }
280
- /**
281
- The number of child nodes in this fragment.
282
- */
283
- get childCount() {
284
- return this.content.length;
285
- }
286
- /**
287
- Get the child node at the given index. Raise an error when the
288
- index is out of range.
289
- */
290
- child(index) {
291
- let found = this.content[index];
292
- if (!found) throw new RangeError("Index " + index + " out of range for " + this);
293
- return found;
294
- }
295
- /**
296
- Get the child node at the given index, if it exists.
297
- */
298
- maybeChild(index) {
299
- return this.content[index] || null;
300
- }
301
- /**
302
- Call `f` for every child node, passing the node, its offset
303
- into this parent node, and its index.
304
- */
305
- forEach(f) {
306
- for (let i = 0, p = 0; i < this.content.length; i++) {
307
- let child = this.content[i];
308
- f(child, p, i);
309
- p += child.nodeSize;
310
- }
311
- }
312
- /**
313
- Find the first position at which this fragment and another
314
- fragment differ, or `null` if they are the same.
315
- */
316
- findDiffStart(other, pos = 0) {
317
- return findDiffStart(this, other, pos);
318
- }
319
- /**
320
- Find the first position, searching from the end, at which this
321
- fragment and the given fragment differ, or `null` if they are
322
- the same. Since this position will not be the same in both
323
- nodes, an object with two separate positions is returned.
324
- */
325
- findDiffEnd(other, pos = this.size, otherPos = other.size) {
326
- return findDiffEnd(this, other, pos, otherPos);
327
- }
328
- /**
329
- Find the index and inner offset corresponding to a given relative
330
- position in this fragment. The result object will be reused
331
- (overwritten) the next time the function is called. @internal
332
- */
333
- findIndex(pos) {
334
- if (pos == 0) return retIndex(0, pos);
335
- if (pos == this.size) return retIndex(this.content.length, pos);
336
- if (pos > this.size || pos < 0) throw new RangeError(`Position ${pos} outside of fragment (${this})`);
337
- for (let i = 0, curPos = 0;; i++) {
338
- let cur = this.child(i), end = curPos + cur.nodeSize;
339
- if (end >= pos) {
340
- if (end == pos) return retIndex(i + 1, end);
341
- return retIndex(i, curPos);
342
- }
343
- curPos = end;
344
- }
345
- }
346
- /**
347
- Return a debugging string that describes this fragment.
348
- */
349
- toString() {
350
- return "<" + this.toStringInner() + ">";
351
- }
352
- /**
353
- @internal
354
- */
355
- toStringInner() {
356
- return this.content.join(", ");
357
- }
358
- /**
359
- Create a JSON-serializeable representation of this fragment.
360
- */
361
- toJSON() {
362
- return this.content.length ? this.content.map((n) => n.toJSON()) : null;
363
- }
364
- /**
365
- Deserialize a fragment from its JSON representation.
366
- */
367
- static fromJSON(schema, value) {
368
- if (!value) return Fragment.empty;
369
- if (!Array.isArray(value)) throw new RangeError("Invalid input for Fragment.fromJSON");
370
- return new Fragment(value.map(schema.nodeFromJSON));
371
- }
372
- /**
373
- Build a fragment from an array of nodes. Ensures that adjacent
374
- text nodes with the same marks are joined together.
375
- */
376
- static fromArray(array) {
377
- if (!array.length) return Fragment.empty;
378
- let joined, size = 0;
379
- for (let i = 0; i < array.length; i++) {
380
- let node = array[i];
381
- size += node.nodeSize;
382
- if (i && node.isText && array[i - 1].sameMarkup(node)) {
383
- if (!joined) joined = array.slice(0, i);
384
- joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
385
- } else if (joined) joined.push(node);
386
- }
387
- return new Fragment(joined || array, size);
388
- }
389
- /**
390
- Create a fragment from something that can be interpreted as a
391
- set of nodes. For `null`, it returns the empty fragment. For a
392
- fragment, the fragment itself. For a node or array of nodes, a
393
- fragment containing those nodes.
394
- */
395
- static from(nodes) {
396
- if (!nodes) return Fragment.empty;
397
- if (nodes instanceof Fragment) return nodes;
398
- if (Array.isArray(nodes)) return this.fromArray(nodes);
399
- if (nodes.attrs) return new Fragment([nodes], nodes.nodeSize);
400
- throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
401
- }
402
- };
403
- /**
404
- An empty fragment. Intended to be reused whenever a node doesn't
405
- contain anything (rather than allocating a new empty fragment for
406
- each leaf node).
407
- */
408
- Fragment.empty = new Fragment([], 0);
409
- var found = {
410
- index: 0,
411
- offset: 0
412
- };
413
- function retIndex(index, offset) {
414
- found.index = index;
415
- found.offset = offset;
416
- return found;
417
- }
418
- function compareDeep(a, b) {
419
- if (a === b) return true;
420
- if (!(a && typeof a == "object") || !(b && typeof b == "object")) return false;
421
- let array = Array.isArray(a);
422
- if (Array.isArray(b) != array) return false;
423
- if (array) {
424
- if (a.length != b.length) return false;
425
- for (let i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false;
426
- } else {
427
- for (let p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false;
428
- for (let p in b) if (!(p in a)) return false;
429
- }
430
- return true;
431
- }
432
- /**
433
- A mark is a piece of information that can be attached to a node,
434
- such as it being emphasized, in code font, or a link. It has a
435
- type and optionally a set of attributes that provide further
436
- information (such as the target of the link). Marks are created
437
- through a `Schema`, which controls which types exist and which
438
- attributes they have.
439
- */
440
- var Mark = class Mark {
441
- /**
442
- @internal
443
- */
444
- constructor(type, attrs) {
445
- this.type = type;
446
- this.attrs = attrs;
447
- }
448
- /**
449
- Given a set of marks, create a new set which contains this one as
450
- well, in the right position. If this mark is already in the set,
451
- the set itself is returned. If any marks that are set to be
452
- [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
453
- those are replaced by this one.
454
- */
455
- addToSet(set) {
456
- let copy, placed = false;
457
- for (let i = 0; i < set.length; i++) {
458
- let other = set[i];
459
- if (this.eq(other)) return set;
460
- if (this.type.excludes(other.type)) {
461
- if (!copy) copy = set.slice(0, i);
462
- } else if (other.type.excludes(this.type)) return set;
463
- else {
464
- if (!placed && other.type.rank > this.type.rank) {
465
- if (!copy) copy = set.slice(0, i);
466
- copy.push(this);
467
- placed = true;
468
- }
469
- if (copy) copy.push(other);
470
- }
471
- }
472
- if (!copy) copy = set.slice();
473
- if (!placed) copy.push(this);
474
- return copy;
475
- }
476
- /**
477
- Remove this mark from the given set, returning a new set. If this
478
- mark is not in the set, the set itself is returned.
479
- */
480
- removeFromSet(set) {
481
- for (let i = 0; i < set.length; i++) if (this.eq(set[i])) return set.slice(0, i).concat(set.slice(i + 1));
482
- return set;
483
- }
484
- /**
485
- Test whether this mark is in the given set of marks.
486
- */
487
- isInSet(set) {
488
- for (let i = 0; i < set.length; i++) if (this.eq(set[i])) return true;
489
- return false;
490
- }
491
- /**
492
- Test whether this mark has the same type and attributes as
493
- another mark.
494
- */
495
- eq(other) {
496
- return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
497
- }
498
- /**
499
- Convert this mark to a JSON-serializeable representation.
500
- */
501
- toJSON() {
502
- let obj = { type: this.type.name };
503
- for (let _ in this.attrs) {
504
- obj.attrs = this.attrs;
505
- break;
506
- }
507
- return obj;
508
- }
509
- /**
510
- Deserialize a mark from JSON.
511
- */
512
- static fromJSON(schema, json) {
513
- if (!json) throw new RangeError("Invalid input for Mark.fromJSON");
514
- let type = schema.marks[json.type];
515
- if (!type) throw new RangeError(`There is no mark type ${json.type} in this schema`);
516
- let mark = type.create(json.attrs);
517
- type.checkAttrs(mark.attrs);
518
- return mark;
519
- }
520
- /**
521
- Test whether two sets of marks are identical.
522
- */
523
- static sameSet(a, b) {
524
- if (a == b) return true;
525
- if (a.length != b.length) return false;
526
- for (let i = 0; i < a.length; i++) if (!a[i].eq(b[i])) return false;
527
- return true;
528
- }
529
- /**
530
- Create a properly sorted mark set from null, a single mark, or an
531
- unsorted array of marks.
532
- */
533
- static setFrom(marks) {
534
- if (!marks || Array.isArray(marks) && marks.length == 0) return Mark.none;
535
- if (marks instanceof Mark) return [marks];
536
- let copy = marks.slice();
537
- copy.sort((a, b) => a.type.rank - b.type.rank);
538
- return copy;
539
- }
540
- };
541
- /**
542
- The empty set of marks.
543
- */
544
- Mark.none = [];
545
- /**
546
- Error type raised by [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) when
547
- given an invalid replacement.
548
- */
549
- var ReplaceError = class extends Error {};
550
- /**
551
- A slice represents a piece cut out of a larger document. It
552
- stores not only a fragment, but also the depth up to which nodes on
553
- both side are ‘open’ (cut through).
554
- */
555
- var Slice = class Slice {
556
- /**
557
- Create a slice. When specifying a non-zero open depth, you must
558
- make sure that there are nodes of at least that depth at the
559
- appropriate side of the fragment—i.e. if the fragment is an
560
- empty paragraph node, `openStart` and `openEnd` can't be greater
561
- than 1.
562
-
563
- It is not necessary for the content of open nodes to conform to
564
- the schema's content constraints, though it should be a valid
565
- start/end/middle for such a node, depending on which sides are
566
- open.
567
- */
568
- constructor(content, openStart, openEnd) {
569
- this.content = content;
570
- this.openStart = openStart;
571
- this.openEnd = openEnd;
572
- }
573
- /**
574
- The size this slice would add when inserted into a document.
575
- */
576
- get size() {
577
- return this.content.size - this.openStart - this.openEnd;
578
- }
579
- /**
580
- @internal
581
- */
582
- insertAt(pos, fragment) {
583
- let content = insertInto(this.content, pos + this.openStart, fragment);
584
- return content && new Slice(content, this.openStart, this.openEnd);
585
- }
586
- /**
587
- @internal
588
- */
589
- removeBetween(from, to) {
590
- return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
591
- }
592
- /**
593
- Tests whether this slice is equal to another slice.
594
- */
595
- eq(other) {
596
- return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
597
- }
598
- /**
599
- @internal
600
- */
601
- toString() {
602
- return this.content + "(" + this.openStart + "," + this.openEnd + ")";
603
- }
604
- /**
605
- Convert a slice to a JSON-serializable representation.
606
- */
607
- toJSON() {
608
- if (!this.content.size) return null;
609
- let json = { content: this.content.toJSON() };
610
- if (this.openStart > 0) json.openStart = this.openStart;
611
- if (this.openEnd > 0) json.openEnd = this.openEnd;
612
- return json;
613
- }
614
- /**
615
- Deserialize a slice from its JSON representation.
616
- */
617
- static fromJSON(schema, json) {
618
- if (!json) return Slice.empty;
619
- let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
620
- if (typeof openStart != "number" || typeof openEnd != "number") throw new RangeError("Invalid input for Slice.fromJSON");
621
- return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);
622
- }
623
- /**
624
- Create a slice from a fragment by taking the maximum possible
625
- open value on both side of the fragment.
626
- */
627
- static maxOpen(fragment, openIsolating = true) {
628
- let openStart = 0, openEnd = 0;
629
- for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild) openStart++;
630
- for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild) openEnd++;
631
- return new Slice(fragment, openStart, openEnd);
632
- }
633
- };
634
- /**
635
- The empty slice.
636
- */
637
- Slice.empty = new Slice(Fragment.empty, 0, 0);
638
- function removeRange(content, from, to) {
639
- let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
640
- let { index: indexTo, offset: offsetTo } = content.findIndex(to);
641
- if (offset == from || child.isText) {
642
- if (offsetTo != to && !content.child(indexTo).isText) throw new RangeError("Removing non-flat range");
643
- return content.cut(0, from).append(content.cut(to));
644
- }
645
- if (index != indexTo) throw new RangeError("Removing non-flat range");
646
- return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
647
- }
648
- function insertInto(content, dist, insert, parent) {
649
- let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
650
- if (offset == dist || child.isText) {
651
- if (parent && !parent.canReplace(index, index, insert)) return null;
652
- return content.cut(0, dist).append(insert).append(content.cut(dist));
653
- }
654
- let inner = insertInto(child.content, dist - offset - 1, insert, child);
655
- return inner && content.replaceChild(index, child.copy(inner));
656
- }
657
- function replace($from, $to, slice) {
658
- if (slice.openStart > $from.depth) throw new ReplaceError("Inserted content deeper than insertion position");
659
- if ($from.depth - slice.openStart != $to.depth - slice.openEnd) throw new ReplaceError("Inconsistent open depths");
660
- return replaceOuter($from, $to, slice, 0);
661
- }
662
- function replaceOuter($from, $to, slice, depth) {
663
- let index = $from.index(depth), node = $from.node(depth);
664
- if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
665
- let inner = replaceOuter($from, $to, slice, depth + 1);
666
- return node.copy(node.content.replaceChild(index, inner));
667
- } else if (!slice.content.size) return close(node, replaceTwoWay($from, $to, depth));
668
- else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
669
- let parent = $from.parent, content = parent.content;
670
- return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
671
- } else {
672
- let { start, end } = prepareSliceForReplace(slice, $from);
673
- return close(node, replaceThreeWay($from, start, end, $to, depth));
674
- }
675
- }
676
- function checkJoin(main, sub) {
677
- if (!sub.type.compatibleContent(main.type)) throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
678
- }
679
- function joinable($before, $after, depth) {
680
- let node = $before.node(depth);
681
- checkJoin(node, $after.node(depth));
682
- return node;
683
- }
684
- function addNode(child, target) {
685
- let last = target.length - 1;
686
- if (last >= 0 && child.isText && child.sameMarkup(target[last])) target[last] = child.withText(target[last].text + child.text);
687
- else target.push(child);
688
- }
689
- function addRange($start, $end, depth, target) {
690
- let node = ($end || $start).node(depth);
691
- let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
692
- if ($start) {
693
- startIndex = $start.index(depth);
694
- if ($start.depth > depth) startIndex++;
695
- else if ($start.textOffset) {
696
- addNode($start.nodeAfter, target);
697
- startIndex++;
698
- }
699
- }
700
- for (let i = startIndex; i < endIndex; i++) addNode(node.child(i), target);
701
- if ($end && $end.depth == depth && $end.textOffset) addNode($end.nodeBefore, target);
702
- }
703
- function close(node, content) {
704
- node.type.checkContent(content);
705
- return node.copy(content);
706
- }
707
- function replaceThreeWay($from, $start, $end, $to, depth) {
708
- let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
709
- let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
710
- let content = [];
711
- addRange(null, $from, depth, content);
712
- if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
713
- checkJoin(openStart, openEnd);
714
- addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
715
- } else {
716
- if (openStart) addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
717
- addRange($start, $end, depth, content);
718
- if (openEnd) addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
719
- }
720
- addRange($to, null, depth, content);
721
- return new Fragment(content);
722
- }
723
- function replaceTwoWay($from, $to, depth) {
724
- let content = [];
725
- addRange(null, $from, depth, content);
726
- if ($from.depth > depth) addNode(close(joinable($from, $to, depth + 1), replaceTwoWay($from, $to, depth + 1)), content);
727
- addRange($to, null, depth, content);
728
- return new Fragment(content);
729
- }
730
- function prepareSliceForReplace(slice, $along) {
731
- let extra = $along.depth - slice.openStart;
732
- let node = $along.node(extra).copy(slice.content);
733
- for (let i = extra - 1; i >= 0; i--) node = $along.node(i).copy(Fragment.from(node));
734
- return {
735
- start: node.resolveNoCache(slice.openStart + extra),
736
- end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
737
- };
738
- }
739
- /**
740
- You can [_resolve_](https://prosemirror.net/docs/ref/#model.Node.resolve) a position to get more
741
- information about it. Objects of this class represent such a
742
- resolved position, providing various pieces of context
743
- information, and some helper methods.
744
-
745
- Throughout this interface, methods that take an optional `depth`
746
- parameter will interpret undefined as `this.depth` and negative
747
- numbers as `this.depth + value`.
748
- */
749
- var ResolvedPos = class ResolvedPos {
750
- /**
751
- @internal
752
- */
753
- constructor(pos, path, parentOffset) {
754
- this.pos = pos;
755
- this.path = path;
756
- this.parentOffset = parentOffset;
757
- this.depth = path.length / 3 - 1;
758
- }
759
- /**
760
- @internal
761
- */
762
- resolveDepth(val) {
763
- if (val == null) return this.depth;
764
- if (val < 0) return this.depth + val;
765
- return val;
766
- }
767
- /**
768
- The parent node that the position points into. Note that even if
769
- a position points into a text node, that node is not considered
770
- the parent—text nodes are ‘flat’ in this model, and have no content.
771
- */
772
- get parent() {
773
- return this.node(this.depth);
774
- }
775
- /**
776
- The root node in which the position was resolved.
777
- */
778
- get doc() {
779
- return this.node(0);
780
- }
781
- /**
782
- The ancestor node at the given level. `p.node(p.depth)` is the
783
- same as `p.parent`.
784
- */
785
- node(depth) {
786
- return this.path[this.resolveDepth(depth) * 3];
787
- }
788
- /**
789
- The index into the ancestor at the given level. If this points
790
- at the 3rd node in the 2nd paragraph on the top level, for
791
- example, `p.index(0)` is 1 and `p.index(1)` is 2.
792
- */
793
- index(depth) {
794
- return this.path[this.resolveDepth(depth) * 3 + 1];
795
- }
796
- /**
797
- The index pointing after this position into the ancestor at the
798
- given level.
799
- */
800
- indexAfter(depth) {
801
- depth = this.resolveDepth(depth);
802
- return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
803
- }
804
- /**
805
- The (absolute) position at the start of the node at the given
806
- level.
807
- */
808
- start(depth) {
809
- depth = this.resolveDepth(depth);
810
- return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
811
- }
812
- /**
813
- The (absolute) position at the end of the node at the given
814
- level.
815
- */
816
- end(depth) {
817
- depth = this.resolveDepth(depth);
818
- return this.start(depth) + this.node(depth).content.size;
819
- }
820
- /**
821
- The (absolute) position directly before the wrapping node at the
822
- given level, or, when `depth` is `this.depth + 1`, the original
823
- position.
824
- */
825
- before(depth) {
826
- depth = this.resolveDepth(depth);
827
- if (!depth) throw new RangeError("There is no position before the top-level node");
828
- return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
829
- }
830
- /**
831
- The (absolute) position directly after the wrapping node at the
832
- given level, or the original position when `depth` is `this.depth + 1`.
833
- */
834
- after(depth) {
835
- depth = this.resolveDepth(depth);
836
- if (!depth) throw new RangeError("There is no position after the top-level node");
837
- return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
838
- }
839
- /**
840
- When this position points into a text node, this returns the
841
- distance between the position and the start of the text node.
842
- Will be zero for positions that point between nodes.
843
- */
844
- get textOffset() {
845
- return this.pos - this.path[this.path.length - 1];
846
- }
847
- /**
848
- Get the node directly after the position, if any. If the position
849
- points into a text node, only the part of that node after the
850
- position is returned.
851
- */
852
- get nodeAfter() {
853
- let parent = this.parent, index = this.index(this.depth);
854
- if (index == parent.childCount) return null;
855
- let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
856
- return dOff ? parent.child(index).cut(dOff) : child;
857
- }
858
- /**
859
- Get the node directly before the position, if any. If the
860
- position points into a text node, only the part of that node
861
- before the position is returned.
862
- */
863
- get nodeBefore() {
864
- let index = this.index(this.depth);
865
- let dOff = this.pos - this.path[this.path.length - 1];
866
- if (dOff) return this.parent.child(index).cut(0, dOff);
867
- return index == 0 ? null : this.parent.child(index - 1);
868
- }
869
- /**
870
- Get the position at the given index in the parent node at the
871
- given depth (which defaults to `this.depth`).
872
- */
873
- posAtIndex(index, depth) {
874
- depth = this.resolveDepth(depth);
875
- let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
876
- for (let i = 0; i < index; i++) pos += node.child(i).nodeSize;
877
- return pos;
878
- }
879
- /**
880
- Get the marks at this position, factoring in the surrounding
881
- marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
882
- position is at the start of a non-empty node, the marks of the
883
- node after it (if any) are returned.
884
- */
885
- marks() {
886
- let parent = this.parent, index = this.index();
887
- if (parent.content.size == 0) return Mark.none;
888
- if (this.textOffset) return parent.child(index).marks;
889
- let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
890
- if (!main) {
891
- let tmp = main;
892
- main = other;
893
- other = tmp;
894
- }
895
- let marks = main.marks;
896
- for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks))) marks = marks[i--].removeFromSet(marks);
897
- return marks;
898
- }
899
- /**
900
- Get the marks after the current position, if any, except those
901
- that are non-inclusive and not present at position `$end`. This
902
- is mostly useful for getting the set of marks to preserve after a
903
- deletion. Will return `null` if this position is at the end of
904
- its parent node or its parent node isn't a textblock (in which
905
- case no marks should be preserved).
906
- */
907
- marksAcross($end) {
908
- let after = this.parent.maybeChild(this.index());
909
- if (!after || !after.isInline) return null;
910
- let marks = after.marks, next = $end.parent.maybeChild($end.index());
911
- for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks))) marks = marks[i--].removeFromSet(marks);
912
- return marks;
913
- }
914
- /**
915
- The depth up to which this position and the given (non-resolved)
916
- position share the same parent nodes.
917
- */
918
- sharedDepth(pos) {
919
- for (let depth = this.depth; depth > 0; depth--) if (this.start(depth) <= pos && this.end(depth) >= pos) return depth;
920
- return 0;
921
- }
922
- /**
923
- Returns a range based on the place where this position and the
924
- given position diverge around block content. If both point into
925
- the same textblock, for example, a range around that textblock
926
- will be returned. If they point into different blocks, the range
927
- around those blocks in their shared ancestor is returned. You can
928
- pass in an optional predicate that will be called with a parent
929
- node to see if a range into that parent is acceptable.
930
- */
931
- blockRange(other = this, pred) {
932
- if (other.pos < this.pos) return other.blockRange(this);
933
- for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--) if (other.pos <= this.end(d) && (!pred || pred(this.node(d)))) return new NodeRange(this, other, d);
934
- return null;
935
- }
936
- /**
937
- Query whether the given position shares the same parent node.
938
- */
939
- sameParent(other) {
940
- return this.pos - this.parentOffset == other.pos - other.parentOffset;
941
- }
942
- /**
943
- Return the greater of this and the given position.
944
- */
945
- max(other) {
946
- return other.pos > this.pos ? other : this;
947
- }
948
- /**
949
- Return the smaller of this and the given position.
950
- */
951
- min(other) {
952
- return other.pos < this.pos ? other : this;
953
- }
954
- /**
955
- @internal
956
- */
957
- toString() {
958
- let str = "";
959
- for (let i = 1; i <= this.depth; i++) str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
960
- return str + ":" + this.parentOffset;
961
- }
962
- /**
963
- @internal
964
- */
965
- static resolve(doc, pos) {
966
- if (!(pos >= 0 && pos <= doc.content.size)) throw new RangeError("Position " + pos + " out of range");
967
- let path = [];
968
- let start = 0, parentOffset = pos;
969
- for (let node = doc;;) {
970
- let { index, offset } = node.content.findIndex(parentOffset);
971
- let rem = parentOffset - offset;
972
- path.push(node, index, start + offset);
973
- if (!rem) break;
974
- node = node.child(index);
975
- if (node.isText) break;
976
- parentOffset = rem - 1;
977
- start += offset + 1;
978
- }
979
- return new ResolvedPos(pos, path, parentOffset);
980
- }
981
- /**
982
- @internal
983
- */
984
- static resolveCached(doc, pos) {
985
- let cache = resolveCache.get(doc);
986
- if (cache) for (let i = 0; i < cache.elts.length; i++) {
987
- let elt = cache.elts[i];
988
- if (elt.pos == pos) return elt;
989
- }
990
- else resolveCache.set(doc, cache = new ResolveCache());
991
- let result = cache.elts[cache.i] = ResolvedPos.resolve(doc, pos);
992
- cache.i = (cache.i + 1) % resolveCacheSize;
993
- return result;
994
- }
995
- };
996
- var ResolveCache = class {
997
- constructor() {
998
- this.elts = [];
999
- this.i = 0;
1000
- }
1001
- };
1002
- var resolveCacheSize = 12, resolveCache = /* @__PURE__ */ new WeakMap();
1003
- /**
1004
- Represents a flat range of content, i.e. one that starts and
1005
- ends in the same node.
1006
- */
1007
- var NodeRange = class {
1008
- /**
1009
- Construct a node range. `$from` and `$to` should point into the
1010
- same node until at least the given `depth`, since a node range
1011
- denotes an adjacent set of nodes in a single parent node.
1012
- */
1013
- constructor($from, $to, depth) {
1014
- this.$from = $from;
1015
- this.$to = $to;
1016
- this.depth = depth;
1017
- }
1018
- /**
1019
- The position at the start of the range.
1020
- */
1021
- get start() {
1022
- return this.$from.before(this.depth + 1);
1023
- }
1024
- /**
1025
- The position at the end of the range.
1026
- */
1027
- get end() {
1028
- return this.$to.after(this.depth + 1);
1029
- }
1030
- /**
1031
- The parent node that the range points into.
1032
- */
1033
- get parent() {
1034
- return this.$from.node(this.depth);
1035
- }
1036
- /**
1037
- The start index of the range in the parent node.
1038
- */
1039
- get startIndex() {
1040
- return this.$from.index(this.depth);
1041
- }
1042
- /**
1043
- The end index of the range in the parent node.
1044
- */
1045
- get endIndex() {
1046
- return this.$to.indexAfter(this.depth);
1047
- }
1048
- };
1049
- var emptyAttrs = Object.create(null);
1050
- /**
1051
- This class represents a node in the tree that makes up a
1052
- ProseMirror document. So a document is an instance of `Node`, with
1053
- children that are also instances of `Node`.
1054
-
1055
- Nodes are persistent data structures. Instead of changing them, you
1056
- create new ones with the content you want. Old ones keep pointing
1057
- at the old document shape. This is made cheaper by sharing
1058
- structure between the old and new data as much as possible, which a
1059
- tree shape like this (without back pointers) makes easy.
1060
-
1061
- **Do not** directly mutate the properties of a `Node` object. See
1062
- [the guide](https://prosemirror.net/docs/guide/#doc) for more information.
1063
- */
1064
- var Node = class Node {
1065
- /**
1066
- @internal
1067
- */
1068
- constructor(type, attrs, content, marks = Mark.none) {
1069
- this.type = type;
1070
- this.attrs = attrs;
1071
- this.marks = marks;
1072
- this.content = content || Fragment.empty;
1073
- }
1074
- /**
1075
- The array of this node's child nodes.
1076
- */
1077
- get children() {
1078
- return this.content.content;
1079
- }
1080
- /**
1081
- The size of this node, as defined by the integer-based [indexing
1082
- scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
1083
- amount of characters. For other leaf nodes, it is one. For
1084
- non-leaf nodes, it is the size of the content plus two (the
1085
- start and end token).
1086
- */
1087
- get nodeSize() {
1088
- return this.isLeaf ? 1 : 2 + this.content.size;
1089
- }
1090
- /**
1091
- The number of children that the node has.
1092
- */
1093
- get childCount() {
1094
- return this.content.childCount;
1095
- }
1096
- /**
1097
- Get the child node at the given index. Raises an error when the
1098
- index is out of range.
1099
- */
1100
- child(index) {
1101
- return this.content.child(index);
1102
- }
1103
- /**
1104
- Get the child node at the given index, if it exists.
1105
- */
1106
- maybeChild(index) {
1107
- return this.content.maybeChild(index);
1108
- }
1109
- /**
1110
- Call `f` for every child node, passing the node, its offset
1111
- into this parent node, and its index.
1112
- */
1113
- forEach(f) {
1114
- this.content.forEach(f);
1115
- }
1116
- /**
1117
- Invoke a callback for all descendant nodes recursively between
1118
- the given two positions that are relative to start of this
1119
- node's content. The callback is invoked with the node, its
1120
- position relative to the original node (method receiver),
1121
- its parent node, and its child index. When the callback returns
1122
- false for a given node, that node's children will not be
1123
- recursed over. The last parameter can be used to specify a
1124
- starting position to count from.
1125
- */
1126
- nodesBetween(from, to, f, startPos = 0) {
1127
- this.content.nodesBetween(from, to, f, startPos, this);
1128
- }
1129
- /**
1130
- Call the given callback for every descendant node. Doesn't
1131
- descend into a node when the callback returns `false`.
1132
- */
1133
- descendants(f) {
1134
- this.nodesBetween(0, this.content.size, f);
1135
- }
1136
- /**
1137
- Concatenates all the text nodes found in this fragment and its
1138
- children.
1139
- */
1140
- get textContent() {
1141
- return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
1142
- }
1143
- /**
1144
- Get all text between positions `from` and `to`. When
1145
- `blockSeparator` is given, it will be inserted to separate text
1146
- from different block nodes. If `leafText` is given, it'll be
1147
- inserted for every non-text leaf node encountered, otherwise
1148
- [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
1149
- */
1150
- textBetween(from, to, blockSeparator, leafText) {
1151
- return this.content.textBetween(from, to, blockSeparator, leafText);
1152
- }
1153
- /**
1154
- Returns this node's first child, or `null` if there are no
1155
- children.
1156
- */
1157
- get firstChild() {
1158
- return this.content.firstChild;
1159
- }
1160
- /**
1161
- Returns this node's last child, or `null` if there are no
1162
- children.
1163
- */
1164
- get lastChild() {
1165
- return this.content.lastChild;
1166
- }
1167
- /**
1168
- Test whether two nodes represent the same piece of document.
1169
- */
1170
- eq(other) {
1171
- return this == other || this.sameMarkup(other) && this.content.eq(other.content);
1172
- }
1173
- /**
1174
- Compare the markup (type, attributes, and marks) of this node to
1175
- those of another. Returns `true` if both have the same markup.
1176
- */
1177
- sameMarkup(other) {
1178
- return this.hasMarkup(other.type, other.attrs, other.marks);
1179
- }
1180
- /**
1181
- Check whether this node's markup correspond to the given type,
1182
- attributes, and marks.
1183
- */
1184
- hasMarkup(type, attrs, marks) {
1185
- return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
1186
- }
1187
- /**
1188
- Create a new node with the same markup as this node, containing
1189
- the given content (or empty, if no content is given).
1190
- */
1191
- copy(content = null) {
1192
- if (content == this.content) return this;
1193
- return new Node(this.type, this.attrs, content, this.marks);
1194
- }
1195
- /**
1196
- Create a copy of this node, with the given set of marks instead
1197
- of the node's own marks.
1198
- */
1199
- mark(marks) {
1200
- return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks);
1201
- }
1202
- /**
1203
- Create a copy of this node with only the content between the
1204
- given positions. If `to` is not given, it defaults to the end of
1205
- the node.
1206
- */
1207
- cut(from, to = this.content.size) {
1208
- if (from == 0 && to == this.content.size) return this;
1209
- return this.copy(this.content.cut(from, to));
1210
- }
1211
- /**
1212
- Cut out the part of the document between the given positions, and
1213
- return it as a `Slice` object.
1214
- */
1215
- slice(from, to = this.content.size, includeParents = false) {
1216
- if (from == to) return Slice.empty;
1217
- let $from = this.resolve(from), $to = this.resolve(to);
1218
- let depth = includeParents ? 0 : $from.sharedDepth(to);
1219
- let start = $from.start(depth);
1220
- return new Slice($from.node(depth).content.cut($from.pos - start, $to.pos - start), $from.depth - depth, $to.depth - depth);
1221
- }
1222
- /**
1223
- Replace the part of the document between the given positions with
1224
- the given slice. The slice must 'fit', meaning its open sides
1225
- must be able to connect to the surrounding content, and its
1226
- content nodes must be valid children for the node they are placed
1227
- into. If any of this is violated, an error of type
1228
- [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
1229
- */
1230
- replace(from, to, slice) {
1231
- return replace(this.resolve(from), this.resolve(to), slice);
1232
- }
1233
- /**
1234
- Find the node directly after the given position.
1235
- */
1236
- nodeAt(pos) {
1237
- for (let node = this;;) {
1238
- let { index, offset } = node.content.findIndex(pos);
1239
- node = node.maybeChild(index);
1240
- if (!node) return null;
1241
- if (offset == pos || node.isText) return node;
1242
- pos -= offset + 1;
1243
- }
1244
- }
1245
- /**
1246
- Find the (direct) child node after the given offset, if any,
1247
- and return it along with its index and offset relative to this
1248
- node.
1249
- */
1250
- childAfter(pos) {
1251
- let { index, offset } = this.content.findIndex(pos);
1252
- return {
1253
- node: this.content.maybeChild(index),
1254
- index,
1255
- offset
1256
- };
1257
- }
1258
- /**
1259
- Find the (direct) child node before the given offset, if any,
1260
- and return it along with its index and offset relative to this
1261
- node.
1262
- */
1263
- childBefore(pos) {
1264
- if (pos == 0) return {
1265
- node: null,
1266
- index: 0,
1267
- offset: 0
1268
- };
1269
- let { index, offset } = this.content.findIndex(pos);
1270
- if (offset < pos) return {
1271
- node: this.content.child(index),
1272
- index,
1273
- offset
1274
- };
1275
- let node = this.content.child(index - 1);
1276
- return {
1277
- node,
1278
- index: index - 1,
1279
- offset: offset - node.nodeSize
1280
- };
1281
- }
1282
- /**
1283
- Resolve the given position in the document, returning an
1284
- [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
1285
- */
1286
- resolve(pos) {
1287
- return ResolvedPos.resolveCached(this, pos);
1288
- }
1289
- /**
1290
- @internal
1291
- */
1292
- resolveNoCache(pos) {
1293
- return ResolvedPos.resolve(this, pos);
1294
- }
1295
- /**
1296
- Test whether a given mark or mark type occurs in this document
1297
- between the two given positions.
1298
- */
1299
- rangeHasMark(from, to, type) {
1300
- let found = false;
1301
- if (to > from) this.nodesBetween(from, to, (node) => {
1302
- if (type.isInSet(node.marks)) found = true;
1303
- return !found;
1304
- });
1305
- return found;
1306
- }
1307
- /**
1308
- True when this is a block (non-inline node)
1309
- */
1310
- get isBlock() {
1311
- return this.type.isBlock;
1312
- }
1313
- /**
1314
- True when this is a textblock node, a block node with inline
1315
- content.
1316
- */
1317
- get isTextblock() {
1318
- return this.type.isTextblock;
1319
- }
1320
- /**
1321
- True when this node allows inline content.
1322
- */
1323
- get inlineContent() {
1324
- return this.type.inlineContent;
1325
- }
1326
- /**
1327
- True when this is an inline node (a text node or a node that can
1328
- appear among text).
1329
- */
1330
- get isInline() {
1331
- return this.type.isInline;
1332
- }
1333
- /**
1334
- True when this is a text node.
1335
- */
1336
- get isText() {
1337
- return this.type.isText;
1338
- }
1339
- /**
1340
- True when this is a leaf node.
1341
- */
1342
- get isLeaf() {
1343
- return this.type.isLeaf;
1344
- }
1345
- /**
1346
- True when this is an atom, i.e. when it does not have directly
1347
- editable content. This is usually the same as `isLeaf`, but can
1348
- be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
1349
- on a node's spec (typically used when the node is displayed as
1350
- an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
1351
- */
1352
- get isAtom() {
1353
- return this.type.isAtom;
1354
- }
1355
- /**
1356
- Return a string representation of this node for debugging
1357
- purposes.
1358
- */
1359
- toString() {
1360
- if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this);
1361
- let name = this.type.name;
1362
- if (this.content.size) name += "(" + this.content.toStringInner() + ")";
1363
- return wrapMarks(this.marks, name);
1364
- }
1365
- /**
1366
- Get the content match in this node at the given index.
1367
- */
1368
- contentMatchAt(index) {
1369
- let match = this.type.contentMatch.matchFragment(this.content, 0, index);
1370
- if (!match) throw new Error("Called contentMatchAt on a node with invalid content");
1371
- return match;
1372
- }
1373
- /**
1374
- Test whether replacing the range between `from` and `to` (by
1375
- child index) with the given replacement fragment (which defaults
1376
- to the empty fragment) would leave the node's content valid. You
1377
- can optionally pass `start` and `end` indices into the
1378
- replacement fragment.
1379
- */
1380
- canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {
1381
- let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
1382
- let two = one && one.matchFragment(this.content, to);
1383
- if (!two || !two.validEnd) return false;
1384
- for (let i = start; i < end; i++) if (!this.type.allowsMarks(replacement.child(i).marks)) return false;
1385
- return true;
1386
- }
1387
- /**
1388
- Test whether replacing the range `from` to `to` (by index) with
1389
- a node of the given type would leave the node's content valid.
1390
- */
1391
- canReplaceWith(from, to, type, marks) {
1392
- if (marks && !this.type.allowsMarks(marks)) return false;
1393
- let start = this.contentMatchAt(from).matchType(type);
1394
- let end = start && start.matchFragment(this.content, to);
1395
- return end ? end.validEnd : false;
1396
- }
1397
- /**
1398
- Test whether the given node's content could be appended to this
1399
- node. If that node is empty, this will only return true if there
1400
- is at least one node type that can appear in both nodes (to avoid
1401
- merging completely incompatible nodes).
1402
- */
1403
- canAppend(other) {
1404
- if (other.content.size) return this.canReplace(this.childCount, this.childCount, other.content);
1405
- else return this.type.compatibleContent(other.type);
1406
- }
1407
- /**
1408
- Check whether this node and its descendants conform to the
1409
- schema, and raise an exception when they do not.
1410
- */
1411
- check() {
1412
- this.type.checkContent(this.content);
1413
- this.type.checkAttrs(this.attrs);
1414
- let copy = Mark.none;
1415
- for (let i = 0; i < this.marks.length; i++) {
1416
- let mark = this.marks[i];
1417
- mark.type.checkAttrs(mark.attrs);
1418
- copy = mark.addToSet(copy);
1419
- }
1420
- if (!Mark.sameSet(copy, this.marks)) throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
1421
- this.content.forEach((node) => node.check());
1422
- }
1423
- /**
1424
- Return a JSON-serializeable representation of this node.
1425
- */
1426
- toJSON() {
1427
- let obj = { type: this.type.name };
1428
- for (let _ in this.attrs) {
1429
- obj.attrs = this.attrs;
1430
- break;
1431
- }
1432
- if (this.content.size) obj.content = this.content.toJSON();
1433
- if (this.marks.length) obj.marks = this.marks.map((n) => n.toJSON());
1434
- return obj;
1435
- }
1436
- /**
1437
- Deserialize a node from its JSON representation.
1438
- */
1439
- static fromJSON(schema, json) {
1440
- if (!json) throw new RangeError("Invalid input for Node.fromJSON");
1441
- let marks = void 0;
1442
- if (json.marks) {
1443
- if (!Array.isArray(json.marks)) throw new RangeError("Invalid mark data for Node.fromJSON");
1444
- marks = json.marks.map(schema.markFromJSON);
1445
- }
1446
- if (json.type == "text") {
1447
- if (typeof json.text != "string") throw new RangeError("Invalid text node in JSON");
1448
- return schema.text(json.text, marks);
1449
- }
1450
- let content = Fragment.fromJSON(schema, json.content);
1451
- let node = schema.nodeType(json.type).create(json.attrs, content, marks);
1452
- node.type.checkAttrs(node.attrs);
1453
- return node;
1454
- }
1455
- };
1456
- Node.prototype.text = void 0;
1457
- var TextNode = class TextNode extends Node {
1458
- /**
1459
- @internal
1460
- */
1461
- constructor(type, attrs, content, marks) {
1462
- super(type, attrs, null, marks);
1463
- if (!content) throw new RangeError("Empty text nodes are not allowed");
1464
- this.text = content;
1465
- }
1466
- toString() {
1467
- if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this);
1468
- return wrapMarks(this.marks, JSON.stringify(this.text));
1469
- }
1470
- get textContent() {
1471
- return this.text;
1472
- }
1473
- textBetween(from, to) {
1474
- return this.text.slice(from, to);
1475
- }
1476
- get nodeSize() {
1477
- return this.text.length;
1478
- }
1479
- mark(marks) {
1480
- return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks);
1481
- }
1482
- withText(text) {
1483
- if (text == this.text) return this;
1484
- return new TextNode(this.type, this.attrs, text, this.marks);
1485
- }
1486
- cut(from = 0, to = this.text.length) {
1487
- if (from == 0 && to == this.text.length) return this;
1488
- return this.withText(this.text.slice(from, to));
1489
- }
1490
- eq(other) {
1491
- return this.sameMarkup(other) && this.text == other.text;
1492
- }
1493
- toJSON() {
1494
- let base = super.toJSON();
1495
- base.text = this.text;
1496
- return base;
1497
- }
1498
- };
1499
- function wrapMarks(marks, str) {
1500
- for (let i = marks.length - 1; i >= 0; i--) str = marks[i].type.name + "(" + str + ")";
1501
- return str;
1502
- }
1503
- /**
1504
- Instances of this class represent a match state of a node type's
1505
- [content expression](https://prosemirror.net/docs/ref/#model.NodeSpec.content), and can be used to
1506
- find out whether further content matches here, and whether a given
1507
- position is a valid end of the node.
1508
- */
1509
- var ContentMatch = class ContentMatch {
1510
- /**
1511
- @internal
1512
- */
1513
- constructor(validEnd) {
1514
- this.validEnd = validEnd;
1515
- /**
1516
- @internal
1517
- */
1518
- this.next = [];
1519
- /**
1520
- @internal
1521
- */
1522
- this.wrapCache = [];
1523
- }
1524
- /**
1525
- @internal
1526
- */
1527
- static parse(string, nodeTypes) {
1528
- let stream = new TokenStream(string, nodeTypes);
1529
- if (stream.next == null) return ContentMatch.empty;
1530
- let expr = parseExpr(stream);
1531
- if (stream.next) stream.err("Unexpected trailing text");
1532
- let match = dfa(nfa(expr));
1533
- checkForDeadEnds(match, stream);
1534
- return match;
1535
- }
1536
- /**
1537
- Match a node type, returning a match after that node if
1538
- successful.
1539
- */
1540
- matchType(type) {
1541
- for (let i = 0; i < this.next.length; i++) if (this.next[i].type == type) return this.next[i].next;
1542
- return null;
1543
- }
1544
- /**
1545
- Try to match a fragment. Returns the resulting match when
1546
- successful.
1547
- */
1548
- matchFragment(frag, start = 0, end = frag.childCount) {
1549
- let cur = this;
1550
- for (let i = start; cur && i < end; i++) cur = cur.matchType(frag.child(i).type);
1551
- return cur;
1552
- }
1553
- /**
1554
- @internal
1555
- */
1556
- get inlineContent() {
1557
- return this.next.length != 0 && this.next[0].type.isInline;
1558
- }
1559
- /**
1560
- Get the first matching node type at this match position that can
1561
- be generated.
1562
- */
1563
- get defaultType() {
1564
- for (let i = 0; i < this.next.length; i++) {
1565
- let { type } = this.next[i];
1566
- if (!(type.isText || type.hasRequiredAttrs())) return type;
1567
- }
1568
- return null;
1569
- }
1570
- /**
1571
- @internal
1572
- */
1573
- compatible(other) {
1574
- for (let i = 0; i < this.next.length; i++) for (let j = 0; j < other.next.length; j++) if (this.next[i].type == other.next[j].type) return true;
1575
- return false;
1576
- }
1577
- /**
1578
- Try to match the given fragment, and if that fails, see if it can
1579
- be made to match by inserting nodes in front of it. When
1580
- successful, return a fragment of inserted nodes (which may be
1581
- empty if nothing had to be inserted). When `toEnd` is true, only
1582
- return a fragment if the resulting match goes to the end of the
1583
- content expression.
1584
- */
1585
- fillBefore(after, toEnd = false, startIndex = 0) {
1586
- let seen = [this];
1587
- function search(match, types) {
1588
- let finished = match.matchFragment(after, startIndex);
1589
- if (finished && (!toEnd || finished.validEnd)) return Fragment.from(types.map((tp) => tp.createAndFill()));
1590
- for (let i = 0; i < match.next.length; i++) {
1591
- let { type, next } = match.next[i];
1592
- if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
1593
- seen.push(next);
1594
- let found = search(next, types.concat(type));
1595
- if (found) return found;
1596
- }
1597
- }
1598
- return null;
1599
- }
1600
- return search(this, []);
1601
- }
1602
- /**
1603
- Find a set of wrapping node types that would allow a node of the
1604
- given type to appear at this position. The result may be empty
1605
- (when it fits directly) and will be null when no such wrapping
1606
- exists.
1607
- */
1608
- findWrapping(target) {
1609
- for (let i = 0; i < this.wrapCache.length; i += 2) if (this.wrapCache[i] == target) return this.wrapCache[i + 1];
1610
- let computed = this.computeWrapping(target);
1611
- this.wrapCache.push(target, computed);
1612
- return computed;
1613
- }
1614
- /**
1615
- @internal
1616
- */
1617
- computeWrapping(target) {
1618
- let seen = Object.create(null), active = [{
1619
- match: this,
1620
- type: null,
1621
- via: null
1622
- }];
1623
- while (active.length) {
1624
- let current = active.shift(), match = current.match;
1625
- if (match.matchType(target)) {
1626
- let result = [];
1627
- for (let obj = current; obj.type; obj = obj.via) result.push(obj.type);
1628
- return result.reverse();
1629
- }
1630
- for (let i = 0; i < match.next.length; i++) {
1631
- let { type, next } = match.next[i];
1632
- if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
1633
- active.push({
1634
- match: type.contentMatch,
1635
- type,
1636
- via: current
1637
- });
1638
- seen[type.name] = true;
1639
- }
1640
- }
1641
- }
1642
- return null;
1643
- }
1644
- /**
1645
- The number of outgoing edges this node has in the finite
1646
- automaton that describes the content expression.
1647
- */
1648
- get edgeCount() {
1649
- return this.next.length;
1650
- }
1651
- /**
1652
- Get the _n_​th outgoing edge from this node in the finite
1653
- automaton that describes the content expression.
1654
- */
1655
- edge(n) {
1656
- if (n >= this.next.length) throw new RangeError(`There's no ${n}th edge in this content match`);
1657
- return this.next[n];
1658
- }
1659
- /**
1660
- @internal
1661
- */
1662
- toString() {
1663
- let seen = [];
1664
- function scan(m) {
1665
- seen.push(m);
1666
- for (let i = 0; i < m.next.length; i++) if (seen.indexOf(m.next[i].next) == -1) scan(m.next[i].next);
1667
- }
1668
- scan(this);
1669
- return seen.map((m, i) => {
1670
- let out = i + (m.validEnd ? "*" : " ") + " ";
1671
- for (let i = 0; i < m.next.length; i++) out += (i ? ", " : "") + m.next[i].type.name + "->" + seen.indexOf(m.next[i].next);
1672
- return out;
1673
- }).join("\n");
1674
- }
1675
- };
1676
- /**
1677
- @internal
1678
- */
1679
- ContentMatch.empty = new ContentMatch(true);
1680
- var TokenStream = class {
1681
- constructor(string, nodeTypes) {
1682
- this.string = string;
1683
- this.nodeTypes = nodeTypes;
1684
- this.inline = null;
1685
- this.pos = 0;
1686
- this.tokens = string.split(/\s*(?=\b|\W|$)/);
1687
- if (this.tokens[this.tokens.length - 1] == "") this.tokens.pop();
1688
- if (this.tokens[0] == "") this.tokens.shift();
1689
- }
1690
- get next() {
1691
- return this.tokens[this.pos];
1692
- }
1693
- eat(tok) {
1694
- return this.next == tok && (this.pos++ || true);
1695
- }
1696
- err(str) {
1697
- throw new SyntaxError(str + " (in content expression '" + this.string + "')");
1698
- }
1699
- };
1700
- function parseExpr(stream) {
1701
- let exprs = [];
1702
- do
1703
- exprs.push(parseExprSeq(stream));
1704
- while (stream.eat("|"));
1705
- return exprs.length == 1 ? exprs[0] : {
1706
- type: "choice",
1707
- exprs
1708
- };
1709
- }
1710
- function parseExprSeq(stream) {
1711
- let exprs = [];
1712
- do
1713
- exprs.push(parseExprSubscript(stream));
1714
- while (stream.next && stream.next != ")" && stream.next != "|");
1715
- return exprs.length == 1 ? exprs[0] : {
1716
- type: "seq",
1717
- exprs
1718
- };
1719
- }
1720
- function parseExprSubscript(stream) {
1721
- let expr = parseExprAtom(stream);
1722
- for (;;) if (stream.eat("+")) expr = {
1723
- type: "plus",
1724
- expr
1725
- };
1726
- else if (stream.eat("*")) expr = {
1727
- type: "star",
1728
- expr
1729
- };
1730
- else if (stream.eat("?")) expr = {
1731
- type: "opt",
1732
- expr
1733
- };
1734
- else if (stream.eat("{")) expr = parseExprRange(stream, expr);
1735
- else break;
1736
- return expr;
1737
- }
1738
- function parseNum(stream) {
1739
- if (/\D/.test(stream.next)) stream.err("Expected number, got '" + stream.next + "'");
1740
- let result = Number(stream.next);
1741
- stream.pos++;
1742
- return result;
1743
- }
1744
- function parseExprRange(stream, expr) {
1745
- let min = parseNum(stream), max = min;
1746
- if (stream.eat(",")) if (stream.next != "}") max = parseNum(stream);
1747
- else max = -1;
1748
- if (!stream.eat("}")) stream.err("Unclosed braced range");
1749
- return {
1750
- type: "range",
1751
- min,
1752
- max,
1753
- expr
1754
- };
1755
- }
1756
- function resolveName(stream, name) {
1757
- let types = stream.nodeTypes, type = types[name];
1758
- if (type) return [type];
1759
- let result = [];
1760
- for (let typeName in types) {
1761
- let type = types[typeName];
1762
- if (type.isInGroup(name)) result.push(type);
1763
- }
1764
- if (result.length == 0) stream.err("No node type or group '" + name + "' found");
1765
- return result;
1766
- }
1767
- function parseExprAtom(stream) {
1768
- if (stream.eat("(")) {
1769
- let expr = parseExpr(stream);
1770
- if (!stream.eat(")")) stream.err("Missing closing paren");
1771
- return expr;
1772
- } else if (!/\W/.test(stream.next)) {
1773
- let exprs = resolveName(stream, stream.next).map((type) => {
1774
- if (stream.inline == null) stream.inline = type.isInline;
1775
- else if (stream.inline != type.isInline) stream.err("Mixing inline and block content");
1776
- return {
1777
- type: "name",
1778
- value: type
1779
- };
1780
- });
1781
- stream.pos++;
1782
- return exprs.length == 1 ? exprs[0] : {
1783
- type: "choice",
1784
- exprs
1785
- };
1786
- } else stream.err("Unexpected token '" + stream.next + "'");
1787
- }
1788
- function nfa(expr) {
1789
- let nfa = [[]];
1790
- connect(compile(expr, 0), node());
1791
- return nfa;
1792
- function node() {
1793
- return nfa.push([]) - 1;
1794
- }
1795
- function edge(from, to, term) {
1796
- let edge = {
1797
- term,
1798
- to
1799
- };
1800
- nfa[from].push(edge);
1801
- return edge;
1802
- }
1803
- function connect(edges, to) {
1804
- edges.forEach((edge) => edge.to = to);
1805
- }
1806
- function compile(expr, from) {
1807
- if (expr.type == "choice") return expr.exprs.reduce((out, expr) => out.concat(compile(expr, from)), []);
1808
- else if (expr.type == "seq") for (let i = 0;; i++) {
1809
- let next = compile(expr.exprs[i], from);
1810
- if (i == expr.exprs.length - 1) return next;
1811
- connect(next, from = node());
1812
- }
1813
- else if (expr.type == "star") {
1814
- let loop = node();
1815
- edge(from, loop);
1816
- connect(compile(expr.expr, loop), loop);
1817
- return [edge(loop)];
1818
- } else if (expr.type == "plus") {
1819
- let loop = node();
1820
- connect(compile(expr.expr, from), loop);
1821
- connect(compile(expr.expr, loop), loop);
1822
- return [edge(loop)];
1823
- } else if (expr.type == "opt") return [edge(from)].concat(compile(expr.expr, from));
1824
- else if (expr.type == "range") {
1825
- let cur = from;
1826
- for (let i = 0; i < expr.min; i++) {
1827
- let next = node();
1828
- connect(compile(expr.expr, cur), next);
1829
- cur = next;
1830
- }
1831
- if (expr.max == -1) connect(compile(expr.expr, cur), cur);
1832
- else for (let i = expr.min; i < expr.max; i++) {
1833
- let next = node();
1834
- edge(cur, next);
1835
- connect(compile(expr.expr, cur), next);
1836
- cur = next;
1837
- }
1838
- return [edge(cur)];
1839
- } else if (expr.type == "name") return [edge(from, void 0, expr.value)];
1840
- else throw new Error("Unknown expr type");
1841
- }
1842
- }
1843
- function cmp(a, b) {
1844
- return b - a;
1845
- }
1846
- function nullFrom(nfa, node) {
1847
- let result = [];
1848
- scan(node);
1849
- return result.sort(cmp);
1850
- function scan(node) {
1851
- let edges = nfa[node];
1852
- if (edges.length == 1 && !edges[0].term) return scan(edges[0].to);
1853
- result.push(node);
1854
- for (let i = 0; i < edges.length; i++) {
1855
- let { term, to } = edges[i];
1856
- if (!term && result.indexOf(to) == -1) scan(to);
1857
- }
1858
- }
1859
- }
1860
- function dfa(nfa) {
1861
- let labeled = Object.create(null);
1862
- return explore(nullFrom(nfa, 0));
1863
- function explore(states) {
1864
- let out = [];
1865
- states.forEach((node) => {
1866
- nfa[node].forEach(({ term, to }) => {
1867
- if (!term) return;
1868
- let set;
1869
- for (let i = 0; i < out.length; i++) if (out[i][0] == term) set = out[i][1];
1870
- nullFrom(nfa, to).forEach((node) => {
1871
- if (!set) out.push([term, set = []]);
1872
- if (set.indexOf(node) == -1) set.push(node);
1873
- });
1874
- });
1875
- });
1876
- let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa.length - 1) > -1);
1877
- for (let i = 0; i < out.length; i++) {
1878
- let states = out[i][1].sort(cmp);
1879
- state.next.push({
1880
- type: out[i][0],
1881
- next: labeled[states.join(",")] || explore(states)
1882
- });
1883
- }
1884
- return state;
1885
- }
1886
- }
1887
- function checkForDeadEnds(match, stream) {
1888
- for (let i = 0, work = [match]; i < work.length; i++) {
1889
- let state = work[i], dead = !state.validEnd, nodes = [];
1890
- for (let j = 0; j < state.next.length; j++) {
1891
- let { type, next } = state.next[j];
1892
- nodes.push(type.name);
1893
- if (dead && !(type.isText || type.hasRequiredAttrs())) dead = false;
1894
- if (work.indexOf(next) == -1) work.push(next);
1895
- }
1896
- if (dead) stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
1897
- }
1898
- }
1899
- function defaultAttrs(attrs) {
1900
- let defaults = Object.create(null);
1901
- for (let attrName in attrs) {
1902
- let attr = attrs[attrName];
1903
- if (!attr.hasDefault) return null;
1904
- defaults[attrName] = attr.default;
1905
- }
1906
- return defaults;
1907
- }
1908
- function computeAttrs(attrs, value) {
1909
- let built = Object.create(null);
1910
- for (let name in attrs) {
1911
- let given = value && value[name];
1912
- if (given === void 0) {
1913
- let attr = attrs[name];
1914
- if (attr.hasDefault) given = attr.default;
1915
- else throw new RangeError("No value supplied for attribute " + name);
1916
- }
1917
- built[name] = given;
1918
- }
1919
- return built;
1920
- }
1921
- function checkAttrs(attrs, values, type, name) {
1922
- for (let name in values) if (!(name in attrs)) throw new RangeError(`Unsupported attribute ${name} for ${type} of type ${name}`);
1923
- for (let name in attrs) {
1924
- let attr = attrs[name];
1925
- if (attr.validate) attr.validate(values[name]);
1926
- }
1927
- }
1928
- function initAttrs(typeName, attrs) {
1929
- let result = Object.create(null);
1930
- if (attrs) for (let name in attrs) result[name] = new Attribute(typeName, name, attrs[name]);
1931
- return result;
1932
- }
1933
- /**
1934
- Node types are objects allocated once per `Schema` and used to
1935
- [tag](https://prosemirror.net/docs/ref/#model.Node.type) `Node` instances. They contain information
1936
- about the node type, such as its name and what kind of node it
1937
- represents.
1938
- */
1939
- var NodeType = class NodeType {
1940
- /**
1941
- @internal
1942
- */
1943
- constructor(name, schema, spec) {
1944
- this.name = name;
1945
- this.schema = schema;
1946
- this.spec = spec;
1947
- /**
1948
- The set of marks allowed in this node. `null` means all marks
1949
- are allowed.
1950
- */
1951
- this.markSet = null;
1952
- this.groups = spec.group ? spec.group.split(" ") : [];
1953
- this.attrs = initAttrs(name, spec.attrs);
1954
- this.defaultAttrs = defaultAttrs(this.attrs);
1955
- this.contentMatch = null;
1956
- this.inlineContent = null;
1957
- this.isBlock = !(spec.inline || name == "text");
1958
- this.isText = name == "text";
1959
- }
1960
- /**
1961
- True if this is an inline type.
1962
- */
1963
- get isInline() {
1964
- return !this.isBlock;
1965
- }
1966
- /**
1967
- True if this is a textblock type, a block that contains inline
1968
- content.
1969
- */
1970
- get isTextblock() {
1971
- return this.isBlock && this.inlineContent;
1972
- }
1973
- /**
1974
- True for node types that allow no content.
1975
- */
1976
- get isLeaf() {
1977
- return this.contentMatch == ContentMatch.empty;
1978
- }
1979
- /**
1980
- True when this node is an atom, i.e. when it does not have
1981
- directly editable content.
1982
- */
1983
- get isAtom() {
1984
- return this.isLeaf || !!this.spec.atom;
1985
- }
1986
- /**
1987
- Return true when this node type is part of the given
1988
- [group](https://prosemirror.net/docs/ref/#model.NodeSpec.group).
1989
- */
1990
- isInGroup(group) {
1991
- return this.groups.indexOf(group) > -1;
1992
- }
1993
- /**
1994
- The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.
1995
- */
1996
- get whitespace() {
1997
- return this.spec.whitespace || (this.spec.code ? "pre" : "normal");
1998
- }
1999
- /**
2000
- Tells you whether this node type has any required attributes.
2001
- */
2002
- hasRequiredAttrs() {
2003
- for (let n in this.attrs) if (this.attrs[n].isRequired) return true;
2004
- return false;
2005
- }
2006
- /**
2007
- Indicates whether this node allows some of the same content as
2008
- the given node type.
2009
- */
2010
- compatibleContent(other) {
2011
- return this == other || this.contentMatch.compatible(other.contentMatch);
2012
- }
2013
- /**
2014
- @internal
2015
- */
2016
- computeAttrs(attrs) {
2017
- if (!attrs && this.defaultAttrs) return this.defaultAttrs;
2018
- else return computeAttrs(this.attrs, attrs);
2019
- }
2020
- /**
2021
- Create a `Node` of this type. The given attributes are
2022
- checked and defaulted (you can pass `null` to use the type's
2023
- defaults entirely, if no required attributes exist). `content`
2024
- may be a `Fragment`, a node, an array of nodes, or
2025
- `null`. Similarly `marks` may be `null` to default to the empty
2026
- set of marks.
2027
- */
2028
- create(attrs = null, content, marks) {
2029
- if (this.isText) throw new Error("NodeType.create can't construct text nodes");
2030
- return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
2031
- }
2032
- /**
2033
- Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
2034
- against the node type's content restrictions, and throw an error
2035
- if it doesn't match.
2036
- */
2037
- createChecked(attrs = null, content, marks) {
2038
- content = Fragment.from(content);
2039
- this.checkContent(content);
2040
- return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
2041
- }
2042
- /**
2043
- Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
2044
- necessary to add nodes to the start or end of the given fragment
2045
- to make it fit the node. If no fitting wrapping can be found,
2046
- return null. Note that, due to the fact that required nodes can
2047
- always be created, this will always succeed if you pass null or
2048
- `Fragment.empty` as content.
2049
- */
2050
- createAndFill(attrs = null, content, marks) {
2051
- attrs = this.computeAttrs(attrs);
2052
- content = Fragment.from(content);
2053
- if (content.size) {
2054
- let before = this.contentMatch.fillBefore(content);
2055
- if (!before) return null;
2056
- content = before.append(content);
2057
- }
2058
- let matched = this.contentMatch.matchFragment(content);
2059
- let after = matched && matched.fillBefore(Fragment.empty, true);
2060
- if (!after) return null;
2061
- return new Node(this, attrs, content.append(after), Mark.setFrom(marks));
2062
- }
2063
- /**
2064
- Returns true if the given fragment is valid content for this node
2065
- type.
2066
- */
2067
- validContent(content) {
2068
- let result = this.contentMatch.matchFragment(content);
2069
- if (!result || !result.validEnd) return false;
2070
- for (let i = 0; i < content.childCount; i++) if (!this.allowsMarks(content.child(i).marks)) return false;
2071
- return true;
2072
- }
2073
- /**
2074
- Throws a RangeError if the given fragment is not valid content for this
2075
- node type.
2076
- @internal
2077
- */
2078
- checkContent(content) {
2079
- if (!this.validContent(content)) throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
2080
- }
2081
- /**
2082
- @internal
2083
- */
2084
- checkAttrs(attrs) {
2085
- checkAttrs(this.attrs, attrs, "node", this.name);
2086
- }
2087
- /**
2088
- Check whether the given mark type is allowed in this node.
2089
- */
2090
- allowsMarkType(markType) {
2091
- return this.markSet == null || this.markSet.indexOf(markType) > -1;
2092
- }
2093
- /**
2094
- Test whether the given set of marks are allowed in this node.
2095
- */
2096
- allowsMarks(marks) {
2097
- if (this.markSet == null) return true;
2098
- for (let i = 0; i < marks.length; i++) if (!this.allowsMarkType(marks[i].type)) return false;
2099
- return true;
2100
- }
2101
- /**
2102
- Removes the marks that are not allowed in this node from the given set.
2103
- */
2104
- allowedMarks(marks) {
2105
- if (this.markSet == null) return marks;
2106
- let copy;
2107
- for (let i = 0; i < marks.length; i++) if (!this.allowsMarkType(marks[i].type)) {
2108
- if (!copy) copy = marks.slice(0, i);
2109
- } else if (copy) copy.push(marks[i]);
2110
- return !copy ? marks : copy.length ? copy : Mark.none;
2111
- }
2112
- /**
2113
- @internal
2114
- */
2115
- static compile(nodes, schema) {
2116
- let result = Object.create(null);
2117
- nodes.forEach((name, spec) => result[name] = new NodeType(name, schema, spec));
2118
- let topType = schema.spec.topNode || "doc";
2119
- if (!result[topType]) throw new RangeError("Schema is missing its top node type ('" + topType + "')");
2120
- if (!result.text) throw new RangeError("Every schema needs a 'text' type");
2121
- for (let _ in result.text.attrs) throw new RangeError("The text node type should not have attributes");
2122
- return result;
2123
- }
2124
- };
2125
- function validateType(typeName, attrName, type) {
2126
- let types = type.split("|");
2127
- return (value) => {
2128
- let name = value === null ? "null" : typeof value;
2129
- if (types.indexOf(name) < 0) throw new RangeError(`Expected value of type ${types} for attribute ${attrName} on type ${typeName}, got ${name}`);
2130
- };
2131
- }
2132
- var Attribute = class {
2133
- constructor(typeName, attrName, options) {
2134
- this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default");
2135
- this.default = options.default;
2136
- this.validate = typeof options.validate == "string" ? validateType(typeName, attrName, options.validate) : options.validate;
2137
- }
2138
- get isRequired() {
2139
- return !this.hasDefault;
2140
- }
2141
- };
2142
- /**
2143
- Like nodes, marks (which are associated with nodes to signify
2144
- things like emphasis or being part of a link) are
2145
- [tagged](https://prosemirror.net/docs/ref/#model.Mark.type) with type objects, which are
2146
- instantiated once per `Schema`.
2147
- */
2148
- var MarkType = class MarkType {
2149
- /**
2150
- @internal
2151
- */
2152
- constructor(name, rank, schema, spec) {
2153
- this.name = name;
2154
- this.rank = rank;
2155
- this.schema = schema;
2156
- this.spec = spec;
2157
- this.attrs = initAttrs(name, spec.attrs);
2158
- this.excluded = null;
2159
- let defaults = defaultAttrs(this.attrs);
2160
- this.instance = defaults ? new Mark(this, defaults) : null;
2161
- }
2162
- /**
2163
- Create a mark of this type. `attrs` may be `null` or an object
2164
- containing only some of the mark's attributes. The others, if
2165
- they have defaults, will be added.
2166
- */
2167
- create(attrs = null) {
2168
- if (!attrs && this.instance) return this.instance;
2169
- return new Mark(this, computeAttrs(this.attrs, attrs));
2170
- }
2171
- /**
2172
- @internal
2173
- */
2174
- static compile(marks, schema) {
2175
- let result = Object.create(null), rank = 0;
2176
- marks.forEach((name, spec) => result[name] = new MarkType(name, rank++, schema, spec));
2177
- return result;
2178
- }
2179
- /**
2180
- When there is a mark of this type in the given set, a new set
2181
- without it is returned. Otherwise, the input set is returned.
2182
- */
2183
- removeFromSet(set) {
2184
- for (var i = 0; i < set.length; i++) if (set[i].type == this) {
2185
- set = set.slice(0, i).concat(set.slice(i + 1));
2186
- i--;
2187
- }
2188
- return set;
2189
- }
2190
- /**
2191
- Tests whether there is a mark of this type in the given set.
2192
- */
2193
- isInSet(set) {
2194
- for (let i = 0; i < set.length; i++) if (set[i].type == this) return set[i];
2195
- }
2196
- /**
2197
- @internal
2198
- */
2199
- checkAttrs(attrs) {
2200
- checkAttrs(this.attrs, attrs, "mark", this.name);
2201
- }
2202
- /**
2203
- Queries whether a given mark type is
2204
- [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
2205
- */
2206
- excludes(other) {
2207
- return this.excluded.indexOf(other) > -1;
2208
- }
2209
- };
2210
- /**
2211
- A document schema. Holds [node](https://prosemirror.net/docs/ref/#model.NodeType) and [mark
2212
- type](https://prosemirror.net/docs/ref/#model.MarkType) objects for the nodes and marks that may
2213
- occur in conforming documents, and provides functionality for
2214
- creating and deserializing such documents.
2215
-
2216
- When given, the type parameters provide the names of the nodes and
2217
- marks in this schema.
2218
- */
2219
- var Schema = class {
2220
- /**
2221
- Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
2222
- */
2223
- constructor(spec) {
2224
- /**
2225
- The [linebreak
2226
- replacement](https://prosemirror.net/docs/ref/#model.NodeSpec.linebreakReplacement) node defined
2227
- in this schema, if any.
2228
- */
2229
- this.linebreakReplacement = null;
2230
- /**
2231
- An object for storing whatever values modules may want to
2232
- compute and cache per schema. (If you want to store something
2233
- in it, try to use property names unlikely to clash.)
2234
- */
2235
- this.cached = Object.create(null);
2236
- let instanceSpec = this.spec = {};
2237
- for (let prop in spec) instanceSpec[prop] = spec[prop];
2238
- instanceSpec.nodes = OrderedMap.from(spec.nodes), instanceSpec.marks = OrderedMap.from(spec.marks || {}), this.nodes = NodeType.compile(this.spec.nodes, this);
2239
- this.marks = MarkType.compile(this.spec.marks, this);
2240
- let contentExprCache = Object.create(null);
2241
- for (let prop in this.nodes) {
2242
- if (prop in this.marks) throw new RangeError(prop + " can not be both a node and a mark");
2243
- let type = this.nodes[prop], contentExpr = type.spec.content || "", markExpr = type.spec.marks;
2244
- type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));
2245
- type.inlineContent = type.contentMatch.inlineContent;
2246
- if (type.spec.linebreakReplacement) {
2247
- if (this.linebreakReplacement) throw new RangeError("Multiple linebreak nodes defined");
2248
- if (!type.isInline || !type.isLeaf) throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");
2249
- this.linebreakReplacement = type;
2250
- }
2251
- type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null;
2252
- }
2253
- for (let prop in this.marks) {
2254
- let type = this.marks[prop], excl = type.spec.excludes;
2255
- type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
2256
- }
2257
- this.nodeFromJSON = (json) => Node.fromJSON(this, json);
2258
- this.markFromJSON = (json) => Mark.fromJSON(this, json);
2259
- this.topNodeType = this.nodes[this.spec.topNode || "doc"];
2260
- this.cached.wrappings = Object.create(null);
2261
- }
2262
- /**
2263
- Create a node in this schema. The `type` may be a string or a
2264
- `NodeType` instance. Attributes will be extended with defaults,
2265
- `content` may be a `Fragment`, `null`, a `Node`, or an array of
2266
- nodes.
2267
- */
2268
- node(type, attrs = null, content, marks) {
2269
- if (typeof type == "string") type = this.nodeType(type);
2270
- else if (!(type instanceof NodeType)) throw new RangeError("Invalid node type: " + type);
2271
- else if (type.schema != this) throw new RangeError("Node type from different schema used (" + type.name + ")");
2272
- return type.createChecked(attrs, content, marks);
2273
- }
2274
- /**
2275
- Create a text node in the schema. Empty text nodes are not
2276
- allowed.
2277
- */
2278
- text(text, marks) {
2279
- let type = this.nodes.text;
2280
- return new TextNode(type, type.defaultAttrs, text, Mark.setFrom(marks));
2281
- }
2282
- /**
2283
- Create a mark with the given type and attributes.
2284
- */
2285
- mark(type, attrs) {
2286
- if (typeof type == "string") type = this.marks[type];
2287
- return type.create(attrs);
2288
- }
2289
- /**
2290
- @internal
2291
- */
2292
- nodeType(name) {
2293
- let found = this.nodes[name];
2294
- if (!found) throw new RangeError("Unknown node type: " + name);
2295
- return found;
2296
- }
2297
- };
2298
- function gatherMarks(schema, marks) {
2299
- let found = [];
2300
- for (let i = 0; i < marks.length; i++) {
2301
- let name = marks[i], mark = schema.marks[name], ok = mark;
2302
- if (mark) found.push(mark);
2303
- else for (let prop in schema.marks) {
2304
- let mark = schema.marks[prop];
2305
- if (name == "_" || mark.spec.group && mark.spec.group.split(" ").indexOf(name) > -1) found.push(ok = mark);
2306
- }
2307
- if (!ok) throw new SyntaxError("Unknown mark type: '" + marks[i] + "'");
2308
- }
2309
- return found;
2310
- }
2311
- function isTagRule(rule) {
2312
- return rule.tag != null;
2313
- }
2314
- function isStyleRule(rule) {
2315
- return rule.style != null;
2316
- }
2317
- /**
2318
- A DOM parser represents a strategy for parsing DOM content into a
2319
- ProseMirror document conforming to a given schema. Its behavior is
2320
- defined by an array of [rules](https://prosemirror.net/docs/ref/#model.ParseRule).
2321
- */
2322
- var DOMParser = class DOMParser {
2323
- /**
2324
- Create a parser that targets the given schema, using the given
2325
- parsing rules.
2326
- */
2327
- constructor(schema, rules) {
2328
- this.schema = schema;
2329
- this.rules = rules;
2330
- /**
2331
- @internal
2332
- */
2333
- this.tags = [];
2334
- /**
2335
- @internal
2336
- */
2337
- this.styles = [];
2338
- let matchedStyles = this.matchedStyles = [];
2339
- rules.forEach((rule) => {
2340
- if (isTagRule(rule)) this.tags.push(rule);
2341
- else if (isStyleRule(rule)) {
2342
- let prop = /[^=]*/.exec(rule.style)[0];
2343
- if (matchedStyles.indexOf(prop) < 0) matchedStyles.push(prop);
2344
- this.styles.push(rule);
2345
- }
2346
- });
2347
- this.normalizeLists = !this.tags.some((r) => {
2348
- if (!/^(ul|ol)\b/.test(r.tag) || !r.node) return false;
2349
- let node = schema.nodes[r.node];
2350
- return node.contentMatch.matchType(node);
2351
- });
2352
- }
2353
- /**
2354
- Parse a document from the content of a DOM node.
2355
- */
2356
- parse(dom, options = {}) {
2357
- let context = new ParseContext(this, options, false);
2358
- context.addAll(dom, Mark.none, options.from, options.to);
2359
- return context.finish();
2360
- }
2361
- /**
2362
- Parses the content of the given DOM node, like
2363
- [`parse`](https://prosemirror.net/docs/ref/#model.DOMParser.parse), and takes the same set of
2364
- options. But unlike that method, which produces a whole node,
2365
- this one returns a slice that is open at the sides, meaning that
2366
- the schema constraints aren't applied to the start of nodes to
2367
- the left of the input and the end of nodes at the end.
2368
- */
2369
- parseSlice(dom, options = {}) {
2370
- let context = new ParseContext(this, options, true);
2371
- context.addAll(dom, Mark.none, options.from, options.to);
2372
- return Slice.maxOpen(context.finish());
2373
- }
2374
- /**
2375
- @internal
2376
- */
2377
- matchTag(dom, context, after) {
2378
- for (let i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) {
2379
- let rule = this.tags[i];
2380
- if (matches(dom, rule.tag) && (rule.namespace === void 0 || dom.namespaceURI == rule.namespace) && (!rule.context || context.matchesContext(rule.context))) {
2381
- if (rule.getAttrs) {
2382
- let result = rule.getAttrs(dom);
2383
- if (result === false) continue;
2384
- rule.attrs = result || void 0;
2385
- }
2386
- return rule;
2387
- }
2388
- }
2389
- }
2390
- /**
2391
- @internal
2392
- */
2393
- matchStyle(prop, value, context, after) {
2394
- for (let i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) {
2395
- let rule = this.styles[i], style = rule.style;
2396
- if (style.indexOf(prop) != 0 || rule.context && !context.matchesContext(rule.context) || style.length > prop.length && (style.charCodeAt(prop.length) != 61 || style.slice(prop.length + 1) != value)) continue;
2397
- if (rule.getAttrs) {
2398
- let result = rule.getAttrs(value);
2399
- if (result === false) continue;
2400
- rule.attrs = result || void 0;
2401
- }
2402
- return rule;
2403
- }
2404
- }
2405
- /**
2406
- @internal
2407
- */
2408
- static schemaRules(schema) {
2409
- let result = [];
2410
- function insert(rule) {
2411
- let priority = rule.priority == null ? 50 : rule.priority, i = 0;
2412
- for (; i < result.length; i++) {
2413
- let next = result[i];
2414
- if ((next.priority == null ? 50 : next.priority) < priority) break;
2415
- }
2416
- result.splice(i, 0, rule);
2417
- }
2418
- for (let name in schema.marks) {
2419
- let rules = schema.marks[name].spec.parseDOM;
2420
- if (rules) rules.forEach((rule) => {
2421
- insert(rule = copy(rule));
2422
- if (!(rule.mark || rule.ignore || rule.clearMark)) rule.mark = name;
2423
- });
2424
- }
2425
- for (let name in schema.nodes) {
2426
- let rules = schema.nodes[name].spec.parseDOM;
2427
- if (rules) rules.forEach((rule) => {
2428
- insert(rule = copy(rule));
2429
- if (!(rule.node || rule.ignore || rule.mark)) rule.node = name;
2430
- });
2431
- }
2432
- return result;
2433
- }
2434
- /**
2435
- Construct a DOM parser using the parsing rules listed in a
2436
- schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
2437
- [priority](https://prosemirror.net/docs/ref/#model.GenericParseRule.priority).
2438
- */
2439
- static fromSchema(schema) {
2440
- return schema.cached.domParser || (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema)));
2441
- }
2442
- };
2443
- var blockTags = {
2444
- address: true,
2445
- article: true,
2446
- aside: true,
2447
- blockquote: true,
2448
- canvas: true,
2449
- dd: true,
2450
- div: true,
2451
- dl: true,
2452
- fieldset: true,
2453
- figcaption: true,
2454
- figure: true,
2455
- footer: true,
2456
- form: true,
2457
- h1: true,
2458
- h2: true,
2459
- h3: true,
2460
- h4: true,
2461
- h5: true,
2462
- h6: true,
2463
- header: true,
2464
- hgroup: true,
2465
- hr: true,
2466
- li: true,
2467
- noscript: true,
2468
- ol: true,
2469
- output: true,
2470
- p: true,
2471
- pre: true,
2472
- section: true,
2473
- table: true,
2474
- tfoot: true,
2475
- ul: true
2476
- };
2477
- var ignoreTags = {
2478
- head: true,
2479
- noscript: true,
2480
- object: true,
2481
- script: true,
2482
- style: true,
2483
- title: true
2484
- };
2485
- var listTags = {
2486
- ol: true,
2487
- ul: true
2488
- };
2489
- var OPT_PRESERVE_WS = 1, OPT_PRESERVE_WS_FULL = 2, OPT_OPEN_LEFT = 4;
2490
- function wsOptionsFor(type, preserveWhitespace, base) {
2491
- if (preserveWhitespace != null) return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0);
2492
- return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT;
2493
- }
2494
- var NodeContext = class {
2495
- constructor(type, attrs, marks, solid, match, options) {
2496
- this.type = type;
2497
- this.attrs = attrs;
2498
- this.marks = marks;
2499
- this.solid = solid;
2500
- this.options = options;
2501
- this.content = [];
2502
- this.activeMarks = Mark.none;
2503
- this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch);
2504
- }
2505
- findWrapping(node) {
2506
- if (!this.match) {
2507
- if (!this.type) return [];
2508
- let fill = this.type.contentMatch.fillBefore(Fragment.from(node));
2509
- if (fill) this.match = this.type.contentMatch.matchFragment(fill);
2510
- else {
2511
- let start = this.type.contentMatch, wrap;
2512
- if (wrap = start.findWrapping(node.type)) {
2513
- this.match = start;
2514
- return wrap;
2515
- } else return null;
2516
- }
2517
- }
2518
- return this.match.findWrapping(node.type);
2519
- }
2520
- finish(openEnd) {
2521
- if (!(this.options & OPT_PRESERVE_WS)) {
2522
- let last = this.content[this.content.length - 1], m;
2523
- if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) {
2524
- let text = last;
2525
- if (last.text.length == m[0].length) this.content.pop();
2526
- else this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length));
2527
- }
2528
- }
2529
- let content = Fragment.from(this.content);
2530
- if (!openEnd && this.match) content = content.append(this.match.fillBefore(Fragment.empty, true));
2531
- return this.type ? this.type.create(this.attrs, content, this.marks) : content;
2532
- }
2533
- inlineContext(node) {
2534
- if (this.type) return this.type.inlineContent;
2535
- if (this.content.length) return this.content[0].isInline;
2536
- return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase());
2537
- }
2538
- };
2539
- var ParseContext = class {
2540
- constructor(parser, options, isOpen) {
2541
- this.parser = parser;
2542
- this.options = options;
2543
- this.isOpen = isOpen;
2544
- this.open = 0;
2545
- this.localPreserveWS = false;
2546
- let topNode = options.topNode, topContext;
2547
- let topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0);
2548
- if (topNode) topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, options.topMatch || topNode.type.contentMatch, topOptions);
2549
- else if (isOpen) topContext = new NodeContext(null, null, Mark.none, true, null, topOptions);
2550
- else topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions);
2551
- this.nodes = [topContext];
2552
- this.find = options.findPositions;
2553
- this.needsBlock = false;
2554
- }
2555
- get top() {
2556
- return this.nodes[this.open];
2557
- }
2558
- addDOM(dom, marks) {
2559
- if (dom.nodeType == 3) this.addTextNode(dom, marks);
2560
- else if (dom.nodeType == 1) this.addElement(dom, marks);
2561
- }
2562
- addTextNode(dom, marks) {
2563
- let value = dom.nodeValue;
2564
- let top = this.top, preserveWS = top.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0;
2565
- let { schema } = this.parser;
2566
- if (preserveWS === "full" || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) {
2567
- if (!preserveWS) {
2568
- value = value.replace(/[ \t\r\n\u000c]+/g, " ");
2569
- if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) {
2570
- let nodeBefore = top.content[top.content.length - 1];
2571
- let domNodeBefore = dom.previousSibling;
2572
- if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text)) value = value.slice(1);
2573
- }
2574
- } else if (preserveWS === "full") value = value.replace(/\r\n?/g, "\n");
2575
- else if (schema.linebreakReplacement && /[\r\n]/.test(value) && this.top.findWrapping(schema.linebreakReplacement.create())) {
2576
- let lines = value.split(/\r?\n|\r/);
2577
- for (let i = 0; i < lines.length; i++) {
2578
- if (i) this.insertNode(schema.linebreakReplacement.create(), marks, true);
2579
- if (lines[i]) this.insertNode(schema.text(lines[i]), marks, !/\S/.test(lines[i]));
2580
- }
2581
- value = "";
2582
- } else value = value.replace(/\r?\n|\r/g, " ");
2583
- if (value) this.insertNode(schema.text(value), marks, !/\S/.test(value));
2584
- this.findInText(dom);
2585
- } else this.findInside(dom);
2586
- }
2587
- addElement(dom, marks, matchAfter) {
2588
- let outerWS = this.localPreserveWS, top = this.top;
2589
- if (dom.tagName == "PRE" || /pre/.test(dom.style && dom.style.whiteSpace)) this.localPreserveWS = true;
2590
- let name = dom.nodeName.toLowerCase(), ruleID;
2591
- if (listTags.hasOwnProperty(name) && this.parser.normalizeLists) normalizeList(dom);
2592
- let rule = this.options.ruleFromNode && this.options.ruleFromNode(dom) || (ruleID = this.parser.matchTag(dom, this, matchAfter));
2593
- out: if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) {
2594
- this.findInside(dom);
2595
- this.ignoreFallback(dom, marks);
2596
- } else if (!rule || rule.skip || rule.closeParent) {
2597
- if (rule && rule.closeParent) this.open = Math.max(0, this.open - 1);
2598
- else if (rule && rule.skip.nodeType) dom = rule.skip;
2599
- let sync, oldNeedsBlock = this.needsBlock;
2600
- if (blockTags.hasOwnProperty(name)) {
2601
- if (top.content.length && top.content[0].isInline && this.open) {
2602
- this.open--;
2603
- top = this.top;
2604
- }
2605
- sync = true;
2606
- if (!top.type) this.needsBlock = true;
2607
- } else if (!dom.firstChild) {
2608
- this.leafFallback(dom, marks);
2609
- break out;
2610
- }
2611
- let innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks);
2612
- if (innerMarks) this.addAll(dom, innerMarks);
2613
- if (sync) this.sync(top);
2614
- this.needsBlock = oldNeedsBlock;
2615
- } else {
2616
- let innerMarks = this.readStyles(dom, marks);
2617
- if (innerMarks) this.addElementByRule(dom, rule, innerMarks, rule.consuming === false ? ruleID : void 0);
2618
- }
2619
- this.localPreserveWS = outerWS;
2620
- }
2621
- leafFallback(dom, marks) {
2622
- if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent) this.addTextNode(dom.ownerDocument.createTextNode("\n"), marks);
2623
- }
2624
- ignoreFallback(dom, marks) {
2625
- if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent)) this.findPlace(this.parser.schema.text("-"), marks, true);
2626
- }
2627
- readStyles(dom, marks) {
2628
- let styles = dom.style;
2629
- if (styles && styles.length) for (let i = 0; i < this.parser.matchedStyles.length; i++) {
2630
- let name = this.parser.matchedStyles[i], value = styles.getPropertyValue(name);
2631
- if (value) for (let after = void 0;;) {
2632
- let rule = this.parser.matchStyle(name, value, this, after);
2633
- if (!rule) break;
2634
- if (rule.ignore) return null;
2635
- if (rule.clearMark) marks = marks.filter((m) => !rule.clearMark(m));
2636
- else marks = marks.concat(this.parser.schema.marks[rule.mark].create(rule.attrs));
2637
- if (rule.consuming === false) after = rule;
2638
- else break;
2639
- }
2640
- }
2641
- return marks;
2642
- }
2643
- addElementByRule(dom, rule, marks, continueAfter) {
2644
- let sync, nodeType;
2645
- if (rule.node) {
2646
- nodeType = this.parser.schema.nodes[rule.node];
2647
- if (!nodeType.isLeaf) {
2648
- let inner = this.enter(nodeType, rule.attrs || null, marks, rule.preserveWhitespace);
2649
- if (inner) {
2650
- sync = true;
2651
- marks = inner;
2652
- }
2653
- } else if (!this.insertNode(nodeType.create(rule.attrs), marks, dom.nodeName == "BR")) this.leafFallback(dom, marks);
2654
- } else {
2655
- let markType = this.parser.schema.marks[rule.mark];
2656
- marks = marks.concat(markType.create(rule.attrs));
2657
- }
2658
- let startIn = this.top;
2659
- if (nodeType && nodeType.isLeaf) this.findInside(dom);
2660
- else if (continueAfter) this.addElement(dom, marks, continueAfter);
2661
- else if (rule.getContent) {
2662
- this.findInside(dom);
2663
- rule.getContent(dom, this.parser.schema).forEach((node) => this.insertNode(node, marks, false));
2664
- } else {
2665
- let contentDOM = dom;
2666
- if (typeof rule.contentElement == "string") contentDOM = dom.querySelector(rule.contentElement);
2667
- else if (typeof rule.contentElement == "function") contentDOM = rule.contentElement(dom);
2668
- else if (rule.contentElement) contentDOM = rule.contentElement;
2669
- this.findAround(dom, contentDOM, true);
2670
- this.addAll(contentDOM, marks);
2671
- this.findAround(dom, contentDOM, false);
2672
- }
2673
- if (sync && this.sync(startIn)) this.open--;
2674
- }
2675
- addAll(parent, marks, startIndex, endIndex) {
2676
- let index = startIndex || 0;
2677
- for (let dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) {
2678
- this.findAtPoint(parent, index);
2679
- this.addDOM(dom, marks);
2680
- }
2681
- this.findAtPoint(parent, index);
2682
- }
2683
- findPlace(node, marks, cautious) {
2684
- let route, sync;
2685
- for (let depth = this.open, penalty = 0; depth >= 0; depth--) {
2686
- let cx = this.nodes[depth];
2687
- let found = cx.findWrapping(node);
2688
- if (found && (!route || route.length > found.length + penalty)) {
2689
- route = found;
2690
- sync = cx;
2691
- if (!found.length) break;
2692
- }
2693
- if (cx.solid) {
2694
- if (cautious) break;
2695
- penalty += 2;
2696
- }
2697
- }
2698
- if (!route) return null;
2699
- this.sync(sync);
2700
- for (let i = 0; i < route.length; i++) marks = this.enterInner(route[i], null, marks, false);
2701
- return marks;
2702
- }
2703
- insertNode(node, marks, cautious) {
2704
- if (node.isInline && this.needsBlock && !this.top.type) {
2705
- let block = this.textblockFromContext();
2706
- if (block) marks = this.enterInner(block, null, marks);
2707
- }
2708
- let innerMarks = this.findPlace(node, marks, cautious);
2709
- if (innerMarks) {
2710
- this.closeExtra();
2711
- let top = this.top;
2712
- if (top.match) top.match = top.match.matchType(node.type);
2713
- let nodeMarks = Mark.none;
2714
- for (let m of innerMarks.concat(node.marks)) if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, node.type)) nodeMarks = m.addToSet(nodeMarks);
2715
- top.content.push(node.mark(nodeMarks));
2716
- return true;
2717
- }
2718
- return false;
2719
- }
2720
- enter(type, attrs, marks, preserveWS) {
2721
- let innerMarks = this.findPlace(type.create(attrs), marks, false);
2722
- if (innerMarks) innerMarks = this.enterInner(type, attrs, marks, true, preserveWS);
2723
- return innerMarks;
2724
- }
2725
- enterInner(type, attrs, marks, solid = false, preserveWS) {
2726
- this.closeExtra();
2727
- let top = this.top;
2728
- top.match = top.match && top.match.matchType(type);
2729
- let options = wsOptionsFor(type, preserveWS, top.options);
2730
- if (top.options & OPT_OPEN_LEFT && top.content.length == 0) options |= OPT_OPEN_LEFT;
2731
- let applyMarks = Mark.none;
2732
- marks = marks.filter((m) => {
2733
- if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, type)) {
2734
- applyMarks = m.addToSet(applyMarks);
2735
- return false;
2736
- }
2737
- return true;
2738
- });
2739
- this.nodes.push(new NodeContext(type, attrs, applyMarks, solid, null, options));
2740
- this.open++;
2741
- return marks;
2742
- }
2743
- closeExtra(openEnd = false) {
2744
- let i = this.nodes.length - 1;
2745
- if (i > this.open) {
2746
- for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd));
2747
- this.nodes.length = this.open + 1;
2748
- }
2749
- }
2750
- finish() {
2751
- this.open = 0;
2752
- this.closeExtra(this.isOpen);
2753
- return this.nodes[0].finish(!!(this.isOpen || this.options.topOpen));
2754
- }
2755
- sync(to) {
2756
- for (let i = this.open; i >= 0; i--) if (this.nodes[i] == to) {
2757
- this.open = i;
2758
- return true;
2759
- } else if (this.localPreserveWS) this.nodes[i].options |= OPT_PRESERVE_WS;
2760
- return false;
2761
- }
2762
- get currentPos() {
2763
- this.closeExtra();
2764
- let pos = 0;
2765
- for (let i = this.open; i >= 0; i--) {
2766
- let content = this.nodes[i].content;
2767
- for (let j = content.length - 1; j >= 0; j--) pos += content[j].nodeSize;
2768
- if (i) pos++;
2769
- }
2770
- return pos;
2771
- }
2772
- findAtPoint(parent, offset) {
2773
- if (this.find) {
2774
- for (let i = 0; i < this.find.length; i++) if (this.find[i].node == parent && this.find[i].offset == offset) this.find[i].pos = this.currentPos;
2775
- }
2776
- }
2777
- findInside(parent) {
2778
- if (this.find) {
2779
- for (let i = 0; i < this.find.length; i++) if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) this.find[i].pos = this.currentPos;
2780
- }
2781
- }
2782
- findAround(parent, content, before) {
2783
- if (parent != content && this.find) {
2784
- for (let i = 0; i < this.find.length; i++) if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) {
2785
- if (content.compareDocumentPosition(this.find[i].node) & (before ? 2 : 4)) this.find[i].pos = this.currentPos;
2786
- }
2787
- }
2788
- }
2789
- findInText(textNode) {
2790
- if (this.find) {
2791
- for (let i = 0; i < this.find.length; i++) if (this.find[i].node == textNode) this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset);
2792
- }
2793
- }
2794
- matchesContext(context) {
2795
- if (context.indexOf("|") > -1) return context.split(/\s*\|\s*/).some(this.matchesContext, this);
2796
- let parts = context.split("/");
2797
- let option = this.options.context;
2798
- let useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type);
2799
- let minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1);
2800
- let match = (i, depth) => {
2801
- for (; i >= 0; i--) {
2802
- let part = parts[i];
2803
- if (part == "") {
2804
- if (i == parts.length - 1 || i == 0) continue;
2805
- for (; depth >= minDepth; depth--) if (match(i - 1, depth)) return true;
2806
- return false;
2807
- } else {
2808
- let next = depth > 0 || depth == 0 && useRoot ? this.nodes[depth].type : option && depth >= minDepth ? option.node(depth - minDepth).type : null;
2809
- if (!next || next.name != part && !next.isInGroup(part)) return false;
2810
- depth--;
2811
- }
2812
- }
2813
- return true;
2814
- };
2815
- return match(parts.length - 1, this.open);
2816
- }
2817
- textblockFromContext() {
2818
- let $context = this.options.context;
2819
- if ($context) for (let d = $context.depth; d >= 0; d--) {
2820
- let deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType;
2821
- if (deflt && deflt.isTextblock && deflt.defaultAttrs) return deflt;
2822
- }
2823
- for (let name in this.parser.schema.nodes) {
2824
- let type = this.parser.schema.nodes[name];
2825
- if (type.isTextblock && type.defaultAttrs) return type;
2826
- }
2827
- }
2828
- };
2829
- function normalizeList(dom) {
2830
- for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) {
2831
- let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null;
2832
- if (name && listTags.hasOwnProperty(name) && prevItem) {
2833
- prevItem.appendChild(child);
2834
- child = prevItem;
2835
- } else if (name == "li") prevItem = child;
2836
- else if (name) prevItem = null;
2837
- }
2838
- }
2839
- function matches(dom, selector) {
2840
- return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector);
2841
- }
2842
- function copy(obj) {
2843
- let copy = {};
2844
- for (let prop in obj) copy[prop] = obj[prop];
2845
- return copy;
2846
- }
2847
- function markMayApply(markType, nodeType) {
2848
- let nodes = nodeType.schema.nodes;
2849
- for (let name in nodes) {
2850
- let parent = nodes[name];
2851
- if (!parent.allowsMarkType(markType)) continue;
2852
- let seen = [], scan = (match) => {
2853
- seen.push(match);
2854
- for (let i = 0; i < match.edgeCount; i++) {
2855
- let { type, next } = match.edge(i);
2856
- if (type == nodeType) return true;
2857
- if (seen.indexOf(next) < 0 && scan(next)) return true;
2858
- }
2859
- };
2860
- if (scan(parent.contentMatch)) return true;
2861
- }
2862
- }
2863
- /**
2864
- A DOM serializer knows how to convert ProseMirror nodes and
2865
- marks of various types to DOM nodes.
2866
- */
2867
- var DOMSerializer = class DOMSerializer {
2868
- /**
2869
- Create a serializer. `nodes` should map node names to functions
2870
- that take a node and return a description of the corresponding
2871
- DOM. `marks` does the same for mark names, but also gets an
2872
- argument that tells it whether the mark's content is block or
2873
- inline content (for typical use, it'll always be inline). A mark
2874
- serializer may be `null` to indicate that marks of that type
2875
- should not be serialized.
2876
- */
2877
- constructor(nodes, marks) {
2878
- this.nodes = nodes;
2879
- this.marks = marks;
2880
- }
2881
- /**
2882
- Serialize the content of this fragment to a DOM fragment. When
2883
- not in the browser, the `document` option, containing a DOM
2884
- document, should be passed so that the serializer can create
2885
- nodes.
2886
- */
2887
- serializeFragment(fragment, options = {}, target) {
2888
- if (!target) target = doc(options).createDocumentFragment();
2889
- let top = target, active = [];
2890
- fragment.forEach((node) => {
2891
- if (active.length || node.marks.length) {
2892
- let keep = 0, rendered = 0;
2893
- while (keep < active.length && rendered < node.marks.length) {
2894
- let next = node.marks[rendered];
2895
- if (!this.marks[next.type.name]) {
2896
- rendered++;
2897
- continue;
2898
- }
2899
- if (!next.eq(active[keep][0]) || next.type.spec.spanning === false) break;
2900
- keep++;
2901
- rendered++;
2902
- }
2903
- while (keep < active.length) top = active.pop()[1];
2904
- while (rendered < node.marks.length) {
2905
- let add = node.marks[rendered++];
2906
- let markDOM = this.serializeMark(add, node.isInline, options);
2907
- if (markDOM) {
2908
- active.push([add, top]);
2909
- top.appendChild(markDOM.dom);
2910
- top = markDOM.contentDOM || markDOM.dom;
2911
- }
2912
- }
2913
- }
2914
- top.appendChild(this.serializeNodeInner(node, options));
2915
- });
2916
- return target;
2917
- }
2918
- /**
2919
- @internal
2920
- */
2921
- serializeNodeInner(node, options) {
2922
- let { dom, contentDOM } = renderSpec(doc(options), this.nodes[node.type.name](node), null, node.attrs);
2923
- if (contentDOM) {
2924
- if (node.isLeaf) throw new RangeError("Content hole not allowed in a leaf node spec");
2925
- this.serializeFragment(node.content, options, contentDOM);
2926
- }
2927
- return dom;
2928
- }
2929
- /**
2930
- Serialize this node to a DOM node. This can be useful when you
2931
- need to serialize a part of a document, as opposed to the whole
2932
- document. To serialize a whole document, use
2933
- [`serializeFragment`](https://prosemirror.net/docs/ref/#model.DOMSerializer.serializeFragment) on
2934
- its [content](https://prosemirror.net/docs/ref/#model.Node.content).
2935
- */
2936
- serializeNode(node, options = {}) {
2937
- let dom = this.serializeNodeInner(node, options);
2938
- for (let i = node.marks.length - 1; i >= 0; i--) {
2939
- let wrap = this.serializeMark(node.marks[i], node.isInline, options);
2940
- if (wrap) {
2941
- (wrap.contentDOM || wrap.dom).appendChild(dom);
2942
- dom = wrap.dom;
2943
- }
2944
- }
2945
- return dom;
2946
- }
2947
- /**
2948
- @internal
2949
- */
2950
- serializeMark(mark, inline, options = {}) {
2951
- let toDOM = this.marks[mark.type.name];
2952
- return toDOM && renderSpec(doc(options), toDOM(mark, inline), null, mark.attrs);
2953
- }
2954
- static renderSpec(doc, structure, xmlNS = null, blockArraysIn) {
2955
- return renderSpec(doc, structure, xmlNS, blockArraysIn);
2956
- }
2957
- /**
2958
- Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)
2959
- properties in a schema's node and mark specs.
2960
- */
2961
- static fromSchema(schema) {
2962
- return schema.cached.domSerializer || (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
2963
- }
2964
- /**
2965
- Gather the serializers in a schema's node specs into an object.
2966
- This can be useful as a base to build a custom serializer from.
2967
- */
2968
- static nodesFromSchema(schema) {
2969
- let result = gatherToDOM(schema.nodes);
2970
- if (!result.text) result.text = (node) => node.text;
2971
- return result;
2972
- }
2973
- /**
2974
- Gather the serializers in a schema's mark specs into an object.
2975
- */
2976
- static marksFromSchema(schema) {
2977
- return gatherToDOM(schema.marks);
2978
- }
2979
- };
2980
- function gatherToDOM(obj) {
2981
- let result = {};
2982
- for (let name in obj) {
2983
- let toDOM = obj[name].spec.toDOM;
2984
- if (toDOM) result[name] = toDOM;
2985
- }
2986
- return result;
2987
- }
2988
- function doc(options) {
2989
- return options.document || window.document;
2990
- }
2991
- var suspiciousAttributeCache = /* @__PURE__ */ new WeakMap();
2992
- function suspiciousAttributes(attrs) {
2993
- let value = suspiciousAttributeCache.get(attrs);
2994
- if (value === void 0) suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs));
2995
- return value;
2996
- }
2997
- function suspiciousAttributesInner(attrs) {
2998
- let result = null;
2999
- function scan(value) {
3000
- if (value && typeof value == "object") if (Array.isArray(value)) if (typeof value[0] == "string") {
3001
- if (!result) result = [];
3002
- result.push(value);
3003
- } else for (let i = 0; i < value.length; i++) scan(value[i]);
3004
- else for (let prop in value) scan(value[prop]);
3005
- }
3006
- scan(attrs);
3007
- return result;
3008
- }
3009
- function renderSpec(doc, structure, xmlNS, blockArraysIn) {
3010
- if (typeof structure == "string") return { dom: doc.createTextNode(structure) };
3011
- if (structure.nodeType != null) return { dom: structure };
3012
- if (structure.dom && structure.dom.nodeType != null) return structure;
3013
- let tagName = structure[0], suspicious;
3014
- if (typeof tagName != "string") throw new RangeError("Invalid array passed to renderSpec");
3015
- if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1) throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
3016
- let space = tagName.indexOf(" ");
3017
- if (space > 0) {
3018
- xmlNS = tagName.slice(0, space);
3019
- tagName = tagName.slice(space + 1);
3020
- }
3021
- let contentDOM;
3022
- let dom = xmlNS ? doc.createElementNS(xmlNS, tagName) : doc.createElement(tagName);
3023
- let attrs = structure[1], start = 1;
3024
- if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
3025
- start = 2;
3026
- for (let name in attrs) if (attrs[name] != null) {
3027
- let space = name.indexOf(" ");
3028
- if (space > 0) dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
3029
- else if (name == "style" && dom.style) dom.style.cssText = attrs[name];
3030
- else dom.setAttribute(name, attrs[name]);
3031
- }
3032
- }
3033
- for (let i = start; i < structure.length; i++) {
3034
- let child = structure[i];
3035
- if (child === 0) {
3036
- if (i < structure.length - 1 || i > start) throw new RangeError("Content hole must be the only child of its parent node");
3037
- return {
3038
- dom,
3039
- contentDOM: dom
3040
- };
3041
- } else {
3042
- let { dom: inner, contentDOM: innerContent } = renderSpec(doc, child, xmlNS, blockArraysIn);
3043
- dom.appendChild(inner);
3044
- if (innerContent) {
3045
- if (contentDOM) throw new RangeError("Multiple content holes");
3046
- contentDOM = innerContent;
3047
- }
3048
- }
3049
- }
3050
- return {
3051
- dom,
3052
- contentDOM
3053
- };
3054
- }
3055
- //#endregion
3056
- //#region src/lib/rich-text-editor/rte/utils/textblock-attrs.ts
3057
- var TextblockAttrs = class {
3058
- constructor(specs) {
3059
- this.specs = specs;
3060
- this.attrs = {};
3061
- for (const spec of specs) this.attrs[spec.name] = { default: spec.default };
3062
- }
3063
- fromDOM(dom) {
3064
- return Object.assign({}, ...this.specs.map((s) => ({ [s.name]: s.fromDOM(dom) })));
3065
- }
3066
- getStyle(node) {
3067
- return this.specs.flatMap((s) => s.toStyles(node)).join("; ");
3068
- }
3069
- getDOMAttrsProperties(node) {
3070
- if (!this.specs.length) return {};
3071
- return { style: this.getStyle(node) };
3072
- }
3073
- getDOMAttrs(node) {
3074
- if (!this.specs.length) return [];
3075
- return [this.getDOMAttrsProperties(node)];
3076
- }
3077
- extractFromNode(node) {
3078
- return Object.assign({}, ...Object.keys(this.attrs).map((attr) => ({ [attr]: node.attrs[attr] })));
3079
- }
3080
- };
3081
- //#endregion
3082
- //#region src/lib/rich-text-editor/rte/utils/textblock-marks.ts
3083
- var TextblockMarks = class {
3084
- constructor(specs) {
3085
- this.specs = specs;
3086
- }
3087
- getAllowedMarksForNode(nodeName) {
3088
- return this.specs.filter((spec) => !spec.onNodeName || spec.onNodeName === nodeName).map((spec) => spec.markName);
3089
- }
3090
- getReferencedNodeNames() {
3091
- return new Set(this.specs.map((spec) => spec.onNodeName).filter(Boolean));
3092
- }
3093
- };
1
+ //#region src/lib/rich-text-editor/rte/utils/impl.ts
2
+ var impl = Symbol("rte-internal-impl");
3094
3
  //#endregion
3095
4
  //#region src/lib/rich-text-editor/rte/feature.ts
3096
5
  var sortedContributions = (contributions) => {
@@ -3162,9 +71,6 @@ var featureFacade = (FeatureImpl) => {
3162
71
  return Facade;
3163
72
  };
3164
73
  //#endregion
3165
- //#region src/lib/rich-text-editor/rte/utils/impl.ts
3166
- var impl = Symbol("rte-internal-impl");
3167
- //#endregion
3168
74
  //#region src/shared/utils/slottable-request.ts
3169
75
  var removeSymbol = Symbol.for("slottable-request-remove");
3170
76
  function dispatchSlottableRequest(target, name, slotName, data) {
@@ -3194,84 +100,12 @@ function dispatchSlottableRequest(target, name, slotName, data) {
3194
100
  target.dispatchEvent(event);
3195
101
  }
3196
102
  //#endregion
3197
- Object.defineProperty(exports, "DOMParser", {
3198
- enumerable: true,
3199
- get: function() {
3200
- return DOMParser;
3201
- }
3202
- });
3203
- Object.defineProperty(exports, "DOMSerializer", {
3204
- enumerable: true,
3205
- get: function() {
3206
- return DOMSerializer;
3207
- }
3208
- });
3209
- Object.defineProperty(exports, "Fragment", {
3210
- enumerable: true,
3211
- get: function() {
3212
- return Fragment;
3213
- }
3214
- });
3215
- Object.defineProperty(exports, "Mark", {
3216
- enumerable: true,
3217
- get: function() {
3218
- return Mark;
3219
- }
3220
- });
3221
- Object.defineProperty(exports, "MarkType", {
3222
- enumerable: true,
3223
- get: function() {
3224
- return MarkType;
3225
- }
3226
- });
3227
- Object.defineProperty(exports, "Node", {
3228
- enumerable: true,
3229
- get: function() {
3230
- return Node;
3231
- }
3232
- });
3233
- Object.defineProperty(exports, "NodeRange", {
3234
- enumerable: true,
3235
- get: function() {
3236
- return NodeRange;
3237
- }
3238
- });
3239
- Object.defineProperty(exports, "ReplaceError", {
3240
- enumerable: true,
3241
- get: function() {
3242
- return ReplaceError;
3243
- }
3244
- });
3245
103
  Object.defineProperty(exports, "RteFeatureImpl", {
3246
104
  enumerable: true,
3247
105
  get: function() {
3248
106
  return RteFeatureImpl;
3249
107
  }
3250
108
  });
3251
- Object.defineProperty(exports, "Schema", {
3252
- enumerable: true,
3253
- get: function() {
3254
- return Schema;
3255
- }
3256
- });
3257
- Object.defineProperty(exports, "Slice", {
3258
- enumerable: true,
3259
- get: function() {
3260
- return Slice;
3261
- }
3262
- });
3263
- Object.defineProperty(exports, "TextblockAttrs", {
3264
- enumerable: true,
3265
- get: function() {
3266
- return TextblockAttrs;
3267
- }
3268
- });
3269
- Object.defineProperty(exports, "TextblockMarks", {
3270
- enumerable: true,
3271
- get: function() {
3272
- return TextblockMarks;
3273
- }
3274
- });
3275
109
  Object.defineProperty(exports, "contributionPriority", {
3276
110
  enumerable: true,
3277
111
  get: function() {