@prosekit/core
Advanced tools
Comparing version 0.7.1 to 0.7.2
export { addMark } from './_tsup-dts-rollup'; | ||
export { AddMarkOptions } from './_tsup-dts-rollup'; | ||
export { expandMark } from './_tsup-dts-rollup'; | ||
export { ExpandMarkOptions } from './_tsup-dts-rollup'; | ||
export { insertNode } from './_tsup-dts-rollup'; | ||
export { InsertNodeOptions } from './_tsup-dts-rollup'; | ||
export { removeMark } from './_tsup-dts-rollup'; | ||
export { RemoveMarkOptions } from './_tsup-dts-rollup'; | ||
export { removeNode } from './_tsup-dts-rollup'; | ||
export { RemoveNodeOptions } from './_tsup-dts-rollup'; | ||
export { setBlockType } from './_tsup-dts-rollup'; | ||
export { SetBlockTypeOptions } from './_tsup-dts-rollup'; | ||
export { setNodeAttrs } from './_tsup-dts-rollup'; | ||
export { SetNodeAttrsOptions } from './_tsup-dts-rollup'; | ||
export { toggleMark } from './_tsup-dts-rollup'; | ||
export { ToggleMarkOptions } from './_tsup-dts-rollup'; | ||
export { toggleNode } from './_tsup-dts-rollup'; | ||
export { ToggleNodeOptions } from './_tsup-dts-rollup'; | ||
export { unsetBlockType } from './_tsup-dts-rollup'; | ||
export { UnsetBlockTypeOptions } from './_tsup-dts-rollup'; | ||
export { unsetMark } from './_tsup-dts-rollup'; | ||
export { UnsetMarkOptions } from './_tsup-dts-rollup'; | ||
export { wrap } from './_tsup-dts-rollup'; | ||
export { WrapOptions } from './_tsup-dts-rollup'; | ||
export { MarkBuilder } from './_tsup-dts-rollup'; | ||
@@ -61,3 +76,2 @@ export { NodeBuilder } from './_tsup-dts-rollup'; | ||
export { defineHistory } from './_tsup-dts-rollup'; | ||
export { defineBaseKeymap } from './_tsup-dts-rollup'; | ||
export { defineKeymap } from './_tsup-dts-rollup'; | ||
@@ -67,2 +81,3 @@ export { keymapFacet } from './_tsup-dts-rollup'; | ||
export { KeymapPayload } from './_tsup-dts-rollup'; | ||
export { defineBaseKeymap } from './_tsup-dts-rollup'; | ||
export { defineMarkAttr } from './_tsup-dts-rollup'; | ||
@@ -115,2 +130,3 @@ export { defineMarkSpec } from './_tsup-dts-rollup'; | ||
export { getNodeType } from './_tsup-dts-rollup'; | ||
export { isAtBlockStart } from './_tsup-dts-rollup'; | ||
export { isInCodeBlock } from './_tsup-dts-rollup'; | ||
@@ -117,0 +133,0 @@ export { isMarkAbsent } from './_tsup-dts-rollup'; |
@@ -97,3 +97,3 @@ import { | ||
state.doc, | ||
(_a = options.pos) != null ? _a : state.selection.to, | ||
(_a = options.pos) != null ? _a : state.selection.anchor, | ||
node.type | ||
@@ -272,6 +272,3 @@ ); | ||
} | ||
function toggleMark({ | ||
type, | ||
attrs | ||
}) { | ||
function toggleMark({ type, attrs }) { | ||
return (state, dispatch, view) => baseToggleMark(getMarkType(state.schema, type), attrs, { | ||
@@ -286,6 +283,3 @@ removeWhenPresent: !1 | ||
import "@prosekit/pm/state"; | ||
function toggleNode({ | ||
type, | ||
attrs | ||
}) { | ||
function toggleNode({ type, attrs }) { | ||
return (state, dispatch, view) => { | ||
@@ -302,2 +296,59 @@ if (isNodeActive(state, type, attrs)) { | ||
// src/commands/unset-block-type.ts | ||
import { Fragment, Slice } from "@prosekit/pm/model"; | ||
import "@prosekit/pm/state"; | ||
import { ReplaceAroundStep } from "@prosekit/pm/transform"; | ||
function unsetBlockType(options) { | ||
return (state, dispatch) => { | ||
var _a, _b; | ||
let from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from, to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to; | ||
if (from > to) return !1; | ||
let tr = state.tr; | ||
return unsetTextBlockType(tr, from, to) ? (dispatch == null || dispatch(tr), !0) : !1; | ||
}; | ||
} | ||
function unsetTextBlockType(tr, from, to) { | ||
let mapFrom = tr.steps.length; | ||
return tr.doc.nodesBetween(from, to, (node, pos, parent, index) => { | ||
if (!parent || !node.isTextblock) return !0; | ||
let defaultType = parent.contentMatchAt(index).defaultType; | ||
if (defaultType && defaultType.isTextblock && node.type !== defaultType && defaultType.validContent(node.content)) { | ||
let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos, 1), end = mapping.map(pos + node.nodeSize, 1), step = new ReplaceAroundStep( | ||
start, | ||
end, | ||
start + 1, | ||
end - 1, | ||
new Slice(Fragment.from(defaultType.create()), 0, 0), | ||
1, | ||
!0 | ||
); | ||
tr.step(step); | ||
} | ||
return !1; | ||
}), tr.steps.length > mapFrom; | ||
} | ||
// src/commands/unset-mark.ts | ||
import "@prosekit/pm/state"; | ||
function unsetMark(options) { | ||
return (state, dispatch) => { | ||
var _a, _b; | ||
let from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from, to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to; | ||
return from > to ? !1 : (dispatch == null || dispatch(state.tr.removeMark(from, to)), !0); | ||
}; | ||
} | ||
// src/commands/wrap.ts | ||
import "@prosekit/pm/model"; | ||
import "@prosekit/pm/state"; | ||
import { findWrapping } from "@prosekit/pm/transform"; | ||
function wrap({ nodeType, attrs }) { | ||
return (state, dispatch) => { | ||
let { $from, $to } = state.selection, range = $from.blockRange($to); | ||
if (!range) return !1; | ||
let wrapping = findWrapping(range, nodeType, attrs); | ||
return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1; | ||
}; | ||
} | ||
// src/editor/with-priority.ts | ||
@@ -324,18 +375,2 @@ function withPriority(extension, priority) { | ||
// src/commands/wrap.ts | ||
import "@prosekit/pm/model"; | ||
import "@prosekit/pm/state"; | ||
import { findWrapping } from "@prosekit/pm/transform"; | ||
function wrap({ | ||
nodeType, | ||
attrs | ||
}) { | ||
return (state, dispatch) => { | ||
let { $from, $to } = state.selection, range = $from.blockRange($to); | ||
if (!range) return !1; | ||
let wrapping = findWrapping(range, nodeType, attrs); | ||
return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1; | ||
}; | ||
} | ||
// src/facets/command.ts | ||
@@ -362,3 +397,5 @@ var commandFacet = defineFacet({ | ||
addMark, | ||
removeMark | ||
removeMark, | ||
unsetBlockType, | ||
unsetMark | ||
}); | ||
@@ -708,29 +745,8 @@ } | ||
// src/extensions/keymap.ts | ||
import { | ||
baseKeymap, | ||
chainCommands, | ||
createParagraphNear, | ||
liftEmptyBlock, | ||
newlineInCode | ||
} from "@prosekit/pm/commands"; | ||
import { chainCommands } from "@prosekit/pm/commands"; | ||
import { keydownHandler } from "@prosekit/pm/keymap"; | ||
import { Plugin as Plugin2, PluginKey as PluginKey4 } from "@prosekit/pm/state"; | ||
import { splitSplittableBlock } from "prosemirror-splittable"; | ||
var customBaseKeymap = { | ||
...baseKeymap, | ||
Enter: chainCommands( | ||
newlineInCode, | ||
createParagraphNear, | ||
liftEmptyBlock, | ||
splitSplittableBlock | ||
) | ||
}; | ||
function defineKeymap(keymap) { | ||
return defineFacetPayload(keymapFacet, [keymap]); | ||
} | ||
function defineBaseKeymap(options) { | ||
var _a; | ||
let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */; | ||
return withPriority(defineKeymap(customBaseKeymap), priority); | ||
} | ||
var keymapFacet = defineFacet({ | ||
@@ -782,2 +798,34 @@ reduce: () => { | ||
// src/extensions/keymap-base.ts | ||
import { | ||
baseKeymap, | ||
chainCommands as chainCommands2, | ||
createParagraphNear, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
liftEmptyBlock, | ||
newlineInCode, | ||
selectNodeBackward | ||
} from "@prosekit/pm/commands"; | ||
import { splitSplittableBlock } from "prosemirror-splittable"; | ||
var customEnter = chainCommands2( | ||
newlineInCode, | ||
createParagraphNear, | ||
liftEmptyBlock, | ||
splitSplittableBlock | ||
), customBackspace = chainCommands2( | ||
deleteSelection, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
), customBaseKeymap = { | ||
...baseKeymap, | ||
Enter: customEnter, | ||
Backspace: customBackspace | ||
}; | ||
function defineBaseKeymap(options) { | ||
var _a; | ||
let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */; | ||
return withPriority(defineKeymap(customBaseKeymap), priority); | ||
} | ||
// src/extensions/mark-spec.ts | ||
@@ -966,2 +1014,8 @@ function defineMarkSpec(options) { | ||
// src/utils/is-at-block-start.ts | ||
function isAtBlockStart(state, view) { | ||
let { $cursor } = state.selection; | ||
return !$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0) ? null : $cursor; | ||
} | ||
// src/utils/is-in-code-block.ts | ||
@@ -1048,2 +1102,3 @@ function isCodeBlockType(type) { | ||
isApple, | ||
isAtBlockStart, | ||
isInCodeBlock, | ||
@@ -1073,4 +1128,7 @@ isMark, | ||
union, | ||
unsetBlockType, | ||
unsetMark, | ||
withPriority, | ||
withSkipCodeBlock | ||
withSkipCodeBlock, | ||
wrap | ||
}; |
{ | ||
"name": "@prosekit/core", | ||
"type": "module", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"private": false, | ||
@@ -52,3 +52,3 @@ "author": { | ||
"typescript": "^5.5.3", | ||
"vitest": "^2.0.0-beta.13", | ||
"vitest": "^2.0.2", | ||
"@prosekit/dev": "0.0.0" | ||
@@ -55,0 +55,0 @@ }, |
Sorry, the diff of this file is too big to display
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
143244
4171