@atlaskit/editor-plugin-show-diff 0.1.0 → 0.1.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`941fdc429d140`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/941fdc429d140) -
8
+ Show formatting changes in the diff
9
+ - Updated dependencies
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  ### Minor Changes
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.passionfruit.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../passionfruit/tsDist/@atlaskit__editor-plugin-show-diff/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../../design-system/tokens/afm-passionfruit/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-common/afm-passionfruit/tsconfig.json"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.volt.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../volt/tsDist/@atlaskit__editor-plugin-show-diff/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../../design-system/tokens/afm-volt/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-common/afm-volt/tsconfig.json"
25
+ }
26
+ ]
27
+ }
@@ -13,6 +13,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
13
13
  var _transform = require("@atlaskit/editor-prosemirror/transform");
14
14
  var _view = require("@atlaskit/editor-prosemirror/view");
15
15
  var _decorations = require("./decorations");
16
+ var _markDecorations = require("./markDecorations");
16
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
18
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
19
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
@@ -23,7 +24,7 @@ var calculateDecorations = function calculateDecorations(_ref) {
23
24
  pluginState = _ref.pluginState;
24
25
  var originalDoc = pluginState.originalDoc,
25
26
  steps = pluginState.steps;
26
- if (!originalDoc) {
27
+ if (!originalDoc || !pluginState.isDisplayingChanges) {
27
28
  return _view.DecorationSet.empty;
28
29
  }
29
30
  var tr = state.tr;
@@ -62,6 +63,9 @@ var calculateDecorations = function calculateDecorations(_ref) {
62
63
  }));
63
64
  }
64
65
  });
66
+ (0, _markDecorations.getMarkChangeRanges)(steps).forEach(function (change) {
67
+ decorations.push((0, _decorations.createInlineChangedDecoration)(change));
68
+ });
65
69
  return _view.DecorationSet.empty.add(tr.doc, decorations);
66
70
  };
67
71
  var showDiffPluginKey = exports.showDiffPluginKey = new _state.PluginKey('showDiffPlugin');
@@ -70,10 +74,11 @@ var createPlugin = exports.createPlugin = function createPlugin(config) {
70
74
  key: showDiffPluginKey,
71
75
  state: {
72
76
  init: function init(_, state) {
73
- var _config$steps;
77
+ var _config$steps, _config$steps2;
74
78
  var schema = state.schema;
79
+ var isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
75
80
  return {
76
- steps: ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).map(function (step) {
81
+ steps: ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(function (step) {
77
82
  return _transform.Step.fromJSON(schema, step);
78
83
  }),
79
84
  originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined,
@@ -81,9 +86,11 @@ var createPlugin = exports.createPlugin = function createPlugin(config) {
81
86
  state: state,
82
87
  pluginState: {
83
88
  steps: [],
84
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined
89
+ originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined,
90
+ isDisplayingChanges: isDisplayingChanges
85
91
  }
86
- })
92
+ }),
93
+ isDisplayingChanges: isDisplayingChanges
87
94
  };
88
95
  },
89
96
  apply: function apply(tr, currentPluginState, oldState, newState) {
@@ -108,7 +115,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config) {
108
115
  state: newState,
109
116
  pluginState: {
110
117
  steps: newPluginState.steps,
111
- originalDoc: newPluginState.originalDoc
118
+ originalDoc: newPluginState.originalDoc,
119
+ isDisplayingChanges: newPluginState.isDisplayingChanges
112
120
  }
113
121
  });
