Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prosekit/core

Package Overview
Dependencies
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prosekit/core - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

9

./src/index.ts

@@ -5,3 +5,3 @@ export { addMark, type AddMarkOptions } from './commands/add-mark'

export { Editor, createEditor, type EditorOptions } from './editor/editor'
export { Facet, FacetExtension, type FacetOptions } from './editor/facet'
export { Facet, FacetExtension, type FacetOptions } from './facets/facet'
export { union } from './editor/type-utils'

@@ -27,2 +27,6 @@ export { withPriority } from './editor/with-priority'

export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
export {
defineNodeViewEffect,
type NodeViewEffectOptions,
} from './extensions/node-view-effect'
export { defineParagraph } from './extensions/paragraph'

@@ -32,7 +36,6 @@ export {

pluginFacet,
type PluginFacetInput,
type PluginPayload,
} from './extensions/plugin'
export { defineText } from './extensions/text'
export { type CommandArgs as CommandArgs } from './types/command'
export * from './types/editor'
export {

@@ -39,0 +42,0 @@ type Extension,

@@ -52,4 +52,2 @@ import { Attrs } from '@prosekit/pm/model';

export declare type AnySlot = Slot<any, any>;
export declare function applyAction(operator: Action): Command;

@@ -82,6 +80,10 @@

export declare const commandSlot: Facet<CommandSlotInput, CommandSlotInput>;
export declare const commandFacet: Facet<CommandCreators, CommandCreators>;
export declare type CommandSlotInput = Record<string, CommandCreator<any>>;
export declare type CommandPayload = CommandCreators;
export declare type Converters = ConverterTuple[];
declare type ConverterTuple = Tuple5<FacetConverter | undefined>;
/** @public */

@@ -174,3 +176,3 @@ declare function createEditor<E extends Extension>({ extension, defaultDoc, defaultSelection, }: EditorOptions<E>): Editor<E>;

update?: VoidFunction;
}): FacetExtension<VoidFunction, PluginFacetInput>;
}): FacetExtension<VoidFunction, PluginPayload>;
export { defineEventHandler }

@@ -227,2 +229,6 @@ export { defineEventHandler as defineEventHandler_alias_1 }

declare function defineNodeViewEffect(options: NodeViewEffectOptions): Extension;
export { defineNodeViewEffect }
export { defineNodeViewEffect as defineNodeViewEffect_alias_1 }
/** @public */

@@ -384,12 +390,10 @@ declare function defineParagraph(): Extension< {

/** @internal */
readonly slot: () => Slot<Input, Output>;
readonly converter: () => FacetConverter<Input, Output>;
/** @internal */
readonly next: Facet<Output, any> | null;
/** @internal */
readonly single: boolean;
private constructor();
static define<Input, Output>({ slot, combine, next, single, }: FacetOptions<Input, Output>): Facet<Input, Output>;
static define<Input, Output>({ converter: converter, convert: convert, next, }: FacetOptions<Input, Output>): Facet<Input, Output>;
/** @internal */
static defineSlot<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
extension(inputs: Input[]): FacetExtension<Input, Output>;
static defineRootFacet<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
extension(payloads: Input[]): FacetExtension<Input, Output>;
}

@@ -400,7 +404,13 @@ export { Facet }

/** @public */
export declare interface FacetConverter<Input = any, Output = any> {
create: (inputs: Input[]) => Output;
update: (inputs: Input[]) => Output | null;
}
/** @public */
declare class FacetExtension<Input, Output> {
readonly facet: Facet<Input, Output>;
readonly inputs: Input[];
readonly payloads: Input[];
extension: Extension;
constructor(facet: Facet<Input, Output>, inputs: Input[]);
constructor(facet: Facet<Input, Output>, payloads: Input[]);
}

@@ -412,6 +422,5 @@ export { FacetExtension }

