jazz-tools 0.17.13 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.js +1 -1
  2. package/.svelte-kit/__package__/media/image.svelte +3 -9
  3. package/.svelte-kit/__package__/media/image.svelte.d.ts +1 -6
  4. package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
  5. package/.svelte-kit/__package__/media/image.types.d.ts +7 -0
  6. package/.svelte-kit/__package__/media/image.types.d.ts.map +1 -0
  7. package/.svelte-kit/__package__/media/image.types.js +1 -0
  8. package/.svelte-kit/__package__/tests/media/image.svelte.test.js +31 -31
  9. package/.turbo/turbo-build.log +49 -49
  10. package/CHANGELOG.md +42 -0
  11. package/dist/browser/index.js +2 -2
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/{chunk-SFP5PBPX.js → chunk-HJ3GTGY7.js} +1325 -1001
  14. package/dist/chunk-HJ3GTGY7.js.map +1 -0
  15. package/dist/index.js +18 -18
  16. package/dist/index.js.map +1 -1
  17. package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
  18. package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
  19. package/dist/inspector/index.js +1 -1
  20. package/dist/inspector/index.js.map +1 -1
  21. package/dist/inspector/register-custom-element.js +1 -1
  22. package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
  23. package/dist/media/chunk-KR2V6X2N.js.map +1 -0
  24. package/dist/media/create-image.d.ts +6 -6
  25. package/dist/media/index.browser.d.ts +6 -6
  26. package/dist/media/index.browser.js +1 -1
  27. package/dist/media/index.d.ts +1 -1
  28. package/dist/media/index.js +1 -1
  29. package/dist/media/index.native.d.ts +6 -6
  30. package/dist/media/index.native.js +1 -1
  31. package/dist/media/utils.d.ts.map +1 -1
  32. package/dist/prosemirror/index.js +2 -2
  33. package/dist/prosemirror/index.js.map +1 -1
  34. package/dist/react/index.js +7 -5
  35. package/dist/react/index.js.map +1 -1
  36. package/dist/react-core/hooks.d.ts.map +1 -1
  37. package/dist/react-core/index.js +4658 -23
  38. package/dist/react-core/index.js.map +1 -1
  39. package/dist/react-native-core/index.js +1 -1
  40. package/dist/react-native-core/index.js.map +1 -1
  41. package/dist/svelte/jazz.class.svelte.js +1 -1
  42. package/dist/svelte/media/image.svelte +3 -9
  43. package/dist/svelte/media/image.svelte.d.ts +1 -6
  44. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  45. package/dist/svelte/media/image.types.d.ts +7 -0
  46. package/dist/svelte/media/image.types.d.ts.map +1 -0
  47. package/dist/svelte/media/image.types.js +1 -0
  48. package/dist/svelte/tests/media/image.svelte.test.js +31 -31
  49. package/dist/testing.js +18 -14
  50. package/dist/testing.js.map +1 -1
  51. package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
  52. package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
  53. package/dist/tools/coValues/CoValueBase.d.ts +18 -15
  54. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  55. package/dist/tools/coValues/account.d.ts +100 -46
  56. package/dist/tools/coValues/account.d.ts.map +1 -1
  57. package/dist/tools/coValues/coFeed.d.ts +78 -62
  58. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  59. package/dist/tools/coValues/coList.d.ts +212 -99
  60. package/dist/tools/coValues/coList.d.ts.map +1 -1
  61. package/dist/tools/coValues/coMap.d.ts +200 -192
  62. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  63. package/dist/tools/coValues/coPlainText.d.ts +30 -22
  64. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  65. package/dist/tools/coValues/deepLoading.d.ts +13 -13
  66. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  67. package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
  68. package/dist/tools/coValues/group.d.ts +32 -32
  69. package/dist/tools/coValues/group.d.ts.map +1 -1
  70. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  71. package/dist/tools/coValues/interfaces.d.ts +18 -17
  72. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  73. package/dist/tools/coValues/profile.d.ts +6 -5
  74. package/dist/tools/coValues/profile.d.ts.map +1 -1
  75. package/dist/tools/coValues/schemaUnion.d.ts +3 -3
  76. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  77. package/dist/tools/exports.d.ts +1 -1
  78. package/dist/tools/exports.d.ts.map +1 -1
  79. package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
  80. package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
  81. package/dist/tools/implementation/schema.d.ts +5 -5
  82. package/dist/tools/implementation/schema.d.ts.map +1 -1
  83. package/dist/tools/implementation/symbols.d.ts +2 -0
  84. package/dist/tools/implementation/symbols.d.ts.map +1 -1
  85. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
  86. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  87. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
  88. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  89. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
  90. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  91. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
  92. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  93. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
  94. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
  96. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
  98. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
  100. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
  102. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
  103. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
  104. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  105. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
  106. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  107. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -2
  108. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  109. package/dist/tools/internal.d.ts +2 -1
  110. package/dist/tools/internal.d.ts.map +1 -1
  111. package/dist/tools/lib/migration.d.ts +1 -1
  112. package/dist/tools/lib/migration.d.ts.map +1 -1
  113. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  114. package/dist/tools/subscribe/index.d.ts +1 -1
  115. package/dist/tools/subscribe/index.d.ts.map +1 -1
  116. package/dist/tools/subscribe/utils.d.ts +2 -2
  117. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  118. package/dist/tools/testing.d.ts.map +1 -1
  119. package/dist/tools/tests/utils.d.ts +2 -6
  120. package/dist/tools/tests/utils.d.ts.map +1 -1
  121. package/dist/worker/index.js +3 -3
  122. package/dist/worker/index.js.map +1 -1
  123. package/package.json +4 -4
  124. package/src/browser/auth/PasskeyAuth.ts +2 -2
  125. package/src/browser/createBrowserContext.ts +2 -2
  126. package/src/browser/tests/PasskeyAuth.test.ts +2 -2
  127. package/src/inspector/custom-element.tsx +2 -2
  128. package/src/inspector/viewer/new-app.tsx +1 -1
  129. package/src/media/create-image.test.ts +7 -7
  130. package/src/media/create-image.ts +5 -3
  131. package/src/media/index.ts +1 -1
  132. package/src/media/utils.test.ts +72 -66
  133. package/src/media/utils.ts +9 -6
  134. package/src/prosemirror/lib/plugin.ts +1 -1
  135. package/src/prosemirror/lib/sync.ts +1 -1
  136. package/src/prosemirror/tests/plugin.test.ts +4 -4
  137. package/src/react/media/image.tsx +2 -2
  138. package/src/react/tests/media/image.test.tsx +52 -32
  139. package/src/react-core/hooks.ts +11 -5
  140. package/src/react-core/tests/useAccount.test.ts +16 -22
  141. package/src/react-core/tests/useCoState.test.ts +19 -19
  142. package/src/react-core/tests/useInboxSender.test.ts +5 -2
  143. package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
  144. package/src/react-native-core/media/image.tsx +1 -1
  145. package/src/svelte/jazz.class.svelte.ts +1 -1
  146. package/src/svelte/media/image.svelte +3 -9
  147. package/src/svelte/media/image.types.ts +7 -0
  148. package/src/svelte/tests/media/image.svelte.test.ts +34 -32
  149. package/src/tools/auth/DemoAuth.ts +2 -2
  150. package/src/tools/auth/PassphraseAuth.ts +2 -2
  151. package/src/tools/auth/clerk/index.ts +2 -2
  152. package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
  153. package/src/tools/coValues/CoFieldInit.ts +20 -0
  154. package/src/tools/coValues/CoValueBase.ts +40 -60
  155. package/src/tools/coValues/account.ts +306 -232
  156. package/src/tools/coValues/coFeed.ts +185 -153
  157. package/src/tools/coValues/coList.ts +507 -334
  158. package/src/tools/coValues/coMap.ts +420 -286
  159. package/src/tools/coValues/coPlainText.ts +94 -110
  160. package/src/tools/coValues/deepLoading.ts +13 -13
  161. package/src/tools/coValues/group.ts +100 -114
  162. package/src/tools/coValues/inbox.ts +16 -14
  163. package/src/tools/coValues/interfaces.ts +49 -31
  164. package/src/tools/coValues/profile.ts +8 -6
  165. package/src/tools/coValues/request.ts +9 -9
  166. package/src/tools/coValues/schemaUnion.ts +11 -5
  167. package/src/tools/exports.ts +1 -1
  168. package/src/tools/implementation/ContextManager.ts +4 -4
  169. package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
  170. package/src/tools/implementation/createContext.ts +1 -1
  171. package/src/tools/implementation/devtoolsFormatters.ts +9 -9
  172. package/src/tools/implementation/invites.ts +2 -2
  173. package/src/tools/implementation/schema.ts +7 -7
  174. package/src/tools/implementation/symbols.ts +3 -0
  175. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
  176. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
  177. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
  178. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
  179. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
  180. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
  181. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
  182. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
  183. package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
  184. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
  185. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
  186. package/src/tools/implementation/zodSchema/zodCo.ts +47 -10
  187. package/src/tools/internal.ts +2 -1
  188. package/src/tools/lib/migration.ts +5 -5
  189. package/src/tools/subscribe/SubscriptionScope.ts +32 -24
  190. package/src/tools/subscribe/index.ts +4 -4
  191. package/src/tools/subscribe/utils.ts +11 -11
  192. package/src/tools/testing.ts +17 -13
  193. package/src/tools/tests/ContextManager.test.ts +68 -57
  194. package/src/tools/tests/PassphraseAuth.test.ts +2 -2
  195. package/src/tools/tests/account.test.ts +154 -74
  196. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
  197. package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
  198. package/src/tools/tests/coFeed.test-d.ts +18 -17
  199. package/src/tools/tests/coFeed.test.ts +108 -97
  200. package/src/tools/tests/coList.test-d.ts +18 -23
  201. package/src/tools/tests/coList.test.ts +350 -165
  202. package/src/tools/tests/coMap.record.test-d.ts +9 -13
  203. package/src/tools/tests/coMap.record.test.ts +37 -23
  204. package/src/tools/tests/coMap.test-d.ts +43 -21
  205. package/src/tools/tests/coMap.test.ts +368 -182
  206. package/src/tools/tests/coOptional.test.ts +28 -13
  207. package/src/tools/tests/coPlainText.test.ts +15 -15
  208. package/src/tools/tests/createContext.test.ts +14 -14
  209. package/src/tools/tests/deepLoading.test.ts +95 -94
  210. package/src/tools/tests/exportImport.test.ts +61 -41
  211. package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
  212. package/src/tools/tests/inbox.test.ts +22 -17
  213. package/src/tools/tests/interfaces.test.ts +12 -11
  214. package/src/tools/tests/invites.test.ts +6 -4
  215. package/src/tools/tests/load.test.ts +20 -18
  216. package/src/tools/tests/patterns/notifications.test.ts +6 -6
  217. package/src/tools/tests/patterns/quest.test.ts +3 -3
  218. package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
  219. package/src/tools/tests/request.test.ts +38 -39
  220. package/src/tools/tests/schemaUnion.test.ts +64 -10
  221. package/src/tools/tests/subscribe.test.ts +64 -64
  222. package/src/tools/tests/testing.test.ts +5 -9
  223. package/src/tools/tests/utils.ts +3 -3
  224. package/src/tools/tests/zod.test.ts +3 -3
  225. package/src/worker/index.ts +3 -3
  226. package/dist/chunk-SFP5PBPX.js.map +0 -1
  227. package/dist/media/chunk-E5J3WLQW.js.map +0 -1
  228. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +0 -1
