plitejs 54.0.0-beta.2 → 54.0.0-beta.4

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 (865) hide show
  1. package/dist/{internal/view/annotation-store-metrics.js → annotation-store-metrics-Ccjkef45.js} +1 -1
  2. package/dist/annotations/index.d.ts +1 -1
  3. package/dist/annotations/index.js +1 -1
  4. package/dist/authored/index.d.ts +596 -9
  5. package/dist/authored/index.js +18679 -4
  6. package/dist/{core/authored-veto.js → authored-veto-D_9wCJcK.js} +2 -2
  7. package/dist/{internal/browser-protocol.js → browser-protocol-pvt4HFF7.js} +1 -1
  8. package/dist/comparison-plan-DY_vuGPq.js +1338 -0
  9. package/dist/{diff/lib/comparison-types.d.ts → comparison-types-DdwE6mYq.d.ts} +11 -6
  10. package/dist/create-editor-CLQEkEZ1.js +1108 -0
  11. package/dist/diff/index.d.ts +31 -3
  12. package/dist/diff/index.js +1747 -1
  13. package/dist/dom/index.d.ts +2 -19
  14. package/dist/dom/index.js +2 -16
  15. package/dist/dom-CH2BXXj6.js +9220 -0
  16. package/dist/{core/same-result.js → editor-owner-C9rVbMTs.js} +77 -2
  17. package/dist/{core/editor-view-lifetime.js → editor-view-lifetime-GJKa_QGh.js} +1 -1
  18. package/dist/history/index.d.ts +169 -3
  19. package/dist/history/index.js +6717 -2
  20. package/dist/hyperscript/index.d.ts +1 -19
  21. package/dist/hyperscript/index.js +1 -8
  22. package/dist/{hyperscript/creators.js → hyperscript-CeT83ZLB.js} +134 -8
  23. package/dist/{annotations/store.d.ts → index-BWPcE4ac.d.ts} +27 -6
  24. package/dist/index-BXjLmx1n.d.ts +9827 -0
  25. package/dist/index-DVMNewDn.d.ts +1243 -0
  26. package/dist/index-Db-ktCTE.d.ts +1092 -0
  27. package/dist/index-Dq3Jlj8O.d.ts +119 -0
  28. package/dist/{yjs/core/plugin.d.ts → index-UrB4jAwl.d.ts} +88 -5
  29. package/dist/index.d.ts +2 -51
  30. package/dist/index.js +4 -34
  31. package/dist/internal/index.d.ts +2 -54
  32. package/dist/internal/index.js +156 -52
  33. package/dist/{internal/view/mapped-view-store.js → mapped-view-store-CbWqba_1.js} +2 -3
  34. package/dist/{core/native-grouping-input.js → native-grouping-input-DXNhlPHd.js} +2 -2
  35. package/dist/pagination/index.d.ts +1 -7
  36. package/dist/pagination/index.js +1 -693
  37. package/dist/pagination/react.d.ts +2 -4
  38. package/dist/pagination/react.js +436 -30
  39. package/dist/pagination-CBdYiOuR.js +1021 -0
  40. package/dist/plugin-SR3HTH0j.js +51505 -0
  41. package/dist/{react/range-geometry.js → range-geometry-CdltxcH6.js} +23 -18
  42. package/dist/{react/range-geometry.d.ts → range-geometry-Dwp2oyCc.d.ts} +2 -2
  43. package/dist/react/index.d.ts +5 -97
  44. package/dist/react/index.js +7 -72
  45. package/dist/react/virtualized.d.ts +2 -4
  46. package/dist/react/virtualized.js +146 -7
  47. package/dist/react-CN-iBh1z.js +1018 -0
  48. package/dist/{core/change/retraction.js → retraction-BmPJB9cE.js} +16 -4
  49. package/dist/src-B-zm0kz4.js +1511 -0
  50. package/dist/{internal/view/stable-id-mapped-source.js → store-51r4zpCR.js} +253 -3
  51. package/dist/testing/index.d.ts +182 -8
  52. package/dist/testing/index.js +95 -8
  53. package/dist/use-editor-dom-scope-uDJQ692F.js +28370 -0
  54. package/dist/yjs/index.d.ts +1 -4
  55. package/dist/yjs/index.js +1 -2
  56. package/dist/yjs/react/index.d.ts +25 -5
  57. package/dist/yjs/react/index.js +84 -3
  58. package/dist/yjs-IGE0Al3n.js +13416 -0
  59. package/package.json +1 -1
  60. package/dist/annotations/store.js +0 -244
  61. package/dist/authored/authored.d.ts +0 -116
  62. package/dist/authored/authored.js +0 -1271
  63. package/dist/authored/changes.js +0 -365
  64. package/dist/authored/comparison.d.ts +0 -41
  65. package/dist/authored/comparison.js +0 -270
  66. package/dist/authored/decision-window.js +0 -42
  67. package/dist/authored/decision.js +0 -306
  68. package/dist/authored/facts/admission.js +0 -388
  69. package/dist/authored/facts/compact.d.ts +0 -2
  70. package/dist/authored/facts/compact.js +0 -91
  71. package/dist/authored/facts/dependencies.d.ts +0 -5
  72. package/dist/authored/facts/dependencies.js +0 -66
  73. package/dist/authored/facts/editing.js +0 -12
  74. package/dist/authored/facts/facts.d.ts +0 -8
  75. package/dist/authored/facts/facts.js +0 -535
  76. package/dist/authored/facts/records.d.ts +0 -28
  77. package/dist/authored/facts/records.js +0 -226
  78. package/dist/authored/facts/settle.js +0 -529
  79. package/dist/authored/format.d.ts +0 -34
  80. package/dist/authored/format.js +0 -175
  81. package/dist/authored/ledger/book.js +0 -809
  82. package/dist/authored/ledger/cards.js +0 -223
  83. package/dist/authored/ledger/ledger.js +0 -830
  84. package/dist/authored/ledger/level.js +0 -1081
  85. package/dist/authored/ledger/links.js +0 -20
  86. package/dist/authored/ledger/pairs.js +0 -334
  87. package/dist/authored/ledger/places.js +0 -524
  88. package/dist/authored/ledger/preview-lens.js +0 -252
  89. package/dist/authored/ledger/projection.js +0 -163
  90. package/dist/authored/ledger/roots.js +0 -11
  91. package/dist/authored/ledger/runs.js +0 -480
  92. package/dist/authored/ledger/slots.js +0 -330
  93. package/dist/authored/ledger/work.js +0 -66
  94. package/dist/authored/refusal.d.ts +0 -33
  95. package/dist/authored/refusal.js +0 -188
  96. package/dist/authored/resolve-schema.js +0 -62
  97. package/dist/authored/tree/alignment.js +0 -456
  98. package/dist/authored/tree/carried.js +0 -205
  99. package/dist/authored/tree/command-values.js +0 -344
  100. package/dist/authored/tree/cuts.js +0 -320
  101. package/dist/authored/tree/grid.js +0 -49
  102. package/dist/authored/tree/halves.js +0 -120
  103. package/dist/authored/tree/holders.js +0 -345
  104. package/dist/authored/tree/holds.js +0 -135
  105. package/dist/authored/tree/layers.d.ts +0 -49
  106. package/dist/authored/tree/layers.js +0 -354
  107. package/dist/authored/tree/marks.d.ts +0 -136
  108. package/dist/authored/tree/marks.js +0 -263
  109. package/dist/authored/tree/proposed.js +0 -212
  110. package/dist/authored/tree/readiness.js +0 -545
  111. package/dist/authored/tree/record-completion.js +0 -423
  112. package/dist/authored/tree/record.js +0 -2908
  113. package/dist/authored/tree/reserves.js +0 -449
  114. package/dist/authored/tree/resolve.d.ts +0 -9
  115. package/dist/authored/tree/resolve.js +0 -1860
  116. package/dist/authored/tree/shown.js +0 -153
  117. package/dist/authored/tree/spare-lines.js +0 -119
  118. package/dist/authored/tree/spares.js +0 -61
  119. package/dist/authored/types.d.ts +0 -177
  120. package/dist/core/anchor-state.d.ts +0 -15
  121. package/dist/core/anchor-state.js +0 -792
  122. package/dist/core/anchor.d.ts +0 -34
  123. package/dist/core/anchor.js +0 -843
  124. package/dist/core/authored-document-capability.d.ts +0 -106
  125. package/dist/core/authored-document-capability.js +0 -6
  126. package/dist/core/authored-runtime.d.ts +0 -10
  127. package/dist/core/authored-runtime.js +0 -67
  128. package/dist/core/authored-veto.d.ts +0 -30
  129. package/dist/core/change/builder.d.ts +0 -546
  130. package/dist/core/change/builder.js +0 -1120
  131. package/dist/core/change/carried-projection.js +0 -1518
  132. package/dist/core/change/carried-run.d.ts +0 -26
  133. package/dist/core/change/carried-run.js +0 -251
  134. package/dist/core/change/carry-program.js +0 -537
  135. package/dist/core/change/classification.d.ts +0 -22
  136. package/dist/core/change/classification.js +0 -205
  137. package/dist/core/change/cross-rule.js +0 -238
  138. package/dist/core/change/cross.js +0 -577
  139. package/dist/core/change/document-change.d.ts +0 -137
  140. package/dist/core/change/document-change.js +0 -872
  141. package/dist/core/change/document-index.d.ts +0 -117
  142. package/dist/core/change/document-index.js +0 -542
  143. package/dist/core/change/draft-facts.js +0 -323
  144. package/dist/core/change/enclosure.d.ts +0 -12
  145. package/dist/core/change/enclosure.js +0 -272
  146. package/dist/core/change/join.js +0 -751
  147. package/dist/core/change/json.d.ts +0 -4
  148. package/dist/core/change/json.js +0 -26
  149. package/dist/core/change/lazy-root.d.ts +0 -1
  150. package/dist/core/change/lazy-root.js +0 -73
  151. package/dist/core/change/lineage.d.ts +0 -49
  152. package/dist/core/change/lineage.js +0 -390
  153. package/dist/core/change/mapping.d.ts +0 -31
  154. package/dist/core/change/mapping.js +0 -186
  155. package/dist/core/change/new-letters.d.ts +0 -14
  156. package/dist/core/change/new-letters.js +0 -139
  157. package/dist/core/change/range-association.js +0 -10
  158. package/dist/core/change/read-back.d.ts +0 -7
  159. package/dist/core/change/read-back.js +0 -7
  160. package/dist/core/change/record.d.ts +0 -59
  161. package/dist/core/change/record.js +0 -346
  162. package/dist/core/change/root-change.d.ts +0 -180
  163. package/dist/core/change/root-change.js +0 -3544
  164. package/dist/core/change/slice-facts.js +0 -89
  165. package/dist/core/change/text-splices.js +0 -98
  166. package/dist/core/change/tokens.d.ts +0 -97
  167. package/dist/core/change/tokens.js +0 -449
  168. package/dist/core/change/transform.d.ts +0 -36
  169. package/dist/core/change/transform.js +0 -97
  170. package/dist/core/change/wrap-fidelity.js +0 -295
  171. package/dist/core/change-events.js +0 -223
  172. package/dist/core/clone.js +0 -28
  173. package/dist/core/command-definition.d.ts +0 -25
  174. package/dist/core/command-definition.js +0 -48
  175. package/dist/core/command-document.d.ts +0 -4
  176. package/dist/core/command-document.js +0 -20
  177. package/dist/core/command-frame.js +0 -628
  178. package/dist/core/command-registry.d.ts +0 -36
  179. package/dist/core/command-registry.js +0 -283
  180. package/dist/core/commit-publication.js +0 -40
  181. package/dist/core/commit.d.ts +0 -26
  182. package/dist/core/commit.js +0 -686
  183. package/dist/core/composition-stamp.d.ts +0 -14
  184. package/dist/core/composition-stamp.js +0 -79
  185. package/dist/core/content-completion.d.ts +0 -4
  186. package/dist/core/content-completion.js +0 -343
  187. package/dist/core/content-landing.js +0 -124
  188. package/dist/core/content-slice-roots.js +0 -36
  189. package/dist/core/content-slice.d.ts +0 -38
  190. package/dist/core/content-slice.js +0 -253
  191. package/dist/core/content.js +0 -18
  192. package/dist/core/correction.js +0 -25
  193. package/dist/core/default-storage.js +0 -53
  194. package/dist/core/document-admission.d.ts +0 -4
  195. package/dist/core/document-admission.js +0 -64
  196. package/dist/core/document-change.d.ts +0 -3
  197. package/dist/core/document-recorder.d.ts +0 -6
  198. package/dist/core/document-recorder.js +0 -67
  199. package/dist/core/document-shape.d.ts +0 -68
  200. package/dist/core/document-shape.js +0 -173
  201. package/dist/core/document-view-read.d.ts +0 -16
  202. package/dist/core/document-view-read.js +0 -36
  203. package/dist/core/draft-track.d.ts +0 -3
  204. package/dist/core/draft-track.js +0 -90
  205. package/dist/core/editor-commands.d.ts +0 -99
  206. package/dist/core/editor-commands.js +0 -505
  207. package/dist/core/editor-lifecycle-api.d.ts +0 -8
  208. package/dist/core/editor-lifecycle-api.js +0 -219
  209. package/dist/core/editor-lifetime.js +0 -12
  210. package/dist/core/editor-owner.d.ts +0 -24
  211. package/dist/core/editor-owner.js +0 -78
  212. package/dist/core/editor-read-execution.d.ts +0 -6
  213. package/dist/core/editor-read-execution.js +0 -64
  214. package/dist/core/editor-read-runtime.js +0 -176
  215. package/dist/core/editor-reads.d.ts +0 -128
  216. package/dist/core/editor-reads.js +0 -63
  217. package/dist/core/editor-runtime.d.ts +0 -112
  218. package/dist/core/editor-runtime.js +0 -20
  219. package/dist/core/editor-schema.d.ts +0 -314
  220. package/dist/core/editor-schema.js +0 -2295
  221. package/dist/core/element-owned-root-index.d.ts +0 -4
  222. package/dist/core/element-owned-root-index.js +0 -353
  223. package/dist/core/get-content-slice.js +0 -118
  224. package/dist/core/get-fragment.js +0 -22
  225. package/dist/core/identity-owner.js +0 -697
  226. package/dist/core/import-content-slice.js +0 -26
  227. package/dist/core/initial-value.js +0 -87
  228. package/dist/core/insert-limit.js +0 -81
  229. package/dist/core/is-empty-element.js +0 -20
  230. package/dist/core/json-fingerprint.js +0 -16
  231. package/dist/core/landing.d.ts +0 -11
  232. package/dist/core/landing.js +0 -279
  233. package/dist/core/lifecycle-error.d.ts +0 -11
  234. package/dist/core/lifecycle-error.js +0 -68
  235. package/dist/core/listener-state.d.ts +0 -1
  236. package/dist/core/listener-state.js +0 -59
  237. package/dist/core/measured-sequence.d.ts +0 -43
  238. package/dist/core/measured-sequence.js +0 -404
  239. package/dist/core/missing-reference.js +0 -15
  240. package/dist/core/node-property-mutation.js +0 -10
  241. package/dist/core/node-selection.js +0 -85
  242. package/dist/core/node-write-veto.d.ts +0 -37
  243. package/dist/core/node-write-veto.js +0 -17
  244. package/dist/core/persisted-document.d.ts +0 -6
  245. package/dist/core/persisted-document.js +0 -39
  246. package/dist/core/persistent-map.js +0 -139
  247. package/dist/core/plain-text.d.ts +0 -32
  248. package/dist/core/plain-text.js +0 -92
  249. package/dist/core/plugin-dispatch.d.ts +0 -21
  250. package/dist/core/plugin-dispatch.js +0 -166
  251. package/dist/core/plugin-point.d.ts +0 -6
  252. package/dist/core/plugin-point.js +0 -21
  253. package/dist/core/plugin-registry.d.ts +0 -78
  254. package/dist/core/plugin-registry.js +0 -485
  255. package/dist/core/plugin-slot.d.ts +0 -23
  256. package/dist/core/plugin-slot.js +0 -30
  257. package/dist/core/plugin.d.ts +0 -125
  258. package/dist/core/plugin.js +0 -1485
  259. package/dist/core/prefix-occupant-join.js +0 -52
  260. package/dist/core/profiling.js +0 -18
  261. package/dist/core/property-validity.d.ts +0 -14
  262. package/dist/core/property-validity.js +0 -65
  263. package/dist/core/public-root.d.ts +0 -10
  264. package/dist/core/public-root.js +0 -50
  265. package/dist/core/public-state.d.ts +0 -191
  266. package/dist/core/public-state.js +0 -6772
  267. package/dist/core/read-definition.js +0 -22
  268. package/dist/core/read-registry.js +0 -127
  269. package/dist/core/record-store.d.ts +0 -12
  270. package/dist/core/record-store.js +0 -297
  271. package/dist/core/refusal.d.ts +0 -1
  272. package/dist/core/refusal.js +0 -40
  273. package/dist/core/representation.d.ts +0 -11
  274. package/dist/core/representation.js +0 -844
  275. package/dist/core/resolved-token-cursor.d.ts +0 -21
  276. package/dist/core/resolved-token-cursor.js +0 -294
  277. package/dist/core/root-entries.js +0 -121
  278. package/dist/core/root-ownership.d.ts +0 -19
  279. package/dist/core/root-ownership.js +0 -354
  280. package/dist/core/root-target.d.ts +0 -7
  281. package/dist/core/root-target.js +0 -281
  282. package/dist/core/same-result.d.ts +0 -18
  283. package/dist/core/schema-compiler.d.ts +0 -345
  284. package/dist/core/schema-compiler.js +0 -3166
  285. package/dist/core/schema-contribution-registry.d.ts +0 -12
  286. package/dist/core/schema-contribution-registry.js +0 -88
  287. package/dist/core/schema-definition.d.ts +0 -307
  288. package/dist/core/schema-definition.js +0 -628
  289. package/dist/core/schema-source.internal.d.ts +0 -49
  290. package/dist/core/schema-validation.d.ts +0 -11
  291. package/dist/core/schema-validation.js +0 -85
  292. package/dist/core/screen-reader-announcement.d.ts +0 -13
  293. package/dist/core/screen-reader-announcement.js +0 -17
  294. package/dist/core/selection-protocol.d.ts +0 -38
  295. package/dist/core/selection-protocol.js +0 -523
  296. package/dist/core/selection-state.js +0 -9
  297. package/dist/core/semantic-update-method.d.ts +0 -11
  298. package/dist/core/semantic-update-method.js +0 -26
  299. package/dist/core/set-root.d.ts +0 -3
  300. package/dist/core/set-root.js +0 -244
  301. package/dist/core/slice-end-matter.js +0 -77
  302. package/dist/core/slice-fit/compiled-slice-fitter.d.ts +0 -56
  303. package/dist/core/slice-fit/compiled-slice-fitter.js +0 -2087
  304. package/dist/core/slice-fit/fit-report.d.ts +0 -36
  305. package/dist/core/slice-fit/fit-report.js +0 -122
  306. package/dist/core/slice-fit/frontier.js +0 -98
  307. package/dist/core/slice-fit/origin.js +0 -57
  308. package/dist/core/slice-fit/provenance.d.ts +0 -30
  309. package/dist/core/slice-fit/provenance.js +0 -245
  310. package/dist/core/slice-identities.js +0 -21
  311. package/dist/core/slice-landing-types.d.ts +0 -61
  312. package/dist/core/slice-landing.js +0 -124
  313. package/dist/core/snapshot-index.d.ts +0 -13
  314. package/dist/core/snapshot-index.js +0 -860
  315. package/dist/core/state-field.d.ts +0 -12
  316. package/dist/core/state-field.js +0 -102
  317. package/dist/core/state-fields.js +0 -36
  318. package/dist/core/survival.js +0 -61
  319. package/dist/core/target-runtime.d.ts +0 -5
  320. package/dist/core/target-runtime.js +0 -42
  321. package/dist/core/transaction-values.d.ts +0 -47
  322. package/dist/core/transaction-values.js +0 -66
  323. package/dist/core/transfer-guard.js +0 -299
  324. package/dist/core/transfer-types.d.ts +0 -170
  325. package/dist/core/transfer.d.ts +0 -72
  326. package/dist/core/transfer.js +0 -655
  327. package/dist/core/tx-only.d.ts +0 -64
  328. package/dist/core/tx-only.js +0 -84
  329. package/dist/core/unique-values.js +0 -298
  330. package/dist/core/update-context.js +0 -28
  331. package/dist/core/update-policy.d.ts +0 -17
  332. package/dist/core/update-policy.js +0 -45
  333. package/dist/core/value-codec.d.ts +0 -35
  334. package/dist/core/value-codec.js +0 -240
  335. package/dist/core/view-carets.d.ts +0 -39
  336. package/dist/core/view-carets.js +0 -676
  337. package/dist/core/view-presentation.d.ts +0 -9
  338. package/dist/core/view-presentation.js +0 -70
  339. package/dist/core/work.d.ts +0 -192
  340. package/dist/core/work.js +0 -122
  341. package/dist/core/writable-text.js +0 -37
  342. package/dist/create-editor.d.ts +0 -187
  343. package/dist/create-editor.js +0 -281
  344. package/dist/diff/lib/compare.d.ts +0 -33
  345. package/dist/diff/lib/compare.js +0 -459
  346. package/dist/diff/lib/comparison-align.js +0 -324
  347. package/dist/diff/lib/comparison-index.js +0 -160
  348. package/dist/diff/lib/comparison-internal.js +0 -108
  349. package/dist/diff/lib/comparison-matcher.js +0 -1221
  350. package/dist/diff/lib/comparison-moves.js +0 -151
  351. package/dist/diff/lib/comparison-plan.js +0 -556
  352. package/dist/diff/lib/index.d.ts +0 -3
  353. package/dist/dom/dom-soft-line-end.d.ts +0 -3
  354. package/dist/dom/dom-soft-line-end.js +0 -295
  355. package/dist/dom/internal/index.d.ts +0 -15
  356. package/dist/dom/plugin/data-transfer-format.d.ts +0 -90
  357. package/dist/dom/plugin/data-transfer-format.js +0 -525
  358. package/dist/dom/plugin/dom-clipboard-runtime.d.ts +0 -50
  359. package/dist/dom/plugin/dom-clipboard-runtime.js +0 -482
  360. package/dist/dom/plugin/dom-coverage.d.ts +0 -140
  361. package/dist/dom/plugin/dom-coverage.js +0 -443
  362. package/dist/dom/plugin/dom-drag-scroll.js +0 -176
  363. package/dist/dom/plugin/dom-drag.d.ts +0 -54
  364. package/dist/dom/plugin/dom-drag.js +0 -507
  365. package/dist/dom/plugin/dom-editor.d.ts +0 -421
  366. package/dist/dom/plugin/dom-editor.js +0 -1316
  367. package/dist/dom/plugin/dom-event-range-targets.js +0 -39
  368. package/dist/dom/plugin/dom-geometry.d.ts +0 -11
  369. package/dist/dom/plugin/dom-geometry.js +0 -888
  370. package/dist/dom/plugin/dom-input-runtime.d.ts +0 -1
  371. package/dist/dom/plugin/dom-input-runtime.js +0 -571
  372. package/dist/dom/plugin/dom-integrity-observer.js +0 -436
  373. package/dist/dom/plugin/dom-node-path.js +0 -61
  374. package/dist/dom/plugin/dom-phase-scheduler.d.ts +0 -1
  375. package/dist/dom/plugin/dom-phase-scheduler.js +0 -284
  376. package/dist/dom/plugin/dom-root-runtime.d.ts +0 -10
  377. package/dist/dom/plugin/dom-root-runtime.js +0 -716
  378. package/dist/dom/plugin/dom-sync-mutation-ownership.d.ts +0 -1
  379. package/dist/dom/plugin/dom-sync-mutation-ownership.js +0 -120
  380. package/dist/dom/plugin/dom-text-flow-index.js +0 -396
  381. package/dist/dom/plugin/dom-text-freshness.js +0 -188
  382. package/dist/dom/plugin/dom-text-proofs.d.ts +0 -2
  383. package/dist/dom/plugin/dom-text-proofs.js +0 -350
  384. package/dist/dom/plugin/dom-view-caret.js +0 -28
  385. package/dist/dom/plugin/with-dom.d.ts +0 -53
  386. package/dist/dom/plugin/with-dom.js +0 -101
  387. package/dist/dom/utils/constants.d.ts +0 -5
  388. package/dist/dom/utils/constants.js +0 -5
  389. package/dist/dom/utils/diff-text.d.ts +0 -51
  390. package/dist/dom/utils/diff-text.js +0 -264
  391. package/dist/dom/utils/dom.d.ts +0 -104
  392. package/dist/dom/utils/dom.js +0 -257
  393. package/dist/dom/utils/drag-session.d.ts +0 -2
  394. package/dist/dom/utils/drag-session.js +0 -115
  395. package/dist/dom/utils/drop-indicator.d.ts +0 -18
  396. package/dist/dom/utils/drop-indicator.js +0 -36
  397. package/dist/dom/utils/environment.d.ts +0 -12
  398. package/dist/dom/utils/environment.js +0 -118
  399. package/dist/dom/utils/hotkey-match.d.ts +0 -36
  400. package/dist/dom/utils/hotkey-match.js +0 -208
  401. package/dist/dom/utils/hotkeys.d.ts +0 -32
  402. package/dist/dom/utils/hotkeys.js +0 -121
  403. package/dist/dom/utils/key.d.ts +0 -14
  404. package/dist/dom/utils/key.js +0 -18
  405. package/dist/dom/utils/plite-dom-markers.d.ts +0 -26
  406. package/dist/dom/utils/plite-dom-markers.js +0 -25
  407. package/dist/dom/utils/selection-writes.d.ts +0 -18
  408. package/dist/dom/utils/selection-writes.js +0 -63
  409. package/dist/dom/utils/weak-maps.d.ts +0 -2
  410. package/dist/dom/utils/weak-maps.js +0 -51
  411. package/dist/editor/above.js +0 -30
  412. package/dist/editor/add-mark.js +0 -79
  413. package/dist/editor/adjacent-character-point.js +0 -120
  414. package/dist/editor/after.js +0 -37
  415. package/dist/editor/before.js +0 -124
  416. package/dist/editor/block-void-break.js +0 -20
  417. package/dist/editor/correct-document.js +0 -225
  418. package/dist/editor/delete-backward.js +0 -64
  419. package/dist/editor/delete-forward.js +0 -11
  420. package/dist/editor/delete-fragment.js +0 -40
  421. package/dist/editor/edges.js +0 -5
  422. package/dist/editor/element-read-only.js +0 -35
  423. package/dist/editor/end.d.ts +0 -7
  424. package/dist/editor/end.js +0 -5
  425. package/dist/editor/exit-break.js +0 -51
  426. package/dist/editor/first.js +0 -8
  427. package/dist/editor/get-void.js +0 -9
  428. package/dist/editor/has-blocks.js +0 -6
  429. package/dist/editor/has-inlines.js +0 -6
  430. package/dist/editor/has-path.js +0 -5
  431. package/dist/editor/has-texts.js +0 -5
  432. package/dist/editor/insert-break.js +0 -77
  433. package/dist/editor/insert-default-child.js +0 -55
  434. package/dist/editor/insert-soft-break.js +0 -14
  435. package/dist/editor/insert-text.js +0 -83
  436. package/dist/editor/is-block.js +0 -5
  437. package/dist/editor/is-edge.js +0 -5
  438. package/dist/editor/is-editor.js +0 -13
  439. package/dist/editor/is-empty.js +0 -6
  440. package/dist/editor/is-end.js +0 -9
  441. package/dist/editor/is-start.js +0 -9
  442. package/dist/editor/last.js +0 -20
  443. package/dist/editor/leaf.js +0 -9
  444. package/dist/editor/levels.js +0 -21
  445. package/dist/editor/next.js +0 -46
  446. package/dist/editor/node.js +0 -9
  447. package/dist/editor/nodes.js +0 -106
  448. package/dist/editor/parent.js +0 -14
  449. package/dist/editor/path.js +0 -26
  450. package/dist/editor/point.js +0 -52
  451. package/dist/editor/positions.js +0 -322
  452. package/dist/editor/previous.js +0 -48
  453. package/dist/editor/project-range.js +0 -6
  454. package/dist/editor/range.js +0 -12
  455. package/dist/editor/remove-mark.js +0 -65
  456. package/dist/editor/should-merge-nodes-remove-prev-node.js +0 -11
  457. package/dist/editor/string.js +0 -35
  458. package/dist/editor/toggle-mark.js +0 -71
  459. package/dist/editor/unhang-range.js +0 -71
  460. package/dist/editor-runtime-view.d.ts +0 -33
  461. package/dist/editor-runtime-view.js +0 -788
  462. package/dist/history/history-carets.js +0 -127
  463. package/dist/history/history-character-map.js +0 -425
  464. package/dist/history/history-codec.js +0 -176
  465. package/dist/history/history-merge-policy.js +0 -164
  466. package/dist/history/history-plugin.d.ts +0 -71
  467. package/dist/history/history-plugin.js +0 -814
  468. package/dist/history/history-replay.js +0 -799
  469. package/dist/history/history-selection.js +0 -75
  470. package/dist/history/history-state.js +0 -1287
  471. package/dist/history/history.d.ts +0 -112
  472. package/dist/history/history.js +0 -29
  473. package/dist/hyperscript/creators.d.ts +0 -51
  474. package/dist/hyperscript/hyperscript.d.ts +0 -36
  475. package/dist/hyperscript/hyperscript.js +0 -66
  476. package/dist/hyperscript/tokens.d.ts +0 -31
  477. package/dist/hyperscript/tokens.js +0 -63
  478. package/dist/interfaces/decoration.d.ts +0 -35
  479. package/dist/interfaces/editor.d.ts +0 -2783
  480. package/dist/interfaces/editor.js +0 -348
  481. package/dist/interfaces/element.d.ts +0 -66
  482. package/dist/interfaces/element.js +0 -34
  483. package/dist/interfaces/index.d.ts +0 -13
  484. package/dist/interfaces/json.d.ts +0 -7
  485. package/dist/interfaces/location.d.ts +0 -50
  486. package/dist/interfaces/location.js +0 -26
  487. package/dist/interfaces/node.d.ts +0 -306
  488. package/dist/interfaces/node.js +0 -339
  489. package/dist/interfaces/path.d.ts +0 -118
  490. package/dist/interfaces/path.js +0 -116
  491. package/dist/interfaces/point.d.ts +0 -45
  492. package/dist/interfaces/point.js +0 -32
  493. package/dist/interfaces/range.d.ts +0 -80
  494. package/dist/interfaces/range.js +0 -85
  495. package/dist/interfaces/schema-validation.d.ts +0 -33
  496. package/dist/interfaces/schema.d.ts +0 -870
  497. package/dist/interfaces/selection.d.ts +0 -61
  498. package/dist/interfaces/selection.js +0 -106
  499. package/dist/interfaces/text.d.ts +0 -68
  500. package/dist/interfaces/text.js +0 -52
  501. package/dist/interfaces/transforms/node.d.ts +0 -222
  502. package/dist/interfaces/transforms/selection.d.ts +0 -48
  503. package/dist/interfaces/transforms/text.d.ts +0 -58
  504. package/dist/internal/browser-protocol.d.ts +0 -5
  505. package/dist/internal/document-range.d.ts +0 -9
  506. package/dist/internal/document-range.js +0 -31
  507. package/dist/internal/editor-options.d.ts +0 -37
  508. package/dist/internal/editor-options.js +0 -36
  509. package/dist/internal/fail-invariant.d.ts +0 -4
  510. package/dist/internal/fail-invariant.js +0 -6
  511. package/dist/internal/get-defined.js +0 -7
  512. package/dist/internal/law-check.js +0 -7
  513. package/dist/internal/range-text-marks.js +0 -31
  514. package/dist/internal/root-location.d.ts +0 -23
  515. package/dist/internal/root-location.js +0 -86
  516. package/dist/internal/text-run.d.ts +0 -13
  517. package/dist/internal/text-run.js +0 -44
  518. package/dist/internal/view/annotation-store-metrics.d.ts +0 -11
  519. package/dist/internal/view/view-source.d.ts +0 -20
  520. package/dist/pagination/page-composition.internal.js +0 -313
  521. package/dist/pagination/page-geometry.internal.js +0 -99
  522. package/dist/pagination/page-layout-engine-invalidation.internal.js +0 -20
  523. package/dist/pagination/page-mount-plan.js +0 -84
  524. package/dist/pagination/paged-view-lines.js +0 -163
  525. package/dist/range-projection.d.ts +0 -7
  526. package/dist/range-projection.js +0 -50
  527. package/dist/react/components/dom-coverage-boundary.d.ts +0 -14
  528. package/dist/react/components/dom-coverage-boundary.js +0 -143
  529. package/dist/react/components/editable-descendant-binding.js +0 -70
  530. package/dist/react/components/editable-dom-commit-fence.js +0 -107
  531. package/dist/react/components/editable-element-placement.d.ts +0 -2
  532. package/dist/react/components/editable-element-placement.js +0 -117
  533. package/dist/react/components/editable-external-text.js +0 -47
  534. package/dist/react/components/editable-node-equality.js +0 -25
  535. package/dist/react/components/editable-rendered-element.d.ts +0 -3
  536. package/dist/react/components/editable-rendered-element.js +0 -61
  537. package/dist/react/components/editable-text-blocks.d.ts +0 -192
  538. package/dist/react/components/editable-text-blocks.js +0 -896
  539. package/dist/react/components/editable-text-containers.d.ts +0 -3
  540. package/dist/react/components/editable-text-containers.js +0 -28
  541. package/dist/react/components/editable-text-flow.js +0 -1039
  542. package/dist/react/components/editable-text-pieces.d.ts +0 -7
  543. package/dist/react/components/editable-text-pieces.js +0 -193
  544. package/dist/react/components/editable-text.d.ts +0 -80
  545. package/dist/react/components/editable-text.js +0 -322
  546. package/dist/react/components/editable.d.ts +0 -35
  547. package/dist/react/components/editable.js +0 -406
  548. package/dist/react/components/editor-announcement-live-region.js +0 -113
  549. package/dist/react/components/plite-element.d.ts +0 -18
  550. package/dist/react/components/plite-element.js +0 -54
  551. package/dist/react/components/plite-leaf.d.ts +0 -18
  552. package/dist/react/components/plite-leaf.js +0 -21
  553. package/dist/react/components/plite-placeholder.d.ts +0 -19
  554. package/dist/react/components/plite-placeholder.js +0 -39
  555. package/dist/react/components/plite-spacer.js +0 -14
  556. package/dist/react/components/plite-text.d.ts +0 -23
  557. package/dist/react/components/plite-text.js +0 -32
  558. package/dist/react/components/plite-void-shell.js +0 -49
  559. package/dist/react/components/plite.d.ts +0 -45
  560. package/dist/react/components/plite.js +0 -297
  561. package/dist/react/components/text-string.js +0 -18
  562. package/dist/react/components/windowed-editable.internal.js +0 -51
  563. package/dist/react/components/zero-width-string.js +0 -26
  564. package/dist/react/context.js +0 -11
  565. package/dist/react/decoration-context.d.ts +0 -2
  566. package/dist/react/decoration-context.js +0 -22
  567. package/dist/react/decoration-source.d.ts +0 -11
  568. package/dist/react/decoration-source.js +0 -1030
  569. package/dist/react/dom-text-sync.d.ts +0 -24
  570. package/dist/react/dom-text-sync.js +0 -48
  571. package/dist/react/editable/android-composition.d.ts +0 -3
  572. package/dist/react/editable/android-composition.js +0 -496
  573. package/dist/react/editable/browser-handle.js +0 -515
  574. package/dist/react/editable/caret-engine.js +0 -681
  575. package/dist/react/editable/clipboard-input-strategy.js +0 -632
  576. package/dist/react/editable/composition-lease.d.ts +0 -3
  577. package/dist/react/editable/composition-lease.js +0 -350
  578. package/dist/react/editable/composition-state.js +0 -716
  579. package/dist/react/editable/content-root-boundaries.js +0 -79
  580. package/dist/react/editable/content-root-coordinate-navigation.js +0 -28
  581. package/dist/react/editable/content-root-navigation-actions.js +0 -190
  582. package/dist/react/editable/content-root-navigation.js +0 -819
  583. package/dist/react/editable/content-root-owner-target.js +0 -36
  584. package/dist/react/editable/content-root-owners.js +0 -191
  585. package/dist/react/editable/content-root-vertical-geometry.js +0 -60
  586. package/dist/react/editable/decoration-repair-bridge.js +0 -29
  587. package/dist/react/editable/dom-coverage-selection.js +0 -158
  588. package/dist/react/editable/dom-coverage-vertical-selection.js +0 -446
  589. package/dist/react/editable/dom-input-event.js +0 -14
  590. package/dist/react/editable/dom-repair-queue.d.ts +0 -7
  591. package/dist/react/editable/dom-repair-queue.js +0 -543
  592. package/dist/react/editable/dom-repair-text.js +0 -47
  593. package/dist/react/editable/editable-command-types.d.ts +0 -1
  594. package/dist/react/editable/editable-dom-runtime.d.ts +0 -66
  595. package/dist/react/editable/editable-dom-runtime.js +0 -1022
  596. package/dist/react/editable/editing-epoch-adapter.js +0 -46
  597. package/dist/react/editable/editing-kernel.d.ts +0 -7
  598. package/dist/react/editable/editing-kernel.js +0 -593
  599. package/dist/react/editable/external-text-binding.js +0 -43
  600. package/dist/react/editable/external-text-runtime.d.ts +0 -5
  601. package/dist/react/editable/external-text-runtime.js +0 -851
  602. package/dist/react/editable/history-focus.js +0 -71
  603. package/dist/react/editable/history-keyboard.d.ts +0 -4
  604. package/dist/react/editable/history-keyboard.js +0 -9
  605. package/dist/react/editable/input-controller.d.ts +0 -7
  606. package/dist/react/editable/input-controller.js +0 -175
  607. package/dist/react/editable/input-history.js +0 -21
  608. package/dist/react/editable/input-router.js +0 -742
  609. package/dist/react/editable/input-state.d.ts +0 -18
  610. package/dist/react/editable/input-state.js +0 -330
  611. package/dist/react/editable/input-target.js +0 -30
  612. package/dist/react/editable/install-browser-handle.d.ts +0 -12
  613. package/dist/react/editable/install-browser-handle.js +0 -18
  614. package/dist/react/editable/interaction-owner.js +0 -88
  615. package/dist/react/editable/keyboard-input-strategy.js +0 -730
  616. package/dist/react/editable/line-boundary.js +0 -37
  617. package/dist/react/editable/model-input-strategy.d.ts +0 -9
  618. package/dist/react/editable/model-input-strategy.js +0 -242
  619. package/dist/react/editable/model-selection-dom-preference.js +0 -11
  620. package/dist/react/editable/mutation-block-editing.js +0 -48
  621. package/dist/react/editable/mutation-controller.d.ts +0 -32
  622. package/dist/react/editable/mutation-controller.js +0 -632
  623. package/dist/react/editable/mutation-full-block-editing.d.ts +0 -2
  624. package/dist/react/editable/mutation-full-block-editing.js +0 -44
  625. package/dist/react/editable/mutation-history.d.ts +0 -3
  626. package/dist/react/editable/mutation-history.js +0 -146
  627. package/dist/react/editable/native-input-strategy.js +0 -86
  628. package/dist/react/editable/native-text-input-delta.js +0 -40
  629. package/dist/react/editable/placed-drag.js +0 -177
  630. package/dist/react/editable/plite-string-coordinate-placement.js +0 -46
  631. package/dist/react/editable/press-fence.d.ts +0 -2
  632. package/dist/react/editable/press-fence.js +0 -70
  633. package/dist/react/editable/projected-clipboard.js +0 -123
  634. package/dist/react/editable/projected-native-affordance.js +0 -30
  635. package/dist/react/editable/projected-selection-target.js +0 -13
  636. package/dist/react/editable/render-contract-monitor.d.ts +0 -3
  637. package/dist/react/editable/render-contract-monitor.js +0 -152
  638. package/dist/react/editable/root-interaction-controller.js +0 -1400
  639. package/dist/react/editable/root-interaction-dom-selection-replay.js +0 -40
  640. package/dist/react/editable/root-interaction-resolver.js +0 -116
  641. package/dist/react/editable/root-selector-sources.js +0 -90
  642. package/dist/react/editable/runtime-android-engine.js +0 -40
  643. package/dist/react/editable/runtime-before-input-events.js +0 -671
  644. package/dist/react/editable/runtime-browser-handle-events.js +0 -40
  645. package/dist/react/editable/runtime-clipboard-events.js +0 -169
  646. package/dist/react/editable/runtime-composition-events.js +0 -163
  647. package/dist/react/editable/runtime-drag-events.js +0 -136
  648. package/dist/react/editable/runtime-editor-api.d.ts +0 -20
  649. package/dist/react/editable/runtime-editor-api.js +0 -21
  650. package/dist/react/editable/runtime-event-engine.js +0 -213
  651. package/dist/react/editable/runtime-focus-mouse-events.js +0 -264
  652. package/dist/react/editable/runtime-input-events.js +0 -166
  653. package/dist/react/editable/runtime-kernel-trace.js +0 -185
  654. package/dist/react/editable/runtime-keyboard-events.js +0 -333
  655. package/dist/react/editable/runtime-live-state.js +0 -44
  656. package/dist/react/editable/runtime-mutation-state.js +0 -11
  657. package/dist/react/editable/runtime-repair-engine.js +0 -118
  658. package/dist/react/editable/runtime-root-engine.js +0 -244
  659. package/dist/react/editable/runtime-root-lifecycle.js +0 -118
  660. package/dist/react/editable/runtime-root-selection-export.js +0 -38
  661. package/dist/react/editable/runtime-root-selection-import.js +0 -54
  662. package/dist/react/editable/runtime-root-state.js +0 -62
  663. package/dist/react/editable/runtime-selection-engine.js +0 -260
  664. package/dist/react/editable/runtime-selection-state.js +0 -12
  665. package/dist/react/editable/runtime-target-bridge.js +0 -29
  666. package/dist/react/editable/schema-runtime-invalidation.js +0 -26
  667. package/dist/react/editable/selection-change-listener.js +0 -99
  668. package/dist/react/editable/selection-claim.d.ts +0 -3
  669. package/dist/react/editable/selection-claim.js +0 -398
  670. package/dist/react/editable/selection-controller.d.ts +0 -8
  671. package/dist/react/editable/selection-controller.js +0 -693
  672. package/dist/react/editable/selection-dom-range.js +0 -84
  673. package/dist/react/editable/selection-projected-dom.js +0 -156
  674. package/dist/react/editable/selection-reconciler.js +0 -630
  675. package/dist/react/editable/selection-runtime.js +0 -89
  676. package/dist/react/editable/selection-side-effect-policy.js +0 -20
  677. package/dist/react/editable/selection-triple-click.js +0 -48
  678. package/dist/react/editable/selection-void-target.js +0 -172
  679. package/dist/react/editable/set-root-endpoints.js +0 -75
  680. package/dist/react/editable/soft-line-end-delete.js +0 -106
  681. package/dist/react/editable/text-direction.js +0 -82
  682. package/dist/react/editable/typed-text.d.ts +0 -17
  683. package/dist/react/editable/typed-text.js +0 -89
  684. package/dist/react/editable/unread-press.d.ts +0 -2
  685. package/dist/react/editable/unread-press.js +0 -86
  686. package/dist/react/editable/view-caret-restore.js +0 -128
  687. package/dist/react/editable/view-lines.d.ts +0 -7
  688. package/dist/react/editable/view-lines.js +0 -166
  689. package/dist/react/external-text.d.ts +0 -131
  690. package/dist/react/history-step-views.d.ts +0 -4
  691. package/dist/react/history-step-views.js +0 -119
  692. package/dist/react/hooks/android-input-manager/android-input-manager.d.ts +0 -7
  693. package/dist/react/hooks/android-input-manager/android-input-manager.js +0 -716
  694. package/dist/react/hooks/android-input-manager/use-android-input-manager.js +0 -53
  695. package/dist/react/hooks/focus-plite-editable.js +0 -116
  696. package/dist/react/hooks/use-claim-editable-dom-commit.d.ts +0 -12
  697. package/dist/react/hooks/use-claim-editable-dom-commit.js +0 -31
  698. package/dist/react/hooks/use-drop-indicator.d.ts +0 -9
  699. package/dist/react/hooks/use-drop-indicator.js +0 -14
  700. package/dist/react/hooks/use-editable-clip.d.ts +0 -18
  701. package/dist/react/hooks/use-editable-clip.js +0 -31
  702. package/dist/react/hooks/use-editable-layout-pass.js +0 -53
  703. package/dist/react/hooks/use-editor-composing.d.ts +0 -7
  704. package/dist/react/hooks/use-editor-composing.js +0 -12
  705. package/dist/react/hooks/use-editor-context.d.ts +0 -10
  706. package/dist/react/hooks/use-editor-context.js +0 -18
  707. package/dist/react/hooks/use-editor-dom-scope.d.ts +0 -27
  708. package/dist/react/hooks/use-editor-dom-scope.js +0 -23
  709. package/dist/react/hooks/use-editor-focused.d.ts +0 -7
  710. package/dist/react/hooks/use-editor-focused.js +0 -12
  711. package/dist/react/hooks/use-editor-read-only.d.ts +0 -25
  712. package/dist/react/hooks/use-editor-read-only.js +0 -19
  713. package/dist/react/hooks/use-editor-runtime-state.d.ts +0 -18
  714. package/dist/react/hooks/use-editor-runtime-state.js +0 -38
  715. package/dist/react/hooks/use-editor-selection.d.ts +0 -10
  716. package/dist/react/hooks/use-editor-selection.js +0 -13
  717. package/dist/react/hooks/use-editor-selector.d.ts +0 -38
  718. package/dist/react/hooks/use-editor-selector.js +0 -265
  719. package/dist/react/hooks/use-editor-view-state.d.ts +0 -16
  720. package/dist/react/hooks/use-editor-view-state.js +0 -20
  721. package/dist/react/hooks/use-editor.d.ts +0 -26
  722. package/dist/react/hooks/use-editor.js +0 -27
  723. package/dist/react/hooks/use-element-path.d.ts +0 -7
  724. package/dist/react/hooks/use-element-path.js +0 -36
  725. package/dist/react/hooks/use-element-selected.d.ts +0 -26
  726. package/dist/react/hooks/use-element-selected.js +0 -91
  727. package/dist/react/hooks/use-element.d.ts +0 -13
  728. package/dist/react/hooks/use-element.js +0 -17
  729. package/dist/react/hooks/use-generic-selector.js +0 -91
  730. package/dist/react/hooks/use-hydrated.js +0 -12
  731. package/dist/react/hooks/use-isomorphic-layout-effect.js +0 -9
  732. package/dist/react/hooks/use-node-selector.d.ts +0 -40
  733. package/dist/react/hooks/use-node-selector.js +0 -102
  734. package/dist/react/hooks/use-plite-annotation-store.d.ts +0 -21
  735. package/dist/react/hooks/use-plite-annotation-store.js +0 -61
  736. package/dist/react/hooks/use-plite-annotations.d.ts +0 -9
  737. package/dist/react/hooks/use-plite-annotations.js +0 -16
  738. package/dist/react/hooks/use-plite-child-root.d.ts +0 -14
  739. package/dist/react/hooks/use-plite-child-root.js +0 -38
  740. package/dist/react/hooks/use-plite-content-root.d.ts +0 -21
  741. package/dist/react/hooks/use-plite-content-root.js +0 -26
  742. package/dist/react/hooks/use-plite-history.d.ts +0 -43
  743. package/dist/react/hooks/use-plite-history.js +0 -137
  744. package/dist/react/hooks/use-plite-node-ref.js +0 -513
  745. package/dist/react/hooks/use-plite-root-chrome.d.ts +0 -34
  746. package/dist/react/hooks/use-plite-root-chrome.js +0 -98
  747. package/dist/react/hooks/use-plite-runtime.d.ts +0 -86
  748. package/dist/react/hooks/use-plite-runtime.js +0 -433
  749. package/dist/react/hooks/use-runtime-focus-state.js +0 -37
  750. package/dist/react/hooks/use-selection-geometry.d.ts +0 -12
  751. package/dist/react/hooks/use-selection-geometry.js +0 -39
  752. package/dist/react/hooks/use-selection-view.d.ts +0 -14
  753. package/dist/react/hooks/use-selection-view.js +0 -14
  754. package/dist/react/hooks/use-state-field.d.ts +0 -26
  755. package/dist/react/hooks/use-state-field.js +0 -38
  756. package/dist/react/inactive-selection.js +0 -175
  757. package/dist/react/plugin/react-editor.d.ts +0 -20
  758. package/dist/react/plugin/react-editor.js +0 -6
  759. package/dist/react/plugin/with-react.d.ts +0 -108
  760. package/dist/react/plugin/with-react.js +0 -58
  761. package/dist/react/render-profiler.js +0 -20
  762. package/dist/react/root-key.js +0 -12
  763. package/dist/react/shell-runtime.js +0 -29
  764. package/dist/react/update-policy.d.ts +0 -10
  765. package/dist/react/update-policy.js +0 -15
  766. package/dist/react/utils/environment.js +0 -5
  767. package/dist/react/view-boundary-graph-core.d.ts +0 -1
  768. package/dist/react/view-boundary-graph-core.js +0 -208
  769. package/dist/react/view-boundary-graph.js +0 -105
  770. package/dist/react/view-selection-decoration.js +0 -97
  771. package/dist/react/view-selection.js +0 -184
  772. package/dist/react/viewport-boundary.js +0 -45
  773. package/dist/react/viewport-commands.d.ts +0 -1
  774. package/dist/react/viewport-commands.js +0 -17
  775. package/dist/react/viewport-plan.d.ts +0 -2
  776. package/dist/react/viewport-plan.js +0 -77
  777. package/dist/react/virtualized/use-virtualized-root-plan.js +0 -148
  778. package/dist/testing/createDataTransfer.d.ts +0 -4
  779. package/dist/testing/createDataTransfer.js +0 -13
  780. package/dist/testing/jsx.d.ts +0 -181
  781. package/dist/testing/jsx.js +0 -82
  782. package/dist/transforms-node/insert-nodes.js +0 -143
  783. package/dist/transforms-node/lift-nodes.js +0 -117
  784. package/dist/transforms-node/merge-nodes.js +0 -180
  785. package/dist/transforms-node/move-nodes.js +0 -58
  786. package/dist/transforms-node/remove-nodes.js +0 -86
  787. package/dist/transforms-node/replace-children.js +0 -117
  788. package/dist/transforms-node/set-nodes.js +0 -188
  789. package/dist/transforms-node/split-nodes.js +0 -258
  790. package/dist/transforms-node/unset-nodes.js +0 -10
  791. package/dist/transforms-node/unwrap-nodes.js +0 -182
  792. package/dist/transforms-node/wrap-nodes.js +0 -250
  793. package/dist/transforms-selection/collapse.js +0 -20
  794. package/dist/transforms-selection/deselect.js +0 -8
  795. package/dist/transforms-selection/move.js +0 -35
  796. package/dist/transforms-selection/select.js +0 -59
  797. package/dist/transforms-selection/set-point.js +0 -32
  798. package/dist/transforms-selection/set-selection.js +0 -52
  799. package/dist/transforms-text/delete-text-collapsed-path-targets.js +0 -102
  800. package/dist/transforms-text/delete-text-grid.js +0 -402
  801. package/dist/transforms-text/delete-text-inline-points.js +0 -82
  802. package/dist/transforms-text/delete-text-plan.js +0 -55
  803. package/dist/transforms-text/delete-text-removal.js +0 -153
  804. package/dist/transforms-text/delete-text-structural-cleanup.js +0 -130
  805. package/dist/transforms-text/delete-text-whole-blocks.js +0 -70
  806. package/dist/transforms-text/delete-text.js +0 -804
  807. package/dist/transforms-text/full-document-range.js +0 -12
  808. package/dist/transforms-text/insert-text.js +0 -314
  809. package/dist/types/types.d.ts +0 -13
  810. package/dist/utils/format-debug-value.d.ts +0 -8
  811. package/dist/utils/format-debug-value.js +0 -31
  812. package/dist/utils/get-default-insert-location.js +0 -19
  813. package/dist/utils/is-object.d.ts +0 -4
  814. package/dist/utils/is-object.js +0 -4
  815. package/dist/utils/match-path.js +0 -8
  816. package/dist/utils/node-keys.d.ts +0 -15
  817. package/dist/utils/node-keys.js +0 -179
  818. package/dist/utils/node-match.js +0 -9
  819. package/dist/utils/string.js +0 -283
  820. package/dist/yjs/core/addresses.js +0 -98
  821. package/dist/yjs/core/ancestor-properties.js +0 -56
  822. package/dist/yjs/core/attributes.js +0 -21
  823. package/dist/yjs/core/awareness-adapter.d.ts +0 -5
  824. package/dist/yjs/core/awareness-adapter.js +0 -399
  825. package/dist/yjs/core/awareness-relative-selection.js +0 -22
  826. package/dist/yjs/core/awareness.js +0 -25
  827. package/dist/yjs/core/binding.d.ts +0 -3
  828. package/dist/yjs/core/binding.js +0 -128
  829. package/dist/yjs/core/boundaries.js +0 -453
  830. package/dist/yjs/core/canonical-split.js +0 -130
  831. package/dist/yjs/core/change-bridge.js +0 -124
  832. package/dist/yjs/core/change-regions.js +0 -119
  833. package/dist/yjs/core/controller-registry.js +0 -70
  834. package/dist/yjs/core/controller.d.ts +0 -6
  835. package/dist/yjs/core/controller.js +0 -1282
  836. package/dist/yjs/core/document.js +0 -1499
  837. package/dist/yjs/core/editor-adapter.d.ts +0 -18
  838. package/dist/yjs/core/editor-adapter.js +0 -145
  839. package/dist/yjs/core/editor-only-roots.js +0 -53
  840. package/dist/yjs/core/editor-types.d.ts +0 -1
  841. package/dist/yjs/core/enclosures.js +0 -410
  842. package/dist/yjs/core/event-change-bridge.js +0 -3642
  843. package/dist/yjs/core/index.d.ts +0 -4
  844. package/dist/yjs/core/joined-lines.js +0 -81
  845. package/dist/yjs/core/joins.js +0 -587
  846. package/dist/yjs/core/json-equality.js +0 -31
  847. package/dist/yjs/core/keys.js +0 -29
  848. package/dist/yjs/core/letter-scripts.js +0 -449
  849. package/dist/yjs/core/new-letters.js +0 -300
  850. package/dist/yjs/core/path.js +0 -25
  851. package/dist/yjs/core/plugin.js +0 -206
  852. package/dist/yjs/core/record.js +0 -4
  853. package/dist/yjs/core/replacement.js +0 -165
  854. package/dist/yjs/core/retraction.js +0 -132
  855. package/dist/yjs/core/root-owners.js +0 -110
  856. package/dist/yjs/core/root-projection-index.js +0 -428
  857. package/dist/yjs/core/schema-metadata.js +0 -88
  858. package/dist/yjs/core/selection.js +0 -34
  859. package/dist/yjs/core/set-valued-attributes.js +0 -57
  860. package/dist/yjs/core/shared-effect-log.d.ts +0 -4
  861. package/dist/yjs/core/shared-effect-log.js +0 -674
  862. package/dist/yjs/core/text-runs.js +0 -1596
  863. package/dist/yjs/core/types.d.ts +0 -76
  864. package/dist/yjs/react/useYjs.d.ts +0 -25
  865. package/dist/yjs/react/useYjs.js +0 -85
