@contentful/field-editor-markdown 1.2.0 → 1.3.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.
Files changed (136) hide show
  1. package/dist/cjs/MarkdownActions.js +235 -0
  2. package/dist/cjs/MarkdownEditor.js +180 -0
  3. package/dist/cjs/__fixtures__/FakeSdk.js +183 -0
  4. package/dist/cjs/__fixtures__/asset/index.js +37 -0
  5. package/dist/cjs/__fixtures__/content-type/index.js +16 -0
  6. package/dist/cjs/__fixtures__/entry/index.js +33 -0
  7. package/dist/cjs/__fixtures__/fixtures.js +71 -0
  8. package/dist/cjs/__fixtures__/locale/index.js +40 -0
  9. package/dist/cjs/__fixtures__/space/index.js +16 -0
  10. package/dist/cjs/codemirrorImports.js +9 -0
  11. package/dist/cjs/components/HeadingSelector.js +66 -0
  12. package/dist/cjs/components/InsertLinkSelector.js +86 -0
  13. package/dist/cjs/components/MarkdownBottomBar.js +111 -0
  14. package/dist/cjs/components/MarkdownConstraints.js +79 -0
  15. package/dist/cjs/components/MarkdownPreview.js +249 -0
  16. package/dist/cjs/components/MarkdownTabs.js +128 -0
  17. package/dist/cjs/components/MarkdownTextarea/CodeMirrorWrapper.js +383 -0
  18. package/dist/cjs/components/MarkdownTextarea/MarkdownCommands.js +233 -0
  19. package/dist/cjs/components/MarkdownTextarea/MarkdownTextarea.js +190 -0
  20. package/dist/cjs/components/MarkdownTextarea/createMarkdownEditor.js +101 -0
  21. package/dist/cjs/components/MarkdownToolbar.js +367 -0
  22. package/dist/cjs/components/icons.js +193 -0
  23. package/dist/cjs/dialogs/CheatsheetModalDialog.js +239 -0
  24. package/dist/cjs/dialogs/ConfirmInsertAssetModalDialog.js +94 -0
  25. package/dist/cjs/dialogs/EmdebExternalContentDialog.js +202 -0
  26. package/dist/cjs/dialogs/InsertLinkModalDialog.js +149 -0
  27. package/dist/cjs/dialogs/InsertTableModalDialog.js +140 -0
  28. package/dist/cjs/dialogs/SpecialCharacterModalDialog.js +146 -0
  29. package/dist/cjs/dialogs/ZenModeModalDialog.js +257 -0
  30. package/dist/cjs/dialogs/openMarkdownDialog.js +121 -0
  31. package/dist/cjs/dialogs/renderMarkdownDialog.js +108 -0
  32. package/dist/cjs/index.js +29 -0
  33. package/dist/cjs/types.js +20 -0
  34. package/dist/cjs/utils/insertAssetLinks.js +122 -0
  35. package/dist/cjs/utils/insertAssetLinks.spec.js +22 -0
  36. package/dist/cjs/utils/isValidUrl.js +22 -0
  37. package/dist/cjs/utils/linkOrganizer.js +187 -0
  38. package/dist/cjs/utils/linkOrganizer.spec.js +96 -0
  39. package/dist/cjs/utils/replaceMailtoAmp.js +15 -0
  40. package/dist/cjs/utils/replaceMailtoAmp.spec.js +22 -0
  41. package/dist/cjs/utils/specialCharacters.js +228 -0
  42. package/dist/cjs/utils/userAgent.js +28 -0
  43. package/dist/esm/MarkdownActions.js +186 -0
  44. package/dist/esm/MarkdownEditor.js +118 -0
  45. package/dist/esm/__fixtures__/FakeSdk.js +173 -0
  46. package/dist/esm/__fixtures__/asset/index.js +6 -0
  47. package/dist/esm/__fixtures__/content-type/index.js +2 -0
  48. package/dist/esm/__fixtures__/entry/index.js +5 -0
  49. package/dist/esm/__fixtures__/fixtures.js +6 -0
  50. package/dist/esm/__fixtures__/locale/index.js +15 -0
  51. package/dist/esm/__fixtures__/space/index.js +2 -0
  52. package/dist/esm/codemirrorImports.js +5 -0
  53. package/dist/esm/components/HeadingSelector.js +17 -0
  54. package/dist/esm/components/InsertLinkSelector.js +37 -0
  55. package/dist/esm/components/MarkdownBottomBar.js +46 -0
  56. package/dist/esm/components/MarkdownConstraints.js +25 -0
  57. package/dist/esm/components/MarkdownPreview.js +195 -0
  58. package/dist/esm/components/MarkdownTabs.js +74 -0
  59. package/dist/esm/components/MarkdownTextarea/CodeMirrorWrapper.js +329 -0
  60. package/dist/esm/components/MarkdownTextarea/MarkdownCommands.js +218 -0
  61. package/dist/esm/components/MarkdownTextarea/MarkdownTextarea.js +136 -0
  62. package/dist/esm/components/MarkdownTextarea/createMarkdownEditor.js +52 -0
  63. package/dist/esm/components/MarkdownToolbar.js +302 -0
  64. package/dist/esm/components/icons.js +112 -0
  65. package/dist/esm/dialogs/CheatsheetModalDialog.js +177 -0
  66. package/dist/esm/dialogs/ConfirmInsertAssetModalDialog.js +37 -0
  67. package/dist/esm/dialogs/EmdebExternalContentDialog.js +140 -0
  68. package/dist/esm/dialogs/InsertLinkModalDialog.js +92 -0
  69. package/dist/esm/dialogs/InsertTableModalDialog.js +78 -0
  70. package/dist/esm/dialogs/SpecialCharacterModalDialog.js +84 -0
  71. package/dist/esm/dialogs/ZenModeModalDialog.js +195 -0
  72. package/dist/esm/dialogs/openMarkdownDialog.js +72 -0
  73. package/dist/esm/dialogs/renderMarkdownDialog.js +59 -0
  74. package/dist/esm/index.js +5 -0
  75. package/dist/esm/types.js +10 -0
  76. package/dist/esm/utils/insertAssetLinks.js +99 -0
  77. package/dist/esm/utils/insertAssetLinks.spec.js +18 -0
  78. package/dist/esm/utils/isValidUrl.js +4 -0
  79. package/dist/esm/utils/linkOrganizer.js +152 -0
  80. package/dist/esm/utils/linkOrganizer.spec.js +53 -0
  81. package/dist/esm/utils/replaceMailtoAmp.js +5 -0
  82. package/dist/esm/utils/replaceMailtoAmp.spec.js +18 -0
  83. package/dist/esm/utils/specialCharacters.js +218 -0
  84. package/dist/esm/utils/userAgent.js +13 -0
  85. package/dist/{MarkdownActions.d.ts → types/MarkdownActions.d.ts} +38 -38
  86. package/dist/{MarkdownEditor.d.ts → types/MarkdownEditor.d.ts} +22 -22
  87. package/dist/types/__fixtures__/FakeSdk.d.ts +8 -0
  88. package/dist/types/__fixtures__/asset/index.d.ts +6 -0
  89. package/dist/types/__fixtures__/content-type/index.d.ts +2 -0
  90. package/dist/types/__fixtures__/entry/index.d.ts +5 -0
  91. package/dist/types/__fixtures__/fixtures.d.ts +6 -0
  92. package/dist/types/__fixtures__/locale/index.d.ts +42 -0
  93. package/dist/types/__fixtures__/space/index.d.ts +2 -0
  94. package/dist/{codemirrorImports.d.ts → types/codemirrorImports.d.ts} +5 -5
  95. package/dist/{components → types/components}/HeadingSelector.d.ts +7 -7
  96. package/dist/{components → types/components}/InsertLinkSelector.d.ts +9 -9
  97. package/dist/{components → types/components}/MarkdownBottomBar.d.ts +11 -11
  98. package/dist/{components → types/components}/MarkdownConstraints.d.ts +6 -6
  99. package/dist/{components → types/components}/MarkdownPreview.d.ts +14 -14
  100. package/dist/{components → types/components}/MarkdownTabs.d.ts +8 -8
  101. package/dist/{components → types/components}/MarkdownTextarea/CodeMirrorWrapper.d.ts +58 -58
  102. package/dist/{components → types/components}/MarkdownTextarea/MarkdownCommands.d.ts +33 -33
  103. package/dist/{components → types/components}/MarkdownTextarea/MarkdownTextarea.d.ts +17 -17
  104. package/dist/{components → types/components}/MarkdownTextarea/createMarkdownEditor.d.ts +55 -55
  105. package/dist/{components → types/components}/MarkdownToolbar.d.ts +12 -12
  106. package/dist/types/components/icons.d.ts +18 -0
  107. package/dist/{dialogs → types/dialogs}/CheatsheetModalDialog.d.ts +4 -4
  108. package/dist/{dialogs → types/dialogs}/ConfirmInsertAssetModalDialog.d.ts +23 -23
  109. package/dist/{dialogs → types/dialogs}/EmdebExternalContentDialog.d.ts +9 -9
  110. package/dist/{dialogs → types/dialogs}/InsertLinkModalDialog.d.ts +17 -17
  111. package/dist/{dialogs → types/dialogs}/InsertTableModalDialog.d.ts +13 -13
  112. package/dist/{dialogs → types/dialogs}/SpecialCharacterModalDialog.d.ts +9 -9
  113. package/dist/{dialogs → types/dialogs}/ZenModeModalDialog.d.ts +24 -24
  114. package/dist/{dialogs → types/dialogs}/openMarkdownDialog.d.ts +5 -5
  115. package/dist/{dialogs → types/dialogs}/renderMarkdownDialog.d.ts +8 -8
  116. package/dist/{index.d.ts → types/index.d.ts} +5 -5
  117. package/dist/{types.d.ts → types/types.d.ts} +75 -75
  118. package/dist/{utils → types/utils}/insertAssetLinks.d.ts +29 -29
  119. package/dist/types/utils/insertAssetLinks.spec.d.ts +1 -0
  120. package/dist/{utils → types/utils}/isValidUrl.d.ts +2 -2
  121. package/dist/{utils → types/utils}/linkOrganizer.d.ts +6 -6
  122. package/dist/types/utils/linkOrganizer.spec.d.ts +1 -0
  123. package/dist/{utils → types/utils}/replaceMailtoAmp.d.ts +1 -1
  124. package/dist/types/utils/replaceMailtoAmp.spec.d.ts +1 -0
  125. package/dist/{utils → types/utils}/specialCharacters.d.ts +4 -4
  126. package/dist/{utils → types/utils}/userAgent.d.ts +1 -1
  127. package/package.json +25 -11
  128. package/CHANGELOG.md +0 -308
  129. package/dist/components/icons.d.ts +0 -18
  130. package/dist/field-editor-markdown.cjs.development.js +0 -3605
  131. package/dist/field-editor-markdown.cjs.development.js.map +0 -1
  132. package/dist/field-editor-markdown.cjs.production.min.js +0 -216
  133. package/dist/field-editor-markdown.cjs.production.min.js.map +0 -1
  134. package/dist/field-editor-markdown.esm.js +0 -3595
  135. package/dist/field-editor-markdown.esm.js.map +0 -1
  136. package/dist/index.js +0 -8
