snapshot of https://github.com/ueberdosis/hocuspocus.git @ cf3cfa355b4d3bb61c6b6c80071f71783e32470e (2026-09-15)
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-15 17:21:35 +05:00
commit e0c588ca1c
265 changed files with 55259 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
# @hocuspocus/transformer
[![Version](https://img.shields.io/npm/v/@hocuspocus/transformer.svg?label=version)](https://www.npmjs.com/package/@hocuspocus/transformer)
[![Downloads](https://img.shields.io/npm/dm/@hocuspocus/transformer.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@hocuspocus/transformer.svg)](https://www.npmjs.com/package/@hocuspocus/transformer)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
## Introduction
Convert [Y.js](https://github.com/yjs/yjs) documents to and from [Tiptap](https://github.com/ueberdosis/tiptap) / ProseMirror JSON and HTML. Useful on the server side to render or process collaborative document state outside the editor – for exports, previews, or webhook payloads.
## Official Documentation
Documentation can be found in the [GitHub repository](https://github.com/ueberdosis/hocuspocus).
## License
Hocuspocus is open-sourced software licensed under the [MIT license](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).

View File

@@ -0,0 +1,49 @@
{
"name": "@hocuspocus/transformer",
"version": "4.7.0",
"description": "hocuspocus transformation utilities",
"homepage": "https://hocuspocus.dev",
"keywords": [
"hocuspocus",
"transformer",
"yjs"
],
"license": "MIT",
"type": "module",
"main": "dist/hocuspocus-transformer.cjs",
"module": "dist/hocuspocus-transformer.esm.js",
"types": "dist/index.d.ts",
"exports": {
"source": {
"import": "./src/index.ts"
},
"default": {
"import": "./dist/hocuspocus-transformer.esm.js",
"require": "./dist/hocuspocus-transformer.cjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"src",
"dist"
],
"dependencies": {
"@tiptap/starter-kit": "^3.19.0"
},
"peerDependencies": {
"@tiptap/core": "^3.0.1",
"@tiptap/pm": "^3.0.1",
"y-prosemirror": "^1.2.1",
"yjs": "^13.6.8"
},
"devDependencies": {
"@tiptap/pm": "^3.19.0"
},
"gitHead": "8f2e9df95de9968d70622ea8697c303a333b6cb3",
"repository": {
"url": "https://github.com/ueberdosis/hocuspocus"
},
"publishConfig": {
"access": "public"
}
}

View File

@@ -0,0 +1,76 @@
import { Doc, applyUpdate, encodeStateAsUpdate } from "yjs";
// @ts-expect-error
import { yDocToProsemirrorJSON, prosemirrorJSONToYDoc } from "y-prosemirror";
import { Schema } from "@tiptap/pm/model";
import type { Transformer } from "./types.ts";
class Prosemirror implements Transformer {
defaultSchema: Schema = new Schema({
nodes: {
text: {},
doc: { content: "text*" },
},
});
schema(schema: Schema): Prosemirror {
this.defaultSchema = schema;
return this;
}
fromYdoc(document: Doc, fieldName?: string | Array<string>): any {
const data = {};
// allow a single field name
if (typeof fieldName === "string") {
return yDocToProsemirrorJSON(document, fieldName);
}
// default to all available fields if the given field name is empty
if (fieldName === undefined || fieldName.length === 0) {
fieldName = Array.from(document.share.keys());
}
fieldName.forEach((field) => {
// @ts-expect-error
data[field] = yDocToProsemirrorJSON(document, field);
});
return data;
}
toYdoc(
document: any,
fieldName: string | Array<string> = "prosemirror",
schema?: Schema,
): Doc {
if (!document) {
throw new Error(
`You’ve passed an empty or invalid document to the Transformer. Make sure to pass ProseMirror-compatible JSON. Actually passed JSON: ${document}`,
);
}
// allow a single field name
if (typeof fieldName === "string") {
return prosemirrorJSONToYDoc(
schema || this.defaultSchema,
document,
fieldName,
);
}
const ydoc = new Doc();
fieldName.forEach((field) => {
const update = encodeStateAsUpdate(
prosemirrorJSONToYDoc(schema || this.defaultSchema, document, field),
);
applyUpdate(ydoc, update);
});
return ydoc;
}
}
export const ProsemirrorTransformer = new Prosemirror();

View File

@@ -0,0 +1,35 @@
import type { Doc } from "yjs";
// @ts-expect-error
import type { Extensions } from "@tiptap/core";
import { getSchema } from "@tiptap/core";
import { StarterKit } from "@tiptap/starter-kit";
import type { Transformer } from "./types.ts";
import { ProsemirrorTransformer } from "./Prosemirror.ts";
export class Tiptap implements Transformer {
defaultExtensions: Extensions = [StarterKit];
extensions(extensions: Extensions): Tiptap {
this.defaultExtensions = extensions;
return this;
}
fromYdoc(document: Doc, fieldName?: string | Array<string>): any {
return ProsemirrorTransformer.fromYdoc(document, fieldName);
}
toYdoc(
document: any,
fieldName: string | Array<string> = "default",
extensions?: Extensions,
): Doc {
return ProsemirrorTransformer.toYdoc(
document,
fieldName,
getSchema(extensions || this.defaultExtensions),
);
}
}
export const TiptapTransformer = new Tiptap();

View File

@@ -0,0 +1,3 @@
export * from "./Prosemirror.ts";
export * from "./Tiptap.ts";
export * from "./types.ts";

View File

@@ -0,0 +1,6 @@
import type { Doc } from "yjs";
export interface Transformer {
fromYdoc: (document: Doc, fieldName?: string | Array<string>) => any;
toYdoc: (document: any, fieldName: string) => Doc;
}