declare interface FacetOptions<Input, Output> {
combine?: (inputs: Input[]) => Output;
slot?: () => Slot<Input, Output>;
convert?: (payloads: Input[]) => Output;
converter?: () => FacetConverter<Input, Output>;
next: Facet<Output, any>;
single?: boolean;
}

@@ -421,2 +430,4 @@ export { FacetOptions }

export declare function getFacetCount(): number;
/** @internal */

@@ -432,8 +443,2 @@ declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;

declare type Input = unknown;
export declare type Inputs = InputTuple[];
declare type InputTuple = [Input[], Input[], Input[], Input[], Input[]];
export declare function insertNode({ node, pos, }: {

@@ -511,2 +516,14 @@ node: ProseMirrorNode;

declare type NodeViewEffectOptions = {
group: string;
name: string;
args: unknown;
} | {
group: string;
name?: undefined;
factory: (args: unknown) => NodeViewConstructor;
};
export { NodeViewEffectOptions }
export { NodeViewEffectOptions as NodeViewEffectOptions_alias_1 }
declare interface NodeViewOptions {

@@ -521,4 +538,10 @@ name: string;

declare type Payload = unknown;
export declare type Payloads = PayloadTuple[];
declare type PayloadTuple = Tuple5<Payload[]>;
/** @internal */
declare const pluginFacet: Facet<PluginFacetInput, StateConfigCallback>;
declare const pluginFacet: Facet<PluginPayload, StatePayload>;
export { pluginFacet }

@@ -528,7 +551,7 @@ export { pluginFacet as pluginFacet_alias_1 }

/** @internal */
declare type PluginFacetInput = (context: {
declare type PluginPayload = (context: {
schema: Schema;
}) => Plugin_2[];
export { PluginFacetInput }
export { PluginFacetInput as PluginFacetInput_alias_1 }
export { PluginPayload }
export { PluginPayload as PluginPayload_alias_1 }

@@ -556,4 +579,6 @@ /**

export declare const schemaSlot: Facet<SchemaSpec<any, any>, SchemaSpec<any, any>>;
export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
export declare type SchemaPayload = SchemaSpec;
/**

@@ -590,33 +615,5 @@ * A JSON representation of the prosemirror selection.

export declare interface Slot<Input, Output> {
create: (inputs: Input[]) => Output;
update: (inputs: Input[]) => Output | null;
}
export declare const stateFacet: Facet<StatePayload, StatePayload>;
export declare type Slots = SlotTuple[];
declare type SlotTuple = [
AnySlot | undefined,
AnySlot | undefined,
AnySlot | undefined,
AnySlot | undefined,
AnySlot | undefined
];
/**
* Use topological sort algorithm to sort facets.
*/
export declare function sortFacets(unsorted: readonly Facet<any, any>[]): Facet<any, any>[];
declare type StateConfigCallback = (ctx: StateConfigContext) => EditorStateConfig;
export { StateConfigCallback }
export { StateConfigCallback as StateConfigCallback_alias_1 }
declare interface StateConfigContext {
schema: Schema;
}
export { StateConfigContext }
export { StateConfigContext as StateConfigContext_alias_1 }
/**
* A JSON representation of the prosemirror state.

@@ -639,3 +636,5 @@ *

export declare const stateSlot: Facet<StateConfigCallback, StateConfigCallback>;
export declare type StatePayload = (ctx: {
schema: Schema;
}) => EditorStateConfig;

@@ -676,2 +675,4 @@ export declare type ToCommandApplier<T extends CommandArgs> = {

declare type Tuple5<T> = [T, T, T, T, T];
declare function union<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;

@@ -685,14 +686,12 @@ export { union }

export declare function updateExtension(prevInputs: Inputs, prevSlots: Slots, extension: Extension, mode: 'add' | 'remove'): {
schemaInput: SchemaSpec<any, any> | null;
stateInput: StateConfigCallback | null;
viewInput: ViewProps | null;
commandInput: CommandSlotInput | null;
export declare function updateExtension(prevInputs: Payloads, prevConverters: Converters, extension: Extension, mode: 'add' | 'remove'): {
schemaInput: SchemaPayload | null;
stateInput: StatePayload | null;
viewInput: ViewPayload | null;
commandInput: CommandCreators | null;
};
declare type ViewProps = Omit<DirectEditorProps, 'state'>;
export { ViewProps }
export { ViewProps as ViewProps_alias_1 }
export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
export declare const viewSlot: Facet<ViewProps, ViewProps>;
export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;

@@ -699,0 +698,0 @@ export declare function voidFunction(): void;

@@ -33,6 +33,8 @@ export { addMark } from './_tsup-dts-rollup';

export { NodeViewOptions } from './_tsup-dts-rollup';
export { defineNodeViewEffect } from './_tsup-dts-rollup';
export { NodeViewEffectOptions } from './_tsup-dts-rollup';
export { defineParagraph } from './_tsup-dts-rollup';
export { definePlugin } from './_tsup-dts-rollup';
export { pluginFacet } from './_tsup-dts-rollup';
export { PluginFacetInput } from './_tsup-dts-rollup';
export { PluginPayload } from './_tsup-dts-rollup';
export { defineText } from './_tsup-dts-rollup';

@@ -54,4 +56,1 @@ export { CommandArgs } from './_tsup-dts-rollup';

export { getNodeType } from './_tsup-dts-rollup';
export { StateConfigContext } from './_tsup-dts-rollup';
export { StateConfigCallback } from './_tsup-dts-rollup';
export { ViewProps } from './_tsup-dts-rollup';

@@ -137,5 +137,2 @@ // src/commands/add-mark.ts

// src/editor/slots.ts
import OrderedMap from "orderedmap";
// src/utils/uniq-array.ts

@@ -162,111 +159,46 @@ function uniqPush(prev, next) {

// src/editor/facet.ts
var nextIndex = 0;
// src/facets/facet.ts
var facetCount = 0;
function getFacetCount() {
return facetCount;
}
var Facet = class _Facet {
constructor(slot, next, single) {
constructor(converter, next) {
/** @internal */
this.index = nextIndex++;
this.slot = slot;
this.index = facetCount++;
this.converter = converter;
this.next = next;
this.single = single;
}
static define({
slot,
combine,
next,
single
converter,
convert,
next
}) {
const slotFn = slot ? slot : combine ? () => ({
create: combine,
update: combine
const converterFunction = converter ? converter : convert ? () => ({
create: convert,
update: convert
}) : null;
if (!slotFn) {
throw new ProseKitError(
"Facet must have either 'slot' or 'combine' option"
);
if (!converterFunction) {
throw new ProseKitError("Facet must have either 'convert' or 'converter'");
}
return new _Facet(slotFn, next, single != null ? single : false);
return new _Facet(converterFunction, next);
}
/** @internal */
static defineSlot(options) {
static defineRootFacet(options) {
return _Facet.define(options);
}
extension(inputs) {
return new FacetExtension(this, inputs);
extension(payloads) {
return new FacetExtension(this, payloads);
}
};
var FacetExtension = class {
constructor(facet, inputs) {
constructor(facet, payloads) {
this.facet = facet;
this.inputs = inputs;
this.payloads = payloads;
}
};
function sortFacets(unsorted) {
var _a;
const facets = unsorted.filter((val) => val);
const facetMap = [];
const inbounds = [];
let facetCount = 0;
for (const facet of facets) {
const index = facet.index;
if (facetMap[index] != null) {
continue;
}
if (inbounds[index] == null) {
inbounds[index] = 0;
}
facetCount++;
facetMap[index] = facet;
if (facet.next) {
const nextIndex2 = facet.next.index;
if (inbounds[nextIndex2] == null) {
inbounds[nextIndex2] = 0;
}
inbounds[nextIndex2] += 1;
if (facetMap[nextIndex2] == null) {
facets.push(facet.next);
}
}
}
const sortedFacets = [];
const sortedIndexes = [];
inbounds.forEach((inbound, index) => {
if (inbound === 0) {
sortedIndexes.push(index);
}
});
for (const index of sortedIndexes) {
const facet = facetMap[index];
sortedFacets.push(facet);
const nextIndex2 = (_a = facet.next) == null ? void 0 : _a.index;
if (nextIndex2 == null)
continue;
inbounds[nextIndex2] -= 1;
if (inbounds[nextIndex2] === 0) {
sortedIndexes.push(nextIndex2);
}
}
if (facetCount !== sortedFacets.length) {
throw new ProseKitError(`Facet has circular dependency`);
}
return sortedFacets;
}
// src/editor/slots.ts
var schemaSlot = Facet.defineSlot({
combine: (specs) => {
var _a;
let nodes = OrderedMap.from({});
let marks = OrderedMap.from({});
let topNode = void 0;
for (const spec of specs) {
nodes = nodes.append(spec.nodes);
marks = marks.append((_a = spec.marks) != null ? _a : {});
topNode = topNode != null ? topNode : spec.topNode;
}
return { nodes, marks, topNode };
}
});
var stateSlot = Facet.defineSlot({
combine: (callbacks) => {
// src/facets/state.ts
var stateFacet = Facet.defineRootFacet({
convert: (callbacks) => {
return (ctx) => {

@@ -299,16 +231,6 @@ var _a, _b, _c, _d, _e, _f;

});
var viewSlot = Facet.defineSlot({
combine: (props) => {
return Object.assign({}, ...props);
}
});
var commandSlot = Facet.defineSlot({
combine: (inputs) => {
return Object.assign({}, ...inputs);
}
});
// src/extensions/default-state.ts
function defineDefaultState(options) {
return stateSlot.extension([
return stateFacet.extension([
({ schema }) => {

@@ -423,2 +345,33 @@ const config = {};

// src/facets/command.ts
var commandFacet = Facet.defineRootFacet({
convert: (inputs) => {
return Object.assign({}, ...inputs);
}
});
// src/facets/schema.ts
import OrderedMap from "orderedmap";
var schemaFacet = Facet.defineRootFacet({
convert: (specs) => {
var _a;
let nodes = OrderedMap.from({});
let marks = OrderedMap.from({});
let topNode = void 0;
for (const spec of specs) {
nodes = nodes.append(spec.nodes);
marks = marks.append((_a = spec.marks) != null ? _a : {});
topNode = topNode != null ? topNode : spec.topNode;
}
return { nodes, marks, topNode };
}
});
// src/facets/view.ts
var viewFacet = Facet.defineRootFacet({
convert: (props) => {
return Object.assign({}, ...props);
}
});
// src/types/priority.ts

@@ -479,3 +432,3 @@ var Priority = /* @__PURE__ */ ((Priority2) => {

const facets = [];
const inputs = [];
const payloads = [];
while (extensions.length > 0) {

@@ -488,6 +441,6 @@ const ext = extensions.pop();

facets[facet.index] = facet;
inputs[facet.index] = [[], [], [], [], []];
payloads[facet.index] = [[], [], [], [], []];
}
const facetInputs = ext.inputs;
inputs[facet.index][pri].push(...facetInputs);
const facetPayloads = ext.payloads;
payloads[facet.index][pri].push(...facetPayloads);
} else if (ext.extension) {

@@ -508,5 +461,6 @@ const p = (_a = ext.priority) != null ? _a : pri;

}
return [facets, inputs];
return [facets, payloads];
}
function updateExtension(prevInputs, prevSlots, extension, mode) {
function updateExtension(prevInputs, prevConverters, extension, mode) {
var _a;
const modifyInputTuple = mode === "add" ? mergeInputTuple : removeInputTuple;

@@ -518,12 +472,17 @@ const [facets, inputs] = extractFacets(extension);

let commandInput = null;
for (const facet of sortFacets(facets)) {
for (let index = getFacetCount(); index >= 0; index--) {
const facet = facets[index];
if (!facet) {
continue;
}
const nextFacet = facet.next;
if (nextFacet) {
facets[_a = nextFacet.index] || (facets[_a] = nextFacet);
}
if (!inputs[facet.index]) {
continue;
}
const inputTuple = modifyInputTuple(
prevInputs[facet.index],
inputs[facet.index]
);
prevInputs[facet.index] = inputTuple;
if (facet.next && !facet.single) {
const inputTuple = modifyInputTuple(prevInputs[index], inputs[index]);
prevInputs[index] = inputTuple;
if (facet.next) {
let hasOutput = false;

@@ -536,3 +495,3 @@ const outputTuple = [[], [], [], [], []];

}
const slotTuple = prevSlots[facet.index] || (prevSlots[facet.index] = [
const converterTuple = prevConverters[index] || (prevConverters[index] = [
void 0,

@@ -544,6 +503,6 @@ void 0,

]);
const prevSlot = slotTuple[pri];
const slot = prevSlot || facet.slot();
prevSlots[facet.index][pri] = slot;
const output = prevSlot ? slot.update(inputArray) : slot.create(inputArray);
const prevConverter = converterTuple[pri];
const converter = prevConverter || facet.converter();
prevConverters[index][pri] = converter;
const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
if (!output) {

@@ -565,3 +524,3 @@ continue;

const inputArray = flattenInputTuple(inputTuple);
const slotTuple = prevSlots[facet.index] || (prevSlots[facet.index] = [
const converterTuple = prevConverters[index] || (prevConverters[index] = [
void 0,

@@ -573,33 +532,24 @@ void 0,

]);
const prevSlot = slotTuple[2 /* default */];
const slot = prevSlot || facet.slot();
prevSlots[facet.index][2 /* default */] = slot;
const output = prevSlot ? slot.update(inputArray) : slot.create(inputArray);
const prevConverter = converterTuple[2 /* default */];
const converter = prevConverter || facet.converter();
prevConverters[index][2 /* default */] = converter;
const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
if (!output) {
continue;
}
const outputTuple = [[], [], [output], [], []];
if (facet.next) {
inputs[facet.next.index] = modifyInputTuple(
inputs[facet.next.index],
outputTuple
);
continue;
} else {
switch (facet) {
case schemaSlot:
schemaInput = output;
break;
case stateSlot:
stateInput = output;
break;
case viewSlot:
viewInput = output;
break;
case commandSlot:
commandInput = output;
break;
default:
throw new ProseKitError("Invalid facet");
}
switch (facet) {
case schemaFacet:
schemaInput = output;
break;
case stateFacet:
stateInput = output;
break;
case viewFacet:
viewInput = output;
break;
case commandFacet:
commandInput = output;
break;
default:
throw new ProseKitError("Invalid root facet");
}

@@ -640,7 +590,7 @@ }

this.commandAppliers = {};
this.inputs = [];
this.slots = [];
this.payloads = [];
this.converters = [];
this.mount = this.mount.bind(this);
this.unmount = this.unmount.bind(this);
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.inputs, this.slots, extension, "add");
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.payloads, this.converters, extension, "add");
if (!schemaInput) {

@@ -678,3 +628,3 @@ throw new ProseKitError("Schema must be defined");

var _a;
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.inputs, this.slots, extension, mode);
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.payloads, this.converters, extension, mode);
if (schemaInput) {

@@ -720,4 +670,5 @@ throw new ProseKitError("Schema cannot be changed");

get assertView() {
if (!this.view)
if (!this.view) {
throw new ProseKitError("Editor is not mounted");
}
return this.view;

@@ -847,3 +798,3 @@ }

function defineCommands(commands) {
return commandSlot.extension([commands]);
return commandFacet.extension([commands]);
}

@@ -923,3 +874,3 @@ function defineBaseCommands() {

var nodeSpecFacet = Facet.define({
combine: (options) => {
convert: (options) => {
const nodes = {};

@@ -938,3 +889,3 @@ let topNodeName = void 0;

},
next: schemaSlot
next: schemaFacet
});

@@ -973,3 +924,3 @@

var pluginFacet = Facet.define({
combine: (callbacks) => {
convert: (callbacks) => {
return ({ schema }) => {

@@ -980,3 +931,3 @@ const plugins = callbacks.flatMap((func) => func({ schema }));

},
next: stateSlot
next: stateFacet
});

@@ -991,3 +942,3 @@

var eventFacet = Facet.define({
slot: () => {
converter: () => {
let updateHandlers = [];

@@ -1017,4 +968,3 @@ const plugin = new ProseMirrorPlugin({

},
next: pluginFacet,
single: true
next: pluginFacet
});

@@ -1040,3 +990,3 @@ var pluginKey = new PluginKey("prosekit-event-handler");

var keymapFacet = Facet.define({
slot: () => {
converter: () => {
let handler = null;

@@ -1064,4 +1014,3 @@ const handlerWrapper = (view, event) => {

},
next: pluginFacet,
single: true
next: pluginFacet
});

@@ -1112,3 +1061,3 @@ function mergeKeymaps(keymaps) {

var inputRuleFacet = Facet.define({
combine: (inputs) => {
convert: (inputs) => {
return (context) => {

@@ -1127,3 +1076,3 @@ const rules = inputs.flatMap((callback) => callback(context));

var markSpecFacet = Facet.define({
combine: (options) => {
convert: (options) => {
const marks = {};

@@ -1138,7 +1087,7 @@ for (const { name, ...spec } of options) {

},
next: schemaSlot
next: schemaFacet
});
// src/extensions/node-view.ts
import { Plugin as Plugin5 } from "@prosekit/pm/state";
import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
import "@prosekit/pm/view";

@@ -1149,3 +1098,3 @@ function defineNodeView(options) {

var nodeViewFacet = Facet.define({
combine: (inputs) => {
convert: (inputs) => {
const nodeViews = {};

@@ -1157,3 +1106,3 @@ for (const input of inputs) {

}
return () => [new Plugin5({ props: { nodeViews } })];
return () => [new ProseMirrorPlugin2({ props: { nodeViews } })];
},

@@ -1163,2 +1112,36 @@ next: pluginFacet

// src/extensions/node-view-effect.ts
import { ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
import "@prosekit/pm/view";
function defineNodeViewEffect(options) {
return nodeViewEffectFacet.extension([options]);
}
var nodeViewEffectFacet = Facet.define({
convert: (inputs) => {
const nodeViews = {};
const options = {};
const factories = {};
for (const input of inputs) {
const group = input.group;
if (input.name == null) {
factories[group] = input.factory;
} else {
options[group] || (options[group] = []);
options[group].push({
name: input.name,
args: input.args
});
}
}
for (const [group, factory] of Object.entries(factories)) {
const groupOptions = options[group] || [];
for (const { name, args } of groupOptions) {
nodeViews[name] = factory(args);
}
}
return () => Object.keys(nodeViews).length > 0 ? [new ProseMirrorPlugin3({ props: { nodeViews } })] : [];
},
next: pluginFacet
});
// src/extensions/paragraph.ts

@@ -1204,2 +1187,3 @@ function defineParagraph() {

defineNodeView,
defineNodeViewEffect,
defineParagraph,

@@ -1206,0 +1190,0 @@ definePlugin,

{
"name": "@prosekit/core",
"type": "module",
"version": "0.0.12",
"version": "0.0.13",
"private": false,

@@ -43,3 +43,3 @@ "author": {

"orderedmap": "^2.1.1",
"type-fest": "^4.4.0"
"type-fest": "^4.5.0"
},

@@ -46,0 +46,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc