Compare commits

..

1 Commits

Author SHA1 Message Date
Anselm
c358cb0b3d Attempt to simplify create account logic 2025-05-06 13:59:02 +01:00
240 changed files with 2901 additions and 10944 deletions

View File

@@ -15,7 +15,6 @@
"jazz-browser-media-images",
"jazz-expo",
"jazz-inspector",
"jazz-inspector-element",
"jazz-nodejs",
"jazz-react",
"jazz-react-core",

View File

@@ -0,0 +1,5 @@
---
"cojson": patch
---
Resolve CoValue load as soon as the core is available

View File

@@ -0,0 +1,5 @@
---
"cojson": patch
---
Re-introduce incremental processing on RawCoList

View File

@@ -0,0 +1,5 @@
---
"jazz-richtext-prosemirror": patch
---
createJazzPlugin support custom ProseMirror schema

View File

@@ -1,63 +1,5 @@
# chat-rn-expo-clerk
## 1.0.115
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-expo@0.13.23
- jazz-react-native-media-images@0.13.23
## 1.0.114
### Patch Changes
- jazz-expo@0.13.22
## 1.0.113
### Patch Changes
- jazz-expo@0.13.21
- jazz-tools@0.13.21
- jazz-react-native-media-images@0.13.21
## 1.0.112
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-expo@0.13.20
- jazz-react-native-media-images@0.13.20
## 1.0.111
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-expo@0.13.19
- jazz-react-native-media-images@0.13.19
## 1.0.110
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-expo@0.13.18
- jazz-react-native-media-images@0.13.18
## 1.0.109
### Patch Changes
- jazz-expo@0.13.17
- jazz-tools@0.13.17
- jazz-react-native-media-images@0.13.17
## 1.0.108
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "chat-rn-expo-clerk",
"main": "index.js",
"version": "1.0.115",
"version": "1.0.108",
"scripts": {
"build": "expo export -p ios",
"start": "expo start",

View File

@@ -1,57 +1,5 @@
# chat-rn-expo
## 1.0.102
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-expo@0.13.23
## 1.0.101
### Patch Changes
- jazz-expo@0.13.22
## 1.0.100
### Patch Changes
- jazz-expo@0.13.21
- jazz-tools@0.13.21
## 1.0.99
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-expo@0.13.20
## 1.0.98
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-expo@0.13.19
## 1.0.97
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-expo@0.13.18
## 1.0.96
### Patch Changes
- jazz-expo@0.13.17
- jazz-tools@0.13.17
## 1.0.95
### Patch Changes

View File

@@ -1,55 +0,0 @@
const { withBuildProperties } = require("expo-build-properties");
const { withDangerousMod } = require("@expo/config-plugins");
const fs = require("fs/promises");
const path = require("path");
/**
* https://github.com/mrousavy/nitro/issues/422#issuecomment-2545988256
*/
function withCustomIosMod(config) {
// Use expo-build-properties to bump iOS deployment target
config = withBuildProperties(config, { ios: { deploymentTarget: "16.0" } });
// Patch the generated Podfile fallback to ensure platform is always 16.0
config = withDangerousMod(config, [
"ios",
async (modConfig) => {
const podfilePath = path.join(
modConfig.modRequest.platformProjectRoot,
"Podfile",
);
let contents = await fs.readFile(podfilePath, "utf-8");
// Check if the IPHONEOS_DEPLOYMENT_TARGET setting is already present
// We search for the key being assigned, e.g., config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] =
const deploymentTargetSettingExists =
/\.build_settings\s*\[\s*['"]IPHONEOS_DEPLOYMENT_TARGET['"]\s*\]\s*=/.test(
contents,
);
if (!deploymentTargetSettingExists) {
// IPHONEOS_DEPLOYMENT_TARGET setting not found, proceed to add it.
contents = contents.replace(
/(post_install\s+do\s+\|installer\|[\s\S]*?)(\r?\n\s end\s*)$/m,
`$1
# Expo Build Properties: force deployment target
# https://github.com/mrousavy/nitro/issues/422#issuecomment-2545988256
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0'
end
end
$2`,
);
}
await fs.writeFile(podfilePath, contents);
return modConfig;
},
]);
return config;
}
module.exports = ({ config }) => {
return withCustomIosMod(config);
};

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn-expo",
"version": "1.0.102",
"version": "1.0.95",
"main": "index.js",
"scripts": {
"build": "expo export -p ios",
@@ -36,8 +36,6 @@
"react-dom": "18.3.1",
"react-native": "0.76.7",
"react-native-get-random-values": "^1.11.0",
"react-native-nitro-modules": "0.25.2",
"react-native-quick-crypto": "1.0.0-beta.15",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "4.4.0",
"react-native-url-polyfill": "^2.0.0",

View File

@@ -6,7 +6,6 @@ import {
} from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import * as Linking from "expo-linking";
import { RNQuickCrypto } from "jazz-expo/crypto";
import React, { StrictMode, useEffect, useState } from "react";
import HandleInviteScreen from "./invite";
@@ -47,7 +46,6 @@ function App() {
return (
<StrictMode>
<JazzProvider
CryptoProvider={RNQuickCrypto}
sync={{
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
}}

View File

@@ -20,7 +20,6 @@ import { Chat, Message } from "./schema";
export default function ChatScreen({ navigation }: { navigation: any }) {
const { me, logOut } = useAccount();
const [chatId, setChatId] = useState<ID<Chat>>();
const [chatIdInput, setChatIdInput] = useState<string>();
const loadedChat = useCoState(Chat, chatId, { resolve: { $each: true } });
const [message, setMessage] = useState("");
const profile = useCoState(Profile, me._refs.profile?.id, {});
@@ -58,11 +57,27 @@ export default function ChatScreen({ navigation }: { navigation: any }) {
};
const joinChat = () => {
if (chatIdInput) {
setChatId(chatIdInput as ID<Chat>);
} else {
Alert.alert("Error", "Chat ID cannot be empty.");
}
Alert.prompt(
"Join Chat",
"Enter the Chat ID (example: co_zBGEHYvRfGuT2YSBraY3njGjnde)",
[
{
text: "Cancel",
style: "cancel",
},
{
text: "Join",
onPress: (chatId) => {
if (chatId) {
setChatId(chatId as ID<Chat>);
} else {
Alert.alert("Error", "Chat ID cannot be empty.");
}
},
},
],
"plain-text",
);
};
const sendMessage = () => {
@@ -145,25 +160,9 @@ export default function ChatScreen({ navigation }: { navigation: any }) {
>
<Text className="text-white font-semibold">Start new chat</Text>
</TouchableOpacity>
<Text className="text-m font-bold mt-6">Join existing chat</Text>
<TextInput
className="rounded h-12 p-2 m-2 mt-4 w-80 border border-gray-200 block"
placeholder="Chat ID"
value={chatIdInput ?? ""}
onChangeText={(value) => {
setChatIdInput(value);
}}
textAlignVertical="center"
onSubmitEditing={() => {
if (chatIdInput) {
setChatId(chatIdInput as ID<Chat>);
}
}}
testID="chat-id-input"
/>
<TouchableOpacity
onPress={joinChat}
className="bg-green-500 p-4 rounded-md"
className="bg-green-500 p-4 rounded-md mt-4"
>
<Text className="text-white font-semibold">Join chat</Text>
</TouchableOpacity>
@@ -173,6 +172,7 @@ export default function ChatScreen({ navigation }: { navigation: any }) {
<FlatList
contentContainerStyle={{
flexGrow: 1,
flex: 1,
gap: 6,
padding: 8,
}}

View File

@@ -9,8 +9,6 @@ appId: com.jazz.chatrn
# - tapOn: "Reload"
# login
- assertVisible: "Logout"
- tapOn: "Logout"
- assertVisible: "Anonymous user"
- runFlow:
label: "Erase existing username"
@@ -44,11 +42,9 @@ appId: com.jazz.chatrn
# logout
- tapOn: "Logout"
- assertVisible: "Anonymous user"
# join chat
- tapOn:
id: "chat-id-input"
- inputText: "co_zFs6KFyhxPw4xtw83tcEMzeHUNv" # Use a static id because maestro doesn't have access to the system clipboard
- tapOn: "Join chat"
- assertVisible: "boorad"
- assertVisible: "bro, low key, it do be like that tho"
# This doesn't work on CI, maybe because Android has a different alert dialog
# - tapOn: "Join chat"
# - inputText: "co_zFs6KFyhxPw4xtw83tcEMzeHUNv" # Use a static id because maestro doesn't have access to the system clipboard
# - pressKey: "enter"
# - assertVisible: "boorad"
# - assertVisible: "bro, low key, it do be like that tho"

View File

@@ -1,79 +1,5 @@
# chat-rn
## 1.0.110
### Patch Changes
- Updated dependencies [6b781cf]
- Updated dependencies [02a240c]
- cojson@0.13.23
- jazz-tools@0.13.23
- cojson-transport-ws@0.13.23
- jazz-react-native@0.13.23
## 1.0.109
### Patch Changes
- jazz-react-native@0.13.22
## 1.0.108
### Patch Changes
- Updated dependencies [e14e61f]
- cojson@0.13.21
- cojson-transport-ws@0.13.21
- jazz-react-native@0.13.21
- jazz-tools@0.13.21
## 1.0.107
### Patch Changes
- Updated dependencies [adfc9a6]
- Updated dependencies [1389207]
- Updated dependencies [d6e143e]
- Updated dependencies [439f0fe]
- Updated dependencies [3e6229d]
- cojson@0.13.20
- jazz-tools@0.13.20
- jazz-react-native@0.13.20
- cojson-transport-ws@0.13.20
## 1.0.106
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react-native@0.13.19
## 1.0.105
### Patch Changes
- Updated dependencies [9089252]
- Updated dependencies [b470f63]
- Updated dependencies [761759c]
- Updated dependencies [66373ba]
- Updated dependencies [f24cad1]
- cojson@0.13.18
- jazz-tools@0.13.18
- cojson-transport-ws@0.13.18
- jazz-react-native@0.13.18
## 1.0.104
### Patch Changes
- Updated dependencies [9fb98e2]
- Updated dependencies [0b89fad]
- cojson@0.13.17
- cojson-transport-ws@0.13.17
- jazz-react-native@0.13.17
- jazz-tools@0.13.17
## 1.0.103
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn",
"version": "1.0.110",
"version": "1.0.103",
"main": "index.js",
"scripts": {
"android": "react-native run-android",

View File

@@ -1,57 +1,5 @@
# chat-vue
## 0.0.93
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-browser@0.13.23
- jazz-vue@0.13.23
## 0.0.92
### Patch Changes
- jazz-browser@0.13.21
- jazz-tools@0.13.21
- jazz-vue@0.13.21
## 0.0.91
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-browser@0.13.20
- jazz-vue@0.13.20
## 0.0.90
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-browser@0.13.19
- jazz-vue@0.13.19
## 0.0.89
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-browser@0.13.18
- jazz-vue@0.13.18
## 0.0.88
### Patch Changes
- jazz-browser@0.13.17
- jazz-tools@0.13.17
- jazz-vue@0.13.17
## 0.0.87
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-vue",
"version": "0.0.93",
"version": "0.0.87",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,58 +1,5 @@
# jazz-example-chat
## 0.0.191
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-inspector@0.13.23
- jazz-react@0.13.23
## 0.0.190
### Patch Changes
- Updated dependencies [7de210f]
- jazz-inspector@0.13.21
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.189
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-inspector@0.13.20
- jazz-react@0.13.20
## 0.0.188
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-inspector@0.13.19
- jazz-react@0.13.19
## 0.0.187
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-inspector@0.13.18
- jazz-react@0.13.18
## 0.0.186
### Patch Changes
- jazz-inspector@0.13.17
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.185
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat",
"private": true,
"version": "0.0.191",
"version": "0.0.185",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,57 +1,5 @@
# minimal-auth-clerk
## 0.0.90
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
- jazz-react-auth-clerk@0.13.23
## 0.0.89
### Patch Changes
- jazz-react@0.13.21
- jazz-react-auth-clerk@0.13.21
- jazz-tools@0.13.21
## 0.0.88
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
- jazz-react-auth-clerk@0.13.20
## 0.0.87
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
- jazz-react-auth-clerk@0.13.19
## 0.0.86
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
- jazz-react-auth-clerk@0.13.18
## 0.0.85
### Patch Changes
- jazz-react@0.13.17
- jazz-react-auth-clerk@0.13.17
- jazz-tools@0.13.17
## 0.0.84
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "clerk",
"private": true,
"version": "0.0.90",
"version": "0.0.84",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,61 +1,5 @@
# file-share-svelte
## 0.0.74
### Patch Changes
- Updated dependencies [ec546b4]
- jazz-svelte@0.13.24
## 0.0.73
### Patch Changes
- Updated dependencies [3431076]
- Updated dependencies [02a240c]
- jazz-svelte@0.13.23
- jazz-tools@0.13.23
- jazz-inspector-element@0.13.23
## 0.0.72
### Patch Changes
- jazz-inspector-element@0.13.21
- jazz-svelte@0.13.21
- jazz-tools@0.13.21
## 0.0.71
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-svelte@0.13.20
## 0.0.70
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-svelte@0.13.19
## 0.0.69
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-svelte@0.13.18
## 0.0.68
### Patch Changes
- jazz-svelte@0.13.17
- jazz-tools@0.13.17
## 0.0.67
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "file-share-svelte",
"version": "0.0.74",
"version": "0.0.67",
"private": true,
"type": "module",
"scripts": {
@@ -39,7 +39,6 @@
},
"dependencies": {
"@tailwindcss/typography": "^0.5.15",
"jazz-inspector-element": "workspace:*",
"jazz-svelte": "workspace:*",
"jazz-tools": "workspace:*",
"lucide-svelte": "^0.463.0",

View File

@@ -3,8 +3,9 @@
import { SharedFile } from '$lib/schema';
import { FileStream } from 'jazz-tools';
import { File, FileDown, Trash2, Link2 } from 'lucide-svelte';
import { useAccount } from 'jazz-svelte';
import { toast } from 'svelte-sonner';
import { downloadFileBlob, formatFileSize } from '$lib/utils';
import { formatFileSize } from '$lib/utils';
const {
file,
@@ -16,22 +17,32 @@
onDelete: (file: SharedFile) => void;
} = $props();
const isAdmin = $derived(file._owner?.myRole() === 'admin');
const fileStreamId = $derived(file._refs.file?.id);
const { me } = useAccount();
const isAdmin = $derived(me && file._owner?.myRole() === 'admin');
async function downloadFile() {
if (!fileStreamId) {
if (!file._refs.file?.id || !me) {
toast.error('Failed to download file');
return;
}
try {
const blob = await FileStream.loadAsBlob(fileStreamId);
const fileId = file._refs.file.id;
// Load the file as a blob, can take a while
const blob = await FileStream.loadAsBlob(fileId, me, {});
if (!blob) {
toast.error('Failed to download file');
return;
}
downloadFileBlob(blob, file.name);
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = file.name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
toast.success('File downloaded successfully');
} catch (error) {
console.error('Error downloading file:', error);
@@ -55,19 +66,14 @@
class="flex items-center justify-between rounded-lg border border-gray-200 bg-white p-4"
transition:slide={{ duration: 200 }}
>
<div class="flex items-center space-x-4 flex-grow">
<div class="flex items-center space-x-4">
<div class="flex h-10 w-10 items-center justify-center rounded-lg bg-blue-100 text-blue-600">
<File class="h-6 w-6" />
</div>
<div class="flex-grow">
{#if isAdmin}
<label class="sr-only" for={`file-name-${file.id}`}>File name</label>
<!-- Jazz values are reactive, but they are not recognized as reactive by Svelte -->
<!-- svelte-ignore binding_property_non_reactive -->
<input class="font-medium text-gray-900 w-full py-1" type="text" bind:value={file.name} id={`file-name-${file.id}`} />
{:else}
<div>
<a href="/file/{file.id}" class="hover:text-blue-600 hover:underline">
<h3 class="font-medium text-gray-900">{file.name}</h3>
{/if}
</a>
<p class="text-sm text-gray-500">
{isAdmin ? 'Owned by you' : ''} • Uploaded {new Date(
file.createdAt || 0

View File

@@ -15,8 +15,9 @@ export class FileShareProfile extends Profile {
export class ListOfSharedFiles extends CoList.Of(co.ref(SharedFile)) {}
export class FileShareAccountRoot extends CoMap {
type = co.literal('file-share-account');
type = co.string;
sharedFiles = co.ref(ListOfSharedFiles);
publicGroup = co.ref(Group);
}
export class FileShareAccount extends Account {
@@ -30,7 +31,7 @@ export class FileShareAccount extends Account {
await this._refs.root?.load();
// Initialize root if it doesn't exist
if (this.root === undefined || this.root?.type !== 'file-share-account') {
if (!this.root || this.root.type !== 'file-share-account') {
// Create a group that will own all shared files
const publicGroup = Group.create({ owner: this });
publicGroup.addMember('everyone', 'reader');
@@ -39,7 +40,9 @@ export class FileShareAccount extends Account {
{
type: 'file-share-account',
sharedFiles: ListOfSharedFiles.create([], { owner: publicGroup }),
publicGroup
},
{ owner: this }
);
}
}

View File

@@ -20,13 +20,3 @@ export function formatFileSize(bytes: number): string {
export function generateTempFileId(fileName: string | undefined, createdAt: Date | undefined): string {
return `file-${fileName ?? 'unknown'}-${createdAt?.getTime() ?? 0}`;
}
export function downloadFileBlob(blob: Blob, fileName: string) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}

View File

@@ -8,8 +8,7 @@
<script lang="ts">
import { JazzProvider } from 'jazz-svelte';
import "jazz-inspector-element"
import { PasskeyAuthBasicUI } from 'jazz-svelte';
import { PasskeyAuthBasicUI, usePasskeyAuth } from 'jazz-svelte';
import { Toaster } from 'svelte-sonner';
import '../app.css';
import { FileShareAccount } from '$lib/schema';
@@ -30,7 +29,6 @@
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
}}
>
<jazz-inspector></jazz-inspector>
<PasskeyAuthBasicUI appName="File Share">
<div class="min-h-screen bg-gray-100">
{@render children()}

View File

@@ -1,38 +1,54 @@
<script lang="ts">
import { AccountCoState } from 'jazz-svelte';
import { SharedFile } from '$lib/schema';
import { useAccount, useCoState } from 'jazz-svelte';
import { SharedFile, ListOfSharedFiles } from '$lib/schema';
import { createInviteLink } from 'jazz-svelte';
import { FileStream } from 'jazz-tools';
import FileItem from '$lib/components/FileItem.svelte';
import { SvelteMap } from 'svelte/reactivity';
import { generateTempFileId } from '$lib/utils';
import { CloudUpload } from 'lucide-svelte';
const me = new AccountCoState({
resolve: {
profile: true,
root: {
sharedFiles: {
$each: true
},
}
}
});
const { me, logOut } = useAccount();
const sharedFiles = $derived(me.current?.root.sharedFiles);
const mySharedFilesId = me?.root?._refs.sharedFiles.id;
const sharedFiles = $derived(useCoState(ListOfSharedFiles, mySharedFilesId, [{}]));
let fileInput: HTMLInputElement;
type PendingSharedFile = {
name: string;
id: string;
createdAt: Date;
};
// Track files that are currently uploading
const uploadingFiles = new SvelteMap<string, PendingSharedFile>();
async function handleFileUpload(event: Event) {
const input = event.target as HTMLInputElement;
const files = input.files;
if (!files?.length || !sharedFiles) return;
if (!files || !files.length || !me.root?.sharedFiles || !me.root.publicGroup) return;
const file = files[0];
const fileName = file.name;
const createdAt = new Date();
const fileId = generateTempFileId(fileName, createdAt);
const tempFile: PendingSharedFile = {
name: fileName,
id: fileId,
createdAt
};
// Add to uploading files
uploadingFiles.set(fileId, tempFile);
try {
const ownership = { owner: me.root.publicGroup };
// Create a FileStream from the uploaded file
const fileStream = await FileStream.createFromBlob(file, sharedFiles._owner);
const fileStream = await FileStream.createFromBlob(file, ownership);
// Create the shared file entry
const sharedFile = SharedFile.create(
@@ -43,22 +59,29 @@
uploadedAt: new Date(),
size: file.size
},
sharedFiles._owner
ownership
);
// Add the file to the user's files list
sharedFiles.push(sharedFile);
me.root.sharedFiles.push(sharedFile);
} finally {
uploadingFiles.delete(fileId);
fileInput.value = ''; // reset input
}
}
async function deleteFile(file: SharedFile) {
if (!sharedFiles) return;
async function shareFile(file: SharedFile) {
const inviteLink = createInviteLink(file, 'reader');
await navigator.clipboard.writeText(inviteLink);
alert('Share link copied to clipboard!');
}
const index = sharedFiles.indexOf(file);
async function deleteFile(file: SharedFile) {
if (!me?.root?.sharedFiles || !sharedFiles.current) return;
const index = sharedFiles.current.indexOf(file);
if (index > -1) {
sharedFiles.splice(index, 1);
me.root.sharedFiles.splice(index, 1);
}
}
</script>
@@ -68,11 +91,11 @@
<div class="mb-12 flex items-center justify-between">
<div>
<h1 class="mb-2 text-4xl font-bold text-gray-900">File Share</h1>
<h2 class="text-xl text-gray-600">Welcome back, {me.current?.profile.name}</h2>
<h2 class="text-xl text-gray-600">Welcome back, {me?.profile?.name}</h2>
</div>
<button
onclick={me.logOut}
onclick={logOut}
class="rounded-lg bg-red-500 px-6 py-2.5 text-sm font-medium text-white transition-colors hover:bg-red-600 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2"
>
Log Out
@@ -103,12 +126,14 @@
<!-- Files List -->
<div class="space-y-4">
{#if sharedFiles}
{#if sharedFiles.length}
{#each sharedFiles as file}
{#if sharedFiles.current}
{#if !(sharedFiles.current.length === 0 && uploadingFiles.size === 0)}
{#each [...sharedFiles.current, ...uploadingFiles.values()] as file (generateTempFileId(file?.name, file?.createdAt))}
{#if file}
<FileItem
{file}
loading={uploadingFiles.has(generateTempFileId(file?.name, file?.createdAt))}
onShare={shareFile}
onDelete={deleteFile}
/>
{/if}

View File

@@ -1,33 +1,39 @@
<script lang="ts">
import { page } from '$app/stores';
import { CoState } from 'jazz-svelte';
import { useAccount, useCoState } from 'jazz-svelte';
import { SharedFile } from '$lib/schema';
import { File, FileDown, Link2 } from 'lucide-svelte';
import type { ID } from 'jazz-tools';
import { FileStream } from 'jazz-tools';
import { toast } from 'svelte-sonner';
import { downloadFileBlob } from '$lib/utils';
const { me } = useAccount();
const fileId = $page.params.fileId;
const file = $derived(new CoState(SharedFile, fileId as ID<SharedFile>));
const isAdmin = $derived(file.current?._owner?.myRole() === 'admin');
const fileStreamId = $derived(file.current?._refs.file?.id);
const file = $state(useCoState(SharedFile, fileId as ID<SharedFile>, {}));
const isAdmin = $derived(me && file.current?._owner?.myRole() === 'admin');
async function downloadFile() {
if (!fileStreamId || !file.current) {
if (!file.current?._refs.file?.id || !me) {
toast.error('Failed to download file');
return;
}
try {
const blob = await FileStream.loadAsBlob(fileStreamId);
const fileId = file.current._refs.file.id;
const blob = await FileStream.loadAsBlob(fileId, me, {});
if (!blob) {
toast.error('Failed to download file');
return;
}
downloadFileBlob(blob, file.current.name);
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = file.current.name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
toast.success('File downloaded successfully');
} catch (error) {
console.error('Error downloading file:', error);

View File

@@ -59,7 +59,7 @@ test('can login with passkey and upload file', async ({ page, browser }) => {
await fileChooser.setFiles(filePath);
// Verify the uploaded file appears in the list
await expect(page.getByRole("textbox", { name: "File name" })).toHaveValue("test-file.txt");
await expect(page.getByText('test-file.txt')).toBeVisible();
await page.getByRole('button', { name: 'Share file' }).click();
const inviteLink = await page.evaluate(() => navigator.clipboard.readText());

View File

@@ -1,58 +1,5 @@
# jazz-tailwind-demo-auth-starter
## 0.0.30
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-inspector@0.13.23
- jazz-react@0.13.23
## 0.0.29
### Patch Changes
- Updated dependencies [7de210f]
- jazz-inspector@0.13.21
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.28
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-inspector@0.13.20
- jazz-react@0.13.20
## 0.0.27
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-inspector@0.13.19
- jazz-react@0.13.19
## 0.0.26
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-inspector@0.13.18
- jazz-react@0.13.18
## 0.0.25
### Patch Changes
- jazz-inspector@0.13.17
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.24
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "filestream",
"private": true,
"version": "0.0.30",
"version": "0.0.24",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -189,7 +189,7 @@ export function FileWidget() {
);
}
const fileData = me?.profile?.file?.getMetadata();
const fileData = me?.profile?.file?.getChunks();
const mimeType = fileData?.mimeType || "unknown";
return (

View File

@@ -1,51 +1,5 @@
# form
## 0.1.31
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.1.30
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.1.29
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.1.28
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.1.27
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.1.26
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.1.25
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "form",
"private": true,
"version": "0.1.31",
"version": "0.1.25",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,51 +1,5 @@
# image-upload
## 0.0.87
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.86
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.85
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.84
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.83
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.82
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.81
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "image-upload",
"private": true,
"version": "0.0.87",
"version": "0.0.81",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,64 +1,5 @@
# jazz-example-inspector
## 0.0.141
### Patch Changes
- Updated dependencies [6b781cf]
- cojson@0.13.23
- cojson-transport-ws@0.13.23
- jazz-inspector@0.13.23
## 0.0.140
### Patch Changes
- Updated dependencies [7de210f]
- Updated dependencies [e14e61f]
- jazz-inspector@0.13.21
- cojson@0.13.21
- cojson-transport-ws@0.13.21
## 0.0.139
### Patch Changes
- Updated dependencies [adfc9a6]
- Updated dependencies [1389207]
- Updated dependencies [d6e143e]
- Updated dependencies [3e6229d]
- cojson@0.13.20
- cojson-transport-ws@0.13.20
- jazz-inspector@0.13.20
## 0.0.138
### Patch Changes
- jazz-inspector@0.13.19
## 0.0.137
### Patch Changes
- Updated dependencies [9089252]
- Updated dependencies [b470f63]
- Updated dependencies [66373ba]
- Updated dependencies [f24cad1]
- cojson@0.13.18
- cojson-transport-ws@0.13.18
- jazz-inspector@0.13.18
## 0.0.136
### Patch Changes
- Updated dependencies [9fb98e2]
- Updated dependencies [0b89fad]
- cojson@0.13.17
- cojson-transport-ws@0.13.17
- jazz-inspector@0.13.17
## 0.0.135
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-inspector-app",
"private": true,
"version": "0.0.141",
"version": "0.0.135",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -8,10 +8,7 @@ export function cn(...inputs: ClassValue[]) {
/**
* Given a player selections, returns the winner of the current game.
*/
export function determineWinner(
player1Choice: "rock" | "paper" | "scissors",
player2Choice: "rock" | "paper" | "scissors",
) {
export function determineWinner(player1Choice: string, player2Choice: string) {
if (player1Choice === player2Choice) {
return "draw";
} else if (

View File

@@ -14,7 +14,7 @@ import { type ID } from "jazz-tools";
import { Badge, CircleHelp, Scissors, ScrollText } from "lucide-react";
import { useEffect, useState } from "react";
const playIcon = (selection: "rock" | "paper" | "scissors" | undefined) => {
const playIcon = (selection: string | undefined) => {
switch (selection) {
case "rock":
return <Badge className="w-5 h-5" />;
@@ -50,9 +50,9 @@ function RouteComponent() {
const isPlayer1 = loaderGame.player1?.account?.isMe;
const player = isPlayer1 ? "player1" : "player2";
const [playSelection, setPlaySelection] = useState<
"rock" | "paper" | "scissors" | undefined
>(loaderGame[player]?.playSelection);
const [playSelection, setPlaySelection] = useState(
loaderGame[player]?.playSelection ?? "",
);
const sendInboxMessage = experimental_useInboxSender(WORKER_ID);
const game = useCoState(Game, gameId as ID<Game>);
@@ -62,7 +62,7 @@ function RouteComponent() {
return loaderGame.subscribe((game) => {
if (gameCompleted && !game.outcome) {
setPlaySelection(undefined); // Reset play selection when one player clicks on "Start a new game"
setPlaySelection(""); // Reset play selection when one player clicks on "Start a new game"
}
gameCompleted = Boolean(game.outcome);
@@ -82,10 +82,7 @@ function RouteComponent() {
const opponentSelection = opponentPlayer?.playSelection;
const onSubmit = async (
playSelection: "rock" | "paper" | "scissors" | undefined,
) => {
if (!playSelection) return;
const onSubmit = async (playSelection: string) => {
sendInboxMessage(
PlayIntent.create({ type: "play", gameId, player, playSelection }),
);
@@ -120,9 +117,7 @@ function RouteComponent() {
) : null}
<CardContent>
<div>
{playSelection === undefined
? "Make Your Selection"
: "Your Selection: "}
{playSelection === "" ? "Make Your Selection" : "Your Selection: "}
</div>
<CardSmall>{playIcon(playSelection)}</CardSmall>
{gameComplete ? null : (
@@ -153,7 +148,7 @@ function RouteComponent() {
<div className="m-4">
<Button
disabled={
playSelection === undefined ||
playSelection === "" ||
Boolean(currentPlayer?.playSelection)
}
onClick={() => onSubmit(playSelection)}

View File

@@ -30,7 +30,7 @@ export class Game extends CoMap {
export class Player extends CoMap {
account = co.ref(Account);
playSelection? = co.literal("rock", "paper", "scissors");
playSelection? = co.string;
}
export class WaitingRoom extends CoMap {
@@ -47,7 +47,7 @@ export class PlayIntent extends InboxMessage {
type = co.literal("play");
gameId = co.string;
player = co.literal("player1", "player2");
playSelection = co.literal("rock", "paper", "scissors");
playSelection = co.string;
}
export class NewGameIntent extends InboxMessage {

View File

@@ -186,9 +186,9 @@ async function handlePlayIntent(_: ID<Account>, message: PlayIntent) {
// once both players have a selection, determine the winner
if (
!!player1Selection &&
player1Selection !== undefined &&
player1Selection !== "" &&
!!player2Selection &&
player2Selection !== undefined
player2Selection !== ""
) {
const outcome = determineWinner(player1Selection, player2Selection);
game.outcome = outcome;

View File

@@ -1,51 +1,5 @@
# multi-cursors
## 0.0.83
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.82
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.81
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.80
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.79
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.78
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.77
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "multi-cursors",
"private": true,
"version": "0.0.83",
"version": "0.0.77",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,57 +1,5 @@
# multiauth
## 0.0.31
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
- jazz-react-auth-clerk@0.13.23
## 0.0.30
### Patch Changes
- jazz-react@0.13.21
- jazz-react-auth-clerk@0.13.21
- jazz-tools@0.13.21
## 0.0.29
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
- jazz-react-auth-clerk@0.13.20
## 0.0.28
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
- jazz-react-auth-clerk@0.13.19
## 0.0.27
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
- jazz-react-auth-clerk@0.13.18
## 0.0.26
### Patch Changes
- jazz-react@0.13.17
- jazz-react-auth-clerk@0.13.17
- jazz-tools@0.13.17
## 0.0.25
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "multiauth",
"private": true,
"version": "0.0.31",
"version": "0.0.25",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,58 +1,5 @@
# jazz-example-musicplayer
## 0.0.112
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-inspector@0.13.23
- jazz-react@0.13.23
## 0.0.111
### Patch Changes
- Updated dependencies [7de210f]
- jazz-inspector@0.13.21
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.110
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-inspector@0.13.20
- jazz-react@0.13.20
## 0.0.109
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-inspector@0.13.19
- jazz-react@0.13.19
## 0.0.108
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-inspector@0.13.18
- jazz-react@0.13.18
## 0.0.107
### Patch Changes
- jazz-inspector@0.13.17
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.106
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-music-player",
"private": true,
"version": "0.0.112",
"version": "0.0.106",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,51 +1,5 @@
# organization
## 0.0.83
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.82
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.81
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.80
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.79
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.78
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.77
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "organization",
"private": true,
"version": "0.0.83",
"version": "0.0.77",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,59 +1,5 @@
# passkey-svelte
## 0.0.78
### Patch Changes
- Updated dependencies [ec546b4]
- jazz-svelte@0.13.24
## 0.0.77
### Patch Changes
- Updated dependencies [3431076]
- Updated dependencies [02a240c]
- jazz-svelte@0.13.23
- jazz-tools@0.13.23
## 0.0.76
### Patch Changes
- jazz-svelte@0.13.21
- jazz-tools@0.13.21
## 0.0.75
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-svelte@0.13.20
## 0.0.74
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-svelte@0.13.19
## 0.0.73
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-svelte@0.13.18
## 0.0.72
### Patch Changes
- jazz-svelte@0.13.17
- jazz-tools@0.13.17
## 0.0.71
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "passkey-svelte",
"version": "0.0.78",
"version": "0.0.71",
"type": "module",
"private": true,
"scripts": {

View File

@@ -1,51 +1,5 @@
# minimal-auth-passkey
## 0.0.88
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.87
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.86
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.85
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.84
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.83
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.82
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passkey",
"private": true,
"version": "0.0.88",
"version": "0.0.82",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,51 +1,5 @@
# passphrase
## 0.0.85
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.84
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.83
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.82
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.81
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.80
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.79
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passphrase",
"private": true,
"version": "0.0.85",
"version": "0.0.79",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,51 +1,5 @@
# jazz-password-manager
## 0.0.109
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.108
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.107
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.106
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.105
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.104
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.103
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-password-manager",
"private": true,
"version": "0.0.109",
"version": "0.0.103",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,51 +1,5 @@
# jazz-example-pets
## 0.0.207
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.206
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.205
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.204
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.203
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.202
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.201
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-pets",
"private": true,
"version": "0.0.207",
"version": "0.0.201",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,51 +1,5 @@
# reactions
## 0.0.87
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.86
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.85
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.84
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.83
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.82
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.81
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "reactions",
"private": true,
"version": "0.0.87",
"version": "0.0.81",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,59 +1,5 @@
# richtext
## 0.0.77
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
- jazz-richtext-prosemirror@0.1.11
## 0.0.76
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
- jazz-richtext-prosemirror@0.1.10
## 0.0.75
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
- jazz-richtext-prosemirror@0.1.9
## 0.0.74
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
- jazz-richtext-prosemirror@0.1.8
## 0.0.73
### Patch Changes
- Updated dependencies [761759c]
- Updated dependencies [133b8ab]
- jazz-tools@0.13.18
- jazz-richtext-prosemirror@0.1.7
- jazz-react@0.13.18
## 0.0.72
### Patch Changes
- Updated dependencies [133b8ab]
- jazz-richtext-prosemirror@0.1.6
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.71
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "richtext",
"private": true,
"version": "0.0.77",
"version": "0.0.71",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,57 +1,5 @@
# todo-vue
## 0.0.91
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-browser@0.13.23
- jazz-vue@0.13.23
## 0.0.90
### Patch Changes
- jazz-browser@0.13.21
- jazz-tools@0.13.21
- jazz-vue@0.13.21
## 0.0.89
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-browser@0.13.20
- jazz-vue@0.13.20
## 0.0.88
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-browser@0.13.19
- jazz-vue@0.13.19
## 0.0.87
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-browser@0.13.18
- jazz-vue@0.13.18
## 0.0.86
### Patch Changes
- jazz-browser@0.13.17
- jazz-tools@0.13.17
- jazz-vue@0.13.17
## 0.0.85
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "todo-vue",
"version": "0.0.91",
"version": "0.0.85",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,51 +1,5 @@
# jazz-example-todo
## 0.0.206
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-react@0.13.23
## 0.0.205
### Patch Changes
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.204
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-react@0.13.20
## 0.0.203
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-react@0.13.19
## 0.0.202
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-react@0.13.18
## 0.0.201
### Patch Changes
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.200
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-todo",
"private": true,
"version": "0.0.206",
"version": "0.0.200",
"type": "module",
"scripts": {
"dev": "vite",
@@ -11,7 +11,6 @@
"preview": "vite preview"
},
"dependencies": {
"@faker-js/faker": "^9.7.0",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-toast": "^1.1.4",

View File

@@ -41,9 +41,12 @@ export class TodoAccount extends Account {
*/
migrate() {
if (!this._refs.root) {
this.root = TodoAccountRoot.create({
projects: ListOfProjects.create([]),
});
this.root = TodoAccountRoot.create(
{
projects: ListOfProjects.create([], { owner: this }),
},
{ owner: this },
);
}
}
}

View File

@@ -23,7 +23,6 @@ import {
ThemeProvider,
TitleAndLogo,
} from "./basicComponents/index.ts";
import { TaskGenerator } from "./components/TaskGenerator.tsx";
import { wordlist } from "./wordlist.ts";
/**
@@ -96,10 +95,6 @@ export default function App() {
path: "/invite/*",
element: <p>Accepting invite...</p>,
},
{
path: "/generate",
element: <TaskGenerator />,
},
]);
// `useAcceptInvite()` is a hook that accepts an invite link from the URL hash,

View File

@@ -35,11 +35,7 @@ export function ProjectTodoTable() {
// content - whether we create edits locally, load persisted data, or receive
// sync updates from other devices or participants!
// It also recursively resolves and subsribes to all referenced CoValues.
const project = useCoState(TodoProject, projectId, {
resolve: {
tasks: true,
},
});
const project = useCoState(TodoProject, projectId);
// `createTask` is similar to `createProject` we saw earlier, creating a new CoMap
// for a new task (in the same group as the project), and then

View File

@@ -1,61 +0,0 @@
import { TodoAccount } from "@/1_schema";
import { FormEvent, useState } from "react";
import { useNavigate } from "react-router-dom";
import { generateRandomProject } from "../generate";
export function TaskGenerator() {
const [isGenerating, setIsGenerating] = useState(false);
const navigate = useNavigate();
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const numTasks = Math.max(
1,
parseInt(formData.get("numTasks") as string) || 1,
);
setIsGenerating(true);
const project = generateRandomProject(numTasks);
const { root } = await TodoAccount.getMe().ensureLoaded({
resolve: {
root: {
projects: true,
},
},
});
root.projects.push(project);
navigate(`/project/${project.id}`);
};
return (
<div className="p-4 border rounded-lg shadow-sm bg-white">
<h2 className="text-lg font-semibold mb-4">Generate Random Tasks</h2>
<form onSubmit={handleSubmit} className="flex flex-col gap-4">
<div className="flex items-center gap-2">
<label htmlFor="numTasks" className="text-sm font-medium">
Number of tasks:
</label>
<input
id="numTasks"
name="numTasks"
type="number"
min="1"
defaultValue={5}
className="w-20 px-2 py-1 border rounded"
/>
</div>
<button
type="submit"
disabled={isGenerating}
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:bg-blue-300"
>
{isGenerating ? "Generating..." : "Generate Tasks"}
</button>
</form>
</div>
);
}

View File

@@ -1,25 +0,0 @@
import { faker } from "@faker-js/faker";
import { ListOfTasks, Task, TodoProject } from "./1_schema";
export function generateRandomProject(numTasks: number): TodoProject {
// Generate a random project title
const projectTitle = faker.company.catchPhrase();
// Create a list of tasks
const tasks = ListOfTasks.create([]);
// Generate random tasks
for (let i = 0; i < numTasks; i++) {
const task = Task.create({
done: faker.datatype.boolean(),
text: faker.lorem.sentence({ min: 3, max: 8 }),
});
tasks.push(task);
}
// Create and return the project
return TodoProject.create({
title: projectTitle,
tasks: tasks,
});
}

View File

@@ -1,58 +1,5 @@
# version-history
## 0.0.85
### Patch Changes
- Updated dependencies [02a240c]
- jazz-tools@0.13.23
- jazz-inspector@0.13.23
- jazz-react@0.13.23
## 0.0.84
### Patch Changes
- Updated dependencies [7de210f]
- jazz-inspector@0.13.21
- jazz-react@0.13.21
- jazz-tools@0.13.21
## 0.0.83
### Patch Changes
- Updated dependencies [439f0fe]
- jazz-tools@0.13.20
- jazz-inspector@0.13.20
- jazz-react@0.13.20
## 0.0.82
### Patch Changes
- Updated dependencies [80530a4]
- jazz-tools@0.13.19
- jazz-inspector@0.13.19
- jazz-react@0.13.19
## 0.0.81
### Patch Changes
- Updated dependencies [761759c]
- jazz-tools@0.13.18
- jazz-inspector@0.13.18
- jazz-react@0.13.18
## 0.0.80
### Patch Changes
- jazz-inspector@0.13.17
- jazz-react@0.13.17
- jazz-tools@0.13.17
## 0.0.79
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "version-history",
"private": true,
"version": "0.0.85",
"version": "0.0.79",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -22,7 +22,7 @@ export function JazzLogo({
fillRule="evenodd"
clipRule="evenodd"
d="M136.179 44.8277C136.179 44.8277 136.179 44.8277 136.179 44.8276V21.168C117.931 28.5527 97.9854 32.6192 77.0897 32.6192C65.1466 32.6192 53.5138 31.2908 42.331 28.7737V51.4076C42.331 51.4076 42.331 51.4076 42.331 51.4076V81.1508C41.2955 80.4385 40.1568 79.8458 38.9405 79.3915C36.1732 78.358 33.128 78.0876 30.1902 78.6145C27.2524 79.1414 24.5539 80.4419 22.4358 82.3516C20.3178 84.2613 18.8754 86.6944 18.291 89.3433C17.7066 91.9921 18.0066 94.7377 19.1528 97.2329C20.2991 99.728 22.2403 101.861 24.7308 103.361C27.2214 104.862 30.1495 105.662 33.1448 105.662H33.1455C33.6061 105.662 33.8365 105.662 34.0314 105.659C44.5583 105.449 53.042 96.9656 53.2513 86.4386C53.2534 86.3306 53.2544 86.2116 53.2548 86.0486H53.2552V85.7149L53.2552 85.5521V82.0762L53.2552 53.1993C61.0533 54.2324 69.0092 54.7656 77.0897 54.7656C77.6696 54.7656 78.2489 54.7629 78.8276 54.7574V110.696C77.792 109.983 76.6533 109.391 75.437 108.936C72.6697 107.903 69.6246 107.632 66.6867 108.159C63.7489 108.686 61.0504 109.987 58.9323 111.896C56.8143 113.806 55.3719 116.239 54.7875 118.888C54.2032 121.537 54.5031 124.283 55.6494 126.778C56.7956 129.273 58.7368 131.405 61.2273 132.906C63.7179 134.406 66.646 135.207 69.6414 135.207C70.1024 135.207 70.3329 135.207 70.5279 135.203C81.0548 134.994 89.5385 126.51 89.7478 115.983C89.7517 115.788 89.7517 115.558 89.7517 115.097V111.621L89.7517 54.3266C101.962 53.4768 113.837 51.4075 125.255 48.2397V80.9017C124.219 80.1894 123.081 79.5966 121.864 79.1424C119.097 78.1089 116.052 77.8384 113.114 78.3653C110.176 78.8922 107.478 80.1927 105.36 82.1025C103.242 84.0122 101.799 86.4453 101.215 89.0941C100.631 91.743 100.931 94.4886 102.077 96.9837C103.223 99.4789 105.164 101.612 107.655 103.112C110.145 104.612 113.073 105.413 116.069 105.413C116.53 105.413 116.76 105.413 116.955 105.409C127.482 105.2 135.966 96.7164 136.175 86.1895C136.179 85.9945 136.179 85.764 136.179 85.3029V81.8271L136.179 44.8277Z"
fill="#146AFF"
className="fill-primary"
/>
</svg>
);

View File

@@ -1,3 +1,5 @@
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ImageResponse } from "next/og";
import { JazzLogo } from "../atoms/logos/JazzLogo";
@@ -8,112 +10,28 @@ export const imageSize = {
export const imageContentType = "image/png";
async function loadManropeGoogleFont() {
const url = `https://fonts.googleapis.com/css2?family=Manrope:wght@600`;
const css = await (await fetch(url)).text();
const resource = css.match(
/src: url\((.+)\) format\('(opentype|truetype)'\)/,
export default async function OpenGraphImage({ title }: { title: string }) {
const manropeSemiBold = await readFile(
join(process.cwd(), "public/fonts/Manrope-SemiBold.ttf"),
);
if (resource) {
const response = await fetch(resource[1]);
if (response.status == 200) {
return await response.arrayBuffer();
}
}
throw new Error("failed to load font data");
}
export async function OpenGraphImage({
title,
framework,
contents,
topic,
subtopic,
}: {
title: string;
framework?: string;
contents?: string[];
topic?: string;
subtopic?: string;
}) {
if (!title) {
throw new Error(
`No title from tocItems in opengraph-image.tsx ${framework} ${topic} ${subtopic}`,
);
}
return new ImageResponse(
<div
style={{
fontSize: "7em",
background: "white",
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "center",
alignItems: "center",
justifyContent: "flex-start",
padding: "77px",
letterSpacing: "-0.05em",
}}
>
{title}
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: "1rem",
fontSize: "4rem",
}}
>
{title}
</div>
<div
style={{
position: "absolute",
right: 15,
top: 10,
display: "flex",
alignItems: "center",
justifyContent: "flex-start",
fontSize: "3rem",
color: "#888888",
letterSpacing: "-0.03em",
}}
>
<div style={{ display: "flex", color: "#BBB", paddingRight: "0.5rem" }}>
{framework}
</div>
{topic && (
<span style={{ color: "#CCC", paddingRight: "0.5rem" }}>
/ {topic}
</span>
)}
{subtopic && <span style={{ color: "#DDD" }}>/ {subtopic}</span>}
</div>
<div
style={{
display: "flex",
flexDirection: "column",
marginTop: "1rem",
gap: "0.2rem",
fontSize: "2rem",
color: "#888888",
letterSpacing: "-0.03em",
}}
>
{contents?.map((content) => (
<div key={content}>{content}</div>
))}
</div>
<div
style={{
display: "flex",
position: "absolute",
bottom: 35,
right: 45,
}}
style={{ display: "flex", position: "absolute", bottom: 35, right: 45 }}
>
<JazzLogo width={193} height={73} />
</div>
@@ -123,9 +41,7 @@ export async function OpenGraphImage({
fonts: [
{
name: "Manrope",
data: await loadManropeGoogleFont(),
style: "normal",
weight: 600,
data: manropeSemiBold,
},
],
},

View File

@@ -1,25 +0,0 @@
import { OpenGraphImage, imageSize, imageContentType } from '@garden-co/design-system/src/components/organisms/OpenGraphImage';
import { getMdxWithToc } from '@/lib/docMdxContent';
export const title = "Quickstart";
export const size = imageSize;
export const contentType = imageContentType;
export const alt = "Quickstart";
export default async function Image({ params }: { params: Promise<{ framework: string, topic: string, subtopic: string }> }) {
const { framework, topic, subtopic } = await params;
const { tocItems } = await getMdxWithToc(framework, [topic, subtopic]);
const title = tocItems[0]?.value;
if (!title) {
throw new Error(`No title from tocItems in opengraph-image.tsx ${framework} ${topic} ${subtopic}`);
}
return OpenGraphImage({
title: title,
framework,
contents: tocItems[0]?.children?.map((child) => child.value) ?? [],
topic,
subtopic,
});
}

View File

@@ -1,26 +0,0 @@
import { OpenGraphImage, imageSize, imageContentType } from '@garden-co/design-system/src/components/organisms/OpenGraphImage';
import { getMdxWithToc } from '@/lib/docMdxContent';
export const title = "Quickstart";
export const size = imageSize;
export const contentType = imageContentType;
export const alt = "Quickstart";
export default async function Image({ params }: { params: Promise<{ framework: string, topic: string }> }) {
const { framework, topic } = await params;
const { tocItems } = await getMdxWithToc(framework, [topic]);
// console.log('tocItems', tocItems);
const title = tocItems[0]?.value;
if (!title) {
throw new Error(`No title from tocItems in opengraph-image.tsx ${framework} ${topic}`);
}
return OpenGraphImage({
title: title,
framework,
contents: tocItems[0]?.children?.map((child) => child.value) ?? [],
topic,
});
}

View File

@@ -1,32 +0,0 @@
import { getMdxWithToc } from "@/lib/docMdxContent";
import {
OpenGraphImage,
imageSize,
imageContentType,
} from "@garden-co/design-system/src/components/organisms/OpenGraphImage";
export const title = "Quickstart";
export const size = imageSize;
export const contentType = imageContentType;
export const alt = "Jazz Docs | Quickstart";
export default async function Image({
params,
}: {
params: Promise<{ framework: string }>;
}) {
const { framework } = await params;
const { tocItems } = await getMdxWithToc(framework, []);
const title = tocItems[0]?.value;
if (!title) {
throw new Error(`No title from tocItems in opengraph-image.tsx ${framework}`);
}
return OpenGraphImage({
title: title,
framework,
contents: tocItems[0]?.children?.map((child) => child.value) ?? [],
});
}

View File

@@ -516,7 +516,7 @@ const reactExamples: Example[] = [
tech: [tech.react],
features: [features.serverWorker, features.inbox],
illustration: <JazzPaperScissorsIllustration />,
demoUrl: "https://jazz-paper-scissors.vercel.app",
demoUrl: "https://jazz-paper-scissors.vercel.app"
},
{
name: "Clerk",
@@ -552,7 +552,7 @@ const reactExamples: Example[] = [
tech: [tech.react],
features: [features.inviteLink],
illustration: <OrganizationIllustration />,
demoUrl: "https://jazz-organization.vercel.app",
demoUrl: "https://jazz-organization.vercel.app"
},
{
name: "Version history",
@@ -561,7 +561,7 @@ const reactExamples: Example[] = [
"Track and restore previous versions of your data, and see who made the changes.",
tech: [tech.react],
illustration: <VersionHistoryIllustration />,
demoUrl: "https://jazz-version-history.vercel.app",
demoUrl: "https://jazz-version-history.vercel.app"
},
];

View File

@@ -53,7 +53,6 @@ pre.shiki .line {
.twoslash-popup-code pre.shiki .line {
display: inline;
padding-left: 0;
white-space: break-spaces;
}
html.dark .shiki {

View File

@@ -1,6 +1,5 @@
import { marketingCopy } from "@/content/marketingCopy";
import {
OpenGraphImage,
import OpenGraphImage, {
imageSize,
imageContentType,
} from "@garden-co/design-system/src/components/organisms/OpenGraphImage";

View File

@@ -19,7 +19,8 @@ export default function DocsLayout({
navIcon?: IconName;
tocItems?: TocEntry[];
}) {
const tableOfContentsItems = tocItems ?? [];
const tableOfContentsItems =
tocItems?.length && tocItems[0].children ? tocItems[0].children : [];
const navSections: NavSection[] = [
{

View File

@@ -3,14 +3,13 @@
import type { Toc, TocEntry } from "@stefanprobst/rehype-extract-toc";
import { clsx } from "clsx";
import Link from "next/link";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useState } from "react";
const TocList = ({
items,
level,
currentId,
}: { items: Toc; level: number; currentId: string }) => {
const isActive = (item: TocEntry) => {
if (!item.id) return false;
if (item.id === currentId) return true;
@@ -21,7 +20,7 @@ const TocList = ({
};
return (
<ul className="space-y-2" style={{ paddingLeft: (level > 0) ? "1rem" : "0" }}>
<ul className="space-y-2" style={{ paddingLeft: level ? "1rem" : "0" }}>
{items.map((item) => (
<li key={item.id} className="space-y-2">
{item.id && (
@@ -58,10 +57,8 @@ export function TableOfContents({
}) {
const [currentId, setCurrentId] = useState<string>("");
const itemsUnderH1 = useMemo(() => items[0]?.children || [], [items]);
const getHeadings = useCallback(() => {
return itemsUnderH1
return items
.flatMap((node) => {
const headings = [node];
if (node.children) {
@@ -81,17 +78,17 @@ export function TableOfContents({
return { id: item.id, top };
})
.filter((x): x is { id: string; top: number } => x !== null);
}, [itemsUnderH1]);
}, [items]);
useEffect(() => {
if (itemsUnderH1.length === 0) return;
if (items.length === 0) return;
const onScroll = () => {
const headings = getHeadings();
if (headings.length === 0) return;
const top = window.scrollY;
let current = headings[0]?.id;
let current = headings[0].id;
for (const heading of headings) {
if (top >= heading.top - 500) {
@@ -101,7 +98,7 @@ export function TableOfContents({
}
}
current && setCurrentId(current);
setCurrentId(current);
};
window.addEventListener("scroll", onScroll, { passive: true });
@@ -110,14 +107,14 @@ export function TableOfContents({
return () => {
window.removeEventListener("scroll", onScroll);
};
}, [getHeadings, itemsUnderH1]);
}, [getHeadings, items]);
if (!itemsUnderH1.length) return null;
if (!items.length) return null;
return (
<div className={className}>
<p className="font-medium text-highlight mb-3">On this page</p>
<TocList items={itemsUnderH1} level={0} currentId={currentId} />
<TocList items={items} level={0} currentId={currentId} />
</div>
);
}

View File

@@ -1,8 +1,6 @@
```tsx
<JazzProvider
sync={{
peer: "wss://cloud.jazz.tools/?key=you@example.com"
}}
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }}
>
{children}
</JazzProvider>

View File

@@ -21,7 +21,7 @@ function Code({
<div
className={clsx(
className,
"w-full h-full relative -right-2 -bottom-1 max-w-full lg:max-w-[500px] ml-auto",
"w-full h-full relative -right-2 -bottom-1 max-w-full lg:max-w-[480px] overflow-x-auto ml-auto overflow-hidden",
"shadow-xl shadow-blue/20",
"rounded-tl-lg border",
"flex-1 bg-white ring ring-4 ring-stone-400/20",
@@ -33,9 +33,7 @@ function Code({
{fileName}
</span>
</div>
<pre className="text-xs lg:text-sm p-1 pb-2 overflow-x-auto">
{children}
</pre>
<pre className="text-xs lg:text-sm p-1 pb-2">{children}</pre>
</div>
);
}

View File

@@ -1,4 +1,4 @@
import { CodeGroup, ContentByFramework } from '@/components/forMdx'
import { CodeGroup } from '@/components/forMdx'
import { JazzIcon } from "@garden-co/design-system/src/components/atoms/logos/JazzIcon";
# Jazz Inspector
@@ -9,18 +9,16 @@ For now, you can get your account credentials from the `jazz-logged-in-secret` l
[https://inspector.jazz.tools](https://inspector.jazz.tools)
<ContentByFramework framework={["react", "svelte", "vue", "vanilla"]}>
## Exporting current account to Inspector from your app [!framework=react,svelte,vue,vanilla]
## Exporting current account to Inspector from your app
In development mode, you can launch the Inspector from your Jazz app to inspect your account by pressing `Cmd+J`.
## Embedding the Inspector widget into your app [!framework=react,svelte,vue,vanilla]
## Embedding the Inspector widget into your app
Alternatively, you can embed the Inspector directly into your app, so you don't need to open a separate window.
Install the package.
<ContentByFramework framework="react">
<CodeGroup>
```sh
npm install jazz-inspector
@@ -39,43 +37,10 @@ import { JazzInspector } from "jazz-inspector";
</JazzProvider>
```
</CodeGroup>
</ContentByFramework>
<ContentByFramework framework={["svelte", "vue", "vanilla"]}>
<CodeGroup>
```sh
npm install jazz-inspector-element
```
</CodeGroup>
Render the component.
<CodeGroup>
```ts
import "jazz-inspector-element"
document.body.appendChild(document.createElement("jazz-inspector"))
```
</CodeGroup>
Or
<CodeGroup>
```tsx
import "jazz-inspector-element"
<jazz-inspector />
```
</CodeGroup>
</ContentByFramework>
This will show the Inspector launch button on the right of your page.
</ContentByFramework>
<ContentByFramework framework="react">
### Positioning the Inspector button [!framework=react]
### Positioning the Inspector button
You can also customize the button position with the following options:
@@ -87,7 +52,6 @@ You can also customize the button position with the following options:
- top left
For example:
<CodeGroup>
```tsx
<JazzInspector position="bottom left"/>
@@ -101,12 +65,5 @@ For example:
<JazzIcon className="w-full h-auto"/>
</button>
</div>
</ContentByFramework>
<ContentByFramework framework="react">
Check out the [music player app](https://github.com/garden-co/jazz/blob/main/examples/music-player/src/2_main.tsx) for a full example.
</ContentByFramework>
<ContentByFramework framework="svelte">
Check out the [file share app](https://github.com/garden-co/jazz/blob/main/examples/file-share-svelte/src/src/routes/%2Blayout.svelte) for a full example.
</ContentByFramework>

View File

@@ -4,6 +4,8 @@ import { CodeGroup } from "@/components/forMdx";
# Providers
## Introduction
`<JazzProvider />` is the core component that connects your Expo application to Jazz. It handles:
- **Data Synchronization**: Manages connections to peers and the Jazz cloud

View File

@@ -4,6 +4,8 @@ import { CodeGroup } from "@/components/forMdx";
# Providers
## Introduction
`<JazzProvider />` is the core component that connects your React Native application to Jazz. It handles:
- **Data Synchronization**: Manages connections to peers and the Jazz cloud

View File

@@ -4,6 +4,8 @@ import { CodeGroup } from "@/components/forMdx";
# Providers
## Introduction
`<JazzProvider />` is the core component that connects your React application to Jazz. It handles:
- **Data Synchronization**: Manages connections to peers and the Jazz cloud

View File

@@ -1,380 +1,99 @@
export const metadata = { title: "Installation" };
export const metadata = { title: "React" };
import { CodeGroup } from "@/components/forMdx";
# Installation and Setup
# <span id="react">React</span>
Add Jazz to your React application in minutes. This setup covers standard React apps, Next.js, and gives an overview of experimental SSR approaches.
Integrating Jazz with React is straightforward. You'll define data schemas that describe your application's structure, then wrap your app with a provider that handles sync and storage. The whole process takes just three steps:
1. [Install dependencies](#install-dependencies)
2. [Write your schema](#write-your-schema)
3. [Wrap your app in `<JazzProvider />`](#standard-react-setup)
Looking for complete examples? Check out our [example applications](/examples) for chat apps, collaborative editors, and more.
## Install dependencies
First, install the required packages:
Wrap your application with `<JazzProvider />`, this is where you specify the sync & storage server to connect to (see [Sync and storage](/docs/react/sync-and-storage)).
<CodeGroup>
```bash
pnpm install jazz-react jazz-tools
```
</CodeGroup>
## Write your schema
Define your data schema using [CoValues](/docs/schemas/covalues) from `jazz-tools`.
<CodeGroup>
```tsx twoslash
// schema.ts
import { Account, co } from "jazz-tools";
export class MyAppAccount extends Account {
name = co.string;
}
```
</CodeGroup>
See [CoValues](/docs/schemas/covalues) for more information on how to define your schema.
## Standard React Setup
Wrap your application with `<JazzProvider />` to connect to the Jazz network and define your data schema:
<CodeGroup>
```tsx twoslash
// @filename: schema.ts
import { Account } from "jazz-tools";
export class MyAppAccount extends Account {}
// @filename: app.tsx
import * as React from "react";
import { createRoot } from 'react-dom/client';
function App() {
return <div>Hello, world!</div>;
}
// ---cut---
// app.tsx
{/* prettier-ignore */}
```tsx
import { JazzProvider } from "jazz-react";
import { MyAppAccount } from "./schema";
createRoot(document.getElementById("root")!).render(
<JazzProvider
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }}
AccountSchema={MyAppAccount}
>
<App />
</JazzProvider>
ReactDOM.createRoot(document.getElementById("root")!).render(
<JazzProvider // [!code ++:6]
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }}
AccountSchema={MyAppAccount}
>
<App />
</JazzProvider>
);
// Register your Account schema to enhance TypeScript support
// [!code ++:6]
// Register the Account schema so `useAccount` returns our custom `MyAppAccount`
declare module "jazz-react" {
interface Register {
Account: MyAppAccount;
}
interface Register {
Account: MyAppAccount;
}
}
```
</CodeGroup>
This setup handles:
- Connection to the Jazz sync server
- Schema registration for type-safe data handling
- Local storage configuration
With this in place, you're ready to start using Jazz hooks in your components. [Learn how to access and update your data](/docs/using-covalues/subscription-and-loading#subscription-hooks).
## Next.js Integration
## Next.js
### Client-side Only (Easiest)
### Client-side only
The simplest approach for Next.js is client-side only integration:
The easiest way to use Jazz with Next.JS is to only use it on the client side. You can ensure this by:
- marking the Jazz provider file as `"use client"`
<CodeGroup>
```tsx twoslash
// @filename: schema.ts
import { Account } from "jazz-tools";
export class MyAppAccount extends Account {}
// @filename: app.tsx
import * as React from "react";
// ---cut---
// app.tsx
"use client" // Mark as client component
{/* prettier-ignore */}
```tsx
"use client" // [!code ++]
import { JazzProvider } from "jazz-react";
import { MyAppAccount } from "./schema";
export function JazzWrapper({ children }: { children: React.ReactNode }) {
return (
<JazzProvider
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }}
AccountSchema={MyAppAccount}
>
{children}
</JazzProvider>
);
export function MyJazzProvider(props: { children: React.ReactNode }) {
return (
<JazzProvider
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }}
AccountSchema={MyAppAccount}
>
{props.children}
</JazzProvider>
);
}
```
</CodeGroup>
Remember to mark any component that uses Jazz hooks with `"use client"`:
- marking any file with components where you use Jazz hooks (such as `useAccount` or `useCoState`) as `"use client"`
<CodeGroup>
```tsx twoslash
// @filename: schema.ts
import { Account, co } from "jazz-tools";
### SSR use (experimental)
export class MyAppAccount extends Account {
name = co.string;
}
// @filename: Profile.tsx
import * as React from "react";
import { MyAppAccount } from "./schema";
Pure SSR use of Jazz is basically just using jazz-nodejs (see [Node.JS / Server Workers](/docs/react/project-setup/server-side)) inside Server Components.
declare module "jazz-react" {
interface Register {
Account: MyAppAccount;
}
}
// ---cut---
// Profile.tsx
"use client"; // [!code ++]
Instead of using hooks as you would on the client, you await promises returned by `CoValue.load(...)` inside your Server Components.
import { useAccount } from "jazz-react";
TODO: code example
export function Profile() {
const { me } = useAccount();
return <div>Hello, {me?.name}</div>;
}
```
</CodeGroup>
This should work well for cases like rendering publicly-readable information, since the worker account will be able to load them.
### SSR Support (Experimental)
In the future, it will be possible to use trusted auth methods (such as Clerk, Auth0, etc.) that let you act as the same Jazz user both on the client and on the server, letting you use SSR even for data private to that user.
For server-side rendering, Jazz offers experimental approaches:
### SSR + client-side (experimental)
- Pure SSR
- Hybrid SSR + Client Hydration
You can combine the two approaches by creating
#### Pure SSR
1. A pure "rendering" component that renders an already-loaded CoValue (in JSON-ified form)
Use Jazz in server components by directly loading data with `CoValue.load()`.
TODO: code example
{/*
<CodeGroup>
```tsx twoslash
// @errors: 18047
// @filename: schema.ts
import { co, CoList, CoMap } from "jazz-tools";
2. A "hydrating" component (with `"use client"`) that
export class MyItem extends CoMap {
title = co.string;
}
- expects a pre-loaded CoValue as a prop (in JSON-ified form)
- uses one of the client-side Jazz hooks (such as `useAccount` or `useCoState`) to subscribe to that same CoValue
- passing the client-side subscribed state to the "rendering" component, with the pre-loaded CoValue as a fallback until the client receives the first subscribed state
export class MyCollection extends CoList.Of(co.ref(MyItem)) {}
// @filename: PublicData.tsx
import * as React from "react";
import { ID } from "jazz-tools";
const collectionID = "co_z123" as ID<MyCollection>;
// ---cut---
// Server Component (no "use client" directive)
import { MyCollection, MyItem } from "./schema";
TODO: code example
export default async function PublicData() {
// Load data directly in the server component
const items = await MyCollection.load(collectionID);
if (!items) {
return <div>Loading...</div>;
}
return (
<ul>
{items.map(item => (
item ? <li key={item.id}>{item.title}</li> : null
))}
</ul>
);
}
```
</CodeGroup>
*/}
3. A "pre-loading" Server Component that
This works well for public data accessible to the server account.
- pre-loads the CoValue by awaiting it's `load(...)` method (as described above)
- renders the "hydrating" component, passing the pre-loaded CoValue as a prop
#### Hybrid SSR + Client Hydration
For more complex cases, you can pre-render on the server and hydrate on the client:
1. Create a shared rendering component.
{/*
<CodeGroup>
```tsx twoslash
// @filename: schema.ts
import { co, CoList, CoMap } from "jazz-tools";
export class MyItem extends CoMap {
title = co.string;
}
// @filename: ItemList.tsx
import * as React from "react";
import { MyItem } from "./schema";
// ---cut---
// ItemList.tsx - works in both server and client contexts
export function ItemList({ items }: { items: MyItem[] }) {
return (
<ul>
{items.map(item => (
<li key={item.id}>{item.title}</li>
))}
</ul>
);
}
```
</CodeGroup>
*/}
2. Create a client hydration component.
{/*
<CodeGroup>
```tsx twoslash
// @filename: schema.ts
import { co, CoList, CoMap } from "jazz-tools";
export class MyItem extends CoMap {
title = co.string;
}
export class MyCollection extends CoList.Of(co.ref(MyItem)) {}
// @filename: ItemList.tsx
import * as React from "react";
import { MyItem } from "./schema";
export function ItemList({ items }: { items: MyItem[] }) {
return (
<ul>
{items.map(item => (
<li key={item.id}>{item.title}</li>
))}
</ul>
);
}
// @filename: ItemListHydrator.tsx
// ItemListHydrator.tsx
import * as React from "react";
import { useCoState } from "jazz-react";
import { ID } from "jazz-tools";
const myCollectionID = "co_z123" as ID<MyCollection>;
// ---cut---
"use client"
import { MyCollection, MyItem } from "./schema";
import { ItemList } from "./ItemList";
export function ItemListHydrator({ initialItems }: { initialItems: MyItem[] }) {
// Hydrate with real-time data once client loads
const myCollection = useCoState(MyCollection, myCollectionID);
// Filter out nulls for type safety
const items = Array.from(myCollection?.values() || []).filter(
(item): item is MyItem => !!item
);
// Use server data until client data is available
const displayItems = items || initialItems;
return <ItemList items={displayItems} />;
}
```
</CodeGroup>
*/}
3. Create a server component that pre-loads data.
{/*
<CodeGroup>
```tsx twoslash
// @filename: schema.ts
import { co, CoList, CoMap } from "jazz-tools";
export class MyItem extends CoMap {
title = co.string;
}
export class MyCollection extends CoList.Of(co.ref(MyItem)) {}
// @filename: ItemList.tsx
import * as React from "react";
import { MyItem } from "./schema";
export function ItemList({ items }: { items: MyItem[] }) {
return (
<ul>
{items.map(item => (
<li key={item.id}>{item.title}</li>
))}
</ul>
);
}
// @filename: ItemListHydrator.tsx
// ItemListHydrator.tsx
import * as React from "react";
import { useCoState } from "jazz-react";
import { ID } from "jazz-tools";
const myCollectionID = "co_z123" as ID<MyCollection>;
// ---cut---
"use client"
import { MyCollection, MyItem } from "./schema";
import { ItemList } from "./ItemList";
export function ItemListHydrator({ initialItems }: { initialItems: MyItem[] }) {
// Hydrate with real-time data once client loads
const myCollection = useCoState(MyCollection, myCollectionID);
// Filter out nulls for type safety
const items = Array.from(myCollection?.values() || []).filter(
(item): item is MyItem => !!item
);
// Use server data until client data is available
const displayItems = items || initialItems;
return <ItemList items={displayItems} />;
}
// @filename: ServerItemPage.tsx
import * as React from 'react';
import { ID } from "jazz-tools";
import { MyCollection, MyItem } from "./schema";
import { ItemListHydrator } from "./ItemListHydrator";
const myCollectionID = "co_z123" as ID<MyCollection>;
// ---cut---
// ServerItemPage.tsx
export default async function ServerItemPage() {
// Pre-load data on the server
const initialItems = await MyCollection.load(myCollectionID);
// Filter out nulls for type safety
const items = Array.from(initialItems?.values() || []).filter(
(item): item is MyItem => !!item
);
// Pass to client hydrator
return <ItemListHydrator initialItems={items} />;
}
```
</CodeGroup>
*/}
This approach gives you the best of both worlds: fast initial loading with server rendering, plus real-time updates on the client.
## Further Reading
- [Schemas](/docs/schemas/covalues) - Learn about defining your data model
- [Provider Configuration](/docs/project-setup/providers) - Learn about other configuration options for Providers
- [Authentication](/docs/authentication/overview) - Set up user authentication
- [Sync and Storage](/docs/sync-and-storage) - Learn about data persistence
TODO: code example

View File

@@ -12,7 +12,7 @@ As their name suggests, CoValues are inherently collaborative, meaning **multipl
- CoValues keep their full edit histories, from which they derive their "current state".
- The fact that this happens in an eventually-consistent way makes them [CRDTs](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type).
- Having the full history also means that you often don't need explicit timestamps and author info - you get this for free as part of a CoValue's [edit metadata](/docs/using-covalues/history).
- Having the full history also means that you often don't need explicit timestamps and author info - you get this for free as part of a CoValue's [edit metadata](/docs/using-covalues/metadata).
CoValues model JSON with CoMaps and CoLists, but also offer CoFeeds for simple per-user value feeds, and let you represent binary data with FileStreams.
@@ -31,14 +31,11 @@ Even before you know the details of how your app will work, you'll probably know
Jazz makes it quick to declare schemas, since they are simple TypeScript classes:
<CodeGroup>
```ts twoslash
import { co, CoMap, CoList } from "jazz-tools";
class ListOfTasks extends CoList.Of(co.string) {}
// ---cut---
// schema.ts
{/* prettier-ignore */}
```ts
export class TodoProject extends CoMap {
title = co.string;
tasks = co.ref(ListOfTasks);
title = co.string;
tasks = co.ref(ListOfTasks);
}
```
</CodeGroup>
@@ -48,28 +45,16 @@ Here you can see how we extend a CoValue type and use `co` for declaring (collab
Classes might look old-fashioned, but Jazz makes use of them being both types and values in TypeScript, letting you refer to either with a single definition and import.
<CodeGroup>
```ts twoslash
// @filename: schema.ts
import { co, CoMap, CoList } from "jazz-tools";
export class ListOfTasks extends CoList.Of(co.string) {}
export class TodoProject extends CoMap {
title = co.string;
tasks = co.ref(ListOfTasks);
}
// @filename: app.ts
import { Group } from "jazz-tools";
// ---cut---
// app.ts
{/* prettier-ignore */}
```ts
import { TodoProject, ListOfTasks } from "./schema";
const project: TodoProject = TodoProject.create(
{
title: "New Project",
tasks: ListOfTasks.create([], Group.create()),
},
Group.create()
{
title: "New Project",
tasks: ListOfTasks.create([], Group.create()),
},
Group.create()
);
```
</CodeGroup>
@@ -78,18 +63,17 @@ const project: TodoProject = TodoProject.create(
### `CoMap` (declaration)
CoMaps are the most commonly used type of CoValue. They are the equivalent of JSON objects (Collaborative editing follows a last-write-wins strategy per-key).
CoMaps are the most commonly used type of CoValue. They are the equivalent of JSON objects. (Collaborative editing follows a last-write-wins strategy per-key.)
You can either declare struct-like CoMaps:
<CodeGroup>
```ts twoslash
// schema.ts
import { co, CoMap } from "jazz-tools";
// ---cut---
export class Task extends CoMap {
title = co.string;
completed = co.boolean;
{/* prettier-ignore */}
```ts
class Person extends CoMap {
name = co.string;
age = co.number;
pet = co.optional.ref(Pet);
}
```
</CodeGroup>
@@ -97,13 +81,8 @@ export class Task extends CoMap {
Or record-like CoMaps (key-value pairs, where keys are always `string`):
<CodeGroup>
```ts twoslash
import { co, CoMap } from "jazz-tools";
class Fruit extends CoMap {
name = co.string;
color = co.string;
}
// ---cut---
{/* prettier-ignore */}
```ts
class ColorToHex extends CoMap.Record(co.string) {}
class ColorToFruit extends CoMap.Record(co.ref(Fruit)) {}
@@ -111,10 +90,10 @@ class ColorToFruit extends CoMap.Record(co.ref(Fruit)) {}
</CodeGroup>
See the corresponding sections for [creating](/docs/using-covalues/comaps#creating-comaps),
See the corresponding sections for [creating](/docs/using-covalues/creation#comap-creation),
[subscribing/loading](/docs/using-covalues/subscription-and-loading),
[reading from](/docs/using-covalues/comaps#reading-from-comaps) and
[updating](/docs/using-covalues/comaps#updating-comaps) CoMaps.
[reading from](/docs/using-covalues/reading#comap-reading) and
[writing to](/docs/using-covalues/writing#comap-writing) CoMaps.
### `CoList` (declaration)
@@ -123,48 +102,38 @@ CoLists are ordered lists and are the equivalent of JSON arrays. (They support c
You define them by specifying the type of the items they contain:
<CodeGroup>
```ts twoslash
import { co, CoList, CoMap } from "jazz-tools";
class Task extends CoMap {
title = co.string;
completed = co.boolean;
}
// ---cut---
{/* prettier-ignore */}
```ts
class ListOfColors extends CoList.Of(co.string) {}
class ListOfTasks extends CoList.Of(co.ref(Task)) {}
```
</CodeGroup>
See the corresponding sections for [creating](/docs/using-covalues/colists#creating-colists),
See the corresponding sections for [creating](/docs/using-covalues/creation#colist-creation),
[subscribing/loading](/docs/using-covalues/subscription-and-loading),
[reading from](/docs/using-covalues/colists#reading-from-colists) and
[updating](/docs/using-covalues/colists#updating-colists) CoLists.
[reading from](/docs/using-covalues/reading#colist-reading) and
[writing to](/docs/using-covalues/writing#colist-writing) CoLists.
### `CoFeed` (declaration)
CoFeeds are a special CoValue type that represent a feed of values for a set of users/sessions (Each session of a user gets its own append-only feed).
CoFeeds are a special CoValue type that represent a feed of values for a set of users / sessions. (Each session of a user gets its own append-only feed.)
They allow easy access of the latest or all items belonging to a user or their sessions. This makes them particularly useful for user presence, reactions, notifications, etc.
You define them by specifying the type of feed item:
<CodeGroup>
```ts twoslash
import { co, CoFeed, CoMap } from "jazz-tools";
class Task extends CoMap {
title = co.string;
completed = co.boolean;
}
// ---cut---
{/* prettier-ignore */}
```ts
class FeedOfTasks extends CoFeed.Of(co.ref(Task)) {}
```
</CodeGroup>
See the corresponding sections for [creating](/docs/using-covalues/cofeeds#creating-cofeeds),
See the corresponding sections for [creating](/docs/using-covalues/creation#cofeed-creation),
[subscribing/loading](/docs/using-covalues/subscription-and-loading),
[reading from](/docs/using-covalues/cofeeds#reading-from-cofeeds) and
[writing to](/docs/using-covalues/cofeeds#writing-to-cofeeds) CoFeeds.
[reading from](/docs/using-covalues/reading#cofeed-reading) and
[writing to](/docs/using-covalues/writing#cofeed-writing) CoFeeds.
### `FileStream` (declaration)
@@ -175,22 +144,21 @@ They allow you to upload and reference files, images, etc.
You typically don't need to declare or extend them yourself, you simply refer to the built-in `FileStream` from another CoValue:
<CodeGroup>
```ts twoslash
import { co, CoMap } from "jazz-tools";
// ---cut---
{/* prettier-ignore */}
```ts
import { FileStream } from "jazz-tools";
class Document extends CoMap {
title = co.string;
file = co.ref(FileStream);
class UserProfile extends CoMap {
name = co.string;
avatar = co.ref(FileStream);
}
```
</CodeGroup>
See the corresponding sections for [creating](/docs/using-covalues/filestreams#creating-filestreams),
See the corresponding sections for [creating](/docs/using-covalues/creation#filestream-creation),
[subscribing/loading](/docs/using-covalues/subscription-and-loading),
[reading from](/docs/using-covalues/filestreams#reading-from-filestreams) and
[writing to](/docs/using-covalues/filestreams#writing-to-filestreams) FileStreams.
[reading from](/docs/using-covalues/reading#filestream-reading) and
[writing to](/docs/using-covalues/writing#filestream-writing) FileStreams.
### `SchemaUnion` (declaration)
@@ -199,9 +167,8 @@ SchemaUnion is a helper type that allows you to load and refer to multiple subcl
You declare them with a base class type and discriminating lambda, in which you have access to the `RawCoMap`, on which you can call `get` with the field name to get the discriminating value.
<CodeGroup>
```ts twoslash
import { co } from "jazz-tools";
// ---cut---
{/* prettier-ignore */}
```ts
import { SchemaUnion, CoMap } from "jazz-tools";
class BaseWidget extends CoMap {
@@ -229,9 +196,9 @@ const WidgetUnion = SchemaUnion.Of<BaseWidget>((raw) => {
```
</CodeGroup>
See the corresponding sections for [creating](/docs/using-covalues/schemaunions#creating-schemaunions),
See the corresponding sections for [creating](/docs/using-covalues/creation#schemaunion-creation),
[subscribing/loading](/docs/using-covalues/subscription-and-loading) and
[narrowing](/docs/using-covalues/schemaunions#narrowing) SchemaUnions.
[narrowing](/docs/using-covalues/reading#schemaunion-narrowing) SchemaUnions.
## CoValue field/item types
@@ -242,11 +209,12 @@ Now that we've seen the different types of CoValues, let's see more precisely ho
You can declare primitive field types using the `co` declarer:
<CodeGroup>
```ts twoslash
import { co, CoMap, CoList } from "jazz-tools";
{/* prettier-ignore */}
```ts
import { co } from "jazz-tools";
export class Person extends CoMap {
title = co.string;
title = co.string;
}
export class ListOfColors extends CoList.Of(co.string) {}
@@ -256,25 +224,23 @@ export class ListOfColors extends CoList.Of(co.string) {}
Here's a quick overview of the primitive types you can use:
<CodeGroup>
```ts twoslash
import { co } from "jazz-tools";
// ---cut---
co.string; // For simple strings
co.number; // For numbers
co.boolean; // For booleans
co.null; // For null
co.Date; // For dates
co.literal("waiting", "ready"); // For enums
{/* prettier-ignore */}
```ts
co.string;
co.number;
co.boolean;
co.null;
co.Date;
co.literal("waiting", "ready");
```
</CodeGroup>
Finally, for more complex JSON data, that you *don't want to be collaborative internally* (but only ever update as a whole), you can use `co.json<T>()`:
<CodeGroup>
```ts twoslash
import { co } from "jazz-tools";
// ---cut---
co.json<{ name: string }>(); // For JSON objects
{/* prettier-ignore */}
```ts
co.json<{ name: string }>();
```
</CodeGroup>
@@ -291,18 +257,13 @@ The important caveat here is that **a referenced CoValue might or might not be l
In Schemas, you declare Refs using the `co.ref<T>()` declarer:
<CodeGroup>
```ts twoslash
import { co, CoMap, CoList } from "jazz-tools";
class Person extends CoMap {
name = co.string;
}
// ---cut---
// schema.ts
class ListOfPeople extends CoList.Of(co.ref(Person)) {}
{/* prettier-ignore */}
```ts
class Company extends CoMap {
members = co.ref(ListOfPeople);
members = co.ref(ListOfPeople);
}
class ListOfPeople extends CoList.Of(co.ref(Person)) {}
```
</CodeGroup>
@@ -311,14 +272,10 @@ class Company extends CoMap {
⚠️ If you want to make a referenced CoValue field optional, you *have to* use `co.optional.ref<T>()`: ⚠️
<CodeGroup>
```ts twoslash
import { co, CoMap } from "jazz-tools";
class Pet extends CoMap {
name = co.string;
}
// ---cut---
{/* prettier-ignore */}
```ts
class Person extends CoMap {
pet = co.optional.ref(Pet);
pet = co.optional.ref(Pet);
}
```
</CodeGroup>
@@ -328,25 +285,20 @@ class Person extends CoMap {
Since CoValue schemas are based on classes, you can easily add computed fields and methods:
<CodeGroup>
```ts twoslash
import { co, CoMap } from "jazz-tools";
function differenceInYears(date1: Date, date2: Date) {
const diffTime = Math.abs(date1.getTime() - date2.getTime());
return Math.ceil(diffTime / (1000 * 60 * 60 * 24 * 365.25));
}
// ---cut---
{/* prettier-ignore */}
```ts
class Person extends CoMap {
firstName = co.string;
lastName = co.string;
dateOfBirth = co.Date;
firstName = co.string;
lastName = co.string;
dateOfBirth = co.Date;
get name() {
return `${this.firstName} ${this.lastName}`;
}
get name() {
return `${this.firstName} ${this.lastName}`;
}
ageAsOf(date: Date) {
return differenceInYears(date, this.dateOfBirth);
}
ageAsOf(date: Date) {
return differenceInYears(date, this.dateOfBirth);
}
}
```
</CodeGroup>

View File

@@ -39,6 +39,7 @@ For files from input elements or drag-and-drop interfaces, use `createFromBlob`:
<CodeGroup>
```ts twoslash
// @errors: 18047
import { FileStream, Group } from "jazz-tools";
const myGroup = Group.create();
const progressBar: HTMLElement = document.querySelector('.progress-bar')!;

View File

@@ -42,7 +42,7 @@ export async function getDocMetadata(framework: string, slug?: string[]) {
function DocProse({ children }: { children: React.ReactNode }) {
return (
<Prose className="overflow-hidden pb-8 pt-[calc(61px+2rem)] md:pt-8 md:max-w-3xl mx-auto">
<Prose className="overflow-x-hidden lg:overflow-x-visible lg:flex-1 pb-8 pt-[calc(61px+2rem)] md:pt-8 md:max-w-3xl mx-auto">
{children}
</Prose>
);
@@ -55,8 +55,23 @@ export async function DocPage({
framework: string;
slug?: string[];
}) {
const slugPath = slug?.join("/");
try {
const { Content, tocItems } = await getMdxWithToc(framework, slug);
const mdxSource = await getMdxSource(framework, slugPath);
const {
default: Content,
tableOfContents = [],
headingsFrameworkVisibility = {},
} = mdxSource;
// Remove items that should not be shown for the current framework
const tocItems = (tableOfContents as Toc).filter(({ id }) =>
id && id in headingsFrameworkVisibility
? headingsFrameworkVisibility[id]?.includes(framework)
: true,
);
return (
<DocsLayout nav={<DocNav />} tocItems={tocItems}>
@@ -78,50 +93,3 @@ export async function DocPage({
);
}
}
export async function getMdxWithToc(framework: string, slug?: string[]) {
const slugPath = slug?.join("/");
const mdxSource = await getMdxSource(framework, slugPath);
const {
default: Content,
tableOfContents,
headingsFrameworkVisibility,
} = mdxSource;
// Remove items that should not be shown for the current framework
const tocItems = filterTocItemsForFramework(
tableOfContents as Toc,
framework,
headingsFrameworkVisibility
);
return {
Content,
tocItems,
};
}
function filterTocItemsForFramework(
tocItems: Toc,
framework: string,
headingsFrameworkVisibility: Record<string, string[]>
): Toc {
return tocItems
.map(item => {
const isVisible =
!item.id || !(item.id in headingsFrameworkVisibility) ||
headingsFrameworkVisibility[item.id]?.includes(framework);
if (!isVisible) return null;
const filteredChildren = item.children
? filterTocItemsForFramework(item.children, framework, headingsFrameworkVisibility)
: [];
return {
...item,
children: filteredChildren,
};
})
.filter(Boolean) as Toc;
}

Binary file not shown.

View File

@@ -1,53 +1,5 @@
# cojson-storage-indexeddb
## 0.13.23
### Patch Changes
- Updated dependencies [6b781cf]
- cojson@0.13.23
- cojson-storage@0.13.23
## 0.13.21
### Patch Changes
- Updated dependencies [e14e61f]
- cojson@0.13.21
- cojson-storage@0.13.21
## 0.13.20
### Patch Changes
- Updated dependencies [adfc9a6]
- Updated dependencies [1389207]
- Updated dependencies [d6e143e]
- Updated dependencies [3e6229d]
- cojson-storage@0.13.20
- cojson@0.13.20
## 0.13.18
### Patch Changes
- Updated dependencies [9089252]
- Updated dependencies [b470f63]
- Updated dependencies [8b2df0e]
- Updated dependencies [66373ba]
- Updated dependencies [f24cad1]
- cojson@0.13.18
- cojson-storage@0.13.18
## 0.13.17
### Patch Changes
- Updated dependencies [9fb98e2]
- Updated dependencies [0b89fad]
- cojson@0.13.17
- cojson-storage@0.13.17
## 0.13.16
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage-indexeddb",
"version": "0.13.23",
"version": "0.13.16",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",

View File

@@ -44,7 +44,10 @@ export class IDBNode {
}
static async asPeer(
{ localNodeName = "local" }: { localNodeName?: string } | undefined = {
{
trace,
localNodeName = "local",
}: { trace?: boolean; localNodeName?: string } | undefined = {
localNodeName: "local",
},
): Promise<Peer> {
@@ -54,6 +57,7 @@ export class IDBNode {
{
peer1role: "client",
peer2role: "storage",
trace,
crashOnClose: true,
},
);

View File

@@ -1,53 +1,5 @@
# cojson-storage-sqlite
## 0.13.23
### Patch Changes
- Updated dependencies [6b781cf]
- cojson@0.13.23
- cojson-storage@0.13.23
## 0.13.21
### Patch Changes
- Updated dependencies [e14e61f]
- cojson@0.13.21
- cojson-storage@0.13.21
## 0.13.20
### Patch Changes
- Updated dependencies [adfc9a6]
- Updated dependencies [1389207]
- Updated dependencies [d6e143e]
- Updated dependencies [3e6229d]
- cojson-storage@0.13.20
- cojson@0.13.20
## 0.13.18
### Patch Changes
- Updated dependencies [9089252]
- Updated dependencies [b470f63]
- Updated dependencies [8b2df0e]
- Updated dependencies [66373ba]
- Updated dependencies [f24cad1]
- cojson@0.13.18
- cojson-storage@0.13.18
## 0.13.17
### Patch Changes
- Updated dependencies [9fb98e2]
- Updated dependencies [0b89fad]
- cojson@0.13.17
- cojson-storage@0.13.17
## 0.13.16
### Patch Changes

Some files were not shown because too many files have changed in this diff Show More