quoin-editor 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/ai.cjs +135 -94
  3. package/dist/ai.cjs.map +1 -1
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.js +62 -21
  7. package/dist/ai.js.map +1 -1
  8. package/dist/catalogue.cjs +25 -25
  9. package/dist/catalogue.d.cts +6 -6
  10. package/dist/catalogue.d.ts +6 -6
  11. package/dist/catalogue.js +17 -17
  12. package/dist/{chunk-MQ2XQ4MX.js → chunk-26Q4LSIU.js} +6 -6
  13. package/dist/chunk-26Q4LSIU.js.map +1 -0
  14. package/dist/{chunk-AEJXZBVR.cjs → chunk-56C7GCKO.cjs} +110 -103
  15. package/dist/chunk-56C7GCKO.cjs.map +1 -0
  16. package/dist/{chunk-GTTPVJSD.cjs → chunk-5M4QG3ZC.cjs} +262 -245
  17. package/dist/chunk-5M4QG3ZC.cjs.map +1 -0
  18. package/dist/{chunk-2VDK27IF.cjs → chunk-5R3ISX4A.cjs} +312 -335
  19. package/dist/chunk-5R3ISX4A.cjs.map +1 -0
  20. package/dist/{chunk-LCQSG4M6.js → chunk-62WKUAQY.js} +18 -18
  21. package/dist/{chunk-LCQSG4M6.js.map → chunk-62WKUAQY.js.map} +1 -1
  22. package/dist/{chunk-NOKWNK2O.js → chunk-6LMS5J3Y.js} +3 -2
  23. package/dist/{chunk-HELJTLNC.cjs → chunk-6PKVJZQV.cjs} +12 -12
  24. package/dist/chunk-6PKVJZQV.cjs.map +1 -0
  25. package/dist/chunk-6YSGUAVW.js +376 -0
  26. package/dist/chunk-6YSGUAVW.js.map +1 -0
  27. package/dist/{chunk-CDELOHDY.cjs → chunk-75C6PX2L.cjs} +23 -23
  28. package/dist/{chunk-CDELOHDY.cjs.map → chunk-75C6PX2L.cjs.map} +1 -1
  29. package/dist/{chunk-T7SW6OWV.js → chunk-A4IJSJKL.js} +5 -5
  30. package/dist/{chunk-ND5XJVK2.cjs → chunk-BTBHHBVR.cjs} +19 -19
  31. package/dist/{chunk-ND5XJVK2.cjs.map → chunk-BTBHHBVR.cjs.map} +1 -1
  32. package/dist/{chunk-WXMYDXPN.cjs → chunk-CLTHD5GO.cjs} +4 -3
  33. package/dist/chunk-CLTHD5GO.cjs.map +1 -0
  34. package/dist/{chunk-OMOBMXD5.cjs → chunk-EH5KXQXY.cjs} +7 -2
  35. package/dist/chunk-EH5KXQXY.cjs.map +1 -0
  36. package/dist/{chunk-WQHV3MRE.cjs → chunk-ESMAW4NK.cjs} +12 -12
  37. package/dist/{chunk-WQHV3MRE.cjs.map → chunk-ESMAW4NK.cjs.map} +1 -1
  38. package/dist/{chunk-SLVDAHHK.cjs → chunk-EYFCOV3T.cjs} +5 -5
  39. package/dist/{chunk-SLVDAHHK.cjs.map → chunk-EYFCOV3T.cjs.map} +1 -1
  40. package/dist/{chunk-5DNCCN6X.cjs → chunk-F5V3IEEE.cjs} +27 -27
  41. package/dist/{chunk-5DNCCN6X.cjs.map → chunk-F5V3IEEE.cjs.map} +1 -1
  42. package/dist/{chunk-PMWCQSQX.js → chunk-GPIDU3GN.js} +5 -5
  43. package/dist/{chunk-PZ4GT5JO.cjs → chunk-HOIDJEVI.cjs} +316 -300
  44. package/dist/chunk-HOIDJEVI.cjs.map +1 -0
  45. package/dist/{chunk-RDG4VI6E.cjs → chunk-JJ3RASQS.cjs} +90 -90
  46. package/dist/{chunk-RDG4VI6E.cjs.map → chunk-JJ3RASQS.cjs.map} +1 -1
  47. package/dist/{chunk-ZGZEJCRV.js → chunk-LE3F7WIP.js} +23 -46
  48. package/dist/chunk-LE3F7WIP.js.map +1 -0
  49. package/dist/chunk-LE5XMIFJ.cjs +14 -0
  50. package/dist/chunk-LE5XMIFJ.cjs.map +1 -0
  51. package/dist/{chunk-POBM7MGR.js → chunk-LMAEPFTX.js} +2 -2
  52. package/dist/{chunk-ZHOSSWUM.js → chunk-LV6EYPJO.js} +4 -3
  53. package/dist/chunk-LV6EYPJO.js.map +1 -0
  54. package/dist/chunk-MLRAVUFG.cjs +376 -0
  55. package/dist/chunk-MLRAVUFG.cjs.map +1 -0
  56. package/dist/chunk-MQUCCSWG.js +14 -0
  57. package/dist/chunk-MQUCCSWG.js.map +1 -0
  58. package/dist/{chunk-XEBWC7ZL.js → chunk-O4Z2WMFF.js} +7 -2
  59. package/dist/chunk-O4Z2WMFF.js.map +1 -0
  60. package/dist/{chunk-K574XHMM.js → chunk-OCCKQHCY.js} +2 -2
  61. package/dist/{chunk-SG37UBDO.js → chunk-PGSS4IOS.js} +7 -7
  62. package/dist/{chunk-RUDWMKYX.js → chunk-PIWRSX7U.js} +8 -8
  63. package/dist/{chunk-PWUEPDA3.cjs → chunk-PX6LZMH4.cjs} +44 -44
  64. package/dist/{chunk-PWUEPDA3.cjs.map → chunk-PX6LZMH4.cjs.map} +1 -1
  65. package/dist/{chunk-JDPTZUBW.js → chunk-QXG3HWDS.js} +4 -4
  66. package/dist/{chunk-NNDYYEW5.js → chunk-RQW3P3GH.js} +5 -5
  67. package/dist/{chunk-ZS2WA357.js → chunk-SSIRYUCK.js} +144 -127
  68. package/dist/chunk-SSIRYUCK.js.map +1 -0
  69. package/dist/{chunk-47MLKSI2.js → chunk-UBNG5YCG.js} +6 -6
  70. package/dist/{chunk-KXOBZGQO.js → chunk-UCXLRRWY.js} +21 -14
  71. package/dist/chunk-UCXLRRWY.js.map +1 -0
  72. package/dist/{chunk-EL2OEJQC.cjs → chunk-UDAVVEFC.cjs} +56 -56
  73. package/dist/{chunk-EL2OEJQC.cjs.map → chunk-UDAVVEFC.cjs.map} +1 -1
  74. package/dist/{chunk-HJIQT3S5.js → chunk-UPSLDTLT.js} +100 -84
  75. package/dist/chunk-UPSLDTLT.js.map +1 -0
  76. package/dist/{chunk-GLLXHMH2.cjs → chunk-UWNZG2SD.cjs} +3 -3
  77. package/dist/{chunk-GLLXHMH2.cjs.map → chunk-UWNZG2SD.cjs.map} +1 -1
  78. package/dist/{chunk-HZSSEYJS.cjs → chunk-V3KLMSRO.cjs} +30 -30
  79. package/dist/{chunk-HZSSEYJS.cjs.map → chunk-V3KLMSRO.cjs.map} +1 -1
  80. package/dist/{chunk-ZC24WB7Y.cjs → chunk-VACTAZWS.cjs} +14 -14
  81. package/dist/{chunk-ZC24WB7Y.cjs.map → chunk-VACTAZWS.cjs.map} +1 -1
  82. package/dist/{chunk-KAVU6T6J.js → chunk-WMN6566P.js} +5 -5
  83. package/dist/{chunk-2QCRZ7OL.cjs → chunk-XX5FTPJR.cjs} +12 -11
  84. package/dist/{chunk-2QCRZ7OL.cjs.map → chunk-XX5FTPJR.cjs.map} +1 -1
  85. package/dist/comments.cjs +113 -98
  86. package/dist/comments.cjs.map +1 -1
  87. package/dist/comments.d.cts +6 -1
  88. package/dist/comments.d.ts +6 -1
  89. package/dist/comments.js +32 -17
  90. package/dist/comments.js.map +1 -1
  91. package/dist/diff.cjs +43 -40
  92. package/dist/diff.cjs.map +1 -1
  93. package/dist/diff.js +16 -13
  94. package/dist/diff.js.map +1 -1
  95. package/dist/docx.cjs +60 -40
  96. package/dist/docx.cjs.map +1 -1
  97. package/dist/docx.d.cts +6 -0
  98. package/dist/docx.d.ts +6 -0
  99. package/dist/docx.js +32 -12
  100. package/dist/docx.js.map +1 -1
  101. package/dist/embed.cjs +9 -9
  102. package/dist/embed.d.cts +1 -1
  103. package/dist/embed.d.ts +1 -1
  104. package/dist/embed.js +8 -8
  105. package/dist/{emoji-extension-DpQ43HjE.d.ts → emoji-extension-CmPlRssm.d.ts} +1 -1
  106. package/dist/{emoji-extension-C12gDPm6.d.cts → emoji-extension-zJ6F7hW8.d.cts} +1 -1
  107. package/dist/emoji.cjs +8 -8
  108. package/dist/emoji.d.cts +3 -3
  109. package/dist/emoji.d.ts +3 -3
  110. package/dist/emoji.js +7 -7
  111. package/dist/engine.cjs +4 -4
  112. package/dist/engine.d.cts +2 -2
  113. package/dist/engine.d.ts +2 -2
  114. package/dist/engine.js +3 -3
  115. package/dist/{find-extension-_sbZEt3R.d.cts → find-extension-BcRyE9K4.d.cts} +1 -1
  116. package/dist/{find-extension-DKqLLSuP.d.ts → find-extension-CmFehyul.d.ts} +1 -1
  117. package/dist/find.cjs +8 -8
  118. package/dist/find.d.cts +2 -2
  119. package/dist/find.d.ts +2 -2
  120. package/dist/find.js +7 -7
  121. package/dist/headless.cjs +5 -5
  122. package/dist/headless.d.cts +4 -4
  123. package/dist/headless.d.ts +4 -4
  124. package/dist/headless.js +4 -4
  125. package/dist/{index-CgD72kHB.d.cts → index-CFPmCee4.d.cts} +5 -2
  126. package/dist/{index-DNYbTK3w.d.ts → index-DiCGV60d.d.ts} +5 -2
  127. package/dist/index.cjs +7 -7
  128. package/dist/index.d.cts +4 -4
  129. package/dist/index.d.ts +4 -4
  130. package/dist/index.js +6 -6
  131. package/dist/math.cjs +10 -10
  132. package/dist/math.d.cts +1 -1
  133. package/dist/math.d.ts +1 -1
  134. package/dist/math.js +9 -9
  135. package/dist/mention.cjs +10 -10
  136. package/dist/mention.d.cts +1 -1
  137. package/dist/mention.d.ts +1 -1
  138. package/dist/mention.js +9 -9
  139. package/dist/presence.cjs +96 -99
  140. package/dist/presence.cjs.map +1 -1
  141. package/dist/presence.d.cts +2 -2
  142. package/dist/presence.d.ts +2 -2
  143. package/dist/presence.js +64 -67
  144. package/dist/presence.js.map +1 -1
  145. package/dist/{stats-extension-Bly88uio.d.ts → stats-extension-DisOEbbI.d.ts} +1 -1
  146. package/dist/{stats-extension-CJPijvUb.d.cts → stats-extension-Dt1lgP3m.d.cts} +1 -1
  147. package/dist/stats.cjs +9 -9
  148. package/dist/stats.d.cts +3 -3
  149. package/dist/stats.d.ts +3 -3
  150. package/dist/stats.js +8 -8
  151. package/dist/styles.css +1 -1
  152. package/dist/{table-extension-Dzf4k6hI.d.ts → table-extension-BTMJnT7J.d.ts} +1 -1
  153. package/dist/{table-extension-BTLxFy2S.d.cts → table-extension-DxZz3jqp.d.cts} +1 -1
  154. package/dist/table.cjs +8 -8
  155. package/dist/table.d.cts +2 -2
  156. package/dist/table.d.ts +2 -2
  157. package/dist/table.js +7 -7
  158. package/dist/{toc-extension-DWm5alVj.d.ts → toc-extension-CR9U-l6j.d.ts} +1 -1
  159. package/dist/{toc-extension-B3-s6h2x.d.cts → toc-extension-DGHywOBv.d.cts} +1 -1
  160. package/dist/toc.cjs +8 -8
  161. package/dist/toc.d.cts +2 -2
  162. package/dist/toc.d.ts +2 -2
  163. package/dist/toc.js +7 -7
  164. package/dist/{types-a1CRBlEh.d.ts → types-C6_QkXzy.d.ts} +1 -9
  165. package/dist/{types-Cz7XJLaK.d.cts → types-CJ7Gq3GX.d.cts} +1 -9
  166. package/dist/{view-controller-DSHw0ltQ.d.cts → view-controller-BD1KwYfE.d.cts} +6 -19
  167. package/dist/{view-controller-UbpzblGl.d.ts → view-controller-y4cb60ue.d.ts} +6 -19
  168. package/dist/view.cjs +6 -6
  169. package/dist/view.js +3 -3
  170. package/dist/yjs.cjs +234 -396
  171. package/dist/yjs.cjs.map +1 -1
  172. package/dist/yjs.d.cts +3 -3
  173. package/dist/yjs.d.ts +3 -3
  174. package/dist/yjs.js +126 -288
  175. package/dist/yjs.js.map +1 -1
  176. package/package.json +1 -1
  177. package/dist/chunk-2VDK27IF.cjs.map +0 -1
  178. package/dist/chunk-AEJXZBVR.cjs.map +0 -1
  179. package/dist/chunk-E75EHRPA.cjs +0 -175
  180. package/dist/chunk-E75EHRPA.cjs.map +0 -1
  181. package/dist/chunk-GTTPVJSD.cjs.map +0 -1
  182. package/dist/chunk-HELJTLNC.cjs.map +0 -1
  183. package/dist/chunk-HJIQT3S5.js.map +0 -1
  184. package/dist/chunk-JEIFJHEI.js +0 -14
  185. package/dist/chunk-JEIFJHEI.js.map +0 -1
  186. package/dist/chunk-KXOBZGQO.js.map +0 -1
  187. package/dist/chunk-MQ2XQ4MX.js.map +0 -1
  188. package/dist/chunk-OMOBMXD5.cjs.map +0 -1
  189. package/dist/chunk-PZ4GT5JO.cjs.map +0 -1
  190. package/dist/chunk-QAW5NH6S.cjs +0 -14
  191. package/dist/chunk-QAW5NH6S.cjs.map +0 -1
  192. package/dist/chunk-TC4DARU2.js +0 -175
  193. package/dist/chunk-TC4DARU2.js.map +0 -1
  194. package/dist/chunk-WXMYDXPN.cjs.map +0 -1
  195. package/dist/chunk-XEBWC7ZL.js.map +0 -1
  196. package/dist/chunk-ZGZEJCRV.js.map +0 -1
  197. package/dist/chunk-ZHOSSWUM.js.map +0 -1
  198. package/dist/chunk-ZS2WA357.js.map +0 -1
  199. /package/dist/{chunk-NOKWNK2O.js.map → chunk-6LMS5J3Y.js.map} +0 -0
  200. /package/dist/{chunk-T7SW6OWV.js.map → chunk-A4IJSJKL.js.map} +0 -0
  201. /package/dist/{chunk-PMWCQSQX.js.map → chunk-GPIDU3GN.js.map} +0 -0
  202. /package/dist/{chunk-POBM7MGR.js.map → chunk-LMAEPFTX.js.map} +0 -0
  203. /package/dist/{chunk-K574XHMM.js.map → chunk-OCCKQHCY.js.map} +0 -0
  204. /package/dist/{chunk-SG37UBDO.js.map → chunk-PGSS4IOS.js.map} +0 -0
  205. /package/dist/{chunk-RUDWMKYX.js.map → chunk-PIWRSX7U.js.map} +0 -0
  206. /package/dist/{chunk-JDPTZUBW.js.map → chunk-QXG3HWDS.js.map} +0 -0
  207. /package/dist/{chunk-NNDYYEW5.js.map → chunk-RQW3P3GH.js.map} +0 -0
  208. /package/dist/{chunk-47MLKSI2.js.map → chunk-UBNG5YCG.js.map} +0 -0
  209. /package/dist/{chunk-KAVU6T6J.js.map → chunk-WMN6566P.js.map} +0 -0
