@prosekit/core
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -16,2 +16,3 @@ export { addMark, type AddMarkOptions } from './commands/add-mark' | ||
export { addEventHandler } from './extensions/event-handler' | ||
export { addHistory } from './extensions/history' | ||
export { addInputRule } from './extensions/input-rules' | ||
@@ -33,4 +34,4 @@ export { addBaseKeymap, addKeymap, type Keymap } from './extensions/keymap' | ||
type Extension, | ||
type ExtractCommandAppliers, | ||
type ExtractCommandCreators, | ||
type ExtractCommandDispatchers, | ||
type ExtractMarks, | ||
@@ -37,0 +38,0 @@ type ExtractNodes, |
@@ -99,2 +99,14 @@ import { Attrs } from '@prosekit/pm/model'; | ||
/** | ||
* Add undo/redo history to the editor. | ||
*/ | ||
declare function addHistory(): Extension< { | ||
COMMAND_ARGS: { | ||
undo: []; | ||
redo: []; | ||
}; | ||
}>; | ||
export { addHistory } | ||
export { addHistory as addHistory_alias_1 } | ||
/** | ||
* @public | ||
@@ -193,2 +205,7 @@ */ | ||
export declare interface CommandApplier<Args extends any[] = any[]> { | ||
(...args: Args): boolean; | ||
canApply(...args: Args): boolean; | ||
} | ||
/** @internal */ | ||
@@ -207,4 +224,2 @@ declare interface CommandArgs { | ||
export declare type CommandDispatcher<Args extends any[] = any[]> = (...arg: Args) => boolean; | ||
export declare const commandSlot: Facet<CommandSlotInput, CommandSlotInput>; | ||
@@ -254,3 +269,3 @@ | ||
get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>; | ||
get commands(): ExtractCommandDispatchers<E>; | ||
get commands(): ExtractCommandAppliers<E>; | ||
mount(place: HTMLElement | null | undefined | void): void; | ||
@@ -320,2 +335,9 @@ unmount(): void; | ||
/** | ||
* @public | ||
*/ | ||
declare type ExtractCommandAppliers<E extends Extension> = ToCommandApplier<ExtractCommandArgs<E>>; | ||
export { ExtractCommandAppliers } | ||
export { ExtractCommandAppliers as ExtractCommandAppliers_alias_1 } | ||
/** | ||
* @internal | ||
@@ -335,9 +357,2 @@ */ | ||
/** | ||
* @public | ||
*/ | ||
declare type ExtractCommandDispatchers<E extends Extension> = ToCommandDispatcher<ExtractCommandArgs<E>>; | ||
export { ExtractCommandDispatchers } | ||
export { ExtractCommandDispatchers as ExtractCommandDispatchers_alias_1 } | ||
/** | ||
* @intneral | ||
@@ -430,2 +445,4 @@ */ | ||
export declare const isMac: boolean; | ||
export declare function isMark(mark: unknown): mark is Mark; | ||
@@ -621,2 +638,6 @@ | ||
export declare type ToCommandApplier<T extends CommandArgs> = { | ||
[K in keyof T]: CommandApplier<T[K]>; | ||
}; | ||
export declare type ToCommandArgs<T extends CommandCreators> = { | ||
@@ -630,6 +651,2 @@ [K in keyof T]: Parameters<T[K]>; | ||
export declare type ToCommandDispatcher<T extends CommandArgs> = { | ||
[K in keyof T]: CommandDispatcher<T[K]>; | ||
}; | ||
declare function toggleMark(options: ToggleMarkOptions): Command; | ||
@@ -636,0 +653,0 @@ export { toggleMark } |
@@ -22,2 +22,3 @@ export { addMark } from './_tsup-dts-rollup'; | ||
export { addEventHandler } from './_tsup-dts-rollup'; | ||
export { addHistory } from './_tsup-dts-rollup'; | ||
export { addInputRule } from './_tsup-dts-rollup'; | ||
@@ -40,4 +41,4 @@ export { addBaseKeymap } from './_tsup-dts-rollup'; | ||
export { Extension } from './_tsup-dts-rollup'; | ||
export { ExtractCommandAppliers } from './_tsup-dts-rollup'; | ||
export { ExtractCommandCreators } from './_tsup-dts-rollup'; | ||
export { ExtractCommandDispatchers } from './_tsup-dts-rollup'; | ||
export { ExtractMarks } from './_tsup-dts-rollup'; | ||
@@ -44,0 +45,0 @@ export { ExtractNodes } from './_tsup-dts-rollup'; |
@@ -627,3 +627,3 @@ // src/commands/add-mark.ts | ||
this.view = null; | ||
this.commandDispatchers = {}; | ||
this.commandAppliers = {}; | ||
this.inputs = []; | ||
@@ -728,11 +728,22 @@ this.slots = []; | ||
addCommand(name, commandCreator) { | ||
const dispatcher = (...args) => { | ||
const view = this.assertView; | ||
const applier = (...args) => { | ||
const view = this.view; | ||
if (!view) { | ||
return false; | ||
} | ||
const command = commandCreator(...args); | ||
return command(view.state, view.dispatch.bind(view), view); | ||
}; | ||
this.commandDispatchers[name] = dispatcher; | ||
applier.canApply = (...args) => { | ||
const view = this.view; | ||
if (!view) { | ||
return false; | ||
} | ||
const command = commandCreator(...args); | ||
return command(view.state, void 0, view); | ||
}; | ||
this.commandAppliers[name] = applier; | ||
} | ||
removeCommand(name) { | ||
delete this.commandDispatchers[name]; | ||
delete this.commandAppliers[name]; | ||
} | ||
@@ -765,3 +776,3 @@ }; | ||
get commands() { | ||
return this.instance.commandDispatchers; | ||
return this.instance.commandAppliers; | ||
} | ||
@@ -992,23 +1003,12 @@ mount(place) { | ||
// src/extensions/input-rules.ts | ||
import { inputRules } from "@prosekit/pm/inputrules"; | ||
import "@prosekit/pm/model"; | ||
import "@prosekit/pm/state"; | ||
function addInputRule(rules) { | ||
return inputRuleFacet.extension([rules]); | ||
} | ||
var inputRuleFacet = Facet.define({ | ||
combine: (inputs) => { | ||
return (context) => { | ||
const rules = inputs.flatMap((callback) => callback(context)); | ||
return [inputRules({ rules })]; | ||
}; | ||
}, | ||
next: pluginFacet | ||
}); | ||
// src/extensions/history.ts | ||
import { history, redo, undo } from "@prosekit/pm/history"; | ||
// src/utils/env.ts | ||
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false; | ||
// src/extensions/keymap.ts | ||
import { baseKeymap, chainCommands } from "@prosekit/pm/commands"; | ||
import { keydownHandler } from "@prosekit/pm/keymap"; | ||
import { Plugin as Plugin4, PluginKey as PluginKey2 } from "@prosekit/pm/state"; | ||
import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@prosekit/pm/state"; | ||
function addKeymap(keymap) { | ||
@@ -1028,3 +1028,3 @@ return keymapFacet.extension([keymap]); | ||
}; | ||
const plugin = new Plugin4({ | ||
const plugin = new Plugin3({ | ||
key: keymapPluginKey, | ||
@@ -1065,2 +1065,38 @@ props: { handleKeyDown: handlerWrapper } | ||
// src/extensions/history.ts | ||
function addHistory() { | ||
const keymap = { | ||
"Mod-z": undo, | ||
"Shift-Mod-z": redo | ||
}; | ||
if (!isMac) { | ||
keymap["Mod-y"] = redo; | ||
} | ||
return defineExtension([ | ||
addPlugin(history()), | ||
addKeymap(keymap), | ||
addCommands({ | ||
undo: () => undo, | ||
redo: () => redo | ||
}) | ||
]); | ||
} | ||
// src/extensions/input-rules.ts | ||
import { inputRules } from "@prosekit/pm/inputrules"; | ||
import "@prosekit/pm/model"; | ||
import "@prosekit/pm/state"; | ||
function addInputRule(rules) { | ||
return inputRuleFacet.extension([rules]); | ||
} | ||
var inputRuleFacet = Facet.define({ | ||
combine: (inputs) => { | ||
return (context) => { | ||
const rules = inputs.flatMap((callback) => callback(context)); | ||
return [inputRules({ rules })]; | ||
}; | ||
}, | ||
next: pluginFacet | ||
}); | ||
// src/extensions/mark-spec.ts | ||
@@ -1135,2 +1171,3 @@ function addMarkSpec(options) { | ||
addEventHandler, | ||
addHistory, | ||
addInputRule, | ||
@@ -1137,0 +1174,0 @@ addKeymap, |
{ | ||
"name": "@prosekit/core", | ||
"type": "module", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"private": false, | ||
@@ -41,3 +41,3 @@ "author": { | ||
"dependencies": { | ||
"@prosekit/pm": "^0.0.5", | ||
"@prosekit/pm": "^0.0.6", | ||
"orderedmap": "^2.1.1", | ||
@@ -50,3 +50,3 @@ "type-fest": "^4.3.1" | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.3" | ||
"vitest": "^0.34.5" | ||
}, | ||
@@ -53,0 +53,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
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
59835
1874
+ Added@prosekit/pm@0.0.6(transitive)
+ Addedprosemirror-history@1.4.1(transitive)
+ Addedrope-sequence@1.3.4(transitive)
- Removed@prosekit/pm@0.0.5(transitive)
Updated@prosekit/pm@^0.0.6