@squiz/formatted-text-editor 2.3.0 → 2.5.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 +12 -0
- package/demo/{App.tsx → diff/App.tsx} +3 -2
- package/demo/{AppContext.tsx → diff/AppContext.tsx} +1 -2
- package/demo/diff/index.html +14 -0
- package/demo/{main.tsx → diff/main.tsx} +1 -1
- package/demo/index.html +47 -2
- package/demo/portals/Accordion.tsx +50 -0
- package/demo/portals/App.tsx +150 -0
- package/demo/portals/index.html +13 -0
- package/demo/portals/index.scss +8 -0
- package/demo/portals/index.tsx +12 -0
- package/demo/portals/preview.html +91 -0
- package/demo/portals/preview.tsx +10 -0
- package/lib/Editor/Editor.d.ts +21 -0
- package/lib/Editor/Editor.js +76 -0
- package/lib/Editor/EditorContext.d.ts +10 -0
- package/lib/Editor/EditorContext.js +16 -0
- package/lib/EditorToolbar/FloatingToolbar.d.ts +2 -0
- package/lib/EditorToolbar/FloatingToolbar.js +76 -0
- package/lib/EditorToolbar/Toolbar.d.ts +8 -0
- package/lib/EditorToolbar/Toolbar.js +51 -0
- package/lib/EditorToolbar/Tools/Bold/BoldButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Bold/BoldButton.js +23 -0
- package/lib/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.js +57 -0
- package/lib/EditorToolbar/Tools/ContentTools/ContentToolsDropdown.d.ts +3 -0
- package/lib/EditorToolbar/Tools/ContentTools/ContentToolsDropdown.js +104 -0
- package/lib/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.js +25 -0
- package/lib/EditorToolbar/Tools/Image/Form/ImageForm.d.ts +19 -0
- package/lib/EditorToolbar/Tools/Image/Form/ImageForm.js +183 -0
- package/lib/EditorToolbar/Tools/Image/ImageButton.d.ts +6 -0
- package/lib/EditorToolbar/Tools/Image/ImageButton.js +79 -0
- package/lib/EditorToolbar/Tools/Image/ImageModal.d.ts +9 -0
- package/lib/EditorToolbar/Tools/Image/ImageModal.js +26 -0
- package/lib/EditorToolbar/Tools/Italic/ItalicButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Italic/ItalicButton.js +23 -0
- package/lib/EditorToolbar/Tools/Link/Form/LinkForm.d.ts +19 -0
- package/lib/EditorToolbar/Tools/Link/Form/LinkForm.js +63 -0
- package/lib/EditorToolbar/Tools/Link/LinkButton.d.ts +6 -0
- package/lib/EditorToolbar/Tools/Link/LinkButton.js +71 -0
- package/lib/EditorToolbar/Tools/Link/LinkModal.d.ts +9 -0
- package/lib/EditorToolbar/Tools/Link/LinkModal.js +27 -0
- package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.d.ts +4 -0
- package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.js +54 -0
- package/lib/EditorToolbar/Tools/Lists/ListButtons.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Lists/ListButtons.js +14 -0
- package/lib/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.js +22 -0
- package/lib/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.js +22 -0
- package/lib/EditorToolbar/Tools/Redo/RedoButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Redo/RedoButton.js +22 -0
- package/lib/EditorToolbar/Tools/Table/TableButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Table/TableButton.js +20 -0
- package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.js +22 -0
- package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.js +22 -0
- package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.js +22 -0
- package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.js +22 -0
- package/lib/EditorToolbar/Tools/TextAlign/TextAlignButtons.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextAlign/TextAlignButtons.js +21 -0
- package/lib/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.js +22 -0
- package/lib/EditorToolbar/Tools/TextType/Heading/HeadingButton.d.ts +6 -0
- package/lib/EditorToolbar/Tools/TextType/Heading/HeadingButton.js +37 -0
- package/lib/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.js +21 -0
- package/lib/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.js +22 -0
- package/lib/EditorToolbar/Tools/TextType/TextTypeDropdown.d.ts +3 -0
- package/lib/EditorToolbar/Tools/TextType/TextTypeDropdown.js +46 -0
- package/lib/EditorToolbar/Tools/Underline/UnderlineButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Underline/UnderlineButton.js +23 -0
- package/lib/EditorToolbar/Tools/Undo/UndoButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/Undo/UndoButton.js +22 -0
- package/lib/EditorToolbar/index.d.ts +2 -0
- package/lib/EditorToolbar/index.js +18 -0
- package/lib/Extensions/ClearFormattingExtension/ClearFormattingExtension.d.ts +5 -0
- package/lib/Extensions/ClearFormattingExtension/ClearFormattingExtension.js +63 -0
- package/lib/Extensions/CodeBlockExtension/CodeBlockExtension.d.ts +15 -0
- package/lib/Extensions/CodeBlockExtension/CodeBlockExtension.js +96 -0
- package/lib/Extensions/CommandsExtension/CommandsExtension.d.ts +20 -0
- package/lib/Extensions/CommandsExtension/CommandsExtension.js +52 -0
- package/lib/Extensions/Extensions.d.ts +18 -0
- package/lib/Extensions/Extensions.js +76 -0
- package/lib/Extensions/FetchUrlExtension/FetchUrlExtension.d.ts +12 -0
- package/lib/Extensions/FetchUrlExtension/FetchUrlExtension.js +69 -0
- package/lib/Extensions/ImageExtension/AssetImageExtension.d.ts +17 -0
- package/lib/Extensions/ImageExtension/AssetImageExtension.js +91 -0
- package/lib/Extensions/ImageExtension/DAMImageExtension.d.ts +17 -0
- package/lib/Extensions/ImageExtension/DAMImageExtension.js +97 -0
- package/lib/Extensions/ImageExtension/ImageExtension.d.ts +7 -0
- package/lib/Extensions/ImageExtension/ImageExtension.js +18 -0
- package/lib/Extensions/LinkExtension/AssetLinkExtension.d.ts +27 -0
- package/lib/Extensions/LinkExtension/AssetLinkExtension.js +101 -0
- package/lib/Extensions/LinkExtension/LinkExtension.d.ts +23 -0
- package/lib/Extensions/LinkExtension/LinkExtension.js +87 -0
- package/lib/Extensions/LinkExtension/common.d.ts +7 -0
- package/lib/Extensions/LinkExtension/common.js +14 -0
- package/lib/Extensions/PreformattedExtension/PreformattedExtension.d.ts +15 -0
- package/lib/Extensions/PreformattedExtension/PreformattedExtension.js +83 -0
- package/lib/Extensions/UnsuportedExtension/UnsupportedNodeExtension.d.ts +10 -0
- package/lib/Extensions/UnsuportedExtension/UnsupportedNodeExtension.js +76 -0
- package/lib/Icons/AiIcon.d.ts +2 -0
- package/lib/Icons/AiIcon.js +60 -0
- package/lib/hooks/index.d.ts +3 -0
- package/lib/hooks/index.js +19 -0
- package/lib/hooks/useExpandedSelection/useExpandedSelection.d.ts +23 -0
- package/lib/hooks/useExpandedSelection/useExpandedSelection.js +37 -0
- package/lib/hooks/useExtensionNames/useExtensionNames.d.ts +1 -0
- package/lib/hooks/useExtensionNames/useExtensionNames.js +16 -0
- package/lib/hooks/useFocus/useFocus.d.ts +6 -0
- package/lib/hooks/useFocus/useFocus.js +57 -0
- package/lib/index.css +5894 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +16 -0
- package/lib/types.d.ts +7 -0
- package/lib/types.js +2 -0
- package/lib/ui/Button/Button.d.ts +12 -0
- package/lib/ui/Button/Button.js +13 -0
- package/lib/ui/CollapseBox/CollapseBox.d.ts +7 -0
- package/lib/ui/CollapseBox/CollapseBox.js +48 -0
- package/lib/ui/EditorInput/EditorInput.d.ts +3 -0
- package/lib/ui/EditorInput/EditorInput.js +49 -0
- package/lib/ui/EditorInput/EditorInput.props.d.ts +4 -0
- package/lib/ui/EditorInput/EditorInput.props.js +2 -0
- package/lib/ui/Fields/Checkbox/Checkbox.d.ts +9 -0
- package/lib/ui/Fields/Checkbox/Checkbox.js +47 -0
- package/lib/ui/Fields/Input/Input.d.ts +3 -0
- package/lib/ui/Fields/Input/Input.js +33 -0
- package/lib/ui/Fields/InputContainer/InputContainer.d.ts +9 -0
- package/lib/ui/Fields/InputContainer/InputContainer.js +16 -0
- package/lib/ui/Fields/MatrixAsset/MatrixAsset.d.ts +19 -0
- package/lib/ui/Fields/MatrixAsset/MatrixAsset.js +30 -0
- package/lib/ui/Fields/ResourceBrowserSelector/ResourceBrowserSelector.d.ts +28 -0
- package/lib/ui/Fields/ResourceBrowserSelector/ResourceBrowserSelector.js +88 -0
- package/lib/ui/Modal/FormModal.d.ts +5 -0
- package/lib/ui/Modal/FormModal.js +39 -0
- package/lib/ui/Modal/Modal.d.ts +11 -0
- package/lib/ui/Modal/Modal.js +79 -0
- package/lib/ui/Tabs/Tabs.d.ts +11 -0
- package/lib/ui/Tabs/Tabs.js +46 -0
- package/lib/ui/ToolbarDropdown/ToolbarDropdown.d.ts +7 -0
- package/lib/ui/ToolbarDropdown/ToolbarDropdown.js +48 -0
- package/lib/ui/ToolbarDropdownButton/ToolbarDropdownButton.d.ts +11 -0
- package/lib/ui/ToolbarDropdownButton/ToolbarDropdownButton.js +15 -0
- package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.d.ts +5 -0
- package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.js +23 -0
- package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.props.d.ts +3 -0
- package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.props.js +2 -0
- package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.d.ts +11 -0
- package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.js +235 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.d.ts +9 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +208 -0
- package/lib/utils/createToolbarPositioner.d.ts +18 -0
- package/lib/utils/createToolbarPositioner.js +96 -0
- package/lib/utils/getCursorRect.d.ts +2 -0
- package/lib/utils/getCursorRect.js +7 -0
- package/lib/utils/getMarkNamesByGroup.d.ts +2 -0
- package/lib/utils/getMarkNamesByGroup.js +9 -0
- package/lib/utils/getNodeNamesByGroup.d.ts +2 -0
- package/lib/utils/getNodeNamesByGroup.js +9 -0
- package/lib/utils/getShortcutSymbol.d.ts +1 -0
- package/lib/utils/getShortcutSymbol.js +8 -0
- package/lib/utils/undefinedIfEmpty.d.ts +1 -0
- package/lib/utils/undefinedIfEmpty.js +7 -0
- package/lib/utils/validation.d.ts +3 -0
- package/lib/utils/validation.js +16 -0
- package/package.json +1 -1
- package/src/Editor/Editor.spec.tsx +35 -10
- package/src/Editor/Editor.tsx +48 -44
- package/src/Editor/_editor.scss +4 -0
- package/src/EditorToolbar/Toolbar.tsx +8 -4
- package/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx +0 -3
- package/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.tsx +3 -3
- package/src/EditorToolbar/_toolbar.scss +3 -2
- package/src/Extensions/CodeBlockExtension/CodeBlockExtension.props.ts +3 -0
- package/src/Extensions/CodeBlockExtension/CodeBlockExtension.spec.ts +59 -0
- package/src/Extensions/CodeBlockExtension/CodeBlockExtension.ts +82 -7
- package/src/Extensions/Extensions.ts +4 -4
- package/src/Extensions/PreformattedExtension/PreformattedExtension.ts +15 -3
- package/src/hooks/index.ts +3 -2
- package/src/hooks/useFocus/useFocus.spec.tsx +48 -0
- package/src/hooks/useFocus/useFocus.ts +71 -0
- package/src/ui/EditorInput/EditorInput.props.ts +5 -0
- package/src/ui/EditorInput/EditorInput.spec.tsx +38 -0
- package/src/ui/EditorInput/EditorInput.tsx +30 -0
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.spec.ts +1 -3
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts +0 -4
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +1 -4
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +0 -5
- package/src/hooks/useFocus.ts +0 -61
- /package/demo/{index.scss → diff/index.scss} +0 -0
- /package/demo/{resources.json → diff/resources.json} +0 -0
- /package/demo/{sources.json → diff/sources.json} +0 -0
- /package/demo/{vite-env.d.ts → diff/vite-env.d.ts} +0 -0
- /package/src/hooks/{useExpandedSelection.ts → useExpandedSelection/useExpandedSelection.ts} +0 -0
- /package/src/hooks/{useExtensionNames.ts → useExtensionNames/useExtensionNames.ts} +0 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createExtensions = exports.MarkName = exports.NodeName = void 0;
|
4
|
+
const extensions_1 = require("remirror/extensions");
|
5
|
+
const PreformattedExtension_1 = require("./PreformattedExtension/PreformattedExtension");
|
6
|
+
const AssetLinkExtension_1 = require("./LinkExtension/AssetLinkExtension");
|
7
|
+
const LinkExtension_1 = require("./LinkExtension/LinkExtension");
|
8
|
+
const ImageExtension_1 = require("./ImageExtension/ImageExtension");
|
9
|
+
const CommandsExtension_1 = require("./CommandsExtension/CommandsExtension");
|
10
|
+
const AssetImageExtension_1 = require("./ImageExtension/AssetImageExtension");
|
11
|
+
const DAMImageExtension_1 = require("./ImageExtension/DAMImageExtension");
|
12
|
+
const CodeBlockExtension_1 = require("./CodeBlockExtension/CodeBlockExtension");
|
13
|
+
const ClearFormattingExtension_1 = require("./ClearFormattingExtension/ClearFormattingExtension");
|
14
|
+
const UnsupportedNodeExtension_1 = require("./UnsuportedExtension/UnsupportedNodeExtension");
|
15
|
+
const FetchUrlExtension_1 = require("./FetchUrlExtension/FetchUrlExtension");
|
16
|
+
const extension_react_tables_1 = require("@remirror/extension-react-tables");
|
17
|
+
const extension_react_component_1 = require("@remirror/extension-react-component");
|
18
|
+
var NodeName;
|
19
|
+
(function (NodeName) {
|
20
|
+
NodeName["Image"] = "image";
|
21
|
+
NodeName["CodeBlock"] = "codeBlock";
|
22
|
+
NodeName["AssetImage"] = "assetImage";
|
23
|
+
NodeName["DAMImage"] = "DAMImage";
|
24
|
+
NodeName["Text"] = "text";
|
25
|
+
NodeName["TableControllerCell"] = "tableControllerCell";
|
26
|
+
NodeName["tableCell"] = "tableCell";
|
27
|
+
NodeName["hardBreak"] = "hardBreak";
|
28
|
+
NodeName["Unsupported"] = "unsupportedNode";
|
29
|
+
})(NodeName = exports.NodeName || (exports.NodeName = {}));
|
30
|
+
var MarkName;
|
31
|
+
(function (MarkName) {
|
32
|
+
MarkName["Link"] = "link";
|
33
|
+
MarkName["AssetLink"] = "assetLink";
|
34
|
+
})(MarkName = exports.MarkName || (exports.MarkName = {}));
|
35
|
+
const createExtensions = (context, enableDecorations = true) => {
|
36
|
+
return () => {
|
37
|
+
return [
|
38
|
+
new CommandsExtension_1.CommandsExtension(),
|
39
|
+
new extensions_1.BoldExtension(),
|
40
|
+
new extensions_1.DocExtension(),
|
41
|
+
new extensions_1.HeadingExtension(),
|
42
|
+
new extensions_1.ItalicExtension(),
|
43
|
+
new extensions_1.NodeFormattingExtension({ indents: [] }),
|
44
|
+
new extensions_1.ParagraphExtension(),
|
45
|
+
new extensions_1.HardBreakExtension(),
|
46
|
+
new CodeBlockExtension_1.CodeBlockExtension({ enableDecorations }),
|
47
|
+
new PreformattedExtension_1.PreformattedExtension({ enableDecorations }),
|
48
|
+
new extensions_1.UnderlineExtension(),
|
49
|
+
new extensions_1.HistoryExtension(),
|
50
|
+
new ImageExtension_1.ImageExtension(),
|
51
|
+
new ImageExtension_1.ImageExtension({ preferPastedTextContent: false }),
|
52
|
+
new AssetImageExtension_1.AssetImageExtension({
|
53
|
+
matrixDomain: context.matrix.matrixDomain,
|
54
|
+
}),
|
55
|
+
new DAMImageExtension_1.DAMImageExtension(),
|
56
|
+
new LinkExtension_1.LinkExtension(),
|
57
|
+
new AssetLinkExtension_1.AssetLinkExtension({
|
58
|
+
matrixDomain: context.matrix.matrixDomain,
|
59
|
+
}),
|
60
|
+
new UnsupportedNodeExtension_1.UnsupportedNodeExtension(),
|
61
|
+
new ClearFormattingExtension_1.ClearFormattingExtension(),
|
62
|
+
new extensions_1.BulletListExtension(),
|
63
|
+
new extensions_1.ListItemExtension(),
|
64
|
+
new extensions_1.OrderedListExtension(),
|
65
|
+
new extensions_1.HorizontalRuleExtension(),
|
66
|
+
new extensions_1.PlaceholderExtension(),
|
67
|
+
new FetchUrlExtension_1.FetchUrlExtension({
|
68
|
+
fetchUrl: context.resolveNodeToUrl,
|
69
|
+
}),
|
70
|
+
new extensions_1.TextExtension(),
|
71
|
+
new extension_react_tables_1.TableExtension(),
|
72
|
+
new extension_react_component_1.ReactComponentExtension(),
|
73
|
+
];
|
74
|
+
};
|
75
|
+
};
|
76
|
+
exports.createExtensions = createExtensions;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { PlainExtension } from '@remirror/core';
|
2
|
+
import { Dispose, EditorView } from '@remirror/core-types';
|
3
|
+
import { ResolveNodeToUrl } from '../../types';
|
4
|
+
export type FetchUrlOptions = {
|
5
|
+
fetchUrl?: ResolveNodeToUrl;
|
6
|
+
};
|
7
|
+
export declare class FetchUrlExtension extends PlainExtension<FetchUrlOptions> {
|
8
|
+
get name(): string;
|
9
|
+
onView(view: EditorView): Dispose | void;
|
10
|
+
private findAssetLinkMark;
|
11
|
+
private fetchAndReplace;
|
12
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.FetchUrlExtension = void 0;
|
10
|
+
const core_1 = require("@remirror/core");
|
11
|
+
const Extensions_1 = require("../Extensions");
|
12
|
+
let FetchUrlExtension = class FetchUrlExtension extends core_1.PlainExtension {
|
13
|
+
get name() {
|
14
|
+
return 'fetchUrl';
|
15
|
+
}
|
16
|
+
// Implement the `onView` lifecycle method to scan for `[fetch]` and replace attributes
|
17
|
+
onView(view) {
|
18
|
+
const { state } = view;
|
19
|
+
const { tr } = state;
|
20
|
+
const promises = [];
|
21
|
+
state.doc.descendants((node, pos) => {
|
22
|
+
if (node.type.name === Extensions_1.NodeName.AssetImage && node.attrs.src === '') {
|
23
|
+
promises.push(this.fetchAndReplace(node.attrs, (url) => {
|
24
|
+
const newNode = state.schema.nodes[Extensions_1.NodeName.AssetImage].create({ ...node.attrs, src: url });
|
25
|
+
tr.replaceWith(pos, pos + node.nodeSize, newNode);
|
26
|
+
}));
|
27
|
+
}
|
28
|
+
if (node.type.name === Extensions_1.NodeName.DAMImage && node.attrs.src === '') {
|
29
|
+
promises.push(this.fetchAndReplace(node.attrs, (url) => {
|
30
|
+
const newNode = state.schema.nodes[Extensions_1.NodeName.DAMImage].create({ ...node.attrs, src: url });
|
31
|
+
tr.replaceWith(pos, pos + node.nodeSize, newNode);
|
32
|
+
}));
|
33
|
+
}
|
34
|
+
const assetLinkMark = this.findAssetLinkMark(node.marks);
|
35
|
+
if (node.type.name === 'text' && assetLinkMark) {
|
36
|
+
promises.push(this.fetchAndReplace(assetLinkMark.attrs, (url) => {
|
37
|
+
const updatedMark = assetLinkMark.type.create({ ...assetLinkMark.attrs, href: url });
|
38
|
+
tr.addMark(pos, pos + node.nodeSize, updatedMark);
|
39
|
+
}));
|
40
|
+
}
|
41
|
+
});
|
42
|
+
if (promises.length) {
|
43
|
+
Promise.all(promises).then(() => {
|
44
|
+
view.dispatch(tr);
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
findAssetLinkMark(marks) {
|
49
|
+
return marks.find((mark) => mark.type.name === Extensions_1.MarkName.AssetLink && mark.attrs.href === '');
|
50
|
+
}
|
51
|
+
fetchAndReplace(nodeAttrs, onFetched) {
|
52
|
+
return this.options
|
53
|
+
.fetchUrl(nodeAttrs)
|
54
|
+
.then((url) => {
|
55
|
+
onFetched(url);
|
56
|
+
})
|
57
|
+
.catch((error) => {
|
58
|
+
console.error('Error fetching URL:', error);
|
59
|
+
});
|
60
|
+
}
|
61
|
+
};
|
62
|
+
FetchUrlExtension = __decorate([
|
63
|
+
(0, core_1.extension)({
|
64
|
+
defaultOptions: {
|
65
|
+
fetchUrl: () => Promise.resolve(''),
|
66
|
+
},
|
67
|
+
})
|
68
|
+
], FetchUrlExtension);
|
69
|
+
exports.FetchUrlExtension = FetchUrlExtension;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { ApplySchemaAttributes, NodeExtension, NodeExtensionSpec, NodeSpecOverride, CommandFunction } from '@remirror/core';
|
2
|
+
import { NodeName } from '../Extensions';
|
3
|
+
export type AssetImageOptions = {
|
4
|
+
matrixDomain?: string;
|
5
|
+
};
|
6
|
+
export type AssetImageAttributes = {
|
7
|
+
matrixAssetId: string;
|
8
|
+
matrixIdentifier: string;
|
9
|
+
matrixDomain: string;
|
10
|
+
url: string;
|
11
|
+
};
|
12
|
+
export declare class AssetImageExtension extends NodeExtension<AssetImageOptions> {
|
13
|
+
get name(): NodeName.AssetImage;
|
14
|
+
createTags(): ("inline" | "media")[];
|
15
|
+
createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec;
|
16
|
+
insertAssetImage(attrs: AssetImageAttributes): CommandFunction;
|
17
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.AssetImageExtension = void 0;
|
10
|
+
const core_1 = require("@remirror/core");
|
11
|
+
const remirror_1 = require("remirror");
|
12
|
+
const Extensions_1 = require("../Extensions");
|
13
|
+
let AssetImageExtension = class AssetImageExtension extends core_1.NodeExtension {
|
14
|
+
get name() {
|
15
|
+
return Extensions_1.NodeName.AssetImage;
|
16
|
+
}
|
17
|
+
createTags() {
|
18
|
+
return [core_1.ExtensionTag.InlineNode, core_1.ExtensionTag.Media];
|
19
|
+
}
|
20
|
+
createNodeSpec(extra, override) {
|
21
|
+
return {
|
22
|
+
inline: true,
|
23
|
+
draggable: true,
|
24
|
+
selectable: true,
|
25
|
+
...override,
|
26
|
+
attrs: {
|
27
|
+
...extra.defaults(),
|
28
|
+
matrixAssetId: {},
|
29
|
+
matrixIdentifier: {},
|
30
|
+
matrixDomain: { default: this.options.matrixDomain },
|
31
|
+
src: { default: '' },
|
32
|
+
},
|
33
|
+
parseDOM: [
|
34
|
+
{
|
35
|
+
tag: 'img[data-matrix-asset-id]',
|
36
|
+
getAttrs: (node) => {
|
37
|
+
if (!(0, core_1.isElementDomNode)(node)) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
const matrixAssetId = node.getAttribute('data-matrix-asset-id');
|
41
|
+
const matrixIdentifier = node.getAttribute('data-matrix-identifier');
|
42
|
+
const matrixDomain = node.getAttribute('data-matrix-domain');
|
43
|
+
if (!matrixAssetId || !matrixIdentifier || !matrixDomain) {
|
44
|
+
return false;
|
45
|
+
}
|
46
|
+
return {
|
47
|
+
...extra.parse(node),
|
48
|
+
matrixAssetId,
|
49
|
+
matrixIdentifier,
|
50
|
+
matrixDomain,
|
51
|
+
};
|
52
|
+
},
|
53
|
+
},
|
54
|
+
],
|
55
|
+
toDOM: (node) => {
|
56
|
+
const { matrixAssetId, matrixIdentifier, matrixDomain, src, ...rest } = (0, core_1.omitExtraAttributes)(node.attrs, extra);
|
57
|
+
return [
|
58
|
+
'img',
|
59
|
+
{
|
60
|
+
...extra.dom(node),
|
61
|
+
...rest,
|
62
|
+
src,
|
63
|
+
'data-matrix-asset-id': matrixAssetId,
|
64
|
+
'data-matrix-identifier': matrixIdentifier,
|
65
|
+
'data-matrix-domain': matrixDomain,
|
66
|
+
},
|
67
|
+
];
|
68
|
+
},
|
69
|
+
};
|
70
|
+
}
|
71
|
+
insertAssetImage(attrs) {
|
72
|
+
return ({ tr, dispatch }) => {
|
73
|
+
const { from, to } = (0, remirror_1.getTextSelection)(tr.selection, tr.doc);
|
74
|
+
const node = this.type.create({ ...attrs, src: attrs.url });
|
75
|
+
dispatch?.(tr.replaceRangeWith(from, to, node));
|
76
|
+
return true;
|
77
|
+
};
|
78
|
+
}
|
79
|
+
};
|
80
|
+
__decorate([
|
81
|
+
(0, core_1.command)()
|
82
|
+
], AssetImageExtension.prototype, "insertAssetImage", null);
|
83
|
+
AssetImageExtension = __decorate([
|
84
|
+
(0, core_1.extension)({
|
85
|
+
defaultOptions: {
|
86
|
+
matrixDomain: '',
|
87
|
+
},
|
88
|
+
defaultPriority: core_1.ExtensionPriority.High,
|
89
|
+
})
|
90
|
+
], AssetImageExtension);
|
91
|
+
exports.AssetImageExtension = AssetImageExtension;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { ApplySchemaAttributes, NodeExtension, NodeExtensionSpec, NodeSpecOverride, CommandFunction } from '@remirror/core';
|
2
|
+
import { NodeName } from '../Extensions';
|
3
|
+
export type DAMImageAttributes = {
|
4
|
+
damObjectId: string;
|
5
|
+
damSystemIdentifier: string;
|
6
|
+
damSystemType: string;
|
7
|
+
damAdditional?: {
|
8
|
+
variant: string;
|
9
|
+
};
|
10
|
+
url: string;
|
11
|
+
};
|
12
|
+
export declare class DAMImageExtension extends NodeExtension {
|
13
|
+
get name(): NodeName.DAMImage;
|
14
|
+
createTags(): ("inline" | "media")[];
|
15
|
+
createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec;
|
16
|
+
insertDAMImage(attrs: DAMImageAttributes): CommandFunction;
|
17
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.DAMImageExtension = void 0;
|
10
|
+
const core_1 = require("@remirror/core");
|
11
|
+
const remirror_1 = require("remirror");
|
12
|
+
const Extensions_1 = require("../Extensions");
|
13
|
+
let DAMImageExtension = class DAMImageExtension extends core_1.NodeExtension {
|
14
|
+
get name() {
|
15
|
+
return Extensions_1.NodeName.DAMImage;
|
16
|
+
}
|
17
|
+
createTags() {
|
18
|
+
return [core_1.ExtensionTag.InlineNode, core_1.ExtensionTag.Media];
|
19
|
+
}
|
20
|
+
createNodeSpec(extra, override) {
|
21
|
+
return {
|
22
|
+
inline: true,
|
23
|
+
draggable: true,
|
24
|
+
selectable: true,
|
25
|
+
...override,
|
26
|
+
attrs: {
|
27
|
+
...extra.defaults(),
|
28
|
+
damObjectId: {},
|
29
|
+
damSystemIdentifier: {},
|
30
|
+
damSystemType: {},
|
31
|
+
damAdditional: { default: undefined },
|
32
|
+
src: { default: '' },
|
33
|
+
},
|
34
|
+
parseDOM: [
|
35
|
+
{
|
36
|
+
tag: 'img[data-dam-object-id]',
|
37
|
+
getAttrs: (node) => {
|
38
|
+
if (!(0, core_1.isElementDomNode)(node)) {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
const damObjectId = node.getAttribute('data-dam-object-id');
|
42
|
+
const damSystemIdentifier = node.getAttribute('data-dam-system-identifier');
|
43
|
+
const damSystemType = node.getAttribute('data-dam-system-type');
|
44
|
+
let damAdditional = node.getAttribute('data-dam-additional') || undefined;
|
45
|
+
if (!damObjectId || !damSystemIdentifier || !damSystemType) {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
if (damAdditional) {
|
49
|
+
damAdditional = JSON.parse(damAdditional);
|
50
|
+
}
|
51
|
+
return {
|
52
|
+
...extra.parse(node),
|
53
|
+
damObjectId,
|
54
|
+
damSystemIdentifier,
|
55
|
+
damSystemType,
|
56
|
+
damAdditional,
|
57
|
+
src: '',
|
58
|
+
};
|
59
|
+
},
|
60
|
+
},
|
61
|
+
],
|
62
|
+
toDOM: (node) => {
|
63
|
+
const { damObjectId, damSystemIdentifier, damSystemType, damAdditional, src, ...rest } = (0, core_1.omitExtraAttributes)(node.attrs, extra);
|
64
|
+
return [
|
65
|
+
'img',
|
66
|
+
{
|
67
|
+
...extra.dom(node),
|
68
|
+
...rest,
|
69
|
+
src,
|
70
|
+
'data-dam-object-id': damObjectId,
|
71
|
+
'data-dam-system-identifier': damSystemIdentifier,
|
72
|
+
'data-dam-system-type': damSystemType,
|
73
|
+
'data-dam-additional': damAdditional ? JSON.stringify(damAdditional) : undefined,
|
74
|
+
},
|
75
|
+
];
|
76
|
+
},
|
77
|
+
};
|
78
|
+
}
|
79
|
+
insertDAMImage(attrs) {
|
80
|
+
return ({ tr, dispatch }) => {
|
81
|
+
const { from, to } = (0, remirror_1.getTextSelection)(tr.selection, tr.doc);
|
82
|
+
const node = this.type.create({ ...attrs, src: attrs.url });
|
83
|
+
dispatch?.(tr.replaceRangeWith(from, to, node));
|
84
|
+
return true;
|
85
|
+
};
|
86
|
+
}
|
87
|
+
};
|
88
|
+
__decorate([
|
89
|
+
(0, core_1.command)()
|
90
|
+
], DAMImageExtension.prototype, "insertDAMImage", null);
|
91
|
+
DAMImageExtension = __decorate([
|
92
|
+
(0, core_1.extension)({
|
93
|
+
defaultOptions: {},
|
94
|
+
defaultPriority: core_1.ExtensionPriority.High,
|
95
|
+
})
|
96
|
+
], DAMImageExtension);
|
97
|
+
exports.DAMImageExtension = DAMImageExtension;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ImageExtension as RemirrorImageExtension } from 'remirror/extensions';
|
2
|
+
import { PasteRule } from 'prosemirror-paste-rules';
|
3
|
+
import { ApplySchemaAttributes, NodeSpecOverride, NodeExtensionSpec } from '@remirror/core';
|
4
|
+
export declare class ImageExtension extends RemirrorImageExtension {
|
5
|
+
createPasteRules(): PasteRule[];
|
6
|
+
createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec;
|
7
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ImageExtension = void 0;
|
4
|
+
const extensions_1 = require("remirror/extensions");
|
5
|
+
class ImageExtension extends extensions_1.ImageExtension {
|
6
|
+
createPasteRules() {
|
7
|
+
// override super behaviour of handling file uploads.
|
8
|
+
return [];
|
9
|
+
}
|
10
|
+
createNodeSpec(extra, override) {
|
11
|
+
const spec = super.createNodeSpec(extra, override);
|
12
|
+
return {
|
13
|
+
...spec,
|
14
|
+
selectable: true,
|
15
|
+
};
|
16
|
+
}
|
17
|
+
}
|
18
|
+
exports.ImageExtension = ImageExtension;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { ApplySchemaAttributes, FromToProps, MarkExtensionSpec, MarkSpecOverride } from 'remirror';
|
2
|
+
import { CommandFunction, MarkExtension } from '@remirror/core';
|
3
|
+
import { LinkTarget } from './common';
|
4
|
+
export type AssetLinkAttributes = {
|
5
|
+
matrixAssetId: string;
|
6
|
+
matrixIdentifier: string;
|
7
|
+
matrixDomain: string;
|
8
|
+
target: LinkTarget;
|
9
|
+
href: string;
|
10
|
+
url: string;
|
11
|
+
};
|
12
|
+
export type AssetLinkOptions = {
|
13
|
+
matrixDomain?: string;
|
14
|
+
defaultTarget?: LinkTarget;
|
15
|
+
supportedTargets?: LinkTarget[];
|
16
|
+
};
|
17
|
+
export type UpdateAssetLinkProps = {
|
18
|
+
text: string;
|
19
|
+
attrs: Partial<AssetLinkAttributes>;
|
20
|
+
range: FromToProps;
|
21
|
+
};
|
22
|
+
export declare class AssetLinkExtension extends MarkExtension<AssetLinkOptions> {
|
23
|
+
get name(): string;
|
24
|
+
createMarkSpec(extra: ApplySchemaAttributes, override: MarkSpecOverride): MarkExtensionSpec;
|
25
|
+
updateAssetLink({ text, attrs, range }: UpdateAssetLinkProps): CommandFunction;
|
26
|
+
removeAssetLink(): CommandFunction;
|
27
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.AssetLinkExtension = void 0;
|
10
|
+
const remirror_1 = require("remirror");
|
11
|
+
const core_1 = require("@remirror/core");
|
12
|
+
const common_1 = require("./common");
|
13
|
+
const CommandsExtension_1 = require("../CommandsExtension/CommandsExtension");
|
14
|
+
const Extensions_1 = require("../Extensions");
|
15
|
+
let AssetLinkExtension = class AssetLinkExtension extends core_1.MarkExtension {
|
16
|
+
get name() {
|
17
|
+
return Extensions_1.MarkName.AssetLink;
|
18
|
+
}
|
19
|
+
createMarkSpec(extra, override) {
|
20
|
+
return {
|
21
|
+
inclusive: false,
|
22
|
+
excludes: [this.name, Extensions_1.MarkName.Link].join(' '),
|
23
|
+
...override,
|
24
|
+
attrs: {
|
25
|
+
...extra.defaults(),
|
26
|
+
matrixAssetId: {},
|
27
|
+
matrixIdentifier: {},
|
28
|
+
href: { default: '' },
|
29
|
+
matrixDomain: { default: this.options.matrixDomain },
|
30
|
+
target: { default: this.options.defaultTarget },
|
31
|
+
},
|
32
|
+
parseDOM: [
|
33
|
+
{
|
34
|
+
tag: 'a[data-matrix-asset-id]',
|
35
|
+
getAttrs: (node) => {
|
36
|
+
if (!(0, remirror_1.isElementDomNode)(node)) {
|
37
|
+
return false;
|
38
|
+
}
|
39
|
+
const matrixAssetId = node.getAttribute('data-matrix-asset-id');
|
40
|
+
const matrixIdentifier = node.getAttribute('data-matrix-identifier');
|
41
|
+
const matrixDomain = node.getAttribute('data-matrix-domain');
|
42
|
+
if (!matrixAssetId || !matrixIdentifier || !matrixDomain) {
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
return {
|
46
|
+
...extra.parse(node),
|
47
|
+
matrixAssetId,
|
48
|
+
matrixIdentifier,
|
49
|
+
matrixDomain,
|
50
|
+
target: (0, common_1.validateTarget)(node.getAttribute('target'), this.options.supportedTargets, this.options.defaultTarget),
|
51
|
+
};
|
52
|
+
},
|
53
|
+
},
|
54
|
+
],
|
55
|
+
toDOM: (node) => {
|
56
|
+
const { matrixAssetId, matrixIdentifier, matrixDomain, target, href, ...rest } = (0, core_1.omitExtraAttributes)(node.attrs, extra);
|
57
|
+
const rel = 'noopener noreferrer nofollow';
|
58
|
+
const attrs = {
|
59
|
+
...extra.dom(node),
|
60
|
+
...rest,
|
61
|
+
rel,
|
62
|
+
href,
|
63
|
+
target: (0, common_1.validateTarget)(target, this.options.supportedTargets, this.options.defaultTarget),
|
64
|
+
'data-matrix-asset-id': matrixAssetId,
|
65
|
+
'data-matrix-identifier': matrixIdentifier,
|
66
|
+
'data-matrix-domain': matrixDomain,
|
67
|
+
};
|
68
|
+
return ['a', attrs, 0];
|
69
|
+
},
|
70
|
+
};
|
71
|
+
}
|
72
|
+
updateAssetLink({ text, attrs, range }) {
|
73
|
+
return this.store.getExtension(CommandsExtension_1.CommandsExtension).updateMark({
|
74
|
+
attrs: { ...attrs, href: attrs.url },
|
75
|
+
text,
|
76
|
+
range,
|
77
|
+
mark: this.type,
|
78
|
+
removeMark: !attrs.matrixAssetId,
|
79
|
+
});
|
80
|
+
}
|
81
|
+
removeAssetLink() {
|
82
|
+
return (0, core_1.removeMark)({ type: this.type });
|
83
|
+
}
|
84
|
+
};
|
85
|
+
__decorate([
|
86
|
+
(0, core_1.command)()
|
87
|
+
], AssetLinkExtension.prototype, "updateAssetLink", null);
|
88
|
+
__decorate([
|
89
|
+
(0, core_1.command)()
|
90
|
+
], AssetLinkExtension.prototype, "removeAssetLink", null);
|
91
|
+
AssetLinkExtension = __decorate([
|
92
|
+
(0, core_1.extension)({
|
93
|
+
defaultOptions: {
|
94
|
+
matrixDomain: '',
|
95
|
+
defaultTarget: common_1.LinkTarget.Self,
|
96
|
+
supportedTargets: [common_1.LinkTarget.Self, common_1.LinkTarget.Blank],
|
97
|
+
},
|
98
|
+
defaultPriority: remirror_1.ExtensionPriority.High,
|
99
|
+
})
|
100
|
+
], AssetLinkExtension);
|
101
|
+
exports.AssetLinkExtension = AssetLinkExtension;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { ApplySchemaAttributes, FromToProps, MarkExtensionSpec, MarkSpecOverride } from 'remirror';
|
2
|
+
import { CommandFunction, MarkExtension } from '@remirror/core';
|
3
|
+
import { LinkTarget } from './common';
|
4
|
+
export type LinkAttributes = {
|
5
|
+
href: string;
|
6
|
+
title?: string;
|
7
|
+
target: LinkTarget;
|
8
|
+
};
|
9
|
+
export type LinkOptions = {
|
10
|
+
defaultTarget?: LinkTarget;
|
11
|
+
supportedTargets?: LinkTarget[];
|
12
|
+
};
|
13
|
+
export type UpdateLinkProps = {
|
14
|
+
text: string;
|
15
|
+
attrs: Partial<LinkAttributes>;
|
16
|
+
range: FromToProps;
|
17
|
+
};
|
18
|
+
export declare class LinkExtension extends MarkExtension<LinkOptions> {
|
19
|
+
get name(): string;
|
20
|
+
createMarkSpec(extra: ApplySchemaAttributes, override: MarkSpecOverride): MarkExtensionSpec;
|
21
|
+
updateLink({ text, attrs, range }: UpdateLinkProps): CommandFunction;
|
22
|
+
removeLink(): CommandFunction;
|
23
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.LinkExtension = void 0;
|
10
|
+
const remirror_1 = require("remirror");
|
11
|
+
const core_1 = require("@remirror/core");
|
12
|
+
const common_1 = require("./common");
|
13
|
+
const CommandsExtension_1 = require("../CommandsExtension/CommandsExtension");
|
14
|
+
const Extensions_1 = require("../Extensions");
|
15
|
+
let LinkExtension = class LinkExtension extends core_1.MarkExtension {
|
16
|
+
get name() {
|
17
|
+
return Extensions_1.MarkName.Link;
|
18
|
+
}
|
19
|
+
createMarkSpec(extra, override) {
|
20
|
+
return {
|
21
|
+
inclusive: false,
|
22
|
+
excludes: [this.name, Extensions_1.MarkName.AssetLink].join(' '),
|
23
|
+
...override,
|
24
|
+
attrs: {
|
25
|
+
...extra.defaults(),
|
26
|
+
href: {},
|
27
|
+
title: { default: undefined },
|
28
|
+
target: { default: this.options.defaultTarget },
|
29
|
+
},
|
30
|
+
parseDOM: [
|
31
|
+
{
|
32
|
+
tag: 'a[href]',
|
33
|
+
getAttrs: (node) => {
|
34
|
+
if (!(0, remirror_1.isElementDomNode)(node)) {
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
return {
|
38
|
+
...extra.parse(node),
|
39
|
+
href: node.getAttribute('href'),
|
40
|
+
title: node.getAttribute('title'),
|
41
|
+
target: (0, common_1.validateTarget)(node.getAttribute('target'), this.options.supportedTargets, this.options.defaultTarget),
|
42
|
+
};
|
43
|
+
},
|
44
|
+
},
|
45
|
+
],
|
46
|
+
toDOM: (node) => {
|
47
|
+
const { target, ...rest } = (0, core_1.omitExtraAttributes)(node.attrs, extra);
|
48
|
+
const rel = 'noopener noreferrer nofollow';
|
49
|
+
const attrs = {
|
50
|
+
...extra.dom(node),
|
51
|
+
...rest,
|
52
|
+
rel,
|
53
|
+
target: (0, common_1.validateTarget)(target, this.options.supportedTargets, this.options.defaultTarget),
|
54
|
+
};
|
55
|
+
return ['a', attrs, 0];
|
56
|
+
},
|
57
|
+
};
|
58
|
+
}
|
59
|
+
updateLink({ text, attrs, range }) {
|
60
|
+
return this.store.getExtension(CommandsExtension_1.CommandsExtension).updateMark({
|
61
|
+
attrs,
|
62
|
+
text,
|
63
|
+
range,
|
64
|
+
mark: this.type,
|
65
|
+
removeMark: !attrs.href,
|
66
|
+
});
|
67
|
+
}
|
68
|
+
removeLink() {
|
69
|
+
return (0, core_1.removeMark)({ type: this.type });
|
70
|
+
}
|
71
|
+
};
|
72
|
+
__decorate([
|
73
|
+
(0, core_1.command)()
|
74
|
+
], LinkExtension.prototype, "updateLink", null);
|
75
|
+
__decorate([
|
76
|
+
(0, core_1.command)()
|
77
|
+
], LinkExtension.prototype, "removeLink", null);
|
78
|
+
LinkExtension = __decorate([
|
79
|
+
(0, core_1.extension)({
|
80
|
+
defaultOptions: {
|
81
|
+
defaultTarget: common_1.LinkTarget.Self,
|
82
|
+
supportedTargets: [common_1.LinkTarget.Self, common_1.LinkTarget.Blank],
|
83
|
+
},
|
84
|
+
defaultPriority: remirror_1.ExtensionPriority.Medium,
|
85
|
+
})
|
86
|
+
], LinkExtension);
|
87
|
+
exports.LinkExtension = LinkExtension;
|