114
122
  return _objectSpread(_objectSpread({}, newPluginState), {}, {
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getMarkChangeRanges = void 0;
7
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
8
+ var filterUndefined = function filterUndefined(x) {
9
+ return !!x;
10
+ };
11
+ var getMarkChangeRanges = exports.getMarkChangeRanges = function getMarkChangeRanges(steps) {
12
+ return steps.map(function (step) {
13
+ if (step instanceof _transform.AddMarkStep || step instanceof _transform.RemoveMarkStep) {
14
+ return {
15
+ fromB: step.from,
16
+ toB: step.to
17
+ };
18
+ }
19
+ return undefined;
20
+ }).filter(filterUndefined);
21
+ };
@@ -6,6 +6,7 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
6
  import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
9
+ import { getMarkChangeRanges } from './markDecorations';
9
10
  const calculateDecorations = ({
10
11
  state,
11
12
  pluginState
@@ -14,7 +15,7 @@ const calculateDecorations = ({
14
15
  originalDoc,
15
16
  steps
16
17
  } = pluginState;
17
- if (!originalDoc) {
18
+ if (!originalDoc || !pluginState.isDisplayingChanges) {
18
19
  return DecorationSet.empty;
19
20
  }
20
21
  const {
@@ -46,6 +47,9 @@ const calculateDecorations = ({
46
47
  }));
47
48
  }
48
49
  });
50
+ getMarkChangeRanges(steps).forEach(change => {
51
+ decorations.push(createInlineChangedDecoration(change));
52
+ });
49
53
  return DecorationSet.empty.add(tr.doc, decorations);
50
54
  };
51
55
  export const showDiffPluginKey = new PluginKey('showDiffPlugin');
@@ -54,18 +58,21 @@ export const createPlugin = config => {
54
58
  key: showDiffPluginKey,
55
59
  state: {
56
60
  init(_, state) {
57
- var _config$steps;
61
+ var _config$steps, _config$steps2;
58
62
  const schema = state.schema;
63
+ const isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
59
64
  return {
60
- steps: ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).map(step => ProseMirrorStep.fromJSON(schema, step)),
65
+ steps: ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(step => ProseMirrorStep.fromJSON(schema, step)),
61
66
  originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
62
67
  decorations: calculateDecorations({
63
68
  state,
64
69
  pluginState: {
65
70
  steps: [],
66
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined
71
+ originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
72
+ isDisplayingChanges
67
73
  }
68
- })
74
+ }),
75
+ isDisplayingChanges
69
76
  };
70
77
  },
71
78
  apply: (tr, currentPluginState, oldState, newState) => {
@@ -97,7 +104,8 @@ export const createPlugin = config => {
97
104
  state: newState,
98
105
  pluginState: {
99
106
  steps: newPluginState.steps,
100
- originalDoc: newPluginState.originalDoc
107
+ originalDoc: newPluginState.originalDoc,
108
+ isDisplayingChanges: newPluginState.isDisplayingChanges
101
109
  }
102
110
  });
103
111
  return {
@@ -0,0 +1,13 @@
1
+ import { AddMarkStep, RemoveMarkStep } from '@atlaskit/editor-prosemirror/transform';
2
+ const filterUndefined = x => !!x;
3
+ export const getMarkChangeRanges = steps => {
4
+ return steps.map(step => {
5
+ if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
6
+ return {
7
+ fromB: step.from,
8
+ toB: step.to
9
+ };
10
+ }
11
+ return undefined;
12
+ }).filter(filterUndefined);
13
+ };
@@ -12,12 +12,13 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
12
12
  import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
13
13
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
14
14
  import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
15
+ import { getMarkChangeRanges } from './markDecorations';
15
16
  var calculateDecorations = function calculateDecorations(_ref) {
16
17
  var state = _ref.state,
17
18
  pluginState = _ref.pluginState;
18
19
  var originalDoc = pluginState.originalDoc,
19
20
  steps = pluginState.steps;
20
- if (!originalDoc) {
21
+ if (!originalDoc || !pluginState.isDisplayingChanges) {
21
22
  return DecorationSet.empty;
22
23
  }
23
24
  var tr = state.tr;
@@ -56,6 +57,9 @@ var calculateDecorations = function calculateDecorations(_ref) {
56
57
  }));
57
58
  }
58
59
  });
60
+ getMarkChangeRanges(steps).forEach(function (change) {
61
+ decorations.push(createInlineChangedDecoration(change));
62
+ });
59
63
  return DecorationSet.empty.add(tr.doc, decorations);
60
64
  };
61
65
  export var showDiffPluginKey = new PluginKey('showDiffPlugin');
@@ -64,10 +68,11 @@ export var createPlugin = function createPlugin(config) {
64
68
  key: showDiffPluginKey,
65
69
  state: {
66
70
  init: function init(_, state) {
67
- var _config$steps;
71
+ var _config$steps, _config$steps2;
68
72
  var schema = state.schema;
73
+ var isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
69
74
  return {
70
- steps: ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).map(function (step) {
75
+ steps: ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(function (step) {
71
76
  return ProseMirrorStep.fromJSON(schema, step);
72
77
  }),
73
78
  originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
@@ -75,9 +80,11 @@ export var createPlugin = function createPlugin(config) {
75
80
  state: state,
76
81
  pluginState: {
77
82
  steps: [],
78
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined
83
+ originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
84
+ isDisplayingChanges: isDisplayingChanges
79
85
  }
80
- })
86
+ }),
87
+ isDisplayingChanges: isDisplayingChanges
81
88
  };
82
89
  },
