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.2.7 to 0.3.0

34

dist/_tsup-dts-rollup.d.ts

@@ -12,3 +12,2 @@ import { AllSelection } from '@prosekit/pm/state';

import type { EmptyObject } from 'type-fest';
import { InputRule } from '@prosekit/pm/inputrules';
import type { IsEqual } from 'type-fest';

@@ -338,20 +337,4 @@ import { Mark } from '@prosekit/pm/model';

/**
* Defines an input rule extension.
*
* @param rule - The ProseMirror input rule to add, or an array of input rules,
* or a function that returns one or multiple input rules.
*
* @public
*
* @deprecated Use `prosekit/extensions/input-rule` instead.
*/
declare function defineInputRule(rule: InputRule | InputRule[] | ((context: {
schema: Schema;
}) => InputRule | InputRule[])): Extension;
export { defineInputRule }
export { defineInputRule as defineInputRule_alias_1 }
/**
* @public
*/
declare function defineKeymap(keymap: Keymap): Extension;

@@ -591,4 +574,18 @@ export { defineKeymap }

/**
* Expands the selection to include the entire mark at the current position.
*
* @public
*/
declare function expandMark(options: {
/**
* The type of the mark to expand.
*/
type: string | MarkType;
}): Command;
export { expandMark }
export { expandMark as expandMark_alias_1 }
/**
* @public
*/
declare interface Extension<T extends ExtensionTyping = ExtensionTyping> {

@@ -840,2 +837,5 @@ extension: Extension | Extension[];

/**
* @internal
*/
export declare function isMarkActive(state: EditorState, type: string | MarkType, attrs?: Attrs | null): boolean;

@@ -842,0 +842,0 @@

export { addMark } from './_tsup-dts-rollup';
export { expandMark } from './_tsup-dts-rollup';
export { insertNode } from './_tsup-dts-rollup';

@@ -13,4 +14,4 @@ export { removeMark } from './_tsup-dts-rollup';

export { withPriority } from './_tsup-dts-rollup';
export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-rollup';
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-rollup';
export { defineBaseCommands } from './_tsup-dts-rollup';

@@ -32,3 +33,2 @@ export { defineCommands } from './_tsup-dts-rollup';

export { defineHistory } from './_tsup-dts-rollup';
export { defineInputRule } from './_tsup-dts-rollup';
export { defineBaseKeymap } from './_tsup-dts-rollup';

@@ -35,0 +35,0 @@ export { defineKeymap } from './_tsup-dts-rollup';

@@ -46,2 +46,55 @@ // src/commands/add-mark.ts

// src/commands/expand-mark.ts
import { TextSelection } from "@prosekit/pm/state";
function expandMark(options) {
return (state, dispatch) => {
const markType = getMarkType(state.schema, options.type);
const predicate = (mark) => mark.type === markType;
const from = expandMarkBefore(state.selection.$from, predicate);
const to = expandMarkAfter(state.selection.$to, predicate);
if (from === state.selection.from && to === state.selection.to) {
return false;
}
if (dispatch) {
dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
}
return true;
};
}
function expandMarkBefore($pos, predicate) {
const { parent } = $pos;
if (!$pos.marks().some(predicate)) {
return $pos.pos;
}
const index = $pos.index();
let boundaryIndex = index;
for (let i = index; i >= 0; i--) {
const node = parent.child(i);
if (node.marks.some(predicate)) {
boundaryIndex = i;
} else {
break;
}
}
return $pos.posAtIndex(boundaryIndex);
}
function expandMarkAfter($pos, predicate) {
const { parent } = $pos;
if (!$pos.marks().some(predicate)) {
return $pos.pos;
}
const index = Math.max(0, $pos.indexAfter() - 1);
const childCount = parent.childCount;
let boundaryIndex = index;
for (let i = index; i < childCount; i++) {
const node = parent.child(i);
if (node.marks.some(predicate)) {
boundaryIndex = i;
} else {
break;
}
}
return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
}
// src/commands/insert-node.ts

@@ -65,7 +118,7 @@ import "@prosekit/pm/state";

// src/utils/set-selection-around.ts
import { TextSelection } from "@prosekit/pm/state";
import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
function setSelectionAround(tr, pos) {
const docSize = tr.doc.content.size;
const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
const selection = TextSelection.between($pos, $pos);
const selection = TextSelection2.between($pos, $pos);
tr.setSelection(selection);

@@ -120,3 +173,3 @@ }

// src/utils/get-custom-selection.ts
import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
function getCustomSelection(state, from, to) {

@@ -127,3 +180,3 @@ const pos = from != null ? from : to;

const $to = state.doc.resolve(to != null ? to : pos);
return TextSelection2.between($from, $to);
return TextSelection3.between($from, $to);
}

@@ -703,2 +756,15 @@ return state.selection;

// src/utils/is-mark-active.ts
function isMarkActive(state, type, attrs) {
const { from, $from, to, empty } = state.selection;
const markType = getMarkType(state.schema, type);
if (empty) {
const mark = attrs ? markType.create(attrs) : markType;
return !!mark.isInSet(state.storedMarks || $from.marks());
} else {
const markOrType = attrs ? markType.create(attrs) : markType;
return state.doc.rangeHasMark(from, to, markOrType);
}
}
// src/utils/type-assertion.ts

@@ -709,3 +775,3 @@ import { Mark, ProseMirrorNode } from "@prosekit/pm/model";

NodeSelection,
TextSelection as TextSelection3
TextSelection as TextSelection4
} from "@prosekit/pm/state";

