@ant-design/agentic-ui 2.7.1 → 2.9.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/dist/AgentRunBar/Robot.js +105 -57
- package/dist/AgentRunBar/icons/PauseIcon.js +38 -38
- package/dist/AgentRunBar/icons/PlayIcon.js +38 -38
- package/dist/AgentRunBar/icons/SimplePauseIcon.js +38 -38
- package/dist/AgentRunBar/icons/SimplePlayIcon.js +38 -38
- package/dist/AgentRunBar/icons/SimpleStopIcon.js +38 -38
- package/dist/AgentRunBar/icons/StopIcon.js +41 -50
- package/dist/AgentRunBar/icons/index.js +0 -1
- package/dist/AgentRunBar/index.js +270 -237
- package/dist/AgentRunBar/style.js +273 -239
- package/dist/AgenticLayout/index.js +140 -85
- package/dist/AgenticLayout/style.js +126 -107
- package/dist/AnswerAlert/components/CloseIcon.js +12 -21
- package/dist/AnswerAlert/components/ErrorIcon.js +42 -38
- package/dist/AnswerAlert/components/InfoIcon.js +42 -38
- package/dist/AnswerAlert/components/LoaderIcon.js +12 -21
- package/dist/AnswerAlert/components/SuccessIcon.js +42 -38
- package/dist/AnswerAlert/components/WarningIcon.js +42 -38
- package/dist/AnswerAlert/index.js +155 -75
- package/dist/AnswerAlert/style.js +159 -147
- package/dist/BackTo/BackBottom.js +154 -70
- package/dist/BackTo/BackTop.js +148 -68
- package/dist/BackTo/ScrollVisibleButton.js +124 -98
- package/dist/BackTo/hooks/useScrollVisible.js +79 -33
- package/dist/BackTo/icons/BottomIcon.js +37 -37
- package/dist/BackTo/icons/TopIcon.js +37 -37
- package/dist/BackTo/index.js +22 -7
- package/dist/BackTo/style.js +93 -70
- package/dist/Bubble/AIBubble.js +469 -406
- package/dist/Bubble/Avatar/index.js +139 -85
- package/dist/Bubble/Avatar/isEmoji.js +2 -6
- package/dist/Bubble/Bubble.js +114 -38
- package/dist/Bubble/BubbleBeforeNode.js +104 -74
- package/dist/Bubble/BubbleConfigProvide.js +3 -7
- package/dist/Bubble/FileView.js +63 -69
- package/dist/Bubble/List/PureBubbleList.js +130 -131
- package/dist/Bubble/List/SkeletonList.js +33 -24
- package/dist/Bubble/List/index.js +187 -124
- package/dist/Bubble/List/style.js +76 -47
- package/dist/Bubble/MessagesContent/BubbleContext.js +6 -12
- package/dist/Bubble/MessagesContent/BubbleExtra.js +663 -355
- package/dist/Bubble/MessagesContent/CopyButton/index.js +326 -96
- package/dist/Bubble/MessagesContent/DocInfo.js +351 -386
- package/dist/Bubble/MessagesContent/EXCEPTION.js +42 -22
- package/dist/Bubble/MessagesContent/MarkdownPreview.js +206 -156
- package/dist/Bubble/MessagesContent/VoiceButton/index.js +213 -115
- package/dist/Bubble/MessagesContent/VoiceButton/style.js +129 -105
- package/dist/Bubble/MessagesContent/VoiceButton/types.js +9 -0
- package/dist/Bubble/MessagesContent/docInfoStyle.js +118 -88
- package/dist/Bubble/MessagesContent/icons.js +157 -57
- package/dist/Bubble/MessagesContent/index.js +609 -368
- package/dist/Bubble/PureBubble.js +439 -326
- package/dist/Bubble/Title.js +110 -87
- package/dist/Bubble/UserBubble.js +218 -279
- package/dist/Bubble/index.js +10 -16
- package/dist/Bubble/style.js +248 -227
- package/dist/Bubble/type.js +3 -0
- package/dist/Bubble/types/BubbleExtra.js +1 -0
- package/dist/Bubble/types/DocInfo.js +1 -0
- package/dist/ChatBootPage/ButtonTab.js +25 -45
- package/dist/ChatBootPage/ButtonTabGroup.js +74 -47
- package/dist/ChatBootPage/ButtonTabGroupStyle.js +73 -45
- package/dist/ChatBootPage/ButtonTabStyle.js +121 -98
- package/dist/ChatBootPage/CaseReply.js +119 -113
- package/dist/ChatBootPage/CaseReplyStyle.js +217 -189
- package/dist/ChatBootPage/Title.js +19 -23
- package/dist/ChatBootPage/index.js +9 -11
- package/dist/ChatBootPage/style.js +80 -50
- package/dist/ChatLayout/index.js +93 -57
- package/dist/ChatLayout/style.js +206 -176
- package/dist/ChatLayout/types.js +1 -0
- package/dist/Components/ActionIconBox/index.js +571 -197
- package/dist/Components/ActionIconBox/style.js +141 -111
- package/dist/Components/ActionItemBox/ActionItemBox.js +95 -149
- package/dist/Components/ActionItemBox/index.js +7 -7
- package/dist/Components/ActionItemBox/style.js +353 -361
- package/dist/Components/Button/IconButton/index.js +35 -43
- package/dist/Components/Button/IconButton/style.js +357 -331
- package/dist/Components/Button/SwitchButton/index.js +243 -87
- package/dist/Components/Button/SwitchButton/style.js +160 -146
- package/dist/Components/Button/ToggleButton/index.js +46 -57
- package/dist/Components/Button/ToggleButton/style.js +283 -258
- package/dist/Components/Button/index.js +6 -2
- package/dist/Components/GradientText/index.js +21 -27
- package/dist/Components/GradientText/style.js +88 -63
- package/dist/Components/ImageList.js +111 -133
- package/dist/Components/LayoutHeader/index.js +145 -81
- package/dist/Components/LayoutHeader/style.js +89 -64
- package/dist/Components/LayoutHeader/types.js +3 -0
- package/dist/Components/Loading/index.js +53 -22
- package/dist/Components/Robot/index.js +90 -56
- package/dist/Components/Robot/lotties/DazingLottie/index.js +78 -47
- package/dist/Components/Robot/lotties/ThinkingLottie/index.js +78 -47
- package/dist/Components/Robot/lotties/index.js +0 -1
- package/dist/Components/SuggestionList/index.js +354 -182
- package/dist/Components/SuggestionList/style.js +204 -186
- package/dist/Components/TextAnimate/index.js +494 -362
- package/dist/Components/TextAnimate/style.js +72 -48
- package/dist/Components/TypingAnimation/index.js +214 -169
- package/dist/Components/TypingAnimation/style.js +76 -52
- package/dist/Components/VisualList/index.js +267 -180
- package/dist/Components/VisualList/style.js +140 -124
- package/dist/Components/icons/LoadingSpinnerIcon.js +124 -73
- package/dist/Components/lotties/DazingLottie/index.js +78 -47
- package/dist/Components/lotties/LoadingLottie/index.js +82 -48
- package/dist/Components/lotties/TextLoading/index.js +73 -49
- package/dist/Components/lotties/TextLoading/style.js +95 -78
- package/dist/Components/lotties/ThinkingLottie/index.js +78 -47
- package/dist/Components/lotties/index.js +0 -1
- package/dist/Constants/colors.js +71 -97
- package/dist/History/components/HistoryActionsBox.js +407 -180
- package/dist/History/components/HistoryEmpty.js +38 -42
- package/dist/History/components/HistoryEmptyIcon.js +682 -964
- package/dist/History/components/HistoryItem.js +683 -471
- package/dist/History/components/HistoryList.js +170 -87
- package/dist/History/components/HistoryRunningIcon.js +160 -111
- package/dist/History/components/LoadMoreComponent.js +308 -103
- package/dist/History/components/NewChatComponent.js +261 -69
- package/dist/History/components/NewChatComponent.style.js +79 -53
- package/dist/History/components/SearchComponent.js +367 -156
- package/dist/History/components/index.js +11 -23
- package/dist/History/hooks/useHistory.js +404 -129
- package/dist/History/index.js +301 -186
- package/dist/History/menu.js +158 -212
- package/dist/History/style.js +282 -268
- package/dist/History/types/HistoryData.js +6 -10
- package/dist/History/types/HistoryList.js +3 -0
- package/dist/History/types/index.js +3 -0
- package/dist/History/utils/index.js +35 -32
- package/dist/Hooks/useAutoScroll.js +262 -84
- package/dist/Hooks/useClickAway.js +60 -21
- package/dist/Hooks/useCopied.js +72 -20
- package/dist/Hooks/useDebounceFn/index.js +213 -55
- package/dist/Hooks/useIntersectionOnce.js +163 -74
- package/dist/Hooks/useLanguage.js +67 -26
- package/dist/Hooks/useRefFunction/index.js +76 -11
- package/dist/Hooks/useSpeechSynthesis.js +143 -99
- package/dist/Hooks/useStyle/index.js +95 -60
- package/dist/Hooks/useThrottleFn/index.js +41 -41
- package/dist/I18n/index.js +246 -109
- package/dist/I18n/locales.js +718 -711
- package/dist/Icons/animated/VoicePlayLottie/index.js +75 -46
- package/dist/Icons/animated/VoicingLottie/index.js +78 -47
- package/dist/MarkdownEditor/BaseMarkdownEditor.js +421 -349
- package/dist/MarkdownEditor/editor/Editor.js +1160 -843
- package/dist/MarkdownEditor/editor/components/CommentList/index.js +407 -239
- package/dist/MarkdownEditor/editor/components/CommentList/style.js +119 -89
- package/dist/MarkdownEditor/editor/components/ContributorAvatar/index.js +61 -63
- package/dist/MarkdownEditor/editor/components/ContributorAvatar/style.js +82 -52
- package/dist/MarkdownEditor/editor/components/LazyElement/index.js +208 -106
- package/dist/MarkdownEditor/editor/components/LazyElement/style.js +69 -42
- package/dist/MarkdownEditor/editor/components/fntTag/index.js +7 -11
- package/dist/MarkdownEditor/editor/components/fntTag/style.js +66 -36
- package/dist/MarkdownEditor/editor/components/index.js +0 -1
- package/dist/MarkdownEditor/editor/elements/Blockquote.js +95 -37
- package/dist/MarkdownEditor/editor/elements/Break.js +56 -25
- package/dist/MarkdownEditor/editor/elements/Card/index.js +131 -52
- package/dist/MarkdownEditor/editor/elements/Code.js +89 -67
- package/dist/MarkdownEditor/editor/elements/Comment/index.js +79 -50
- package/dist/MarkdownEditor/editor/elements/ErrorBoundary.js +117 -21
- package/dist/MarkdownEditor/editor/elements/FootnoteDefinition.js +83 -64
- package/dist/MarkdownEditor/editor/elements/FootnoteReference.js +115 -41
- package/dist/MarkdownEditor/editor/elements/Head.js +131 -67
- package/dist/MarkdownEditor/editor/elements/Hr.js +63 -38
- package/dist/MarkdownEditor/editor/elements/Image/index.js +636 -494
- package/dist/MarkdownEditor/editor/elements/InlineKatex.js +60 -44
- package/dist/MarkdownEditor/editor/elements/Katex.js +71 -55
- package/dist/MarkdownEditor/editor/elements/LinkCard/index.js +79 -175
- package/dist/MarkdownEditor/editor/elements/LinkCard/style.js +130 -100
- package/dist/MarkdownEditor/editor/elements/List/List.js +96 -69
- package/dist/MarkdownEditor/editor/elements/List/ListItem.js +422 -247
- package/dist/MarkdownEditor/editor/elements/List/index.js +1 -5
- package/dist/MarkdownEditor/editor/elements/List/style.js +131 -117
- package/dist/MarkdownEditor/editor/elements/Media.js +637 -519
- package/dist/MarkdownEditor/editor/elements/Mermaid.js +79 -54
- package/dist/MarkdownEditor/editor/elements/Paragraph.js +144 -83
- package/dist/MarkdownEditor/editor/elements/Schema.js +167 -128
- package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +211 -178
- package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +73 -49
- package/dist/MarkdownEditor/editor/elements/Table/Table.js +285 -204
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/index.js +397 -280
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/style.js +126 -101
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/index.js +381 -276
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/style.js +120 -98
- package/dist/MarkdownEditor/editor/elements/Table/TableContext.js +64 -21
- package/dist/MarkdownEditor/editor/elements/Table/TableRowIndex/index.js +52 -42
- package/dist/MarkdownEditor/editor/elements/Table/TableRowIndex/style.js +69 -39
- package/dist/MarkdownEditor/editor/elements/Table/Td/index.js +126 -72
- package/dist/MarkdownEditor/editor/elements/Table/Td/style.js +85 -55
- package/dist/MarkdownEditor/editor/elements/Table/index.js +204 -105
- package/dist/MarkdownEditor/editor/elements/Table/style.js +244 -233
- package/dist/MarkdownEditor/editor/elements/Table/useScrollShadow.js +119 -62
- package/dist/MarkdownEditor/editor/elements/TagPopup/index.js +438 -276
- package/dist/MarkdownEditor/editor/elements/TagPopup/style.js +103 -77
- package/dist/MarkdownEditor/editor/elements/index.js +437 -424
- package/dist/MarkdownEditor/editor/parser/json-parse.js +38 -9
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +1753 -1168
- package/dist/MarkdownEditor/editor/parser/parserMdToSchema.js +16 -20
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +1021 -606
- package/dist/MarkdownEditor/editor/parser/remarkParse.js +158 -102
- package/dist/MarkdownEditor/editor/plugins/catchError.js +78 -17
- package/dist/MarkdownEditor/editor/plugins/elements.js +458 -342
- package/dist/MarkdownEditor/editor/plugins/handlePaste.js +752 -300
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/arrow.js +215 -129
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/backspace.js +325 -180
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/enter.js +576 -418
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/match.js +157 -47
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/tab.js +331 -209
- package/dist/MarkdownEditor/editor/plugins/index.js +0 -1
- package/dist/MarkdownEditor/editor/plugins/insertParsedHtmlNodes.js +1245 -507
- package/dist/MarkdownEditor/editor/plugins/parseMarkdownToNodesAndInsert.js +36 -24
- package/dist/MarkdownEditor/editor/plugins/useHighlight.js +267 -116
- package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +234 -160
- package/dist/MarkdownEditor/editor/plugins/useOnchange.js +253 -92
- package/dist/MarkdownEditor/editor/plugins/withMarkdown.js +728 -439
- package/dist/MarkdownEditor/editor/store.js +1819 -1389
- package/dist/MarkdownEditor/editor/style.js +551 -506
- package/dist/MarkdownEditor/editor/tagStyles.js +43 -43
- package/dist/MarkdownEditor/editor/tools/DragHandle.js +56 -54
- package/dist/MarkdownEditor/editor/tools/InsertAutocomplete.js +1049 -732
- package/dist/MarkdownEditor/editor/tools/InsertLink.js +232 -181
- package/dist/MarkdownEditor/editor/tools/Leading.js +566 -303
- package/dist/MarkdownEditor/editor/tools/ToolBar/BaseBar.js +415 -377
- package/dist/MarkdownEditor/editor/tools/ToolBar/FloatBar.js +162 -125
- package/dist/MarkdownEditor/editor/tools/ToolBar/ReadonlyBaseBar.js +480 -258
- package/dist/MarkdownEditor/editor/tools/ToolBar/ToolBar.js +44 -44
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/ClearFormatButton.js +20 -35
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/ColorPickerButton.js +69 -73
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/FormatButton.js +13 -19
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/FormattingTools.js +34 -41
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/HeadingDropdown.js +53 -47
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/LinkButton.js +11 -19
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/ToolBarItem.js +23 -43
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/UndoRedoButtons.js +14 -25
- package/dist/MarkdownEditor/editor/tools/ToolBar/config/toolsConfig.js +139 -102
- package/dist/MarkdownEditor/editor/tools/ToolBar/floatBarStyle.js +95 -65
- package/dist/MarkdownEditor/editor/tools/ToolBar/hooks/useToolBarLogic.js +252 -161
- package/dist/MarkdownEditor/editor/tools/ToolBar/index.js +14 -24
- package/dist/MarkdownEditor/editor/tools/ToolBar/toolBarStyle.js +95 -65
- package/dist/MarkdownEditor/editor/tools/insertAutocompleteStyle.js +82 -52
- package/dist/MarkdownEditor/editor/types/Table.js +1 -0
- package/dist/MarkdownEditor/editor/utils/InlineChromiumBugfix.js +11 -16
- package/dist/MarkdownEditor/editor/utils/ace.js +136 -40
- package/dist/MarkdownEditor/editor/utils/docx/docxDeserializer.js +29 -32
- package/dist/MarkdownEditor/editor/utils/docx/index.js +0 -1
- package/dist/MarkdownEditor/editor/utils/docx/module.js +193 -164
- package/dist/MarkdownEditor/editor/utils/docx/utils.js +113 -98
- package/dist/MarkdownEditor/editor/utils/dom.js +119 -90
- package/dist/MarkdownEditor/editor/utils/editorUtils.js +1369 -906
- package/dist/MarkdownEditor/editor/utils/htmlToMarkdown.js +196 -184
- package/dist/MarkdownEditor/editor/utils/index.js +354 -215
- package/dist/MarkdownEditor/editor/utils/isMarkdown.js +56 -44
- package/dist/MarkdownEditor/editor/utils/keyboard.js +1229 -664
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +294 -76
- package/dist/MarkdownEditor/editor/utils/media.js +274 -99
- package/dist/MarkdownEditor/editor/utils/path.js +22 -16
- package/dist/MarkdownEditor/editor/utils/performanceMonitor.js +370 -168
- package/dist/MarkdownEditor/editor/utils/useLocalState.js +96 -37
- package/dist/MarkdownEditor/el.js +1 -0
- package/dist/MarkdownEditor/hooks/editor.js +123 -41
- package/dist/MarkdownEditor/hooks/subscribe.js +18 -15
- package/dist/MarkdownEditor/index.js +118 -30
- package/dist/MarkdownEditor/plugin.js +2 -5
- package/dist/MarkdownEditor/style.js +96 -66
- package/dist/MarkdownEditor/types.js +1 -0
- package/dist/MarkdownEditor/utils/exportHtml.js +42 -83
- package/dist/MarkdownEditor/utils/native-table/index.js +0 -1
- package/dist/MarkdownEditor/utils/native-table/native-table-editor.js +337 -222
- package/dist/MarkdownEditor/utils/native-table/native-table-keyboard.js +201 -113
- package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.js +86 -79
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +62 -33
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.js +147 -125
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/index.js +174 -129
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/style.js +263 -237
- package/dist/MarkdownInputField/AttachmentButton/index.js +465 -205
- package/dist/MarkdownInputField/AttachmentButton/style.js +143 -114
- package/dist/MarkdownInputField/AttachmentButton/types.js +3 -0
- package/dist/MarkdownInputField/AttachmentButton/utils.js +64 -34
- package/dist/MarkdownInputField/BeforeToolContainer/BeforeToolContainer.js +438 -404
- package/dist/MarkdownInputField/Enlargement/index.js +7 -17
- package/dist/MarkdownInputField/FileMapView/FileMapViewItem.js +193 -216
- package/dist/MarkdownInputField/FileMapView/index.js +387 -174
- package/dist/MarkdownInputField/FileMapView/style.js +281 -259
- package/dist/MarkdownInputField/FilePaste/index.js +239 -65
- package/dist/MarkdownInputField/FileUploadManager/index.js +460 -170
- package/dist/MarkdownInputField/MarkdownInputField.js +819 -549
- package/dist/MarkdownInputField/QuickActions/index.js +304 -134
- package/dist/MarkdownInputField/RefinePromptButton/index.js +24 -33
- package/dist/MarkdownInputField/RefinePromptButton/style.js +99 -73
- package/dist/MarkdownInputField/SendActions/index.js +179 -197
- package/dist/MarkdownInputField/SendButton/index.js +150 -110
- package/dist/MarkdownInputField/SendButton/style.js +95 -64
- package/dist/MarkdownInputField/SkillModeBar/hooks/index.js +3 -5
- package/dist/MarkdownInputField/SkillModeBar/hooks/useSkillModeState.js +51 -26
- package/dist/MarkdownInputField/SkillModeBar/index.js +119 -106
- package/dist/MarkdownInputField/SkillModeBar/style.js +124 -98
- package/dist/MarkdownInputField/Suggestion/index.js +391 -154
- package/dist/MarkdownInputField/TopOperatingArea/index.js +37 -44
- package/dist/MarkdownInputField/TopOperatingArea/style.js +98 -81
- package/dist/MarkdownInputField/VoiceInput/index.js +210 -82
- package/dist/MarkdownInputField/VoiceInput/style.js +85 -59
- package/dist/MarkdownInputField/VoiceInputManager/index.js +321 -94
- package/dist/MarkdownInputField/style.js +296 -233
- package/dist/Plugins/chart/AreaChart/index.js +541 -393
- package/dist/Plugins/chart/AreaChart/style.js +114 -90
- package/dist/Plugins/chart/BarChart/index.d.ts +4 -0
- package/dist/Plugins/chart/BarChart/index.js +865 -697
- package/dist/Plugins/chart/BarChart/style.js +114 -90
- package/dist/Plugins/chart/ChartAttrToolBar/ChartAttrToolBarStyle.js +82 -52
- package/dist/Plugins/chart/ChartAttrToolBar/index.js +94 -65
- package/dist/Plugins/chart/ChartMark/Area.js +176 -150
- package/dist/Plugins/chart/ChartMark/Bar.js +181 -152
- package/dist/Plugins/chart/ChartMark/Column.js +181 -151
- package/dist/Plugins/chart/ChartMark/Container.js +116 -75
- package/dist/Plugins/chart/ChartMark/Line.js +179 -151
- package/dist/Plugins/chart/ChartMark/Pie.js +79 -63
- package/dist/Plugins/chart/ChartMark/index.js +6 -13
- package/dist/Plugins/chart/ChartMark/useChart.js +1 -0
- package/dist/Plugins/chart/ChartRender.d.ts +2 -0
- package/dist/Plugins/chart/ChartRender.js +981 -705
- package/dist/Plugins/chart/ChartStatistic/index.js +47 -62
- package/dist/Plugins/chart/ChartStatistic/style.js +142 -143
- package/dist/Plugins/chart/ChartStatistic/utils.js +37 -27
- package/dist/Plugins/chart/DonutChart/Legend.js +94 -124
- package/dist/Plugins/chart/DonutChart/constants.js +4 -11
- package/dist/Plugins/chart/DonutChart/hooks.js +183 -112
- package/dist/Plugins/chart/DonutChart/index.js +588 -516
- package/dist/Plugins/chart/DonutChart/plugins.js +47 -44
- package/dist/Plugins/chart/DonutChart/style.js +186 -175
- package/dist/Plugins/chart/DonutChart/types.js +1 -0
- package/dist/Plugins/chart/FunnelChart/index.js +844 -647
- package/dist/Plugins/chart/FunnelChart/style.js +97 -71
- package/dist/Plugins/chart/LineChart/index.js +516 -393
- package/dist/Plugins/chart/LineChart/style.js +114 -90
- package/dist/Plugins/chart/RadarChart/index.js +580 -582
- package/dist/Plugins/chart/RadarChart/style.js +122 -112
- package/dist/Plugins/chart/ScatterChart/index.js +633 -640
- package/dist/Plugins/chart/ScatterChart/style.js +108 -94
- package/dist/Plugins/chart/components/ChartContainer/ChartContainer.js +151 -80
- package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundary.js +160 -41
- package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundaryExample.js +80 -62
- package/dist/Plugins/chart/components/ChartContainer/index.js +2 -7
- package/dist/Plugins/chart/components/ChartContainer/style.js +121 -91
- package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +58 -90
- package/dist/Plugins/chart/components/ChartFilter/style.js +169 -154
- package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +54 -59
- package/dist/Plugins/chart/components/ChartToolBar/style.js +132 -117
- package/dist/Plugins/chart/components/icons/TimeIcon.js +20 -26
- package/dist/Plugins/chart/components/index.js +32 -34
- package/dist/Plugins/chart/const.js +34 -25
- package/dist/Plugins/chart/hooks/useChartStatistic.js +1 -0
- package/dist/Plugins/chart/index.js +436 -339
- package/dist/Plugins/chart/loadChartRuntime.js +209 -87
- package/dist/Plugins/chart/utils.js +311 -87
- package/dist/Plugins/code/CodeUI/Katex/Katex.js +112 -66
- package/dist/Plugins/code/components/AceEditor.js +334 -237
- package/dist/Plugins/code/components/AceEditorContainer.js +23 -32
- package/dist/Plugins/code/components/CodeContainer.js +41 -56
- package/dist/Plugins/code/components/CodeRenderer.js +202 -155
- package/dist/Plugins/code/components/CodeToolbar.js +137 -181
- package/dist/Plugins/code/components/HtmlPreview.js +19 -22
- package/dist/Plugins/code/components/LanguageSelector.js +162 -96
- package/dist/Plugins/code/components/LoadImage.js +145 -46
- package/dist/Plugins/code/components/ThinkBlock.js +38 -42
- package/dist/Plugins/code/components/index.js +13 -23
- package/dist/Plugins/code/hooks/index.js +7 -9
- package/dist/Plugins/code/hooks/useCodeEditorState.js +139 -62
- package/dist/Plugins/code/hooks/useRenderConditions.js +31 -23
- package/dist/Plugins/code/hooks/useToolbarConfig.js +44 -46
- package/dist/Plugins/code/index.js +141 -89
- package/dist/Plugins/code/langIconMap.js +400 -108
- package/dist/Plugins/code/langIcons/AbapIcon.js +90 -57
- package/dist/Plugins/code/langIcons/ActionscriptIcon.js +89 -56
- package/dist/Plugins/code/langIcons/AdaIcon.js +89 -52
- package/dist/Plugins/code/langIcons/ApacheIcon.js +205 -254
- package/dist/Plugins/code/langIcons/ApexIcon.js +108 -82
- package/dist/Plugins/code/langIcons/AplIcon.js +90 -54
- package/dist/Plugins/code/langIcons/ApplescriptIcon.js +89 -56
- package/dist/Plugins/code/langIcons/AstroIcon.js +91 -58
- package/dist/Plugins/code/langIcons/AwkIcon.js +98 -68
- package/dist/Plugins/code/langIcons/BallerinaIcon.js +92 -59
- package/dist/Plugins/code/langIcons/BatIcon.js +158 -229
- package/dist/Plugins/code/langIcons/BicepIcon.js +91 -58
- package/dist/Plugins/code/langIcons/BladeIcon.js +90 -58
- package/dist/Plugins/code/langIcons/CIcon.js +90 -55
- package/dist/Plugins/code/langIcons/CadenceIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ClojureIcon.js +96 -75
- package/dist/Plugins/code/langIcons/CmakeIcon.js +93 -62
- package/dist/Plugins/code/langIcons/CobolIcon.js +99 -70
- package/dist/Plugins/code/langIcons/CodeqlIcon.js +96 -76
- package/dist/Plugins/code/langIcons/CoffeeIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ConsoleIcon.js +89 -56
- package/dist/Plugins/code/langIcons/CppIcon.js +90 -55
- package/dist/Plugins/code/langIcons/CrystalIcon.js +90 -57
- package/dist/Plugins/code/langIcons/CsharpIcon.js +90 -59
- package/dist/Plugins/code/langIcons/CssIcon.js +89 -52
- package/dist/Plugins/code/langIcons/DIcon.js +90 -53
- package/dist/Plugins/code/langIcons/DartIcon.js +92 -71
- package/dist/Plugins/code/langIcons/DatabaseIcon.js +90 -57
- package/dist/Plugins/code/langIcons/DiffIcon.js +90 -57
- package/dist/Plugins/code/langIcons/DockerIcon.js +89 -56
- package/dist/Plugins/code/langIcons/DotenvIcon.js +94 -56
- package/dist/Plugins/code/langIcons/ElixirIcon.js +91 -58
- package/dist/Plugins/code/langIcons/ElmIcon.js +105 -58
- package/dist/Plugins/code/langIcons/ErbIcon.js +90 -54
- package/dist/Plugins/code/langIcons/ErlangIcon.js +89 -56
- package/dist/Plugins/code/langIcons/FsharpIcon.js +93 -62
- package/dist/Plugins/code/langIcons/GdscriptIcon.js +96 -88
- package/dist/Plugins/code/langIcons/GlslIcon.js +90 -58
- package/dist/Plugins/code/langIcons/GnuplotIcon.js +98 -77
- package/dist/Plugins/code/langIcons/GoIcon.js +114 -93
- package/dist/Plugins/code/langIcons/GraphqlIcon.js +106 -66
- package/dist/Plugins/code/langIcons/GroovyIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HackIcon.js +97 -64
- package/dist/Plugins/code/langIcons/HamlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HandlebarsIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HaskellIcon.js +93 -64
- package/dist/Plugins/code/langIcons/HclIcon.js +118 -93
- package/dist/Plugins/code/langIcons/HclLightIcon.js +118 -97
- package/dist/Plugins/code/langIcons/HjsonIcon.js +94 -62
- package/dist/Plugins/code/langIcons/HlslIcon.js +96 -76
- package/dist/Plugins/code/langIcons/HtmlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HttpIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ImbaIcon.js +98 -65
- package/dist/Plugins/code/langIcons/IniIcon.js +90 -54
- package/dist/Plugins/code/langIcons/JavaIcon.js +89 -56
- package/dist/Plugins/code/langIcons/JavascriptIcon.js +89 -56
- package/dist/Plugins/code/langIcons/JinjaIcon.js +100 -68
- package/dist/Plugins/code/langIcons/Json5Icon.js +100 -82
- package/dist/Plugins/code/langIcons/JsonIcon.js +89 -56
- package/dist/Plugins/code/langIcons/JsonnetIcon.js +102 -86
- package/dist/Plugins/code/langIcons/JuliaIcon.js +105 -52
- package/dist/Plugins/code/langIcons/KotlinIcon.js +104 -74
- package/dist/Plugins/code/langIcons/KustoIcon.js +90 -57
- package/dist/Plugins/code/langIcons/LessIcon.js +90 -57
- package/dist/Plugins/code/langIcons/LiquidIcon.js +91 -58
- package/dist/Plugins/code/langIcons/LispIcon.js +89 -56
- package/dist/Plugins/code/langIcons/LuaIcon.js +93 -60
- package/dist/Plugins/code/langIcons/MakefileIcon.js +91 -58
- package/dist/Plugins/code/langIcons/MarkdownIcon.js +89 -56
- package/dist/Plugins/code/langIcons/MarkojsIcon.js +96 -73
- package/dist/Plugins/code/langIcons/MatlabIcon.js +93 -64
- package/dist/Plugins/code/langIcons/MdxIcon.js +90 -53
- package/dist/Plugins/code/langIcons/MermaidIcon.js +95 -64
- package/dist/Plugins/code/langIcons/MojoIcon.js +95 -62
- package/dist/Plugins/code/langIcons/NginxIcon.js +94 -61
- package/dist/Plugins/code/langIcons/NimIcon.js +91 -54
- package/dist/Plugins/code/langIcons/NixIcon.js +92 -56
- package/dist/Plugins/code/langIcons/ObjectiveCIcon.js +90 -59
- package/dist/Plugins/code/langIcons/ObjectiveCppIcon.js +90 -57
- package/dist/Plugins/code/langIcons/OcamlIcon.js +90 -61
- package/dist/Plugins/code/langIcons/PascalIcon.js +95 -55
- package/dist/Plugins/code/langIcons/Perl6Icon.js +299 -320
- package/dist/Plugins/code/langIcons/PerlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/PhpIcon.js +89 -52
- package/dist/Plugins/code/langIcons/PostcssIcon.js +130 -113
- package/dist/Plugins/code/langIcons/PowershellIcon.js +91 -58
- package/dist/Plugins/code/langIcons/PrismaIcon.js +97 -68
- package/dist/Plugins/code/langIcons/PrologIcon.js +91 -58
- package/dist/Plugins/code/langIcons/ProtoIcon.js +94 -68
- package/dist/Plugins/code/langIcons/PugIcon.js +177 -145
- package/dist/Plugins/code/langIcons/PuppetIcon.js +96 -52
- package/dist/Plugins/code/langIcons/PurescriptIcon.js +93 -61
- package/dist/Plugins/code/langIcons/PythonIcon.js +90 -61
- package/dist/Plugins/code/langIcons/RIcon.js +89 -52
- package/dist/Plugins/code/langIcons/RazorIcon.js +90 -57
- package/dist/Plugins/code/langIcons/ReactIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ReactTsIcon.js +90 -57
- package/dist/Plugins/code/langIcons/RubyIcon.js +91 -58
- package/dist/Plugins/code/langIcons/RustIcon.js +89 -56
- package/dist/Plugins/code/langIcons/SasIcon.js +89 -52
- package/dist/Plugins/code/langIcons/SassIcon.js +90 -57
- package/dist/Plugins/code/langIcons/ScalaIcon.js +96 -53
- package/dist/Plugins/code/langIcons/SchemeIcon.js +91 -58
- package/dist/Plugins/code/langIcons/ShaderlabIcon.js +89 -56
- package/dist/Plugins/code/langIcons/SolidityIcon.js +94 -52
- package/dist/Plugins/code/langIcons/SparqlIcon.js +94 -64
- package/dist/Plugins/code/langIcons/StataIcon.js +126 -108
- package/dist/Plugins/code/langIcons/StylusIcon.js +92 -59
- package/dist/Plugins/code/langIcons/SvelteIcon.js +91 -58
- package/dist/Plugins/code/langIcons/SwiftIcon.js +90 -57
- package/dist/Plugins/code/langIcons/SystemverilogIcon.js +115 -102
- package/dist/Plugins/code/langIcons/TclIcon.js +89 -52
- package/dist/Plugins/code/langIcons/TexIcon.js +99 -65
- package/dist/Plugins/code/langIcons/TomlIcon.js +94 -70
- package/dist/Plugins/code/langIcons/TwigIcon.js +89 -56
- package/dist/Plugins/code/langIcons/TypescriptIcon.js +93 -60
- package/dist/Plugins/code/langIcons/VerilogIcon.js +89 -56
- package/dist/Plugins/code/langIcons/VhdlIcon.js +94 -64
- package/dist/Plugins/code/langIcons/VimIcon.js +278 -420
- package/dist/Plugins/code/langIcons/VueIcon.js +92 -59
- package/dist/Plugins/code/langIcons/WebassemblyIcon.js +103 -76
- package/dist/Plugins/code/langIcons/WenyanIcon.js +104 -100
- package/dist/Plugins/code/langIcons/WgslIcon.js +93 -77
- package/dist/Plugins/code/langIcons/WolframlanguageIcon.js +100 -71
- package/dist/Plugins/code/langIcons/XmlIcon.js +89 -52
- package/dist/Plugins/code/langIcons/XslIcon.js +94 -66
- package/dist/Plugins/code/langIcons/YamlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ZigIcon.js +106 -81
- package/dist/Plugins/code/langIcons/index.js +128 -259
- package/dist/Plugins/code/utils/index.js +5 -5
- package/dist/Plugins/code/utils/langOptions.js +86 -11
- package/dist/Plugins/defaultPlugins.js +9 -13
- package/dist/Plugins/formatter/index.js +205 -105
- package/dist/Plugins/index.js +6 -2
- package/dist/Plugins/katex/InlineKatex.js +196 -107
- package/dist/Plugins/katex/Katex.js +139 -65
- package/dist/Plugins/katex/index.js +163 -103
- package/dist/Plugins/mermaid/Mermaid.d.ts +9 -4
- package/dist/Plugins/mermaid/Mermaid.js +475 -178
- package/dist/Plugins/mermaid/index.js +237 -142
- package/dist/Quote/index.js +112 -73
- package/dist/Quote/style.js +176 -160
- package/dist/Schema/SchemaEditor/AceEditorWrapper.js +163 -119
- package/dist/Schema/SchemaEditor/index.js +385 -275
- package/dist/Schema/SchemaEditor/style.js +261 -269
- package/dist/Schema/SchemaForm/index.js +443 -268
- package/dist/Schema/SchemaForm/types.js +1 -0
- package/dist/Schema/SchemaRenderer/index.js +973 -588
- package/dist/Schema/SchemaRenderer/templateEngine.js +106 -26
- package/dist/Schema/index.js +7 -11
- package/dist/Schema/types.js +1 -0
- package/dist/Schema/validator.js +74 -36
- package/dist/TaskList/index.js +197 -142
- package/dist/TaskList/style.js +143 -122
- package/dist/ThoughtChainList/CostMillis.js +88 -54
- package/dist/ThoughtChainList/DeepThink.js +187 -152
- package/dist/ThoughtChainList/DotAni/index.js +29 -14
- package/dist/ThoughtChainList/DotAni/style.js +82 -50
- package/dist/ThoughtChainList/FlipText/index.js +74 -30
- package/dist/ThoughtChainList/MarkdownEditor.js +126 -72
- package/dist/ThoughtChainList/RagRetrievalInfo.js +113 -145
- package/dist/ThoughtChainList/TableSql.js +413 -459
- package/dist/ThoughtChainList/ThoughtChainListItem.js +388 -222
- package/dist/ThoughtChainList/TitleInfo.js +189 -185
- package/dist/ThoughtChainList/ToolCall.js +429 -463
- package/dist/ThoughtChainList/WebSearch.js +192 -162
- package/dist/ThoughtChainList/index.js +449 -410
- package/dist/ThoughtChainList/style.js +253 -232
- package/dist/ThoughtChainList/types.js +1 -0
- package/dist/ToolUseBar/ToolUseBarItem.js +183 -139
- package/dist/ToolUseBar/ToolUseBarItemComponents.js +345 -276
- package/dist/ToolUseBar/ToolUseBarThink.js +335 -396
- package/dist/ToolUseBar/index.js +226 -113
- package/dist/ToolUseBar/style.js +334 -308
- package/dist/ToolUseBar/thinkStyle.js +350 -328
- package/dist/Types/common.js +1 -0
- package/dist/Types/index.js +4 -2
- package/dist/Types/message.js +1 -0
- package/dist/Utils/easings.js +9 -12
- package/dist/Utils/formatTime.js +41 -17
- package/dist/Utils/getScroll.js +41 -41
- package/dist/Utils/language.js +355 -150
- package/dist/Utils/proxySandbox/ProxySandbox.js +1637 -1076
- package/dist/Utils/proxySandbox/SecurityContextManager.js +607 -343
- package/dist/Utils/proxySandbox/index.js +554 -267
- package/dist/Utils/proxySandbox/types.js +187 -52
- package/dist/Utils/scrollTo.js +48 -56
- package/dist/Utils/throttleByAnimationFrame.js +46 -20
- package/dist/WelcomeMessage/index.js +106 -58
- package/dist/WelcomeMessage/style.js +80 -55
- package/dist/Workspace/Browser/index.js +102 -40
- package/dist/Workspace/Browser/style.js +62 -33
- package/dist/Workspace/File/DataSourceStrategy.js +419 -217
- package/dist/Workspace/File/FileComponent.js +1004 -791
- package/dist/Workspace/File/FileTypeProcessor.js +337 -184
- package/dist/Workspace/File/PreviewComponent.js +472 -532
- package/dist/Workspace/File/index.js +3 -10
- package/dist/Workspace/File/style.js +397 -424
- package/dist/Workspace/File/utils.js +160 -106
- package/dist/Workspace/HtmlPreview/index.js +238 -137
- package/dist/Workspace/HtmlPreview/style.js +99 -77
- package/dist/Workspace/RealtimeFollow/index.js +411 -413
- package/dist/Workspace/RealtimeFollow/style.js +299 -303
- package/dist/Workspace/Task/index.js +53 -35
- package/dist/Workspace/Task/style.js +99 -73
- package/dist/Workspace/index.js +332 -254
- package/dist/Workspace/style.js +165 -146
- package/dist/Workspace/types.js +471 -252
- package/dist/Workspace/utils/codeLanguageUtils.js +148 -129
- package/dist/Workspace/utils.js +28 -20
- package/dist/index.js +27 -17
- package/package.json +3 -2
|
@@ -1,152 +1,321 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1
|
+
/* eslint-disable no-param-reassign */ function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function _class_call_check(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Node,
|
|
26
|
-
Path,
|
|
27
|
-
Point,
|
|
28
|
-
Range,
|
|
29
|
-
Text,
|
|
30
|
-
Transforms
|
|
31
|
-
} from "slate";
|
|
32
|
-
import { ReactEditor } from "slate-react";
|
|
33
|
-
import { getMediaType } from "./dom";
|
|
34
|
-
var _EditorUtils = class {
|
|
35
|
-
static get p() {
|
|
36
|
-
return { type: "paragraph", children: [{ text: "" }] };
|
|
37
|
-
}
|
|
38
|
-
static hasPath(editor, path) {
|
|
39
|
-
return Editor.hasPath(editor, path);
|
|
40
|
-
}
|
|
41
|
-
static focus(editor) {
|
|
42
|
-
try {
|
|
43
|
-
ReactEditor.focus(editor);
|
|
44
|
-
} catch (e) {
|
|
45
|
-
console.error(e);
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for(var i = 0; i < props.length; i++){
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
23
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
46
24
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
25
|
+
}
|
|
26
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
27
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
28
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
29
|
+
return Constructor;
|
|
30
|
+
}
|
|
31
|
+
function _define_property(obj, key, value) {
|
|
32
|
+
if (key in obj) {
|
|
33
|
+
Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
obj[key] = value;
|
|
53
41
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
function _iterable_to_array(iter) {
|
|
45
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
46
|
+
}
|
|
47
|
+
function _iterable_to_array_limit(arr, i) {
|
|
48
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
49
|
+
if (_i == null) return;
|
|
50
|
+
var _arr = [];
|
|
51
|
+
var _n = true;
|
|
52
|
+
var _d = false;
|
|
53
|
+
var _s, _e;
|
|
54
|
+
try {
|
|
55
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
56
|
+
_arr.push(_s.value);
|
|
57
|
+
if (i && _arr.length === i) break;
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
_d = true;
|
|
61
|
+
_e = err;
|
|
62
|
+
} finally{
|
|
63
|
+
try {
|
|
64
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
65
|
+
} finally{
|
|
66
|
+
if (_d) throw _e;
|
|
76
67
|
}
|
|
77
|
-
} else {
|
|
78
|
-
path = Path.parent(path);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
static findMediaInsertPath(editor) {
|
|
84
|
-
var _a, _b, _c;
|
|
85
|
-
const [cur] = Editor.nodes(editor, {
|
|
86
|
-
match: (n) => Element.isElement(n),
|
|
87
|
-
mode: "lowest"
|
|
88
|
-
});
|
|
89
|
-
if (!cur)
|
|
90
|
-
return null;
|
|
91
|
-
let path = cur[1];
|
|
92
|
-
if (((_a = cur == null ? void 0 : cur[0]) == null ? void 0 : _a.type) === "table-cell") {
|
|
93
|
-
path = Path.next(Path.parent(Path.parent(cur[1])));
|
|
94
|
-
}
|
|
95
|
-
if (((_b = cur == null ? void 0 : cur[0]) == null ? void 0 : _b.type) === "head") {
|
|
96
|
-
path = Path.next(path);
|
|
97
|
-
}
|
|
98
|
-
if (((_c = cur == null ? void 0 : cur[0]) == null ? void 0 : _c.type) === "paragraph" && Node.string(cur[0])) {
|
|
99
|
-
path = Path.next(cur[1]);
|
|
100
68
|
}
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
69
|
+
return _arr;
|
|
70
|
+
}
|
|
71
|
+
function _non_iterable_rest() {
|
|
72
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
73
|
+
}
|
|
74
|
+
function _non_iterable_spread() {
|
|
75
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
76
|
+
}
|
|
77
|
+
function _object_spread(target) {
|
|
78
|
+
for(var i = 1; i < arguments.length; i++){
|
|
79
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
80
|
+
var ownKeys = Object.keys(source);
|
|
81
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
82
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
83
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
ownKeys.forEach(function(key) {
|
|
87
|
+
_define_property(target, key, source[key]);
|
|
88
|
+
});
|
|
110
89
|
}
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
count++;
|
|
90
|
+
return target;
|
|
91
|
+
}
|
|
92
|
+
function ownKeys(object, enumerableOnly) {
|
|
93
|
+
var keys = Object.keys(object);
|
|
94
|
+
if (Object.getOwnPropertySymbols) {
|
|
95
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
96
|
+
if (enumerableOnly) {
|
|
97
|
+
symbols = symbols.filter(function(sym) {
|
|
98
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
keys.push.apply(keys, symbols);
|
|
124
102
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
path: Path.next(path),
|
|
132
|
-
node: { text: "" }
|
|
133
|
-
});
|
|
134
|
-
Transforms.select(editor, Path.next(path));
|
|
103
|
+
return keys;
|
|
104
|
+
}
|
|
105
|
+
function _object_spread_props(target, source) {
|
|
106
|
+
source = source != null ? source : {};
|
|
107
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
108
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
135
109
|
} else {
|
|
136
|
-
|
|
110
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
111
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
112
|
+
});
|
|
137
113
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
114
|
+
return target;
|
|
115
|
+
}
|
|
116
|
+
function _sliced_to_array(arr, i) {
|
|
117
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
118
|
+
}
|
|
119
|
+
function _to_consumable_array(arr) {
|
|
120
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
121
|
+
}
|
|
122
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
123
|
+
if (!o) return;
|
|
124
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
125
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
126
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
127
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
128
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
129
|
+
}
|
|
130
|
+
import { Editor, Element, Node, Path, Point, Range, Text, Transforms } from "slate";
|
|
131
|
+
import { ReactEditor } from "slate-react";
|
|
132
|
+
import { getMediaType } from "./dom";
|
|
133
|
+
export var EditorUtils = /*#__PURE__*/ function() {
|
|
134
|
+
"use strict";
|
|
135
|
+
function EditorUtils() {
|
|
136
|
+
_class_call_check(this, EditorUtils);
|
|
146
137
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
138
|
+
_create_class(EditorUtils, null, [
|
|
139
|
+
{
|
|
140
|
+
key: "p",
|
|
141
|
+
get: function get() {
|
|
142
|
+
return {
|
|
143
|
+
type: 'paragraph',
|
|
144
|
+
children: [
|
|
145
|
+
{
|
|
146
|
+
text: ''
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
key: "hasPath",
|
|
154
|
+
value: function hasPath(editor, path) {
|
|
155
|
+
return Editor.hasPath(editor, path);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
key: "focus",
|
|
160
|
+
value: function focus(editor) {
|
|
161
|
+
try {
|
|
162
|
+
ReactEditor.focus(editor);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
console.error(e);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
key: "blur",
|
|
170
|
+
value: function blur(editor) {
|
|
171
|
+
try {
|
|
172
|
+
ReactEditor.blur(editor);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
console.error(e);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
key: "isPrevious",
|
|
180
|
+
value: function isPrevious(firstPath, nextPath) {
|
|
181
|
+
return Path.equals(Path.parent(firstPath), Path.parent(nextPath)) && Path.compare(firstPath, nextPath) === -1;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
key: "isNextPath",
|
|
186
|
+
value: function isNextPath(firstPath, nextPath) {
|
|
187
|
+
return Path.equals(Path.parent(firstPath), Path.parent(nextPath)) && Path.compare(firstPath, nextPath) === 1;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
key: "isDirtLeaf",
|
|
192
|
+
value: function isDirtLeaf(leaf) {
|
|
193
|
+
return leaf.bold || leaf.code || leaf.italic || leaf.strikethrough || !!(leaf === null || leaf === void 0 ? void 0 : leaf.url) || leaf.fnd || leaf.fnc || leaf.html || leaf.highColor;
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
key: "isTop",
|
|
198
|
+
value: function isTop(editor, path) {
|
|
199
|
+
var p = Editor.parent(editor, path);
|
|
200
|
+
return Editor.isEditor(p[0]);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
key: "findPrev",
|
|
205
|
+
value: function findPrev(editor, path) {
|
|
206
|
+
while(path.length){
|
|
207
|
+
if (Path.hasPrevious(path)) {
|
|
208
|
+
var _Node_get;
|
|
209
|
+
if (((_Node_get = Node.get(editor, Path.previous(path))) === null || _Node_get === void 0 ? void 0 : _Node_get.type) === 'hr') {
|
|
210
|
+
path = Path.previous(path);
|
|
211
|
+
} else {
|
|
212
|
+
return Path.previous(path);
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
path = Path.parent(path);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
key: "findMediaInsertPath",
|
|
223
|
+
value: function findMediaInsertPath(editor) {
|
|
224
|
+
var _cur_, _cur_1, _cur_2;
|
|
225
|
+
var _Editor_nodes = _sliced_to_array(Editor.nodes(editor, {
|
|
226
|
+
match: function(n) {
|
|
227
|
+
return Element.isElement(n);
|
|
228
|
+
},
|
|
229
|
+
mode: 'lowest'
|
|
230
|
+
}), 1), cur = _Editor_nodes[0];
|
|
231
|
+
if (!cur) return null;
|
|
232
|
+
var path = cur[1];
|
|
233
|
+
if ((cur === null || cur === void 0 ? void 0 : (_cur_ = cur[0]) === null || _cur_ === void 0 ? void 0 : _cur_.type) === 'table-cell') {
|
|
234
|
+
path = Path.next(Path.parent(Path.parent(cur[1])));
|
|
235
|
+
}
|
|
236
|
+
if ((cur === null || cur === void 0 ? void 0 : (_cur_1 = cur[0]) === null || _cur_1 === void 0 ? void 0 : _cur_1.type) === 'head') {
|
|
237
|
+
path = Path.next(path);
|
|
238
|
+
}
|
|
239
|
+
if ((cur === null || cur === void 0 ? void 0 : (_cur_2 = cur[0]) === null || _cur_2 === void 0 ? void 0 : _cur_2.type) === 'paragraph' && Node.string(cur[0])) {
|
|
240
|
+
path = Path.next(cur[1]);
|
|
241
|
+
}
|
|
242
|
+
return path;
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
key: "findNext",
|
|
247
|
+
value: function findNext(editor, path) {
|
|
248
|
+
while(path.length){
|
|
249
|
+
if (Editor.hasPath(editor, Path.next(path))) {
|
|
250
|
+
return Path.next(path);
|
|
251
|
+
} else {
|
|
252
|
+
path = Path.parent(path);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
key: "moveNodes",
|
|
260
|
+
value: function moveNodes(editor, from, to) {
|
|
261
|
+
var index = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 1;
|
|
262
|
+
var count = 0;
|
|
263
|
+
while(Editor.hasPath(editor, from)){
|
|
264
|
+
if (count > 100) break;
|
|
265
|
+
Transforms.moveNodes(editor, {
|
|
266
|
+
at: from,
|
|
267
|
+
to: _to_consumable_array(to).concat([
|
|
268
|
+
index
|
|
269
|
+
])
|
|
270
|
+
});
|
|
271
|
+
index++;
|
|
272
|
+
count++;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
key: "moveAfterSpace",
|
|
278
|
+
value: function moveAfterSpace(editor, path) {
|
|
279
|
+
var next = Editor.next(editor, {
|
|
280
|
+
at: path
|
|
281
|
+
});
|
|
282
|
+
if (!next || !Text.isText(next[0])) {
|
|
283
|
+
Transforms.transform(editor, {
|
|
284
|
+
type: 'insert_node',
|
|
285
|
+
path: Path.next(path),
|
|
286
|
+
node: {
|
|
287
|
+
text: ''
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
Transforms.select(editor, Path.next(path));
|
|
291
|
+
} else {
|
|
292
|
+
Transforms.move(editor, {
|
|
293
|
+
unit: 'offset'
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
key: "moveBeforeSpace",
|
|
300
|
+
value: function moveBeforeSpace(editor, path) {
|
|
301
|
+
if (!Path.hasPrevious(path)) {
|
|
302
|
+
Transforms.transform(editor, {
|
|
303
|
+
type: 'insert_node',
|
|
304
|
+
path: path,
|
|
305
|
+
node: {
|
|
306
|
+
text: ''
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
Transforms.move(editor, {
|
|
311
|
+
unit: 'offset',
|
|
312
|
+
reverse: true
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
key: "clearMarks",
|
|
318
|
+
value: /**
|
|
150
319
|
* 清除编辑器中选中的文本的所有标记
|
|
151
320
|
*
|
|
152
321
|
* @param editor - 编辑器实例
|
|
@@ -160,58 +329,67 @@ var _EditorUtils = class {
|
|
|
160
329
|
*
|
|
161
330
|
* 当 split=true 时,会在不同格式的边界处分割文本节点,
|
|
162
331
|
* 这允许对部分文本应用/移除格式而不影响相邻文本
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
332
|
+
*/ function clearMarks(editor) {
|
|
333
|
+
var split = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
334
|
+
if (!editor.selection) return;
|
|
335
|
+
// 移除所有格式标记
|
|
336
|
+
Transforms.unsetNodes(editor, EditorUtils.CLEARABLE_MARKS, {
|
|
337
|
+
split: split,
|
|
338
|
+
match: Text.isText
|
|
339
|
+
});
|
|
340
|
+
var anchorPath = editor.selection.anchor.path;
|
|
341
|
+
var parentPath = Path.parent(anchorPath);
|
|
342
|
+
try {
|
|
343
|
+
var node = Node.get(editor, parentPath);
|
|
344
|
+
// 向上查找非段落的父节点
|
|
345
|
+
if (node.type === 'paragraph' && Editor.hasPath(editor, Path.parent(parentPath))) {
|
|
346
|
+
node = Node.get(editor, Path.parent(parentPath));
|
|
347
|
+
}
|
|
348
|
+
// 处理列表项的提升
|
|
349
|
+
if (node.type === 'list-item') {
|
|
350
|
+
Transforms.liftNodes(editor, {
|
|
351
|
+
at: Path.parent(anchorPath),
|
|
352
|
+
mode: 'highest'
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
// 查找最高级别的选中元素节点
|
|
356
|
+
var nodeEntries = Array.from(Editor.nodes(editor, {
|
|
357
|
+
match: function(n) {
|
|
358
|
+
return Element.isElement(n);
|
|
359
|
+
},
|
|
360
|
+
mode: 'highest'
|
|
361
|
+
}));
|
|
362
|
+
if (nodeEntries.length > 0) {
|
|
363
|
+
var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 2), selectNodes = _nodeEntries_[0], selectPath = _nodeEntries_[1];
|
|
364
|
+
// 处理列表转段落的特殊情况
|
|
365
|
+
if (selectNodes.type === 'list') {
|
|
366
|
+
Transforms.removeNodes(editor, {
|
|
367
|
+
at: selectPath,
|
|
368
|
+
voids: true
|
|
369
|
+
});
|
|
370
|
+
var paragraphNodes = EditorUtils.listToParagraph(editor, selectNodes);
|
|
371
|
+
if (paragraphNodes.length > 0) {
|
|
372
|
+
Transforms.insertNodes(editor, paragraphNodes, {
|
|
373
|
+
at: editor.selection
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
// 将选中区域转换为段落
|
|
380
|
+
Transforms.setNodes(editor, {
|
|
381
|
+
type: 'paragraph'
|
|
382
|
+
}, {
|
|
383
|
+
at: parentPath
|
|
384
|
+
});
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error('Error in clearMarks:', error);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
key: "listToParagraph",
|
|
392
|
+
value: /**
|
|
215
393
|
* 将列表节点转换为段落节点数组
|
|
216
394
|
*
|
|
217
395
|
* @param editor - 编辑器实例
|
|
@@ -221,840 +399,1125 @@ var _EditorUtils = class {
|
|
|
221
399
|
* @description
|
|
222
400
|
* 该方法通过递归遍历列表节点及其子节点,提取所有段落节点,
|
|
223
401
|
* 并将它们汇集成一个扁平化的数组。支持嵌套列表的处理。
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
402
|
+
*/ function listToParagraph(editor, listNode) {
|
|
403
|
+
if (!listNode.children || listNode.children.length === 0) {
|
|
404
|
+
return [];
|
|
405
|
+
}
|
|
406
|
+
var paragraphNodes = [];
|
|
407
|
+
var extractParagraphs = function(children) {
|
|
408
|
+
children.forEach(function(item) {
|
|
409
|
+
if (!(item === null || item === void 0 ? void 0 : item.children)) return;
|
|
410
|
+
item.children.forEach(function(child) {
|
|
411
|
+
if (child.type === 'paragraph') {
|
|
412
|
+
paragraphNodes.push(child);
|
|
413
|
+
} else if (child.type === 'list') {
|
|
414
|
+
var _paragraphNodes;
|
|
415
|
+
// 递归处理嵌套列表
|
|
416
|
+
var nestedParagraphs = EditorUtils.listToParagraph(editor, child);
|
|
417
|
+
(_paragraphNodes = paragraphNodes).push.apply(_paragraphNodes, _to_consumable_array(nestedParagraphs));
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
extractParagraphs(listNode.children);
|
|
423
|
+
return paragraphNodes.flat();
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
key: "deleteAll",
|
|
428
|
+
value: /**
|
|
248
429
|
* 删除编辑器中的所有内容,并插入新的节点
|
|
249
430
|
*
|
|
250
431
|
* @param editor - 编辑器实例
|
|
251
432
|
* @param insertNodes - 要插入的新节点数组。如果未提供,将插入默认段落节点
|
|
252
|
-
*/
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
433
|
+
*/ function deleteAll(editor, insertNodes) {
|
|
434
|
+
var allNodes = Array.from(Editor.nodes(editor, {
|
|
435
|
+
at: [],
|
|
436
|
+
match: function(n) {
|
|
437
|
+
return Element.isElement(n);
|
|
438
|
+
},
|
|
439
|
+
mode: 'highest',
|
|
440
|
+
reverse: true
|
|
441
|
+
}));
|
|
442
|
+
if (allNodes.length > 0) {
|
|
443
|
+
var firstNode = allNodes[allNodes.length - 1];
|
|
444
|
+
var lastNode = allNodes[0];
|
|
445
|
+
Transforms.delete(editor, {
|
|
446
|
+
at: {
|
|
447
|
+
anchor: Editor.start(editor, firstNode[1]),
|
|
448
|
+
focus: Editor.end(editor, lastNode[1])
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
// 删除剩余的第一个节点
|
|
452
|
+
if (Editor.hasPath(editor, [
|
|
453
|
+
0
|
|
454
|
+
])) {
|
|
455
|
+
Transforms.delete(editor, {
|
|
456
|
+
at: [
|
|
457
|
+
0
|
|
458
|
+
]
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
var nodesToInsert = insertNodes || [
|
|
463
|
+
EditorUtils.p
|
|
464
|
+
];
|
|
465
|
+
Transforms.insertNodes(editor, nodesToInsert, {
|
|
466
|
+
at: [
|
|
467
|
+
0
|
|
468
|
+
]
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
key: "reset",
|
|
474
|
+
value: /**
|
|
279
475
|
* 重置编辑器的内容,并可选地插入新的节点和重置历史记录
|
|
280
476
|
*
|
|
281
477
|
* @param editor - 要重置的编辑器实例
|
|
282
478
|
* @param insertNodes - 可选的插入节点数组。如果未提供,则使用默认段落节点
|
|
283
479
|
* @param force - 可选的布尔值或历史记录对象。如果为布尔值,则强制重置历史记录;如果为历史记录对象,则使用提供的历史记录
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
480
|
+
*/ function reset(editor, insertNodes, force) {
|
|
481
|
+
var nodesToInsert = insertNodes || [
|
|
482
|
+
EditorUtils.p
|
|
483
|
+
];
|
|
484
|
+
// 深克隆节点以避免引用问题
|
|
485
|
+
editor.children = JSON.parse(JSON.stringify(nodesToInsert));
|
|
486
|
+
if (force) {
|
|
487
|
+
editor.history = typeof force === 'boolean' ? {
|
|
488
|
+
redos: [],
|
|
489
|
+
undos: []
|
|
490
|
+
} : force;
|
|
491
|
+
}
|
|
492
|
+
editor.onChange();
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
key: "includeAll",
|
|
497
|
+
value: /**
|
|
294
498
|
* 检查选区是否完全包含在指定节点路径中。
|
|
295
499
|
*
|
|
296
500
|
* @param editor - 编辑器实例。
|
|
297
501
|
* @param sel - 选区范围。
|
|
298
502
|
* @param nodePath - 节点路径。
|
|
299
503
|
* @returns 如果选区完全包含在节点路径中,则返回 true,否则返回 false。
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
504
|
+
*/ function includeAll(editor, sel, nodePath) {
|
|
505
|
+
var _Range_edges = _sliced_to_array(Range.edges(sel), 2), start = _Range_edges[0], end = _Range_edges[1];
|
|
506
|
+
return Point.compare(start, Editor.start(editor, nodePath)) !== 1 && Point.compare(end, Editor.end(editor, nodePath)) !== -1;
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
key: "copy",
|
|
511
|
+
value: function copy(data) {
|
|
512
|
+
return JSON.parse(JSON.stringify(data));
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
key: "copyText",
|
|
517
|
+
value: /**
|
|
309
518
|
* 复制指定范围内的文本内容。
|
|
310
519
|
*
|
|
311
520
|
* @param editor - 编辑器实例。
|
|
312
521
|
* @param start - 文本复制的起始位置。
|
|
313
522
|
* @param end - (可选)文本复制的结束位置。如果未提供,则复制从起始位置到文档末尾的所有文本。
|
|
314
523
|
* @returns 返回指定范围内的文本内容。
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
524
|
+
*/ function copyText(editor, start, end) {
|
|
525
|
+
var _leaf_text;
|
|
526
|
+
var leaf = Node.leaf(editor, start.path);
|
|
527
|
+
var text = '';
|
|
528
|
+
// Handle first leaf node from start offset
|
|
529
|
+
text += ((_leaf_text = leaf.text) === null || _leaf_text === void 0 ? void 0 : _leaf_text.slice(start.offset)) || '';
|
|
530
|
+
// Get next nodes until we reach the end point
|
|
531
|
+
var next = Editor.next(editor, {
|
|
532
|
+
at: start.path
|
|
533
|
+
});
|
|
534
|
+
while(next){
|
|
535
|
+
if (end && Path.equals(next[1], end.path)) {
|
|
536
|
+
var _next__text;
|
|
537
|
+
// If we reach the end path, slice until end offset
|
|
538
|
+
text += ((_next__text = next[0].text) === null || _next__text === void 0 ? void 0 : _next__text.slice(0, end.offset)) || '';
|
|
539
|
+
break;
|
|
540
|
+
} else {
|
|
541
|
+
// Add full text content of intermediate nodes
|
|
542
|
+
text += next[0].text || '';
|
|
543
|
+
next = Editor.next(editor, {
|
|
544
|
+
at: next[1]
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return text;
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
key: "cutText",
|
|
553
|
+
value: /**
|
|
334
554
|
* 从编辑器中剪切文本。
|
|
335
555
|
*
|
|
336
556
|
* @param editor - 编辑器实例。
|
|
337
557
|
* @param start - 开始位置的点。
|
|
338
558
|
* @param end - 结束位置的点(可选)。
|
|
339
559
|
* @returns 剪切的文本数组,每个元素为一个 CustomLeaf 对象。
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
560
|
+
*/ function cutText(editor, start, end) {
|
|
561
|
+
var _leaf_text;
|
|
562
|
+
var leaf = Node.leaf(editor, start.path);
|
|
563
|
+
var texts = [
|
|
564
|
+
_object_spread_props(_object_spread({}, leaf), {
|
|
565
|
+
text: ((_leaf_text = leaf.text) === null || _leaf_text === void 0 ? void 0 : _leaf_text.slice(start.offset)) || ''
|
|
566
|
+
})
|
|
567
|
+
];
|
|
568
|
+
var next = Editor.next(editor, {
|
|
569
|
+
at: start.path
|
|
570
|
+
});
|
|
571
|
+
while(next){
|
|
572
|
+
if (end && Path.equals(next[1], end.path)) {
|
|
573
|
+
var _next__text;
|
|
574
|
+
texts.push(_object_spread_props(_object_spread({}, next[0]), {
|
|
575
|
+
text: ((_next__text = next[0].text) === null || _next__text === void 0 ? void 0 : _next__text.slice(0, end.offset)) || ''
|
|
576
|
+
}));
|
|
577
|
+
break;
|
|
578
|
+
} else {
|
|
579
|
+
texts.push(next[0]);
|
|
580
|
+
next = Editor.next(editor, {
|
|
581
|
+
at: next[1]
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return texts;
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
key: "isFormatActive",
|
|
590
|
+
value: /**
|
|
362
591
|
* 检查编辑器中是否有指定格式的活动节点
|
|
363
592
|
*
|
|
364
593
|
* @param editor - 编辑器实例
|
|
365
594
|
* @param format - 要检查的格式名称
|
|
366
595
|
* @param value - 可选的值,用于进一步验证格式是否匹配
|
|
367
596
|
* @returns 如果存在匹配的格式节点,则返回 true;否则返回 false
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
597
|
+
*/ function isFormatActive(editor, format, value) {
|
|
598
|
+
try {
|
|
599
|
+
var nodeEntries = Array.from(Editor.nodes(editor, {
|
|
600
|
+
match: function(n) {
|
|
601
|
+
return !!n[format];
|
|
602
|
+
},
|
|
603
|
+
mode: 'lowest'
|
|
604
|
+
}));
|
|
605
|
+
if (nodeEntries.length === 0) return false;
|
|
606
|
+
var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 1), node = _nodeEntries_[0];
|
|
607
|
+
return value ? node[format] === value : !!node[format];
|
|
608
|
+
} catch (error) {
|
|
609
|
+
console.error('Error checking format active:', error);
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
key: "getUrl",
|
|
616
|
+
value: /**
|
|
387
617
|
* 获取编辑器中选中文本的URL
|
|
388
618
|
*
|
|
389
619
|
* @param editor - 编辑器实例
|
|
390
620
|
* @returns 返回选中文本的URL,如果没有则返回空字符串
|
|
391
|
-
*/
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
621
|
+
*/ function getUrl(editor) {
|
|
622
|
+
try {
|
|
623
|
+
var _nodeEntries__;
|
|
624
|
+
var nodeEntries = Array.from(Editor.nodes(editor, {
|
|
625
|
+
match: function(n) {
|
|
626
|
+
return Text.isText(n) && !!(n === null || n === void 0 ? void 0 : n.url);
|
|
627
|
+
},
|
|
628
|
+
mode: 'lowest'
|
|
629
|
+
}));
|
|
630
|
+
return nodeEntries.length > 0 ? ((_nodeEntries__ = nodeEntries[0][0]) === null || _nodeEntries__ === void 0 ? void 0 : _nodeEntries__.url) || '' : '';
|
|
631
|
+
} catch (error) {
|
|
632
|
+
console.error('Error getting URL:', error);
|
|
633
|
+
return '';
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
key: "toggleFormat",
|
|
639
|
+
value: /**
|
|
408
640
|
* 切换文本格式(加粗、斜体等)
|
|
409
641
|
*
|
|
410
642
|
* @param editor - 编辑器实例
|
|
411
643
|
* @param format - 要切换的格式类型
|
|
412
|
-
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
/**
|
|
644
|
+
*/ function toggleFormat(editor, format) {
|
|
645
|
+
if (!editor.selection) return;
|
|
646
|
+
var selectedText = Editor.string(editor, editor.selection);
|
|
647
|
+
if (!selectedText) return;
|
|
648
|
+
var isActive = EditorUtils.isFormatActive(editor, format);
|
|
649
|
+
Transforms.setNodes(editor, _define_property({}, format, isActive ? null : true), {
|
|
650
|
+
match: Text.isText,
|
|
651
|
+
split: true
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
key: "highColor",
|
|
657
|
+
value: /**
|
|
427
658
|
* 为编辑器中的文本节点设置高亮颜色
|
|
428
659
|
*
|
|
429
660
|
* @param editor - 编辑器实例
|
|
430
661
|
* @param color - 可选的高亮颜色字符串。如果未提供,则移除高亮颜色
|
|
431
|
-
*/
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
662
|
+
*/ function highColor(editor, color) {
|
|
663
|
+
if (!editor.selection) return;
|
|
664
|
+
Transforms.setNodes(editor, {
|
|
665
|
+
highColor: color
|
|
666
|
+
}, {
|
|
667
|
+
match: Text.isText,
|
|
668
|
+
split: true
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
key: "setAlignment",
|
|
674
|
+
value: /**
|
|
442
675
|
* 设置文本对齐方式
|
|
443
676
|
*
|
|
444
677
|
* @param editor - 编辑器实例
|
|
445
678
|
* @param alignment - 对齐方式:'left', 'center', 或 'right'
|
|
446
|
-
*/
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
679
|
+
*/ function setAlignment(editor, alignment) {
|
|
680
|
+
if (!editor.selection) return;
|
|
681
|
+
Transforms.setNodes(editor, {
|
|
682
|
+
align: alignment
|
|
683
|
+
}, {
|
|
684
|
+
match: function(n) {
|
|
685
|
+
return Element.isElement(n) && !Editor.isEditor(n);
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
key: "isAlignmentActive",
|
|
692
|
+
value: /**
|
|
457
693
|
* 检查当前选中块的对齐方式
|
|
458
694
|
*
|
|
459
695
|
* @param editor - 编辑器实例
|
|
460
696
|
* @param alignment - 要检查的对齐方式
|
|
461
697
|
* @returns 是否处于指定的对齐方式
|
|
462
|
-
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
698
|
+
*/ function isAlignmentActive(editor, alignment) {
|
|
699
|
+
try {
|
|
700
|
+
var nodeEntries = Array.from(Editor.nodes(editor, {
|
|
701
|
+
match: function(n) {
|
|
702
|
+
return Element.isElement(n) && n.align === alignment;
|
|
703
|
+
}
|
|
704
|
+
}));
|
|
705
|
+
return nodeEntries.length > 0;
|
|
706
|
+
} catch (error) {
|
|
707
|
+
console.error('Error checking alignment active:', error);
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
key: "checkEnd",
|
|
714
|
+
value: /**
|
|
477
715
|
* 检查编辑器末尾是否需要添加段落节点
|
|
478
716
|
*
|
|
479
717
|
* @param editor - 编辑器实例
|
|
480
718
|
* @returns 如果添加了段落节点则返回 true,否则返回 false
|
|
481
|
-
*/
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
719
|
+
*/ function checkEnd(editor) {
|
|
720
|
+
try {
|
|
721
|
+
var _node_children, _node_children_;
|
|
722
|
+
var nodeEntries = Array.from(Editor.nodes(editor, {
|
|
723
|
+
at: [],
|
|
724
|
+
mode: 'highest',
|
|
725
|
+
match: function(n) {
|
|
726
|
+
return Element.isElement(n);
|
|
727
|
+
},
|
|
728
|
+
reverse: true
|
|
729
|
+
}));
|
|
730
|
+
if (nodeEntries.length === 0) return false;
|
|
731
|
+
var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 2), node = _nodeEntries_[0], path = _nodeEntries_[1];
|
|
732
|
+
var nodeString = Node.string(node);
|
|
733
|
+
var hasMediaChild = (node === null || node === void 0 ? void 0 : (_node_children = node.children) === null || _node_children === void 0 ? void 0 : _node_children.length) === 1 && (node === null || node === void 0 ? void 0 : (_node_children_ = node.children[0]) === null || _node_children_ === void 0 ? void 0 : _node_children_.type) === 'media';
|
|
734
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== 'paragraph' || nodeString || hasMediaChild) {
|
|
735
|
+
Transforms.insertNodes(editor, EditorUtils.p, {
|
|
736
|
+
at: Path.next(path)
|
|
737
|
+
});
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
return false;
|
|
741
|
+
} catch (error) {
|
|
742
|
+
console.error('Error in checkEnd:', error);
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
key: "checkSelEnd",
|
|
749
|
+
value: /**
|
|
511
750
|
* 检查指定路径是否在编辑器末尾
|
|
512
751
|
*
|
|
513
752
|
* @param editor - 编辑器实例
|
|
514
753
|
* @param path - 要检查的路径
|
|
515
754
|
* @returns 如果路径在末尾则返回 true,否则返回 false
|
|
516
|
-
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
755
|
+
*/ function checkSelEnd(editor, path) {
|
|
756
|
+
try {
|
|
757
|
+
var currentNode = Editor.node(editor, path);
|
|
758
|
+
while(!Editor.isEditor(currentNode[0])){
|
|
759
|
+
if (Editor.hasPath(editor, Path.next(currentNode[1]))) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
currentNode = Editor.node(editor, Path.parent(currentNode[1]));
|
|
763
|
+
}
|
|
764
|
+
return true;
|
|
765
|
+
} catch (error) {
|
|
766
|
+
console.error('Error in checkSelEnd:', error);
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
key: "findPath",
|
|
773
|
+
value: /**
|
|
533
774
|
* 安全地查找元素对应的Slate路径
|
|
534
775
|
*
|
|
535
776
|
* @param editor - 编辑器实例
|
|
536
777
|
* @param el - DOM元素
|
|
537
778
|
* @returns 元素对应的路径,如果查找失败则返回编辑器起始路径
|
|
538
|
-
*/
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
779
|
+
*/ function findPath(editor, el) {
|
|
780
|
+
try {
|
|
781
|
+
return ReactEditor.findPath(editor, el);
|
|
782
|
+
} catch (error) {
|
|
783
|
+
console.error('find path error', error);
|
|
784
|
+
return Editor.start(editor, []).path;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
key: "createMediaNode",
|
|
790
|
+
value: /**
|
|
548
791
|
* 创建媒体节点(图片、视频等)
|
|
549
792
|
*
|
|
550
793
|
* @param src - 媒体资源URL
|
|
551
794
|
* @param type - 媒体类型
|
|
552
795
|
* @param extraPros - 额外属性
|
|
553
796
|
* @returns 创建的媒体节点
|
|
554
|
-
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
797
|
+
*/ function createMediaNode(src, type, extraPros) {
|
|
798
|
+
if (!src) {
|
|
799
|
+
return {
|
|
800
|
+
text: ''
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
try {
|
|
804
|
+
var fullSrc = EditorUtils.normalizeUrl(src);
|
|
805
|
+
var urlParams = EditorUtils.parseUrlParams(fullSrc);
|
|
806
|
+
var altText = (extraPros === null || extraPros === void 0 ? void 0 : extraPros.alt) || urlParams.get('alt') || '';
|
|
807
|
+
if (type === 'image' && EditorUtils.isImageType(src, (extraPros === null || extraPros === void 0 ? void 0 : extraPros.alt) || type)) {
|
|
808
|
+
return EditorUtils.createImageNode(src, altText, urlParams, extraPros);
|
|
809
|
+
}
|
|
810
|
+
return EditorUtils.createGenericMediaNode(src, type, extraPros);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
console.error('Error creating media node:', error, src);
|
|
813
|
+
return EditorUtils.createGenericMediaNode(src, type, extraPros);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
key: "normalizeUrl",
|
|
819
|
+
value: /**
|
|
573
820
|
* 标准化URL,添加协议前缀
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
821
|
+
*/ function normalizeUrl(src) {
|
|
822
|
+
if (src.match(/^(https?:\/\/|data:|file:)/)) {
|
|
823
|
+
return src;
|
|
824
|
+
}
|
|
825
|
+
var origin = window.location.origin || '';
|
|
826
|
+
return src.startsWith('/') ? "".concat(origin).concat(src) : "".concat(origin, "/").concat(src);
|
|
827
|
+
}
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
key: "parseUrlParams",
|
|
831
|
+
value: /**
|
|
583
832
|
* 解析URL参数
|
|
584
|
-
*/
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
833
|
+
*/ function parseUrlParams(url) {
|
|
834
|
+
try {
|
|
835
|
+
return new URL(url).searchParams;
|
|
836
|
+
} catch (e) {
|
|
837
|
+
return new URLSearchParams();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
key: "isImageType",
|
|
843
|
+
value: /**
|
|
593
844
|
* 检查是否为图片类型
|
|
594
|
-
*/
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
*/
|
|
601
|
-
static createImageNode(src, altText, urlParams, extraPros) {
|
|
602
|
-
return {
|
|
603
|
-
type: "card",
|
|
604
|
-
block: urlParams.get("block") || false,
|
|
605
|
-
children: [
|
|
845
|
+
*/ function isImageType(src, alt) {
|
|
846
|
+
return [
|
|
847
|
+
'image'
|
|
848
|
+
].includes(getMediaType(src, alt));
|
|
849
|
+
}
|
|
850
|
+
},
|
|
606
851
|
{
|
|
607
|
-
|
|
608
|
-
|
|
852
|
+
key: "createImageNode",
|
|
853
|
+
value: /**
|
|
854
|
+
* 创建图片节点
|
|
855
|
+
*/ function createImageNode(src, altText, urlParams, extraPros) {
|
|
856
|
+
return {
|
|
857
|
+
type: 'card',
|
|
858
|
+
block: urlParams.get('block') || false,
|
|
859
|
+
children: [
|
|
860
|
+
{
|
|
861
|
+
type: 'card-before',
|
|
862
|
+
children: [
|
|
863
|
+
{
|
|
864
|
+
text: ''
|
|
865
|
+
}
|
|
866
|
+
]
|
|
867
|
+
},
|
|
868
|
+
_object_spread_props(_object_spread({}, extraPros || {}), {
|
|
869
|
+
block: urlParams.get('block') || false,
|
|
870
|
+
type: 'image',
|
|
871
|
+
url: src,
|
|
872
|
+
mediaType: 'image',
|
|
873
|
+
alt: altText,
|
|
874
|
+
width: urlParams.get('width') || undefined,
|
|
875
|
+
height: urlParams.get('height') || undefined,
|
|
876
|
+
children: [
|
|
877
|
+
{
|
|
878
|
+
text: ''
|
|
879
|
+
}
|
|
880
|
+
]
|
|
881
|
+
}),
|
|
882
|
+
{
|
|
883
|
+
type: 'card-after',
|
|
884
|
+
children: [
|
|
885
|
+
{
|
|
886
|
+
text: ''
|
|
887
|
+
}
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
]
|
|
891
|
+
};
|
|
892
|
+
}
|
|
609
893
|
},
|
|
610
|
-
__spreadProps(__spreadValues({}, extraPros || {}), {
|
|
611
|
-
block: urlParams.get("block") || false,
|
|
612
|
-
type: "image",
|
|
613
|
-
url: src,
|
|
614
|
-
mediaType: "image",
|
|
615
|
-
alt: altText,
|
|
616
|
-
width: urlParams.get("width") || void 0,
|
|
617
|
-
height: urlParams.get("height") || void 0,
|
|
618
|
-
children: [{ text: "" }]
|
|
619
|
-
}),
|
|
620
894
|
{
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
]
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
895
|
+
key: "createGenericMediaNode",
|
|
896
|
+
value: /**
|
|
628
897
|
* 创建通用媒体节点
|
|
629
|
-
*/
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
898
|
+
*/ function createGenericMediaNode(src, type, extraPros) {
|
|
899
|
+
return {
|
|
900
|
+
type: 'card',
|
|
901
|
+
children: [
|
|
902
|
+
{
|
|
903
|
+
type: 'card-before',
|
|
904
|
+
children: [
|
|
905
|
+
{
|
|
906
|
+
text: ''
|
|
907
|
+
}
|
|
908
|
+
]
|
|
909
|
+
},
|
|
910
|
+
_object_spread_props(_object_spread({}, extraPros || {}), {
|
|
911
|
+
type: 'media',
|
|
912
|
+
url: src,
|
|
913
|
+
children: [
|
|
914
|
+
{
|
|
915
|
+
text: ''
|
|
916
|
+
}
|
|
917
|
+
],
|
|
918
|
+
mediaType: type
|
|
919
|
+
}),
|
|
920
|
+
{
|
|
921
|
+
type: 'card-after',
|
|
922
|
+
children: [
|
|
923
|
+
{
|
|
924
|
+
text: ''
|
|
925
|
+
}
|
|
926
|
+
]
|
|
927
|
+
}
|
|
928
|
+
]
|
|
929
|
+
};
|
|
930
|
+
}
|
|
637
931
|
},
|
|
638
|
-
__spreadProps(__spreadValues({}, extraPros || {}), {
|
|
639
|
-
type: "media",
|
|
640
|
-
url: src,
|
|
641
|
-
children: [{ text: "" }],
|
|
642
|
-
mediaType: type
|
|
643
|
-
}),
|
|
644
932
|
{
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
]
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
933
|
+
key: "wrapperCardNode",
|
|
934
|
+
value: /**
|
|
652
935
|
* 用卡片节点包装普通节点
|
|
653
936
|
*
|
|
654
937
|
* @param node - 要包装的节点
|
|
655
938
|
* @param props - 额外属性
|
|
656
939
|
* @returns 包装后的卡片节点
|
|
657
|
-
*/
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
940
|
+
*/ function wrapperCardNode(node) {
|
|
941
|
+
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
942
|
+
return _object_spread_props(_object_spread({
|
|
943
|
+
type: 'card'
|
|
944
|
+
}, props), {
|
|
945
|
+
children: [
|
|
946
|
+
{
|
|
947
|
+
type: 'card-before',
|
|
948
|
+
children: [
|
|
949
|
+
{
|
|
950
|
+
text: ''
|
|
951
|
+
}
|
|
952
|
+
]
|
|
953
|
+
},
|
|
954
|
+
node,
|
|
955
|
+
{
|
|
956
|
+
type: 'card-after',
|
|
957
|
+
children: [
|
|
958
|
+
{
|
|
959
|
+
text: ''
|
|
960
|
+
}
|
|
961
|
+
]
|
|
962
|
+
}
|
|
963
|
+
]
|
|
964
|
+
});
|
|
965
|
+
}
|
|
671
966
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
};
|
|
676
|
-
var EditorUtils = _EditorUtils;
|
|
967
|
+
]);
|
|
968
|
+
return EditorUtils;
|
|
969
|
+
}();
|
|
677
970
|
// 可清除的文本格式属性
|
|
678
|
-
EditorUtils
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
];
|
|
971
|
+
_define_property(EditorUtils, "CLEARABLE_MARKS", [
|
|
972
|
+
'url',
|
|
973
|
+
'strikethrough',
|
|
974
|
+
'italic',
|
|
975
|
+
'code',
|
|
976
|
+
'bold',
|
|
977
|
+
'color',
|
|
978
|
+
'textColor',
|
|
979
|
+
'highColor'
|
|
980
|
+
]);
|
|
688
981
|
/**
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
|
|
982
|
+
* 替换编辑器中当前选中的节点
|
|
983
|
+
*
|
|
984
|
+
* @param editor - 编辑器实例
|
|
985
|
+
* @param newNode - 要插入的新节点数组
|
|
986
|
+
*
|
|
987
|
+
* @description
|
|
988
|
+
* 该方法会查找当前选区中的最低块级节点,然后用新的节点替换它。
|
|
989
|
+
* 替换过程包括:查找最低块级节点,选中整个节点,插入新节点来替换原内容。
|
|
990
|
+
*/ _define_property(EditorUtils, "replaceSelectedNode", function(editor, newNode) {
|
|
991
|
+
var nodeEntries = Array.from(Editor.nodes(editor, {
|
|
992
|
+
mode: 'lowest'
|
|
993
|
+
}));
|
|
994
|
+
if (nodeEntries.length === 0) {
|
|
995
|
+
// 如果没有选中节点,则直接插入新节点
|
|
996
|
+
Transforms.insertNodes(editor, newNode);
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 2), node = _nodeEntries_[0], path = _nodeEntries_[1];
|
|
1000
|
+
if (Text.isText(node) && node.text === '') {
|
|
1001
|
+
// 如果是空文本节点,则操作其父节点
|
|
1002
|
+
var parentPath = Path.parent(path);
|
|
1003
|
+
Transforms.removeNodes(editor, {
|
|
1004
|
+
at: parentPath
|
|
1005
|
+
});
|
|
1006
|
+
Transforms.insertNodes(editor, newNode, {
|
|
1007
|
+
at: parentPath,
|
|
1008
|
+
select: true
|
|
1009
|
+
});
|
|
1010
|
+
} else {
|
|
1011
|
+
// 直接插入新节点
|
|
1012
|
+
Transforms.insertNodes(editor, newNode, {
|
|
1013
|
+
select: true
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
export var getDefaultView = function(value) {
|
|
1018
|
+
return value && value.ownerDocument && value.ownerDocument.defaultView || null;
|
|
724
1019
|
};
|
|
725
|
-
var isDOMNode = (value)
|
|
726
|
-
|
|
727
|
-
|
|
1020
|
+
export var isDOMNode = function(value) {
|
|
1021
|
+
var window1 = getDefaultView(value);
|
|
1022
|
+
return !!window1 && value instanceof window1.Node;
|
|
728
1023
|
};
|
|
729
|
-
var isEventHandled = (event, handler)
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
1024
|
+
export var isEventHandled = function(event, handler) {
|
|
1025
|
+
if (!handler) {
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
handler(event);
|
|
1029
|
+
return event.isDefaultPrevented() || event.isPropagationStopped();
|
|
735
1030
|
};
|
|
736
|
-
var hasTarget = (editor, target)
|
|
737
|
-
|
|
1031
|
+
export var hasTarget = function(editor, target) {
|
|
1032
|
+
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
|
|
738
1033
|
};
|
|
739
1034
|
function checkText(domPoint) {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1035
|
+
var _domPoint_parentElement;
|
|
1036
|
+
if (!isDOMNode(domPoint)) {
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
var leafNode = domPoint === null || domPoint === void 0 ? void 0 : (_domPoint_parentElement = domPoint.parentElement) === null || _domPoint_parentElement === void 0 ? void 0 : _domPoint_parentElement.closest('[data-slate-leaf]');
|
|
1040
|
+
if (!leafNode) {
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
var textNode = leafNode.closest('[data-slate-node="text"]');
|
|
1044
|
+
return !!textNode;
|
|
750
1045
|
}
|
|
751
|
-
var isTargetInsideVoid = (editor, target)
|
|
752
|
-
|
|
753
|
-
|
|
1046
|
+
export var isTargetInsideVoid = function(editor, target) {
|
|
1047
|
+
var slateNode = hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target);
|
|
1048
|
+
// @ts-ignore
|
|
1049
|
+
return Editor.isVoid(editor, slateNode);
|
|
754
1050
|
};
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
if (
|
|
765
|
-
|
|
1051
|
+
/**
|
|
1052
|
+
* 基于 anchorNode 和 focusNode 创建新的 DOM Selection 对象
|
|
1053
|
+
*
|
|
1054
|
+
* @param anchorNode - 选区起始节点
|
|
1055
|
+
* @param anchorOffset - 起始节点中的偏移量
|
|
1056
|
+
* @param focusNode - 选区结束节点
|
|
1057
|
+
* @param focusOffset - 结束节点中的偏移量
|
|
1058
|
+
* @returns 新创建的 Selection 对象,如果创建失败则返回 null
|
|
1059
|
+
*/ export function createSelectionFromNodes(anchorNode, anchorOffset, focusNode, focusOffset) {
|
|
1060
|
+
if (typeof window === 'undefined') {
|
|
1061
|
+
return null;
|
|
1062
|
+
}
|
|
1063
|
+
if (!anchorNode || !focusNode) {
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
try {
|
|
1067
|
+
var selection = window.getSelection();
|
|
1068
|
+
if (!selection) {
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1071
|
+
// 清除当前选区
|
|
1072
|
+
selection.removeAllRanges();
|
|
1073
|
+
// 使用 setBaseAndExtent 方法创建新的选区
|
|
1074
|
+
selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
1075
|
+
return selection;
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
console.error('创建 Selection 对象失败:', error);
|
|
1078
|
+
return null;
|
|
766
1079
|
}
|
|
767
|
-
selection.removeAllRanges();
|
|
768
|
-
selection.setBaseAndExtent(
|
|
769
|
-
anchorNode,
|
|
770
|
-
anchorOffset,
|
|
771
|
-
focusNode,
|
|
772
|
-
focusOffset
|
|
773
|
-
);
|
|
774
|
-
return selection;
|
|
775
|
-
} catch (error) {
|
|
776
|
-
console.error("创建 Selection 对象失败:", error);
|
|
777
|
-
return null;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
function createDomRangeFromNodes(anchorNode, anchorOffset, focusNode, focusOffset) {
|
|
781
|
-
if (typeof window === "undefined") {
|
|
782
|
-
return null;
|
|
783
|
-
}
|
|
784
|
-
if (!anchorNode || !focusNode) {
|
|
785
|
-
return null;
|
|
786
|
-
}
|
|
787
|
-
try {
|
|
788
|
-
const range = document.createRange();
|
|
789
|
-
range.setStart(anchorNode, anchorOffset);
|
|
790
|
-
range.setEnd(focusNode, focusOffset);
|
|
791
|
-
return range;
|
|
792
|
-
} catch (error) {
|
|
793
|
-
console.error("创建 DOM Range 对象失败:", error);
|
|
794
|
-
return null;
|
|
795
|
-
}
|
|
796
1080
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
1081
|
+
/**
|
|
1082
|
+
* 基于 anchorNode 和 focusNode 创建 DOM Range 对象
|
|
1083
|
+
*
|
|
1084
|
+
* @param anchorNode - 选区起始节点
|
|
1085
|
+
* @param anchorOffset - 起始节点中的偏移量
|
|
1086
|
+
* @param focusNode - 选区结束节点
|
|
1087
|
+
* @param focusOffset - 结束节点中的偏移量
|
|
1088
|
+
* @returns 新创建的 DOM Range 对象,如果创建失败则返回 null
|
|
1089
|
+
*/ export function createDomRangeFromNodes(anchorNode, anchorOffset, focusNode, focusOffset) {
|
|
1090
|
+
if (typeof window === 'undefined') {
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
if (!anchorNode || !focusNode) {
|
|
1094
|
+
return null;
|
|
1095
|
+
}
|
|
1096
|
+
try {
|
|
1097
|
+
var range = document.createRange();
|
|
1098
|
+
range.setStart(anchorNode, anchorOffset);
|
|
1099
|
+
range.setEnd(focusNode, focusOffset);
|
|
1100
|
+
return range;
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
console.error('创建 DOM Range 对象失败:', error);
|
|
1103
|
+
return null;
|
|
1104
|
+
}
|
|
801
1105
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
} catch (error) {
|
|
812
|
-
console.error("创建并转换 Range 失败:", error);
|
|
813
|
-
return null;
|
|
814
|
-
}
|
|
1106
|
+
/**
|
|
1107
|
+
* 检查节点是否可选择
|
|
1108
|
+
*
|
|
1109
|
+
* @param editor - React 编辑器实例
|
|
1110
|
+
* @param node - 待检查的节点
|
|
1111
|
+
* @returns 节点是否可选择
|
|
1112
|
+
*/ function isNodeSelectable(editor, node) {
|
|
1113
|
+
if (!node) return false;
|
|
1114
|
+
return hasTarget(editor, node) || isTargetInsideVoid(editor, node);
|
|
815
1115
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1116
|
+
/**
|
|
1117
|
+
* 创建并转换 Range 对象
|
|
1118
|
+
*
|
|
1119
|
+
* @param editor - React 编辑器实例
|
|
1120
|
+
* @param anchorNode - 起始节点
|
|
1121
|
+
* @param focusNode - 结束节点
|
|
1122
|
+
* @param originalRange - 原始 Range 对象
|
|
1123
|
+
* @returns 转换后的 Slate Range
|
|
1124
|
+
*/ function createAndConvertRange(editor, anchorNode, focusNode, originalRange) {
|
|
1125
|
+
try {
|
|
1126
|
+
// 创建新的 DOM Range
|
|
1127
|
+
var domRange = document.createRange();
|
|
1128
|
+
// 使用原始 Range 的偏移量,确保精确性
|
|
1129
|
+
domRange.setStart(anchorNode, originalRange.startOffset);
|
|
1130
|
+
domRange.setEnd(focusNode, originalRange.endOffset);
|
|
1131
|
+
// 转换为 Slate Range
|
|
1132
|
+
return ReactEditor.toSlateRange(editor, domRange, {
|
|
1133
|
+
exactMatch: true,
|
|
1134
|
+
suppressThrow: false
|
|
1135
|
+
});
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
console.error('创建并转换 Range 失败:', error);
|
|
1138
|
+
return null;
|
|
824
1139
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* 从 DOM Selection 对象中提取并转换为 Slate Range
|
|
1143
|
+
*
|
|
1144
|
+
* @param editor - React 编辑器实例
|
|
1145
|
+
* @param domSelection - DOM Selection 对象
|
|
1146
|
+
* @returns 转换后的 Slate Range 对象,如果转换失败则返回 null
|
|
1147
|
+
*/ export function getSelectionFromDomSelection(editor, domSelection) {
|
|
1148
|
+
// 检查 Selection 是否有有效的 Range
|
|
1149
|
+
if (!domSelection.rangeCount || domSelection.rangeCount === 0) {
|
|
1150
|
+
return null;
|
|
829
1151
|
}
|
|
830
|
-
|
|
831
|
-
|
|
1152
|
+
try {
|
|
1153
|
+
var range = domSelection.getRangeAt(0);
|
|
1154
|
+
if (!range) {
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
// 获取起始和结束容器节点
|
|
1158
|
+
var anchorNode = range.startContainer;
|
|
1159
|
+
var focusNode = range.endContainer;
|
|
1160
|
+
// 验证节点是否可选择
|
|
1161
|
+
if (!isNodeSelectable(editor, anchorNode) || !isNodeSelectable(editor, focusNode)) {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
// 验证文本节点
|
|
1165
|
+
if (!checkText(anchorNode) || !checkText(focusNode)) {
|
|
1166
|
+
return null;
|
|
1167
|
+
}
|
|
1168
|
+
// 创建新的 Range 并转换
|
|
1169
|
+
return createAndConvertRange(editor, anchorNode, focusNode, range);
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
console.error('getSelectionFromDomSelection error:', error);
|
|
1172
|
+
return null;
|
|
832
1173
|
}
|
|
833
|
-
return createAndConvertRange(editor, anchorNode, focusNode, range);
|
|
834
|
-
} catch (error) {
|
|
835
|
-
console.error("getSelectionFromDomSelection error:", error);
|
|
836
|
-
return null;
|
|
837
|
-
}
|
|
838
1174
|
}
|
|
839
|
-
|
|
840
|
-
|
|
1175
|
+
/**
|
|
1176
|
+
* 检查目标是否为可编辑的 DOM 节点。
|
|
1177
|
+
*
|
|
1178
|
+
* @param editor - React 编辑器实例。
|
|
1179
|
+
* @param target - 事件目标,可能为 null。
|
|
1180
|
+
* @returns 如果目标是可编辑的 DOM 节点,则返回 true。
|
|
1181
|
+
*/ export var hasEditableTarget = function(editor, target) {
|
|
1182
|
+
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target, {
|
|
1183
|
+
editable: true
|
|
1184
|
+
});
|
|
841
1185
|
};
|
|
842
|
-
function getPointStrOffset(editor, point) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
1186
|
+
export function getPointStrOffset(editor, point) {
|
|
1187
|
+
var nodes = Node.fragment(editor, {
|
|
1188
|
+
anchor: {
|
|
1189
|
+
path: Node.first(editor, point.path)[1],
|
|
1190
|
+
offset: 0
|
|
1191
|
+
},
|
|
1192
|
+
focus: point
|
|
1193
|
+
});
|
|
1194
|
+
var str = Node.string({
|
|
1195
|
+
type: '',
|
|
1196
|
+
children: nodes
|
|
1197
|
+
});
|
|
1198
|
+
return str.length;
|
|
852
1199
|
}
|
|
853
|
-
function getRelativePath(path, anther) {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}
|
|
863
|
-
const relativePath = [];
|
|
864
|
-
for (let i = 0; i < newPath.length; i++) {
|
|
865
|
-
if (newPath[i] !== newAnther[i]) {
|
|
866
|
-
relativePath.push(newPath[i] - newAnther[i]);
|
|
867
|
-
} else {
|
|
868
|
-
relativePath.push(0);
|
|
1200
|
+
export function getRelativePath(path, anther) {
|
|
1201
|
+
var newPath = _to_consumable_array(path);
|
|
1202
|
+
var newAnther = _to_consumable_array(anther);
|
|
1203
|
+
var relativeLen = path.length - anther.length;
|
|
1204
|
+
if (relativeLen > 0) {
|
|
1205
|
+
newAnther.unshift(new Array(relativeLen).fill(0));
|
|
1206
|
+
} else if (relativeLen < 0) {
|
|
1207
|
+
return new Array(anther.length).fill(0);
|
|
1208
|
+
newPath.unshift(new Array(-relativeLen).fill(0));
|
|
869
1209
|
}
|
|
870
|
-
|
|
871
|
-
|
|
1210
|
+
var relativePath = [];
|
|
1211
|
+
for(var i = 0; i < newPath.length; i++){
|
|
1212
|
+
if (newPath[i] !== newAnther[i]) {
|
|
1213
|
+
relativePath.push(newPath[i] - newAnther[i]);
|
|
1214
|
+
} else {
|
|
1215
|
+
relativePath.push(0);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
return relativePath;
|
|
872
1219
|
}
|
|
873
|
-
function calcPath(path, anther) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1220
|
+
export function calcPath(path, anther) {
|
|
1221
|
+
var newPath = _to_consumable_array(path);
|
|
1222
|
+
var newAnther = _to_consumable_array(anther);
|
|
1223
|
+
var relativeLen = path.length - anther.length;
|
|
1224
|
+
if (relativeLen > 0) {
|
|
1225
|
+
newAnther.unshift(new Array(relativeLen).fill(0));
|
|
1226
|
+
} else if (relativeLen < 0) {
|
|
1227
|
+
newPath.unshift(new Array(-relativeLen).fill(0));
|
|
1228
|
+
}
|
|
1229
|
+
var relativePath = [];
|
|
1230
|
+
for(var i = 0; i < newPath.length; i++){
|
|
1231
|
+
relativePath.push(newPath[i] + newAnther[i]);
|
|
1232
|
+
}
|
|
1233
|
+
return relativePath;
|
|
887
1234
|
}
|
|
888
|
-
function isPath(path) {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1235
|
+
export function isPath(path) {
|
|
1236
|
+
for(var i = 0; i < path.length; i++){
|
|
1237
|
+
var num = path[i];
|
|
1238
|
+
if (!(isFinite(num) && num >= 0)) {
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
893
1241
|
}
|
|
894
|
-
|
|
895
|
-
return true;
|
|
1242
|
+
return true;
|
|
896
1243
|
}
|
|
897
|
-
function findLeafPath(editor, path) {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
return
|
|
903
|
-
return node[1];
|
|
1244
|
+
export function findLeafPath(editor, path) {
|
|
1245
|
+
var node = Editor.leaf(editor, path, {
|
|
1246
|
+
edge: 'end'
|
|
1247
|
+
});
|
|
1248
|
+
if (!node) return path;
|
|
1249
|
+
return node[1];
|
|
904
1250
|
}
|
|
905
|
-
|
|
906
|
-
|
|
1251
|
+
/**
|
|
1252
|
+
* 转义正则表达式特殊字符
|
|
1253
|
+
*
|
|
1254
|
+
* @param string - 需要转义的字符串
|
|
1255
|
+
* @returns 转义后的字符串
|
|
1256
|
+
* @private
|
|
1257
|
+
*/ export function escapeRegExp(string) {
|
|
1258
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
907
1259
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1260
|
+
/**
|
|
1261
|
+
* 清理和标准化 Markdown 搜索文本
|
|
1262
|
+
*
|
|
1263
|
+
* @param searchText - 原始搜索文本,可能包含 Markdown 语法
|
|
1264
|
+
* @returns 包含原文本和清理后文本的数组
|
|
1265
|
+
* @public
|
|
1266
|
+
*/ export function normalizeMarkdownSearchText(searchText) {
|
|
1267
|
+
if (!searchText.trim()) return [];
|
|
1268
|
+
var searchVariants = new Set();
|
|
1269
|
+
// 添加原始文本
|
|
1270
|
+
searchVariants.add(searchText.trim());
|
|
1271
|
+
// 移除常见的 Markdown 语法
|
|
1272
|
+
var cleanText = searchText// 移除图片语法  -> alt (必须在链接语法之前处理)
|
|
1273
|
+
.replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1')// 移除链接语法 [text](url) -> text
|
|
1274
|
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')// 移除粗体语法 **text** 或 __text__ -> text
|
|
1275
|
+
.replace(/\*\*(.*?)\*\*/g, '$1').replace(/__(.*?)__/g, '$1')// 移除斜体语法 *text* 或 _text_ -> text
|
|
1276
|
+
.replace(/\*(.*?)\*/g, '$1').replace(/_(.*?)_/g, '$1')// 移除行内代码语法 `code` -> code
|
|
1277
|
+
.replace(/`([^`]+)`/g, '$1')// 移除删除线语法 ~~text~~ -> text
|
|
1278
|
+
.replace(/~~(.*?)~~/g, '$1')// 移除标题语法 # text -> text
|
|
1279
|
+
.replace(/^#+\s+(.*)$/gm, '$1')// 移除引用语法 > text -> text
|
|
1280
|
+
.replace(/^>\s*(.*)$/gm, '$1')// 移除列表标记 - text 或 * text 或 + text -> text
|
|
1281
|
+
.replace(/^[\s]*[-*+]\s+(.*)$/gm, '$1')// 移除有序列表标记 1. text -> text
|
|
1282
|
+
.replace(/^\s*\d+\.\s+(.*)$/gm, '$1').trim();
|
|
1283
|
+
if (cleanText && cleanText !== searchText.trim()) {
|
|
1284
|
+
searchVariants.add(cleanText);
|
|
1285
|
+
}
|
|
1286
|
+
// 如果清理后的文本包含多个单词,也添加每个单词
|
|
1287
|
+
var words = cleanText.split(/\s+/).filter(function(word) {
|
|
1288
|
+
return word.length > 1;
|
|
1289
|
+
});
|
|
1290
|
+
if (words.length > 1) {
|
|
1291
|
+
words.forEach(function(word) {
|
|
1292
|
+
return searchVariants.add(word);
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
// 移除空字符串
|
|
1296
|
+
return Array.from(searchVariants).filter(function(text) {
|
|
1297
|
+
return text.length > 0;
|
|
1298
|
+
});
|
|
922
1299
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1300
|
+
/**
|
|
1301
|
+
* 在编辑器中按路径和文本搜索内容,支持 Markdown 文本的智能处理
|
|
1302
|
+
*
|
|
1303
|
+
* @param editor - 编辑器实例
|
|
1304
|
+
* @param pathDescription - 搜索范围的路径描述
|
|
1305
|
+
* @param searchText - 搜索文本,支持 Markdown 语法
|
|
1306
|
+
* @param options - 搜索选项
|
|
1307
|
+
* @param options.caseSensitive - 是否区分大小写,默认 false
|
|
1308
|
+
* @param options.wholeWord - 是否全词匹配,默认 false
|
|
1309
|
+
* @param options.maxResults - 最大结果数量,默认 2
|
|
1310
|
+
* @param options.includeMarkdownVariants - 是否包含 Markdown 语法的清理变体,默认 true
|
|
1311
|
+
* @returns 搜索结果数组,包含路径、范围、节点、链接信息等
|
|
1312
|
+
*
|
|
1313
|
+
* @description
|
|
1314
|
+
* 该函数支持以下功能:
|
|
1315
|
+
* - 自动清理 Markdown 语法(链接、粗体、斜体、代码等)
|
|
1316
|
+
* - 生成多个搜索变体以提高匹配率
|
|
1317
|
+
* - 避免重复匹配同一位置的文本
|
|
1318
|
+
* - 记录匹配的搜索变体信息
|
|
1319
|
+
* - 支持识别链接(a 标签):返回结果包含 isLink 和 linkUrl 字段
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* // 搜索包含 Markdown 语法的文本
|
|
1323
|
+
* const results = findByPathAndText(editor, [0], "**粗体文本**");
|
|
1324
|
+
* // 将同时匹配 "**粗体文本**" 和 "粗体文本"
|
|
1325
|
+
*
|
|
1326
|
+
* @example
|
|
1327
|
+
* // 搜索链接文本
|
|
1328
|
+
* const results = findByPathAndText(editor, [0], "点击这里");
|
|
1329
|
+
* // 如果匹配到的是链接,results[0].isLink === true 且 results[0].linkUrl 包含 URL
|
|
1330
|
+
*/ export function findByPathAndText(editor, pathDescription, searchText) {
|
|
1331
|
+
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1332
|
+
var _options_caseSensitive = options.caseSensitive, caseSensitive = _options_caseSensitive === void 0 ? false : _options_caseSensitive, _options_wholeWord = options.wholeWord, wholeWord = _options_wholeWord === void 0 ? false : _options_wholeWord, _options_maxResults = options.maxResults, maxResults = _options_maxResults === void 0 ? 2 : _options_maxResults, _options_includeMarkdownVariants = options.includeMarkdownVariants, includeMarkdownVariants = _options_includeMarkdownVariants === void 0 ? true : _options_includeMarkdownVariants;
|
|
1333
|
+
if (!searchText.trim()) return [];
|
|
1334
|
+
var results = [];
|
|
1335
|
+
// 获取所有搜索变体
|
|
1336
|
+
var searchVariants = includeMarkdownVariants ? normalizeMarkdownSearchText(searchText) : [
|
|
1337
|
+
searchText.trim()
|
|
1338
|
+
];
|
|
1339
|
+
if (searchVariants.length === 0) return [];
|
|
1340
|
+
// 为每个搜索变体创建正则表达式
|
|
1341
|
+
var flags = caseSensitive ? 'g' : 'gi';
|
|
1342
|
+
var patterns = searchVariants.map(function(variant) {
|
|
1343
|
+
return {
|
|
1344
|
+
variant: variant,
|
|
1345
|
+
pattern: wholeWord ? new RegExp("\\b".concat(escapeRegExp(variant), "\\b"), flags) : new RegExp(escapeRegExp(variant), flags)
|
|
1346
|
+
};
|
|
1347
|
+
});
|
|
1348
|
+
try {
|
|
1349
|
+
// 根据 pathDescription 确定搜索范围
|
|
1350
|
+
var searchRange;
|
|
1351
|
+
if (pathDescription && pathDescription.length > 0) {
|
|
1352
|
+
// 路径数组模式:直接在指定路径中搜索
|
|
1353
|
+
try {
|
|
1354
|
+
if (Editor.hasPath(editor, pathDescription)) {
|
|
1355
|
+
searchRange = [
|
|
1356
|
+
pathDescription
|
|
1357
|
+
];
|
|
1358
|
+
}
|
|
1359
|
+
} catch (e) {
|
|
1360
|
+
console.debug('无效的搜索路径:', pathDescription, e);
|
|
1361
|
+
searchRange = undefined;
|
|
1362
|
+
}
|
|
947
1363
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
searchRange
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1364
|
+
// 获取文本节点
|
|
1365
|
+
var textNodesGenerator;
|
|
1366
|
+
if (searchRange && searchRange.length > 0) {
|
|
1367
|
+
// 在指定路径范围内搜索
|
|
1368
|
+
var allTextNodes = [];
|
|
1369
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1370
|
+
try {
|
|
1371
|
+
for(var _iterator = searchRange[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1372
|
+
var rangePath = _step.value;
|
|
1373
|
+
try {
|
|
1374
|
+
var _allTextNodes;
|
|
1375
|
+
var rangeNodes = Array.from(Editor.nodes(editor, {
|
|
1376
|
+
at: rangePath,
|
|
1377
|
+
match: function(n) {
|
|
1378
|
+
return Text.isText(n) && typeof n.text === 'string' && n.text.length > 0;
|
|
1379
|
+
}
|
|
1380
|
+
}));
|
|
1381
|
+
(_allTextNodes = allTextNodes).push.apply(_allTextNodes, _to_consumable_array(rangeNodes));
|
|
1382
|
+
} catch (e) {
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
} catch (err) {
|
|
1387
|
+
_didIteratorError = true;
|
|
1388
|
+
_iteratorError = err;
|
|
1389
|
+
} finally{
|
|
1390
|
+
try {
|
|
1391
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1392
|
+
_iterator.return();
|
|
1393
|
+
}
|
|
1394
|
+
} finally{
|
|
1395
|
+
if (_didIteratorError) {
|
|
1396
|
+
throw _iteratorError;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
textNodesGenerator = allTextNodes;
|
|
1401
|
+
} else {
|
|
1402
|
+
// 在整个编辑器中搜索
|
|
1403
|
+
textNodesGenerator = Array.from(Editor.nodes(editor, {
|
|
1404
|
+
at: [],
|
|
1405
|
+
match: function(n) {
|
|
1406
|
+
return Text.isText(n) && typeof n.text === 'string' && n.text.length > 0;
|
|
1407
|
+
}
|
|
1408
|
+
}));
|
|
967
1409
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1410
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
1411
|
+
try {
|
|
1412
|
+
var _loop = function() {
|
|
1413
|
+
var _step_value = _sliced_to_array(_step1.value, 2), node = _step_value[0], path = _step_value[1];
|
|
1414
|
+
if (!Text.isText(node) || !node.text) return "continue";
|
|
1415
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1416
|
+
try {
|
|
1417
|
+
// 对每个搜索变体进行匹配
|
|
1418
|
+
for(var _iterator = patterns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1419
|
+
var _loop = function() {
|
|
1420
|
+
// 获取父节点信息
|
|
1421
|
+
var lineContent = node.text;
|
|
1422
|
+
var nodeType = 'text';
|
|
1423
|
+
try {
|
|
1424
|
+
var parentPath = Path.parent(path);
|
|
1425
|
+
if (Editor.hasPath(editor, parentPath)) {
|
|
1426
|
+
var parent = Node.get(editor, parentPath);
|
|
1427
|
+
if (Element.isElement(parent)) {
|
|
1428
|
+
lineContent = Node.string(parent);
|
|
1429
|
+
nodeType = parent.type || 'unknown';
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
} catch (e) {
|
|
1433
|
+
// 如果获取父节点失败,使用原始文本
|
|
1434
|
+
}
|
|
1435
|
+
var matchIndex = match.index;
|
|
1436
|
+
var matchLength = match[0].length;
|
|
1437
|
+
var matchText = match[0];
|
|
1438
|
+
var range = {
|
|
1439
|
+
anchor: {
|
|
1440
|
+
path: path,
|
|
1441
|
+
offset: matchIndex
|
|
1442
|
+
},
|
|
1443
|
+
focus: {
|
|
1444
|
+
path: path,
|
|
1445
|
+
offset: matchIndex + matchLength
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
// 检查是否已经有相同位置的匹配结果,避免重复
|
|
1449
|
+
var isDuplicate = results.some(function(result) {
|
|
1450
|
+
return Path.equals(result.path, path) && result.offset.start === matchIndex && result.offset.end === matchIndex + matchLength;
|
|
1451
|
+
});
|
|
1452
|
+
if (!isDuplicate) {
|
|
1453
|
+
// 检查是否为链接节点(带有 url 属性的文本节点)
|
|
1454
|
+
var isLink = Text.isText(node) && !!node.url;
|
|
1455
|
+
var linkUrl = isLink ? node.url : undefined;
|
|
1456
|
+
results.push({
|
|
1457
|
+
path: path,
|
|
1458
|
+
range: range,
|
|
1459
|
+
node: node,
|
|
1460
|
+
matchedText: matchText,
|
|
1461
|
+
offset: {
|
|
1462
|
+
start: matchIndex,
|
|
1463
|
+
end: matchIndex + matchLength
|
|
1464
|
+
},
|
|
1465
|
+
lineContent: lineContent.trim(),
|
|
1466
|
+
nodeType: nodeType,
|
|
1467
|
+
searchVariant: variant !== searchText.trim() ? variant : undefined,
|
|
1468
|
+
isLink: isLink,
|
|
1469
|
+
linkUrl: linkUrl
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
// 限制结果数量避免性能问题
|
|
1473
|
+
if (results.length >= maxResults) return "break";
|
|
1474
|
+
};
|
|
1475
|
+
var _step_value1 = _step.value, variant = _step_value1.variant, pattern = _step_value1.pattern;
|
|
1476
|
+
var match = void 0;
|
|
1477
|
+
pattern.lastIndex = 0;
|
|
1478
|
+
while((match = pattern.exec(node.text)) !== null){
|
|
1479
|
+
var _ret = _loop();
|
|
1480
|
+
if (_ret === "break") break;
|
|
1481
|
+
}
|
|
1482
|
+
if (results.length >= maxResults) break;
|
|
1483
|
+
}
|
|
1484
|
+
} catch (err) {
|
|
1485
|
+
_didIteratorError = true;
|
|
1486
|
+
_iteratorError = err;
|
|
1487
|
+
} finally{
|
|
1488
|
+
try {
|
|
1489
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1490
|
+
_iterator.return();
|
|
1491
|
+
}
|
|
1492
|
+
} finally{
|
|
1493
|
+
if (_didIteratorError) {
|
|
1494
|
+
throw _iteratorError;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
if (results.length >= maxResults) return "break";
|
|
1499
|
+
};
|
|
1500
|
+
// 遍历文本节点查找匹配
|
|
1501
|
+
for(var _iterator1 = textNodesGenerator[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
1502
|
+
var _ret = _loop();
|
|
1503
|
+
if (_ret === "break") break;
|
|
1504
|
+
}
|
|
1505
|
+
} catch (err) {
|
|
1506
|
+
_didIteratorError1 = true;
|
|
1507
|
+
_iteratorError1 = err;
|
|
1508
|
+
} finally{
|
|
1509
|
+
try {
|
|
1510
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
1511
|
+
_iterator1.return();
|
|
1512
|
+
}
|
|
1513
|
+
} finally{
|
|
1514
|
+
if (_didIteratorError1) {
|
|
1515
|
+
throw _iteratorError1;
|
|
1516
|
+
}
|
|
995
1517
|
}
|
|
996
|
-
} catch (e) {
|
|
997
|
-
}
|
|
998
|
-
const matchIndex = match.index;
|
|
999
|
-
const matchLength = match[0].length;
|
|
1000
|
-
const matchText = match[0];
|
|
1001
|
-
const range = {
|
|
1002
|
-
anchor: { path, offset: matchIndex },
|
|
1003
|
-
focus: { path, offset: matchIndex + matchLength }
|
|
1004
|
-
};
|
|
1005
|
-
const isDuplicate = results.some(
|
|
1006
|
-
(result) => Path.equals(result.path, path) && result.offset.start === matchIndex && result.offset.end === matchIndex + matchLength
|
|
1007
|
-
);
|
|
1008
|
-
if (!isDuplicate) {
|
|
1009
|
-
const isLink = Text.isText(node) && !!node.url;
|
|
1010
|
-
const linkUrl = isLink ? node.url : void 0;
|
|
1011
|
-
results.push({
|
|
1012
|
-
path,
|
|
1013
|
-
range,
|
|
1014
|
-
node,
|
|
1015
|
-
matchedText: matchText,
|
|
1016
|
-
offset: {
|
|
1017
|
-
start: matchIndex,
|
|
1018
|
-
end: matchIndex + matchLength
|
|
1019
|
-
},
|
|
1020
|
-
lineContent: lineContent.trim(),
|
|
1021
|
-
nodeType,
|
|
1022
|
-
searchVariant: variant !== searchText.trim() ? variant : void 0,
|
|
1023
|
-
isLink,
|
|
1024
|
-
linkUrl
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
if (results.length >= maxResults)
|
|
1028
|
-
break;
|
|
1029
1518
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
}
|
|
1033
|
-
if (results.length >= maxResults)
|
|
1034
|
-
break;
|
|
1519
|
+
} catch (error) {
|
|
1520
|
+
console.error('查找过程中出错:', error);
|
|
1035
1521
|
}
|
|
1036
|
-
|
|
1037
|
-
console.error("查找过程中出错:", error);
|
|
1038
|
-
}
|
|
1039
|
-
return results;
|
|
1522
|
+
return results;
|
|
1040
1523
|
}
|
|
1041
|
-
export {
|
|
1042
|
-
EditorUtils,
|
|
1043
|
-
calcPath,
|
|
1044
|
-
createDomRangeFromNodes,
|
|
1045
|
-
createSelectionFromNodes,
|
|
1046
|
-
escapeRegExp,
|
|
1047
|
-
findByPathAndText,
|
|
1048
|
-
findLeafPath,
|
|
1049
|
-
getDefaultView,
|
|
1050
|
-
getPointStrOffset,
|
|
1051
|
-
getRelativePath,
|
|
1052
|
-
getSelectionFromDomSelection,
|
|
1053
|
-
hasEditableTarget,
|
|
1054
|
-
hasTarget,
|
|
1055
|
-
isDOMNode,
|
|
1056
|
-
isEventHandled,
|
|
1057
|
-
isPath,
|
|
1058
|
-
isTargetInsideVoid,
|
|
1059
|
-
normalizeMarkdownSearchText
|
|
1060
|
-
};
|