prosemirror-view 1.24.1 → 1.26.1
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 +6 -2
- package/dist/index.d.ts +45 -13
- package/dist/index.js +4 -2
- package/package.json +6 -3
- package/src/README.md +4 -0
- package/src/decoration.ts +6 -0
- package/src/index.ts +37 -18
- package/src/viewdesc.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 1.26.1 (2022-06-13)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix incorrect types for `handleDrop` and `decorations`. Document open properties on widget specs
|
|
6
|
+
|
|
7
|
+
## 1.26.0 (2022-06-07)
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
Export the `NodeViewConstructor` and `MarkViewConstructor` types. Include Node/MarkViewConstructor in doc template
|
|
12
|
+
|
|
13
|
+
## 1.25.0 (2022-06-01)
|
|
14
|
+
|
|
15
|
+
### New features
|
|
16
|
+
|
|
17
|
+
Mark views can now be specified with a separate editor prop, `markViews`, to make it easier to get the types right.
|
|
18
|
+
|
|
1
19
|
## 1.24.1 (2022-05-30)
|
|
2
20
|
|
|
3
21
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -5698,11 +5698,15 @@ function selectionContextChanged(sel1, sel2) {
|
|
|
5698
5698
|
|
|
5699
5699
|
function buildNodeViews(view) {
|
|
5700
5700
|
var result = Object.create(null);
|
|
5701
|
-
|
|
5701
|
+
|
|
5702
|
+
function add(obj) {
|
|
5702
5703
|
for (var _prop3 in obj) {
|
|
5703
5704
|
if (!Object.prototype.hasOwnProperty.call(result, _prop3)) result[_prop3] = obj[_prop3];
|
|
5704
5705
|
}
|
|
5705
|
-
}
|
|
5706
|
+
}
|
|
5707
|
+
|
|
5708
|
+
view.someProp("nodeViews", add);
|
|
5709
|
+
view.someProp("markViews", add);
|
|
5706
5710
|
return result;
|
|
5707
5711
|
}
|
|
5708
5712
|
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,10 @@ declare class Decoration {
|
|
|
79
79
|
mapping
|
|
80
80
|
*/
|
|
81
81
|
destroy?: (node: DOMNode) => void;
|
|
82
|
+
/**
|
|
83
|
+
Specs allow arbitrary additional properties.
|
|
84
|
+
*/
|
|
85
|
+
[key: string]: any;
|
|
82
86
|
}): Decoration;
|
|
83
87
|
/**
|
|
84
88
|
Creates an inline decoration, which adds the given attributes to
|
|
@@ -99,6 +103,10 @@ declare class Decoration {
|
|
|
99
103
|
[`inclusiveStart`](https://prosemirror.net/docs/ref/#view.Decoration^inline^spec.inclusiveStart).
|
|
100
104
|
*/
|
|
101
105
|
inclusiveEnd?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
Specs may have arbitrary additional properties.
|
|
108
|
+
*/
|
|
109
|
+
[key: string]: any;
|
|
102
110
|
}): Decoration;
|
|
103
111
|
/**
|
|
104
112
|
Creates a node decoration. `from` and `to` should point precisely
|
|
@@ -536,7 +544,19 @@ declare class EditorView {
|
|
|
536
544
|
*/
|
|
537
545
|
dispatch(tr: Transaction): void;
|
|
538
546
|
}
|
|
539
|
-
|
|
547
|
+
/**
|
|
548
|
+
The type of function [provided](https://prosemirror.net/docs/ref/#view.ViewProps.nodeViews) to
|
|
549
|
+
create [node views](https://prosemirror.net/docs/ref/#view.NodeView).
|
|
550
|
+
*/
|
|
551
|
+
declare type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
|
|
552
|
+
/**
|
|
553
|
+
The function types [used](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) to create
|
|
554
|
+
mark views.
|
|
555
|
+
*/
|
|
556
|
+
declare type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {
|
|
557
|
+
dom: HTMLElement;
|
|
558
|
+
contentDOM?: HTMLElement;
|
|
559
|
+
};
|
|
540
560
|
/**
|
|
541
561
|
Helper type that maps event names to event object types, but
|
|
542
562
|
includes events that TypeScript's HTMLElementEventMap doesn't know
|
|
@@ -571,7 +591,7 @@ interface EditorProps {
|
|
|
571
591
|
default behavior).
|
|
572
592
|
*/
|
|
573
593
|
handleDOMEvents?: {
|
|
574
|
-
[event in
|
|
594
|
+
[event in keyof DOMEventMap]?: (view: EditorView, event: DOMEventMap[event]) => boolean | void;
|
|
575
595
|
};
|
|
576
596
|
/**
|
|
577
597
|
Called when the editor receives a `keydown` event.
|
|
@@ -624,7 +644,7 @@ interface EditorProps {
|
|
|
624
644
|
true if this drop moves from the current selection (which should
|
|
625
645
|
thus be deleted).
|
|
626
646
|
*/
|
|
627
|
-
handleDrop?: (view: EditorView, event:
|
|
647
|
+
handleDrop?: (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void;
|
|
628
648
|
/**
|
|
629
649
|
Called when the view, after updating its state, tries to scroll
|
|
630
650
|
the selection into view. A handler function may return false to
|
|
@@ -676,14 +696,12 @@ interface EditorProps {
|
|
|
676
696
|
*/
|
|
677
697
|
transformPasted?: (slice: Slice) => Slice;
|
|
678
698
|
/**
|
|
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.
|
|
699
|
+
Allows you to pass custom rendering and behavior logic for
|
|
700
|
+
nodes. Should map node names to constructor functions that
|
|
701
|
+
produce a [`NodeView`](https://prosemirror.net/docs/ref/#view.NodeView) object implementing the
|
|
702
|
+
node's display behavior. The third argument `getPos` is a
|
|
703
|
+
function that can be called to get the node's current position,
|
|
704
|
+
which can be useful when creating transactions to update it.
|
|
687
705
|
|
|
688
706
|
`decorations` is an array of node or inline decorations that are
|
|
689
707
|
active around the node. They are automatically drawn in the
|
|
@@ -697,11 +715,25 @@ interface EditorProps {
|
|
|
697
715
|
on the content. But if you, for example, want to create a nested
|
|
698
716
|
editor with the content, it may make sense to provide it with the
|
|
699
717
|
inner decorations.
|
|
718
|
+
|
|
719
|
+
(For backwards compatibility reasons, [mark
|
|
720
|
+
views](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) can also be included in this
|
|
721
|
+
object.)
|
|
700
722
|
*/
|
|
701
723
|
nodeViews?: {
|
|
702
724
|
[node: string]: NodeViewConstructor;
|
|
703
725
|
};
|
|
704
726
|
/**
|
|
727
|
+
Pass custom mark rendering functions. Note that these cannot
|
|
728
|
+
provide the kind of dynamic behavior that [node
|
|
729
|
+
views](https://prosemirror.net/docs/ref/#view.NodeView) can—they just provide custom rendering
|
|
730
|
+
logic. The third argument indicates whether the mark's content
|
|
731
|
+
is inline.
|
|
732
|
+
*/
|
|
733
|
+
markViews?: {
|
|
734
|
+
[mark: string]: MarkViewConstructor;
|
|
735
|
+
};
|
|
736
|
+
/**
|
|
705
737
|
The DOM serializer to use when putting content onto the
|
|
706
738
|
clipboard. If not given, the result of
|
|
707
739
|
[`DOMSerializer.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMSerializer^fromSchema)
|
|
@@ -722,7 +754,7 @@ interface EditorProps {
|
|
|
722
754
|
A set of [document decorations](https://prosemirror.net/docs/ref/#view.Decoration) to show in the
|
|
723
755
|
view.
|
|
724
756
|
*/
|
|
725
|
-
decorations?: (state: EditorState) => DecorationSource | null;
|
|
757
|
+
decorations?: (state: EditorState) => DecorationSource | null | undefined;
|
|
726
758
|
/**
|
|
727
759
|
When this returns false, the content of the view is not directly
|
|
728
760
|
editable.
|
|
@@ -796,4 +828,4 @@ interface DirectEditorProps extends EditorProps {
|
|
|
796
828
|
dispatchTransaction?: (tr: Transaction) => void;
|
|
797
829
|
}
|
|
798
830
|
|
|
799
|
-
export { DOMEventMap, Decoration, DecorationAttrs, DecorationSet, DecorationSource, DirectEditorProps, EditorProps, EditorView, NodeView };
|
|
831
|
+
export { DOMEventMap, Decoration, DecorationAttrs, DecorationSet, DecorationSource, DirectEditorProps, EditorProps, EditorView, MarkViewConstructor, NodeView, NodeViewConstructor };
|
package/dist/index.js
CHANGED
|
@@ -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.1",
|
|
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/decoration.ts
CHANGED
|
@@ -182,6 +182,9 @@ export class Decoration {
|
|
|
182
182
|
/// Called when the widget decoration is removed as a result of
|
|
183
183
|
/// mapping
|
|
184
184
|
destroy?: (node: DOMNode) => void
|
|
185
|
+
|
|
186
|
+
/// Specs allow arbitrary additional properties.
|
|
187
|
+
[key: string]: any
|
|
185
188
|
}): Decoration {
|
|
186
189
|
return new Decoration(pos, pos, new WidgetType(toDOM, spec))
|
|
187
190
|
}
|
|
@@ -200,6 +203,9 @@ export class Decoration {
|
|
|
200
203
|
/// See
|
|
201
204
|
/// [`inclusiveStart`](#view.Decoration^inline^spec.inclusiveStart).
|
|
202
205
|
inclusiveEnd?: boolean
|
|
206
|
+
|
|
207
|
+
/// Specs may have arbitrary additional properties.
|
|
208
|
+
[key: string]: any
|
|
203
209
|
}) {
|
|
204
210
|
return new Decoration(from, to, new InlineType(attrs, spec))
|
|
205
211
|
}
|
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
|
|
@@ -527,7 +537,7 @@ export interface EditorProps {
|
|
|
527
537
|
/// `preventDefault` yourself (or not, if you want to allow the
|
|
528
538
|
/// default behavior).
|
|
529
539
|
handleDOMEvents?: {
|
|
530
|
-
[event in
|
|
540
|
+
[event in keyof DOMEventMap]?: (view: EditorView, event: DOMEventMap[event]) => boolean | void
|
|
531
541
|
}
|
|
532
542
|
|
|
533
543
|
/// Called when the editor receives a `keydown` event.
|
|
@@ -569,7 +579,7 @@ export interface EditorProps {
|
|
|
569
579
|
/// Called when something is dropped on the editor. `moved` will be
|
|
570
580
|
/// true if this drop moves from the current selection (which should
|
|
571
581
|
/// thus be deleted).
|
|
572
|
-
handleDrop?: (view: EditorView, event:
|
|
582
|
+
handleDrop?: (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void
|
|
573
583
|
|
|
574
584
|
/// Called when the view, after updating its state, tries to scroll
|
|
575
585
|
/// the selection into view. A handler function may return false to
|
|
@@ -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)
|
|
@@ -653,7 +672,7 @@ export interface EditorProps {
|
|
|
653
672
|
|
|
654
673
|
/// A set of [document decorations](#view.Decoration) to show in the
|
|
655
674
|
/// view.
|
|
656
|
-
decorations?: (state: EditorState) => DecorationSource | null
|
|
675
|
+
decorations?: (state: EditorState) => DecorationSource | null | undefined
|
|
657
676
|
|
|
658
677
|
/// When this returns false, the content of the view is not directly
|
|
659
678
|
/// editable.
|
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
|