package/dist/yjs.cjs CHANGED
@@ -15,7 +15,6 @@
15
15
 
16
16
 
17
17
 
18
- var _chunkE75EHRPAcjs = require('./chunk-E75EHRPA.cjs');
19
18
 
20
19
 
21
20
 
@@ -32,12 +31,11 @@ var _chunkE75EHRPAcjs = require('./chunk-E75EHRPA.cjs');
32
31
 
33
32
 
34
33
 
34
+ var _chunkMLRAVUFGcjs = require('./chunk-MLRAVUFG.cjs');
35
35
 
36
36
 
37
- var _chunkPZ4GT5JOcjs = require('./chunk-PZ4GT5JO.cjs');
38
37
 
39
38
 
40
- var _chunk2QCRZ7OLcjs = require('./chunk-2QCRZ7OL.cjs');
41
39
 
42
40
 
43
41
 
@@ -47,127 +45,23 @@ var _chunk2QCRZ7OLcjs = require('./chunk-2QCRZ7OL.cjs');
47
45
 
48
46
 
49
47
 
48
+ var _chunkHOIDJEVIcjs = require('./chunk-HOIDJEVI.cjs');
49
+
50
+
51
+ var _chunkXX5FTPJRcjs = require('./chunk-XX5FTPJR.cjs');
50
52
 
51
53
 
52
54
 
53
- var _chunkND5XJVK2cjs = require('./chunk-ND5XJVK2.cjs');
54
55
 
55
- // src/engine/collab/apply-remote.ts
56
- function applyRemote(editor, steps, selectionHint) {
57
- const tr = editor.createTransaction().setOrigin("remote").setMeta("addToHistory", false);
58
- for (const step of steps) tr.step(step);
59
- if (selectionHint && _chunkPZ4GT5JOcjs.sameSelection.call(void 0, _chunkPZ4GT5JOcjs.validateSelection.call(void 0, tr.doc, editor.schema, selectionHint), selectionHint)) {
60
- tr.setSelection(selectionHint);
61
- }
62
- editor.dispatch(tr);
63
- }
64
56
 
65
- // src/yjs/local-to-yjs.ts
66
- var _yjs = require('yjs'); var Y4 = _interopRequireWildcard(_yjs); var Y = _interopRequireWildcard(_yjs); var Y2 = _interopRequireWildcard(_yjs); var Y3 = _interopRequireWildcard(_yjs); var Y5 = _interopRequireWildcard(_yjs); var Y6 = _interopRequireWildcard(_yjs);
67
-
68
- // src/yjs/doc-shape.ts
69
-
70
-
71
- // src/yjs/marks-codec.ts
72
- var ESCAPE = "$";
73
- var escapeKey = (key) => key in Object.prototype || key.startsWith(ESCAPE) ? ESCAPE + key : key;
74
- var unescapeKey = (key) => key.startsWith(ESCAPE) ? key.slice(1) : key;
75
- var onlyString = (attrs, key) => Object.keys(attrs).length === 1 && Object.hasOwn(attrs, key) && typeof attrs[key] === "string";
76
- function markAttribute(mark) {
77
- const key = _chunkND5XJVK2cjs.markKey.call(void 0, mark);
78
- const { attrs } = mark;
79
- const stacked = key !== mark.type;
80
- if (attrs === void 0) return [escapeKey(key), !stacked];
81
- if (stacked && onlyString(attrs, "id")) return [escapeKey(key), true];
82
- if (onlyString(attrs, mark.type)) return [escapeKey(key), attrs[mark.type]];
83
- return [escapeKey(key), attrs];
84
- }
85
- function stackedType(key) {
86
- const colon = key.indexOf(":");
87
- if (colon < 1) return null;
88
- const type = key.slice(0, colon);
89
- const id = key.slice(colon + 1);
90
- return _chunkND5XJVK2cjs.markKey.call(void 0, { type, attrs: { id } }) === key ? [type, id] : null;
91
- }
92
- function markFromAttribute(attribute, value) {
93
- const key = unescapeKey(attribute);
94
- const stacked = stackedType(key);
95
- const type = _nullishCoalesce(_optionalChain([stacked, 'optionalAccess', _2 => _2[0]]), () => ( key));
96
- if (value === true) return stacked === null ? { type } : { type, attrs: { id: stacked[1] } };
97
- if (value === false) return { type };
98
- if (typeof value === "string") return { type, attrs: { [type]: value } };
99
- return { type, attrs: value };
100
- }
101
- var marksToAttributes = (marks) => Object.fromEntries(marks.map(markAttribute));
102
- var attributesToMarks = (attributes = {}) => Object.entries(attributes).map(([key, value]) => markFromAttribute(key, value));
103
-
104
- // src/yjs/inline-codec.ts
105
- var inlineOps = (inline) => inline.map((node) => ({
106
- insert: node.kind === "text" ? node.text : { atom: node.type, attrs: node.attrs },
107
- attributes: marksToAttributes(node.marks)
108
- }));
109
- function insertInline(target, at, inline) {
110
- let offset = at;
111
- for (const node of inline) {
112
- const attributes = marksToAttributes(node.marks);
113
- if (node.kind === "text") target.insert(offset, node.text, attributes);
114
- else target.insertEmbed(offset, { atom: node.type, attrs: node.attrs }, attributes);
115
- offset += _chunkND5XJVK2cjs.nodeLength.call(void 0, node);
116
- }
117
- }
118
- function nodeOf({ insert, attributes }) {
119
- const marks = attributesToMarks(attributes);
120
- return typeof insert === "string" ? _chunkND5XJVK2cjs.text.call(void 0, insert, marks) : _chunkND5XJVK2cjs.atom.call(void 0, insert.atom, insert.attrs, marks);
121
- }
122
- var inlineOfOps = (ops) => _chunkND5XJVK2cjs.normalizeInline.call(void 0, ops.map(nodeOf));
123
-
124
- // src/yjs/doc-shape.ts
125
- var deleteText = (text2, at, length) => text2.applyDelta(at > 0 ? [{ retain: at }, { delete: length }] : [{ delete: length }]);
126
- var regionStart = (name) => ({ r: name });
127
- var isPlainObject = (value) => typeof value === "object" && value !== null && !(value instanceof Y.AbstractType);
128
- var regionNameOf = (embed) => isPlainObject(embed) && typeof embed.r === "string" && embed.atom === void 0 ? embed.r : null;
129
- var isAtomEmbed = (embed) => isPlainObject(embed) && typeof embed.atom === "string" && isPlainObject(embed.attrs);
130
- var definedEntries = (attrs) => Object.entries(attrs).filter(([, value]) => value !== void 0);
131
- function markerOf(block) {
132
- return new Y.Map([
133
- ["id", block.id],
134
- ["type", block.type],
135
- ["indent", block.indent],
136
- ["attrs", new Y.Map(definedEntries(block.attrs))]
137
- ]);
138
- }
139
- function readMarker(map) {
140
- const [id, type, indent, attrs] = ["id", "type", "indent", "attrs"].map((key) => map.get(key));
141
- if (typeof id !== "string") return null;
142
- return {
143
- id,
144
- type: typeof type === "string" ? type : "",
145
- indent: typeof indent === "number" ? indent : 0,
146
- attrs: attrs instanceof Y.Map ? attrs : null
147
- };
148
- }
149
- function blockOps(block, map, open) {
150
- const ops = [{ insert: map, attributes: {} }];
151
- for (const [name, inline] of Object.entries(block.regions)) {
152
- ops.push({ insert: regionStart(name), attributes: {} });
153
- if (name === open) break;
154
- ops.push(...inlineOps(inline));
155
- }
156
- return ops;
157
- }
158
- var writeOps = (text2, at, ops) => text2.applyDelta(at > 0 ? [{ retain: at }, ...ops] : ops);
159
- function writeBlock(text2, at, block, map, open) {
160
- writeOps(text2, at, blockOps(block, map, open));
161
- }
162
- function writeBlocks(text2, at, blocks) {
163
- const maps = blocks.map(markerOf);
164
- writeOps(text2, at, blocks.flatMap((block, i) => blockOps(block, maps[i])));
165
- return maps;
166
- }
167
57
 