@@ -1,20 +1,15 @@
1
- import {
2
- ControlledAccount,
3
- type OpID,
4
- RawAccount,
5
- type RawCoPlainText,
6
- stringifyOpID,
7
- } from "cojson";
1
+ import { type OpID, type RawCoPlainText, stringifyOpID } from "cojson";
8
2
  import { calcPatch } from "fast-myers-diff";
9
3
  import {
10
4
  AnonymousJazzAgent,
11
5
  CoValue,
12
6
  CoValueClass,
7
+ CoValueJazzApi,
13
8
  ID,
14
9
  Resolved,
15
10
  SubscribeListenerOptions,
16
11
  SubscribeRestArgs,
17
- coValueClassFromCoValueClassOrSchema,
12
+ TypeSym,
18
13
  parseCoValueCreateOptions,
19
14
  } from "../internal.js";
20
15
  import {
@@ -24,37 +19,15 @@ import {
24
19
  subscribeToCoValueWithoutMe,
25
20
  subscribeToExistingCoValue,
26
21
  } from "../internal.js";
27
- import { coValuesCache } from "../lib/cache.js";
28
22
  import { Account } from "./account.js";
29
- import { Group } from "./group.js";
30
- import { RegisteredSchemas } from "./registeredSchemas.js";
23
+ import { getCoValueOwner, Group } from "./group.js";
31
24
 
32
25
  export type TextPos = OpID;
33
26
 
34
27
  export class CoPlainText extends String implements CoValue {
35
- declare id: ID<this>;
36
- declare _type: "CoPlainText";
37
- declare _raw: RawCoPlainText;
38
-
39
- get _owner(): Account | Group {
40
- return this._raw.group instanceof RawAccount
41
- ? Account.fromRaw(this._raw.group)
42
- : Group.fromRaw(this._raw.group);
43
- }
44
-
45
- get _loadedAs() {
46
- const agent = this._raw.core.node.getCurrentAgent();
28
+ declare [TypeSym]: "CoPlainText";
47
29
 
48
- if (agent instanceof ControlledAccount) {
49
- return coValuesCache.get(agent.account, () =>
50
- coValueClassFromCoValueClassOrSchema(
51
- RegisteredSchemas["Account"],
52
- ).fromRaw(agent.account),
53
- );
54
- }
55
-
56
- return new AnonymousJazzAgent(this._raw.core.node);
57
- }
30
+ declare $jazz: CoTextJazzApi<this>;
58
31
 
59
32
  /** @internal */
60
33
  constructor(
@@ -72,20 +45,24 @@ export class CoPlainText extends String implements CoValue {
72
45
  super(options.fromRaw.toString());
73
46
  const raw = options.fromRaw;
74
47
  Object.defineProperties(this, {
75
- id: { value: raw.id, enumerable: false },
76
- _type: { value: "CoPlainText", enumerable: false },
77
- _raw: { value: raw, enumerable: false },
48
+ [TypeSym]: { value: "CoPlainText", enumerable: false },
49
+ $jazz: {
50
+ value: new CoTextJazzApi(this, raw),
51
+ enumerable: false,
52
+ },
78
53
  });
79
54
  return;
80
55
  }
81
56
 
82
57
  if ("text" in options && "owner" in options) {
83
58
  super(options.text);
84
- const raw = options.owner._raw.createPlainText(options.text);
59
+ const raw = options.owner.$jazz.raw.createPlainText(options.text);
85
60
  Object.defineProperties(this, {
86
- id: { value: raw.id, enumerable: false },
87
- _type: { value: "CoPlainText", enumerable: false },
88
- _raw: { value: raw, enumerable: false },
61
+ [TypeSym]: { value: "CoPlainText", enumerable: false },
62
+ $jazz: {
63
+ value: new CoTextJazzApi(this, raw),
64
+ enumerable: false,
65
+ },
89
66
  });
90
67
  return;
91
68
  }
@@ -106,6 +83,7 @@ export class CoPlainText extends String implements CoValue {
106
83
  * ```
107
84
  *
108
85
  * @category Creation
86
+ * @deprecated Use `co.plainText(...).create` instead.
109
87
  */
110
88
  static create<T extends CoPlainText>(
111
89
  this: CoValueClass<T>,
@@ -117,19 +95,19 @@ export class CoPlainText extends String implements CoValue {
117
95
  }
118
96
 
119
97
  get length() {
120
- return this._raw.toString().length;
98
+ return this.$jazz.raw.toString().length;
121
99
  }
122
100
 
123
101
  toString() {
124
- return this._raw.toString();
102
+ return this.$jazz.raw.toString();
125
103
  }
126
104
 
127
105
  valueOf() {
128
- return this._raw.toString();
106
+ return this.$jazz.raw.toString();
129
107
  }
130
108
 
131
109
  toJSON(): string {
132
- return this._raw.toString();
110
+ return this.$jazz.raw.toString();
133
111
  }
134
112
 
135
113
  [inspect]() {
@@ -137,33 +115,34 @@ export class CoPlainText extends String implements CoValue {
137
115
  }
138
116
 
139
117
  insertBefore(idx: number, text: string) {
140
- this._raw.insertBefore(idx, text);
118
+ this.$jazz.raw.insertBefore(idx, text);
141
119
  }
142
120
 
143
121
  insertAfter(idx: number, text: string) {
144
- this._raw.insertAfter(idx, text);
122
+ this.$jazz.raw.insertAfter(idx, text);
145
123
  }
146
124
 
147
125
  deleteRange(range: { from: number; to: number }) {
148
- this._raw.deleteRange(range);
126
+ this.$jazz.raw.deleteRange(range);
149
127
  }
150
128
 
151
129
  posBefore(idx: number): TextPos | undefined {
152
- return this._raw.mapping.opIDbeforeIdx[idx];
130
+ return this.$jazz.raw.mapping.opIDbeforeIdx[idx];
153
131
  }
154
132
 
155
133
  posAfter(idx: number): TextPos | undefined {
156
- return this._raw.mapping.opIDafterIdx[idx];
134
+ return this.$jazz.raw.mapping.opIDafterIdx[idx];
157
135
  }
158
136
 
159
137
  idxBefore(pos: TextPos): number | undefined {
160
- return this._raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
138
+ return this.$jazz.raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
161
139
  }
162
140
 
163
141
  idxAfter(pos: TextPos): number | undefined {
164
- return this._raw.mapping.idxAfterOpID[stringifyOpID(pos)];
142
+ return this.$jazz.raw.mapping.idxAfterOpID[stringifyOpID(pos)];
165
143
  }
166
144
 
145
+ /** @category Internals */
167
146
  static fromRaw<V extends CoPlainText>(
168
147
  this: CoValueClass<V> & typeof CoPlainText,
169
148
  raw: RawCoPlainText,
@@ -171,37 +150,11 @@ export class CoPlainText extends String implements CoValue {
171
150
  return new this({ fromRaw: raw });
172
151
  }
173
152
 
174
- /**
175
- * Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
176
- *
177
- * @category Mutation
178
- */
179
- applyDiff(other: string) {
180
- const current = this._raw.toString();
181
-
182
- // Split both strings into grapheme arrays for proper comparison
183
- const currentGraphemes = this._raw.toGraphemes(current);
184
- const otherGraphemes = this._raw.toGraphemes(other);
185
-
186
- // Calculate the diff on grapheme arrays
187
- const patches = [...calcPatch(currentGraphemes, otherGraphemes)];
188
-
189
- // Apply patches in reverse order to avoid index shifting issues
190
- for (const [from, to, insert] of patches.reverse()) {
191
- if (to > from) {
192
- this.deleteRange({ from, to });
193
- }
194
- if (insert.length > 0) {
195
- // Join the graphemes back into a string for insertion
196
- this.insertBefore(from, this._raw.fromGraphemes(insert));
197
- }
198
- }
199
- }
200
-
201
153
  /**
202
154
  * Load a `CoPlainText` with a given ID, as a given account.
203
155
  *
204
156
  * @category Subscription & Loading
157
+ * @deprecated Use `co.plainText(...).load` instead.
205
158
  */
206
159
  static load<T extends CoPlainText>(
207
160
  this: CoValueClass<T>,
@@ -211,20 +164,6 @@ export class CoPlainText extends String implements CoValue {
211
164
  return loadCoValueWithoutMe(this, id, options);
212
165
  }
213
166
 
214
- // /**
215
- // * Effectful version of `CoMap.load()`.
216
- // *
217
- // * Needs to be run inside an `AccountCtx` context.
218
- // *
219
- // * @category Subscription & Loading
220
- // */
221
- // static loadEf<T extends CoPlainText>(
222
- // this: CoValueClass<T>,
223
- // id: ID<T>,
224
- // ): Effect.Effect<T, UnavailableError, AccountCtx> {
225
- // return loadCoValueEf(this, id, []);
226
- // }
227
-
228
167
  /**
229
168
  * Load and subscribe to a `CoPlainText` with a given ID, as a given account.
230
169
  *
@@ -237,6 +176,7 @@ export class CoPlainText extends String implements CoValue {
237
176
  * Also see the `useCoState` hook to reactively subscribe to a CoValue in a React component.
238
177
  *
239
178
  * @category Subscription & Loading
179
+ * @deprecated Use `co.plainText(...).subscribe` instead.
240
180
  */
241
181
  static subscribe<T extends CoPlainText>(
242
182
  this: CoValueClass<T>,
@@ -258,22 +198,6 @@ export class CoPlainText extends String implements CoValue {
258
198
  return subscribeToCoValueWithoutMe<T, true>(this, id, options, listener);
259
199
  }
260
200
 
261
- /**
262
- * Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
263
- *
264
- * Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
265
- *
266
- * Returns an unsubscribe function that you should call when you no longer need updates.
267
- *
268
- * @category Subscription & Loading
269
- **/
270
- subscribe<T extends CoPlainText>(
271
- this: T,
272
- listener: (value: Resolved<T, true>, unsubscribe: () => void) => void,
273
- ): () => void {
274
- return subscribeToExistingCoValue(this, {}, listener);
275
- }
276
-
277
201
  /**
278
202
  * Allow CoPlainText to behave like a primitive string in most contexts (e.g.,
279
203
  * string concatenation, template literals, React rendering, etc.) by implementing
@@ -287,9 +211,69 @@ export class CoPlainText extends String implements CoValue {
287
211
  [Symbol.toPrimitive](hint: string) {
288
212
  if (hint === "number") {
289
213
  // Not meaningful for text, but required for completeness
290
- return Number(this._raw.toString());
214
+ return Number(this.$jazz.raw.toString());
291
215
  }
292
216
  // For 'string' and 'default', return the string representation
293
- return this._raw.toString();
217
+ return this.$jazz.raw.toString();
218
+ }
219
+ }
220
+
221
+ export class CoTextJazzApi<T extends CoPlainText> extends CoValueJazzApi<T> {
222
+ constructor(
223
+ private coText: T,
224
+ public raw: RawCoPlainText,
225
+ ) {
226
+ super(coText);
227
+ }
228
+
229
+ get id(): ID<T> {
230
+ return this.raw.id;
231
+ }
232
+
233
+ get owner(): Group {
234
+ return getCoValueOwner(this.coText);
235
+ }
236
+
237
+ /**
238
+ * Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
239
+ *
240
+ * @category Mutation
241
+ */
242
+ applyDiff(other: string) {
243
+ const current = this.raw.toString();
244
+
245
+ // Split both strings into grapheme arrays for proper comparison
246
+ const currentGraphemes = this.raw.toGraphemes(current);
247
+ const otherGraphemes = this.raw.toGraphemes(other);
248
+
249
+ // Calculate the diff on grapheme arrays
250
+ const patches = [...calcPatch(currentGraphemes, otherGraphemes)];
251
+
252
+ // Apply patches in reverse order to avoid index shifting issues
253
+ for (const [from, to, insert] of patches.reverse()) {
254
+ if (to > from) {
255
+ this.coText.deleteRange({ from, to });
256
+ }
257
+ if (insert.length > 0) {
258
+ // Join the graphemes back into a string for insertion
259
+ this.coText.insertBefore(from, this.raw.fromGraphemes(insert));
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
266
+ *
267
+ * Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
268
+ *
269
+ * Returns an unsubscribe function that you should call when you no longer need updates.
270
+ *
271
+ * @category Subscription & Loading
272
+ **/
273
+ subscribe<T extends CoPlainText>(
274
+ this: CoTextJazzApi<T>,
275
+ listener: (value: Resolved<T, true>, unsubscribe: () => void) => void,
276
+ ): () => void {
277
+ return subscribeToExistingCoValue(this.coText, {}, listener);
294
278
  }
295
279
  }
@@ -1,5 +1,5 @@
1
1
  import { SessionID } from "cojson";
2
- import { ItemsSym } from "../internal.js";
2
+ import { ItemsSym, TypeSym } from "../internal.js";
3
3
  import { type Account } from "./account.js";
4
4
  import { CoFeedEntry } from "./coFeed.js";
5
5
  import { type CoKeys } from "./coMap.js";
@@ -34,7 +34,7 @@ export type RefsToResolve<
34
34
  : IsUnion<NonNullable<V>> extends true
35
35
  ? true
36
36
  : // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
37
- V extends Array<infer Item>
37
+ V extends ReadonlyArray<infer Item>
38
38
  ?
39
39
  | {
40
40
  $each?: RefsToResolve<
@@ -46,7 +46,7 @@ export type RefsToResolve<
46
46
  }
47
47
  | boolean
48
48
  : // Basically V extends CoMap | Group | Account - but if we used that we'd introduce circularity into the definition of CoMap itself
49
- V extends { _type: "CoMap" | "Group" | "Account" }
49
+ V extends { [TypeSym]: "CoMap" | "Group" | "Account" }
50
50
  ?
51
51
  | ({
52
52
  [Key in CoKeys<V> as NonNullable<V[Key]> extends CoValue
@@ -69,7 +69,7 @@ export type RefsToResolve<
69
69
  : never)
70
70
  | boolean
71
71
  : V extends {
72
- _type: "CoStream";
72
+ [TypeSym]: "CoStream";
73
73
  byMe: CoFeedEntry<infer Item> | undefined;
74
74
  }
75
75
  ?
@@ -103,7 +103,7 @@ type CoMapLikeLoaded<
103
103
  DepthLimit extends number,
104
104
  CurrentDepth extends number[],
105
105
  > = {
106
- -readonly [Key in keyof Depth]-?: Key extends CoKeys<V>
106
+ readonly [Key in keyof Omit<Depth, "$onError">]-?: Key extends CoKeys<V>
107
107
  ? NonNullable<V[Key]> extends CoValue
108
108
  ?
109
109
  | DeeplyLoaded<
@@ -128,11 +128,11 @@ export type DeeplyLoaded<
128
128
  : Depth extends boolean | undefined // Checking against boolean instead of true because the inference from RefsToResolveStrict transforms true into boolean
129
129
  ? V
130
130
  : // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
131
- [V] extends [Array<infer Item>]
131
+ [V] extends [ReadonlyArray<infer Item>]
132
132
  ? NotNull<Item> extends CoValue
133
133
  ? Depth extends { $each: infer ItemDepth }
134
134
  ? // Deeply loaded CoList
135
- (
135
+ ReadonlyArray<
136
136
  | (NotNull<Item> &
137
137
  DeeplyLoaded<
138
138
  NotNull<Item>,
@@ -141,12 +141,12 @@ export type DeeplyLoaded<
141
141
  [0, ...CurrentDepth]
142
142
  >)
143
143
  | onErrorNullEnabled<Depth["$each"]>
144
- )[] &
144
+ > &
145
145
  V // the CoList base type needs to be intersected after so that built-in methods return the correct narrowed array type
146
146
  : never
147
147
  : V
148
148
  : // Basically V extends CoMap | Group | Account - but if we used that we'd introduce circularity into the definition of CoMap itself
149
- [V] extends [{ _type: "CoMap" | "Group" | "Account" }]
149
+ [V] extends [{ [TypeSym]: "CoMap" | "Group" | "Account" }]
150
150
  ? // If Depth = {} return V in any case
151
151
  keyof Depth extends never
152
152
  ? V
@@ -155,7 +155,7 @@ export type DeeplyLoaded<
155
155
  ? // 1.1. Deeply loaded Record-like CoMap with { $each: true | {$onError: null} }
156
156
  Depth extends { $each: infer ItemDepth }
157
157
  ? {
158
- [key: string]:
158
+ readonly [key: string]:
159
159
  | DeeplyLoaded<
160
160
  NonNullable<V[ItemsSym]>,
161
161
  ItemDepth,
@@ -174,7 +174,7 @@ export type DeeplyLoaded<
174
174
  CoMapLikeLoaded<V, Depth, DepthLimit, CurrentDepth>
175
175
  : [V] extends [
176
176
  {
177
- _type: "CoStream";
177
+ [TypeSym]: "CoStream";
178
178
  byMe: CoFeedEntry<infer Item> | undefined;
179
179
  },
180
180
  ]
@@ -188,13 +188,13 @@ export type DeeplyLoaded<
188
188
  } & { [key: ID<Account>]: { value: NotNull<Item> } } & V // same reason as in CoList
189
189
  : [V] extends [
190
190
  {
191
- _type: "BinaryCoStream";
191
+ [TypeSym]: "BinaryCoStream";
192
192
  },
193
193
  ]
194
194
  ? V
195
195
  : [V] extends [
196
196
  {
197
- _type: "CoPlainText";
197
+ [TypeSym]: "CoPlainText";
198
198
  },
199
199
  ]
200
200
  ? V