@prosekit/core
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -9,2 +9,4 @@ import { AllSelection } from '@prosekit/pm/state'; | ||
import type { DOMEventMap } from '@prosekit/pm/view'; | ||
import { DOMParser as DOMParser_2 } from '@prosekit/pm/model'; | ||
import { DOMSerializer } from '@prosekit/pm/model'; | ||
import { EditorState } from '@prosekit/pm/state'; | ||
@@ -609,2 +611,9 @@ import type { EditorStateConfig } from '@prosekit/pm/state'; | ||
/** @public */ | ||
declare type DOMDocumentOptions = { | ||
document?: Document; | ||
}; | ||
export { DOMDocumentOptions } | ||
export { DOMDocumentOptions as DOMDocumentOptions_alias_1 } | ||
/** | ||
@@ -634,2 +643,16 @@ * @internal | ||
/** @public */ | ||
declare type DOMParserOptions = { | ||
DOMParser?: typeof DOMParser_2; | ||
}; | ||
export { DOMParserOptions } | ||
export { DOMParserOptions as DOMParserOptions_alias_1 } | ||
/** @public */ | ||
declare type DOMSerializerOptions = { | ||
DOMSerializer?: typeof DOMSerializer; | ||
}; | ||
export { DOMSerializerOptions } | ||
export { DOMSerializerOptions as DOMSerializerOptions_alias_1 } | ||
declare type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void; | ||
@@ -741,5 +764,3 @@ export { DoubleClickHandler } | ||
*/ | ||
export declare function elementFromHTML(html: string, options?: { | ||
document?: Document; | ||
}): HTMLElement; | ||
export declare function elementFromHTML(html: string, options?: DOMDocumentOptions): HTMLElement; | ||
@@ -751,5 +772,3 @@ /** | ||
*/ | ||
declare function elementFromJSON(json: NodeJSON, schema: Schema, options?: { | ||
document?: Document; | ||
}): HTMLElement; | ||
declare function elementFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): HTMLElement; | ||
export { elementFromJSON } | ||
@@ -763,5 +782,3 @@ export { elementFromJSON as elementFromJSON_alias_1 } | ||
*/ | ||
declare function elementFromNode(node: ProseMirrorNode, options?: { | ||
document?: Document; | ||
}): HTMLElement; | ||
declare function elementFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): HTMLElement; | ||
export { elementFromNode } | ||
@@ -1002,5 +1019,3 @@ export { elementFromNode as elementFromNode_alias_1 } | ||
*/ | ||
declare function htmlFromJSON(json: NodeJSON, schema: Schema, options?: { | ||
document?: Document; | ||
}): string; | ||
declare function htmlFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): string; | ||
export { htmlFromJSON } | ||
@@ -1014,3 +1029,3 @@ export { htmlFromJSON as htmlFromJSON_alias_1 } | ||
*/ | ||
declare function htmlFromNode(node: ProseMirrorNode): string; | ||
declare function htmlFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): string; | ||
export { htmlFromNode } | ||
@@ -1117,3 +1132,3 @@ export { htmlFromNode as htmlFromNode_alias_1 } | ||
*/ | ||
export declare function jsonFromElement(element: DOMNode, schema: Schema): NodeJSON; | ||
export declare function jsonFromElement(element: DOMNode, options: DOMParserOptions & JSONParserOptions): NodeJSON; | ||
@@ -1125,5 +1140,3 @@ /** | ||
*/ | ||
declare function jsonFromHTML(html: string, schema: Schema, options?: { | ||
document?: Document; | ||
}): NodeJSON; | ||
declare function jsonFromHTML(html: string, options: DOMDocumentOptions & DOMParserOptions & JSONParserOptions): NodeJSON; | ||
export { jsonFromHTML } | ||
@@ -1150,2 +1163,9 @@ export { jsonFromHTML as jsonFromHTML_alias_1 } | ||
/** @public */ | ||
declare type JSONParserOptions = { | ||
schema: Schema; | ||
}; | ||
export { JSONParserOptions } | ||
export { JSONParserOptions as JSONParserOptions_alias_1 } | ||
declare type KeyDownHandler = (view: EditorView, event: KeyboardEvent) => boolean | void; | ||
@@ -1283,3 +1303,3 @@ export { KeyDownHandler } | ||
*/ | ||
declare function nodeFromElement(element: DOMNode, schema: Schema): ProseMirrorNode; | ||
declare function nodeFromElement(element: DOMNode, options: DOMParserOptions & JSONParserOptions): ProseMirrorNode; | ||
export { nodeFromElement } | ||
@@ -1293,5 +1313,3 @@ export { nodeFromElement as nodeFromElement_alias_1 } | ||
*/ | ||
declare function nodeFromHTML(html: string, schema: Schema, options?: { | ||
document?: Document; | ||
}): ProseMirrorNode; | ||
declare function nodeFromHTML(html: string, options: DOMParserOptions & JSONParserOptions & DOMDocumentOptions): ProseMirrorNode; | ||
export { nodeFromHTML } | ||
@@ -1305,3 +1323,3 @@ export { nodeFromHTML as nodeFromHTML_alias_1 } | ||
*/ | ||
declare function nodeFromJSON(json: NodeJSON, schema: Schema): ProseMirrorNode; | ||
declare function nodeFromJSON(json: NodeJSON, options: JSONParserOptions): ProseMirrorNode; | ||
export { nodeFromJSON } | ||
@@ -1558,3 +1576,3 @@ export { nodeFromJSON as nodeFromJSON_alias_1 } | ||
*/ | ||
declare function stateFromJSON(json: StateJSON, schema: Schema): EditorState; | ||
declare function stateFromJSON(json: StateJSON, options: JSONParserOptions): EditorState; | ||
export { stateFromJSON } | ||
@@ -1561,0 +1579,0 @@ export { stateFromJSON as stateFromJSON_alias_1 } |
@@ -113,2 +113,6 @@ export { addMark } from './_tsup-dts-rollup'; | ||
export { stateFromJSON } from './_tsup-dts-rollup'; | ||
export { DOMDocumentOptions } from './_tsup-dts-rollup'; | ||
export { DOMParserOptions } from './_tsup-dts-rollup'; | ||
export { DOMSerializerOptions } from './_tsup-dts-rollup'; | ||
export { JSONParserOptions } from './_tsup-dts-rollup'; | ||
export { isAllSelection } from './_tsup-dts-rollup'; | ||
@@ -115,0 +119,0 @@ export { isMark } from './_tsup-dts-rollup'; |
@@ -488,4 +488,4 @@ // src/commands/add-mark.ts | ||
} | ||
function stateFromJSON(json, schema) { | ||
return EditorState.fromJSON({ schema }, json); | ||
function stateFromJSON(json, options) { | ||
return EditorState.fromJSON({ schema: options.schema }, json); | ||
} | ||
@@ -495,17 +495,24 @@ function jsonFromNode(node) { | ||
} | ||
function nodeFromJSON(json, schema) { | ||
return schema.nodeFromJSON(json); | ||
function nodeFromJSON(json, options) { | ||
return options.schema.nodeFromJSON(json); | ||
} | ||
function nodeFromElement(element, schema) { | ||
return DOMParser.fromSchema(schema).parse(element); | ||
function nodeFromElement(element, options) { | ||
const Parser = options.DOMParser || DOMParser; | ||
const schema = options.schema; | ||
return Parser.fromSchema(schema).parse(element); | ||
} | ||
function elementFromNode(node, options) { | ||
const Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer; | ||
const document2 = getBrowserDocument(options); | ||
const schema = node.type.schema; | ||
const serializer = DOMSerializer.fromSchema(schema); | ||
const serializer = Serializer.fromSchema(schema); | ||
if (schema.topNodeType !== node.type) { | ||
return serializer.serializeNode(node, options); | ||
return serializer.serializeNode(node, { document: document2 }); | ||
} else { | ||
return serializer.serializeFragment( | ||
node.content, | ||
{ document: document2 }, | ||
document2.createElement("div") | ||
); | ||
} | ||
const doc = getBrowserDocument(); | ||
const div = doc.createElement("div"); | ||
return serializer.serializeFragment(node.content, options, div); | ||
} | ||
@@ -520,19 +527,19 @@ function elementFromHTML(html, options) { | ||
} | ||
function nodeFromHTML(html, schema, options) { | ||
return nodeFromElement(elementFromHTML(html, options), schema); | ||
function nodeFromHTML(html, options) { | ||
return nodeFromElement(elementFromHTML(html, options), options); | ||
} | ||
function htmlFromNode(node) { | ||
return elementFromNode(node).outerHTML; | ||
function htmlFromNode(node, options) { | ||
return elementFromNode(node, options).outerHTML; | ||
} | ||
function jsonFromElement(element, schema) { | ||
return jsonFromNode(nodeFromElement(element, schema)); | ||
function jsonFromElement(element, options) { | ||
return jsonFromNode(nodeFromElement(element, options)); | ||
} | ||
function elementFromJSON(json, schema, options) { | ||
return elementFromNode(nodeFromJSON(json, schema), options); | ||
function elementFromJSON(json, options) { | ||
return elementFromNode(nodeFromJSON(json, options), options); | ||
} | ||
function jsonFromHTML(html, schema, options) { | ||
return jsonFromElement(elementFromHTML(html, options), schema); | ||
function jsonFromHTML(html, options) { | ||
return jsonFromElement(elementFromHTML(html, options), options); | ||
} | ||
function htmlFromJSON(json, schema, options) { | ||
return htmlFromElement(elementFromJSON(json, schema, options)); | ||
function htmlFromJSON(json, options) { | ||
return htmlFromElement(elementFromJSON(json, options)); | ||
} | ||
@@ -556,5 +563,5 @@ | ||
if (typeof defaultHTML === "string") { | ||
defaultDoc = jsonFromHTML(defaultHTML, schema); | ||
defaultDoc = jsonFromHTML(defaultHTML, { schema }); | ||
} else { | ||
defaultDoc = jsonFromElement(defaultHTML, schema); | ||
defaultDoc = jsonFromElement(defaultHTML, { schema }); | ||
} | ||
@@ -561,0 +568,0 @@ } |
{ | ||
"name": "@prosekit/core", | ||
"type": "module", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116574
3617