@atlaskit/editor-plugin-code-block-advanced 1.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/CHANGELOG.md +13 -0
- package/LICENSE.md +11 -0
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +36 -0
- package/build/tsconfig.json +17 -0
- package/dist/cjs/codeBlockAdvancedPlugin.js +33 -0
- package/dist/cjs/codeBlockAdvancedPluginType.js +5 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +212 -0
- package/dist/cjs/nodeviews/codeBlockNodeWithToDOMFixed.js +55 -0
- package/dist/cjs/nodeviews/codemirrorSync/syncCMWithPM.js +38 -0
- package/dist/cjs/nodeviews/codemirrorSync/updateCMSelection.js +36 -0
- package/dist/cjs/nodeviews/extensions/bidiCharWarning.js +83 -0
- package/dist/cjs/nodeviews/extensions/keymap/backspace.js +33 -0
- package/dist/cjs/nodeviews/extensions/keymap/index.js +129 -0
- package/dist/cjs/nodeviews/extensions/keymap/maybeEscape.js +63 -0
- package/dist/cjs/nodeviews/languages/languageMap.js +100 -0
- package/dist/cjs/nodeviews/languages/loader.js +50 -0
- package/dist/cjs/nodeviews/lazyCodeBlockAdvanced.js +29 -0
- package/dist/cjs/pm-plugins/main.js +17 -0
- package/dist/cjs/ui/syntaxHighlightingTheme.js +76 -0
- package/dist/cjs/ui/theme.js +55 -0
- package/dist/es2019/codeBlockAdvancedPlugin.js +26 -0
- package/dist/es2019/codeBlockAdvancedPluginType.js +1 -0
- package/dist/es2019/index.js +4 -0
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +170 -0
- package/dist/es2019/nodeviews/codeBlockNodeWithToDOMFixed.js +42 -0
- package/dist/es2019/nodeviews/codemirrorSync/syncCMWithPM.js +35 -0
- package/dist/es2019/nodeviews/codemirrorSync/updateCMSelection.js +30 -0
- package/dist/es2019/nodeviews/extensions/bidiCharWarning.js +53 -0
- package/dist/es2019/nodeviews/extensions/keymap/backspace.js +28 -0
- package/dist/es2019/nodeviews/extensions/keymap/index.js +107 -0
- package/dist/es2019/nodeviews/extensions/keymap/maybeEscape.js +57 -0
- package/dist/es2019/nodeviews/languages/languageMap.js +82 -0
- package/dist/es2019/nodeviews/languages/loader.js +37 -0
- package/dist/es2019/nodeviews/lazyCodeBlockAdvanced.js +18 -0
- package/dist/es2019/pm-plugins/main.js +11 -0
- package/dist/es2019/ui/syntaxHighlightingTheme.js +70 -0
- package/dist/es2019/ui/theme.js +49 -0
- package/dist/esm/codeBlockAdvancedPlugin.js +27 -0
- package/dist/esm/codeBlockAdvancedPluginType.js +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/nodeviews/codeBlockAdvanced.js +205 -0
- package/dist/esm/nodeviews/codeBlockNodeWithToDOMFixed.js +48 -0
- package/dist/esm/nodeviews/codemirrorSync/syncCMWithPM.js +32 -0
- package/dist/esm/nodeviews/codemirrorSync/updateCMSelection.js +30 -0
- package/dist/esm/nodeviews/extensions/bidiCharWarning.js +77 -0
- package/dist/esm/nodeviews/extensions/keymap/backspace.js +27 -0
- package/dist/esm/nodeviews/extensions/keymap/index.js +122 -0
- package/dist/esm/nodeviews/extensions/keymap/maybeEscape.js +56 -0
- package/dist/esm/nodeviews/languages/languageMap.js +86 -0
- package/dist/esm/nodeviews/languages/loader.js +44 -0
- package/dist/esm/nodeviews/lazyCodeBlockAdvanced.js +17 -0
- package/dist/esm/pm-plugins/main.js +11 -0
- package/dist/esm/ui/syntaxHighlightingTheme.js +70 -0
- package/dist/esm/ui/theme.js +49 -0
- package/dist/types/codeBlockAdvancedPlugin.d.ts +2 -0
- package/dist/types/codeBlockAdvancedPluginType.d.ts +11 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +38 -0
- package/dist/types/nodeviews/codeBlockNodeWithToDOMFixed.d.ts +2 -0
- package/dist/types/nodeviews/codemirrorSync/syncCMWithPM.d.ts +17 -0
- package/dist/types/nodeviews/codemirrorSync/updateCMSelection.d.ts +11 -0
- package/dist/types/nodeviews/extensions/bidiCharWarning.d.ts +8 -0
- package/dist/types/nodeviews/extensions/keymap/backspace.d.ts +12 -0
- package/dist/types/nodeviews/extensions/keymap/index.d.ts +14 -0
- package/dist/types/nodeviews/extensions/keymap/maybeEscape.d.ts +17 -0
- package/dist/types/nodeviews/languages/languageMap.d.ts +5 -0
- package/dist/types/nodeviews/languages/loader.d.ts +11 -0
- package/dist/types/nodeviews/lazyCodeBlockAdvanced.d.ts +9 -0
- package/dist/types/pm-plugins/main.d.ts +10 -0
- package/dist/types/ui/syntaxHighlightingTheme.d.ts +2 -0
- package/dist/types/ui/theme.d.ts +1 -0
- package/dist/types-ts4.5/codeBlockAdvancedPlugin.d.ts +2 -0
- package/dist/types-ts4.5/codeBlockAdvancedPluginType.d.ts +15 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +38 -0
- package/dist/types-ts4.5/nodeviews/codeBlockNodeWithToDOMFixed.d.ts +2 -0
- package/dist/types-ts4.5/nodeviews/codemirrorSync/syncCMWithPM.d.ts +17 -0
- package/dist/types-ts4.5/nodeviews/codemirrorSync/updateCMSelection.d.ts +11 -0
- package/dist/types-ts4.5/nodeviews/extensions/bidiCharWarning.d.ts +8 -0
- package/dist/types-ts4.5/nodeviews/extensions/keymap/backspace.d.ts +12 -0
- package/dist/types-ts4.5/nodeviews/extensions/keymap/index.d.ts +14 -0
- package/dist/types-ts4.5/nodeviews/extensions/keymap/maybeEscape.d.ts +17 -0
- package/dist/types-ts4.5/nodeviews/languages/languageMap.d.ts +5 -0
- package/dist/types-ts4.5/nodeviews/languages/loader.d.ts +12 -0
- package/dist/types-ts4.5/nodeviews/lazyCodeBlockAdvanced.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +10 -0
- package/dist/types-ts4.5/ui/syntaxHighlightingTheme.d.ts +2 -0
- package/dist/types-ts4.5/ui/theme.d.ts +1 -0
- package/docs/0-intro.tsx +56 -0
- package/package.json +96 -0
- package/src/codeBlockAdvancedPlugin.tsx +25 -0
- package/src/codeBlockAdvancedPluginType.ts +18 -0
- package/src/index.ts +5 -0
- package/src/nodeviews/codeBlockAdvanced.ts +223 -0
- package/src/nodeviews/codeBlockNodeWithToDOMFixed.ts +59 -0
- package/src/nodeviews/codemirrorSync/syncCMWithPM.ts +40 -0
- package/src/nodeviews/codemirrorSync/updateCMSelection.ts +40 -0
- package/src/nodeviews/extensions/bidiCharWarning.ts +72 -0
- package/src/nodeviews/extensions/keymap/backspace.ts +47 -0
- package/src/nodeviews/extensions/keymap/index.ts +118 -0
- package/src/nodeviews/extensions/keymap/maybeEscape.ts +69 -0
- package/src/nodeviews/languages/languageMap.ts +91 -0
- package/src/nodeviews/languages/loader.ts +44 -0
- package/src/nodeviews/lazyCodeBlockAdvanced.ts +32 -0
- package/src/pm-plugins/main.ts +22 -0
- package/src/ui/syntaxHighlightingTheme.ts +50 -0
- package/src/ui/theme.ts +52 -0
- package/tsconfig.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-code-block-advanced
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#100411](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100411)
|
|
8
|
+
[`14499ab145534`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/14499ab145534) -
|
|
9
|
+
[ux] Introduces advanced code block as per:
|
|
10
|
+
https://hello.atlassian.net/wiki/spaces/EDITOR/pages/4632293323/Editor+RFC+063+Advanced+code+blocks.
|
|
11
|
+
This can be added to an existing editor preset to enrich the code block experience with syntax
|
|
12
|
+
highlighting and can be extended for other features via CodeMirror extensions (ie. autocompletion,
|
|
13
|
+
code folding etc.).
|
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 code block-advanced
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.confluence.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"composite": true,
|
|
6
|
+
"outDir": "../dist",
|
|
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": "../../editor-common/afm-cc/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-plugin-code-block/afm-cc/tsconfig.json"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../editor-plugin-editor-disabled/afm-cc/tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../../editor-plugin-selection/afm-cc/tsconfig.json"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "../../../design-system/tokens/afm-cc/tsconfig.json"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -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,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.codeBlockAdvancedPlugin = void 0;
|
|
7
|
+
var _codeBlockNodeWithToDOMFixed = require("./nodeviews/codeBlockNodeWithToDOMFixed");
|
|
8
|
+
var _main = require("./pm-plugins/main");
|
|
9
|
+
var codeBlockAdvancedPlugin = exports.codeBlockAdvancedPlugin = function codeBlockAdvancedPlugin(_ref) {
|
|
10
|
+
var api = _ref.api,
|
|
11
|
+
config = _ref.config;
|
|
12
|
+
return {
|
|
13
|
+
name: 'codeBlockAdvanced',
|
|
14
|
+
nodes: function nodes() {
|
|
15
|
+
return [{
|
|
16
|
+
name: 'codeBlock',
|
|
17
|
+
node: (0, _codeBlockNodeWithToDOMFixed.codeBlockNodeWithFixedToDOM)()
|
|
18
|
+
}];
|
|
19
|
+
},
|
|
20
|
+
pmPlugins: function pmPlugins() {
|
|
21
|
+
return [{
|
|
22
|
+
name: 'codeBlockAdvancedPlugin',
|
|
23
|
+
plugin: function plugin() {
|
|
24
|
+
var _config$extensions;
|
|
25
|
+
return (0, _main.createPlugin)({
|
|
26
|
+
api: api,
|
|
27
|
+
extensions: (_config$extensions = config === null || config === void 0 ? void 0 : config.extensions) !== null && _config$extensions !== void 0 ? _config$extensions : []
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}];
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "codeBlockAdvancedPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _codeBlockAdvancedPlugin.codeBlockAdvancedPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _codeBlockAdvancedPlugin = require("./codeBlockAdvancedPlugin");
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getCodeBlockAdvancedNodeView = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
var _autocomplete = require("@codemirror/autocomplete");
|
|
13
|
+
var _language = require("@codemirror/language");
|
|
14
|
+
var _state = require("@codemirror/state");
|
|
15
|
+
var _view = require("@codemirror/view");
|
|
16
|
+
var _codeBlock = require("@atlaskit/editor-common/code-block");
|
|
17
|
+
var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
18
|
+
var _syntaxHighlightingTheme = require("../ui/syntaxHighlightingTheme");
|
|
19
|
+
var _theme = require("../ui/theme");
|
|
20
|
+
var _syncCMWithPM = require("./codemirrorSync/syncCMWithPM");
|
|
21
|
+
var _updateCMSelection = require("./codemirrorSync/updateCMSelection");
|
|
22
|
+
var _bidiCharWarning = require("./extensions/bidiCharWarning");
|
|
23
|
+
var _keymap = require("./extensions/keymap");
|
|
24
|
+
var _loader = require("./languages/loader");
|
|
25
|
+
// Based on: https://prosemirror.net/examples/codemirror/
|
|
26
|
+
var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
28
|
+
function CodeBlockAdvancedNodeView(node, view, getPos, config) {
|
|
29
|
+
var _config$api,
|
|
30
|
+
_this = this,
|
|
31
|
+
_config$api2;
|
|
32
|
+
(0, _classCallCheck2.default)(this, CodeBlockAdvancedNodeView);
|
|
33
|
+
(0, _defineProperty2.default)(this, "lineWrappingCompartment", new _state.Compartment());
|
|
34
|
+
(0, _defineProperty2.default)(this, "languageCompartment", new _state.Compartment());
|
|
35
|
+
(0, _defineProperty2.default)(this, "readOnlyCompartment", new _state.Compartment());
|
|
36
|
+
(0, _defineProperty2.default)(this, "maybeTryingToReachNodeSelection", false);
|
|
37
|
+
(0, _defineProperty2.default)(this, "wordWrappingEnabled", false);
|
|
38
|
+
this.node = node;
|
|
39
|
+
this.view = view;
|
|
40
|
+
this.getPos = getPos;
|
|
41
|
+
this.selectionAPI = (_config$api = config.api) === null || _config$api === void 0 || (_config$api = _config$api.selection) === null || _config$api === void 0 ? void 0 : _config$api.actions;
|
|
42
|
+
var getNode = function getNode() {
|
|
43
|
+
return _this.node;
|
|
44
|
+
};
|
|
45
|
+
var onMaybeNodeSelection = function onMaybeNodeSelection() {
|
|
46
|
+
return _this.maybeTryingToReachNodeSelection = true;
|
|
47
|
+
};
|
|
48
|
+
this.cleanupDisabledState = (_config$api2 = config.api) === null || _config$api2 === void 0 || (_config$api2 = _config$api2.editorDisabled) === null || _config$api2 === void 0 ? void 0 : _config$api2.sharedState.onChange(function () {
|
|
49
|
+
_this.updateReadonlyState();
|
|
50
|
+
});
|
|
51
|
+
this.languageLoader = new _loader.LanguageLoader(function (lang) {
|
|
52
|
+
_this.updating = true;
|
|
53
|
+
_this.cm.dispatch({
|
|
54
|
+
effects: _this.languageCompartment.reconfigure(lang)
|
|
55
|
+
});
|
|
56
|
+
_this.updating = false;
|
|
57
|
+
});
|
|
58
|
+
this.cm = new _view.EditorView({
|
|
59
|
+
doc: this.node.textContent,
|
|
60
|
+
extensions: [].concat((0, _toConsumableArray2.default)(config.extensions), [this.lineWrappingCompartment.of([]), this.languageCompartment.of([]), (0, _keymap.keymapExtension)({
|
|
61
|
+
view: view,
|
|
62
|
+
getPos: getPos,
|
|
63
|
+
getNode: getNode,
|
|
64
|
+
selectCodeBlockNode: this.selectCodeBlockNode.bind(this),
|
|
65
|
+
onMaybeNodeSelection: onMaybeNodeSelection
|
|
66
|
+
}), _theme.cmTheme, (0, _language.syntaxHighlighting)(_syntaxHighlightingTheme.highlightStyle), (0, _view.lineNumbers)(), _view.EditorView.updateListener.of(function (update) {
|
|
67
|
+
return _this.forwardUpdate(update);
|
|
68
|
+
}), this.readOnlyCompartment.of(_view.EditorView.editable.of(this.view.editable)), (0, _autocomplete.closeBrackets)(), _view.EditorView.editorAttributes.of({
|
|
69
|
+
class: 'code-block'
|
|
70
|
+
}), _bidiCharWarning.bidiCharWarningExtension])
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// The editor's outer node is our DOM representation
|
|
74
|
+
this.dom = this.cm.dom;
|
|
75
|
+
|
|
76
|
+
// This flag is used to avoid an update loop between the outer and
|
|
77
|
+
// inner editor
|
|
78
|
+
this.updating = false;
|
|
79
|
+
this.updateLanguage();
|
|
80
|
+
}
|
|
81
|
+
return (0, _createClass2.default)(CodeBlockAdvancedNodeView, [{
|
|
82
|
+
key: "destroy",
|
|
83
|
+
value: function destroy() {
|
|
84
|
+
var _this$cleanupDisabled;
|
|
85
|
+
(_this$cleanupDisabled = this.cleanupDisabledState) === null || _this$cleanupDisabled === void 0 || _this$cleanupDisabled.call(this);
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "forwardUpdate",
|
|
89
|
+
value: function forwardUpdate(update) {
|
|
90
|
+
var _this$getPos, _this$getPos2;
|
|
91
|
+
if (this.updating || !this.cm.hasFocus) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
var offset = ((_this$getPos = (_this$getPos2 = this.getPos) === null || _this$getPos2 === void 0 ? void 0 : _this$getPos2.call(this)) !== null && _this$getPos !== void 0 ? _this$getPos : 0) + 1;
|
|
95
|
+
(0, _syncCMWithPM.syncCMWithPM)({
|
|
96
|
+
view: this.view,
|
|
97
|
+
update: update,
|
|
98
|
+
offset: offset
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "setSelection",
|
|
103
|
+
value: function setSelection(anchor, head) {
|
|
104
|
+
if (!this.maybeTryingToReachNodeSelection) {
|
|
105
|
+
this.cm.focus();
|
|
106
|
+
}
|
|
107
|
+
this.updating = true;
|
|
108
|
+
this.cm.dispatch({
|
|
109
|
+
selection: {
|
|
110
|
+
anchor: anchor,
|
|
111
|
+
head: head
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.updating = false;
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "updateReadonlyState",
|
|
118
|
+
value: function updateReadonlyState() {
|
|
119
|
+
this.updating = true;
|
|
120
|
+
this.cm.dispatch({
|
|
121
|
+
effects: this.readOnlyCompartment.reconfigure(_view.EditorView.editable.of(this.view.editable))
|
|
122
|
+
});
|
|
123
|
+
this.updating = false;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "updateLanguage",
|
|
127
|
+
value: function updateLanguage() {
|
|
128
|
+
this.languageLoader.updateLanguage(this.node.attrs.language);
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "selectCodeBlockNode",
|
|
132
|
+
value: function selectCodeBlockNode(relativeSelectionPos) {
|
|
133
|
+
var _this$selectionAPI, _this$getPos3, _this$getPos4;
|
|
134
|
+
var tr = (_this$selectionAPI = this.selectionAPI) === null || _this$selectionAPI === void 0 ? void 0 : _this$selectionAPI.selectNearNode({
|
|
135
|
+
selectionRelativeToNode: relativeSelectionPos,
|
|
136
|
+
selection: _state2.NodeSelection.create(this.view.state.doc, (_this$getPos3 = (_this$getPos4 = this.getPos) === null || _this$getPos4 === void 0 ? void 0 : _this$getPos4.call(this)) !== null && _this$getPos3 !== void 0 ? _this$getPos3 : 0)
|
|
137
|
+
})(this.view.state);
|
|
138
|
+
if (tr) {
|
|
139
|
+
this.view.dispatch(tr);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: "updateWordWrap",
|
|
144
|
+
value: function updateWordWrap(node) {
|
|
145
|
+
if (this.wordWrappingEnabled !== (0, _codeBlock.isCodeBlockWordWrapEnabled)(node)) {
|
|
146
|
+
this.updating = true;
|
|
147
|
+
this.cm.dispatch({
|
|
148
|
+
effects: [this.lineWrappingCompartment.reconfigure((0, _codeBlock.isCodeBlockWordWrapEnabled)(node) ? _view.EditorView.lineWrapping : [])]
|
|
149
|
+
});
|
|
150
|
+
this.updating = false;
|
|
151
|
+
this.wordWrappingEnabled = !this.wordWrappingEnabled;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}, {
|
|
155
|
+
key: "update",
|
|
156
|
+
value: function update(node) {
|
|
157
|
+
var _this2 = this;
|
|
158
|
+
this.maybeTryingToReachNodeSelection = false;
|
|
159
|
+
if (node.type !== this.node.type) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
this.updateWordWrap(node);
|
|
163
|
+
this.node = node;
|
|
164
|
+
if (this.updating) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
this.updateLanguage();
|
|
168
|
+
var newText = node.textContent,
|
|
169
|
+
curText = this.cm.state.doc.toString();
|
|
170
|
+
(0, _updateCMSelection.updateCMSelection)(curText, newText, function (tr) {
|
|
171
|
+
_this2.updating = true;
|
|
172
|
+
_this2.cm.dispatch(tr);
|
|
173
|
+
_this2.updating = false;
|
|
174
|
+
});
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "stopEvent",
|
|
179
|
+
value: function stopEvent(e) {
|
|
180
|
+
var _this3 = this,
|
|
181
|
+
_this$getPos5;
|
|
182
|
+
if (e instanceof MouseEvent && e.type === 'mousedown') {
|
|
183
|
+
// !Warning: Side effect!
|
|
184
|
+
// CodeMirror on blur updates the dom observer with a `setTimeout(..., 10);`
|
|
185
|
+
// We need to select the nodeview after this has taken place to ensure
|
|
186
|
+
// ProseMirror takes over
|
|
187
|
+
// https://github.com/codemirror/view/commit/70a9a253df04a57004247b9463198c17832f92f4#diff-cb8cbffa623ff0975389e7e8c315e69d5e10345239ffe2c9b4b7986a56ad95efR720
|
|
188
|
+
setTimeout(function () {
|
|
189
|
+
// Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
|
|
190
|
+
// cause funky behaviour
|
|
191
|
+
_this3.updating = true;
|
|
192
|
+
_this3.cm.dispatch({
|
|
193
|
+
selection: _state.EditorSelection.create([_state.EditorSelection.cursor(0)], 0)
|
|
194
|
+
});
|
|
195
|
+
_this3.updating = false;
|
|
196
|
+
_this3.selectCodeBlockNode(undefined);
|
|
197
|
+
_this3.view.focus();
|
|
198
|
+
}, 20);
|
|
199
|
+
}
|
|
200
|
+
// If we have selected the node we should not stop these events
|
|
201
|
+
if (e instanceof KeyboardEvent && this.view.state.selection instanceof _state2.NodeSelection && this.view.state.selection.from === ((_this$getPos5 = this.getPos) === null || _this$getPos5 === void 0 ? void 0 : _this$getPos5.call(this))) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
}]);
|
|
207
|
+
}();
|
|
208
|
+
var getCodeBlockAdvancedNodeView = exports.getCodeBlockAdvancedNodeView = function getCodeBlockAdvancedNodeView(props) {
|
|
209
|
+
return function (node, view, getPos) {
|
|
210
|
+
return new CodeBlockAdvancedNodeView(node, view, getPos, props);
|
|
211
|
+
};
|
|
212
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.codeBlockNodeWithFixedToDOM = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
var codeBlockClassNames = {
|
|
14
|
+
container: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
|
|
15
|
+
start: _styles.CodeBlockSharedCssClassName.CODEBLOCK_START,
|
|
16
|
+
end: _styles.CodeBlockSharedCssClassName.CODEBLOCK_END,
|
|
17
|
+
contentWrapper: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
|
|
18
|
+
contentWrapped: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED,
|
|
19
|
+
gutter: _styles.CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
|
|
20
|
+
content: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT,
|
|
21
|
+
lineNumberWidget: _styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER_LINE_NUMBER_WIDGET
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// From: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
|
|
25
|
+
var _toDOM = function toDOM(node, contentEditable, formattedAriaLabel) {
|
|
26
|
+
return ['div', {
|
|
27
|
+
class: codeBlockClassNames.container
|
|
28
|
+
}, ['div', {
|
|
29
|
+
class: codeBlockClassNames.start,
|
|
30
|
+
contenteditable: 'false'
|
|
31
|
+
}], ['div', {
|
|
32
|
+
class: codeBlockClassNames.contentWrapper
|
|
33
|
+
}, ['div', {
|
|
34
|
+
class: codeBlockClassNames.gutter,
|
|
35
|
+
contenteditable: 'false'
|
|
36
|
+
}], ['div', {
|
|
37
|
+
class: codeBlockClassNames.content
|
|
38
|
+
}, ['code', {
|
|
39
|
+
'data-language': node.attrs.language || '',
|
|
40
|
+
spellcheck: 'false',
|
|
41
|
+
contenteditable: contentEditable ? 'true' : 'false',
|
|
42
|
+
'data-testid': 'code-block--code',
|
|
43
|
+
'aria-label': formattedAriaLabel
|
|
44
|
+
}, 0]]], ['div', {
|
|
45
|
+
class: codeBlockClassNames.end,
|
|
46
|
+
contenteditable: 'false'
|
|
47
|
+
}]];
|
|
48
|
+
};
|
|
49
|
+
var codeBlockNodeWithFixedToDOM = exports.codeBlockNodeWithFixedToDOM = function codeBlockNodeWithFixedToDOM() {
|
|
50
|
+
return _objectSpread(_objectSpread({}, _adfSchema.codeBlock), {}, {
|
|
51
|
+
toDOM: function toDOM(node) {
|
|
52
|
+
return _toDOM(node, false, '');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.syncCMWithPM = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Synchronises the CodeMirror update changes with the Prosemirror editor
|
|
11
|
+
*
|
|
12
|
+
* @param props.view EditorView - Prosemirror EditorView
|
|
13
|
+
* @param props.update ViewUpdate - CodeMirror ViewUpdate
|
|
14
|
+
* @param props.offset number - position where the code block starts in prosemirror
|
|
15
|
+
*/
|
|
16
|
+
var syncCMWithPM = exports.syncCMWithPM = function syncCMWithPM(_ref) {
|
|
17
|
+
var view = _ref.view,
|
|
18
|
+
update = _ref.update,
|
|
19
|
+
offset = _ref.offset;
|
|
20
|
+
var main = update.state.selection.main;
|
|
21
|
+
var selFrom = offset + main.from;
|
|
22
|
+
var selTo = offset + main.to;
|
|
23
|
+
var pmSel = view.state.selection;
|
|
24
|
+
if (update.docChanged || pmSel.from !== selFrom || pmSel.to !== selTo) {
|
|
25
|
+
var tr = view.state.tr;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
27
|
+
update.changes.iterChanges(function (fromA, toA, fromB, toB, text) {
|
|
28
|
+
if (text.length) {
|
|
29
|
+
tr.replaceWith(offset + fromA, offset + toA, view.state.schema.text(text.toString()));
|
|
30
|
+
} else {
|
|
31
|
+
tr.delete(offset + fromA, offset + toA);
|
|
32
|
+
}
|
|
33
|
+
offset += toB - fromB - (toA - fromA);
|
|
34
|
+
});
|
|
35
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, selFrom, selTo));
|
|
36
|
+
view.dispatch(tr);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.updateCMSelection = void 0;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* Compares the updated text with the current to determine the transaction to fire
|
|
10
|
+
* in the CodeMirror editor.
|
|
11
|
+
*
|
|
12
|
+
* @param curText string - the current CodeMirror text
|
|
13
|
+
* @param newText string - the new CodeMirror text
|
|
14
|
+
* @param updateCallback Callback to process the CodeMirror transaction
|
|
15
|
+
*/
|
|
16
|
+
var updateCMSelection = exports.updateCMSelection = function updateCMSelection(curText, newText, updateCallback) {
|
|
17
|
+
if (newText !== curText) {
|
|
18
|
+
var start = 0,
|
|
19
|
+
curEnd = curText.length,
|
|
20
|
+
newEnd = newText.length;
|
|
21
|
+
while (start < curEnd && curText.charCodeAt(start) === newText.charCodeAt(start)) {
|
|
22
|
+
++start;
|
|
23
|
+
}
|
|
24
|
+
while (curEnd > start && newEnd > start && curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1)) {
|
|
25
|
+
curEnd--;
|
|
26
|
+
newEnd--;
|
|
27
|
+
}
|
|
28
|
+
updateCallback({
|
|
29
|
+
changes: {
|
|
30
|
+
from: start,
|
|
31
|
+
to: curEnd,
|
|
32
|
+
insert: newText.slice(start, newEnd)
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.bidiCharWarningExtension = void 0;
|
|
8
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
9
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
10
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _view = require("@codemirror/view");
|
|
14
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
15
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
|
|
16
|
+
* Code based on warning from @atlaskit/code
|
|
17
|
+
*/
|
|
18
|
+
var bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/g;
|
|
19
|
+
var placeholderMatcher = new _view.MatchDecorator({
|
|
20
|
+
regexp: bidiCharacterRegex,
|
|
21
|
+
decoration: function decoration(match) {
|
|
22
|
+
return _view.Decoration.replace({
|
|
23
|
+
widget: new PlaceholderWidget(match[0])
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
var bidiCharWarningExtension = exports.bidiCharWarningExtension = _view.ViewPlugin.fromClass( /*#__PURE__*/function () {
|
|
28
|
+
function _class(view) {
|
|
29
|
+
(0, _classCallCheck2.default)(this, _class);
|
|
30
|
+
this.placeholders = placeholderMatcher.createDeco(view);
|
|
31
|
+
}
|
|
32
|
+
return (0, _createClass2.default)(_class, [{
|
|
33
|
+
key: "update",
|
|
34
|
+
value: function update(_update) {
|
|
35
|
+
this.placeholders = placeholderMatcher.updateDeco(_update, this.placeholders);
|
|
36
|
+
}
|
|
37
|
+
}]);
|
|
38
|
+
}(), {
|
|
39
|
+
decorations: function decorations(instance) {
|
|
40
|
+
return instance.placeholders;
|
|
41
|
+
},
|
|
42
|
+
provide: function provide(plugin) {
|
|
43
|
+
return _view.EditorView.atomicRanges.of(function (view) {
|
|
44
|
+
var _view$plugin;
|
|
45
|
+
return ((_view$plugin = view.plugin(plugin)) === null || _view$plugin === void 0 ? void 0 : _view$plugin.placeholders) || _view.Decoration.none;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
function getBidiCharacterCode(bidiCharacter) {
|
|
50
|
+
var _bidiCharacter$codePo;
|
|
51
|
+
var bidiCharacterCode = (_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toString(16);
|
|
52
|
+
return "U+".concat(bidiCharacterCode);
|
|
53
|
+
}
|
|
54
|
+
var PlaceholderWidget = /*#__PURE__*/function (_WidgetType) {
|
|
55
|
+
function PlaceholderWidget(name) {
|
|
56
|
+
var _this;
|
|
57
|
+
(0, _classCallCheck2.default)(this, PlaceholderWidget);
|
|
58
|
+
_this = _callSuper(this, PlaceholderWidget);
|
|
59
|
+
_this.name = name;
|
|
60
|
+
return _this;
|
|
61
|
+
}
|
|
62
|
+
(0, _inherits2.default)(PlaceholderWidget, _WidgetType);
|
|
63
|
+
return (0, _createClass2.default)(PlaceholderWidget, [{
|
|
64
|
+
key: "eq",
|
|
65
|
+
value: function eq(other) {
|
|
66
|
+
return this.name === other.name;
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "toDOM",
|
|
70
|
+
value: function toDOM() {
|
|
71
|
+
var elt = document.createElement('span');
|
|
72
|
+
elt.setAttribute('data-bidi-character-code', this.name);
|
|
73
|
+
elt.style.cssText = "\n padding: 0 3px;\n color: ".concat("var(--ds-text-warning, #A54800)", ";\n\t\t\tbackground: ", "var(--ds-background-warning, #FFF7D6)", ";\n\t\t\taria-hidden=\"true\"");
|
|
74
|
+
elt.textContent = "<".concat(getBidiCharacterCode(this.name), ">");
|
|
75
|
+
return elt;
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "ignoreEvent",
|
|
79
|
+
value: function ignoreEvent() {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}]);
|
|
83
|
+
}(_view.WidgetType);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.backspaceKeymap = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var backspaceKeymap = exports.backspaceKeymap = function backspaceKeymap(_ref) {
|
|
9
|
+
var _getPos;
|
|
10
|
+
var cm = _ref.cm,
|
|
11
|
+
view = _ref.view,
|
|
12
|
+
getPos = _ref.getPos,
|
|
13
|
+
getNode = _ref.getNode;
|
|
14
|
+
var ranges = cm.state.selection.ranges;
|
|
15
|
+
if (ranges.length > 1) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var selection = ranges[0];
|
|
19
|
+
if (selection && (!selection.empty || selection.anchor > 0)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (cm.state.doc.lines >= 2) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
var state = view.state;
|
|
26
|
+
var pos = (_getPos = getPos()) !== null && _getPos !== void 0 ? _getPos : 0;
|
|
27
|
+
var node = getNode();
|
|
28
|
+
var tr = state.tr.replaceWith(pos, pos + node.nodeSize, state.schema.nodes.paragraph.createChecked({}, node.content));
|
|
29
|
+
tr.setSelection(_state.TextSelection.near(tr.doc.resolve(pos)));
|
|
30
|
+
view.dispatch(tr);
|
|
31
|
+
view.focus();
|
|
32
|
+
return true;
|
|
33
|
+
};
|