@strapi/content-manager 5.33.3 → 5.33.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js +23 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.mjs +23 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.js +14 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.mjs +14 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.js +157 -7
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.mjs +154 -5
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.js +28 -20
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.mjs +25 -17
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +6 -3
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +7 -4
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +12 -12
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +13 -13
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/types.js +4 -8
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/types.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/types.mjs +4 -7
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/types.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js +2 -12
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs +2 -12
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +48 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +49 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +47 -13
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +49 -15
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +10 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +10 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js +5 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs +5 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.js +6 -2
- package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.mjs +6 -2
- package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +22 -0
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +22 -1
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/plugins/withStrapiSchema.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/types.d.ts +2 -4
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +2 -1
- package/dist/admin/src/pages/EditView/utils/data.d.ts +6 -1
- package/package.json +7 -7
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withImages.js +0 -17
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withImages.js.map +0 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withImages.mjs +0 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withImages.mjs.map +0 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withLinks.js +0 -75
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withLinks.js.map +0 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withLinks.mjs +0 -73
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withLinks.mjs.map +0 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/links.js +0 -88
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/links.js.map +0 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/links.mjs +0 -84
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/utils/links.mjs.map +0 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/plugins/withImages.d.ts +0 -11
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/plugins/withLinks.d.ts +0 -9
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/links.d.ts +0 -12
|
@@ -8,8 +8,6 @@ var slate = require('slate');
|
|
|
8
8
|
var slateReact = require('slate-react');
|
|
9
9
|
var styledComponents = require('styled-components');
|
|
10
10
|
var BlocksEditor = require('../BlocksEditor.js');
|
|
11
|
-
var links = require('../utils/links.js');
|
|
12
|
-
var types = require('../utils/types.js');
|
|
13
11
|
|
|
14
12
|
function _interopNamespaceDefault(e) {
|
|
15
13
|
var n = Object.create(null);
|
|
@@ -30,6 +28,88 @@ function _interopNamespaceDefault(e) {
|
|
|
30
28
|
|
|
31
29
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
32
30
|
|
|
31
|
+
const isLinkNode = (element)=>{
|
|
32
|
+
return element.type === 'link';
|
|
33
|
+
};
|
|
34
|
+
const removeLink = (editor)=>{
|
|
35
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
36
|
+
match: (node)=>!slate.Editor.isEditor(node) && slate.Element.isElement(node) && node.type === 'link'
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const insertLink = (editor, { url })=>{
|
|
40
|
+
if (editor.selection) {
|
|
41
|
+
// We want to remove all link on the selection
|
|
42
|
+
const linkNodes = Array.from(slate.Editor.nodes(editor, {
|
|
43
|
+
at: editor.selection,
|
|
44
|
+
match: (node)=>!slate.Editor.isEditor(node) && node.type === 'link'
|
|
45
|
+
}));
|
|
46
|
+
linkNodes.forEach(([, path])=>{
|
|
47
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
48
|
+
at: path
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
if (slate.Range.isCollapsed(editor.selection)) {
|
|
52
|
+
const link = {
|
|
53
|
+
type: 'link',
|
|
54
|
+
url: url ?? '',
|
|
55
|
+
children: [
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
text: url
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
rel: '',
|
|
62
|
+
target: ''
|
|
63
|
+
};
|
|
64
|
+
slate.Transforms.insertNodes(editor, link);
|
|
65
|
+
} else {
|
|
66
|
+
slate.Transforms.wrapNodes(editor, {
|
|
67
|
+
type: 'link',
|
|
68
|
+
url: url ?? ''
|
|
69
|
+
}, {
|
|
70
|
+
split: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const editLink = (editor, link)=>{
|
|
76
|
+
const { url, text, rel, target } = link;
|
|
77
|
+
if (!editor.selection) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const linkEntry = slate.Editor.above(editor, {
|
|
81
|
+
match: (node)=>!slate.Editor.isEditor(node) && node.type === 'link'
|
|
82
|
+
});
|
|
83
|
+
if (linkEntry) {
|
|
84
|
+
const [, linkPath] = linkEntry;
|
|
85
|
+
slate.Transforms.setNodes(editor, {
|
|
86
|
+
url,
|
|
87
|
+
rel,
|
|
88
|
+
target
|
|
89
|
+
}, {
|
|
90
|
+
at: linkPath
|
|
91
|
+
});
|
|
92
|
+
// If link text is different, we remove the old text and insert the new one
|
|
93
|
+
if (text !== '' && text !== slate.Editor.string(editor, linkPath)) {
|
|
94
|
+
const linkNodeChildrens = Array.from(slate.Node.children(editor, linkPath, {
|
|
95
|
+
reverse: true
|
|
96
|
+
}));
|
|
97
|
+
linkNodeChildrens.forEach(([, childPath])=>{
|
|
98
|
+
slate.Transforms.removeNodes(editor, {
|
|
99
|
+
at: childPath
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
slate.Transforms.insertNodes(editor, [
|
|
103
|
+
{
|
|
104
|
+
type: 'text',
|
|
105
|
+
text
|
|
106
|
+
}
|
|
107
|
+
], {
|
|
108
|
+
at: linkPath.concat(0)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
33
113
|
const StyledLink = styledComponents.styled(designSystem.Box)`
|
|
34
114
|
text-decoration: none;
|
|
35
115
|
`;
|
|
@@ -74,7 +154,7 @@ const LinkContent = /*#__PURE__*/ React__namespace.forwardRef(({ link, children,
|
|
|
74
154
|
const [, parentPath] = slate.Editor.parent(editor, editor.selection.focus?.path);
|
|
75
155
|
slate.Transforms.select(editor, parentPath);
|
|
76
156
|
}
|
|
77
|
-
|
|
157
|
+
editLink(editor, {
|
|
78
158
|
url: linkUrl,
|
|
79
159
|
text: linkText,
|
|
80
160
|
rel: linkRel,
|
|
@@ -86,7 +166,7 @@ const LinkContent = /*#__PURE__*/ React__namespace.forwardRef(({ link, children,
|
|
|
86
166
|
};
|
|
87
167
|
const handleClose = ()=>{
|
|
88
168
|
if (link.url === '') {
|
|
89
|
-
|
|
169
|
+
removeLink(editor);
|
|
90
170
|
}
|
|
91
171
|
setPopoverOpen(false);
|
|
92
172
|
slateReact.ReactEditor.focus(editor);
|
|
@@ -230,7 +310,7 @@ const LinkContent = /*#__PURE__*/ React__namespace.forwardRef(({ link, children,
|
|
|
230
310
|
children: [
|
|
231
311
|
/*#__PURE__*/ jsxRuntime.jsx(RemoveButton, {
|
|
232
312
|
variant: "danger-light",
|
|
233
|
-
onClick: ()=>
|
|
313
|
+
onClick: ()=>removeLink(editor),
|
|
234
314
|
$visible: isLastInsertedLink,
|
|
235
315
|
children: formatMessage({
|
|
236
316
|
id: 'components.Blocks.popover.remove',
|
|
@@ -267,7 +347,7 @@ const LinkContent = /*#__PURE__*/ React__namespace.forwardRef(({ link, children,
|
|
|
267
347
|
});
|
|
268
348
|
});
|
|
269
349
|
const Link = /*#__PURE__*/ React__namespace.forwardRef((props, forwardedRef)=>{
|
|
270
|
-
if (!
|
|
350
|
+
if (!isLinkNode(props.element)) {
|
|
271
351
|
return null;
|
|
272
352
|
}
|
|
273
353
|
// LinkContent uses React hooks that rely on props.element being a link. If the type guard above
|
|
@@ -279,6 +359,73 @@ const Link = /*#__PURE__*/ React__namespace.forwardRef((props, forwardedRef)=>{
|
|
|
279
359
|
ref: forwardedRef
|
|
280
360
|
});
|
|
281
361
|
});
|
|
362
|
+
const withLinks = (editor)=>{
|
|
363
|
+
const { isInline, apply, insertText, insertData } = editor;
|
|
364
|
+
// Links are inline elements, so we need to override the isInline method for slate
|
|
365
|
+
editor.isInline = (element)=>{
|
|
366
|
+
return element.type === 'link' ? true : isInline(element);
|
|
367
|
+
};
|
|
368
|
+
// We keep a track of the last inserted link path
|
|
369
|
+
// So we can show the popover on the link component if that link is the last one inserted
|
|
370
|
+
editor.lastInsertedLinkPath = null;
|
|
371
|
+
// We intercept the apply method, so everytime we insert a new link, we save its path
|
|
372
|
+
editor.apply = (operation)=>{
|
|
373
|
+
if (operation.type === 'insert_node') {
|
|
374
|
+
if (!slate.Editor.isEditor(operation.node) && operation.node.type === 'link' && editor.shouldSaveLinkPath) {
|
|
375
|
+
editor.lastInsertedLinkPath = operation.path;
|
|
376
|
+
}
|
|
377
|
+
} else if (operation.type === 'move_node') {
|
|
378
|
+
// We need to update the last inserted link path when link is moved
|
|
379
|
+
// If link is the first word in the paragraph we dont need to update the path
|
|
380
|
+
if (slate.Path.hasPrevious(operation.path) && editor.lastInsertedLinkPath && editor.shouldSaveLinkPath) {
|
|
381
|
+
editor.lastInsertedLinkPath = slate.Path.transform(editor.lastInsertedLinkPath, operation);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
apply(operation);
|
|
385
|
+
};
|
|
386
|
+
editor.insertText = (text)=>{
|
|
387
|
+
// When selection is at the end of a link and user types a space, we want to break the link
|
|
388
|
+
if (editor.selection && slate.Range.isCollapsed(editor.selection) && text === ' ') {
|
|
389
|
+
const linksInSelection = Array.from(slate.Editor.nodes(editor, {
|
|
390
|
+
at: editor.selection,
|
|
391
|
+
match: (node)=>!slate.Editor.isEditor(node) && node.type === 'link'
|
|
392
|
+
}));
|
|
393
|
+
const selectionIsInLink = editor.selection && linksInSelection.length > 0;
|
|
394
|
+
const selectionIsAtEndOfLink = selectionIsInLink && slate.Point.equals(editor.selection.anchor, slate.Editor.end(editor, linksInSelection[0][1]));
|
|
395
|
+
if (selectionIsAtEndOfLink) {
|
|
396
|
+
slate.Transforms.insertNodes(editor, {
|
|
397
|
+
text: ' ',
|
|
398
|
+
type: 'text'
|
|
399
|
+
}, {
|
|
400
|
+
at: slate.Path.next(linksInSelection[0][1]),
|
|
401
|
+
select: true
|
|
402
|
+
});
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
insertText(text);
|
|
407
|
+
};
|
|
408
|
+
// Add data as a clickable link if its a valid URL
|
|
409
|
+
editor.insertData = (data)=>{
|
|
410
|
+
const pastedText = data.getData('text/plain');
|
|
411
|
+
if (pastedText) {
|
|
412
|
+
try {
|
|
413
|
+
// eslint-disable-next-line no-new
|
|
414
|
+
new URL(pastedText);
|
|
415
|
+
// Do not show link popup on copy-paste a link, so do not save its path
|
|
416
|
+
editor.shouldSaveLinkPath = false;
|
|
417
|
+
insertLink(editor, {
|
|
418
|
+
url: pastedText
|
|
419
|
+
});
|
|
420
|
+
return;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
// continue normal data insertion
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
insertData(data);
|
|
426
|
+
};
|
|
427
|
+
return editor;
|
|
428
|
+
};
|
|
282
429
|
const linkBlocks = {
|
|
283
430
|
link: {
|
|
284
431
|
renderElement: (props)=>/*#__PURE__*/ jsxRuntime.jsx(Link, {
|
|
@@ -288,9 +435,12 @@ const linkBlocks = {
|
|
|
288
435
|
}),
|
|
289
436
|
// No handleConvert here, links are created via the link button in the toolbar
|
|
290
437
|
matchNode: (node)=>node.type === 'link',
|
|
291
|
-
isInBlocksSelector: false
|
|
438
|
+
isInBlocksSelector: false,
|
|
439
|
+
plugin: withLinks,
|
|
440
|
+
isDraggable: ()=>false
|
|
292
441
|
}
|
|
293
442
|
};
|
|
294
443
|
|
|
444
|
+
exports.insertLink = insertLink;
|
|
295
445
|
exports.linkBlocks = linkBlocks;
|
|
296
446
|
//# sourceMappingURL=Link.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, Button, Field, Flex, Popover, useComposedRefs } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { Editor, Path, Range, Transforms } from 'slate';\nimport { type RenderElementProps, ReactEditor } from 'slate-react';\nimport { styled } from 'styled-components';\n\nimport { type BlocksStore, useBlocksEditorContext } from '../BlocksEditor';\nimport { editLink, removeLink } from '../utils/links';\nimport { isLinkNode, type Block } from '../utils/types';\n\nconst StyledLink = styled(Box)`\n text-decoration: none;\n`;\n\nconst RemoveButton = styled(Button)<{ $visible: boolean }>`\n visibility: ${(props) => (props.$visible ? 'visible' : 'hidden')};\n`;\n\ninterface LinkContentProps extends RenderElementProps {\n link: Block<'link'>;\n}\n\nconst LinkContent = React.forwardRef<HTMLAnchorElement, LinkContentProps>(\n ({ link, children, attributes }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const { editor } = useBlocksEditorContext('Link');\n const path = ReactEditor.findPath(editor, link);\n const [popoverOpen, setPopoverOpen] = React.useState(\n editor.lastInsertedLinkPath ? Path.equals(path, editor.lastInsertedLinkPath) : false\n );\n const elementText = link.children.map((child) => child.text).join('');\n const [linkText, setLinkText] = React.useState(elementText);\n const [linkUrl, setLinkUrl] = React.useState(link.url);\n const [linkRel, setLinRel] = React.useState(link.rel);\n const [linkTarget, setLinkTarget] = React.useState(link.target);\n const linkInputRef = React.useRef<HTMLInputElement>(null);\n const isLastInsertedLink = editor.lastInsertedLinkPath\n ? !Path.equals(path, editor.lastInsertedLinkPath)\n : true;\n const [isSaveDisabled, setIsSaveDisabled] = React.useState(false);\n\n const onLinkChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setIsSaveDisabled(false);\n setLinkUrl(e.target.value);\n\n try {\n // eslint-disable-next-line no-new\n new URL(\n e.target.value?.startsWith('/') ? `https://strapi.io${e.target.value}` : e.target.value\n );\n } catch (error) {\n setIsSaveDisabled(true);\n }\n };\n\n const onLinkRelChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setIsSaveDisabled(false);\n setLinRel(e.target.value);\n };\n\n const onLinkTargetChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setIsSaveDisabled(false);\n setLinkTarget(e.target.value);\n };\n\n const handleSave: React.FormEventHandler = (e) => {\n e.stopPropagation();\n\n // If the selection is collapsed, we select the parent node because we want all the link to be replaced)\n if (editor.selection && Range.isCollapsed(editor.selection)) {\n const [, parentPath] = Editor.parent(editor, editor.selection.focus?.path);\n Transforms.select(editor, parentPath);\n }\n\n editLink(editor, { url: linkUrl, text: linkText, rel: linkRel, target: linkTarget });\n setPopoverOpen(false);\n editor.lastInsertedLinkPath = null;\n ReactEditor.focus(editor);\n };\n\n const handleClose = () => {\n if (link.url === '') {\n removeLink(editor);\n }\n\n setPopoverOpen(false);\n ReactEditor.focus(editor);\n };\n\n React.useEffect(() => {\n // Focus on the link input element when the popover opens\n if (popoverOpen) linkInputRef.current?.focus();\n }, [popoverOpen]);\n\n const inputNotDirty =\n !linkText ||\n !linkUrl ||\n (link.url &&\n link.url === linkUrl &&\n elementText &&\n elementText === linkText &&\n link.rel === linkRel &&\n link.target === linkTarget);\n\n return (\n <Popover.Root open={popoverOpen}>\n <Popover.Trigger>\n <StyledLink\n {...attributes}\n ref={forwardedRef}\n tag=\"a\"\n href={link.url}\n rel={link.rel}\n target={link.target}\n onClick={() => setPopoverOpen(true)}\n color=\"primary600\"\n >\n {children}\n </StyledLink>\n </Popover.Trigger>\n <Popover.Content onPointerDownOutside={handleClose}>\n <Flex padding={4} direction=\"column\" gap={4}>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.text',\n defaultMessage: 'Text',\n })}\n </Field.Label>\n <Field.Input\n name=\"text\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.text.placeholder',\n defaultMessage: 'Enter link text',\n })}\n value={linkText}\n onChange={(e) => {\n setLinkText(e.target.value);\n }}\n />\n </Flex>\n </Field.Root>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.link',\n defaultMessage: 'Link',\n })}\n </Field.Label>\n <Field.Input\n ref={linkInputRef}\n name=\"url\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.link.placeholder',\n defaultMessage: 'Paste link',\n })}\n value={linkUrl}\n onChange={onLinkChange}\n />\n </Flex>\n </Field.Root>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.link.rel',\n defaultMessage: 'Rel (optional)',\n })}\n </Field.Label>\n <Field.Input\n name=\"rel\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.link.rel.placeholder',\n defaultMessage: 'noopener, nofollow, noreferrer',\n })}\n value={linkRel}\n onChange={onLinkRelChange}\n />\n </Flex>\n </Field.Root>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.link.target',\n defaultMessage: 'Target (optional)',\n })}\n </Field.Label>\n <Field.Input\n name=\"target\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.link.target.placeholder',\n defaultMessage: '_blank, _self, _parent, _top',\n })}\n value={linkTarget}\n onChange={onLinkTargetChange}\n />\n </Flex>\n </Field.Root>\n <Flex justifyContent=\"space-between\" width=\"100%\">\n <RemoveButton\n variant=\"danger-light\"\n onClick={() => removeLink(editor)}\n $visible={isLastInsertedLink}\n >\n {formatMessage({\n id: 'components.Blocks.popover.remove',\n defaultMessage: 'Remove',\n })}\n </RemoveButton>\n <Flex gap={2}>\n <Button variant=\"tertiary\" onClick={handleClose}>\n {formatMessage({\n id: 'global.cancel',\n defaultMessage: 'Cancel',\n })}\n </Button>\n <Button disabled={Boolean(inputNotDirty) || isSaveDisabled} onClick={handleSave}>\n {formatMessage({\n id: 'global.save',\n defaultMessage: 'Save',\n })}\n </Button>\n </Flex>\n </Flex>\n </Flex>\n </Popover.Content>\n </Popover.Root>\n );\n }\n);\n\nconst Link = React.forwardRef<HTMLAnchorElement, RenderElementProps>((props, forwardedRef) => {\n if (!isLinkNode(props.element)) {\n return null;\n }\n\n // LinkContent uses React hooks that rely on props.element being a link. If the type guard above\n // doesn't pass, those hooks would be called conditionnally, which is not allowed.\n // Hence the need for a separate component.\n return <LinkContent {...props} link={props.element} ref={forwardedRef} />;\n});\n\nconst linkBlocks: Pick<BlocksStore, 'link'> = {\n link: {\n renderElement: (props) => (\n <Link element={props.element} attributes={props.attributes}>\n {props.children}\n </Link>\n ),\n // No handleConvert here, links are created via the link button in the toolbar\n matchNode: (node) => node.type === 'link',\n isInBlocksSelector: false,\n },\n};\n\nexport { linkBlocks };\n"],"names":["StyledLink","styled","Box","RemoveButton","Button","props","$visible","LinkContent","React","forwardRef","link","children","attributes","forwardedRef","formatMessage","useIntl","editor","useBlocksEditorContext","path","ReactEditor","findPath","popoverOpen","setPopoverOpen","useState","lastInsertedLinkPath","Path","equals","elementText","map","child","text","join","linkText","setLinkText","linkUrl","setLinkUrl","url","linkRel","setLinRel","rel","linkTarget","setLinkTarget","target","linkInputRef","useRef","isLastInsertedLink","isSaveDisabled","setIsSaveDisabled","onLinkChange","e","value","URL","startsWith","error","onLinkRelChange","onLinkTargetChange","handleSave","stopPropagation","selection","Range","isCollapsed","parentPath","Editor","parent","focus","Transforms","select","editLink","handleClose","removeLink","useEffect","current","inputNotDirty","_jsxs","Popover","Root","open","_jsx","Trigger","ref","tag","href","onClick","color","Content","onPointerDownOutside","Flex","padding","direction","gap","Field","width","alignItems","Label","id","defaultMessage","Input","name","placeholder","onChange","justifyContent","variant","disabled","Boolean","Link","isLinkNode","element","linkBlocks","renderElement","matchNode","node","type","isInBlocksSelector"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAMA,UAAAA,GAAaC,uBAAOC,CAAAA,gBAAAA,CAAI;;AAE9B,CAAC;AAED,MAAMC,YAAAA,GAAeF,uBAAOG,CAAAA,mBAAAA,CAA8B;AAC5C,cAAA,EAAE,CAACC,KAAWA,GAAAA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gB,EAAA;AAClB,6CAAA;;sDAEFlB,cAACzE,CAAAA,mBAAAA,EAAAA;AAAOkG,4CAAAA,QAAAA,EAAUC,QAAQ/B,aAAkB1B,CAAAA,IAAAA,cAAAA;4CAAgBoC,OAAS1B,EAAAA,UAAAA;sDAClE1C,aAAc,CAAA;gDACbgF,EAAI,EAAA,aAAA;gDACJC,cAAgB,EAAA;AAClB,6CAAA;;;;;;;;;;;AAQhB,CAAA,CAAA;AAGF,MAAMS,IAAOhG,iBAAAA,gBAAAA,CAAMC,UAAU,CAAwC,CAACJ,KAAOQ,EAAAA,YAAAA,GAAAA;AAC3E,IAAA,IAAI,CAAC4F,gBAAAA,CAAWpG,KAAMqG,CAAAA,OAAO,CAAG,EAAA;QAC9B,OAAO,IAAA;AACT;;;;AAKA,IAAA,qBAAO7B,cAACtE,CAAAA,WAAAA,EAAAA;AAAa,QAAA,GAAGF,KAAK;AAAEK,QAAAA,IAAAA,EAAML,MAAMqG,OAAO;QAAE3B,GAAKlE,EAAAA;;AAC3D,CAAA,CAAA;AAEA,MAAM8F,UAAwC,GAAA;IAC5CjG,IAAM,EAAA;QACJkG,aAAe,EAAA,CAACvG,sBACdwE,cAAC2B,CAAAA,IAAAA,EAAAA;AAAKE,gBAAAA,OAAAA,EAASrG,MAAMqG,OAAO;AAAE9F,gBAAAA,UAAAA,EAAYP,MAAMO,UAAU;AACvDP,gBAAAA,QAAAA,EAAAA,KAAAA,CAAMM;;;AAIXkG,QAAAA,SAAAA,EAAW,CAACC,IAAAA,GAASA,IAAKC,CAAAA,IAAI,KAAK,MAAA;QACnCC,kBAAoB,EAAA;AACtB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"Link.js","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, Button, Field, Flex, Popover } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport {\n BaseEditor,\n Editor,\n Element,\n Path,\n Point,\n Range,\n Transforms,\n Element as SlateElement,\n Node,\n} from 'slate';\nimport { type RenderElementProps, ReactEditor } from 'slate-react';\nimport { styled } from 'styled-components';\n\nimport { type BlocksStore, useBlocksEditorContext } from '../BlocksEditor';\nimport { type Block } from '../utils/types';\n\nimport type { Schema } from '@strapi/types';\n\nconst isLinkNode = (element: Element): element is Schema.Attribute.LinkInlineNode => {\n return element.type === 'link';\n};\n\nconst removeLink = (editor: Editor) => {\n Transforms.unwrapNodes(editor, {\n match: (node) => !Editor.isEditor(node) && SlateElement.isElement(node) && node.type === 'link',\n });\n};\n\nconst insertLink = (editor: Editor, { url }: { url: string }) => {\n if (editor.selection) {\n // We want to remove all link on the selection\n const linkNodes = Array.from(\n Editor.nodes(editor, {\n at: editor.selection,\n match: (node) => !Editor.isEditor(node) && node.type === 'link',\n })\n );\n\n linkNodes.forEach(([, path]) => {\n Transforms.unwrapNodes(editor, { at: path });\n });\n\n if (Range.isCollapsed(editor.selection)) {\n const link: Block<'link'> = {\n type: 'link',\n url: url ?? '',\n children: [{ type: 'text', text: url }],\n rel: '',\n target: '',\n };\n\n Transforms.insertNodes(editor, link);\n } else {\n Transforms.wrapNodes(editor, { type: 'link', url: url ?? '' } as Block<'link'>, {\n split: true,\n });\n }\n }\n};\n\nconst editLink = (\n editor: Editor,\n link: { url: string; text: string; rel: string; target: string }\n) => {\n const { url, text, rel, target } = link;\n\n if (!editor.selection) {\n return;\n }\n\n const linkEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'link',\n });\n\n if (linkEntry) {\n const [, linkPath] = linkEntry;\n Transforms.setNodes(editor, { url, rel, target }, { at: linkPath });\n\n // If link text is different, we remove the old text and insert the new one\n if (text !== '' && text !== Editor.string(editor, linkPath)) {\n const linkNodeChildrens = Array.from(Node.children(editor, linkPath, { reverse: true }));\n\n linkNodeChildrens.forEach(([, childPath]) => {\n Transforms.removeNodes(editor, { at: childPath });\n });\n\n Transforms.insertNodes(editor, [{ type: 'text', text }], { at: linkPath.concat(0) });\n }\n }\n};\n\nconst StyledLink = styled(Box)`\n text-decoration: none;\n`;\n\nconst RemoveButton = styled(Button)<{ $visible: boolean }>`\n visibility: ${(props) => (props.$visible ? 'visible' : 'hidden')};\n`;\n\ninterface LinkContentProps extends RenderElementProps {\n link: Block<'link'>;\n}\n\nconst LinkContent = React.forwardRef<HTMLAnchorElement, LinkContentProps>(\n ({ link, children, attributes }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const { editor } = useBlocksEditorContext('Link');\n const path = ReactEditor.findPath(editor, link);\n const [popoverOpen, setPopoverOpen] = React.useState(\n editor.lastInsertedLinkPath ? Path.equals(path, editor.lastInsertedLinkPath) : false\n );\n const elementText = link.children.map((child) => child.text).join('');\n const [linkText, setLinkText] = React.useState(elementText);\n const [linkUrl, setLinkUrl] = React.useState(link.url);\n const [linkRel, setLinRel] = React.useState(link.rel);\n const [linkTarget, setLinkTarget] = React.useState(link.target);\n const linkInputRef = React.useRef<HTMLInputElement>(null);\n const isLastInsertedLink = editor.lastInsertedLinkPath\n ? !Path.equals(path, editor.lastInsertedLinkPath)\n : true;\n const [isSaveDisabled, setIsSaveDisabled] = React.useState(false);\n\n const onLinkChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setIsSaveDisabled(false);\n setLinkUrl(e.target.value);\n\n try {\n // eslint-disable-next-line no-new\n new URL(\n e.target.value?.startsWith('/') ? `https://strapi.io${e.target.value}` : e.target.value\n );\n } catch (error) {\n setIsSaveDisabled(true);\n }\n };\n\n const onLinkRelChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setIsSaveDisabled(false);\n setLinRel(e.target.value);\n };\n\n const onLinkTargetChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setIsSaveDisabled(false);\n setLinkTarget(e.target.value);\n };\n\n const handleSave: React.FormEventHandler = (e) => {\n e.stopPropagation();\n\n // If the selection is collapsed, we select the parent node because we want all the link to be replaced)\n if (editor.selection && Range.isCollapsed(editor.selection)) {\n const [, parentPath] = Editor.parent(editor, editor.selection.focus?.path);\n Transforms.select(editor, parentPath);\n }\n\n editLink(editor, { url: linkUrl, text: linkText, rel: linkRel, target: linkTarget });\n setPopoverOpen(false);\n editor.lastInsertedLinkPath = null;\n ReactEditor.focus(editor);\n };\n\n const handleClose = () => {\n if (link.url === '') {\n removeLink(editor);\n }\n\n setPopoverOpen(false);\n ReactEditor.focus(editor);\n };\n\n React.useEffect(() => {\n // Focus on the link input element when the popover opens\n if (popoverOpen) linkInputRef.current?.focus();\n }, [popoverOpen]);\n\n const inputNotDirty =\n !linkText ||\n !linkUrl ||\n (link.url &&\n link.url === linkUrl &&\n elementText &&\n elementText === linkText &&\n link.rel === linkRel &&\n link.target === linkTarget);\n\n return (\n <Popover.Root open={popoverOpen}>\n <Popover.Trigger>\n <StyledLink\n {...attributes}\n ref={forwardedRef}\n tag=\"a\"\n href={link.url}\n rel={link.rel}\n target={link.target}\n onClick={() => setPopoverOpen(true)}\n color=\"primary600\"\n >\n {children}\n </StyledLink>\n </Popover.Trigger>\n <Popover.Content onPointerDownOutside={handleClose}>\n <Flex padding={4} direction=\"column\" gap={4}>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.text',\n defaultMessage: 'Text',\n })}\n </Field.Label>\n <Field.Input\n name=\"text\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.text.placeholder',\n defaultMessage: 'Enter link text',\n })}\n value={linkText}\n onChange={(e) => {\n setLinkText(e.target.value);\n }}\n />\n </Flex>\n </Field.Root>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.link',\n defaultMessage: 'Link',\n })}\n </Field.Label>\n <Field.Input\n ref={linkInputRef}\n name=\"url\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.link.placeholder',\n defaultMessage: 'Paste link',\n })}\n value={linkUrl}\n onChange={onLinkChange}\n />\n </Flex>\n </Field.Root>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.link.rel',\n defaultMessage: 'Rel (optional)',\n })}\n </Field.Label>\n <Field.Input\n name=\"rel\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.link.rel.placeholder',\n defaultMessage: 'noopener, nofollow, noreferrer',\n })}\n value={linkRel}\n onChange={onLinkRelChange}\n />\n </Flex>\n </Field.Root>\n <Field.Root width=\"368px\">\n <Flex direction=\"column\" gap={1} alignItems=\"stretch\">\n <Field.Label>\n {formatMessage({\n id: 'components.Blocks.popover.link.target',\n defaultMessage: 'Target (optional)',\n })}\n </Field.Label>\n <Field.Input\n name=\"target\"\n placeholder={formatMessage({\n id: 'components.Blocks.popover.link.target.placeholder',\n defaultMessage: '_blank, _self, _parent, _top',\n })}\n value={linkTarget}\n onChange={onLinkTargetChange}\n />\n </Flex>\n </Field.Root>\n <Flex justifyContent=\"space-between\" width=\"100%\">\n <RemoveButton\n variant=\"danger-light\"\n onClick={() => removeLink(editor)}\n $visible={isLastInsertedLink}\n >\n {formatMessage({\n id: 'components.Blocks.popover.remove',\n defaultMessage: 'Remove',\n })}\n </RemoveButton>\n <Flex gap={2}>\n <Button variant=\"tertiary\" onClick={handleClose}>\n {formatMessage({\n id: 'global.cancel',\n defaultMessage: 'Cancel',\n })}\n </Button>\n <Button disabled={Boolean(inputNotDirty) || isSaveDisabled} onClick={handleSave}>\n {formatMessage({\n id: 'global.save',\n defaultMessage: 'Save',\n })}\n </Button>\n </Flex>\n </Flex>\n </Flex>\n </Popover.Content>\n </Popover.Root>\n );\n }\n);\n\nconst Link = React.forwardRef<HTMLAnchorElement, RenderElementProps>((props, forwardedRef) => {\n if (!isLinkNode(props.element)) {\n return null;\n }\n\n // LinkContent uses React hooks that rely on props.element being a link. If the type guard above\n // doesn't pass, those hooks would be called conditionnally, which is not allowed.\n // Hence the need for a separate component.\n return <LinkContent {...props} link={props.element} ref={forwardedRef} />;\n});\n\nconst withLinks = (editor: Editor) => {\n const { isInline, apply, insertText, insertData } = editor;\n\n // Links are inline elements, so we need to override the isInline method for slate\n editor.isInline = (element) => {\n return element.type === 'link' ? true : isInline(element);\n };\n\n // We keep a track of the last inserted link path\n // So we can show the popover on the link component if that link is the last one inserted\n editor.lastInsertedLinkPath = null;\n\n // We intercept the apply method, so everytime we insert a new link, we save its path\n editor.apply = (operation) => {\n if (operation.type === 'insert_node') {\n if (\n !Editor.isEditor(operation.node) &&\n operation.node.type === 'link' &&\n editor.shouldSaveLinkPath\n ) {\n editor.lastInsertedLinkPath = operation.path;\n }\n } else if (operation.type === 'move_node') {\n // We need to update the last inserted link path when link is moved\n // If link is the first word in the paragraph we dont need to update the path\n if (\n Path.hasPrevious(operation.path) &&\n editor.lastInsertedLinkPath &&\n editor.shouldSaveLinkPath\n ) {\n editor.lastInsertedLinkPath = Path.transform(editor.lastInsertedLinkPath, operation);\n }\n }\n\n apply(operation);\n };\n\n editor.insertText = (text) => {\n // When selection is at the end of a link and user types a space, we want to break the link\n if (editor.selection && Range.isCollapsed(editor.selection) && text === ' ') {\n const linksInSelection = Array.from(\n Editor.nodes(editor, {\n at: editor.selection,\n match: (node) => !Editor.isEditor(node) && node.type === 'link',\n })\n );\n\n const selectionIsInLink = editor.selection && linksInSelection.length > 0;\n const selectionIsAtEndOfLink =\n selectionIsInLink &&\n Point.equals(editor.selection.anchor, Editor.end(editor, linksInSelection[0][1]));\n\n if (selectionIsAtEndOfLink) {\n Transforms.insertNodes(\n editor,\n { text: ' ', type: 'text' },\n { at: Path.next(linksInSelection[0][1]), select: true }\n );\n\n return;\n }\n }\n\n insertText(text);\n };\n\n // Add data as a clickable link if its a valid URL\n editor.insertData = (data) => {\n const pastedText = data.getData('text/plain');\n\n if (pastedText) {\n try {\n // eslint-disable-next-line no-new\n new URL(pastedText);\n // Do not show link popup on copy-paste a link, so do not save its path\n editor.shouldSaveLinkPath = false;\n insertLink(editor, { url: pastedText });\n return;\n } catch (error) {\n // continue normal data insertion\n }\n }\n\n insertData(data);\n };\n\n return editor;\n};\n\nconst linkBlocks: Pick<BlocksStore, 'link'> = {\n link: {\n renderElement: (props) => (\n <Link element={props.element} attributes={props.attributes}>\n {props.children}\n </Link>\n ),\n // No handleConvert here, links are created via the link button in the toolbar\n matchNode: (node) => node.type === 'link',\n isInBlocksSelector: false,\n plugin: withLinks,\n isDraggable: () => false,\n },\n};\n\nexport interface LinkEditor extends BaseEditor {\n lastInsertedLinkPath: Path | null;\n shouldSaveLinkPath: boolean;\n}\n\nexport { linkBlocks, insertLink };\n"],"names":["isLinkNode","element","type","removeLink","editor","Transforms","unwrapNodes","match","node","Editor","isEditor","SlateElement","isElement","insertLink","url","selection","linkNodes","Array","from","nodes","at","forEach","path","Range","isCollapsed","link","children","text","rel","target","insertNodes","wrapNodes","split","editLink","linkEntry","above","linkPath","setNodes","string","linkNodeChildrens","Node","reverse","childPath","removeNodes","concat","StyledLink","styled","Box","RemoveButton","Button","props","$visible","LinkContent","React","forwardRef","attributes","forwardedRef","formatMessage","useIntl","useBlocksEditorContext","ReactEditor","findPath","popoverOpen","setPopoverOpen","useState","lastInsertedLinkPath","Path","equals","elementText","map","child","join","linkText","setLinkText","linkUrl","setLinkUrl","linkRel","setLinRel","linkTarget","setLinkTarget","linkInputRef","useRef","isLastInsertedLink","isSaveDisabled","setIsSaveDisabled","onLinkChange","e","value","URL","startsWith","error","onLinkRelChange","onLinkTargetChange","handleSave","stopPropagation","parentPath","parent","focus","select","handleClose","useEffect","current","inputNotDirty","_jsxs","Popover","Root","open","_jsx","Trigger","ref","tag","href","onClick","color","Content","onPointerDownOutside","Flex","padding","direction","gap","Field","width","alignItems","Label","id","defaultMessage","Input","name","placeholder","onChange","justifyContent","variant","disabled","Boolean","Link","withLinks","isInline","apply","insertText","insertData","operation","shouldSaveLinkPath","hasPrevious","transform","linksInSelection","selectionIsInLink","length","selectionIsAtEndOfLink","Point","anchor","end","next","data","pastedText","getData","linkBlocks","renderElement","matchNode","isInBlocksSelector","plugin","isDraggable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,aAAa,CAACC,OAAAA,GAAAA;IAClB,OAAOA,OAAAA,CAAQC,IAAI,KAAK,MAAA;AAC1B,CAAA;AAEA,MAAMC,aAAa,CAACC,MAAAA,GAAAA;IAClBC,gBAAWC,CAAAA,WAAW,CAACF,MAAQ,EAAA;AAC7BG,QAAAA,KAAAA,EAAO,CAACC,IAAAA,GAAS,CAACC,YAAAA,CAAOC,QAAQ,CAACF,IAASG,CAAAA,IAAAA,aAAAA,CAAaC,SAAS,CAACJ,IAASA,CAAAA,IAAAA,IAAAA,CAAKN,IAAI,KAAK;AAC3F,KAAA,CAAA;AACF,CAAA;AAEA,MAAMW,UAAa,GAAA,CAACT,MAAgB,EAAA,EAAEU,GAAG,EAAmB,GAAA;IAC1D,IAAIV,MAAAA,CAAOW,SAAS,EAAE;;AAEpB,QAAA,MAAMC,YAAYC,KAAMC,CAAAA,IAAI,CAC1BT,YAAOU,CAAAA,KAAK,CAACf,MAAQ,EAAA;AACnBgB,YAAAA,EAAAA,EAAIhB,OAAOW,SAAS;YACpBR,KAAO,EAAA,CAACC,OAAS,CAACC,YAAAA,CAAOC,QAAQ,CAACF,IAAAA,CAAAA,IAASA,IAAKN,CAAAA,IAAI,KAAK;AAC3D,SAAA,CAAA,CAAA;AAGFc,QAAAA,SAAAA,CAAUK,OAAO,CAAC,CAAC,GAAGC,IAAK,CAAA,GAAA;YACzBjB,gBAAWC,CAAAA,WAAW,CAACF,MAAQ,EAAA;gBAAEgB,EAAIE,EAAAA;AAAK,aAAA,CAAA;AAC5C,SAAA,CAAA;AAEA,QAAA,IAAIC,WAAMC,CAAAA,WAAW,CAACpB,MAAAA,CAAOW,SAAS,CAAG,EAAA;AACvC,YAAA,MAAMU,IAAsB,GAAA;gBAC1BvB,IA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AvB,MAAOuI,CAAAA,UAAU,GAAG,CAACa,IAAAA,GAAAA;QACnB,MAAMC,UAAAA,GAAaD,IAAKE,CAAAA,OAAO,CAAC,YAAA,CAAA;AAEhC,QAAA,IAAID,UAAY,EAAA;YACd,IAAI;;AAEF,gBAAA,IAAIjE,GAAIiE,CAAAA,UAAAA,CAAAA;;AAERrJ,gBAAAA,MAAAA,CAAOyI,kBAAkB,GAAG,KAAA;AAC5BhI,gBAAAA,UAAAA,CAAWT,MAAQ,EAAA;oBAAEU,GAAK2I,EAAAA;AAAW,iBAAA,CAAA;AACrC,gBAAA;AACF,aAAA,CAAE,OAAO/D,KAAO,EAAA;;AAEhB;AACF;QAEAiD,UAAWa,CAAAA,IAAAA,CAAAA;AACb,KAAA;IAEA,OAAOpJ,MAAAA;AACT,CAAA;AAEA,MAAMuJ,UAAwC,GAAA;IAC5ClI,IAAM,EAAA;QACJmI,aAAe,EAAA,CAAC1G,sBACdyD,cAAC2B,CAAAA,IAAAA,EAAAA;AAAKrI,gBAAAA,OAAAA,EAASiD,MAAMjD,OAAO;AAAEsD,gBAAAA,UAAAA,EAAYL,MAAMK,UAAU;AACvDL,gBAAAA,QAAAA,EAAAA,KAAAA,CAAMxB;;;AAIXmI,QAAAA,SAAAA,EAAW,CAACrJ,IAAAA,GAASA,IAAKN,CAAAA,IAAI,KAAK,MAAA;QACnC4J,kBAAoB,EAAA,KAAA;QACpBC,MAAQxB,EAAAA,SAAAA;AACRyB,QAAAA,WAAAA,EAAa,IAAM;AACrB;AACF;;;;;"}
|
|
@@ -2,13 +2,93 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { Box, Button, Popover, Flex, Field } from '@strapi/design-system';
|
|
4
4
|
import { useIntl } from 'react-intl';
|
|
5
|
-
import { Path, Range,
|
|
5
|
+
import { Editor, Path, Range, Point, Transforms, Element, Node } from 'slate';
|
|
6
6
|
import { ReactEditor } from 'slate-react';
|
|
7
7
|
import { styled } from 'styled-components';
|
|
8
8
|
import { useBlocksEditorContext } from '../BlocksEditor.mjs';
|
|
9
|
-
import { removeLink, editLink } from '../utils/links.mjs';
|
|
10
|
-
import { isLinkNode } from '../utils/types.mjs';
|
|
11
9
|
|
|
10
|
+
const isLinkNode = (element)=>{
|
|
11
|
+
return element.type === 'link';
|
|
12
|
+
};
|
|
13
|
+
const removeLink = (editor)=>{
|
|
14
|
+
Transforms.unwrapNodes(editor, {
|
|
15
|
+
match: (node)=>!Editor.isEditor(node) && Element.isElement(node) && node.type === 'link'
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const insertLink = (editor, { url })=>{
|
|
19
|
+
if (editor.selection) {
|
|
20
|
+
// We want to remove all link on the selection
|
|
21
|
+
const linkNodes = Array.from(Editor.nodes(editor, {
|
|
22
|
+
at: editor.selection,
|
|
23
|
+
match: (node)=>!Editor.isEditor(node) && node.type === 'link'
|
|
24
|
+
}));
|
|
25
|
+
linkNodes.forEach(([, path])=>{
|
|
26
|
+
Transforms.unwrapNodes(editor, {
|
|
27
|
+
at: path
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
if (Range.isCollapsed(editor.selection)) {
|
|
31
|
+
const link = {
|
|
32
|
+
type: 'link',
|
|
33
|
+
url: url ?? '',
|
|
34
|
+
children: [
|
|
35
|
+
{
|
|
36
|
+
type: 'text',
|
|
37
|
+
text: url
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
rel: '',
|
|
41
|
+
target: ''
|
|
42
|
+
};
|
|
43
|
+
Transforms.insertNodes(editor, link);
|
|
44
|
+
} else {
|
|
45
|
+
Transforms.wrapNodes(editor, {
|
|
46
|
+
type: 'link',
|
|
47
|
+
url: url ?? ''
|
|
48
|
+
}, {
|
|
49
|
+
split: true
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const editLink = (editor, link)=>{
|
|
55
|
+
const { url, text, rel, target } = link;
|
|
56
|
+
if (!editor.selection) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const linkEntry = Editor.above(editor, {
|
|
60
|
+
match: (node)=>!Editor.isEditor(node) && node.type === 'link'
|
|
61
|
+
});
|
|
62
|
+
if (linkEntry) {
|
|
63
|
+
const [, linkPath] = linkEntry;
|
|
64
|
+
Transforms.setNodes(editor, {
|
|
65
|
+
url,
|
|
66
|
+
rel,
|
|
67
|
+
target
|
|
68
|
+
}, {
|
|
69
|
+
at: linkPath
|
|
70
|
+
});
|
|
71
|
+
// If link text is different, we remove the old text and insert the new one
|
|
72
|
+
if (text !== '' && text !== Editor.string(editor, linkPath)) {
|
|
73
|
+
const linkNodeChildrens = Array.from(Node.children(editor, linkPath, {
|
|
74
|
+
reverse: true
|
|
75
|
+
}));
|
|
76
|
+
linkNodeChildrens.forEach(([, childPath])=>{
|
|
77
|
+
Transforms.removeNodes(editor, {
|
|
78
|
+
at: childPath
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
Transforms.insertNodes(editor, [
|
|
82
|
+
{
|
|
83
|
+
type: 'text',
|
|
84
|
+
text
|
|
85
|
+
}
|
|
86
|
+
], {
|
|
87
|
+
at: linkPath.concat(0)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
12
92
|
const StyledLink = styled(Box)`
|
|
13
93
|
text-decoration: none;
|
|
14
94
|
`;
|
|
@@ -258,6 +338,73 @@ const Link = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
|
258
338
|
ref: forwardedRef
|
|
259
339
|
});
|
|
260
340
|
});
|
|
341
|
+
const withLinks = (editor)=>{
|
|
342
|
+
const { isInline, apply, insertText, insertData } = editor;
|
|
343
|
+
// Links are inline elements, so we need to override the isInline method for slate
|
|
344
|
+
editor.isInline = (element)=>{
|
|
345
|
+
return element.type === 'link' ? true : isInline(element);
|
|
346
|
+
};
|
|
347
|
+
// We keep a track of the last inserted link path
|
|
348
|
+
// So we can show the popover on the link component if that link is the last one inserted
|
|
349
|
+
editor.lastInsertedLinkPath = null;
|
|
350
|
+
// We intercept the apply method, so everytime we insert a new link, we save its path
|
|
351
|
+
editor.apply = (operation)=>{
|
|
352
|
+
if (operation.type === 'insert_node') {
|
|
353
|
+
if (!Editor.isEditor(operation.node) && operation.node.type === 'link' && editor.shouldSaveLinkPath) {
|
|
354
|
+
editor.lastInsertedLinkPath = operation.path;
|
|
355
|
+
}
|
|
356
|
+
} else if (operation.type === 'move_node') {
|
|
357
|
+
// We need to update the last inserted link path when link is moved
|
|
358
|
+
// If link is the first word in the paragraph we dont need to update the path
|
|
359
|
+
if (Path.hasPrevious(operation.path) && editor.lastInsertedLinkPath && editor.shouldSaveLinkPath) {
|
|
360
|
+
editor.lastInsertedLinkPath = Path.transform(editor.lastInsertedLinkPath, operation);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
apply(operation);
|
|
364
|
+
};
|
|
365
|
+
editor.insertText = (text)=>{
|
|
366
|
+
// When selection is at the end of a link and user types a space, we want to break the link
|
|
367
|
+
if (editor.selection && Range.isCollapsed(editor.selection) && text === ' ') {
|
|
368
|
+
const linksInSelection = Array.from(Editor.nodes(editor, {
|
|
369
|
+
at: editor.selection,
|
|
370
|
+
match: (node)=>!Editor.isEditor(node) && node.type === 'link'
|
|
371
|
+
}));
|
|
372
|
+
const selectionIsInLink = editor.selection && linksInSelection.length > 0;
|
|
373
|
+
const selectionIsAtEndOfLink = selectionIsInLink && Point.equals(editor.selection.anchor, Editor.end(editor, linksInSelection[0][1]));
|
|
374
|
+
if (selectionIsAtEndOfLink) {
|
|
375
|
+
Transforms.insertNodes(editor, {
|
|
376
|
+
text: ' ',
|
|
377
|
+
type: 'text'
|
|
378
|
+
}, {
|
|
379
|
+
at: Path.next(linksInSelection[0][1]),
|
|
380
|
+
select: true
|
|
381
|
+
});
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
insertText(text);
|
|
386
|
+
};
|
|
387
|
+
// Add data as a clickable link if its a valid URL
|
|
388
|
+
editor.insertData = (data)=>{
|
|
389
|
+
const pastedText = data.getData('text/plain');
|
|
390
|
+
if (pastedText) {
|
|
391
|
+
try {
|
|
392
|
+
// eslint-disable-next-line no-new
|
|
393
|
+
new URL(pastedText);
|
|
394
|
+
// Do not show link popup on copy-paste a link, so do not save its path
|
|
395
|
+
editor.shouldSaveLinkPath = false;
|
|
396
|
+
insertLink(editor, {
|
|
397
|
+
url: pastedText
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
} catch (error) {
|
|
401
|
+
// continue normal data insertion
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
insertData(data);
|
|
405
|
+
};
|
|
406
|
+
return editor;
|
|
407
|
+
};
|
|
261
408
|
const linkBlocks = {
|
|
262
409
|
link: {
|
|
263
410
|
renderElement: (props)=>/*#__PURE__*/ jsx(Link, {
|
|
@@ -267,9 +414,11 @@ const linkBlocks = {
|
|
|
267
414
|
}),
|
|
268
415
|
// No handleConvert here, links are created via the link button in the toolbar
|
|
269
416
|
matchNode: (node)=>node.type === 'link',
|
|
270
|
-
isInBlocksSelector: false
|
|
417
|
+
isInBlocksSelector: false,
|
|
418
|
+
plugin: withLinks,
|
|
419
|
+
isDraggable: ()=>false
|
|
271
420
|
}
|
|
272
421
|
};
|
|
273
422
|
|
|
274
|
-
export { linkBlocks };
|
|
423
|
+
export { insertLink, linkBlocks };
|
|
275
424
|
//# sourceMappingURL=Link.mjs.map
|