Skip to content

Commit a422137

Browse files
authored
Merge pull request #186 from get-convex/component-api
component api
2 parents def1f1c + 4742c0e commit a422137

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1723
-8011
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ jobs:
1919
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2020

2121
- name: Node setup
22-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
22+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
2323
with:
24-
node-version: "18.20.8"
24+
cache-dependency-path: package.json
25+
node-version: "20.x"
26+
cache: "npm"
2527

26-
- run: |
28+
- name: Install and build
29+
run: |
2730
npm i
28-
npm run typecheck
2931
npm run build
32+
- name: Publish package for testing branch
33+
run: npx pkg-pr-new publish || echo "Have you set up pkg-pr-new for this repo?"
34+
- name: Test
35+
run: |
3036
npm run test
31-
cd example
32-
npm i
37+
npm run typecheck
3338
npm run lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ node_modules
1515
react/package.json
1616
# npm pack output
1717
*.tgz
18+
*.tsbuildinfo

.prettierrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"trailingComma": "es5"
2+
"trailingComma": "all",
3+
"proseWrap": "always"
34
}

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# Changelog
22

3+
## 0.2.0
4+
5+
- Adds /test and /\_generated/component.js entrypoints
6+
- Drops commonjs support
7+
- Improves source mapping for generated files
8+
- Changes to a statically generated component API
9+
310
## 0.1.28
411

512
- Imports with file extensions to help module resolution for NodeNext
613

714
## 0.1.27
815

9-
- Reduce the number of deltas in one round to avoid returning too long of arrays of steps
10-
when catching up old clients
16+
- Reduce the number of deltas in one round to avoid returning too long of arrays
17+
of steps when catching up old clients
1118

1219
## 0.1.26
1320

@@ -17,7 +24,6 @@
1724

1825
- Support BlockNote ^0.33
1926

20-
2127
## 0.1.24
2228

2329
- Change the BlockNoteEditor to be a type parameter instead, as mismatched

CONTRIBUTING.md

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,39 @@
22

33
## Running locally
44

5-
Setup:
6-
75
```sh
86
npm i
9-
cd example
10-
npm i
11-
npm run dev:convex -- --once
12-
```
13-
14-
Run the frontend and backend:
15-
16-
```sh
177
npm run dev
188
```
199

2010
## Testing
2111

2212
```sh
23-
rm -rf dist/ && npm run build
13+
npm run clean
14+
npm run build
2415
npm run typecheck
25-
npm run test
26-
cd example
2716
npm run lint
28-
cd ..
17+
npm run test
2918
```
3019

3120
## Deploying
3221

3322
### Building a one-off package
3423

3524
```sh
36-
rm -rf dist/ && npm run build
25+
npm run clean
26+
npm ci
3727
npm pack
3828
```
3929

4030
### Deploying a new version
4131

4232
```sh
43-
# this will change the version and commit it (if you run it in the root directory)
44-
npm version patch
45-
npm publish --dry-run
46-
# sanity check files being included
47-
npm publish
48-
git push --tags
33+
npm run release
4934
```
5035

51-
#### Alpha release
52-
53-
The same as above, but it requires extra flags so the release is only installed with `@alpha`:
36+
or for alpha release:
5437

5538
```sh
56-
npm version prerelease --preid alpha
57-
npm publish --tag alpha
39+
npm run alpha
5840
```

README.md

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ synced to the cloud. The data lives in your Convex database, and can be stored
1515
alongside the rest of your app's data.
1616

