@atlaskit/editor-plugin-code-block-advanced 1.0.2 → 1.1.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 +21 -0
- package/afm-cc/tsconfig.json +6 -0
- package/afm-jira/tsconfig.json +6 -0
- package/afm-post-office/tsconfig.json +6 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +29 -26
- package/dist/cjs/nodeviews/codemirrorSync/syncCMWithPM.js +0 -1
- package/dist/cjs/nodeviews/extensions/keymap/index.js +23 -3
- package/dist/cjs/nodeviews/extensions/manageSelectionMarker.js +28 -0
- package/dist/cjs/nodeviews/extensions/prosemirrorDecorations.js +134 -0
- package/dist/cjs/ui/theme.js +20 -2
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +27 -27
- package/dist/es2019/nodeviews/codemirrorSync/syncCMWithPM.js +0 -1
- package/dist/es2019/nodeviews/extensions/keymap/index.js +23 -3
- package/dist/es2019/nodeviews/extensions/manageSelectionMarker.js +22 -0
- package/dist/es2019/nodeviews/extensions/prosemirrorDecorations.js +99 -0
- package/dist/es2019/ui/theme.js +62 -2
- package/dist/esm/nodeviews/codeBlockAdvanced.js +30 -27
- package/dist/esm/nodeviews/codemirrorSync/syncCMWithPM.js +0 -1
- package/dist/esm/nodeviews/extensions/keymap/index.js +23 -3
- package/dist/esm/nodeviews/extensions/manageSelectionMarker.js +22 -0
- package/dist/esm/nodeviews/extensions/prosemirrorDecorations.js +127 -0
- package/dist/esm/ui/theme.js +20 -2
- package/dist/types/codeBlockAdvancedPluginType.d.ts +9 -1
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +10 -5
- package/dist/types/nodeviews/extensions/keymap/index.d.ts +2 -1
- package/dist/types/nodeviews/extensions/manageSelectionMarker.d.ts +10 -0
- package/dist/types/nodeviews/extensions/prosemirrorDecorations.d.ts +20 -0
- package/dist/types-ts4.5/codeBlockAdvancedPluginType.d.ts +5 -1
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +10 -5
- package/dist/types-ts4.5/nodeviews/extensions/keymap/index.d.ts +2 -1
- package/dist/types-ts4.5/nodeviews/extensions/manageSelectionMarker.d.ts +10 -0
- package/dist/types-ts4.5/nodeviews/extensions/prosemirrorDecorations.d.ts +20 -0
- package/package.json +10 -8
- package/src/codeBlockAdvancedPluginType.ts +9 -1
- package/src/nodeviews/codeBlockAdvanced.ts +31 -30
- package/src/nodeviews/codemirrorSync/syncCMWithPM.ts +0 -1
- package/src/nodeviews/extensions/keymap/index.ts +31 -1
- package/src/nodeviews/extensions/manageSelectionMarker.ts +28 -0
- package/src/nodeviews/extensions/prosemirrorDecorations.ts +148 -0
- package/src/ui/theme.ts +64 -0
- package/tsconfig.app.json +6 -0
- package/dist/cjs/nodeviews/extensions/bidiCharWarning.js +0 -83
- package/dist/cjs/nodeviews/extensions/copyButtonDecorations.js +0 -22
- package/dist/es2019/nodeviews/extensions/bidiCharWarning.js +0 -53
- package/dist/es2019/nodeviews/extensions/copyButtonDecorations.js +0 -16
- package/dist/esm/nodeviews/extensions/bidiCharWarning.js +0 -77
- package/dist/esm/nodeviews/extensions/copyButtonDecorations.js +0 -16
- package/dist/types/nodeviews/extensions/bidiCharWarning.d.ts +0 -8
- package/dist/types/nodeviews/extensions/copyButtonDecorations.d.ts +0 -1
- package/dist/types-ts4.5/nodeviews/extensions/bidiCharWarning.d.ts +0 -8
- package/dist/types-ts4.5/nodeviews/extensions/copyButtonDecorations.d.ts +0 -1
- package/src/nodeviews/extensions/bidiCharWarning.ts +0 -72
- package/src/nodeviews/extensions/copyButtonDecorations.ts +0 -15
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Facet } from '@codemirror/state';
|
|
2
|
+
import {
|
|
3
|
+
ViewPlugin,
|
|
4
|
+
WidgetType,
|
|
5
|
+
Decoration as CodeMirrorDecoration,
|
|
6
|
+
EditorView as CodeMirror,
|
|
7
|
+
DecorationSet,
|
|
8
|
+
ViewUpdate,
|
|
9
|
+
} from '@codemirror/view';
|
|
10
|
+
|
|
11
|
+
import type { EditorView, Decoration, DecorationSource } from '@atlaskit/editor-prosemirror/view';
|
|
12
|
+
|
|
13
|
+
class PMWidget extends WidgetType {
|
|
14
|
+
constructor(readonly toDOMElement: HTMLElement) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
toDOM() {
|
|
18
|
+
return this.toDOMElement;
|
|
19
|
+
}
|
|
20
|
+
ignoreEvent() {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// This type is not exposed publically by ProseMirror but we need it to map to CodeMirror
|
|
26
|
+
// See: https://github.com/ProseMirror/prosemirror-view/blob/master/src/decoration.ts
|
|
27
|
+
type WidgetConstructor = ((view: EditorView, getPos: () => number | undefined) => Node) | Node;
|
|
28
|
+
|
|
29
|
+
// This type is not exposed publically by ProseMirror but we need it to map to CodeMirror
|
|
30
|
+
// See: https://github.com/ProseMirror/prosemirror-view/blob/master/src/decoration.ts
|
|
31
|
+
interface ExtendedProseMirrorDecoration extends Decoration {
|
|
32
|
+
inline: boolean;
|
|
33
|
+
widget: boolean;
|
|
34
|
+
type: {
|
|
35
|
+
attrs?: Record<string, string>;
|
|
36
|
+
toDOM?: WidgetConstructor;
|
|
37
|
+
side?: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// This type is not exposed publically by ProseMirror but we need it to map to CodeMirror
|
|
42
|
+
// See: https://github.com/ProseMirror/prosemirror-view/blob/master/src/decoration.ts
|
|
43
|
+
function isExtendedDecoration(decoration: Decoration): decoration is ExtendedProseMirrorDecoration {
|
|
44
|
+
return (
|
|
45
|
+
(decoration as ExtendedProseMirrorDecoration).inline !== undefined &&
|
|
46
|
+
(decoration as ExtendedProseMirrorDecoration).widget !== undefined &&
|
|
47
|
+
(decoration as ExtendedProseMirrorDecoration).type !== undefined
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getHTMLElement = (
|
|
52
|
+
toDOM: WidgetConstructor | undefined,
|
|
53
|
+
view: EditorView,
|
|
54
|
+
getPos: () => number | undefined,
|
|
55
|
+
): HTMLElement | undefined => {
|
|
56
|
+
if (toDOM instanceof Function) {
|
|
57
|
+
const element = toDOM(view, getPos);
|
|
58
|
+
return element instanceof HTMLElement ? element : undefined;
|
|
59
|
+
} else if (toDOM instanceof HTMLElement) {
|
|
60
|
+
return toDOM;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const mapPMDecorationToCMDecoration = (
|
|
65
|
+
decoration: Decoration,
|
|
66
|
+
view: EditorView,
|
|
67
|
+
getPos: () => number | undefined,
|
|
68
|
+
) => {
|
|
69
|
+
if (!isExtendedDecoration(decoration)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
if (decoration.inline) {
|
|
73
|
+
const markDecoration = CodeMirrorDecoration.mark({
|
|
74
|
+
attributes: decoration.type.attrs,
|
|
75
|
+
});
|
|
76
|
+
return markDecoration.range(decoration.from, decoration.to);
|
|
77
|
+
} else if (decoration.widget) {
|
|
78
|
+
const toDOM = getHTMLElement(decoration?.type?.toDOM, view, getPos);
|
|
79
|
+
if (!toDOM) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const widgetDecoration = CodeMirrorDecoration.widget({
|
|
84
|
+
widget: new PMWidget(toDOM),
|
|
85
|
+
side: decoration.type.side,
|
|
86
|
+
});
|
|
87
|
+
return widgetDecoration.range(decoration.from, decoration.to);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function isDefined<TValue>(value: TValue | undefined): value is TValue {
|
|
92
|
+
return value !== undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Creates CodeMirror versions of the decorations provided by ProseMirror.
|
|
97
|
+
*
|
|
98
|
+
* Inline ProseMirror decorations -> Mark CodeMirror decorations
|
|
99
|
+
* Widget ProseMirror decorations -> Widget CodeMirror decorations
|
|
100
|
+
*
|
|
101
|
+
* This way any decorations applied in ProseMirror land should automatically be supported
|
|
102
|
+
* by the CodeMirror editor
|
|
103
|
+
*
|
|
104
|
+
* @param updateDecorationsEffect Facet for the prosemirror decorations
|
|
105
|
+
* @returns CodeMirror extension
|
|
106
|
+
*/
|
|
107
|
+
export const prosemirrorDecorationPlugin = (
|
|
108
|
+
updateDecorationsEffect: Facet<DecorationSource>,
|
|
109
|
+
editorView: EditorView,
|
|
110
|
+
getPos: () => number | undefined,
|
|
111
|
+
) =>
|
|
112
|
+
ViewPlugin.fromClass(
|
|
113
|
+
class {
|
|
114
|
+
decorations: DecorationSet;
|
|
115
|
+
|
|
116
|
+
constructor(view: CodeMirror) {
|
|
117
|
+
this.decorations = this.updateDecorations(view);
|
|
118
|
+
}
|
|
119
|
+
updateDecorations(view: CodeMirror) {
|
|
120
|
+
const { from, to } = view.viewport;
|
|
121
|
+
|
|
122
|
+
const innnerDecorations = view.state.facet(updateDecorationsEffect);
|
|
123
|
+
const allDecorations: Decoration[] = [];
|
|
124
|
+
innnerDecorations?.map((source) => {
|
|
125
|
+
source?.forEachSet((set) => {
|
|
126
|
+
const decorations = set
|
|
127
|
+
.find(from, to)
|
|
128
|
+
// Do not render the code block line decorations
|
|
129
|
+
.filter((dec) => dec.spec.type !== 'decorationWidgetType');
|
|
130
|
+
allDecorations.push(...decorations);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const cmDecorations = allDecorations
|
|
135
|
+
.sort((a, b) => (a.from < b.from ? -1 : 1))
|
|
136
|
+
.map((decoration) => mapPMDecorationToCMDecoration(decoration, editorView, getPos))
|
|
137
|
+
.filter(isDefined);
|
|
138
|
+
|
|
139
|
+
return CodeMirrorDecoration.set(cmDecorations);
|
|
140
|
+
}
|
|
141
|
+
update(update: ViewUpdate) {
|
|
142
|
+
this.decorations = this.updateDecorations(update.view);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
decorations: (v) => v.decorations,
|
|
147
|
+
},
|
|
148
|
+
);
|
package/src/ui/theme.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const cmTheme = CodeMirror.theme({
|
|
|
8
8
|
padding: '0',
|
|
9
9
|
marginTop: token('space.100'),
|
|
10
10
|
marginBottom: token('space.100'),
|
|
11
|
+
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
11
12
|
fontSize: '0.875rem',
|
|
12
13
|
// Custom syntax styling to match existing styling
|
|
13
14
|
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
@@ -35,6 +36,10 @@ export const cmTheme = CodeMirror.theme({
|
|
|
35
36
|
lineHeight: 'unset',
|
|
36
37
|
fontFamily: token('font.family.code'),
|
|
37
38
|
borderRadius: token('border.radius'),
|
|
39
|
+
backgroundImage: overflowShadow({
|
|
40
|
+
leftCoverWidth: token('space.300'),
|
|
41
|
+
}),
|
|
42
|
+
backgroundAttachment: 'local, local, local, local, scroll, scroll, scroll, scroll',
|
|
38
43
|
},
|
|
39
44
|
'&.cm-focused .cm-cursor': {
|
|
40
45
|
borderLeftColor: token('color.text'),
|
|
@@ -51,3 +56,62 @@ export const cmTheme = CodeMirror.theme({
|
|
|
51
56
|
minWidth: 'unset',
|
|
52
57
|
},
|
|
53
58
|
});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Copied directly from `packages/editor/editor-shared-styles/src/overflow-shadow/overflow-shadow.ts`
|
|
62
|
+
* `CodeMirror` does not support emotion styling so this has been re-created.
|
|
63
|
+
*/
|
|
64
|
+
function overflowShadow({
|
|
65
|
+
leftCoverWidth,
|
|
66
|
+
rightCoverWidth,
|
|
67
|
+
}: {
|
|
68
|
+
leftCoverWidth?: string;
|
|
69
|
+
rightCoverWidth?: string;
|
|
70
|
+
}) {
|
|
71
|
+
const width = token('space.100');
|
|
72
|
+
const leftCoverWidthResolved = leftCoverWidth || width;
|
|
73
|
+
const rightCoverWidthResolved = rightCoverWidth || width;
|
|
74
|
+
|
|
75
|
+
return `
|
|
76
|
+
linear-gradient(
|
|
77
|
+
to right,
|
|
78
|
+
${token('color.background.neutral')} ${leftCoverWidthResolved},
|
|
79
|
+
transparent ${leftCoverWidthResolved}
|
|
80
|
+
),
|
|
81
|
+
linear-gradient(
|
|
82
|
+
to right,
|
|
83
|
+
${token('elevation.surface.raised')} ${leftCoverWidthResolved},
|
|
84
|
+
transparent ${leftCoverWidthResolved}
|
|
85
|
+
),
|
|
86
|
+
linear-gradient(
|
|
87
|
+
to left,
|
|
88
|
+
${token('color.background.neutral')} ${rightCoverWidthResolved},
|
|
89
|
+
transparent ${rightCoverWidthResolved}
|
|
90
|
+
),
|
|
91
|
+
linear-gradient(
|
|
92
|
+
to left,
|
|
93
|
+
${token('elevation.surface.raised')} ${rightCoverWidthResolved},
|
|
94
|
+
transparent ${rightCoverWidthResolved}
|
|
95
|
+
),
|
|
96
|
+
linear-gradient(
|
|
97
|
+
to left,
|
|
98
|
+
${token('elevation.shadow.overflow.spread')} 0,
|
|
99
|
+
${token('utility.UNSAFE.transparent')} ${width}
|
|
100
|
+
),
|
|
101
|
+
linear-gradient(
|
|
102
|
+
to left,
|
|
103
|
+
${token('elevation.shadow.overflow.perimeter')} 0,
|
|
104
|
+
${token('utility.UNSAFE.transparent')} ${width}
|
|
105
|
+
),
|
|
106
|
+
linear-gradient(
|
|
107
|
+
to right,
|
|
108
|
+
${token('elevation.shadow.overflow.spread')} 0,
|
|
109
|
+
${token('utility.UNSAFE.transparent')} ${width}
|
|
110
|
+
),
|
|
111
|
+
linear-gradient(
|
|
112
|
+
to right,
|
|
113
|
+
${token('elevation.shadow.overflow.perimeter')} 0,
|
|
114
|
+
${token('utility.UNSAFE.transparent')} ${width}
|
|
115
|
+
)
|
|
116
|
+
`;
|
|
117
|
+
}
|
package/tsconfig.app.json
CHANGED
|
@@ -43,9 +43,15 @@
|
|
|
43
43
|
{
|
|
44
44
|
"path": "../editor-plugin-editor-disabled/tsconfig.app.json"
|
|
45
45
|
},
|
|
46
|
+
{
|
|
47
|
+
"path": "../editor-plugin-find-replace/tsconfig.app.json"
|
|
48
|
+
},
|
|
46
49
|
{
|
|
47
50
|
"path": "../editor-plugin-selection/tsconfig.app.json"
|
|
48
51
|
},
|
|
52
|
+
{
|
|
53
|
+
"path": "../editor-plugin-selection-marker/tsconfig.app.json"
|
|
54
|
+
},
|
|
49
55
|
{
|
|
50
56
|
"path": "../../design-system/tokens/tsconfig.app.json"
|
|
51
57
|
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.copyButtonDecorations = void 0;
|
|
7
|
-
var _state = require("@codemirror/state");
|
|
8
|
-
var _view = require("@codemirror/view");
|
|
9
|
-
var copyButtonDecorations = exports.copyButtonDecorations = _view.EditorView.decorations.compute([], function (state) {
|
|
10
|
-
var allTextDecoration = _view.Decoration.mark({
|
|
11
|
-
attributes: {
|
|
12
|
-
class: 'ProseMirror-fake-text-selection'
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
// Create a set of decorations for the entire document
|
|
16
|
-
var builder = new _state.RangeSetBuilder();
|
|
17
|
-
for (var i = 0; i < state.doc.lines; i++) {
|
|
18
|
-
builder.add(state.doc.line(i + 1).from, state.doc.line(i + 1).to, allTextDecoration);
|
|
19
|
-
}
|
|
20
|
-
var decorations = builder.finish();
|
|
21
|
-
return decorations;
|
|
22
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Code based on warning from @atlaskit/code
|
|
3
|
-
*/
|
|
4
|
-
import { EditorView as CodeMirror, ViewPlugin, Decoration, MatchDecorator, WidgetType } from '@codemirror/view';
|
|
5
|
-
const bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/gu;
|
|
6
|
-
const placeholderMatcher = new MatchDecorator({
|
|
7
|
-
regexp: bidiCharacterRegex,
|
|
8
|
-
decoration: match => Decoration.replace({
|
|
9
|
-
widget: new PlaceholderWidget(match[0])
|
|
10
|
-
})
|
|
11
|
-
});
|
|
12
|
-
export const bidiCharWarningExtension = ViewPlugin.fromClass(class {
|
|
13
|
-
constructor(view) {
|
|
14
|
-
this.placeholders = placeholderMatcher.createDeco(view);
|
|
15
|
-
}
|
|
16
|
-
update(update) {
|
|
17
|
-
this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders);
|
|
18
|
-
}
|
|
19
|
-
}, {
|
|
20
|
-
decorations: instance => instance.placeholders,
|
|
21
|
-
provide: plugin => CodeMirror.atomicRanges.of(view => {
|
|
22
|
-
var _view$plugin;
|
|
23
|
-
return ((_view$plugin = view.plugin(plugin)) === null || _view$plugin === void 0 ? void 0 : _view$plugin.placeholders) || Decoration.none;
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
function getBidiCharacterCode(bidiCharacter) {
|
|
27
|
-
var _bidiCharacter$codePo;
|
|
28
|
-
const bidiCharacterCode = (_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toString(16);
|
|
29
|
-
return `U+${bidiCharacterCode}`;
|
|
30
|
-
}
|
|
31
|
-
class PlaceholderWidget extends WidgetType {
|
|
32
|
-
constructor(name) {
|
|
33
|
-
super();
|
|
34
|
-
this.name = name;
|
|
35
|
-
}
|
|
36
|
-
eq(other) {
|
|
37
|
-
return this.name === other.name;
|
|
38
|
-
}
|
|
39
|
-
toDOM() {
|
|
40
|
-
const elt = document.createElement('span');
|
|
41
|
-
elt.setAttribute('data-bidi-character-code', this.name);
|
|
42
|
-
elt.style.cssText = `
|
|
43
|
-
padding: 0 3px;
|
|
44
|
-
color: ${"var(--ds-text-warning, #A54800)"};
|
|
45
|
-
background: ${"var(--ds-background-warning, #FFF7D6)"};
|
|
46
|
-
aria-hidden="true"`;
|
|
47
|
-
elt.textContent = `<${getBidiCharacterCode(this.name)}>`;
|
|
48
|
-
return elt;
|
|
49
|
-
}
|
|
50
|
-
ignoreEvent() {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { RangeSetBuilder } from '@codemirror/state';
|
|
2
|
-
import { EditorView as CodeMirror, Decoration } from '@codemirror/view';
|
|
3
|
-
export const copyButtonDecorations = CodeMirror.decorations.compute([], state => {
|
|
4
|
-
const allTextDecoration = Decoration.mark({
|
|
5
|
-
attributes: {
|
|
6
|
-
class: 'ProseMirror-fake-text-selection'
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
// Create a set of decorations for the entire document
|
|
10
|
-
const builder = new RangeSetBuilder();
|
|
11
|
-
for (let i = 0; i < state.doc.lines; i++) {
|
|
12
|
-
builder.add(state.doc.line(i + 1).from, state.doc.line(i + 1).to, allTextDecoration);
|
|
13
|
-
}
|
|
14
|
-
const decorations = builder.finish();
|
|
15
|
-
return decorations;
|
|
16
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
2
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
|
-
/**
|
|
9
|
-
* Code based on warning from @atlaskit/code
|
|
10
|
-
*/
|
|
11
|
-
import { EditorView as CodeMirror, ViewPlugin, Decoration, MatchDecorator, WidgetType } from '@codemirror/view';
|
|
12
|
-
var bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/g;
|
|
13
|
-
var placeholderMatcher = new MatchDecorator({
|
|
14
|
-
regexp: bidiCharacterRegex,
|
|
15
|
-
decoration: function decoration(match) {
|
|
16
|
-
return Decoration.replace({
|
|
17
|
-
widget: new PlaceholderWidget(match[0])
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
export var bidiCharWarningExtension = ViewPlugin.fromClass( /*#__PURE__*/function () {
|
|
22
|
-
function _class(view) {
|
|
23
|
-
_classCallCheck(this, _class);
|
|
24
|
-
this.placeholders = placeholderMatcher.createDeco(view);
|
|
25
|
-
}
|
|
26
|
-
return _createClass(_class, [{
|
|
27
|
-
key: "update",
|
|
28
|
-
value: function update(_update) {
|
|
29
|
-
this.placeholders = placeholderMatcher.updateDeco(_update, this.placeholders);
|
|
30
|
-
}
|
|
31
|
-
}]);
|
|
32
|
-
}(), {
|
|
33
|
-
decorations: function decorations(instance) {
|
|
34
|
-
return instance.placeholders;
|
|
35
|
-
},
|
|
36
|
-
provide: function provide(plugin) {
|
|
37
|
-
return CodeMirror.atomicRanges.of(function (view) {
|
|
38
|
-
var _view$plugin;
|
|
39
|
-
return ((_view$plugin = view.plugin(plugin)) === null || _view$plugin === void 0 ? void 0 : _view$plugin.placeholders) || Decoration.none;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
function getBidiCharacterCode(bidiCharacter) {
|
|
44
|
-
var _bidiCharacter$codePo;
|
|
45
|
-
var bidiCharacterCode = (_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toString(16);
|
|
46
|
-
return "U+".concat(bidiCharacterCode);
|
|
47
|
-
}
|
|
48
|
-
var PlaceholderWidget = /*#__PURE__*/function (_WidgetType) {
|
|
49
|
-
function PlaceholderWidget(name) {
|
|
50
|
-
var _this;
|
|
51
|
-
_classCallCheck(this, PlaceholderWidget);
|
|
52
|
-
_this = _callSuper(this, PlaceholderWidget);
|
|
53
|
-
_this.name = name;
|
|
54
|
-
return _this;
|
|
55
|
-
}
|
|
56
|
-
_inherits(PlaceholderWidget, _WidgetType);
|
|
57
|
-
return _createClass(PlaceholderWidget, [{
|
|
58
|
-
key: "eq",
|
|
59
|
-
value: function eq(other) {
|
|
60
|
-
return this.name === other.name;
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "toDOM",
|
|
64
|
-
value: function toDOM() {
|
|
65
|
-
var elt = document.createElement('span');
|
|
66
|
-
elt.setAttribute('data-bidi-character-code', this.name);
|
|
67
|
-
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\"");
|
|
68
|
-
elt.textContent = "<".concat(getBidiCharacterCode(this.name), ">");
|
|
69
|
-
return elt;
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "ignoreEvent",
|
|
73
|
-
value: function ignoreEvent() {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}]);
|
|
77
|
-
}(WidgetType);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { RangeSetBuilder } from '@codemirror/state';
|
|
2
|
-
import { EditorView as CodeMirror, Decoration } from '@codemirror/view';
|
|
3
|
-
export var copyButtonDecorations = CodeMirror.decorations.compute([], function (state) {
|
|
4
|
-
var allTextDecoration = Decoration.mark({
|
|
5
|
-
attributes: {
|
|
6
|
-
class: 'ProseMirror-fake-text-selection'
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
// Create a set of decorations for the entire document
|
|
10
|
-
var builder = new RangeSetBuilder();
|
|
11
|
-
for (var i = 0; i < state.doc.lines; i++) {
|
|
12
|
-
builder.add(state.doc.line(i + 1).from, state.doc.line(i + 1).to, allTextDecoration);
|
|
13
|
-
}
|
|
14
|
-
var decorations = builder.finish();
|
|
15
|
-
return decorations;
|
|
16
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const copyButtonDecorations: import("@codemirror/state").Extension;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const copyButtonDecorations: import("@codemirror/state").Extension;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Code based on warning from @atlaskit/code
|
|
3
|
-
*/
|
|
4
|
-
import {
|
|
5
|
-
EditorView as CodeMirror,
|
|
6
|
-
ViewPlugin,
|
|
7
|
-
ViewUpdate,
|
|
8
|
-
Decoration,
|
|
9
|
-
MatchDecorator,
|
|
10
|
-
DecorationSet,
|
|
11
|
-
WidgetType,
|
|
12
|
-
} from '@codemirror/view';
|
|
13
|
-
|
|
14
|
-
import { token } from '@atlaskit/tokens';
|
|
15
|
-
|
|
16
|
-
const bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/gu;
|
|
17
|
-
|
|
18
|
-
const placeholderMatcher = new MatchDecorator({
|
|
19
|
-
regexp: bidiCharacterRegex,
|
|
20
|
-
decoration: (match) =>
|
|
21
|
-
Decoration.replace({
|
|
22
|
-
widget: new PlaceholderWidget(match[0]),
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const bidiCharWarningExtension = ViewPlugin.fromClass(
|
|
27
|
-
class {
|
|
28
|
-
placeholders: DecorationSet;
|
|
29
|
-
constructor(view: CodeMirror) {
|
|
30
|
-
this.placeholders = placeholderMatcher.createDeco(view);
|
|
31
|
-
}
|
|
32
|
-
update(update: ViewUpdate) {
|
|
33
|
-
this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
decorations: (instance) => instance.placeholders,
|
|
38
|
-
provide: (plugin) =>
|
|
39
|
-
CodeMirror.atomicRanges.of((view) => {
|
|
40
|
-
return view.plugin(plugin)?.placeholders || Decoration.none;
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
function getBidiCharacterCode(bidiCharacter: string) {
|
|
46
|
-
const bidiCharacterCode = bidiCharacter.codePointAt(0)?.toString(16);
|
|
47
|
-
|
|
48
|
-
return `U+${bidiCharacterCode}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
class PlaceholderWidget extends WidgetType {
|
|
52
|
-
constructor(readonly name: string) {
|
|
53
|
-
super();
|
|
54
|
-
}
|
|
55
|
-
eq(other: PlaceholderWidget) {
|
|
56
|
-
return this.name === other.name;
|
|
57
|
-
}
|
|
58
|
-
toDOM() {
|
|
59
|
-
const elt = document.createElement('span');
|
|
60
|
-
elt.setAttribute('data-bidi-character-code', this.name);
|
|
61
|
-
elt.style.cssText = `
|
|
62
|
-
padding: 0 3px;
|
|
63
|
-
color: ${token('color.text.warning')};
|
|
64
|
-
background: ${token('color.background.warning')};
|
|
65
|
-
aria-hidden="true"`;
|
|
66
|
-
elt.textContent = `<${getBidiCharacterCode(this.name)}>`;
|
|
67
|
-
return elt;
|
|
68
|
-
}
|
|
69
|
-
ignoreEvent() {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RangeSetBuilder } from '@codemirror/state';
|
|
2
|
-
import { EditorView as CodeMirror, Decoration } from '@codemirror/view';
|
|
3
|
-
|
|
4
|
-
export const copyButtonDecorations = CodeMirror.decorations.compute([], (state) => {
|
|
5
|
-
const allTextDecoration = Decoration.mark({
|
|
6
|
-
attributes: { class: 'ProseMirror-fake-text-selection' },
|
|
7
|
-
});
|
|
8
|
-
// Create a set of decorations for the entire document
|
|
9
|
-
const builder = new RangeSetBuilder<Decoration>();
|
|
10
|
-
for (let i = 0; i < state.doc.lines; i++) {
|
|
11
|
-
builder.add(state.doc.line(i + 1).from, state.doc.line(i + 1).to, allTextDecoration);
|
|
12
|
-
}
|
|
13
|
-
const decorations = builder.finish();
|
|
14
|
-
return decorations;
|
|
15
|
-
});
|