Skip to content

Commit 4e96b0c

Browse files
committed
fix: patch in the latest version of yjs
1 parent c8d19dc commit 4e96b0c

7 files changed

Lines changed: 356 additions & 244 deletions

File tree

packages/core/src/pm-nodes/BlockContainer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const BlockContainer = Node.create<{
2323
name: "blockContainer",
2424
group: "blockGroupChild bnBlock",
2525
// A block always contains content, and optionally a blockGroup which contains nested blocks
26-
content: "suggestionBlockContent* blockContent suggestionBlockContent* blockGroup?",
26+
content:
27+
"suggestionBlockContent* blockContent suggestionBlockContent* blockGroup?",
2728
// Ensures content-specific keyboard handlers trigger first.
2829
priority: 50,
2930
defining: true,

packages/core/src/y/extensions/YSync.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ export const YSyncExtension = createExtension(
120120
mapAttributionToMark,
121121
attributedNodes: (
122122
nodeName: string,
123-
kinds: { deleted: boolean; inserted: boolean; formatted: boolean },
123+
kinds: { delete: boolean; insert: boolean; format: boolean },
124124
) => {
125-
// eslint-disable-next-line no-console
126-
console.log(nodeName, kinds);
127-
return Boolean(editor.schema.blockSpecs[nodeName] && kinds.deleted);
125+
const result = Boolean(
126+
editor.schema.blockSpecs[nodeName] && kinds.delete,
127+
);
128+
129+
return result;
128130
},
129131
}),
130132
],

patches/@y__prosemirror@2.0.0-2.patch

Lines changed: 16 additions & 212 deletions
Large diffs are not rendered by default.

patches/@y__y@14.0.0-rc.16.patch

Lines changed: 193 additions & 0 deletions
Large diffs are not rendered by default.

pnpm-lock.yaml

Lines changed: 28 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ allowBuilds:
3535
leveldown: false
3636
patchedDependencies:
3737
"@y/prosemirror@2.0.0-2": "patches/@y__prosemirror@2.0.0-2.patch"
38+
'@y/y@14.0.0-rc.16': patches/@y__y@14.0.0-rc.16.patch
3839
lib0@1.0.0-rc.13: patches/lib0@1.0.0-rc.13.patch

scripts/patch-yjs.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Regenerates the pnpm patch for @y/y (yjs) from a local build.
4+
#
5+
# Usage:
6+
# ./scripts/patch-yjs.sh [path-to-yjs]
7+
#
8+
# Defaults to ../yjs relative to this repo root.
9+
10+
set -euo pipefail
11+
12+
# Version that is actually installed in this repo (pnpm patches the installed
13+
# version). The local ../yjs checkout may be a newer rc; we still pin to this.
14+
YJS_PKG="@y/y"
15+
YJS_VERSION="14.0.0-rc.16"
16+
17+
# pnpm keeps the scope path for the temp patch dir (e.g. .pnpm_patches/@y/y@VER)
18+
# but escapes "/" to "__" for the committed patch file name.
19+
YJS_PATCH_DIR_NAME="$YJS_PKG@$YJS_VERSION"
20+
YJS_PATCH_FILE_NAME="@y__y@$YJS_VERSION.patch"
21+
22+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
23+
BLOCKNOTE_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
24+
LOCAL_YJS="${1:-$(cd "$BLOCKNOTE_ROOT/../yjs" && pwd)}"
25+
26+
if [[ ! -d "$LOCAL_YJS/src" ]]; then
27+
echo "ERROR: Cannot find yjs at $LOCAL_YJS"
28+
echo "Pass the path as an argument: $0 /path/to/yjs"
29+
exit 1
30+
fi
31+
32+
echo "==> Using local yjs at: $LOCAL_YJS"
33+
echo "==> BlockNote root: $BLOCKNOTE_ROOT"
34+
35+
# 0. Build yjs so dist/ is up to date
36+
echo "==> Building yjs (npm run dist) ..."
37+
(cd "$LOCAL_YJS" && npm run dist)
38+
39+
PATCH_DIR="$BLOCKNOTE_ROOT/node_modules/.pnpm_patches/$YJS_PATCH_DIR_NAME"
40+
41+
# 1. Clean up any leftover patch dir, then start fresh
42+
if [[ -d "$PATCH_DIR" ]]; then
43+
echo "==> Cleaning up old patch dir ..."
44+
rm -rf "$PATCH_DIR"
45+
fi
46+
47+
echo "==> Running pnpm patch $YJS_PKG@$YJS_VERSION ..."
48+
cd "$BLOCKNOTE_ROOT"
49+
pnpm patch "$YJS_PKG@$YJS_VERSION"
50+
51+
echo "==> Patch temp dir: $PATCH_DIR"
52+
53+
# 2. Replace src/ with local build
54+
echo "==> Replacing src/ ..."
55+
rm -rf "$PATCH_DIR/src"
56+
cp -R "$LOCAL_YJS/src" "$PATCH_DIR/src"
57+
58+
# 3. Replace dist/ with local build (.d.ts files)
59+
echo "==> Replacing dist/ ..."
60+
rm -rf "$PATCH_DIR/dist"
61+
cp -R "$LOCAL_YJS/dist" "$PATCH_DIR/dist"
62+
63+
# 4. Replace tests/ (testHelper is part of the published exports)
64+
if [[ -d "$LOCAL_YJS/tests" ]]; then
65+
echo "==> Replacing tests/ ..."
66+
rm -rf "$PATCH_DIR/tests"
67+
cp -R "$LOCAL_YJS/tests" "$PATCH_DIR/tests"
68+
fi
69+
70+
# 5. Copy top-level type decls referenced by the package (e.g. global.d.ts)
71+
if [[ -f "$LOCAL_YJS/global.d.ts" ]]; then
72+
echo "==> Copying global.d.ts ..."
73+
cp "$LOCAL_YJS/global.d.ts" "$PATCH_DIR/global.d.ts"
74+
fi
75+
76+
# 6. Update package.json in the patch dir
77+
echo "==> Updating package.json ..."
78+
node -e "
79+
const fs = require('fs');
80+
const orig = JSON.parse(fs.readFileSync('$PATCH_DIR/package.json', 'utf8'));
81+
const local = JSON.parse(fs.readFileSync('$LOCAL_YJS/package.json', 'utf8'));
82+
83+
// Keep the original (installed) version so pnpm doesn't try to fetch a
84+
// different version from the registry.
85+
orig.version = '$YJS_VERSION';
86+
87+
// Update exports (this package is exports-based, no main/module)
88+
if (local.exports) orig.exports = local.exports;
89+
90+
// Update files list
91+
if (local.files) orig.files = local.files;
92+
93+
// Update type/sideEffects if present
94+
if (local.type) orig.type = local.type;
95+
if ('sideEffects' in local) orig.sideEffects = local.sideEffects;
96+
97+
// Update bin if present
98+
if (local.bin) orig.bin = local.bin;
99+
100+
fs.writeFileSync('$PATCH_DIR/package.json', JSON.stringify(orig, null, 2) + '\n');
101+
console.log(' package.json updated');
102+
"
103+
104+
# 7. Commit the patch
105+
echo ""
106+
echo "==> Running pnpm patch-commit ..."
107+
pnpm patch-commit "$PATCH_DIR"
108+
109+
echo ""
110+
echo "==> Done! Patch regenerated at patches/$YJS_PATCH_FILE_NAME"

0 commit comments

Comments
 (0)