@x15ventures/x15-ui-library 3.19.0 → 3.20.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/THIRD_PARTY_LICENSES.md +11182 -0
- package/dist/cjs/autoGenerated/libraryThemes.js +12 -12
- package/dist/cjs/autoGenerated/libraryThemes.js.map +1 -1
- package/dist/cjs/autoGenerated/libraryThemes.json +12 -12
- package/dist/cjs/components/design/banners/pageBanner/PageBanner.js +27 -12
- package/dist/cjs/components/design/banners/pageBanner/PageBanner.js.map +1 -1
- package/dist/cjs/components/design/card/cardHeader/CardHeaderItem.js +22 -15
- package/dist/cjs/components/design/card/cardHeader/CardHeaderItem.js.map +1 -1
- package/dist/cjs/components/design/dialog/dialog.css +4 -0
- package/dist/cjs/components/design/logos/LogoLink.js +2 -1
- package/dist/cjs/components/design/logos/LogoLink.js.map +1 -1
- package/dist/cjs/components/design/logos/VentureLogo.js +2 -1
- package/dist/cjs/components/design/logos/VentureLogo.js.map +1 -1
- package/dist/cjs/components/design/revealMore/RevealMoreBelow.js +2 -2
- package/dist/cjs/components/design/revealMore/RevealMoreBelow.js.map +1 -1
- package/dist/cjs/components/design/skeleton/Skeleton.js +15 -5
- package/dist/cjs/components/design/skeleton/Skeleton.js.map +1 -1
- package/dist/cjs/components/design/themeLoader/ThemeLoader.js +1 -1
- package/dist/cjs/components/design/themeLoader/ThemeLoader.js.map +1 -1
- package/dist/cjs/components/form/buttons/SimpleButton.js +3 -1
- package/dist/cjs/components/form/buttons/SimpleButton.js.map +1 -1
- package/dist/cjs/components/form/buttons/button.interface.js.map +1 -1
- package/dist/cjs/components/form/buttons/userPicButton/UserPicButton.js +5 -3
- package/dist/cjs/components/form/buttons/userPicButton/UserPicButton.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js +64 -19
- package/dist/cjs/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js.map +1 -1
- package/dist/cjs/components/navigation/link/Link.js +2 -1
- package/dist/cjs/components/navigation/link/Link.js.map +1 -1
- package/dist/cjs/components/testing/devToolbar/DevToolbar.js +5 -3
- package/dist/cjs/components/testing/devToolbar/DevToolbar.js.map +1 -1
- package/dist/cjs/constants/fileUploadTypes.js +9 -4
- package/dist/cjs/constants/fileUploadTypes.js.map +1 -1
- package/dist/cjs/helpers/dateHelpers.js +34 -23
- package/dist/cjs/helpers/dateHelpers.js.map +1 -1
- package/dist/cjs/helpers/fileHelpers.js +58 -0
- package/dist/cjs/helpers/fileHelpers.js.map +1 -0
- package/dist/cjs/helpers/index.js +44 -0
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/helpers/interactionsHelper.js +8 -1
- package/dist/cjs/helpers/interactionsHelper.js.map +1 -1
- package/dist/cjs/helpers/objectHelpers.js +23 -9
- package/dist/cjs/helpers/objectHelpers.js.map +1 -1
- package/dist/cjs/helpers/stringHelpers.js +61 -5
- package/dist/cjs/helpers/stringHelpers.js.map +1 -1
- package/dist/cjs/helpers/urlHelpers.js +48 -0
- package/dist/cjs/helpers/urlHelpers.js.map +1 -0
- package/dist/cjs/index.js +191 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +3 -305
- package/dist/cjs/styles/index.css +18 -0
- package/dist/cjs/styles/variables/cssVars/_designVariables.css +18 -0
- package/dist/cjs/widgets/documentComments/DocumentComments.js +305 -0
- package/dist/cjs/widgets/documentComments/DocumentComments.js.map +1 -0
- package/dist/cjs/widgets/documentComments/_documentCommentsVariables.css +0 -0
- package/dist/cjs/widgets/documentComments/documentComments.css +107 -0
- package/dist/cjs/widgets/documentComments/documentComments.interfaces.js +6 -0
- package/dist/cjs/widgets/documentComments/documentComments.interfaces.js.map +1 -0
- package/dist/cjs/widgets/documentComments/index.js +19 -0
- package/dist/cjs/widgets/documentComments/index.js.map +1 -0
- package/dist/cjs/widgets/documentComparer/DocumentComparer.js +309 -0
- package/dist/cjs/widgets/documentComparer/DocumentComparer.js.map +1 -0
- package/dist/cjs/widgets/documentComparer/_documentComparerVariables.css +0 -0
- package/dist/cjs/widgets/documentComparer/documentComparer.css +117 -0
- package/dist/cjs/widgets/documentComparer/documentComparer.interfaces.js +6 -0
- package/dist/cjs/widgets/documentComparer/documentComparer.interfaces.js.map +1 -0
- package/dist/cjs/widgets/documentComparer/index.js +19 -0
- package/dist/cjs/widgets/documentComparer/index.js.map +1 -0
- package/dist/cjs/widgets/documentEditor/DocumentEditor.js +142 -0
- package/dist/cjs/widgets/documentEditor/DocumentEditor.js.map +1 -0
- package/dist/cjs/widgets/documentEditor/_documentEditorVariables.css +0 -0
- package/dist/cjs/widgets/documentEditor/documentEditor.css +33 -0
- package/dist/cjs/widgets/documentEditor/documentEditor.interfaces.js +6 -0
- package/dist/cjs/widgets/documentEditor/documentEditor.interfaces.js.map +1 -0
- package/dist/cjs/widgets/documentEditor/index.js +19 -0
- package/dist/cjs/widgets/documentEditor/index.js.map +1 -0
- package/dist/cjs/widgets/documentViewer/DocumentViewer.js +206 -0
- package/dist/cjs/widgets/documentViewer/DocumentViewer.js.map +1 -0
- package/dist/cjs/widgets/documentViewer/_documentViewerVariables.css +0 -0
- package/dist/cjs/widgets/documentViewer/documentViewer.css +82 -0
- package/dist/cjs/widgets/documentViewer/documentViewer.interfaces.js +6 -0
- package/dist/cjs/widgets/documentViewer/documentViewer.interfaces.js.map +1 -0
- package/dist/cjs/widgets/documentViewer/index.js +19 -0
- package/dist/cjs/widgets/documentViewer/index.js.map +1 -0
- package/dist/cjs/widgets/index.js +126 -0
- package/dist/cjs/widgets/index.js.map +1 -1
- package/dist/cjs/widgets/shared/documents/ToggleGroup.js +32 -0
- package/dist/cjs/widgets/shared/documents/ToggleGroup.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/_documentVariables.css +0 -0
- package/dist/cjs/widgets/shared/documents/annotations/AnnotationLayer.js +279 -0
- package/dist/cjs/widgets/shared/documents/annotations/AnnotationLayer.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/annotations/_annotationLayerVariables.css +0 -0
- package/dist/cjs/widgets/shared/documents/annotations/annotationLayer.css +65 -0
- package/dist/cjs/widgets/shared/documents/annotations/annotations.interfaces.js +21 -0
- package/dist/cjs/widgets/shared/documents/annotations/annotations.interfaces.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/annotations/highlightRegistry.js +67 -0
- package/dist/cjs/widgets/shared/documents/annotations/highlightRegistry.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/annotations/index.js +39 -0
- package/dist/cjs/widgets/shared/documents/annotations/index.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/annotations/textIndex.js +112 -0
- package/dist/cjs/widgets/shared/documents/annotations/textIndex.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/annotations/textQuoteAnchor.js +160 -0
- package/dist/cjs/widgets/shared/documents/annotations/textQuoteAnchor.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/documentHelpers.js +186 -0
- package/dist/cjs/widgets/shared/documents/documentHelpers.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/documents.interfaces.js +6 -0
- package/dist/cjs/widgets/shared/documents/documents.interfaces.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/DocumentDiff.js +73 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/DocumentDiff.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/_documentDiffVariables.css +0 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/buildDocumentDiff.js +114 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/buildDocumentDiff.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/documentDiff.css +69 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/documentDiff.interfaces.js +6 -0
- package/dist/cjs/widgets/shared/documents/engines/documentDiff/documentDiff.interfaces.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/lazyEngines.js +19 -0
- package/dist/cjs/widgets/shared/documents/engines/lazyEngines.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/MarkdownEditorEngine.js +200 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/MarkdownEditorEngine.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/_markdownEditorEngineVariables.css +0 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.css +50 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.interfaces.js +6 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.interfaces.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/markdownTextIndex.js +179 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/markdownTextIndex.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.js +278 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.js +208 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/MarkdownRenderer.js +85 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/MarkdownRenderer.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/_markdownRendererVariables.css +0 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/markdownRenderer.css +78 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/index.js +64 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/index.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/markdownNode.interfaces.js +6 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/markdownNode.interfaces.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/rehypeTableCleanup.js +71 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/rehypeTableCleanup.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/remarkPlugins.js +192 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/remarkPlugins.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/remarkSafeTables.js +86 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/remarkSafeTables.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/tableHelpers.js +38 -0
- package/dist/cjs/widgets/shared/documents/engines/markdownRenderer/plugins/tableHelpers.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/WordRenderer.js +49 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/WordRenderer.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/renderWordDocument.js +214 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/renderWordDocument.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/wordPreviewNumbering.js +112 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/wordPreviewNumbering.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/wordXml.js +68 -0
- package/dist/cjs/widgets/shared/documents/engines/wordRenderer/wordXml.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/index.js +50 -0
- package/dist/cjs/widgets/shared/documents/index.js.map +1 -0
- package/dist/cjs/widgets/shared/documents/toggleGroup.css +8 -0
- package/dist/cjs/widgets/shared/documents/useDocumentContent.js +222 -0
- package/dist/cjs/widgets/shared/documents/useDocumentContent.js.map +1 -0
- package/dist/components/design/banners/pageBanner/PageBanner.d.ts.map +1 -1
- package/dist/components/design/card/cardHeader/CardHeaderItem.d.ts.map +1 -1
- package/dist/components/design/logos/LogoLink.d.ts.map +1 -1
- package/dist/components/design/logos/VentureLogo.d.ts.map +1 -1
- package/dist/components/design/skeleton/Skeleton.d.ts +1 -1
- package/dist/components/design/skeleton/Skeleton.d.ts.map +1 -1
- package/dist/components/design/themeLoader/ThemeLoader.d.ts.map +1 -1
- package/dist/components/form/buttons/SimpleButton.d.ts.map +1 -1
- package/dist/components/form/buttons/button.interface.d.ts +1 -0
- package/dist/components/form/buttons/button.interface.d.ts.map +1 -1
- package/dist/components/form/buttons/userPicButton/UserPicButton.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.d.ts.map +1 -1
- package/dist/components/navigation/link/Link.d.ts.map +1 -1
- package/dist/components/testing/devToolbar/DevToolbar.d.ts.map +1 -1
- package/dist/constants/fileUploadTypes.d.ts.map +1 -1
- package/dist/esm/autoGenerated/libraryThemes.js +12 -12
- package/dist/esm/autoGenerated/libraryThemes.js.map +1 -1
- package/dist/esm/autoGenerated/libraryThemes.json +12 -12
- package/dist/esm/components/design/banners/pageBanner/PageBanner.js +27 -12
- package/dist/esm/components/design/banners/pageBanner/PageBanner.js.map +1 -1
- package/dist/esm/components/design/card/cardHeader/CardHeaderItem.js +22 -15
- package/dist/esm/components/design/card/cardHeader/CardHeaderItem.js.map +1 -1
- package/dist/esm/components/design/dialog/dialog.css +4 -0
- package/dist/esm/components/design/logos/LogoLink.js +2 -1
- package/dist/esm/components/design/logos/LogoLink.js.map +1 -1
- package/dist/esm/components/design/logos/VentureLogo.js +2 -1
- package/dist/esm/components/design/logos/VentureLogo.js.map +1 -1
- package/dist/esm/components/design/revealMore/RevealMoreBelow.js +1 -1
- package/dist/esm/components/design/revealMore/RevealMoreBelow.js.map +1 -1
- package/dist/esm/components/design/skeleton/Skeleton.js +15 -5
- package/dist/esm/components/design/skeleton/Skeleton.js.map +1 -1
- package/dist/esm/components/design/themeLoader/ThemeLoader.js +1 -1
- package/dist/esm/components/design/themeLoader/ThemeLoader.js.map +1 -1
- package/dist/esm/components/form/buttons/SimpleButton.js +3 -1
- package/dist/esm/components/form/buttons/SimpleButton.js.map +1 -1
- package/dist/esm/components/form/buttons/button.interface.js.map +1 -1
- package/dist/esm/components/form/buttons/userPicButton/UserPicButton.js +5 -3
- package/dist/esm/components/form/buttons/userPicButton/UserPicButton.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js +65 -19
- package/dist/esm/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js.map +1 -1
- package/dist/esm/components/navigation/link/Link.js +2 -1
- package/dist/esm/components/navigation/link/Link.js.map +1 -1
- package/dist/esm/components/testing/devToolbar/DevToolbar.js +5 -3
- package/dist/esm/components/testing/devToolbar/DevToolbar.js.map +1 -1
- package/dist/esm/constants/fileUploadTypes.js +9 -4
- package/dist/esm/constants/fileUploadTypes.js.map +1 -1
- package/dist/esm/helpers/dateHelpers.js +34 -23
- package/dist/esm/helpers/dateHelpers.js.map +1 -1
- package/dist/esm/helpers/fileHelpers.js +48 -0
- package/dist/esm/helpers/fileHelpers.js.map +1 -0
- package/dist/esm/helpers/index.js +2 -0
- package/dist/esm/helpers/index.js.map +1 -1
- package/dist/esm/helpers/interactionsHelper.js +5 -0
- package/dist/esm/helpers/interactionsHelper.js.map +1 -1
- package/dist/esm/helpers/objectHelpers.js +23 -9
- package/dist/esm/helpers/objectHelpers.js.map +1 -1
- package/dist/esm/helpers/stringHelpers.js +61 -5
- package/dist/esm/helpers/stringHelpers.js.map +1 -1
- package/dist/esm/helpers/urlHelpers.js +40 -0
- package/dist/esm/helpers/urlHelpers.js.map +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +2 -304
- package/dist/esm/styles/index.css +18 -0
- package/dist/esm/styles/variables/cssVars/_designVariables.css +18 -0
- package/dist/esm/widgets/documentComments/DocumentComments.js +298 -0
- package/dist/esm/widgets/documentComments/DocumentComments.js.map +1 -0
- package/dist/esm/widgets/documentComments/_documentCommentsVariables.css +0 -0
- package/dist/esm/widgets/documentComments/documentComments.css +107 -0
- package/dist/esm/widgets/documentComments/documentComments.interfaces.js +2 -0
- package/dist/esm/widgets/documentComments/documentComments.interfaces.js.map +1 -0
- package/dist/esm/widgets/documentComments/index.js +2 -0
- package/dist/esm/widgets/documentComments/index.js.map +1 -0
- package/dist/esm/widgets/documentComparer/DocumentComparer.js +301 -0
- package/dist/esm/widgets/documentComparer/DocumentComparer.js.map +1 -0
- package/dist/esm/widgets/documentComparer/_documentComparerVariables.css +0 -0
- package/dist/esm/widgets/documentComparer/documentComparer.css +117 -0
- package/dist/esm/widgets/documentComparer/documentComparer.interfaces.js +2 -0
- package/dist/esm/widgets/documentComparer/documentComparer.interfaces.js.map +1 -0
- package/dist/esm/widgets/documentComparer/index.js +2 -0
- package/dist/esm/widgets/documentComparer/index.js.map +1 -0
- package/dist/esm/widgets/documentEditor/DocumentEditor.js +135 -0
- package/dist/esm/widgets/documentEditor/DocumentEditor.js.map +1 -0
- package/dist/esm/widgets/documentEditor/_documentEditorVariables.css +0 -0
- package/dist/esm/widgets/documentEditor/documentEditor.css +33 -0
- package/dist/esm/widgets/documentEditor/documentEditor.interfaces.js +2 -0
- package/dist/esm/widgets/documentEditor/documentEditor.interfaces.js.map +1 -0
- package/dist/esm/widgets/documentEditor/index.js +2 -0
- package/dist/esm/widgets/documentEditor/index.js.map +1 -0
- package/dist/esm/widgets/documentViewer/DocumentViewer.js +198 -0
- package/dist/esm/widgets/documentViewer/DocumentViewer.js.map +1 -0
- package/dist/esm/widgets/documentViewer/_documentViewerVariables.css +0 -0
- package/dist/esm/widgets/documentViewer/documentViewer.css +82 -0
- package/dist/esm/widgets/documentViewer/documentViewer.interfaces.js +2 -0
- package/dist/esm/widgets/documentViewer/documentViewer.interfaces.js.map +1 -0
- package/dist/esm/widgets/documentViewer/index.js +2 -0
- package/dist/esm/widgets/documentViewer/index.js.map +1 -0
- package/dist/esm/widgets/index.js +6 -0
- package/dist/esm/widgets/index.js.map +1 -1
- package/dist/esm/widgets/shared/documents/ToggleGroup.js +24 -0
- package/dist/esm/widgets/shared/documents/ToggleGroup.js.map +1 -0
- package/dist/esm/widgets/shared/documents/_documentVariables.css +0 -0
- package/dist/esm/widgets/shared/documents/annotations/AnnotationLayer.js +273 -0
- package/dist/esm/widgets/shared/documents/annotations/AnnotationLayer.js.map +1 -0
- package/dist/esm/widgets/shared/documents/annotations/_annotationLayerVariables.css +0 -0
- package/dist/esm/widgets/shared/documents/annotations/annotationLayer.css +65 -0
- package/dist/esm/widgets/shared/documents/annotations/annotations.interfaces.js +14 -0
- package/dist/esm/widgets/shared/documents/annotations/annotations.interfaces.js.map +1 -0
- package/dist/esm/widgets/shared/documents/annotations/highlightRegistry.js +58 -0
- package/dist/esm/widgets/shared/documents/annotations/highlightRegistry.js.map +1 -0
- package/dist/esm/widgets/shared/documents/annotations/index.js +4 -0
- package/dist/esm/widgets/shared/documents/annotations/index.js.map +1 -0
- package/dist/esm/widgets/shared/documents/annotations/textIndex.js +103 -0
- package/dist/esm/widgets/shared/documents/annotations/textIndex.js.map +1 -0
- package/dist/esm/widgets/shared/documents/annotations/textQuoteAnchor.js +150 -0
- package/dist/esm/widgets/shared/documents/annotations/textQuoteAnchor.js.map +1 -0
- package/dist/esm/widgets/shared/documents/documentHelpers.js +168 -0
- package/dist/esm/widgets/shared/documents/documentHelpers.js.map +1 -0
- package/dist/esm/widgets/shared/documents/documents.interfaces.js +2 -0
- package/dist/esm/widgets/shared/documents/documents.interfaces.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/DocumentDiff.js +65 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/DocumentDiff.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/_documentDiffVariables.css +0 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/buildDocumentDiff.js +102 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/buildDocumentDiff.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/documentDiff.css +69 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/documentDiff.interfaces.js +2 -0
- package/dist/esm/widgets/shared/documents/engines/documentDiff/documentDiff.interfaces.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/lazyEngines.js +13 -0
- package/dist/esm/widgets/shared/documents/engines/lazyEngines.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/MarkdownEditorEngine.js +191 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/MarkdownEditorEngine.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/_markdownEditorEngineVariables.css +0 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.css +50 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.interfaces.js +2 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.interfaces.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/markdownTextIndex.js +170 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/markdownTextIndex.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.js +270 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.js +198 -0
- package/dist/esm/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/MarkdownRenderer.js +76 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/MarkdownRenderer.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/_markdownRendererVariables.css +0 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/markdownRenderer.css +78 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/index.js +5 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/index.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/markdownNode.interfaces.js +2 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/markdownNode.interfaces.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/rehypeTableCleanup.js +64 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/rehypeTableCleanup.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/remarkPlugins.js +182 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/remarkPlugins.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/remarkSafeTables.js +78 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/remarkSafeTables.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/tableHelpers.js +30 -0
- package/dist/esm/widgets/shared/documents/engines/markdownRenderer/plugins/tableHelpers.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/WordRenderer.js +41 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/WordRenderer.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/renderWordDocument.js +207 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/renderWordDocument.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/wordPreviewNumbering.js +105 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/wordPreviewNumbering.js.map +1 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/wordXml.js +57 -0
- package/dist/esm/widgets/shared/documents/engines/wordRenderer/wordXml.js.map +1 -0
- package/dist/esm/widgets/shared/documents/index.js +3 -0
- package/dist/esm/widgets/shared/documents/index.js.map +1 -0
- package/dist/esm/widgets/shared/documents/toggleGroup.css +8 -0
- package/dist/esm/widgets/shared/documents/useDocumentContent.js +215 -0
- package/dist/esm/widgets/shared/documents/useDocumentContent.js.map +1 -0
- package/dist/helpers/dateHelpers.d.ts.map +1 -1
- package/dist/helpers/fileHelpers.d.ts +5 -0
- package/dist/helpers/fileHelpers.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/interactionsHelper.d.ts +2 -0
- package/dist/helpers/interactionsHelper.d.ts.map +1 -1
- package/dist/helpers/objectHelpers.d.ts.map +1 -1
- package/dist/helpers/stringHelpers.d.ts.map +1 -1
- package/dist/helpers/urlHelpers.d.ts +3 -0
- package/dist/helpers/urlHelpers.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/package.json +42 -28
- package/dist/widgets/documentComments/DocumentComments.d.ts +7 -0
- package/dist/widgets/documentComments/DocumentComments.d.ts.map +1 -0
- package/dist/widgets/documentComments/documentComments.interfaces.d.ts +57 -0
- package/dist/widgets/documentComments/documentComments.interfaces.d.ts.map +1 -0
- package/dist/widgets/documentComments/index.d.ts +3 -0
- package/dist/widgets/documentComments/index.d.ts.map +1 -0
- package/dist/widgets/documentComparer/DocumentComparer.d.ts +7 -0
- package/dist/widgets/documentComparer/DocumentComparer.d.ts.map +1 -0
- package/dist/widgets/documentComparer/documentComparer.interfaces.d.ts +78 -0
- package/dist/widgets/documentComparer/documentComparer.interfaces.d.ts.map +1 -0
- package/dist/widgets/documentComparer/index.d.ts +3 -0
- package/dist/widgets/documentComparer/index.d.ts.map +1 -0
- package/dist/widgets/documentEditor/DocumentEditor.d.ts +7 -0
- package/dist/widgets/documentEditor/DocumentEditor.d.ts.map +1 -0
- package/dist/widgets/documentEditor/documentEditor.interfaces.d.ts +40 -0
- package/dist/widgets/documentEditor/documentEditor.interfaces.d.ts.map +1 -0
- package/dist/widgets/documentEditor/index.d.ts +3 -0
- package/dist/widgets/documentEditor/index.d.ts.map +1 -0
- package/dist/widgets/documentViewer/DocumentViewer.d.ts +7 -0
- package/dist/widgets/documentViewer/DocumentViewer.d.ts.map +1 -0
- package/dist/widgets/documentViewer/documentViewer.interfaces.d.ts +47 -0
- package/dist/widgets/documentViewer/documentViewer.interfaces.d.ts.map +1 -0
- package/dist/widgets/documentViewer/index.d.ts +3 -0
- package/dist/widgets/documentViewer/index.d.ts.map +1 -0
- package/dist/widgets/index.d.ts +12 -0
- package/dist/widgets/index.d.ts.map +1 -1
- package/dist/widgets/shared/documents/ToggleGroup.d.ts +15 -0
- package/dist/widgets/shared/documents/ToggleGroup.d.ts.map +1 -0
- package/dist/widgets/shared/documents/annotations/AnnotationLayer.d.ts +27 -0
- package/dist/widgets/shared/documents/annotations/AnnotationLayer.d.ts.map +1 -0
- package/dist/widgets/shared/documents/annotations/annotations.interfaces.d.ts +43 -0
- package/dist/widgets/shared/documents/annotations/annotations.interfaces.d.ts.map +1 -0
- package/dist/widgets/shared/documents/annotations/highlightRegistry.d.ts +12 -0
- package/dist/widgets/shared/documents/annotations/highlightRegistry.d.ts.map +1 -0
- package/dist/widgets/shared/documents/annotations/index.d.ts +6 -0
- package/dist/widgets/shared/documents/annotations/index.d.ts.map +1 -0
- package/dist/widgets/shared/documents/annotations/textIndex.d.ts +16 -0
- package/dist/widgets/shared/documents/annotations/textIndex.d.ts.map +1 -0
- package/dist/widgets/shared/documents/annotations/textQuoteAnchor.d.ts +15 -0
- package/dist/widgets/shared/documents/annotations/textQuoteAnchor.d.ts.map +1 -0
- package/dist/widgets/shared/documents/documentHelpers.d.ts +14 -0
- package/dist/widgets/shared/documents/documentHelpers.d.ts.map +1 -0
- package/dist/widgets/shared/documents/documents.interfaces.d.ts +20 -0
- package/dist/widgets/shared/documents/documents.interfaces.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/documentDiff/DocumentDiff.d.ts +6 -0
- package/dist/widgets/shared/documents/engines/documentDiff/DocumentDiff.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/documentDiff/buildDocumentDiff.d.ts +25 -0
- package/dist/widgets/shared/documents/engines/documentDiff/buildDocumentDiff.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/documentDiff/documentDiff.interfaces.d.ts +17 -0
- package/dist/widgets/shared/documents/engines/documentDiff/documentDiff.interfaces.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/lazyEngines.d.ts +5 -0
- package/dist/widgets/shared/documents/engines/lazyEngines.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/MarkdownEditorEngine.d.ts +8 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/MarkdownEditorEngine.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.interfaces.d.ts +23 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/markdownEditorEngine.interfaces.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/markdownTextIndex.d.ts +12 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/markdownTextIndex.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.d.ts +8 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.d.ts +32 -0
- package/dist/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/MarkdownRenderer.d.ts +12 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/MarkdownRenderer.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/index.d.ts +7 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/index.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/markdownNode.interfaces.d.ts +16 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/markdownNode.interfaces.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/rehypeTableCleanup.d.ts +3 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/rehypeTableCleanup.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/remarkPlugins.d.ts +6 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/remarkPlugins.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/remarkSafeTables.d.ts +3 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/remarkSafeTables.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/tableHelpers.d.ts +8 -0
- package/dist/widgets/shared/documents/engines/markdownRenderer/plugins/tableHelpers.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/WordRenderer.d.ts +11 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/WordRenderer.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/renderWordDocument.d.ts +7 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/renderWordDocument.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/wordPreviewNumbering.d.ts +3 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/wordPreviewNumbering.d.ts.map +1 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/wordXml.d.ts +21 -0
- package/dist/widgets/shared/documents/engines/wordRenderer/wordXml.d.ts.map +1 -0
- package/dist/widgets/shared/documents/index.d.ts +5 -0
- package/dist/widgets/shared/documents/index.d.ts.map +1 -0
- package/dist/widgets/shared/documents/useDocumentContent.d.ts +11 -0
- package/dist/widgets/shared/documents/useDocumentContent.d.ts.map +1 -0
- package/package.json +42 -28
- package/readme.md +49 -2
- package/dist/components/design/dialog/Dialog.test.d.ts +0 -5
- package/dist/components/design/dialog/Dialog.test.d.ts.map +0 -1
- package/dist/components/design/progressIndicators/circularProgressIndicator/CircularProgressIndicator.test.d.ts +0 -5
- package/dist/components/design/progressIndicators/circularProgressIndicator/CircularProgressIndicator.test.d.ts.map +0 -1
- package/dist/components/design/tooltip/Tooltip.test.d.ts +0 -2
- package/dist/components/design/tooltip/Tooltip.test.d.ts.map +0 -1
- package/dist/components/form/buttons/SimpleButton.test.d.ts +0 -5
- package/dist/components/form/buttons/SimpleButton.test.d.ts.map +0 -1
- package/dist/components/form/formFields/formFieldWrapper/FormField.test.d.ts +0 -5
- package/dist/components/form/formFields/formFieldWrapper/FormField.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/inputs/checkbox/checkboxSwitch/CheckboxSwitch.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/inputs/checkbox/checkboxSwitch/CheckboxSwitch.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/inputs/file/fileAttachmentList/FileAttachmentsList.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/inputs/file/fileAttachmentList/FileAttachmentsList.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/inputs/text/InputText.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/inputs/text/InputText.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/nestedFormContext.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/nestedFormContext.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/select/Select.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/select/Select.test.d.ts.map +0 -1
- package/dist/components/form/formFields/subComponents/textarea/Textarea.test.d.ts +0 -5
- package/dist/components/form/formFields/subComponents/textarea/Textarea.test.d.ts.map +0 -1
- package/dist/components/form/hookFormWrapper/HookFormWrapper.test.d.ts +0 -5
- package/dist/components/form/hookFormWrapper/HookFormWrapper.test.d.ts.map +0 -1
- package/dist/components/form/validation/ValidationMessages.test.d.ts +0 -5
- package/dist/components/form/validation/ValidationMessages.test.d.ts.map +0 -1
- package/dist/components/navigation/bubbleNavigator/bubbleNavigatorUtilities.test.d.ts +0 -2
- package/dist/components/navigation/bubbleNavigator/bubbleNavigatorUtilities.test.d.ts.map +0 -1
- package/dist/components/navigation/menu/menuItemContent/MenuItemIcon.test.d.ts +0 -5
- package/dist/components/navigation/menu/menuItemContent/MenuItemIcon.test.d.ts.map +0 -1
- package/dist/helpers/ageHelpers.test.d.ts +0 -2
- package/dist/helpers/ageHelpers.test.d.ts.map +0 -1
- package/dist/helpers/dateHelpers.test.d.ts +0 -2
- package/dist/helpers/dateHelpers.test.d.ts.map +0 -1
- package/dist/helpers/formatters.test.d.ts +0 -5
- package/dist/helpers/formatters.test.d.ts.map +0 -1
- package/dist/helpers/iconHelpers.test.d.ts +0 -5
- package/dist/helpers/iconHelpers.test.d.ts.map +0 -1
- package/dist/helpers/numberHelpers.test.d.ts +0 -5
- package/dist/helpers/numberHelpers.test.d.ts.map +0 -1
- package/dist/helpers/objectHelpers.test.d.ts +0 -2
- package/dist/helpers/objectHelpers.test.d.ts.map +0 -1
- package/dist/helpers/stringHelpers.test.d.ts +0 -2
- package/dist/helpers/stringHelpers.test.d.ts.map +0 -1
- package/dist/hooks/InteractiveHostFocus.test.d.ts +0 -5
- package/dist/hooks/InteractiveHostFocus.test.d.ts.map +0 -1
- package/dist/widgets/processLauncher/ProcessLauncher.test.d.ts +0 -5
- package/dist/widgets/processLauncher/ProcessLauncher.test.d.ts.map +0 -1
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sanitizeEditorInput = exports.desanitizeEditorOutput = void 0;
|
|
7
|
+
/*
|
|
8
|
+
MDXEditor parses markdown as MDX, so two kinds of input need neutralising before it sees them:
|
|
9
|
+
1. HTML injection: every `<` that is not part of explicitly allowed HTML is encoded as `<`,
|
|
10
|
+
making it inert text the parser cannot interpret as markup.
|
|
11
|
+
2. MDX expressions: `{` is encoded as `{` so it is never evaluated.
|
|
12
|
+
|
|
13
|
+
Allowed HTML is protected with placeholders rather than an HTML sanitiser, so content never
|
|
14
|
+
passes through an HTML serialiser (which would encode `&` and other text and cause false diffs).
|
|
15
|
+
|
|
16
|
+
SECURITY NOTE: HTML tokens are scanned linearly and validated without constructing regexes from
|
|
17
|
+
the allowlist. Remaining regexes are fixed patterns with no nested ambiguous repetitions.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const PLACEHOLDER_MARK = String.fromCharCode(0xffff);
|
|
21
|
+
const placeholderPattern = /\uFFFF(\d+)\uFFFF/g;
|
|
22
|
+
const hasPlaceholder = /\uFFFF\d+\uFFFF/;
|
|
23
|
+
const isWhitespace = character => character !== undefined && /\s/.test(character);
|
|
24
|
+
const findTagEnd = (input, start) => {
|
|
25
|
+
let quote;
|
|
26
|
+
for (let index = start; index < input.length; index += 1) {
|
|
27
|
+
const character = input[index];
|
|
28
|
+
if (character === '<') {
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
31
|
+
if (quote) {
|
|
32
|
+
if (character === quote) {
|
|
33
|
+
quote = undefined;
|
|
34
|
+
}
|
|
35
|
+
} else if (character === '"' || character === '\'') {
|
|
36
|
+
quote = character;
|
|
37
|
+
} else if (character === '>') {
|
|
38
|
+
return index;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return -1;
|
|
42
|
+
};
|
|
43
|
+
const findHtmlTokens = (input, tag) => {
|
|
44
|
+
const tokens = [];
|
|
45
|
+
const openingPrefix = `<${tag}`;
|
|
46
|
+
const closingToken = `</${tag}>`;
|
|
47
|
+
let searchFrom = 0;
|
|
48
|
+
while (searchFrom < input.length) {
|
|
49
|
+
const index = input.indexOf('<', searchFrom);
|
|
50
|
+
if (index < 0) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
if (input.startsWith(closingToken, index)) {
|
|
54
|
+
tokens.push({
|
|
55
|
+
index,
|
|
56
|
+
token: closingToken,
|
|
57
|
+
closing: true
|
|
58
|
+
});
|
|
59
|
+
searchFrom = index + closingToken.length;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (!input.startsWith(openingPrefix, index)) {
|
|
63
|
+
searchFrom = index + 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const nameEnd = index + openingPrefix.length;
|
|
67
|
+
const boundary = input[nameEnd];
|
|
68
|
+
if (boundary !== '/' && boundary !== '>' && !isWhitespace(boundary)) {
|
|
69
|
+
searchFrom = index + 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const end = findTagEnd(input, nameEnd);
|
|
73
|
+
if (end < 0) {
|
|
74
|
+
searchFrom = index + 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
tokens.push({
|
|
78
|
+
index,
|
|
79
|
+
token: input.slice(index, end + 1),
|
|
80
|
+
closing: false
|
|
81
|
+
});
|
|
82
|
+
searchFrom = end + 1;
|
|
83
|
+
}
|
|
84
|
+
return tokens;
|
|
85
|
+
};
|
|
86
|
+
const isAllowedOpening = ({
|
|
87
|
+
tag,
|
|
88
|
+
classes,
|
|
89
|
+
attrs
|
|
90
|
+
}, token) => {
|
|
91
|
+
const suffix = token.slice(tag.length + 1, -1);
|
|
92
|
+
const hasRestrictions = Boolean(classes?.length || attrs?.length);
|
|
93
|
+
const allowedClasses = classes ?? [];
|
|
94
|
+
if (!hasRestrictions) {
|
|
95
|
+
return suffix === '' || suffix === '/' || isWhitespace(suffix[0]) && !suffix.includes('>');
|
|
96
|
+
}
|
|
97
|
+
let index = 0;
|
|
98
|
+
while (isWhitespace(suffix[index])) {
|
|
99
|
+
index += 1;
|
|
100
|
+
}
|
|
101
|
+
if (index === suffix.length || suffix[index] === '/' && index === suffix.length - 1) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
while (index < suffix.length) {
|
|
105
|
+
const attributeStart = index;
|
|
106
|
+
while (index < suffix.length && !isWhitespace(suffix[index]) && suffix[index] !== '=') {
|
|
107
|
+
index += 1;
|
|
108
|
+
}
|
|
109
|
+
if (index === attributeStart || suffix[index] !== '=') {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const attribute = suffix.slice(attributeStart, index);
|
|
113
|
+
index += 1;
|
|
114
|
+
if (suffix[index] !== '"') {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const valueStart = ++index;
|
|
118
|
+
while (index < suffix.length && suffix[index] !== '"') {
|
|
119
|
+
index += 1;
|
|
120
|
+
}
|
|
121
|
+
if (index === suffix.length) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const value = suffix.slice(valueStart, index);
|
|
125
|
+
const isAllowedClass = attribute === 'class' && allowedClasses.length > 0 && value.split(/\s+/).every(className => className.length > 0 && allowedClasses.includes(className));
|
|
126
|
+
if (!attrs?.includes(attribute) && !isAllowedClass) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
index += 1;
|
|
130
|
+
if (index === suffix.length) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
const separatorStart = index;
|
|
134
|
+
while (isWhitespace(suffix[index])) {
|
|
135
|
+
index += 1;
|
|
136
|
+
}
|
|
137
|
+
if (index === suffix.length || suffix[index] === '/' && index === suffix.length - 1) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (index === separatorStart) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
};
|
|
146
|
+
const isVoidToken = (token, entry) => token.endsWith('/>') || ['img', 'br'].includes(entry.tag);
|
|
147
|
+
const preserve = (value, preserved) => {
|
|
148
|
+
preserved.push(value);
|
|
149
|
+
return `${PLACEHOLDER_MARK}${preserved.length - 1}${PLACEHOLDER_MARK}`;
|
|
150
|
+
};
|
|
151
|
+
const protectInlineCode = (markdown, preserved) => {
|
|
152
|
+
const runs = [];
|
|
153
|
+
for (let index = 0; index < markdown.length;) {
|
|
154
|
+
if (markdown[index] !== '`') {
|
|
155
|
+
index += 1;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
let end = index + 1;
|
|
159
|
+
while (markdown[end] === '`') {
|
|
160
|
+
end += 1;
|
|
161
|
+
}
|
|
162
|
+
let precedingBackslashes = 0;
|
|
163
|
+
for (let previous = index - 1; previous >= 0 && markdown[previous] === '\\'; previous -= 1) {
|
|
164
|
+
precedingBackslashes += 1;
|
|
165
|
+
}
|
|
166
|
+
const escapedTickCount = precedingBackslashes % 2;
|
|
167
|
+
if (end - index > escapedTickCount) {
|
|
168
|
+
runs.push({
|
|
169
|
+
start: index + escapedTickCount,
|
|
170
|
+
end,
|
|
171
|
+
length: end - index - escapedTickCount
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
index = end;
|
|
175
|
+
}
|
|
176
|
+
const nextRunByLength = new Map();
|
|
177
|
+
const nextRun = new Array(runs.length);
|
|
178
|
+
for (let index = runs.length - 1; index >= 0; index -= 1) {
|
|
179
|
+
nextRun[index] = nextRunByLength.get(runs[index].length);
|
|
180
|
+
nextRunByLength.set(runs[index].length, index);
|
|
181
|
+
}
|
|
182
|
+
let result = '';
|
|
183
|
+
let copiedThrough = 0;
|
|
184
|
+
for (let index = 0; index < runs.length; index += 1) {
|
|
185
|
+
const closingIndex = nextRun[index];
|
|
186
|
+
if (closingIndex === undefined) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const opening = runs[index];
|
|
190
|
+
const closing = runs[closingIndex];
|
|
191
|
+
result += markdown.slice(copiedThrough, opening.start);
|
|
192
|
+
result += preserve(markdown.slice(opening.start, closing.end), preserved);
|
|
193
|
+
copiedThrough = closing.end;
|
|
194
|
+
index = closingIndex;
|
|
195
|
+
}
|
|
196
|
+
return result + markdown.slice(copiedThrough);
|
|
197
|
+
};
|
|
198
|
+
const protectCode = (markdown, preserved) => {
|
|
199
|
+
const lines = markdown.split('\n');
|
|
200
|
+
const protectedLines = [];
|
|
201
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
202
|
+
const opening = /^ {0,3}(`{3,}|~{3,})/.exec(lines[index]);
|
|
203
|
+
if (!opening) {
|
|
204
|
+
protectedLines.push(lines[index]);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const marker = opening[1];
|
|
208
|
+
let closingIndex = index + 1;
|
|
209
|
+
for (; closingIndex < lines.length; closingIndex += 1) {
|
|
210
|
+
const closing = /^ {0,3}(`+|~+)[ \t]*$/.exec(lines[closingIndex]);
|
|
211
|
+
if (closing && closing[1][0] === marker[0] && closing[1].length >= marker.length) {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const lastCodeLine = Math.min(closingIndex, lines.length - 1);
|
|
216
|
+
protectedLines.push(preserve(lines.slice(index, lastCodeLine + 1).join('\n'), preserved));
|
|
217
|
+
index = lastCodeLine;
|
|
218
|
+
}
|
|
219
|
+
return protectInlineCode(protectedLines.join('\n'), preserved);
|
|
220
|
+
};
|
|
221
|
+
const sanitizeEditorInput = (markdown, allowedHtml = []) => {
|
|
222
|
+
const preserved = [];
|
|
223
|
+
let withPlaceholders = protectCode(markdown, preserved);
|
|
224
|
+
allowedHtml.forEach(entry => {
|
|
225
|
+
const tokens = findHtmlTokens(withPlaceholders, entry.tag);
|
|
226
|
+
const keep = new Set();
|
|
227
|
+
const openings = [];
|
|
228
|
+
tokens.forEach(({
|
|
229
|
+
token,
|
|
230
|
+
index,
|
|
231
|
+
closing
|
|
232
|
+
}) => {
|
|
233
|
+
if (closing) {
|
|
234
|
+
// A closing tag survives only alongside the allowed opening tag it pairs with.
|
|
235
|
+
const opening = openings.pop();
|
|
236
|
+
if (opening?.allowed) {
|
|
237
|
+
keep.add(opening.index);
|
|
238
|
+
keep.add(index);
|
|
239
|
+
}
|
|
240
|
+
} else if (isVoidToken(token, entry)) {
|
|
241
|
+
if (isAllowedOpening(entry, token)) {
|
|
242
|
+
keep.add(index);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
openings.push({
|
|
246
|
+
index,
|
|
247
|
+
allowed: isAllowedOpening(entry, token)
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
let copiedThrough = 0;
|
|
252
|
+
withPlaceholders = tokens.reduce((result, {
|
|
253
|
+
index,
|
|
254
|
+
token
|
|
255
|
+
}) => {
|
|
256
|
+
result += withPlaceholders.slice(copiedThrough, index);
|
|
257
|
+
result += keep.has(index) ? preserve(token, preserved) : token;
|
|
258
|
+
copiedThrough = index + token.length;
|
|
259
|
+
return result;
|
|
260
|
+
}, '') + withPlaceholders.slice(copiedThrough);
|
|
261
|
+
});
|
|
262
|
+
let result = withPlaceholders.replace(/</g, '<').replace(/\{/g, '{');
|
|
263
|
+
// Nested allowed elements leave placeholders inside restored placeholders, so repeat until none remain.
|
|
264
|
+
while (hasPlaceholder.test(result)) {
|
|
265
|
+
result = result.replace(placeholderPattern, (_, index) => preserved[Number(index)]);
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/*
|
|
271
|
+
Reverses the backslash escapes MDXEditor's serialiser adds for MDX/HTML reasons during its
|
|
272
|
+
markdown -> AST -> markdown round-trip, so `&`, `{`, `}`, `<`, `>` and `"` are saved literally.
|
|
273
|
+
Markdown syntax escapes (\*, \#, \-, ...) are deliberately left alone.
|
|
274
|
+
*/
|
|
275
|
+
exports.sanitizeEditorInput = sanitizeEditorInput;
|
|
276
|
+
const desanitizeEditorOutput = markdown => markdown.replace(/\\&/g, '&').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\</g, '<').replace(/\\>/g, '>').replace(/\\"/g, '"');
|
|
277
|
+
exports.desanitizeEditorOutput = desanitizeEditorOutput;
|
|
278
|
+
//# sourceMappingURL=sanitizeForMdx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeForMdx.js","names":["PLACEHOLDER_MARK","String","fromCharCode","placeholderPattern","hasPlaceholder","isWhitespace","character","undefined","test","findTagEnd","input","start","quote","index","length","findHtmlTokens","tag","tokens","openingPrefix","closingToken","searchFrom","indexOf","startsWith","push","token","closing","nameEnd","boundary","end","slice","isAllowedOpening","classes","attrs","suffix","hasRestrictions","Boolean","allowedClasses","includes","attributeStart","attribute","valueStart","value","isAllowedClass","split","every","className","separatorStart","isVoidToken","entry","endsWith","preserve","preserved","protectInlineCode","markdown","runs","precedingBackslashes","previous","escapedTickCount","nextRunByLength","Map","nextRun","Array","get","set","result","copiedThrough","closingIndex","opening","protectCode","lines","protectedLines","exec","marker","lastCodeLine","Math","min","join","sanitizeEditorInput","allowedHtml","withPlaceholders","forEach","keep","Set","openings","pop","allowed","add","reduce","has","replace","_","Number","exports","desanitizeEditorOutput"],"sources":["../../../../../../../src/widgets/shared/documents/engines/markdownEditor/sanitizeForMdx.ts"],"sourcesContent":["/*\n MDXEditor parses markdown as MDX, so two kinds of input need neutralising before it sees them:\n 1. HTML injection: every `<` that is not part of explicitly allowed HTML is encoded as `<`,\n making it inert text the parser cannot interpret as markup.\n 2. MDX expressions: `{` is encoded as `{` so it is never evaluated.\n\n Allowed HTML is protected with placeholders rather than an HTML sanitiser, so content never\n passes through an HTML serialiser (which would encode `&` and other text and cause false diffs).\n \n SECURITY NOTE: HTML tokens are scanned linearly and validated without constructing regexes from\n the allowlist. Remaining regexes are fixed patterns with no nested ambiguous repetitions.\n */\n\nexport type AllowedHtmlEntry = {\n tag: string;\n classes?: string[];\n attrs?: string[];\n};\n\nconst PLACEHOLDER_MARK = String.fromCharCode(0xffff);\nconst placeholderPattern = /\\uFFFF(\\d+)\\uFFFF/g;\nconst hasPlaceholder = /\\uFFFF\\d+\\uFFFF/;\n\ntype HtmlToken = {\n index: number;\n token: string;\n closing: boolean;\n};\n\nconst isWhitespace = (character: string | undefined): boolean =>\n character !== undefined && /\\s/.test(character);\n\nconst findTagEnd = (input: string, start: number): number => {\n let quote: '\"' | '\\'' | undefined;\n for (let index = start; index < input.length; index += 1) {\n const character = input[index];\n if (character === '<') {\n return -1;\n }\n if (quote) {\n if (character === quote) {\n quote = undefined;\n }\n } else if (character === '\"' || character === '\\'') {\n quote = character;\n } else if (character === '>') {\n return index;\n }\n }\n return -1;\n};\n\nconst findHtmlTokens = (input: string, tag: string): HtmlToken[] => {\n const tokens: HtmlToken[] = [];\n const openingPrefix = `<${ tag }`;\n const closingToken = `</${ tag }>`;\n let searchFrom = 0;\n\n while (searchFrom < input.length) {\n const index = input.indexOf('<', searchFrom);\n if (index < 0) {\n break;\n }\n\n if (input.startsWith(closingToken, index)) {\n tokens.push({ index, token: closingToken, closing: true });\n searchFrom = index + closingToken.length;\n continue;\n }\n\n if (!input.startsWith(openingPrefix, index)) {\n searchFrom = index + 1;\n continue;\n }\n\n const nameEnd = index + openingPrefix.length;\n const boundary = input[nameEnd];\n if (boundary !== '/' && boundary !== '>' && !isWhitespace(boundary)) {\n searchFrom = index + 1;\n continue;\n }\n\n const end = findTagEnd(input, nameEnd);\n if (end < 0) {\n searchFrom = index + 1;\n continue;\n }\n\n tokens.push({ index, token: input.slice(index, end + 1), closing: false });\n searchFrom = end + 1;\n }\n\n return tokens;\n};\n\nconst isAllowedOpening = ({ tag, classes, attrs }: AllowedHtmlEntry, token: string): boolean => {\n const suffix = token.slice(tag.length + 1, -1);\n const hasRestrictions = Boolean(classes?.length || attrs?.length);\n const allowedClasses = classes ?? [];\n\n if (!hasRestrictions) {\n return suffix === '' ||\n suffix === '/' ||\n (isWhitespace(suffix[0]) && !suffix.includes('>'));\n }\n\n let index = 0;\n while (isWhitespace(suffix[index])) {\n index += 1;\n }\n if (index === suffix.length || (suffix[index] === '/' && index === suffix.length - 1)) {\n return true;\n }\n\n while (index < suffix.length) {\n const attributeStart = index;\n while (index < suffix.length && !isWhitespace(suffix[index]) && suffix[index] !== '=') {\n index += 1;\n }\n if (index === attributeStart || suffix[index] !== '=') {\n return false;\n }\n\n const attribute = suffix.slice(attributeStart, index);\n index += 1;\n if (suffix[index] !== '\"') {\n return false;\n }\n const valueStart = ++index;\n while (index < suffix.length && suffix[index] !== '\"') {\n index += 1;\n }\n if (index === suffix.length) {\n return false;\n }\n\n const value = suffix.slice(valueStart, index);\n const isAllowedClass = attribute === 'class' && allowedClasses.length > 0 &&\n value.split(/\\s+/).every((className) => className.length > 0 && allowedClasses.includes(className));\n if (!attrs?.includes(attribute) && !isAllowedClass) {\n return false;\n }\n\n index += 1;\n if (index === suffix.length) {\n return true;\n }\n const separatorStart = index;\n while (isWhitespace(suffix[index])) {\n index += 1;\n }\n if (index === suffix.length || (suffix[index] === '/' && index === suffix.length - 1)) {\n return true;\n }\n if (index === separatorStart) {\n return false;\n }\n }\n\n return true;\n};\n\nconst isVoidToken = (token: string, entry: AllowedHtmlEntry): boolean => token.endsWith('/>') || ['img', 'br'].includes(entry.tag);\n\nconst preserve = (value: string, preserved: string[]): string => {\n preserved.push(value);\n return `${ PLACEHOLDER_MARK }${ preserved.length - 1 }${ PLACEHOLDER_MARK }`;\n};\n\nconst protectInlineCode = (markdown: string, preserved: string[]): string => {\n const runs: { start: number; end: number; length: number }[] = [];\n for (let index = 0; index < markdown.length;) {\n if (markdown[index] !== '`') {\n index += 1;\n continue;\n }\n\n let end = index + 1;\n while (markdown[end] === '`') {\n end += 1;\n }\n let precedingBackslashes = 0;\n for (let previous = index - 1; previous >= 0 && markdown[previous] === '\\\\'; previous -= 1) {\n precedingBackslashes += 1;\n }\n const escapedTickCount = precedingBackslashes % 2;\n if (end - index > escapedTickCount) {\n runs.push({ start: index + escapedTickCount, end, length: end - index - escapedTickCount });\n }\n index = end;\n }\n\n const nextRunByLength = new Map<number, number>();\n const nextRun: (number | undefined)[] = new Array(runs.length);\n for (let index = runs.length - 1; index >= 0; index -= 1) {\n nextRun[index] = nextRunByLength.get(runs[index].length);\n nextRunByLength.set(runs[index].length, index);\n }\n\n let result = '';\n let copiedThrough = 0;\n for (let index = 0; index < runs.length; index += 1) {\n const closingIndex = nextRun[index];\n if (closingIndex === undefined) {\n continue;\n }\n\n const opening = runs[index];\n const closing = runs[closingIndex];\n result += markdown.slice(copiedThrough, opening.start);\n result += preserve(markdown.slice(opening.start, closing.end), preserved);\n copiedThrough = closing.end;\n index = closingIndex;\n }\n return result + markdown.slice(copiedThrough);\n};\n\nconst protectCode = (markdown: string, preserved: string[]): string => {\n const lines = markdown.split('\\n');\n const protectedLines: string[] = [];\n\n for (let index = 0; index < lines.length; index += 1) {\n const opening = /^ {0,3}(`{3,}|~{3,})/.exec(lines[index]);\n if (!opening) {\n protectedLines.push(lines[index]);\n continue;\n }\n\n const marker = opening[1];\n let closingIndex = index + 1;\n for (; closingIndex < lines.length; closingIndex += 1) {\n const closing = /^ {0,3}(`+|~+)[ \\t]*$/.exec(lines[closingIndex]);\n if (closing && closing[1][0] === marker[0] && closing[1].length >= marker.length) {\n break;\n }\n }\n\n const lastCodeLine = Math.min(closingIndex, lines.length - 1);\n protectedLines.push(preserve(lines.slice(index, lastCodeLine + 1).join('\\n'), preserved));\n index = lastCodeLine;\n }\n\n return protectInlineCode(protectedLines.join('\\n'), preserved);\n};\n\nexport const sanitizeEditorInput = (markdown: string, allowedHtml: AllowedHtmlEntry[] = []): string => {\n const preserved: string[] = [];\n let withPlaceholders = protectCode(markdown, preserved);\n\n allowedHtml.forEach((entry) => {\n const tokens = findHtmlTokens(withPlaceholders, entry.tag);\n const keep = new Set<number>();\n const openings: { index: number; allowed: boolean }[] = [];\n\n tokens.forEach(({ token, index, closing }) => {\n if (closing) {\n // A closing tag survives only alongside the allowed opening tag it pairs with.\n const opening = openings.pop();\n if (opening?.allowed) {\n keep.add(opening.index);\n keep.add(index);\n }\n } else if (isVoidToken(token, entry)) {\n if (isAllowedOpening(entry, token)) {\n keep.add(index);\n }\n } else {\n openings.push({ index, allowed: isAllowedOpening(entry, token) });\n }\n });\n\n let copiedThrough = 0;\n withPlaceholders = tokens.reduce((result, { index, token }) => {\n result += withPlaceholders.slice(copiedThrough, index);\n result += keep.has(index) ? preserve(token, preserved) : token;\n copiedThrough = index + token.length;\n return result;\n }, '') + withPlaceholders.slice(copiedThrough);\n });\n\n let result = withPlaceholders.replace(/</g, '<').replace(/\\{/g, '{');\n // Nested allowed elements leave placeholders inside restored placeholders, so repeat until none remain.\n while (hasPlaceholder.test(result)) {\n result = result.replace(placeholderPattern, (_, index: string) => preserved[Number(index)]);\n }\n return result;\n};\n\n/*\n Reverses the backslash escapes MDXEditor's serialiser adds for MDX/HTML reasons during its\n markdown -> AST -> markdown round-trip, so `&`, `{`, `}`, `<`, `>` and `\"` are saved literally.\n Markdown syntax escapes (\\*, \\#, \\-, ...) are deliberately left alone.\n */\nexport const desanitizeEditorOutput = (markdown: string): string => markdown\n .replace(/\\\\&/g, '&')\n .replace(/\\\\{/g, '{')\n .replace(/\\\\}/g, '}')\n .replace(/\\\\</g, '<')\n .replace(/\\\\>/g, '>')\n .replace(/\\\\\"/g, '\"');\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,MAAMA,gBAAgB,GAAGC,MAAM,CAACC,YAAY,CAAC,MAAM,CAAC;AACpD,MAAMC,kBAAkB,GAAG,oBAAoB;AAC/C,MAAMC,cAAc,GAAG,iBAAiB;AAQxC,MAAMC,YAAY,GAAIC,SAA6B,IACjDA,SAAS,KAAKC,SAAS,IAAI,IAAI,CAACC,IAAI,CAACF,SAAS,CAAC;AAEjD,MAAMG,UAAU,GAAGA,CAACC,KAAa,EAAEC,KAAa,KAAa;EAC3D,IAAIC,KAA6B;EACjC,KAAK,IAAIC,KA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W,KAAK,CAACV,MAAM;MACpC,OAAOkD,MAAM;IACf,CAAC,EAAE,EAAE,CAAC,GAAGe,gBAAgB,CAAClD,KAAK,CAACoC,aAAa,CAAC;EAChD,CAAC,CAAC;EAEF,IAAID,MAAM,GAAGe,gBAAgB,CAACU,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;EAC5E;EACA,OAAOrF,cAAc,CAACI,IAAI,CAACwD,MAAM,CAAC,EAAE;IAClCA,MAAM,GAAGA,MAAM,CAACyB,OAAO,CAACtF,kBAAkB,EAAE,CAACuF,CAAC,EAAE7E,KAAa,KAAKsC,SAAS,CAACwC,MAAM,CAAC9E,KAAK,CAAC,CAAC,CAAC;EAC7F;EACA,OAAOmD,MAAM;AACf,CAAC;;AAED;AACA;AACA;AACA;AACA;AAJA4B,OAAA,CAAAf,mBAAA,GAAAA,mBAAA;AAKO,MAAMgB,sBAAsB,GAAIxC,QAAgB,IAAaA,QAAQ,CACzEoC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBA,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBA,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBA,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBA,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBA,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;AAACG,OAAA,CAAAC,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSourceAnnotations = exports.createSourceAnchorResolver = exports.createSourceAnchor = exports.buildSourceDecorations = void 0;
|
|
7
|
+
var _state = require("@codemirror/state");
|
|
8
|
+
var _view = require("@codemirror/view");
|
|
9
|
+
var _annotations = require("../../annotations/annotations.interfaces");
|
|
10
|
+
var _textQuoteAnchor = require("../../annotations/textQuoteAnchor");
|
|
11
|
+
var _markdownTextIndex = require("./markdownTextIndex");
|
|
12
|
+
const COMMENT_ID_ATTRIBUTE = 'data-comment-id';
|
|
13
|
+
const setAnnotations = _state.StateEffect.define();
|
|
14
|
+
// Decorations and selections read the same document repeatedly, so the latest index is reused.
|
|
15
|
+
let cachedIndex = null;
|
|
16
|
+
const getMarkdownTextIndex = markdown => {
|
|
17
|
+
if (cachedIndex?.markdown !== markdown) {
|
|
18
|
+
cachedIndex = {
|
|
19
|
+
markdown,
|
|
20
|
+
index: (0, _markdownTextIndex.buildMarkdownTextIndex)(markdown)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return cachedIndex.index;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
Returns a resolver for anchors in markdown source. Quotes are matched against the rendered text so
|
|
28
|
+
they resolve in either view; the raw source is a fallback for quotes that include markdown syntax.
|
|
29
|
+
*/
|
|
30
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
31
|
+
const createSourceAnchorResolver = doc => {
|
|
32
|
+
const index = getMarkdownTextIndex(doc);
|
|
33
|
+
const resolveInText = (0, _textQuoteAnchor.createTextQuoteResolver)(index.text);
|
|
34
|
+
let resolveInSource;
|
|
35
|
+
return anchor => {
|
|
36
|
+
const match = resolveInText(anchor);
|
|
37
|
+
if (match) {
|
|
38
|
+
return (0, _markdownTextIndex.textToSourceRange)(index, match.start, match.end);
|
|
39
|
+
}
|
|
40
|
+
resolveInSource ??= (0, _textQuoteAnchor.createTextQuoteResolver)(doc);
|
|
41
|
+
const sourceMatch = resolveInSource(anchor);
|
|
42
|
+
return sourceMatch ? {
|
|
43
|
+
from: sourceMatch.start,
|
|
44
|
+
to: sourceMatch.end
|
|
45
|
+
} : null;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Creates an anchor for the rendered text within source[from, to); markup-only selections return null.
|
|
50
|
+
exports.createSourceAnchorResolver = createSourceAnchorResolver;
|
|
51
|
+
const createSourceAnchor = (doc, from, to) => {
|
|
52
|
+
const index = getMarkdownTextIndex(doc);
|
|
53
|
+
return (0, _textQuoteAnchor.createTextQuoteAnchor)(index.text, (0, _markdownTextIndex.sourceToTextOffset)(index, from), (0, _markdownTextIndex.sourceToTextOffset)(index, to));
|
|
54
|
+
};
|
|
55
|
+
exports.createSourceAnchor = createSourceAnchor;
|
|
56
|
+
const buildDecorationState = (doc, state) => {
|
|
57
|
+
const ranges = [];
|
|
58
|
+
let selectedRange = null;
|
|
59
|
+
const resolveAnchor = createSourceAnchorResolver(doc);
|
|
60
|
+
(0, _annotations.getVisibleComments)(state.comments, state.showResolved).forEach(comment => {
|
|
61
|
+
const match = comment.anchor ? resolveAnchor(comment.anchor) : null;
|
|
62
|
+
if (!match || match.from >= match.to) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const isSelected = comment.id === state.selectedCommentId;
|
|
66
|
+
if (isSelected) {
|
|
67
|
+
selectedRange = match;
|
|
68
|
+
}
|
|
69
|
+
ranges.push(_view.Decoration.mark({
|
|
70
|
+
class: `documentAnnotations__sourceHighlight${isSelected ? ' documentAnnotations__sourceHighlight--selected' : ''}`,
|
|
71
|
+
attributes: {
|
|
72
|
+
[COMMENT_ID_ATTRIBUTE]: comment.id
|
|
73
|
+
}
|
|
74
|
+
}).range(match.from, match.to));
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
decorations: _view.Decoration.set(ranges, true),
|
|
78
|
+
selectedRange
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const buildSourceDecorations = (doc, state) => buildDecorationState(doc, state).decorations;
|
|
82
|
+
exports.buildSourceDecorations = buildSourceDecorations;
|
|
83
|
+
const annotationField = _state.StateField.define({
|
|
84
|
+
create: () => ({
|
|
85
|
+
state: {
|
|
86
|
+
comments: []
|
|
87
|
+
},
|
|
88
|
+
decorations: _view.Decoration.none,
|
|
89
|
+
selectedRange: null
|
|
90
|
+
}),
|
|
91
|
+
update: (value, transaction) => {
|
|
92
|
+
const effect = transaction.effects.find(candidate => candidate.is(setAnnotations));
|
|
93
|
+
if (!effect && !transaction.docChanged) {
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
const state = effect ? effect.value : value.state;
|
|
97
|
+
// Anchors are resolved again after edits so highlights follow (or drop) the quoted text.
|
|
98
|
+
return {
|
|
99
|
+
state,
|
|
100
|
+
...buildDecorationState(transaction.state.doc.toString(), state)
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
provide: field => _view.EditorView.decorations.from(field, value => value.decorations)
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
Comment support for the markdown source editor (CodeMirror), which renders and virtualises its
|
|
108
|
+
own DOM, so highlights are drawn as decorations rather than through the DOM-based AnnotationLayer.
|
|
109
|
+
|
|
110
|
+
MDXEditor rebuilds the source editor whenever its extensions change, so the extension is created
|
|
111
|
+
once and annotation state is pushed into every live editor through `update`.
|
|
112
|
+
*/
|
|
113
|
+
const createSourceAnnotations = handlers => {
|
|
114
|
+
const views = new Set();
|
|
115
|
+
const selectionVersions = new WeakMap();
|
|
116
|
+
let latest = {
|
|
117
|
+
comments: []
|
|
118
|
+
};
|
|
119
|
+
const tracker = _view.ViewPlugin.define(view => {
|
|
120
|
+
views.add(view);
|
|
121
|
+
// A view created after the latest update (e.g. on switching to source mode) needs the current state.
|
|
122
|
+
queueMicrotask(() => {
|
|
123
|
+
if (views.has(view)) {
|
|
124
|
+
view.dispatch({
|
|
125
|
+
effects: setAnnotations.of(latest)
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
destroy: () => {
|
|
131
|
+
selectionVersions.delete(view);
|
|
132
|
+
views.delete(view);
|
|
133
|
+
// Switching to rich text destroys the source view; its selection must not outlive it.
|
|
134
|
+
if (views.size === 0) {
|
|
135
|
+
handlers.onSelectionChange(null);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
const selectionListener = _view.EditorView.updateListener.of(update => {
|
|
141
|
+
if (!update.selectionSet && !update.docChanged) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const version = (selectionVersions.get(update.view) ?? 0) + 1;
|
|
145
|
+
selectionVersions.set(update.view, version);
|
|
146
|
+
const isCurrentSelection = () => selectionVersions.get(update.view) === version;
|
|
147
|
+
const {
|
|
148
|
+
from,
|
|
149
|
+
to,
|
|
150
|
+
empty
|
|
151
|
+
} = update.state.selection.main;
|
|
152
|
+
const anchor = empty ? null : createSourceAnchor(update.state.doc.toString(), from, to);
|
|
153
|
+
if (!anchor) {
|
|
154
|
+
handlers.onSelectionChange(null);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// Layout must not be read while CodeMirror is applying an update.
|
|
158
|
+
update.view.requestMeasure({
|
|
159
|
+
read: view => isCurrentSelection() ? view.coordsAtPos(to) : null,
|
|
160
|
+
write: coords => {
|
|
161
|
+
if (isCurrentSelection()) {
|
|
162
|
+
handlers.onSelectionChange(coords ? {
|
|
163
|
+
anchor,
|
|
164
|
+
rect: {
|
|
165
|
+
bottom: coords.bottom,
|
|
166
|
+
right: coords.right
|
|
167
|
+
}
|
|
168
|
+
} : null);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
const clickHandler = _view.EditorView.domEventHandlers({
|
|
174
|
+
click: event => {
|
|
175
|
+
const highlight = event.target?.closest?.(`[${COMMENT_ID_ATTRIBUTE}]`);
|
|
176
|
+
const commentId = highlight?.getAttribute(COMMENT_ID_ATTRIBUTE);
|
|
177
|
+
if (commentId) {
|
|
178
|
+
handlers.onSelectComment(commentId);
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
const extension = [annotationField, tracker, selectionListener, clickHandler];
|
|
184
|
+
const update = state => {
|
|
185
|
+
// Only a newly selected comment scrolls, not other annotation updates.
|
|
186
|
+
const shouldScroll = Boolean(state.selectedCommentId) && state.selectedCommentId !== latest.selectedCommentId;
|
|
187
|
+
latest = state;
|
|
188
|
+
views.forEach(view => {
|
|
189
|
+
view.dispatch({
|
|
190
|
+
effects: setAnnotations.of(state)
|
|
191
|
+
});
|
|
192
|
+
const selectedRange = shouldScroll ? view.state.field(annotationField).selectedRange : null;
|
|
193
|
+
if (selectedRange) {
|
|
194
|
+
view.dispatch({
|
|
195
|
+
effects: _view.EditorView.scrollIntoView(selectedRange.from, {
|
|
196
|
+
y: 'center'
|
|
197
|
+
})
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
extension,
|
|
204
|
+
update
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
exports.createSourceAnnotations = createSourceAnnotations;
|
|
208
|
+
//# sourceMappingURL=sourceAnnotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceAnnotations.js","names":["_state","require","_view","_annotations","_textQuoteAnchor","_markdownTextIndex","COMMENT_ID_ATTRIBUTE","setAnnotations","StateEffect","define","cachedIndex","getMarkdownTextIndex","markdown","index","buildMarkdownTextIndex","createSourceAnchorResolver","doc","resolveInText","createTextQuoteResolver","text","resolveInSource","anchor","match","textToSourceRange","start","end","sourceMatch","from","to","exports","createSourceAnchor","createTextQuoteAnchor","sourceToTextOffset","buildDecorationState","state","ranges","selectedRange","resolveAnchor","getVisibleComments","comments","showResolved","forEach","comment","isSelected","id","selectedCommentId","push","Decoration","mark","class","attributes","range","decorations","set","buildSourceDecorations","annotationField","StateField","create","none","update","value","transaction","effect","effects","find","candidate","is","docChanged","toString","provide","field","EditorView","createSourceAnnotations","handlers","views","Set","selectionVersions","WeakMap","latest","tracker","ViewPlugin","view","add","queueMicrotask","has","dispatch","of","destroy","delete","size","onSelectionChange","selectionListener","updateListener","selectionSet","version","get","isCurrentSelection","empty","selection","main","requestMeasure","read","coordsAtPos","write","coords","rect","bottom","right","clickHandler","domEventHandlers","click","event","highlight","target","closest","commentId","getAttribute","onSelectComment","extension","shouldScroll","Boolean","scrollIntoView","y"],"sources":["../../../../../../../src/widgets/shared/documents/engines/markdownEditor/sourceAnnotations.ts"],"sourcesContent":["import { Extension, Range, StateEffect, StateField } from '@codemirror/state';\nimport { Decoration, DecorationSet, EditorView, ViewPlugin } from '@codemirror/view';\n\nimport { DocumentComment, getVisibleComments, TextQuoteAnchor } from '../../annotations/annotations.interfaces';\nimport { createTextQuoteAnchor, createTextQuoteResolver } from '../../annotations/textQuoteAnchor';\nimport { buildMarkdownTextIndex, MarkdownTextIndex, sourceToTextOffset, textToSourceRange } from './markdownTextIndex';\n\nexport type SourceAnnotationState = {\n comments: DocumentComment[];\n selectedCommentId?: string;\n showResolved?: boolean;\n};\n\nexport type SourceSelection = {\n anchor: TextQuoteAnchor;\n rect: { bottom: number; right: number };\n} | null;\n\nexport type SourceAnnotationHandlers = {\n /* eslint-disable-next-line no-unused-vars */\n onSelectionChange: (selection: SourceSelection) => void;\n /* eslint-disable-next-line no-unused-vars */\n onSelectComment: (commentId: string) => void;\n};\n\nconst COMMENT_ID_ATTRIBUTE = 'data-comment-id';\nconst setAnnotations = StateEffect.define<SourceAnnotationState>();\n\ntype SourceRange = { from: number; to: number };\n\n// Decorations and selections read the same document repeatedly, so the latest index is reused.\nlet cachedIndex: { markdown: string; index: MarkdownTextIndex } | null = null;\nconst getMarkdownTextIndex = (markdown: string): MarkdownTextIndex => {\n if (cachedIndex?.markdown !== markdown) {\n cachedIndex = { markdown, index: buildMarkdownTextIndex(markdown) };\n }\n return cachedIndex.index;\n};\n\n/*\n Returns a resolver for anchors in markdown source. Quotes are matched against the rendered text so\n they resolve in either view; the raw source is a fallback for quotes that include markdown syntax.\n */\n/* eslint-disable-next-line no-unused-vars */\nexport const createSourceAnchorResolver = (doc: string): ((anchor: TextQuoteAnchor) => SourceRange | null) => {\n const index = getMarkdownTextIndex(doc);\n const resolveInText = createTextQuoteResolver(index.text);\n let resolveInSource: ReturnType<typeof createTextQuoteResolver> | undefined;\n return (anchor) => {\n const match = resolveInText(anchor);\n if (match) {\n return textToSourceRange(index, match.start, match.end);\n }\n resolveInSource ??= createTextQuoteResolver(doc);\n const sourceMatch = resolveInSource(anchor);\n return sourceMatch ? { from: sourceMatch.start, to: sourceMatch.end } : null;\n };\n};\n\n// Creates an anchor for the rendered text within source[from, to); markup-only selections return null.\nexport const createSourceAnchor = (doc: string, from: number, to: number): TextQuoteAnchor | null => {\n const index = getMarkdownTextIndex(doc);\n return createTextQuoteAnchor(index.text, sourceToTextOffset(index, from), sourceToTextOffset(index, to));\n};\n\ntype SourceDecorations = { decorations: DecorationSet; selectedRange: SourceRange | null };\n\nconst buildDecorationState = (doc: string, state: SourceAnnotationState): SourceDecorations => {\n const ranges: Range<Decoration>[] = [];\n let selectedRange: SourceRange | null = null;\n const resolveAnchor = createSourceAnchorResolver(doc);\n getVisibleComments(state.comments, state.showResolved).forEach((comment) => {\n const match = comment.anchor ? resolveAnchor(comment.anchor) : null;\n if (!match || match.from >= match.to) {\n return;\n }\n const isSelected = comment.id === state.selectedCommentId;\n if (isSelected) {\n selectedRange = match;\n }\n ranges.push(Decoration.mark({\n class: `documentAnnotations__sourceHighlight${ isSelected ? ' documentAnnotations__sourceHighlight--selected' : '' }`,\n attributes: { [COMMENT_ID_ATTRIBUTE]: comment.id }\n }).range(match.from, match.to));\n });\n return { decorations: Decoration.set(ranges, true), selectedRange };\n};\n\nexport const buildSourceDecorations = (doc: string, state: SourceAnnotationState): DecorationSet =>\n buildDecorationState(doc, state).decorations;\n\ntype FieldValue = SourceDecorations & { state: SourceAnnotationState };\n\nconst annotationField = StateField.define<FieldValue>({\n create: () => ({ state: { comments: [] }, decorations: Decoration.none, selectedRange: null }),\n update: (value, transaction) => {\n const effect = transaction.effects.find((candidate) => candidate.is(setAnnotations));\n if (!effect && !transaction.docChanged) {\n return value;\n }\n const state = effect ? (effect.value as SourceAnnotationState) : value.state;\n // Anchors are resolved again after edits so highlights follow (or drop) the quoted text.\n return { state, ...buildDecorationState(transaction.state.doc.toString(), state) };\n },\n provide: (field) => EditorView.decorations.from(field, (value) => value.decorations)\n});\n\n/*\n Comment support for the markdown source editor (CodeMirror), which renders and virtualises its\n own DOM, so highlights are drawn as decorations rather than through the DOM-based AnnotationLayer.\n\n MDXEditor rebuilds the source editor whenever its extensions change, so the extension is created\n once and annotation state is pushed into every live editor through `update`.\n */\nexport const createSourceAnnotations = (handlers: SourceAnnotationHandlers) => {\n const views = new Set<EditorView>();\n const selectionVersions = new WeakMap<EditorView, number>();\n let latest: SourceAnnotationState = { comments: [] };\n\n const tracker = ViewPlugin.define((view) => {\n views.add(view);\n // A view created after the latest update (e.g. on switching to source mode) needs the current state.\n queueMicrotask(() => {\n if (views.has(view)) {\n view.dispatch({ effects: setAnnotations.of(latest) });\n }\n });\n return {\n destroy: () => {\n selectionVersions.delete(view);\n views.delete(view);\n // Switching to rich text destroys the source view; its selection must not outlive it.\n if (views.size === 0) {\n handlers.onSelectionChange(null);\n }\n }\n };\n });\n\n const selectionListener = EditorView.updateListener.of((update) => {\n if (!update.selectionSet && !update.docChanged) {\n return;\n }\n const version = (selectionVersions.get(update.view) ?? 0) + 1;\n selectionVersions.set(update.view, version);\n const isCurrentSelection = () => selectionVersions.get(update.view) === version;\n const { from, to, empty } = update.state.selection.main;\n const anchor = empty ? null : createSourceAnchor(update.state.doc.toString(), from, to);\n if (!anchor) {\n handlers.onSelectionChange(null);\n return;\n }\n // Layout must not be read while CodeMirror is applying an update.\n update.view.requestMeasure({\n read: (view) => (isCurrentSelection() ? view.coordsAtPos(to) : null),\n write: (coords) => {\n if (isCurrentSelection()) {\n handlers.onSelectionChange(coords ? { anchor, rect: { bottom: coords.bottom, right: coords.right } } : null);\n }\n }\n });\n });\n\n const clickHandler = EditorView.domEventHandlers({\n click: (event) => {\n const highlight = (event.target as Element | null)?.closest?.(`[${ COMMENT_ID_ATTRIBUTE }]`);\n const commentId = highlight?.getAttribute(COMMENT_ID_ATTRIBUTE);\n if (commentId) {\n handlers.onSelectComment(commentId);\n }\n return false;\n }\n });\n\n const extension: Extension = [annotationField, tracker, selectionListener, clickHandler];\n\n const update = (state: SourceAnnotationState) => {\n // Only a newly selected comment scrolls, not other annotation updates.\n const shouldScroll = Boolean(state.selectedCommentId) && state.selectedCommentId !== latest.selectedCommentId;\n latest = state;\n views.forEach((view) => {\n view.dispatch({ effects: setAnnotations.of(state) });\n const selectedRange = shouldScroll ? view.state.field(annotationField).selectedRange : null;\n if (selectedRange) {\n view.dispatch({ effects: EditorView.scrollIntoView(selectedRange.from, { y: 'center' }) });\n }\n });\n };\n\n return { extension, update };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AAoBA,MAAMK,oBAAoB,GAAG,iBAAiB;AAC9C,MAAMC,cAAc,GAAGC,kBAAW,CAACC,MAAM,CAAwB,CAAC;AAIlE;AACA,IAAIC,WAAkE,GAAG,IAAI;AAC7E,MAAMC,oBAAoB,GAAIC,QAAgB,IAAwB;EACpE,IAAIF,WAAW,EAAEE,QAAQ,KAAKA,QAAQ,EAAE;IACtCF,WAAW,GAAG;MAAEE,QAAQ;MAAEC,KAAK,EAAE,IAAAC,yCAAsB,EAACF,QAAQ;IAAE,CAAC;EACrE;EACA,OAAOF,WAAW,CAACG,KAAK;AAC1B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,GAAIC,GAAW,IAAwD;EAC5G,MAAMH,KAAK,GAAGF,oBAAoB,CAACK,GAAG,CAAC;EACvC,MAAMC,aAAa,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AO,EAAEQ,gBAAU,CAACkD,cAAc,CAACrF,aAAa,CAACT,IAAI,EAAE;YAAE+F,CAAC,EAAE;UAAS,CAAC;QAAE,CAAC,CAAC;MAC5F;IACF,CAAC,CAAC;EACJ,CAAC;EAED,OAAO;IAAEJ,SAAS;IAAE3D;EAAO,CAAC;AAC9B,CAAC;AAAC9B,OAAA,CAAA2C,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.MarkdownRenderer = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactMarkdown = _interopRequireWildcard(require("react-markdown"));
|
|
11
|
+
var _remarkGfm = _interopRequireDefault(require("remark-gfm"));
|
|
12
|
+
var _documentHelpers = require("../../documentHelpers");
|
|
13
|
+
var _plugins = require("./plugins");
|
|
14
|
+
require("./markdownRenderer.css");
|
|
15
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
16
|
+
const remarkPlugins = [_remarkGfm.default, _plugins.remarkLineBreaks, _plugins.remarkParagraphBreaks, _plugins.remarkLayoutTables, _plugins.remarkTableCellLists, _plugins.remarkSafeTables];
|
|
17
|
+
const rehypePlugins = [_plugins.rehypeTableCleanup];
|
|
18
|
+
const headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
|
19
|
+
|
|
20
|
+
// mdast-util-to-hast prefixes footnote targets but leaves the shared label ID unprefixed.
|
|
21
|
+
const rehypeFootnoteLabel = labelId => tree => {
|
|
22
|
+
const visit = node => {
|
|
23
|
+
if (node.properties?.id === 'footnote-label') {
|
|
24
|
+
node.properties.id = labelId;
|
|
25
|
+
}
|
|
26
|
+
if (node.properties?.dataFootnoteRef) {
|
|
27
|
+
node.properties.ariaDescribedBy = [labelId];
|
|
28
|
+
}
|
|
29
|
+
node.children?.forEach(visit);
|
|
30
|
+
};
|
|
31
|
+
visit(tree);
|
|
32
|
+
};
|
|
33
|
+
const getHeadingComponents = headingOffset => {
|
|
34
|
+
if (headingOffset <= 0) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return Object.fromEntries(headingTags.map((tag, index) => {
|
|
38
|
+
const level = index + 1 + headingOffset;
|
|
39
|
+
const HeadingComponent = (
|
|
40
|
+
// `node` is react-markdown's AST node; it is removed so it is not written to the DOM.
|
|
41
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
42
|
+
{
|
|
43
|
+
node: _node,
|
|
44
|
+
...props
|
|
45
|
+
}) => level <= 6 ? /*#__PURE__*/(0, _react.createElement)(`h${level}`, props) : /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, props, {
|
|
46
|
+
role: "heading",
|
|
47
|
+
"aria-level": level
|
|
48
|
+
}));
|
|
49
|
+
return [tag, HeadingComponent];
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
const MarkdownRenderer = ({
|
|
53
|
+
markdown,
|
|
54
|
+
headingOffset = 0,
|
|
55
|
+
resolveResourceUrl,
|
|
56
|
+
cssClass = ''
|
|
57
|
+
}) => {
|
|
58
|
+
const components = (0, _react.useMemo)(() => getHeadingComponents(headingOffset), [headingOffset]);
|
|
59
|
+
const footnoteId = (0, _react.useId)();
|
|
60
|
+
const scopedRehypePlugins = (0, _react.useMemo)(() => [...(rehypePlugins ?? []), [rehypeFootnoteLabel, `document-${footnoteId}-footnote-label`]], [footnoteId]);
|
|
61
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
62
|
+
className: `markdownRenderer ${cssClass}`.trim()
|
|
63
|
+
}, /*#__PURE__*/_react.default.createElement(_reactMarkdown.default, {
|
|
64
|
+
remarkPlugins: remarkPlugins,
|
|
65
|
+
rehypePlugins: scopedRehypePlugins,
|
|
66
|
+
remarkRehypeOptions: {
|
|
67
|
+
clobberPrefix: `document-${footnoteId}-`
|
|
68
|
+
},
|
|
69
|
+
components: components,
|
|
70
|
+
urlTransform: (url, key, node) => {
|
|
71
|
+
// react-markdown visits final HAST, including children injected by remarkSafeTables.
|
|
72
|
+
const resolved = resolveResourceUrl ? resolveResourceUrl(url) ?? '' : url;
|
|
73
|
+
if (key === 'src' && node.tagName === 'img') {
|
|
74
|
+
const vetted = (0, _documentHelpers.resolveDocumentResource)(resolved);
|
|
75
|
+
if (/^(?:blob:|data:)/i.test(vetted)) {
|
|
76
|
+
return vetted;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return (0, _reactMarkdown.defaultUrlTransform)(resolved);
|
|
80
|
+
}
|
|
81
|
+
}, markdown));
|
|
82
|
+
};
|
|
83
|
+
exports.MarkdownRenderer = MarkdownRenderer;
|
|
84
|
+
var _default = exports.default = MarkdownRenderer;
|
|
85
|
+
//# sourceMappingURL=MarkdownRenderer.js.map
|