168
- // src/yjs/read-shared.ts
169
58
 
170
59
 
60
+ var _chunkBTBHHBVRcjs = require('./chunk-BTBHHBVR.cjs');
61
+
62
+ // src/yjs/read-shared.ts
63
+ var _yjs = require('yjs'); var Y = _interopRequireWildcard(_yjs); var Y2 = _interopRequireWildcard(_yjs); var Y3 = _interopRequireWildcard(_yjs);
64
+
171
65
  // src/yjs/required-regions.ts
172
66
  var noRequiredRegions = () => [];
173
67
  function requiredRegions(schema) {
@@ -176,7 +70,7 @@ function requiredRegions(schema) {
176
70
  let names = known.get(type);
177
71
  if (names === void 0) {
178
72
  const spec = schema.blocks.get(type);
179
- names = _optionalChain([spec, 'optionalAccess', _3 => _3.flow]) === "text" ? Object.keys(spec.initial().regions) : [];
73
+ names = _optionalChain([spec, 'optionalAccess', _2 => _2.flow]) === "text" ? Object.keys(spec.initial().regions) : [];
180
74
  known.set(type, names);
181
75
  }
182
76
  return names;
@@ -185,7 +79,7 @@ function requiredRegions(schema) {
185
79
 
186
80
  // src/yjs/read-shared.ts
187
81
  function reader(required) {
188
- const spans = [_chunkE75EHRPAcjs.emptySpan.call(void 0, )];
82
+ const spans = [_chunkMLRAVUFGcjs.emptySpan.call(void 0, )];
189
83
  const entries = /* @__PURE__ */ new Map();
190
84
  const markers = /* @__PURE__ */ new Map();
191
85
  const order = [];
@@ -222,11 +116,11 @@ function reader(required) {
222
116
  }
223
117
  }
224
118
  function marker(map) {
225
- span = _chunkE75EHRPAcjs.emptySpan.call(void 0, );
119
+ span = _chunkMLRAVUFGcjs.emptySpan.call(void 0, );
226
120
  span.index = spans.length;
227
121
  spans.push(span);
228
122
  [open, stray] = [null, null];
229
- const fields = readMarker(map);
123
+ const fields = _chunkMLRAVUFGcjs.readMarker.call(void 0, map);
230
124
  const kept = fields !== null && !entries.has(fields.id);
231
125
  entry = kept ? { id: fields.id, map, span, regions: [], copies: [] } : null;
232
126
  if (entry !== null) {
@@ -242,14 +136,22 @@ function reader(required) {
242
136
  }
243
137
  }
244
138
  function embed(value) {
245
- const name = regionNameOf(value);
139
+ let name = _chunkMLRAVUFGcjs.regionNameOf.call(void 0, value);
246
140
  stray = null;
247
- if (name !== null && entry !== null && !entry.regions.some((region2) => region2.name === name)) {
248
- const region2 = { name, entry, segs: [] };
249
- entry.regions.push(region2);
250
- order.push(region2);
251
- open = opened(region2);
252
- return;
141
+ const missing = (one) => !entry.regions.some((region2) => region2.name === one);
142
+ if (name !== null && entry !== null) {
143
+ const needed = required(markers.get(entry).type);
144
+ if (needed.length > 0 && !needed.includes(name)) {
145
+ clean = false;
146
+ name = _nullishCoalesce(needed.find(missing), () => ( null));
147
+ }
148
+ if (name !== null && missing(name)) {
149
+ const region2 = { name, entry, segs: [] };
150
+ entry.regions.push(region2);
151
+ order.push(region2);
152
+ open = opened(region2);
153
+ return;
154
+ }
253
155
  }
254
156
  clean = false;
255
157
  if (open !== null) open = opened(open.region);
@@ -257,13 +159,13 @@ function reader(required) {
257
159
  return {
258
160
  read(op) {
259
161
  const { insert } = op;
260
- if (typeof insert === "string" || isAtomEmbed(insert)) {
162
+ if (typeof insert === "string" || _chunkMLRAVUFGcjs.isAtomEmbed.call(void 0, insert)) {
261
163
  const length = typeof insert === "string" ? insert.length : 1;
262
164
  content(op, length);
263
165
  span.length += length;
264
166
  return;
265
167
  }
266
- if (insert instanceof Y2.Map) marker(insert);
168
+ if (insert instanceof Y.Map) marker(insert);
267
169
  else embed(insert);
268
170
  span.length += 1;
269
171
  },
@@ -281,18 +183,18 @@ function reader(required) {
281
183
  if (after === null) leading.push(seg);
282
184
  else region2.segs.push(seg);
283
185
  }
284
- _optionalChain([order, 'access', _4 => _4[0], 'optionalAccess', _5 => _5.segs, 'access', _6 => _6.unshift, 'call', _7 => _7(...leading)]);
186
+ _optionalChain([order, 'access', _3 => _3[0], 'optionalAccess', _4 => _4.segs, 'access', _5 => _5.unshift, 'call', _6 => _6(...leading)]);
285
187
  const blocks = [...entries.values()].map((kept) => {
286
188
  const { type, indent, attrs } = markers.get(kept);
287
189
  for (const name of required(type)) {
288
190
  if (!kept.regions.some((region2) => region2.name === name)) kept.regions.push({ name, entry: kept, segs: [] });
289
191
  }
290
- const inline = (segs) => inlineOfOps(segs.flatMap((seg) => held2.get(seg)));
192
+ const inline = (segs) => _chunkMLRAVUFGcjs.inlineOfOps.call(void 0, segs.flatMap((seg) => held2.get(seg)));
291
193
  const regions = kept.regions.map(({ name, segs }) => [name, inline(segs)]);
292
- return { id: kept.id, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _8 => _8.toJSON, 'call', _9 => _9()]), () => ( {})), regions: Object.fromEntries(regions) };
194
+ return { id: kept.id, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _7 => _7.toJSON, 'call', _8 => _8()]), () => ( {})), regions: Object.fromEntries(regions) };
293
195
  });
294
- const layout = _chunkE75EHRPAcjs.createLayout.call(void 0, spans, entries, clean, { read, leading: new Set(leading), unread });
295
- return { doc: _chunkND5XJVK2cjs.createDoc.call(void 0, blocks), layout };
196
+ const layout = _chunkMLRAVUFGcjs.createLayout.call(void 0, spans, entries, clean, { read, leading: new Set(leading), unread });
197
+ return { doc: _chunkBTBHHBVRcjs.createDoc.call(void 0, blocks), layout };
296
198
  }
297
199
  };
298
200
  }
@@ -310,44 +212,41 @@ function reread(shared) {
310
212
  function insertContent(shared, region2, offset, inline) {
311
213
  if (inline.length === 0) return;
312
214
  if (region2.segs.length === 0) return openRegion(shared, region2, inline);
313
- const { seg, rel } = _chunkE75EHRPAcjs.pointOf.call(void 0, region2, offset);
314
- insertInline(shared.text, _chunkE75EHRPAcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, inline);
315
- _chunkE75EHRPAcjs.grow.call(void 0, shared.layout, seg, rel, _chunkND5XJVK2cjs.inlineLength.call(void 0, inline));
215
+ const { seg, rel } = _chunkMLRAVUFGcjs.pointOf.call(void 0, region2, offset);
216
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, shared.text, _chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, inline);
217
+ _chunkMLRAVUFGcjs.grow.call(void 0, shared.layout, seg, rel, _chunkBTBHHBVRcjs.inlineLength.call(void 0, inline));
316
218
  }
317
219
  function deleteContent(shared, region2, from, to) {
318
- for (const { seg, rel, length } of _chunkE75EHRPAcjs.piecesOf.call(void 0, region2, from, to).reverse()) {
319
- deleteText(shared.text, _chunkE75EHRPAcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, length);
320
- _chunkE75EHRPAcjs.grow.call(void 0, shared.layout, seg, rel, -length);
220
+ for (const { seg, rel, length } of _chunkMLRAVUFGcjs.piecesOf.call(void 0, region2, from, to).reverse()) {
221
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, shared.text, _chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, length);
222
+ _chunkMLRAVUFGcjs.grow.call(void 0, shared.layout, seg, rel, -length);
321
223
  }
322
224
  }