1717
Just configure your editor features, add this component to your Convex backend,
18-
and use the provided sync React hook.
19-
Read this [Stack post](https://stack.convex.dev/add-a-collaborative-document-editor-to-your-app) for more details.
18+
and use the provided sync React hook. Read this
19+
[Stack post](https://stack.convex.dev/add-a-collaborative-document-editor-to-your-app)
20+
for more details.
2021

2122
[![Example of editing](./blocknote.gif)](http://www.youtube.com/watch?v=TGd-Nl7PBYQ "Collaborative editing syncing")
2223

@@ -62,16 +63,17 @@ Features:
6263
- Transform the document server-side, enabling easy AI interoperation.
6364

6465
See [below](#future-features) for future feature ideas and
65-
[CONTRIBUTING.md](./CONTRIBUTING.md) for how to contribute.
66-
Found a bug? Feature request? [File it here](https://github.com/get-convex/prosemirror-sync/issues).
66+
[CONTRIBUTING.md](./CONTRIBUTING.md) for how to contribute. Found a bug? Feature
67+
request? [File it here](https://github.com/get-convex/prosemirror-sync/issues).
6768

6869
## Pre-requisite: Convex
6970

70-
You'll need an existing Convex project to use the component.
71-
Convex is a hosted backend platform, including a database, serverless functions,
72-
and a ton more you can learn about [here](https://docs.convex.dev/get-started).
71+
You'll need an existing Convex project to use the component. Convex is a hosted
72+
backend platform, including a database, serverless functions, and a ton more you
73+
can learn about [here](https://docs.convex.dev/get-started).
7374

74-
Run `npm create convex` or follow any of the [quickstarts](https://docs.convex.dev/home) to set one up.
75+
Run `npm create convex` or follow any of the
76+
[quickstarts](https://docs.convex.dev/home) to set one up.
7577

7678
## Installation
7779

@@ -81,12 +83,13 @@ Install the component package:
8183
npm install @convex-dev/prosemirror-sync
8284
```
8385

84-
Create a `convex.config.ts` file in your app's `convex/` folder and install the component by calling `use`:
86+
Create a `convex.config.ts` file in your app's `convex/` folder and install the
87+
component by calling `use`:
8588

8689
```ts
8790
// convex/convex.config.ts
8891
import { defineApp } from "convex/server";
89-
import prosemirrorSync from "@convex-dev/prosemirror-sync/convex.config";
92+
import prosemirrorSync from "@convex-dev/prosemirror-sync/convex.config.js";
9093

9194
const app = defineApp();
9295
app.use(prosemirrorSync);
@@ -97,9 +100,8 @@ export default app;
97100
## Usage
98101

99102
To use the component, you expose the API in a file in your `convex/` folder, and
100-
use the editor-specific sync React hook, passing in a reference to
101-
the API you defined. For this example, we'll create the API in
102-
`convex/example.ts`.
103+
use the editor-specific sync React hook, passing in a reference to the API you
104+
defined. For this example, we'll create the API in `convex/example.ts`.
103105

104106
```ts
105107
// convex/example.ts
@@ -194,21 +196,22 @@ See a working example in [example.ts](./example/convex/example.ts) and
194196

195197
### Configuring the snapshot debounce interval
196198

197-
The snapshot debounce interval is set to one second by default.
198-
You can specify a different interval with the `snapshotDebounceMs` option when
199-
calling `useTiptapSync` or `useBlockNoteSync`.
199+
The snapshot debounce interval is set to one second by default. You can specify
200+
a different interval with the `snapshotDebounceMs` option when calling
201+
`useTiptapSync` or `useBlockNoteSync`.
200202

201203
A snapshot won't be sent until both of these are true:
202204

203205
- The document has been idle for the debounce interval.
204206
- The current user was the last to make a change.
205207

206-
There can be races, but since each client will submit the snapshot for their
207-
own change, they won't conflict with each other and are safe to apply.
208+
There can be races, but since each client will submit the snapshot for their own
209+
change, they won't conflict with each other and are safe to apply.
208210

209211
### Creating a new document
210212

211-
You can create a new document from the client by calling `sync.create(content)`, or on the server by calling `prosemirrorSync.create(ctx, id, content)`.
213+
You can create a new document from the client by calling `sync.create(content)`,
214+
or on the server by calling `prosemirrorSync.create(ctx, id, content)`.
212215

213216
The content should be a JSON object matching the
214217
[Schema](https://tiptap.dev/docs/editor/core-concepts/schema). If you're using
@@ -229,8 +232,8 @@ For client-side document creation:
229232

230233
### Transforming the document server-side
231234

232-
You can transform the document server-side. It will give you the latest
233-
version of the document, and you return a
235+
You can transform the document server-side. It will give you the latest version
236+
of the document, and you return a
234237
[ProseMirror Transform](https://prosemirror.net/docs/ref/#transform.Transform).
235238

236239
You can make this transoform via `new Transform(doc)` or, if you are hydrating a
@@ -260,11 +263,11 @@ export const transformExample = action({
260263

261264
- The `extensions` should be the same as the ones used by your client editor,
262265
for any extensions that affect the schema (not the sync extension).
263-
- The `transform` function can be called multiple times if the document is
264-
being modified concurrently. Ideally this callback doesn't do any slow
265-
operations internally. Instead, do them beforehand.
266-
- The `doc` may differ from the one returned from `getDoc`. You can compare
267-
the `version` returned from `getDoc` to the second argument to the `transform`
266+
- The `transform` function can be called multiple times if the document is being
267+
modified concurrently. Ideally this callback doesn't do any slow operations
268+
internally. Instead, do them beforehand.
269+
- The `doc` may differ from the one returned from `getDoc`. You can compare the
270+
`version` returned from `getDoc` to the second argument to the `transform`
268271
function to see if the document has changed.
269272
- The `transform` function can return a null value to abort making changes.
270273
- If you're passing along a position to insert the text, be aware that changes
@@ -300,9 +303,9 @@ Features that could be added later:
300303

301304
- Offline editing support: cache the document and local changes in
302305
`sessionStorage` and sync when back online (only for active browser tab).
303-
- Also save snapshots (but not local edits) to `localStorage` so new tabs
304-
can see and edit documents offline (but won't see edits from other tabs
305-
until they're back online).
306+
- Also save snapshots (but not local edits) to `localStorage` so new tabs can
307+
see and edit documents offline (but won't see edits from other tabs until
308+
they're back online).
306309
- Configuration for debouncing syncing steps (to reduce function calls).
307310
- Option to write the concrete value each time a delta is submitted.
308311
- Pluggable storage for ReactNative, assuming single-session.
@@ -329,9 +332,9 @@ Missing features that aren't currently planned:
329332
- Callback to confirm rebases and handle failures in the client (during sync).
330333
- Optimization to sync a snapshot instead of many deltas when an old client
331334
reconnects and doesn't have local changes.
332-
- Handling multiple AsyncStorage instances that are restored from the same
333-
cloud backup, leading to multiple clients with the same clientID. For now,
334-
we'll assume that AsyncStorage is only used by one client at a time.
335+
- Handling multiple AsyncStorage instances that are restored from the same cloud
336+
backup, leading to multiple clients with the same clientID. For now, we'll
337+
assume that AsyncStorage is only used by one client at a time.
335338

336339
<!-- END: Include on https://convex.dev/components -->
337340

commonjs.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

convex.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/convex/schemas/convex.schema.json",
3+
"functions": "example/convex",
4+
"codegen": {
5+
"legacyComponentApi": false
6+
}
7+
}

0 commit comments

Comments
 (0)