@squiz/formatted-text-editor 1.21.1-alpha.3 → 1.21.1-alpha.30
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/demo/App.tsx +45 -10
- package/demo/index.scss +11 -10
- package/jest.config.ts +0 -2
- package/lib/Editor/Editor.d.ts +1 -0
- package/lib/Editor/Editor.js +45 -7
- package/lib/Editor/EditorContext.d.ts +10 -0
- package/lib/Editor/EditorContext.js +15 -0
- package/lib/EditorToolbar/FloatingToolbar.d.ts +1 -0
- package/lib/EditorToolbar/FloatingToolbar.js +11 -5
- package/lib/EditorToolbar/Toolbar.d.ts +1 -0
- package/lib/EditorToolbar/Toolbar.js +3 -1
- package/lib/EditorToolbar/Tools/Bold/BoldButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Bold/BoldButton.js +2 -2
- package/lib/EditorToolbar/Tools/Image/Form/ImageForm.d.ts +17 -0
- package/lib/EditorToolbar/Tools/Image/Form/ImageForm.js +82 -0
- package/lib/EditorToolbar/Tools/Image/ImageButton.d.ts +6 -0
- package/lib/EditorToolbar/Tools/Image/ImageButton.js +77 -0
- package/lib/EditorToolbar/Tools/Image/ImageModal.d.ts +9 -0
- package/lib/EditorToolbar/Tools/Image/ImageModal.js +16 -0
- package/lib/EditorToolbar/Tools/Italic/ItalicButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Italic/ItalicButton.js +2 -2
- package/lib/EditorToolbar/Tools/Link/Form/LinkForm.d.ts +14 -5
- package/lib/EditorToolbar/Tools/Link/Form/LinkForm.js +67 -15
- package/lib/EditorToolbar/Tools/Link/LinkButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Link/LinkButton.js +22 -14
- package/lib/EditorToolbar/Tools/Link/LinkModal.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Link/LinkModal.js +12 -5
- package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.js +2 -9
- package/lib/EditorToolbar/Tools/Redo/RedoButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Redo/RedoButton.js +2 -2
- package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.js +2 -2
- package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.js +2 -2
- package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.js +2 -2
- package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.js +2 -2
- package/lib/EditorToolbar/Tools/TextAlign/TextAlignButtons.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextType/Heading/HeadingButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/TextType/TextTypeDropdown.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Underline/UnderlineButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Underline/UnderlineButton.js +2 -2
- package/lib/EditorToolbar/Tools/Undo/UndoButton.d.ts +1 -0
- package/lib/EditorToolbar/Tools/Undo/UndoButton.js +2 -2
- package/lib/Extensions/CommandsExtension/CommandsExtension.d.ts +20 -0
- package/lib/Extensions/CommandsExtension/CommandsExtension.js +52 -0
- package/lib/Extensions/Extensions.d.ts +7 -4
- package/lib/Extensions/Extensions.js +32 -19
- package/lib/Extensions/ImageExtension/ImageExtension.d.ts +10 -0
- package/lib/Extensions/ImageExtension/ImageExtension.js +92 -0
- package/lib/Extensions/LinkExtension/AssetLinkExtension.d.ts +26 -0
- package/lib/Extensions/LinkExtension/AssetLinkExtension.js +102 -0
- package/lib/Extensions/LinkExtension/LinkExtension.d.ts +21 -12
- package/lib/Extensions/LinkExtension/LinkExtension.js +63 -65
- package/lib/Extensions/LinkExtension/common.d.ts +7 -0
- package/lib/Extensions/LinkExtension/common.js +14 -0
- package/lib/Extensions/PreformattedExtension/PreformattedExtension.d.ts +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/useExpandedSelection.d.ts +23 -0
- package/lib/hooks/useExpandedSelection.js +37 -0
- package/lib/index.css +159 -74
- package/lib/index.d.ts +5 -2
- package/lib/index.js +9 -3
- package/lib/types.d.ts +3 -0
- package/lib/types.js +2 -0
- package/lib/ui/Button/Button.d.ts +11 -0
- package/lib/ui/{ToolbarButton/ToolbarButton.js → Button/Button.js} +6 -3
- package/lib/ui/Fields/Input/Input.d.ts +5 -0
- package/lib/ui/{Inputs/Text/TextInput.js → Fields/Input/Input.js} +10 -5
- package/lib/ui/{Inputs → Fields}/Select/Select.d.ts +1 -0
- package/lib/ui/Modal/Modal.js +5 -3
- package/lib/ui/ToolbarDropdown/ToolbarDropdown.d.ts +1 -0
- package/lib/ui/ToolbarDropdownButton/ToolbarDropdownButton.d.ts +1 -0
- package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.d.ts +9 -0
- package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.js +165 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.d.ts +9 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +129 -0
- package/lib/utils/undefinedIfEmpty.d.ts +1 -0
- package/lib/utils/undefinedIfEmpty.js +7 -0
- package/package.json +11 -4
- package/src/Editor/Editor.spec.tsx +78 -18
- package/src/Editor/Editor.tsx +28 -9
- package/src/Editor/EditorContext.spec.tsx +26 -0
- package/src/Editor/EditorContext.ts +19 -0
- package/src/Editor/_editor.scss +20 -51
- package/src/EditorToolbar/FloatingToolbar.spec.tsx +2 -3
- package/src/EditorToolbar/FloatingToolbar.tsx +15 -6
- package/src/EditorToolbar/Toolbar.tsx +2 -0
- package/src/EditorToolbar/Tools/Bold/BoldButton.spec.tsx +1 -1
- package/src/EditorToolbar/Tools/Bold/BoldButton.tsx +2 -2
- package/src/EditorToolbar/Tools/Image/Form/ImageForm.spec.tsx +77 -0
- package/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx +90 -0
- package/src/EditorToolbar/Tools/Image/ImageButton.spec.tsx +135 -0
- package/src/EditorToolbar/Tools/Image/ImageButton.tsx +72 -0
- package/src/EditorToolbar/Tools/Image/ImageModal.spec.tsx +83 -0
- package/src/EditorToolbar/Tools/Image/ImageModal.tsx +24 -0
- package/src/EditorToolbar/Tools/Italic/ItalicButton.spec.tsx +1 -1
- package/src/EditorToolbar/Tools/Italic/ItalicButton.tsx +2 -2
- package/src/EditorToolbar/Tools/Link/Form/LinkForm.spec.tsx +37 -9
- package/src/EditorToolbar/Tools/Link/Form/LinkForm.tsx +97 -27
- package/src/EditorToolbar/Tools/Link/LinkButton.spec.tsx +104 -26
- package/src/EditorToolbar/Tools/Link/LinkButton.tsx +30 -21
- package/src/EditorToolbar/Tools/Link/LinkModal.tsx +13 -6
- package/src/EditorToolbar/Tools/Link/RemoveLinkButton.spec.tsx +26 -26
- package/src/EditorToolbar/Tools/Link/RemoveLinkButton.tsx +4 -12
- package/src/EditorToolbar/Tools/Redo/RedoButton.tsx +2 -2
- package/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.tsx +2 -2
- package/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.tsx +2 -2
- package/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.tsx +2 -2
- package/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.tsx +2 -2
- package/src/EditorToolbar/Tools/Underline/Underline.spec.tsx +1 -1
- package/src/EditorToolbar/Tools/Underline/UnderlineButton.tsx +2 -2
- package/src/EditorToolbar/Tools/Undo/UndoButton.spec.tsx +22 -1
- package/src/EditorToolbar/Tools/Undo/UndoButton.tsx +2 -2
- package/src/EditorToolbar/_floating-toolbar.scss +5 -0
- package/src/EditorToolbar/_toolbar.scss +11 -5
- package/src/Extensions/CommandsExtension/CommandsExtension.ts +54 -0
- package/src/Extensions/Extensions.ts +32 -17
- package/src/Extensions/ImageExtension/ImageExtension.ts +112 -0
- package/src/Extensions/LinkExtension/AssetLinkExtension.spec.ts +104 -0
- package/src/Extensions/LinkExtension/AssetLinkExtension.ts +128 -0
- package/src/Extensions/LinkExtension/LinkExtension.spec.ts +68 -0
- package/src/Extensions/LinkExtension/LinkExtension.ts +88 -82
- package/src/Extensions/LinkExtension/common.ts +10 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useExpandedSelection.ts +44 -0
- package/src/index.scss +2 -2
- package/src/index.ts +5 -2
- package/src/types.ts +5 -0
- package/src/ui/Button/Button.spec.tsx +44 -0
- package/src/ui/Button/Button.tsx +29 -0
- package/src/ui/{_buttons.scss → Button/_button.scss} +19 -1
- package/src/ui/{Inputs/Text/TextInput.spec.tsx → Fields/Input/Input.spec.tsx} +8 -8
- package/src/ui/Fields/Input/Input.tsx +34 -0
- package/src/ui/Modal/Modal.spec.tsx +15 -0
- package/src/ui/Modal/Modal.tsx +8 -4
- package/src/ui/ToolbarDropdown/_toolbar-dropdown.scss +1 -1
- package/src/ui/_forms.scss +14 -0
- package/src/ui/_typography.scss +46 -0
- package/src/utils/converters/mocks/squizNodeJson.mock.ts +252 -0
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.spec.ts +480 -0
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts +202 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +329 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +151 -0
- package/src/utils/undefinedIfEmpty.spec.ts +12 -0
- package/src/utils/undefinedIfEmpty.ts +3 -0
- package/tailwind.config.cjs +3 -0
- package/tests/renderWithEditor.tsx +28 -15
- package/tsconfig.json +1 -1
- package/lib/FormattedTextEditor.d.ts +0 -2
- package/lib/FormattedTextEditor.js +0 -7
- package/lib/ui/Inputs/Text/TextInput.d.ts +0 -4
- package/lib/ui/ToolbarButton/ToolbarButton.d.ts +0 -10
- package/src/Editor/Editor.mock.tsx +0 -43
- package/src/FormattedTextEditor.spec.tsx +0 -10
- package/src/FormattedTextEditor.tsx +0 -3
- package/src/ui/Inputs/Text/TextInput.tsx +0 -20
- package/src/ui/ToolbarButton/ToolbarButton.tsx +0 -26
- package/src/ui/ToolbarButton/_toolbar-button.scss +0 -17
- /package/lib/ui/{Inputs → Fields}/Select/Select.js +0 -0
- /package/src/ui/{Inputs → Fields}/Select/Select.spec.tsx +0 -0
- /package/src/ui/{Inputs → Fields}/Select/Select.tsx +0 -0
- /package/tests/{select.tsx → select.ts} +0 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ImageExtension = void 0;
|
4
|
+
const extensions_1 = require("remirror/extensions");
|
5
|
+
const core_1 = require("@remirror/core");
|
6
|
+
/**
|
7
|
+
* Get the width and the height of the image.
|
8
|
+
*/
|
9
|
+
function getDimensions(element) {
|
10
|
+
let { width, height } = element.style;
|
11
|
+
width = width || element.getAttribute('width') || '';
|
12
|
+
height = height || element.getAttribute('height') || '';
|
13
|
+
return { width, height };
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* Retrieve attributes from the dom for the image extension.
|
17
|
+
*/
|
18
|
+
function getImageAttributes({ element, parse }) {
|
19
|
+
const { width, height } = getDimensions(element);
|
20
|
+
return {
|
21
|
+
...parse(element),
|
22
|
+
alt: element.getAttribute('alt') ?? '',
|
23
|
+
height: Number.parseInt(height || '0', 10) || null,
|
24
|
+
src: element.getAttribute('src') ?? null,
|
25
|
+
title: element.getAttribute('title') ?? '',
|
26
|
+
width: Number.parseInt(width || '0', 10) || null,
|
27
|
+
fileName: element.getAttribute('data-file-name') ?? null,
|
28
|
+
};
|
29
|
+
}
|
30
|
+
class ImageExtension extends extensions_1.ImageExtension {
|
31
|
+
createPasteRules() {
|
32
|
+
return [
|
33
|
+
{
|
34
|
+
type: 'file',
|
35
|
+
regexp: /image/i,
|
36
|
+
fileHandler: () => {
|
37
|
+
return false;
|
38
|
+
},
|
39
|
+
},
|
40
|
+
];
|
41
|
+
}
|
42
|
+
createNodeSpec(extra, override) {
|
43
|
+
const { preferPastedTextContent } = this.options;
|
44
|
+
return {
|
45
|
+
inline: true,
|
46
|
+
draggable: true,
|
47
|
+
selectable: true,
|
48
|
+
...override,
|
49
|
+
attrs: {
|
50
|
+
...extra.defaults(),
|
51
|
+
alt: { default: '' },
|
52
|
+
crop: { default: null },
|
53
|
+
height: { default: null },
|
54
|
+
width: { default: null },
|
55
|
+
rotate: { default: null },
|
56
|
+
src: { default: null },
|
57
|
+
title: { default: '' },
|
58
|
+
fileName: { default: null },
|
59
|
+
resizable: { default: false },
|
60
|
+
},
|
61
|
+
parseDOM: [
|
62
|
+
{
|
63
|
+
tag: 'img[src]',
|
64
|
+
getAttrs: (element) => {
|
65
|
+
if ((0, core_1.isElementDomNode)(element)) {
|
66
|
+
const attrs = getImageAttributes({ element, parse: extra.parse });
|
67
|
+
if (preferPastedTextContent && attrs.src?.startsWith('file:///')) {
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
return attrs;
|
71
|
+
}
|
72
|
+
return {};
|
73
|
+
},
|
74
|
+
},
|
75
|
+
...(override.parseDOM ?? []),
|
76
|
+
],
|
77
|
+
toDOM: (node) => {
|
78
|
+
const attrs = (0, core_1.omitExtraAttributes)(node.attrs, extra);
|
79
|
+
return ['img', { ...extra.dom(node), ...attrs }];
|
80
|
+
},
|
81
|
+
};
|
82
|
+
}
|
83
|
+
insertImage(attributes, selection) {
|
84
|
+
return ({ tr, dispatch }) => {
|
85
|
+
const { from, to } = (0, core_1.getTextSelection)(selection ?? tr.selection, tr.doc);
|
86
|
+
const node = this.type.create(attributes);
|
87
|
+
dispatch?.(tr.replaceRangeWith(from, to, node));
|
88
|
+
return true;
|
89
|
+
};
|
90
|
+
}
|
91
|
+
}
|
92
|
+
exports.ImageExtension = ImageExtension;
|
@@ -0,0 +1,26 @@
|
|
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
|
+
};
|
10
|
+
export type AssetLinkOptions = {
|
11
|
+
matrixIdentifier?: string;
|
12
|
+
matrixDomain?: string;
|
13
|
+
defaultTarget?: LinkTarget;
|
14
|
+
supportedTargets?: LinkTarget[];
|
15
|
+
};
|
16
|
+
export type UpdateAssetLinkProps = {
|
17
|
+
text: string;
|
18
|
+
attrs: Partial<AssetLinkAttributes>;
|
19
|
+
range: FromToProps;
|
20
|
+
};
|
21
|
+
export declare class AssetLinkExtension extends MarkExtension<AssetLinkOptions> {
|
22
|
+
get name(): string;
|
23
|
+
createMarkSpec(extra: ApplySchemaAttributes, override: MarkSpecOverride): MarkExtensionSpec;
|
24
|
+
updateAssetLink({ text, attrs, range }: UpdateAssetLinkProps): CommandFunction;
|
25
|
+
removeAssetLink(): CommandFunction;
|
26
|
+
}
|
@@ -0,0 +1,102 @@
|
|
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: 'link',
|
23
|
+
...override,
|
24
|
+
attrs: {
|
25
|
+
...extra.defaults(),
|
26
|
+
matrixAssetId: {},
|
27
|
+
matrixIdentifier: { default: this.options.matrixIdentifier },
|
28
|
+
matrixDomain: { default: this.options.matrixDomain },
|
29
|
+
target: { default: this.options.defaultTarget },
|
30
|
+
},
|
31
|
+
parseDOM: [
|
32
|
+
{
|
33
|
+
tag: 'a[data-matrix-asset-id]',
|
34
|
+
getAttrs: (node) => {
|
35
|
+
if (!(0, remirror_1.isElementDomNode)(node)) {
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
const matrixAssetId = node.getAttribute('data-matrix-asset-id');
|
39
|
+
const matrixIdentifier = node.getAttribute('data-matrix-identifier');
|
40
|
+
const matrixDomain = node.getAttribute('data-matrix-domain');
|
41
|
+
if (!matrixAssetId || !matrixIdentifier || !matrixDomain) {
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
return {
|
45
|
+
...extra.parse(node),
|
46
|
+
matrixAssetId,
|
47
|
+
matrixIdentifier,
|
48
|
+
matrixDomain,
|
49
|
+
target: (0, common_1.validateTarget)(node.getAttribute('target'), this.options.supportedTargets, this.options.defaultTarget),
|
50
|
+
};
|
51
|
+
},
|
52
|
+
},
|
53
|
+
],
|
54
|
+
toDOM: (node) => {
|
55
|
+
const { matrixAssetId, matrixIdentifier, matrixDomain, target, ...rest } = (0, core_1.omitExtraAttributes)(node.attrs, extra);
|
56
|
+
const rel = 'noopener noreferrer nofollow';
|
57
|
+
const attrs = {
|
58
|
+
...extra.dom(node),
|
59
|
+
...rest,
|
60
|
+
rel,
|
61
|
+
// TODO: this won't be acceptable if/when we get to rendering outside of Matrix.
|
62
|
+
href: `/?a=${matrixAssetId}`,
|
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,
|
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
|
+
matrixIdentifier: '',
|
95
|
+
matrixDomain: '',
|
96
|
+
defaultTarget: common_1.LinkTarget.Self,
|
97
|
+
supportedTargets: [common_1.LinkTarget.Self, common_1.LinkTarget.Blank],
|
98
|
+
},
|
99
|
+
defaultPriority: remirror_1.ExtensionPriority.High,
|
100
|
+
})
|
101
|
+
], AssetLinkExtension);
|
102
|
+
exports.AssetLinkExtension = AssetLinkExtension;
|
@@ -1,16 +1,25 @@
|
|
1
|
-
import { ApplySchemaAttributes, MarkExtensionSpec, MarkSpecOverride } from 'remirror';
|
2
|
-
import { KeyBindingProps } from '@remirror/core';
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
text: string;
|
7
|
-
};
|
8
|
-
export type LinkAttributes = RemirrorLinkAttributes & {
|
1
|
+
import { ApplySchemaAttributes, FromToProps, MarkExtensionSpec, MarkSpecOverride } from 'remirror';
|
2
|
+
import { CommandFunction, Handler, KeyBindingProps, MarkExtension } from '@remirror/core';
|
3
|
+
import { LinkTarget } from './common';
|
4
|
+
export type LinkAttributes = {
|
5
|
+
href: string;
|
9
6
|
title?: string;
|
7
|
+
target: LinkTarget;
|
8
|
+
};
|
9
|
+
export type LinkOptions = {
|
10
|
+
defaultTarget?: LinkTarget;
|
11
|
+
supportedTargets?: LinkTarget[];
|
12
|
+
onShortcut?: Handler<() => void>;
|
13
|
+
};
|
14
|
+
export type UpdateLinkProps = {
|
15
|
+
text: string;
|
16
|
+
attrs: Partial<LinkAttributes>;
|
17
|
+
range: FromToProps;
|
10
18
|
};
|
11
|
-
export declare class LinkExtension extends
|
19
|
+
export declare class LinkExtension extends MarkExtension<LinkOptions> {
|
20
|
+
get name(): string;
|
12
21
|
createMarkSpec(extra: ApplySchemaAttributes, override: MarkSpecOverride): MarkExtensionSpec;
|
13
|
-
shortcut(
|
14
|
-
|
15
|
-
|
22
|
+
shortcut(_: KeyBindingProps): boolean;
|
23
|
+
updateLink({ text, attrs, range }: UpdateLinkProps): CommandFunction;
|
24
|
+
removeLink(): CommandFunction;
|
16
25
|
}
|
@@ -1,18 +1,31 @@
|
|
1
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
|
+
};
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
9
|
exports.LinkExtension = void 0;
|
4
10
|
const remirror_1 = require("remirror");
|
5
11
|
const core_1 = require("@remirror/core");
|
6
|
-
const
|
7
|
-
|
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
|
+
}
|
8
19
|
createMarkSpec(extra, override) {
|
9
|
-
const spec = super.createMarkSpec(extra, override);
|
10
20
|
return {
|
11
|
-
|
12
|
-
excludes:
|
21
|
+
inclusive: false,
|
22
|
+
excludes: 'assetLink',
|
23
|
+
...override,
|
13
24
|
attrs: {
|
14
|
-
...
|
25
|
+
...extra.defaults(),
|
26
|
+
href: {},
|
15
27
|
title: { default: undefined },
|
28
|
+
target: { default: this.options.defaultTarget },
|
16
29
|
},
|
17
30
|
parseDOM: [
|
18
31
|
{
|
@@ -23,75 +36,60 @@ class LinkExtension extends extensions_1.LinkExtension {
|
|
23
36
|
}
|
24
37
|
return {
|
25
38
|
...extra.parse(node),
|
26
|
-
auto: false,
|
27
39
|
href: node.getAttribute('href'),
|
28
|
-
target: node.getAttribute('target'),
|
29
40
|
title: node.getAttribute('title'),
|
41
|
+
target: (0, common_1.validateTarget)(node.getAttribute('target'), this.options.supportedTargets, this.options.defaultTarget),
|
30
42
|
};
|
31
43
|
},
|
32
44
|
},
|
33
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
|
+
},
|
34
57
|
};
|
35
58
|
}
|
36
|
-
shortcut(
|
37
|
-
|
38
|
-
const { from, to, $from } = tr.selection;
|
39
|
-
const mark = (0, core_1.getMarkRange)($from, this.type);
|
40
|
-
const selectedText = tr.doc.textBetween(from, to);
|
41
|
-
this.options.onShortcut({
|
42
|
-
activeLink: mark ? { attrs: mark.mark.attrs, from: mark.from, to: mark.to } : undefined,
|
43
|
-
selectedText,
|
44
|
-
from,
|
45
|
-
to,
|
46
|
-
});
|
59
|
+
shortcut(_) {
|
60
|
+
this.options.onShortcut();
|
47
61
|
return true;
|
48
62
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
58
|
-
// work out the start position of the first link and end position of the last link in the selection.
|
59
|
-
const from = Math.min(tr.selection.from, ...ranges.map((range) => range.from));
|
60
|
-
const to = Math.max(tr.selection.to, ...ranges.map((range) => range.to));
|
61
|
-
// don't need to widen the selection, return early.
|
62
|
-
if (tr.selection.from === from && tr.selection.to === to) {
|
63
|
-
return false;
|
64
|
-
}
|
65
|
-
// widen the selection to make sure the full link is included.
|
66
|
-
this.store.commands.selectText.original({ from, to })(props);
|
67
|
-
return true;
|
68
|
-
};
|
63
|
+
updateLink({ text, attrs, range }) {
|
64
|
+
return this.store.getExtension(CommandsExtension_1.CommandsExtension).updateMark({
|
65
|
+
attrs,
|
66
|
+
text,
|
67
|
+
range,
|
68
|
+
mark: this.type,
|
69
|
+
removeMark: !attrs.href,
|
70
|
+
});
|
69
71
|
}
|
70
|
-
|
71
|
-
|
72
|
-
return (props) => {
|
73
|
-
const { tr, dispatch, view } = props;
|
74
|
-
const range = { from: tr.selection.from, to: tr.selection.to };
|
75
|
-
const selectedText = tr.doc.textBetween(range.from, range.to);
|
76
|
-
if (text !== selectedText) {
|
77
|
-
// update the text in the editor if it was updated, update the range to cover the length of the new text.
|
78
|
-
tr.insertText(text);
|
79
|
-
range.to = range.from + text.length;
|
80
|
-
}
|
81
|
-
// apply the link, or remove it if no URL was provided.
|
82
|
-
if (attrs.href.length > 0) {
|
83
|
-
tr.addMark(range.from, range.to, this.type.create(attrs));
|
84
|
-
}
|
85
|
-
else {
|
86
|
-
tr.removeMark(range.from, range.to, this.type);
|
87
|
-
}
|
88
|
-
// move the cursor to the end of the link and re-focus the editor.
|
89
|
-
tr.setSelection((0, core_1.getTextSelection)({ from: range.to, to: range.to }, tr.doc));
|
90
|
-
// apply the transaction.
|
91
|
-
dispatch?.(tr);
|
92
|
-
view?.focus();
|
93
|
-
return true;
|
94
|
-
};
|
72
|
+
removeLink() {
|
73
|
+
return (0, core_1.removeMark)({ type: this.type });
|
95
74
|
}
|
96
|
-
}
|
75
|
+
};
|
76
|
+
__decorate([
|
77
|
+
(0, core_1.keyBinding)({ shortcut: core_1.NamedShortcut.InsertLink })
|
78
|
+
], LinkExtension.prototype, "shortcut", null);
|
79
|
+
__decorate([
|
80
|
+
(0, core_1.command)()
|
81
|
+
], LinkExtension.prototype, "updateLink", null);
|
82
|
+
__decorate([
|
83
|
+
(0, core_1.command)()
|
84
|
+
], LinkExtension.prototype, "removeLink", null);
|
85
|
+
LinkExtension = __decorate([
|
86
|
+
(0, core_1.extension)({
|
87
|
+
defaultOptions: {
|
88
|
+
defaultTarget: common_1.LinkTarget.Self,
|
89
|
+
supportedTargets: [common_1.LinkTarget.Self, common_1.LinkTarget.Blank],
|
90
|
+
},
|
91
|
+
handlerKeys: ['onShortcut'],
|
92
|
+
defaultPriority: remirror_1.ExtensionPriority.Medium,
|
93
|
+
})
|
94
|
+
], LinkExtension);
|
97
95
|
exports.LinkExtension = LinkExtension;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.validateTarget = exports.LinkTarget = void 0;
|
4
|
+
var LinkTarget;
|
5
|
+
(function (LinkTarget) {
|
6
|
+
LinkTarget["Self"] = "_self";
|
7
|
+
LinkTarget["Blank"] = "_blank";
|
8
|
+
LinkTarget["Parent"] = "_parent";
|
9
|
+
LinkTarget["Top"] = "_top";
|
10
|
+
})(LinkTarget = exports.LinkTarget || (exports.LinkTarget = {}));
|
11
|
+
const validateTarget = (target, supportedTargets, defaultTarget) => {
|
12
|
+
return supportedTargets.includes(target) ? target : defaultTarget;
|
13
|
+
};
|
14
|
+
exports.validateTarget = validateTarget;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ApplySchemaAttributes, CommandFunction, NodeExtension, NodeExtensionSpec, NodeSpecOverride } from '@remirror/core';
|
2
2
|
export declare class PreformattedExtension extends NodeExtension {
|
3
3
|
get name(): "preformatted";
|
4
|
-
createTags(): ("
|
4
|
+
createTags(): ("block" | "formattingNode" | "textBlock")[];
|
5
5
|
createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec;
|
6
6
|
/**
|
7
7
|
* Toggle the <pre> for the current block.
|
package/lib/hooks/index.d.ts
CHANGED
package/lib/hooks/index.js
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
import { Selection } from '@remirror/core';
|
2
|
+
import { Mark, MarkType } from 'remirror';
|
3
|
+
export type ExpandedSelection = {
|
4
|
+
selection: Selection;
|
5
|
+
marks: Mark[];
|
6
|
+
};
|
7
|
+
/**
|
8
|
+
* Returns a single range that is either:
|
9
|
+
* 1. The current selection if the current selection does not contain any of the indicated marks.
|
10
|
+
* 2. An expanded version of the current selection if the range contains any of the indicated marks.
|
11
|
+
*
|
12
|
+
* For example, given the content:
|
13
|
+
*
|
14
|
+
* <strong>Bold</strong> regular <u>underline</u> <u>more underline</u>
|
15
|
+
*
|
16
|
+
* If the marks passed in are 'bold' and 'underline' and the text "old regular under" is selected
|
17
|
+
* the returned range will be "Bold regular underline".
|
18
|
+
*
|
19
|
+
* @param {(MarkType|string)[]} markTypes
|
20
|
+
*
|
21
|
+
* @return {ExpandedSelection}
|
22
|
+
*/
|
23
|
+
export declare const useExpandedSelection: (markTypes: (MarkType | string)[]) => ExpandedSelection;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.useExpandedSelection = void 0;
|
4
|
+
const remirror_1 = require("remirror");
|
5
|
+
const react_1 = require("@remirror/react");
|
6
|
+
/**
|
7
|
+
* Returns a single range that is either:
|
8
|
+
* 1. The current selection if the current selection does not contain any of the indicated marks.
|
9
|
+
* 2. An expanded version of the current selection if the range contains any of the indicated marks.
|
10
|
+
*
|
11
|
+
* For example, given the content:
|
12
|
+
*
|
13
|
+
* <strong>Bold</strong> regular <u>underline</u> <u>more underline</u>
|
14
|
+
*
|
15
|
+
* If the marks passed in are 'bold' and 'underline' and the text "old regular under" is selected
|
16
|
+
* the returned range will be "Bold regular underline".
|
17
|
+
*
|
18
|
+
* @param {(MarkType|string)[]} markTypes
|
19
|
+
*
|
20
|
+
* @return {ExpandedSelection}
|
21
|
+
*/
|
22
|
+
const useExpandedSelection = (markTypes) => {
|
23
|
+
const { doc, selection } = (0, react_1.useEditorState)();
|
24
|
+
const ranges = [];
|
25
|
+
markTypes.forEach((markType) => {
|
26
|
+
ranges.push(...(0, remirror_1.getMarkRanges)(selection, markType));
|
27
|
+
});
|
28
|
+
if (ranges.length === 0) {
|
29
|
+
return { selection, marks: [] };
|
30
|
+
}
|
31
|
+
// work out the start position of the first link and end position of the last link in the selection.
|
32
|
+
const from = Math.min(selection.from, ...ranges.map((range) => range.from));
|
33
|
+
const to = Math.max(selection.to, ...ranges.map((range) => range.to));
|
34
|
+
const marks = ranges.map((range) => range.mark);
|
35
|
+
return { selection: (0, remirror_1.getTextSelection)({ from, to }, doc), marks };
|
36
|
+
};
|
37
|
+
exports.useExpandedSelection = useExpandedSelection;
|