323
225
  function formatContent(shared, region2, from, to, attributes) {
324
- for (const { seg, rel, length } of _chunkE75EHRPAcjs.piecesOf.call(void 0, region2, from, to)) {
325
- shared.text.format(_chunkE75EHRPAcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, length, attributes);
226
+ for (const { seg, rel, length } of _chunkMLRAVUFGcjs.piecesOf.call(void 0, region2, from, to)) {
227
+ shared.text.format(_chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, length, attributes);
326
228
  }
327
229
  }
328
230
  function openRegion(shared, { name, entry }, inline) {
329
- const at = _chunkE75EHRPAcjs.spanStart.call(void 0, shared.layout, entry.span) + entry.span.length;
330
- shared.text.insertEmbed(at, regionStart(name), {});
331
- insertInline(shared.text, at + 1, inline);
231
+ const at = _chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, entry.span) + entry.span.length;
232
+ shared.text.insertEmbed(at, _chunkMLRAVUFGcjs.regionStart.call(void 0, name), {});
233
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, shared.text, at + 1, inline);
332
234
  reread(shared);
333
235
  }
334
236
 
335
- // src/yjs/sync-block.ts
336
-
337
-
338
237
  // src/yjs/inline-span.ts
339
238
  var units = (inline) => inline.flatMap(
340
- (node) => node.kind === "text" ? Array.from({ length: node.text.length }, (_, i) => _chunkND5XJVK2cjs.text.call(void 0, node.text[i], node.marks)) : [node]
239
+ (node) => node.kind === "text" ? Array.from({ length: node.text.length }, (_, i) => _chunkBTBHHBVRcjs.text.call(void 0, node.text[i], node.marks)) : [node]
341
240
  );
342
241
  function changedSpan(before, after) {
343
242
  const a = units(before);
344
243
  const b = units(after);
345
244
  let start = 0;
346
- while (start < a.length && start < b.length && _chunkND5XJVK2cjs.equalNode.call(void 0, a[start], b[start])) start += 1;
245
+ while (start < a.length && start < b.length && _chunkBTBHHBVRcjs.equalNode.call(void 0, a[start], b[start])) start += 1;
347
246
  let end = 0;
348
247
  const shared = Math.min(a.length, b.length) - start;
349
- while (end < shared && _chunkND5XJVK2cjs.equalNode.call(void 0, a[a.length - 1 - end], b[b.length - 1 - end])) end += 1;
350
- return { from: start, to: _chunkND5XJVK2cjs.inlineLength.call(void 0, before) - end, slice: _chunkND5XJVK2cjs.sliceInline.call(void 0, after, start, _chunkND5XJVK2cjs.inlineLength.call(void 0, after) - end) };
248
+ while (end < shared && _chunkBTBHHBVRcjs.equalNode.call(void 0, a[a.length - 1 - end], b[b.length - 1 - end])) end += 1;
249
+ return { from: start, to: _chunkBTBHHBVRcjs.inlineLength.call(void 0, before) - end, slice: _chunkBTBHHBVRcjs.sliceInline.call(void 0, after, start, _chunkBTBHHBVRcjs.inlineLength.call(void 0, after) - end) };
351
250
  }
352
251
 
353
252
  // src/yjs/plain.ts
@@ -361,7 +260,7 @@ function isPlain({ span, regions }) {
361
260
  return span.length === end;
362
261
  }
363
262
  function rewritten(entry, block, map = entry.map) {
364
- const next = _chunkE75EHRPAcjs.cleanEntry.call(void 0, block, map);
263
+ const next = _chunkMLRAVUFGcjs.cleanEntry.call(void 0, block, map);
365
264
  next.copies.push(...entry.copies);
366
265
  for (const copy of next.copies) copy.copyOf = next;
367
266
  return next;
@@ -369,8 +268,8 @@ function rewritten(entry, block, map = entry.map) {
369
268
  function crossesStray(layout, index) {
370
269
  const { read, leading, unread } = layout.strays;
371
270
  return unread || read.some((seg) => {
372
- const region2 = _chunkE75EHRPAcjs.indexOf.call(void 0, layout, seg.region.entry.span);
373
- return leading.has(seg) ? index <= region2 : region2 < index && index <= _chunkE75EHRPAcjs.indexOf.call(void 0, layout, seg.host);
271
+ const region2 = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, seg.region.entry.span);
272
+ return leading.has(seg) ? index <= region2 : region2 < index && index <= _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, seg.host);
374
273
  });
375
274
  }
376
275
 
@@ -378,11 +277,11 @@ function crossesStray(layout, index) {
378
277
  function insertBlocks(shared, next, blocks) {
379
278
  const { layout, text: text2 } = shared;
380
279
  const span = next === null ? null : layout.entries.get(next).span;
381
- const index = span === null ? layout.spans.length : _chunkE75EHRPAcjs.indexOf.call(void 0, layout, span);
280
+ const index = span === null ? layout.spans.length : _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, span);
382
281
  const crosses = blocks.some((block) => Object.keys(block.regions).length > 0) && crossesStray(layout, index);
383
- const maps = writeBlocks(text2, span === null ? _chunkE75EHRPAcjs.textLength.call(void 0, layout) : _chunkE75EHRPAcjs.spanStart.call(void 0, layout, span), blocks);
282
+ const maps = _chunkMLRAVUFGcjs.writeBlocks.call(void 0, text2, span === null ? _chunkMLRAVUFGcjs.textLength.call(void 0, layout) : _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span), blocks);
384
283
  if (crosses) reread(shared);
385
- else _chunkE75EHRPAcjs.placeEntries.call(void 0, layout, index, 0, blocks.map((block, i) => _chunkE75EHRPAcjs.cleanEntry.call(void 0, block, maps[i])));
284
+ else _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, index, 0, blocks.map((block, i) => _chunkMLRAVUFGcjs.cleanEntry.call(void 0, block, maps[i])));
386
285
  }
387
286
  function ownParts(entry, span) {
388
287
  const parts = [];
@@ -397,15 +296,15 @@ function ownParts(entry, span) {
397
296
  }
398
297
  function dropSpans(shared, spans) {
399
298
  const { layout, text: text2 } = shared;
400
- for (const span of [...spans].sort((a, b) => _chunkE75EHRPAcjs.indexOf.call(void 0, layout, b) - _chunkE75EHRPAcjs.indexOf.call(void 0, layout, a))) {
401
- const at = _chunkE75EHRPAcjs.indexOf.call(void 0, layout, span);
402
- deleteText(text2, _chunkE75EHRPAcjs.spanStart.call(void 0, layout, span), span.length);
403
- _chunkE75EHRPAcjs.placeEntries.call(void 0, layout, at, 1, []);
299
+ for (const span of [...spans].sort((a, b) => _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, b) - _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, a))) {
300
+ const at = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, span);
301
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span), span.length);
302
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, at, 1, []);
404
303
  }
405
304
  }
406
305
  function unreadBefore(layout, span) {
407
306
  const before = [];
408
- for (let at = _chunkE75EHRPAcjs.indexOf.call(void 0, layout, span) - 1; at > 0 && layout.spans[at].entry === null; at--) {
307
+ for (let at = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, span) - 1; at > 0 && layout.spans[at].entry === null; at--) {
409
308
  before.push(layout.spans[at]);
410
309
  }
411
310
  return before;
@@ -417,25 +316,22 @@ function removeBlock(shared, id) {
417
316
  if (isPlain(entry)) return dropSpans(shared, [.../* @__PURE__ */ new Set([entry.span, ...unread])]);
418
317
  dropSpans(shared, [...new Set(unread)]);
419
318
  const ranges = [];
420
- const start = _chunkE75EHRPAcjs.spanStart.call(void 0, layout, entry.span);
319
+ const start = _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, entry.span);
421
320
  ranges.push(...ownParts(entry, entry.span).map(([at, length]) => [start + at, length]));
422
321
  for (const seg of entry.regions.flatMap((region2) => region2.segs)) {
423
- if (seg.host !== entry.span) ranges.push([_chunkE75EHRPAcjs.spanStart.call(void 0, layout, seg.host) + seg.at, seg.length]);
322
+ if (seg.host !== entry.span) ranges.push([_chunkMLRAVUFGcjs.spanStart.call(void 0, layout, seg.host) + seg.at, seg.length]);
424
323
  }
425
- for (const [at, length] of ranges.sort((a, b) => b[0] - a[0])) if (length > 0) deleteText(text2, at, length);
324
+ for (const [at, length] of ranges.sort((a, b) => b[0] - a[0])) if (length > 0) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, length);
426
325
  reread(shared);
427
326
  }
428
327
 
429
328
  // src/yjs/sync-block.ts
430
329
  function syncAttrs(map, before, after) {
431
- const current = map.get("attrs");
432
- if (!(current instanceof Y3.Map)) {
433
- map.set("attrs", new Y3.Map(definedEntries(after)));
434
- return;
435
- }
436
- const kept = new Map(definedEntries(after));
330
+ const current = _chunkMLRAVUFGcjs.attrsMap.call(void 0, map, after);
331
+ if (current === null) return;
332
+ const kept = new Map(_chunkMLRAVUFGcjs.definedEntries.call(void 0, after));
437
333
  for (const key of [...current.keys()]) if (!kept.has(key)) current.delete(key);
438
- for (const [key, value] of kept) if (!_chunk2QCRZ7OLcjs.sameValue.call(void 0, before[key], value)) current.set(key, value);
334
+ for (const [key, value] of kept) if (!_chunkXX5FTPJRcjs.sameValue.call(void 0, before[key], value)) current.set(key, value);
439
335
  }
440
336
  function keptNames(before, after) {
441
337
  const kept = /* @__PURE__ */ new Set();
@@ -451,33 +347,33 @@ function keptNames(before, after) {
451
347
  function syncRegions(shared, entry, before, after) {
452
348
  const { text: text2, layout } = shared;
453
349
  const names = Object.keys(after.regions);
454
- const kept = keptNames(Object.keys(before.regions), names);
455
- const queue = Object.entries(before.regions);
456
- let at = _chunkE75EHRPAcjs.spanStart.call(void 0, layout, entry.span) + 1;
350
+ const queue = entry.regions.map(({ name }) => [name, before.regions[name]]);
351
+ const kept = keptNames(queue.map(([name]) => name), names);
352
+ let at = _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, entry.span) + 1;
457
353
  const dropGone = () => {
458
- while (queue.length > 0 && !kept.has(queue[0][0])) deleteText(text2, at, 1 + _chunkND5XJVK2cjs.inlineLength.call(void 0, queue.shift()[1]));
354
+ while (queue.length > 0 && !kept.has(queue[0][0])) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, 1 + _chunkBTBHHBVRcjs.inlineLength.call(void 0, queue.shift()[1]));
459
355
  };
460
356
  for (const name of names) {
461
357
  dropGone();
462
358
  const inline = after.regions[name];
463
359
  if (kept.has(name)) {
464
360
  const { from, to, slice } = changedSpan(queue.shift()[1], inline);
465
- if (to > from) deleteText(text2, at + 1 + from, to - from);
466
- insertInline(text2, at + 1 + from, slice);
361
+ if (to > from) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at + 1 + from, to - from);
362
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, text2, at + 1 + from, slice);
467
363
  } else {
468
- text2.insertEmbed(at, regionStart(name), {});
469
- insertInline(text2, at + 1, inline);
364
+ text2.insertEmbed(at, _chunkMLRAVUFGcjs.regionStart.call(void 0, name), {});
365
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, text2, at + 1, inline);
470
366
  }