@@ -719,3 +785,3 @@ function isProseMirrorNode(node) {

function isTextSelection(sel) {
return sel instanceof TextSelection3;
return sel instanceof TextSelection4;
}

@@ -729,24 +795,2 @@ function isNodeSelection(sel) {

// src/utils/is-mark-active.ts
function isMarkActive(state, type, attrs) {
const markType = getMarkType(state.schema, type);
const mark = attrs ? markType.create(attrs) : markType;
const { from, $from, to, empty } = state.selection;
if (empty) {
return hasMark(state.storedMarks || $from.marks(), mark);
} else {
return state.doc.rangeHasMark(from, to, mark);
}
}
function hasMark(marks, mark) {
if (marks.length === 0) {
return false;
}
if (isMark(mark)) {
return marks.some((m) => m.eq(mark));
} else {
return marks.some((m) => m.type === mark);
}
}
// src/editor/builder.ts

@@ -1416,12 +1460,7 @@ function createNodeBuilder(getState, type) {

key: new PluginKey2("prosekit-focus-handler"),
view: (view) => {
const dom = view.dom;
dom.addEventListener("focus", handleFocus);
dom.addEventListener("blur", handleBlur);
return {
destroy: () => {
dom.removeEventListener("focus", handleFocus);
dom.removeEventListener("blur", handleBlur);
}
};
props: {
handleDOMEvents: {
focus: handleFocus,
blur: handleBlur
}
}

@@ -1513,28 +1552,2 @@ });

// src/extensions/input-rules.ts
import { InputRule, inputRules } from "@prosekit/pm/inputrules";
import "@prosekit/pm/model";
import "@prosekit/pm/state";
function defineInputRule(rule) {
if (rule instanceof InputRule) {
return inputRuleFacet.extension([() => rule]);
}
if (Array.isArray(rule) && rule.every((r) => r instanceof InputRule)) {
return inputRuleFacet.extension([() => rule]);
}
if (typeof rule === "function") {
return inputRuleFacet.extension([rule]);
}
throw new TypeError("Invalid input rule");
}
var inputRuleFacet = Facet.define({
convert: (inputs) => {
return (context) => {
const rules = inputs.flatMap((callback) => callback(context));
return [inputRules({ rules })];
};
},
next: pluginFacet
});
// src/extensions/mark-spec.ts

@@ -1769,3 +1782,2 @@ function defineMarkSpec(options) {

defineHistory,
defineInputRule,
defineKeymap,

@@ -1784,2 +1796,3 @@ defineMarkAttr,

defineUpdateHandler,
expandMark,
getMarkType,

@@ -1786,0 +1799,0 @@ getNodeType,

{
"name": "@prosekit/core",
"type": "module",
"version": "0.2.7",
"version": "0.3.0",
"private": false,

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

"orderedmap": "^2.1.1",
"type-fest": "^4.10.1"
"type-fest": "^4.10.2"
},

@@ -48,3 +48,3 @@ "devDependencies": {

"typescript": "^5.3.3",
"vitest": "^1.2.1"
"vitest": "^1.2.2"
},

@@ -51,0 +51,0 @@ "scripts": {

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