@openeditor/tiptap 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +53 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BlockSpec, OpenEditorDocument } from '@openeditor/core';
|
|
2
|
+
import { NodeConfig, Node, Extensions } from '@tiptap/core';
|
|
3
|
+
import { Schema } from '@tiptap/pm/model';
|
|
4
|
+
|
|
5
|
+
type OpenEditorTiptapDiagnostic = {
|
|
6
|
+
code: "invalid_prosemirror_document" | "block_contract_mismatch";
|
|
7
|
+
path: string;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
type OpenEditorTiptapValidationResult = {
|
|
11
|
+
valid: true;
|
|
12
|
+
diagnostics: readonly [];
|
|
13
|
+
} | {
|
|
14
|
+
valid: false;
|
|
15
|
+
diagnostics: readonly OpenEditorTiptapDiagnostic[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A server-safe block definition. React node views and other presentation
|
|
19
|
+
* adapters consume this definition instead of owning the ProseMirror schema.
|
|
20
|
+
*/
|
|
21
|
+
type OpenEditorTiptapBlock = {
|
|
22
|
+
block: BlockSpec;
|
|
23
|
+
extension: Node;
|
|
24
|
+
};
|
|
25
|
+
type DefineOpenEditorTiptapNodeOptions = {
|
|
26
|
+
block: BlockSpec;
|
|
27
|
+
node: Omit<Partial<NodeConfig>, "name" | "addNodeView">;
|
|
28
|
+
};
|
|
29
|
+
declare const defineOpenEditorTiptapNode: ({ block, node, }: DefineOpenEditorTiptapNodeOptions) => OpenEditorTiptapBlock;
|
|
30
|
+
declare const getOpenEditorTiptapSchema: (extensions: Extensions) => Schema;
|
|
31
|
+
/** Validate with the real configured ProseMirror schema in a DOM-free runtime. */
|
|
32
|
+
declare const validateOpenEditorTiptapDocument: (document: OpenEditorDocument, extensions: Extensions) => OpenEditorTiptapValidationResult;
|
|
33
|
+
type OpenEditorTiptapSchemaManifest = {
|
|
34
|
+
topNode: string;
|
|
35
|
+
nodes: Readonly<Record<string, {
|
|
36
|
+
inline: boolean;
|
|
37
|
+
atom: boolean;
|
|
38
|
+
leaf: boolean;
|
|
39
|
+
group: string | null;
|
|
40
|
+
contentExpression: string | null;
|
|
41
|
+
marksExpression: string | null;
|
|
42
|
+
defining: boolean;
|
|
43
|
+
isolating: boolean;
|
|
44
|
+
attributes: readonly string[];
|
|
45
|
+
}>>;
|
|
46
|
+
marks: Readonly<Record<string, {
|
|
47
|
+
attributes: readonly string[];
|
|
48
|
+
}>>;
|
|
49
|
+
};
|
|
50
|
+
/** A deterministic, JSON-safe description for workspace instructions and review tooling. */
|
|
51
|
+
declare const createOpenEditorTiptapSchemaManifest: (extensions: Extensions) => OpenEditorTiptapSchemaManifest;
|
|
52
|
+
|
|
53
|
+
export { type DefineOpenEditorTiptapNodeOptions, type OpenEditorTiptapBlock, type OpenEditorTiptapDiagnostic, type OpenEditorTiptapSchemaManifest, type OpenEditorTiptapValidationResult, createOpenEditorTiptapSchemaManifest, defineOpenEditorTiptapNode, getOpenEditorTiptapSchema, validateOpenEditorTiptapDocument };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { toProseMirrorDocument } from '@openeditor/core';
|
|
2
|
+
import { Node, getSchema } from '@tiptap/core';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
var defineOpenEditorTiptapNode = ({
|
|
6
|
+
block,
|
|
7
|
+
node
|
|
8
|
+
}) => ({
|
|
9
|
+
block,
|
|
10
|
+
extension: Node.create({
|
|
11
|
+
...node,
|
|
12
|
+
name: block.nodeType ?? block.name
|
|
13
|
+
})
|
|
14
|
+
});
|
|
15
|
+
var getOpenEditorTiptapSchema = (extensions) => getSchema(extensions);
|
|
16
|
+
var validateOpenEditorTiptapDocument = (document, extensions) => {
|
|
17
|
+
try {
|
|
18
|
+
const schema = getOpenEditorTiptapSchema(extensions);
|
|
19
|
+
const node = schema.nodeFromJSON(toProseMirrorDocument(document));
|
|
20
|
+
node.check();
|
|
21
|
+
return { valid: true, diagnostics: [] };
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return {
|
|
24
|
+
valid: false,
|
|
25
|
+
diagnostics: [{
|
|
26
|
+
code: "invalid_prosemirror_document",
|
|
27
|
+
path: "$",
|
|
28
|
+
message: error instanceof Error ? error.message : "Document does not match the configured ProseMirror schema."
|
|
29
|
+
}]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var createOpenEditorTiptapSchemaManifest = (extensions) => {
|
|
34
|
+
const schema = getOpenEditorTiptapSchema(extensions);
|
|
35
|
+
return {
|
|
36
|
+
topNode: schema.topNodeType.name,
|
|
37
|
+
nodes: Object.fromEntries(Object.entries(schema.nodes).sort(([left], [right]) => left.localeCompare(right)).map(([name, type]) => [name, {
|
|
38
|
+
inline: type.isInline,
|
|
39
|
+
atom: type.isAtom,
|
|
40
|
+
leaf: type.isLeaf,
|
|
41
|
+
group: type.spec.group ?? null,
|
|
42
|
+
contentExpression: type.spec.content ?? null,
|
|
43
|
+
marksExpression: type.spec.marks ?? null,
|
|
44
|
+
defining: Boolean(type.spec.defining),
|
|
45
|
+
isolating: Boolean(type.spec.isolating),
|
|
46
|
+
attributes: Object.keys(type.spec.attrs ?? {}).sort()
|
|
47
|
+
}])),
|
|
48
|
+
marks: Object.fromEntries(Object.entries(schema.marks).sort(([left], [right]) => left.localeCompare(right)).map(([name, type]) => [name, {
|
|
49
|
+
attributes: Object.keys(type.spec.attrs ?? {}).sort()
|
|
50
|
+
}]))
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { createOpenEditorTiptapSchemaManifest, defineOpenEditorTiptapNode, getOpenEditorTiptapSchema, validateOpenEditorTiptapDocument };
|
|
55
|
+
//# sourceMappingURL=index.js.map
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F","file":"index.js","sourcesContent":["import {\n type BlockSpec,\n type OpenEditorDocument,\n toProseMirrorDocument,\n} from \"@openeditor/core\";\nimport {\n Node,\n getSchema,\n type Extensions,\n type NodeConfig,\n} from \"@tiptap/core\";\nimport type { Schema } from \"@tiptap/pm/model\";\n\nexport type OpenEditorTiptapDiagnostic = {\n code: \"invalid_prosemirror_document\" | \"block_contract_mismatch\";\n path: string;\n message: string;\n};\n\nexport type OpenEditorTiptapValidationResult =\n | { valid: true; diagnostics: readonly [] }\n | { valid: false; diagnostics: readonly OpenEditorTiptapDiagnostic[] };\n\n/**\n * A server-safe block definition. React node views and other presentation\n * adapters consume this definition instead of owning the ProseMirror schema.\n */\nexport type OpenEditorTiptapBlock = {\n block: BlockSpec;\n extension: Node;\n};\n\nexport type DefineOpenEditorTiptapNodeOptions = {\n block: BlockSpec;\n node: Omit<Partial<NodeConfig>, \"name\" | \"addNodeView\">;\n};\n\nexport const defineOpenEditorTiptapNode = ({\n block,\n node,\n}: DefineOpenEditorTiptapNodeOptions): OpenEditorTiptapBlock => ({\n block,\n extension: Node.create({\n ...node,\n name: block.nodeType ?? block.name,\n }),\n});\n\nexport const getOpenEditorTiptapSchema = (extensions: Extensions): Schema =>\n getSchema(extensions);\n\n/** Validate with the real configured ProseMirror schema in a DOM-free runtime. */\nexport const validateOpenEditorTiptapDocument = (\n document: OpenEditorDocument,\n extensions: Extensions,\n): OpenEditorTiptapValidationResult => {\n try {\n const schema = getOpenEditorTiptapSchema(extensions);\n const node = schema.nodeFromJSON(toProseMirrorDocument(document));\n node.check();\n return { valid: true, diagnostics: [] };\n } catch (error) {\n return {\n valid: false,\n diagnostics: [{\n code: \"invalid_prosemirror_document\",\n path: \"$\",\n message: error instanceof Error ? error.message : \"Document does not match the configured ProseMirror schema.\",\n }],\n };\n }\n};\n\nexport type OpenEditorTiptapSchemaManifest = {\n topNode: string;\n nodes: Readonly<Record<string, {\n inline: boolean;\n atom: boolean;\n leaf: boolean;\n group: string | null;\n contentExpression: string | null;\n marksExpression: string | null;\n defining: boolean;\n isolating: boolean;\n attributes: readonly string[];\n }>>;\n marks: Readonly<Record<string, { attributes: readonly string[] }>>;\n};\n\n/** A deterministic, JSON-safe description for workspace instructions and review tooling. */\nexport const createOpenEditorTiptapSchemaManifest = (\n extensions: Extensions,\n): OpenEditorTiptapSchemaManifest => {\n const schema = getOpenEditorTiptapSchema(extensions);\n return {\n topNode: schema.topNodeType.name,\n nodes: Object.fromEntries(Object.entries(schema.nodes)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([name, type]) => [name, {\n inline: type.isInline,\n atom: type.isAtom,\n leaf: type.isLeaf,\n group: type.spec.group ?? null,\n contentExpression: type.spec.content ?? null,\n marksExpression: type.spec.marks ?? null,\n defining: Boolean(type.spec.defining),\n isolating: Boolean(type.spec.isolating),\n attributes: Object.keys(type.spec.attrs ?? {}).sort(),\n }])),\n marks: Object.fromEntries(Object.entries(schema.marks)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([name, type]) => [name, {\n attributes: Object.keys(type.spec.attrs ?? {}).sort(),\n }])),\n };\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openeditor/tiptap",
|
|
3
|
+
"version": "0.0.36",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/EasyLink-HQ/openeditor.git",
|
|
9
|
+
"directory": "packages/tiptap"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@openeditor/core": "0.0.36",
|
|
28
|
+
"@tiptap/core": "3.29.2",
|
|
29
|
+
"@tiptap/pm": "3.29.2"
|
|
30
|
+
}
|
|
31
|
+
}
|