@contentful/field-editor-markdown 2.3.3-canary.0 → 2.3.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.
@@ -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 _isMarkdownListItem = require("./utils/isMarkdownListItem");
32
31
  function _interop_require_default(obj) {
33
32
  return obj && obj.__esModule ? obj : {
34
33
  default: obj
@@ -89,7 +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 [isCurrentLineAListItem, setIsCurrentLineAListItem] = _react.useState(false);
93
91
  _react.useEffect(()=>{
94
92
  if (props.enableTab) {
95
93
  setSelectedTab(props.enableTab);
@@ -131,7 +129,6 @@ function MarkdownEditor(props) {
131
129
  editor
132
130
  ]);
133
131
  const isActionDisabled = editor === null || props.isDisabled || selectedTab !== 'editor';
134
- const isIndentationDisabled = isActionDisabled || !isCurrentLineAListItem;
135
132
  const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
136
133
  const actions = _react.useMemo(()=>{
137
134
  return (0, _MarkdownActions.createMarkdownActions)({
@@ -158,7 +155,6 @@ function MarkdownEditor(props) {
158
155
  }), /*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, {
159
156
  mode: "default",
160
157
  disabled: isActionDisabled,
161
- indentationDisabled: isIndentationDisabled,
162
158
  canUploadAssets: canUploadAssets,
163
159
  actions: actions
164
160
  }), /*#__PURE__*/ _react.createElement(_MarkdownTextarea.MarkdownTextarea, {
@@ -175,10 +171,6 @@ function MarkdownEditor(props) {
175
171
  const trimmedValue = value.replace(/^\s+$/gm, '');
176
172
  props.saveValueToSDK(trimmedValue);
177
173
  setCurrentValue(value);
178
- setIsCurrentLineAListItem((0, _isMarkdownListItem.isMarkdownListItem)(editor.getCurrentLine()));
179
- });
180
- editor.events.onCursorActivity(()=>{
181
- setIsCurrentLineAListItem((0, _isMarkdownListItem.isMarkdownListItem)(editor.getCurrentLine()));
182
174
  });
183
175
  }
184
176
  }), selectedTab === 'preview' && /*#__PURE__*/ _react.createElement(_react.Suspense, {
@@ -100,14 +100,7 @@ function create(host, options) {
100
100
  }
101
101
  cm.setOption('extraKeys', {
102
102
  Tab: function() {
103
- const line = cm.getLine(cm.getCursor().line);
104
- const leadingSpaces = (line.match(/^ */) ?? [
105
- ''
106
- ])[0].length;
107
- const indentUnit = cm.getOption('indentUnit') ?? 2;
108
- if (leadingSpaces + indentUnit <= 3) {
109
- replaceSelectedText(getIndentation());
110
- }
103
+ replaceSelectedText(getIndentation());
111
104
  },
112
105
  Enter: 'newlineAndIndentContinueMarkdownList',
113
106
  Esc: ()=>{
@@ -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.indentationDisabled,
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.indentationDisabled,
267
+ isDisabled: props.disabled,
268
268
  testId: "markdown-action-button-dedent",
269
269
  tooltip: "Decrease indentation",
270
270
  tooltipPlace: tooltipPlace,
@@ -59,7 +59,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
59
59
  const createProps = ()=>({
60
60
  canUploadAssets: true,
61
61
  disabled: false,
62
- indentationDisabled: false,
63
62
  mode: 'default',
64
63
  actions: {
65
64
  headings: {
@@ -124,22 +123,6 @@ const createProps = ()=>({
124
123
  name: 'Undo'
125
124
  })).toBeInTheDocument();
126
125
  });
127
- (0, _vitest.it)('disables indentation controls when indentation is unavailable', async ()=>{
128
- const props = {
129
- ...createProps(),
130
- indentationDisabled: true
131
- };
132
- (0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
133
- await _userevent.default.click(_react1.screen.getByRole('button', {
134
- name: 'More actions'
135
- }));
136
- (0, _vitest.expect)(_react1.screen.getByRole('button', {
137
- name: 'Increase indentation'
138
- })).toBeDisabled();
139
- (0, _vitest.expect)(_react1.screen.getByRole('button', {
140
- name: 'Decrease indentation'
141
- })).toBeDisabled();
142
- });
143
126
  (0, _vitest.it)('triggers a toolbar action once per click', async ()=>{
144
127
  const props = createProps();
145
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 _isMarkdownListItem = require("../utils/isMarkdownListItem");
32
31
  function _interop_require_default(obj) {
33
32
  return obj && obj.__esModule ? obj : {
34
33
  default: obj
@@ -140,7 +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 [isCurrentLineAListItem, setIsCurrentLineAListItem] = _react.useState(false);
144
142
  _react.useEffect(()=>{
145
143
  props.sdk?.window?.updateHeight('100%');
146
144
  }, []);
@@ -176,7 +174,6 @@ const ZenModeModalDialog = (props)=>{
176
174
  }, /*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, {
177
175
  mode: "zen",
178
176
  disabled: false,
179
- indentationDisabled: !isCurrentLineAListItem,
180
177
  canUploadAssets: false,
181
178
  actions: actions
182
179
  })), /*#__PURE__*/ _react.createElement(_f36components.Grid.Item, {
@@ -196,10 +193,6 @@ const ZenModeModalDialog = (props)=>{
196
193
  editor.events.onChange((value)=>{
197
194
  setCurrentValue(value);
198
195
  props.saveValueToSDK(value);
199
- setIsCurrentLineAListItem((0, _isMarkdownListItem.isMarkdownListItem)(editor.getCurrentLine()));
200
- });
201
- editor.events.onCursorActivity(()=>{
202
- setIsCurrentLineAListItem((0, _isMarkdownListItem.isMarkdownListItem)(editor.getCurrentLine()));
203
196
  });
204
197
  }
205
198
  })), showPreview && /*#__PURE__*/ _react.createElement(_f36components.Grid.Item, {
@@ -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 { isMarkdownListItem } from './utils/isMarkdownListItem';
14
13
  const MarkdownPreview = /*#__PURE__*/ React.lazy(()=>import('./components/MarkdownPreview'));
15
14
  const styles = {
16
15
  container: css({
@@ -25,7 +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 [isCurrentLineAListItem, setIsCurrentLineAListItem] = React.useState(false);
29
27
  React.useEffect(()=>{
30
28
  if (props.enableTab) {
31
29
  setSelectedTab(props.enableTab);
@@ -67,7 +65,6 @@ export function MarkdownEditor(props) {
67
65
  editor
68
66
  ]);
69
67
  const isActionDisabled = editor === null || props.isDisabled || selectedTab !== 'editor';
70
- const isIndentationDisabled = isActionDisabled || !isCurrentLineAListItem;
71
68
  const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
72
69
  const actions = React.useMemo(()=>{
73
70
  return createMarkdownActions({
@@ -94,7 +91,6 @@ export function MarkdownEditor(props) {
94
91
  }), /*#__PURE__*/ React.createElement(MarkdownToolbar, {
95
92
  mode: "default",
96
93
  disabled: isActionDisabled,
97
- indentationDisabled: isIndentationDisabled,
98
94
  canUploadAssets: canUploadAssets,
99
95
  actions: actions
100
96
  }), /*#__PURE__*/ React.createElement(MarkdownTextarea, {
@@ -111,10 +107,6 @@ export function MarkdownEditor(props) {
111
107
  const trimmedValue = value.replace(/^\s+$/gm, '');
112
108
  props.saveValueToSDK(trimmedValue);
113
109
  setCurrentValue(value);
114
- setIsCurrentLineAListItem(isMarkdownListItem(editor.getCurrentLine()));
115
- });
116
- editor.events.onCursorActivity(()=>{
117
- setIsCurrentLineAListItem(isMarkdownListItem(editor.getCurrentLine()));
118
110
  });
119
111
  }
120
112
  }), selectedTab === 'preview' && /*#__PURE__*/ React.createElement(React.Suspense, {
@@ -44,14 +44,7 @@ export function create(host, options) {
44
44
  }
45
45
  cm.setOption('extraKeys', {
46
46
  Tab: function() {
47
- const line = cm.getLine(cm.getCursor().line);
48
- const leadingSpaces = (line.match(/^ */) ?? [
49
- ''
50
- ])[0].length;
51
- const indentUnit = cm.getOption('indentUnit') ?? 2;
52
- if (leadingSpaces + indentUnit <= 3) {
53
- replaceSelectedText(getIndentation());
54
- }
47
+ replaceSelectedText(getIndentation());
55
48
  },
56
49
  Enter: 'newlineAndIndentContinueMarkdownList',
57
50
  Esc: ()=>{
@@ -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.indentationDisabled,
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.indentationDisabled,
200
+ isDisabled: props.disabled,
201
201
  testId: "markdown-action-button-dedent",
202
202
  tooltip: "Decrease indentation",
203
203
  tooltipPlace: tooltipPlace,
@@ -9,7 +9,6 @@ configure({
9
9
  const createProps = ()=>({
10
10
  canUploadAssets: true,
11
11
  disabled: false,
12
- indentationDisabled: false,
13
12
  mode: 'default',
14
13
  actions: {
15
14
  headings: {
@@ -74,22 +73,6 @@ describe('MarkdownToolbar', ()=>{
74
73
  name: 'Undo'
75
74
  })).toBeInTheDocument();
76
75
  });
77
- it('disables indentation controls when indentation is unavailable', async ()=>{
78
- const props = {
79
- ...createProps(),
80
- indentationDisabled: true
81
- };
82
- render(/*#__PURE__*/ React.createElement(MarkdownToolbar, props));
83
- await userEvent.click(screen.getByRole('button', {
84
- name: 'More actions'
85
- }));
86
- expect(screen.getByRole('button', {
87
- name: 'Increase indentation'
88
- })).toBeDisabled();
89
- expect(screen.getByRole('button', {
90
- name: 'Decrease indentation'
91
- })).toBeDisabled();
92
- });
93
76
  it('triggers a toolbar action once per click', async ()=>{
94
77
  const props = createProps();
95
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 { isMarkdownListItem } from '../utils/isMarkdownListItem';
14
13
  const MarkdownPreview = /*#__PURE__*/ React.lazy(()=>import('../components/MarkdownPreview'));
15
14
  const styles = {
16
15
  root: css({
@@ -76,7 +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 [isCurrentLineAListItem, setIsCurrentLineAListItem] = React.useState(false);
80
78
  React.useEffect(()=>{
81
79
  props.sdk?.window?.updateHeight('100%');
82
80
  }, []);
@@ -112,7 +110,6 @@ export const ZenModeModalDialog = (props)=>{
112
110
  }, /*#__PURE__*/ React.createElement(MarkdownToolbar, {
113
111
  mode: "zen",
114
112
  disabled: false,
115
- indentationDisabled: !isCurrentLineAListItem,
116
113
  canUploadAssets: false,
117
114
  actions: actions
118
115
  })), /*#__PURE__*/ React.createElement(Grid.Item, {
@@ -132,10 +129,6 @@ export const ZenModeModalDialog = (props)=>{
132
129
  editor.events.onChange((value)=>{
133
130
  setCurrentValue(value);
134
131
  props.saveValueToSDK(value);
135
- setIsCurrentLineAListItem(isMarkdownListItem(editor.getCurrentLine()));
136
- });
137
- editor.events.onCursorActivity(()=>{
138
- setIsCurrentLineAListItem(isMarkdownListItem(editor.getCurrentLine()));
139
132
  });
140
133
  }
141
134
  })), showPreview && /*#__PURE__*/ React.createElement(Grid.Item, {
@@ -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;
@@ -3,7 +3,6 @@ import { MarkdownActions } from '../types';
3
3
  interface MarkdownToolbarProps {
4
4
  canUploadAssets: boolean;
5
5
  disabled: boolean;
6
- indentationDisabled: boolean;
7
6
  actions: MarkdownActions;
8
7
  mode: 'default' | 'zen';
9
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-markdown",
3
- "version": "2.3.3-canary.0+cad01e3e",
3
+ "version": "2.3.3",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "registry": "https://npm.pkg.github.com/"
67
67
  },
68
- "gitHead": "cad01e3e96e743d140d9d5a949056f6a7a5a69db"
68
+ "gitHead": "a8ea42c6a81ba5b2d311c38275fbb8843d481e0b"
69
69
  }
@@ -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,3 +0,0 @@
1
- export function isMarkdownListItem(line) {
2
- return /^\s*(?:[-*+] |\d+[.)] )/.test(line);
3
- }
@@ -1 +0,0 @@
1
- export declare function isMarkdownListItem(line: string): boolean;