@prosekit/core
Advanced tools
Comparing version 0.7.11 to 0.7.12
@@ -9,3 +9,3 @@ import { | ||
setupEditorExtension | ||
} from "./chunk-RNBMCB5M.js"; | ||
} from "./chunk-LAFNHJDR.js"; | ||
@@ -12,0 +12,0 @@ // src/test/test-editor.ts |
@@ -5,6 +5,6 @@ export { addMark } from './_tsup-dts-rollup'; | ||
export { ExpandMarkOptions } from './_tsup-dts-rollup'; | ||
export { insertDefaultBlock } from './_tsup-dts-rollup'; | ||
export { InsertDefaultBlockOptions } from './_tsup-dts-rollup'; | ||
export { insertNode } from './_tsup-dts-rollup'; | ||
export { InsertNodeOptions } from './_tsup-dts-rollup'; | ||
export { insertDefaultBlock } from './_tsup-dts-rollup'; | ||
export { InsertDefaultBlockOptions } from './_tsup-dts-rollup'; | ||
export { removeMark } from './_tsup-dts-rollup'; | ||
@@ -22,2 +22,4 @@ export { RemoveMarkOptions } from './_tsup-dts-rollup'; | ||
export { ToggleNodeOptions } from './_tsup-dts-rollup'; | ||
export { toggleWrap } from './_tsup-dts-rollup'; | ||
export { ToggleWrapOptions } from './_tsup-dts-rollup'; | ||
export { unsetBlockType } from './_tsup-dts-rollup'; | ||
@@ -27,4 +29,2 @@ export { UnsetBlockTypeOptions } from './_tsup-dts-rollup'; | ||
export { UnsetMarkOptions } from './_tsup-dts-rollup'; | ||
export { toggleWrap } from './_tsup-dts-rollup'; | ||
export { ToggleWrapOptions } from './_tsup-dts-rollup'; | ||
export { wrap } from './_tsup-dts-rollup'; | ||
@@ -79,2 +79,4 @@ export { WrapOptions } from './_tsup-dts-rollup'; | ||
export { TripleClickOnHandler } from './_tsup-dts-rollup'; | ||
export { editorEventFacet } from './_tsup-dts-rollup'; | ||
export { EditorEventPayload } from './_tsup-dts-rollup'; | ||
export { defineFocusChangeHandler } from './_tsup-dts-rollup'; | ||
@@ -121,2 +123,3 @@ export { FocusChangeHandler } from './_tsup-dts-rollup'; | ||
export { defineFacetPayload } from './_tsup-dts-rollup'; | ||
export { AnyFunction } from './_tsup-dts-rollup'; | ||
export { AnyAttrs } from './_tsup-dts-rollup'; | ||
@@ -186,2 +189,3 @@ export { AttrSpec } from './_tsup-dts-rollup'; | ||
export { JSONParserOptions } from './_tsup-dts-rollup'; | ||
export { setSelectionAround } from './_tsup-dts-rollup'; | ||
export { isAllSelection } from './_tsup-dts-rollup'; | ||
@@ -188,0 +192,0 @@ export { isFragment } from './_tsup-dts-rollup'; |
@@ -42,3 +42,3 @@ import { | ||
union | ||
} from "./chunk-RNBMCB5M.js"; | ||
} from "./chunk-LAFNHJDR.js"; | ||
@@ -113,38 +113,5 @@ // src/commands/add-mark.ts | ||
// src/commands/insert-node.ts | ||
import { insertPoint } from "@prosekit/pm/transform"; | ||
// src/utils/set-selection-around.ts | ||
// src/commands/insert-default-block.ts | ||
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 = TextSelection2.between($pos, $pos); | ||
tr.setSelection(selection); | ||
} | ||
// src/commands/insert-node.ts | ||
function insertNode(options) { | ||
return (state, dispatch) => { | ||
var _a; | ||
const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null; | ||
assert(node, "You must provide either a node or a type"); | ||
const insertPos = insertPoint( | ||
state.doc, | ||
(_a = options.pos) != null ? _a : state.selection.anchor, | ||
node.type | ||
); | ||
if (insertPos == null) return false; | ||
if (dispatch) { | ||
const tr = state.tr.insert(insertPos, node); | ||
setSelectionAround(tr, insertPos + node.nodeSize); | ||
dispatch(tr); | ||
} | ||
return true; | ||
}; | ||
} | ||
// src/commands/insert-default-block.ts | ||
import { TextSelection as TextSelection3 } from "@prosekit/pm/state"; | ||
// src/utils/default-block-at.ts | ||
@@ -173,3 +140,3 @@ function defaultBlockAt(match) { | ||
const tr = state.tr.insert(pos, node); | ||
const selection = TextSelection3.findFrom(tr.doc.resolve(pos), 1); | ||
const selection = TextSelection2.findFrom(tr.doc.resolve(pos), 1); | ||
if (!selection) return false; | ||
@@ -183,2 +150,35 @@ tr.setSelection(selection); | ||
// src/commands/insert-node.ts | ||
import { insertPoint } from "@prosekit/pm/transform"; | ||
// src/utils/set-selection-around.ts | ||
import { TextSelection as TextSelection3 } 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 = TextSelection3.between($pos, $pos); | ||
tr.setSelection(selection); | ||
} | ||
// src/commands/insert-node.ts | ||
function insertNode(options) { | ||
return (state, dispatch) => { | ||
var _a; | ||
const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null; | ||
assert(node, "You must provide either a node or a type"); | ||
const insertPos = insertPoint( | ||
state.doc, | ||
(_a = options.pos) != null ? _a : state.selection.anchor, | ||
node.type | ||
); | ||
if (insertPos == null) return false; | ||
if (dispatch) { | ||
const tr = state.tr.insert(insertPos, node); | ||
setSelectionAround(tr, insertPos + node.nodeSize); | ||
dispatch(tr); | ||
} | ||
return true; | ||
}; | ||
} | ||
// src/commands/remove-mark.ts | ||
@@ -231,3 +231,5 @@ function removeMark(options) { | ||
// src/utils/get-custom-selection.ts | ||
import { TextSelection as TextSelection4 } from "@prosekit/pm/state"; | ||
import { | ||
TextSelection as TextSelection4 | ||
} from "@prosekit/pm/state"; | ||
function getCustomSelection(state, from, to) { | ||
@@ -355,2 +357,31 @@ const pos = from != null ? from : to; | ||
// src/commands/toggle-wrap.ts | ||
import { lift } from "@prosekit/pm/commands"; | ||
// src/commands/wrap.ts | ||
import { findWrapping } from "@prosekit/pm/transform"; | ||
function wrap(options) { | ||
return (state, dispatch) => { | ||
const { $from, $to } = state.selection; | ||
const range = $from.blockRange($to); | ||
if (!range) return false; | ||
const nodeType = getNodeType(state.schema, options.nodeType || options.type); | ||
const wrapping = findWrapping(range, nodeType, options.attrs); | ||
if (!wrapping) return false; | ||
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping)); | ||
return true; | ||
}; | ||
} | ||
// src/commands/toggle-wrap.ts | ||
function toggleWrap(options) { | ||
const { type, attrs } = options; | ||
return (state, dispatch) => { | ||
if (isNodeActive(state, type, attrs)) { | ||
return lift(state, dispatch); | ||
} | ||
return wrap({ type, attrs })(state, dispatch); | ||
}; | ||
} | ||
// src/commands/unset-block-type.ts | ||
@@ -410,31 +441,2 @@ import { Fragment, Slice } from "@prosekit/pm/model"; | ||
// src/commands/toggle-wrap.ts | ||
import { lift } from "@prosekit/pm/commands"; | ||
// src/commands/wrap.ts | ||
import { findWrapping } from "@prosekit/pm/transform"; | ||
function wrap(options) { | ||
return (state, dispatch) => { | ||
const { $from, $to } = state.selection; | ||
const range = $from.blockRange($to); | ||
if (!range) return false; | ||
const nodeType = getNodeType(state.schema, options.nodeType || options.type); | ||
const wrapping = findWrapping(range, nodeType, options.attrs); | ||
if (!wrapping) return false; | ||
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping)); | ||
return true; | ||
}; | ||
} | ||
// src/commands/toggle-wrap.ts | ||
function toggleWrap(options) { | ||
const { type, attrs } = options; | ||
return (state, dispatch) => { | ||
if (isNodeActive(state, type, attrs)) { | ||
return lift(state, dispatch); | ||
} | ||
return wrap({ type, attrs })(state, dispatch); | ||
}; | ||
} | ||
// src/editor/with-priority.ts | ||
@@ -853,84 +855,96 @@ function withPriority(extension, priority) { | ||
// src/extensions/events/dom-event.ts | ||
function defineDomEventFacetPayload(...payloads) { | ||
return defineFacetPayload( | ||
domEventFacet, | ||
payloads | ||
); | ||
} | ||
function defineDOMEventHandler(event, handler) { | ||
return defineFacetPayload(domEventFacet, [ | ||
[event, handler] | ||
return defineDomEventFacetPayload([ | ||
event, | ||
handler | ||
]); | ||
} | ||
var domEventFacet = defineFacet({ | ||
reduce: () => { | ||
const setHandlersMap = {}; | ||
const combinedHandlerMap = {}; | ||
let plugin; | ||
const update = (payloads) => { | ||
var _a; | ||
let hasNewEvent = false; | ||
for (const [event] of payloads) { | ||
if (!setHandlersMap[event]) { | ||
hasNewEvent = true; | ||
const [setHandlers, combinedHandler] = combineEventHandlers(); | ||
setHandlersMap[event] = setHandlers; | ||
const e = (view, eventObject) => { | ||
return combinedHandler(view, eventObject); | ||
}; | ||
combinedHandlerMap[event] = e; | ||
var domEventFacet = defineFacet( | ||
{ | ||
reduce: () => { | ||
const setHandlersMap = {}; | ||
const combinedHandlerMap = {}; | ||
let plugin; | ||
const update = (payloads) => { | ||
var _a; | ||
let hasNewEvent = false; | ||
for (const [event] of payloads) { | ||
if (!setHandlersMap[event]) { | ||
hasNewEvent = true; | ||
const [setHandlers, combinedHandler] = combineEventHandlers(); | ||
setHandlersMap[event] = setHandlers; | ||
const e = (view, eventObject) => { | ||
return combinedHandler(view, eventObject); | ||
}; | ||
combinedHandlerMap[event] = e; | ||
} | ||
} | ||
} | ||
const map = groupEntries(payloads); | ||
for (const [event, setHandlers] of Object.entries(setHandlersMap)) { | ||
const handlers = (_a = map[event]) != null ? _a : []; | ||
setHandlers(handlers); | ||
} | ||
if (hasNewEvent) { | ||
plugin = new ProseMirrorPlugin2({ | ||
key: new PluginKey2("prosekit-dom-event-handler"), | ||
props: { handleDOMEvents: combinedHandlerMap } | ||
}); | ||
} | ||
}; | ||
return function reducer(inputs) { | ||
update(inputs); | ||
return plugin != null ? plugin : []; | ||
}; | ||
}, | ||
parent: pluginFacet, | ||
singleton: true | ||
}); | ||
const map = groupEntries(payloads); | ||
for (const [event, setHandlers] of Object.entries(setHandlersMap)) { | ||
const handlers = (_a = map[event]) != null ? _a : []; | ||
setHandlers(handlers); | ||
} | ||
if (hasNewEvent) { | ||
plugin = new ProseMirrorPlugin2({ | ||
key: new PluginKey2("prosekit-dom-event-handler"), | ||
props: { handleDOMEvents: combinedHandlerMap } | ||
}); | ||
} | ||
}; | ||
return function reducer(inputs) { | ||
update(inputs); | ||
return plugin != null ? plugin : []; | ||
}; | ||
}, | ||
parent: pluginFacet, | ||
singleton: true | ||
} | ||
); | ||
// src/extensions/events/editor-event.ts | ||
import { PluginKey as PluginKey3, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state"; | ||
function defineEventFacetPayload(payload) { | ||
return defineFacetPayload(editorEventFacet, [payload]); | ||
} | ||
function defineKeyDownHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["keyDown", handler]]); | ||
return defineEventFacetPayload(["keyDown", handler]); | ||
} | ||
function defineKeyPressHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["keyPress", handler]]); | ||
return defineEventFacetPayload(["keyPress", handler]); | ||
} | ||
function defineTextInputHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["textInput", handler]]); | ||
return defineEventFacetPayload(["textInput", handler]); | ||
} | ||
function defineClickOnHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["clickOn", handler]]); | ||
return defineEventFacetPayload(["clickOn", handler]); | ||
} | ||
function defineClickHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["click", handler]]); | ||
return defineEventFacetPayload(["click", handler]); | ||
} | ||
function defineDoubleClickOnHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["doubleClickOn", handler]]); | ||
return defineEventFacetPayload(["doubleClickOn", handler]); | ||
} | ||
function defineDoubleClickHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["doubleClick", handler]]); | ||
return defineEventFacetPayload(["doubleClick", handler]); | ||
} | ||
function defineTripleClickOnHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["tripleClickOn", handler]]); | ||
return defineEventFacetPayload(["tripleClickOn", handler]); | ||
} | ||
function defineTripleClickHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["tripleClick", handler]]); | ||
return defineEventFacetPayload(["tripleClick", handler]); | ||
} | ||
function definePasteHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["paste", handler]]); | ||
return defineEventFacetPayload(["paste", handler]); | ||
} | ||
function defineDropHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["drop", handler]]); | ||
return defineEventFacetPayload(["drop", handler]); | ||
} | ||
function defineScrollToSelectionHandler(handler) { | ||
return defineFacetPayload(editorEventFacet, [["scrollToSelection", handler]]); | ||
return defineEventFacetPayload(["scrollToSelection", handler]); | ||
} | ||
@@ -1001,6 +1015,6 @@ var editorEventFacet = defineFacet({ | ||
const handleBlur = () => handler(false); | ||
return defineFacetPayload(domEventFacet, [ | ||
return defineDomEventFacetPayload( | ||
["focus", handleFocus], | ||
["blur", handleBlur] | ||
]); | ||
); | ||
} | ||
@@ -1115,6 +1129,3 @@ | ||
const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */; | ||
return withPriority( | ||
defineKeymap(customBaseKeymap), | ||
priority | ||
); | ||
return withPriority(defineKeymap(customBaseKeymap), priority); | ||
} | ||
@@ -1341,3 +1352,3 @@ | ||
function isCodeBlockType(type) { | ||
return type.spec.code && type.isBlock; | ||
return !!(type.spec.code && type.isBlock); | ||
} | ||
@@ -1418,2 +1429,3 @@ function isInCodeBlock(selection) { | ||
defineUpdateHandler, | ||
editorEventFacet, | ||
elementFromJSON, | ||
@@ -1456,2 +1468,3 @@ elementFromNode, | ||
setNodeAttrs, | ||
setSelectionAround, | ||
stateFromJSON, | ||
@@ -1458,0 +1471,0 @@ toggleMark, |
{ | ||
"name": "@prosekit/core", | ||
"type": "module", | ||
"version": "0.7.11", | ||
"version": "0.7.12", | ||
"private": false, | ||
@@ -48,10 +48,10 @@ "author": { | ||
"prosemirror-splittable": "^0.1.1", | ||
"type-fest": "^4.26.0", | ||
"type-fest": "^4.26.1", | ||
"@prosekit/pm": "^0.1.8" | ||
}, | ||
"devDependencies": { | ||
"@vitest/browser": "^2.0.5", | ||
"tsup": "^8.2.4", | ||
"typescript": "^5.5.4", | ||
"vitest": "^2.0.5", | ||
"@vitest/browser": "^2.1.3", | ||
"tsup": "^8.3.0", | ||
"typescript": "^5.6.3", | ||
"vitest": "^2.1.3", | ||
"@prosekit/dev": "0.0.0" | ||
@@ -58,0 +58,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
175507
5504
Updatedtype-fest@^4.26.1