83
90
  apply: function apply(tr, currentPluginState, oldState, newState) {
@@ -102,7 +109,8 @@ export var createPlugin = function createPlugin(config) {
102
109
  state: newState,
103
110
  pluginState: {
104
111
  steps: newPluginState.steps,
105
- originalDoc: newPluginState.originalDoc
112
+ originalDoc: newPluginState.originalDoc,
113
+ isDisplayingChanges: newPluginState.isDisplayingChanges
106
114
  }
107
115
  });
108
116
  return _objectSpread(_objectSpread({}, newPluginState), {}, {
@@ -0,0 +1,15 @@
1
+ import { AddMarkStep, RemoveMarkStep } from '@atlaskit/editor-prosemirror/transform';
2
+ var filterUndefined = function filterUndefined(x) {
3
+ return !!x;
4
+ };
5
+ export var getMarkChangeRanges = function getMarkChangeRanges(steps) {
6
+ return steps.map(function (step) {
7
+ if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
8
+ return {
9
+ fromB: step.from,
10
+ toB: step.to
11
+ };
12
+ }
13
+ return undefined;
14
+ }).filter(filterUndefined);
15
+ };
@@ -8,7 +8,10 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
8
  * @param change Changeset "change" containing information about the change content + range
9
9
  * @returns Prosemirror inline decoration
10
10
  */
11
- export declare const createInlineChangedDecoration: (change: Change) => Decoration;
11
+ export declare const createInlineChangedDecoration: (change: {
12
+ fromB: number;
13
+ toB: number;
14
+ }) => Decoration;
12
15
  interface DeletedContentDecorationProps {
13
16
  change: Change;
14
17
  doc: PMNode;
@@ -9,6 +9,7 @@ type ShowDiffPluginState = {
9
9
  steps: ProseMirrorStep[];
10
10
  originalDoc: PMNode | undefined;
11
11
  decorations: DecorationSet;
12
+ isDisplayingChanges: boolean;
12
13
  };
13
14
  export declare const createPlugin: (config: DiffParams | undefined) => SafePlugin<ShowDiffPluginState>;
14
15
  export {};
@@ -0,0 +1,7 @@
1
+ import { type Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
2
+ type StepRange = {
3
+ fromB: number;
4
+ toB: number;
5
+ };
6
+ export declare const getMarkChangeRanges: (steps: ProseMirrorStep[]) => StepRange[];
7
+ export {};
@@ -8,7 +8,10 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
8
  * @param change Changeset "change" containing information about the change content + range
9
9
  * @returns Prosemirror inline decoration
10
10
  */
11
- export declare const createInlineChangedDecoration: (change: Change) => Decoration;
11
+ export declare const createInlineChangedDecoration: (change: {
12
+ fromB: number;
13
+ toB: number;
14
+ }) => Decoration;
12
15
  interface DeletedContentDecorationProps {
13
16
  change: Change;
14
17
  doc: PMNode;
@@ -9,6 +9,7 @@ type ShowDiffPluginState = {
9
9
  steps: ProseMirrorStep[];
10
10
  originalDoc: PMNode | undefined;
11
11
  decorations: DecorationSet;
12
+ isDisplayingChanges: boolean;
12
13
  };
13
14
  export declare const createPlugin: (config: DiffParams | undefined) => SafePlugin<ShowDiffPluginState>;
14
15
  export {};
@@ -0,0 +1,7 @@
1
+ import { type Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
2
+ type StepRange = {
3
+ fromB: number;
4
+ toB: number;
5
+ };
6
+ export declare const getMarkChangeRanges: (steps: ProseMirrorStep[]) => StepRange[];
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -37,7 +37,7 @@
37
37
  "prosemirror-changeset": "^2.2.1"
38
38
  },
39
39
  "peerDependencies": {
40
- "@atlaskit/editor-common": "^107.20.0",
40
+ "@atlaskit/editor-common": "^107.23.0",
41
41
  "react": "^18.2.0"
42
42
  },
43
43
  "techstack": {