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.js CHANGED
@@ -1,172 +1,66 @@
1
1
  import {
2
+ applyRemote,
3
+ attrsMap,
2
4
  cleanEntry,
3
5
  createLayout,
6
+ definedEntries,
7
+ deleteText,
4
8
  emptySpan,
5
9
  grow,
6
10
  holdBinding,
7
11
  holdSelection,
8
12
  indexOf,
13
+ inlineOfOps,
14
+ insertInline,
15
+ isAtomEmbed,
16
+ markAttribute,
17
+ markerOf,
9
18
  offsetIn,
10
19
  piecesOf,
11
20
  placeEntries,
12
21
  pointOf,
22
+ readMarker,
23
+ regionNameOf,
13
24
  regionOf,
25
+ regionStart,
14
26
  restoreSelection,
27
+ sharedChange,
15
28
  spanAt,
16
29
  spanStart,
17
- textLength
18
- } from "./chunk-TC4DARU2.js";
30
+ textLength,
31
+ textSteps,
32
+ writeBlock,
33
+ writeBlocks
34
+ } from "./chunk-6YSGUAVW.js";
19
35
  import {
20
- HISTORY_GROUP,
21
36
  HISTORY_PROVIDER,
22
- addMarkStep,
23
37
  createPluginKey,
24
38
  defineExtension,
25
39
  getPluginState,
40
+ groupOf,
26
41
  joinBlocksStep,
27
- removeMarkStep,
28
42
  replaceBlockStep,
29
43
  replaceDocStep,
30
- replaceInlineStep,
31
44
  sameDoc,
32
- sameSelection,
33
45
  setAttrsStep,
34
46
  setIndentStep,
35
- splitBlockStep,
36
- validateSelection
37
- } from "./chunk-HJIQT3S5.js";
47
+ splitBlockStep
48
+ } from "./chunk-UPSLDTLT.js";
38
49
  import {
39
50
  sameValue
40
- } from "./chunk-NOKWNK2O.js";
51
+ } from "./chunk-6LMS5J3Y.js";
41
52
  import {
42
- atom,
43
53
  blockById,
44
54
  createDoc,
45
55
  equalInline,
46
56
  equalNode,
47
57
  inlineLength,
48
- markKey,
49
- nodeLength,
50
- normalizeInline,
51
58
  sliceInline,
52
59
  text
53
- } from "./chunk-LCQSG4M6.js";
54
-
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 && sameSelection(validateSelection(tr.doc, editor.schema, selectionHint), selectionHint)) {
60
- tr.setSelection(selectionHint);
61
- }
62
- editor.dispatch(tr);
63
- }
64
-
65
- // src/yjs/local-to-yjs.ts
66
- import * as Y4 from "yjs";
67
-
68
- // src/yjs/doc-shape.ts
69
- import * as Y from "yjs";
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 = markKey(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 markKey({ 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 = stacked?.[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 += nodeLength(node);
116
- }
117
- }
118
- function nodeOf({ insert, attributes }) {
119
- const marks = attributesToMarks(attributes);
120
- return typeof insert === "string" ? text(insert, marks) : atom(insert.atom, insert.attrs, marks);
121
- }
122
- var inlineOfOps = (ops) => normalizeInline(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
- }
60
+ } from "./chunk-62WKUAQY.js";
167
61
 
168
62
  // src/yjs/read-shared.ts
169
- import * as Y2 from "yjs";
63
+ import * as Y from "yjs";
170
64
 
171
65
  // src/yjs/required-regions.ts
172
66
  var noRequiredRegions = () => [];
@@ -242,14 +136,22 @@ function reader(required) {
242
136
  }
243
137
  }
