prosemirror-view 1.24.0 → 1.26.0
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/CHANGELOG.md +18 -0
- package/dist/index.cjs +21 -19
- package/dist/index.d.ts +34 -10
- package/dist/index.js +8 -6
- package/package.json +6 -3
- package/src/README.md +4 -0
- package/src/capturekeys.ts +4 -4
- package/src/index.ts +34 -15
- package/src/viewdesc.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 1.26.0 (2022-06-07)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
Export the `NodeViewConstructor` and `MarkViewConstructor` types. Include Node/MarkViewConstructor in doc template
|
|
6
|
+
|
|
7
|
+
## 1.25.0 (2022-06-01)
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
Mark views can now be specified with a separate editor prop, `markViews`, to make it easier to get the types right.
|
|
12
|
+
|
|
13
|
+
## 1.24.1 (2022-05-30)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Fix a regression that caused the key handler to crash.
|
|
18
|
+
|
|
1
19
|
## 1.24.0 (2022-05-30)
|
|
2
20
|
|
|
3
21
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1774,10 +1774,9 @@ var CustomNodeViewDesc = function (_NodeViewDesc2) {
|
|
|
1774
1774
|
if (this.dirty == NODE_DIRTY) return false;
|
|
1775
1775
|
|
|
1776
1776
|
if (this.spec.update) {
|
|
1777
|
-
var
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
return _result;
|
|
1777
|
+
var result = this.spec.update(node, outerDeco, innerDeco);
|
|
1778
|
+
if (result) this.updateInner(node, outerDeco, innerDeco, view);
|
|
1779
|
+
return result;
|
|
1781
1780
|
} else if (!this.contentDOM && !node.isLeaf) {
|
|
1782
1781
|
return false;
|
|
1783
1782
|
} else {
|
|
@@ -2867,13 +2866,13 @@ function captureKeyDown(view, event) {
|
|
|
2867
2866
|
return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodesRight(view);
|
|
2868
2867
|
} else if (code == 13 || code == 27) {
|
|
2869
2868
|
return true;
|
|
2870
|
-
} else if (code == 37 ||
|
|
2869
|
+
} else if (code == 37 || mac && code == 66 && mods == "c") {
|
|
2871
2870
|
return selectHorizontally(view, -1, mods) || skipIgnoredNodesLeft(view);
|
|
2872
|
-
} else if (code == 39 ||
|
|
2871
|
+
} else if (code == 39 || mac && code == 70 && mods == "c") {
|
|
2873
2872
|
return selectHorizontally(view, 1, mods) || skipIgnoredNodesRight(view);
|
|
2874
|
-
} else if (code == 38 ||
|
|
2873
|
+
} else if (code == 38 || mac && code == 80 && mods == "c") {
|
|
2875
2874
|
return selectVertically(view, -1, mods) || skipIgnoredNodesLeft(view);
|
|
2876
|
-
} else if (code == 40 ||
|
|
2875
|
+
} else if (code == 40 || mac && code == 78 && mods == "c") {
|
|
2877
2876
|
return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodesRight(view);
|
|
2878
2877
|
} else if (mods == (mac ? "m" : "c") && (code == 66 || code == 73 || code == 89 || code == 90)) {
|
|
2879
2878
|
return true;
|
|
@@ -4331,10 +4330,9 @@ var DecorationGroup = function () {
|
|
|
4331
4330
|
var found = [];
|
|
4332
4331
|
|
|
4333
4332
|
for (var i = 0; i < this.members.length; i++) {
|
|
4334
|
-
var
|
|
4335
|
-
|
|
4336
|
-
if (
|
|
4337
|
-
if (_result2 instanceof DecorationGroup) found = found.concat(_result2.members);else found.push(_result2);
|
|
4333
|
+
var result = this.members[i].forChild(offset, child);
|
|
4334
|
+
if (result == empty) continue;
|
|
4335
|
+
if (result instanceof DecorationGroup) found = found.concat(result.members);else found.push(result);
|
|
4338
4336
|
}
|
|
4339
4337
|
|
|
4340
4338
|
return DecorationGroup.from(found);
|
|
@@ -4827,12 +4825,12 @@ var DOMObserver = function () {
|
|
|
4827
4825
|
|
|
4828
4826
|
if (this.view.editable) {
|
|
4829
4827
|
for (var i = 0; i < mutations.length; i++) {
|
|
4830
|
-
var
|
|
4828
|
+
var result = this.registerMutation(mutations[i], added);
|
|
4831
4829
|
|
|
4832
|
-
if (
|
|
4833
|
-
from = from < 0 ?
|
|
4834
|
-
to = to < 0 ?
|
|
4835
|
-
if (
|
|
4830
|
+
if (result) {
|
|
4831
|
+
from = from < 0 ? result.from : Math.min(result.from, from);
|
|
4832
|
+
to = to < 0 ? result.to : Math.max(result.to, to);
|
|
4833
|
+
if (result.typeOver) typeOver = true;
|
|
4836
4834
|
}
|
|
4837
4835
|
}
|
|
4838
4836
|
}
|
|
@@ -5700,11 +5698,15 @@ function selectionContextChanged(sel1, sel2) {
|
|
|
5700
5698
|
|
|
5701
5699
|
function buildNodeViews(view) {
|
|
5702
5700
|
var result = Object.create(null);
|
|
5703
|
-
|
|
5701
|
+
|
|
5702
|
+
function add(obj) {
|
|
5704
5703
|
for (var _prop3 in obj) {
|
|
5705
5704
|
if (!Object.prototype.hasOwnProperty.call(result, _prop3)) result[_prop3] = obj[_prop3];
|
|
5706
5705
|
}
|
|
5707
|
-
}
|
|
5706
|
+
}
|
|
5707
|
+
|
|
5708
|
+
view.someProp("nodeViews", add);
|
|
5709
|
+
view.someProp("markViews", add);
|
|
5708
5710
|
return result;
|
|
5709
5711
|
}
|
|
5710
5712
|
|
package/dist/index.d.ts
CHANGED
|
@@ -536,7 +536,19 @@ declare class EditorView {
|
|
|
536
536
|
*/
|
|
537
537
|
dispatch(tr: Transaction): void;
|
|
538
538
|
}
|
|
539
|
-
|
|
539
|
+
/**
|
|
540
|
+
The type of function [provided](https://prosemirror.net/docs/ref/#view.ViewProps.nodeViews) to
|
|
541
|
+
create [node views](https://prosemirror.net/docs/ref/#view.NodeView).
|
|
542
|
+
*/
|
|
543
|
+
declare type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
|
|
544
|
+
/**
|
|
545
|
+
The function types [used](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) to create
|
|
546
|
+
mark views.
|
|
547
|
+
*/
|
|
548
|
+
declare type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {
|
|
549
|
+
dom: HTMLElement;
|
|
550
|
+
contentDOM?: HTMLElement;
|
|
551
|
+
};
|
|
540
552
|
/**
|
|
541
553
|
Helper type that maps event names to event object types, but
|
|
542
554
|
includes events that TypeScript's HTMLElementEventMap doesn't know
|
|
@@ -676,14 +688,12 @@ interface EditorProps {
|
|
|
676
688
|
*/
|
|
677
689
|
transformPasted?: (slice: Slice) => Slice;
|
|
678
690
|
/**
|
|
679
|
-
Allows you to pass custom rendering and behavior logic for
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
transactions to update it. For marks, the third argument is a
|
|
686
|
-
boolean that indicates whether the mark's content is inline.
|
|
691
|
+
Allows you to pass custom rendering and behavior logic for
|
|
692
|
+
nodes. Should map node names to constructor functions that
|
|
693
|
+
produce a [`NodeView`](https://prosemirror.net/docs/ref/#view.NodeView) object implementing the
|
|
694
|
+
node's display behavior. The third argument `getPos` is a
|
|
695
|
+
function that can be called to get the node's current position,
|
|
696
|
+
which can be useful when creating transactions to update it.
|
|
687
697
|
|
|
688
698
|
`decorations` is an array of node or inline decorations that are
|
|
689
699
|
active around the node. They are automatically drawn in the
|
|
@@ -697,11 +707,25 @@ interface EditorProps {
|
|
|
697
707
|
on the content. But if you, for example, want to create a nested
|
|
698
708
|
editor with the content, it may make sense to provide it with the
|
|
699
709
|
inner decorations.
|
|
710
|
+
|
|
711
|
+
(For backwards compatibility reasons, [mark
|
|
712
|
+
views](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) can also be included in this
|
|
713
|
+
object.)
|
|
700
714
|
*/
|
|
701
715
|
nodeViews?: {
|
|
702
716
|
[node: string]: NodeViewConstructor;
|
|
703
717
|
};
|
|
704
718
|
/**
|
|
719
|
+
Pass custom mark rendering functions. Note that these cannot
|
|
720
|
+
provide the kind of dynamic behavior that [node
|
|
721
|
+
views](https://prosemirror.net/docs/ref/#view.NodeView) can—they just provide custom rendering
|
|
722
|
+
logic. The third argument indicates whether the mark's content
|
|
723
|
+
is inline.
|
|
724
|
+
*/
|
|
725
|
+
markViews?: {
|
|
726
|
+
[mark: string]: MarkViewConstructor;
|
|
727
|
+
};
|
|
728
|
+
/**
|
|
705
729
|
The DOM serializer to use when putting content onto the
|
|
706
730
|
clipboard. If not given, the result of
|
|
707
731
|
[`DOMSerializer.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMSerializer^fromSchema)
|
|
@@ -796,4 +820,4 @@ interface DirectEditorProps extends EditorProps {
|
|
|
796
820
|
dispatchTransaction?: (tr: Transaction) => void;
|
|
797
821
|
}
|
|
798
822
|
|
|
799
|
-
export { DOMEventMap, Decoration, DecorationAttrs, DecorationSet, DecorationSource, DirectEditorProps, EditorProps, EditorView, NodeView };
|
|
823
|
+
export { DOMEventMap, Decoration, DecorationAttrs, DecorationSet, DecorationSource, DirectEditorProps, EditorProps, EditorView, MarkViewConstructor, NodeView, NodeViewConstructor };
|
package/dist/index.js
CHANGED
|
@@ -2509,16 +2509,16 @@ function captureKeyDown(view, event) {
|
|
|
2509
2509
|
else if (code == 13 || code == 27) { // Enter, Esc
|
|
2510
2510
|
return true;
|
|
2511
2511
|
}
|
|
2512
|
-
else if (code == 37 || (
|
|
2512
|
+
else if (code == 37 || (mac && code == 66 && mods == "c")) { // Left arrow, Ctrl-b on Mac
|
|
2513
2513
|
return selectHorizontally(view, -1, mods) || skipIgnoredNodesLeft(view);
|
|
2514
2514
|
}
|
|
2515
|
-
else if (code == 39 || (
|
|
2515
|
+
else if (code == 39 || (mac && code == 70 && mods == "c")) { // Right arrow, Ctrl-f on Mac
|
|
2516
2516
|
return selectHorizontally(view, 1, mods) || skipIgnoredNodesRight(view);
|
|
2517
2517
|
}
|
|
2518
|
-
else if (code == 38 || (
|
|
2518
|
+
else if (code == 38 || (mac && code == 80 && mods == "c")) { // Up arrow, Ctrl-p on Mac
|
|
2519
2519
|
return selectVertically(view, -1, mods) || skipIgnoredNodesLeft(view);
|
|
2520
2520
|
}
|
|
2521
|
-
else if (code == 40 || (
|
|
2521
|
+
else if (code == 40 || (mac && code == 78 && mods == "c")) { // Down arrow, Ctrl-n on Mac
|
|
2522
2522
|
return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodesRight(view);
|
|
2523
2523
|
}
|
|
2524
2524
|
else if (mods == (mac ? "m" : "c") &&
|
|
@@ -5226,11 +5226,13 @@ function selectionContextChanged(sel1, sel2) {
|
|
|
5226
5226
|
}
|
|
5227
5227
|
function buildNodeViews(view) {
|
|
5228
5228
|
let result = Object.create(null);
|
|
5229
|
-
|
|
5229
|
+
function add(obj) {
|
|
5230
5230
|
for (let prop in obj)
|
|
5231
5231
|
if (!Object.prototype.hasOwnProperty.call(result, prop))
|
|
5232
5232
|
result[prop] = obj[prop];
|
|
5233
|
-
}
|
|
5233
|
+
}
|
|
5234
|
+
view.someProp("nodeViews", add);
|
|
5235
|
+
view.someProp("markViews", add);
|
|
5234
5236
|
return result;
|
|
5235
5237
|
}
|
|
5236
5238
|
function changedNodeViews(a, b) {
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prosemirror-view",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "ProseMirror's view component",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./style/prosemirror.css": "./style/prosemirror.css"
|
|
12
15
|
},
|
|
13
16
|
"sideEffects": false,
|
|
14
17
|
"style": "style/prosemirror.css",
|
package/src/README.md
CHANGED
package/src/capturekeys.ts
CHANGED
|
@@ -256,13 +256,13 @@ export function captureKeyDown(view: EditorView, event: KeyboardEvent) {
|
|
|
256
256
|
return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodesRight(view)
|
|
257
257
|
} else if (code == 13 || code == 27) { // Enter, Esc
|
|
258
258
|
return true
|
|
259
|
-
} else if (code == 37 || (
|
|
259
|
+
} else if (code == 37 || (browser.mac && code == 66 && mods == "c")) { // Left arrow, Ctrl-b on Mac
|
|
260
260
|
return selectHorizontally(view, -1, mods) || skipIgnoredNodesLeft(view)
|
|
261
|
-
} else if (code == 39 || (
|
|
261
|
+
} else if (code == 39 || (browser.mac && code == 70 && mods == "c")) { // Right arrow, Ctrl-f on Mac
|
|
262
262
|
return selectHorizontally(view, 1, mods) || skipIgnoredNodesRight(view)
|
|
263
|
-
} else if (code == 38 || (
|
|
263
|
+
} else if (code == 38 || (browser.mac && code == 80 && mods == "c")) { // Up arrow, Ctrl-p on Mac
|
|
264
264
|
return selectVertically(view, -1, mods) || skipIgnoredNodesLeft(view)
|
|
265
|
-
} else if (code == 40 || (
|
|
265
|
+
} else if (code == 40 || (browser.mac && code == 78 && mods == "c")) { // Down arrow, Ctrl-n on Mac
|
|
266
266
|
return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodesRight(view)
|
|
267
267
|
} else if (mods == (browser.mac ? "m" : "c") &&
|
|
268
268
|
(code == 66 || code == 73 || code == 89 || code == 90)) { // Mod-[biyz]
|
package/src/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ export class EditorView {
|
|
|
42
42
|
/// @internal
|
|
43
43
|
cursorWrapper: {dom: DOMNode, deco: Decoration} | null = null
|
|
44
44
|
/// @internal
|
|
45
|
-
nodeViews:
|
|
45
|
+
nodeViews: NodeViewSet
|
|
46
46
|
/// @internal
|
|
47
47
|
lastSelectedViewDesc: ViewDesc | undefined = undefined
|
|
48
48
|
/// @internal
|
|
@@ -472,15 +472,17 @@ function selectionContextChanged(sel1: Selection, sel2: Selection) {
|
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
function buildNodeViews(view: EditorView) {
|
|
475
|
-
let result:
|
|
476
|
-
|
|
475
|
+
let result: NodeViewSet = Object.create(null)
|
|
476
|
+
function add(obj: NodeViewSet) {
|
|
477
477
|
for (let prop in obj) if (!Object.prototype.hasOwnProperty.call(result, prop))
|
|
478
478
|
result[prop] = obj[prop]
|
|
479
|
-
}
|
|
479
|
+
}
|
|
480
|
+
view.someProp("nodeViews", add)
|
|
481
|
+
view.someProp("markViews", add)
|
|
480
482
|
return result
|
|
481
483
|
}
|
|
482
484
|
|
|
483
|
-
function changedNodeViews(a:
|
|
485
|
+
function changedNodeViews(a: NodeViewSet, b: NodeViewSet) {
|
|
484
486
|
let nA = 0, nB = 0
|
|
485
487
|
for (let prop in a) {
|
|
486
488
|
if (a[prop] != b[prop]) return true
|
|
@@ -495,8 +497,16 @@ function checkStateComponent(plugin: Plugin) {
|
|
|
495
497
|
throw new RangeError("Plugins passed directly to the view must not have a state component")
|
|
496
498
|
}
|
|
497
499
|
|
|
498
|
-
type
|
|
499
|
-
|
|
500
|
+
/// The type of function [provided](#view.ViewProps.nodeViews) to
|
|
501
|
+
/// create [node views](#view.NodeView).
|
|
502
|
+
export type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number,
|
|
503
|
+
decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView
|
|
504
|
+
|
|
505
|
+
/// The function types [used](#view.ViewProps.markViews) to create
|
|
506
|
+
/// mark views.
|
|
507
|
+
export type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {dom: HTMLElement, contentDOM?: HTMLElement}
|
|
508
|
+
|
|
509
|
+
type NodeViewSet = {[name: string]: NodeViewConstructor | MarkViewConstructor}
|
|
500
510
|
|
|
501
511
|
/// Helper type that maps event names to event object types, but
|
|
502
512
|
/// includes events that TypeScript's HTMLElementEventMap doesn't know
|
|
@@ -613,14 +623,12 @@ export interface EditorProps {
|
|
|
613
623
|
/// the document.
|
|
614
624
|
transformPasted?: (slice: Slice) => Slice
|
|
615
625
|
|
|
616
|
-
/// Allows you to pass custom rendering and behavior logic for
|
|
617
|
-
///
|
|
618
|
-
///
|
|
619
|
-
///
|
|
620
|
-
///
|
|
621
|
-
///
|
|
622
|
-
/// transactions to update it. For marks, the third argument is a
|
|
623
|
-
/// boolean that indicates whether the mark's content is inline.
|
|
626
|
+
/// Allows you to pass custom rendering and behavior logic for
|
|
627
|
+
/// nodes. Should map node names to constructor functions that
|
|
628
|
+
/// produce a [`NodeView`](#view.NodeView) object implementing the
|
|
629
|
+
/// node's display behavior. The third argument `getPos` is a
|
|
630
|
+
/// function that can be called to get the node's current position,
|
|
631
|
+
/// which can be useful when creating transactions to update it.
|
|
624
632
|
///
|
|
625
633
|
/// `decorations` is an array of node or inline decorations that are
|
|
626
634
|
/// active around the node. They are automatically drawn in the
|
|
@@ -634,8 +642,19 @@ export interface EditorProps {
|
|
|
634
642
|
/// on the content. But if you, for example, want to create a nested
|
|
635
643
|
/// editor with the content, it may make sense to provide it with the
|
|
636
644
|
/// inner decorations.
|
|
645
|
+
///
|
|
646
|
+
/// (For backwards compatibility reasons, [mark
|
|
647
|
+
/// views](#view.ViewProps.markViews) can also be included in this
|
|
648
|
+
/// object.)
|
|
637
649
|
nodeViews?: {[node: string]: NodeViewConstructor}
|
|
638
650
|
|
|
651
|
+
/// Pass custom mark rendering functions. Note that these cannot
|
|
652
|
+
/// provide the kind of dynamic behavior that [node
|
|
653
|
+
/// views](#view.NodeView) can—they just provide custom rendering
|
|
654
|
+
/// logic. The third argument indicates whether the mark's content
|
|
655
|
+
/// is inline.
|
|
656
|
+
markViews?: {[mark: string]: MarkViewConstructor}
|
|
657
|
+
|
|
639
658
|
/// The DOM serializer to use when putting content onto the
|
|
640
659
|
/// clipboard. If not given, the result of
|
|
641
660
|
/// [`DOMSerializer.fromSchema`](#model.DOMSerializer^fromSchema)
|
package/src/viewdesc.ts
CHANGED
|
@@ -565,9 +565,9 @@ class MarkViewDesc extends ViewDesc {
|
|
|
565
565
|
|
|
566
566
|
static create(parent: ViewDesc, mark: Mark, inline: boolean, view: EditorView) {
|
|
567
567
|
let custom = view.nodeViews[mark.type.name]
|
|
568
|
-
let spec:
|
|
568
|
+
let spec: {dom: HTMLElement, contentDOM?: HTMLElement} = custom && (custom as any)(mark, view, inline)
|
|
569
569
|
if (!spec || !spec.dom)
|
|
570
|
-
spec = DOMSerializer.renderSpec(document, mark.type.spec.toDOM!(mark, inline))
|
|
570
|
+
spec = DOMSerializer.renderSpec(document, mark.type.spec.toDOM!(mark, inline)) as any
|
|
571
571
|
return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom as HTMLElement)
|
|
572
572
|
}
|
|
573
573
|
|
|
@@ -631,7 +631,7 @@ export class NodeViewDesc extends ViewDesc {
|
|
|
631
631
|
static create(parent: ViewDesc | undefined, node: Node, outerDeco: readonly Decoration[],
|
|
632
632
|
innerDeco: DecorationSource, view: EditorView, pos: number) {
|
|
633
633
|
let custom = view.nodeViews[node.type.name], descObj: ViewDesc
|
|
634
|
-
let spec = custom && custom(node, view, () => {
|
|
634
|
+
let spec: NodeView | undefined = custom && (custom as any)(node, view, () => {
|
|
635
635
|
// (This is a function that allows the custom view to find its
|
|
636
636
|
// own position)
|
|
637
637
|
if (!descObj) return pos
|