@atlaskit/editor-plugin-show-diff 12.1.2 → 12.1.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.
@@ -1,120 +0,0 @@
1
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
- import { createLeftAnchorWidget } from './createAnchorDecorationWidgets';
3
- import { buildDiffDecorationSpec, buildAnchorDecorationKey } from './decorationKeys';
4
- import { wrapBlockNodeView, injectInnerWrapper } from './utils/wrapBlockNodeView';
5
-
6
- /**
7
- * Creates a single block widget that renders a reference text block content
8
- * beneath a granular diff set, for reference when deleted content is hidden.
9
- *
10
- * Since granular diffing only applies to singular isTextBlock=true nodes, this
11
- * widget always renders exactly one block node and does not need the slice/fragment
12
- * complexity of createNodeChangedDecorationWidget.
13
- *
14
- * Resolves which doc and positions to render based on isInverted:
15
- * - !isInverted: renders originalDoc at A-side positions (what was there before)
16
- * - isInverted: renders newDoc at B-side positions (the current/new content)
17
- *
18
- * The widget is always inserted at the B-side block boundary in newDoc since
19
- * ProseMirror decorations are always anchored against the live (new) document.
20
- */
21
- export var createGranularBlockReferenceWidget = function createGranularBlockReferenceWidget(_ref) {
22
- var change = _ref.change,
23
- originalDoc = _ref.originalDoc,
24
- newDoc = _ref.newDoc,
25
- isInverted = _ref.isInverted,
26
- nodeViewSerializer = _ref.nodeViewSerializer,
27
- colorScheme = _ref.colorScheme,
28
- intl = _ref.intl,
29
- activeIndexPos = _ref.activeIndexPos,
30
- diffId = _ref.diffId,
31
- _ref$showIndicators = _ref.showIndicators,
32
- showIndicators = _ref$showIndicators === void 0 ? false : _ref$showIndicators;
33
- // Determine which doc and positions to use for rendering the reference block.
34
- var renderDoc = isInverted ? newDoc : originalDoc;
35
- var renderTo = isInverted ? change.toB : change.toA;
36
-
37
- // The insertion point is always in newDoc — ProseMirror decorates against the live document.
38
- // Walk up from toB to find the enclosing text block boundary for widget placement.
39
- var insertResolvedPos = newDoc.resolve(change.toB);
40
- var blockEnd = change.toB;
41
- for (var depth = insertResolvedPos.depth; depth >= 0; depth--) {
42
- var node = insertResolvedPos.node(depth);
43
- if (node.isTextblock) {
44
- blockEnd = insertResolvedPos.start(depth) + node.nodeSize - 1;
45
- break;
46
- }
47
- }
48
-
49
- // Find the block node to render from the render doc at the render positions.
50
- var renderResolvedPos = renderDoc.resolve(renderTo);
51
- var renderBlockNode = null;
52
- for (var _depth = renderResolvedPos.depth; _depth >= 0; _depth--) {
53
- var _node = renderResolvedPos.node(_depth);
54
- if (_node.isTextblock) {
55
- renderBlockNode = _node;
56
- break;
57
- }
58
- }
59
- if (!renderBlockNode) {
60
- return [];
61
- }
62
- var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
63
-
64
- /**
65
- * This will always be a block node as it's a textBlock-like node.
66
- * We use div instead of span so we can add margins.
67
- */
68
- var dom = document.createElement('div');
69
- dom.setAttribute('data-testid', 'show-diff-granular-block-reference');
70
- dom.style.setProperty('margin-top', "var(--ds-space-200, 16px)");
71
- var nodeView = nodeViewSerializer.tryCreateNodeView(renderBlockNode);
72
- if (nodeView) {
73
- wrapBlockNodeView({
74
- dom: dom,
75
- nodeView: nodeView,
76
- targetNode: renderBlockNode,
77
- colorScheme: colorScheme,
78
- intl: intl,
79
- isActive: !!isActive,
80
- isInserted: false
81
- });
82
- } else {
83
- var serialized = nodeViewSerializer.serializeNode(renderBlockNode);
84
- if (serialized && serialized instanceof HTMLElement) {
85
- injectInnerWrapper({
86
- node: serialized,
87
- colorScheme: colorScheme,
88
- isActive: !!isActive,
89
- isInserted: false
90
- });
91
- dom.append(serialized);
92
- } else if (serialized) {
93
- dom.append(serialized);
94
- }
95
- }
96
- if (dom.childNodes.length === 0) {
97
- return [];
98
- }
99
- var decorations = [];
100
- if (showIndicators) {
101
- var leftAnchor = createLeftAnchorWidget({
102
- doc: newDoc,
103
- from: blockEnd,
104
- diffId: diffId
105
- });
106
- dom.style.setProperty('anchor-name', "--".concat(buildAnchorDecorationKey({
107
- diffId: diffId
108
- })));
109
- if (leftAnchor) {
110
- decorations.push(leftAnchor);
111
- }
112
- }
113
- decorations.push(Decoration.widget(blockEnd, dom, buildDiffDecorationSpec({
114
- decorationType: 'widget',
115
- diffId: diffId,
116
- // We want it to be as close to the granular diff as possible
117
- side: -999
118
- })));
119
- return decorations;
120
- };
@@ -1,36 +0,0 @@
1
- import type { Change } from 'prosemirror-changeset';
2
- import type { IntlShape } from 'react-intl';
3
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
- import type { ColorScheme } from '../../showDiffPluginType';
6
- import type { NodeViewSerializer } from '../NodeViewSerializer';
7
- /**
8
- * Creates a single block widget that renders a reference text block content
9
- * beneath a granular diff set, for reference when deleted content is hidden.
10
- *
11
- * Since granular diffing only applies to singular isTextBlock=true nodes, this
12
- * widget always renders exactly one block node and does not need the slice/fragment
13
- * complexity of createNodeChangedDecorationWidget.
14
- *
15
- * Resolves which doc and positions to render based on isInverted:
16
- * - !isInverted: renders originalDoc at A-side positions (what was there before)
17
- * - isInverted: renders newDoc at B-side positions (the current/new content)
18
- *
19
- * The widget is always inserted at the B-side block boundary in newDoc since
20
- * ProseMirror decorations are always anchored against the live (new) document.
21
- */
22
- export declare const createGranularBlockReferenceWidget: ({ change, originalDoc, newDoc, isInverted, nodeViewSerializer, colorScheme, intl, activeIndexPos, diffId, showIndicators, }: {
23
- activeIndexPos?: {
24
- from: number;
25
- to: number;
26
- };
27
- change: Change;
28
- colorScheme?: ColorScheme;
29
- diffId: string;
30
- intl: IntlShape;
31
- isInverted: boolean;
32
- newDoc: PMNode;
33
- nodeViewSerializer: NodeViewSerializer;
34
- originalDoc: PMNode;
35
- showIndicators?: boolean;
36
- }) => Decoration[];