471
- at += 1 + _chunkND5XJVK2cjs.inlineLength.call(void 0, inline);
367
+ at += 1 + _chunkBTBHHBVRcjs.inlineLength.call(void 0, inline);
472
368
  }
473
369
  dropGone();
474
- _chunkE75EHRPAcjs.placeEntries.call(void 0, layout, _chunkE75EHRPAcjs.indexOf.call(void 0, layout, entry.span), 1, [rewritten(entry, after)]);
370
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, entry.span), 1, [rewritten(entry, after)]);
475
371
  }
476
372
  function syncBlock(shared, before, after, next) {
477
373
  if (before === after) return;
478
374
  const entry = shared.layout.entries.get(before.id);
479
375
  const plain = isPlain(entry);
480
- if (!plain && !_chunk2QCRZ7OLcjs.sameValue.call(void 0, Object.keys(before.regions), Object.keys(after.regions))) {
376
+ if (!plain && !_chunkXX5FTPJRcjs.sameValue.call(void 0, Object.keys(before.regions), Object.keys(after.regions))) {
481
377
  removeBlock(shared, before.id);
482
378
  insertBlocks(shared, next, [after]);
483
379
  return;
@@ -487,16 +383,16 @@ function syncBlock(shared, before, after, next) {
487
383
  syncAttrs(entry.map, before.attrs, after.attrs);
488
384
  if (plain) {
489
385
  const gains = Object.keys(before.regions).length === 0 && Object.keys(after.regions).length > 0;
490
- const crosses = gains && crossesStray(shared.layout, _chunkE75EHRPAcjs.indexOf.call(void 0, shared.layout, entry.span));
386
+ const crosses = gains && crossesStray(shared.layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, shared.layout, entry.span));
491
387
  syncRegions(shared, entry, before, after);
492
388
  if (crosses) reread(shared);
493
389
  return;
494
390
  }
495
391
  for (const name of entry.regions.map((region2) => region2.name)) {
496
392
  const [was, now] = [before.regions[name], after.regions[name]];
497
- if (_chunkND5XJVK2cjs.equalInline.call(void 0, was, now)) continue;
393
+ if (_chunkBTBHHBVRcjs.equalInline.call(void 0, was, now)) continue;
498
394
  const { from, to, slice } = changedSpan(was, now);
499
- const region2 = _chunkE75EHRPAcjs.regionOf.call(void 0, shared.layout, before.id, name);
395
+ const region2 = _chunkMLRAVUFGcjs.regionOf.call(void 0, shared.layout, before.id, name);
500
396
  deleteContent(shared, region2, from, to);
501
397
  insertContent(shared, region2, from, slice);
502
398
  }
@@ -530,18 +426,18 @@ var held = (region2) => region2 !== void 0 && region2.segs.length > 0;
530
426
  function writeSplit(shared, after, { block, region: region2, offset, created }) {
531
427
  const { layout, text: text2 } = shared;
532
428
  const entry = layout.entries.get(block);
533
- const tail = _chunkND5XJVK2cjs.blockById.call(void 0, after, created.id);
429
+ const tail = _chunkBTBHHBVRcjs.blockById.call(void 0, after, created.id);
534
430
  const last = entry.regions[entry.regions.length - 1];
535
431
  if (!held(last) || last.name !== region2 || Object.keys(tail.regions).at(-1) !== created.region) return false;
536
- const { seg, rel } = _chunkE75EHRPAcjs.pointOf.call(void 0, last, offset);
537
- const map = markerOf(tail);
538
- writeBlock(text2, _chunkE75EHRPAcjs.spanStart.call(void 0, layout, seg.host) + rel, tail, map, created.region);
432
+ const { seg, rel } = _chunkMLRAVUFGcjs.pointOf.call(void 0, last, offset);
433
+ const map = _chunkMLRAVUFGcjs.markerOf.call(void 0, tail);
434
+ _chunkMLRAVUFGcjs.writeBlock.call(void 0, text2, _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, seg.host) + rel, tail, map, created.region);
539
435
  if (!isPlain(entry)) {
540
436
  reread(shared);
541
437
  return true;
542
438
  }
543
- const head = rewritten(entry, _chunkND5XJVK2cjs.blockById.call(void 0, after, block));
544
- _chunkE75EHRPAcjs.placeEntries.call(void 0, layout, _chunkE75EHRPAcjs.indexOf.call(void 0, layout, entry.span), 1, [head, _chunkE75EHRPAcjs.cleanEntry.call(void 0, tail, map)]);
439
+ const head = rewritten(entry, _chunkBTBHHBVRcjs.blockById.call(void 0, after, block));
440
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, entry.span), 1, [head, _chunkMLRAVUFGcjs.cleanEntry.call(void 0, tail, map)]);
545
441
  return true;
546
442
  }
547
443
  function writeJoin(shared, after, join2) {
@@ -550,28 +446,28 @@ function writeJoin(shared, after, join2) {
550
446
  const [into, from] = [target, source].map((id) => layout.entries.get(id));
551
447
  const [end, start] = [into.regions.at(-1), from.regions[0]];
552
448
  if (!held(end) || !held(start) || end.name !== targetRegion || start.name !== sourceRegion) return false;
553
- const between = layout.spans.slice(_chunkE75EHRPAcjs.indexOf.call(void 0, layout, into.span) + 1, _chunkE75EHRPAcjs.indexOf.call(void 0, layout, from.span));
449
+ const between = layout.spans.slice(_chunkMLRAVUFGcjs.indexOf.call(void 0, layout, into.span) + 1, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, from.span));
554
450
  dropSpans(shared, [...from.copies, ...between]);
555
- const at = _chunkE75EHRPAcjs.spanStart.call(void 0, layout, from.span);
451
+ const at = _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, from.span);
556
452
  if (!isPlain(into) || !isPlain(from)) {
557
453
  const own = start.segs.find((seg) => seg.host === from.span);
558
- deleteText(text2, at + own.at - 1, 1);
559
- deleteText(text2, at, 1);
454
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at + own.at - 1, 1);
455
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, 1);
560
456
  reread(shared);
561
457
  return true;
562
458
  }
563
- const index = _chunkE75EHRPAcjs.indexOf.call(void 0, layout, into.span);
459
+ const index = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, into.span);
564
460
  const moved = from.regions[0].segs[0].length;
565
461
  const rest = from.span.length - 2 - moved;
566
- if (rest > 0) deleteText(text2, at + 2 + moved, rest);
567
- deleteText(text2, at, 2);
568
- _chunkE75EHRPAcjs.placeEntries.call(void 0, layout, index, 2, [rewritten(into, _chunkND5XJVK2cjs.blockById.call(void 0, after, target))]);
462
+ if (rest > 0) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at + 2 + moved, rest);
463
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, 2);
464
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, index, 2, [rewritten(into, _chunkBTBHHBVRcjs.blockById.call(void 0, after, target))]);
569
465
  return true;
570
466
  }
571
467
 
572
468
  // src/yjs/local-to-yjs.ts