@@ -1,3595 +0,0 @@
1
- import 'codemirror/mode/markdown/markdown';
2
- import 'codemirror/mode/xml/xml';
3
- import 'codemirror/addon/edit/continuelist';
4
- import 'codemirror/addon/mode/overlay';
5
- import 'codemirror/addon/display/autorefresh';
6
- import React, { useRef, useState, useEffect } from 'react';
7
- import tokens from '@contentful/f36-tokens';
8
- import { ConstraintsUtils, CharCounter, CharValidation, FieldConnector, ModalDialogLauncher } from '@contentful/field-editor-shared';
9
- import { css, cx } from 'emotion';
10
- import { Paragraph, TextLink, Menu, Button, Tooltip, IconButton, Flex, ModalContent, Heading, EntityList, ModalControls, Form, FormControl, TextInput, Radio, Checkbox, Text } from '@contentful/f36-components';
11
- import DOMPurify from 'dompurify';
12
- import Markdown from 'markdown-to-jsx';
13
- import CodeMirror from 'codemirror';
14
- import 'codemirror/addon/edit/matchbrackets';
15
- import throttle from 'lodash-es/throttle';
16
- import transform from 'lodash-es/transform';
17
- import get from 'lodash-es/get';
18
- import max from 'lodash-es/max';
19
- import min from 'lodash-es/min';
20
- import range from 'lodash-es/range';
21
- import times from 'lodash-es/times';
22
- import repeat from 'lodash-es/repeat';
23
- import { AssetIcon, ChevronDownIcon, MoreHorizontalIcon, HeadingIcon, FormatBoldIcon, FormatItalicIcon, QuoteIcon, ListBulletedIcon, ListNumberedIcon, LinkIcon, CodeIcon, HorizontalRuleIcon, ChevronRightIcon, ChevronLeftIcon } from '@contentful/f36-icons';
24
- import inRange from 'lodash-es/inRange';
25
- import isObject from 'lodash-es/isObject';
26
- import extend from 'lodash-es/extend';
27
- import isString from 'lodash-es/isString';
28
- import isFinite from 'lodash-es/isFinite';
29
- import forEach from 'lodash-es/forEach';
30
-
31
- const styles = {
32
- root: /*#__PURE__*/css({
33
- display: 'flex',
34
- justifyContent: 'space-between',
35
- background: tokens.gray100,
36
- border: `1px solid ${tokens.gray400}`,
37
- borderBottomLeftRadius: tokens.borderRadiusSmall,
38
- borderBottomRightRadius: tokens.borderRadiusSmall,
39
- padding: `${tokens.spacingXs} ${tokens.spacingS}`
40
- }),
41
- help: /*#__PURE__*/css({
42
- color: tokens.gray700,
43
- fontSize: tokens.fontSizeS,
44
- button: {
45
- fontSize: tokens.fontSizeS,
46
- lineHeight: 'inherit'
47
- }
48
- })
49
- };
50
- function MarkdownHelp(props) {
51
- return React.createElement(Paragraph, {
52
- marginBottom: "none",
53
- className: styles.help
54
- }, "Format your text like a pro with the", ' ', React.createElement(TextLink, {
55
- as: "button",
56
- testId: "open-markdown-cheatsheet-button",
57
- onClick: () => {
58
- props.onClick();
59
- }
60
- }, "markdown cheatsheet"), ".");
61
- }
62
- function MarkdownBottomBar(props) {
63
- return React.createElement("div", {
64
- className: styles.root
65
- }, props.children);
66
- }
67
-
68
- const styles$1 = {
69
- root: /*#__PURE__*/css({
70
- display: 'flex',
71
- justifyContent: 'space-between',
72
- fontSize: tokens.fontSizeM,
73
- marginTop: tokens.spacingXs,
74
- color: tokens.gray700
75
- })
76
- };
77
- function MarkdownConstraints(props) {
78
- const constraints = ConstraintsUtils.fromFieldValidations(props.sdk.field.validations, props.sdk.field.type);
79
- const checkConstraint = ConstraintsUtils.makeChecker(constraints);
80
- return React.createElement("div", {
81
- className: styles$1.root
82
- }, React.createElement(CharCounter, {
83
- value: props.value,
84
- checkConstraint: checkConstraint
85
- }), React.createElement(CharValidation, {
86
- constraints: constraints
87
- }));
88
- }
89
-
90
- // This code will replace '&' with '&' only inside the href attribute of the mailto link.
91
- // Otherwise the mailto link will not work correctly
92
- const replaceMailtoAmp = string => {
93
- return string.replace(/href="mailto:[^"]*&/g, function (match) {
94
- return match.replace(/&/g, '&');
95
- });
96
- };
97
-
98
- const styles$2 = {
99
- root: css`
100
- border: 1px solid ${tokens.gray400};
101
- border-width: 0 1px;
102
- word-wrap: break-word;
103
- overflow-wrap: break-word;
104
- min-height: 300px;
105
- padding: ${tokens.spacingL};
106
- font-size: ${tokens.fontSizeM};
107
- font-family: ${tokens.fontStackPrimary};
108
- line-height: ${tokens.lineHeightDefault};
109
- color: ${tokens.gray700};
110
- white-space: pre-line;
111
-
112
- h1,
113
- h2,
114
- h3,
115
- h4,
116
- h5,
117
- h6 {
118
- margin-top: ${tokens.spacingL};
119
- margin-bottom: ${tokens.spacingM};
120
- color: ${tokens.gray900};
121
- }
122
-
123
- h1:first-child,
124
- h2:first-child,
125
- h3:first-child,
126
- h4:first-child,
127
- h5:first-child,
128
- h6:first-child {
129
- margin-top: 0;
130
- }
131
-
132
- h1 {
133
- font-size: 1.9em;
134
- }
135
- h2 {
136
- font-size: 1.75em;
137
- }
138
- h3 {
139
- font-size: 1.6em;
140
- }
141
- h4 {
142
- font-size: 1.45em;
143
- }
144
- h5 {
145
- font-size: 1.3em;
146
- }
147
- h6 {
148
- font-size: 1.15em;
149
- }
150
-
151
- p {
152
- margin-top: 0;
153
- margin-bottom: ${tokens.spacingM};
154
- }
155
-
156
- ul,
157
- ol {
158
- margin: ${tokens.spacingS} 0;
159
- padding-left: ${tokens.spacingM};
160
- }
161
- ul > li {
162
- list-style-type: disc;
163
- margin-bottom: 0;
164
- }
165
-
166
- ol > li {
167
- list-style-type: decimal;
168
- margin-bottom: 0;
169
- }
170
-
171
- table {
172
- table-layout: fixed;
173
- border-right-width: 0;
174
- border-bottom-width: 0;
175
- width: 80%;
176
- margin: ${tokens.spacingM} auto;
177
- border-spacing: 0;
178
- border-collapse: collapse;
179
- border: 1px solid ${tokens.gray300};
180
- }
181
-
182
- table th,
183
- table td {
184
- padding: 5px;
185
- border-left-width: 0;
186
- border-top-width: 0;
187
- }
188
-
189
- table th {
190
- background: ${tokens.gray200};
191
- }
192
-
193
- table td {
194
- border: 1px solid ${tokens.gray300};
195
- }
196
-
197
- a {
198
- color: ${tokens.blue500};
199
- }
200
-
201
- hr {
202
- margin-top: ${tokens.spacingL};
203
- margin-bottom: ${tokens.spacingL};
204
- height: 1px;
205
- background-color: ${tokens.gray300};
206
- border: none;
207
- }
208
-
209
- blockquote {
210
- border-left: 4px solid ${tokens.gray200};
211
- padding-left: ${tokens.spacingL};
212
- margin: 0;
213
- margin-top: ${tokens.spacingM};
214
- font-style: italic;
215
- }
216
-
217
- img {
218
- margin: ${tokens.spacingM} auto;
219
- display: block;
220
- max-width: 80%;
221
- max-height: 250px;
222
- }
223
-
224
- pre code {
225
- font-size: ${tokens.fontSizeS};
226
- font-family: ${tokens.fontStackMonospace};
227
- }
228
-
229
- .embedly-card {
230
- margin: ${tokens.spacingM} auto;
231
- display: block;
232
- }
233
- `,
234
- framed: /*#__PURE__*/css({
235
- height: '100%',
236
- maxHeight: '500px',
237
- overflowY: 'auto'
238
- }),
239
- zen: /*#__PURE__*/css({
240
- maxWidth: '650px',
241
- margin: '0 auto',
242
- border: 'none !important'
243
- }),
244
- rtl: /*#__PURE__*/css({
245
- direction: 'rtl'
246
- })
247
- };
248
-
249
- function MarkdownLink(props) {
250
- const {
251
- Embedly,
252
- children,
253
- ...rest
254
- } = props;
255
-
256
- if (props.className === 'embedly-card' && Embedly) {
257
- return React.createElement(Embedly, {
258
- url: props.href
259
- });
260
- }
261
-
262
- return React.createElement("a", { ...rest,
263
- target: "_blank",
264
- rel: "noopener noreferrer"
265
- }, children);
266
- }
267
-
268
- const MarkdownPreview = /*#__PURE__*/React.memo(props => {
269
- var _props$previewCompone;
270
-
271
- const className = cx(styles$2.root, props.minHeight !== undefined ? css({
272
- minHeight: props.minHeight
273
- }) : undefined, props.mode === 'default' ? styles$2.framed : styles$2.zen, props.direction === 'rtl' ? styles$2.rtl : undefined); // See the list of allowed Tags here:
274
- // https://github.com/cure53/DOMPurify/blob/main/src/tags.js#L3-L121
275
-
276
- const cleanHTML = React.useMemo(() => {
277
- return replaceMailtoAmp(DOMPurify.sanitize(props.value));
278
- }, [props.value]);
279
- return React.createElement("div", {
280
- className: className,
281
- "data-test-id": "markdown-preview"
282
- }, React.createElement(Markdown, {
283
- options: {
284
- overrides: {
285
- a: {
286
- // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
287
- component: MarkdownLink,
288
- props: {
289
- Embedly: (_props$previewCompone = props.previewComponents) == null ? void 0 : _props$previewCompone.embedly
290
- }
291
- }
292
- }
293
- }
294
- }, cleanHTML));
295
- });
296
- MarkdownPreview.displayName = 'MarkdownPreview';
297
-
298
- const styles$3 = {
299
- root: /*#__PURE__*/css({
300
- display: 'flex',
301
- zIndex: 10,
302
- flexDirection: 'row',
303
- justifyContent: 'flex-end',
304
- overflow: 'hidden',
305
- marginBottom: '-1px',
306
- fontSize: tokens.fontSizeM
307
- }),
308
- tab: /*#__PURE__*/css({
309
- cursor: 'pointer',
310
- color: tokens.gray700,
311
- padding: tokens.spacingXs,
312
- minWidth: '70px',
313
- border: `1px solid ${tokens.gray400}`,
314
- borderTopLeftRadius: tokens.borderRadiusSmall,
315
- borderTopRightRadius: tokens.borderRadiusSmall,
316
- marginLeft: tokens.spacingXs,
317
- textAlign: 'center',
318
- backgroundColor: tokens.gray100,
319
- borderBottomColor: tokens.gray100,
320
- outline: 'none',
321
- '&:focus': {
322
- boxShadow: tokens.boxShadowHeavy
323
- },
324
- transition: `all ${tokens.transitionEasingDefault} ${tokens.transitionDurationShort}`
325
- }),
326
- inactiveTab: /*#__PURE__*/css({
327
- background: tokens.gray200,
328
- borderBottomColor: tokens.gray400,
329
- '&:hover': {
330
- background: tokens.gray300
331
- }
332
- })
333
- };
334
-
335
- function MarkdownTabItem(props) {
336
- return React.createElement("div", {
337
- className: cx(styles$3.tab, {
338
- [styles$3.inactiveTab]: props.isActive === false
339
- }),
340
- onClick: () => {
341
- props.onSelect(props.name);
342
- },
343
- onKeyDown: e => {
344
- if (e.keyCode === 13) {
345
- props.onSelect(props.name);
346
- }
347
- },
348
- tabIndex: 0,
349
- role: "tab",
350
- "aria-controls": props.name,
351
- "aria-selected": props.isActive === true,
352
- "data-test-id": props.testId
353
- }, props.children);
354
- }
355
-
356
- function MarkdownTabs(props) {
357
- return React.createElement("div", {
358
- className: styles$3.root
359
- }, React.createElement(MarkdownTabItem, {
360
- name: "editor",
361
- onSelect: props.onSelect,
362
- isActive: props.active === 'editor',
363
- testId: "markdown-tab-md"
364
- }, "Editor"), React.createElement(MarkdownTabItem, {
365
- name: "preview",
366
- onSelect: props.onSelect,
367
- isActive: props.active === 'preview',
368
- testId: "markdown-tab-preview"
369
- }, "Preview"));
370
- }
371
-
372
- const userAgent = /*#__PURE__*/get(window, 'navigator.userAgent', '');
373
- const platform = /*#__PURE__*/get(window, 'navigator.platform', '');
374
- let ctrlKey = 'Ctrl';
375
- const tests = {
376
- // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/ban-ts-comment
377
- // @ts-ignore ignore missing MSStream
378
- ios: /*#__PURE__*/ /(iphone os|ipad|iphone|ipod)/i.test(userAgent) && !window.MSStream
379
- };
380
-
381
- if (tests.ios || /mac(68k|ppc|intel)/i.test(platform)) {
382
- ctrlKey = 'Cmd';
383
- }
384
-
385
- function getCtrlKey() {
386
- return ctrlKey;
387
- }
388
-
389
- /* eslint-disable @typescript-eslint/no-use-before-define, @typescript-eslint/no-explicit-any */
390
-
391
- function stripUnit(value) {
392
- if (typeof value !== 'string') return value;
393
- const cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
394
- const matchedValue = value.match(cssRegex);
395
-
396
- if (!matchedValue) {
397
- throw new Error("Couldn't match unit in given string");
398
- }
399
-
400
- return parseFloat(value);
401
- }
402
-
403
- function create(host, options) {
404
- const {
405
- direction,
406
- fixedHeight,
407
- height,
408
- readOnly
409
- } = options || {}; // Set to true if `setValue()` has been called. This is to prevent
410
- // undoing the initial content.
411
-
412
- let initializedWithValue = false;
413
- const LF = '\n';
414
- const EDITOR_SIZE = {
415
- min: height ? stripUnit(height) : 300,
416
- max: 500,
417
- shift: 50
418
- };
419
- const cm = CodeMirror(host, {
420
- direction,
421
- readOnly,
422
- mode: 'markdown',
423
- lineNumbers: false,
424
- undoDepth: 200,
425
- matchBrackets: true,
426
- lineWrapping: true,
427
- // When `lineSeparator === null` the document will be split
428
- // on CRLFs as well as lone CRs and LFs. A single LF will
429
- // be used as line separator in all output
430
- lineSeparator: null,
431
- theme: 'elegant',
432
- tabSize: 2,
433
- indentWithTabs: false,
434
- indentUnit: 2,
435
- autoRefresh: true,
436
- spellcheck: true,
437
- inputStyle: 'contenteditable'
438
- });
439
- cm.setSize('100%', EDITOR_SIZE.min);
440
-
441
- if (!fixedHeight) {
442
- cm.on('change', throttle(assureHeight, 150));
443
- }
444
-
445
- cm.setOption('extraKeys', {
446
- Tab: function () {
447
- replaceSelectedText(getIndentation());
448
- },
449
- Enter: 'newlineAndIndentContinueMarkdownList',
450
- Esc: () => {
451
- cm.getInputField().blur();
452
- }
453
- });
454
- /**
455
- * @description
456
- * Custom API for a CodeMirror instance.
457
- *
458
- * An instance wraps a CodeMirror instance and provides a custom interface
459
- * on top of CodeMirror.
460
- */
461
-
462
- return {
463
- destroy,
464
- disable,
465
- enable,
466
- attachEvent,
467
- addKeyShortcuts,
468
- setValue,
469
- cmd,
470
- moveToLineBeginning,
471
- moveIfNotEmpty,
472
- restoreCursor,
473
- moveToLineEnd,
474
- usePrimarySelection,
475
- focus,
476
- select,
477
- selectBackwards,
478
- selectAll: () => cm.execCommand('selectAll'),
479
- extendSelectionBy,
480
- insertAtCursor,
481
- insertAtLineBeginning,
482
- wrapSelection,
483
- removeFromLineBeginning,
484
- removeSelectedText,
485
- replaceSelectedText,
486
- getCursor,
487
- setCursor,
488
- getSelection,
489
- getLine,
490
- isLineEmpty,
491
- getSelectedText,
492
- getSelectionLength,
493
- getCurrentLine,
494
- getCurrentLineNumber,
495
- getCurrentCharacter,
496
- getCurrentLineLength,
497
- lineStartsWith,
498
- getIndentation,
499
- getNl,
500
- getValue,
501
- getLinesCount,
502
- getHistorySize,
503
- setReadOnly: value => cm.setOption('readOnly', value),
504
- getHistory: () => cm.getHistory(),
505
- setHistory: history => cm.setHistory(history),
506
- setFullsize: () => {
507
- cm.setSize('100%', '100%');
508
- cm.refresh();
509
- },
510
- refresh: () => cm.refresh()
511
- };
512
-
513
- function destroy() {
514
- // @ts-expect-error
515
- cm.toTextArea();
516
- }
517
-
518
- function disable() {
519
- cm.setOption('readOnly', 'nocursor');
520
- }
521
-
522
- function enable() {
523
- cm.setOption('readOnly', false);
524
- }
525
-
526
- function assureHeight() {
527
- const current = cm.heightAtLine(cm.lastLine(), 'local') + EDITOR_SIZE.shift;
528
- let next = current;
529
-
530
- if (current < EDITOR_SIZE.min) {
531
- next = EDITOR_SIZE.min;
532
- }
533
-
534
- if (current > EDITOR_SIZE.max) {
535
- next = EDITOR_SIZE.max;
536
- }
537
-
538
- cm.setSize('100%', next);
539
- }
540
-
541
- function attachEvent(name, fn, throttleInterval) {
542
- if (throttleInterval) {
543
- fn = throttle(fn, throttleInterval);
544
- }
545
-
546
- cm.on(name, fn);
547
- }
548
-
549
- function addKeyShortcuts(map) {
550
- const ctrlKey = getCtrlKey();
551
- cm.addKeyMap(transform(map, (acc, value, key) => {
552
- // eslint-disable-next-line -- TODO: describe this disable
553
- // @ts-ignore
554
- acc[ctrlKey + '-' + key] = value;
555
- }, {}));
556
- }
557
- /**
558
- * low-level editor manipulation functions
559
- */
560
-
561
- /**
562
- * @description
563
- * Sets the content of the editor while preserving the cursor
564
- * position.
565
- *
566
- * If called for the first time it will not record the change in
567
- * the history.
568
- */
569
-
570
-
571
- function setValue(value) {
572
- value = value || '';
573
-
574
- if (getValue() === value) {
575
- return;
576
- } // set value, but save cursor position first
577
- // position will be restored, but w/o focus (third arg)
578
-
579
-
580
- const line = getCurrentLineNumber();
581
- const ch = getCurrentCharacter();
582
- cm.setValue(value);
583
- restoreCursor(ch, line, true); // We do not want to record the initial population in the
584
- // history. Otherwise it would always be possible to revert to
585
- // the empty string.
586
-
587
- if (!initializedWithValue) {
588
- cm.clearHistory();
589
- initializedWithValue = true;
590
- }
591
- }
592
-
593
- function cmd(name) {
594
- cm.execCommand(name);
595
- cm.focus();
596
- }
597
-
598
- function moveToLineBeginning(lineNumber) {
599
- cm.setCursor({
600
- line: defaultToCurrentLineNumber(lineNumber),
601
- ch: 0
602
- });
603
- cm.focus();
604
- }
605
- /**
606
- * @description
607
- * Insert a new line below the cursor and move to the beginning of
608
- * that line.
609
- *
610
- * Only do this if the editor has content and we are not already on
611
- * the last line.
612
- *
613
- * TODO rename this
614
- */
615
-
616
-
617
- function moveIfNotEmpty() {
618
- if (getCurrentLineLength() < 1) {
619
- return;
620
- }
621
-
622
- const next = getCurrentLineNumber() + 1;
623
-
624
- if (cm.lastLine() < next) {
625
- moveToLineEnd();
626
- insertAtCursor(getNl());
627
- }
628
-
629
- moveToLineBeginning(next);
630
- }
631
-
632
- function restoreCursor(character, lineNumber, noFocus) {
633
- cm.setCursor(defaultToCurrentLineNumber(lineNumber), character, {
634
- scroll: !noFocus
635
- });
636
-
637
- if (!noFocus) {
638
- cm.focus();
639
- }
640
- }
641
-
642
- function moveToLineEnd(lineNumber) {
643
- cm.setCursor({
644
- line: defaultToCurrentLineNumber(lineNumber),
645
- ch: getCurrentLineLength()
646
- });
647
- cm.focus();
648
- }
649
-
650
- function defaultToCurrentLineNumber(lineNumber) {
651
- if (lineNumber === 0 || lineNumber !== undefined && lineNumber > 0) {
652
- return lineNumber;
653
- }
654
-
655
- return getCurrentLineNumber();
656
- }
657
-
658
- function usePrimarySelection() {
659
- cmd('singleSelection');
660
- }
661
-
662
- function focus() {
663
- cm.focus();
664
- }
665
-
666
- function select(from, to) {
667
- cm.setSelection(from, to);
668
- cm.focus();
669
- }
670
-
671
- function selectBackwards(skip, len) {
672
- select(getPos(-skip - len), getPos(-skip));
673
-
674
- function getPos(modifier) {
675
- return {
676
- line: getCurrentLineNumber(),
677
- ch: getCurrentCharacter() + modifier
678
- };
679
- }
680
- }
681
-
682
- function extendSelectionBy(modifier) {
683
- select(getPos('anchor', 0), getPos('head', modifier));
684
-
685
- function getPos(prop, modifier) {
686
- const selection = getSelection();
687
-
688
- if (!selection) {
689
- return {
690
- line: 0,
691
- ch: 0
692
- };
693
- }
694
-
695
- return {
696
- line: selection[prop].line,
697
- ch: selection[prop].ch + modifier
698
- };
699
- }
700
- }
701
-
702
- function insertAtCursor(text) {
703
- cm.replaceRange(text, cm.getCursor());
704
- cm.focus();
705
- }
706
-
707
- function insertAtLineBeginning(text) {
708
- const initialCh = getCurrentCharacter();
709
- moveToLineBeginning();
710
- insertAtCursor(text);
711
- restoreCursor(initialCh + text.length);
712
- cm.focus();
713
- }
714
-
715
- function wrapSelection(wrapper) {
716
- const replacement = wrapper + getSelectedText() + wrapper;
717
- const selection = getSelection();
718
-
719
- if (selection) {
720
- cm.replaceRange(replacement, selection.anchor, selection == null ? void 0 : selection.head);
721
- cm.focus();
722
- }
723
- }
724
-
725
- function removeFromLineBeginning(charCount) {
726
- const lineNumber = getCurrentLineNumber();
727
- cm.replaceRange('', {
728
- line: lineNumber,
729
- ch: 0
730
- }, {
731
- line: lineNumber,
732
- ch: charCount
733
- });
734
- cm.focus();
735
- }
736
-
737
- function removeSelectedText() {
738
- cm.replaceSelection('');
739
- cm.focus();
740
- }
741
- /**
742
- * @description
743
- * Replace the selected text with the given string.
744
- *
745
- * If nothing is selected it will insert the text at the current
746
- * cursor position
747
- *
748
- * The optional `select` parameter controls what will be selected
749
- * afters wards. By default the cursor will be at the end of the
750
- * inserted text. You can pass 'around' to select the inserted
751
- * text.
752
- */
753
-
754
-
755
- function replaceSelectedText(replacement, select) {
756
- cm.replaceSelection(replacement, select);
757
- cm.focus();
758
- }
759
- /**
760
- * low-level editor get/check functions
761
- */
762
-
763
-
764
- function getCursor() {
765
- return cm.getCursor();
766
- }
767
-
768
- function setCursor(cursor) {
769
- cm.setCursor(cursor);
770
- }
771
-
772
- function getSelection() {
773
- const selections = cm.listSelections();
774
-
775
- if (!cm.somethingSelected() || !selections || selections.length < 1) {
776
- return null;
777
- }
778
-
779
- return selections[0];
780
- }
781
-
782
- function getLine(lineNumber) {
783
- return cm.getLine(lineNumber) || '';
784
- }
785
-
786
- function isLineEmpty(lineNumber) {
787
- const n = defaultToCurrentLineNumber(lineNumber);
788
- return n > -1 && getLine(n).length < 1 && n < cm.lineCount();
789
- }
790
-
791
- function getLinesCount() {
792
- return cm.lineCount();
793
- }
794
-
795
- function getSelectedText() {
796
- return getSelection() ? cm.getSelection() : '';
797
- }
798
-
799
- function getSelectionLength() {
800
- return getSelectedText().length;
801
- }
802
-
803
- function getCurrentLine() {
804
- return getLine(getCurrentLineNumber());
805
- }
806
-
807
- function getCurrentLineNumber() {
808
- return cm.getCursor().line;
809
- }
810
-
811
- function getCurrentCharacter() {
812
- return cm.getCursor().ch;
813
- }
814
-
815
- function getCurrentLineLength() {
816
- return getCurrentLine().length;
817
- }
818
-
819
- function lineStartsWith(text) {
820
- return getCurrentLine().startsWith(text);
821
- }
822
-
823
- function getIndentation() {
824
- return repeat(' ', cm.getOption('indentUnit') ?? 0);
825
- }
826
-
827
- function getNl(n = 1) {
828
- if (n < 1) {
829
- return '';
830
- }
831
-
832
- return repeat(LF, n);
833
- }
834
-
835
- function getValue() {
836
- return cm.getValue() || '';
837
- }
838
-
839
- function getHistorySize(which) {
840
- const history = cm.historySize();
841
- return which ? history[which] : history;
842
- }
843
-
844
- function repeat(what, n) {
845
- return new Array(n + 1).join(what);
846
- }
847
- }
848
-
849
- /* eslint-disable @typescript-eslint/no-use-before-define */
850
-
851
- function createPrefixToggleFn(prefix) {
852
- return editor => {
853
- if (editor.lineStartsWith(prefix)) {
854
- editor.removeFromLineBeginning(prefix.length);
855
- } else {
856
- editor.insertAtLineBeginning(prefix);
857
- }
858
- };
859
- }
860
- /**
861
- * Wraps the current selection with a marker.
862
- *
863
- * If nothing is selected it inserts the given text wrapped in the
864
- * marker and selects the inner text
865
- *
866
- * Used b the `bold`, `italic`, and `strike` commands.
867
- */
868
-
869
-
870
- function wrapSelection(editor, marker, emptyText) {
871
- return () => {
872
- editor.usePrimarySelection(); // there's a selection - wrap it with inline marker
873
-
874
- if (editor.getSelection()) {
875
- const selectedText = editor.getSelectedText();
876
-
877
- if (selectedText.startsWith(marker) && selectedText.endsWith(marker)) {
878
- const markerLength = marker.length;
879
- const textWithoutMarker = selectedText.slice(markerLength, selectedText.length - markerLength);
880
- editor.replaceSelectedText(textWithoutMarker);
881
- } else {
882
- editor.wrapSelection(marker);
883
- }
884
- } else {
885
- // no selection - insert sample text and select it
886
- editor.insertAtCursor(marker + emptyText + marker);
887
- editor.selectBackwards(marker.length, emptyText.length);
888
- }
889
- };
890
- }
891
-
892
- const HEADER_CHAR = '#';
893
- const quoteToggleFn = /*#__PURE__*/createPrefixToggleFn('> ');
894
- const codeToggleFn = /*#__PURE__*/createPrefixToggleFn(' ');
895
- /**
896
- * @description
897
- * A collection of commands used by the user bound to a
898
- * CodeMirrorWrapper instance.
899
- *
900
- * The command collection only depends on the wrapper instance and is
901
- * used by UI from code mirror stuff.
902
- */
903
-
904
- function create$1(editor) {
905
- return {
906
- bold: wrapSelection(editor, '__', 'text in bold'),
907
- italic: wrapSelection(editor, '*', 'text in italic'),
908
- strike: wrapSelection(editor, '~~', 'striked out'),
909
- quote: modifySelection(editor, quoteToggleFn),
910
- code: modifySelection(editor, codeToggleFn),
911
- link,
912
- h1: toggleHeader(editor, 1),
913
- h2: toggleHeader(editor, 2),
914
- h3: toggleHeader(editor, 3),
915
- ul: modifySelection(editor, ulToggleFn, true),
916
- ol: modifySelection(editor, olToggleFn, true),
917
- undo: function () {
918
- editor.cmd('undo');
919
- },
920
- redo: function () {
921
- editor.cmd('redo');
922
- },
923
- hr,
924
- indent,
925
- dedent,
926
- table
927
- };
928
- /**
929
- * @description
930
- * Insert a line with `---` below the cursor.
931
- */
932
-
933
- function hr() {
934
- editor.moveIfNotEmpty();
935
- const nl = editor.getNl();
936
- const markup = nl + '---' + nl + nl;
937
- editor.insertAtCursor(markup);
938
- }
939
- /**
940
- * @description
941
- * Indent the current line.
942
- */
943
-
944
-
945
- function indent() {
946
- editor.insertAtLineBeginning(editor.getIndentation());
947
- }
948
- /**
949
- * @description
950
- * Dedent the current line.
951
- */
952
-
953
-
954
- function dedent() {
955
- const indentation = editor.getIndentation();
956
-
957
- if (editor.lineStartsWith(indentation)) {
958
- editor.removeFromLineBeginning(indentation.length);
959
- }
960
- }
961
- /**
962
- * @description
963
- * Insert a markdown table template in a new line.
964
- */
965
-
966
-
967
- function table(config) {
968
- const nl = editor.getNl();
969
- editor.moveIfNotEmpty();
970
- editor.insertAtCursor(nl);
971
- const line = editor.getCurrentLineNumber();
972
- editor.insertAtCursor(tableTemplate(config.rows, config.cols).join(nl));
973
- editor.insertAtCursor(nl + nl);
974
- editor.restoreCursor(2, line);
975
- }
976
- /**
977
- * @description
978
- * Inserts or replaces the current selection with a markdown link
979
- */
980
-
981
-
982
- function link(url, text, title) {
983
- editor.usePrimarySelection();
984
- const linkTitle = title ? ' "' + title + '"' : '';
985
- const link = text ? '[' + text + '](' + url + linkTitle + ')' : '<' + url + '>';
986
- editor.replaceSelectedText(link, 'around');
987
- }
988
- }
989
- /**
990
- * For each line in the selection move to that line and call
991
- * `toggleFn` with the 1-based index of the line in the selection.
992
- *
993
- * If there is no selection we just call `toggleFn(editor)`.
994
- */
995
-
996
- function modifySelection(editor, toggleFn, isList) {
997
- return () => {
998
- editor.usePrimarySelection();
999
- const selection = editor.getSelection();
1000
-
1001
- if (selection) {
1002
- // there's a selection - toggle list bullet for each line
1003
- // listNumber is 1, 2, 3... and can be used as ol bullet
1004
- forLineIn(selection, (lineNumber, listNumber) => {
1005
- // TODO move this into forLineIn
1006
- editor.moveToLineBeginning(lineNumber);
1007
- toggleFn(editor, listNumber);
1008
- });
1009
- editor.moveToLineEnd();
1010
- } else {
1011
- // there's no selection - just toggle line prefix
1012
- // but if adding list, add whitespace before and after list
1013
- if (isList && !getListNumber(editor) && !editor.lineStartsWith('- ')) {
1014
- prepareListWhitespace(editor);
1015
- }
1016
-
1017
- toggleFn(editor);
1018
- }
1019
- };
1020
- }
1021
- /**
1022
- * Calls callback for each line number that is in the selection
1023
- *
1024
- * The second argument is the 1-based index of the iteration.
1025
- *
1026
- * @param {CodeMirror.Selection} selection
1027
- * param {function(number)} cb
1028
- */
1029
-
1030
-
1031
- function forLineIn(selection, cb) {
1032
- // anchor/head depend on selection direction, so min & max have to be used
1033
- const lines = [selection.anchor.line, selection.head.line];
1034
- const maxNumber = max(lines);
1035
- const minNumber = min(lines);
1036
- const lineRange = range(minNumber || 0, maxNumber !== undefined ? maxNumber + 1 : undefined);
1037
- lineRange.forEach((lineNumber, i) => {
1038
- cb(lineNumber, i + 1);
1039
- });
1040
- }
1041
-
1042
- function prepareListWhitespace(editor) {
1043
- const line = editor.getCurrentLineNumber();
1044
- const isCurrentLineEmpty = editor.isLineEmpty(line);
1045
- const isPrevLineEmpty = line > 0 ? editor.isLineEmpty(line - 1) : false;
1046
- const isNextLineEmpty = line < editor.getLinesCount() - 1 ? editor.isLineEmpty(line + 1) : true;
1047
- let linesToInsert = isCurrentLineEmpty ? 2 : 4;
1048
-
1049
- if (isPrevLineEmpty) {
1050
- linesToInsert = linesToInsert - 1;
1051
- }
1052
-
1053
- if (isNextLineEmpty) {
1054
- linesToInsert = linesToInsert - 1;
1055
- }
1056
-
1057
- editor.moveToLineEnd();
1058
- editor.insertAtCursor(editor.getNl(linesToInsert));
1059
- editor.restoreCursor(0, isCurrentLineEmpty ? line : line + 2);
1060
- }
1061
-
1062
- function getListNumber(editor) {
1063
- const result = editor.getCurrentLine().match(/^(\d+\. )/);
1064
- return result ? result[1] : null;
1065
- }
1066
-
1067
- function ulToggleFn(editor) {
1068
- if (editor.lineStartsWith('- ')) {
1069
- editor.removeFromLineBeginning(2);
1070
- } else {
1071
- const listNumber = getListNumber(editor);
1072
-
1073
- if (listNumber) {
1074
- editor.removeFromLineBeginning(listNumber.length);
1075
- }
1076
-
1077
- editor.insertAtLineBeginning('- ');
1078
- }
1079
- }
1080
-
1081
- function olToggleFn(editor, n) {
1082
- const listNumber = getListNumber(editor);
1083
-
1084
- if (listNumber) {
1085
- editor.removeFromLineBeginning(listNumber.length);
1086
- } else {
1087
- if (editor.lineStartsWith('- ')) {
1088
- editor.removeFromLineBeginning(2);
1089
- }
1090
-
1091
- editor.insertAtLineBeginning((n || 1) + '. ');
1092
- }
1093
- }
1094
- /**
1095
- * From a table layout specification build a Markdown table template.
1096
- *
1097
- * Returns the lines as an array.
1098
- * Used by the `table()` command
1099
- *
1100
- * @param {object} config
1101
- * @param {number} rows
1102
- * @param {number} cols
1103
- * @returns {string[]}
1104
- */
1105
-
1106
-
1107
- function tableTemplate(nrows, ncols) {
1108
- const cellWidth = new Array(11);
1109
- const cell = ' ' + cellWidth.join(' ') + ' |';
1110
- const separatorCell = ' ' + cellWidth.join('-') + ' |';
1111
- let baseRow = '|';
1112
- let separatorRow = '|';
1113
- times(ncols, () => {
1114
- baseRow += cell;
1115
- separatorRow += separatorCell;
1116
- });
1117
- const bodyRows = range(nrows).map(() => baseRow.replace(/\| {5}/g, '| Cell'));
1118
- const headerRow = baseRow.replace(/\| {7}/g, '| Header');
1119
- return [headerRow, separatorRow].concat(bodyRows);
1120
- }
1121
- /**
1122
- * Toggles the header prefix for a given level on the current line.
1123
- *
1124
- * - Removes a header when one of the same level is
1125
- * - Replaces the header if there is one of a different level
1126
- * - Otherwise inserts the header
1127
- */
1128
-
1129
-
1130
- function toggleHeader(editor, level) {
1131
- return () => {
1132
- const initialCh = editor.getCurrentCharacter();
1133
- const currentHeader = selectHeader(editor);
1134
- const prefix = repeat(HEADER_CHAR, level); // there's no header at the current line - create one
1135
-
1136
- if (!currentHeader) {
1137
- editor.moveToLineBeginning();
1138
- editor.insertAtCursor(prefix + ' ');
1139
- editor.restoreCursor(initialCh + prefix.length + 1);
1140
- return;
1141
- } // there's exactly the same header - remove one
1142
-
1143
-
1144
- if (editor.getSelectedText() === prefix) {
1145
- editor.extendSelectionBy(1);
1146
- const removedCh = editor.getSelectionLength();
1147
- editor.removeSelectedText();
1148
- editor.restoreCursor(initialCh - removedCh);
1149
- return;
1150
- } // there's another header at the current line - replace
1151
-
1152
-
1153
- const diff = prefix.length - editor.getSelectionLength();
1154
- editor.replaceSelectedText(prefix);
1155
- editor.restoreCursor(initialCh + diff);
1156
- };
1157
- }
1158
- /**
1159
- * On the current line select a Markdown header prefix. That is the
1160
- * string at the beginning of the line that consists of up to six `#`.
1161
- *
1162
- * If the selection was successful return the selected string.
1163
- */
1164
-
1165
-
1166
- function selectHeader(editor) {
1167
- const result = editor.getCurrentLine().match(/^( {0,3})(#{1,6}) /);
1168
-
1169
- if (!result) {
1170
- return null;
1171
- }
1172
-
1173
- const indentation = result[1];
1174
- const header = result[2];
1175
- editor.select(getPos(0), getPos(header.length));
1176
- return editor.getSelection();
1177
-
1178
- function getPos(modifier) {
1179
- return {
1180
- line: editor.getCurrentLineNumber(),
1181
- ch: indentation.length + modifier
1182
- };
1183
- }
1184
- }
1185
-
1186
- /* eslint-disable @typescript-eslint/no-explicit-any */
1187
- function createMarkdownEditor(host, options) {
1188
- const editor = create(host, options);
1189
-
1190
- function wrapChange(fn) {
1191
- return (e, ch) => {
1192
- fn(editor.getValue(), e, ch);
1193
- };
1194
- }
1195
-
1196
- const api = {
1197
- actions: create$1(editor),
1198
- history: {
1199
- hasUndo: function () {
1200
- return editor.getHistorySize('undo') > 0;
1201
- },
1202
- hasRedo: function () {
1203
- return editor.getHistorySize('redo') > 0;
1204
- }
1205
- },
1206
- events: {
1207
- onScroll: function (fn) {
1208
- editor.attachEvent('scroll', fn, 150);
1209
- },
1210
- onChange: function (fn) {
1211
- editor.attachEvent('change', wrapChange(fn), 0);
1212
- },
1213
- onPaste: function (fn) {
1214
- editor.attachEvent('paste', fn, 0);
1215
- }
1216
- },
1217
- insert: editor.insertAtCursor,
1218
- focus: editor.focus,
1219
- getContent: editor.getValue,
1220
- destroy: editor.destroy,
1221
- setContent: editor.setValue,
1222
- getSelectedText: editor.getSelectedText,
1223
- usePrimarySelection: editor.usePrimarySelection,
1224
- setReadOnly: editor.setReadOnly,
1225
- selectBackwards: editor.selectBackwards,
1226
- getCursor: editor.getCursor,
1227
- setCursor: editor.setCursor,
1228
- clear: () => editor.setValue(''),
1229
- selectAll: editor.selectAll,
1230
- setFullsize: editor.setFullsize,
1231
- refresh: editor.refresh
1232
- };
1233
- editor.addKeyShortcuts({
1234
- B: api.actions.bold,
1235
- I: api.actions.italic
1236
- });
1237
- return api;
1238
- }
1239
-
1240
- const styles$4 = {
1241
- root: css`
1242
- border: 1px solid ${tokens.gray400};
1243
- border-width: 0 1px;
1244
- overflow-y: auto;
1245
- height: auto;
1246
- min-height: 300px;
1247
-
1248
- .CodeMirror {
1249
- height: auto;
1250
- line-height: ${tokens.lineHeightDefault};
1251
- }
1252
- .CodeMirror-lines {
1253
- color: ${tokens.gray700};
1254
- padding: ${tokens.spacingL};
1255
- }
1256
- .CodeMirror-code {
1257
- font-family: ${tokens.fontStackMonospace};
1258
- font-size: ${tokens.fontSizeM};
1259
- }
1260
- .CodeMirror-scroll {
1261
- min-height: '6rem';
1262
- }
1263
-
1264
- .cm-header {
1265
- color: ${tokens.gray900};
1266
- }
1267
- span.cm-variable-2 {
1268
- color: ${tokens.gray700};
1269
- }
1270
- .cm-header-1 {
1271
- font-size: 1.9em;
1272
- }
1273
- .cm-header-2 {
1274
- font-size: 1.75em;
1275
- }
1276
- .cm-header-3 {
1277
- font-size: 1.6em;
1278
- }
1279
- .cm-header-4 {
1280
- font-size: 1.45em;
1281
- }
1282
- .cm-header-5 {
1283
- font-size: 1.3em;
1284
- }
1285
- .cm-header-6 {
1286
- font-size: 1.15em;
1287
- }
1288
-
1289
- span.cm-tag,
1290
- span.cm-string,
1291
- span.cm-attribute {
1292
- color: ${tokens.red600};
1293
- }
1294
- span.cm-string {
1295
- text-decoration: none !important;
1296
- }
1297
- span.cm-quote,
1298
- span.cm-comment {
1299
- color: ${tokens.gray600};
1300
- }
1301
- span.cm-link,
1302
- span.cm-url {
1303
- color: ${tokens.blue500} !important;
1304
- }
1305
- span.cm-link {
1306
- text-decoration: underline;
1307
- }
1308
- `,
1309
- framed: /*#__PURE__*/css({
1310
- '.CodeMirror': {
1311
- maxHeight: '500px'
1312
- }
1313
- }),
1314
- zen: /*#__PURE__*/css({
1315
- border: 'none !important',
1316
- '.CodeMirror-lines': {
1317
- maxWidth: '650px',
1318
- margin: '0 auto'
1319
- }
1320
- }),
1321
- disabled: css`
1322
- .CodeMirror {
1323
- background: ${tokens.gray100};
1324
- cursor: 'not-allowed';
1325
- }
1326
- .CodeMirror-cursors {
1327
- visibility: hidden !important;
1328
- }
1329
- .CodeMirror-scroll,
1330
- .CodeMirror-sizer,
1331
- .CodeMirror-lines {
1332
- cursor: not-allowed;
1333
- }
1334
- `
1335
- };
1336
- const MarkdownTextarea = /*#__PURE__*/React.memo(props => {
1337
- const hostRef = useRef(null);
1338
- const [editor, setEditor] = useState(null);
1339
- useEffect(() => {
1340
- if (hostRef.current) {
1341
- setEditor(createMarkdownEditor(hostRef.current, Object.assign({}, {
1342
- direction: props.direction,
1343
- readOnly: true
1344
- }, props.mode === 'zen' ? {
1345
- fixedHeight: true,
1346
- height: '100%'
1347
- } : {}, props.minHeight !== undefined ? {
1348
- height: props.minHeight
1349
- } : {})));
1350
- } // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
1351
-
1352
- }, []);
1353
- useEffect(() => {
1354
- if (editor) {
1355
- props.onReady(editor);
1356
- } // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
1357
-
1358
- }, [editor]);
1359
- const className = cx(styles$4.root, props.minHeight !== undefined ? css({
1360
- minHeight: props.minHeight
1361
- }) : undefined, props.mode === 'default' ? styles$4.framed : styles$4.zen, props.disabled && styles$4.disabled);
1362
- return React.createElement("div", {
1363
- className: className,
1364
- ref: hostRef,
1365
- "data-test-id": "markdown-textarea",
1366
- style: {
1367
- display: props.visible ? 'block' : 'none'
1368
- }
1369
- });
1370
- });
1371
- MarkdownTextarea.displayName = 'MarkdownTextarea';
1372
-
1373
- const HeadingSelector = props => {
1374
- const handleMenuClick = heading => {
1375
- props.onSelect(heading);
1376
- };
1377
-
1378
- return React.createElement(Menu, null, React.createElement(Menu.Trigger, null, props.children), React.createElement(Menu.List, null, React.createElement(Menu.Item, {
1379
- testId: "markdown-action-button-heading-h1",
1380
- onClick: () => handleMenuClick('h1')
1381
- }, "Heading 1"), React.createElement(Menu.Item, {
1382
- testId: "markdown-action-button-heading-h2",
1383
- onClick: () => handleMenuClick('h2')
1384
- }, "Heading 2"), React.createElement(Menu.Item, {
1385
- testId: "markdown-action-button-heading-h3",
1386
- onClick: () => handleMenuClick('h3')
1387
- }, "Heading 3")));
1388
- };
1389
-
1390
- const srOnly = /*#__PURE__*/css({
1391
- position: 'absolute',
1392
- width: '1px',
1393
- height: '1px',
1394
- padding: '0',
1395
- margin: '-1px',
1396
- overflow: 'hidden',
1397
- clip: 'rect(0, 0, 0, 0)',
1398
- border: '0'
1399
- });
1400
- const Zen = ({
1401
- label,
1402
- ...rest
1403
- }) => React.createElement("svg", {
1404
- width: 14,
1405
- height: 14,
1406
- viewBox: "0 0 1792 1792",
1407
- ...rest
1408
- }, React.createElement("path", {
1409
- d: "M1411 541l-355 355 355 355 144-144q29-31 70-14 39 17 39 59v448q0 26-19 45t-45 19h-448q-42 0-59-40-17-39 14-69l144-144-355-355-355 355 144 144q31 30 14 69-17 40-59 40H192q-26 0-45-19t-19-45v-448q0-42 40-59 39-17 69 14l144 144 355-355-355-355-144 144q-19 19-45 19-12 0-24-5-40-17-40-59V192q0-26 19-45t45-19h448q42 0 59 40 17 39-14 69L541 381l355 355 355-355-144-144q-31-30-14-69 17-40 59-40h448q26 0 45 19t19 45v448q0 42-39 59-13 5-25 5-26 0-45-19z"
1410
- }), React.createElement("span", {
1411
- className: srOnly
1412
- }, label));
1413
- const Strikethrough = ({
1414
- label,
1415
- ...rest
1416
- }) => React.createElement("svg", {
1417
- width: 14,
1418
- height: 14,
1419
- viewBox: "0 0 1792 1792",
1420
- ...rest
1421
- }, React.createElement("path", {
1422
- d: "M1760 896q14 0 23 9t9 23v64q0 14-9 23t-23 9H32q-14 0-23-9t-9-23v-64q0-14 9-23t23-9h1728zM483 832q-28-35-51-80-48-98-48-188 0-181 134-309 133-127 393-127 50 0 167 19 66 12 177 48 10 38 21 118 14 123 14 183 0 18-5 45l-12 3-84-6-14-2q-50-149-103-205-88-91-210-91-114 0-182 59-67 58-67 146 0 73 66 140t279 129q69 20 173 66 58 28 95 52H483zm507 256h411q7 39 7 92 0 111-41 212-23 56-71 104-37 35-109 81-80 48-153 66-80 21-203 21-114 0-195-23l-140-40q-57-16-72-28-8-8-8-22v-13q0-108-2-156-1-30 0-68l2-37v-44l102-2q15 34 30 71t22.5 56 12.5 27q35 57 80 94 43 36 105 57 59 22 132 22 64 0 139-27 77-26 122-86 47-61 47-129 0-84-81-157-34-29-137-71z"
1423
- }), React.createElement("span", {
1424
- className: srOnly
1425
- }, label));
1426
- const Indent = ({
1427
- label,
1428
- ...rest
1429
- }) => React.createElement("svg", {
1430
- width: 14,
1431
- height: 14,
1432
- viewBox: "0 0 1792 1792",
1433
- ...rest
1434
- }, React.createElement("path", {
1435
- d: "M352 832q0 14-9 23L55 1143q-9 9-23 9-13 0-22.5-9.5T0 1120V544q0-13 9.5-22.5T32 512q14 0 23 9l288 288q9 9 9 23zm1440 480v192q0 13-9.5 22.5t-22.5 9.5H32q-13 0-22.5-9.5T0 1504v-192q0-13 9.5-22.5T32 1280h1728q13 0 22.5 9.5t9.5 22.5zm0-384v192q0 13-9.5 22.5t-22.5 9.5H672q-13 0-22.5-9.5T640 1120V928q0-13 9.5-22.5T672 896h1088q13 0 22.5 9.5t9.5 22.5zm0-384v192q0 13-9.5 22.5T1760 768H672q-13 0-22.5-9.5T640 736V544q0-13 9.5-22.5T672 512h1088q13 0 22.5 9.5t9.5 22.5zm0-384v192q0 13-9.5 22.5T1760 384H32q-13 0-22.5-9.5T0 352V160q0-13 9.5-22.5T32 128h1728q13 0 22.5 9.5t9.5 22.5z"
1436
- }), React.createElement("span", {
1437
- className: srOnly
1438
- }, label));
1439
- const Dedent = ({
1440
- label,
1441
- ...rest
1442
- }) => React.createElement("svg", {
1443
- width: 14,
1444
- height: 14,
1445
- viewBox: "0 0 1792 1792",
1446
- ...rest
1447
- }, React.createElement("path", {
1448
- d: "M384 544v576q0 13-9.5 22.5T352 1152q-14 0-23-9L41 855q-9-9-9-23t9-23l288-288q9-9 23-9 13 0 22.5 9.5T384 544zm1408 768v192q0 13-9.5 22.5t-22.5 9.5H32q-13 0-22.5-9.5T0 1504v-192q0-13 9.5-22.5T32 1280h1728q13 0 22.5 9.5t9.5 22.5zm0-384v192q0 13-9.5 22.5t-22.5 9.5H672q-13 0-22.5-9.5T640 1120V928q0-13 9.5-22.5T672 896h1088q13 0 22.5 9.5t9.5 22.5zm0-384v192q0 13-9.5 22.5T1760 768H672q-13 0-22.5-9.5T640 736V544q0-13 9.5-22.5T672 512h1088q13 0 22.5 9.5t9.5 22.5zm0-384v192q0 13-9.5 22.5T1760 384H32q-13 0-22.5-9.5T0 352V160q0-13 9.5-22.5T32 128h1728q13 0 22.5 9.5t9.5 22.5z"
1449
- }), React.createElement("span", {
1450
- className: srOnly
1451
- }, label));
1452
- const Cubes = ({
1453
- label,
1454
- ...rest
1455
- }) => React.createElement("svg", {
1456
- width: 18,
1457
- height: 14,
1458
- viewBox: "0 0 2304 1792",
1459
- ...rest
1460
- }, React.createElement("path", {
1461
- d: "M640 1632l384-192v-314l-384 164v342zm-64-454l404-173-404-173-404 173zm1088 454l384-192v-314l-384 164v342zm-64-454l404-173-404-173-404 173zm-448-293l384-165V454l-384 164v267zm-64-379l441-189-441-189-441 189zm1088 518v416q0 36-19 67t-52 47l-448 224q-25 14-57 14t-57-14l-448-224q-4-2-7-4-2 2-7 4l-448 224q-25 14-57 14t-57-14L71 1554q-33-16-52-47t-19-67v-416q0-38 21.5-70T78 906l434-186V320q0-38 21.5-70t56.5-48l448-192q23-10 50-10t50 10l448 192q35 16 56.5 48t21.5 70v400l434 186q36 16 57 48t21 70z"
1462
- }), React.createElement("span", {
1463
- className: srOnly
1464
- }, label));
1465
- const Table = ({
1466
- label,
1467
- ...rest
1468
- }) => React.createElement("svg", {
1469
- width: 14,
1470
- height: 14,
1471
- viewBox: "0 0 1792 1792",
1472
- ...rest
1473
- }, React.createElement("path", {
1474
- d: "M576 1376v-192q0-14-9-23t-23-9H224q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm0-384V800q0-14-9-23t-23-9H224q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm512 384v-192q0-14-9-23t-23-9H736q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zM576 608V416q0-14-9-23t-23-9H224q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm512 384V800q0-14-9-23t-23-9H736q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm512 384v-192q0-14-9-23t-23-9h-320q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm-512-768V416q0-14-9-23t-23-9H736q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm512 384V800q0-14-9-23t-23-9h-320q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm0-384V416q0-14-9-23t-23-9h-320q-14 0-23 9t-9 23v192q0 14 9 23t23 9h320q14 0 23-9t9-23zm128-320v1088q0 66-47 113t-113 47H224q-66 0-113-47t-47-113V288q0-66 47-113t113-47h1344q66 0 113 47t47 113z"
1475
- }), React.createElement("span", {
1476
- className: srOnly
1477
- }, label));
1478
- const SpecialChar = ({
1479
- label,
1480
- ...rest
1481
- }) => React.createElement("svg", {
1482
- width: 14,
1483
- height: 14,
1484
- viewBox: "0 0 1792 1792",
1485
- ...rest
1486
- }, React.createElement("path", {
1487
- d: "M1360 1307l35 159q3 12-3 22.5t-17 14.5l-5 1q-4 2-10.5 3.5t-16 4.5-21.5 5.5-25.5 5-30 5-33.5 4.5-36.5 3-38.5 1q-234 0-409-130.5T511 1054h-95q-13 0-22.5-9.5T384 1022V909q0-13 9.5-22.5T416 877h66q-2-57 1-105h-67q-14 0-23-9t-9-23V626q0-14 9-23t23-9h98q67-210 243.5-338T1158 128q102 0 194 23 11 3 20 15 6 11 3 24l-43 159q-3 13-14 19.5t-24 2.5l-4-1q-4-1-11.5-2.5L1261 364l-22.5-3.5-26-3-29-2.5-29.5-1q-126 0-226 64T778 594h468q16 0 25 12 10 12 7 26l-24 114q-5 26-32 26H734q-3 37 0 105h459q15 0 25 12 9 12 6 27l-24 112q-2 11-11 18.5t-20 7.5H782q48 117 149.5 185.5T1160 1308q18 0 36-1.5t33.5-3.5 29.5-4.5 24.5-5 18.5-4.5l12-3 5-2q13-5 26 2 12 7 15 21z"
1488
- }), React.createElement("span", {
1489
- className: srOnly
1490
- }, label));
1491
- const OrgLinks = ({
1492
- label,
1493
- ...rest
1494
- }) => React.createElement("svg", {
1495
- width: 14,
1496
- height: 14,
1497
- viewBox: "0 0 1792 1792",
1498
- ...rest
1499
- }, React.createElement("path", {
1500
- d: "M1792 1248v320q0 40-28 68t-68 28h-320q-40 0-68-28t-28-68v-320q0-40 28-68t68-28h96V960H960v192h96q40 0 68 28t28 68v320q0 40-28 68t-68 28H736q-40 0-68-28t-28-68v-320q0-40 28-68t68-28h96V960H320v192h96q40 0 68 28t28 68v320q0 40-28 68t-68 28H96q-40 0-68-28t-28-68v-320q0-40 28-68t68-28h96V960q0-52 38-90t90-38h512V640h-96q-40 0-68-28t-28-68V224q0-40 28-68t68-28h320q40 0 68 28t28 68v320q0 40-28 68t-68 28h-96v192h512q52 0 90 38t38 90v192h96q40 0 68 28t28 68z"
1501
- }), React.createElement("span", {
1502
- className: srOnly
1503
- }, label));
1504
- const Undo = ({
1505
- label,
1506
- ...rest
1507
- }) => React.createElement("svg", {
1508
- width: 14,
1509
- height: 14,
1510
- viewBox: "0 0 1792 1792",
1511
- ...rest
1512
- }, React.createElement("path", {
1513
- d: "M1664 896q0 156-61 298t-164 245-245 164-298 61q-172 0-327-72.5T305 1387q-7-10-6.5-22.5t8.5-20.5l137-138q10-9 25-9 16 2 23 12 73 95 179 147t225 52q104 0 198.5-40.5T1258 1258t109.5-163.5T1408 896t-40.5-198.5T1258 534t-163.5-109.5T896 384q-98 0-188 35.5T548 521l137 138q31 30 14 69-17 40-59 40H192q-26 0-45-19t-19-45V256q0-42 40-59 39-17 69 14l130 129q107-101 244.5-156.5T896 128q156 0 298 61t245 164 164 245 61 298z"
1514
- }), React.createElement("span", {
1515
- className: srOnly
1516
- }, label));
1517
- const Redo = ({
1518
- label,
1519
- ...rest
1520
- }) => React.createElement("svg", {
1521
- width: 14,
1522
- height: 14,
1523
- viewBox: "0 0 1792 1792",
1524
- ...rest
1525
- }, React.createElement("path", {
1526
- d: "M1664 256v448q0 26-19 45t-45 19h-448q-42 0-59-40-17-39 14-69l138-138q-148-137-349-137-104 0-198.5 40.5T534 534 424.5 697.5 384 896t40.5 198.5T534 1258t163.5 109.5T896 1408q119 0 225-52t179-147q7-10 23-12 15 0 25 9l137 138q9 8 9.5 20.5t-7.5 22.5q-109 132-264 204.5T896 1664q-156 0-298-61t-245-164-164-245-61-298 61-298 164-245 245-164 298-61q147 0 284.5 55.5T1425 340l130-129q29-31 70-14 39 17 39 59z"
1527
- }), React.createElement("span", {
1528
- className: srOnly
1529
- }, label));
1530
-
1531
- const InsertLinkSelector = props => {
1532
- if (props.canAddNew) {
1533
- return React.createElement(MultipleMediaContextMenu, { ...props
1534
- });
1535
- } else {
1536
- return React.createElement(Button, {
1537
- isDisabled: props.disabled,
1538
- startIcon: React.createElement(AssetIcon, null),
1539
- testId: "markdownEditor.linkExistingAssets",
1540
- size: "small",
1541
- variant: "secondary",
1542
- onClick: () => {
1543
- props.onSelectExisting();
1544
- }
1545
- }, "Insert media");
1546
- }
1547
- };
1548
-
1549
- const MultipleMediaContextMenu = props => {
1550
- return React.createElement(Menu, {
1551
- placement: "bottom-end"
1552
- }, React.createElement(Menu.Trigger, null, React.createElement(Button, {
1553
- endIcon: React.createElement(ChevronDownIcon, null),
1554
- isDisabled: props.disabled,
1555
- startIcon: React.createElement(AssetIcon, null),
1556
- testId: "markdownEditor.insertMediaDropdownTrigger",
1557
- size: "small",
1558
- variant: "secondary"
1559
- }, "Insert media")), React.createElement(Menu.List, null, React.createElement(Menu.Item, {
1560
- testId: "markdownEditor.uploadAssetsAndLink",
1561
- onClick: () => props.onAddNew()
1562
- }, "Add new media and link"), React.createElement(Menu.Item, {
1563
- testId: "markdownEditor.linkExistingAssets",
1564
- onClick: () => props.onSelectExisting()
1565
- }, "Link existing media")));
1566
- };
1567
-
1568
- /* eslint-disable react/prop-types */
1569
- const styles$5 = {
1570
- root: /*#__PURE__*/css({
1571
- position: 'relative',
1572
- zIndex: /*#__PURE__*/Number(tokens.zIndexWorkbenchHeader),
1573
- border: `1px solid ${tokens.gray400}`,
1574
- backgroundColor: tokens.gray100,
1575
- padding: tokens.spacingXs,
1576
- borderTopLeftRadius: tokens.borderRadiusSmall
1577
- }),
1578
- button: /*#__PURE__*/css({
1579
- height: '30px',
1580
- width: '36px',
1581
- marginLeft: tokens.spacing2Xs,
1582
- marginRight: tokens.spacing2Xs
1583
- }),
1584
- icon: /*#__PURE__*/css({
1585
- fill: tokens.gray700,
1586
- verticalAlign: 'middle'
1587
- }),
1588
- zenButton: /*#__PURE__*/css({
1589
- marginLeft: tokens.spacingXs
1590
- }),
1591
- zenButtonPressed: /*#__PURE__*/css({
1592
- backgroundColor: tokens.gray400
1593
- }),
1594
- tooltip: /*#__PURE__*/css({
1595
- zIndex: /*#__PURE__*/Number(tokens.zIndexTooltip)
1596
- })
1597
- };
1598
- const ToolbarButton = /*#__PURE__*/React.forwardRef((props, ref) => {
1599
- const {
1600
- tooltip,
1601
- onClick,
1602
- children,
1603
- className,
1604
- variant = 'transparent',
1605
- tooltipPlace = 'top',
1606
- isDisabled = false,
1607
- ...otherProps
1608
- } = props;
1609
- return React.createElement(Tooltip, {
1610
- className: styles$5.tooltip,
1611
- placement: tooltipPlace,
1612
- content: tooltip
1613
- }, React.createElement(IconButton, { ...otherProps,
1614
- ref: ref,
1615
- className: cx(styles$5.button, className),
1616
- isDisabled: isDisabled,
1617
- onClick: onClick,
1618
- variant: variant,
1619
- size: "small",
1620
- icon: children,
1621
- "aria-label": tooltip
1622
- }));
1623
- });
1624
- ToolbarButton.displayName = 'ToolbarButton';
1625
-
1626
- function MainButtons(props) {
1627
- const tooltipPlace = props.mode === 'zen' ? 'bottom' : 'top';
1628
- return React.createElement(React.Fragment, null, React.createElement(HeadingSelector, {
1629
- onSelect: heading => {
1630
- if (heading && props.actions.headings[heading]) {
1631
- props.actions.headings[heading]();
1632
- }
1633
- }
1634
- }, React.createElement(ToolbarButton, {
1635
- isDisabled: props.disabled,
1636
- testId: "markdown-action-button-heading",
1637
- tooltip: "Headings",
1638
- tooltipPlace: tooltipPlace
1639
- }, React.createElement(HeadingIcon, {
1640
- "aria-label": "Headings",
1641
- className: styles$5.icon
1642
- }))), React.createElement(ToolbarButton, {
1643
- isDisabled: props.disabled,
1644
- testId: "markdown-action-button-bold",
1645
- tooltip: "Bold",
1646
- tooltipPlace: tooltipPlace,
1647
- onClick: props.actions.simple.bold
1648
- }, React.createElement(FormatBoldIcon, {
1649
- "aria-label": "Bold",
1650
- className: styles$5.icon
1651
- })), React.createElement(ToolbarButton, {
1652
- isDisabled: props.disabled,
1653
- testId: "markdown-action-button-italic",
1654
- tooltip: "Italic",
1655
- tooltipPlace: tooltipPlace,
1656
- onClick: props.actions.simple.italic
1657
- }, React.createElement(FormatItalicIcon, {
1658
- "aria-label": "Italic",
1659
- className: styles$5.icon
1660
- })), React.createElement(ToolbarButton, {
1661
- isDisabled: props.disabled,
1662
- testId: "markdown-action-button-quote",
1663
- tooltip: "Quote",
1664
- tooltipPlace: tooltipPlace,
1665
- onClick: props.actions.simple.quote
1666
- }, React.createElement(QuoteIcon, {
1667
- "aria-label": "Quote",
1668
- className: styles$5.icon
1669
- })), React.createElement(ToolbarButton, {
1670
- isDisabled: props.disabled,
1671
- testId: "markdown-action-button-ul",
1672
- tooltip: "Unordered list",
1673
- tooltipPlace: tooltipPlace,
1674
- onClick: props.actions.simple.ul
1675
- }, React.createElement(ListBulletedIcon, {
1676
- "aria-label": "Unordered list",
1677
- className: styles$5.icon
1678
- })), React.createElement(ToolbarButton, {
1679
- isDisabled: props.disabled,
1680
- testId: "markdown-action-button-ol",
1681
- tooltip: "Ordered list",
1682
- tooltipPlace: tooltipPlace,
1683
- onClick: props.actions.simple.ol
1684
- }, React.createElement(ListNumberedIcon, {
1685
- "aria-label": "Ordered list",
1686
- className: styles$5.icon
1687
- })), React.createElement(ToolbarButton, {
1688
- isDisabled: props.disabled,
1689
- testId: "markdown-action-button-link",
1690
- tooltip: "Link",
1691
- tooltipPlace: tooltipPlace,
1692
- onClick: props.actions.insertLink
1693
- }, React.createElement(LinkIcon, {
1694
- "aria-label": "Link",
1695
- className: styles$5.icon
1696
- })));
1697
- }
1698
-
1699
- function AdditionalButtons(props) {
1700
- const tooltipPlace = props.mode === 'zen' ? 'bottom' : 'top';
1701
- return React.createElement(React.Fragment, null, React.createElement(ToolbarButton, {
1702
- isDisabled: props.disabled,
1703
- testId: "markdown-action-button-strike",
1704
- tooltip: "Strike out",
1705
- tooltipPlace: tooltipPlace,
1706
- onClick: props.actions.simple.strike
1707
- }, React.createElement(Strikethrough, {
1708
- label: "Strike out",
1709
- className: styles$5.icon
1710
- })), React.createElement(ToolbarButton, {
1711
- isDisabled: props.disabled,
1712
- testId: "markdown-action-button-code",
1713
- tooltip: "Code block",
1714
- tooltipPlace: tooltipPlace,
1715
- onClick: props.actions.simple.code
1716
- }, React.createElement(CodeIcon, {
1717
- "aria-label": "Code block",
1718
- className: styles$5.icon
1719
- })), React.createElement(ToolbarButton, {
1720
- isDisabled: props.disabled,
1721
- testId: "markdown-action-button-hr",
1722
- tooltip: "Horizontal rule",
1723
- tooltipPlace: tooltipPlace,
1724
- onClick: props.actions.simple.hr
1725
- }, React.createElement(HorizontalRuleIcon, {
1726
- "aria-label": "Horizontal rule",
1727
- className: styles$5.icon
1728
- })), React.createElement(ToolbarButton, {
1729
- isDisabled: props.disabled,
1730
- testId: "markdown-action-button-indent",
1731
- tooltip: "Increase indentation",
1732
- tooltipPlace: tooltipPlace,
1733
- onClick: props.actions.simple.indent
1734
- }, React.createElement(Indent, {
1735
- label: "Increase indentation",
1736
- className: styles$5.icon
1737
- })), React.createElement(ToolbarButton, {
1738
- isDisabled: props.disabled,
1739
- testId: "markdown-action-button-dedent",
1740
- tooltip: "Decrease indentation",
1741
- tooltipPlace: tooltipPlace,
1742
- onClick: props.actions.simple.dedent
1743
- }, React.createElement(Dedent, {
1744
- label: "Decrease indentation",
1745
- className: styles$5.icon
1746
- })), React.createElement(ToolbarButton, {
1747
- isDisabled: props.disabled,
1748
- testId: "markdown-action-button-embed",
1749
- tooltip: "Embed external content",
1750
- tooltipPlace: tooltipPlace,
1751
- onClick: props.actions.embedExternalContent
1752
- }, React.createElement(Cubes, {
1753
- label: "Embed external content",
1754
- className: styles$5.icon
1755
- })), React.createElement(ToolbarButton, {
1756
- isDisabled: props.disabled,
1757
- testId: "markdown-action-button-table",
1758
- tooltip: "Insert table",
1759
- tooltipPlace: tooltipPlace,
1760
- onClick: props.actions.insertTable
1761
- }, React.createElement(Table, {
1762
- label: "Insert table",
1763
- className: styles$5.icon
1764
- })), React.createElement(ToolbarButton, {
1765
- isDisabled: props.disabled,
1766
- testId: "markdown-action-button-special",
1767
- tooltip: "Insert special character",
1768
- tooltipPlace: tooltipPlace,
1769
- onClick: props.actions.insertSpecialCharacter
1770
- }, React.createElement(SpecialChar, {
1771
- label: "Insert special character",
1772
- className: styles$5.icon
1773
- })), React.createElement(ToolbarButton, {
1774
- isDisabled: props.disabled,
1775
- testId: "markdown-action-button-organizeLinks",
1776
- tooltip: "Organize links",
1777
- tooltipPlace: tooltipPlace,
1778
- onClick: props.actions.organizeLinks
1779
- }, React.createElement(OrgLinks, {
1780
- label: "Organize links",
1781
- className: styles$5.icon
1782
- })), React.createElement(ToolbarButton, {
1783
- isDisabled: props.disabled,
1784
- testId: "markdown-action-button-undo",
1785
- tooltip: "Undo",
1786
- tooltipPlace: tooltipPlace,
1787
- onClick: props.actions.history.undo
1788
- }, React.createElement(Undo, {
1789
- label: "Undo",
1790
- className: styles$5.icon
1791
- })), React.createElement(ToolbarButton, {
1792
- isDisabled: props.disabled,
1793
- testId: "markdown-action-button-redo",
1794
- tooltip: "Redo",
1795
- tooltipPlace: tooltipPlace,
1796
- onClick: props.actions.history.redo
1797
- }, React.createElement(Redo, {
1798
- label: "Redo",
1799
- className: styles$5.icon
1800
- })));
1801
- }
1802
-
1803
- function DefaultMarkdownToolbar(props) {
1804
- const [showAdditional, setShowAdditional] = React.useState(false);
1805
- return React.createElement("div", {
1806
- className: styles$5.root
1807
- }, React.createElement(Flex, {
1808
- justifyContent: "space-between"
1809
- }, React.createElement(Flex, null, React.createElement(MainButtons, { ...props
1810
- }), React.createElement(ToolbarButton, {
1811
- isDisabled: props.disabled,
1812
- testId: "markdown-action-button-toggle-additional",
1813
- tooltip: showAdditional ? 'Hide additional actions' : 'More actions',
1814
- onClick: () => {
1815
- setShowAdditional(!showAdditional);
1816
- }
1817
- }, React.createElement(MoreHorizontalIcon, {
1818
- className: styles$5.icon
1819
- }))), React.createElement(Flex, null, React.createElement(InsertLinkSelector, {
1820
- disabled: props.disabled,
1821
- onSelectExisting: props.actions.linkExistingMedia,
1822
- onAddNew: props.actions.addNewMedia,
1823
- canAddNew: props.canUploadAssets
1824
- }), React.createElement(ToolbarButton, {
1825
- isDisabled: props.disabled,
1826
- testId: "markdown-action-button-zen",
1827
- variant: "secondary",
1828
- onClick: props.actions.openZenMode,
1829
- className: styles$5.zenButton,
1830
- tooltip: "Expand"
1831
- }, React.createElement(Zen, {
1832
- label: "Expand",
1833
- className: styles$5.icon
1834
- })))), showAdditional && React.createElement(Flex, {
1835
- justifyContent: "space-between",
1836
- marginTop: "spacingXs"
1837
- }, React.createElement(Flex, null, React.createElement(AdditionalButtons, { ...props
1838
- }))));
1839
- }
1840
- function ZenMarkdownToolbar(props) {
1841
- return React.createElement("div", {
1842
- className: styles$5.root
1843
- }, React.createElement(Flex, {
1844
- justifyContent: "space-between"
1845
- }, React.createElement(Flex, null, React.createElement(MainButtons, { ...props
1846
- }), React.createElement(AdditionalButtons, { ...props
1847
- })), React.createElement(Flex, null, React.createElement(InsertLinkSelector, {
1848
- disabled: props.disabled,
1849
- onSelectExisting: props.actions.linkExistingMedia,
1850
- onAddNew: props.actions.addNewMedia,
1851
- canAddNew: props.canUploadAssets
1852
- }), React.createElement(IconButton, {
1853
- testId: "markdown-action-button-zen-close",
1854
- variant: "secondary",
1855
- size: "small",
1856
- className: cx(styles$5.zenButton, styles$5.zenButtonPressed),
1857
- onClick: () => {
1858
- props.actions.closeZenMode();
1859
- },
1860
- icon: React.createElement(Zen, {
1861
- label: "Collapse",
1862
- className: styles$5.icon
1863
- }),
1864
- "aria-label": "Collapse"
1865
- }))));
1866
- }
1867
- const MarkdownToolbar = /*#__PURE__*/React.memo(props => {
1868
- if (props.mode === 'zen') {
1869
- return React.createElement(ZenMarkdownToolbar, { ...props
1870
- });
1871
- }
1872
-
1873
- return React.createElement(DefaultMarkdownToolbar, { ...props
1874
- });
1875
- });
1876
- MarkdownToolbar.displayName = 'MarkdownToolbar';
1877
-
1878
- var MarkdownDialogType;
1879
-
1880
- (function (MarkdownDialogType) {
1881
- MarkdownDialogType["cheatsheet"] = "markdown-cheatsheet";
1882
- MarkdownDialogType["insertLink"] = "markdown-insertLink";
1883
- MarkdownDialogType["insertSpecialCharacter"] = "markdown-insertSpecialCharacter";
1884
- MarkdownDialogType["insertTable"] = "markdown-insertTable";
1885
- MarkdownDialogType["embedExternalContent"] = "markdown-embedExternalContent";
1886
- MarkdownDialogType["confirmInsertAsset"] = "markdown-confirmInsertAsset";
1887
- MarkdownDialogType["zenMode"] = "markdown-zenMode";
1888
- })(MarkdownDialogType || (MarkdownDialogType = {}));
1889
-
1890
- const styles$6 = {
1891
- flexColumnContainer: /*#__PURE__*/css({
1892
- display: 'flex',
1893
- flexWrap: 'nowrap'
1894
- }),
1895
- flexColumn: /*#__PURE__*/css({
1896
- flexGrow: 1
1897
- }),
1898
- verticalDivider: /*#__PURE__*/css({
1899
- borderRight: `1px solid ${tokens.gray500}`,
1900
- paddingRight: tokens.spacing3Xl,
1901
- marginRight: tokens.spacing2Xl
1902
- }),
1903
- preview: /*#__PURE__*/css({
1904
- display: 'inline-block',
1905
- paddingRight: tokens.spacingL,
1906
- width: '50%'
1907
- }),
1908
- unOrderedListPreview: /*#__PURE__*/css({
1909
- listStyleType: 'disc',
1910
- marginLeft: tokens.spacingS
1911
- }),
1912
- orderedListPreview: /*#__PURE__*/css({
1913
- listStyleType: 'decimal',
1914
- marginLeft: tokens.spacingS
1915
- }),
1916
- markup: /*#__PURE__*/css({
1917
- display: 'inline-block',
1918
- color: tokens.gray600,
1919
- paddingLeft: tokens.spacingL,
1920
- width: '50%'
1921
- }),
1922
- h1: /*#__PURE__*/css({
1923
- fontSize: tokens.fontSize2Xl
1924
- }),
1925
- h2: /*#__PURE__*/css({
1926
- fontSize: tokens.fontSizeXl
1927
- }),
1928
- h3: /*#__PURE__*/css({
1929
- fontSize: tokens.fontSizeL
1930
- }),
1931
- helpItem: /*#__PURE__*/css({
1932
- marginBottom: tokens.spacingS,
1933
- display: 'flex',
1934
- alignItems: 'flex-end',
1935
- height: tokens.spacingXl
1936
- }),
1937
- helpLink: /*#__PURE__*/css({
1938
- margin: 'auto'
1939
- }),
1940
- flexRowContainer: /*#__PURE__*/css({
1941
- display: 'flex',
1942
- width: '100%',
1943
- justifyContent: 'center',
1944
- marginTop: tokens.spacingXl
1945
- })
1946
- };
1947
- const CheatsheetModalDialog = () => {
1948
- return React.createElement(ModalContent, {
1949
- testId: "markdown-cheatsheet-dialog-content"
1950
- }, React.createElement("div", {
1951
- className: styles$6.flexColumnContainer
1952
- }, React.createElement("div", {
1953
- className: cx(styles$6.flexColumn, styles$6.verticalDivider)
1954
- }, React.createElement("div", {
1955
- className: styles$6.helpItem
1956
- }, React.createElement(Heading, {
1957
- marginBottom: "none",
1958
- as: "h1",
1959
- className: cx(styles$6.preview, styles$6.h1)
1960
- }, "H1"), React.createElement("div", {
1961
- className: styles$6.markup
1962
- }, "# heading")), React.createElement("div", {
1963
- className: styles$6.helpItem
1964
- }, React.createElement(Heading, {
1965
- marginBottom: "none",
1966
- as: "h2",
1967
- className: cx(styles$6.preview, styles$6.h2)
1968
- }, "H2"), React.createElement("div", {
1969
- className: styles$6.markup
1970
- }, "## heading")), React.createElement("div", {
1971
- className: styles$6.helpItem
1972
- }, React.createElement(Heading, {
1973
- marginBottom: "none",
1974
- as: "h3",
1975
- className: cx(styles$6.preview, styles$6.h3)
1976
- }, "H3"), React.createElement("div", {
1977
- className: styles$6.markup
1978
- }, "### heading")), React.createElement("div", {
1979
- className: styles$6.helpItem
1980
- }, React.createElement("strong", {
1981
- className: styles$6.preview
1982
- }, "bold"), React.createElement("div", {
1983
- className: styles$6.markup
1984
- }, "__text__")), React.createElement("div", {
1985
- className: styles$6.helpItem
1986
- }, React.createElement("em", {
1987
- className: styles$6.preview
1988
- }, "italic"), React.createElement("div", {
1989
- className: styles$6.markup
1990
- }, "*text*")), React.createElement("div", {
1991
- className: styles$6.helpItem
1992
- }, React.createElement("div", {
1993
- className: styles$6.preview
1994
- }, "strikethrough"), React.createElement("div", {
1995
- className: styles$6.markup
1996
- }, "~~text~~")), React.createElement("div", {
1997
- className: styles$6.helpItem
1998
- }, React.createElement(TextLink, {
1999
- as: "button",
2000
- className: styles$6.preview
2001
- }, "Link"), React.createElement("div", {
2002
- className: styles$6.markup
2003
- }, "[text](url)"))), React.createElement("div", {
2004
- className: styles$6.flexColumn
2005
- }, React.createElement("div", {
2006
- className: styles$6.helpItem
2007
- }, React.createElement("div", {
2008
- className: styles$6.preview
2009
- }, "Image"), React.createElement("div", {
2010
- className: styles$6.markup
2011
- }, "![alt-text](url)")), React.createElement("div", {
2012
- className: styles$6.helpItem
2013
- }, React.createElement("div", {
2014
- className: styles$6.preview
2015
- }, "Unordered list"), React.createElement("div", {
2016
- className: styles$6.markup
2017
- }, "* list item")), React.createElement("div", {
2018
- className: styles$6.helpItem
2019
- }, React.createElement("div", {
2020
- className: styles$6.preview
2021
- }, React.createElement("div", null, "Ordered list")), React.createElement("div", {
2022
- className: styles$6.markup
2023
- }, "1. list item")), React.createElement("div", {
2024
- className: styles$6.helpItem
2025
- }, React.createElement("div", {
2026
- className: styles$6.preview
2027
- }, React.createElement("div", null, "Blockquote")), React.createElement("div", {
2028
- className: styles$6.markup
2029
- }, "> quote")), React.createElement("div", {
2030
- className: styles$6.helpItem
2031
- }, React.createElement("div", {
2032
- className: styles$6.preview
2033
- }, "code span"), React.createElement("div", {
2034
- className: styles$6.markup
2035
- }, "`code here`")), React.createElement("div", {
2036
- className: styles$6.helpItem
2037
- }, React.createElement("div", {
2038
- className: styles$6.preview
2039
- }, "code block"), React.createElement("div", {
2040
- className: styles$6.markup
2041
- }, "```code here```")))), React.createElement("div", {
2042
- className: styles$6.flexRowContainer
2043
- }, React.createElement(TextLink, {
2044
- className: styles$6.helpLink,
2045
- href: "https://help.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax",
2046
- target: "_blank",
2047
- rel: "noopener noreferrer"
2048
- }, "View the full GitHub-flavored Markdown syntax help (opens in a new window)")));
2049
- };
2050
- const openCheatsheetModal = dialogs => {
2051
- return dialogs.openCurrent({
2052
- title: 'Markdown formatting help',
2053
- width: 'large',
2054
- minHeight: '415px',
2055
- shouldCloseOnEscapePress: true,
2056
- shouldCloseOnOverlayClick: true,
2057
- parameters: {
2058
- type: MarkdownDialogType.cheatsheet
2059
- }
2060
- });
2061
- };
2062
-
2063
- const ConfirmInsertAssetModalDialog = ({
2064
- onClose,
2065
- assets,
2066
- locale
2067
- }) => {
2068
- const localesNumber = assets.length;
2069
- return React.createElement(React.Fragment, null, React.createElement(ModalContent, {
2070
- testId: "confirm-insert-asset"
2071
- }, React.createElement(Paragraph, null, localesNumber === 1 ? `Link asset with missing file for locale ${locale}` : `Link assets with missing files for locale ${locale}`), React.createElement(Paragraph, null, localesNumber === 1 ? 'Do you want to link to the file in its fallback locale?' : 'Do you want to link to the files in their fallback locales?'), React.createElement(EntityList, null, assets.map(({
2072
- title,
2073
- description,
2074
- thumbnailUrl,
2075
- thumbnailAltText
2076
- }) => React.createElement(EntityList.Item, {
2077
- key: thumbnailUrl,
2078
- title: title,
2079
- thumbnailUrl: `${thumbnailUrl}?w=46&h=46&fit=thumb`,
2080
- thumbnailAltText: thumbnailAltText,
2081
- description: description
2082
- })))), React.createElement(ModalControls, null, React.createElement(Button, {
2083
- onClick: () => onClose(false),
2084
- variant: "secondary",
2085
- size: "small"
2086
- }, "Cancel"), React.createElement(Button, {
2087
- testId: "confirm-insert-asset",
2088
- onClick: () => onClose(true),
2089
- variant: "positive",
2090
- size: "small"
2091
- }, "Confirm")));
2092
- };
2093
- const openConfirmInsertAsset = (dialogs, options) => {
2094
- return dialogs.openCurrent({
2095
- title: 'Confirm using fallback assets',
2096
- width: 'medium',
2097
- minHeight: '270px',
2098
- shouldCloseOnEscapePress: true,
2099
- shouldCloseOnOverlayClick: true,
2100
- parameters: {
2101
- type: MarkdownDialogType.confirmInsertAsset,
2102
- ...options
2103
- }
2104
- });
2105
- };
2106
-
2107
- const urlRegex = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?$/;
2108
- function isValidUrl(value) {
2109
- return urlRegex.test(value);
2110
- }
2111
-
2112
- const styles$7 = {
2113
- widthFiledGroup: /*#__PURE__*/css({
2114
- display: 'flex',
2115
- flexWrap: 'nowrap',
2116
- alignItems: 'flex-start'
2117
- }),
2118
- radioButtonGroup: /*#__PURE__*/css({
2119
- display: 'inline-flex',
2120
- alignItems: 'flex-start',
2121
- paddingTop: tokens.spacingXl
2122
- }),
2123
- radioButton: /*#__PURE__*/css({
2124
- marginLeft: tokens.spacingM
2125
- })
2126
- };
2127
-
2128
- const makeEmbedlyLink = ({
2129
- url,
2130
- width,
2131
- selectedUnit,
2132
- attachSocial
2133
- }) => {
2134
- const s = {
2135
- percent: '%',
2136
- px: 'px'
2137
- };
2138
- return ['<a href="' + url + '" class="embedly-card" ', 'data-card-width="' + width + s[selectedUnit] + '" ', 'data-card-controls="' + (attachSocial ? '1' : '0') + '"', '>Embedded content: ' + url + '</a>'].join('');
2139
- };
2140
-
2141
- const isWidthValid = (width, unit) => unit === 'percent' ? width <= 100 : true;
2142
-
2143
- const EmbedExternalContentModal = ({
2144
- onClose
2145
- }) => {
2146
- const mainInputRef = useRef(null);
2147
- const [url, setUrl] = useState('https://');
2148
- const [selectedUnit, setUnit] = useState('percent');
2149
- const [urlIsValid, setUrlValidity] = useState(true);
2150
- const [width, setWidth] = useState('100');
2151
- const [attachSocial, setAttachSocial] = useState(false);
2152
- useEffect(() => {
2153
- var _mainInputRef$current;
2154
-
2155
- if ((_mainInputRef$current = mainInputRef.current) != null && _mainInputRef$current.focus) {
2156
- mainInputRef.current.focus();
2157
- }
2158
- }, [mainInputRef]);
2159
- return React.createElement(React.Fragment, null, React.createElement(ModalContent, {
2160
- testId: "embed-external-dialog"
2161
- }, React.createElement(Form, null, React.createElement(FormControl, {
2162
- id: "external-link-url-field",
2163
- isRequired: true,
2164
- isInvalid: !urlIsValid
2165
- }, React.createElement(FormControl.Label, null, "Content URL"), React.createElement(TextInput, {
2166
- name: "external-link-url",
2167
- value: url,
2168
- onChange: e => {
2169
- const value = e.target.value;
2170
- setUrl(value);
2171
- setUrlValidity(isValidUrl(value));
2172
- },
2173
- testId: "external-link-url-field",
2174
- placeholder: "https://example.com",
2175
- ref: mainInputRef
2176
- }), React.createElement(FormControl.HelpText, null, "Include protocol (e.g. https://)"), !urlIsValid && React.createElement(FormControl.ValidationMessage, null, "URL is invalid")), React.createElement(TextLink, {
2177
- href: "http://embed.ly/providers",
2178
- target: "_blank",
2179
- rel: "noopener noreferrer"
2180
- }, "Supported sources"), React.createElement("div", {
2181
- className: styles$7.widthFiledGroup
2182
- }, React.createElement(FormControl, {
2183
- id: "embedded-content-width",
2184
- isRequired: true,
2185
- isInvalid: !isWidthValid(Number(width), selectedUnit)
2186
- }, React.createElement(FormControl.Label, null, "Width"), React.createElement(TextInput, {
2187
- value: width,
2188
- name: "embedded-content-width",
2189
- testId: "embedded-content-width",
2190
- type: "number",
2191
- width: "small",
2192
- onChange: e => setWidth(e.target.value)
2193
- }), !isWidthValid(Number(width), selectedUnit) && React.createElement(FormControl.ValidationMessage, null, "Should be equal or less then 100")), React.createElement("div", {
2194
- className: styles$7.radioButtonGroup
2195
- }, React.createElement(Radio, {
2196
- id: "unit-option-percent",
2197
- value: "percent",
2198
- isChecked: selectedUnit === 'percent',
2199
- onChange: () => setUnit('percent'),
2200
- className: styles$7.radioButton
2201
- }, "percent"), React.createElement(Radio, {
2202
- id: "unit-option-pixels",
2203
- value: "pixels",
2204
- isChecked: selectedUnit === 'px',
2205
- onChange: () => setUnit('px'),
2206
- className: styles$7.radioButton
2207
- }, "pixels"))), React.createElement(Checkbox, {
2208
- id: "attach-social-checkbox",
2209
- name: "attach-social-checkbox",
2210
- value: "Yes",
2211
- isChecked: attachSocial,
2212
- onChange: () => setAttachSocial(!attachSocial),
2213
- testId: "attach-social-checkbox"
2214
- }, "Attach social sharing links to this element"), React.createElement(Text, {
2215
- as: "p",
2216
- fontColor: "gray500",
2217
- marginTop: "spacingXs"
2218
- }, "To enable this embedded content in your application make sure to add the\u00A0", React.createElement(TextLink, {
2219
- href: "http://embed.ly/docs/products/cards",
2220
- target: "_blank",
2221
- rel: "noopener noreferrer"
2222
- }, "Embedly's platform.js"), "\u00A0on your development environment"))), React.createElement(ModalControls, null, React.createElement(Button, {
2223
- testId: "emded-external-cancel",
2224
- onClick: () => onClose(false),
2225
- variant: "secondary",
2226
- size: "small"
2227
- }, "Cancel"), React.createElement(Button, {
2228
- testId: "embed-external-confirm",
2229
- onClick: () => onClose(makeEmbedlyLink({
2230
- url,
2231
- width: Number(width),
2232
- selectedUnit,
2233
- attachSocial
2234
- })),
2235
- variant: "positive",
2236
- size: "small"
2237
- }, "Insert")));
2238
- };
2239
- const openEmbedExternalContentDialog = dialogs => {
2240
- return dialogs.openCurrent({
2241
- title: 'Embed external content',
2242
- width: 'large',
2243
- minHeight: '435px',
2244
- shouldCloseOnEscapePress: true,
2245
- shouldCloseOnOverlayClick: true,
2246
- parameters: {
2247
- type: MarkdownDialogType.embedExternalContent
2248
- }
2249
- });
2250
- };
2251
-
2252
- const InsertLinkModal = ({
2253
- selectedText,
2254
- onClose
2255
- }) => {
2256
- const mainInputRef = useRef(null);
2257
- const [text, setText] = useState(selectedText || '');
2258
- const [url, setUrl] = useState('');
2259
- const [touched, setTouched] = useState(false);
2260
- const [title, setTitle] = useState('');
2261
-
2262
- const onInsert = values => onClose(values);
2263
-
2264
- const urlIsValid = isValidUrl(url);
2265
- useEffect(() => {
2266
- var _mainInputRef$current;
2267
-
2268
- if (mainInputRef != null && (_mainInputRef$current = mainInputRef.current) != null && _mainInputRef$current.focus) {
2269
- mainInputRef.current.focus();
2270
- }
2271
- }, [mainInputRef]);
2272
- return React.createElement(React.Fragment, null, React.createElement(ModalContent, {
2273
- testId: "insert-link-modal"
2274
- }, React.createElement(Form, {
2275
- onSubmit: () => onInsert({
2276
- url,
2277
- text,
2278
- title
2279
- })
2280
- }, React.createElement(FormControl, {
2281
- id: "link-text-field",
2282
- isDisabled: Boolean(selectedText)
2283
- }, React.createElement(FormControl.Label, null, "Link text"), React.createElement(TextInput, {
2284
- name: "link-text",
2285
- value: text,
2286
- onChange: e => {
2287
- setText(e.target.value);
2288
- },
2289
- testId: "link-text-field"
2290
- })), React.createElement(FormControl, {
2291
- id: "target-url-field",
2292
- isInvalid: touched && !urlIsValid
2293
- }, React.createElement(FormControl.Label, null, "Target URL"), React.createElement(TextInput, {
2294
- name: "target-url",
2295
- value: url,
2296
- onChange: e => {
2297
- setUrl(e.target.value);
2298
- setTouched(true);
2299
- },
2300
- placeholder: "https://",
2301
- maxLength: 2100,
2302
- testId: "target-url-field",
2303
- ref: mainInputRef
2304
- }), React.createElement(FormControl.HelpText, null, "Include protocol (e.g. https://)"), touched && !urlIsValid && React.createElement(FormControl.ValidationMessage, null, "Invalid URL")), React.createElement(FormControl, {
2305
- id: "link-title-field"
2306
- }, React.createElement(FormControl.Label, null, "Link title"), React.createElement(TextInput, {
2307
- name: "link-title",
2308
- value: title,
2309
- onChange: e => {
2310
- setTitle(e.target.value);
2311
- },
2312
- testId: "link-title-field"
2313
- }), React.createElement(FormControl.HelpText, null, "Extra link information, usually shown as a tooltip on mouse hover")))), React.createElement(ModalControls, null, React.createElement(Button, {
2314
- testId: "insert-link-cancel",
2315
- onClick: () => onClose(false),
2316
- variant: "secondary",
2317
- size: "small"
2318
- }, "Cancel"), React.createElement(Button, {
2319
- testId: "insert-link-confirm",
2320
- onClick: () => {
2321
- onInsert({
2322
- url,
2323
- text,
2324
- title
2325
- });
2326
- },
2327
- isDisabled: !urlIsValid,
2328
- variant: "positive",
2329
- size: "small"
2330
- }, "Insert")));
2331
- };
2332
- const openInsertLinkDialog = (dialogs, params) => {
2333
- return dialogs.openCurrent({
2334
- title: 'Insert link',
2335
- width: 'large',
2336
- minHeight: '410px',
2337
- shouldCloseOnEscapePress: true,
2338
- shouldCloseOnOverlayClick: true,
2339
- parameters: {
2340
- type: MarkdownDialogType.insertLink,
2341
- ...params
2342
- }
2343
- });
2344
- };
2345
-
2346
- const InsertTableModal = ({
2347
- onClose
2348
- }) => {
2349
- const mainInputRef = useRef(null);
2350
- const [rows, setRows] = useState(2);
2351
- const [cols, setColumns] = useState(1);
2352
- const rowsAreValid = inRange(rows, 2, 100);
2353
- const colsAreValid = inRange(cols, 1, 100);
2354
- useEffect(() => {
2355
- var _mainInputRef$current;
2356
-
2357
- if ((_mainInputRef$current = mainInputRef.current) != null && _mainInputRef$current.focus) {
2358
- mainInputRef.current.focus();
2359
- }
2360
- }, [mainInputRef]);
2361
- return React.createElement(React.Fragment, null, React.createElement(ModalContent, {
2362
- testId: "insert-table-modal"
2363
- }, React.createElement(Form, null, React.createElement(FormControl, {
2364
- id: "insert-table-rows-number-field",
2365
- isRequired: true,
2366
- isInvalid: !rowsAreValid
2367
- }, React.createElement(FormControl.Label, null, "Number of rows"), React.createElement(TextInput, {
2368
- name: "rows",
2369
- value: rows.toString(),
2370
- onChange: e => setRows(Number(e.target.value)),
2371
- testId: "insert-table-rows-number-field",
2372
- min: 2,
2373
- max: 100,
2374
- pattern: "[1-9][0-9]*",
2375
- type: "number",
2376
- width: "small",
2377
- autoComplete: "off",
2378
- ref: mainInputRef
2379
- }), !rowsAreValid && React.createElement(FormControl.ValidationMessage, null, "Should be between 2 and 100")), React.createElement(FormControl, {
2380
- id: "insert-table-columns-number-field",
2381
- isRequired: true,
2382
- isInvalid: !colsAreValid
2383
- }, React.createElement(FormControl.Label, null, "Number of columns"), React.createElement(TextInput, {
2384
- name: "columns",
2385
- value: cols.toString(),
2386
- onChange: e => setColumns(Number(e.target.value)),
2387
- testId: "insert-table-columns-number-field",
2388
- min: 1,
2389
- max: 100,
2390
- pattern: "[1-9][0-9]*",
2391
- type: "number",
2392
- width: "small",
2393
- autoComplete: "off"
2394
- }), !colsAreValid && React.createElement(FormControl.ValidationMessage, null, "Should be between 1 and 100")))), React.createElement(ModalControls, null, React.createElement(Button, {
2395
- testId: "insert-table-cancel",
2396
- onClick: () => onClose(false),
2397
- variant: "secondary",
2398
- size: "small"
2399
- }, "Cancel"), React.createElement(Button, {
2400
- testId: "insert-table-confirm",
2401
- onClick: () => onClose({
2402
- rows,
2403
- cols
2404
- }),
2405
- variant: "positive",
2406
- size: "small",
2407
- isDisabled: !rowsAreValid || !colsAreValid
2408
- }, "Insert")));
2409
- };
2410
- const openInsertTableDialog = dialogs => {
2411
- return dialogs.openCurrent({
2412
- title: 'Insert table',
2413
- width: 'medium',
2414
- minHeight: '260px',
2415
- shouldCloseOnEscapePress: true,
2416
- shouldCloseOnOverlayClick: true,
2417
- parameters: {
2418
- type: MarkdownDialogType.insertTable
2419
- }
2420
- });
2421
- };
2422
-
2423
- const specialCharacters = [{
2424
- code: 180,
2425
- desc: 'acute accent'
2426
- }, {
2427
- code: 38,
2428
- desc: 'ampersand'
2429
- }, {
2430
- code: 166,
2431
- desc: 'broken vertical bar'
2432
- }, {
2433
- code: 8226,
2434
- desc: 'bullet'
2435
- }, {
2436
- code: 184,
2437
- desc: 'cedilla'
2438
- }, {
2439
- code: 162,
2440
- desc: 'cent'
2441
- }, {
2442
- code: 169,
2443
- desc: 'copyright'
2444
- }, {
2445
- code: 176,
2446
- desc: 'degree'
2447
- }, {
2448
- code: 247,
2449
- desc: 'division'
2450
- }, {
2451
- code: 189,
2452
- desc: 'fraction half'
2453
- }, {
2454
- code: 188,
2455
- desc: 'fraction quarter'
2456
- }, {
2457
- code: 190,
2458
- desc: 'fraction three quarters'
2459
- }, {
2460
- code: 62,
2461
- desc: 'greater than'
2462
- }, {
2463
- code: 161,
2464
- desc: 'inverted exclamation mark'
2465
- }, {
2466
- code: 191,
2467
- desc: 'inverted question mark'
2468
- }, {
2469
- code: 171,
2470
- desc: 'left-pointing double angle quotation mark'
2471
- }, {
2472
- code: 60,
2473
- desc: 'less than'
2474
- }, {
2475
- code: 175,
2476
- desc: 'macron'
2477
- }, {
2478
- code: 181,
2479
- desc: 'micro'
2480
- }, {
2481
- code: 160,
2482
- desc: 'non-breaking space'
2483
- }, {
2484
- code: 172,
2485
- desc: 'not'
2486
- }, {
2487
- code: 182,
2488
- desc: 'paragraph'
2489
- }, {
2490
- code: 177,
2491
- desc: 'plus-minus'
2492
- }, {
2493
- code: 34,
2494
- desc: 'quotation mark'
2495
- }, {
2496
- code: 174,
2497
- desc: 'registered'
2498
- }, {
2499
- code: 187,
2500
- desc: 'right-pointing double angle quotation mark'
2501
- }, {
2502
- code: 167,
2503
- desc: 'section'
2504
- }, {
2505
- code: 168,
2506
- desc: 'umlaut/diaeresis'
2507
- }, {
2508
- code: 215,
2509
- desc: 'multiplication'
2510
- }, {
2511
- code: 8482,
2512
- desc: 'trade mark'
2513
- }, {
2514
- code: 8364,
2515
- desc: 'euro'
2516
- }, {
2517
- code: 163,
2518
- desc: 'pound'
2519
- }, {
2520
- code: 165,
2521
- desc: 'yen'
2522
- }, {
2523
- code: 8222,
2524
- desc: 'double low-9 quotation mark'
2525
- }, {
2526
- code: 710,
2527
- desc: 'modifier circumflex accent'
2528
- }, {
2529
- code: 8224,
2530
- desc: 'dagger'
2531
- }, {
2532
- code: 8225,
2533
- desc: 'double dagger'
2534
- }, {
2535
- code: 8230,
2536
- desc: 'horizontal ellipsis'
2537
- }, {
2538
- code: 8220,
2539
- desc: 'left double quotation mark'
2540
- }, {
2541
- code: 8249,
2542
- desc: 'single left-pointing angle quotation mark'
2543
- }, {
2544
- code: 8216,
2545
- desc: 'left single quotation mark'
2546
- }, {
2547
- code: 183,
2548
- desc: 'middle dot'
2549
- }, {
2550
- code: 8212,
2551
- desc: 'em dash'
2552
- }, {
2553
- code: 8211,
2554
- desc: 'en dash'
2555
- }, {
2556
- code: 8240,
2557
- desc: 'per mille'
2558
- }, {
2559
- code: 8250,
2560
- desc: 'single right-pointing angle quotation mark'
2561
- }, {
2562
- code: 8217,
2563
- desc: 'right single quotation mark'
2564
- }, {
2565
- code: 8218,
2566
- desc: 'single low-9 quotation mark'
2567
- }, {
2568
- code: 170,
2569
- desc: 'feminine ordinal indicator'
2570
- }, {
2571
- code: 186,
2572
- desc: 'masculine ordinal indicator'
2573
- }, {
2574
- code: 8221,
2575
- desc: 'right double quotation mark'
2576
- }, {
2577
- code: 732,
2578
- desc: 'small tilde'
2579
- }, {
2580
- code: 9829,
2581
- desc: 'black heart'
2582
- }, {
2583
- code: 9830,
2584
- desc: 'diamond'
2585
- }];
2586
-
2587
- const styles$8 = {
2588
- buttonPanel: /*#__PURE__*/css({
2589
- display: 'flex',
2590
- flexWrap: 'wrap'
2591
- }),
2592
- charButton: /*#__PURE__*/css({
2593
- border: `1px solid ${tokens.gray500}`,
2594
- width: '4.1rem',
2595
- height: '4.1rem',
2596
- fontSize: tokens.fontSizeXl,
2597
- marginTop: tokens.spacing2Xs,
2598
- marginRight: tokens.spacing2Xs
2599
- }),
2600
- selectedCharButton: /*#__PURE__*/css({
2601
- backgroundColor: tokens.gray100
2602
- }),
2603
- tooltip: /*#__PURE__*/css({
2604
- zIndex: 1000
2605
- }),
2606
- button: /*#__PURE__*/css({
2607
- marginTop: tokens.spacingM,
2608
- marginRight: tokens.spacingS
2609
- })
2610
- };
2611
- const SpecialCharacterModalDialog = ({
2612
- onClose
2613
- }) => {
2614
- const [selectedCharacter, setSelectedCharacter] = useState(specialCharacters[0]);
2615
- return React.createElement(React.Fragment, null, React.createElement(ModalContent, {
2616
- testId: "insert-special-character-modal"
2617
- }, React.createElement(Flex, {
2618
- flexDirection: "column",
2619
- alignItems: "center"
2620
- }, React.createElement(Text, {
2621
- as: "div",
2622
- lineHeight: "lineHeight3Xl",
2623
- fontSize: "fontSize3Xl",
2624
- marginBottom: "spacingS"
2625
- }, String.fromCharCode(selectedCharacter.code)), React.createElement(Text, {
2626
- as: "div",
2627
- marginBottom: "spacingS"
2628
- }, selectedCharacter.desc)), React.createElement("div", {
2629
- className: styles$8.buttonPanel
2630
- }, specialCharacters.map(char => React.createElement("div", {
2631
- key: char.code
2632
- }, React.createElement(Tooltip, {
2633
- className: styles$8.tooltip,
2634
- content: char.desc
2635
- }, React.createElement(Button, {
2636
- testId: "special-character-button",
2637
- isActive: char.code === selectedCharacter.code,
2638
- className: styles$8.charButton,
2639
- variant: "transparent",
2640
- onClick: () => setSelectedCharacter(char)
2641
- }, String.fromCharCode(char.code))))))), React.createElement(ModalControls, null, React.createElement(Button, {
2642
- testId: "insert-character-cancel",
2643
- className: styles$8.button,
2644
- onClick: () => onClose(false),
2645
- variant: "secondary",
2646
- size: "small"
2647
- }, "Cancel"), React.createElement(Button, {
2648
- className: styles$8.button,
2649
- testId: "insert-character-confirm",
2650
- onClick: () => onClose(String.fromCharCode(selectedCharacter.code)),
2651
- variant: "positive",
2652
- size: "small"
2653
- }, "Insert selected")));
2654
- };
2655
- const openInsertSpecialCharacter = dialogs => {
2656
- return dialogs.openCurrent({
2657
- title: 'Insert special character',
2658
- width: 'large',
2659
- minHeight: '600px',
2660
- shouldCloseOnEscapePress: true,
2661
- shouldCloseOnOverlayClick: true,
2662
- parameters: {
2663
- type: MarkdownDialogType.insertSpecialCharacter
2664
- }
2665
- });
2666
- };
2667
-
2668
- const styles$9 = {
2669
- root: /*#__PURE__*/css({
2670
- position: 'fixed',
2671
- left: 0,
2672
- right: 0,
2673
- top: 0,
2674
- bottom: 0
2675
- }),
2676
- topSplit: /*#__PURE__*/css({
2677
- position: 'fixed',
2678
- top: 0,
2679
- height: '48px',
2680
- left: 0,
2681
- right: 0
2682
- }),
2683
- bottomSplit: /*#__PURE__*/css({
2684
- position: 'fixed',
2685
- bottom: 0,
2686
- left: 0,
2687
- right: 0,
2688
- height: '36px'
2689
- }),
2690
- editorSplit: /*#__PURE__*/css({
2691
- width: '50%',
2692
- position: 'fixed',
2693
- top: '48px',
2694
- left: 0,
2695
- bottom: '36px',
2696
- overflowX: 'hidden',
2697
- overflowY: 'scroll'
2698
- }),
2699
- editorSplitFullscreen: /*#__PURE__*/css({
2700
- left: 0,
2701
- right: 0,
2702
- width: '100%'
2703
- }),
2704
- previewSplit: /*#__PURE__*/css({
2705
- width: '50%',
2706
- position: 'fixed',
2707
- top: '48px',
2708
- right: 0,
2709
- bottom: '36px',
2710
- overflowX: 'hidden',
2711
- overflowY: 'scroll'
2712
- }),
2713
- separator: /*#__PURE__*/css({
2714
- position: 'fixed',
2715
- top: '48px',
2716
- bottom: '36px',
2717
- width: '1px',
2718
- background: tokens.gray400,
2719
- left: '50%'
2720
- }),
2721
- button: /*#__PURE__*/css({
2722
- position: 'fixed',
2723
- cursor: 'pointer',
2724
- zIndex: 105,
2725
- top: '49%',
2726
- height: '30px',
2727
- backgroundColor: tokens.gray100,
2728
- border: `1px solid ${tokens.gray400}`,
2729
- padding: 0
2730
- }),
2731
- hideButton: /*#__PURE__*/css({
2732
- left: '50%'
2733
- }),
2734
- showButton: /*#__PURE__*/css({
2735
- right: 0,
2736
- borderRightWidth: 0
2737
- }),
2738
- icon: /*#__PURE__*/css({
2739
- verticalAlign: 'middle'
2740
- })
2741
- };
2742
- const ZenModeModalDialog = props => {
2743
- const [currentValue, setCurrentValue] = React.useState(props.initialValue ?? '');
2744
- const [showPreview, setShowPreview] = React.useState(true);
2745
- const [editor, setEditor] = React.useState(null);
2746
- React.useEffect(() => {
2747
- var _props$sdk, _props$sdk$window;
2748
-
2749
- // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
2750
- (_props$sdk = props.sdk) == null ? void 0 : (_props$sdk$window = _props$sdk.window) == null ? void 0 : _props$sdk$window.updateHeight('100%'); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
2751
- }, []); // refresh editor right after dialog is opened to avoid disappearing effect
2752
-
2753
- React.useEffect(() => {
2754
- setTimeout(() => {
2755
- editor == null ? void 0 : editor.setFullsize();
2756
- editor == null ? void 0 : editor.refresh();
2757
- }, 150);
2758
- }, [editor]);
2759
- const actions = React.useMemo(() => {
2760
- return createMarkdownActions({
2761
- sdk: props.sdk,
2762
- editor,
2763
- locale: props.locale
2764
- }); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
2765
- }, [editor]);
2766
-
2767
- actions.closeZenMode = () => {
2768
- props.onClose({
2769
- value: currentValue,
2770
- cursor: editor == null ? void 0 : editor.getCursor()
2771
- });
2772
- };
2773
-
2774
- const direction = props.sdk.locales.direction[props.locale] ?? 'ltr';
2775
- return React.createElement("div", {
2776
- className: styles$9.root,
2777
- "data-test-id": "zen-mode-markdown-editor"
2778
- }, React.createElement("div", {
2779
- className: styles$9.topSplit
2780
- }, React.createElement(MarkdownToolbar, {
2781
- mode: "zen",
2782
- disabled: false,
2783
- canUploadAssets: false,
2784
- actions: actions
2785
- })), React.createElement("div", {
2786
- className: cx(styles$9.editorSplit, {
2787
- [styles$9.editorSplitFullscreen]: showPreview === false
2788
- })
2789
- }, React.createElement(MarkdownTextarea, {
2790
- mode: "zen",
2791
- visible: true,
2792
- disabled: false,
2793
- direction: direction,
2794
- onReady: editor => {
2795
- editor.setContent(props.initialValue ?? '');
2796
- editor.setReadOnly(false);
2797
- setEditor(editor);
2798
- editor.focus();
2799
- editor.events.onChange(value => {
2800
- setCurrentValue(value);
2801
- props.saveValueToSDK(value);
2802
- });
2803
- }
2804
- })), showPreview && React.createElement("div", {
2805
- className: styles$9.previewSplit
2806
- }, React.createElement(MarkdownPreview, {
2807
- direction: direction,
2808
- mode: "zen",
2809
- value: currentValue,
2810
- previewComponents: props.previewComponents
2811
- })), showPreview && React.createElement("div", {
2812
- className: styles$9.separator
2813
- }), showPreview && React.createElement("button", {
2814
- className: cx(styles$9.button, styles$9.hideButton),
2815
- "aria-label": "Hide preview",
2816
- onClick: () => {
2817
- setShowPreview(false);
2818
- }
2819
- }, React.createElement(ChevronRightIcon, {
2820
- variant: "muted",
2821
- size: "tiny",
2822
- className: styles$9.icon
2823
- })), !showPreview && React.createElement("button", {
2824
- className: cx(styles$9.button, styles$9.showButton),
2825
- "aria-label": "Show preview",
2826
- onClick: () => {
2827
- setShowPreview(true);
2828
- }
2829
- }, React.createElement(ChevronLeftIcon, {
2830
- variant: "muted",
2831
- size: "tiny",
2832
- className: styles$9.icon
2833
- })), React.createElement("div", {
2834
- className: styles$9.bottomSplit
2835
- }, React.createElement(MarkdownBottomBar, null, React.createElement(MarkdownHelp, {
2836
- onClick: () => {
2837
- openCheatsheetModal(props.sdk.dialogs);
2838
- }
2839
- }))));
2840
- };
2841
- const openZenMode = (dialogs, options) => {
2842
- return dialogs.openCurrent({
2843
- width: 'zen',
2844
- shouldCloseOnEscapePress: false,
2845
- minHeight: '100vh',
2846
- shouldCloseOnOverlayClick: false,
2847
- parameters: {
2848
- type: MarkdownDialogType.zenMode,
2849
- initialValue: options.initialValue,
2850
- locale: options.locale
2851
- }
2852
- });
2853
- };
2854
-
2855
- function normalizeWhiteSpace(str) {
2856
- if (str) {
2857
- return str.trim().replace(/\s{2,}/g, ' ');
2858
- } else {
2859
- return str;
2860
- }
2861
- }
2862
-
2863
- function removeExtension(str) {
2864
- return str.replace(/\.\w+$/g, '');
2865
- }
2866
-
2867
- function fileNameToTitle(str) {
2868
- return normalizeWhiteSpace(removeExtension(str).replace(/_/g, ' '));
2869
- }
2870
-
2871
- function replaceAssetDomain(fileUrl) {
2872
- const assetDomainMap = {
2873
- images: 'images.ctfassets.net',
2874
- assets: 'assets.ctfassets.net',
2875
- downloads: 'downloads.ctfassets.net',
2876
- videos: 'videos.ctfassets.net'
2877
- };
2878
- return fileUrl.replace(/(images|assets|downloads|videos).contentful.com/, (_, p1) => {
2879
- return assetDomainMap[p1];
2880
- });
2881
- }
2882
-
2883
- function makeAssetLink(asset, {
2884
- localeCode,
2885
- fallbackCode,
2886
- defaultLocaleCode
2887
- }) {
2888
- const localizedFile = get(asset, ['fields', 'file', localeCode]);
2889
- const fallbackFile = fallbackCode ? get(asset, ['fields', 'file', fallbackCode]) : null;
2890
- const defaultFile = get(asset, ['fields', 'file', defaultLocaleCode]);
2891
- const file = localizedFile || fallbackFile || defaultFile;
2892
-
2893
- if (isObject(file) && file.url) {
2894
- const title = get(asset, ['fields', 'title', localeCode]) || get(asset, ['fields', 'title', fallbackCode || '']) || get(asset, ['fields', 'title', defaultLocaleCode]) || fileNameToTitle(file.fileName);
2895
- const fileUrl = replaceAssetDomain(file.url);
2896
- return {
2897
- title,
2898
- asset,
2899
- url: fileUrl,
2900
- // is normally localized and we should not warn about this file
2901
- isLocalized: Boolean(localizedFile),
2902
- // was fallback value used
2903
- // if it was not localized normally, and we did not used a fallback
2904
- // it means we used a default locale - we filter empty values
2905
- isFallback: Boolean(fallbackFile),
2906
- // todo: tranform using fromHostname
2907
- asMarkdown: `![${title}](${fileUrl})`
2908
- };
2909
- } else {
2910
- return null;
2911
- }
2912
- }
2913
-
2914
- async function insertAssetLinks(assets, locales) {
2915
- // check whether do we have some assets, which don't have
2916
- // a version in this field's locale
2917
- const otherLocales = assets.filter(asset => {
2918
- return !get(asset, ['fields', 'file', locales.localeCode]);
2919
- });
2920
- const linksWithMeta = assets.map(asset => makeAssetLink(asset, locales)) // remove empty links
2921
- .filter(asset => asset !== null); // if there have values from fallback/default locales, we need to
2922
- // provide user a warning so we show him modal
2923
-
2924
- if (otherLocales.length > 0) {
2925
- const fallbackAssets = linksWithMeta // we don't want to warn about normally localized files
2926
- .filter(({
2927
- isLocalized
2928
- }) => !isLocalized).map(({
2929
- title,
2930
- isFallback,
2931
- asset
2932
- }) => {
2933
- const code = isFallback ? locales.fallbackCode : locales.defaultLocaleCode;
2934
- return {
2935
- title,
2936
- thumbnailUrl: asset.fields.file[code].url,
2937
- thumbnailAltText: title,
2938
- description: isFallback ? `Fallback locale (${code})` : `Default locale (${code})`,
2939
- asset: asset
2940
- };
2941
- });
2942
- return {
2943
- fallbacks: fallbackAssets,
2944
- links: linksWithMeta
2945
- };
2946
- }
2947
-
2948
- return {
2949
- links: linksWithMeta
2950
- };
2951
- }
2952
-
2953
- /* eslint-disable @typescript-eslint/no-use-before-define, @typescript-eslint/no-explicit-any */
2954
-
2955
- function extractTitle(title) {
2956
- title = title || '';
2957
- title = title.replace(/^ *('|"|\()*/, '');
2958
- title = title.replace(/('|"|\))* *$/, '');
2959
- return title;
2960
- }
2961
-
2962
- function head(text) {
2963
- return text.split(' ').shift();
2964
- }
2965
-
2966
- function tail(text) {
2967
- const segments = text.split(' ');
2968
- segments.shift();
2969
- return segments.join(' ');
2970
- }
2971
-
2972
- const PROCESSORS = {
2973
- inline: function (match) {
2974
- return {
2975
- match: match[0],
2976
- text: match[1],
2977
- href: head(match[2]),
2978
- title: extractTitle(tail(match[2]))
2979
- };
2980
- },
2981
- ref: function (match) {
2982
- return {
2983
- match: match[0],
2984
- text: match[1],
2985
- id: match[2]
2986
- };
2987
- },
2988
- label: function (match) {
2989
- return {
2990
- match: match[0],
2991
- id: match[1],
2992
- href: head(match[2]),
2993
- title: extractTitle(tail(match[2]))
2994
- };
2995
- }
2996
- };
2997
- const REGEXS = {
2998
- inline: /\[([^\r\n[\]]+)]\(([^\r\n)]+)\)/,
2999
- ref: /\[([^\r\n[\]]+)] ?\[([^\r\n[\]]+)]/,
3000
- label: /^ {0,3}\[([^\r\n[\]]+)]:\s+(.+)$/
3001
- };
3002
- const findInline = /*#__PURE__*/makeFinder('inline');
3003
- const findRefs = /*#__PURE__*/makeFinder('ref');
3004
- const findLabels = /*#__PURE__*/makeFinder('label');
3005
- function convertInlineToRef(text) {
3006
- let id = findMaxLabelId(text);
3007
- forEach(findInline(text), inline => {
3008
- id += 1;
3009
- text = text.replace(inline.match, buildRef(inline, id));
3010
- text += '\n' + buildLabel(inline, id);
3011
- });
3012
- return text;
3013
- }
3014
-
3015
- function mergeLabels(text) {
3016
- const byHref = {};
3017
- const byOldId = {};
3018
- forEach(findLabels(text), label => {
3019
- const alreadyAdded = byHref[label.href];
3020
- const current = extend({}, label);
3021
-
3022
- if (!alreadyAdded) {
3023
- byHref[current.href] = current;
3024
- } else if (hasTitle(current) && !hasTitle(alreadyAdded)) {
3025
- alreadyAdded.title = current.title;
3026
- }
3027
-
3028
- byOldId[current.id] = alreadyAdded || current;
3029
- });
3030
- return {
3031
- byHref: byHref,
3032
- byOldId: byOldId
3033
- };
3034
- }
3035
-
3036
- function rewriteRefs(text) {
3037
- const merged = mergeLabels(text);
3038
- const hrefToRefId = {};
3039
- const labels = [];
3040
- const rewrites = [];
3041
- let i = 1; // 1. compose list of labels with new ids, in order
3042
-
3043
- forEach(findRefs(text), ref => {
3044
- const oldLabel = merged.byOldId[ref.id];
3045
-
3046
- if (!oldLabel) {
3047
- return;
3048
- }
3049
-
3050
- const href = oldLabel.href;
3051
- let newRefId = hrefToRefId[href];
3052
-
3053
- if (!newRefId) {
3054
- hrefToRefId[href] = newRefId = i;
3055
- i += 1;
3056
- labels.push(extend({
3057
- newId: newRefId
3058
- }, oldLabel));
3059
- } // 1b. prepare rewrites to be applied, with new label ids
3060
-
3061
-
3062
- rewrites.push(extend({
3063
- newId: newRefId
3064
- }, ref));
3065
- }); // 2. remove all labels!
3066
-
3067
- forEach(findLabels(text), label => {
3068
- text = text.replace(label.match, '');
3069
- }); // 3. remove whitespace from the end of text
3070
-
3071
- text = text.replace(/[\r\n\s]*$/, '');
3072
- text += '\n\n'; // 4. apply rewrites
3073
-
3074
- forEach(rewrites, ref => {
3075
- text = text.replace(ref.match, buildRef(ref, ref.newId));
3076
- }); // 5. print new labels at the end of text
3077
-
3078
- forEach(labels, label => {
3079
- text += '\n' + buildLabel(label, label.newId);
3080
- });
3081
- return text;
3082
- }
3083
- /**
3084
- * Finding stuff
3085
- */
3086
-
3087
- function makeFinder(type) {
3088
- return text => findAll(text, type).map(PROCESSORS[type]);
3089
- }
3090
-
3091
- function findMaxLabelId(textOrLabels) {
3092
- if (isString(textOrLabels)) {
3093
- textOrLabels = findLabels(textOrLabels);
3094
- }
3095
-
3096
- const ids = textOrLabels.map(x => x.id).map(x => parseInt(x, 10)).filter(x => isFinite(x) && x > 0);
3097
- return ids.length > 0 ? max(ids) || 0 : 0;
3098
- }
3099
-
3100
- function findAll(text, type) {
3101
- const flags = 'g' + (type === 'label' ? 'm' : '');
3102
- const matches = [];
3103
- const re = new RegExp(REGEXS[type].source, flags);
3104
- let found = re.exec(text);
3105
-
3106
- while (found) {
3107
- matches.push(found);
3108
- re.lastIndex = found.index + found[0].length;
3109
- found = re.exec(text);
3110
- }
3111
-
3112
- return matches;
3113
- }
3114
- /**
3115
- * Other utilities
3116
- */
3117
-
3118
-
3119
- function hasTitle(link) {
3120
- return isObject(link) && isString(link.title) && link.title.length > 0;
3121
- }
3122
-
3123
- function buildLabel(link, id) {
3124
- let markup = '[' + id + ']: ' + link.href;
3125
-
3126
- if (hasTitle(link)) {
3127
- markup += ' "' + link.title + '"';
3128
- }
3129
-
3130
- return markup;
3131
- }
3132
-
3133
- function buildRef(link, id) {
3134
- return '[' + link.text + '][' + id + ']';
3135
- }
3136
-
3137
- function createMarkdownActions(props) {
3138
- const {
3139
- sdk,
3140
- editor,
3141
- locale
3142
- } = props; // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/ban-types
3143
-
3144
- const insertAssetsWithConfirmation = async assets => {
3145
- if (assets) {
3146
- const {
3147
- links,
3148
- fallbacks
3149
- } = await insertAssetLinks(assets, {
3150
- localeCode: locale,
3151
- defaultLocaleCode: sdk.locales.default,
3152
- fallbackCode: sdk.locales.fallbacks[locale]
3153
- });
3154
-
3155
- if (links && links.length > 0) {
3156
- if (fallbacks) {
3157
- const insertAnyway = await openConfirmInsertAsset(sdk.dialogs, {
3158
- locale: locale,
3159
- assets: fallbacks
3160
- });
3161
-
3162
- if (!insertAnyway) {
3163
- throw Error('User decided to not use fallbacks');
3164
- }
3165
- }
3166
-
3167
- return links.map(link => link.asMarkdown).join('\n\n');
3168
- }
3169
- }
3170
-
3171
- return '';
3172
- };
3173
-
3174
- return {
3175
- headings: {
3176
- h1: () => {
3177
- editor == null ? void 0 : editor.actions.h1();
3178
- },
3179
- h2: () => {
3180
- editor == null ? void 0 : editor.actions.h2();
3181
- },
3182
- h3: () => {
3183
- editor == null ? void 0 : editor.actions.h3();
3184
- }
3185
- },
3186
- simple: {
3187
- italic: () => {
3188
- editor == null ? void 0 : editor.actions.italic();
3189
- },
3190
- bold: () => {
3191
- editor == null ? void 0 : editor.actions.bold();
3192
- },
3193
- quote: () => {
3194
- editor == null ? void 0 : editor.actions.quote();
3195
- },
3196
- ol: () => {
3197
- editor == null ? void 0 : editor.actions.ol();
3198
- },
3199
- ul: () => {
3200
- editor == null ? void 0 : editor.actions.ul();
3201
- },
3202
- strike: () => {
3203
- editor == null ? void 0 : editor.actions.strike();
3204
- },
3205
- code: () => {
3206
- editor == null ? void 0 : editor.actions.code();
3207
- },
3208
- hr: () => {
3209
- editor == null ? void 0 : editor.actions.hr();
3210
- },
3211
- indent: () => {
3212
- editor == null ? void 0 : editor.actions.indent();
3213
- },
3214
- dedent: () => {
3215
- editor == null ? void 0 : editor.actions.dedent();
3216
- }
3217
- },
3218
- history: {
3219
- undo: () => {
3220
- editor == null ? void 0 : editor.actions.undo();
3221
- },
3222
- redo: () => {
3223
- editor == null ? void 0 : editor.actions.redo();
3224
- }
3225
- },
3226
- insertLink: async () => {
3227
- if (!editor) {
3228
- return;
3229
- }
3230
-
3231
- editor.usePrimarySelection();
3232
- const selectedText = editor.getSelectedText();
3233
- const result = await openInsertLinkDialog(sdk.dialogs, {
3234
- selectedText
3235
- });
3236
-
3237
- if (result) {
3238
- editor.actions.link(result.url, selectedText || result.text, result.title);
3239
- }
3240
- },
3241
- insertSpecialCharacter: async () => {
3242
- if (!editor) {
3243
- return;
3244
- }
3245
-
3246
- const result = await openInsertSpecialCharacter(sdk.dialogs);
3247
-
3248
- if (result) {
3249
- editor.insert(result);
3250
- }
3251
- },
3252
- insertTable: async () => {
3253
- if (!editor) {
3254
- return;
3255
- }
3256
-
3257
- const result = await openInsertTableDialog(sdk.dialogs);
3258
-
3259
- if (result) {
3260
- editor.actions.table(result);
3261
- }
3262
- },
3263
- organizeLinks: () => {
3264
- if (!editor) {
3265
- return;
3266
- }
3267
-
3268
- let text = editor.getContent();
3269
-
3270
- if (!text) {
3271
- return;
3272
- }
3273
-
3274
- text = convertInlineToRef(text);
3275
- text = rewriteRefs(text);
3276
- editor.setContent(text);
3277
- sdk.notifier.success('All your links are now references at the bottom of your document.');
3278
- },
3279
- embedExternalContent: async () => {
3280
- if (!editor) {
3281
- return;
3282
- }
3283
-
3284
- const result = await openEmbedExternalContentDialog(sdk.dialogs);
3285
-
3286
- if (result) {
3287
- editor.insert(result);
3288
- }
3289
- },
3290
- addNewMedia: async () => {
3291
- if (!editor) {
3292
- return;
3293
- }
3294
-
3295
- try {
3296
- const {
3297
- entity: asset
3298
- } = await sdk.navigator.openNewAsset({
3299
- slideIn: {
3300
- waitForClose: true
3301
- }
3302
- }); // eslint-disable-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
3303
-
3304
- const markdownLinks = await insertAssetsWithConfirmation([asset]);
3305
- editor.insert(markdownLinks);
3306
- } finally {
3307
- editor.focus();
3308
- }
3309
- },
3310
- linkExistingMedia: async () => {
3311
- if (!editor) {
3312
- return;
3313
- }
3314
-
3315
- try {
3316
- const assets = await sdk.dialogs.selectMultipleAssets({
3317
- locale: locale
3318
- });
3319
- const markdownLinks = await insertAssetsWithConfirmation(assets);
3320
- editor.insert(markdownLinks);
3321
- } finally {
3322
- editor.focus();
3323
- }
3324
- },
3325
- openZenMode: async () => {
3326
- if (!editor) {
3327
- return;
3328
- }
3329
-
3330
- const result = await openZenMode(sdk.dialogs, {
3331
- initialValue: editor.getContent(),
3332
- locale: props.locale
3333
- });
3334
- editor.setContent(result.value);
3335
-
3336
- if (result.cursor) {
3337
- editor.setCursor(result.cursor);
3338
- }
3339
-
3340
- editor.focus();
3341
- },
3342
- closeZenMode: () => {// do nothing
3343
- // this method is overwritten in dialog app
3344
- }
3345
- };
3346
- }
3347
-
3348
- const styles$a = {
3349
- container: /*#__PURE__*/css({
3350
- display: 'flex',
3351
- flexDirection: 'column',
3352
- fontFamily: tokens.fontStackPrimary
3353
- })
3354
- };
3355
- function MarkdownEditor(props) {
3356
- const [currentValue, setCurrentValue] = React.useState(props.initialValue ?? '');
3357
- const [selectedTab, setSelectedTab] = React.useState('editor');
3358
- const [editor, setEditor] = React.useState(null);
3359
- const [canUploadAssets, setCanUploadAssets] = React.useState(false);
3360
- React.useEffect(() => {
3361
- if (editor && props.onReady) {
3362
- props.onReady(editor); // fix: http://codemirror.977696.n3.nabble.com/codemirror-content-not-visible-in-bootstrap-modal-td4026988.html
3363
-
3364
- setTimeout(() => {
3365
- editor.refresh();
3366
- }, 1);
3367
- } // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
3368
-
3369
- }, [editor]);
3370
- React.useEffect(() => {
3371
- props.sdk.access.can('create', 'Asset').then(value => {
3372
- setCanUploadAssets(value);
3373
- }); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
3374
- }, []);
3375
- React.useEffect(() => {
3376
- if (editor) {
3377
- editor.setReadOnly(props.disabled);
3378
- }
3379
- }, [editor, props.disabled]);
3380
- const isActionDisabled = editor === null || props.disabled || selectedTab !== 'editor';
3381
- const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
3382
- const actions = React.useMemo(() => {
3383
- return createMarkdownActions({
3384
- sdk: props.sdk,
3385
- editor,
3386
- locale: props.sdk.field.locale
3387
- }); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
3388
- }, [editor]);
3389
- const openMarkdownHelp = React.useCallback(() => {
3390
- openCheatsheetModal(props.sdk.dialogs); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
3391
- }, []);
3392
- return React.createElement("div", {
3393
- className: styles$a.container,
3394
- "data-test-id": "markdown-editor"
3395
- }, React.createElement(MarkdownTabs, {
3396
- active: selectedTab,
3397
- onSelect: tab => {
3398
- setSelectedTab(tab);
3399
- }
3400
- }), React.createElement(MarkdownToolbar, {
3401
- mode: "default",
3402
- disabled: isActionDisabled,
3403
- canUploadAssets: canUploadAssets,
3404
- actions: actions
3405
- }), React.createElement(MarkdownTextarea, {
3406
- minHeight: props.minHeight,
3407
- mode: "default",
3408
- visible: selectedTab === 'editor',
3409
- disabled: isActionDisabled,
3410
- direction: direction,
3411
- onReady: editor => {
3412
- editor.setContent(props.initialValue ?? '');
3413
- editor.setReadOnly(props.disabled);
3414
- setEditor(editor);
3415
- editor.events.onChange(value => {
3416
- // Trim empty lines
3417
- const trimmedValue = value.replace(/^\s+$/gm, '');
3418
- props.saveValueToSDK(trimmedValue);
3419
- setCurrentValue(value);
3420
- });
3421
- }
3422
- }), selectedTab === 'preview' && React.createElement(MarkdownPreview, {
3423
- direction: direction,
3424
- minHeight: props.minHeight,
3425
- mode: "default",
3426
- value: currentValue,
3427
- previewComponents: props.previewComponents
3428
- }), React.createElement(MarkdownBottomBar, null, React.createElement(MarkdownHelp, {
3429
- onClick: openMarkdownHelp
3430
- })), React.createElement(MarkdownConstraints, {
3431
- sdk: props.sdk,
3432
- value: currentValue
3433
- }));
3434
- }
3435
- function MarkdownEditorConnected(props) {
3436
- return React.createElement(FieldConnector, {
3437
- throttle: 300,
3438
- field: props.sdk.field,
3439
- isInitiallyDisabled: props.isInitiallyDisabled
3440
- }, ({
3441
- value,
3442
- disabled,
3443
- setValue,
3444
- externalReset
3445
- }) => {
3446
- // on external change reset component completely and init with initial value again
3447
- return React.createElement(MarkdownEditor, { ...props,
3448
- key: `markdown-editor-${externalReset}`,
3449
- initialValue: value,
3450
- disabled: disabled,
3451
- saveValueToSDK: setValue
3452
- });
3453
- });
3454
- }
3455
-
3456
- const openMarkdownDialog = (sdk, previewComponents) => options => {
3457
- var _options$parameters, _options$parameters2, _options$parameters3, _options$parameters4, _options$parameters5, _options$parameters6, _options$parameters7;
3458
-
3459
- if (((_options$parameters = options.parameters) == null ? void 0 : _options$parameters.type) === MarkdownDialogType.cheatsheet) {
3460
- return ModalDialogLauncher.openDialog(options, () => {
3461
- return React.createElement(CheatsheetModalDialog, null);
3462
- });
3463
- } else if (((_options$parameters2 = options.parameters) == null ? void 0 : _options$parameters2.type) === MarkdownDialogType.insertLink) {
3464
- const selectedText = options.parameters.selectedText;
3465
- return ModalDialogLauncher.openDialog(options, ({
3466
- onClose
3467
- }) => {
3468
- return React.createElement(InsertLinkModal, {
3469
- selectedText: selectedText,
3470
- onClose: onClose
3471
- });
3472
- });
3473
- } else if (((_options$parameters3 = options.parameters) == null ? void 0 : _options$parameters3.type) === MarkdownDialogType.insertSpecialCharacter) {
3474
- return ModalDialogLauncher.openDialog(options, ({
3475
- onClose
3476
- }) => {
3477
- return React.createElement(SpecialCharacterModalDialog, {
3478
- onClose: onClose
3479
- });
3480
- });
3481
- } else if (((_options$parameters4 = options.parameters) == null ? void 0 : _options$parameters4.type) === MarkdownDialogType.insertTable) {
3482
- return ModalDialogLauncher.openDialog(options, ({
3483
- onClose
3484
- }) => {
3485
- return React.createElement(InsertTableModal, {
3486
- onClose: onClose
3487
- });
3488
- });
3489
- } else if (((_options$parameters5 = options.parameters) == null ? void 0 : _options$parameters5.type) === MarkdownDialogType.embedExternalContent) {
3490
- return ModalDialogLauncher.openDialog(options, ({
3491
- onClose
3492
- }) => {
3493
- return React.createElement(EmbedExternalContentModal, {
3494
- onClose: onClose
3495
- });
3496
- });
3497
- } else if (((_options$parameters6 = options.parameters) == null ? void 0 : _options$parameters6.type) === MarkdownDialogType.confirmInsertAsset) {
3498
- const locale = options.parameters.locale;
3499
- const assets = options.parameters.assets;
3500
- return ModalDialogLauncher.openDialog(options, ({
3501
- onClose
3502
- }) => {
3503
- return React.createElement(ConfirmInsertAssetModalDialog, {
3504
- onClose: onClose,
3505
- locale: locale,
3506
- assets: assets
3507
- });
3508
- });
3509
- } else if (((_options$parameters7 = options.parameters) == null ? void 0 : _options$parameters7.type) === MarkdownDialogType.zenMode) {
3510
- const initialValue = options.parameters.initialValue;
3511
- const locale = options.parameters.locale;
3512
- return ModalDialogLauncher.openDialog(options, ({
3513
- onClose
3514
- }) => {
3515
- return React.createElement(ZenModeModalDialog, {
3516
- saveValueToSDK: value => {
3517
- var _sdk$field2;
3518
-
3519
- if (value) {
3520
- var _sdk$field;
3521
-
3522
- return sdk == null ? void 0 : (_sdk$field = sdk.field) == null ? void 0 : _sdk$field.setValue(value);
3523
- }
3524
-
3525
- return sdk == null ? void 0 : (_sdk$field2 = sdk.field) == null ? void 0 : _sdk$field2.removeValue();
3526
- },
3527
- onClose: onClose,
3528
- initialValue: initialValue,
3529
- locale: locale,
3530
- sdk: sdk,
3531
- previewComponents: previewComponents
3532
- });
3533
- });
3534
- }
3535
-
3536
- return Promise.reject();
3537
- };
3538
-
3539
- const renderMarkdownDialog = sdk => {
3540
- const parameters = sdk.parameters.invocation;
3541
-
3542
- if (parameters.type === MarkdownDialogType.cheatsheet) {
3543
- sdk.window.startAutoResizer();
3544
- return React.createElement(CheatsheetModalDialog, null);
3545
- } else if (parameters.type === MarkdownDialogType.insertLink) {
3546
- const selectedText = parameters.selectedText;
3547
- sdk.window.startAutoResizer();
3548
- return React.createElement(InsertLinkModal, {
3549
- selectedText: selectedText,
3550
- onClose: sdk.close
3551
- });
3552
- } else if (parameters.type === MarkdownDialogType.insertSpecialCharacter) {
3553
- sdk.window.startAutoResizer();
3554
- return React.createElement(SpecialCharacterModalDialog, {
3555
- onClose: sdk.close
3556
- });
3557
- } else if (parameters.type === MarkdownDialogType.insertTable) {
3558
- sdk.window.startAutoResizer();
3559
- return React.createElement(InsertTableModal, {
3560
- onClose: sdk.close
3561
- });
3562
- } else if (parameters.type === MarkdownDialogType.embedExternalContent) {
3563
- sdk.window.startAutoResizer();
3564
- return React.createElement(EmbedExternalContentModal, {
3565
- onClose: sdk.close
3566
- });
3567
- } else if (parameters.type === MarkdownDialogType.confirmInsertAsset) {
3568
- const locale = parameters.locale;
3569
- const assets = parameters.assets;
3570
- sdk.window.startAutoResizer();
3571
- return React.createElement(ConfirmInsertAssetModalDialog, {
3572
- onClose: sdk.close,
3573
- locale: locale,
3574
- assets: assets
3575
- });
3576
- } else if (parameters.type === MarkdownDialogType.zenMode) {
3577
- const locale = parameters.locale;
3578
- const initialValue = parameters.initialValue; // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
3579
-
3580
- sdk.window.updateHeight('100%');
3581
- return React.createElement(ZenModeModalDialog, {
3582
- onClose: sdk.close,
3583
- saveValueToSDK: () => {// don't save changes in dialog mode
3584
- },
3585
- initialValue: initialValue,
3586
- locale: locale,
3587
- sdk: sdk
3588
- });
3589
- }
3590
-
3591
- return React.createElement("div", null);
3592
- };
3593
-
3594
- export { MarkdownEditorConnected as MarkdownEditor, MarkdownPreview, openMarkdownDialog, renderMarkdownDialog };
3595
- //# sourceMappingURL=field-editor-markdown.esm.js.map