jazz-tools 0.17.14 → 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.
- package/.svelte-kit/__package__/jazz.class.svelte.js +1 -1
- package/.svelte-kit/__package__/media/image.svelte +3 -9
- package/.svelte-kit/__package__/media/image.svelte.d.ts +1 -6
- package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/media/image.types.d.ts +7 -0
- package/.svelte-kit/__package__/media/image.types.d.ts.map +1 -0
- package/.svelte-kit/__package__/media/image.types.js +1 -0
- package/.svelte-kit/__package__/tests/media/image.svelte.test.js +31 -31
- package/.turbo/turbo-build.log +50 -50
- package/CHANGELOG.md +31 -0
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/{chunk-LZOF6WP5.js → chunk-HJ3GTGY7.js} +1320 -1018
- package/dist/chunk-HJ3GTGY7.js.map +1 -0
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
- package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
- package/dist/inspector/index.js +1 -1
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
- package/dist/media/chunk-KR2V6X2N.js.map +1 -0
- package/dist/media/create-image.d.ts +6 -6
- package/dist/media/index.browser.d.ts +6 -6
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.d.ts +6 -6
- package/dist/media/index.native.js +1 -1
- package/dist/media/utils.d.ts.map +1 -1
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/index.js.map +1 -1
- package/dist/react/index.js +7 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +4658 -23
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-native-core/index.js +1 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +1 -1
- package/dist/svelte/media/image.svelte +3 -9
- package/dist/svelte/media/image.svelte.d.ts +1 -6
- package/dist/svelte/media/image.svelte.d.ts.map +1 -1
- package/dist/svelte/media/image.types.d.ts +7 -0
- package/dist/svelte/media/image.types.d.ts.map +1 -0
- package/dist/svelte/media/image.types.js +1 -0
- package/dist/svelte/tests/media/image.svelte.test.js +31 -31
- package/dist/testing.js +18 -14
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
- package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
- package/dist/tools/coValues/CoValueBase.d.ts +18 -15
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +100 -46
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +78 -62
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +212 -99
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +200 -192
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coPlainText.d.ts +30 -22
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +13 -13
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
- package/dist/tools/coValues/group.d.ts +32 -32
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +18 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/profile.d.ts +6 -5
- package/dist/tools/coValues/profile.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +3 -3
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +5 -5
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/symbols.d.ts +2 -0
- package/dist/tools/implementation/symbols.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +2 -1
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/migration.d.ts +1 -1
- package/dist/tools/lib/migration.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts +1 -1
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +2 -2
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/utils.d.ts +2 -6
- package/dist/tools/tests/utils.d.ts.map +1 -1
- package/dist/worker/index.js +3 -3
- package/dist/worker/index.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/auth/PasskeyAuth.ts +2 -2
- package/src/browser/createBrowserContext.ts +2 -2
- package/src/browser/tests/PasskeyAuth.test.ts +2 -2
- package/src/inspector/custom-element.tsx +2 -2
- package/src/inspector/viewer/new-app.tsx +1 -1
- package/src/media/create-image.test.ts +7 -7
- package/src/media/create-image.ts +5 -3
- package/src/media/index.ts +1 -1
- package/src/media/utils.test.ts +72 -66
- package/src/media/utils.ts +9 -6
- package/src/prosemirror/lib/plugin.ts +1 -1
- package/src/prosemirror/lib/sync.ts +1 -1
- package/src/prosemirror/tests/plugin.test.ts +4 -4
- package/src/react/media/image.tsx +2 -2
- package/src/react/tests/media/image.test.tsx +52 -32
- package/src/react-core/hooks.ts +11 -5
- package/src/react-core/tests/useAccount.test.ts +16 -22
- package/src/react-core/tests/useCoState.test.ts +19 -19
- package/src/react-core/tests/useInboxSender.test.ts +5 -2
- package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
- package/src/react-native-core/media/image.tsx +1 -1
- package/src/svelte/jazz.class.svelte.ts +1 -1
- package/src/svelte/media/image.svelte +3 -9
- package/src/svelte/media/image.types.ts +7 -0
- package/src/svelte/tests/media/image.svelte.test.ts +34 -32
- package/src/tools/auth/DemoAuth.ts +2 -2
- package/src/tools/auth/PassphraseAuth.ts +2 -2
- package/src/tools/auth/clerk/index.ts +2 -2
- package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
- package/src/tools/coValues/CoFieldInit.ts +20 -0
- package/src/tools/coValues/CoValueBase.ts +40 -60
- package/src/tools/coValues/account.ts +306 -232
- package/src/tools/coValues/coFeed.ts +185 -153
- package/src/tools/coValues/coList.ts +507 -334
- package/src/tools/coValues/coMap.ts +420 -286
- package/src/tools/coValues/coPlainText.ts +94 -110
- package/src/tools/coValues/deepLoading.ts +13 -13
- package/src/tools/coValues/group.ts +100 -114
- package/src/tools/coValues/inbox.ts +16 -14
- package/src/tools/coValues/interfaces.ts +49 -31
- package/src/tools/coValues/profile.ts +8 -6
- package/src/tools/coValues/request.ts +9 -9
- package/src/tools/coValues/schemaUnion.ts +11 -5
- package/src/tools/exports.ts +1 -1
- package/src/tools/implementation/ContextManager.ts +4 -4
- package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
- package/src/tools/implementation/createContext.ts +1 -1
- package/src/tools/implementation/devtoolsFormatters.ts +9 -9
- package/src/tools/implementation/invites.ts +2 -2
- package/src/tools/implementation/schema.ts +7 -7
- package/src/tools/implementation/symbols.ts +3 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
- package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
- package/src/tools/implementation/zodSchema/zodCo.ts +2 -2
- package/src/tools/internal.ts +2 -1
- package/src/tools/lib/migration.ts +5 -5
- package/src/tools/subscribe/SubscriptionScope.ts +32 -24
- package/src/tools/subscribe/index.ts +4 -4
- package/src/tools/subscribe/utils.ts +11 -11
- package/src/tools/testing.ts +17 -13
- package/src/tools/tests/ContextManager.test.ts +68 -57
- package/src/tools/tests/PassphraseAuth.test.ts +2 -2
- package/src/tools/tests/account.test.ts +139 -69
- package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
- package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
- package/src/tools/tests/coFeed.test-d.ts +18 -17
- package/src/tools/tests/coFeed.test.ts +108 -97
- package/src/tools/tests/coList.test-d.ts +18 -23
- package/src/tools/tests/coList.test.ts +350 -165
- package/src/tools/tests/coMap.record.test-d.ts +9 -13
- package/src/tools/tests/coMap.record.test.ts +37 -23
- package/src/tools/tests/coMap.test-d.ts +43 -21
- package/src/tools/tests/coMap.test.ts +360 -182
- package/src/tools/tests/coOptional.test.ts +28 -13
- package/src/tools/tests/coPlainText.test.ts +15 -15
- package/src/tools/tests/createContext.test.ts +14 -14
- package/src/tools/tests/deepLoading.test.ts +95 -94
- package/src/tools/tests/exportImport.test.ts +61 -41
- package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
- package/src/tools/tests/inbox.test.ts +22 -17
- package/src/tools/tests/interfaces.test.ts +12 -11
- package/src/tools/tests/invites.test.ts +6 -4
- package/src/tools/tests/load.test.ts +20 -18
- package/src/tools/tests/patterns/notifications.test.ts +6 -6
- package/src/tools/tests/patterns/quest.test.ts +3 -3
- package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
- package/src/tools/tests/request.test.ts +38 -39
- package/src/tools/tests/schemaUnion.test.ts +64 -10
- package/src/tools/tests/subscribe.test.ts +64 -64
- package/src/tools/tests/testing.test.ts +5 -9
- package/src/tools/tests/utils.ts +3 -3
- package/src/tools/tests/zod.test.ts +3 -3
- package/src/worker/index.ts +3 -3
- package/dist/chunk-LZOF6WP5.js.map +0 -1
- package/dist/media/chunk-E5J3WLQW.js.map +0 -1
- 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
|
-
|
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
|
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
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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.
|
59
|
+
const raw = options.owner.$jazz.raw.createPlainText(options.text);
|
85
60
|
Object.defineProperties(this, {
|
86
|
-
|
87
|
-
|
88
|
-
|
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.
|
98
|
+
return this.$jazz.raw.toString().length;
|
121
99
|
}
|
122
100
|
|
123
101
|
toString() {
|
124
|
-
return this.
|
102
|
+
return this.$jazz.raw.toString();
|
125
103
|
}
|
126
104
|
|
127
105
|
valueOf() {
|
128
|
-
return this.
|
106
|
+
return this.$jazz.raw.toString();
|
129
107
|
}
|
130
108
|
|
131
109
|
toJSON(): string {
|
132
|
-
return this.
|
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.
|
118
|
+
this.$jazz.raw.insertBefore(idx, text);
|
141
119
|
}
|
142
120
|
|
143
121
|
insertAfter(idx: number, text: string) {
|
144
|
-
this.
|
122
|
+
this.$jazz.raw.insertAfter(idx, text);
|
145
123
|
}
|
146
124
|
|
147
125
|
deleteRange(range: { from: number; to: number }) {
|
148
|
-
this.
|
126
|
+
this.$jazz.raw.deleteRange(range);
|
149
127
|
}
|
150
128
|
|
151
129
|
posBefore(idx: number): TextPos | undefined {
|
152
|
-
return this.
|
130
|
+
return this.$jazz.raw.mapping.opIDbeforeIdx[idx];
|
153
131
|
}
|
154
132
|
|
155
133
|
posAfter(idx: number): TextPos | undefined {
|
156
|
-
return this.
|
134
|
+
return this.$jazz.raw.mapping.opIDafterIdx[idx];
|
157
135
|
}
|
158
136
|
|
159
137
|
idxBefore(pos: TextPos): number | undefined {
|
160
|
-
return this.
|
138
|
+
return this.$jazz.raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
|
161
139
|
}
|
162
140
|
|
163
141
|
idxAfter(pos: TextPos): number | undefined {
|
164
|
-
return this.
|
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.
|
214
|
+
return Number(this.$jazz.raw.toString());
|
291
215
|
}
|
292
216
|
// For 'string' and 'default', return the string representation
|
293
|
-
return this.
|
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
|
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 {
|
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
|
-
|
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
|
-
|
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 [
|
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 [{
|
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
|
-
|
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
|
-
|
191
|
+
[TypeSym]: "BinaryCoStream";
|
192
192
|
},
|
193
193
|
]
|
194
194
|
? V
|
195
195
|
: [V] extends [
|
196
196
|
{
|
197
|
-
|
197
|
+
[TypeSym]: "CoPlainText";
|
198
198
|
},
|
199
199
|
]
|
200
200
|
? V
|