@contentful/field-editor-markdown 2.3.3-canary.2 → 2.3.4-canary.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/MarkdownEditor.js +0 -14
- package/dist/cjs/components/MarkdownTextarea/CodeMirrorWrapper.js +1 -7
- package/dist/cjs/components/MarkdownTextarea/MarkdownCommands.js +4 -10
- package/dist/cjs/components/MarkdownTextarea/createMarkdownEditor.js +0 -4
- package/dist/cjs/components/MarkdownToolbar.js +2 -2
- package/dist/cjs/components/MarkdownToolbar.spec.js +0 -34
- package/dist/cjs/dialogs/ZenModeModalDialog.js +0 -12
- package/dist/esm/MarkdownEditor.js +0 -14
- package/dist/esm/components/MarkdownTextarea/CodeMirrorWrapper.js +1 -7
- package/dist/esm/components/MarkdownTextarea/MarkdownCommands.js +4 -10
- package/dist/esm/components/MarkdownTextarea/createMarkdownEditor.js +0 -4
- package/dist/esm/components/MarkdownToolbar.js +2 -2
- package/dist/esm/components/MarkdownToolbar.spec.js +0 -34
- package/dist/esm/dialogs/ZenModeModalDialog.js +0 -12
- package/dist/types/components/MarkdownTextarea/createMarkdownEditor.d.ts +0 -2
- package/dist/types/components/MarkdownToolbar.d.ts +0 -2
- package/package.json +3 -3
- package/dist/cjs/utils/indentation.js +0 -36
- package/dist/cjs/utils/isMarkdownListItem.js +0 -13
- package/dist/esm/utils/indentation.js +0 -12
- package/dist/esm/utils/isMarkdownListItem.js +0 -3
- package/dist/types/utils/indentation.d.ts +0 -4
- package/dist/types/utils/isMarkdownListItem.d.ts +0 -1
|
@@ -28,7 +28,6 @@ const _MarkdownTextarea = require("./components/MarkdownTextarea/MarkdownTextare
|
|
|
28
28
|
const _MarkdownToolbar = require("./components/MarkdownToolbar");
|
|
29
29
|
const _CheatsheetModalDialog = require("./dialogs/CheatsheetModalDialog");
|
|
30
30
|
const _MarkdownActions = require("./MarkdownActions");
|
|
31
|
-
const _indentation = require("./utils/indentation");
|
|
32
31
|
function _interop_require_default(obj) {
|
|
33
32
|
return obj && obj.__esModule ? obj : {
|
|
34
33
|
default: obj
|
|
@@ -89,8 +88,6 @@ function MarkdownEditor(props) {
|
|
|
89
88
|
const [selectedTab, setSelectedTab] = _react.useState('editor');
|
|
90
89
|
const [editor, setEditor] = _react.useState(null);
|
|
91
90
|
const [canUploadAssets, setCanUploadAssets] = _react.useState(false);
|
|
92
|
-
const [canIndentLine, setCanIndentLine] = _react.useState(false);
|
|
93
|
-
const [canDedentLine, setCanDedentLine] = _react.useState(false);
|
|
94
91
|
_react.useEffect(()=>{
|
|
95
92
|
if (props.enableTab) {
|
|
96
93
|
setSelectedTab(props.enableTab);
|
|
@@ -132,8 +129,6 @@ function MarkdownEditor(props) {
|
|
|
132
129
|
editor
|
|
133
130
|
]);
|
|
134
131
|
const isActionDisabled = editor === null || props.isDisabled || selectedTab !== 'editor';
|
|
135
|
-
const indentDisabled = isActionDisabled || !canIndentLine;
|
|
136
|
-
const dedentDisabled = isActionDisabled || !canDedentLine;
|
|
137
132
|
const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
|
|
138
133
|
const actions = _react.useMemo(()=>{
|
|
139
134
|
return (0, _MarkdownActions.createMarkdownActions)({
|
|
@@ -160,8 +155,6 @@ function MarkdownEditor(props) {
|
|
|
160
155
|
}), /*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, {
|
|
161
156
|
mode: "default",
|
|
162
157
|
disabled: isActionDisabled,
|
|
163
|
-
indentDisabled: indentDisabled,
|
|
164
|
-
dedentDisabled: dedentDisabled,
|
|
165
158
|
canUploadAssets: canUploadAssets,
|
|
166
159
|
actions: actions
|
|
167
160
|
}), /*#__PURE__*/ _react.createElement(_MarkdownTextarea.MarkdownTextarea, {
|
|
@@ -174,18 +167,11 @@ function MarkdownEditor(props) {
|
|
|
174
167
|
editor.setContent(props.value ?? '');
|
|
175
168
|
editor.setReadOnly(!!props.isDisabled);
|
|
176
169
|
setEditor(editor);
|
|
177
|
-
const syncIndentState = ()=>{
|
|
178
|
-
const line = editor.getCurrentLine();
|
|
179
|
-
setCanIndentLine((0, _indentation.canIndent)(line));
|
|
180
|
-
setCanDedentLine((0, _indentation.canDedent)(line));
|
|
181
|
-
};
|
|
182
170
|
editor.events.onChange((value)=>{
|
|
183
171
|
const trimmedValue = value.replace(/^\s+$/gm, '');
|
|
184
172
|
props.saveValueToSDK(trimmedValue);
|
|
185
173
|
setCurrentValue(value);
|
|
186
|
-
syncIndentState();
|
|
187
174
|
});
|
|
188
|
-
editor.events.onCursorActivity(syncIndentState);
|
|
189
175
|
}
|
|
190
176
|
}), selectedTab === 'preview' && /*#__PURE__*/ _react.createElement(_react.Suspense, {
|
|
191
177
|
fallback: /*#__PURE__*/ _react.createElement(_MarkdownPreviewSkeleton.default, null)
|
|
@@ -12,7 +12,6 @@ const _codemirror = /*#__PURE__*/ _interop_require_default(require("codemirror")
|
|
|
12
12
|
require("codemirror/addon/edit/matchbrackets");
|
|
13
13
|
const _throttle = /*#__PURE__*/ _interop_require_default(require("lodash/throttle"));
|
|
14
14
|
const _transform = /*#__PURE__*/ _interop_require_default(require("lodash/transform"));
|
|
15
|
-
const _indentation = require("../../utils/indentation");
|
|
16
15
|
const _userAgent = /*#__PURE__*/ _interop_require_wildcard(require("../../utils/userAgent"));
|
|
17
16
|
function _interop_require_default(obj) {
|
|
18
17
|
return obj && obj.__esModule ? obj : {
|
|
@@ -101,12 +100,7 @@ function create(host, options) {
|
|
|
101
100
|
}
|
|
102
101
|
cm.setOption('extraKeys', {
|
|
103
102
|
Tab: function() {
|
|
104
|
-
|
|
105
|
-
const line = cm.getLine(cursor.line);
|
|
106
|
-
const indentUnit = cm.getOption('indentUnit') ?? 2;
|
|
107
|
-
if (cursor.ch > (0, _indentation.getLeadingSpaces)(line) || (0, _indentation.canIndent)(line, indentUnit)) {
|
|
108
|
-
replaceSelectedText(getIndentation());
|
|
109
|
-
}
|
|
103
|
+
replaceSelectedText(getIndentation());
|
|
110
104
|
},
|
|
111
105
|
Enter: 'newlineAndIndentContinueMarkdownList',
|
|
112
106
|
Esc: ()=>{
|
|
@@ -13,7 +13,6 @@ const _min = /*#__PURE__*/ _interop_require_default(require("lodash/min"));
|
|
|
13
13
|
const _range = /*#__PURE__*/ _interop_require_default(require("lodash/range"));
|
|
14
14
|
const _times = /*#__PURE__*/ _interop_require_default(require("lodash/times"));
|
|
15
15
|
const _repeat = /*#__PURE__*/ _interop_require_default(require("lodash/repeat"));
|
|
16
|
-
const _indentation = require("../../utils/indentation");
|
|
17
16
|
function _interop_require_default(obj) {
|
|
18
17
|
return obj && obj.__esModule ? obj : {
|
|
19
18
|
default: obj
|
|
@@ -80,17 +79,12 @@ function create(editor) {
|
|
|
80
79
|
editor.insertAtCursor(markup);
|
|
81
80
|
}
|
|
82
81
|
function indent() {
|
|
83
|
-
|
|
84
|
-
const indentUnit = editor.getIndentation().length;
|
|
85
|
-
if ((0, _indentation.canIndent)(line, indentUnit)) {
|
|
86
|
-
editor.insertAtLineBeginning(editor.getIndentation());
|
|
87
|
-
}
|
|
82
|
+
editor.insertAtLineBeginning(editor.getIndentation());
|
|
88
83
|
}
|
|
89
84
|
function dedent() {
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
editor.removeFromLineBeginning(remove);
|
|
85
|
+
const indentation = editor.getIndentation();
|
|
86
|
+
if (editor.lineStartsWith(indentation)) {
|
|
87
|
+
editor.removeFromLineBeginning(indentation.length);
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
90
|
function table(config) {
|
|
@@ -77,15 +77,11 @@ function createMarkdownEditor(host, options) {
|
|
|
77
77
|
},
|
|
78
78
|
onPaste: function(fn) {
|
|
79
79
|
editor.attachEvent('paste', fn, 0);
|
|
80
|
-
},
|
|
81
|
-
onCursorActivity: function(fn) {
|
|
82
|
-
editor.attachEvent('cursorActivity', fn, 0);
|
|
83
80
|
}
|
|
84
81
|
},
|
|
85
82
|
insert: editor.insertAtCursor,
|
|
86
83
|
focus: editor.focus,
|
|
87
84
|
getContent: editor.getValue,
|
|
88
|
-
getCurrentLine: editor.getCurrentLine,
|
|
89
85
|
destroy: editor.destroy,
|
|
90
86
|
setContent: editor.setValue,
|
|
91
87
|
getSelectedText: editor.getSelectedText,
|
|
@@ -255,7 +255,7 @@ function AdditionalButtons(props) {
|
|
|
255
255
|
"aria-label": "Horizontal rule",
|
|
256
256
|
className: styles.icon
|
|
257
257
|
})), /*#__PURE__*/ _react.createElement(ToolbarButton, {
|
|
258
|
-
isDisabled: props.
|
|
258
|
+
isDisabled: props.disabled,
|
|
259
259
|
testId: "markdown-action-button-indent",
|
|
260
260
|
tooltip: "Increase indentation",
|
|
261
261
|
tooltipPlace: tooltipPlace,
|
|
@@ -264,7 +264,7 @@ function AdditionalButtons(props) {
|
|
|
264
264
|
"aria-label": "Increase indentation",
|
|
265
265
|
className: styles.icon
|
|
266
266
|
})), /*#__PURE__*/ _react.createElement(ToolbarButton, {
|
|
267
|
-
isDisabled: props.
|
|
267
|
+
isDisabled: props.disabled,
|
|
268
268
|
testId: "markdown-action-button-dedent",
|
|
269
269
|
tooltip: "Decrease indentation",
|
|
270
270
|
tooltipPlace: tooltipPlace,
|
|
@@ -59,8 +59,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
59
59
|
const createProps = ()=>({
|
|
60
60
|
canUploadAssets: true,
|
|
61
61
|
disabled: false,
|
|
62
|
-
indentDisabled: false,
|
|
63
|
-
dedentDisabled: false,
|
|
64
62
|
mode: 'default',
|
|
65
63
|
actions: {
|
|
66
64
|
headings: {
|
|
@@ -125,38 +123,6 @@ const createProps = ()=>({
|
|
|
125
123
|
name: 'Undo'
|
|
126
124
|
})).toBeInTheDocument();
|
|
127
125
|
});
|
|
128
|
-
(0, _vitest.it)('disables indent button when indent is unavailable', async ()=>{
|
|
129
|
-
const props = {
|
|
130
|
-
...createProps(),
|
|
131
|
-
indentDisabled: true
|
|
132
|
-
};
|
|
133
|
-
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
134
|
-
await _userevent.default.click(_react1.screen.getByRole('button', {
|
|
135
|
-
name: 'More actions'
|
|
136
|
-
}));
|
|
137
|
-
(0, _vitest.expect)(_react1.screen.getByRole('button', {
|
|
138
|
-
name: 'Increase indentation'
|
|
139
|
-
})).toBeDisabled();
|
|
140
|
-
(0, _vitest.expect)(_react1.screen.getByRole('button', {
|
|
141
|
-
name: 'Decrease indentation'
|
|
142
|
-
})).not.toBeDisabled();
|
|
143
|
-
});
|
|
144
|
-
(0, _vitest.it)('disables dedent button when dedent is unavailable', async ()=>{
|
|
145
|
-
const props = {
|
|
146
|
-
...createProps(),
|
|
147
|
-
dedentDisabled: true
|
|
148
|
-
};
|
|
149
|
-
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
150
|
-
await _userevent.default.click(_react1.screen.getByRole('button', {
|
|
151
|
-
name: 'More actions'
|
|
152
|
-
}));
|
|
153
|
-
(0, _vitest.expect)(_react1.screen.getByRole('button', {
|
|
154
|
-
name: 'Increase indentation'
|
|
155
|
-
})).not.toBeDisabled();
|
|
156
|
-
(0, _vitest.expect)(_react1.screen.getByRole('button', {
|
|
157
|
-
name: 'Decrease indentation'
|
|
158
|
-
})).toBeDisabled();
|
|
159
|
-
});
|
|
160
126
|
(0, _vitest.it)('triggers a toolbar action once per click', async ()=>{
|
|
161
127
|
const props = createProps();
|
|
162
128
|
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
@@ -28,7 +28,6 @@ const _MarkdownToolbar = require("../components/MarkdownToolbar");
|
|
|
28
28
|
const _CheatsheetModalDialog = require("../dialogs/CheatsheetModalDialog");
|
|
29
29
|
const _MarkdownActions = require("../MarkdownActions");
|
|
30
30
|
const _types = require("../types");
|
|
31
|
-
const _indentation = require("../utils/indentation");
|
|
32
31
|
function _interop_require_default(obj) {
|
|
33
32
|
return obj && obj.__esModule ? obj : {
|
|
34
33
|
default: obj
|
|
@@ -140,8 +139,6 @@ const ZenModeModalDialog = (props)=>{
|
|
|
140
139
|
const [currentValue, setCurrentValue] = _react.useState(props.initialValue ?? '');
|
|
141
140
|
const [showPreview, setShowPreview] = _react.useState(true);
|
|
142
141
|
const [editor, setEditor] = _react.useState(null);
|
|
143
|
-
const [canIndentLine, setCanIndentLine] = _react.useState(false);
|
|
144
|
-
const [canDedentLine, setCanDedentLine] = _react.useState(false);
|
|
145
142
|
_react.useEffect(()=>{
|
|
146
143
|
props.sdk?.window?.updateHeight('100%');
|
|
147
144
|
}, []);
|
|
@@ -177,8 +174,6 @@ const ZenModeModalDialog = (props)=>{
|
|
|
177
174
|
}, /*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, {
|
|
178
175
|
mode: "zen",
|
|
179
176
|
disabled: false,
|
|
180
|
-
indentDisabled: !canIndentLine,
|
|
181
|
-
dedentDisabled: !canDedentLine,
|
|
182
177
|
canUploadAssets: false,
|
|
183
178
|
actions: actions
|
|
184
179
|
})), /*#__PURE__*/ _react.createElement(_f36components.Grid.Item, {
|
|
@@ -195,17 +190,10 @@ const ZenModeModalDialog = (props)=>{
|
|
|
195
190
|
editor.setReadOnly(false);
|
|
196
191
|
setEditor(editor);
|
|
197
192
|
editor.focus();
|
|
198
|
-
const syncIndentState = ()=>{
|
|
199
|
-
const line = editor.getCurrentLine();
|
|
200
|
-
setCanIndentLine((0, _indentation.canIndent)(line));
|
|
201
|
-
setCanDedentLine((0, _indentation.canDedent)(line));
|
|
202
|
-
};
|
|
203
193
|
editor.events.onChange((value)=>{
|
|
204
194
|
setCurrentValue(value);
|
|
205
195
|
props.saveValueToSDK(value);
|
|
206
|
-
syncIndentState();
|
|
207
196
|
});
|
|
208
|
-
editor.events.onCursorActivity(syncIndentState);
|
|
209
197
|
}
|
|
210
198
|
})), showPreview && /*#__PURE__*/ _react.createElement(_f36components.Grid.Item, {
|
|
211
199
|
className: styles.previewSplit
|
|
@@ -10,7 +10,6 @@ import { MarkdownTextarea } from './components/MarkdownTextarea/MarkdownTextarea
|
|
|
10
10
|
import { MarkdownToolbar } from './components/MarkdownToolbar';
|
|
11
11
|
import { openCheatsheetModal } from './dialogs/CheatsheetModalDialog';
|
|
12
12
|
import { createMarkdownActions } from './MarkdownActions';
|
|
13
|
-
import { canIndent, canDedent } from './utils/indentation';
|
|
14
13
|
const MarkdownPreview = /*#__PURE__*/ React.lazy(()=>import('./components/MarkdownPreview'));
|
|
15
14
|
const styles = {
|
|
16
15
|
container: css({
|
|
@@ -25,8 +24,6 @@ export function MarkdownEditor(props) {
|
|
|
25
24
|
const [selectedTab, setSelectedTab] = React.useState('editor');
|
|
26
25
|
const [editor, setEditor] = React.useState(null);
|
|
27
26
|
const [canUploadAssets, setCanUploadAssets] = React.useState(false);
|
|
28
|
-
const [canIndentLine, setCanIndentLine] = React.useState(false);
|
|
29
|
-
const [canDedentLine, setCanDedentLine] = React.useState(false);
|
|
30
27
|
React.useEffect(()=>{
|
|
31
28
|
if (props.enableTab) {
|
|
32
29
|
setSelectedTab(props.enableTab);
|
|
@@ -68,8 +65,6 @@ export function MarkdownEditor(props) {
|
|
|
68
65
|
editor
|
|
69
66
|
]);
|
|
70
67
|
const isActionDisabled = editor === null || props.isDisabled || selectedTab !== 'editor';
|
|
71
|
-
const indentDisabled = isActionDisabled || !canIndentLine;
|
|
72
|
-
const dedentDisabled = isActionDisabled || !canDedentLine;
|
|
73
68
|
const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
|
|
74
69
|
const actions = React.useMemo(()=>{
|
|
75
70
|
return createMarkdownActions({
|
|
@@ -96,8 +91,6 @@ export function MarkdownEditor(props) {
|
|
|
96
91
|
}), /*#__PURE__*/ React.createElement(MarkdownToolbar, {
|
|
97
92
|
mode: "default",
|
|
98
93
|
disabled: isActionDisabled,
|
|
99
|
-
indentDisabled: indentDisabled,
|
|
100
|
-
dedentDisabled: dedentDisabled,
|
|
101
94
|
canUploadAssets: canUploadAssets,
|
|
102
95
|
actions: actions
|
|
103
96
|
}), /*#__PURE__*/ React.createElement(MarkdownTextarea, {
|
|
@@ -110,18 +103,11 @@ export function MarkdownEditor(props) {
|
|
|
110
103
|
editor.setContent(props.value ?? '');
|
|
111
104
|
editor.setReadOnly(!!props.isDisabled);
|
|
112
105
|
setEditor(editor);
|
|
113
|
-
const syncIndentState = ()=>{
|
|
114
|
-
const line = editor.getCurrentLine();
|
|
115
|
-
setCanIndentLine(canIndent(line));
|
|
116
|
-
setCanDedentLine(canDedent(line));
|
|
117
|
-
};
|
|
118
106
|
editor.events.onChange((value)=>{
|
|
119
107
|
const trimmedValue = value.replace(/^\s+$/gm, '');
|
|
120
108
|
props.saveValueToSDK(trimmedValue);
|
|
121
109
|
setCurrentValue(value);
|
|
122
|
-
syncIndentState();
|
|
123
110
|
});
|
|
124
|
-
editor.events.onCursorActivity(syncIndentState);
|
|
125
111
|
}
|
|
126
112
|
}), selectedTab === 'preview' && /*#__PURE__*/ React.createElement(React.Suspense, {
|
|
127
113
|
fallback: /*#__PURE__*/ React.createElement(MarkdownPreviewSkeleton, null)
|
|
@@ -2,7 +2,6 @@ import CodeMirror from 'codemirror';
|
|
|
2
2
|
import 'codemirror/addon/edit/matchbrackets';
|
|
3
3
|
import throttle from 'lodash/throttle';
|
|
4
4
|
import transform from 'lodash/transform';
|
|
5
|
-
import { canIndent, getLeadingSpaces } from '../../utils/indentation';
|
|
6
5
|
import * as userAgent from '../../utils/userAgent';
|
|
7
6
|
function stripUnit(value) {
|
|
8
7
|
if (typeof value !== 'string') return value;
|
|
@@ -45,12 +44,7 @@ export function create(host, options) {
|
|
|
45
44
|
}
|
|
46
45
|
cm.setOption('extraKeys', {
|
|
47
46
|
Tab: function() {
|
|
48
|
-
|
|
49
|
-
const line = cm.getLine(cursor.line);
|
|
50
|
-
const indentUnit = cm.getOption('indentUnit') ?? 2;
|
|
51
|
-
if (cursor.ch > getLeadingSpaces(line) || canIndent(line, indentUnit)) {
|
|
52
|
-
replaceSelectedText(getIndentation());
|
|
53
|
-
}
|
|
47
|
+
replaceSelectedText(getIndentation());
|
|
54
48
|
},
|
|
55
49
|
Enter: 'newlineAndIndentContinueMarkdownList',
|
|
56
50
|
Esc: ()=>{
|
|
@@ -3,7 +3,6 @@ import min from 'lodash/min';
|
|
|
3
3
|
import range from 'lodash/range';
|
|
4
4
|
import times from 'lodash/times';
|
|
5
5
|
import repeat from 'lodash/repeat';
|
|
6
|
-
import { canIndent, canDedent, getLeadingSpaces } from '../../utils/indentation';
|
|
7
6
|
function createPrefixToggleFn(prefix) {
|
|
8
7
|
return (editor)=>{
|
|
9
8
|
if (editor.lineStartsWith(prefix)) {
|
|
@@ -65,17 +64,12 @@ export function create(editor) {
|
|
|
65
64
|
editor.insertAtCursor(markup);
|
|
66
65
|
}
|
|
67
66
|
function indent() {
|
|
68
|
-
|
|
69
|
-
const indentUnit = editor.getIndentation().length;
|
|
70
|
-
if (canIndent(line, indentUnit)) {
|
|
71
|
-
editor.insertAtLineBeginning(editor.getIndentation());
|
|
72
|
-
}
|
|
67
|
+
editor.insertAtLineBeginning(editor.getIndentation());
|
|
73
68
|
}
|
|
74
69
|
function dedent() {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
editor.removeFromLineBeginning(remove);
|
|
70
|
+
const indentation = editor.getIndentation();
|
|
71
|
+
if (editor.lineStartsWith(indentation)) {
|
|
72
|
+
editor.removeFromLineBeginning(indentation.length);
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
function table(config) {
|
|
@@ -26,15 +26,11 @@ export function createMarkdownEditor(host, options) {
|
|
|
26
26
|
},
|
|
27
27
|
onPaste: function(fn) {
|
|
28
28
|
editor.attachEvent('paste', fn, 0);
|
|
29
|
-
},
|
|
30
|
-
onCursorActivity: function(fn) {
|
|
31
|
-
editor.attachEvent('cursorActivity', fn, 0);
|
|
32
29
|
}
|
|
33
30
|
},
|
|
34
31
|
insert: editor.insertAtCursor,
|
|
35
32
|
focus: editor.focus,
|
|
36
33
|
getContent: editor.getValue,
|
|
37
|
-
getCurrentLine: editor.getCurrentLine,
|
|
38
34
|
destroy: editor.destroy,
|
|
39
35
|
setContent: editor.setValue,
|
|
40
36
|
getSelectedText: editor.getSelectedText,
|
|
@@ -188,7 +188,7 @@ function AdditionalButtons(props) {
|
|
|
188
188
|
"aria-label": "Horizontal rule",
|
|
189
189
|
className: styles.icon
|
|
190
190
|
})), /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
191
|
-
isDisabled: props.
|
|
191
|
+
isDisabled: props.disabled,
|
|
192
192
|
testId: "markdown-action-button-indent",
|
|
193
193
|
tooltip: "Increase indentation",
|
|
194
194
|
tooltipPlace: tooltipPlace,
|
|
@@ -197,7 +197,7 @@ function AdditionalButtons(props) {
|
|
|
197
197
|
"aria-label": "Increase indentation",
|
|
198
198
|
className: styles.icon
|
|
199
199
|
})), /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
200
|
-
isDisabled: props.
|
|
200
|
+
isDisabled: props.disabled,
|
|
201
201
|
testId: "markdown-action-button-dedent",
|
|
202
202
|
tooltip: "Decrease indentation",
|
|
203
203
|
tooltipPlace: tooltipPlace,
|
|
@@ -9,8 +9,6 @@ configure({
|
|
|
9
9
|
const createProps = ()=>({
|
|
10
10
|
canUploadAssets: true,
|
|
11
11
|
disabled: false,
|
|
12
|
-
indentDisabled: false,
|
|
13
|
-
dedentDisabled: false,
|
|
14
12
|
mode: 'default',
|
|
15
13
|
actions: {
|
|
16
14
|
headings: {
|
|
@@ -75,38 +73,6 @@ describe('MarkdownToolbar', ()=>{
|
|
|
75
73
|
name: 'Undo'
|
|
76
74
|
})).toBeInTheDocument();
|
|
77
75
|
});
|
|
78
|
-
it('disables indent button when indent is unavailable', async ()=>{
|
|
79
|
-
const props = {
|
|
80
|
-
...createProps(),
|
|
81
|
-
indentDisabled: true
|
|
82
|
-
};
|
|
83
|
-
render(/*#__PURE__*/ React.createElement(MarkdownToolbar, props));
|
|
84
|
-
await userEvent.click(screen.getByRole('button', {
|
|
85
|
-
name: 'More actions'
|
|
86
|
-
}));
|
|
87
|
-
expect(screen.getByRole('button', {
|
|
88
|
-
name: 'Increase indentation'
|
|
89
|
-
})).toBeDisabled();
|
|
90
|
-
expect(screen.getByRole('button', {
|
|
91
|
-
name: 'Decrease indentation'
|
|
92
|
-
})).not.toBeDisabled();
|
|
93
|
-
});
|
|
94
|
-
it('disables dedent button when dedent is unavailable', async ()=>{
|
|
95
|
-
const props = {
|
|
96
|
-
...createProps(),
|
|
97
|
-
dedentDisabled: true
|
|
98
|
-
};
|
|
99
|
-
render(/*#__PURE__*/ React.createElement(MarkdownToolbar, props));
|
|
100
|
-
await userEvent.click(screen.getByRole('button', {
|
|
101
|
-
name: 'More actions'
|
|
102
|
-
}));
|
|
103
|
-
expect(screen.getByRole('button', {
|
|
104
|
-
name: 'Increase indentation'
|
|
105
|
-
})).not.toBeDisabled();
|
|
106
|
-
expect(screen.getByRole('button', {
|
|
107
|
-
name: 'Decrease indentation'
|
|
108
|
-
})).toBeDisabled();
|
|
109
|
-
});
|
|
110
76
|
it('triggers a toolbar action once per click', async ()=>{
|
|
111
77
|
const props = createProps();
|
|
112
78
|
render(/*#__PURE__*/ React.createElement(MarkdownToolbar, props));
|
|
@@ -10,7 +10,6 @@ import { MarkdownToolbar } from '../components/MarkdownToolbar';
|
|
|
10
10
|
import { openCheatsheetModal } from '../dialogs/CheatsheetModalDialog';
|
|
11
11
|
import { createMarkdownActions } from '../MarkdownActions';
|
|
12
12
|
import { MarkdownDialogType } from '../types';
|
|
13
|
-
import { canIndent, canDedent } from '../utils/indentation';
|
|
14
13
|
const MarkdownPreview = /*#__PURE__*/ React.lazy(()=>import('../components/MarkdownPreview'));
|
|
15
14
|
const styles = {
|
|
16
15
|
root: css({
|
|
@@ -76,8 +75,6 @@ export const ZenModeModalDialog = (props)=>{
|
|
|
76
75
|
const [currentValue, setCurrentValue] = React.useState(props.initialValue ?? '');
|
|
77
76
|
const [showPreview, setShowPreview] = React.useState(true);
|
|
78
77
|
const [editor, setEditor] = React.useState(null);
|
|
79
|
-
const [canIndentLine, setCanIndentLine] = React.useState(false);
|
|
80
|
-
const [canDedentLine, setCanDedentLine] = React.useState(false);
|
|
81
78
|
React.useEffect(()=>{
|
|
82
79
|
props.sdk?.window?.updateHeight('100%');
|
|
83
80
|
}, []);
|
|
@@ -113,8 +110,6 @@ export const ZenModeModalDialog = (props)=>{
|
|
|
113
110
|
}, /*#__PURE__*/ React.createElement(MarkdownToolbar, {
|
|
114
111
|
mode: "zen",
|
|
115
112
|
disabled: false,
|
|
116
|
-
indentDisabled: !canIndentLine,
|
|
117
|
-
dedentDisabled: !canDedentLine,
|
|
118
113
|
canUploadAssets: false,
|
|
119
114
|
actions: actions
|
|
120
115
|
})), /*#__PURE__*/ React.createElement(Grid.Item, {
|
|
@@ -131,17 +126,10 @@ export const ZenModeModalDialog = (props)=>{
|
|
|
131
126
|
editor.setReadOnly(false);
|
|
132
127
|
setEditor(editor);
|
|
133
128
|
editor.focus();
|
|
134
|
-
const syncIndentState = ()=>{
|
|
135
|
-
const line = editor.getCurrentLine();
|
|
136
|
-
setCanIndentLine(canIndent(line));
|
|
137
|
-
setCanDedentLine(canDedent(line));
|
|
138
|
-
};
|
|
139
129
|
editor.events.onChange((value)=>{
|
|
140
130
|
setCurrentValue(value);
|
|
141
131
|
props.saveValueToSDK(value);
|
|
142
|
-
syncIndentState();
|
|
143
132
|
});
|
|
144
|
-
editor.events.onCursorActivity(syncIndentState);
|
|
145
133
|
}
|
|
146
134
|
})), showPreview && /*#__PURE__*/ React.createElement(Grid.Item, {
|
|
147
135
|
className: styles.previewSplit
|
|
@@ -36,12 +36,10 @@ export declare function createMarkdownEditor(host: HTMLElement, options: {
|
|
|
36
36
|
onScroll: (fn: Function) => void;
|
|
37
37
|
onChange: (fn: Function) => void;
|
|
38
38
|
onPaste: (fn: Function) => void;
|
|
39
|
-
onCursorActivity: (fn: Function) => void;
|
|
40
39
|
};
|
|
41
40
|
insert: (text: string) => void;
|
|
42
41
|
focus: () => void;
|
|
43
42
|
getContent: () => string;
|
|
44
|
-
getCurrentLine: () => string;
|
|
45
43
|
destroy: () => void;
|
|
46
44
|
setContent: (value?: string | undefined) => void;
|
|
47
45
|
getSelectedText: () => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-markdown",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4-canary.3+ad149adb",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"remark-gfm": "^4.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@babel/core": "^7.
|
|
53
|
+
"@babel/core": "^7.29.7",
|
|
54
54
|
"@contentful/app-sdk": "^4.29.0",
|
|
55
55
|
"@contentful/field-editor-test-utils": "^3.1.2",
|
|
56
56
|
"@lingui/core": "5.3.0",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"registry": "https://npm.pkg.github.com/"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "ad149adb0b9c0fe493ae9301aaf0102fae470344"
|
|
69
69
|
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
MAX_PARAGRAPH_LEADING_SPACES: function() {
|
|
13
|
-
return MAX_PARAGRAPH_LEADING_SPACES;
|
|
14
|
-
},
|
|
15
|
-
canDedent: function() {
|
|
16
|
-
return canDedent;
|
|
17
|
-
},
|
|
18
|
-
canIndent: function() {
|
|
19
|
-
return canIndent;
|
|
20
|
-
},
|
|
21
|
-
getLeadingSpaces: function() {
|
|
22
|
-
return getLeadingSpaces;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const _isMarkdownListItem = require("./isMarkdownListItem");
|
|
26
|
-
const MAX_PARAGRAPH_LEADING_SPACES = 2;
|
|
27
|
-
function getLeadingSpaces(line) {
|
|
28
|
-
return line.match(/^ */)?.[0].length ?? 0;
|
|
29
|
-
}
|
|
30
|
-
function canIndent(line, indentUnit = 2) {
|
|
31
|
-
if ((0, _isMarkdownListItem.isMarkdownListItem)(line)) return true;
|
|
32
|
-
return getLeadingSpaces(line) + indentUnit <= MAX_PARAGRAPH_LEADING_SPACES;
|
|
33
|
-
}
|
|
34
|
-
function canDedent(line) {
|
|
35
|
-
return getLeadingSpaces(line) > 0;
|
|
36
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "isMarkdownListItem", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return isMarkdownListItem;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function isMarkdownListItem(line) {
|
|
12
|
-
return /^\s*(?:[-*+] |\d+[.)] )/.test(line);
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { isMarkdownListItem } from './isMarkdownListItem';
|
|
2
|
-
export const MAX_PARAGRAPH_LEADING_SPACES = 2;
|
|
3
|
-
export function getLeadingSpaces(line) {
|
|
4
|
-
return line.match(/^ */)?.[0].length ?? 0;
|
|
5
|
-
}
|
|
6
|
-
export function canIndent(line, indentUnit = 2) {
|
|
7
|
-
if (isMarkdownListItem(line)) return true;
|
|
8
|
-
return getLeadingSpaces(line) + indentUnit <= MAX_PARAGRAPH_LEADING_SPACES;
|
|
9
|
-
}
|
|
10
|
-
export function canDedent(line) {
|
|
11
|
-
return getLeadingSpaces(line) > 0;
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isMarkdownListItem(line: string): boolean;
|