@@ -1,2295 +0,0 @@
1
- import { getDefined } from "../internal/get-defined.js";
2
- import { countCoreWork } from "./work.js";
3
- import { cloneFrozen, isImmutable, isOwnedJsonValue } from "./clone.js";
4
- import { jsonEqual } from "./change/json.js";
5
- import { isFrozenWithRoots, visitRootNames } from "./change/lazy-root.js";
6
- import { areEditorJsonValuesEqual, assertEditorJsonValue, snapshotEditorJsonValue } from "./value-codec.js";
7
- import { getValueRecords } from "./record-store.js";
8
- import { normalizeSetValues } from "./change/transform.js";
9
- import { DocumentIndex, rootIndexOf } from "./change/document-index.js";
10
- import { profileCoreDuration } from "./profiling.js";
11
- import { getInternalDocumentChangeEntries, getInternalDocumentChangeRecords, getInternalDocumentRootChange, valueRootIndex, valueRootNodes } from "./change/document-change.js";
12
- import { TextApi } from "../interfaces/text.js";
13
- import { ElementApi } from "../interfaces/element.js";
14
- import { failInvariant } from "../internal/fail-invariant.js";
15
- import { getEditorDocumentShapeIssueMessage, readEditorDocument } from "./document-shape.js";
16
- import { getCompiledPropertyCandidates, matchesCompiledSchemaTarget, resolveCompiledSchemaProperty, toCompiledNodeContext, toCompiledTargetContext, unwrittenAs } from "./schema-compiler.js";
17
- import { getPluginRegistry } from "./plugin-registry.js";
18
- import { ContentSlice } from "./content-slice.js";
19
- import { countElementOwnedRootBuilds, ensureElementOwnedRootIndex, findElementOwnedRootOwnerPath, forgetElementOwnedRootBuilds, getChangedElementOwnedRootKeys, getElementOwnedRootGrammarBindings, getElementOwnedRootIssues, getElementOwnedRootKeys, getIntroducedElementOwnedRootIssues, rebaseElementOwnedRootIndex, schemaDeclaresSetRoots } from "./element-owned-root-index.js";
20
- import { emptyIndexedDocument, orphanedRoots, schemaHasContentRoots } from "./root-ownership.js";
21
- import { completeContent } from "./content-completion.js";
22
- import { getPropertyDefault } from "./default-storage.js";
23
- import { verdictOf } from "./property-validity.js";
24
- import { EditorSchemaValidationError, createEditorSchemaValidationError } from "./schema-validation.js";
25
- import { schemaModelLocation, schemaRepair } from "./slice-fit/fit-report.js";
26
- import { createCompiledSliceFitterDelegate } from "./slice-fit/compiled-slice-fitter.js";
27
- import { getEditorDocumentValue } from "./public-state.js";
28
- import { NodeApi } from "../interfaces/node.js";
29
- //#region src/core/editor-schema.ts
30
- /**
31
- * A required property that nothing supplies. Only `createDeclarativeAndFill`
32
- * and `canonicalizeDeclarativePropertyRecord` without a `validationLocation`
33
- * throw it, so `refuseMissingProperty` returns `null` for it alone, and every
34
- * other failure still throws, a `missing-property` error from validation or
35
- * one from a generator included.
36
- */
37
- var MissingPropertyError = class extends EditorSchemaValidationError {
38
- constructor(diagnostics) {
39
- super(diagnostics);
40
- this.name = "MissingPropertyError";
41
- }
42
- };
43
- const refuseMissingProperty = (build) => {
44
- try {
45
- return build();
46
- } catch (error) {
47
- if (error instanceof MissingPropertyError) return null;
48
- throw error;
49
- }
50
- };
51
- /**
52
- * A build under a mask that needs a generated element value the mask
53
- * covers, which a resolver tells apart from every other build failure.
54
- *
55
- * @internal
56
- */
57
- var ElementGenerationMaskedError = class extends Error {
58
- name = "ElementGenerationMaskedError";
59
- constructor() {
60
- super("A build under masked element generation needs a generated value.");
61
- }
62
- };
63
- /**
64
- * The generators a build may not run: every one, the ones of the properties
65
- * a set names, or none.
66
- */
67
- let masked = null;
68
- const withMask = (mask, read) => {
69
- const outer = masked;
70
- masked = outer === "every" || mask === "every" ? "every" : outer ? /* @__PURE__ */ new Set([...outer, ...mask]) : mask;
71
- try {
72
- return read();
73
- } finally {
74
- masked = outer;
75
- }
76
- };
77
- /**
78
- * Builds under `read` run no generator: one that needs a generated element
79
- * value throws `ElementGenerationMaskedError`, and one that needs a text
80
- * value throws a schema refusal.
81
- *
82
- * @internal
83
- */
84
- const withoutGeneration = (read) => withMask("every", read);
85
- /**
86
- * Builds under `read` run every generator but those of `properties`, and
87
- * throw `ElementGenerationMaskedError` where they need one of theirs.
88
- *
89
- * @internal
90
- */
91
- const withoutGenerationOf = (properties, read) => properties.size === 0 ? read() : withMask(properties, read);
92
- /**
93
- * A `MissingPropertyError` from a generator's own schema build, such as
94
- * `schema.create`, fails the outer build instead of refusing it.
95
- */
96
- const generatePropertyValue = (property, placement) => {
97
- if (masked === "every" ? placement === "element" : masked?.has(property)) throw new ElementGenerationMaskedError();
98
- if (masked === "every") throw new EditorSchemaValidationError("An export cannot generate a property value.");
99
- try {
100
- return property.descriptor.generate?.();
101
- } catch (error) {
102
- throw error instanceof MissingPropertyError ? new EditorSchemaValidationError(error.diagnostics, { cause: error }) : error;
103
- }
104
- };
105
- const structurallyEqual = (left, right) => {
106
- if (Object.is(left, right)) return true;
107
- if (Array.isArray(left) || Array.isArray(right)) return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => structurallyEqual(value, right[index]));
108
- if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) return false;
109
- const leftRecord = left;
110
- const rightRecord = right;
111
- const keys = Object.keys(leftRecord);
112
- return keys.length === Object.keys(rightRecord).length && keys.every((key) => Object.hasOwn(rightRecord, key) && structurallyEqual(leftRecord[key], rightRecord[key]));
113
- };
114
- const nodePropertiesEqual = (left, right, contentKey, rightKeys) => {
115
- if (Object.keys(left).length - (Object.hasOwn(left, contentKey) ? 1 : 0) !== rightKeys.length) return false;
116
- for (const key of rightKeys) if (!Object.hasOwn(left, key) || !structurallyEqual(left[key], right[key])) return false;
117
- return true;
118
- };
119
- const contentProgramsEqual = (left, right) => left === right || left !== null && right !== null && left.allowsText === right.allowsText && left.allowsUnknownElements === right.allowsUnknownElements && left.min === right.min && left.max === right.max && left.allowedElementTypes.size === right.allowedElementTypes.size && [...left.allowedElementTypes].every((type) => right.allowedElementTypes.has(type)) && structurallyEqual(left.defaultPlan, right.defaultPlan) && structurallyEqual(left.prefix, right.prefix) && contentProgramsEqual(left.remainder ?? null, right.remainder ?? null);
120
- const canonicalizeCompiledExclusiveTextProperties = (schema, source, context, preferredKey) => {
121
- const entries = Object.entries(source).map(([key, value]) => ({
122
- key,
123
- property: resolveCompiledSchemaProperty(schema, "text", key, context),
124
- value
125
- }));
126
- const preferredId = preferredKey ? resolveCompiledSchemaProperty(schema, "text", preferredKey, context)?.id : void 0;
127
- const acceptedIds = /* @__PURE__ */ new Set();
128
- const acceptedKeys = /* @__PURE__ */ new Set();
129
- for (const entry of [...entries].sort((left, right) => {
130
- return (left.property?.id === preferredId ? 0 : 1) - (right.property?.id === preferredId ? 0 : 1) || (left.property?.id ?? left.key).localeCompare(right.property?.id ?? right.key) || left.key.localeCompare(right.key);
131
- })) {
132
- const { property } = entry;
133
- const active = property && unwrittenAs(property.descriptor, entry.value) !== "left-out";
134
- if (active && [...acceptedIds].some((acceptedId) => schema.properties.conflictsByPropertyId.get(acceptedId)?.has(property.id))) continue;
135
- acceptedKeys.add(entry.key);
136
- if (active) acceptedIds.add(property.id);
137
- }
138
- if (acceptedKeys.size === entries.length) return source;
139
- return Object.freeze(Object.fromEntries(entries.flatMap(({ key, value }) => acceptedKeys.has(key) ? [[key, value]] : [])));
140
- };
141
- const getTextPropertyInParent = (schema, key, parentContext) => {
142
- if (parentContext) return resolveCompiledSchemaProperty(schema, "text", key, parentContext);
143
- const candidates = getCompiledPropertyCandidates(schema, "text", key);
144
- return candidates.length === 1 ? candidates[0] : null;
145
- };
146
- const getCompiledEmptyTextDrops = (schema, context) => {
147
- if (schema?.elements.byType.get(context.type)?.behavior.void) return;
148
- return (key, value) => {
149
- const property = schema && getTextPropertyInParent(schema, key, context.type ? context : null);
150
- if (!property) return true;
151
- const { descriptor } = property;
152
- return !(property.role === "metadata" || descriptor.required || descriptor.generate !== void 0 || Object.hasOwn(descriptor, "default") && areEditorJsonValuesEqual(descriptor.default, value));
153
- };
154
- };
155
- const fillDefaultedProperties = (schema, placement, context, output, valueOf) => {
156
- const allowedIds = placement === "element" ? schema.properties.elementAllowedByType.get(context.type) : schema.properties.textAllowedByParentType.get(context.type);
157
- for (const id of allowedIds ?? []) {
158
- const property = schema.properties.byId.get(id);
159
- if (!property || typeof property.key !== "string" || Object.hasOwn(output, property.key) || !matchesCompiledSchemaTarget(schema, property.target, context) || !Object.hasOwn(property.descriptor, "default") && !property.descriptor.generate || property.descriptor.omitDefault) continue;
160
- output[property.key] = valueOf(property, property.key);
161
- }
162
- };
163
- /** @internal */
164
- const readEmptyText = (schema, ancestors, root) => {
165
- const context = toCompiledNodeContext({ text: "" }, ancestors, root);
166
- const output = { text: "" };
167
- let generated = false;
168
- fillDefaultedProperties(schema, "text", context, output, (property) => {
169
- generated ||= !!property.descriptor.generate;
170
- return property.descriptor.default;
171
- });
172
- return generated ? null : canonicalizeCompiledExclusiveTextProperties(schema, output, context);
173
- };
174
- const canonicalizeCompiledTextProperties = (schema, text, context) => {
175
- const drops = text.text === "" ? getCompiledEmptyTextDrops(schema, context) : void 0;
176
- const kept = drops && Object.entries(text).filter(([key, value]) => key === "text" || !drops(key, value));
177
- return canonicalizeCompiledExclusiveTextProperties(schema, kept && kept.length < Object.keys(text).length ? Object.fromEntries(kept) : text, context);
178
- };
179
- const getElementType = (element) => typeof element.type === "string" && element.type.length > 0 ? element.type : null;
180
- const getValidationNodeType = (node) => NodeApi.isText(node) ? "text" : getElementType(node) ?? void 0;
181
- const toSchemaValidationLocation = (root, path, nodeType, ancestors = []) => {
182
- const ancestorTypes = ancestors.flatMap((ancestor) => {
183
- const type = getElementType(ancestor);
184
- return type ? [type] : [];
185
- });
186
- return {
187
- ...ancestorTypes.length > 0 ? { ancestorTypes } : {},
188
- ...nodeType === void 0 ? {} : { nodeType },
189
- ...ancestorTypes[0] ? { parentType: ancestorTypes[0] } : {},
190
- path,
191
- root: root === "main" ? null : root
192
- };
193
- };
194
- const canonicalizePropertyValue = (owner, descriptor, value) => {
195
- let canonical;
196
- if (descriptor.kind === "set") {
197
- if (!Array.isArray(value)) throw new EditorSchemaValidationError(`${owner} must be an array.`);
198
- const itemDescriptor = descriptor.item;
199
- canonical = normalizeSetValues(value.map((item) => canonicalizePropertyValue(owner, itemDescriptor, item)));
200
- } else {
201
- try {
202
- canonical = snapshotEditorJsonValue(value, owner);
203
- } catch {
204
- throw new EditorSchemaValidationError(`${owner} must encode to JSON-compatible data.`);
205
- }
206
- if (!(descriptor.kind === "json" || (descriptor.kind === "enum" ? typeof canonical === "string" && descriptor.values.includes(canonical) : typeof canonical === descriptor.kind))) throw new EditorSchemaValidationError(`${owner} must be ${descriptor.kind}.`);
207
- }
208
- return canonical;
209
- };
210
- /**
211
- * A fresh generated value for an element property, as building an element
212
- * would store it. Under a generation mask it throws as that build would.
213
- *
214
- * @internal
215
- */
216
- const generateElementPropertyValue = (property) => canonicalizePropertyValue(`Editor element property "${String(property.key)}"`, property.descriptor, generatePropertyValue(property, "element"));
217
- const validatePropertyValue = (owner, descriptor, value) => {
218
- const canonical = canonicalizePropertyValue(owner, descriptor, value);
219
- const validateCanonical = (currentDescriptor, current) => {
220
- if (currentDescriptor.kind === "set") {
221
- const itemDescriptor = currentDescriptor.item;
222
- for (const item of current) validateCanonical(itemDescriptor, item);
223
- }
224
- if (currentDescriptor.validate && !verdictOf(currentDescriptor.validate, current)) throw new EditorSchemaValidationError(`${owner} fails custom property validation.`);
225
- };
226
- validateCanonical(descriptor, canonical);
227
- return canonical;
228
- };
229
- const acceptsPropertyValue = (descriptor, value) => {
230
- try {
231
- validatePropertyValue("Editor property", descriptor, value);
232
- return true;
233
- } catch (error) {
234
- if (error instanceof ElementGenerationMaskedError) throw error;
235
- return false;
236
- }
237
- };
238
- const getDocumentRoot = (value, root) => root === "main" ? value.children : value.roots?.[root] ?? [];
239
- const getDocumentRootNodes = (value, root) => valueRootNodes(value, root);
240
- const editorRootLabel = (root) => root === "main" ? "primary root" : `root "${root}"`;
241
- const getDescendant = (children, path) => {
242
- let descendants = children;
243
- let node;
244
- for (const index of path) {
245
- node = descendants.at(index);
246
- if (!node) return null;
247
- descendants = ElementApi.isElement(node) ? node.children : [];
248
- }
249
- return node ?? null;
250
- };
251
- const getElementAncestors = (children, path, options = {}) => {
252
- const ancestors = [];
253
- const limit = options.includeTarget ? path.length : path.length - 1;
254
- for (let depth = 1; depth <= limit; depth++) {
255
- const node = getDescendant(children, path.slice(0, depth));
256
- if (ElementApi.isElement(node)) ancestors.unshift(node);
257
- }
258
- return ancestors;
259
- };
260
- const COMPILED_SCHEMA_BY_API = /* @__PURE__ */ new WeakMap();
261
- const INTERNAL_BY_API = /* @__PURE__ */ new WeakMap();
262
- const REPRESENTATION_EDITOR_BY_API = /* @__PURE__ */ new WeakMap();
263
- const VALIDATED_DOCUMENT_ROOTS = /* @__PURE__ */ new Map();
264
- const isRootValidatedBy = (children, authority) => VALIDATED_DOCUMENT_ROOTS.get(authority)?.has(children) === true;
265
- const markRootValidatedBy = (children, authority) => {
266
- let roots = VALIDATED_DOCUMENT_ROOTS.get(authority);
267
- if (!roots) {
268
- roots = /* @__PURE__ */ new WeakSet();
269
- VALIDATED_DOCUMENT_ROOTS.set(authority, roots);
270
- }
271
- roots.add(children);
272
- };
273
- const DEEP_FROZEN_NODES = /* @__PURE__ */ new WeakSet();
274
- const isDeepFrozenNode = (node) => {
275
- if (DEEP_FROZEN_NODES.has(node)) return true;
276
- if (!Object.isFrozen(node) || !NodeApi.isText(node) && (!Object.isFrozen(node.children) || !node.children.every(isDeepFrozenNode))) return false;
277
- DEEP_FROZEN_NODES.add(node);
278
- return true;
279
- };
280
- const VALIDATED_ROOT_NODES = /* @__PURE__ */ new WeakMap();
281
- const SCHEMA_HAS_COPY_TRANSFORMS = /* @__PURE__ */ new WeakMap();
282
- const rootNodes = (document) => document.nodes;
283
- /**
284
- * Resolve the exact compiled artifact behind a candidate schema API.
285
- *
286
- * @internal
287
- */
288
- const getCompiledEditorSchemaFromApi = (schemaApi) => COMPILED_SCHEMA_BY_API.get(schemaApi)?.() ?? null;
289
- /** @internal */
290
- const getInternalEditorSchemaFromApi = (schemaApi) => getDefined(INTERNAL_BY_API.get(schemaApi));
291
- /**
292
- * The editor `schemaApi` completes and canonicalizes content through, which
293
- * reads only that schema, so a detached schema completes with no live editor.
294
- *
295
- * @internal
296
- */
297
- const getRepresentationEditorFromApi = (schemaApi) => getDefined(REPRESENTATION_EDITOR_BY_API.get(schemaApi));
298
- /** @internal */
299
- const placeElementAt = (schemaApi, source, options) => getInternalEditorSchemaFromApi(schemaApi).placeElementAt(source, options);
300
- /** @internal */
301
- const canPlaceBlocksAtPath = (schemaApi, at, fit, options = {}) => getInternalEditorSchemaFromApi(schemaApi).canPlaceAtPath(at, fit, options);
302
- /** @internal */
303
- const landNodePropertiesAt = (schemaApi, change, path, options = {}) => getInternalEditorSchemaFromApi(schemaApi).landNodePropertiesAt(change, path, options.root);
304
- /**
305
- * Whether a root that changed only inside `windows`, ordered by position,
306
- * still holds its content. It checks each child inside a window at its final
307
- * index, each retained child that ends in or leaves the root's prefix, and the
308
- * final count. Any other retained child keeps a remainder slot, which does not
309
- * depend on its index.
310
- *
311
- * @internal
312
- */
313
- const holdsImportedRoot = (schema, root, after, windows) => {
314
- const content = schema.getRootContent(root);
315
- if (!content) return true;
316
- if (after.length < content.min || content.max !== null && after.length > content.max) return false;
317
- const indexes = /* @__PURE__ */ new Set();
318
- let next = 0;
319
- let shift = 0;
320
- for (const window of windows) for (let index = window.afterFrom; index < window.afterTo; index++) indexes.add(index);
321
- for (let index = 0; index < (content.prefix?.length ?? 0); index++) {
322
- indexes.add(index);
323
- while ((windows[next]?.beforeTo ?? Number.POSITIVE_INFINITY) <= index) {
324
- const passed = getDefined(windows[next]);
325
- shift += passed.afterTo - passed.afterFrom - (passed.beforeTo - passed.beforeFrom);
326
- next += 1;
327
- }
328
- if ((windows[next]?.beforeFrom ?? Number.POSITIVE_INFINITY) > index) indexes.add(index + shift);
329
- }
330
- for (const index of indexes) if (index < after.length && !schema.canContainAt(null, after.at(index), index, root)) return false;
331
- return true;
332
- };
333
- const createEditorSchema = (getEditor, getRegistry = () => getPluginRegistry(getEditor()), getDocument = () => getEditorDocumentValue(getEditor())) => {
334
- const getDeclarativeSchema = () => {
335
- return getRegistry().schemaContributions.compiled;
336
- };
337
- const assertDeclaredRecordSets = (sets, schema) => {
338
- for (const set of sets) if (!schema.recordSets.has(set)) throw createEditorSchemaValidationError("invalid-document", `Undeclared record set "${set}" in editor schema.`, toSchemaValidationLocation("main", []));
339
- };
340
- const getValidationAuthority = () => {
341
- const schema = getDeclarativeSchema();
342
- return schema ? `schema:${schema.identity.fingerprint}:${schema.revision}` : `schema:unavailable:${getRegistry().schemaRevision}`;
343
- };
344
- let publicViewSchema = null;
345
- let publicElementViews = /* @__PURE__ */ new Map();
346
- let publicPropertyViews = /* @__PURE__ */ new Map();
347
- const ensurePublicViews = (schema) => {
348
- if (publicViewSchema === schema) return;
349
- publicViewSchema = schema;
350
- publicElementViews = /* @__PURE__ */ new Map();
351
- publicPropertyViews = /* @__PURE__ */ new Map();
352
- };
353
- const toPublicContent = (content) => Object.freeze({
354
- allowedElementTypes: Object.freeze([...content.allowedElementTypes].sort((left, right) => left.localeCompare(right))),
355
- allowsText: content.allowsText,
356
- allowsUnknownElements: content.allowsUnknownElements,
357
- default: content.defaultPlan?.kind === "text" ? "text" : content.defaultPlan?.kind === "element" ? Object.freeze({
358
- ...content.defaultPlan.properties ? { properties: content.defaultPlan.properties } : {},
359
- type: content.defaultPlan.type
360
- }) : null,
361
- max: content.max,
362
- min: content.min,
363
- ...content.prefix ? { prefix: content.prefix } : {},
364
- ...content.remainder ? { remainder: toPublicContent(content.remainder) } : {}
365
- });
366
- const getPublicElement = (type) => {
367
- const schema = getDeclarativeSchema();
368
- if (!schema) return null;
369
- ensurePublicViews(schema);
370
- const known = publicElementViews.get(type);
371
- if (known) return known;
372
- const element = schema.elements.byType.get(type);
373
- if (!element) return null;
374
- const value = Object.freeze({
375
- behavior: element.behavior,
376
- content: element.content ? toPublicContent(element.content) : null,
377
- contentRoots: Object.freeze(Object.fromEntries([...element.contentRoots].map(([slot, root]) => [slot, Object.freeze({
378
- content: toPublicContent(root.content),
379
- ownership: root.ownership,
380
- ...root.structure ? { structure: root.structure } : {}
381
- })]))),
382
- groups: Object.freeze([...element.groups].sort()),
383
- propertyIds: Object.freeze([...element.propertyIds].sort()),
384
- slice: element.slice,
385
- structure: element.structure,
386
- type
387
- });
388
- publicElementViews.set(type, value);
389
- return value;
390
- };
391
- const toPublicProperty = (property) => {
392
- const known = publicPropertyViews.get(property.id);
393
- if (known) return known;
394
- const value = Object.freeze({
395
- id: property.id,
396
- key: property.key,
397
- lifecycle: Object.freeze({
398
- ...property.lifecycle,
399
- landing: property.lifecycle.landing ?? "preserve"
400
- }),
401
- merge: property.merge,
402
- placement: property.placement,
403
- role: property.role,
404
- target: property.target,
405
- value: property.descriptor
406
- });
407
- publicPropertyViews.set(property.id, value);
408
- return value;
409
- };
410
- const getPublicProperty = (input) => {
411
- const schema = getDeclarativeSchema();
412
- if (!schema) return null;
413
- if ("kind" in input) {
414
- const property = schema.properties.byId.get(input.id);
415
- return property ? toPublicProperty(property) : null;
416
- }
417
- const { ancestors = [], key, placement, root = null, type } = input;
418
- if (root === "main") throw new Error("The primary schema root is implicit; omit root or pass null.");
419
- ensurePublicViews(schema);
420
- const candidates = getCompiledPropertyCandidates(schema, placement, key);
421
- const property = type ? resolveCompiledSchemaProperty(schema, placement, key, {
422
- ancestors,
423
- root,
424
- type
425
- }) : candidates.length === 1 ? candidates[0] : null;
426
- return property ? toPublicProperty(property) : null;
427
- };
428
- const getDeclarativeRootProgram = (schema, root) => (root === "main" ? schema.primaryRoot : schema.roots.get(root))?.content;
429
- const documentOwnershipIndexes = /* @__PURE__ */ new WeakMap();
430
- const getDocumentOwnershipIndexes = (schema, value) => {
431
- const known = documentOwnershipIndexes.get(value);
432
- if (known?.schema === schema) return known.indexes;
433
- forgetElementOwnedRootBuilds(schema, value.roots ?? {});
434
- const indexes = Object.freeze(["main", ...visitRootNames(value.roots)].map((root) => ({
435
- index: ensureElementOwnedRootIndex(schema, root, valueRootIndex(value, root)),
436
- root
437
- })));
438
- if (isFrozenWithRoots(value)) documentOwnershipIndexes.set(value, {
439
- indexes,
440
- schema
441
- });
442
- return indexes;
443
- };
444
- const getLiveDocumentOwnershipIndexes = (schema, targetRoot) => {
445
- const editor = getEditor();
446
- const pending = [
447
- "main",
448
- ...schema.roots.keys(),
449
- ...targetRoot === "main" ? [] : [targetRoot]
450
- ];
451
- const seen = /* @__PURE__ */ new Set();
452
- const indexes = [];
453
- for (const root of pending) {
454
- if (seen.has(root)) continue;
455
- seen.add(root);
456
- const children = root === "main" ? editor.read.children() : editor.read.root(root);
457
- const index = ensureElementOwnedRootIndex(schema, root, DocumentIndex.fromValue(children));
458
- indexes.push({
459
- index,
460
- root
461
- });
462
- for (const childRoot of getElementOwnedRootKeys(index)) if (!seen.has(childRoot)) pending.push(childRoot);
463
- }
464
- return Object.freeze(indexes);
465
- };
466
- const getDocumentRootProgram = (schema, root, value) => {
467
- const declared = getDeclarativeRootProgram(schema, root);
468
- if (declared || root === "main") return declared;
469
- let projected;
470
- const indexes = value ? getDocumentOwnershipIndexes(schema, value) : getLiveDocumentOwnershipIndexes(schema, root);
471
- for (const { index } of indexes) for (const binding of getElementOwnedRootGrammarBindings(index, root)) {
472
- if (projected && !contentProgramsEqual(projected, binding.content)) return null;
473
- projected = binding.content;
474
- }
475
- return projected;
476
- };
477
- const matchesTargetWithOpenAncestorBoundary = (schema, target, context) => {
478
- if (!target) return true;
479
- switch (target.kind) {
480
- case "type": {
481
- const current = target;
482
- return context.type === current.type;
483
- }
484
- case "types": return target.types.includes(context.type);
485
- case "group": {
486
- const current = target;
487
- return schema.elements.groups.get(current.group)?.has(context.type) ?? false;
488
- }
489
- case "root": {
490
- const current = target;
491
- return context.root === current.root;
492
- }
493
- case "parent": {
494
- const current = target;
495
- const [parent, ...ancestors] = context.ancestors ?? [];
496
- return parent ? matchesTargetWithOpenAncestorBoundary(schema, current.target, {
497
- ancestors,
498
- root: context.root,
499
- type: parent
500
- }) : "unknown";
501
- }
502
- case "not": {
503
- const result = matchesTargetWithOpenAncestorBoundary(schema, target.target, context);
504
- return result === "unknown" ? result : !result;
505
- }
506
- case "and": {
507
- const current = target;
508
- let unknown = false;
509
- for (const child of current.targets) {
510
- const result = matchesTargetWithOpenAncestorBoundary(schema, child, context);
511
- if (result === false) return false;
512
- unknown ||= result === "unknown";
513
- }
514
- return unknown ? "unknown" : true;
515
- }
516
- case "or": {
517
- const current = target;
518
- let unknown = false;
519
- for (const child of current.targets) {
520
- const result = matchesTargetWithOpenAncestorBoundary(schema, child, context);
521
- if (result === true) return true;
522
- unknown ||= result === "unknown";
523
- }
524
- return unknown ? "unknown" : false;
525
- }
526
- }
527
- return failInvariant("Unexpected schema target kind");
528
- };
529
- const DEFAULT_ELEMENT_BEHAVIOR = Object.freeze({
530
- atom: false,
531
- inline: false,
532
- isolating: false,
533
- markableVoid: false,
534
- object: false,
535
- ownsExit: false,
536
- readOnly: false,
537
- selectable: true,
538
- void: false
539
- });
540
- const getCompiledElement = (element) => {
541
- const type = getElementType(element);
542
- return type ? getDeclarativeSchema()?.elements.byType.get(type) ?? null : null;
543
- };
544
- const getElementContent = (type) => getDeclarativeSchema()?.elements.byType.get(type)?.content ?? null;
545
- const getRootContent = (root = "main", value = getDocument()) => {
546
- const schema = getDeclarativeSchema();
547
- return schema ? getDocumentRootProgram(schema, root, value) ?? null : null;
548
- };
549
- const indexConstructedRoot = ({ after, before, change, root }) => {
550
- const schema = getDeclarativeSchema();
551
- if (schema && hasContentRoots()) rebaseElementOwnedRootIndex(schema, root, change, before, after);
552
- };
553
- const getElementBehavior = (element) => getCompiledElement(element)?.behavior ?? DEFAULT_ELEMENT_BEHAVIOR;
554
- const getElementContentRoots = (element) => {
555
- const slots = getCompiledElement(element)?.contentRoots;
556
- if (!slots || slots.size === 0) return Object.freeze({});
557
- const { childRoots } = element;
558
- if (typeof childRoots !== "object" || childRoots === null) return Object.freeze({});
559
- return Object.freeze(Object.fromEntries([...slots.keys()].flatMap((slot) => {
560
- const root = childRoots[slot];
561
- return typeof root === "string" && root.length > 0 ? [[slot, root]] : [];
562
- })));
563
- };
564
- const getElementOwnedRoots = (element) => {
565
- const contentRoots = getCompiledElement(element)?.contentRoots;
566
- const { childRoots } = element;
567
- if (!contentRoots || contentRoots.size === 0 || typeof childRoots !== "object" || childRoots === null) return Object.freeze([]);
568
- return Object.freeze([...contentRoots].flatMap(([slot, declaration]) => {
569
- const root = childRoots[slot];
570
- return typeof root === "string" && root.length > 0 && root !== "main" ? [Object.freeze({
571
- ownership: declaration.ownership,
572
- root,
573
- slot
574
- })] : [];
575
- }));
576
- };
577
- const hasContentRoots = () => {
578
- const schema = getDeclarativeSchema();
579
- return schema ? schemaHasContentRoots(schema) : false;
580
- };
581
- const rootOwnerBinding = (schema, root, value) => {
582
- for (const { index } of getDocumentOwnershipIndexes(schema, value)) {
583
- const [binding] = getElementOwnedRootGrammarBindings(index, root);
584
- if (binding) return binding.owner;
585
- }
586
- return null;
587
- };
588
- const setRootAnswers = /* @__PURE__ */ new Map();
589
- const isSetRoot = (root, read) => {
590
- if (root === "main") return false;
591
- const schema = getDeclarativeSchema();
592
- if (!schema || !schemaDeclaresSetRoots(schema) || schema.roots.has(root)) return false;
593
- const known = setRootAnswers.get(root);
594
- const knownChildren = known?.ownerChildren.deref();
595
- if (known?.schema === schema && knownChildren !== void 0 && knownChildren === read.rootChildren(known.ownerRoot)) return known.set;
596
- const owner = rootOwnerBinding(schema, root, read.value());
597
- const ownerChildren = owner ? read.rootChildren(owner.ownerRoot) : void 0;
598
- if (!owner || !ownerChildren) {
599
- setRootAnswers.delete(root);
600
- return false;
601
- }
602
- const set = schema.elements.byType.get(owner.ownerType)?.contentRoots.get(owner.slot)?.structure?.kind === "set";
603
- setRootAnswers.set(root, {
604
- ownerChildren: new WeakRef(ownerChildren),
605
- ownerRoot: owner.ownerRoot,
606
- schema,
607
- set
608
- });
609
- return set;
610
- };
611
- const holdsSetRoot = (type) => {
612
- const schema = getDeclarativeSchema();
613
- if (!schema || !schemaDeclaresSetRoots(schema)) return false;
614
- return [...schema.elements.byType.get(type)?.contentRoots.values() ?? []].some((root) => root.structure?.kind === "set");
615
- };
616
- const declaresSetRoots = () => {
617
- const schema = getDeclarativeSchema();
618
- return !!schema && schemaDeclaresSetRoots(schema);
619
- };
620
- const findRootOwner = (root, value) => {
621
- const schema = getDeclarativeSchema();
622
- if (!schema || root === "main") return null;
623
- const owner = rootOwnerBinding(schema, root, value);
624
- if (!owner) return null;
625
- const path = findElementOwnedRootOwnerPath(owner.ownerRoot === "main" ? value.children : value.roots?.[owner.ownerRoot] ?? [], owner);
626
- return path ? Object.freeze({
627
- path,
628
- root: owner.ownerRoot
629
- }) : null;
630
- };
631
- const readContentRootOwnerRoots = (value) => {
632
- const schema = getDeclarativeSchema();
633
- if (!schema || !hasContentRoots()) return /* @__PURE__ */ new Map();
634
- const ownerRoots = /* @__PURE__ */ new Map();
635
- for (const { index, root } of getDocumentOwnershipIndexes(schema, value)) {
636
- countCoreWork("ownershipIndexVisits");
637
- for (const childRoot of getElementOwnedRootKeys(index)) {
638
- const owners = ownerRoots.get(childRoot) ?? [];
639
- owners.push(root);
640
- ownerRoots.set(childRoot, owners);
641
- }
642
- }
643
- return ownerRoots;
644
- };
645
- const getOrphanedElementOwnedRoots = (input) => {
646
- const schema = getDeclarativeSchema();
647
- return schema ? orphanedRoots(schema, input) : Object.freeze([]);
648
- };
649
- const getElementSlicePolicy = (element) => getCompiledElement(element)?.slice ?? Object.freeze({
650
- endMatter: false,
651
- preserveContext: false,
652
- replaceWhenCovered: true
653
- });
654
- const allowsElementType = (parentType, childType) => {
655
- const schema = getDeclarativeSchema();
656
- const content = schema?.elements.byType.get(parentType)?.content;
657
- if (!schema || !content) return false;
658
- return content.allowedElementTypes.has(childType) || content.allowsUnknownElements && schema.unknown === "preserve" && !schema.elements.byType.has(childType);
659
- };
660
- const isElementTypeInGroup = (type, group) => getDeclarativeSchema()?.elements.groups.get(group)?.has(type) ?? false;
661
- const resolveElementProperty = (element, property, options = {}) => {
662
- const schema = getDeclarativeSchema();
663
- const type = getElementType(element);
664
- return schema && type ? resolveCompiledSchemaProperty(schema, "element", property, toCompiledTargetContext(type, options)) : null;
665
- };
666
- const getProperty = ((node, property, options = {}) => {
667
- if (typeof property === "string") {
668
- const key = property;
669
- const ownDescriptor = Object.getOwnPropertyDescriptor(node, key);
670
- const ownValue = ownDescriptor && "value" in ownDescriptor ? ownDescriptor.value : void 0;
671
- if (ownValue !== void 0) return ownValue;
672
- if (ElementApi.isElement(node)) {
673
- const resolved = resolveElementProperty(node, key, options);
674
- return resolved ? getPropertyDefault(resolved) : void 0;
675
- }
676
- const schema = getDeclarativeSchema();
677
- const resolved = schema ? options.parent ? resolveCompiledSchemaProperty(schema, "text", key, toCompiledTargetContext(getElementType(options.parent) ?? "", options)) : getCompiledPropertyCandidates(schema, "text", key).find((candidate) => candidate.target === null) ?? null : null;
678
- return resolved ? getPropertyDefault(resolved) : void 0;
679
- }
680
- const schema = getDeclarativeSchema();
681
- const resolved = schema?.properties.byId.get(property.id);
682
- if (!resolved || resolved.placement !== property.placement || typeof resolved.key !== "string") return;
683
- if (resolved.placement === "element" && !ElementApi.isElement(node) || resolved.placement === "text" && !NodeApi.isText(node)) return;
684
- const ownDescriptor = Object.getOwnPropertyDescriptor(node, resolved.key);
685
- const ownValue = ownDescriptor && "value" in ownDescriptor ? ownDescriptor.value : void 0;
686
- if (resolved.placement === "text" && !resolved.target) return ownValue !== void 0 ? ownValue : getPropertyDefault(resolved);
687
- const type = ElementApi.isElement(node) ? getElementType(node) : options.parent ? getElementType(options.parent) : null;
688
- if (!type || !matchesCompiledSchemaTarget(schema, resolved.target, toCompiledTargetContext(type, options))) return;
689
- return ownValue !== void 0 ? ownValue : getPropertyDefault(resolved);
690
- });
691
- const contentAllows = (schema, content, child) => NodeApi.isText(child) ? content.allowsText : content.allowedElementTypes.has(getElementType(child) ?? "") || content.allowsUnknownElements && schema.unknown === "preserve" && !getCompiledElement(child);
692
- const validationContentAllows = (schema, content, child) => contentAllows(schema, content, child) || schema.identity.kind === "derived" && ElementApi.isElement(child) && !getCompiledElement(child);
693
- const contentAllowsAt = (schema, content, child, index, options = {}) => {
694
- const { prefix } = content;
695
- if (prefix && index < prefix.length) {
696
- const slot = prefix[index];
697
- return ElementApi.isElement(child) && getElementType(child) === slot.type && Object.entries(slot.properties).every(([key, value]) => structurallyEqual(getProperty(child, key, options), value));
698
- }
699
- return validationContentAllows(schema, content.remainder ?? content, child);
700
- };
701
- const elementUsesInlineContent = (element) => {
702
- if (getElementBehavior(element).void) return false;
703
- const content = getCompiledElement(element)?.content;
704
- return content ? content.allowsText : element.children.some((child) => NodeApi.isText(child) || ElementApi.isElement(child) && getElementBehavior(child).inline);
705
- };
706
- const canContain = (parent, child) => {
707
- const schema = getDeclarativeSchema();
708
- const content = getCompiledElement(parent)?.content;
709
- if (schema && content) return contentAllows(schema, content, child);
710
- return elementUsesInlineContent(parent) ? NodeApi.isText(child) || ElementApi.isElement(child) && getElementBehavior(child).inline : ElementApi.isElement(child) && !getElementBehavior(child).inline;
711
- };
712
- const canContainAtRoot = (child, root = "main") => {
713
- const schema = getDeclarativeSchema();
714
- const content = getRootContent(root);
715
- if (schema && content) return contentAllows(schema, content, child);
716
- return ElementApi.isElement(child) && !getElementBehavior(child).inline;
717
- };
718
- const canContainAt = (parent, child, index, root = "main") => {
719
- const schema = getDeclarativeSchema();
720
- const content = parent ? getCompiledElement(parent)?.content : getRootContent(root);
721
- if (schema && content) return contentAllowsAt(schema, content, child, index, {
722
- ancestors: parent ? [parent] : [],
723
- root
724
- });
725
- return parent ? canContain(parent, child) : canContainAtRoot(child, root);
726
- };
727
- const canWrap = (parent, wrapper, index, root) => (index === void 0 ? !!parent && canContain(parent, wrapper) : canContainAt(parent, wrapper, index, root)) && wrapper.children.every((child) => canContain(wrapper, child));
728
- const canPlaceIn = (ancestors, children, fit, at, { removing = [], root = "main", strict = false } = {}) => {
729
- const [parent = null] = ancestors;
730
- const schema = getDeclarativeSchema();
731
- const content = parent ? getCompiledElement(parent)?.content : getRootContent(root);
732
- if (!schema || !content) return !parent && fit.every((child) => canContainAtRoot(child, root));
733
- const removed = [...removing].sort((a, b) => a - b);
734
- const index = at - removed.filter((position) => position < at).length;
735
- const length = children.length - removed.length + fit.length;
736
- if (content.max !== null && length > content.max) return false;
737
- const remaining = (position) => {
738
- let original = position;
739
- for (const gone of removed) if (gone <= original) original += 1;
740
- return getDefined(children.at(original));
741
- };
742
- const childAt = (position) => position < index ? remaining(position) : position < index + fit.length ? fit[position - index] : remaining(position - fit.length);
743
- const options = {
744
- ancestors,
745
- root
746
- };
747
- const prefixLength = content.prefix?.length ?? 0;
748
- const shifted = Math.min(length, prefixLength > 0 ? prefixLength + fit.length + removed.length : 0);
749
- for (let position = 0; position < shifted; position++) {
750
- if (position >= index && position < index + fit.length) continue;
751
- if (!contentAllowsAt(schema, content, childAt(position), position, options)) return false;
752
- }
753
- return fit.every((child, offset) => {
754
- const position = index + offset;
755
- return position < prefixLength || !strict ? contentAllowsAt(schema, content, child, position, options) : contentAllows(schema, content.remainder ?? content, child);
756
- });
757
- };
758
- const canPlaceAt = (parent, children, fit, at, options) => canPlaceIn(parent ? [parent] : [], children, fit, at, options);
759
- const canPlaceAtPath = (at, fit, { removing, root = "main" } = {}) => {
760
- const index = at.at(-1);
761
- const ancestors = getSlotAncestors(at, root);
762
- if (index === void 0 || !ancestors) return false;
763
- const [parent] = ancestors;
764
- if (parent && !getCompiledElement(parent)?.content) return true;
765
- return canPlaceIn(ancestors, parent?.children ?? getDocumentRootNodes(getDocument(), root), fit, index, {
766
- removing,
767
- root
768
- });
769
- };
770
- const createDeclarativeAndFill = (schema, type, properties, creating = /* @__PURE__ */ new Set(), options = {}) => {
771
- const compiled = schema.elements.byType.get(type);
772
- if (!compiled) throw new Error(`Unknown editor element spec "${type}".`);
773
- if (creating.has(type)) throw new Error(`Recursive default content for editor element "${type}".`);
774
- if (properties?.type !== void 0 && properties.type !== type) throw new EditorSchemaValidationError(`Editor element construction for "${type}" cannot change its declared type.`);
775
- const context = toCompiledTargetContext(type, options);
776
- const nextProperties = {};
777
- for (const propertyId of compiled.construction.materializedPropertyIds) {
778
- const property = getDefined(schema.properties.byId.get(propertyId));
779
- if (typeof property.key !== "string" || !matchesCompiledSchemaTarget(schema, property.target, context) || property.descriptor.omitDefault || Object.hasOwn(properties ?? {}, property.key)) continue;
780
- nextProperties[property.key] = property.descriptor.generate ? canonicalizePropertyValue(`Editor element property "${property.key}"`, property.descriptor, generatePropertyValue(property, "element")) : property.descriptor.default;
781
- }
782
- for (const propertyId of schema.properties.elementAllowedByType.get(type) ?? []) {
783
- const property = schema.properties.byId.get(propertyId);
784
- if (property?.descriptor.required && typeof property.key === "string" && matchesCompiledSchemaTarget(schema, property.target, context) && !Object.hasOwn(properties ?? {}, property.key)) throw new MissingPropertyError(createEditorSchemaValidationError("missing-property", `Editor element "${type}" requires property "${property.key}".`, {
785
- nodeType: type,
786
- path: options.path ?? [],
787
- root: options.root ?? null
788
- }, { property: {
789
- candidates: [property],
790
- key: property.key,
791
- placement: "element"
792
- } }).diagnostics);
793
- }
794
- for (const [key, value] of Object.entries(properties ?? {})) {
795
- if (key === "children" || key === "type") continue;
796
- const candidates = getCompiledPropertyCandidates(schema, "element", key);
797
- const property = resolveCompiledSchemaProperty(schema, "element", key, context);
798
- if (!property) {
799
- if (candidates.length > 0 || schema.unknown === "reject") throw new EditorSchemaValidationError(candidates.length > 0 ? `Editor element property "${key}" cannot target "${type}".` : `Unknown editor element property "${key}" on "${type}" in closed editor schema.`);
800
- nextProperties[key] = snapshotEditorJsonValue(value, `Editor element "${type}" property "${key}"`);
801
- continue;
802
- }
803
- nextProperties[key] = validatePropertyValue(`Editor element "${type}" property "${key}"`, property.descriptor, value);
804
- }
805
- const children = [];
806
- const element = {
807
- ...nextProperties,
808
- children,
809
- type
810
- };
811
- const nextCreating = new Set(creating).add(type);
812
- const site = {
813
- ancestors: [element, ...options.ancestors ?? []],
814
- root: options.root
815
- };
816
- if (compiled.content) children.push(...completeContent({
817
- children: [],
818
- content: compiled.content,
819
- element: true,
820
- schema: {
821
- create: (childType, childProperties) => createDeclarativeAndFill(schema, childType, childProperties, nextCreating, site),
822
- fitsPrefix: () => false,
823
- isInline: (node) => ElementApi.isElement(node) && getElementBehavior(node).inline
824
- }
825
- }).children);
826
- assertEditorJsonValue(element, `Editor element "${type}"`);
827
- return cloneFrozen(canonicalizeDeclarativeChildren([element], schema, options.root ?? "main", options.ancestors ?? [], false)[0]);
828
- };
829
- const create = ((element, properties, creating = /* @__PURE__ */ new Set(), options = {}) => {
830
- const type = typeof element === "string" ? element : element.type;
831
- const declarative = getDeclarativeSchema();
832
- if (!declarative) throw new Error(`Unknown editor element type "${type}".`);
833
- return createDeclarativeAndFill(declarative, type, properties, creating, options);
834
- });
835
- const emptyTextDrops = ({ ancestors, parent, root }) => parent ? getCompiledEmptyTextDrops(getDeclarativeSchema(), toCompiledTargetContext(getElementType(parent) ?? "", {
836
- ancestors,
837
- root
838
- })) : void 0;
839
- const createAt = (type, properties, site) => {
840
- const declarative = getDeclarativeSchema();
841
- if (!declarative) throw new Error(`Unknown editor element type "${type}".`);
842
- return createDeclarativeAndFill(declarative, type, properties, /* @__PURE__ */ new Set(), site);
843
- };
844
- const defaultSlotIn = (content, index, site) => {
845
- const schema = getDeclarativeSchema();
846
- if (!schema || !content) return null;
847
- const slot = content.prefix?.[index];
848
- if (slot) return {
849
- kind: "element",
850
- properties: slot.properties,
851
- schema,
852
- site,
853
- type: slot.type
854
- };
855
- const plan = content.defaultPlan;
856
- if (plan?.kind === "text") return { kind: "text" };
857
- if (!plan) return null;
858
- return {
859
- kind: "element",
860
- properties: plan.properties,
861
- schema,
862
- site,
863
- type: plan.type
864
- };
865
- };
866
- const getSlotAncestors = (at, root) => {
867
- const ancestors = at.length > 1 ? getElementAncestors(getDocumentRootNodes(getDocument(), root), at) : [];
868
- return ancestors.length === at.length - 1 ? ancestors : null;
869
- };
870
- const resolveDefaultSlot = (at, root) => {
871
- const index = at.at(-1);
872
- const ancestors = getSlotAncestors(at, root);
873
- if (index === void 0 || !ancestors) return null;
874
- const [parent] = ancestors;
875
- const content = parent ? getCompiledElement(parent)?.content : getRootContent(root);
876
- return parent && !content ? defaultSlotIn(getRootContent(root), getDefined(at[0]), {
877
- ancestors: [],
878
- root
879
- }) : defaultSlotIn(content, index, {
880
- ancestors,
881
- root
882
- });
883
- };
884
- const buildDefaultSlot = (slot) => {
885
- if (!slot) return null;
886
- if (slot.kind === "text") return { text: "" };
887
- return createDeclarativeAndFill(slot.schema, slot.type, slot.properties, /* @__PURE__ */ new Set(), slot.site);
888
- };
889
- const createDefaultChild = ({ at, root = "main" }) => buildDefaultSlot(resolveDefaultSlot(at, root));
890
- const tryCreateDefaultChild = ({ at, root = "main" }) => refuseMissingProperty(() => buildDefaultSlot(resolveDefaultSlot(at, root)));
891
- const placeDerivedElement = (source, { at, root = "main" }) => {
892
- const schema = getDeclarativeSchema();
893
- const index = at.at(-1);
894
- const ancestors = getSlotAncestors(at, root);
895
- if (!schema || index === void 0 || !ancestors) return source;
896
- const [parent] = ancestors;
897
- const content = parent ? getCompiledElement(parent)?.content : getRootContent(root);
898
- if (!content || contentAllowsAt(schema, content, source, index, {
899
- ancestors,
900
- root
901
- })) return source;
902
- const landing = buildDefaultSlot(defaultSlotIn(content, index, {
903
- ancestors,
904
- root
905
- }));
906
- if (!ElementApi.isElement(landing) || !elementUsesInlineContent(landing) || !elementUsesInlineContent(source)) return null;
907
- const preserved = NodeApi.extractProps(elementForTypeChangeAt(source, landing.type, at, root));
908
- const fixed = content.prefix?.[index]?.properties ?? {};
909
- const kept = Object.fromEntries(Object.entries(preserved).filter(([key]) => !Object.hasOwn(fixed, key)));
910
- return {
911
- ...landing,
912
- ...kept,
913
- children: source.children
914
- };
915
- };
916
- let canonicalizationObserver;
917
- const observeRootCanonicalization = (root, run) => {
918
- if (canonicalizationObserver) throw new Error("Schema fit canonicalization observers cannot nest.");
919
- const observer = {
920
- events: [],
921
- passes: [],
922
- root
923
- };
924
- canonicalizationObserver = observer;
925
- try {
926
- const value = run();
927
- return Object.freeze({
928
- events: Object.freeze([...observer.events]),
929
- passes: Object.freeze([...observer.passes]),
930
- value
931
- });
932
- } finally {
933
- canonicalizationObserver = void 0;
934
- }
935
- };
936
- const fitReportSink = (root) => {
937
- const observer = canonicalizationObserver;
938
- return observer?.root === root ? (event) => {
939
- observer.events.push(event);
940
- } : void 0;
941
- };
942
- const collectPropertyRepairs = (input, output, root, inputPaths) => {
943
- if (structurallyEqual(input, output)) return Object.freeze([]);
944
- const declarative = getDeclarativeSchema();
945
- if (!declarative) throw new Error(`Unclassified property mutation in editor root "${root}" without a compiled schema.`);
946
- const repairs = [];
947
- const visit = (before, after, ancestors, parentPath) => {
948
- if (before.length !== after.length) throw new Error(`Property canonicalization changed child topology in editor root "${root}".`);
949
- for (const [index, source] of before.entries()) {
950
- const targetNode = after[index];
951
- const path = [...parentPath, index];
952
- if (!targetNode || NodeApi.isText(source) !== NodeApi.isText(targetNode)) throw new Error(`Property canonicalization changed node structure in editor root "${root}" at [${path}].`);
953
- const placement = NodeApi.isText(source) ? "text" : "element";
954
- const type = NodeApi.isText(source) ? getElementType(ancestors[0] ?? {}) ?? "" : getElementType(source);
955
- if (!type || !NodeApi.isText(source) && type !== getElementType(targetNode)) throw new Error(`Property canonicalization changed element identity in editor root "${root}" at [${path}].`);
956
- const context = toCompiledTargetContext(type, {
957
- ancestors: NodeApi.isText(source) ? ancestors.slice(1) : ancestors,
958
- root
959
- });
960
- const reserved = new Set(NodeApi.isText(source) ? ["text"] : [
961
- "children",
962
- "type",
963
- ...(declarative.elements.byType.get(type)?.contentRoots.size ?? 0) > 0 ? ["childRoots"] : []
964
- ]);
965
- const sourceRecord = source;
966
- const targetRecord = targetNode;
967
- const keys = /* @__PURE__ */ new Set([...Object.keys(sourceRecord), ...Object.keys(targetRecord)]);
968
- for (const key of keys) {
969
- if (reserved.has(key)) continue;
970
- const had = Object.hasOwn(sourceRecord, key);
971
- const has = Object.hasOwn(targetRecord, key);
972
- if (had && has && structurallyEqual(sourceRecord[key], targetRecord[key])) continue;
973
- const property = resolveCompiledSchemaProperty(declarative, placement, key, context);
974
- if (!property) throw new Error(`Unclassified schema property mutation for "${key}" in editor root "${root}" at [${path}].`);
975
- const inputLocations = inputPaths(path).map((sourcePath) => schemaModelLocation(root, sourcePath, key));
976
- const outputLocation = schemaModelLocation(root, path, key);
977
- if (!had && has) {
978
- const code = property.descriptor.generate ? "generate-property" : Object.hasOwn(property.descriptor, "default") ? "default-property" : null;
979
- if (!code) throw new Error(`Unclassified inserted schema property "${key}" in editor root "${root}" at [${path}].`);
980
- repairs.push(schemaRepair({
981
- code,
982
- impact: "lossless",
983
- outputs: [outputLocation],
984
- owner: "property"
985
- }));
986
- continue;
987
- }
988
- if (had && !has) {
989
- if (placement !== "text" || property.exclusiveGroupIds.length === 0) throw new Error(`Unclassified removed schema property "${key}" in editor root "${root}" at [${path}].`);
990
- repairs.push(schemaRepair({
991
- code: "resolve-exclusive-property",
992
- impact: "lossy",
993
- inputs: inputLocations,
994
- owner: "property"
995
- }));
996
- continue;
997
- }
998
- if (property.descriptor.kind !== "set") throw new Error(`Unclassified changed schema property "${key}" in editor root "${root}" at [${path}].`);
999
- repairs.push(schemaRepair({
1000
- code: "canonicalize-set-property",
1001
- impact: "lossless",
1002
- inputs: inputLocations,
1003
- outputs: [outputLocation],
1004
- owner: "property"
1005
- }));
1006
- }
1007
- if (!NodeApi.isText(source) && !NodeApi.isText(targetNode)) visit(source.children, targetNode.children, [source, ...ancestors], path);
1008
- }
1009
- };
1010
- visit(input, output, [], []);
1011
- if (repairs.length === 0) throw new Error(`Unclassified property mutation in editor root "${root}".`);
1012
- return Object.freeze(repairs);
1013
- };
1014
- const representationEditor = Object.freeze({ getSchema: () => api });
1015
- const sliceFitter = createCompiledSliceFitterDelegate(() => ({
1016
- canContain,
1017
- collectPropertyRepairs,
1018
- contentAllows,
1019
- contentAllowsAt,
1020
- createDeclarativeAndFill,
1021
- editorRootLabel,
1022
- elementUsesInlineContent,
1023
- getCompiledElement,
1024
- getDescendant,
1025
- getDocumentRoot,
1026
- getDocumentRootProgram,
1027
- getEditor: () => representationEditor,
1028
- getElementAncestors,
1029
- getElementBehavior,
1030
- getElementContentRoots,
1031
- getElementSlicePolicy,
1032
- getElementType,
1033
- getRootContent,
1034
- getVocabulary,
1035
- indexConstructedRoot,
1036
- isSetValuedProperty,
1037
- nodePropertiesEqual,
1038
- observeRootCanonicalization,
1039
- revision: getRegistry().schemaRevision,
1040
- schema: getDeclarativeSchema(),
1041
- schemaApi: api,
1042
- structurallyEqual,
1043
- validateDeclarativeChildren,
1044
- validateDocument: assertDocument,
1045
- validateSliceVocabulary,
1046
- withoutGeneration
1047
- }));
1048
- const fit = sliceFitter.fit;
1049
- const fitContent = sliceFitter.fitContent;
1050
- const fitDocument = (input) => sliceFitter.fitDocument(input);
1051
- const fitDocumentWithReport = (input) => sliceFitter.fitDocumentWithReport(input);
1052
- const fitDocumentAndMapPositions = (input, options) => sliceFitter.fitDocumentAndMapPositions(input, options);
1053
- const fitDocumentWithSelection = (input, options) => sliceFitter.fitDocumentWithSelection(input, options);
1054
- const findWrapping = sliceFitter.findWrapping;
1055
- const canonicalizeDeclarativePropertyRecord = (source, schema, placement, context, reserved, dropMisplaced, openAncestorBoundary = false, validationLocation, carried) => {
1056
- const output = {};
1057
- const canonicalizeProperty = (key, property, value) => {
1058
- try {
1059
- return (validationLocation ? validatePropertyValue : canonicalizePropertyValue)(`Editor ${placement} property "${key}"`, property.descriptor, value);
1060
- } catch (error) {
1061
- if (!validationLocation) throw error;
1062
- throw createEditorSchemaValidationError("invalid-property-value", error instanceof Error ? error.message : `Editor ${placement} property "${key}" is invalid.`, validationLocation, {
1063
- cause: error,
1064
- property: {
1065
- candidates: [property],
1066
- key,
1067
- placement
1068
- }
1069
- });
1070
- }
1071
- };
1072
- for (const key of reserved) if (Object.hasOwn(source, key)) output[key] = source[key];
1073
- for (const [key, value] of Object.entries(source)) {
1074
- if (reserved.has(key)) continue;
1075
- const candidates = getCompiledPropertyCandidates(schema, placement, key);
1076
- const property = resolveCompiledSchemaProperty(schema, placement, key, context);
1077
- if (!property) {
1078
- if (candidates.length > 0) {
1079
- const boundaryProperty = openAncestorBoundary ? candidates.find((candidate) => matchesTargetWithOpenAncestorBoundary(schema, candidate.target, context) === "unknown") : void 0;
1080
- if (boundaryProperty) {
1081
- output[key] = canonicalizeProperty(key, boundaryProperty, value);
1082
- continue;
1083
- }
1084
- if (dropMisplaced || carried?.(key)) continue;
1085
- const message = `Schema ${placement} property "${key}" cannot target ${placement === "text" ? `text under "${context.type}"` : `element "${context.type}"`}.`;
1086
- throw validationLocation ? createEditorSchemaValidationError("property-target-mismatch", message, validationLocation, { property: {
1087
- candidates,
1088
- key,
1089
- placement
1090
- } }) : new EditorSchemaValidationError(message);
1091
- }
1092
- if (schema.unknown === "reject") {
1093
- const message = `Unknown ${placement} property "${key}" in closed editor schema.`;
1094
- throw validationLocation ? createEditorSchemaValidationError("unknown-property", message, validationLocation) : new EditorSchemaValidationError(message);
1095
- }
1096
- output[key] = snapshotEditorJsonValue(value, `Editor ${placement} property "${key}"`);
1097
- continue;
1098
- }
1099
- try {
1100
- output[key] = canonicalizeProperty(key, property, value);
1101
- } catch (error) {
1102
- if (error instanceof EditorSchemaValidationError && carried?.(key)) continue;
1103
- throw error;
1104
- }
1105
- }
1106
- fillDefaultedProperties(schema, placement, context, output, (property, key) => {
1107
- if (validationLocation) throw createEditorSchemaValidationError("missing-property", `Editor ${placement} requires canonical property "${key}".`, validationLocation, { property: {
1108
- candidates: [property],
1109
- key,
1110
- placement
1111
- } });
1112
- return property.descriptor.generate ? canonicalizeProperty(key, property, generatePropertyValue(property, placement)) : property.descriptor.default;
1113
- });
1114
- const allowedIds = placement === "element" ? schema.properties.elementAllowedByType.get(context.type) : schema.properties.textAllowedByParentType.get(context.type);
1115
- for (const id of allowedIds ?? []) {
1116
- const property = schema.properties.byId.get(id);
1117
- if (!property?.descriptor.required || typeof property.key !== "string" || Object.hasOwn(output, property.key) || !matchesCompiledSchemaTarget(schema, property.target, context)) continue;
1118
- const message = `Editor ${placement} requires property "${property.key}".`;
1119
- throw validationLocation ? createEditorSchemaValidationError("missing-property", message, validationLocation, { property: {
1120
- candidates: [property],
1121
- key: property.key,
1122
- placement
1123
- } }) : new MissingPropertyError({
1124
- code: "missing-property",
1125
- message,
1126
- path: [],
1127
- root: null
1128
- });
1129
- }
1130
- const sourceKeys = Object.keys(source);
1131
- const canonicalOutput = placement === "text" ? canonicalizeCompiledExclusiveTextProperties(schema, output, context) : output;
1132
- const outputKeys = Object.keys(canonicalOutput);
1133
- return sourceKeys.length === outputKeys.length && sourceKeys.every((key) => Object.hasOwn(canonicalOutput, key) && structurallyEqual(source[key], canonicalOutput[key])) ? source : canonicalOutput;
1134
- };
1135
- const canonicalizeDeclarativeChildren = (children, schema, root, ancestors, dropMisplaced, baseline, offset = 0, carried, prefix = []) => {
1136
- const canonical = children.map((node, index) => {
1137
- const previous = baseline?.at(index + offset);
1138
- if (node === previous) return node;
1139
- countCoreWork("canonicalNodes");
1140
- const path = carried ? [...prefix, index] : prefix;
1141
- const carriedKey = carried && ((key) => carried(path, node, key));
1142
- if (NodeApi.isText(node)) return canonicalizeDeclarativePropertyRecord(node, schema, "text", toCompiledNodeContext(node, ancestors, root), /* @__PURE__ */ new Set(["text"]), dropMisplaced, false, void 0, carriedKey);
1143
- const type = getElementType(node);
1144
- const previousChildren = previous && !NodeApi.isText(previous) && getElementType(previous) === type ? previous.children : void 0;
1145
- if (!type || !schema.elements.byType.has(type)) {
1146
- if (schema.unknown === "reject") throw new EditorSchemaValidationError(`Unknown editor element type "${type ?? "missing"}".`);
1147
- const nested = canonicalizeDeclarativeChildren(node.children, schema, root, [node, ...ancestors], dropMisplaced, previousChildren, 0, carried, path);
1148
- return nested === node.children ? node : {
1149
- ...node,
1150
- children: nested
1151
- };
1152
- }
1153
- const candidate = canonicalizeDeclarativePropertyRecord(node, schema, "element", toCompiledNodeContext(node, ancestors, root), /* @__PURE__ */ new Set([
1154
- "children",
1155
- "type",
1156
- ...(schema.elements.byType.get(type)?.contentRoots.size ?? 0) > 0 ? ["childRoots"] : []
1157
- ]), dropMisplaced, false, void 0, carriedKey);
1158
- const nested = canonicalizeDeclarativeChildren(node.children, schema, root, [candidate, ...ancestors], dropMisplaced, previousChildren, 0, carried, path);
1159
- if (candidate === node && nested === node.children) return node;
1160
- return {
1161
- ...candidate,
1162
- children: nested,
1163
- type
1164
- };
1165
- });
1166
- return canonical.every((node, index) => node === children[index]) ? children : canonical;
1167
- };
1168
- const canonicalizeChildren = (children, root, ancestors, dropMisplaced, baseline, carried) => {
1169
- const schema = getDeclarativeSchema();
1170
- let previous = baseline && baseline.path.length === ancestors.length && isRootValidatedBy(baseline.document, getValidationAuthority()) ? rootNodes(baseline.document) : void 0;
1171
- if (baseline) for (let depth = 0; previous && depth < baseline.path.length; depth++) {
1172
- const parent = previous.at(baseline.path[depth]);
1173
- if (!parent || NodeApi.isText(parent) || getElementType(parent) !== getElementType(ancestors[baseline.path.length - depth - 1] ?? {})) {
1174
- previous = void 0;
1175
- break;
1176
- }
1177
- previous = parent.children;
1178
- }
1179
- const canonical = schema ? canonicalizeDeclarativeChildren(children, schema, root, ancestors, dropMisplaced, previous, baseline?.from ?? 0, carried) : children;
1180
- if (canonicalizationObserver?.root === root && ancestors.length === 0 && baseline === void 0) canonicalizationObserver.passes.push(Object.freeze({
1181
- input: children,
1182
- output: canonical
1183
- }));
1184
- return canonical;
1185
- };
1186
- const copyDeclarativeChildren = (children, schema, root, ancestors) => {
1187
- const copyProperties = (node, placement, context, reserved) => {
1188
- const source = node;
1189
- const output = Object.fromEntries(Object.entries(source).filter(([key]) => {
1190
- if (reserved.has(key)) return true;
1191
- return resolveCompiledSchemaProperty(schema, placement, key, context)?.lifecycle.copy !== "drop";
1192
- }));
1193
- return Object.keys(output).length === Object.keys(source).length ? node : output;
1194
- };
1195
- const copied = children.map((node) => {
1196
- if (NodeApi.isText(node)) return copyProperties(node, "text", toCompiledNodeContext(node, ancestors, root), /* @__PURE__ */ new Set(["text"]));
1197
- const candidate = copyProperties(node, "element", toCompiledNodeContext(node, ancestors, root), /* @__PURE__ */ new Set([
1198
- "childRoots",
1199
- "children",
1200
- "type"
1201
- ]));
1202
- const nested = copyDeclarativeChildren(node.children, schema, root, [candidate, ...ancestors]);
1203
- return candidate === node && nested === node.children ? node : {
1204
- ...candidate,
1205
- children: nested
1206
- };
1207
- });
1208
- return copied.every((node, index) => node === children[index]) ? children : copied;
1209
- };
1210
- const copyChildren = (children, root, ancestors = []) => {
1211
- const schema = getDeclarativeSchema();
1212
- if (!schema) return children;
1213
- let hasCopyTransforms = SCHEMA_HAS_COPY_TRANSFORMS.get(schema);
1214
- if (hasCopyTransforms === void 0) {
1215
- hasCopyTransforms = false;
1216
- for (const lifecycle of schema.properties.lifecycle.values()) if (lifecycle.copy === "drop") {
1217
- hasCopyTransforms = true;
1218
- break;
1219
- }
1220
- SCHEMA_HAS_COPY_TRANSFORMS.set(schema, hasCopyTransforms);
1221
- }
1222
- return hasCopyTransforms ? copyDeclarativeChildren(children, schema, root, ancestors) : children;
1223
- };
1224
- const copyNodeAt = (node, path, root = "main") => {
1225
- const children = getDocumentRootNodes(getDocument(), root);
1226
- return copyChildren(node ? [node] : [], root, getElementAncestors(children, path))[0];
1227
- };
1228
- const getTextProperty = (schema, key, options = {}) => {
1229
- const parentType = options.parent ? getElementType(options.parent) ?? "" : "";
1230
- return getTextPropertyInParent(schema, key, parentType ? toCompiledTargetContext(parentType, options) : null);
1231
- };
1232
- const getTextTargetOptions = (value, path, root = "main") => {
1233
- const children = getDocumentRootNodes(value, root);
1234
- const ancestors = getElementAncestors(children, path);
1235
- return {
1236
- ancestors: ancestors.slice(1),
1237
- parent: ancestors[0] ?? null,
1238
- root
1239
- };
1240
- };
1241
- const getTextTargetOptionsAt = (path, root = "main") => getTextTargetOptions(getDocument(), path, root);
1242
- const getElementTargetOptionsAt = (path, root = "main", children = getDocumentRootNodes(getDocument(), root)) => ({
1243
- ancestors: getElementAncestors(children, path),
1244
- root
1245
- });
1246
- const keepsElementPropertyOnSplit = (schema, key, context) => {
1247
- if (key === "type") return true;
1248
- const property = resolveCompiledSchemaProperty(schema, "element", key, context);
1249
- return property ? property.lifecycle.split === "preserve" : schema.unknown === "preserve" && getCompiledPropertyCandidates(schema, "element", key).length === 0;
1250
- };
1251
- const elementPropertiesForSplitIn = (element, options) => {
1252
- const schema = getDeclarativeSchema();
1253
- if (!schema) return NodeApi.extractProps(element);
1254
- const context = toCompiledTargetContext(getElementType(element) ?? "", options);
1255
- return Object.freeze(Object.fromEntries(Object.entries(NodeApi.extractProps(element)).filter(([key]) => keepsElementPropertyOnSplit(schema, key, context))));
1256
- };
1257
- const elementPropertiesForSplitAt = (element, path, root = "main", children) => elementPropertiesForSplitIn(element, getElementTargetOptionsAt(path, root, children));
1258
- const elementPropertiesForSplitUnder = (element, ancestors, root = "main") => elementPropertiesForSplitIn(element, {
1259
- ancestors,
1260
- root
1261
- });
1262
- const elementSplitKeepsIn = (source, continuation, { continuationAncestors: ancestors, continuationIndex, root, sourceAncestors }) => {
1263
- const schema = getDeclarativeSchema();
1264
- if (!schema) return () => true;
1265
- const [parent] = ancestors;
1266
- const continuationSlotFixed = (parent ? getCompiledElement(parent)?.content : getRootContent(root))?.prefix?.[continuationIndex]?.properties ?? {};
1267
- const from = toCompiledTargetContext(getElementType(source) ?? "", {
1268
- ancestors: sourceAncestors,
1269
- root
1270
- });
1271
- const landed = toCompiledTargetContext(getElementType(continuation) ?? "", {
1272
- ancestors,
1273
- root
1274
- });
1275
- const retyped = continuation.type !== source.type;
1276
- const to = retyped || !jsonEqual(from.ancestors, landed.ancestors) ? landed : null;
1277
- return (key, value) => {
1278
- if (Object.hasOwn(continuationSlotFixed, key) || !keepsElementPropertyOnSplit(schema, key, from)) return false;
1279
- if (!to) return true;
1280
- if (key === "type") return !retyped;
1281
- if (!retyped) return keepsElementPropertyOnSplit(schema, key, to);
1282
- const keep = typeChangeKeep(schema, key, from, to);
1283
- return keep !== null && (value === void 0 || keep(value) !== null);
1284
- };
1285
- };
1286
- const elementSplitKeepsAt = (source, continuation, { children, path, root }) => {
1287
- const ancestors = getElementAncestors(children, path);
1288
- return elementSplitKeepsIn(source, continuation, {
1289
- continuationAncestors: ancestors,
1290
- continuationIndex: getDefined(path.at(-1)) + 1,
1291
- root,
1292
- sourceAncestors: ancestors
1293
- });
1294
- };
1295
- const elementDeclaredPropertiesIn = (element, { ancestors, root }) => {
1296
- const schema = getDeclarativeSchema();
1297
- const declared = /* @__PURE__ */ new Map();
1298
- if (!schema) return declared;
1299
- const context = toCompiledTargetContext(getElementType(element) ?? "", {
1300
- ancestors,
1301
- root
1302
- });
1303
- for (const id of schema.properties.elementAllowedByType.get(context.type) ?? []) {
1304
- const property = schema.properties.byId.get(id);
1305
- if (!property || typeof property.key !== "string" || !matchesCompiledSchemaTarget(schema, property.target, context)) continue;
1306
- if (declared.get(property.key) === void 0) declared.set(property.key, property.descriptor.omitDefault ? void 0 : getPropertyDefault(property));
1307
- }
1308
- return declared;
1309
- };
1310
- const elementPropertyLanding = (element, key, ancestors, root) => {
1311
- const schema = getDeclarativeSchema();
1312
- return schema ? resolveCompiledSchemaProperty(schema, "element", key, toCompiledTargetContext(getElementType(element) ?? "", {
1313
- ancestors,
1314
- root
1315
- }))?.lifecycle.landing ?? "preserve" : "preserve";
1316
- };
1317
- const getTextPropertyAt = (key, path, root = "main") => {
1318
- const schema = getDeclarativeSchema();
1319
- return schema ? getTextProperty(schema, key, getTextTargetOptionsAt(path, root)) : null;
1320
- };
1321
- const canonicalizeTextPropertiesIn = (properties, [parentType, ...ancestors], root = "main", preferredKey) => {
1322
- const schema = getDeclarativeSchema();
1323
- return schema && parentType ? canonicalizeCompiledExclusiveTextProperties(schema, properties, {
1324
- ...toCompiledTargetContext(parentType, { root }),
1325
- ancestors
1326
- }, preferredKey) : properties;
1327
- };
1328
- const canonicalizeTextPropertiesAt = (properties, path, root = "main", preferredKey, value = getDocument()) => {
1329
- const { ancestors = [], parent } = getTextTargetOptions(value, path, root);
1330
- return canonicalizeTextPropertiesIn(properties, parent ? [getElementType(parent) ?? "", ...ancestors.flatMap((element) => getElementType(element) ?? [])] : [], root, preferredKey);
1331
- };
1332
- const isSetValuedProperty = (_node, key, context) => {
1333
- const schema = getDeclarativeSchema();
1334
- return Boolean(schema && resolveCompiledSchemaProperty(schema, context.placement, key, {
1335
- ancestors: context.ancestors,
1336
- root: context.root,
1337
- type: context.type
1338
- })?.merge === "set");
1339
- };
1340
- const getVocabulary = () => {
1341
- const schema = getDeclarativeSchema();
1342
- if (!schema) return Object.freeze({
1343
- elementTypes: Object.freeze([]),
1344
- groupNames: Object.freeze([]),
1345
- propertyIds: Object.freeze([]),
1346
- rootNames: Object.freeze([])
1347
- });
1348
- return schema.vocabulary;
1349
- };
1350
- const textPropertyAppliesToContext = (parent, key, options = {}) => {
1351
- const schema = getDeclarativeSchema();
1352
- if (!schema) return true;
1353
- if (getCompiledPropertyCandidates(schema, "text", key).length === 0) return schema.unknown === "preserve";
1354
- return Boolean(resolveCompiledSchemaProperty(schema, "text", key, toCompiledTargetContext(getElementType(parent) ?? "", options)));
1355
- };
1356
- const isTextPropertyAllowedAt = (key, path, root = "main", value = getDocument()) => {
1357
- const options = getTextTargetOptions(value, path, root);
1358
- return Boolean(options.parent && textPropertyAppliesToContext(options.parent, key, options));
1359
- };
1360
- const mergeCompiledTextProperty = (key, previous, value, options = {}) => {
1361
- const schema = getDeclarativeSchema();
1362
- if (!schema) return snapshotEditorJsonValue(value, `Editor text property "${key}"`);
1363
- const candidates = getCompiledPropertyCandidates(schema, "text", key);
1364
- const property = getTextProperty(schema, key, options);
1365
- if (!property) {
1366
- if (candidates.length > 0 || schema.unknown === "reject") throw new EditorSchemaValidationError(candidates.length > 0 ? `Editor text property "${key}" cannot target editor element "${options.parent?.type ?? "root"}".` : `Unknown text property "${key}" in closed editor schema.`);
1367
- return snapshotEditorJsonValue(value, `Editor text property "${key}"`);
1368
- }
1369
- const canonical = validatePropertyValue(`Editor text property "${key}"`, property.descriptor, value);
1370
- if (property.merge !== "set") return canonical;
1371
- return normalizeSetValues([...previous === void 0 ? [] : validatePropertyValue(`Editor text property "${key}"`, property.descriptor, previous), ...canonical]);
1372
- };
1373
- const mergeTextPropertyAt = (key, previous, value, path, root = "main") => mergeCompiledTextProperty(key, previous, value, getTextTargetOptionsAt(path, root));
1374
- const getTextProperties = (text) => {
1375
- const { text: _text, ...properties } = text;
1376
- return properties;
1377
- };
1378
- const textPropertiesForSplit = (text, options = {}) => {
1379
- const schema = getDeclarativeSchema();
1380
- if (!schema) return Object.freeze(getTextProperties(text));
1381
- return Object.freeze(Object.fromEntries(Object.entries(getTextProperties(text)).filter(([key]) => {
1382
- const property = getTextProperty(schema, key, options);
1383
- return property ? property.lifecycle.split === "preserve" : schema.unknown === "preserve";
1384
- })));
1385
- };
1386
- const textPropertiesForSplitAt = (text, path, root = "main") => textPropertiesForSplit(text, getTextTargetOptionsAt(path, root));
1387
- const typeChangeKeep = (schema, key, from, to) => {
1388
- const source = resolveCompiledSchemaProperty(schema, "element", key, from);
1389
- if (!source) return schema.unknown === "preserve" && getCompiledPropertyCandidates(schema, "element", key).length === 0 ? (value) => ({ value }) : null;
1390
- if (source.lifecycle.typeChange !== "preserve-if-allowed") return null;
1391
- const destination = resolveCompiledSchemaProperty(schema, "element", key, to);
1392
- return destination ? (value) => {
1393
- try {
1394
- return { value: validatePropertyValue(`Editor element property "${key}"`, destination.descriptor, value) };
1395
- } catch (error) {
1396
- if (error instanceof ElementGenerationMaskedError) throw error;
1397
- return null;
1398
- }
1399
- } : null;
1400
- };
1401
- const keptElementProperties = (schema, element, from, to) => Object.fromEntries(Object.entries(NodeApi.extractProps(element)).flatMap(([key, value]) => {
1402
- if (key === "type") return [];
1403
- const kept = typeChangeKeep(schema, key, from, to)?.(value);
1404
- return kept ? [[key, kept.value]] : [];
1405
- }));
1406
- const elementForTypeChangeAt = (element, type, path, root) => {
1407
- if (element.type === type) return element;
1408
- const schema = getDeclarativeSchema();
1409
- if (!schema) return Object.freeze({
1410
- ...element,
1411
- type
1412
- });
1413
- const options = getElementTargetOptionsAt(path, root);
1414
- const fromType = getElementType(element) ?? "";
1415
- const toType = getElementType({ type }) ?? "";
1416
- const from = toCompiledTargetContext(fromType, options);
1417
- const to = toCompiledTargetContext(toType, options);
1418
- const textRules = /* @__PURE__ */ new Map();
1419
- const keepsText = (key, value) => {
1420
- let rule = textRules.get(key);
1421
- if (!rule) {
1422
- rule = [getTextPropertyInParent(schema, key, fromType ? from : null), getTextPropertyInParent(schema, key, toType ? to : null)];
1423
- textRules.set(key, rule);
1424
- }
1425
- const [source, destination] = rule;
1426
- if (!source) return schema.unknown === "preserve";
1427
- return source.lifecycle.typeChange === "preserve-if-allowed" && destination !== null && acceptsPropertyValue(destination.descriptor, value);
1428
- };
1429
- let children = null;
1430
- for (let index = 0; index < element.children.length; index++) {
1431
- const child = element.children[index];
1432
- if (!NodeApi.isText(child)) continue;
1433
- let kept = null;
1434
- for (const [key, value] of Object.entries(getTextProperties(child))) {
1435
- if (keepsText(key, value)) continue;
1436
- kept ??= { ...child };
1437
- delete kept[key];
1438
- }
1439
- if (!kept) continue;
1440
- children ??= [...element.children];
1441
- children[index] = kept;
1442
- }
1443
- return Object.freeze({
1444
- ...keptElementProperties(schema, element, from, to),
1445
- type,
1446
- children: children ?? element.children
1447
- });
1448
- };
1449
- const landTextPropertiesAt = (properties, at) => {
1450
- const schema = getDeclarativeSchema();
1451
- if (!schema) return properties;
1452
- const children = getDocumentRootNodes(at.value, at.root);
1453
- const ancestors = getElementAncestors(children, at.path);
1454
- const context = toCompiledNodeContext({ text: "" }, ancestors, at.root);
1455
- const stored = getDescendant(children, at.path);
1456
- const kept = /* @__PURE__ */ new Map();
1457
- const undeclared = [];
1458
- for (const [key, value] of Object.entries(properties)) {
1459
- if (getCompiledPropertyCandidates(schema, "text", key).length === 0) {
1460
- undeclared.push([key, value]);
1461
- continue;
1462
- }
1463
- const property = resolveCompiledSchemaProperty(schema, "text", key, context);
1464
- if (!property || acceptsPropertyValue(property.descriptor, value)) kept.set(key, value);
1465
- }
1466
- const [landed] = canonicalizeChildren([{
1467
- ...Object.fromEntries(kept),
1468
- text: ""
1469
- }], at.root, ancestors, true);
1470
- const storedProperties = stored && NodeApi.isText(stored) ? getTextProperties(stored) : {};
1471
- const marks = Object.fromEntries([...Object.entries(getTextProperties(landed)).filter(([key, value]) => kept.has(key) || !resolveCompiledSchemaProperty(schema, "text", key, context)?.descriptor.generate && (!Object.hasOwn(storedProperties, key) || jsonEqual(storedProperties[key], value))), ...undeclared]);
1472
- return TextApi.equals({
1473
- ...properties,
1474
- text: ""
1475
- }, {
1476
- ...marks,
1477
- text: ""
1478
- }) ? properties : marks;
1479
- };
1480
- const landNodeProperties = ({ properties, retype }, path, root = "main") => {
1481
- const schema = getDeclarativeSchema();
1482
- if (!schema) return {
1483
- ...properties,
1484
- ...retype
1485
- };
1486
- const children = getDocumentRootNodes(getDocument(), root);
1487
- const node = getDescendant(children, path);
1488
- if (!node) return {};
1489
- const ancestors = getElementAncestors(children, path);
1490
- const lands = (placement, key, value, context) => {
1491
- const property = resolveCompiledSchemaProperty(schema, placement, key, context);
1492
- return property ? acceptsPropertyValue(property.descriptor, value) : schema.unknown !== "reject" && getCompiledPropertyCandidates(schema, placement, key).length === 0;
1493
- };
1494
- const survivors = (wanted, canonical) => Object.fromEntries(Object.entries(wanted).filter(([key, value]) => Object.hasOwn(canonical, key) && structurallyEqual(canonical[key], value)));
1495
- if (NodeApi.isText(node)) {
1496
- if (ancestors.length === 0) return {};
1497
- const context = toCompiledNodeContext({ text: "" }, ancestors, root);
1498
- const activeId = (key, value) => {
1499
- const property = resolveCompiledSchemaProperty(schema, "text", key, context);
1500
- return property && unwrittenAs(property.descriptor, value) !== "left-out" ? property.id : null;
1501
- };
1502
- const own = getTextProperties(node);
1503
- const rank = ({ id, key }) => {
1504
- if (id === null) return 0;
1505
- return Object.hasOwn(own, key) ? 1 : 2;
1506
- };
1507
- const incoming = Object.entries(properties).filter(([key, value]) => lands("text", key, value, context)).map(([key, value]) => ({
1508
- id: activeId(key, value),
1509
- key,
1510
- value
1511
- })).toSorted((left, right) => rank(left) - rank(right) || (left.id ?? "").localeCompare(right.id ?? "") || left.key.localeCompare(right.key));
1512
- const occupied = new Map(Object.entries(own).flatMap(([key, value]) => {
1513
- const id = activeId(key, value);
1514
- return id ? [[key, id]] : [];
1515
- }));
1516
- const accepted = {};
1517
- for (const { id, key, value } of incoming) {
1518
- if (id && [...occupied].some(([other, taken]) => other !== key && schema.properties.conflictsByPropertyId.get(taken)?.has(id))) continue;
1519
- accepted[key] = value;
1520
- if (id) occupied.set(key, id);
1521
- else occupied.delete(key);
1522
- }
1523
- const held = Object.entries(own).filter(([key]) => !Object.hasOwn(accepted, key));
1524
- try {
1525
- return survivors(accepted, canonicalizeDeclarativePropertyRecord({
1526
- ...Object.fromEntries(held),
1527
- ...accepted
1528
- }, schema, "text", context, /* @__PURE__ */ new Set(), true));
1529
- } catch (error) {
1530
- if (error instanceof EditorSchemaValidationError) return {};
1531
- throw error;
1532
- }
1533
- }
1534
- if (!ElementApi.isElement(node)) return {};
1535
- const index = getDefined(path.at(-1));
1536
- const options = {
1537
- ancestors,
1538
- root
1539
- };
1540
- const [parent] = ancestors;
1541
- const content = parent ? getCompiledElement(parent)?.content : getRootContent(root);
1542
- const slotFixed = content?.prefix?.[index]?.properties ?? {};
1543
- const landAs = (type, element, identity) => {
1544
- const context = toCompiledTargetContext(getElementType({ type }) ?? "", options);
1545
- const accepted = Object.fromEntries(Object.entries(properties).filter(([key, value]) => lands("element", key, value, context) && (!Object.hasOwn(slotFixed, key) || structurallyEqual(slotFixed[key], value))));
1546
- try {
1547
- const canonical = canonicalizeDeclarativePropertyRecord({
1548
- ...NodeApi.extractProps(element),
1549
- ...accepted,
1550
- ...identity,
1551
- type
1552
- }, schema, "element", context, /* @__PURE__ */ new Set(["type", ...(schema.elements.byType.get(type)?.contentRoots.size ?? 0) > 0 ? ["childRoots"] : []]), true);
1553
- const landed = survivors(accepted, canonical);
1554
- if (Object.keys(survivors(identity, canonical)).length !== Object.keys(identity).length) return null;
1555
- if (type !== node.type || Object.keys(identity).length > 0) {
1556
- const final = {
1557
- ...canonical,
1558
- children: element.children,
1559
- type
1560
- };
1561
- validateDeclarativeChildren(canonicalizeDeclarativeChildren([final], schema, root, ancestors, false), schema, root, ancestors, path.slice(0, -1));
1562
- if (content && !contentAllowsAt(schema, content, final, index, options)) return null;
1563
- }
1564
- return landed;
1565
- } catch (error) {
1566
- if (error instanceof EditorSchemaValidationError) return null;
1567
- throw error;
1568
- }
1569
- };
1570
- if (retype) {
1571
- const { type, ...identity } = retype;
1572
- const landed = landAs(type, elementForTypeChangeAt(node, type, path, root), identity);
1573
- if (landed) return {
1574
- ...landed,
1575
- ...retype
1576
- };
1577
- }
1578
- return landAs(node.type, node, {}) ?? {};
1579
- };
1580
- const elementPropertiesForResetAt = (element, at, root = "main") => {
1581
- const slot = resolveDefaultSlot(at, root);
1582
- if (slot?.kind !== "element") return null;
1583
- const { schema, type } = slot;
1584
- const options = getElementTargetOptionsAt(at, root);
1585
- const context = toCompiledTargetContext(type, options);
1586
- const changed = elementForTypeChangeAt(element, type, at, root);
1587
- const sameType = changed === element;
1588
- const seed = sameType ? keptElementProperties(schema, element, context, context) : NodeApi.extractProps(changed);
1589
- if (sameType) for (const [key, value] of Object.entries(NodeApi.extractProps(element))) {
1590
- const property = resolveCompiledSchemaProperty(schema, "element", key, context);
1591
- if (property && !Object.hasOwn(property.descriptor, "default") && !property.descriptor.generate) seed[key] = value;
1592
- }
1593
- return refuseMissingProperty(() => {
1594
- const properties = canonicalizeDeclarativePropertyRecord({
1595
- ...seed,
1596
- ...slot.properties,
1597
- type
1598
- }, schema, "element", context, /* @__PURE__ */ new Set(["type"]), false);
1599
- if (sameType) return properties;
1600
- canonicalizeDeclarativeChildren([{
1601
- ...properties,
1602
- children: changed.children,
1603
- type
1604
- }], schema, root, options.ancestors ?? [], false);
1605
- return properties;
1606
- });
1607
- };
1608
- const validateTextProperties = (properties, parent, options = {}, location = toSchemaValidationLocation(options.root ?? "main", [], "text", parent ? [parent, ...options.ancestors ?? []] : options.ancestors)) => {
1609
- const schema = getDeclarativeSchema();
1610
- if (!schema) return;
1611
- for (const [key, value] of Object.entries(properties)) {
1612
- const candidates = getCompiledPropertyCandidates(schema, "text", key);
1613
- const property = parent ? resolveCompiledSchemaProperty(schema, "text", key, toCompiledTargetContext(getElementType(parent) ?? "", options)) : candidates.length === 1 && !candidates[0].target ? candidates[0] : null;
1614
- if (!property) {
1615
- if (candidates.length > 0 || schema.unknown === "reject") {
1616
- const message = candidates.length > 0 ? `Editor text property "${key}" cannot target editor element "${parent?.type ?? "root"}".` : `Unknown text property "${key}" in closed editor schema.`;
1617
- throw createEditorSchemaValidationError(candidates.length > 0 ? "property-target-mismatch" : "unknown-property", message, location, candidates.length > 0 ? { property: {
1618
- candidates,
1619
- key,
1620
- placement: "text"
1621
- } } : void 0);
1622
- }
1623
- continue;
1624
- }
1625
- try {
1626
- validatePropertyValue(`Editor text property "${key}"`, property.descriptor, value);
1627
- } catch (error) {
1628
- throw createEditorSchemaValidationError("invalid-property-value", error instanceof Error ? error.message : `Editor text property "${key}" is invalid.`, location, {
1629
- cause: error,
1630
- property: {
1631
- candidates: [property],
1632
- key,
1633
- placement: "text"
1634
- }
1635
- });
1636
- }
1637
- }
1638
- const context = parent ? toCompiledTargetContext(getElementType(parent) ?? "", options) : null;
1639
- if (context) {
1640
- for (const id of schema.properties.textAllowedByParentType.get(context.type) ?? []) {
1641
- const property = schema.properties.byId.get(id);
1642
- if (!property || typeof property.key !== "string" || Object.hasOwn(properties, property.key) || !matchesCompiledSchemaTarget(schema, property.target, context)) continue;
1643
- const hasCanonicalDefault = typeof property.descriptor.generate === "function" || Object.hasOwn(property.descriptor, "default") && !property.descriptor.omitDefault;
1644
- if (!property.descriptor.required && !hasCanonicalDefault) continue;
1645
- throw createEditorSchemaValidationError("missing-property", property.descriptor.required ? `Editor text requires property "${property.key}".` : `Editor text requires canonical property "${property.key}".`, location, { property: {
1646
- candidates: [property],
1647
- key: property.key,
1648
- placement: "text"
1649
- } });
1650
- }
1651
- const canonical = canonicalizeCompiledExclusiveTextProperties(schema, properties, context);
1652
- if (Object.keys(canonical).length !== Object.keys(properties).length) throw createEditorSchemaValidationError("exclusive-property-conflict", "Editor text properties contain mutually exclusive schema properties.", location);
1653
- }
1654
- };
1655
- const validateTextPropertiesAtValue = (properties, path, value, root = "main") => {
1656
- const options = getTextTargetOptions(value, path, root);
1657
- validateTextProperties(properties, options.parent ?? null, options, toSchemaValidationLocation(root, path, "text", options.parent ? [options.parent, ...options.ancestors ?? []] : options.ancestors));
1658
- };
1659
- const validateDeclarativeNodeProperties = (node, schema, root, ancestors, path, openAncestorBoundary = false) => {
1660
- const location = toSchemaValidationLocation(root, path, getValidationNodeType(node), ancestors);
1661
- if (NodeApi.isText(node)) {
1662
- validateTextProperties(getTextProperties(node), ancestors[0] ?? null, {
1663
- ancestors: ancestors.slice(1),
1664
- root
1665
- }, location);
1666
- return null;
1667
- }
1668
- const type = getElementType(node);
1669
- const element = type ? schema.elements.byType.get(type) : null;
1670
- if (!element) {
1671
- if (schema.unknown === "reject") throw createEditorSchemaValidationError("unknown-element", `Unknown editor element type "${type ?? "missing"}" at [${path}].`, location);
1672
- return null;
1673
- }
1674
- canonicalizeDeclarativePropertyRecord(node, schema, "element", toCompiledTargetContext(getDefined(type), {
1675
- ancestors,
1676
- root
1677
- }), /* @__PURE__ */ new Set([
1678
- "children",
1679
- "type",
1680
- ...element.contentRoots.size > 0 ? ["childRoots"] : []
1681
- ]), false, openAncestorBoundary, location);
1682
- return element;
1683
- };
1684
- const validateDeclarativeChildren = (children, schema, root, ancestors, parentPath, openAncestorBoundary = false, validated) => {
1685
- children.forEach((node, index) => {
1686
- if (validated?.(node)) return;
1687
- const path = [...parentPath, index];
1688
- const element = validateDeclarativeNodeProperties(node, schema, root, ancestors, path, openAncestorBoundary);
1689
- if (NodeApi.isText(node)) return;
1690
- const type = getElementType(node);
1691
- const location = toSchemaValidationLocation(root, path, type ?? void 0, ancestors);
1692
- const content = element?.content;
1693
- if (content) {
1694
- if (node.children.length < content.min) throw createEditorSchemaValidationError("invalid-content", `Editor element "${type}" at [${path}] requires at least ${content.min} children.`, location);
1695
- if (content.max !== null && node.children.length > content.max) throw createEditorSchemaValidationError("invalid-content", `Editor element "${type}" at [${path}] allows at most ${content.max} children.`, location);
1696
- for (const [childIndex, child] of node.children.entries()) {
1697
- const childType = NodeApi.isText(child) ? null : getElementType(child);
1698
- if (!contentAllowsAt(schema, content, child, childIndex, {
1699
- ancestors: [node, ...ancestors],
1700
- root
1701
- })) throw createEditorSchemaValidationError("invalid-content", `Editor element "${type}" at [${path}] cannot contain "${NodeApi.isText(child) ? "text" : childType ?? "element"}".`, toSchemaValidationLocation(root, [...path, childIndex], getValidationNodeType(child), [node, ...ancestors]));
1702
- }
1703
- }
1704
- validateDeclarativeChildren(node.children, schema, root, [node, ...ancestors], path, openAncestorBoundary);
1705
- });
1706
- };
1707
- const validateFragmentContents = (children, root = "main") => {
1708
- const declarative = getDeclarativeSchema();
1709
- if (declarative) validateDeclarativeChildren(children, declarative, root, [], [], true);
1710
- };
1711
- const assertSchemaJsonValue = (value, label, location) => {
1712
- try {
1713
- assertEditorJsonValue(value, label);
1714
- } catch (error) {
1715
- throw createEditorSchemaValidationError("invalid-json", error instanceof Error ? error.message : `${label} must encode to JSON-compatible data.`, location, { cause: error });
1716
- }
1717
- };
1718
- const assertFragment = (input) => {
1719
- const location = toSchemaValidationLocation("main", []);
1720
- assertSchemaJsonValue(input, "Editor document fragment", location);
1721
- if (!Array.isArray(input)) throw createEditorSchemaValidationError("invalid-json", "Editor document fragment must be an array.", location);
1722
- validateFragmentContents(input);
1723
- };
1724
- const validateSliceVocabulary = (children) => {
1725
- const declarative = getDeclarativeSchema();
1726
- if (declarative) {
1727
- const visitDeclarative = (node) => {
1728
- if (NodeApi.isText(node)) {
1729
- for (const [key, value] of Object.entries(getTextProperties(node))) {
1730
- const candidates = getCompiledPropertyCandidates(declarative, "text", key);
1731
- if (candidates.length === 0) {
1732
- if (declarative.unknown === "reject") throw new EditorSchemaValidationError(`Unknown text property "${key}" in closed editor schema.`);
1733
- continue;
1734
- }
1735
- if (!candidates.some((property) => {
1736
- try {
1737
- validatePropertyValue(`Editor text property "${key}"`, property.descriptor, value);
1738
- return true;
1739
- } catch (error) {
1740
- if (error instanceof ElementGenerationMaskedError) throw error;
1741
- return false;
1742
- }
1743
- })) throw new EditorSchemaValidationError(`Editor text property "${key}" is invalid.`);
1744
- }
1745
- return;
1746
- }
1747
- const type = getElementType(node);
1748
- const element = type ? declarative.elements.byType.get(type) : void 0;
1749
- if (!element && declarative.unknown === "reject") throw new EditorSchemaValidationError(`Unknown editor element type "${type ?? "missing"}".`);
1750
- for (const [key, value] of Object.entries(node)) {
1751
- if (key === "children" || key === "type" || key === "childRoots" && (element?.contentRoots.size ?? 0) > 0) continue;
1752
- const candidates = getCompiledPropertyCandidates(declarative, "element", key);
1753
- if (candidates.length === 0) {
1754
- if (declarative.unknown === "reject") throw new EditorSchemaValidationError(`Unknown editor element property "${key}" on "${type ?? "missing"}" in closed editor schema.`);
1755
- continue;
1756
- }
1757
- if (!candidates.some((property) => {
1758
- try {
1759
- validatePropertyValue(`Editor element property "${key}"`, property.descriptor, value);
1760
- return true;
1761
- } catch (error) {
1762
- if (error instanceof ElementGenerationMaskedError) throw error;
1763
- return false;
1764
- }
1765
- })) throw new EditorSchemaValidationError(`Editor element property "${key}" is invalid.`);
1766
- }
1767
- node.children.forEach(visitDeclarative);
1768
- };
1769
- children.forEach(visitDeclarative);
1770
- }
1771
- };
1772
- const assertContentSliceForSchema = (input) => {
1773
- const slice = ContentSlice.fromJSON(input);
1774
- const declarative = getDeclarativeSchema();
1775
- validateSliceVocabulary(slice.content);
1776
- for (const children of Object.values(slice.roots ?? {})) validateSliceVocabulary(children);
1777
- if (!declarative) return;
1778
- const detachedRoots = slice.roots ?? {};
1779
- const reached = /* @__PURE__ */ new Set();
1780
- const pending = [{
1781
- children: slice.content,
1782
- root: "main"
1783
- }];
1784
- while (pending.length > 0) {
1785
- const current = getDefined(pending.shift());
1786
- if (reached.has(current.root)) continue;
1787
- reached.add(current.root);
1788
- const visit = (node, path) => {
1789
- if (NodeApi.isText(node)) return;
1790
- const type = getElementType(node);
1791
- const element = type ? declarative.elements.byType.get(type) : void 0;
1792
- if (element && element.contentRoots.size > 0) {
1793
- const { childRoots } = node;
1794
- if (typeof childRoots !== "object" || childRoots === null || Array.isArray(childRoots)) throw new EditorSchemaValidationError(`Detached content slice element "${type}" at ${current.root}:[${path}] is missing its content-root references.`);
1795
- const references = childRoots;
1796
- const unknownSlot = Object.keys(references).find((slot) => !element.contentRoots.has(slot));
1797
- if (unknownSlot) throw new EditorSchemaValidationError(`Detached content slice element "${type}" at ${current.root}:[${path}] has undeclared content-root reference "${unknownSlot}".`);
1798
- for (const slot of element.contentRoots.keys()) {
1799
- const childRoot = references[slot];
1800
- if (typeof childRoot !== "string" || childRoot.length === 0 || childRoot === "main") throw new EditorSchemaValidationError(`Detached content slice element "${type}" at ${current.root}:[${path}] has an invalid content-root reference for "${slot}".`);
1801
- const children = detachedRoots[childRoot];
1802
- if (!children) throw new EditorSchemaValidationError(`Detached content slice is missing referenced root "${childRoot}".`);
1803
- pending.push({
1804
- children,
1805
- root: childRoot
1806
- });
1807
- }
1808
- }
1809
- node.children.forEach((child, index) => visit(child, [...path, index]));
1810
- };
1811
- current.children.forEach((node, index) => visit(node, [index]));
1812
- }
1813
- const orphan = Object.keys(detachedRoots).find((root) => !reached.has(root));
1814
- if (orphan) throw new EditorSchemaValidationError(`Detached content slice root "${orphan}" is not reachable from its content.`);
1815
- };
1816
- const validateDeclarativeRootContent = (root, children, content, schema) => {
1817
- if (children.length < content.min) throw createEditorSchemaValidationError("invalid-content", `Editor ${editorRootLabel(root)} requires at least ${content.min} children.`, toSchemaValidationLocation(root, []));
1818
- if (content.max !== null && children.length > content.max) throw createEditorSchemaValidationError("invalid-content", `Editor ${editorRootLabel(root)} allows at most ${content.max} children.`, toSchemaValidationLocation(root, []));
1819
- for (const [index, child] of children.entries()) if (!contentAllowsAt(schema, content, child, index, { root })) throw createEditorSchemaValidationError("invalid-content", `Editor ${editorRootLabel(root)} cannot contain "${NodeApi.isText(child) ? "text" : getElementType(child) ?? "element"}".`, toSchemaValidationLocation(root, [index], getValidationNodeType(child)));
1820
- };
1821
- const elementOwnedRootLocation = (value, input) => {
1822
- const path = findElementOwnedRootOwnerPath(input.ownerRoot === "main" ? value.children : value.roots?.[input.ownerRoot] ?? [], input);
1823
- if (!path) return failInvariant(`Element-owned root index counts a "${input.ownerType}.${input.slot ?? "contentRoots"}" declaration the document lacks.`);
1824
- return toSchemaValidationLocation(input.ownerRoot, path, input.ownerType);
1825
- };
1826
- const throwElementOwnedRootIssue = (value, issue) => {
1827
- const location = elementOwnedRootLocation(value, issue);
1828
- if (issue.kind === "missing-content-roots") throw createEditorSchemaValidationError("invalid-root", `Editor element "${issue.ownerType}" is missing its declared content roots.`, location);
1829
- if (issue.kind === "missing-slot") throw createEditorSchemaValidationError("invalid-root", `Editor element "${issue.ownerType}" is missing content root "${issue.slot}".`, location);
1830
- throw createEditorSchemaValidationError("invalid-root", `Editor element "${issue.ownerType}" content root "${issue.slot}" must reference a secondary root key.`, location);
1831
- };
1832
- const getProjectedRoot = (value, schema, childRoot, indexes = getDocumentOwnershipIndexes(schema, value)) => {
1833
- let exclusive = false;
1834
- let ownerCount = 0;
1835
- let projection;
1836
- for (const { index } of indexes) for (const grammar of getElementOwnedRootGrammarBindings(index, childRoot)) {
1837
- exclusive ||= grammar.ownership === "exclusive";
1838
- ownerCount += grammar.count;
1839
- if (projection && !contentProgramsEqual(projection.content, grammar.content)) {
1840
- const previous = elementOwnedRootLocation(value, projection.owner);
1841
- const conflicting = elementOwnedRootLocation(value, grammar.owner);
1842
- throw createEditorSchemaValidationError("invalid-root", `Editor root "${childRoot}" has conflicting projected content grammars from ${editorRootLabel(projection.owner.ownerRoot)}:[${previous.path}] "${projection.owner.ownerType}.${projection.owner.slot}" and ${editorRootLabel(grammar.owner.ownerRoot)}:[${conflicting.path}] "${grammar.owner.ownerType}.${grammar.owner.slot}".`, conflicting);
1843
- }
1844
- projection ??= Object.freeze({
1845
- content: grammar.content,
1846
- owner: grammar.owner
1847
- });
1848
- }
1849
- if (exclusive && ownerCount !== 1 && projection) throw createEditorSchemaValidationError("invalid-root", `Exclusive editor content root "${childRoot}" must have exactly one owner; received ${ownerCount}.`, elementOwnedRootLocation(value, projection.owner));
1850
- return projection;
1851
- };
1852
- const validateDeclarativeDocument = (value, schema) => {
1853
- const roots = {
1854
- main: value.children,
1855
- ...value.roots
1856
- };
1857
- const reuseRootNodes = !hasContentRoots();
1858
- const ownershipIndexes = hasContentRoots() ? getDocumentOwnershipIndexes(schema, value) : [];
1859
- const projectedRoots = /* @__PURE__ */ new Map();
1860
- const projectedRootKeys = /* @__PURE__ */ new Set();
1861
- for (const { index } of ownershipIndexes) {
1862
- const issue = getElementOwnedRootIssues(index)[0];
1863
- if (issue) throwElementOwnedRootIssue(value, issue);
1864
- for (const childRoot of getElementOwnedRootKeys(index)) projectedRootKeys.add(childRoot);
1865
- }
1866
- for (const childRoot of projectedRootKeys) {
1867
- const projection = getProjectedRoot(value, schema, childRoot, ownershipIndexes);
1868
- if (projection) projectedRoots.set(childRoot, projection);
1869
- }
1870
- for (const [name, root] of schema.roots) if (!Object.hasOwn(roots, name) && root.content.min > 0) throw createEditorSchemaValidationError("invalid-root", `Editor root "${name}" is missing from the document.`, toSchemaValidationLocation(name, []));
1871
- for (const [root, projection] of projectedRoots) {
1872
- if (!Object.hasOwn(roots, root)) throw createEditorSchemaValidationError("invalid-root", `Editor content root "${root}" is missing from the document.`, elementOwnedRootLocation(value, projection.owner));
1873
- if (schema.roots.has(root)) throw createEditorSchemaValidationError("invalid-root", `Editor root "${root}" cannot be both named and element-owned.`, elementOwnedRootLocation(value, projection.owner));
1874
- }
1875
- for (const [root, children] of Object.entries(roots)) {
1876
- const content = getDeclarativeRootProgram(schema, root) ?? projectedRoots.get(root)?.content;
1877
- if (content === void 0 && schema.unknown === "reject") throw createEditorSchemaValidationError("invalid-root", `Undeclared editor root "${root}" in closed editor schema.`, toSchemaValidationLocation(root, []));
1878
- const validated = reuseRootNodes ? VALIDATED_ROOT_NODES.get(schema) : void 0;
1879
- validateDeclarativeChildren(children, schema, root, [], [], false, validated ? (node) => validated.get(node) === root : void 0);
1880
- if (content) validateDeclarativeRootContent(root, children, content, schema);
1881
- }
1882
- };
1883
- const documentRoots = (value) => {
1884
- const roots = { main: rootIndexOf(value, "children") };
1885
- for (const root of visitRootNames(value.roots)) roots[root] = valueRootIndex(value, root);
1886
- return roots;
1887
- };
1888
- const frozenRoots = /* @__PURE__ */ new Map();
1889
- const rememberValidatedDocumentRoots = (value) => {
1890
- const authority = getValidationAuthority();
1891
- const holdsFrozenNodes = (root, document) => {
1892
- const checked = frozenRoots.get(root);
1893
- const frozen = checked ? checked.changedChildren(document).every((range) => {
1894
- for (let at = range[2]; at < range[3]; at += 1) if (!isDeepFrozenNode(document.child(at))) return false;
1895
- return true;
1896
- }) : isImmutable(document.value) && document.value.every((node) => isDeepFrozenNode(node));
1897
- if (frozen) frozenRoots.set(root, document);
1898
- return frozen;
1899
- };
1900
- const roots = documentRoots(value);
1901
- for (const root of visitRootNames(roots)) {
1902
- const document = roots[root];
1903
- if (isRootValidatedBy(document, authority) || holdsFrozenNodes(root, document)) markRootValidatedBy(document, authority);
1904
- }
1905
- for (const root of frozenRoots.keys()) if (!Object.hasOwn(roots, root)) frozenRoots.delete(root);
1906
- };
1907
- const assertDocument = (input) => {
1908
- profileCoreDuration("schema-validation-full-document-boundary", () => {
1909
- const location = toSchemaValidationLocation("main", []);
1910
- const rejectShape = (issue) => {
1911
- const root = issue.kind === "root" ? issue.root : "main";
1912
- throw createEditorSchemaValidationError(issue.kind === "field" || issue.kind === "meta-key" ? "invalid-document" : issue.kind === "root" || issue.kind === "roots" || issue.kind === "primary-root" ? "invalid-root" : "invalid-json", getEditorDocumentShapeIssueMessage(issue), toSchemaValidationLocation(root, []));
1913
- };
1914
- const value = readEditorDocument(input, rejectShape, (record) => assertSchemaJsonValue(record, "Editor document value", location));
1915
- const declarative = getDeclarativeSchema();
1916
- if (declarative) {
1917
- assertDeclaredRecordSets(Object.keys(getValueRecords(value)), declarative);
1918
- validateDeclarativeDocument(value, declarative);
1919
- if (!hasContentRoots()) {
1920
- let validated = VALIDATED_ROOT_NODES.get(declarative);
1921
- if (!validated) {
1922
- validated = /* @__PURE__ */ new WeakMap();
1923
- VALIDATED_ROOT_NODES.set(declarative, validated);
1924
- }
1925
- for (const [root, document] of Object.entries(documentRoots(value))) for (const node of document.value) if (isOwnedJsonValue(node)) validated.set(node, root);
1926
- }
1927
- }
1928
- rememberValidatedDocumentRoots(value);
1929
- });
1930
- };
1931
- const checkDocumentChange = ({ after, before, change, indexedAfter, indexedBefore }, beforeRoots) => {
1932
- const checked = [];
1933
- if (after.roots && Object.hasOwn(after.roots, "main")) throw new EditorSchemaValidationError("Editor document roots cannot redefine the primary root; use children.");
1934
- const schema = getDeclarativeSchema();
1935
- profileCoreDuration("schema-validation-incremental-hit", () => void 0);
1936
- if (schema) assertDeclaredRecordSets(getInternalDocumentChangeRecords(change).keys(), schema);
1937
- const afterRoots = documentRoots(after);
1938
- const changedRoots = /* @__PURE__ */ new Set([
1939
- ...[...getInternalDocumentChangeEntries(change)].map(([root]) => root),
1940
- ...change.createRoots,
1941
- ...change.deleteRoots
1942
- ]);
1943
- const touchedRoots = new Set(changedRoots);
1944
- const ownershipIndexes = [];
1945
- if (schema && hasContentRoots()) {
1946
- const dirtyChildRoots = /* @__PURE__ */ new Set();
1947
- let introduced;
1948
- const collectOwnershipChanges = (root, index) => {
1949
- const previous = beforeRoots[root] ? ensureElementOwnedRootIndex(schema, root, indexedBefore.get(root) ?? beforeRoots[root]) : null;
1950
- for (const childRoot of getChangedElementOwnedRootKeys(previous, index)) dirtyChildRoots.add(childRoot);
1951
- introduced ??= getIntroducedElementOwnedRootIssues(previous, index)[0];
1952
- };
1953
- for (const root of visitRootNames(afterRoots)) {
1954
- const afterDocument = indexedAfter.get(root) ?? afterRoots[root];
1955
- const beforeDocument = indexedBefore.get(root) ?? beforeRoots[root] ?? emptyIndexedDocument();
1956
- const index = touchedRoots.has(root) ? rebaseElementOwnedRootIndex(schema, root, getInternalDocumentRootChange(change, root), beforeDocument, afterDocument) : ensureElementOwnedRootIndex(schema, root, afterDocument);
1957
- ownershipIndexes.push({
1958
- index,
1959
- root
1960
- });
1961
- if (touchedRoots.has(root)) collectOwnershipChanges(root, index);
1962
- }
1963
- for (const root of change.deleteRoots) collectOwnershipChanges(root, null);
1964
- if (introduced) throwElementOwnedRootIssue(after, introduced);
1965
- const ownershipRoots = /* @__PURE__ */ new Set([
1966
- ...dirtyChildRoots,
1967
- ...change.createRoots,
1968
- ...change.deleteRoots
1969
- ]);
1970
- const checkOwnedRoot = (value, roots, root, indexes) => {
1971
- const projection = getProjectedRoot(value, schema, root, indexes);
1972
- if (projection) {
1973
- if (!Object.hasOwn(roots, root)) throw createEditorSchemaValidationError("invalid-root", `Editor content root "${root}" is missing from the document.`, elementOwnedRootLocation(value, projection.owner));
1974
- if (schema.roots.has(root)) throw createEditorSchemaValidationError("invalid-root", `Editor root "${root}" cannot be both named and element-owned.`, elementOwnedRootLocation(value, projection.owner));
1975
- return true;
1976
- }
1977
- if (Object.hasOwn(roots, root) && !schema.roots.has(root) && schema.unknown === "reject") throw createEditorSchemaValidationError("invalid-root", `Undeclared editor root "${root}" in closed editor schema.`, toSchemaValidationLocation(root, []));
1978
- return false;
1979
- };
1980
- const baselineHasRootError = (root) => {
1981
- try {
1982
- checkOwnedRoot(before, beforeRoots, root);
1983
- return false;
1984
- } catch (error) {
1985
- if (error instanceof EditorSchemaValidationError) return true;
1986
- throw error;
1987
- }
1988
- };
1989
- for (const root of ownershipRoots) {
1990
- if (root === "main") continue;
1991
- try {
1992
- if (checkOwnedRoot(after, afterRoots, root, ownershipIndexes)) touchedRoots.add(root);
1993
- } catch (error) {
1994
- if (!(error instanceof EditorSchemaValidationError) || !baselineHasRootError(root)) throw error;
1995
- }
1996
- }
1997
- }
1998
- const pathId = (path) => JSON.stringify(path);
1999
- const assertOwnJsonProperties = (node, root, path) => {
2000
- if (!Object.isFrozen(node)) throw new EditorSchemaValidationError(`Changed editor node at ${root}:[${path}] must be immutable.`);
2001
- for (const [key, value] of Object.entries(node)) {
2002
- if (key === "children" || key === "text") continue;
2003
- assertEditorJsonValue(value, `Editor node property "${key}" at ${root}:[${path}]`);
2004
- }
2005
- };
2006
- const validateContentIndexes = (children, content, indexes, owner, options) => {
2007
- if (children.length < content.min) throw new EditorSchemaValidationError(`${owner} requires at least ${content.min} children.`);
2008
- if (content.max !== null && children.length > content.max) throw new EditorSchemaValidationError(`${owner} allows at most ${content.max} children.`);
2009
- for (const index of indexes) {
2010
- const child = children.at(index);
2011
- if (!child || !schema || contentAllowsAt(schema, content, child, index, options)) continue;
2012
- throw new EditorSchemaValidationError(`${owner} cannot contain "${NodeApi.isText(child) ? "text" : getElementType(child) ?? "element"}".`);
2013
- }
2014
- };
2015
- if (schema) {
2016
- for (const [name, root] of schema.roots) if (!Object.hasOwn(afterRoots, name) && root.content.min > 0) throw new EditorSchemaValidationError(`Editor root "${name}" is missing from the document.`);
2017
- }
2018
- for (const root of touchedRoots) {
2019
- if (change.deleteRoots.has(root)) continue;
2020
- const document = afterRoots[root];
2021
- if (!document) throw new EditorSchemaValidationError(`Changed editor root "${root}" is missing from the document.`);
2022
- const afterDocument = indexedAfter.get(root) ?? (changedRoots.has(root) ? void 0 : document);
2023
- if (!afterDocument || afterDocument !== document) throw new EditorSchemaValidationError(`Changed editor root "${root}" lost its immutable construction index.`);
2024
- const children = rootNodes(afterDocument);
2025
- const beforeDocument = indexedBefore.get(root) ?? beforeRoots[root] ?? emptyIndexedDocument();
2026
- const rootChange = getInternalDocumentRootChange(change, root);
2027
- const ownPaths = /* @__PURE__ */ new Map();
2028
- const recursivePaths = /* @__PURE__ */ new Map();
2029
- const parentIndexes = /* @__PURE__ */ new Map();
2030
- const addParentIndex = (path, index) => {
2031
- const key = pathId(path);
2032
- const entry = parentIndexes.get(key) ?? {
2033
- indexes: /* @__PURE__ */ new Set(),
2034
- path: Object.freeze([...path])
2035
- };
2036
- if (index !== void 0 && index >= 0) entry.indexes.add(index);
2037
- parentIndexes.set(key, entry);
2038
- if (path.length > 0) ownPaths.set(key, entry.path);
2039
- };
2040
- const addOwnPath = (path) => {
2041
- ownPaths.set(pathId(path), Object.freeze([...path]));
2042
- const index = path.at(-1);
2043
- if (index !== void 0) addParentIndex(path.slice(0, -1), index);
2044
- };
2045
- profileCoreDuration("schema-validation-window-discovery", () => rootChange?.iterChangedRanges((fromBefore, toBefore, fromAfter, toAfter) => {
2046
- for (const entry of afterDocument.nodeRangesTouching(fromAfter, toAfter)) {
2047
- addOwnPath(entry.path);
2048
- if (entry.from >= fromAfter && entry.to <= toAfter) recursivePaths.set(pathId(entry.path), entry.path);
2049
- }
2050
- for (const position of [fromAfter, toAfter]) {
2051
- const boundary = afterDocument.childBoundaryAt(position);
2052
- if (boundary) addParentIndex(boundary.parentPath);
2053
- }
2054
- const edges = (entry, from, to) => ({
2055
- close: from < entry.to && entry.to <= to,
2056
- open: from <= entry.from && entry.from < to
2057
- });
2058
- for (const entry of afterDocument.nodeRangesTouching(fromAfter, toAfter)) {
2059
- const { close, open } = edges(entry, fromAfter, toAfter);
2060
- if (entry.kind !== "element" || open === close) continue;
2061
- afterDocument.node(entry.path).children.forEach((_child, index) => {
2062
- addParentIndex(entry.path, index);
2063
- });
2064
- }
2065
- for (const entry of beforeDocument.nodeRangesTouching(fromBefore, toBefore)) {
2066
- const { close, open } = edges(entry, fromBefore, toBefore);
2067
- if (entry.kind !== "element" || open === close) continue;
2068
- const boundary = afterDocument.childBoundaryAt(open ? fromAfter : toAfter);
2069
- if (!boundary) continue;
2070
- const { length } = beforeDocument.node(entry.path).children;
2071
- const first = open ? boundary.index : boundary.index - length;
2072
- for (let index = first; index < first + length; index++) addParentIndex(boundary.parentPath, index);
2073
- }
2074
- const beforeEntry = beforeDocument.nodeStartingAt(fromBefore);
2075
- const afterEntry = afterDocument.nodeStartingAt(fromAfter);
2076
- if (beforeEntry && afterEntry && toBefore === fromBefore + 1 && toAfter === fromAfter + 1) {
2077
- const previous = beforeDocument.node(beforeEntry.path);
2078
- const next = afterDocument.node(afterEntry.path);
2079
- if (ElementApi.isElement(previous) && ElementApi.isElement(next) && getElementType(previous) !== getElementType(next)) recursivePaths.set(pathId(afterEntry.path), afterEntry.path);
2080
- }
2081
- }));
2082
- const moved = profileCoreDuration("schema-validation-move-detection", () => rootChange?.movedNode(beforeDocument));
2083
- if (moved) {
2084
- recursivePaths.set(pathId(moved.targetPath), moved.targetPath);
2085
- addOwnPath(moved.targetPath);
2086
- }
2087
- const recursiveIndex = {
2088
- children: /* @__PURE__ */ new Map(),
2089
- terminal: false
2090
- };
2091
- const isRecursivelyValidated = (path) => {
2092
- let entry = recursiveIndex;
2093
- if (entry.terminal) return true;
2094
- for (const part of path) {
2095
- const child = entry.children.get(part);
2096
- if (!child) return false;
2097
- entry = child;
2098
- if (entry.terminal) return true;
2099
- }
2100
- return false;
2101
- };
2102
- const indexRecursivePath = (path) => {
2103
- let entry = recursiveIndex;
2104
- for (const part of path) {
2105
- let child = entry.children.get(part);
2106
- if (!child) {
2107
- child = {
2108
- children: /* @__PURE__ */ new Map(),
2109
- terminal: false
2110
- };
2111
- entry.children.set(part, child);
2112
- }
2113
- entry = child;
2114
- }
2115
- entry.terminal = true;
2116
- };
2117
- const recursive = [];
2118
- for (const path of [...recursivePaths.values()].sort((left, right) => left.length - right.length)) {
2119
- if (isRecursivelyValidated(path)) continue;
2120
- indexRecursivePath(path);
2121
- recursive.push(path);
2122
- }
2123
- const validateSubtree = (node, path, ancestors) => {
2124
- if (!Object.isFrozen(node)) throw new EditorSchemaValidationError(`Changed editor node at ${root}:[${path}] must be immutable.`);
2125
- assertEditorJsonValue(node, `Changed editor node at ${root}:[${path}]`);
2126
- if (!schema) return;
2127
- const element = validateDeclarativeNodeProperties(node, schema, root, ancestors, path);
2128
- if (NodeApi.isText(node)) return;
2129
- if (!Object.isFrozen(node.children)) throw new EditorSchemaValidationError(`Changed editor children at ${root}:[${path}] must be immutable.`);
2130
- if (element?.content) validateContentIndexes(node.children, element.content, new Set(node.children.map((_child, index) => index)), `Editor element "${node.type}" at [${path}]`, {
2131
- ancestors: [node, ...ancestors],
2132
- root
2133
- });
2134
- node.children.forEach((child, index) => {
2135
- validateSubtree(child, [...path, index], [node, ...ancestors]);
2136
- });
2137
- };
2138
- for (const path of recursive) {
2139
- const node = getDescendant(children, path);
2140
- if (!node) throw new EditorSchemaValidationError(`Cannot validate changed editor node at ${root}:[${path}].`);
2141
- validateSubtree(node, path, getElementAncestors(children, path));
2142
- }
2143
- for (const path of ownPaths.values()) {
2144
- if (isRecursivelyValidated(path)) continue;
2145
- const node = getDescendant(children, path);
2146
- if (!node) continue;
2147
- assertOwnJsonProperties(node, root, path);
2148
- if (schema) validateDeclarativeNodeProperties(node, schema, root, getElementAncestors(children, path), path);
2149
- }
2150
- for (const { indexes, path } of parentIndexes.values()) {
2151
- const parent = path.length === 0 ? null : getDescendant(children, path);
2152
- const content = path.length === 0 ? schema ? getDocumentRootProgram(schema, root, after) : null : schema && ElementApi.isElement(parent) ? schema.elements.byType.get(getElementType(parent) ?? "")?.content : null;
2153
- if (path.length === 0 && schema && !content) {
2154
- if (schema.unknown === "reject") throw new EditorSchemaValidationError(`Undeclared editor root "${root}" in closed editor schema.`);
2155
- continue;
2156
- }
2157
- if (!content) continue;
2158
- validateContentIndexes(path.length === 0 ? children : ElementApi.isElement(parent) ? parent.children : [], content, indexes, path.length === 0 ? `Editor ${editorRootLabel(root)}` : `Editor element "${parent.type}" at [${path}]`, {
2159
- ancestors: parent && ElementApi.isElement(parent) ? [parent, ...getElementAncestors(children, path)] : [],
2160
- root
2161
- });
2162
- }
2163
- checked.push(afterDocument);
2164
- }
2165
- return {
2166
- afterRoots,
2167
- checked,
2168
- touchedRoots
2169
- };
2170
- };
2171
- const validateDocumentChange = (input) => {
2172
- const authority = getValidationAuthority();
2173
- const beforeRoots = documentRoots(input.before);
2174
- const unvalidatedRoot = visitRootNames(beforeRoots).find((root) => !isRootValidatedBy(beforeRoots[root], authority));
2175
- if (unvalidatedRoot) throw new Error(`Incremental schema validation requires an explicitly validated immutable baseline for ${editorRootLabel(unvalidatedRoot)}. Call assertDocument() at the external document boundary before constructing changes.`);
2176
- const { afterRoots, checked, touchedRoots } = checkDocumentChange(input, beforeRoots);
2177
- for (const document of checked) markRootValidatedBy(document, authority);
2178
- for (const root of visitRootNames(afterRoots)) if (!isRootValidatedBy(afterRoots[root], authority) && !touchedRoots.has(root)) throw new EditorSchemaValidationError(`Unchanged editor root "${root}" lost validation authority.`);
2179
- };
2180
- const api = Object.freeze({
2181
- adoptDocumentBaseline: rememberValidatedDocumentRoots,
2182
- cachedRootCounts: () => {
2183
- const compiled = getDeclarativeSchema();
2184
- return Object.freeze({
2185
- frozen: frozenRoots.size,
2186
- ownership: compiled ? countElementOwnedRootBuilds(compiled) : 0
2187
- });
2188
- },
2189
- allowsElementType,
2190
- canContain,
2191
- canContainAt,
2192
- canContainAtRoot,
2193
- canPlaceAt,
2194
- canPlaceAtPath,
2195
- canWrap,
2196
- canonicalizeTextPropertiesAt,
2197
- canonicalizeTextPropertiesIn,
2198
- canonicalizeChildren,
2199
- copyChildren,
2200
- copyNodeAt,
2201
- validateChildrenAt: (children, root, ancestors) => {
2202
- const declarative = getDeclarativeSchema();
2203
- if (declarative) validateDeclarativeChildren(children, declarative, root, ancestors, []);
2204
- },
2205
- elementPropertiesForResetAt,
2206
- placeElementAt: placeDerivedElement,
2207
- elementPropertiesForSplitAt,
2208
- elementPropertiesForSplitUnder,
2209
- elementSplitKeepsAt,
2210
- elementSplitKeepsIn,
2211
- elementDeclaredPropertiesIn,
2212
- elementForTypeChangeAt,
2213
- landTextPropertiesAt,
2214
- landNodePropertiesAt: landNodeProperties,
2215
- elementPropertyLanding,
2216
- assertContentSliceForSchema,
2217
- assertDocument,
2218
- assertFragment,
2219
- create,
2220
- copy: (node, options) => copyNodeAt(node, options.at, options.root ?? "main"),
2221
- createAt,
2222
- createDefaultChild,
2223
- emptyTextDrops,
2224
- fitReportSink,
2225
- delta: () => getRegistry().schemaContributions.delta,
2226
- element: getPublicElement,
2227
- fit,
2228
- fitContent,
2229
- fitDocument,
2230
- fitDocumentAndMapPositions,
2231
- fitDocumentWithReport,
2232
- fitDocumentWithSelection,
2233
- findWrapping,
2234
- getElementBehavior,
2235
- getElementContent,
2236
- getElementContentRoots,
2237
- getOrphanedElementOwnedRoots,
2238
- isSetRoot,
2239
- holdsSetRoot,
2240
- declaresSetRoots,
2241
- findRootOwner,
2242
- readContentRootOwnerRoots,
2243
- getElementOwnedRoots,
2244
- getProperty,
2245
- getElementSlicePolicy,
2246
- getRootContent,
2247
- indexConstructedRoot,
2248
- getTextPropertyAt,
2249
- getVocabulary,
2250
- hasContentRoots,
2251
- identity: () => getRegistry().schemaContributions.compiled.identity,
2252
- isAtom: (element) => ElementApi.isElement(element) && getElementBehavior(element).atom,
2253
- isBlock: (element) => ElementApi.isElement(element) && !getElementBehavior(element).inline,
2254
- isElementTypeInGroup,
2255
- isSetValuedProperty,
2256
- isTextPropertyAllowedAt,
2257
- isInline: (element) => ElementApi.isElement(element) && getElementBehavior(element).inline,
2258
- isIsolating: (element) => ElementApi.isElement(element) && getElementBehavior(element).isolating,
2259
- isObject: (element) => ElementApi.isElement(element) && getElementBehavior(element).object,
2260
- isReadOnly: (element) => ElementApi.isElement(element) && getElementBehavior(element).readOnly,
2261
- isSelectable: (element) => ElementApi.isElement(element) && getElementBehavior(element).selectable,
2262
- isVoid: (element) => ElementApi.isElement(element) && getElementBehavior(element).void,
2263
- isMarkableVoid: (element) => ElementApi.isElement(element) && getElementBehavior(element).markableVoid,
2264
- property: getPublicProperty,
2265
- mergeTextPropertyAt,
2266
- textPropertiesForSplitAt,
2267
- tryCreateDefaultChild,
2268
- validateDocumentChange,
2269
- checkDocumentChange: (input) => checkDocumentChange(input, documentRoots(input.before)),
2270
- validateTextPropertiesAtValue
2271
- });
2272
- COMPILED_SCHEMA_BY_API.set(api, getDeclarativeSchema);
2273
- INTERNAL_BY_API.set(api, api);
2274
- REPRESENTATION_EDITOR_BY_API.set(api, representationEditor);
2275
- return api;
2276
- };
2277
- /** Create immutable schema authority that cannot read or retain a live editor. @internal */
2278
- const createDetachedEditorSchema = (schema, document) => {
2279
- const registry = {
2280
- schemaContributions: { compiled: schema },
2281
- schemaRevision: schema.revision
2282
- };
2283
- return createEditorSchema(() => {
2284
- throw new Error("Detached editor schema cannot read a live editor.");
2285
- }, () => registry, () => {
2286
- if (document) return document;
2287
- throw new Error("Detached editor schema requires an explicit document for document-relative operations.");
2288
- });
2289
- };
2290
- const holdsOneText = (schema, type) => {
2291
- const content = schema.getElementContent(type);
2292
- return content?.max === 1 && content.allowsText;
2293
- };
2294
- //#endregion
2295
- export { ElementGenerationMaskedError, acceptsPropertyValue, canPlaceBlocksAtPath, canonicalizeCompiledTextProperties, createDetachedEditorSchema, createEditorSchema, generateElementPropertyValue, getCompiledEditorSchemaFromApi, getInternalEditorSchemaFromApi, getRepresentationEditorFromApi, holdsImportedRoot, holdsOneText, landNodePropertiesAt, placeElementAt, readEmptyText, withoutGeneration, withoutGenerationOf };