@prosekit/core 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { A as isSelection, B as assert, C as defineFacetPayload, D as isNodeSelection, E as isMark, F as rootFacet, H as EditorNotFoundError, I as defineFacet, L as Priority, M as isTextSelection, N as toReversed, O as isNotNullish, P as schemaFacet, R as isNodeActive, S as stateFacet, T as isFragment, U as ProseKitError, V as getMarkType, _ as jsonFromState, a as union, b as nodeFromJSON, c as isMarkActive, d as elementFromJSON, f as elementFromNode, g as jsonFromNode, h as jsonFromHTML, j as isSlice, k as isProseMirrorNode, l as isMarkAbsent, m as htmlFromNode, p as htmlFromJSON, r as createEditor, t as Editor, u as defineDefaultState, v as nodeFromElement, w as isAllSelection, x as stateFromJSON, y as nodeFromHTML, z as getNodeType } from "./editor-D2iEkgO8.js";
1
+ import { A as isSelection, B as assert, C as defineFacetPayload, D as isNodeSelection, E as isMark, F as rootFacet, H as EditorNotFoundError, I as defineFacet, L as Priority, M as isTextSelection, N as toReversed, O as isNotNullish, P as schemaFacet, R as isNodeActive, S as stateFacet, T as isFragment, U as ProseKitError, V as getMarkType, _ as jsonFromState, a as union, b as nodeFromJSON, c as isMarkActive, d as elementFromJSON, f as elementFromNode, g as jsonFromNode, h as jsonFromHTML, j as isSlice, k as isProseMirrorNode, l as isMarkAbsent, m as htmlFromNode, p as htmlFromJSON, r as createEditor, t as Editor, u as defineDefaultState, v as nodeFromElement, w as isAllSelection, x as stateFromJSON, y as nodeFromHTML, z as getNodeType } from "./editor-B0L9BgMi.js";
2
2
  import { AllSelection, Plugin, PluginKey, ProseMirrorPlugin, TextSelection } from "@prosekit/pm/state";
3
3
  import { ReplaceAroundStep, findWrapping, insertPoint } from "@prosekit/pm/transform";
4
4
  import { baseKeymap, chainCommands, createParagraphNear, deleteSelection, joinTextblockBackward, lift, liftEmptyBlock, newlineInCode, selectNodeBackward, setBlockType as setBlockType$1, toggleMark as toggleMark$1 } from "@prosekit/pm/commands";
@@ -766,7 +766,7 @@ const nodeSpecFacet = defineFacet({
766
766
  let topNodeName = void 0;
767
767
  const specPayloads = payloads.map((input) => input[0]).filter(isNotNullish);
768
768
  const attrPayloads = payloads.map((input) => input[1]).filter(isNotNullish);
769
- for (const { name, topNode,...spec } of specPayloads) {
769
+ for (const { name, topNode, ...spec } of specPayloads) {
770
770
  if (topNode) topNodeName = name;
771
771
  const prevSpec = specs.get(name);
772
772
  if (prevSpec) specs = specs.update(name, mergeSpecs(prevSpec, spec));
@@ -1147,6 +1147,8 @@ function defineFocusChangeHandler(handler) {
1147
1147
  //#endregion
1148
1148
  //#region src/utils/env.ts
1149
1149
  /**
1150
+ * https://github.com/ProseMirror/prosemirror-keymap/blob/1.2.3/src/keymap.ts#L5
1151
+ *
1150
1152
  * @internal
1151
1153
  */
1152
1154
  const isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
@@ -1154,6 +1156,9 @@ const isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(nav
1154
1156
  //#endregion
1155
1157
  //#region src/extensions/keymap.ts
1156
1158
  /**
1159
+ * Adds a set of keybindings to the editor. Please read the
1160
+ * [documentation](https://prosemirror.net/docs/ref/#keymap) for more details.
1161
+ *
1157
1162
  * @public
1158
1163
  */
1159
1164
  function defineKeymap(keymap$1) {
@@ -1183,12 +1188,35 @@ const keymapFacet = defineFacet({
1183
1188
  });
1184
1189
  function mergeKeymaps(keymaps) {
1185
1190
  const bindings = {};
1186
- for (const keymap$1 of keymaps) for (const [key, command] of Object.entries(keymap$1)) (bindings[key] || (bindings[key] = [])).push(command);
1191
+ for (const keymap$1 of keymaps) for (const [key, command] of Object.entries(keymap$1)) {
1192
+ const normalizedKey = normalizeKeyName(key);
1193
+ (bindings[normalizedKey] ||= []).push(command);
1194
+ }
1187
1195
  return mapValues(bindings, mergeCommands);
1188
1196
  }
1189
1197
  function mergeCommands(commands$1) {
1190
1198
  return chainCommands(...commands$1);
1191
1199
  }
1200
+ function normalizeKeyName(name) {
1201
+ let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
1202
+ if (result == "Space") result = " ";
1203
+ let alt, ctrl, shift, meta;
1204
+ for (let i = 0; i < parts.length - 1; i++) {
1205
+ let mod = parts[i];
1206
+ if (/^(cmd|meta|m)$/i.test(mod)) meta = true;
1207
+ else if (/^a(lt)?$/i.test(mod)) alt = true;
1208
+ else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;
1209
+ else if (/^s(hift)?$/i.test(mod)) shift = true;
1210
+ else if (/^mod$/i.test(mod)) if (isApple) meta = true;
1211
+ else ctrl = true;
1212
+ else throw new Error("Unrecognized modifier name: " + mod);
1213
+ }
1214
+ if (alt) result = "Alt-" + result;
1215
+ if (ctrl) result = "Ctrl-" + result;
1216
+ if (meta) result = "Meta-" + result;
1217
+ if (shift) result = "Shift-" + result;
1218
+ return result;
1219
+ }
1192
1220
  const keymapPluginKey = new PluginKey("prosekit-keymap");
1193
1221
 
1194
1222
  //#endregion
@@ -1254,7 +1282,7 @@ const markSpecFacet = defineFacet({
1254
1282
  let specs = OrderedMap.from({});
1255
1283
  const specPayloads = payloads.map((input) => input[0]).filter(isNotNullish);
1256
1284
  const attrPayloads = payloads.map((input) => input[1]).filter(isNotNullish);
1257
- for (const { name,...spec } of specPayloads) {
1285
+ for (const { name, ...spec } of specPayloads) {
1258
1286
  const prevSpec = specs.get(name);
1259
1287
  if (prevSpec) specs = specs.update(name, mergeSpecs(prevSpec, spec));
1260
1288
  else specs = specs.addToStart(name, spec);