@contentful/field-editor-markdown 1.1.8 → 1.1.10

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.
@@ -18,8 +18,8 @@ import min from 'lodash-es/min';
18
18
  import max from 'lodash-es/max';
19
19
  import times from 'lodash-es/times';
20
20
  import repeat from 'lodash-es/repeat';
21
- import Markdown from 'markdown-to-jsx';
22
21
  import DOMPurify from 'dompurify';
22
+ import Markdown from 'markdown-to-jsx';
23
23
  import inRange from 'lodash-es/inRange';
24
24
  import isObject from 'lodash-es/isObject';
25
25
  import extend from 'lodash-es/extend';
@@ -27,80 +27,6 @@ import isString from 'lodash-es/isString';
27
27
  import isFinite from 'lodash-es/isFinite';
28
28
  import forEach from 'lodash-es/forEach';
29
29
 
30
- var styles = {
31
- root: /*#__PURE__*/css({
32
- display: 'flex',
33
- zIndex: 10,
34
- flexDirection: 'row',
35
- justifyContent: 'flex-end',
36
- overflow: 'hidden',
37
- marginBottom: '-1px',
38
- fontSize: tokens.fontSizeM
39
- }),
40
- tab: /*#__PURE__*/css({
41
- cursor: 'pointer',
42
- color: tokens.gray700,
43
- padding: tokens.spacingXs,
44
- minWidth: '70px',
45
- border: "1px solid " + tokens.gray400,
46
- borderTopLeftRadius: tokens.borderRadiusSmall,
47
- borderTopRightRadius: tokens.borderRadiusSmall,
48
- marginLeft: tokens.spacingXs,
49
- textAlign: 'center',
50
- backgroundColor: tokens.gray100,
51
- borderBottomColor: tokens.gray100,
52
- outline: 'none',
53
- '&:focus': {
54
- boxShadow: tokens.boxShadowHeavy
55
- },
56
- transition: "all " + tokens.transitionEasingDefault + " " + tokens.transitionDurationShort
57
- }),
58
- inactiveTab: /*#__PURE__*/css({
59
- background: tokens.gray200,
60
- borderBottomColor: tokens.gray400,
61
- '&:hover': {
62
- background: tokens.gray300
63
- }
64
- })
65
- };
66
-
67
- function MarkdownTabItem(props) {
68
- var _cx;
69
-
70
- return React.createElement("div", {
71
- className: cx(styles.tab, (_cx = {}, _cx[styles.inactiveTab] = props.isActive === false, _cx)),
72
- onClick: function onClick() {
73
- props.onSelect(props.name);
74
- },
75
- onKeyDown: function onKeyDown(e) {
76
- if (e.keyCode === 13) {
77
- props.onSelect(props.name);
78
- }
79
- },
80
- tabIndex: 0,
81
- role: "tab",
82
- "aria-controls": props.name,
83
- "aria-selected": props.isActive === true,
84
- "data-test-id": props.testId
85
- }, props.children);
86
- }
87
-
88
- function MarkdownTabs(props) {
89
- return React.createElement("div", {
90
- className: styles.root
91
- }, React.createElement(MarkdownTabItem, {
92
- name: "editor",
93
- onSelect: props.onSelect,
94
- isActive: props.active === 'editor',
95
- testId: "markdown-tab-md"
96
- }, "Editor"), React.createElement(MarkdownTabItem, {
97
- name: "preview",
98
- onSelect: props.onSelect,
99
- isActive: props.active === 'preview',
100
- testId: "markdown-tab-preview"
101
- }, "Preview"));
102
- }
103
-
104
30
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
105
31
  try {
106
32
  var info = gen[key](arg);
@@ -179,6 +105,80 @@ function _taggedTemplateLiteralLoose(strings, raw) {
179
105
  return strings;
180
106
  }
181
107
 
108
+ var styles = {
109
+ root: /*#__PURE__*/css({
110
+ display: 'flex',
111
+ zIndex: 10,
112
+ flexDirection: 'row',
113
+ justifyContent: 'flex-end',
114
+ overflow: 'hidden',
115
+ marginBottom: '-1px',
116
+ fontSize: tokens.fontSizeM
117
+ }),
118
+ tab: /*#__PURE__*/css({
119
+ cursor: 'pointer',
120
+ color: tokens.gray700,
121
+ padding: tokens.spacingXs,
122
+ minWidth: '70px',
123
+ border: "1px solid " + tokens.gray400,
124
+ borderTopLeftRadius: tokens.borderRadiusSmall,
125
+ borderTopRightRadius: tokens.borderRadiusSmall,
126
+ marginLeft: tokens.spacingXs,
127
+ textAlign: 'center',
128
+ backgroundColor: tokens.gray100,
129
+ borderBottomColor: tokens.gray100,
130
+ outline: 'none',
131
+ '&:focus': {
132
+ boxShadow: tokens.boxShadowHeavy
133
+ },
134
+ transition: "all " + tokens.transitionEasingDefault + " " + tokens.transitionDurationShort
135
+ }),
136
+ inactiveTab: /*#__PURE__*/css({
137
+ background: tokens.gray200,
138
+ borderBottomColor: tokens.gray400,
139
+ '&:hover': {
140
+ background: tokens.gray300
141
+ }
142
+ })
143
+ };
144
+
145
+ function MarkdownTabItem(props) {
146
+ var _cx;
147
+
148
+ return React.createElement("div", {
149
+ className: cx(styles.tab, (_cx = {}, _cx[styles.inactiveTab] = props.isActive === false, _cx)),
150
+ onClick: function onClick() {
151
+ props.onSelect(props.name);
152
+ },
153
+ onKeyDown: function onKeyDown(e) {
154
+ if (e.keyCode === 13) {
155
+ props.onSelect(props.name);
156
+ }
157
+ },
158
+ tabIndex: 0,
159
+ role: "tab",
160
+ "aria-controls": props.name,
161
+ "aria-selected": props.isActive === true,
162
+ "data-test-id": props.testId
163
+ }, props.children);
164
+ }
165
+
166
+ function MarkdownTabs(props) {
167
+ return React.createElement("div", {
168
+ className: styles.root
169
+ }, React.createElement(MarkdownTabItem, {
170
+ name: "editor",
171
+ onSelect: props.onSelect,
172
+ isActive: props.active === 'editor',
173
+ testId: "markdown-tab-md"
174
+ }, "Editor"), React.createElement(MarkdownTabItem, {
175
+ name: "preview",
176
+ onSelect: props.onSelect,
177
+ isActive: props.active === 'preview',
178
+ testId: "markdown-tab-preview"
179
+ }, "Preview"));
180
+ }
181
+
182
182
  var _excluded = ["label"],
183
183
  _excluded2 = ["label"],
184
184
  _excluded3 = ["label"],
@@ -203,7 +203,7 @@ var Zen = function Zen(_ref) {
203
203
  var label = _ref.label,
204
204
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
205
205
 
206
- return React.createElement("svg", Object.assign({
206
+ return React.createElement("svg", _extends({
207
207
  width: 14,
208
208
  height: 14,
209
209
  viewBox: "0 0 1792 1792"
@@ -217,7 +217,7 @@ var Strikethrough = function Strikethrough(_ref2) {
217
217
  var label = _ref2.label,
218
218
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
219
219
 
220
- return React.createElement("svg", Object.assign({
220
+ return React.createElement("svg", _extends({
221
221
  width: 14,
222
222
  height: 14,
223
223
  viewBox: "0 0 1792 1792"
@@ -231,7 +231,7 @@ var Indent = function Indent(_ref3) {
231
231
  var label = _ref3.label,
232
232
  rest = _objectWithoutPropertiesLoose(_ref3, _excluded3);
233
233
 
234
- return React.createElement("svg", Object.assign({
234
+ return React.createElement("svg", _extends({
235
235
  width: 14,
236
236
  height: 14,
237
237
  viewBox: "0 0 1792 1792"
@@ -245,7 +245,7 @@ var Dedent = function Dedent(_ref4) {
245
245
  var label = _ref4.label,
246
246
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded4);
247
247
 
248
- return React.createElement("svg", Object.assign({
248
+ return React.createElement("svg", _extends({
249
249
  width: 14,
250
250
  height: 14,
251
251
  viewBox: "0 0 1792 1792"
@@ -259,7 +259,7 @@ var Cubes = function Cubes(_ref5) {
259
259
  var label = _ref5.label,
260
260
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded5);
261
261
 
262
- return React.createElement("svg", Object.assign({
262
+ return React.createElement("svg", _extends({
263
263
  width: 18,
264
264
  height: 14,
265
265
  viewBox: "0 0 2304 1792"
@@ -273,7 +273,7 @@ var Table = function Table(_ref6) {
273
273
  var label = _ref6.label,
274
274
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded6);
275
275
 
276
- return React.createElement("svg", Object.assign({
276
+ return React.createElement("svg", _extends({
277
277
  width: 14,
278
278
  height: 14,
279
279
  viewBox: "0 0 1792 1792"
@@ -287,7 +287,7 @@ var SpecialChar = function SpecialChar(_ref7) {
287
287
  var label = _ref7.label,
288
288
  rest = _objectWithoutPropertiesLoose(_ref7, _excluded7);
289
289
 
290
- return React.createElement("svg", Object.assign({
290
+ return React.createElement("svg", _extends({
291
291
  width: 14,
292
292
  height: 14,
293
293
  viewBox: "0 0 1792 1792"
@@ -301,7 +301,7 @@ var OrgLinks = function OrgLinks(_ref8) {
301
301
  var label = _ref8.label,
302
302
  rest = _objectWithoutPropertiesLoose(_ref8, _excluded8);
303
303
 
304
- return React.createElement("svg", Object.assign({
304
+ return React.createElement("svg", _extends({
305
305
  width: 14,
306
306
  height: 14,
307
307
  viewBox: "0 0 1792 1792"
@@ -315,7 +315,7 @@ var Undo = function Undo(_ref9) {
315
315
  var label = _ref9.label,
316
316
  rest = _objectWithoutPropertiesLoose(_ref9, _excluded9);
317
317
 
318
- return React.createElement("svg", Object.assign({
318
+ return React.createElement("svg", _extends({
319
319
  width: 14,
320
320
  height: 14,
321
321
  viewBox: "0 0 1792 1792"
@@ -329,7 +329,7 @@ var Redo = function Redo(_ref10) {
329
329
  var label = _ref10.label,
330
330
  rest = _objectWithoutPropertiesLoose(_ref10, _excluded10);
331
331
 
332
- return React.createElement("svg", Object.assign({
332
+ return React.createElement("svg", _extends({
333
333
  width: 14,
334
334
  height: 14,
335
335
  viewBox: "0 0 1792 1792"
@@ -365,7 +365,7 @@ var HeadingSelector = function HeadingSelector(props) {
365
365
 
366
366
  var InsertLinkSelector = function InsertLinkSelector(props) {
367
367
  if (props.canAddNew) {
368
- return React.createElement(MultipleMediaContextMenu, Object.assign({}, props));
368
+ return React.createElement(MultipleMediaContextMenu, _extends({}, props));
369
369
  } else {
370
370
  return React.createElement(Button, {
371
371
  isDisabled: props.disabled,
@@ -450,7 +450,7 @@ var ToolbarButton = /*#__PURE__*/React.forwardRef(function (props, ref) {
450
450
  className: styles$1.tooltip,
451
451
  placement: tooltipPlace,
452
452
  content: tooltip
453
- }, React.createElement(IconButton, Object.assign({}, otherProps, {
453
+ }, React.createElement(IconButton, _extends({}, otherProps, {
454
454
  ref: ref,
455
455
  className: cx(styles$1.button, className),
456
456
  isDisabled: isDisabled,
@@ -649,7 +649,7 @@ function DefaultMarkdownToolbar(props) {
649
649
  className: styles$1.root
650
650
  }, React.createElement(Flex, {
651
651
  justifyContent: "space-between"
652
- }, React.createElement(Flex, null, React.createElement(MainButtons, Object.assign({}, props)), React.createElement(ToolbarButton, {
652
+ }, React.createElement(Flex, null, React.createElement(MainButtons, _extends({}, props)), React.createElement(ToolbarButton, {
653
653
  isDisabled: props.disabled,
654
654
  testId: "markdown-action-button-toggle-additional",
655
655
  tooltip: showAdditional ? 'Hide additional actions' : 'More actions',
@@ -676,14 +676,14 @@ function DefaultMarkdownToolbar(props) {
676
676
  })))), showAdditional && React.createElement(Flex, {
677
677
  justifyContent: "space-between",
678
678
  marginTop: "spacingXs"
679
- }, React.createElement(Flex, null, React.createElement(AdditionalButtons, Object.assign({}, props)))));
679
+ }, React.createElement(Flex, null, React.createElement(AdditionalButtons, _extends({}, props)))));
680
680
  }
681
681
  function ZenMarkdownToolbar(props) {
682
682
  return React.createElement("div", {
683
683
  className: styles$1.root
684
684
  }, React.createElement(Flex, {
685
685
  justifyContent: "space-between"
686
- }, React.createElement(Flex, null, React.createElement(MainButtons, Object.assign({}, props)), React.createElement(AdditionalButtons, Object.assign({}, props))), React.createElement(Flex, null, React.createElement(InsertLinkSelector, {
686
+ }, React.createElement(Flex, null, React.createElement(MainButtons, _extends({}, props)), React.createElement(AdditionalButtons, _extends({}, props))), React.createElement(Flex, null, React.createElement(InsertLinkSelector, {
687
687
  disabled: props.disabled,
688
688
  onSelectExisting: props.actions.linkExistingMedia,
689
689
  onAddNew: props.actions.addNewMedia,
@@ -705,10 +705,10 @@ function ZenMarkdownToolbar(props) {
705
705
  }
706
706
  var MarkdownToolbar = /*#__PURE__*/React.memo(function (props) {
707
707
  if (props.mode === 'zen') {
708
- return React.createElement(ZenMarkdownToolbar, Object.assign({}, props));
708
+ return React.createElement(ZenMarkdownToolbar, _extends({}, props));
709
709
  }
710
710
 
711
- return React.createElement(DefaultMarkdownToolbar, Object.assign({}, props));
711
+ return React.createElement(DefaultMarkdownToolbar, _extends({}, props));
712
712
  });
713
713
  MarkdownToolbar.displayName = 'MarkdownToolbar';
714
714
 
@@ -1879,6 +1879,14 @@ var openCheatsheetModal = function openCheatsheetModal(dialogs) {
1879
1879
  });
1880
1880
  };
1881
1881
 
1882
+ // This code will replace '&' with '&' only inside the href attribute of the mailto link.
1883
+ // Otherwise the mailto link will not work correctly
1884
+ var replaceMailtoAmp = function replaceMailtoAmp(string) {
1885
+ return string.replace(/href="mailto:[^"]*&/g, function (match) {
1886
+ return match.replace(/&/g, '&');
1887
+ });
1888
+ };
1889
+
1882
1890
  var _excluded$2 = ["Embedly", "children"];
1883
1891
 
1884
1892
  var _templateObject$1;
@@ -1910,7 +1918,7 @@ function MarkdownLink(props) {
1910
1918
  });
1911
1919
  }
1912
1920
 
1913
- return React.createElement("a", Object.assign({}, rest, {
1921
+ return React.createElement("a", _extends({}, rest, {
1914
1922
  target: "_blank",
1915
1923
  rel: "noopener noreferrer"
1916
1924
  }), children);
@@ -1925,7 +1933,7 @@ var MarkdownPreview = /*#__PURE__*/React.memo(function (props) {
1925
1933
  // https://github.com/cure53/DOMPurify/blob/main/src/tags.js#L3-L121
1926
1934
 
1927
1935
  var cleanHTML = React.useMemo(function () {
1928
- return DOMPurify.sanitize(props.value);
1936
+ return replaceMailtoAmp(DOMPurify.sanitize(props.value));
1929
1937
  }, [props.value]);
1930
1938
  return React.createElement("div", {
1931
1939
  className: className,
@@ -2065,11 +2073,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
2065
2073
 
2066
2074
 
2067
2075
  var IteratorPrototype = {};
2068
-
2069
- IteratorPrototype[iteratorSymbol] = function () {
2076
+ define(IteratorPrototype, iteratorSymbol, function () {
2070
2077
  return this;
2071
- };
2072
-
2078
+ });
2073
2079
  var getProto = Object.getPrototypeOf;
2074
2080
  var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
2075
2081
 
@@ -2080,8 +2086,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
2080
2086
  }
2081
2087
 
2082
2088
  var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
2083
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
2084
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
2089
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
2090
+ define(Gp, "constructor", GeneratorFunctionPrototype);
2091
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
2085
2092
  GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
2086
2093
  // Iterator interface in terms of a single ._invoke method.
2087
2094
 
@@ -2186,11 +2193,9 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
2186
2193
  }
2187
2194
 
2188
2195
  defineIteratorMethods(AsyncIterator.prototype);
2189
-
2190
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
2196
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
2191
2197
  return this;
2192
- };
2193
-
2198
+ });
2194
2199
  exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
2195
2200
  // AsyncIterator objects; they just return a Promise for the value of
2196
2201
  // the final result produced by the iterator.
@@ -2367,13 +2372,12 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
2367
2372
  // object to not be returned from this call. This ensures that doesn't happen.
2368
2373
  // See https://github.com/facebook/regenerator/issues/274 for more details.
2369
2374
 
2370
- Gp[iteratorSymbol] = function () {
2375
+ define(Gp, iteratorSymbol, function () {
2371
2376
  return this;
2372
- };
2373
-
2374
- Gp.toString = function () {
2377
+ });
2378
+ define(Gp, "toString", function () {
2375
2379
  return "[object Generator]";
2376
- };
2380
+ });
2377
2381
 
2378
2382
  function pushTryEntry(locs) {
2379
2383
  var entry = {
@@ -2685,14 +2689,19 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
2685
2689
  } catch (accidentalStrictMode) {
2686
2690
  // This module should not be running in strict mode, so the above
2687
2691
  // assignment should always work unless something is misconfigured. Just
2688
- // in case runtime.js accidentally runs in strict mode, we can escape
2692
+ // in case runtime.js accidentally runs in strict mode, in modern engines
2693
+ // we can explicitly access globalThis. In older engines we can escape
2689
2694
  // strict mode using a global Function call. This could conceivably fail
2690
2695
  // if a Content Security Policy forbids using Function, but in that case
2691
2696
  // the proper solution is to fix the accidental strict mode problem. If
2692
2697
  // you've misconfigured your bundler to force strict mode and applied a
2693
2698
  // CSP to forbid Function, and you're not willing to fix either of those
2694
2699
  // problems, please detail your unique predicament in a GitHub issue.
2695
- Function("r", "regeneratorRuntime = r")(runtime);
2700
+ if (typeof globalThis === "object") {
2701
+ globalThis.regeneratorRuntime = runtime;
2702
+ } else {
2703
+ Function("r", "regeneratorRuntime = r")(runtime);
2704
+ }
2696
2705
  }
2697
2706
  });
2698
2707
 
@@ -4459,7 +4468,7 @@ function MarkdownEditorConnected(props) {
4459
4468
  setValue = _ref.setValue,
4460
4469
  externalReset = _ref.externalReset;
4461
4470
  // on external change reset component completely and init with initial value again
4462
- return React.createElement(MarkdownEditor, Object.assign({}, props, {
4471
+ return React.createElement(MarkdownEditor, _extends({}, props, {
4463
4472
  key: "markdown-editor-" + externalReset,
4464
4473
  initialValue: value,
4465
4474
  disabled: disabled,