prosemirror-view 1.24.1 → 1.25.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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.25.0 (2022-06-01)
2
+
3
+ ### New features
4
+
5
+ Mark views can now be specified with a separate editor prop, `markViews`, to make it easier to get the types right.
6
+
1
7
  ## 1.24.1 (2022-05-30)
2
8
 
3
9
  ### 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
- view.someProp("nodeViews", function (obj) {
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
@@ -536,7 +536,11 @@ declare class EditorView {
536
536
  */
537
537
  dispatch(tr: Transaction): void;
538
538
  }
539
- declare type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number | undefined, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
539
+ declare type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
540
+ declare type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {
541
+ dom: HTMLElement;
542
+ contentDOM?: HTMLElement;
543
+ };
540
544
  /**
541
545
  Helper type that maps event names to event object types, but
542
546
  includes events that TypeScript's HTMLElementEventMap doesn't know
@@ -676,14 +680,12 @@ interface EditorProps {
676
680
  */
677
681
  transformPasted?: (slice: Slice) => Slice;
678
682
  /**
679
- Allows you to pass custom rendering and behavior logic for nodes
680
- and marks. Should map node and mark names to constructor
681
- functions that produce a [`NodeView`](https://prosemirror.net/docs/ref/#view.NodeView) object
682
- implementing the node's display behavior. For nodes, the third
683
- argument `getPos` is a function that can be called to get the
684
- node's current position, which can be useful when creating
685
- transactions to update it. For marks, the third argument is a
686
- boolean that indicates whether the mark's content is inline.
683
+ Allows you to pass custom rendering and behavior logic for
684
+ nodes. Should map node names to constructor functions that
685
+ produce a [`NodeView`](https://prosemirror.net/docs/ref/#view.NodeView) object implementing the
686
+ node's display behavior. The third argument `getPos` is a
687
+ function that can be called to get the node's current position,
688
+ which can be useful when creating transactions to update it.
687
689
 
688
690
  `decorations` is an array of node or inline decorations that are
689
691
  active around the node. They are automatically drawn in the
@@ -697,11 +699,25 @@ interface EditorProps {
697
699
  on the content. But if you, for example, want to create a nested
698
700
  editor with the content, it may make sense to provide it with the
699
701
  inner decorations.
702
+
703
+ (For backwards compatibility reasons, [mark
704
+ views](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) can also be included in this
705
+ object.)
700
706
  */
701
707
  nodeViews?: {
702
708
  [node: string]: NodeViewConstructor;
703
709
  };
704
710
  /**
711
+ Pass custom mark rendering functions. Note that these cannot
712
+ provide the kind of dynamic behavior that [node
713
+ views](https://prosemirror.net/docs/ref/#view.NodeView) can—they just provide custom rendering
714
+ logic. The third argument indicates whether the mark's content
715
+ is inline.
716
+ */
717
+ markViews?: {
718
+ [mark: string]: MarkViewConstructor;
719
+ };
720
+ /**
705
721
  The DOM serializer to use when putting content onto the
706
722
  clipboard. If not given, the result of
707
723
  [`DOMSerializer.fromSchema`](https://prosemirror.net/docs/ref/#model.DOMSerializer^fromSchema)
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
- view.someProp("nodeViews", obj => {
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.24.1",
3
+ "version": "1.25.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
- "import": "./dist/index.js",
11
- "require": "./dist/index.cjs"
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/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: {[node: string]: NodeViewConstructor}
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: {[node: string]: NodeViewConstructor} = Object.create(null)
476
- view.someProp("nodeViews", obj => {
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: {[node: string]: NodeViewConstructor}, b: {[node: string]: NodeViewConstructor}) {
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,11 @@ 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 NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number | undefined,
500
+ type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number,
499
501
  decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView
502
+ type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {dom: HTMLElement, contentDOM?: HTMLElement}
503
+
504
+ type NodeViewSet = {[name: string]: NodeViewConstructor | MarkViewConstructor}
500
505
 
501
506
  /// Helper type that maps event names to event object types, but
502
507
  /// includes events that TypeScript's HTMLElementEventMap doesn't know
@@ -613,14 +618,12 @@ export interface EditorProps {
613
618
  /// the document.
614
619
  transformPasted?: (slice: Slice) => Slice
615
620
 
616
- /// Allows you to pass custom rendering and behavior logic for nodes
617
- /// and marks. Should map node and mark names to constructor
618
- /// functions that produce a [`NodeView`](#view.NodeView) object
619
- /// implementing the node's display behavior. For nodes, the third
620
- /// argument `getPos` is a function that can be called to get the
621
- /// node's current position, which can be useful when creating
622
- /// transactions to update it. For marks, the third argument is a
623
- /// boolean that indicates whether the mark's content is inline.
621
+ /// Allows you to pass custom rendering and behavior logic for
622
+ /// nodes. Should map node names to constructor functions that
623
+ /// produce a [`NodeView`](#view.NodeView) object implementing the
624
+ /// node's display behavior. The third argument `getPos` is a
625
+ /// function that can be called to get the node's current position,
626
+ /// which can be useful when creating transactions to update it.
624
627
  ///
625
628
  /// `decorations` is an array of node or inline decorations that are
626
629
  /// active around the node. They are automatically drawn in the
@@ -634,8 +637,19 @@ export interface EditorProps {
634
637
  /// on the content. But if you, for example, want to create a nested
635
638
  /// editor with the content, it may make sense to provide it with the
636
639
  /// inner decorations.
640
+ ///
641
+ /// (For backwards compatibility reasons, [mark
642
+ /// views](#view.ViewProps.markViews) can also be included in this
643
+ /// object.)
637
644
  nodeViews?: {[node: string]: NodeViewConstructor}
638
645
 
646
+ /// Pass custom mark rendering functions. Note that these cannot
647
+ /// provide the kind of dynamic behavior that [node
648
+ /// views](#view.NodeView) can—they just provide custom rendering
649
+ /// logic. The third argument indicates whether the mark's content
650
+ /// is inline.
651
+ markViews?: {[mark: string]: MarkViewConstructor}
652
+
639
653
  /// The DOM serializer to use when putting content onto the
640
654
  /// clipboard. If not given, the result of
641
655
  /// [`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: NodeView = custom && (custom as any)(mark, view, inline)
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