@quadrats/react 0.7.8 → 1.1.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/accordion/accordion.css +1 -0
- package/accordion/accordion.scss +81 -0
- package/accordion/components/Accordion.d.ts +9 -0
- package/accordion/components/Accordion.js +22 -0
- package/accordion/components/AccordionContent.d.ts +8 -0
- package/accordion/components/AccordionContent.js +24 -0
- package/accordion/components/AccordionTitle.d.ts +8 -0
- package/accordion/components/AccordionTitle.js +20 -0
- package/accordion/contexts/AccordionContext.d.ts +2 -0
- package/accordion/contexts/AccordionContext.js +5 -0
- package/accordion/createReactAccordion.d.ts +4 -0
- package/accordion/createReactAccordion.js +144 -0
- package/accordion/defaultRenderAccordionElements.d.ts +2 -0
- package/accordion/defaultRenderAccordionElements.js +12 -0
- package/accordion/hooks/useAccordion.d.ts +1 -0
- package/accordion/hooks/useAccordion.js +8 -0
- package/accordion/index.cjs.js +212 -0
- package/accordion/index.d.ts +8 -0
- package/accordion/index.js +10 -0
- package/accordion/jsx-serializer/createJsxSerializeAccordion.d.ts +5 -0
- package/accordion/jsx-serializer/createJsxSerializeAccordion.js +48 -0
- package/accordion/jsx-serializer/defaultRenderAccordionElements.d.ts +2 -0
- package/accordion/jsx-serializer/defaultRenderAccordionElements.js +16 -0
- package/accordion/jsx-serializer/index.cjs.js +64 -0
- package/accordion/jsx-serializer/index.d.ts +3 -0
- package/accordion/jsx-serializer/index.js +2 -0
- package/accordion/jsx-serializer/package.json +7 -0
- package/accordion/jsx-serializer/typings.d.ts +4 -0
- package/accordion/package.json +10 -0
- package/accordion/toolbar/AccordionToolbarIcon.d.ts +8 -0
- package/accordion/toolbar/AccordionToolbarIcon.js +12 -0
- package/accordion/toolbar/index.cjs.js +22 -0
- package/accordion/toolbar/index.d.ts +2 -0
- package/accordion/toolbar/index.js +2 -0
- package/accordion/toolbar/package.json +7 -0
- package/accordion/toolbar/useAccordionTool.d.ts +4 -0
- package/accordion/toolbar/useAccordionTool.js +10 -0
- package/accordion/typings.d.ts +25 -0
- package/align/constants.d.ts +8 -0
- package/align/constants.js +10 -0
- package/align/createReactAlign.d.ts +2 -0
- package/align/createReactAlign.js +26 -0
- package/align/index.cjs.js +39 -0
- package/align/index.d.ts +3 -0
- package/align/index.js +2 -0
- package/align/package.json +7 -0
- package/align/toolbar/AlignToolbarIcon.d.ts +10 -0
- package/align/toolbar/AlignToolbarIcon.js +12 -0
- package/align/toolbar/index.cjs.js +30 -0
- package/align/toolbar/index.d.ts +2 -0
- package/align/toolbar/index.js +2 -0
- package/align/toolbar/package.json +7 -0
- package/align/toolbar/useAlignTool.d.ts +6 -0
- package/align/toolbar/useAlignTool.js +18 -0
- package/align/typings.d.ts +17 -0
- package/blockquote/blockquote.css +1 -0
- package/blockquote/blockquote.scss +23 -0
- package/blockquote/defaultRenderBlockquoteElement.js +3 -1
- package/blockquote/index.cjs.js +3 -1
- package/blockquote/package.json +4 -1
- package/card/card.css +1 -0
- package/card/card.scss +243 -0
- package/card/components/Card.d.ts +15 -0
- package/card/components/Card.js +109 -0
- package/card/components/CardContents.d.ts +9 -0
- package/card/components/CardContents.js +18 -0
- package/card/components/CardImage.d.ts +9 -0
- package/card/components/CardImage.js +13 -0
- package/card/components/CardPlaceholder.d.ts +4 -0
- package/card/components/CardPlaceholder.js +21 -0
- package/card/createReactCard.d.ts +4 -0
- package/card/createReactCard.js +82 -0
- package/card/defaultRenderCardElements.d.ts +3 -0
- package/card/defaultRenderCardElements.js +14 -0
- package/card/index.cjs.js +242 -0
- package/card/index.d.ts +7 -0
- package/card/index.js +6 -0
- package/card/jsx-serializer/createJsxSerializeCard.d.ts +5 -0
- package/card/jsx-serializer/createJsxSerializeCard.js +48 -0
- package/card/jsx-serializer/defaultRenderCardElements.d.ts +2 -0
- package/card/jsx-serializer/defaultRenderCardElements.js +10 -0
- package/card/jsx-serializer/index.cjs.js +58 -0
- package/card/jsx-serializer/index.d.ts +3 -0
- package/card/jsx-serializer/index.js +2 -0
- package/card/jsx-serializer/package.json +7 -0
- package/card/jsx-serializer/typings.d.ts +9 -0
- package/card/package.json +10 -0
- package/card/toolbar/CardToolbarIcon.d.ts +8 -0
- package/card/toolbar/CardToolbarIcon.js +12 -0
- package/card/toolbar/index.cjs.js +66 -0
- package/card/toolbar/index.d.ts +2 -0
- package/card/toolbar/index.js +2 -0
- package/card/toolbar/package.json +7 -0
- package/card/toolbar/useCardTool.d.ts +4 -0
- package/card/toolbar/useCardTool.js +55 -0
- package/card/typings.d.ts +24 -0
- package/carousel/carousel.css +1 -0
- package/carousel/carousel.scss +356 -0
- package/carousel/components/Carousel.d.ts +15 -0
- package/carousel/components/Carousel.js +66 -0
- package/carousel/components/CarouselCaption.d.ts +9 -0
- package/carousel/components/CarouselCaption.js +12 -0
- package/carousel/components/CarouselImages.d.ts +9 -0
- package/carousel/components/CarouselImages.js +52 -0
- package/carousel/components/CarouselPlaceholder.d.ts +4 -0
- package/carousel/components/CarouselPlaceholder.js +17 -0
- package/carousel/contexts/CarouselContext.d.ts +2 -0
- package/carousel/contexts/CarouselContext.js +5 -0
- package/carousel/createReactCarousel.d.ts +4 -0
- package/carousel/createReactCarousel.js +82 -0
- package/carousel/defaultRenderCarouselElements.d.ts +3 -0
- package/carousel/defaultRenderCarouselElements.js +14 -0
- package/carousel/hooks/useCarousel.d.ts +1 -0
- package/carousel/hooks/useCarousel.js +8 -0
- package/carousel/index.cjs.js +236 -0
- package/carousel/index.d.ts +9 -0
- package/carousel/index.js +8 -0
- package/carousel/jsx-serializer/createJsxSerializeCarousel.d.ts +5 -0
- package/carousel/jsx-serializer/createJsxSerializeCarousel.js +48 -0
- package/carousel/jsx-serializer/defaultRenderCarouselElements.d.ts +2 -0
- package/carousel/jsx-serializer/defaultRenderCarouselElements.js +10 -0
- package/carousel/jsx-serializer/index.cjs.js +58 -0
- package/carousel/jsx-serializer/index.d.ts +3 -0
- package/carousel/jsx-serializer/index.js +2 -0
- package/carousel/jsx-serializer/package.json +7 -0
- package/carousel/jsx-serializer/typings.d.ts +9 -0
- package/carousel/package.json +10 -0
- package/carousel/toolbar/CarouselToolbarIcon.d.ts +8 -0
- package/carousel/toolbar/CarouselToolbarIcon.js +12 -0
- package/carousel/toolbar/index.cjs.js +57 -0
- package/carousel/toolbar/index.d.ts +2 -0
- package/carousel/toolbar/index.js +2 -0
- package/carousel/toolbar/package.json +7 -0
- package/carousel/toolbar/useCarouselTool.d.ts +4 -0
- package/carousel/toolbar/useCarouselTool.js +46 -0
- package/carousel/typings.d.ts +27 -0
- package/components/BaseField/index.d.ts +11 -0
- package/components/BaseField/index.js +17 -0
- package/components/Button/index.d.ts +14 -0
- package/components/Button/index.js +12 -0
- package/components/Hint/index.d.ts +15 -0
- package/components/Hint/index.js +30 -0
- package/components/ImageUploader/index.d.ts +25 -0
- package/components/ImageUploader/index.js +174 -0
- package/components/Input/index.d.ts +14 -0
- package/components/Input/index.js +24 -0
- package/components/Message/index.d.ts +18 -0
- package/components/Message/index.js +72 -0
- package/components/Modal/index.d.ts +28 -0
- package/components/Modal/index.js +61 -0
- package/components/Notifier/NotifierManager.d.ts +17 -0
- package/components/Notifier/NotifierManager.js +24 -0
- package/components/Notifier/createNotifier.d.ts +21 -0
- package/components/Notifier/createNotifier.js +60 -0
- package/components/Notifier/typings.d.ts +28 -0
- package/components/Progress/index.d.ts +1 -1
- package/components/Progress/index.js +12 -8
- package/components/SegmentedControl/index.d.ts +13 -0
- package/components/SegmentedControl/index.js +14 -0
- package/components/Textarea/index.d.ts +15 -0
- package/components/Textarea/index.js +24 -0
- package/components/Toggle/index.d.ts +8 -0
- package/components/Toggle/index.js +15 -0
- package/components/Tooltip/index.js +5 -2
- package/components/Transition/SlideFade.d.ts +20 -0
- package/components/Transition/SlideFade.js +91 -0
- package/components/Transition/Transition.d.ts +98 -0
- package/components/Transition/Transition.js +27 -0
- package/components/Transition/getTransitionStyleProps.d.ts +16 -0
- package/components/Transition/getTransitionStyleProps.js +25 -0
- package/components/Transition/useSetNodeTransition.d.ts +7 -0
- package/components/Transition/useSetNodeTransition.js +35 -0
- package/components/baseField.css +1 -0
- package/components/baseField.scss +34 -0
- package/components/button.css +1 -0
- package/components/button.scss +254 -0
- package/components/components.css +1 -0
- package/components/components.scss +12 -0
- package/components/hint.css +1 -0
- package/components/hint.scss +59 -0
- package/components/index.cjs.js +652 -13
- package/components/index.d.ts +12 -0
- package/components/index.js +11 -0
- package/components/input.css +1 -0
- package/components/input.scss +102 -0
- package/components/message.css +1 -0
- package/components/message.scss +57 -0
- package/components/modal.css +1 -0
- package/components/modal.scss +200 -0
- package/components/progress.css +1 -1
- package/components/progress.scss +32 -20
- package/components/segmentedControl.css +1 -0
- package/components/segmentedControl.scss +63 -0
- package/components/textarea.css +1 -0
- package/components/textarea.scss +104 -0
- package/components/toggle.css +1 -0
- package/components/toggle.scss +55 -0
- package/components/tooltip.css +1 -1
- package/components/tooltip.scss +1 -1
- package/core/components/Editable.js +22 -3
- package/core/components/Quadrats.d.ts +4 -1
- package/core/components/Quadrats.js +6 -2
- package/core/constants.d.ts +1 -0
- package/core/constants.js +3 -0
- package/core/contexts/composition/CompositionProvider.d.ts +8 -0
- package/core/contexts/composition/CompositionProvider.js +8 -0
- package/core/contexts/composition/composition.d.ts +7 -0
- package/core/contexts/composition/composition.js +11 -0
- package/core/contexts/message/MessageProvider.d.ts +5 -0
- package/core/contexts/message/MessageProvider.js +35 -0
- package/core/contexts/message/message.d.ts +10 -0
- package/core/contexts/message/message.js +10 -0
- package/core/contexts/modal/CardModal/CardModal.d.ts +28 -0
- package/core/contexts/modal/CardModal/CardModal.js +103 -0
- package/core/contexts/modal/CarouselModal/CarouselItem.d.ts +15 -0
- package/core/contexts/modal/CarouselModal/CarouselItem.js +56 -0
- package/core/contexts/modal/CarouselModal/CarouselModal.d.ts +11 -0
- package/core/contexts/modal/CarouselModal/CarouselModal.js +174 -0
- package/core/contexts/modal/CarouselModal/FilesDropZone.d.ts +13 -0
- package/core/contexts/modal/CarouselModal/FilesDropZone.js +64 -0
- package/core/contexts/modal/ConfirmModal/ConfirmModal.d.ts +14 -0
- package/core/contexts/modal/ConfirmModal/ConfirmModal.js +21 -0
- package/core/contexts/modal/EmbedModal/EmbedModal.d.ts +11 -0
- package/core/contexts/modal/EmbedModal/EmbedModal.js +25 -0
- package/core/contexts/modal/ModalProvider.d.ts +8 -0
- package/core/contexts/modal/ModalProvider.js +66 -0
- package/core/contexts/modal/modal.d.ts +24 -0
- package/core/contexts/modal/modal.js +15 -0
- package/core/index.d.ts +8 -1
- package/divider/defaultRenderDividerElement.d.ts +1 -1
- package/divider/defaultRenderDividerElement.js +2 -3
- package/divider/divider.css +1 -0
- package/divider/divider.scss +9 -0
- package/divider/index.cjs.js +2 -3
- package/divider/jsx-serializer/defaultRenderDividerElement.js +2 -1
- package/divider/jsx-serializer/index.cjs.js +2 -1
- package/divider/package.json +4 -1
- package/editable.css +1 -1
- package/editable.scss +5 -6
- package/embed/components/VideoIframe.d.ts +3 -2
- package/embed/components/VideoIframe.js +2 -1
- package/embed/createReactEmbed.js +4 -1
- package/embed/createRenderEmbedElementBase.js +3 -1
- package/embed/embed.css +1 -0
- package/embed/embed.scss +234 -0
- package/embed/index.cjs.js +8 -2
- package/embed/jsx-serializer/youtube/index.cjs.js +1 -10
- package/embed/jsx-serializer/youtube/index.d.ts +1 -1
- package/embed/jsx-serializer/youtube/index.js +1 -1
- package/embed/package.json +4 -1
- package/embed/renderers/base/components/BaseEmbedElement.d.ts +21 -0
- package/embed/renderers/base/components/BaseEmbedElement.js +70 -0
- package/embed/renderers/base/index.cjs.js +73 -0
- package/embed/renderers/base/index.d.ts +1 -0
- package/embed/renderers/base/index.js +1 -0
- package/embed/renderers/base/package.json +7 -0
- package/embed/renderers/facebook/components/Facebook.d.ts +3 -2
- package/embed/renderers/facebook/components/Facebook.js +18 -11
- package/embed/renderers/facebook/defaultRenderFacebookEmbedElement.d.ts +2 -0
- package/embed/renderers/facebook/defaultRenderFacebookEmbedElement.js +42 -2
- package/embed/renderers/facebook/index.cjs.js +61 -12
- package/embed/renderers/facebook/index.d.ts +1 -1
- package/embed/renderers/facebook/index.js +1 -1
- package/embed/renderers/instagram/components/Instagram.d.ts +3 -2
- package/embed/renderers/instagram/components/Instagram.js +22 -11
- package/embed/renderers/instagram/defaultRenderInstagramEmbedElement.d.ts +2 -0
- package/embed/renderers/instagram/defaultRenderInstagramEmbedElement.js +42 -2
- package/embed/renderers/instagram/index.cjs.js +65 -12
- package/embed/renderers/instagram/index.d.ts +1 -1
- package/embed/renderers/instagram/index.js +1 -1
- package/embed/renderers/podcast-apple/components/PodcastApple.d.ts +3 -2
- package/embed/renderers/podcast-apple/components/PodcastApple.js +2 -1
- package/embed/renderers/podcast-apple/defaultRenderPodcastAppleEmbedElement.d.ts +2 -0
- package/embed/renderers/podcast-apple/defaultRenderPodcastAppleEmbedElement.js +35 -2
- package/embed/renderers/podcast-apple/index.cjs.js +38 -2
- package/embed/renderers/podcast-apple/index.d.ts +1 -1
- package/embed/renderers/podcast-apple/index.js +1 -1
- package/embed/renderers/spotify/components/Spotify.d.ts +3 -2
- package/embed/renderers/spotify/components/Spotify.js +3 -1
- package/embed/renderers/spotify/defaultRenderSpotifyEmbedElement.d.ts +2 -0
- package/embed/renderers/spotify/defaultRenderSpotifyEmbedElement.js +32 -2
- package/embed/renderers/spotify/index.cjs.js +36 -2
- package/embed/renderers/spotify/index.d.ts +1 -1
- package/embed/renderers/spotify/index.js +1 -1
- package/embed/renderers/twitter/components/Twitter.d.ts +3 -2
- package/embed/renderers/twitter/components/Twitter.js +14 -2
- package/embed/renderers/twitter/defaultRenderTwitterEmbedElement.d.ts +2 -0
- package/embed/renderers/twitter/defaultRenderTwitterEmbedElement.js +42 -2
- package/embed/renderers/twitter/index.cjs.js +57 -3
- package/embed/renderers/twitter/index.d.ts +1 -1
- package/embed/renderers/twitter/index.js +1 -1
- package/embed/renderers/vimeo/defaultRenderVimeoEmbedElement.d.ts +2 -0
- package/embed/renderers/vimeo/defaultRenderVimeoEmbedElement.js +26 -2
- package/embed/renderers/vimeo/index.cjs.js +27 -1
- package/embed/renderers/vimeo/index.d.ts +1 -1
- package/embed/renderers/vimeo/index.js +1 -1
- package/embed/renderers/youtube/defaultRenderYoutubeEmbedElement.d.ts +2 -0
- package/embed/renderers/youtube/defaultRenderYoutubeEmbedElement.js +26 -2
- package/embed/renderers/youtube/index.cjs.js +27 -1
- package/embed/renderers/youtube/index.d.ts +1 -1
- package/embed/renderers/youtube/index.js +1 -1
- package/embed/toolbar/EmbedToolbarIcon.d.ts +3 -6
- package/embed/toolbar/EmbedToolbarIcon.js +2 -2
- package/embed/toolbar/index.cjs.js +98 -13
- package/embed/toolbar/useEmbedTool.d.ts +1 -3
- package/embed/toolbar/useEmbedTool.js +96 -11
- package/embed/typings.d.ts +1 -0
- package/file-uploader/components/FileUploader.js +1 -2
- package/file-uploader/createReactFileUploader.js +4 -1
- package/file-uploader/defaultRenderFileUploaderElement.js +1 -1
- package/file-uploader/file-uploader.css +1 -1
- package/file-uploader/file-uploader.scss +0 -20
- package/file-uploader/index.cjs.js +5 -3
- package/file-uploader/toolbar/index.cjs.js +4 -1
- package/file-uploader/toolbar/useFileUploaderTool.d.ts +1 -1
- package/file-uploader/toolbar/useFileUploaderTool.js +4 -1
- package/file-uploader/typings.d.ts +6 -1
- package/footnote/defaultRenderFootnoteElement.js +1 -1
- package/footnote/index.cjs.js +1 -1
- package/footnote/jsx-serializer/defaultRenderFootnoteElement.js +1 -1
- package/footnote/jsx-serializer/index.cjs.js +1 -1
- package/footnote/toolbar/index.cjs.js +1 -1
- package/footnote/toolbar/useFootnoteTool.js +1 -1
- package/heading/defaultRenderHeadingElement.js +2 -1
- package/heading/heading.css +1 -0
- package/heading/heading.scss +53 -0
- package/heading/index.cjs.js +2 -1
- package/heading/package.json +4 -1
- package/image/components/Image.js +59 -10
- package/image/components/ImageCaption.js +6 -4
- package/image/components/ImagePlaceholder.d.ts +4 -0
- package/image/components/ImagePlaceholder.js +11 -0
- package/image/createReactImage.js +1 -1
- package/image/image.css +1 -1
- package/image/image.scss +61 -6
- package/image/index.cjs.js +93 -33
- package/image/index.d.ts +1 -0
- package/image/index.js +1 -0
- package/image/jsx-serializer/defaultRenderImageElements.js +2 -1
- package/image/jsx-serializer/index.cjs.js +2 -1
- package/image/jsx-serializer/typings.d.ts +2 -0
- package/image/typings.d.ts +2 -0
- package/index.cjs.js +555 -6
- package/index.js +9 -3
- package/input-block/components/InputBlock.js +19 -9
- package/input-block/defaultRenderInputBlockElement.js +1 -1
- package/input-block/hooks/useInputBlock.d.ts +2 -0
- package/input-block/hooks/useInputBlock.js +16 -8
- package/input-block/index.cjs.js +35 -17
- package/input-block/input-block.css +1 -0
- package/input-block/input-block.scss +38 -0
- package/input-block/package.json +4 -1
- package/line-break/line-break.scss +0 -2
- package/list/createReactList.js +11 -1
- package/list/index.cjs.js +15 -5
- package/list/list.css +1 -0
- package/list/list.scss +43 -0
- package/list/package.json +4 -1
- package/package.json +11 -8
- package/paragraph/createReactParagraph.d.ts +2 -0
- package/paragraph/createReactParagraph.js +8 -0
- package/paragraph/createRenderParagraphElement.d.ts +1 -1
- package/paragraph/defaultRenderParagraphElement.d.ts +3 -1
- package/paragraph/defaultRenderParagraphElement.js +4 -1
- package/paragraph/index.cjs.js +15 -2
- package/paragraph/index.d.ts +1 -0
- package/paragraph/index.js +1 -0
- package/paragraph/paragraph.css +1 -1
- package/paragraph/paragraph.scss +7 -2
- package/paragraph/renderParagraphElementWithSymbol.d.ts +3 -1
- package/paragraph/renderParagraphElementWithSymbol.js +4 -1
- package/paragraph/toolbar/ParagraphToolbarIcon.d.ts +8 -0
- package/paragraph/toolbar/ParagraphToolbarIcon.js +12 -0
- package/paragraph/toolbar/index.cjs.js +23 -0
- package/paragraph/toolbar/index.d.ts +2 -0
- package/paragraph/toolbar/index.js +2 -0
- package/paragraph/toolbar/package.json +7 -0
- package/paragraph/toolbar/useToggleParagraphTool.d.ts +5 -0
- package/paragraph/toolbar/useToggleParagraphTool.js +11 -0
- package/read-more/components/ReadMore.js +5 -3
- package/read-more/index.cjs.js +5 -3
- package/read-more/read-more.css +1 -1
- package/read-more/read-more.scss +27 -20
- package/table/components/Table.d.ts +9 -0
- package/table/components/Table.js +231 -0
- package/table/components/TableBody.d.ts +5 -0
- package/table/components/TableBody.js +8 -0
- package/table/components/TableCell.d.ts +5 -0
- package/table/components/TableCell.js +191 -0
- package/table/components/TableHeader.d.ts +5 -0
- package/table/components/TableHeader.js +13 -0
- package/table/components/TableMain.d.ts +5 -0
- package/table/components/TableMain.js +225 -0
- package/table/components/TableRow.d.ts +5 -0
- package/table/components/TableRow.js +8 -0
- package/table/components/TableTitle.d.ts +5 -0
- package/table/components/TableTitle.js +18 -0
- package/table/contexts/TableActionsContext.d.ts +3 -0
- package/table/contexts/TableActionsContext.js +5 -0
- package/table/contexts/TableHeaderContext.d.ts +2 -0
- package/table/contexts/TableHeaderContext.js +7 -0
- package/table/contexts/TableMetadataContext.d.ts +3 -0
- package/table/contexts/TableMetadataContext.js +5 -0
- package/table/contexts/TableScrollContext.d.ts +2 -0
- package/table/contexts/TableScrollContext.js +9 -0
- package/table/contexts/TableStateContext.d.ts +3 -0
- package/table/contexts/TableStateContext.js +5 -0
- package/table/createReactTable.d.ts +4 -0
- package/table/createReactTable.js +297 -0
- package/table/defaultRenderTableElements.d.ts +2 -0
- package/table/defaultRenderTableElements.js +20 -0
- package/table/hooks/useColumnResize.d.ts +12 -0
- package/table/hooks/useColumnResize.js +139 -0
- package/table/hooks/useTableActions.d.ts +25 -0
- package/table/hooks/useTableActions.js +886 -0
- package/table/hooks/useTableActionsContext.d.ts +1 -0
- package/table/hooks/useTableActionsContext.js +12 -0
- package/table/hooks/useTableCell.d.ts +16 -0
- package/table/hooks/useTableCell.js +166 -0
- package/table/hooks/useTableCellToolbarActions.d.ts +34 -0
- package/table/hooks/useTableCellToolbarActions.js +404 -0
- package/table/hooks/useTableMetadata.d.ts +1 -0
- package/table/hooks/useTableMetadata.js +12 -0
- package/table/hooks/useTableStateContext.d.ts +1 -0
- package/table/hooks/useTableStateContext.js +12 -0
- package/table/hooks/useTableStates.d.ts +18 -0
- package/table/hooks/useTableStates.js +14 -0
- package/table/index.cjs.js +3254 -0
- package/table/index.d.ts +16 -0
- package/table/index.js +24 -0
- package/table/jsx-serializer/components/Table.d.ts +3 -0
- package/table/jsx-serializer/components/Table.js +7 -0
- package/table/jsx-serializer/components/TableBody.d.ts +3 -0
- package/table/jsx-serializer/components/TableBody.js +7 -0
- package/table/jsx-serializer/components/TableCell.d.ts +5 -0
- package/table/jsx-serializer/components/TableCell.js +33 -0
- package/table/jsx-serializer/components/TableHeader.d.ts +3 -0
- package/table/jsx-serializer/components/TableHeader.js +10 -0
- package/table/jsx-serializer/components/TableMain.d.ts +6 -0
- package/table/jsx-serializer/components/TableMain.js +18 -0
- package/table/jsx-serializer/components/TableRow.d.ts +3 -0
- package/table/jsx-serializer/components/TableRow.js +7 -0
- package/table/jsx-serializer/components/TableTitle.d.ts +3 -0
- package/table/jsx-serializer/components/TableTitle.js +7 -0
- package/table/jsx-serializer/contexts/TableHeaderContext.d.ts +1 -0
- package/table/jsx-serializer/contexts/TableHeaderContext.js +5 -0
- package/table/jsx-serializer/contexts/TableScrollContext.d.ts +2 -0
- package/table/jsx-serializer/contexts/TableScrollContext.js +7 -0
- package/table/jsx-serializer/createJsxSerializeTable.d.ts +5 -0
- package/table/jsx-serializer/createJsxSerializeTable.js +113 -0
- package/table/jsx-serializer/defaultRenderTableElements.d.ts +2 -0
- package/table/jsx-serializer/defaultRenderTableElements.js +20 -0
- package/table/jsx-serializer/index.cjs.js +195 -0
- package/table/jsx-serializer/index.d.ts +3 -0
- package/table/jsx-serializer/index.js +2 -0
- package/table/jsx-serializer/package.json +7 -0
- package/table/jsx-serializer/typings.d.ts +12 -0
- package/table/package.json +10 -0
- package/table/table.css +1 -0
- package/table/table.scss +393 -0
- package/table/toolbar/TableToolbarIcon.d.ts +8 -0
- package/table/toolbar/TableToolbarIcon.js +12 -0
- package/table/toolbar/index.cjs.js +24 -0
- package/table/toolbar/index.d.ts +2 -0
- package/table/toolbar/index.js +2 -0
- package/table/toolbar/package.json +7 -0
- package/table/toolbar/useTableTool.d.ts +4 -0
- package/table/toolbar/useTableTool.js +13 -0
- package/table/typings.d.ts +66 -0
- package/table/utils/helper.d.ts +160 -0
- package/table/utils/helper.js +693 -0
- package/toolbar/components/InlineToolbar.d.ts +19 -0
- package/toolbar/components/InlineToolbar.js +31 -0
- package/toolbar/components/Toolbar.js +24 -7
- package/toolbar/components/ToolbarGroupIcon.d.ts +7 -0
- package/toolbar/components/ToolbarGroupIcon.js +80 -0
- package/toolbar/components/ToolbarIcon.d.ts +3 -1
- package/toolbar/components/ToolbarIcon.js +24 -6
- package/toolbar/components/toolbarIconName.d.ts +2 -0
- package/toolbar/components/toolbarIconName.js +86 -0
- package/toolbar/contexts/toolbar.d.ts +7 -0
- package/toolbar/contexts/toolbar.js +10 -0
- package/toolbar/contexts/toolbarMenu.d.ts +6 -0
- package/toolbar/contexts/toolbarMenu.js +11 -0
- package/toolbar/hooks/useAutoGroupIcons.d.ts +12 -0
- package/toolbar/hooks/useAutoGroupIcons.js +68 -0
- package/toolbar/index.cjs.js +304 -13
- package/toolbar/index.d.ts +2 -0
- package/toolbar/index.js +2 -0
- package/toolbar/toolbar.css +1 -1
- package/toolbar/toolbar.scss +194 -43
- package/utils/index.cjs.js +159 -0
- package/utils/index.d.ts +6 -0
- package/utils/index.js +6 -0
- package/utils/removePreviousElement.d.ts +9 -0
- package/utils/removePreviousElement.js +44 -0
- package/utils/upload.d.ts +11 -0
- package/utils/upload.js +57 -0
- package/utils/useClickAway.d.ts +5 -0
- package/utils/useClickAway.js +23 -0
- package/utils/useDocumentEvents.d.ts +5 -0
- package/utils/useDocumentEvents.js +21 -0
- package/utils/useIsomorphicLayoutEffect.d.ts +2 -0
- package/utils/useIsomorphicLayoutEffect.js +9 -0
- package/utils/usePreviousValue.d.ts +1 -0
- package/utils/usePreviousValue.js +11 -0
- package/core/index.js +0 -11
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import React, { useRef, useState, useMemo, useEffect, useCallback } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useModal, useSlateStatic, ReactEditor } from '@quadrats/react';
|
|
4
|
+
import { Icon } from '@quadrats/react/components';
|
|
5
|
+
import { Copy, Trash, AlignLeft, AlignCenter, AlignRight, Plus } from '@quadrats/icons';
|
|
6
|
+
import { useTableActionsContext } from '../hooks/useTableActionsContext.js';
|
|
7
|
+
import { useTableMetadata } from '../hooks/useTableMetadata.js';
|
|
8
|
+
import { useTableStateContext } from '../hooks/useTableStateContext.js';
|
|
9
|
+
import { InlineToolbar, ToolbarGroupIcon, ToolbarIcon } from '@quadrats/react/toolbar';
|
|
10
|
+
import { Transforms } from 'slate';
|
|
11
|
+
import { calculateTableMinWidth, columnWidthToCSS } from '@quadrats/common/table';
|
|
12
|
+
import { TableScrollContext } from '../contexts/TableScrollContext.js';
|
|
13
|
+
import { useTableCellAlign, useTableCellAlignStatus } from '../hooks/useTableCell.js';
|
|
14
|
+
import { getTableElements, getColumnWidths } from '../utils/helper.js';
|
|
15
|
+
|
|
16
|
+
function TableMain(props) {
|
|
17
|
+
const { attributes, children } = props;
|
|
18
|
+
const { setConfirmModalConfig } = useModal();
|
|
19
|
+
const editor = useSlateStatic();
|
|
20
|
+
const { addColumn, addRow, addColumnAndRow } = useTableActionsContext();
|
|
21
|
+
const { isReachMaximumColumns, isReachMaximumRows, tableElement } = useTableMetadata();
|
|
22
|
+
const { tableSelectedOn, setTableSelectedOn } = useTableStateContext();
|
|
23
|
+
// Table align functions
|
|
24
|
+
const setAlign = useTableCellAlign(tableElement, editor);
|
|
25
|
+
const getAlign = useTableCellAlignStatus(tableElement, editor);
|
|
26
|
+
const tablePath = ReactEditor.findPath(editor, tableElement);
|
|
27
|
+
const scrollRef = useRef(null);
|
|
28
|
+
const tableRef = useRef(null);
|
|
29
|
+
const [scrollTop, setScrollTop] = useState(0);
|
|
30
|
+
const [scrollLeft, setScrollLeft] = useState(0);
|
|
31
|
+
const [tableWidth, setTableWidth] = useState(0);
|
|
32
|
+
const scrollUpdateTimerRef = useRef(null);
|
|
33
|
+
const isUpdatingScrollRef = useRef(false); // 標記是否正在更新滾動位置
|
|
34
|
+
const previousColumnWidthsRef = useRef(''); // 追蹤 columnWidths 的變化
|
|
35
|
+
// sizing
|
|
36
|
+
const { tableBodyElement } = getTableElements(tableElement);
|
|
37
|
+
const firstRowCells = tableBodyElement === null || tableBodyElement === void 0 ? void 0 : tableBodyElement.children[0].children;
|
|
38
|
+
// 獲取欄位寬度(傳入 tableWidth 以支援混合模式)
|
|
39
|
+
const columnWidths = useMemo(() => getColumnWidths(tableElement, tableWidth), [tableElement, tableWidth]);
|
|
40
|
+
// 計算 table 的最小寬度
|
|
41
|
+
const tableMinWidth = useMemo(() => calculateTableMinWidth(columnWidths), [columnWidths]);
|
|
42
|
+
// 監聽 table 寬度變化
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const { current: table } = tableRef;
|
|
45
|
+
if (!table)
|
|
46
|
+
return;
|
|
47
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
setTableWidth(entry.contentRect.width);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
resizeObserver.observe(table);
|
|
53
|
+
// 初始化寬度
|
|
54
|
+
setTableWidth(table.getBoundingClientRect().width);
|
|
55
|
+
return () => {
|
|
56
|
+
resizeObserver.disconnect();
|
|
57
|
+
};
|
|
58
|
+
}, []);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const { current: scrollContainer } = scrollRef;
|
|
61
|
+
if (!scrollContainer)
|
|
62
|
+
return;
|
|
63
|
+
const handleScroll = () => {
|
|
64
|
+
setScrollTop(scrollContainer.scrollTop);
|
|
65
|
+
setScrollLeft(scrollContainer.scrollLeft);
|
|
66
|
+
// 如果正在程式化更新滾動位置,不要觸發 Slate 更新
|
|
67
|
+
if (isUpdatingScrollRef.current) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// 使用 debounce 來減少 Slate 更新頻率
|
|
71
|
+
if (scrollUpdateTimerRef.current) {
|
|
72
|
+
clearTimeout(scrollUpdateTimerRef.current);
|
|
73
|
+
}
|
|
74
|
+
scrollUpdateTimerRef.current = setTimeout(() => {
|
|
75
|
+
// 更新 tableElement 的 scrollPosition
|
|
76
|
+
const tablePath = ReactEditor.findPath(editor, tableElement);
|
|
77
|
+
Transforms.setNodes(editor, {
|
|
78
|
+
scrollPosition: {
|
|
79
|
+
scrollLeft: scrollContainer.scrollLeft,
|
|
80
|
+
scrollTop: scrollContainer.scrollTop,
|
|
81
|
+
},
|
|
82
|
+
}, { at: tablePath });
|
|
83
|
+
}, 300); // 300ms debounce
|
|
84
|
+
};
|
|
85
|
+
scrollContainer.addEventListener('scroll', handleScroll, false);
|
|
86
|
+
return () => {
|
|
87
|
+
scrollContainer.removeEventListener('scroll', handleScroll, false);
|
|
88
|
+
if (scrollUpdateTimerRef.current) {
|
|
89
|
+
clearTimeout(scrollUpdateTimerRef.current);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}, [editor, tableElement]);
|
|
93
|
+
// 只在 columnWidths 改變時恢復滾動位置
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const { current: scrollContainer } = scrollRef;
|
|
96
|
+
if (!scrollContainer || !tableElement.scrollPosition)
|
|
97
|
+
return;
|
|
98
|
+
// 檢查 columnWidths 是否真的改變了
|
|
99
|
+
const currentColumnWidthsStr = JSON.stringify(columnWidths);
|
|
100
|
+
if (previousColumnWidthsRef.current !== currentColumnWidthsStr) {
|
|
101
|
+
previousColumnWidthsRef.current = currentColumnWidthsStr;
|
|
102
|
+
// 標記正在更新,避免觸發 handleScroll
|
|
103
|
+
isUpdatingScrollRef.current = true;
|
|
104
|
+
// 使用 requestAnimationFrame 確保 DOM 已更新
|
|
105
|
+
requestAnimationFrame(() => {
|
|
106
|
+
var _a, _b, _c, _d;
|
|
107
|
+
scrollContainer.scrollLeft = (_b = (_a = tableElement.scrollPosition) === null || _a === void 0 ? void 0 : _a.scrollLeft) !== null && _b !== void 0 ? _b : 0;
|
|
108
|
+
scrollContainer.scrollTop = (_d = (_c = tableElement.scrollPosition) === null || _c === void 0 ? void 0 : _c.scrollTop) !== null && _d !== void 0 ? _d : 0;
|
|
109
|
+
// 重置標記
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
isUpdatingScrollRef.current = false;
|
|
112
|
+
}, 100);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, [columnWidths, tableElement.scrollPosition]);
|
|
116
|
+
const scrollContextValue = useMemo(() => ({ scrollTop, scrollLeft, scrollRef }), [scrollTop, scrollLeft, scrollRef]);
|
|
117
|
+
// 複製 Table 功能
|
|
118
|
+
const copyTable = useCallback(() => {
|
|
119
|
+
try {
|
|
120
|
+
const clonedTable = JSON.parse(JSON.stringify(tableElement));
|
|
121
|
+
// 找到當前 table 的父節點路徑
|
|
122
|
+
const tableParentPath = tablePath.slice(0, -1);
|
|
123
|
+
const tableIndex = tablePath[tablePath.length - 1];
|
|
124
|
+
// 在當前 table 之後插入複製的 table
|
|
125
|
+
Transforms.insertNodes(editor, clonedTable, {
|
|
126
|
+
at: [...tableParentPath, tableIndex + 1],
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error('Failed to copy table:', error);
|
|
131
|
+
}
|
|
132
|
+
}, [editor, tableElement, tablePath]);
|
|
133
|
+
// 獲取當前 table 的 align 狀態
|
|
134
|
+
const currentTableAlign = getAlign('table');
|
|
135
|
+
// 根據當前 table align 狀態選擇對應的 icon
|
|
136
|
+
const getCurrentTableAlignIcon = () => {
|
|
137
|
+
switch (currentTableAlign) {
|
|
138
|
+
case 'left':
|
|
139
|
+
return AlignLeft;
|
|
140
|
+
case 'center':
|
|
141
|
+
return AlignCenter;
|
|
142
|
+
case 'right':
|
|
143
|
+
return AlignRight;
|
|
144
|
+
default:
|
|
145
|
+
return AlignLeft;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return (React.createElement("div", { className: clsx('qdr-table__mainWrapper', {
|
|
149
|
+
'qdr-table__mainWrapper--selected': (tableSelectedOn === null || tableSelectedOn === void 0 ? void 0 : tableSelectedOn.region) === 'table',
|
|
150
|
+
}) },
|
|
151
|
+
React.createElement(InlineToolbar, { className: "qdr-table__table-toolbar", onClickAway: (tableSelectedOn === null || tableSelectedOn === void 0 ? void 0 : tableSelectedOn.region) === 'table' ? () => setTableSelectedOn(undefined) : undefined, iconGroups: [
|
|
152
|
+
{
|
|
153
|
+
icons: [
|
|
154
|
+
{
|
|
155
|
+
icon: Copy,
|
|
156
|
+
onClick: () => {
|
|
157
|
+
copyTable();
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
React.createElement(ToolbarGroupIcon, { key: "table-align-change", icon: getCurrentTableAlignIcon() },
|
|
161
|
+
React.createElement(ToolbarIcon, { icon: AlignLeft, onClick: () => {
|
|
162
|
+
setAlign('left', 'table');
|
|
163
|
+
} }),
|
|
164
|
+
React.createElement(ToolbarIcon, { icon: AlignCenter, onClick: () => {
|
|
165
|
+
setAlign('center', 'table');
|
|
166
|
+
} }),
|
|
167
|
+
React.createElement(ToolbarIcon, { icon: AlignRight, onClick: () => {
|
|
168
|
+
setAlign('right', 'table');
|
|
169
|
+
} })),
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
icons: [
|
|
174
|
+
{
|
|
175
|
+
icon: Trash,
|
|
176
|
+
className: 'qdr-table__delete',
|
|
177
|
+
onClick: () => {
|
|
178
|
+
setConfirmModalConfig({
|
|
179
|
+
title: '刪除表格',
|
|
180
|
+
content: '是否確認刪除此表格?刪除後將立即移除,且此操作無法復原。',
|
|
181
|
+
confirmText: '刪除表格',
|
|
182
|
+
onConfirm: () => {
|
|
183
|
+
Transforms.removeNodes(editor, { at: tablePath });
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
] }),
|
|
191
|
+
React.createElement("div", { ref: scrollRef, className: "qdr-table__scrollContainer" },
|
|
192
|
+
React.createElement(TableScrollContext.Provider, { value: scrollContextValue },
|
|
193
|
+
React.createElement("table", Object.assign({}, attributes, { ref: (node) => {
|
|
194
|
+
// 合併兩個 refs
|
|
195
|
+
tableRef.current = node;
|
|
196
|
+
if (typeof attributes.ref === 'function') {
|
|
197
|
+
attributes.ref(node);
|
|
198
|
+
}
|
|
199
|
+
else if (attributes.ref) {
|
|
200
|
+
attributes.ref.current = node;
|
|
201
|
+
}
|
|
202
|
+
}, className: "qdr-table__main", style: {
|
|
203
|
+
minWidth: tableMinWidth,
|
|
204
|
+
} }),
|
|
205
|
+
React.createElement("colgroup", null, columnWidths.map((width, index) => (React.createElement("col", { key: index, style: {
|
|
206
|
+
width: columnWidthToCSS(width),
|
|
207
|
+
minWidth: columnWidthToCSS(width),
|
|
208
|
+
} })))),
|
|
209
|
+
children))),
|
|
210
|
+
React.createElement("div", { className: "qdr-table__size-indicators" }, firstRowCells === null || firstRowCells === void 0 ? void 0 : firstRowCells.map((cell, colIndex) => (React.createElement("div", { key: colIndex, className: "qdr-table__size-indicator", style: {
|
|
211
|
+
width: columnWidthToCSS(columnWidths[colIndex]),
|
|
212
|
+
minWidth: columnWidthToCSS(columnWidths[colIndex]),
|
|
213
|
+
transform: cell.pinned ? 'none' : `translateX(-${scrollLeft}px)`,
|
|
214
|
+
zIndex: cell.pinned ? 2 : 1,
|
|
215
|
+
} },
|
|
216
|
+
React.createElement("div", { className: "qdr-table__size" }, columnWidthToCSS(columnWidths[colIndex])))))),
|
|
217
|
+
isReachMaximumColumns ? null : (React.createElement("button", { type: "button", onClick: () => addColumn(), title: "Add Column", className: "qdr-table__add-column" },
|
|
218
|
+
React.createElement(Icon, { icon: Plus, width: 20, height: 20, className: "qdr-table__btn-icon" }))),
|
|
219
|
+
isReachMaximumRows ? null : (React.createElement("button", { type: "button", onClick: () => addRow(), title: "Add Row", className: "qdr-table__add-row" },
|
|
220
|
+
React.createElement(Icon, { icon: Plus, width: 20, height: 20, className: "qdr-table__btn-icon" }))),
|
|
221
|
+
isReachMaximumColumns || isReachMaximumRows ? null : (React.createElement("button", { type: "button", onClick: addColumnAndRow, title: "Add Column and Row", className: "qdr-table__add-both" },
|
|
222
|
+
React.createElement(Icon, { icon: Plus, width: 20, height: 20, className: "qdr-table__btn-icon" })))));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { TableMain as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Editor, Path } from '@quadrats/core';
|
|
3
|
+
import { useComposition, useQuadrats, ReactEditor } from '@quadrats/react';
|
|
4
|
+
|
|
5
|
+
function TableTitle(props) {
|
|
6
|
+
const { compositionPath } = useComposition();
|
|
7
|
+
const { attributes, children, element } = props;
|
|
8
|
+
const editor = useQuadrats();
|
|
9
|
+
const path = ReactEditor.findPath(editor, element);
|
|
10
|
+
const text = Editor.string(editor, path);
|
|
11
|
+
const isEmpty = !text;
|
|
12
|
+
const composing = useMemo(() => Path.equals(compositionPath, path), [compositionPath, path]);
|
|
13
|
+
return (React.createElement("h3", Object.assign({}, attributes, { className: "qdr-table__title" }),
|
|
14
|
+
children,
|
|
15
|
+
isEmpty && !composing && (React.createElement("span", { className: "qdr-table__title__placeholder", contentEditable: false }, "\u8ACB\u8F38\u5165\u8868\u683C\u6A19\u984C"))));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { TableTitle as default };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TableContextType } from '../typings';
|
|
2
|
+
export type TableActionsContextType = Pick<TableContextType, 'addColumn' | 'addRow' | 'addColumnAndRow' | 'deleteRow' | 'deleteColumn' | 'moveRowToBody' | 'moveRowToHeader' | 'unsetColumnAsTitle' | 'setColumnAsTitle' | 'pinColumn' | 'unpinColumn' | 'pinRow' | 'unpinRow'>;
|
|
3
|
+
export declare const TableActionsContext: import("react").Context<TableActionsContextType | undefined>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TableContextType } from '../typings';
|
|
2
|
+
export type TableMetadataContextType = Pick<TableContextType, 'tableElement' | 'columnCount' | 'rowCount' | 'portalContainerRef' | 'isReachMaximumColumns' | 'isReachMaximumRows' | 'isReachMinimumNormalColumns' | 'isReachMinimumBodyRows' | 'pinnedColumns' | 'pinnedRows' | 'cellPositions' | 'isColumnPinned' | 'isRowPinned'>;
|
|
3
|
+
export declare const TableMetadataContext: import("react").Context<TableMetadataContextType | undefined>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TableContextType } from '../typings';
|
|
2
|
+
export type TableStateContextType = Pick<TableContextType, 'tableSelectedOn' | 'setTableSelectedOn' | 'tableHoveredOn' | 'setTableHoveredOn'>;
|
|
3
|
+
export declare const TableStateContext: import("react").Context<TableStateContextType | undefined>;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { createTable } from '@quadrats/common/table';
|
|
2
|
+
import { createRenderElements } from '@quadrats/react';
|
|
3
|
+
import { Editor, Element, Transforms, PARAGRAPH_TYPE, Text } from '@quadrats/core';
|
|
4
|
+
import { defaultRenderTableElements } from './defaultRenderTableElements.js';
|
|
5
|
+
|
|
6
|
+
function createReactTable(options = {}) {
|
|
7
|
+
const core = createTable(options);
|
|
8
|
+
const { types } = core;
|
|
9
|
+
return Object.assign(Object.assign({}, core), { createHandlers: () => ({
|
|
10
|
+
onKeyDown(event, editor, next) {
|
|
11
|
+
if (event.nativeEvent.isComposing) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (core.isSelectionInTableCell(editor)) {
|
|
15
|
+
const checkCurrentCellHasContent = () => {
|
|
16
|
+
if (!editor.selection)
|
|
17
|
+
return false;
|
|
18
|
+
const [cellNode] = Editor.node(editor, editor.selection);
|
|
19
|
+
if (Text.isText(cellNode)) {
|
|
20
|
+
return cellNode.text.trim() !== '';
|
|
21
|
+
}
|
|
22
|
+
if (!Element.isElement(cellNode))
|
|
23
|
+
return false;
|
|
24
|
+
const hasContent = cellNode.children.some((child) => {
|
|
25
|
+
if (Text.isText(child)) {
|
|
26
|
+
return child.text.trim() !== '';
|
|
27
|
+
}
|
|
28
|
+
return Element.isElement(child);
|
|
29
|
+
});
|
|
30
|
+
return hasContent;
|
|
31
|
+
};
|
|
32
|
+
if (event.key === 'Enter') {
|
|
33
|
+
if (core.isSelectionInTableList(editor)) {
|
|
34
|
+
return next();
|
|
35
|
+
}
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
const currentCellHasContent = checkCurrentCellHasContent();
|
|
38
|
+
if (currentCellHasContent) {
|
|
39
|
+
// Insert soft break
|
|
40
|
+
Editor.insertText(editor, '\n');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Move to next cell
|
|
44
|
+
core.moveToNextCell(editor, types);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (event.key === 'Tab') {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
// shift+tab
|
|
51
|
+
if (event.shiftKey)
|
|
52
|
+
return;
|
|
53
|
+
core.moveToNextCell(editor, types);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// 處理方向鍵上下移動
|
|
57
|
+
if (event.key === 'ArrowUp') {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
if (event.shiftKey) {
|
|
60
|
+
// Shift + 上:擴展選取範圍
|
|
61
|
+
core.extendSelectionUp(editor, types);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// 只按上:移動到上一行
|
|
65
|
+
core.moveToRowAbove(editor, types);
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (event.key === 'ArrowDown') {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
if (event.shiftKey) {
|
|
72
|
+
// Shift + 下:擴展選取範圍
|
|
73
|
+
core.extendSelectionDown(editor, types);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// 只按下:移動到下一行
|
|
77
|
+
core.moveToRowBelow(editor, types);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (event.key === 'ArrowLeft') {
|
|
82
|
+
// Shift + 左:擴展選取範圍
|
|
83
|
+
if (event.shiftKey) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
core.extendSelectionLeft(editor, types);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (event.key === 'ArrowRight') {
|
|
90
|
+
// Shift + 右:擴展選取範圍
|
|
91
|
+
if (event.shiftKey) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
core.extendSelectionRight(editor, types);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
next();
|
|
99
|
+
},
|
|
100
|
+
}), createRenderElement: (options = {}) => {
|
|
101
|
+
const renderTable = options.table || defaultRenderTableElements.table;
|
|
102
|
+
const renderTableTitle = options.table_title || defaultRenderTableElements.table_title;
|
|
103
|
+
const renderTableMain = options.table_main || defaultRenderTableElements.table_main;
|
|
104
|
+
const renderTableHeader = options.table_header || defaultRenderTableElements.table_header;
|
|
105
|
+
const renderTableBody = options.table_body || defaultRenderTableElements.table_body;
|
|
106
|
+
const renderTableRow = options.table_row || defaultRenderTableElements.table_row;
|
|
107
|
+
const renderTableCell = options.table_cell || defaultRenderTableElements.table_cell;
|
|
108
|
+
return createRenderElements([
|
|
109
|
+
{
|
|
110
|
+
type: types.table,
|
|
111
|
+
render: (props) => {
|
|
112
|
+
const { attributes, children, element } = props;
|
|
113
|
+
return renderTable({
|
|
114
|
+
attributes,
|
|
115
|
+
element,
|
|
116
|
+
children,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: types.table_title,
|
|
122
|
+
render: (props) => {
|
|
123
|
+
const { attributes, children, element } = props;
|
|
124
|
+
return renderTableTitle({
|
|
125
|
+
attributes,
|
|
126
|
+
element,
|
|
127
|
+
children,
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: types.table_main,
|
|
133
|
+
render: (props) => {
|
|
134
|
+
const { attributes, children, element } = props;
|
|
135
|
+
return renderTableMain({
|
|
136
|
+
attributes,
|
|
137
|
+
element,
|
|
138
|
+
children,
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: types.table_header,
|
|
144
|
+
render: (props) => {
|
|
145
|
+
const { attributes, children, element } = props;
|
|
146
|
+
return renderTableHeader({
|
|
147
|
+
attributes,
|
|
148
|
+
element,
|
|
149
|
+
children,
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: types.table_body,
|
|
155
|
+
render: (props) => {
|
|
156
|
+
const { attributes, children, element } = props;
|
|
157
|
+
return renderTableBody({
|
|
158
|
+
attributes,
|
|
159
|
+
element,
|
|
160
|
+
children,
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: types.table_row,
|
|
166
|
+
render: (props) => {
|
|
167
|
+
const { attributes, children, element } = props;
|
|
168
|
+
return renderTableRow({
|
|
169
|
+
attributes,
|
|
170
|
+
element,
|
|
171
|
+
children,
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
type: types.table_cell,
|
|
177
|
+
render: (props) => {
|
|
178
|
+
const { attributes, children, element } = props;
|
|
179
|
+
return renderTableCell({
|
|
180
|
+
attributes,
|
|
181
|
+
element,
|
|
182
|
+
children,
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
}, with(editor) {
|
|
188
|
+
const { insertData } = editor;
|
|
189
|
+
/** 從他處複製文字貼過來時觸發 */
|
|
190
|
+
editor.insertData = (data) => {
|
|
191
|
+
const { selection } = editor;
|
|
192
|
+
if (!selection) {
|
|
193
|
+
insertData(data);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// 先檢查選取的起點是否在 table cell 中
|
|
197
|
+
const cellEntry = Editor.above(editor, {
|
|
198
|
+
at: selection.anchor,
|
|
199
|
+
match: (n) => Element.isElement(n) && n.type === types.table_cell,
|
|
200
|
+
});
|
|
201
|
+
if (cellEntry) {
|
|
202
|
+
// 確認在 table 內,將選取範圍縮減到起點
|
|
203
|
+
Transforms.collapse(editor, { edge: 'start' });
|
|
204
|
+
// 重新取得 cell entry(使用當前游標位置)
|
|
205
|
+
const targetCellEntry = Editor.above(editor, {
|
|
206
|
+
match: (n) => Element.isElement(n) && n.type === types.table_cell,
|
|
207
|
+
});
|
|
208
|
+
if (!targetCellEntry) {
|
|
209
|
+
insertData(data);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const [, cellPath] = targetCellEntry;
|
|
213
|
+
// 從剪貼簿取得純文字
|
|
214
|
+
const text = data.getData('text/plain');
|
|
215
|
+
if (text) {
|
|
216
|
+
// 檢測是否為表格格式(包含 Tab 或換行)
|
|
217
|
+
const hasTableFormat = text.includes('\t') || text.includes('\n');
|
|
218
|
+
if (hasTableFormat) {
|
|
219
|
+
// 解析表格格式:行由 \n 分隔,欄位由 \t 分隔
|
|
220
|
+
const rows = text.split('\n').filter((row) => row.length > 0);
|
|
221
|
+
if (rows.length === 0) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
// 找到當前 cell 所在的 row 和 column index
|
|
225
|
+
const rowEntry = Editor.above(editor, {
|
|
226
|
+
at: cellPath,
|
|
227
|
+
match: (n) => Element.isElement(n) && n.type === types.table_row,
|
|
228
|
+
});
|
|
229
|
+
if (!rowEntry) {
|
|
230
|
+
// 如果找不到 row,降級為純文字插入
|
|
231
|
+
Transforms.insertText(editor, text.replace(/\t/g, ' '));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const [, rowPath] = rowEntry;
|
|
235
|
+
const currentColumnIndex = cellPath[cellPath.length - 1];
|
|
236
|
+
// 找到 table body 或 header
|
|
237
|
+
const containerEntry = Editor.above(editor, {
|
|
238
|
+
at: rowPath,
|
|
239
|
+
match: (n) => Element.isElement(n) &&
|
|
240
|
+
(n.type === types.table_body || n.type === types.table_header),
|
|
241
|
+
});
|
|
242
|
+
if (!containerEntry) {
|
|
243
|
+
// 降級為純文字插入
|
|
244
|
+
Transforms.insertText(editor, text.replace(/\t/g, ' '));
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const [container, containerPath] = containerEntry;
|
|
248
|
+
const currentRowIndex = rowPath[rowPath.length - 1];
|
|
249
|
+
// 使用 Editor.withoutNormalizing 批次處理
|
|
250
|
+
Editor.withoutNormalizing(editor, () => {
|
|
251
|
+
rows.forEach((rowText, rowOffset) => {
|
|
252
|
+
const columns = rowText.split('\t');
|
|
253
|
+
const targetRowIndex = currentRowIndex + rowOffset;
|
|
254
|
+
// 檢查目標 row 是否存在
|
|
255
|
+
if (targetRowIndex >= container.children.length) {
|
|
256
|
+
return; // 超出範圍,跳過此行
|
|
257
|
+
}
|
|
258
|
+
const targetRow = container.children[targetRowIndex];
|
|
259
|
+
if (!Element.isElement(targetRow) || targetRow.type !== types.table_row) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// 貼上到各個 cell
|
|
263
|
+
columns.forEach((columnText, columnOffset) => {
|
|
264
|
+
const targetColumnIndex = currentColumnIndex + columnOffset;
|
|
265
|
+
// 檢查目標 cell 是否存在
|
|
266
|
+
if (targetColumnIndex >= targetRow.children.length) {
|
|
267
|
+
return; // 超出範圍,跳過此欄
|
|
268
|
+
}
|
|
269
|
+
const targetCellPath = [...containerPath, targetRowIndex, targetColumnIndex];
|
|
270
|
+
// 清空目標 cell 的內容
|
|
271
|
+
const targetCell = targetRow.children[targetColumnIndex];
|
|
272
|
+
if (Element.isElement(targetCell) && targetCell.type === types.table_cell) {
|
|
273
|
+
// 移除所有子節點
|
|
274
|
+
for (let i = targetCell.children.length - 1; i >= 0; i--) {
|
|
275
|
+
Transforms.removeNodes(editor, { at: [...targetCellPath, i] });
|
|
276
|
+
}
|
|
277
|
+
// 插入新內容
|
|
278
|
+
Transforms.insertNodes(editor, {
|
|
279
|
+
type: PARAGRAPH_TYPE,
|
|
280
|
+
children: [{ text: columnText }],
|
|
281
|
+
}, { at: [...targetCellPath, 0] });
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// 預設行為
|
|
291
|
+
insertData(data);
|
|
292
|
+
};
|
|
293
|
+
return core.with(editor);
|
|
294
|
+
} });
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { createReactTable };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Table from './components/Table.js';
|
|
3
|
+
import TableTitle from './components/TableTitle.js';
|
|
4
|
+
import TableMain from './components/TableMain.js';
|
|
5
|
+
import TableHeader from './components/TableHeader.js';
|
|
6
|
+
import TableRow from './components/TableRow.js';
|
|
7
|
+
import TableCell from './components/TableCell.js';
|
|
8
|
+
import TableBody from './components/TableBody.js';
|
|
9
|
+
|
|
10
|
+
const defaultRenderTableElements = {
|
|
11
|
+
table: (props) => React.createElement(Table, Object.assign({}, props)),
|
|
12
|
+
table_title: (props) => React.createElement(TableTitle, Object.assign({}, props)),
|
|
13
|
+
table_main: (props) => React.createElement(TableMain, Object.assign({}, props)),
|
|
14
|
+
table_header: (props) => React.createElement(TableHeader, Object.assign({}, props)),
|
|
15
|
+
table_body: (props) => React.createElement(TableBody, Object.assign({}, props)),
|
|
16
|
+
table_row: (props) => React.createElement(TableRow, Object.assign({}, props)),
|
|
17
|
+
table_cell: (props) => React.createElement(TableCell, Object.assign({}, props)),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { defaultRenderTableElements };
|