573
- var region = ({ shared, params }) => _chunkE75EHRPAcjs.regionOf.call(void 0, shared.layout, params.block, params.region);
574
- var following = (doc, id) => _nullishCoalesce(_optionalChain([doc, 'access', _10 => _10.blocks, 'access', _11 => _11[doc.index.get(id) + 1], 'optionalAccess', _12 => _12.id]), () => ( null));
469
+ var region = ({ shared, params }) => _chunkMLRAVUFGcjs.regionOf.call(void 0, shared.layout, params.block, params.region);
470
+ var following = (doc, id) => _nullishCoalesce(_optionalChain([doc, 'access', _9 => _9.blocks, 'access', _10 => _10[doc.index.get(id) + 1], 'optionalAccess', _11 => _11.id]), () => ( null));
575
471
  function replaceInline(context) {
576
472
  const { from, to, slice } = context.params;
577
473
  const target = region(context);
@@ -581,20 +477,20 @@ function replaceInline(context) {
581
477
  function format(context, keys) {
582
478
  const { block, region: name, from, to } = context.params;
583
479
  if (to === from) return;
584
- const inline = _chunkND5XJVK2cjs.blockById.call(void 0, context.before, block).regions[name];
585
- formatContent(context.shared, region(context), from, to, keys(_chunkND5XJVK2cjs.sliceInline.call(void 0, inline, from, to)));
480
+ const inline = _chunkBTBHHBVRcjs.blockById.call(void 0, context.before, block).regions[name];
481
+ formatContent(context.shared, region(context), from, to, keys(_chunkBTBHHBVRcjs.sliceInline.call(void 0, inline, from, to)));
586
482
  }
587
483
  function removedKeys(mark, inline) {
588
- if (typeof mark !== "string") return { [markAttribute(mark)[0]]: null };
484
+ if (typeof mark !== "string") return { [_chunkMLRAVUFGcjs.markAttribute.call(void 0, mark)[0]]: null };
589
485
  const marks = inline.flatMap((node) => node.marks.filter((candidate) => candidate.type === mark));
590
- return Object.fromEntries(marks.map((found) => [markAttribute(found)[0], null]));
486
+ return Object.fromEntries(marks.map((found) => [_chunkMLRAVUFGcjs.markAttribute.call(void 0, found)[0], null]));
591
487
  }
592
488
  function setAttrs({ shared, after, params }) {
593
489
  const id = params.block;
594
490
  const { map } = shared.layout.entries.get(id);
595
- const next = _chunkND5XJVK2cjs.blockById.call(void 0, after, id).attrs;
596
- const attrs = map.get("attrs");
597
- if (!(attrs instanceof Y4.Map)) return void map.set("attrs", new Y4.Map(definedEntries(next)));
491
+ const next = _chunkBTBHHBVRcjs.blockById.call(void 0, after, id).attrs;
492
+ const attrs = _chunkMLRAVUFGcjs.attrsMap.call(void 0, map, next);
493
+ if (attrs === null) return;
598
494
  for (const key of Object.keys(params.patch)) {
599
495
  if (next[key] === void 0) attrs.delete(key);
600
496
  else attrs.set(key, next[key]);
@@ -605,15 +501,15 @@ function moveBlocks({ shared, before, after, params }) {
605
501
  if (count === 0 || from === to) return;
606
502
  const moved = before.blocks.slice(from, from + count);
607
503
  for (const block of moved) removeBlock(shared, block.id);
608
- insertBlocks(shared, _nullishCoalesce(_optionalChain([after, 'access', _13 => _13.blocks, 'access', _14 => _14[to + count], 'optionalAccess', _15 => _15.id]), () => ( null)), moved);
504
+ insertBlocks(shared, _nullishCoalesce(_optionalChain([after, 'access', _12 => _12.blocks, 'access', _13 => _13[to + count], 'optionalAccess', _14 => _14.id]), () => ( null)), moved);
609
505
  }
610
506
  var WRITERS = {
611
507
  replaceInline,
612
- addMark: (context) => format(context, () => Object.fromEntries([markAttribute(context.params.mark)])),
508
+ addMark: (context) => format(context, () => Object.fromEntries([_chunkMLRAVUFGcjs.markAttribute.call(void 0, context.params.mark)])),
613
509
  removeMark: (context) => format(context, (inline) => removedKeys(context.params.mark, inline)),
614
510
  setAttrs,
615
511
  setIndent: ({ shared, params }) => shared.layout.entries.get(params.block).map.set("indent", params.indent),
616
- insertBlocks: ({ shared, before, params }) => insertBlocks(shared, _nullishCoalesce(_optionalChain([before, 'access', _16 => _16.blocks, 'access', _17 => _17[params.index], 'optionalAccess', _18 => _18.id]), () => ( null)), params.blocks),
512
+ insertBlocks: ({ shared, before, params }) => insertBlocks(shared, _nullishCoalesce(_optionalChain([before, 'access', _15 => _15.blocks, 'access', _16 => _16[params.index], 'optionalAccess', _17 => _17.id]), () => ( null)), params.blocks),
617
513
  removeBlocks: ({ shared, before, params }) => {
618
514
  const { index, count } = params;
619
515
  for (const block of before.blocks.slice(index, index + count)) removeBlock(shared, block.id);
@@ -631,7 +527,7 @@ var WRITERS = {
631
527
  },
632
528
  replaceBlock: ({ shared, before, params }) => {
633
529
  const block = params.block;
634
- syncBlock(shared, _chunkND5XJVK2cjs.blockById.call(void 0, before, block.id), block, following(before, block.id));
530
+ syncBlock(shared, _chunkBTBHHBVRcjs.blockById.call(void 0, before, block.id), block, following(before, block.id));
635
531
  }
636
532
  };
637
533
  function writeLocalSteps(shared, steps, docs) {
@@ -643,203 +539,89 @@ function writeLocalSteps(shared, steps, docs) {
643
539
  });
644
540
  }
645
541
 
646
- // src/yjs/own-change.ts
647
- function ownChange(editor, steps, hint) {
648
- const tr = editor.createTransaction().setOrigin("history").setMeta("addToHistory", false);
649
- for (const step of steps) tr.step(step);
650
- if (hint && _chunkPZ4GT5JOcjs.sameSelection.call(void 0, _chunkPZ4GT5JOcjs.validateSelection.call(void 0, tr.doc, editor.schema, hint), hint)) tr.setSelection(hint);
651
- return tr;
652
- }
653
-
654
542
  // src/yjs/seed.ts
655
543
  function seedOrLoad(editor, text2, { origin, seed, required }) {
656
544
  const { blocks } = editor.state.doc;
657
545
  if (text2.length === 0 && seed === "if-empty") {
658
546
  let maps = [];
659
- text2.doc.transact(() => maps = writeBlocks(text2, 0, blocks), origin);
660
- const entries = blocks.map((block, i) => _chunkE75EHRPAcjs.cleanEntry.call(void 0, block, maps[i]));
661
- const spans = [_chunkE75EHRPAcjs.emptySpan.call(void 0, ), ...entries.map((entry) => entry.span)];
662
- return _chunkE75EHRPAcjs.createLayout.call(void 0, spans, new Map(entries.map((entry) => [entry.id, entry])), true);
547
+ text2.doc.transact(() => maps = _chunkMLRAVUFGcjs.writeBlocks.call(void 0, text2, 0, blocks), origin);
548
+ const entries = blocks.map((block, i) => _chunkMLRAVUFGcjs.cleanEntry.call(void 0, block, maps[i]));
549
+ const spans = [_chunkMLRAVUFGcjs.emptySpan.call(void 0, ), ...entries.map((entry) => entry.span)];
550
+ return _chunkMLRAVUFGcjs.createLayout.call(void 0, spans, new Map(entries.map((entry) => [entry.id, entry])), true);
663
551
  }
664
552
  const { doc, layout } = readShared(text2, required);
665
- if (!_chunkPZ4GT5JOcjs.sameDoc.call(void 0, doc, editor.state.doc)) applyRemote(editor, [_chunkPZ4GT5JOcjs.replaceDocStep.call(void 0, doc)]);
553
+ if (!_chunkHOIDJEVIcjs.sameDoc.call(void 0, doc, editor.state.doc)) _chunkMLRAVUFGcjs.applyRemote.call(void 0, editor, [_chunkHOIDJEVIcjs.replaceDocStep.call(void 0, doc)]);
666
554
  return layout;
667
555
  }
668
556
 
669
- // src/yjs/undo-history.ts
670
-
671
- var GROUP_DELAY = 500;
672
- var SELECTION = "selection";
673
- function groupOf(tr) {
674
- if (tr.getMeta("closeHistory") === true) return null;
675
- const named = tr.getMeta(_chunkPZ4GT5JOcjs.HISTORY_GROUP);
676
- if (named !== void 0) return named;
677
- const before = tr.before.selection;
678
- if (tr.origin !== "input" || _optionalChain([before, 'optionalAccess', _19 => _19.kind]) !== "text") return null;
679
- return JSON.stringify([before.head.block, before.head.region]);
680
- }
681
- function undoHistory(text2, origin) {
682
- const manager = new Y5.UndoManager(text2, { trackedOrigins: /* @__PURE__ */ new Set([origin]), captureTimeout: Infinity });
683
- let group = null;
684
- let time = 0;
685
- let before = null;
686
- let hint = null;
687
- manager.on("stack-item-added", ({ stackItem }) => stackItem.meta.set(SELECTION, before));
688
- return {
689
- manager,
690
- record(tr) {
691
- if (!tr.docChanged) {
692
- if (tr.getMeta("closeHistory") === true) group = null;
693
- return;
694
- }
695
- const next = groupOf(tr);
696
- if (next === null || next !== group || tr.time - time >= GROUP_DELAY) manager.stopCapturing();
697
- group = next;
698
- time = tr.time;
699
- before = tr.before.selection;
700
- },
701
- travel(direction, editor) {
702
- const stack = direction === "undo" ? manager.undoStack : manager.redoStack;
703
- const item = stack.at(-1);
704
- if (item === void 0) return false;
705
- hint = _nullishCoalesce(item.meta.get(SELECTION), () => ( null));
706
- before = editor.state.selection;
707
- group = null;
708
- try {
709
- return (direction === "undo" ? manager.undo() : manager.redo()) !== null;
710
- } finally {
711
- hint = null;
712
- }
713
- },
714
- hint: () => hint,
715
- destroy: () => manager.destroy()
716
- };
717
- }
718
-
719
557
  // src/yjs/read-split-join.ts
720
558
 
721
559
  var bare = (op) => op === void 0 || op.attributes === void 0;
722
560
  function split(layout, delta, required) {
723
- const [at, ops] = _optionalChain([delta, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.retain]) === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
724
- const map = _optionalChain([ops, 'access', _22 => _22[0], 'optionalAccess', _23 => _23.insert]);
725
- const name = regionNameOf(_optionalChain([ops, 'access', _24 => _24[1], 'optionalAccess', _25 => _25.insert]));
726
- if (ops.length !== 2 || !(map instanceof Y6.Map) || name === null || !bare(delta[0])) return null;
727
- const marker = readMarker(map);
728
- const span = _chunkE75EHRPAcjs.spanAt.call(void 0, layout, at);
561
+ const [at, ops] = _optionalChain([delta, 'access', _18 => _18[0], 'optionalAccess', _19 => _19.retain]) === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
562
+ const map = _optionalChain([ops, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.insert]);
563
+ const name = _chunkMLRAVUFGcjs.regionNameOf.call(void 0, _optionalChain([ops, 'access', _22 => _22[1], 'optionalAccess', _23 => _23.insert]));
564
+ if (ops.length !== 2 || !(map instanceof Y2.Map) || name === null || !bare(delta[0])) return null;
565
+ const marker = _chunkMLRAVUFGcjs.readMarker.call(void 0, map);
566
+ const span = _chunkMLRAVUFGcjs.spanAt.call(void 0, layout, at);
729
567
  if (span.entry === null || !isPlain(span.entry)) return null;
730
568
  const region2 = span.entry.regions.at(-1);
731
- const seg = _optionalChain([region2, 'optionalAccess', _26 => _26.segs, 'access', _27 => _27[0]]);
732
- const rel = at - _chunkE75EHRPAcjs.spanStart.call(void 0, layout, span);
733
- if (marker === null || seg === void 0 || rel < seg.at || rel > seg.at + seg.length) return null;
569
+ const seg = _optionalChain([region2, 'optionalAccess', _24 => _24.segs, 'access', _25 => _25[0]]);
570
+ const rel = at - _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span);
571
+ if (marker === null || layout.entries.has(marker.id) || seg === void 0) return null;
572
+ if (rel < seg.at || rel > seg.at + seg.length) return null;
734
573
  if (required(marker.type).some((needed) => needed !== name)) return null;
735
574
  const { id, type, indent, attrs } = marker;
736
- const created = { id, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _28 => _28.toJSON, 'call', _29 => _29()]), () => ( {})), region: name, regions: {} };
737
- return { step: _chunkPZ4GT5JOcjs.splitBlockStep.call(void 0, span.entry.id, region2.name, _chunkE75EHRPAcjs.offsetIn.call(void 0, seg, rel), created), map };
575
+ const created = { id, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _26 => _26.toJSON, 'call', _27 => _27()]), () => ( {})), region: name, regions: {} };
576
+ return { step: _chunkHOIDJEVIcjs.splitBlockStep.call(void 0, span.entry.id, region2.name, _chunkMLRAVUFGcjs.offsetIn.call(void 0, seg, rel), created), map };
738
577
  }
739
578
  function join(layout, delta) {
740
- const [at, ops] = _optionalChain([delta, 'access', _30 => _30[0], 'optionalAccess', _31 => _31.retain]) === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
579
+ const [at, ops] = _optionalChain([delta, 'access', _28 => _28[0], 'optionalAccess', _29 => _29.retain]) === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
741
580
  if (ops.length !== 1 || ops[0].delete !== 2 || !bare(delta[0])) return null;
742
- const span = _chunkE75EHRPAcjs.spanAt.call(void 0, layout, at, true);
581
+ const span = _chunkMLRAVUFGcjs.spanAt.call(void 0, layout, at, true);
743
582
  const source = span.entry;
744
- const target = _nullishCoalesce(_optionalChain([layout, 'access', _32 => _32.spans, 'access', _33 => _33[span.index - 1], 'optionalAccess', _34 => _34.entry]), () => ( null));
745
- if (_chunkE75EHRPAcjs.spanStart.call(void 0, layout, span) !== at || source === null || target === null) return null;
583
+ const target = _nullishCoalesce(_optionalChain([layout, 'access', _30 => _30.spans, 'access', _31 => _31[span.index - 1], 'optionalAccess', _32 => _32.entry]), () => ( null));
584
+ if (_chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span) !== at || source === null || target === null) return null;
746
585
  if (source.regions.length !== 1 || target.regions.length === 0 || source.copies.length > 0) return null;
747
586
  if (!isPlain(source) || !isPlain(target)) return null;
748
- return _chunkPZ4GT5JOcjs.joinBlocksStep.call(void 0, target.id, target.regions.at(-1).name, source.id, source.regions[0].name);
587
+ return _chunkHOIDJEVIcjs.joinBlocksStep.call(void 0, target.id, target.regions.at(-1).name, source.id, source.regions[0].name);
749
588
  }
