@atlaskit/editor-plugin-show-diff 0.0.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/LICENSE.md +11 -0
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +27 -0
- package/afm-jira/tsconfig.json +27 -0
- package/afm-post-office/tsconfig.json +27 -0
- package/afm-rovo-extension/tsconfig.json +27 -0
- package/afm-townsquare/tsconfig.json +27 -0
- package/build/tsconfig.json +17 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/pm-plugins/decorations.js +55 -0
- package/dist/cjs/pm-plugins/main.js +94 -0
- package/dist/cjs/showDiffPlugin.js +36 -0
- package/dist/cjs/showDiffPluginType.js +5 -0
- package/dist/es2019/index.js +4 -0
- package/dist/es2019/pm-plugins/decorations.js +48 -0
- package/dist/es2019/pm-plugins/main.js +76 -0
- package/dist/es2019/showDiffPlugin.js +27 -0
- package/dist/es2019/showDiffPluginType.js +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/pm-plugins/decorations.js +49 -0
- package/dist/esm/pm-plugins/main.js +87 -0
- package/dist/esm/showDiffPlugin.js +30 -0
- package/dist/esm/showDiffPluginType.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/pm-plugins/decorations.d.ts +26 -0
- package/dist/types/pm-plugins/main.d.ts +12 -0
- package/dist/types/showDiffPlugin.d.ts +2 -0
- package/dist/types/showDiffPluginType.d.ts +26 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +26 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +12 -0
- package/dist/types-ts4.5/showDiffPlugin.d.ts +2 -0
- package/dist/types-ts4.5/showDiffPluginType.d.ts +26 -0
- package/docs/0-intro.tsx +43 -0
- package/package.json +82 -0
- package/tsconfig.json +14 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2019 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
|
4
|
+
compliance with the License. You may obtain a copy of the License at
|
|
5
|
+
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
9
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
10
|
+
implied. See the License for the specific language governing permissions and limitations under the
|
|
11
|
+
License.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Editor plugin show diff
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.confluence.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"composite": true,
|
|
6
|
+
"outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-show-diff",
|
|
7
|
+
"rootDir": "../"
|
|
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-cc/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-cc/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.jira.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"outDir": "../../../../../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-jira/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-jira/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.post-office.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"outDir": "../../../../../post-office/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-post-office/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-post-office/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.rovo-extension.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"outDir": "../../../../../rovo-extension/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-rovo-extension/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-rovo-extension/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.townsquare.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"outDir": "../../../../../townsquare/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-townsquare/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-townsquare/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"paths": {}
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"../src/**/*.ts",
|
|
9
|
+
"../src/**/*.tsx"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"../src/**/__tests__/*",
|
|
13
|
+
"../src/**/*.test.*",
|
|
14
|
+
"../src/**/test.*",
|
|
15
|
+
"../src/**/examples.*"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "showDiffPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _showDiffPlugin.showDiffPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _showDiffPlugin = require("./showDiffPlugin");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createInlineChangedDecoration = exports.createDeletedContentDecoration = void 0;
|
|
7
|
+
var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
|
|
8
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
9
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
10
|
+
var style = (0, _lazyNodeView.convertToInlineCss)({
|
|
11
|
+
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
12
|
+
textDecoration: 'underline',
|
|
13
|
+
textDecorationStyle: 'dotted',
|
|
14
|
+
textDecorationThickness: "var(--ds-space-025, 2px)",
|
|
15
|
+
textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Inline decoration used for insertions as the content already exists in the document
|
|
20
|
+
*
|
|
21
|
+
* @param change Changeset "change" containing information about the change content + range
|
|
22
|
+
* @returns Prosemirror inline decoration
|
|
23
|
+
*/
|
|
24
|
+
var createInlineChangedDecoration = exports.createInlineChangedDecoration = function createInlineChangedDecoration(change) {
|
|
25
|
+
return _view.Decoration.inline(change.fromB, change.toB, {
|
|
26
|
+
style: style
|
|
27
|
+
}, {});
|
|
28
|
+
};
|
|
29
|
+
var deletedContentStyle = (0, _lazyNodeView.convertToInlineCss)({
|
|
30
|
+
color: "var(--ds-text-accent-gray, #44546F)",
|
|
31
|
+
textDecoration: 'line-through'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a widget to represent the deleted content in the editor
|
|
36
|
+
*
|
|
37
|
+
* @param props.change Changeset "change" containing information about the change content + range
|
|
38
|
+
* @param props.doc Baseline doc to compare against
|
|
39
|
+
* @param props.tr The relevant transaction this decoration is being created against
|
|
40
|
+
* @returns Prosemirror widget decoration
|
|
41
|
+
*/
|
|
42
|
+
var createDeletedContentDecoration = exports.createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
|
|
43
|
+
var change = _ref.change,
|
|
44
|
+
doc = _ref.doc,
|
|
45
|
+
tr = _ref.tr;
|
|
46
|
+
var dom = document.createElement('span');
|
|
47
|
+
dom.setAttribute('style', deletedContentStyle);
|
|
48
|
+
dom.appendChild(_model.DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(doc.slice(change.fromA, change.toA).content));
|
|
49
|
+
|
|
50
|
+
// Widget decoration used for deletions as the content is not in the document
|
|
51
|
+
// and we want to display the deleted content with a style.
|
|
52
|
+
return _view.Decoration.widget(change.fromB, dom, {
|
|
53
|
+
marks: []
|
|
54
|
+
});
|
|
55
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.showDiffPluginKey = exports.createPlugin = void 0;
|
|
8
|
+
var _readOnlyError2 = _interopRequireDefault(require("@babel/runtime/helpers/readOnlyError"));
|
|
9
|
+
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
10
|
+
var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
|
|
11
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
14
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
|
+
var _decorations = require("./decorations");
|
|
16
|
+
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; } } }; }
|
|
17
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
18
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
19
|
+
var showDiffPluginKey = exports.showDiffPluginKey = new _state.PluginKey('showDiffPlugin');
|
|
20
|
+
var createPlugin = exports.createPlugin = function createPlugin(config) {
|
|
21
|
+
return new _safePlugin.SafePlugin({
|
|
22
|
+
key: showDiffPluginKey,
|
|
23
|
+
state: {
|
|
24
|
+
init: function init(_, state) {
|
|
25
|
+
var _config$steps;
|
|
26
|
+
var schema = state.schema;
|
|
27
|
+
return {
|
|
28
|
+
steps: ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).map(function (step) {
|
|
29
|
+
return _transform.Step.fromJSON(schema, step);
|
|
30
|
+
}),
|
|
31
|
+
originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
apply: function apply(tr, currentPluginState) {
|
|
35
|
+
var meta = tr.getMeta(showDiffPluginKey);
|
|
36
|
+
if (meta) {
|
|
37
|
+
return meta;
|
|
38
|
+
}
|
|
39
|
+
return currentPluginState;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
props: {
|
|
43
|
+
decorations: function decorations(state) {
|
|
44
|
+
var pluginState = showDiffPluginKey.getState(state);
|
|
45
|
+
if (!pluginState) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
var originalDoc = pluginState.originalDoc,
|
|
49
|
+
steps = pluginState.steps;
|
|
50
|
+
if (!originalDoc) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
var tr = state.tr;
|
|
54
|
+
var steppedDoc = originalDoc;
|
|
55
|
+
var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc);
|
|
56
|
+
var _iterator = _createForOfIteratorHelper(steps),
|
|
57
|
+
_step;
|
|
58
|
+
try {
|
|
59
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
60
|
+
var step = _step.value;
|
|
61
|
+
var result = step.apply(steppedDoc);
|
|
62
|
+
if (result.failed === null && result.doc) {
|
|
63
|
+
steppedDoc = result.doc;
|
|
64
|
+
changeset = changeset.addSteps(steppedDoc, [step.getMap()], tr.doc);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
_iterator.e(err);
|
|
69
|
+
} finally {
|
|
70
|
+
_iterator.f();
|
|
71
|
+
}
|
|
72
|
+
if (!steppedDoc.eq(tr.doc)) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
var changes = (0, _prosemirrorChangeset.simplifyChanges)(changeset.changes, tr.doc);
|
|
76
|
+
var decoration = _view.DecorationSet.empty;
|
|
77
|
+
var decorations = [];
|
|
78
|
+
changes.forEach(function (change) {
|
|
79
|
+
if (change.inserted.length > 0) {
|
|
80
|
+
decorations.push((0, _decorations.createInlineChangedDecoration)(change));
|
|
81
|
+
}
|
|
82
|
+
if (change.deleted.length > 0) {
|
|
83
|
+
decorations.push((0, _decorations.createDeletedContentDecoration)({
|
|
84
|
+
change: change,
|
|
85
|
+
doc: originalDoc,
|
|
86
|
+
tr: tr
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return decoration.add(tr.doc, decorations);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.showDiffPlugin = void 0;
|
|
7
|
+
var _main = require("./pm-plugins/main");
|
|
8
|
+
var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
|
|
9
|
+
var api = _ref.api,
|
|
10
|
+
config = _ref.config;
|
|
11
|
+
return {
|
|
12
|
+
name: 'showDiff',
|
|
13
|
+
commands: {
|
|
14
|
+
showDiff: function showDiff(params) {
|
|
15
|
+
return function (_ref2) {
|
|
16
|
+
var tr = _ref2.tr;
|
|
17
|
+
return tr.setMeta(_main.showDiffPluginKey, params);
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
hideDiff: function hideDiff(_ref3) {
|
|
21
|
+
var tr = _ref3.tr;
|
|
22
|
+
return tr.setMeta(_main.showDiffPluginKey, {
|
|
23
|
+
steps: []
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
pmPlugins: function pmPlugins() {
|
|
28
|
+
return [{
|
|
29
|
+
name: 'showDiffPlugin',
|
|
30
|
+
plugin: function plugin() {
|
|
31
|
+
return (0, _main.createPlugin)(config);
|
|
32
|
+
}
|
|
33
|
+
}];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
const style = convertToInlineCss({
|
|
5
|
+
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
6
|
+
textDecoration: 'underline',
|
|
7
|
+
textDecorationStyle: 'dotted',
|
|
8
|
+
textDecorationThickness: "var(--ds-space-025, 2px)",
|
|
9
|
+
textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inline decoration used for insertions as the content already exists in the document
|
|
14
|
+
*
|
|
15
|
+
* @param change Changeset "change" containing information about the change content + range
|
|
16
|
+
* @returns Prosemirror inline decoration
|
|
17
|
+
*/
|
|
18
|
+
export const createInlineChangedDecoration = change => Decoration.inline(change.fromB, change.toB, {
|
|
19
|
+
style
|
|
20
|
+
}, {});
|
|
21
|
+
const deletedContentStyle = convertToInlineCss({
|
|
22
|
+
color: "var(--ds-text-accent-gray, #44546F)",
|
|
23
|
+
textDecoration: 'line-through'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a widget to represent the deleted content in the editor
|
|
28
|
+
*
|
|
29
|
+
* @param props.change Changeset "change" containing information about the change content + range
|
|
30
|
+
* @param props.doc Baseline doc to compare against
|
|
31
|
+
* @param props.tr The relevant transaction this decoration is being created against
|
|
32
|
+
* @returns Prosemirror widget decoration
|
|
33
|
+
*/
|
|
34
|
+
export const createDeletedContentDecoration = ({
|
|
35
|
+
change,
|
|
36
|
+
doc,
|
|
37
|
+
tr
|
|
38
|
+
}) => {
|
|
39
|
+
const dom = document.createElement('span');
|
|
40
|
+
dom.setAttribute('style', deletedContentStyle);
|
|
41
|
+
dom.appendChild(DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(doc.slice(change.fromA, change.toA).content));
|
|
42
|
+
|
|
43
|
+
// Widget decoration used for deletions as the content is not in the document
|
|
44
|
+
// and we want to display the deleted content with a style.
|
|
45
|
+
return Decoration.widget(change.fromB, dom, {
|
|
46
|
+
marks: []
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
|
|
2
|
+
import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
|
|
3
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
6
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
|
|
8
|
+
export const showDiffPluginKey = new PluginKey('showDiffPlugin');
|
|
9
|
+
export const createPlugin = config => {
|
|
10
|
+
return new SafePlugin({
|
|
11
|
+
key: showDiffPluginKey,
|
|
12
|
+
state: {
|
|
13
|
+
init(_, state) {
|
|
14
|
+
var _config$steps;
|
|
15
|
+
const schema = state.schema;
|
|
16
|
+
return {
|
|
17
|
+
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)),
|
|
18
|
+
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
apply: (tr, currentPluginState) => {
|
|
22
|
+
const meta = tr.getMeta(showDiffPluginKey);
|
|
23
|
+
if (meta) {
|
|
24
|
+
return meta;
|
|
25
|
+
}
|
|
26
|
+
return currentPluginState;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
props: {
|
|
30
|
+
decorations: state => {
|
|
31
|
+
const pluginState = showDiffPluginKey.getState(state);
|
|
32
|
+
if (!pluginState) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
originalDoc,
|
|
37
|
+
steps
|
|
38
|
+
} = pluginState;
|
|
39
|
+
if (!originalDoc) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const {
|
|
43
|
+
tr
|
|
44
|
+
} = state;
|
|
45
|
+
let steppedDoc = originalDoc;
|
|
46
|
+
let changeset = ChangeSet.create(originalDoc);
|
|
47
|
+
for (const step of steps) {
|
|
48
|
+
const result = step.apply(steppedDoc);
|
|
49
|
+
if (result.failed === null && result.doc) {
|
|
50
|
+
steppedDoc = result.doc;
|
|
51
|
+
changeset = changeset.addSteps(steppedDoc, [step.getMap()], tr.doc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!steppedDoc.eq(tr.doc)) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const changes = simplifyChanges(changeset.changes, tr.doc);
|
|
58
|
+
const decoration = DecorationSet.empty;
|
|
59
|
+
const decorations = [];
|
|
60
|
+
changes.forEach(change => {
|
|
61
|
+
if (change.inserted.length > 0) {
|
|
62
|
+
decorations.push(createInlineChangedDecoration(change));
|
|
63
|
+
}
|
|
64
|
+
if (change.deleted.length > 0) {
|
|
65
|
+
decorations.push(createDeletedContentDecoration({
|
|
66
|
+
change,
|
|
67
|
+
doc: originalDoc,
|
|
68
|
+
tr
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return decoration.add(tr.doc, decorations);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createPlugin, showDiffPluginKey } from './pm-plugins/main';
|
|
2
|
+
export const showDiffPlugin = ({
|
|
3
|
+
api,
|
|
4
|
+
config
|
|
5
|
+
}) => ({
|
|
6
|
+
name: 'showDiff',
|
|
7
|
+
commands: {
|
|
8
|
+
showDiff: params => ({
|
|
9
|
+
tr
|
|
10
|
+
}) => {
|
|
11
|
+
return tr.setMeta(showDiffPluginKey, params);
|
|
12
|
+
},
|
|
13
|
+
hideDiff: ({
|
|
14
|
+
tr
|
|
15
|
+
}) => {
|
|
16
|
+
return tr.setMeta(showDiffPluginKey, {
|
|
17
|
+
steps: []
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
pmPlugins() {
|
|
22
|
+
return [{
|
|
23
|
+
name: 'showDiffPlugin',
|
|
24
|
+
plugin: () => createPlugin(config)
|
|
25
|
+
}];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
var style = convertToInlineCss({
|
|
5
|
+
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
6
|
+
textDecoration: 'underline',
|
|
7
|
+
textDecorationStyle: 'dotted',
|
|
8
|
+
textDecorationThickness: "var(--ds-space-025, 2px)",
|
|
9
|
+
textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inline decoration used for insertions as the content already exists in the document
|
|
14
|
+
*
|
|
15
|
+
* @param change Changeset "change" containing information about the change content + range
|
|
16
|
+
* @returns Prosemirror inline decoration
|
|
17
|
+
*/
|
|
18
|
+
export var createInlineChangedDecoration = function createInlineChangedDecoration(change) {
|
|
19
|
+
return Decoration.inline(change.fromB, change.toB, {
|
|
20
|
+
style: style
|
|
21
|
+
}, {});
|
|
22
|
+
};
|
|
23
|
+
var deletedContentStyle = convertToInlineCss({
|
|
24
|
+
color: "var(--ds-text-accent-gray, #44546F)",
|
|
25
|
+
textDecoration: 'line-through'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a widget to represent the deleted content in the editor
|
|
30
|
+
*
|
|
31
|
+
* @param props.change Changeset "change" containing information about the change content + range
|
|
32
|
+
* @param props.doc Baseline doc to compare against
|
|
33
|
+
* @param props.tr The relevant transaction this decoration is being created against
|
|
34
|
+
* @returns Prosemirror widget decoration
|
|
35
|
+
*/
|
|
36
|
+
export var createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
|
|
37
|
+
var change = _ref.change,
|
|
38
|
+
doc = _ref.doc,
|
|
39
|
+
tr = _ref.tr;
|
|
40
|
+
var dom = document.createElement('span');
|
|
41
|
+
dom.setAttribute('style', deletedContentStyle);
|
|
42
|
+
dom.appendChild(DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(doc.slice(change.fromA, change.toA).content));
|
|
43
|
+
|
|
44
|
+
// Widget decoration used for deletions as the content is not in the document
|
|
45
|
+
// and we want to display the deleted content with a style.
|
|
46
|
+
return Decoration.widget(change.fromB, dom, {
|
|
47
|
+
marks: []
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _readOnlyError from "@babel/runtime/helpers/readOnlyError";
|
|
2
|
+
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; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
|
|
6
|
+
import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
|
|
7
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
8
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
+
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
10
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
11
|
+
import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
|
|
12
|
+
export var showDiffPluginKey = new PluginKey('showDiffPlugin');
|
|
13
|
+
export var createPlugin = function createPlugin(config) {
|
|
14
|
+
return new SafePlugin({
|
|
15
|
+
key: showDiffPluginKey,
|
|
16
|
+
state: {
|
|
17
|
+
init: function init(_, state) {
|
|
18
|
+
var _config$steps;
|
|
19
|
+
var schema = state.schema;
|
|
20
|
+
return {
|
|
21
|
+
steps: ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).map(function (step) {
|
|
22
|
+
return ProseMirrorStep.fromJSON(schema, step);
|
|
23
|
+
}),
|
|
24
|
+
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
apply: function apply(tr, currentPluginState) {
|
|
28
|
+
var meta = tr.getMeta(showDiffPluginKey);
|
|
29
|
+
if (meta) {
|
|
30
|
+
return meta;
|
|
31
|
+
}
|
|
32
|
+
return currentPluginState;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
props: {
|
|
36
|
+
decorations: function decorations(state) {
|
|
37
|
+
var pluginState = showDiffPluginKey.getState(state);
|
|
38
|
+
if (!pluginState) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
var originalDoc = pluginState.originalDoc,
|
|
42
|
+
steps = pluginState.steps;
|
|
43
|
+
if (!originalDoc) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
var tr = state.tr;
|
|
47
|
+
var steppedDoc = originalDoc;
|
|
48
|
+
var changeset = ChangeSet.create(originalDoc);
|
|
49
|
+
var _iterator = _createForOfIteratorHelper(steps),
|
|
50
|
+
_step;
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
+
var step = _step.value;
|
|
54
|
+
var result = step.apply(steppedDoc);
|
|
55
|
+
if (result.failed === null && result.doc) {
|
|
56
|
+
steppedDoc = result.doc;
|
|
57
|
+
changeset = changeset.addSteps(steppedDoc, [step.getMap()], tr.doc);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator.f();
|
|
64
|
+
}
|
|
65
|
+
if (!steppedDoc.eq(tr.doc)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
var changes = simplifyChanges(changeset.changes, tr.doc);
|
|
69
|
+
var decoration = DecorationSet.empty;
|
|
70
|
+
var decorations = [];
|
|
71
|
+
changes.forEach(function (change) {
|
|
72
|
+
if (change.inserted.length > 0) {
|
|
73
|
+
decorations.push(createInlineChangedDecoration(change));
|
|
74
|
+
}
|
|
75
|
+
if (change.deleted.length > 0) {
|
|
76
|
+
decorations.push(createDeletedContentDecoration({
|
|
77
|
+
change: change,
|
|
78
|
+
doc: originalDoc,
|
|
79
|
+
tr: tr
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return decoration.add(tr.doc, decorations);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createPlugin, showDiffPluginKey } from './pm-plugins/main';
|
|
2
|
+
export var showDiffPlugin = function showDiffPlugin(_ref) {
|
|
3
|
+
var api = _ref.api,
|
|
4
|
+
config = _ref.config;
|
|
5
|
+
return {
|
|
6
|
+
name: 'showDiff',
|
|
7
|
+
commands: {
|
|
8
|
+
showDiff: function showDiff(params) {
|
|
9
|
+
return function (_ref2) {
|
|
10
|
+
var tr = _ref2.tr;
|
|
11
|
+
return tr.setMeta(showDiffPluginKey, params);
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
hideDiff: function hideDiff(_ref3) {
|
|
15
|
+
var tr = _ref3.tr;
|
|
16
|
+
return tr.setMeta(showDiffPluginKey, {
|
|
17
|
+
steps: []
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
pmPlugins: function pmPlugins() {
|
|
22
|
+
return [{
|
|
23
|
+
name: 'showDiffPlugin',
|
|
24
|
+
plugin: function plugin() {
|
|
25
|
+
return createPlugin(config);
|
|
26
|
+
}
|
|
27
|
+
}];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Change } from 'prosemirror-changeset';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
/**
|
|
6
|
+
* Inline decoration used for insertions as the content already exists in the document
|
|
7
|
+
*
|
|
8
|
+
* @param change Changeset "change" containing information about the change content + range
|
|
9
|
+
* @returns Prosemirror inline decoration
|
|
10
|
+
*/
|
|
11
|
+
export declare const createInlineChangedDecoration: (change: Change) => Decoration;
|
|
12
|
+
interface DeletedContentDecorationProps {
|
|
13
|
+
change: Change;
|
|
14
|
+
doc: PMNode;
|
|
15
|
+
tr: Transaction;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a widget to represent the deleted content in the editor
|
|
19
|
+
*
|
|
20
|
+
* @param props.change Changeset "change" containing information about the change content + range
|
|
21
|
+
* @param props.doc Baseline doc to compare against
|
|
22
|
+
* @param props.tr The relevant transaction this decoration is being created against
|
|
23
|
+
* @returns Prosemirror widget decoration
|
|
24
|
+
*/
|
|
25
|
+
export declare const createDeletedContentDecoration: ({ change, doc, tr, }: DeletedContentDecorationProps) => Decoration;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
+
import type { DiffParams } from '../showDiffPluginType';
|
|
6
|
+
export declare const showDiffPluginKey: PluginKey<ShowDiffPluginState>;
|
|
7
|
+
type ShowDiffPluginState = {
|
|
8
|
+
steps: ProseMirrorStep[];
|
|
9
|
+
originalDoc: PMNode | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare const createPlugin: (config: DiffParams | undefined) => SafePlugin<ShowDiffPluginState>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StepJson } from '@atlaskit/editor-common/collab';
|
|
2
|
+
import type { NextEditorPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
4
|
+
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import type { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
6
|
+
export type DiffParams = {
|
|
7
|
+
/**
|
|
8
|
+
* Prosemirror steps. This is used to calculate and show the diff in the editor
|
|
9
|
+
*/
|
|
10
|
+
steps: StepJson[];
|
|
11
|
+
originalDoc: JSONDocNode;
|
|
12
|
+
};
|
|
13
|
+
export type PMDiffParams = {
|
|
14
|
+
/**
|
|
15
|
+
* Prosemirror steps. This is used to calculate and show the diff in the editor
|
|
16
|
+
*/
|
|
17
|
+
steps: Step[];
|
|
18
|
+
originalDoc: Node;
|
|
19
|
+
};
|
|
20
|
+
export type ShowDiffPlugin = NextEditorPlugin<'showDiff', {
|
|
21
|
+
pluginConfiguration: DiffParams | undefined;
|
|
22
|
+
commands: {
|
|
23
|
+
showDiff: (config: PMDiffParams) => EditorCommand;
|
|
24
|
+
hideDiff: EditorCommand;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Change } from 'prosemirror-changeset';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
/**
|
|
6
|
+
* Inline decoration used for insertions as the content already exists in the document
|
|
7
|
+
*
|
|
8
|
+
* @param change Changeset "change" containing information about the change content + range
|
|
9
|
+
* @returns Prosemirror inline decoration
|
|
10
|
+
*/
|
|
11
|
+
export declare const createInlineChangedDecoration: (change: Change) => Decoration;
|
|
12
|
+
interface DeletedContentDecorationProps {
|
|
13
|
+
change: Change;
|
|
14
|
+
doc: PMNode;
|
|
15
|
+
tr: Transaction;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a widget to represent the deleted content in the editor
|
|
19
|
+
*
|
|
20
|
+
* @param props.change Changeset "change" containing information about the change content + range
|
|
21
|
+
* @param props.doc Baseline doc to compare against
|
|
22
|
+
* @param props.tr The relevant transaction this decoration is being created against
|
|
23
|
+
* @returns Prosemirror widget decoration
|
|
24
|
+
*/
|
|
25
|
+
export declare const createDeletedContentDecoration: ({ change, doc, tr, }: DeletedContentDecorationProps) => Decoration;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
+
import type { DiffParams } from '../showDiffPluginType';
|
|
6
|
+
export declare const showDiffPluginKey: PluginKey<ShowDiffPluginState>;
|
|
7
|
+
type ShowDiffPluginState = {
|
|
8
|
+
steps: ProseMirrorStep[];
|
|
9
|
+
originalDoc: PMNode | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare const createPlugin: (config: DiffParams | undefined) => SafePlugin<ShowDiffPluginState>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StepJson } from '@atlaskit/editor-common/collab';
|
|
2
|
+
import type { NextEditorPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
4
|
+
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import type { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
6
|
+
export type DiffParams = {
|
|
7
|
+
/**
|
|
8
|
+
* Prosemirror steps. This is used to calculate and show the diff in the editor
|
|
9
|
+
*/
|
|
10
|
+
steps: StepJson[];
|
|
11
|
+
originalDoc: JSONDocNode;
|
|
12
|
+
};
|
|
13
|
+
export type PMDiffParams = {
|
|
14
|
+
/**
|
|
15
|
+
* Prosemirror steps. This is used to calculate and show the diff in the editor
|
|
16
|
+
*/
|
|
17
|
+
steps: Step[];
|
|
18
|
+
originalDoc: Node;
|
|
19
|
+
};
|
|
20
|
+
export type ShowDiffPlugin = NextEditorPlugin<'showDiff', {
|
|
21
|
+
pluginConfiguration: DiffParams | undefined;
|
|
22
|
+
commands: {
|
|
23
|
+
showDiff: (config: PMDiffParams) => EditorCommand;
|
|
24
|
+
hideDiff: EditorCommand;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
package/docs/0-intro.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { AtlassianInternalWarning, code, md } from '@atlaskit/docs';
|
|
4
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
|
+
import { createEditorUseOnlyNotice } from '@atlaskit/editor-common/doc-utils';
|
|
6
|
+
import { token } from '@atlaskit/tokens';
|
|
7
|
+
|
|
8
|
+
export default md`
|
|
9
|
+
|
|
10
|
+
${createEditorUseOnlyNotice('Editor Plugin Show Diff', [
|
|
11
|
+
{ name: 'Editor Core', link: '/packages/editor/editor-core' },
|
|
12
|
+
])}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
${
|
|
16
|
+
(
|
|
17
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
18
|
+
<div style={{ marginTop: token('space.100', '8px') }}>
|
|
19
|
+
<AtlassianInternalWarning />
|
|
20
|
+
</div>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
This package includes the show diff plugin used by \`@atlaskit/editor-core\`.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
The \`dependencies\`, \`configuration\`, \`state\`, \`actions\`, and \`commands\` of the plugin are defined
|
|
30
|
+
below:
|
|
31
|
+
|
|
32
|
+
${code`
|
|
33
|
+
type ShowDiffPlugin = NextEditorPlugin<'showDiff'>
|
|
34
|
+
`}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Support
|
|
38
|
+
---
|
|
39
|
+
For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
|
|
40
|
+
## License
|
|
41
|
+
---
|
|
42
|
+
Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
|
|
43
|
+
`;
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-show-diff",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "ShowDiff plugin for @atlaskit/editor-core",
|
|
5
|
+
"author": "Atlassian Pty Ltd",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org/"
|
|
9
|
+
},
|
|
10
|
+
"atlassian": {
|
|
11
|
+
"team": "Editor: Lego",
|
|
12
|
+
"releaseModel": "continuous",
|
|
13
|
+
"singleton": true
|
|
14
|
+
},
|
|
15
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
|
|
16
|
+
"main": "dist/cjs/index.js",
|
|
17
|
+
"module": "dist/esm/index.js",
|
|
18
|
+
"module:es2019": "dist/es2019/index.js",
|
|
19
|
+
"types": "dist/types/index.d.ts",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
">=4.5 <4.9": {
|
|
22
|
+
"*": [
|
|
23
|
+
"dist/types-ts4.5/*",
|
|
24
|
+
"dist/types-ts4.5/index.d.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"atlaskit:src": "src/index.ts",
|
|
30
|
+
"af:exports": {
|
|
31
|
+
".": "./src/index.ts"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
35
|
+
"@atlaskit/tokens": "^5.6.0",
|
|
36
|
+
"@babel/runtime": "^7.0.0",
|
|
37
|
+
"prosemirror-changeset": "^2.2.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@atlaskit/editor-common": "^107.12.0",
|
|
41
|
+
"react": "^18.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "~5.4.2"
|
|
45
|
+
},
|
|
46
|
+
"techstack": {
|
|
47
|
+
"@atlassian/frontend": {
|
|
48
|
+
"code-structure": [
|
|
49
|
+
"editor-plugin"
|
|
50
|
+
],
|
|
51
|
+
"import-structure": [
|
|
52
|
+
"atlassian-conventions"
|
|
53
|
+
],
|
|
54
|
+
"circular-dependencies": [
|
|
55
|
+
"file-and-folder-level"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"@repo/internal": {
|
|
59
|
+
"dom-events": "use-bind-event-listener",
|
|
60
|
+
"analytics": [
|
|
61
|
+
"analytics-next"
|
|
62
|
+
],
|
|
63
|
+
"design-tokens": [
|
|
64
|
+
"color"
|
|
65
|
+
],
|
|
66
|
+
"theming": [
|
|
67
|
+
"react-context"
|
|
68
|
+
],
|
|
69
|
+
"ui-components": [
|
|
70
|
+
"lite-mode"
|
|
71
|
+
],
|
|
72
|
+
"deprecation": "no-deprecated-imports",
|
|
73
|
+
"styling": [
|
|
74
|
+
"emotion",
|
|
75
|
+
"emotion"
|
|
76
|
+
],
|
|
77
|
+
"imports": [
|
|
78
|
+
"import-no-extraneous-disable-for-examples-and-docs"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"__tests__/**/*.ts",
|
|
5
|
+
"__tests__/**/*.tsx",
|
|
6
|
+
"docs/**/*.ts",
|
|
7
|
+
"docs/**/*.tsx",
|
|
8
|
+
"examples/**/*.ts",
|
|
9
|
+
"examples/**/*.tsx",
|
|
10
|
+
"src/**/*.ts",
|
|
11
|
+
"src/**/*.tsx"
|
|
12
|
+
],
|
|
13
|
+
"compilerOptions": {}
|
|
14
|
+
}
|