@squiz/formatted-text-editor 0.0.0-rbv2-20240530041851
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/.eslintrc.json +41 -0
- package/CHANGELOG.md +155 -0
- package/README.md +74 -0
- package/build.js +21 -0
- package/coverage/clover.xml +1544 -0
- package/coverage/coverage-final.json +74 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +911 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/Editor/Editor.tsx.html +436 -0
- package/coverage/lcov-report/src/Editor/EditorContext.ts.html +145 -0
- package/coverage/lcov-report/src/Editor/index.html +131 -0
- package/coverage/lcov-report/src/EditorToolbar/FloatingToolbar.tsx.html +271 -0
- package/coverage/lcov-report/src/EditorToolbar/Toolbar.tsx.html +265 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Bold/BoldButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Bold/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.tsx.html +229 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/ClearFormatting/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.tsx.html +187 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/HorizontalLine/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx.html +688 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Image/Form/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Image/ImageButton.tsx.html +301 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Image/ImageModal.tsx.html +181 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Image/index.html +131 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Italic/ItalicButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Italic/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Link/Form/LinkForm.tsx.html +508 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Link/Form/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Link/LinkButton.tsx.html +286 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Link/LinkModal.tsx.html +196 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Link/RemoveLinkButton.tsx.html +211 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Link/index.html +146 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/ListButtons.tsx.html +127 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.tsx.html +175 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/OrderedList/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.tsx.html +175 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/UnorderedList/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Redo/RedoButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Redo/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Table/TableButton.tsx.html +181 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Table/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/CenterAlign/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/JustifyAlign/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/LeftAlign/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/RightAlign/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/TextAlignButtons.tsx.html +148 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.tsx.html +181 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/CodeBlock/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Heading/HeadingButton.tsx.html +241 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Heading/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.tsx.html +160 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Paragraph/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.tsx.html +181 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Preformatted/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/TextTypeDropdown.tsx.html +247 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Underline/UnderlineButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Underline/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Undo/UndoButton.tsx.html +178 -0
- package/coverage/lcov-report/src/EditorToolbar/Tools/Undo/index.html +116 -0
- package/coverage/lcov-report/src/EditorToolbar/index.html +146 -0
- package/coverage/lcov-report/src/EditorToolbar/index.ts.html +91 -0
- package/coverage/lcov-report/src/Extensions/ClearFormattingExtension/ClearFormattingExtension.ts.html +256 -0
- package/coverage/lcov-report/src/Extensions/ClearFormattingExtension/index.html +116 -0
- package/coverage/lcov-report/src/Extensions/CodeBlockExtension/CodeBlockExtension.ts.html +187 -0
- package/coverage/lcov-report/src/Extensions/CodeBlockExtension/index.html +116 -0
- package/coverage/lcov-report/src/Extensions/CommandsExtension/CommandsExtension.ts.html +247 -0
- package/coverage/lcov-report/src/Extensions/CommandsExtension/index.html +116 -0
- package/coverage/lcov-report/src/Extensions/Extensions.ts.html +349 -0
- package/coverage/lcov-report/src/Extensions/FetchUrlExtension/FetchUrlExtension.ts.html +289 -0
- package/coverage/lcov-report/src/Extensions/FetchUrlExtension/index.html +116 -0
- package/coverage/lcov-report/src/Extensions/ImageExtension/AssetImageExtension.ts.html +412 -0
- package/coverage/lcov-report/src/Extensions/ImageExtension/ImageExtension.ts.html +142 -0
- package/coverage/lcov-report/src/Extensions/ImageExtension/index.html +131 -0
- package/coverage/lcov-report/src/Extensions/LinkExtension/AssetLinkExtension.ts.html +466 -0
- package/coverage/lcov-report/src/Extensions/LinkExtension/LinkExtension.ts.html +400 -0
- package/coverage/lcov-report/src/Extensions/LinkExtension/common.ts.html +115 -0
- package/coverage/lcov-report/src/Extensions/LinkExtension/index.html +146 -0
- package/coverage/lcov-report/src/Extensions/PreformattedExtension/PreformattedExtension.ts.html +340 -0
- package/coverage/lcov-report/src/Extensions/PreformattedExtension/index.html +116 -0
- package/coverage/lcov-report/src/Extensions/UnsuportedExtension/UnsupportedNodeExtension.tsx.html +325 -0
- package/coverage/lcov-report/src/Extensions/UnsuportedExtension/index.html +116 -0
- package/coverage/lcov-report/src/Extensions/index.html +116 -0
- package/coverage/lcov-report/src/hooks/index.html +161 -0
- package/coverage/lcov-report/src/hooks/index.ts.html +91 -0
- package/coverage/lcov-report/src/hooks/useExpandedSelection.ts.html +217 -0
- package/coverage/lcov-report/src/hooks/useExtensionNames.ts.html +130 -0
- package/coverage/lcov-report/src/hooks/useFocus.ts.html +268 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +112 -0
- package/coverage/lcov-report/src/ui/Button/Button.tsx.html +190 -0
- package/coverage/lcov-report/src/ui/Button/index.html +116 -0
- package/coverage/lcov-report/src/ui/CollapseBox/CollapseBox.tsx.html +193 -0
- package/coverage/lcov-report/src/ui/CollapseBox/index.html +116 -0
- package/coverage/lcov-report/src/ui/Fields/Checkbox/Checkbox.tsx.html +232 -0
- package/coverage/lcov-report/src/ui/Fields/Checkbox/index.html +116 -0
- package/coverage/lcov-report/src/ui/Fields/Input/Input.tsx.html +160 -0
- package/coverage/lcov-report/src/ui/Fields/Input/index.html +116 -0
- package/coverage/lcov-report/src/ui/Fields/InputContainer/InputContainer.tsx.html +172 -0
- package/coverage/lcov-report/src/ui/Fields/InputContainer/index.html +116 -0
- package/coverage/lcov-report/src/ui/Fields/MatrixAsset/MatrixAsset.tsx.html +256 -0
- package/coverage/lcov-report/src/ui/Fields/MatrixAsset/index.html +116 -0
- package/coverage/lcov-report/src/ui/Fields/Select/Select.tsx.html +283 -0
- package/coverage/lcov-report/src/ui/Fields/Select/index.html +116 -0
- package/coverage/lcov-report/src/ui/Modal/FormModal.tsx.html +136 -0
- package/coverage/lcov-report/src/ui/Modal/Modal.tsx.html +397 -0
- package/coverage/lcov-report/src/ui/Modal/index.html +131 -0
- package/coverage/lcov-report/src/ui/Tabs/Tabs.tsx.html +208 -0
- package/coverage/lcov-report/src/ui/Tabs/index.html +116 -0
- package/coverage/lcov-report/src/ui/ToolbarDropdown/ToolbarDropdown.tsx.html +211 -0
- package/coverage/lcov-report/src/ui/ToolbarDropdown/index.html +116 -0
- package/coverage/lcov-report/src/ui/ToolbarDropdownButton/ToolbarDropdownButton.tsx.html +184 -0
- package/coverage/lcov-report/src/ui/ToolbarDropdownButton/index.html +116 -0
- package/coverage/lcov-report/src/utils/converters/htmlToSquizNode/htmlToSquizNode.ts.html +166 -0
- package/coverage/lcov-report/src/utils/converters/htmlToSquizNode/index.html +116 -0
- package/coverage/lcov-report/src/utils/converters/mocks/index.html +116 -0
- package/coverage/lcov-report/src/utils/converters/mocks/squizNodeJson.mock.ts.html +895 -0
- package/coverage/lcov-report/src/utils/converters/remirrorNodeToSquizNode/index.html +116 -0
- package/coverage/lcov-report/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts.html +976 -0
- package/coverage/lcov-report/src/utils/converters/squizNodeToRemirrorNode/index.html +116 -0
- package/coverage/lcov-report/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts.html +748 -0
- package/coverage/lcov-report/src/utils/createToolbarPositioner.ts.html +469 -0
- package/coverage/lcov-report/src/utils/getCursorRect.ts.html +100 -0
- package/coverage/lcov-report/src/utils/getMarkNamesByGroup.ts.html +106 -0
- package/coverage/lcov-report/src/utils/getNodeNamesByGroup.ts.html +106 -0
- package/coverage/lcov-report/src/utils/getShortcutSymbol.ts.html +97 -0
- package/coverage/lcov-report/src/utils/index.html +206 -0
- package/coverage/lcov-report/src/utils/undefinedIfEmpty.ts.html +94 -0
- package/coverage/lcov-report/src/utils/validation.ts.html +133 -0
- package/coverage/lcov.info +2737 -0
- package/cypress/e2e/bold.spec.cy.ts +18 -0
- package/cypress/global.d.ts +9 -0
- package/cypress/support/commands.ts +130 -0
- package/cypress/support/e2e.ts +20 -0
- package/cypress/tsconfig.json +8 -0
- package/cypress.config.ts +7 -0
- package/demo/App.tsx +107 -0
- package/demo/AppContext.tsx +70 -0
- package/demo/index.html +13 -0
- package/demo/index.scss +33 -0
- package/demo/main.tsx +12 -0
- package/demo/public/favicon-dxp.svg +3 -0
- package/demo/resources.json +204 -0
- package/demo/sources.json +27 -0
- package/demo/vite-env.d.ts +1 -0
- package/file-transformer.js +1 -0
- package/jest.bootstrap.ts +3 -0
- package/jest.config.ts +27 -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 +47 -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/HorizontalLine/HorizontalLineButton.d.ts +3 -0
- package/lib/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.js +25 -0
- package/lib/EditorToolbar/Tools/Image/Form/ImageForm.d.ts +18 -0
- package/lib/EditorToolbar/Tools/Image/Form/ImageForm.js +143 -0
- package/lib/EditorToolbar/Tools/Image/ImageButton.d.ts +6 -0
- package/lib/EditorToolbar/Tools/Image/ImageButton.js +76 -0
- package/lib/EditorToolbar/Tools/Image/ImageModal.d.ts +9 -0
- package/lib/EditorToolbar/Tools/Image/ImageModal.js +24 -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 +22 -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 +17 -0
- package/lib/Extensions/Extensions.js +73 -0
- package/lib/Extensions/FetchUrlExtension/FetchUrlExtension.d.ts +12 -0
- package/lib/Extensions/FetchUrlExtension/FetchUrlExtension.js +63 -0
- package/lib/Extensions/ImageExtension/AssetImageExtension.d.ts +17 -0
- package/lib/Extensions/ImageExtension/AssetImageExtension.js +91 -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/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 +1525 -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/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 +229 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.d.ts +9 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +205 -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 +83 -0
- package/postcss.config.js +12 -0
- package/src/Editor/Editor.spec.tsx +465 -0
- package/src/Editor/Editor.tsx +117 -0
- package/src/Editor/EditorContext.spec.tsx +25 -0
- package/src/Editor/EditorContext.ts +20 -0
- package/src/Editor/_editor.scss +430 -0
- package/src/EditorToolbar/FloatingToolbar.spec.tsx +49 -0
- package/src/EditorToolbar/FloatingToolbar.tsx +62 -0
- package/src/EditorToolbar/Toolbar.tsx +60 -0
- package/src/EditorToolbar/Tools/Bold/BoldButton.spec.tsx +19 -0
- package/src/EditorToolbar/Tools/Bold/BoldButton.tsx +31 -0
- package/src/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.spec.tsx +34 -0
- package/src/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.tsx +48 -0
- package/src/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.spec.tsx +23 -0
- package/src/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.tsx +34 -0
- package/src/EditorToolbar/Tools/Image/Form/ImageForm.spec.tsx +117 -0
- package/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx +201 -0
- package/src/EditorToolbar/Tools/Image/ImageButton.spec.tsx +385 -0
- package/src/EditorToolbar/Tools/Image/ImageButton.tsx +72 -0
- package/src/EditorToolbar/Tools/Image/ImageModal.spec.tsx +123 -0
- package/src/EditorToolbar/Tools/Image/ImageModal.tsx +32 -0
- package/src/EditorToolbar/Tools/Italic/ItalicButton.spec.tsx +19 -0
- package/src/EditorToolbar/Tools/Italic/ItalicButton.tsx +31 -0
- package/src/EditorToolbar/Tools/Link/Form/LinkForm.spec.tsx +79 -0
- package/src/EditorToolbar/Tools/Link/Form/LinkForm.tsx +141 -0
- package/src/EditorToolbar/Tools/Link/LinkButton.spec.tsx +402 -0
- package/src/EditorToolbar/Tools/Link/LinkButton.tsx +67 -0
- package/src/EditorToolbar/Tools/Link/LinkModal.tsx +37 -0
- package/src/EditorToolbar/Tools/Link/RemoveLinkButton.spec.tsx +143 -0
- package/src/EditorToolbar/Tools/Link/RemoveLinkButton.tsx +42 -0
- package/src/EditorToolbar/Tools/Lists/ListButtons.tsx +14 -0
- package/src/EditorToolbar/Tools/Lists/OrderedList/OrderListButton.spec.tsx +39 -0
- package/src/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.tsx +30 -0
- package/src/EditorToolbar/Tools/Lists/UnorderedList/UnorderedList.spec.tsx +19 -0
- package/src/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.tsx +30 -0
- package/src/EditorToolbar/Tools/Redo/RedoButton.spec.tsx +59 -0
- package/src/EditorToolbar/Tools/Redo/RedoButton.tsx +31 -0
- package/src/EditorToolbar/Tools/Table/TableButton.spec.tsx +25 -0
- package/src/EditorToolbar/Tools/Table/TableButton.tsx +32 -0
- package/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.spec.tsx +39 -0
- package/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.tsx +31 -0
- package/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.spec.tsx +39 -0
- package/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.tsx +31 -0
- package/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.spec.tsx +39 -0
- package/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.tsx +31 -0
- package/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.spec.tsx +39 -0
- package/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.tsx +31 -0
- package/src/EditorToolbar/Tools/TextAlign/TextAlignButtons.tsx +21 -0
- package/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.spec.tsx +47 -0
- package/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.tsx +32 -0
- package/src/EditorToolbar/Tools/TextType/Heading/HeadingButton.spec.tsx +56 -0
- package/src/EditorToolbar/Tools/TextType/Heading/HeadingButton.tsx +52 -0
- package/src/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.spec.tsx +30 -0
- package/src/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.tsx +25 -0
- package/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.spec.tsx +47 -0
- package/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.tsx +32 -0
- package/src/EditorToolbar/Tools/TextType/TextTypeDropdown.spec.tsx +51 -0
- package/src/EditorToolbar/Tools/TextType/TextTypeDropdown.tsx +54 -0
- package/src/EditorToolbar/Tools/Underline/Underline.spec.tsx +19 -0
- package/src/EditorToolbar/Tools/Underline/UnderlineButton.tsx +31 -0
- package/src/EditorToolbar/Tools/Undo/UndoButton.spec.tsx +70 -0
- package/src/EditorToolbar/Tools/Undo/UndoButton.tsx +31 -0
- package/src/EditorToolbar/_floating-toolbar.scss +9 -0
- package/src/EditorToolbar/_toolbar.scss +37 -0
- package/src/EditorToolbar/index.ts +2 -0
- package/src/Extensions/ClearFormattingExtension/ClearFormattingExtension.ts +57 -0
- package/src/Extensions/CodeBlockExtension/CodeBlockExtension.ts +34 -0
- package/src/Extensions/CommandsExtension/CommandsExtension.ts +54 -0
- package/src/Extensions/Extensions.ts +88 -0
- package/src/Extensions/FetchUrlExtension/FetchUrlExtension.ts +68 -0
- package/src/Extensions/ImageExtension/AssetImageExtension.spec.ts +77 -0
- package/src/Extensions/ImageExtension/AssetImageExtension.ts +109 -0
- package/src/Extensions/ImageExtension/ImageExtension.ts +19 -0
- package/src/Extensions/LinkExtension/AssetLinkExtension.spec.ts +106 -0
- package/src/Extensions/LinkExtension/AssetLinkExtension.ts +127 -0
- package/src/Extensions/LinkExtension/LinkExtension.spec.ts +68 -0
- package/src/Extensions/LinkExtension/LinkExtension.ts +105 -0
- package/src/Extensions/LinkExtension/common.ts +10 -0
- package/src/Extensions/PreformattedExtension/PreformattedExtension.spec.ts +43 -0
- package/src/Extensions/PreformattedExtension/PreformattedExtension.ts +85 -0
- package/src/Extensions/UnsuportedExtension/UnsupportedNodeExtension.spec.ts +137 -0
- package/src/Extensions/UnsuportedExtension/UnsupportedNodeExtension.tsx +80 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useExpandedSelection.ts +44 -0
- package/src/hooks/useExtensionNames.ts +15 -0
- package/src/hooks/useFocus.ts +61 -0
- package/src/index.scss +24 -0
- package/src/index.ts +9 -0
- package/src/types.ts +10 -0
- package/src/ui/Button/Button.spec.tsx +44 -0
- package/src/ui/Button/Button.tsx +35 -0
- package/src/ui/Button/_button.scss +37 -0
- package/src/ui/CollapseBox/CollapseBox.spec.tsx +49 -0
- package/src/ui/CollapseBox/CollapseBox.tsx +36 -0
- package/src/ui/CollapseBox/_collapseBox.scss +23 -0
- package/src/ui/Fields/Checkbox/Checkbox.spec.tsx +50 -0
- package/src/ui/Fields/Checkbox/Checkbox.tsx +49 -0
- package/src/ui/Fields/Checkbox/_checkbox.scss +26 -0
- package/src/ui/Fields/Input/Input.spec.tsx +49 -0
- package/src/ui/Fields/Input/Input.tsx +25 -0
- package/src/ui/Fields/InputContainer/InputContainer.spec.tsx +18 -0
- package/src/ui/Fields/InputContainer/InputContainer.tsx +29 -0
- package/src/ui/Fields/MatrixAsset/MatrixAsset.spec.tsx +121 -0
- package/src/ui/Fields/MatrixAsset/MatrixAsset.tsx +57 -0
- package/src/ui/Fields/Select/Select.spec.tsx +30 -0
- package/src/ui/Fields/Select/Select.tsx +66 -0
- package/src/ui/Modal/FormModal.spec.tsx +21 -0
- package/src/ui/Modal/FormModal.tsx +17 -0
- package/src/ui/Modal/Modal.spec.tsx +136 -0
- package/src/ui/Modal/Modal.tsx +104 -0
- package/src/ui/Modal/_modal.scss +24 -0
- package/src/ui/Tabs/Tabs.spec.tsx +44 -0
- package/src/ui/Tabs/Tabs.tsx +41 -0
- package/src/ui/ToolbarDropdown/ToolbarDropdown.spec.tsx +80 -0
- package/src/ui/ToolbarDropdown/ToolbarDropdown.tsx +42 -0
- package/src/ui/ToolbarDropdown/_toolbar-dropdown.scss +32 -0
- package/src/ui/ToolbarDropdownButton/ToolbarDropdownButton.spec.tsx +48 -0
- package/src/ui/ToolbarDropdownButton/ToolbarDropdownButton.tsx +33 -0
- package/src/ui/ToolbarDropdownButton/_toolbar-dropdown-button.scss +25 -0
- package/src/ui/_forms.scss +32 -0
- package/src/ui/_typography.scss +95 -0
- package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.props.ts +3 -0
- package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.spec.ts +179 -0
- package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.ts +27 -0
- package/src/utils/converters/mocks/squizNodeJson.mock.ts +270 -0
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.spec.ts +1058 -0
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts +297 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +878 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +221 -0
- package/src/utils/createToolbarPositioner.ts +128 -0
- package/src/utils/getCursorRect.ts +5 -0
- package/src/utils/getMarkNamesByGroup.spec.ts +20 -0
- package/src/utils/getMarkNamesByGroup.ts +7 -0
- package/src/utils/getNodeNamesByGroup.spec.ts +37 -0
- package/src/utils/getNodeNamesByGroup.ts +7 -0
- package/src/utils/getShortcutSymbol.spec.ts +27 -0
- package/src/utils/getShortcutSymbol.ts +4 -0
- package/src/utils/undefinedIfEmpty.spec.ts +12 -0
- package/src/utils/undefinedIfEmpty.ts +3 -0
- package/src/utils/validation.spec.ts +22 -0
- package/src/utils/validation.ts +16 -0
- package/tailwind.config.cjs +87 -0
- package/tests/index.ts +4 -0
- package/tests/mockResourceBrowserContext.tsx +99 -0
- package/tests/renderWithContext.tsx +75 -0
- package/tests/renderWithEditor.tsx +123 -0
- package/tests/select.ts +16 -0
- package/tsconfig.json +22 -0
- package/vite.config.ts +27 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
import '@testing-library/jest-dom';
|
2
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
3
|
+
import React from 'react';
|
4
|
+
import { LinkForm } from './LinkForm';
|
5
|
+
import { LinkTarget } from '../../../../Extensions/LinkExtension/common';
|
6
|
+
import { MarkName } from '../../../../Extensions/Extensions';
|
7
|
+
import { mockResourceBrowserContext } from '../../../../../tests';
|
8
|
+
|
9
|
+
describe('Link Form', () => {
|
10
|
+
const handleSubmit = jest.fn();
|
11
|
+
const data = {
|
12
|
+
linkType: MarkName.Link,
|
13
|
+
text: 'Link text',
|
14
|
+
range: { from: 10, to: 15 },
|
15
|
+
link: {
|
16
|
+
href: 'https://www.squiz.net/link-form',
|
17
|
+
target: LinkTarget.Blank,
|
18
|
+
title: 'Link title',
|
19
|
+
},
|
20
|
+
assetLink: {
|
21
|
+
matrixAssetId: '100',
|
22
|
+
matrixIdentifier: 'matrix-api-identifier',
|
23
|
+
matrixDomain: 'my-matrix.squiz.net',
|
24
|
+
target: LinkTarget.Blank,
|
25
|
+
},
|
26
|
+
};
|
27
|
+
|
28
|
+
it('Renders the form with expected default values when no data is provided', async () => {
|
29
|
+
const { MockResourceBrowserContext } = mockResourceBrowserContext({ sources: [], resources: [] });
|
30
|
+
render(
|
31
|
+
<MockResourceBrowserContext>
|
32
|
+
<LinkForm onSubmit={handleSubmit} />
|
33
|
+
</MockResourceBrowserContext>,
|
34
|
+
);
|
35
|
+
|
36
|
+
expect(document.querySelector('div[data-headlessui-state="selected"]')).toHaveTextContent('From source');
|
37
|
+
expect(screen.getByLabelText('Text')).toHaveValue('');
|
38
|
+
expect(document.querySelector('div.squiz-fte-checkbox')).toHaveTextContent('Open link in new window');
|
39
|
+
expect(document.querySelectorAll('label')).toHaveLength(1);
|
40
|
+
|
41
|
+
await waitFor(() => {
|
42
|
+
expect(screen.queryByRole('button', { name: 'Choose asset' })).toBeInTheDocument();
|
43
|
+
});
|
44
|
+
});
|
45
|
+
|
46
|
+
it('Renders the form with the expected fields for arbitrary links', () => {
|
47
|
+
render(<LinkForm data={data} onSubmit={handleSubmit} />);
|
48
|
+
|
49
|
+
expect(document.querySelector('div[data-headlessui-state="selected"]')).toHaveTextContent('From URL');
|
50
|
+
expect(screen.getByLabelText('URL')).toHaveValue('https://www.squiz.net/link-form');
|
51
|
+
expect(screen.getByLabelText('Text')).toHaveValue('Link text');
|
52
|
+
expect(screen.getByLabelText('Title')).toHaveValue('Link title');
|
53
|
+
expect(document.querySelector('div.squiz-fte-checkbox')).toHaveTextContent('Open link in new window');
|
54
|
+
expect(document.querySelectorAll('label')).toHaveLength(3);
|
55
|
+
});
|
56
|
+
|
57
|
+
it('Renders the form with the expected fields for asset links', async () => {
|
58
|
+
const { MockResourceBrowserContext } = mockResourceBrowserContext({
|
59
|
+
sources: [{ id: 'my-source-id' }],
|
60
|
+
resources: [{ id: '100', name: 'My selected resource' }],
|
61
|
+
});
|
62
|
+
|
63
|
+
render(
|
64
|
+
<MockResourceBrowserContext>
|
65
|
+
<LinkForm data={{ ...data, linkType: MarkName.AssetLink }} onSubmit={handleSubmit} />
|
66
|
+
</MockResourceBrowserContext>,
|
67
|
+
);
|
68
|
+
|
69
|
+
expect(document.querySelector('div[data-headlessui-state="selected"]')).toHaveTextContent('From source');
|
70
|
+
|
71
|
+
expect(screen.getByLabelText('Text')).toHaveValue('Link text');
|
72
|
+
expect(document.querySelector('div.squiz-fte-checkbox')).toHaveTextContent('Open link in new window');
|
73
|
+
expect(document.querySelectorAll('label')).toHaveLength(1);
|
74
|
+
|
75
|
+
await waitFor(() => {
|
76
|
+
expect(screen.getByText('My selected resource')).toBeInTheDocument();
|
77
|
+
});
|
78
|
+
});
|
79
|
+
});
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import React, { ReactElement } from 'react';
|
2
|
+
import clsx from 'clsx';
|
3
|
+
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
|
4
|
+
import { FromToProps } from 'remirror';
|
5
|
+
import { Input } from '../../../../ui/Fields/Input/Input';
|
6
|
+
import { Checkbox } from '../../../../ui/Fields/Checkbox/Checkbox';
|
7
|
+
import { UpdateLinkProps } from '../../../../Extensions/LinkExtension/LinkExtension';
|
8
|
+
import { UpdateAssetLinkProps } from '../../../../Extensions/LinkExtension/AssetLinkExtension';
|
9
|
+
import { LinkTarget } from '../../../../Extensions/LinkExtension/common';
|
10
|
+
import { MarkName } from '../../../../Extensions/Extensions';
|
11
|
+
import { DeepPartial } from '../../../../types';
|
12
|
+
import { hasProperties, noEmptySpacesValidation } from '../../../../utils/validation';
|
13
|
+
import { TabOptions, Tabs } from '../../../../ui/Tabs/Tabs';
|
14
|
+
import { MatrixAsset } from '../../../../ui/Fields/MatrixAsset/MatrixAsset';
|
15
|
+
|
16
|
+
export type LinkFormData = {
|
17
|
+
linkType: MarkName;
|
18
|
+
text: string;
|
19
|
+
link: UpdateLinkProps['attrs'];
|
20
|
+
assetLink: UpdateAssetLinkProps['attrs'];
|
21
|
+
range: FromToProps;
|
22
|
+
};
|
23
|
+
|
24
|
+
export type FormProps = {
|
25
|
+
data?: DeepPartial<LinkFormData>;
|
26
|
+
onSubmit: SubmitHandler<LinkFormData>;
|
27
|
+
};
|
28
|
+
|
29
|
+
const linkTypeOptions: TabOptions = {
|
30
|
+
[MarkName.AssetLink]: { label: 'From source' },
|
31
|
+
[MarkName.Link]: { label: 'From URL' },
|
32
|
+
};
|
33
|
+
|
34
|
+
export const LinkForm = ({ data, onSubmit }: FormProps): ReactElement => {
|
35
|
+
const {
|
36
|
+
control,
|
37
|
+
register,
|
38
|
+
handleSubmit,
|
39
|
+
setValue,
|
40
|
+
watch,
|
41
|
+
formState: { errors },
|
42
|
+
} = useForm<LinkFormData>({
|
43
|
+
defaultValues: data,
|
44
|
+
});
|
45
|
+
const linkType = watch('linkType') || MarkName.AssetLink;
|
46
|
+
|
47
|
+
return (
|
48
|
+
<form className="squiz-fte-form" onSubmit={handleSubmit(onSubmit)}>
|
49
|
+
<div className="squiz-fte-form-group mb-4">
|
50
|
+
<Tabs
|
51
|
+
value={linkType}
|
52
|
+
options={linkTypeOptions}
|
53
|
+
onChange={(value) => setValue('linkType', value as MarkName)}
|
54
|
+
/>
|
55
|
+
</div>
|
56
|
+
{/* Arbitrary link form fields */}
|
57
|
+
{linkType === MarkName.Link && (
|
58
|
+
<>
|
59
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
60
|
+
<Input
|
61
|
+
label="URL"
|
62
|
+
required
|
63
|
+
error={errors?.link?.href?.message}
|
64
|
+
{...register('link.href', {
|
65
|
+
required: 'URL is required',
|
66
|
+
validate: {
|
67
|
+
noEmptySpaces: noEmptySpacesValidation,
|
68
|
+
},
|
69
|
+
})}
|
70
|
+
/>
|
71
|
+
</div>
|
72
|
+
|
73
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
74
|
+
<Input
|
75
|
+
label="Text"
|
76
|
+
required
|
77
|
+
error={errors?.text?.message}
|
78
|
+
{...register('text', {
|
79
|
+
required: 'Text is required',
|
80
|
+
validate: {
|
81
|
+
noEmptySpaces: noEmptySpacesValidation,
|
82
|
+
},
|
83
|
+
})}
|
84
|
+
/>
|
85
|
+
</div>
|
86
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
87
|
+
<Input label="Title" error={errors?.link?.title?.message} {...register('link.title')} />
|
88
|
+
</div>
|
89
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
90
|
+
<Checkbox
|
91
|
+
label="Open link in new window"
|
92
|
+
onChange={(value) => setValue('link.target', value as LinkTarget)}
|
93
|
+
defaultChecked={data?.link?.target === LinkTarget.Blank}
|
94
|
+
unchecked={LinkTarget.Self}
|
95
|
+
checked={LinkTarget.Blank}
|
96
|
+
/>
|
97
|
+
</div>
|
98
|
+
</>
|
99
|
+
)}
|
100
|
+
{/* Asset link form fields */}
|
101
|
+
{linkType === MarkName.AssetLink && (
|
102
|
+
<>
|
103
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
104
|
+
<Controller
|
105
|
+
control={control}
|
106
|
+
name="assetLink"
|
107
|
+
rules={{
|
108
|
+
validate: hasProperties('An asset must be selected', ['matrixIdentifier', 'matrixAssetId']),
|
109
|
+
}}
|
110
|
+
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
111
|
+
<MatrixAsset modalTitle="Insert link" value={value} onChange={onChange} error={error?.message} />
|
112
|
+
)}
|
113
|
+
/>
|
114
|
+
</div>
|
115
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
116
|
+
<Input
|
117
|
+
label="Text"
|
118
|
+
required
|
119
|
+
error={errors?.text?.message}
|
120
|
+
{...register('text', {
|
121
|
+
required: 'Text is required',
|
122
|
+
validate: {
|
123
|
+
noEmptySpaces: noEmptySpacesValidation,
|
124
|
+
},
|
125
|
+
})}
|
126
|
+
/>
|
127
|
+
</div>
|
128
|
+
<div className={clsx('squiz-fte-form-group mb-2')}>
|
129
|
+
<Checkbox
|
130
|
+
label="Open link in new window"
|
131
|
+
onChange={(value) => setValue('assetLink.target', value as LinkTarget)}
|
132
|
+
defaultChecked={data?.assetLink?.target === '_blank'}
|
133
|
+
unchecked={'_self' as LinkTarget}
|
134
|
+
checked={'_blank' as LinkTarget}
|
135
|
+
/>
|
136
|
+
</div>
|
137
|
+
</>
|
138
|
+
)}
|
139
|
+
</form>
|
140
|
+
);
|
141
|
+
};
|
@@ -0,0 +1,402 @@
|
|
1
|
+
import '@testing-library/jest-dom';
|
2
|
+
import { act, screen, fireEvent, waitForElementToBeRemoved, waitFor } from '@testing-library/react';
|
3
|
+
import React from 'react';
|
4
|
+
import { renderWithEditor, mockResourceBrowserContext } from '../../../../tests';
|
5
|
+
import LinkButton from './LinkButton';
|
6
|
+
|
7
|
+
describe('LinkButton', () => {
|
8
|
+
const openModal = async () => {
|
9
|
+
fireEvent.click(screen.getByRole('button', { name: 'Link (Ctrl+K)' }));
|
10
|
+
await screen.findByRole('button', { name: 'Apply' });
|
11
|
+
fireEvent.click(screen.getByRole('button', { name: 'From URL' }));
|
12
|
+
};
|
13
|
+
|
14
|
+
it('Adds a new link', async () => {
|
15
|
+
const { editor, getJsonContent } = await renderWithEditor(<LinkButton />, { content: '[start][end]' });
|
16
|
+
|
17
|
+
// move the cursor to between the start and end tags.
|
18
|
+
await act(() => editor.selectText(8));
|
19
|
+
|
20
|
+
// open the modal and add a link.
|
21
|
+
await openModal();
|
22
|
+
fireEvent.change(screen.getByLabelText('URL'), { target: { value: 'https://www.squiz.net/link-button' } });
|
23
|
+
fireEvent.change(screen.getByLabelText('Text'), { target: { value: 'Link text' } });
|
24
|
+
fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'Link title' } });
|
25
|
+
fireEvent.click(document.querySelector('div.squiz-fte-checkbox button') as HTMLButtonElement);
|
26
|
+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
|
27
|
+
|
28
|
+
await waitForElementToBeRemoved(() => screen.getByRole('button', { name: 'Apply' }));
|
29
|
+
|
30
|
+
expect(getJsonContent()).toEqual({
|
31
|
+
type: 'paragraph',
|
32
|
+
attrs: expect.any(Object),
|
33
|
+
content: [
|
34
|
+
{ type: 'text', text: '[start]' },
|
35
|
+
{
|
36
|
+
type: 'text',
|
37
|
+
text: 'Link text',
|
38
|
+
marks: [
|
39
|
+
{
|
40
|
+
type: 'link',
|
41
|
+
attrs: { href: 'https://www.squiz.net/link-button', target: '_blank', title: 'Link title' },
|
42
|
+
},
|
43
|
+
],
|
44
|
+
},
|
45
|
+
{ type: 'text', text: '[end]' },
|
46
|
+
],
|
47
|
+
});
|
48
|
+
});
|
49
|
+
|
50
|
+
it('Updates the attributes of an existing link', async () => {
|
51
|
+
const { editor, getJsonContent } = await renderWithEditor(<LinkButton />, {
|
52
|
+
content:
|
53
|
+
'<a href="https://www.example.org/my-link" title="Sample title">Sample link</a> with some other content.',
|
54
|
+
});
|
55
|
+
|
56
|
+
// jump to the middle of the link.
|
57
|
+
await act(() => editor.selectText(3));
|
58
|
+
|
59
|
+
// open the modal and update the link.
|
60
|
+
await openModal();
|
61
|
+
fireEvent.change(screen.getByLabelText('URL'), { target: { value: 'https://www.example.org/updated-link' } });
|
62
|
+
fireEvent.change(screen.getByLabelText('Text'), { target: { value: 'Updated sample link' } });
|
63
|
+
fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'Updated sample title' } });
|
64
|
+
|
65
|
+
// verify the content matches what was initially set prior to applying.
|
66
|
+
expect(getJsonContent()).toEqual({
|
67
|
+
type: 'paragraph',
|
68
|
+
attrs: expect.any(Object),
|
69
|
+
content: [
|
70
|
+
{
|
71
|
+
type: 'text',
|
72
|
+
text: 'Sample link',
|
73
|
+
marks: [
|
74
|
+
{
|
75
|
+
type: 'link',
|
76
|
+
attrs: { href: 'https://www.example.org/my-link', target: '_self', title: 'Sample title' },
|
77
|
+
},
|
78
|
+
],
|
79
|
+
},
|
80
|
+
{ type: 'text', text: ' with some other content.' },
|
81
|
+
],
|
82
|
+
});
|
83
|
+
|
84
|
+
// apply the changes.
|
85
|
+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
|
86
|
+
|
87
|
+
await waitForElementToBeRemoved(() => screen.getByRole('button', { name: 'Apply' }));
|
88
|
+
|
89
|
+
// cursor should be positioned after the link and the text should be updated.
|
90
|
+
expect(editor.from).toBe(20);
|
91
|
+
expect(editor.to).toBe(20);
|
92
|
+
expect(getJsonContent()).toEqual({
|
93
|
+
type: 'paragraph',
|
94
|
+
attrs: expect.any(Object),
|
95
|
+
content: [
|
96
|
+
{
|
97
|
+
type: 'text',
|
98
|
+
text: 'Updated sample link',
|
99
|
+
marks: [
|
100
|
+
{
|
101
|
+
type: 'link',
|
102
|
+
attrs: { href: 'https://www.example.org/updated-link', target: '_self', title: 'Updated sample title' },
|
103
|
+
},
|
104
|
+
],
|
105
|
+
},
|
106
|
+
{ type: 'text', text: ' with some other content.' },
|
107
|
+
],
|
108
|
+
});
|
109
|
+
});
|
110
|
+
|
111
|
+
it('Updates unselected part of link when link is partially selected', async () => {
|
112
|
+
const { editor, getJsonContent } = await renderWithEditor(<LinkButton />, {
|
113
|
+
content:
|
114
|
+
'<a href="https://www.example.org/my-link" title="Sample title">Sample link</a> <strong>with</strong> some other content.',
|
115
|
+
});
|
116
|
+
|
117
|
+
// jump to the middle of the link and select some of the text after it.
|
118
|
+
await act(() => editor.selectText({ from: 3, to: 22 }));
|
119
|
+
|
120
|
+
// open the modal and apply the link to the selection.
|
121
|
+
await openModal();
|
122
|
+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
|
123
|
+
|
124
|
+
await waitForElementToBeRemoved(() => screen.getByRole('button', { name: 'Apply' }));
|
125
|
+
|
126
|
+
// link should be applied to the additional selected text ("with some"), formatting should be preserved.
|
127
|
+
expect(editor.from).toBe(22);
|
128
|
+
expect(editor.to).toBe(22);
|
129
|
+
expect(getJsonContent()).toEqual({
|
130
|
+
type: 'paragraph',
|
131
|
+
attrs: expect.any(Object),
|
132
|
+
content: [
|
133
|
+
{
|
134
|
+
type: 'text',
|
135
|
+
text: 'Sample link ',
|
136
|
+
marks: [
|
137
|
+
{
|
138
|
+
type: 'link',
|
139
|
+
attrs: { href: 'https://www.example.org/my-link', target: '_self', title: 'Sample title' },
|
140
|
+
},
|
141
|
+
],
|
142
|
+
},
|
143
|
+
{
|
144
|
+
type: 'text',
|
145
|
+
text: 'with',
|
146
|
+
marks: [
|
147
|
+
{
|
148
|
+
type: 'link',
|
149
|
+
attrs: { href: 'https://www.example.org/my-link', target: '_self', title: 'Sample title' },
|
150
|
+
},
|
151
|
+
{ type: 'bold' },
|
152
|
+
],
|
153
|
+
},
|
154
|
+
{
|
155
|
+
type: 'text',
|
156
|
+
text: ' some',
|
157
|
+
marks: [
|
158
|
+
{
|
159
|
+
type: 'link',
|
160
|
+
attrs: { href: 'https://www.example.org/my-link', target: '_self', title: 'Sample title' },
|
161
|
+
},
|
162
|
+
],
|
163
|
+
},
|
164
|
+
{ type: 'text', text: ' other content.' },
|
165
|
+
],
|
166
|
+
});
|
167
|
+
});
|
168
|
+
|
169
|
+
it('Updates text and formatting when selection has a mixture of formatting', async () => {
|
170
|
+
const { editor, getJsonContent } = await renderWithEditor(<LinkButton />, {
|
171
|
+
content:
|
172
|
+
'<a href="https://www.example.org/my-link" title="Sample title">Sample link</a> <strong>with</strong> some other content.',
|
173
|
+
});
|
174
|
+
|
175
|
+
// jump to the middle of the link and select some of the text after it.
|
176
|
+
await act(() => editor.selectText({ from: 3, to: 22 }));
|
177
|
+
|
178
|
+
// open the modal and apply the link to the selection.
|
179
|
+
await openModal();
|
180
|
+
fireEvent.change(screen.getByLabelText('Text'), { target: { value: 'Updated sample link and' } });
|
181
|
+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
|
182
|
+
|
183
|
+
await waitForElementToBeRemoved(() => screen.getByRole('button', { name: 'Apply' }));
|
184
|
+
|
185
|
+
// link should be applied and text should be updated.
|
186
|
+
expect(editor.from).toBe(24);
|
187
|
+
expect(editor.to).toBe(24);
|
188
|
+
expect(getJsonContent()).toEqual({
|
189
|
+
type: 'paragraph',
|
190
|
+
attrs: expect.any(Object),
|
191
|
+
content: [
|
192
|
+
{
|
193
|
+
type: 'text',
|
194
|
+
text: 'Updated sample link and',
|
195
|
+
marks: [
|
196
|
+
{
|
197
|
+
type: 'link',
|
198
|
+
attrs: { href: 'https://www.example.org/my-link', target: '_self', title: 'Sample title' },
|
199
|
+
},
|
200
|
+
],
|
201
|
+
},
|
202
|
+
{ type: 'text', text: ' other content.' },
|
203
|
+
],
|
204
|
+
});
|
205
|
+
});
|
206
|
+
|
207
|
+
it('Opens the modal when clicking the keyboard shortcut', async () => {
|
208
|
+
const { editor, elements } = await renderWithEditor(<LinkButton />, {
|
209
|
+
content: '<a href="https://www.example.org/my-link">Sample link</a> with some other content.',
|
210
|
+
});
|
211
|
+
|
212
|
+
// jump to the middle of the link.
|
213
|
+
await act(() => editor.selectText({ from: 1, to: 12 }));
|
214
|
+
|
215
|
+
// press the keyboard shortcut.
|
216
|
+
fireEvent.keyDown(elements.editor, { key: 'k', ctrlKey: true });
|
217
|
+
|
218
|
+
// verify the modal opens and has populated with where the link details where our cursor is positioned.
|
219
|
+
expect(await screen.findByLabelText('URL')).toHaveValue('https://www.example.org/my-link');
|
220
|
+
expect(await screen.findByLabelText('Text')).toHaveValue('Sample link');
|
221
|
+
});
|
222
|
+
|
223
|
+
it('Closes the modal when clicking on the cancel button', async () => {
|
224
|
+
await renderWithEditor(<LinkButton />);
|
225
|
+
|
226
|
+
// open the modal and assert it is visible.
|
227
|
+
await openModal();
|
228
|
+
const modalHeading = screen.getByRole('heading', { name: 'Link' });
|
229
|
+
expect(modalHeading).toBeInTheDocument();
|
230
|
+
|
231
|
+
// close the modal and assert it has disappeared.
|
232
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
233
|
+
expect(modalHeading).not.toBeInTheDocument();
|
234
|
+
});
|
235
|
+
|
236
|
+
it('Add a new asset link', async () => {
|
237
|
+
const matrixIdentifier = 'matrix-api-identifier';
|
238
|
+
const matrixDomain = 'https://my-matrix.squiz.net';
|
239
|
+
const { MockResourceBrowserContext, selectResource } = mockResourceBrowserContext({
|
240
|
+
sources: [{ id: matrixIdentifier }],
|
241
|
+
resources: [{ id: 'my-resource-id', name: 'My resource' }],
|
242
|
+
});
|
243
|
+
|
244
|
+
const { getJsonContent } = await renderWithEditor(
|
245
|
+
<MockResourceBrowserContext>
|
246
|
+
<LinkButton />
|
247
|
+
</MockResourceBrowserContext>,
|
248
|
+
{
|
249
|
+
context: {
|
250
|
+
editor: {
|
251
|
+
matrix: {
|
252
|
+
matrixDomain,
|
253
|
+
},
|
254
|
+
},
|
255
|
+
},
|
256
|
+
},
|
257
|
+
);
|
258
|
+
|
259
|
+
await openModal();
|
260
|
+
fireEvent.click(screen.getByRole('button', { name: 'From source' }));
|
261
|
+
await waitFor(() => {
|
262
|
+
expect(screen.getByRole('button', { name: 'Choose asset' })).toBeInTheDocument();
|
263
|
+
});
|
264
|
+
await selectResource(screen.getByRole('button', { name: 'Choose asset' }), 'My resource');
|
265
|
+
fireEvent.change(screen.getByLabelText('Text'), { target: { value: 'Link text' } });
|
266
|
+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
|
267
|
+
|
268
|
+
await waitForElementToBeRemoved(() => screen.getByRole('button', { name: 'Apply' }));
|
269
|
+
|
270
|
+
expect(getJsonContent()).toEqual({
|
271
|
+
type: 'paragraph',
|
272
|
+
attrs: expect.any(Object),
|
273
|
+
content: [
|
274
|
+
{
|
275
|
+
type: 'text',
|
276
|
+
text: 'Link text',
|
277
|
+
marks: [
|
278
|
+
{
|
279
|
+
type: 'assetLink',
|
280
|
+
attrs: {
|
281
|
+
matrixAssetId: 'my-resource-id',
|
282
|
+
target: '_self',
|
283
|
+
matrixDomain,
|
284
|
+
matrixIdentifier,
|
285
|
+
href: 'https://default-resource/',
|
286
|
+
},
|
287
|
+
},
|
288
|
+
],
|
289
|
+
},
|
290
|
+
],
|
291
|
+
});
|
292
|
+
});
|
293
|
+
|
294
|
+
it('Updates an existing link to be an asset link', async () => {
|
295
|
+
const matrixIdentifier = 'matrix-api-identifier';
|
296
|
+
const matrixDomain = 'https://my-matrix.squiz.net';
|
297
|
+
const { MockResourceBrowserContext, selectResource } = mockResourceBrowserContext({
|
298
|
+
sources: [{ id: matrixIdentifier }],
|
299
|
+
resources: [{ id: 'my-resource-id', name: 'My resource' }],
|
300
|
+
});
|
301
|
+
|
302
|
+
const { editor, getJsonContent } = await renderWithEditor(
|
303
|
+
<MockResourceBrowserContext>
|
304
|
+
<LinkButton />
|
305
|
+
</MockResourceBrowserContext>,
|
306
|
+
{
|
307
|
+
content:
|
308
|
+
'<a href="https://www.example.org/my-link">Sample link</a> with ' +
|
309
|
+
'<a href="https://www.example.org/another-link">another link</a>',
|
310
|
+
context: {
|
311
|
+
editor: {
|
312
|
+
matrix: {
|
313
|
+
matrixDomain,
|
314
|
+
},
|
315
|
+
},
|
316
|
+
},
|
317
|
+
},
|
318
|
+
);
|
319
|
+
|
320
|
+
await act(() => editor.selectText(5));
|
321
|
+
|
322
|
+
await openModal();
|
323
|
+
fireEvent.click(screen.getByRole('button', { name: 'From source' }));
|
324
|
+
await waitFor(() => {
|
325
|
+
expect(screen.getByRole('button', { name: 'Choose asset' })).toBeInTheDocument();
|
326
|
+
});
|
327
|
+
await selectResource(screen.getByRole('button', { name: 'Choose asset' }), 'My resource');
|
328
|
+
fireEvent.click(document.querySelector('div.squiz-fte-checkbox button') as HTMLButtonElement);
|
329
|
+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
|
330
|
+
|
331
|
+
await waitForElementToBeRemoved(() => screen.getByRole('button', { name: 'Apply' }));
|
332
|
+
|
333
|
+
expect(getJsonContent()).toEqual({
|
334
|
+
type: 'paragraph',
|
335
|
+
attrs: expect.any(Object),
|
336
|
+
content: [
|
337
|
+
{
|
338
|
+
type: 'text',
|
339
|
+
text: 'Sample link',
|
340
|
+
marks: [
|
341
|
+
{
|
342
|
+
type: 'assetLink',
|
343
|
+
attrs: {
|
344
|
+
matrixAssetId: 'my-resource-id',
|
345
|
+
target: '_blank',
|
346
|
+
matrixDomain,
|
347
|
+
matrixIdentifier,
|
348
|
+
href: 'https://default-resource/',
|
349
|
+
},
|
350
|
+
},
|
351
|
+
],
|
352
|
+
},
|
353
|
+
{ type: 'text', text: ' with ' },
|
354
|
+
{
|
355
|
+
type: 'text',
|
356
|
+
text: 'another link',
|
357
|
+
marks: [
|
358
|
+
{
|
359
|
+
type: 'link',
|
360
|
+
attrs: { href: 'https://www.example.org/another-link', target: '_self', title: null },
|
361
|
+
},
|
362
|
+
],
|
363
|
+
},
|
364
|
+
],
|
365
|
+
});
|
366
|
+
});
|
367
|
+
|
368
|
+
it('Shows an error if no asset is selected', async () => {
|
369
|
+
await renderWithEditor(<LinkButton />);
|
370
|
+
|
371
|
+
await openModal();
|
372
|
+
fireEvent.click(screen.getByRole('button', { name: 'From source' }));
|
373
|
+
await act(() => fireEvent.click(screen.getByRole('button', { name: 'Apply' })));
|
374
|
+
|
375
|
+
expect(screen.getByText('An asset must be selected')).toBeInTheDocument();
|
376
|
+
});
|
377
|
+
|
378
|
+
it('Shows an error if a required field is not provided', async () => {
|
379
|
+
await renderWithEditor(<LinkButton />);
|
380
|
+
|
381
|
+
await openModal();
|
382
|
+
fireEvent.change(screen.getByLabelText('URL'), { target: { value: '' } });
|
383
|
+
fireEvent.change(screen.getByLabelText('Text'), { target: { value: '' } });
|
384
|
+
fireEvent.change(screen.getByLabelText('Title'), { target: { value: '' } });
|
385
|
+
await act(() => fireEvent.click(screen.getByRole('button', { name: 'Apply' })));
|
386
|
+
|
387
|
+
expect(screen.getByText('URL is required')).toBeInTheDocument();
|
388
|
+
expect(screen.getByText('Text is required')).toBeInTheDocument();
|
389
|
+
});
|
390
|
+
|
391
|
+
it('Shows an error if the field value is just an empty space', async () => {
|
392
|
+
await renderWithEditor(<LinkButton />);
|
393
|
+
|
394
|
+
await openModal();
|
395
|
+
fireEvent.change(screen.getByLabelText('URL'), { target: { value: ' ' } });
|
396
|
+
fireEvent.change(screen.getByLabelText('Text'), { target: { value: ' ' } });
|
397
|
+
fireEvent.change(screen.getByLabelText('Title'), { target: { value: ' ' } });
|
398
|
+
await act(() => fireEvent.click(screen.getByRole('button', { name: 'Apply' })));
|
399
|
+
|
400
|
+
expect(screen.getAllByText('Empty space is not allowed')).toHaveLength(2);
|
401
|
+
});
|
402
|
+
});
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
2
|
+
import InsertLinkRoundedIcon from '@mui/icons-material/InsertLinkRounded';
|
3
|
+
import LinkModal from './LinkModal';
|
4
|
+
import { LinkFormData } from './Form/LinkForm';
|
5
|
+
import Button from '../../../ui/Button/Button';
|
6
|
+
import { useActive, useCommands, useKeymap } from '@remirror/react';
|
7
|
+
import { LinkExtension } from '../../../Extensions/LinkExtension/LinkExtension';
|
8
|
+
import { CommandsExtension } from '../../../Extensions/CommandsExtension/CommandsExtension';
|
9
|
+
import { AssetLinkExtension } from '../../../Extensions/LinkExtension/AssetLinkExtension';
|
10
|
+
import { MarkName } from '../../../Extensions/Extensions';
|
11
|
+
import { ImageExtension } from '../../../Extensions/ImageExtension/ImageExtension';
|
12
|
+
import { CodeBlockExtension } from 'remirror/dist-types/extensions';
|
13
|
+
import { getShortcutSymbol } from '../../../utils/getShortcutSymbol';
|
14
|
+
|
15
|
+
export type LinkButtonProps = {
|
16
|
+
inPopover?: boolean;
|
17
|
+
};
|
18
|
+
|
19
|
+
const LinkButton = ({ inPopover = false }: LinkButtonProps) => {
|
20
|
+
const [showModal, setShowModal] = useState(false);
|
21
|
+
const { updateLink, updateAssetLink } = useCommands<AssetLinkExtension | LinkExtension | CommandsExtension>();
|
22
|
+
const active = useActive<LinkExtension | AssetLinkExtension | ImageExtension | CodeBlockExtension>();
|
23
|
+
// If the image tool is active, disable the link tool as they shouldn't work at the same time
|
24
|
+
const disabled = active.image() || active.codeBlock();
|
25
|
+
const handleClick = () => {
|
26
|
+
if (!showModal) {
|
27
|
+
setShowModal(true);
|
28
|
+
}
|
29
|
+
};
|
30
|
+
const handleShortcut = useCallback(() => {
|
31
|
+
handleClick();
|
32
|
+
// Prevent other key handlers being run
|
33
|
+
return true;
|
34
|
+
}, []);
|
35
|
+
|
36
|
+
const handleSubmit = (data: LinkFormData) => {
|
37
|
+
if (data.linkType === MarkName.AssetLink) {
|
38
|
+
updateAssetLink({ text: data.text, attrs: data.assetLink, range: data.range });
|
39
|
+
} else {
|
40
|
+
updateLink({ text: data.text, attrs: data.link, range: data.range });
|
41
|
+
}
|
42
|
+
|
43
|
+
setShowModal(false);
|
44
|
+
};
|
45
|
+
|
46
|
+
// when Ctrl+K is pressed show the modal, only registered in the toolbar button instance to avoid the key press
|
47
|
+
// being double handled.
|
48
|
+
if (!inPopover) {
|
49
|
+
// disable the shortcut if the button is disabled
|
50
|
+
useKeymap('Mod-k', disabled ? () => true : handleShortcut);
|
51
|
+
}
|
52
|
+
|
53
|
+
return (
|
54
|
+
<>
|
55
|
+
<Button
|
56
|
+
handleOnClick={handleClick}
|
57
|
+
isActive={active.link() || active.assetLink()}
|
58
|
+
icon={<InsertLinkRoundedIcon />}
|
59
|
+
label={`Link (${getShortcutSymbol()}+K)`}
|
60
|
+
isDisabled={disabled}
|
61
|
+
/>
|
62
|
+
{showModal && <LinkModal onCancel={() => setShowModal(false)} onSubmit={handleSubmit} />}
|
63
|
+
</>
|
64
|
+
);
|
65
|
+
};
|
66
|
+
|
67
|
+
export default LinkButton;
|