750
589
  function splitOrJoin(layout, delta, doc, required) {
751
590
  const found = split(layout, delta, required);
752
- const step = _nullishCoalesce(_optionalChain([found, 'optionalAccess', _35 => _35.step]), () => ( join(layout, delta)));
591
+ const step = _nullishCoalesce(_optionalChain([found, 'optionalAccess', _33 => _33.step]), () => ( join(layout, delta)));
753
592
  if (step === null) return null;
754
593
  const after = step.apply(doc).doc;
755
594
  const { block, target, created } = step.toJSON();
756
595
  const kept = layout.entries.get(_nullishCoalesce(block, () => ( target)));
757
- const entries = [rewritten(kept, _chunkND5XJVK2cjs.blockById.call(void 0, after, kept.id))];
758
- if (found !== null) entries.push(_chunkE75EHRPAcjs.cleanEntry.call(void 0, _chunkND5XJVK2cjs.blockById.call(void 0, after, created.id), found.map));
759
- _chunkE75EHRPAcjs.placeEntries.call(void 0, layout, _chunkE75EHRPAcjs.indexOf.call(void 0, layout, kept.span), found === null ? 2 : 1, entries);
596
+ const entries = [rewritten(kept, _chunkBTBHHBVRcjs.blockById.call(void 0, after, kept.id))];
597
+ if (found !== null) entries.push(_chunkMLRAVUFGcjs.cleanEntry.call(void 0, _chunkBTBHHBVRcjs.blockById.call(void 0, after, created.id), found.map));
598
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, kept.span), found === null ? 2 : 1, entries);
760
599
  return step;
761
600
  }
762
601
 
763
- // src/yjs/text-steps.ts
764
- function segAt(layout, at, item) {
765
- const span = _chunkE75EHRPAcjs.spanAt.call(void 0, layout, at, item);
766
- const rel = at - _chunkE75EHRPAcjs.spanStart.call(void 0, layout, span);
767
- const seg = span.segs.find((candidate) => candidate.at <= rel && rel <= candidate.at + candidate.length);
768
- return seg === void 0 ? null : { seg, rel };
769
- }
770
- function formatSteps(layout, at, length, attributes) {
771
- const steps = [];
772
- for (let span = _chunkE75EHRPAcjs.spanAt.call(void 0, layout, at, true); ; span = layout.spans[span.index + 1]) {
773
- const start = _chunkE75EHRPAcjs.spanStart.call(void 0, layout, span);
774
- if (start >= at + length) break;
775
- for (const seg of span.segs) {
776
- const from = Math.max(at - start, seg.at);
777
- const to = Math.min(at + length - start, seg.at + seg.length);
778
- if (to <= from) continue;
779
- const { entry, name } = seg.region;
780
- const [first, last] = [_chunkE75EHRPAcjs.offsetIn.call(void 0, seg, from), _chunkE75EHRPAcjs.offsetIn.call(void 0, seg, to)];
781
- for (const [key, value] of Object.entries(attributes)) {
782
- const mark = markFromAttribute(key, _nullishCoalesce(value, () => ( true)));
783
- steps.push((value === null ? _chunkPZ4GT5JOcjs.removeMarkStep : (0, _chunkPZ4GT5JOcjs.addMarkStep))(entry.id, name, first, last, mark));
784
- }
785
- }
786
- if (span.index + 1 >= layout.spans.length) break;
787
- }
788
- return steps;
789
- }
790
- function textSteps(layout, delta) {
791
- const steps = [];
792
- let at = 0;
793
- for (const op of delta) {
794
- if (op.retain !== void 0) {
795
- if (op.attributes !== void 0) steps.push(...formatSteps(layout, at, op.retain, op.attributes));
796
- at += op.retain;
797
- } else if (op.delete !== void 0) {
798
- const found = segAt(layout, at, true);
799
- if (found === null || found.rel + op.delete > found.seg.at + found.seg.length) return null;
800
- const from = _chunkE75EHRPAcjs.offsetIn.call(void 0, found.seg, found.rel);
801
- const { entry, name } = found.seg.region;
802
- steps.push(_chunkPZ4GT5JOcjs.replaceInlineStep.call(void 0, entry.id, name, from, from + op.delete, []));
803
- _chunkE75EHRPAcjs.grow.call(void 0, layout, found.seg, found.rel, -op.delete);
804
- } else {
805
- const found = typeof op.insert === "string" || isAtomEmbed(op.insert) ? segAt(layout, at, false) : null;
806
- if (found === null) return null;
807
- const inline = inlineOfOps([op]);
808
- const from = _chunkE75EHRPAcjs.offsetIn.call(void 0, found.seg, found.rel);
809
- const { entry, name } = found.seg.region;
810
- steps.push(_chunkPZ4GT5JOcjs.replaceInlineStep.call(void 0, entry.id, name, from, from, inline));
811
- _chunkE75EHRPAcjs.grow.call(void 0, layout, found.seg, found.rel, _chunkND5XJVK2cjs.inlineLength.call(void 0, inline));
812
- at += _chunkND5XJVK2cjs.inlineLength.call(void 0, inline);
813
- }
814
- }
815
- return steps;
816
- }
817
-
818
602
  // src/yjs/yjs-to-steps.ts
819
603
  var REREAD = new Error("reread");
820
604
  function markerSteps(shared, event, doc) {
821
605
  const target = event.target;
822
606
  const marker = target.parent === shared.text ? target : target.parent;
823
- const fields = readMarker(marker);
824
- const block = fields === null ? void 0 : _chunkND5XJVK2cjs.blockById.call(void 0, doc, fields.id);
825
- if (block === void 0 || _optionalChain([shared, 'access', _36 => _36.layout, 'access', _37 => _37.entries, 'access', _38 => _38.get, 'call', _39 => _39(block.id), 'optionalAccess', _40 => _40.map]) !== marker) return [];
607
+ const fields = _chunkMLRAVUFGcjs.readMarker.call(void 0, marker);
608
+ const block = fields === null ? void 0 : _chunkBTBHHBVRcjs.blockById.call(void 0, doc, fields.id);
609
+ if (block === void 0 || _optionalChain([shared, 'access', _34 => _34.layout, 'access', _35 => _35.entries, 'access', _36 => _36.get, 'call', _37 => _37(block.id), 'optionalAccess', _38 => _38.map]) !== marker) return [];
826
610
  const keys = [...event.keysChanged];
827
611
  if (target !== marker) {
828
612
  if (fields.attrs !== target) return [];
829
- return [_chunkPZ4GT5JOcjs.setAttrsStep.call(void 0, block.id, Object.fromEntries(keys.map((key) => [key, target.get(key)])))];
613
+ return [_chunkHOIDJEVIcjs.setAttrsStep.call(void 0, block.id, Object.fromEntries(keys.map((key) => [key, target.get(key)])))];
830
614
  }
831
- if (keys.includes("id")) throw REREAD;
832
- if (keys.every((key) => key === "indent")) return [_chunkPZ4GT5JOcjs.setIndentStep.call(void 0, block.id, fields.indent)];
833
- const { type, indent, attrs } = fields;
834
- const empty = shared.layout.entries.get(block.id).regions.some((region2) => region2.segs.length === 0);
835
- if (empty || shared.required(type).some((name) => !Object.hasOwn(block.regions, name))) throw REREAD;
836
- return [_chunkPZ4GT5JOcjs.replaceBlockStep.call(void 0, { ...block, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _41 => _41.toJSON, 'call', _42 => _42()]), () => ( {})) })];
615
+ if (keys.includes("id") || keys.includes("type")) throw REREAD;
616
+ const { indent, attrs } = fields;
617
+ if (keys.every((key) => key === "indent")) return [_chunkHOIDJEVIcjs.setIndentStep.call(void 0, block.id, indent)];
618
+ return [_chunkHOIDJEVIcjs.replaceBlockStep.call(void 0, { ...block, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _39 => _39.toJSON, 'call', _40 => _40()]), () => ( {})) })];
837
619
  }
