@prosekit/core
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -590,2 +590,9 @@ import { AllSelection } from '@prosekit/pm/state'; | ||
*/ | ||
declare function defineNodeViewComponent<T>(options: NodeViewComponentOptions<T>): Extension; | ||
export { defineNodeViewComponent } | ||
export { defineNodeViewComponent as defineNodeViewComponent_alias_1 } | ||
/** | ||
* @internal | ||
*/ | ||
declare function defineNodeViewFactory<T>(options: NodeViewFactoryOptions<T>): Extension; | ||
@@ -1615,9 +1622,15 @@ export { defineNodeViewFactory } | ||
*/ | ||
declare type NodeViewFactoryOptions<T> = { | ||
declare type NodeViewComponentOptions<T> = { | ||
group: string; | ||
name: string; | ||
args: T; | ||
} | { | ||
}; | ||
export { NodeViewComponentOptions } | ||
export { NodeViewComponentOptions as NodeViewComponentOptions_alias_1 } | ||
/** | ||
* @internal | ||
*/ | ||
declare type NodeViewFactoryOptions<T> = { | ||
group: string; | ||
name?: undefined; | ||
factory: (args: T) => NodeViewConstructor; | ||
@@ -1624,0 +1637,0 @@ }; |
@@ -21,4 +21,2 @@ export { addMark } from './_tsup-dts-rollup'; | ||
export { defineCommands } from './_tsup-dts-rollup'; | ||
export { collectNodes } from './_tsup-dts-rollup'; | ||
export { NodeContent } from './_tsup-dts-rollup'; | ||
export { defineDefaultState } from './_tsup-dts-rollup'; | ||
@@ -79,3 +77,5 @@ export { DefaultStateOptions } from './_tsup-dts-rollup'; | ||
export { NodeViewOptions } from './_tsup-dts-rollup'; | ||
export { defineNodeViewComponent } from './_tsup-dts-rollup'; | ||
export { defineNodeViewFactory } from './_tsup-dts-rollup'; | ||
export { NodeViewComponentOptions } from './_tsup-dts-rollup'; | ||
export { NodeViewFactoryOptions } from './_tsup-dts-rollup'; | ||
@@ -108,2 +108,4 @@ export { defineParagraph } from './_tsup-dts-rollup'; | ||
export { clsx } from './_tsup-dts-rollup'; | ||
export { collectNodes } from './_tsup-dts-rollup'; | ||
export { NodeContent } from './_tsup-dts-rollup'; | ||
export { defaultBlockAt } from './_tsup-dts-rollup'; | ||
@@ -110,0 +112,0 @@ export { isApple } from './_tsup-dts-rollup'; |
@@ -361,18 +361,2 @@ import { | ||
// src/utils/collect-nodes.ts | ||
import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model"; | ||
function collectNodes(content) { | ||
if (Array.isArray(content)) | ||
return content.flatMap(collectNodes); | ||
if (content instanceof ProseMirrorNode2) | ||
return [content]; | ||
if (content instanceof ProseMirrorFragment) { | ||
let nodes = []; | ||
for (let i = 0; i < content.childCount; i++) | ||
nodes.push(content.child(i)); | ||
return nodes; | ||
} | ||
throw new ProseKitError(`Invalid node content: ${typeof content}`); | ||
} | ||
// src/extensions/node-spec.ts | ||
@@ -879,19 +863,14 @@ import OrderedMap2 from "orderedmap"; | ||
function defineNodeViewFactory(options) { | ||
return defineFacetPayload(nodeViewFactoryFacet, [options]); | ||
return defineFacetPayload(nodeViewFactoryFacet, [[options, null]]); | ||
} | ||
function defineNodeViewComponent(options) { | ||
return defineFacetPayload(nodeViewFactoryFacet, [[null, options]]); | ||
} | ||
var nodeViewFactoryFacet = defineFacet({ | ||
reducer: (inputs) => { | ||
let nodeViews = {}, options = {}, factories = {}; | ||
for (let input of inputs) { | ||
let group = input.group; | ||
input.name == null ? factories[group] = input.factory : (options[group] || (options[group] = []), options[group].push({ | ||
name: input.name, | ||
args: input.args | ||
})); | ||
let nodeViews = {}, factories = inputs.map((x) => x[0]).filter(isNotNull), options = inputs.map((x) => x[1]).filter(isNotNull); | ||
for (let { group, name, args } of options) { | ||
let factory = factories.find((factory2) => factory2.group === group); | ||
factory && (nodeViews[name] = factory.factory(args)); | ||
} | ||
for (let [group, factory] of Object.entries(factories)) { | ||
let groupOptions = options[group] || []; | ||
for (let { name, args } of groupOptions) | ||
nodeViews[name] = factory(args); | ||
} | ||
return () => [ | ||
@@ -950,2 +929,18 @@ new ProseMirrorPlugin6({ | ||
// src/utils/collect-nodes.ts | ||
import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model"; | ||
function collectNodes(content) { | ||
if (Array.isArray(content)) | ||
return content.flatMap(collectNodes); | ||
if (content instanceof ProseMirrorNode2) | ||
return [content]; | ||
if (content instanceof ProseMirrorFragment) { | ||
let nodes = []; | ||
for (let i = 0; i < content.childCount; i++) | ||
nodes.push(content.child(i)); | ||
return nodes; | ||
} | ||
throw new ProseKitError(`Invalid node content: ${typeof content}`); | ||
} | ||
// src/utils/default-block-at.ts | ||
@@ -1025,2 +1020,3 @@ function defaultBlockAt(match) { | ||
defineNodeView, | ||
defineNodeViewComponent, | ||
defineNodeViewFactory, | ||
@@ -1027,0 +1023,0 @@ defineParagraph, |
{ | ||
"name": "@prosekit/core", | ||
"type": "module", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"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
135904
4001