@squiz/formatted-text-editor 2.3.0 → 2.4.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 +6 -0
- package/lib/Editor/Editor.d.ts +16 -0
- package/lib/Editor/Editor.js +85 -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 +7 -0
- package/lib/EditorToolbar/Toolbar.js +49 -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 +186 -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 +5 -0
- package/lib/Extensions/CodeBlockExtension/CodeBlockExtension.js +30 -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 +12 -0
- package/lib/Extensions/PreformattedExtension/PreformattedExtension.js +76 -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 +2 -0
- package/lib/hooks/index.js +18 -0
- package/lib/hooks/useExpandedSelection.d.ts +23 -0
- package/lib/hooks/useExpandedSelection.js +37 -0
- package/lib/hooks/useExtensionNames.d.ts +1 -0
- package/lib/hooks/useExtensionNames.js +16 -0
- package/lib/hooks/useFocus.d.ts +8 -0
- package/lib/hooks/useFocus.js +43 -0
- package/lib/index.css +5889 -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/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 +238 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.d.ts +9 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +214 -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
@@ -0,0 +1,96 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createToolbarPositioner = void 0;
|
4
|
+
const extensions_1 = require("remirror/extensions");
|
5
|
+
const remirror_1 = require("remirror");
|
6
|
+
const getCursorRect_1 = require("./getCursorRect");
|
7
|
+
/* istanbul ignore next */
|
8
|
+
const createToolbarPositioner = ({ types }) => {
|
9
|
+
// Inspired by "createMarkPositioner".
|
10
|
+
// See: https://github.com/remirror/remirror/blob/107cba/packages/remirror__extension-positioner/src/core-positioners.ts#L267
|
11
|
+
return extensions_1.Positioner.create({
|
12
|
+
hasChanged: extensions_1.hasStateChanged,
|
13
|
+
getActive: (props) => {
|
14
|
+
const { state, view } = props;
|
15
|
+
try {
|
16
|
+
const selection = (0, remirror_1.getTextSelection)(state.selection, state.doc);
|
17
|
+
const cursor = { from: view.coordsAtPos(selection.from), to: view.coordsAtPos(selection.to) };
|
18
|
+
const data = {
|
19
|
+
isSelectionInView: (0, extensions_1.isPositionVisible)((0, getCursorRect_1.getCursorRect)(cursor.from), view.dom) ||
|
20
|
+
(0, extensions_1.isPositionVisible)((0, getCursorRect_1.getCursorRect)(cursor.to), view.dom),
|
21
|
+
cursor: cursor,
|
22
|
+
visible: false,
|
23
|
+
marks: {},
|
24
|
+
};
|
25
|
+
data.visible = !selection.empty && data.isSelectionInView;
|
26
|
+
types.forEach((type) => {
|
27
|
+
const markRange = (0, remirror_1.getMarkRange)(selection.$from, type, selection.$to);
|
28
|
+
if (!markRange) {
|
29
|
+
data.marks[type] = { isActive: false, isExclusivelyActive: false };
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
// exclusively active =
|
33
|
+
// the entire selection has the mark applied.
|
34
|
+
// active =
|
35
|
+
// at least part of the selection has the mark applied. "getMarkRanges" will return an empty array
|
36
|
+
// if this isn't the case. if there is no selection the cursor must be within the bounds of the mark,
|
37
|
+
// not on the edges.
|
38
|
+
const isExclusivelyActive = selection.empty
|
39
|
+
? selection.from > markRange.from && selection.to < markRange.to
|
40
|
+
: selection.from >= markRange.from && selection.to <= markRange.to;
|
41
|
+
const isActive = selection.empty ? selection.from > markRange.from && selection.to < markRange.to : true;
|
42
|
+
// the toolbar will be visible if there is either a selection, or we are within the bounds of a mark
|
43
|
+
// we have formatting tools for.
|
44
|
+
data.visible = data.visible || isExclusivelyActive;
|
45
|
+
data.marks[type] = { isExclusivelyActive, isActive };
|
46
|
+
});
|
47
|
+
return data.visible ? [data] : extensions_1.Positioner.EMPTY;
|
48
|
+
}
|
49
|
+
catch {
|
50
|
+
return extensions_1.Positioner.EMPTY;
|
51
|
+
}
|
52
|
+
},
|
53
|
+
getPosition: (props) => {
|
54
|
+
const { element, data, view } = props;
|
55
|
+
const { cursor, visible } = data;
|
56
|
+
const { from, to } = cursor;
|
57
|
+
const parent = element.offsetParent ?? view.dom;
|
58
|
+
const parentRect = parent.getBoundingClientRect();
|
59
|
+
const height = Math.abs(to.bottom - from.top);
|
60
|
+
// Hack to get JSDOM to work, positioning doesn't work great here.
|
61
|
+
if (isNaN(parentRect.top)) {
|
62
|
+
return {
|
63
|
+
rect: new DOMRect(0, 0, 0, 0),
|
64
|
+
y: 0,
|
65
|
+
x: 0,
|
66
|
+
height: 0,
|
67
|
+
width: 0,
|
68
|
+
visible: false,
|
69
|
+
};
|
70
|
+
}
|
71
|
+
// True when the selection spans multiple lines.
|
72
|
+
const spansMultipleLines = height > from.bottom - from.top;
|
73
|
+
// The position furthest to the left.
|
74
|
+
const leftmost = Math.min(from.left, to.left);
|
75
|
+
// The position nearest the top.
|
76
|
+
const topmost = Math.min(from.top, to.top);
|
77
|
+
const bottommost = Math.max(from.bottom, to.bottom);
|
78
|
+
const left = parent.scrollLeft + (spansMultipleLines ? to.left - parentRect.left : leftmost - parentRect.left);
|
79
|
+
const top = parent.scrollTop + topmost - parentRect.top;
|
80
|
+
const width = spansMultipleLines ? 1 : Math.abs(from.left - to.right);
|
81
|
+
const rect = new DOMRect(spansMultipleLines ? to.left : leftmost, topmost, width, height);
|
82
|
+
// Get header toolbar by class inside the current element/editor
|
83
|
+
const headerToolbar = element.parentElement?.getElementsByClassName('header-toolbar')?.[0];
|
84
|
+
const headerBarRects = headerToolbar?.getBoundingClientRect();
|
85
|
+
const headerBarHeight = headerBarRects?.height ?? 0;
|
86
|
+
const headerBarBottom = (headerBarRects?.top ?? 0) + headerBarHeight;
|
87
|
+
// If floating toolbar will overlap fixed toolbar, set position to under selection
|
88
|
+
const isOverlapping = headerBarBottom + headerBarHeight > topmost;
|
89
|
+
// This is a good bottom position instead of it being on top of the toolbar when there is an overlap
|
90
|
+
const bottomPosition = parent.scrollTop + bottommost - parentRect.top + 62;
|
91
|
+
const y = isOverlapping ? bottomPosition : top;
|
92
|
+
return { rect, y, x: left, height, width, visible };
|
93
|
+
},
|
94
|
+
});
|
95
|
+
};
|
96
|
+
exports.createToolbarPositioner = createToolbarPositioner;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getCursorRect = void 0;
|
4
|
+
const getCursorRect = (coords) => {
|
5
|
+
return new DOMRect(coords.left, coords.top, 1, coords.top - coords.bottom);
|
6
|
+
};
|
7
|
+
exports.getCursorRect = getCursorRect;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getMarkNamesByGroup = void 0;
|
4
|
+
const getMarkNamesByGroup = (schema, group) => {
|
5
|
+
return Object.values(schema.marks)
|
6
|
+
.filter((mark) => mark.spec.group?.includes(group))
|
7
|
+
.map((mark) => mark.name);
|
8
|
+
};
|
9
|
+
exports.getMarkNamesByGroup = getMarkNamesByGroup;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getNodeNamesByGroup = void 0;
|
4
|
+
const getNodeNamesByGroup = (schema, group) => {
|
5
|
+
return Object.values(schema.nodes)
|
6
|
+
.filter((node) => node.spec.group?.includes(group))
|
7
|
+
.map((node) => node.name);
|
8
|
+
};
|
9
|
+
exports.getNodeNamesByGroup = getNodeNamesByGroup;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getShortcutSymbol: () => string;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getShortcutSymbol = void 0;
|
4
|
+
const getShortcutSymbol = () => {
|
5
|
+
// If we can detect Mac then we return "⌘" otherwise default to "Ctrl"
|
6
|
+
return window.navigator.userAgent.toLowerCase().indexOf('mac') > -1 ? '⌘' : 'Ctrl';
|
7
|
+
};
|
8
|
+
exports.getShortcutSymbol = getShortcutSymbol;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const undefinedIfEmpty: <T extends object>(object: T) => T | undefined;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.undefinedIfEmpty = void 0;
|
4
|
+
const undefinedIfEmpty = (object) => {
|
5
|
+
return Object.keys(object).length > 0 ? object : undefined;
|
6
|
+
};
|
7
|
+
exports.undefinedIfEmpty = undefinedIfEmpty;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
export declare const noEmptySpacesValidation: (value: string | undefined) => "Empty space is not allowed" | undefined;
|
2
|
+
export declare const hasProperties: <T>(message: string, properties: (keyof T)[]) => (value: T) => string | undefined;
|
3
|
+
export declare const regexDataURI: RegExp;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.regexDataURI = exports.hasProperties = exports.noEmptySpacesValidation = void 0;
|
4
|
+
const noEmptySpacesValidation = (value) => {
|
5
|
+
if (value && !(value.trim().length > 0)) {
|
6
|
+
return 'Empty space is not allowed';
|
7
|
+
}
|
8
|
+
};
|
9
|
+
exports.noEmptySpacesValidation = noEmptySpacesValidation;
|
10
|
+
const hasProperties = (message, properties) => (value) => {
|
11
|
+
if (!value || properties.filter((property) => value[property]).length !== properties.length) {
|
12
|
+
return message;
|
13
|
+
}
|
14
|
+
};
|
15
|
+
exports.hasProperties = hasProperties;
|
16
|
+
exports.regexDataURI = /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*)$/i;
|