838
620
  function contentSteps(shared, events, doc) {
839
621
  const textEvent = events.find((event) => event.target === shared.text);
840
- const delta = _nullishCoalesce(_optionalChain([textEvent, 'optionalAccess', _43 => _43.delta]), () => ( []));
622
+ const delta = _nullishCoalesce(_optionalChain([textEvent, 'optionalAccess', _41 => _41.delta]), () => ( []));
841
623
  const structure = splitOrJoin(shared.layout, delta, doc, shared.required);
842
- const steps = structure === null ? textSteps(shared.layout, delta) : [structure];
624
+ const steps = structure === null ? _chunkMLRAVUFGcjs.textSteps.call(void 0, shared.layout, delta) : [structure];
843
625
  if (steps === null) throw REREAD;
844
626
  let current = steps.reduce((changed, step) => step.apply(changed).doc, doc);
845
627
  for (const event of events) {
@@ -854,52 +636,55 @@ function contentSteps(shared, events, doc) {
854
636
  function readRemote(shared, events, doc) {
855
637
  try {
856
638
  return { steps: contentSteps(shared, events, doc), structural: false };
857
- } catch (e) {
639
+ } catch (error) {
858
640
  const read = readShared(shared.text, shared.required);
859
641
  shared.layout = read.layout;
860
642
  const blocks = read.doc.blocks.map((block) => {
861
- const held2 = _chunkND5XJVK2cjs.blockById.call(void 0, doc, block.id);
862
- return held2 !== void 0 && _chunk2QCRZ7OLcjs.sameValue.call(void 0, held2, block) ? held2 : block;
643
+ const held2 = _chunkBTBHHBVRcjs.blockById.call(void 0, doc, block.id);
644
+ return held2 !== void 0 && _chunkXX5FTPJRcjs.sameValue.call(void 0, held2, block) ? held2 : block;
863
645
  });
864
- const next = _chunkND5XJVK2cjs.createDoc.call(void 0, blocks);
865
- return { steps: _chunkPZ4GT5JOcjs.sameDoc.call(void 0, next, doc) ? [] : [_chunkPZ4GT5JOcjs.replaceDocStep.call(void 0, next)], structural: true };
646
+ const next = _chunkBTBHHBVRcjs.createDoc.call(void 0, blocks);
647
+ const failed = error === REREAD ? void 0 : error;
648
+ return { steps: _chunkHOIDJEVIcjs.sameDoc.call(void 0, next, doc) ? [] : [_chunkHOIDJEVIcjs.replaceDocStep.call(void 0, next)], structural: true, failed };
866
649
  }
867
650
  }
868
651
 
869
652
  // src/yjs/binding.ts
870
- function bind(editor, text2, { origins, seed }) {
653
+ function bind(editor, text2, options) {
654
+ const { origins, seed, onError } = options;
871
655
  const doc = text2.doc;
872
656
  const required = requiredRegions(editor.state.schema);
873
657
  const layout = seedOrLoad(editor, text2, { origin: origins.local, seed, required });
658
+ const history = options.history();
874
659
  const shared = { text: text2, layout, stale: false, required };
875
- const history = undoHistory(text2, origins.local);
876
660
  const ours = (origin) => origin === origins.local || origin === origins.untracked;
877
661
  let held2 = null;
878
662
  const written = /* @__PURE__ */ new WeakSet();
879
663
  const hold = (transaction) => {
880
- if (!ours(transaction.origin)) held2 = _chunkE75EHRPAcjs.holdSelection.call(void 0, text2, shared.layout, editor.state.selection);
664
+ if (!ours(transaction.origin)) held2 = _chunkMLRAVUFGcjs.holdSelection.call(void 0, text2, shared.layout, editor.state.selection);
881
665
  };
882
666
  const observer = (events, transaction) => {
883
667
  if (ours(transaction.origin)) return;
884
- const { steps, structural } = readRemote(shared, events, editor.state.doc);
885
- if (steps.length === 0) return;
886
- if (transaction.origin !== history.manager)
887
- return applyRemote(editor, steps, structural ? _chunkE75EHRPAcjs.restoreSelection.call(void 0, text2, shared.layout, held2) : null);
888
- const tr = ownChange(editor, steps, history.hint());
889
- written.add(tr);
890
- editor.dispatch(tr);
668
+ const { steps, structural, failed } = readRemote(shared, events, editor.state.doc);
669
+ if (steps.length > 0 && transaction.origin !== history.manager) {
670
+ _chunkMLRAVUFGcjs.applyRemote.call(void 0, editor, steps, structural ? _chunkMLRAVUFGcjs.restoreSelection.call(void 0, text2, shared.layout, held2) : null);
671
+ } else if (steps.length > 0) {
672
+ const tr = _chunkMLRAVUFGcjs.sharedChange.call(void 0, editor, steps, history.hint(), "history");
673
+ written.add(tr);
674
+ editor.dispatch(tr);
675
+ }
676
+ if (failed) onError(failed);
891
677
  };
892
678
  const settle = () => {
893
679
  shared.stale = false;
894
680
  const read = readShared(text2, required);
895
681
  shared.layout = read.layout;
896
- if (!_chunkPZ4GT5JOcjs.sameDoc.call(void 0, read.doc, editor.state.doc)) applyRemote(editor, [_chunkPZ4GT5JOcjs.replaceDocStep.call(void 0, read.doc)]);
682
+ if (!_chunkHOIDJEVIcjs.sameDoc.call(void 0, read.doc, editor.state.doc)) _chunkMLRAVUFGcjs.applyRemote.call(void 0, editor, [_chunkHOIDJEVIcjs.replaceDocStep.call(void 0, read.doc)]);
897
683
  };
898
684
  doc.on("beforeTransaction", hold);
899
685
  text2.observeDeep(observer);
900
686
  return {
901
687
  editor,
902
- history,
903
688
  shared,
904
689
  local(tr) {
905
690
  if (written.has(tr)) return;
@@ -914,18 +699,60 @@ function bind(editor, text2, { origins, seed }) {
914
699
  stop() {
915
700
  doc.off("beforeTransaction", hold);
916
701
  text2.unobserveDeep(observer);
917
- history.destroy();
918
702
  }
919
703
  };
920
704
  }
921
705
 
706
+ // src/yjs/undo-history.ts
707
+
708
+ var GROUP_DELAY = 500;
709
+ var SELECTION = "selection";
710
+ function undoHistory(text2, origin) {
711
+ const manager = new Y3.UndoManager(text2, { trackedOrigins: /* @__PURE__ */ new Set([origin]), captureTimeout: Infinity });
712
+ let group = null;
713
+ let time = 0;
714
+ let before = null;
715
+ let hint = null;
716
+ manager.on("stack-item-added", ({ stackItem }) => stackItem.meta.set(SELECTION, before));
717
+ return {
718
+ manager,
719
+ record(tr) {
720
+ if (!tr.docChanged) {
721
+ if (tr.getMeta("closeHistory") === true) group = null;
722
+ return;
723
+ }
724
+ const next = _chunkHOIDJEVIcjs.groupOf.call(void 0, tr);
725
+ if (next === null || next !== group || tr.time - time >= GROUP_DELAY) manager.stopCapturing();
726
+ group = next;
727
+ time = tr.time;
728
+ before = tr.before.selection;
729
+ },
730
+ travel(direction, editor) {
731
+ const stack = direction === "undo" ? manager.undoStack : manager.redoStack;
732
+ const item = stack.at(-1);
733
+ if (item === void 0) return false;
734
+ hint = _nullishCoalesce(item.meta.get(SELECTION), () => ( null));
735
+ before = editor.state.selection;
736
+ group = null;
737
+ try {
738
+ return (direction === "undo" ? manager.undo() : manager.redo()) !== null;
739
+ } finally {
740
+ hint = null;
741
+ }
742
+ },
743
+ hint: () => hint
744
+ };
745
+ }
746
+
922
747
  // src/yjs/index.ts
923
748
  function yjsCollaboration(options) {
924
749
  const { doc, field = "quoin", awareness, user, seed = "if-empty" } = options;
925
750
  const onError = _nullishCoalesce(options.onError, () => ( ((error) => console.error(error))));
926
751
  const text2 = doc.getText(field);
927
752
  const origins = { local: { user }, untracked: {} };
753
+ let history;
928
754
  let binding = null;
755
+ let disconnects = 0;
929
756
  const collaboration = {
930
757
  doc,
931
758
  text: text2,
@@ -937,46 +764,57 @@ function yjsCollaboration(options) {
937
764
  onError(new Error("A Yjs collaboration connects one editor at a time; this editor stays unconnected."));
938
765
  return () => void 0;
939
766
  }
940
- const current = bind(editor, text2, { origins, seed });
767
+ const current = bind(editor, text2, {
768
+ origins,
769
+ seed,
770
+ onError,
771
+ history: () => history ??= undoHistory(text2, origins.local)
772
+ });
941
773
  binding = current;
942
774
  return () => {
943
775
  current.stop();
944
776
  if (binding === current) binding = null;
777
+ const at = ++disconnects;
778
+ setTimeout(() => {
779
+ if (binding !== null || at !== disconnects) return;
780
+ _optionalChain([history, 'optionalAccess', _42 => _42.manager, 'access', _43 => _43.destroy, 'call', _44 => _44()]);
781
+ history = void 0;
782
+ }, 16);
945
783
  };
946
784
  },
947
785
  onLocalTransaction: (tr, state) => {
948
- if (_optionalChain([binding, 'optionalAccess', _44 => _44.editor, 'access', _45 => _45.state]) === state) binding.local(tr);
786
+ if (_optionalChain([binding, 'optionalAccess', _45 => _45.editor, 'access', _46 => _46.state]) === state) binding.local(tr);
949
787
  },
950
788
  history: {
951
- undo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _46 => _46.travel, 'call', _47 => _47("undo")]), () => ( false)),
952
- redo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _48 => _48.travel, 'call', _49 => _49("redo")]), () => ( false)),
953
- canUndo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _50 => _50.history, 'access', _51 => _51.manager, 'access', _52 => _52.canUndo, 'call', _53 => _53()]), () => ( false)),
954
- canRedo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _54 => _54.history, 'access', _55 => _55.manager, 'access', _56 => _56.canRedo, 'call', _57 => _57()]), () => ( false))
789
+ undo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _47 => _47.travel, 'call', _48 => _48("undo")]), () => ( false)),
790
+ redo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _49 => _49.travel, 'call', _50 => _50("redo")]), () => ( false)),
791
+ canUndo: () => binding !== null && history.manager.canUndo(),
792
+ canRedo: () => binding !== null && history.manager.canRedo()
955
793
  }
956
794
  };
957
- _chunkE75EHRPAcjs.holdBinding.call(void 0, collaboration, () => binding);
795
+ _chunkMLRAVUFGcjs.holdBinding.call(void 0, collaboration, () => binding);
958
796
  return collaboration;
959
797
  }
960
798
 
961
799
  // src/engine/collab/collaboration-link.ts
962
- var linkKey = _chunkPZ4GT5JOcjs.createPluginKey.call(void 0, "collaborationLink");
800
+ var linkKey = _chunkHOIDJEVIcjs.createPluginKey.call(void 0, "collaborationLink");
963
801
  var linkPlugin = {
964
802
  key: linkKey,
965
803
  init: () => ({ mounts: 0, disconnect: null, warned: false }),
966
804
  apply: (_tr, link) => link
967
805
  };
968
- var linkOf = (state) => _chunkPZ4GT5JOcjs.getPluginState.call(void 0, state, linkKey);
806
+ var linkOf = (state) => _chunkHOIDJEVIcjs.getPluginState.call(void 0, state, linkKey);
969
807
 
970
808
  // src/engine/collab/warn-host-blocks.ts
971
809
  function warnHostBlocks() {
972
- if (typeof process !== "undefined" && _optionalChain([process, 'optionalAccess', _58 => _58.env, 'optionalAccess', _59 => _59.NODE_ENV]) === "production") return;
810
+ if (typeof process !== "undefined" && _optionalChain([process, 'optionalAccess', _51 => _51.env, 'optionalAccess', _52 => _52.NODE_ENV]) === "production") return;
973
811
  console.warn(
974
812
  "Quoin: blocks were supplied to a collaborative editor and ignored, since the shared document holds its content. Supply its starting blocks once and keep the ones it emits."
975
813
  );
976
814
  }
977
815
 
978
816
  // src/engine/collab/collaboration-extension.ts
979
- var providerKey = _chunkPZ4GT5JOcjs.createPluginKey.call(void 0, _chunkPZ4GT5JOcjs.HISTORY_PROVIDER);
817
+ var providerKey = _chunkHOIDJEVIcjs.createPluginKey.call(void 0, _chunkHOIDJEVIcjs.HISTORY_PROVIDER);
980
818
  function providing(history) {
981
819
  const provider = {
982
820
  undo: (dryRun) => dryRun ? history.canUndo() : history.undo(),
@@ -986,7 +824,7 @@ function providing(history) {
986
824
  }
987
825
  function collaborationExtension(adapter) {
988
826
  const { history } = adapter;
989
- return _chunkPZ4GT5JOcjs.defineExtension.call(void 0, {
827
+ return _chunkHOIDJEVIcjs.defineExtension.call(void 0, {
990
828
  name: "collaboration",
991
829
  plugins: history === void 0 ? [linkPlugin] : [linkPlugin, providing(history)],
992
830
  onMount(editor) {
@@ -1002,7 +840,7 @@ function collaborationExtension(adapter) {
1002
840
  }
1003
841
  return () => {
1004
842
  link.mounts -= 1;
1005
- if (link.mounts === 0) _optionalChain([link, 'access', _60 => _60.disconnect, 'optionalCall', _61 => _61()]);
843
+ if (link.mounts === 0) _optionalChain([link, 'access', _53 => _53.disconnect, 'optionalCall', _54 => _54()]);
1006
844
  };
1007
845
  },
1008
846
  onTransaction(tr, state) {
@@ -1022,5 +860,5 @@ function collaborationExtension(adapter) {
1022
860
 
1023
861
 
1024
862
 
1025
- exports.applyRemote = applyRemote; exports.collaborationExtension = collaborationExtension; exports.yjsCollaboration = yjsCollaboration;
863
+ exports.applyRemote = _chunkMLRAVUFGcjs.applyRemote; exports.collaborationExtension = collaborationExtension; exports.yjsCollaboration = yjsCollaboration;
1026
864
  //# sourceMappingURL=yjs.cjs.map