@contentful/field-editor-markdown 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/field-editor-markdown.cjs.development.js +32 -28
- package/dist/field-editor-markdown.cjs.development.js.map +1 -1
- package/dist/field-editor-markdown.cjs.production.min.js +1 -1
- package/dist/field-editor-markdown.cjs.production.min.js.map +1 -1
- package/dist/field-editor-markdown.esm.js +33 -29
- package/dist/field-editor-markdown.esm.js.map +1 -1
- package/dist/utils/insertAssetLinks.d.ts +1 -0
- package/package.json +7 -8
|
@@ -7,7 +7,7 @@ import React, { useRef, useState, useEffect } from 'react';
|
|
|
7
7
|
import { css, cx } from 'emotion';
|
|
8
8
|
import tokens from '@contentful/f36-tokens';
|
|
9
9
|
import { ConstraintsUtils, CharCounter, CharValidation, FieldConnector, ModalDialogLauncher } from '@contentful/field-editor-shared';
|
|
10
|
-
import { Menu, Button, Tooltip, Flex, Paragraph, TextLink, ModalContent, Heading, Form, FormControl, TextInput, ModalControls, Text, Radio, Checkbox, EntityList } from '@contentful/f36-components';
|
|
10
|
+
import { Menu, Button, Tooltip, IconButton, Flex, Paragraph, TextLink, ModalContent, Heading, Form, FormControl, TextInput, ModalControls, Text, Radio, Checkbox, EntityList } from '@contentful/f36-components';
|
|
11
11
|
import { AssetIcon, ChevronDownIcon, MoreHorizontalIcon, HeadingIcon, FormatBoldIcon, FormatItalicIcon, QuoteIcon, ListBulletedIcon, ListNumberedIcon, LinkIcon, CodeIcon, HorizontalRuleIcon, ChevronRightIcon, ChevronLeftIcon } from '@contentful/f36-icons';
|
|
12
12
|
import transform from 'lodash-es/transform';
|
|
13
13
|
import throttle from 'lodash-es/throttle';
|
|
@@ -22,7 +22,6 @@ import Markdown from 'markdown-to-jsx';
|
|
|
22
22
|
import DOMPurify from 'dompurify';
|
|
23
23
|
import inRange from 'lodash-es/inRange';
|
|
24
24
|
import isObject from 'lodash-es/isObject';
|
|
25
|
-
import { toExternal } from '@contentful/hostname-transformer';
|
|
26
25
|
import extend from 'lodash-es/extend';
|
|
27
26
|
import isString from 'lodash-es/isString';
|
|
28
27
|
import isFinite from 'lodash-es/isFinite';
|
|
@@ -447,24 +446,20 @@ var ToolbarButton = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
447
446
|
isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
|
|
448
447
|
otherProps = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
449
448
|
|
|
450
|
-
|
|
449
|
+
return React.createElement(Tooltip, {
|
|
450
|
+
className: styles$1.tooltip,
|
|
451
|
+
placement: tooltipPlace,
|
|
452
|
+
content: tooltip
|
|
453
|
+
}, React.createElement(IconButton, Object.assign({}, otherProps, {
|
|
451
454
|
ref: ref,
|
|
452
455
|
className: cx(styles$1.button, className),
|
|
453
456
|
isDisabled: isDisabled,
|
|
454
457
|
onClick: onClick,
|
|
455
458
|
variant: variant,
|
|
456
|
-
size: "small"
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return React.createElement(Tooltip, {
|
|
461
|
-
className: styles$1.tooltip,
|
|
462
|
-
placement: tooltipPlace,
|
|
463
|
-
content: tooltip
|
|
464
|
-
}, button);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return button;
|
|
459
|
+
size: "small",
|
|
460
|
+
icon: children,
|
|
461
|
+
"aria-label": tooltip
|
|
462
|
+
})));
|
|
468
463
|
});
|
|
469
464
|
ToolbarButton.displayName = 'ToolbarButton';
|
|
470
465
|
|
|
@@ -673,7 +668,8 @@ function DefaultMarkdownToolbar(props) {
|
|
|
673
668
|
testId: "markdown-action-button-zen",
|
|
674
669
|
variant: "secondary",
|
|
675
670
|
onClick: props.actions.openZenMode,
|
|
676
|
-
className: styles$1.zenButton
|
|
671
|
+
className: styles$1.zenButton,
|
|
672
|
+
tooltip: "Expand"
|
|
677
673
|
}, React.createElement(Zen, {
|
|
678
674
|
label: "Expand",
|
|
679
675
|
className: styles$1.icon
|
|
@@ -692,18 +688,20 @@ function ZenMarkdownToolbar(props) {
|
|
|
692
688
|
onSelectExisting: props.actions.linkExistingMedia,
|
|
693
689
|
onAddNew: props.actions.addNewMedia,
|
|
694
690
|
canAddNew: props.canUploadAssets
|
|
695
|
-
}), React.createElement(
|
|
691
|
+
}), React.createElement(IconButton, {
|
|
696
692
|
testId: "markdown-action-button-zen-close",
|
|
697
693
|
variant: "secondary",
|
|
698
694
|
size: "small",
|
|
699
695
|
className: cx(styles$1.zenButton, styles$1.zenButtonPressed),
|
|
700
696
|
onClick: function onClick() {
|
|
701
697
|
props.actions.closeZenMode();
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
698
|
+
},
|
|
699
|
+
icon: React.createElement(Zen, {
|
|
700
|
+
label: "Collapse",
|
|
701
|
+
className: styles$1.icon
|
|
702
|
+
}),
|
|
703
|
+
"aria-label": "Collapse"
|
|
704
|
+
}))));
|
|
707
705
|
}
|
|
708
706
|
var MarkdownToolbar = /*#__PURE__*/React.memo(function (props) {
|
|
709
707
|
if (props.mode === 'zen') {
|
|
@@ -3587,6 +3585,18 @@ function fileNameToTitle(str) {
|
|
|
3587
3585
|
return normalizeWhiteSpace(removeExtension(str).replace(/_/g, ' '));
|
|
3588
3586
|
}
|
|
3589
3587
|
|
|
3588
|
+
function replaceAssetDomain(fileUrl) {
|
|
3589
|
+
var assetDomainMap = {
|
|
3590
|
+
images: 'images.ctfassets.net',
|
|
3591
|
+
assets: 'assets.ctfassets.net',
|
|
3592
|
+
downloads: 'downloads.ctfassets.net',
|
|
3593
|
+
videos: 'videos.ctfassets.net'
|
|
3594
|
+
};
|
|
3595
|
+
return fileUrl.replace(/(images|assets|downloads|videos).contentful.com/, function (_, p1) {
|
|
3596
|
+
return assetDomainMap[p1];
|
|
3597
|
+
});
|
|
3598
|
+
}
|
|
3599
|
+
|
|
3590
3600
|
function makeAssetLink(asset, _ref) {
|
|
3591
3601
|
var localeCode = _ref.localeCode,
|
|
3592
3602
|
fallbackCode = _ref.fallbackCode,
|
|
@@ -3598,13 +3608,7 @@ function makeAssetLink(asset, _ref) {
|
|
|
3598
3608
|
|
|
3599
3609
|
if (isObject(file) && file.url) {
|
|
3600
3610
|
var title = get(asset, ['fields', 'title', localeCode]) || get(asset, ['fields', 'title', fallbackCode || '']) || get(asset, ['fields', 'title', defaultLocaleCode]) || fileNameToTitle(file.fileName);
|
|
3601
|
-
var
|
|
3602
|
-
images: 'images.ctfassets.net',
|
|
3603
|
-
assets: 'assets.ctfassets.net',
|
|
3604
|
-
downloads: 'downloads.ctfassets.net',
|
|
3605
|
-
videos: 'videos.ctfassets.net'
|
|
3606
|
-
};
|
|
3607
|
-
var fileUrl = toExternal(file.url, assetDomainMap);
|
|
3611
|
+
var fileUrl = replaceAssetDomain(file.url);
|
|
3608
3612
|
return {
|
|
3609
3613
|
title: title,
|
|
3610
3614
|
asset: asset,
|