@portabletext/editor 1.57.2 → 1.57.3
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.
- package/lib/index.cjs +50 -189
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +46 -184
- package/lib/index.js.map +1 -1
- package/package.json +2 -1
- package/src/internal-utils/is-hotkey.ts +1 -1
- package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +63 -188
- package/src/keyboard-shortcuts/is-keyboard-shortcut.test.ts +0 -93
- package/src/keyboard-shortcuts/is-keyboard-shortcut.ts +0 -28
- package/src/keyboard-shortcuts/keyboard-shortcuts.ts +0 -120
package/lib/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import get from "lodash/get.js";
|
|
|
31
31
|
import isUndefined from "lodash/isUndefined.js";
|
|
32
32
|
import omitBy from "lodash/omitBy.js";
|
|
33
33
|
import { createDraft, finishDraft } from "immer";
|
|
34
|
+
import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
|
|
34
35
|
import { defineType, defineField } from "@sanity/types";
|
|
35
36
|
import startCase from "lodash.startcase";
|
|
36
37
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
@@ -5376,203 +5377,64 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
5376
5377
|
})]]
|
|
5377
5378
|
}), coreAnnotationBehaviors = {
|
|
5378
5379
|
addAnnotationOnCollapsedSelection
|
|
5379
|
-
}
|
|
5380
|
-
function isKeyboardShortcut(event, key, allowedModifiers = {}) {
|
|
5381
|
-
return event.key.toLowerCase() === key.toLowerCase() && (allowedModifiers.ctrlKey === event.ctrlKey || allowedModifiers.ctrlKey === void 0) && (allowedModifiers.metaKey === event.metaKey || allowedModifiers.metaKey === void 0) && (allowedModifiers.shiftKey === event.shiftKey || allowedModifiers.shiftKey === void 0) && (allowedModifiers.altKey === event.altKey || allowedModifiers.altKey === void 0);
|
|
5382
|
-
}
|
|
5383
|
-
const IS_APPLE = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent);
|
|
5384
|
-
function createKeyboardShortcut(definition) {
|
|
5385
|
-
return IS_APPLE ? definition.apple ?? definition.default : definition.default;
|
|
5386
|
-
}
|
|
5387
|
-
const defaultKeyboardShortcuts = {
|
|
5380
|
+
}, defaultKeyboardShortcuts = {
|
|
5388
5381
|
arrowDown: createKeyboardShortcut({
|
|
5389
|
-
default: {
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
keys: ["ArrowDown"]
|
|
5397
|
-
}
|
|
5382
|
+
default: [{
|
|
5383
|
+
key: "ArrowDown",
|
|
5384
|
+
alt: !1,
|
|
5385
|
+
ctrl: !1,
|
|
5386
|
+
meta: !1,
|
|
5387
|
+
shift: !1
|
|
5388
|
+
}]
|
|
5398
5389
|
}),
|
|
5399
5390
|
arrowUp: createKeyboardShortcut({
|
|
5400
|
-
default: {
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
keys: ["ArrowUp"]
|
|
5408
|
-
}
|
|
5391
|
+
default: [{
|
|
5392
|
+
key: "ArrowUp",
|
|
5393
|
+
alt: !1,
|
|
5394
|
+
ctrl: !1,
|
|
5395
|
+
meta: !1,
|
|
5396
|
+
shift: !1
|
|
5397
|
+
}]
|
|
5409
5398
|
}),
|
|
5410
5399
|
break: createKeyboardShortcut({
|
|
5411
|
-
default: {
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
keys: ["Enter"]
|
|
5416
|
-
}
|
|
5400
|
+
default: [{
|
|
5401
|
+
key: "Enter",
|
|
5402
|
+
shift: !1
|
|
5403
|
+
}]
|
|
5417
5404
|
}),
|
|
5418
5405
|
lineBreak: createKeyboardShortcut({
|
|
5419
|
-
default: {
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
keys: ["Shift", "Enter"]
|
|
5424
|
-
}
|
|
5406
|
+
default: [{
|
|
5407
|
+
key: "Enter",
|
|
5408
|
+
shift: !0
|
|
5409
|
+
}]
|
|
5425
5410
|
}),
|
|
5426
5411
|
decorators: {
|
|
5427
|
-
strong:
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
ctrlKey: !0,
|
|
5432
|
-
metaKey: !1,
|
|
5433
|
-
shiftKey: !1
|
|
5434
|
-
}),
|
|
5435
|
-
keys: ["Ctrl", "B"]
|
|
5436
|
-
},
|
|
5437
|
-
apple: {
|
|
5438
|
-
guard: (event) => isKeyboardShortcut(event, "b", {
|
|
5439
|
-
altKey: !1,
|
|
5440
|
-
ctrlKey: !1,
|
|
5441
|
-
metaKey: !0,
|
|
5442
|
-
shiftKey: !1
|
|
5443
|
-
}),
|
|
5444
|
-
keys: ["\u2318", "B"]
|
|
5445
|
-
}
|
|
5446
|
-
}),
|
|
5447
|
-
em: createKeyboardShortcut({
|
|
5448
|
-
default: {
|
|
5449
|
-
guard: (event) => isKeyboardShortcut(event, "i", {
|
|
5450
|
-
altKey: !1,
|
|
5451
|
-
ctrlKey: !0,
|
|
5452
|
-
metaKey: !1,
|
|
5453
|
-
shiftKey: !1
|
|
5454
|
-
}),
|
|
5455
|
-
keys: ["Ctrl", "I"]
|
|
5456
|
-
},
|
|
5457
|
-
apple: {
|
|
5458
|
-
guard: (event) => isKeyboardShortcut(event, "i", {
|
|
5459
|
-
altKey: !1,
|
|
5460
|
-
ctrlKey: !1,
|
|
5461
|
-
metaKey: !0,
|
|
5462
|
-
shiftKey: !1
|
|
5463
|
-
}),
|
|
5464
|
-
keys: ["\u2318", "I"]
|
|
5465
|
-
}
|
|
5466
|
-
}),
|
|
5467
|
-
underline: createKeyboardShortcut({
|
|
5468
|
-
default: {
|
|
5469
|
-
guard: (event) => isKeyboardShortcut(event, "u", {
|
|
5470
|
-
altKey: !1,
|
|
5471
|
-
ctrlKey: !0,
|
|
5472
|
-
metaKey: !1,
|
|
5473
|
-
shiftKey: !1
|
|
5474
|
-
}),
|
|
5475
|
-
keys: ["Ctrl", "U"]
|
|
5476
|
-
},
|
|
5477
|
-
apple: {
|
|
5478
|
-
guard: (event) => isKeyboardShortcut(event, "u", {
|
|
5479
|
-
altKey: !1,
|
|
5480
|
-
ctrlKey: !1,
|
|
5481
|
-
metaKey: !0,
|
|
5482
|
-
shiftKey: !1
|
|
5483
|
-
}),
|
|
5484
|
-
keys: ["\u2318", "U"]
|
|
5485
|
-
}
|
|
5486
|
-
}),
|
|
5487
|
-
code: createKeyboardShortcut({
|
|
5488
|
-
default: {
|
|
5489
|
-
guard: (event) => isKeyboardShortcut(event, "'", {
|
|
5490
|
-
altKey: !1,
|
|
5491
|
-
ctrlKey: !0,
|
|
5492
|
-
metaKey: !1,
|
|
5493
|
-
shiftKey: !1
|
|
5494
|
-
}),
|
|
5495
|
-
keys: ["Ctrl", "'"]
|
|
5496
|
-
},
|
|
5497
|
-
apple: {
|
|
5498
|
-
guard: (event) => isKeyboardShortcut(event, "'", {
|
|
5499
|
-
altKey: !1,
|
|
5500
|
-
ctrlKey: !1,
|
|
5501
|
-
metaKey: !0,
|
|
5502
|
-
shiftKey: !1
|
|
5503
|
-
}),
|
|
5504
|
-
keys: ["\u2318", "'"]
|
|
5505
|
-
}
|
|
5506
|
-
})
|
|
5412
|
+
strong: bold,
|
|
5413
|
+
em: italic,
|
|
5414
|
+
underline,
|
|
5415
|
+
code
|
|
5507
5416
|
},
|
|
5508
5417
|
history: {
|
|
5509
|
-
undo
|
|
5510
|
-
|
|
5511
|
-
guard: (event) => isKeyboardShortcut(event, "z", {
|
|
5512
|
-
altKey: !1,
|
|
5513
|
-
ctrlKey: !0,
|
|
5514
|
-
metaKey: !1,
|
|
5515
|
-
shiftKey: !1
|
|
5516
|
-
}),
|
|
5517
|
-
keys: ["Ctrl", "Z"]
|
|
5518
|
-
},
|
|
5519
|
-
apple: {
|
|
5520
|
-
guard: (event) => isKeyboardShortcut(event, "z", {
|
|
5521
|
-
altKey: !1,
|
|
5522
|
-
ctrlKey: !1,
|
|
5523
|
-
metaKey: !0,
|
|
5524
|
-
shiftKey: !1
|
|
5525
|
-
}),
|
|
5526
|
-
keys: ["\u2318", "Z"]
|
|
5527
|
-
}
|
|
5528
|
-
}),
|
|
5529
|
-
redo: createKeyboardShortcut({
|
|
5530
|
-
default: {
|
|
5531
|
-
guard: (event) => isKeyboardShortcut(event, "y", {
|
|
5532
|
-
ctrlKey: !0,
|
|
5533
|
-
metaKey: !1,
|
|
5534
|
-
shiftKey: !1,
|
|
5535
|
-
altKey: !1
|
|
5536
|
-
}) || isKeyboardShortcut(event, "z", {
|
|
5537
|
-
ctrlKey: !0,
|
|
5538
|
-
metaKey: !1,
|
|
5539
|
-
shiftKey: !0,
|
|
5540
|
-
altKey: !1
|
|
5541
|
-
}),
|
|
5542
|
-
keys: ["Ctrl", "Y"]
|
|
5543
|
-
},
|
|
5544
|
-
apple: {
|
|
5545
|
-
guard: (event) => isKeyboardShortcut(event, "z", {
|
|
5546
|
-
ctrlKey: !1,
|
|
5547
|
-
metaKey: !0,
|
|
5548
|
-
shiftKey: !0,
|
|
5549
|
-
altKey: !1
|
|
5550
|
-
}),
|
|
5551
|
-
keys: ["\u2318", "Shift", "Z"]
|
|
5552
|
-
}
|
|
5553
|
-
})
|
|
5418
|
+
undo,
|
|
5419
|
+
redo
|
|
5554
5420
|
},
|
|
5555
5421
|
tab: createKeyboardShortcut({
|
|
5556
|
-
default: {
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
keys: ["Tab"]
|
|
5564
|
-
}
|
|
5422
|
+
default: [{
|
|
5423
|
+
key: "Tab",
|
|
5424
|
+
alt: !1,
|
|
5425
|
+
ctrl: !1,
|
|
5426
|
+
meta: !1,
|
|
5427
|
+
shift: !1
|
|
5428
|
+
}]
|
|
5565
5429
|
}),
|
|
5566
5430
|
shiftTab: createKeyboardShortcut({
|
|
5567
|
-
default: {
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
keys: ["Shift", "Tab"]
|
|
5575
|
-
}
|
|
5431
|
+
default: [{
|
|
5432
|
+
key: "Tab",
|
|
5433
|
+
alt: !1,
|
|
5434
|
+
ctrl: !1,
|
|
5435
|
+
meta: !1,
|
|
5436
|
+
shift: !0
|
|
5437
|
+
}]
|
|
5576
5438
|
})
|
|
5577
5439
|
}, arrowDownOnLonelyBlockObject = defineBehavior({
|
|
5578
5440
|
on: "keyboard.keydown",
|
|
@@ -10975,8 +10837,8 @@ function parseHotkey(hotkey) {
|
|
|
10975
10837
|
shiftKey: !1
|
|
10976
10838
|
}, hotkeySegments = hotkey.replace("++", "+add").split("+");
|
|
10977
10839
|
for (const rawHotkeySegment of hotkeySegments) {
|
|
10978
|
-
const optional = rawHotkeySegment.endsWith("?") && rawHotkeySegment.length > 1, hotkeySegment = optional ? rawHotkeySegment.slice(0, -1) : rawHotkeySegment, keyName = toKeyName(hotkeySegment), modifier = modifiers[keyName], alias = aliases[hotkeySegment],
|
|
10979
|
-
if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 &&
|
|
10840
|
+
const optional = rawHotkeySegment.endsWith("?") && rawHotkeySegment.length > 1, hotkeySegment = optional ? rawHotkeySegment.slice(0, -1) : rawHotkeySegment, keyName = toKeyName(hotkeySegment), modifier = modifiers[keyName], alias = aliases[hotkeySegment], code2 = keyCodes[keyName];
|
|
10841
|
+
if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code2 === void 0)
|
|
10980
10842
|
throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
|
|
10981
10843
|
(hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
|
|
10982
10844
|
}
|