244
138
  function embed(value) {
245
- const name = regionNameOf(value);
139
+ let name = regionNameOf(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 = 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);
@@ -263,7 +165,7 @@ function reader(required) {
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
  },
@@ -332,9 +234,6 @@ function openRegion(shared, { name, entry }, inline) {
332
234
  reread(shared);
333
235
  }
334
236
 
335
- // src/yjs/sync-block.ts
336
- import * as Y3 from "yjs";
337
-
338
237
  // src/yjs/inline-span.ts
339
238
  var units = (inline) => inline.flatMap(
340
239
  (node) => node.kind === "text" ? Array.from({ length: node.text.length }, (_, i) => text(node.text[i], node.marks)) : [node]
@@ -428,11 +327,8 @@ function removeBlock(shared, id) {
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
- }
330
+ const current = attrsMap(map, after);
331
+ if (current === null) return;
436
332
  const kept = new Map(definedEntries(after));
437
333
  for (const key of [...current.keys()]) if (!kept.has(key)) current.delete(key);
438
334
  for (const [key, value] of kept) if (!sameValue(before[key], value)) current.set(key, value);
@@ -451,8 +347,8 @@ 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);
350
+ const queue = entry.regions.map(({ name }) => [name, before.regions[name]]);
351
+ const kept = keptNames(queue.map(([name]) => name), names);
456
352
  let at = spanStart(layout, entry.span) + 1;
457
353
  const dropGone = () => {
458
354
  while (queue.length > 0 && !kept.has(queue[0][0])) deleteText(text2, at, 1 + inlineLength(queue.shift()[1]));
@@ -593,8 +489,8 @@ function setAttrs({ shared, after, params }) {
593
489
  const id = params.block;
594
490
  const { map } = shared.layout.entries.get(id);
595
491
  const next = blockById(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)));
492
+ const attrs = attrsMap(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]);
@@ -643,14 +539,6 @@ 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 && sameSelection(validateSelection(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;
@@ -666,71 +554,22 @@ function seedOrLoad(editor, text2, { origin, seed, required }) {
666
554
  return layout;
667
555
  }
668
556
 
669
- // src/yjs/undo-history.ts
670
- import * as Y5 from "yjs";
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(HISTORY_GROUP);
676
- if (named !== void 0) return named;
677
- const before = tr.before.selection;
678
- if (tr.origin !== "input" || before?.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 = 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
- import * as Y6 from "yjs";
558
+ import * as Y2 from "yjs";
721
559
  var bare = (op) => op === void 0 || op.attributes === void 0;
722
560
  function split(layout, delta, required) {
723
561
  const [at, ops] = delta[0]?.retain === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
724
562
  const map = ops[0]?.insert;
725
563
  const name = regionNameOf(ops[1]?.insert);
726
- if (ops.length !== 2 || !(map instanceof Y6.Map) || name === null || !bare(delta[0])) return null;
564
+ if (ops.length !== 2 || !(map instanceof Y2.Map) || name === null || !bare(delta[0])) return null;
727
565
  const marker = readMarker(map);
728
566
  const span = spanAt(layout, at);
729
567
  if (span.entry === null || !isPlain(span.entry)) return null;
730
568
  const region2 = span.entry.regions.at(-1);
731
569
  const seg = region2?.segs[0];
732
570
  const rel = at - spanStart(layout, span);
733
- if (marker === null || seg === void 0 || rel < seg.at || rel > seg.at + seg.length) return null;
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
575
  const created = { id, type, indent, attrs: attrs?.toJSON() ?? {}, region: name, regions: {} };
@@ -760,61 +599,6 @@ function splitOrJoin(layout, delta, doc, required) {
760
599
  return step;
761
600
  }
762
601
 
763
- // src/yjs/text-steps.ts
764
- function segAt(layout, at, item) {
765
- const span = spanAt(layout, at, item);
766
- const rel = at - spanStart(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 = spanAt(layout, at, true); ; span = layout.spans[span.index + 1]) {
773
- const start = spanStart(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] = [offsetIn(seg, from), offsetIn(seg, to)];
781
- for (const [key, value] of Object.entries(attributes)) {
782
- const mark = markFromAttribute(key, value ?? true);
783
- steps.push((value === null ? removeMarkStep : 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 = offsetIn(found.seg, found.rel);
801
- const { entry, name } = found.seg.region;
802
- steps.push(replaceInlineStep(entry.id, name, from, from + op.delete, []));
803
- grow(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 = offsetIn(found.seg, found.rel);
809
- const { entry, name } = found.seg.region;
810
- steps.push(replaceInlineStep(entry.id, name, from, from, inline));
811
- grow(layout, found.seg, found.rel, inlineLength(inline));
812
- at += inlineLength(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) {
@@ -828,12 +612,10 @@ function markerSteps(shared, event, doc) {
828
612
  if (fields.attrs !== target) return [];
829
613
  return [setAttrsStep(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 [setIndentStep(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 [replaceBlockStep({ ...block, type, indent, attrs: attrs?.toJSON() ?? {} })];
615
+ if (keys.includes("id") || keys.includes("type")) throw REREAD;
616
+ const { indent, attrs } = fields;
617
+ if (keys.every((key) => key === "indent")) return [setIndentStep(block.id, indent)];
618
+ return [replaceBlockStep({ ...block, indent, attrs: attrs?.toJSON() ?? {} })];
837
619
  }
838
620
  function contentSteps(shared, events, doc) {
839
621
  const textEvent = events.find((event) => event.target === shared.text);
@@ -854,7 +636,7 @@ 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 {
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) => {
@@ -862,17 +644,19 @@ function readRemote(shared, events, doc) {
862
644
  return held2 !== void 0 && sameValue(held2, block) ? held2 : block;
863
645
  });
864
646
  const next = createDoc(blocks);
865
- return { steps: sameDoc(next, doc) ? [] : [replaceDocStep(next)], structural: true };
647
+ const failed = error === REREAD ? void 0 : error;
648
+ return { steps: sameDoc(next, doc) ? [] : [replaceDocStep(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();
@@ -881,13 +665,15 @@ function bind(editor, text2, { origins, seed }) {
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 ? restoreSelection(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
+ applyRemote(editor, steps, structural ? restoreSelection(text2, shared.layout, held2) : null);
671
+ } else if (steps.length > 0) {
672
+ const tr = sharedChange(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;
@@ -899,7 +685,6 @@ function bind(editor, text2, { origins, seed }) {
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
+ import * as Y3 from "yjs";
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 = groupOf(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 = 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 = 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,11 +764,22 @@ 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
+ history?.manager.destroy();
781
+ history = void 0;
782
+ }, 16);
945
783
  };
946
784
  },
947
785
  onLocalTransaction: (tr, state) => {
@@ -950,8 +788,8 @@ function yjsCollaboration(options) {
950
788
  history: {
951
789
  undo: () => binding?.travel("undo") ?? false,
952
790
  redo: () => binding?.travel("redo") ?? false,
953
- canUndo: () => binding?.history.manager.canUndo() ?? false,
954
- canRedo: () => binding?.history.manager.canRedo() ?? false
791
+ canUndo: () => binding !== null && history.manager.canUndo(),
792
+ canRedo: () => binding !== null && history.manager.canRedo()
955
793
  }
956
794
  };
957
795
  holdBinding(collaboration, () => binding);