@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,153 +1,300 @@
|
|
|
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 @typescript-eslint/no-this-alias */ /* 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
|
-
|
|
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);
|
|
24
|
+
}
|
|
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;
|
|
41
|
+
}
|
|
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;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
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
|
+
});
|
|
89
|
+
}
|
|
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);
|
|
102
|
+
}
|
|
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));
|
|
109
|
+
} else {
|
|
110
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
111
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
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
|
+
}
|
|
22
130
|
import isEqual from "lodash-es/isEqual";
|
|
23
131
|
import { parse } from "querystring";
|
|
24
132
|
import * as React from "react";
|
|
25
|
-
import {
|
|
26
|
-
Editor,
|
|
27
|
-
Element,
|
|
28
|
-
Node,
|
|
29
|
-
Path,
|
|
30
|
-
Range,
|
|
31
|
-
Text,
|
|
32
|
-
Transforms
|
|
33
|
-
} from "slate";
|
|
133
|
+
import { Editor, Element, Node, Path, Range, Text, Transforms } from "slate";
|
|
34
134
|
import { ReactEditor } from "slate-react";
|
|
35
135
|
import { parserMdToSchema } from "./parser/parserMdToSchema";
|
|
36
136
|
import { parserSlateNodeToMarkdown } from "./utils";
|
|
37
137
|
import { getOffsetLeft, getOffsetTop } from "./utils/dom";
|
|
38
138
|
import { EditorUtils, findByPathAndText } from "./utils/editorUtils";
|
|
39
139
|
import { markdownToHtmlSync } from "./utils/markdownToHtml";
|
|
40
|
-
var
|
|
41
|
-
var EditorStoreContext = createContext(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"paragraph",
|
|
61
|
-
"head",
|
|
62
|
-
"blockquote",
|
|
63
|
-
"code",
|
|
64
|
-
"table",
|
|
65
|
-
"list",
|
|
66
|
-
"media",
|
|
67
|
-
"attach"
|
|
68
|
-
]);
|
|
69
|
-
/** 当前拖拽的元素 */
|
|
70
|
-
this.draggedElement = null;
|
|
71
|
-
this.footnoteDefinitionMap = /* @__PURE__ */ new Map();
|
|
72
|
-
this.inputComposition = false;
|
|
73
|
-
this.domRect = null;
|
|
74
|
-
/** 当前 setMDContent 操作的 AbortController */
|
|
75
|
-
this._currentAbortController = null;
|
|
76
|
-
/**
|
|
77
|
-
* 移除节点
|
|
78
|
-
* @param options
|
|
79
|
-
*/
|
|
80
|
-
this.removeNodes = (options) => {
|
|
81
|
-
Transforms.removeNodes(this._editor.current, options);
|
|
140
|
+
var createContext = React.createContext, useContext = React.useContext;
|
|
141
|
+
export var EditorStoreContext = createContext(null);
|
|
142
|
+
/**
|
|
143
|
+
* 获取编辑器存储上下文的Hook
|
|
144
|
+
*
|
|
145
|
+
* 提供安全的上下文访问,包含默认值处理
|
|
146
|
+
*
|
|
147
|
+
* @returns 编辑器存储上下文对象
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```tsx
|
|
151
|
+
* const { store, readonly, typewriter } = useEditorStore();
|
|
152
|
+
* ```
|
|
153
|
+
*/ export var useEditorStore = function() {
|
|
154
|
+
return useContext(EditorStoreContext) || {
|
|
155
|
+
store: {},
|
|
156
|
+
readonly: true,
|
|
157
|
+
typewriter: false,
|
|
158
|
+
editorProps: {},
|
|
159
|
+
markdownEditorRef: {}
|
|
82
160
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
161
|
+
};
|
|
162
|
+
/** 支持键入操作的标签类型列表 */ var SUPPORT_TYPING_TAG = [
|
|
163
|
+
'table-cell',
|
|
164
|
+
'paragraph',
|
|
165
|
+
'head'
|
|
166
|
+
];
|
|
167
|
+
/**
|
|
168
|
+
* 编辑器核心状态管理类
|
|
169
|
+
*
|
|
170
|
+
* 负责管理编辑器的所有状态、操作和事件处理
|
|
171
|
+
* 包括文档结构、选择状态、高亮、拖拽、历史记录等
|
|
172
|
+
*
|
|
173
|
+
* @class
|
|
174
|
+
*/ export var EditorStore = /*#__PURE__*/ function() {
|
|
175
|
+
"use strict";
|
|
176
|
+
function EditorStore(_editor, plugins, markdownToHtmlOptions) {
|
|
177
|
+
var _this = this;
|
|
178
|
+
_class_call_check(this, EditorStore);
|
|
179
|
+
/** 高亮缓存映射表 */ _define_property(this, "highlightCache", new Map());
|
|
180
|
+
/** 允许进入的元素类型集合 */ _define_property(this, "ableToEnter", new Set([
|
|
181
|
+
'paragraph',
|
|
182
|
+
'head',
|
|
183
|
+
'blockquote',
|
|
184
|
+
'code',
|
|
185
|
+
'table',
|
|
186
|
+
'list',
|
|
187
|
+
'media',
|
|
188
|
+
'attach'
|
|
189
|
+
]));
|
|
190
|
+
/** 当前拖拽的元素 */ _define_property(this, "draggedElement", null);
|
|
191
|
+
_define_property(this, "footnoteDefinitionMap", new Map());
|
|
192
|
+
_define_property(this, "inputComposition", false);
|
|
193
|
+
_define_property(this, "plugins", void 0);
|
|
194
|
+
_define_property(this, "domRect", null);
|
|
195
|
+
_define_property(this, "_editor", void 0);
|
|
196
|
+
/** 当前 setMDContent 操作的 AbortController */ _define_property(this, "_currentAbortController", null);
|
|
197
|
+
_define_property(this, "markdownToHtmlOptions", void 0);
|
|
198
|
+
/**
|
|
199
|
+
* 移除节点
|
|
200
|
+
* @param options
|
|
201
|
+
*/ _define_property(this, "removeNodes", function(options) {
|
|
202
|
+
Transforms.removeNodes(_this._editor.current, options);
|
|
203
|
+
});
|
|
204
|
+
this.dragStart = this.dragStart.bind(this);
|
|
205
|
+
this._editor = _editor;
|
|
206
|
+
this.plugins = plugins;
|
|
207
|
+
this.markdownToHtmlOptions = markdownToHtmlOptions;
|
|
208
|
+
}
|
|
209
|
+
_create_class(EditorStore, [
|
|
210
|
+
{
|
|
211
|
+
key: "editor",
|
|
212
|
+
get: /**
|
|
89
213
|
* 获取当前编辑器实例。
|
|
90
214
|
*
|
|
91
215
|
* @returns 当前的 Slate 编辑器实例。
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
216
|
+
*/ function get() {
|
|
217
|
+
return this._editor.current;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
/**
|
|
97
222
|
* 聚焦到编辑器
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
223
|
+
*/ key: "focus",
|
|
224
|
+
value: function focus() {
|
|
225
|
+
var editor = this._editor.current;
|
|
226
|
+
try {
|
|
227
|
+
// 1. 确保编辑器获得焦点
|
|
228
|
+
setTimeout(function() {
|
|
229
|
+
return ReactEditor.focus(editor);
|
|
230
|
+
}, 0);
|
|
231
|
+
// 2. 处理空文档情况
|
|
232
|
+
if (editor.children.length === 0) {
|
|
233
|
+
var defaultNode = {
|
|
234
|
+
type: 'paragraph',
|
|
235
|
+
children: [
|
|
236
|
+
{
|
|
237
|
+
text: ''
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
};
|
|
241
|
+
Transforms.insertNodes(editor, defaultNode, {
|
|
242
|
+
at: [
|
|
243
|
+
0
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// 3. 获取文档末尾位置
|
|
248
|
+
var end = Editor.end(editor, []);
|
|
249
|
+
// 4. 设置光标位置
|
|
250
|
+
Transforms.select(editor, {
|
|
251
|
+
anchor: end,
|
|
252
|
+
focus: end
|
|
253
|
+
});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error('移动光标失败:', error);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
key: "findLatest",
|
|
261
|
+
value: /**
|
|
117
262
|
* 查找最新的节点索引。
|
|
118
263
|
*
|
|
119
264
|
* @param node - 当前节点。
|
|
120
265
|
* @param index - 当前索引路径。
|
|
121
266
|
* @returns 最新节点的索引路径。
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
267
|
+
*/ function findLatest(node, index) {
|
|
268
|
+
if (Array.isArray(node.children)) {
|
|
269
|
+
if (node.children.length === 1 && (SUPPORT_TYPING_TAG.includes(node.type) || !node.children[0].type)) {
|
|
270
|
+
return index;
|
|
271
|
+
}
|
|
272
|
+
return this.findLatest(node.children[node.children.length - 1], _to_consumable_array(index).concat([
|
|
273
|
+
node.children.length - 1
|
|
274
|
+
]));
|
|
275
|
+
}
|
|
276
|
+
return index;
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
/**
|
|
136
281
|
* 检查给定节点是否是最新节点。用于展示 闪动光标
|
|
137
282
|
*
|
|
138
283
|
* @param node - 要检查的节点。
|
|
139
284
|
* @returns 如果节点是最新节点,则返回 true;否则返回 false。
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
285
|
+
*/ key: "isLatestNode",
|
|
286
|
+
value: function isLatestNode(node) {
|
|
287
|
+
try {
|
|
288
|
+
return this.findLatest(this._editor.current.children.at(-1), [
|
|
289
|
+
this._editor.current.children.length - 1
|
|
290
|
+
]).join('-').startsWith(ReactEditor.findPath(this._editor.current, node).join('-'));
|
|
291
|
+
} catch (error) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
/**
|
|
151
298
|
* 插入一个链接到编辑器中。
|
|
152
299
|
*
|
|
153
300
|
* @param filePath - 要插入的文件路径。如果路径以 'http' 开头,则链接文本为路径本身,否则为文件名。
|
|
@@ -160,71 +307,101 @@ var EditorStore = class {
|
|
|
160
307
|
*
|
|
161
308
|
* 如果当前选区所在的元素节点类型不是 'table-cell' 或 'paragraph',则查找包含当前选区的父级元素节点,
|
|
162
309
|
* 并在其后插入一个包含链接节点的新段落。
|
|
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
|
-
|
|
310
|
+
*/ key: "insertLink",
|
|
311
|
+
value: function insertLink(filePath) {
|
|
312
|
+
var p = parse(filePath);
|
|
313
|
+
var insertPath = filePath;
|
|
314
|
+
var node = {
|
|
315
|
+
text: filePath.startsWith('http') ? filePath : p.name,
|
|
316
|
+
url: insertPath
|
|
317
|
+
};
|
|
318
|
+
var sel = this._editor.current.selection;
|
|
319
|
+
if (!sel || !Range.isCollapsed(sel)) return;
|
|
320
|
+
// @ts-ignore
|
|
321
|
+
var _Editor_nodes = _sliced_to_array(Editor.nodes(this._editor.current, {
|
|
322
|
+
match: function(n) {
|
|
323
|
+
return Element.isElement(n);
|
|
324
|
+
},
|
|
325
|
+
mode: 'lowest'
|
|
326
|
+
}), 1), cur = _Editor_nodes[0];
|
|
327
|
+
if (node.text && [
|
|
328
|
+
'table-cell',
|
|
329
|
+
'paragraph'
|
|
330
|
+
].includes(cur[0].type)) {
|
|
331
|
+
Transforms.insertNodes(this._editor.current, node, {
|
|
332
|
+
select: true
|
|
333
|
+
});
|
|
334
|
+
} else {
|
|
335
|
+
// @ts-ignore
|
|
336
|
+
var _Editor_nodes1 = _sliced_to_array(Editor.nodes(this._editor.current, {
|
|
337
|
+
match: function(n) {
|
|
338
|
+
return Element.isElement(n) && [
|
|
339
|
+
'table',
|
|
340
|
+
'code',
|
|
341
|
+
'head'
|
|
342
|
+
].includes(n.type);
|
|
343
|
+
}
|
|
344
|
+
}), 1), par = _Editor_nodes1[0];
|
|
345
|
+
Transforms.insertNodes(this._editor.current, {
|
|
346
|
+
type: 'paragraph',
|
|
347
|
+
children: [
|
|
348
|
+
node
|
|
349
|
+
]
|
|
350
|
+
}, {
|
|
351
|
+
select: true,
|
|
352
|
+
at: Path.next(par[1])
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
189
356
|
},
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
357
|
+
{
|
|
358
|
+
/**
|
|
195
359
|
* 插入节点到编辑器中。
|
|
196
360
|
*
|
|
197
361
|
* @param nodes - 要插入的节点,可以是单个节点或节点数组。
|
|
198
362
|
* @param options - 可选参数,用于指定插入节点的选项。
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
363
|
+
*/ key: "insertNodes",
|
|
364
|
+
value: function insertNodes(nodes, options) {
|
|
365
|
+
Transforms.insertNodes(this._editor.current, nodes, options);
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
key: "toPath",
|
|
370
|
+
value: /**
|
|
204
371
|
* Converts an HTML element to a Slate path and node.
|
|
205
372
|
*
|
|
206
373
|
* @param el - The HTML element to convert.
|
|
207
374
|
* @returns A tuple containing the path and the corresponding Slate node.
|
|
208
375
|
* @private
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
376
|
+
*/ function toPath(el) {
|
|
377
|
+
var node = ReactEditor.toSlateNode(this._editor.current, el);
|
|
378
|
+
var path = ReactEditor.findPath(this._editor.current, node);
|
|
379
|
+
return [
|
|
380
|
+
path,
|
|
381
|
+
node
|
|
382
|
+
];
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
/**
|
|
216
387
|
* Clears all content from the editor, replacing it with an empty paragraph.
|
|
217
|
-
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
388
|
+
*/ key: "clearContent",
|
|
389
|
+
value: function clearContent() {
|
|
390
|
+
this._editor.current.selection = null;
|
|
391
|
+
this._editor.current.children = [
|
|
392
|
+
{
|
|
393
|
+
type: 'paragraph',
|
|
394
|
+
children: [
|
|
395
|
+
{
|
|
396
|
+
text: ''
|
|
397
|
+
}
|
|
398
|
+
]
|
|
399
|
+
}
|
|
400
|
+
];
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
/**
|
|
228
405
|
* 从 markdown 文本设置编辑器内容
|
|
229
406
|
*
|
|
230
407
|
* @param md - 要设置为编辑器内容的 Markdown 字符串
|
|
@@ -238,109 +415,153 @@ var EditorStore = class {
|
|
|
238
415
|
* - batchSize: 每帧处理的节点数量,默认 50,仅在 useRAF=true 时生效
|
|
239
416
|
* - onProgress: 进度回调函数,接收当前进度 (0-1) 作为参数
|
|
240
417
|
* @returns 如果使用 RAF,返回 Promise;否则同步执行
|
|
241
|
-
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
418
|
+
*/ key: "setMDContent",
|
|
419
|
+
value: function setMDContent(md, plugins, options) {
|
|
420
|
+
if (md === undefined) return;
|
|
421
|
+
// 安全地比较当前内容,避免解析异常导致失效
|
|
422
|
+
try {
|
|
423
|
+
var currentMD = parserSlateNodeToMarkdown(this._editor.current.children);
|
|
424
|
+
// 使用 trim 和规范化比较,避免空白字符差异
|
|
425
|
+
if (md.trim() === currentMD.trim()) return;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
// 如果解析当前内容失败,继续执行设置新内容
|
|
428
|
+
console.warn('Failed to compare current content, proceeding with setMDContent:', error);
|
|
429
|
+
}
|
|
430
|
+
// 取消之前的操作,避免竞态条件
|
|
431
|
+
this.cancelSetMDContent();
|
|
432
|
+
var _options_chunkSize;
|
|
433
|
+
var chunkSize = (_options_chunkSize = options === null || options === void 0 ? void 0 : options.chunkSize) !== null && _options_chunkSize !== void 0 ? _options_chunkSize : 5000;
|
|
434
|
+
var _options_separator;
|
|
435
|
+
var separator = (_options_separator = options === null || options === void 0 ? void 0 : options.separator) !== null && _options_separator !== void 0 ? _options_separator : /\n\n/;
|
|
436
|
+
var _options_useRAF;
|
|
437
|
+
var useRAF = (_options_useRAF = options === null || options === void 0 ? void 0 : options.useRAF) !== null && _options_useRAF !== void 0 ? _options_useRAF : true;
|
|
438
|
+
var _options_batchSize;
|
|
439
|
+
var batchSize = (_options_batchSize = options === null || options === void 0 ? void 0 : options.batchSize) !== null && _options_batchSize !== void 0 ? _options_batchSize : 50;
|
|
440
|
+
var targetPlugins = plugins || this.plugins;
|
|
441
|
+
// 如果内容较短,直接处理
|
|
442
|
+
if (md.length <= chunkSize) {
|
|
443
|
+
try {
|
|
444
|
+
var nodeList = parserMdToSchema(md, targetPlugins).schema;
|
|
445
|
+
this.setContent(nodeList);
|
|
446
|
+
this._editor.current.children = nodeList;
|
|
447
|
+
ReactEditor.deselect(this._editor.current);
|
|
448
|
+
// 调用进度回调
|
|
449
|
+
if (options === null || options === void 0 ? void 0 : options.onProgress) {
|
|
450
|
+
options.onProgress(1);
|
|
451
|
+
}
|
|
452
|
+
} catch (error) {
|
|
453
|
+
console.error('Failed to set MD content:', error);
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
// 内容较长时,按指定分隔符拆分并分批处理
|
|
459
|
+
var chunks = this._splitMarkdown(md, separator);
|
|
460
|
+
// 如果禁用 RAF,使用同步模式处理长内容
|
|
461
|
+
if (!useRAF) {
|
|
462
|
+
try {
|
|
463
|
+
var allNodes = [];
|
|
464
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
465
|
+
try {
|
|
466
|
+
for(var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
467
|
+
var chunk = _step.value;
|
|
468
|
+
if (chunk.trim()) {
|
|
469
|
+
var _allNodes;
|
|
470
|
+
var schema = parserMdToSchema(chunk, targetPlugins).schema;
|
|
471
|
+
(_allNodes = allNodes).push.apply(_allNodes, _to_consumable_array(schema));
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
} catch (err) {
|
|
475
|
+
_didIteratorError = true;
|
|
476
|
+
_iteratorError = err;
|
|
477
|
+
} finally{
|
|
478
|
+
try {
|
|
479
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
480
|
+
_iterator.return();
|
|
481
|
+
}
|
|
482
|
+
} finally{
|
|
483
|
+
if (_didIteratorError) {
|
|
484
|
+
throw _iteratorError;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (allNodes.length > 0) {
|
|
489
|
+
this.setContent(allNodes);
|
|
490
|
+
this._editor.current.children = allNodes;
|
|
491
|
+
ReactEditor.deselect(this._editor.current);
|
|
492
|
+
}
|
|
493
|
+
// 调用进度回调
|
|
494
|
+
if (options === null || options === void 0 ? void 0 : options.onProgress) {
|
|
495
|
+
options.onProgress(1);
|
|
496
|
+
}
|
|
497
|
+
} catch (error) {
|
|
498
|
+
console.error('Failed to set MD content synchronously:', error);
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
// 如果使用 RAF 且分块数量较多,异步解析和插入
|
|
504
|
+
if (chunks.length > 10) {
|
|
505
|
+
// 创建新的 AbortController
|
|
506
|
+
this._currentAbortController = new AbortController();
|
|
507
|
+
return this._parseAndSetContentWithRAF(chunks, targetPlugins || [], batchSize, options === null || options === void 0 ? void 0 : options.onProgress, this._currentAbortController.signal);
|
|
508
|
+
}
|
|
509
|
+
// 如果分块数量 <= 10,使用同步模式处理(修复:之前这里直接返回 undefined)
|
|
510
|
+
try {
|
|
511
|
+
var allNodes1 = [];
|
|
512
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
513
|
+
try {
|
|
514
|
+
for(var _iterator1 = chunks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
515
|
+
var chunk1 = _step1.value;
|
|
516
|
+
if (chunk1.trim()) {
|
|
517
|
+
var _allNodes1;
|
|
518
|
+
var schema1 = parserMdToSchema(chunk1, targetPlugins).schema;
|
|
519
|
+
(_allNodes1 = allNodes1).push.apply(_allNodes1, _to_consumable_array(schema1));
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
} catch (err) {
|
|
523
|
+
_didIteratorError1 = true;
|
|
524
|
+
_iteratorError1 = err;
|
|
525
|
+
} finally{
|
|
526
|
+
try {
|
|
527
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
528
|
+
_iterator1.return();
|
|
529
|
+
}
|
|
530
|
+
} finally{
|
|
531
|
+
if (_didIteratorError1) {
|
|
532
|
+
throw _iteratorError1;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (allNodes1.length > 0) {
|
|
537
|
+
this.setContent(allNodes1);
|
|
538
|
+
this._editor.current.children = allNodes1;
|
|
539
|
+
ReactEditor.deselect(this._editor.current);
|
|
540
|
+
}
|
|
541
|
+
// 调用进度回调
|
|
542
|
+
if (options === null || options === void 0 ? void 0 : options.onProgress) {
|
|
543
|
+
options.onProgress(1);
|
|
544
|
+
}
|
|
545
|
+
} catch (error) {
|
|
546
|
+
console.error('Failed to set MD content with small chunks:', error);
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
/**
|
|
335
553
|
* 取消当前正在进行的 setMDContent 操作
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
554
|
+
*/ key: "cancelSetMDContent",
|
|
555
|
+
value: function cancelSetMDContent() {
|
|
556
|
+
if (this._currentAbortController) {
|
|
557
|
+
this._currentAbortController.abort();
|
|
558
|
+
this._currentAbortController = null;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
key: "_parseAndSetContentWithRAF",
|
|
564
|
+
value: /**
|
|
344
565
|
* 使用 requestAnimationFrame 分批解析和设置内容
|
|
345
566
|
* 边解析边插入,实时显示内容
|
|
346
567
|
*
|
|
@@ -350,89 +571,104 @@ var EditorStore = class {
|
|
|
350
571
|
* @param onProgress - 进度回调函数
|
|
351
572
|
* @returns Promise,在所有内容处理完成后 resolve
|
|
352
573
|
* @private
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
574
|
+
*/ function _parseAndSetContentWithRAF(chunks, plugins, batchSize, onProgress, signal) {
|
|
575
|
+
var _this = this;
|
|
576
|
+
return new Promise(function(resolve, reject) {
|
|
577
|
+
var currentChunkIndex = 0;
|
|
578
|
+
var totalChunks = chunks.length;
|
|
579
|
+
var parseChunksPerFrame = Math.max(1, Math.floor(batchSize / 10)); // 每帧解析的 chunk 数
|
|
580
|
+
var isFirstBatch = true;
|
|
581
|
+
var rafId = null;
|
|
582
|
+
// 边解析边插入
|
|
583
|
+
var parseAndInsertNextBatch = function() {
|
|
584
|
+
try {
|
|
585
|
+
// 检查是否被取消
|
|
586
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
587
|
+
if (rafId) {
|
|
588
|
+
cancelAnimationFrame(rafId);
|
|
589
|
+
rafId = null;
|
|
590
|
+
}
|
|
591
|
+
_this._currentAbortController = null;
|
|
592
|
+
reject(new Error('Operation was cancelled'));
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
// 检查编辑器是否仍然有效
|
|
596
|
+
if (!_this._editor.current) {
|
|
597
|
+
if (rafId) {
|
|
598
|
+
cancelAnimationFrame(rafId);
|
|
599
|
+
rafId = null;
|
|
600
|
+
}
|
|
601
|
+
_this._currentAbortController = null;
|
|
602
|
+
reject(new Error('Editor instance is no longer available'));
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
var endIndex = Math.min(currentChunkIndex + parseChunksPerFrame, totalChunks);
|
|
606
|
+
// 解析当前批次的 chunks 并立即插入
|
|
607
|
+
for(var i = currentChunkIndex; i < endIndex; i++){
|
|
608
|
+
var chunk = chunks[i];
|
|
609
|
+
if (chunk.trim()) {
|
|
610
|
+
try {
|
|
611
|
+
var schema = parserMdToSchema(chunk, plugins).schema;
|
|
612
|
+
if (schema.length > 0) {
|
|
613
|
+
if (isFirstBatch) {
|
|
614
|
+
// 第一批:清空并插入
|
|
615
|
+
_this._editor.current.children = schema;
|
|
616
|
+
_this._editor.current.onChange();
|
|
617
|
+
isFirstBatch = false;
|
|
618
|
+
} else {
|
|
619
|
+
// 后续批次:追加节点
|
|
620
|
+
Transforms.insertNodes(_this._editor.current, schema, {
|
|
621
|
+
at: [
|
|
622
|
+
_this._editor.current.children.length
|
|
623
|
+
]
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
} catch (chunkError) {
|
|
628
|
+
// 单个 chunk 解析失败,记录但继续处理其他 chunks
|
|
629
|
+
console.warn("Failed to parse chunk ".concat(i, ":"), chunkError);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
currentChunkIndex = endIndex;
|
|
634
|
+
// 更新进度
|
|
635
|
+
var progress = currentChunkIndex / totalChunks;
|
|
636
|
+
if (onProgress) {
|
|
637
|
+
try {
|
|
638
|
+
onProgress(progress);
|
|
639
|
+
} catch (progressError) {
|
|
640
|
+
// 进度回调失败不应该中断整个流程
|
|
641
|
+
console.warn('Progress callback failed:', progressError);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (currentChunkIndex < totalChunks) {
|
|
645
|
+
// 还有 chunks 未处理,继续下一帧
|
|
646
|
+
rafId = requestAnimationFrame(parseAndInsertNextBatch);
|
|
647
|
+
} else {
|
|
648
|
+
// 所有内容处理完成
|
|
649
|
+
ReactEditor.deselect(_this._editor.current);
|
|
650
|
+
rafId = null;
|
|
651
|
+
_this._currentAbortController = null;
|
|
652
|
+
resolve();
|
|
653
|
+
}
|
|
654
|
+
} catch (error) {
|
|
655
|
+
// 清理资源并拒绝 Promise
|
|
656
|
+
if (rafId) {
|
|
657
|
+
cancelAnimationFrame(rafId);
|
|
658
|
+
rafId = null;
|
|
659
|
+
}
|
|
660
|
+
_this._currentAbortController = null;
|
|
661
|
+
reject(error);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
// 开始处理
|
|
665
|
+
rafId = requestAnimationFrame(parseAndInsertNextBatch);
|
|
666
|
+
});
|
|
413
667
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
ReactEditor.deselect(this._editor.current);
|
|
419
|
-
rafId = null;
|
|
420
|
-
this._currentAbortController = null;
|
|
421
|
-
resolve();
|
|
422
|
-
}
|
|
423
|
-
} catch (error) {
|
|
424
|
-
if (rafId) {
|
|
425
|
-
cancelAnimationFrame(rafId);
|
|
426
|
-
rafId = null;
|
|
427
|
-
}
|
|
428
|
-
this._currentAbortController = null;
|
|
429
|
-
reject(error);
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
rafId = requestAnimationFrame(parseAndInsertNextBatch);
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
key: "_setContentWithRAF",
|
|
671
|
+
value: /**
|
|
436
672
|
* 使用 requestAnimationFrame 分批设置内容
|
|
437
673
|
* 每帧插入一批节点,避免长时间阻塞主线程
|
|
438
674
|
*
|
|
@@ -441,45 +677,56 @@ var EditorStore = class {
|
|
|
441
677
|
* @param onProgress - 进度回调函数
|
|
442
678
|
* @returns Promise,在所有节点插入完成后 resolve
|
|
443
679
|
* @private
|
|
444
|
-
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
680
|
+
*/ function _setContentWithRAF(allNodes, batchSize, onProgress) {
|
|
681
|
+
var _this = this;
|
|
682
|
+
return new Promise(function(resolve, reject) {
|
|
683
|
+
var currentIndex = 0;
|
|
684
|
+
var totalNodes = allNodes.length;
|
|
685
|
+
var rafId = null;
|
|
686
|
+
var insertBatch = function() {
|
|
687
|
+
try {
|
|
688
|
+
var endIndex = Math.min(currentIndex + batchSize, totalNodes);
|
|
689
|
+
var batch = allNodes.slice(currentIndex, endIndex);
|
|
690
|
+
if (currentIndex === 0) {
|
|
691
|
+
// 第一批:清空并插入
|
|
692
|
+
_this._editor.current.children = batch;
|
|
693
|
+
_this._editor.current.onChange();
|
|
694
|
+
} else {
|
|
695
|
+
var // 后续批次:追加节点
|
|
696
|
+
_this__editor_current_children;
|
|
697
|
+
(_this__editor_current_children = _this._editor.current.children).push.apply(_this__editor_current_children, _to_consumable_array(batch));
|
|
698
|
+
_this._editor.current.onChange();
|
|
699
|
+
}
|
|
700
|
+
currentIndex = endIndex;
|
|
701
|
+
var progress = currentIndex / totalNodes;
|
|
702
|
+
// 直接调用进度回调,避免嵌套 requestAnimationFrame
|
|
703
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(progress);
|
|
704
|
+
if (currentIndex < totalNodes) {
|
|
705
|
+
// 还有节点未处理,继续下一帧
|
|
706
|
+
rafId = requestAnimationFrame(insertBatch);
|
|
707
|
+
} else {
|
|
708
|
+
// 所有节点处理完成
|
|
709
|
+
ReactEditor.deselect(_this._editor.current);
|
|
710
|
+
rafId = null;
|
|
711
|
+
resolve();
|
|
712
|
+
}
|
|
713
|
+
} catch (error) {
|
|
714
|
+
// 清理资源并拒绝 Promise
|
|
715
|
+
if (rafId) {
|
|
716
|
+
cancelAnimationFrame(rafId);
|
|
717
|
+
rafId = null;
|
|
718
|
+
}
|
|
719
|
+
reject(error);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
// 开始第一帧
|
|
723
|
+
rafId = requestAnimationFrame(insertBatch);
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
key: "_splitMarkdown",
|
|
729
|
+
value: /**
|
|
483
730
|
* 按指定分隔符拆分 markdown 内容
|
|
484
731
|
* 保持内容结构的完整性
|
|
485
732
|
*
|
|
@@ -487,176 +734,212 @@ var EditorStore = class {
|
|
|
487
734
|
* @param separator - 分隔符,可以是字符串或正则表达式
|
|
488
735
|
* @returns 拆分后的字符串数组
|
|
489
736
|
* @private
|
|
490
|
-
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
737
|
+
*/ function _splitMarkdown(md, separator) {
|
|
738
|
+
if (!md) {
|
|
739
|
+
return [];
|
|
740
|
+
}
|
|
741
|
+
var separatorMatches = this._collectSeparatorMatches(md, separator);
|
|
742
|
+
if (separatorMatches.length === 0) {
|
|
743
|
+
return [
|
|
744
|
+
md
|
|
745
|
+
];
|
|
746
|
+
}
|
|
747
|
+
var chunks = [];
|
|
748
|
+
var start = 0;
|
|
749
|
+
var currentMatchIndex = 0;
|
|
750
|
+
var insideFence = false;
|
|
751
|
+
var activeFence = null;
|
|
752
|
+
var index = 0;
|
|
753
|
+
while(index < md.length){
|
|
754
|
+
if (this._isLineStart(md, index)) {
|
|
755
|
+
var fence = this._matchFence(md, index);
|
|
756
|
+
if (fence) {
|
|
757
|
+
if (!insideFence) {
|
|
758
|
+
insideFence = true;
|
|
759
|
+
activeFence = fence.marker;
|
|
760
|
+
} else if (activeFence === fence.marker) {
|
|
761
|
+
insideFence = false;
|
|
762
|
+
activeFence = null;
|
|
763
|
+
}
|
|
764
|
+
index = fence.end;
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
var match = separatorMatches[currentMatchIndex];
|
|
769
|
+
if (!insideFence && match && index === match.index) {
|
|
770
|
+
var chunk = md.slice(start, index);
|
|
771
|
+
if (chunk.length > 0) {
|
|
772
|
+
chunks.push(chunk);
|
|
773
|
+
}
|
|
774
|
+
start = index + match.length;
|
|
775
|
+
currentMatchIndex += 1;
|
|
776
|
+
index = start;
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
index += 1;
|
|
780
|
+
}
|
|
781
|
+
var tail = md.slice(start);
|
|
782
|
+
if (tail.length > 0) {
|
|
783
|
+
chunks.push(tail);
|
|
784
|
+
}
|
|
785
|
+
return chunks.length > 0 ? chunks : [
|
|
786
|
+
md
|
|
787
|
+
];
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
key: "_collectSeparatorMatches",
|
|
792
|
+
value: function _collectSeparatorMatches(md, separator) {
|
|
793
|
+
if (typeof separator === 'string') {
|
|
794
|
+
var matches = [];
|
|
795
|
+
var searchIndex = md.indexOf(separator);
|
|
796
|
+
while(searchIndex !== -1){
|
|
797
|
+
matches.push({
|
|
798
|
+
index: searchIndex,
|
|
799
|
+
length: separator.length
|
|
800
|
+
});
|
|
801
|
+
searchIndex = md.indexOf(separator, searchIndex + separator.length);
|
|
802
|
+
}
|
|
803
|
+
return matches;
|
|
804
|
+
}
|
|
805
|
+
var flags = separator.flags.includes('g') ? separator.flags : "".concat(separator.flags, "g");
|
|
806
|
+
var globalRegex = new RegExp(separator.source, flags);
|
|
807
|
+
var matches1 = [];
|
|
808
|
+
var match;
|
|
809
|
+
while((match = globalRegex.exec(md)) !== null){
|
|
810
|
+
var matchedText = match[0];
|
|
811
|
+
matches1.push({
|
|
812
|
+
index: match.index,
|
|
813
|
+
length: matchedText.length
|
|
814
|
+
});
|
|
815
|
+
if (matchedText.length === 0) {
|
|
816
|
+
globalRegex.lastIndex += 1;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return matches1;
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
key: "_isLineStart",
|
|
824
|
+
value: function _isLineStart(content, position) {
|
|
825
|
+
if (position === 0) {
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
return content[position - 1] === '\n';
|
|
829
|
+
}
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
key: "_matchFence",
|
|
833
|
+
value: function _matchFence(content, position) {
|
|
834
|
+
var cursor = position;
|
|
835
|
+
var spaces = 0;
|
|
836
|
+
while(cursor < content.length && content[cursor] === ' ' && spaces < 3){
|
|
837
|
+
cursor += 1;
|
|
838
|
+
spaces += 1;
|
|
839
|
+
}
|
|
840
|
+
if (cursor >= content.length) {
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
var char = content[cursor];
|
|
844
|
+
if (char !== '`' && char !== '~') {
|
|
845
|
+
return null;
|
|
846
|
+
}
|
|
847
|
+
var fenceLength = 0;
|
|
848
|
+
while(cursor < content.length && content[cursor] === char){
|
|
849
|
+
cursor += 1;
|
|
850
|
+
fenceLength += 1;
|
|
851
|
+
}
|
|
852
|
+
if (fenceLength < 3) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
var lineEnd = this._findLineEnd(content, cursor);
|
|
856
|
+
return {
|
|
857
|
+
marker: char,
|
|
858
|
+
end: lineEnd
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
key: "_findLineEnd",
|
|
864
|
+
value: function _findLineEnd(content, position) {
|
|
865
|
+
var cursor = position;
|
|
866
|
+
while(cursor < content.length && content[cursor] !== '\n'){
|
|
867
|
+
cursor += 1;
|
|
868
|
+
}
|
|
869
|
+
if (cursor < content.length && content[cursor] === '\n') {
|
|
870
|
+
return cursor + 1;
|
|
871
|
+
}
|
|
872
|
+
return cursor;
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
/**
|
|
604
877
|
* 获取当前编辑器内容作为节点列表
|
|
605
878
|
*
|
|
606
879
|
* @returns 当前编辑器内容的节点列表
|
|
607
|
-
*/
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
880
|
+
*/ key: "getContent",
|
|
881
|
+
value: function getContent() {
|
|
882
|
+
var nodeList = this._editor.current.children;
|
|
883
|
+
return nodeList;
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
/**
|
|
613
888
|
* 获取当前编辑器内容作为 markdown 字符串
|
|
614
889
|
*
|
|
615
890
|
* @param plugins - 可选的自定义 markdown 转换插件
|
|
616
891
|
* @returns 转换为 markdown 的当前编辑器内容
|
|
617
|
-
*/
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
892
|
+
*/ key: "getMDContent",
|
|
893
|
+
value: function getMDContent(plugins) {
|
|
894
|
+
var nodeList = this._editor.current.children;
|
|
895
|
+
var md = parserSlateNodeToMarkdown(nodeList, '', [
|
|
896
|
+
{
|
|
897
|
+
root: true
|
|
898
|
+
}
|
|
899
|
+
], plugins || this.plugins);
|
|
900
|
+
return md;
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
{
|
|
904
|
+
/**
|
|
629
905
|
* 获取当前编辑器内容作为 HTML 字符串
|
|
630
906
|
*
|
|
631
907
|
* @returns 转换为 HTML 的当前编辑器内容
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
908
|
+
*/ key: "getHtmlContent",
|
|
909
|
+
value: function getHtmlContent(options) {
|
|
910
|
+
var markdown = this.getMDContent();
|
|
911
|
+
var appliedOptions = options !== null && options !== void 0 ? options : this.markdownToHtmlOptions;
|
|
912
|
+
if (options) {
|
|
913
|
+
this.markdownToHtmlOptions = options;
|
|
914
|
+
}
|
|
915
|
+
return markdownToHtmlSync(markdown, appliedOptions);
|
|
916
|
+
}
|
|
917
|
+
},
|
|
918
|
+
{
|
|
919
|
+
/**
|
|
642
920
|
* 使用节点列表设置编辑器内容
|
|
643
921
|
*
|
|
644
922
|
* @param nodeList - 要设置为编辑器内容的节点列表
|
|
645
|
-
*/
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
923
|
+
*/ key: "setContent",
|
|
924
|
+
value: function setContent(nodeList) {
|
|
925
|
+
this._editor.current.children = nodeList;
|
|
926
|
+
this._editor.current.onChange();
|
|
927
|
+
// 检查最后一个节点是否以换行符结尾
|
|
928
|
+
var lastNode = nodeList[nodeList.length - 1];
|
|
929
|
+
if (lastNode && Text.isText(lastNode)) {
|
|
930
|
+
var text = Node.string(lastNode);
|
|
931
|
+
if (!text.endsWith('\n')) {
|
|
932
|
+
this._editor.current.insertText('\n', {
|
|
933
|
+
at: [
|
|
934
|
+
nodeList.length - 1
|
|
935
|
+
]
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
/**
|
|
660
943
|
* 使用差异检测和操作队列优化更新节点列表。
|
|
661
944
|
*
|
|
662
945
|
* @param nodeList - 新的节点列表
|
|
@@ -677,39 +960,36 @@ var EditorStore = class {
|
|
|
677
960
|
* 错误处理:
|
|
678
961
|
* - 如果优化更新失败,会回退到直接替换整个节点列表
|
|
679
962
|
* - 错误信息会被记录到控制台
|
|
680
|
-
*/
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
963
|
+
*/ key: "updateNodeList",
|
|
964
|
+
value: function updateNodeList(nodeList) {
|
|
965
|
+
if (!nodeList || !Array.isArray(nodeList)) return;
|
|
966
|
+
// 过滤无效节点
|
|
967
|
+
var filteredNodes = nodeList.filter(function(item) {
|
|
968
|
+
if (!item) return false;
|
|
969
|
+
if (item.type === 'p' && (!item.children || item.children.length === 0)) return false;
|
|
970
|
+
if (item.type === 'list' && (!item.children || item.children.length === 0)) return false;
|
|
971
|
+
if (item.type === 'listItem' && (!item.children || item.children.length === 0)) return false;
|
|
972
|
+
if (item.type === 'code' && item.language === 'code' && (!item.otherProps || item.otherProps.length === 0)) return false;
|
|
973
|
+
if (item.type === 'image' && !item.src) return false;
|
|
974
|
+
return true;
|
|
975
|
+
});
|
|
976
|
+
try {
|
|
977
|
+
// 生成差异操作
|
|
978
|
+
var operations = this.generateDiffOperations(filteredNodes, this._editor.current.children);
|
|
979
|
+
// 执行差异操作
|
|
980
|
+
if (operations.length > 0) {
|
|
981
|
+
this.executeOperations(operations);
|
|
982
|
+
}
|
|
983
|
+
} catch (error) {
|
|
984
|
+
console.error('Failed to update nodes with optimized method:', error);
|
|
985
|
+
// 回退:如果优化方法失败,使用直接替换
|
|
986
|
+
this._editor.current.children = nodeList;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
key: "generateDiffOperations",
|
|
992
|
+
value: /**
|
|
713
993
|
* 生成两个节点列表之间的差异操作队列。
|
|
714
994
|
*
|
|
715
995
|
* @param newNodes - 新的节点列表
|
|
@@ -721,41 +1001,54 @@ var EditorStore = class {
|
|
|
721
1001
|
* 2. 对共有节点进行深度比较
|
|
722
1002
|
* 3. 生成最小化的操作序列
|
|
723
1003
|
* 4. 根据优先级排序操作
|
|
724
|
-
*/
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1004
|
+
*/ function generateDiffOperations(newNodes, oldNodes) {
|
|
1005
|
+
if (!newNodes || !oldNodes) return [];
|
|
1006
|
+
var operations = [];
|
|
1007
|
+
// 第一阶段:处理节点数量不同的情况
|
|
1008
|
+
var lengthDiff = newNodes.length - oldNodes.length;
|
|
1009
|
+
if (lengthDiff > 0) {
|
|
1010
|
+
// 新列表比旧列表长,添加新节点
|
|
1011
|
+
for(var i = oldNodes.length; i < newNodes.length; i++){
|
|
1012
|
+
operations.push({
|
|
1013
|
+
type: 'insert',
|
|
1014
|
+
path: [
|
|
1015
|
+
i
|
|
1016
|
+
],
|
|
1017
|
+
node: newNodes[i],
|
|
1018
|
+
priority: 10
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
} else if (lengthDiff < 0) {
|
|
1022
|
+
// 旧列表比新列表长,需要删除节点
|
|
1023
|
+
// 从后往前删除,以避免索引问题
|
|
1024
|
+
for(var i1 = oldNodes.length - 1; i1 >= newNodes.length; i1--){
|
|
1025
|
+
operations.push({
|
|
1026
|
+
type: 'remove',
|
|
1027
|
+
path: [
|
|
1028
|
+
i1
|
|
1029
|
+
],
|
|
1030
|
+
priority: 0
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
// 第二阶段:深度比较共有的节点
|
|
1035
|
+
var minLength = Math.min(newNodes.length, oldNodes.length);
|
|
1036
|
+
for(var i2 = 0; i2 < minLength; i2++){
|
|
1037
|
+
var newNode = newNodes[i2];
|
|
1038
|
+
var oldNode = oldNodes[i2];
|
|
1039
|
+
this.compareNodes(newNode, oldNode, [
|
|
1040
|
+
i2
|
|
1041
|
+
], operations);
|
|
1042
|
+
}
|
|
1043
|
+
// 按优先级排序操作队列
|
|
1044
|
+
return operations.sort(function(a, b) {
|
|
1045
|
+
return a.priority - b.priority;
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
key: "compareNodes",
|
|
1051
|
+
value: /**
|
|
759
1052
|
* 递归比较两个节点及其子节点的差异。
|
|
760
1053
|
*
|
|
761
1054
|
* @param newNode - 新节点
|
|
@@ -770,67 +1063,78 @@ var EditorStore = class {
|
|
|
770
1063
|
* 4. 比较节点属性
|
|
771
1064
|
* 5. 递归比较子节点
|
|
772
1065
|
* @private
|
|
773
|
-
*/
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1066
|
+
*/ function compareNodes(newNode, oldNode, path, operations) {
|
|
1067
|
+
// 如果节点类型不同,直接替换整个节点
|
|
1068
|
+
if (newNode.type !== oldNode.type) {
|
|
1069
|
+
operations.push({
|
|
1070
|
+
type: 'replace',
|
|
1071
|
+
path: path,
|
|
1072
|
+
node: newNode,
|
|
1073
|
+
priority: 5
|
|
1074
|
+
});
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
// 特殊处理表格节点
|
|
1078
|
+
if (newNode.type === 'table') {
|
|
1079
|
+
this.compareTableNodes(newNode, oldNode, path, operations);
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
// 如果两个节点是文本节点
|
|
1083
|
+
if (typeof newNode.text === 'string' && typeof oldNode.text === 'string') {
|
|
1084
|
+
if (newNode.text !== oldNode.text) {
|
|
1085
|
+
operations.push({
|
|
1086
|
+
type: 'text',
|
|
1087
|
+
path: path,
|
|
1088
|
+
text: newNode.text,
|
|
1089
|
+
priority: 8
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
// 比较文本节点的其他属性(如加粗、斜体等)
|
|
1093
|
+
var newProps = _object_spread({}, newNode);
|
|
1094
|
+
var oldProps = _object_spread({}, oldNode);
|
|
1095
|
+
delete newProps.text;
|
|
1096
|
+
delete oldProps.text;
|
|
1097
|
+
if (!isEqual(newProps, oldProps)) {
|
|
1098
|
+
operations.push({
|
|
1099
|
+
type: 'update',
|
|
1100
|
+
path: path,
|
|
1101
|
+
properties: newProps,
|
|
1102
|
+
priority: 7
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
// 处理其他类型的节点属性更新
|
|
1108
|
+
var newProps1 = _object_spread_props(_object_spread({}, newNode), {
|
|
1109
|
+
children: undefined
|
|
1110
|
+
});
|
|
1111
|
+
var oldProps1 = _object_spread_props(_object_spread({}, oldNode), {
|
|
1112
|
+
children: undefined
|
|
1113
|
+
});
|
|
1114
|
+
if (!isEqual(newProps1, oldProps1)) {
|
|
1115
|
+
operations.push({
|
|
1116
|
+
type: 'update',
|
|
1117
|
+
path: path,
|
|
1118
|
+
properties: newProps1,
|
|
1119
|
+
priority: 7
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
// 递归比较子节点
|
|
1123
|
+
if (newNode.children && oldNode.children) {
|
|
1124
|
+
// 特殊处理列表、引用等可能有嵌套结构的节点
|
|
1125
|
+
var childrenOps = this.generateDiffOperations(newNode.children, oldNode.children);
|
|
1126
|
+
// 将子节点的操作添加到队列中,调整路径
|
|
1127
|
+
childrenOps.forEach(function(op) {
|
|
1128
|
+
operations.push(_object_spread_props(_object_spread({}, op), {
|
|
1129
|
+
path: _to_consumable_array(path).concat(_to_consumable_array(op.path))
|
|
1130
|
+
}));
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
key: "compareTableNodes",
|
|
1137
|
+
value: /**
|
|
834
1138
|
* 特殊处理表格节点的比较。
|
|
835
1139
|
*
|
|
836
1140
|
* @param newTable - 新的表格节点
|
|
@@ -845,134 +1149,176 @@ var EditorStore = class {
|
|
|
845
1149
|
* 4. 处理行数变化
|
|
846
1150
|
* 5. 必要时进行整表替换
|
|
847
1151
|
* @private
|
|
848
|
-
*/
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1152
|
+
*/ function compareTableNodes(newTable, oldTable, path, operations) {
|
|
1153
|
+
var newRows = newTable.children || [];
|
|
1154
|
+
var oldRows = oldTable.children || [];
|
|
1155
|
+
// 检查是否是同一个表格的更新(检查表格的关键属性)
|
|
1156
|
+
var isSameTableStructure = function() {
|
|
1157
|
+
// 如果有表格ID或其他唯一标识符,优先比较这些
|
|
1158
|
+
if (newTable.id && oldTable.id) {
|
|
1159
|
+
return newTable.id === oldTable.id;
|
|
1160
|
+
}
|
|
1161
|
+
// 表格结构基本一致的情况(行数相同)
|
|
1162
|
+
if (newRows.length === oldRows.length) {
|
|
1163
|
+
// 检查每行的单元格数量
|
|
1164
|
+
for(var i = 0; i < newRows.length; i++){
|
|
1165
|
+
var newRow = newRows[i];
|
|
1166
|
+
var oldRow = oldRows[i];
|
|
1167
|
+
if (!newRow.children || !oldRow.children || newRow.children.length !== oldRow.children.length) {
|
|
1168
|
+
return false;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return true;
|
|
1172
|
+
}
|
|
1173
|
+
return false;
|
|
1174
|
+
};
|
|
1175
|
+
// 非结构化属性对比(排除children)
|
|
1176
|
+
var tablePropsChanged = function() {
|
|
1177
|
+
var newProps = _object_spread({}, newTable);
|
|
1178
|
+
var oldProps = _object_spread({}, oldTable);
|
|
1179
|
+
delete newProps.children;
|
|
1180
|
+
delete oldProps.children;
|
|
1181
|
+
return !isEqual(newProps, oldProps);
|
|
1182
|
+
};
|
|
1183
|
+
// 检查表格是否只有内容变化而结构相同
|
|
1184
|
+
if (isSameTableStructure()) {
|
|
1185
|
+
// 只更新表格属性(不包括子节点)
|
|
1186
|
+
if (tablePropsChanged()) {
|
|
1187
|
+
var newTableProps = _object_spread_props(_object_spread({}, newTable), {
|
|
1188
|
+
children: undefined
|
|
1189
|
+
});
|
|
1190
|
+
operations.push({
|
|
1191
|
+
type: 'update',
|
|
1192
|
+
path: path,
|
|
1193
|
+
properties: newTableProps,
|
|
1194
|
+
priority: 7
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
// 逐行比较和更新
|
|
1198
|
+
for(var rowIdx = 0; rowIdx < newRows.length; rowIdx++){
|
|
1199
|
+
var rowPath = _to_consumable_array(path).concat([
|
|
1200
|
+
rowIdx
|
|
1201
|
+
]);
|
|
1202
|
+
var newRow = newRows[rowIdx];
|
|
1203
|
+
var oldRow = oldRows[rowIdx];
|
|
1204
|
+
// 更新行属性(不包括子节点)
|
|
1205
|
+
var newRowProps = _object_spread_props(_object_spread({}, newRow), {
|
|
1206
|
+
children: undefined
|
|
1207
|
+
});
|
|
1208
|
+
var oldRowProps = _object_spread_props(_object_spread({}, oldRow), {
|
|
1209
|
+
children: undefined
|
|
1210
|
+
});
|
|
1211
|
+
if (!isEqual(newRowProps, oldRowProps)) {
|
|
1212
|
+
operations.push({
|
|
1213
|
+
type: 'update',
|
|
1214
|
+
path: rowPath,
|
|
1215
|
+
properties: newRowProps,
|
|
1216
|
+
priority: 7
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
// 单元格比较和更新
|
|
1220
|
+
var newCells = newRow.children || [];
|
|
1221
|
+
var oldCells = oldRow.children || [];
|
|
1222
|
+
var minCellCount = Math.min(newCells.length, oldCells.length);
|
|
1223
|
+
// 更新共有的单元格
|
|
1224
|
+
for(var cellIdx = 0; cellIdx < minCellCount; cellIdx++){
|
|
1225
|
+
var cellPath = _to_consumable_array(rowPath).concat([
|
|
1226
|
+
cellIdx
|
|
1227
|
+
]);
|
|
1228
|
+
var newCell = newCells[cellIdx];
|
|
1229
|
+
var oldCell = oldCells[cellIdx];
|
|
1230
|
+
this.compareCells(newCell, oldCell, cellPath, operations);
|
|
1231
|
+
}
|
|
1232
|
+
// 处理单元格数量变化
|
|
1233
|
+
if (newCells.length > oldCells.length) {
|
|
1234
|
+
// 添加新单元格
|
|
1235
|
+
for(var cellIdx1 = oldCells.length; cellIdx1 < newCells.length; cellIdx1++){
|
|
1236
|
+
operations.push({
|
|
1237
|
+
type: 'insert',
|
|
1238
|
+
path: _to_consumable_array(rowPath).concat([
|
|
1239
|
+
cellIdx1
|
|
1240
|
+
]),
|
|
1241
|
+
node: newCells[cellIdx1],
|
|
1242
|
+
priority: 6
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
} else if (newCells.length < oldCells.length) {
|
|
1246
|
+
// 删除多余单元格(从后向前删除)
|
|
1247
|
+
for(var cellIdx2 = oldCells.length - 1; cellIdx2 >= newCells.length; cellIdx2--){
|
|
1248
|
+
operations.push({
|
|
1249
|
+
type: 'remove',
|
|
1250
|
+
path: _to_consumable_array(rowPath).concat([
|
|
1251
|
+
cellIdx2
|
|
1252
|
+
]),
|
|
1253
|
+
priority: 1
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
// 表格结构发生了变化,检查变化情况决定更新策略
|
|
1260
|
+
// 如果是简单的行增减,采用行级更新而非整表替换
|
|
1261
|
+
if (Math.abs(newRows.length - oldRows.length) <= 2) {
|
|
1262
|
+
// 行数量变化较小,尝试行级别更新
|
|
1263
|
+
// 先更新表格属性
|
|
1264
|
+
if (tablePropsChanged()) {
|
|
1265
|
+
operations.push({
|
|
1266
|
+
type: 'update',
|
|
1267
|
+
path: path,
|
|
1268
|
+
properties: _object_spread_props(_object_spread({}, newTable), {
|
|
1269
|
+
children: undefined
|
|
1270
|
+
}),
|
|
1271
|
+
priority: 7
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
// 更新共有的行
|
|
1275
|
+
var minRowCount = Math.min(newRows.length, oldRows.length);
|
|
1276
|
+
for(var rowIdx1 = 0; rowIdx1 < minRowCount; rowIdx1++){
|
|
1277
|
+
var rowPath1 = _to_consumable_array(path).concat([
|
|
1278
|
+
rowIdx1
|
|
1279
|
+
]);
|
|
1280
|
+
this.compareNodes(newRows[rowIdx1], oldRows[rowIdx1], rowPath1, operations);
|
|
1281
|
+
}
|
|
1282
|
+
// 处理行数变化
|
|
1283
|
+
if (newRows.length > oldRows.length) {
|
|
1284
|
+
// 添加新行
|
|
1285
|
+
for(var rowIdx2 = oldRows.length; rowIdx2 < newRows.length; rowIdx2++){
|
|
1286
|
+
operations.push({
|
|
1287
|
+
type: 'insert',
|
|
1288
|
+
path: _to_consumable_array(path).concat([
|
|
1289
|
+
rowIdx2
|
|
1290
|
+
]),
|
|
1291
|
+
node: newRows[rowIdx2],
|
|
1292
|
+
priority: 5
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
} else if (newRows.length < oldRows.length) {
|
|
1296
|
+
// 从后向前删除多余的行
|
|
1297
|
+
for(var rowIdx3 = oldRows.length - 1; rowIdx3 >= newRows.length; rowIdx3--){
|
|
1298
|
+
operations.push({
|
|
1299
|
+
type: 'remove',
|
|
1300
|
+
path: _to_consumable_array(path).concat([
|
|
1301
|
+
rowIdx3
|
|
1302
|
+
]),
|
|
1303
|
+
priority: 1
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
} else {
|
|
1308
|
+
// 结构变化较大,整表替换可能更高效
|
|
1309
|
+
operations.push({
|
|
1310
|
+
type: 'replace',
|
|
1311
|
+
path: path,
|
|
1312
|
+
node: newTable,
|
|
1313
|
+
priority: 5
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
},
|
|
1319
|
+
{
|
|
1320
|
+
key: "compareCells",
|
|
1321
|
+
value: /**
|
|
976
1322
|
* 比较和更新表格单元格。
|
|
977
1323
|
*
|
|
978
1324
|
* @param newCell - 新的单元格节点
|
|
@@ -986,140 +1332,155 @@ var EditorStore = class {
|
|
|
986
1332
|
* 3. 处理复杂单元格内容
|
|
987
1333
|
* 4. 生成适当的更新操作
|
|
988
1334
|
* @private
|
|
989
|
-
*/
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1335
|
+
*/ function compareCells(newCell, oldCell, path, operations) {
|
|
1336
|
+
// 检查单元格属性是否变化
|
|
1337
|
+
this.compareCellProperties(newCell, oldCell, path, operations);
|
|
1338
|
+
// 处理单元格内容
|
|
1339
|
+
var newChildren = newCell.children || [];
|
|
1340
|
+
var oldChildren = oldCell.children || [];
|
|
1341
|
+
this.compareCellChildren(newChildren, oldChildren, path, operations);
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
key: "compareCellProperties",
|
|
1346
|
+
value: /**
|
|
997
1347
|
* 比较单元格属性
|
|
998
|
-
*/
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1348
|
+
*/ function compareCellProperties(newCell, oldCell, path, operations) {
|
|
1349
|
+
var newCellProps = _object_spread_props(_object_spread({}, newCell), {
|
|
1350
|
+
children: undefined
|
|
1351
|
+
});
|
|
1352
|
+
var oldCellProps = _object_spread_props(_object_spread({}, oldCell), {
|
|
1353
|
+
children: undefined
|
|
1354
|
+
});
|
|
1355
|
+
if (!isEqual(newCellProps, oldCellProps)) {
|
|
1356
|
+
operations.push({
|
|
1357
|
+
type: 'update',
|
|
1358
|
+
path: path,
|
|
1359
|
+
properties: newCellProps,
|
|
1360
|
+
priority: 7
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
},
|
|
1365
|
+
{
|
|
1366
|
+
key: "compareCellChildren",
|
|
1367
|
+
value: /**
|
|
1012
1368
|
* 比较单元格子节点
|
|
1013
|
-
*/
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1369
|
+
*/ function compareCellChildren(newChildren, oldChildren, path, operations) {
|
|
1370
|
+
// 简单文本单元格的优化处理
|
|
1371
|
+
if (this.isSimpleTextCell(newChildren, oldChildren)) {
|
|
1372
|
+
this.compareSimpleTextCell(newChildren, oldChildren, path, operations);
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
// 复杂单元格内容
|
|
1376
|
+
this.compareComplexCellChildren(newChildren, oldChildren, path, operations);
|
|
1377
|
+
}
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
key: "isSimpleTextCell",
|
|
1381
|
+
value: /**
|
|
1022
1382
|
* 判断是否是简单文本单元格
|
|
1023
|
-
*/
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1383
|
+
*/ function isSimpleTextCell(newChildren, oldChildren) {
|
|
1384
|
+
return newChildren.length === 1 && oldChildren.length === 1 && typeof newChildren[0].text === 'string' && typeof oldChildren[0].text === 'string';
|
|
1385
|
+
}
|
|
1386
|
+
},
|
|
1387
|
+
{
|
|
1388
|
+
key: "compareSimpleTextCell",
|
|
1389
|
+
value: /**
|
|
1028
1390
|
* 比较简单文本单元格
|
|
1029
|
-
*/
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1391
|
+
*/ function compareSimpleTextCell(newChildren, oldChildren, path, operations) {
|
|
1392
|
+
// 只有文本内容变化
|
|
1393
|
+
if (newChildren[0].text !== oldChildren[0].text) {
|
|
1394
|
+
operations.push({
|
|
1395
|
+
type: 'text',
|
|
1396
|
+
path: _to_consumable_array(path).concat([
|
|
1397
|
+
0
|
|
1398
|
+
]),
|
|
1399
|
+
text: newChildren[0].text,
|
|
1400
|
+
priority: 8
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
// 检查文本节点的属性变化(加粗、斜体等)
|
|
1404
|
+
this.compareTextNodeProperties(newChildren[0], oldChildren[0], path, operations);
|
|
1405
|
+
}
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
key: "compareTextNodeProperties",
|
|
1409
|
+
value: /**
|
|
1047
1410
|
* 比较文本节点属性
|
|
1048
|
-
*/
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1411
|
+
*/ function compareTextNodeProperties(newChild, oldChild, path, operations) {
|
|
1412
|
+
var newTextProps = _object_spread({}, newChild);
|
|
1413
|
+
var oldTextProps = _object_spread({}, oldChild);
|
|
1414
|
+
delete newTextProps.text;
|
|
1415
|
+
delete oldTextProps.text;
|
|
1416
|
+
if (!isEqual(newTextProps, oldTextProps)) {
|
|
1417
|
+
operations.push({
|
|
1418
|
+
type: 'update',
|
|
1419
|
+
path: _to_consumable_array(path).concat([
|
|
1420
|
+
0
|
|
1421
|
+
]),
|
|
1422
|
+
properties: newTextProps,
|
|
1423
|
+
priority: 7
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
},
|
|
1428
|
+
{
|
|
1429
|
+
key: "compareComplexCellChildren",
|
|
1430
|
+
value: /**
|
|
1064
1431
|
* 比较复杂单元格子节点
|
|
1065
|
-
*/
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1080
|
-
this.compareChildrenSequentially(
|
|
1081
|
-
newChildren,
|
|
1082
|
-
oldChildren,
|
|
1083
|
-
path,
|
|
1084
|
-
operations
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
|
-
/**
|
|
1432
|
+
*/ function compareComplexCellChildren(newChildren, oldChildren, path, operations) {
|
|
1433
|
+
// 检查是否结构完全不同
|
|
1434
|
+
var structurallyDifferent = this.isStructurallyDifferent(newChildren, oldChildren);
|
|
1435
|
+
if (structurallyDifferent) {
|
|
1436
|
+
this.replaceComplexCellChildren(newChildren, oldChildren, path, operations);
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
// 逐个比较并更新子节点
|
|
1440
|
+
this.compareChildrenSequentially(newChildren, oldChildren, path, operations);
|
|
1441
|
+
}
|
|
1442
|
+
},
|
|
1443
|
+
{
|
|
1444
|
+
key: "isStructurallyDifferent",
|
|
1445
|
+
value: /**
|
|
1088
1446
|
* 判断结构是否不同
|
|
1089
|
-
*/
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1447
|
+
*/ function isStructurallyDifferent(newChildren, oldChildren) {
|
|
1448
|
+
if (newChildren.length !== oldChildren.length) return true;
|
|
1449
|
+
return newChildren.some(function(n, i) {
|
|
1450
|
+
return oldChildren[i] && n.type !== oldChildren[i].type;
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
},
|
|
1454
|
+
{
|
|
1455
|
+
key: "replaceComplexCellChildren",
|
|
1456
|
+
value: /**
|
|
1098
1457
|
* 替换复杂单元格子节点
|
|
1099
|
-
*/
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1458
|
+
*/ function replaceComplexCellChildren(newChildren, oldChildren, path, operations) {
|
|
1459
|
+
var childOps = this.generateDiffOperations(newChildren, oldChildren);
|
|
1460
|
+
// 调整子操作的路径
|
|
1461
|
+
childOps.forEach(function(op) {
|
|
1462
|
+
operations.push(_object_spread_props(_object_spread({}, op), {
|
|
1463
|
+
path: _to_consumable_array(path).concat(_to_consumable_array(op.path))
|
|
1464
|
+
}));
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
},
|
|
1468
|
+
{
|
|
1469
|
+
key: "compareChildrenSequentially",
|
|
1470
|
+
value: /**
|
|
1109
1471
|
* 逐个比较子节点
|
|
1110
|
-
*/
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
/**
|
|
1472
|
+
*/ function compareChildrenSequentially(newChildren, oldChildren, path, operations) {
|
|
1473
|
+
var length = Math.min(newChildren.length, oldChildren.length);
|
|
1474
|
+
for(var i = 0; i < length; i++){
|
|
1475
|
+
this.compareNodes(newChildren[i], oldChildren[i], _to_consumable_array(path).concat([
|
|
1476
|
+
i
|
|
1477
|
+
]), operations);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
},
|
|
1481
|
+
{
|
|
1482
|
+
key: "executeOperations",
|
|
1483
|
+
value: /**
|
|
1123
1484
|
* 执行操作队列中的所有操作。
|
|
1124
1485
|
*
|
|
1125
1486
|
* @param operations - 要执行的操作队列
|
|
@@ -1129,55 +1490,80 @@ var EditorStore = class {
|
|
|
1129
1490
|
* 2. 按照操作类型分别处理
|
|
1130
1491
|
* 3. 处理可能的错误情况
|
|
1131
1492
|
* 4. 保证操作的原子性
|
|
1132
|
-
*/
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1493
|
+
*/ function executeOperations(operations) {
|
|
1494
|
+
var editor = this._editor.current;
|
|
1495
|
+
if (!editor) return;
|
|
1496
|
+
// 使用批处理模式执行所有操作
|
|
1497
|
+
Editor.withoutNormalizing(editor, function() {
|
|
1498
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1499
|
+
try {
|
|
1500
|
+
for(var _iterator = operations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1501
|
+
var op = _step.value;
|
|
1502
|
+
try {
|
|
1503
|
+
switch(op.type){
|
|
1504
|
+
case 'insert':
|
|
1505
|
+
if (op.node && editor.hasPath(Path.parent(op.path))) {
|
|
1506
|
+
Transforms.insertNodes(editor, op.node, {
|
|
1507
|
+
at: op.path
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
break;
|
|
1511
|
+
case 'remove':
|
|
1512
|
+
if (editor.hasPath(op.path)) {
|
|
1513
|
+
Transforms.removeNodes(editor, {
|
|
1514
|
+
at: op.path
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
break;
|
|
1518
|
+
case 'update':
|
|
1519
|
+
if (op.properties && editor.hasPath(op.path)) {
|
|
1520
|
+
Transforms.setNodes(editor, op.properties, {
|
|
1521
|
+
at: op.path
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
break;
|
|
1525
|
+
case 'replace':
|
|
1526
|
+
if (op.node && editor.hasPath(op.path)) {
|
|
1527
|
+
Transforms.removeNodes(editor, {
|
|
1528
|
+
at: op.path
|
|
1529
|
+
});
|
|
1530
|
+
Transforms.insertNodes(editor, op.node, {
|
|
1531
|
+
at: op.path
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
break;
|
|
1535
|
+
case 'text':
|
|
1536
|
+
if (op.text !== undefined && editor.hasPath(op.path)) {
|
|
1537
|
+
Transforms.insertText(editor, op.text, {
|
|
1538
|
+
at: op.path,
|
|
1539
|
+
voids: true
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
console.error("Error executing operation ".concat(op.type, " at path ").concat(op.path, ":"), err);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
} catch (err) {
|
|
1549
|
+
_didIteratorError = true;
|
|
1550
|
+
_iteratorError = err;
|
|
1551
|
+
} finally{
|
|
1552
|
+
try {
|
|
1553
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1554
|
+
_iterator.return();
|
|
1555
|
+
}
|
|
1556
|
+
} finally{
|
|
1557
|
+
if (_didIteratorError) {
|
|
1558
|
+
throw _iteratorError;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1167
1562
|
});
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
console.error(
|
|
1173
|
-
`Error executing operation ${op.type} at path ${op.path}:`,
|
|
1174
|
-
err
|
|
1175
|
-
);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1563
|
+
}
|
|
1564
|
+
},
|
|
1565
|
+
{
|
|
1566
|
+
/**
|
|
1181
1567
|
* 处理拖拽开始事件。
|
|
1182
1568
|
*
|
|
1183
1569
|
* @param e - React 拖拽事件对象
|
|
@@ -1191,153 +1577,191 @@ var EditorStore = class {
|
|
|
1191
1577
|
* 5. 计算可拖拽目标的位置
|
|
1192
1578
|
* 6. 处理拖拽过程中的视觉反馈
|
|
1193
1579
|
* 7. 在拖拽结束时更新编辑器内容
|
|
1194
|
-
*/
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
const scrollTop = container.scrollTop;
|
|
1257
|
-
const scrollLeft = container.scrollLeft;
|
|
1258
|
-
last = cur;
|
|
1259
|
-
const width = last.el.dataset.be === "list-item" ? last.el.clientWidth + 20 + "px" : last.el.clientWidth + "px";
|
|
1260
|
-
if (!mark) {
|
|
1261
|
-
mark = document.createElement("div");
|
|
1262
|
-
mark.classList.add("move-mark");
|
|
1263
|
-
mark.style.width = width;
|
|
1264
|
-
mark.style.height = "2px";
|
|
1265
|
-
mark.style.transform = `translate(${last.left - rect.left - scrollLeft}px, ${last.top - rect.top - scrollTop}px)`;
|
|
1266
|
-
container == null ? void 0 : container.parentElement.append(mark);
|
|
1267
|
-
} else {
|
|
1268
|
-
mark.style.width = width;
|
|
1269
|
-
mark.style.transform = `translate(${last.left - rect.left - scrollLeft}px, ${last.top - rect.top - scrollTop}px)`;
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
};
|
|
1273
|
-
window.addEventListener("dragover", dragover);
|
|
1274
|
-
window.addEventListener(
|
|
1275
|
-
"dragend",
|
|
1276
|
-
() => {
|
|
1277
|
-
var _a2, _b2;
|
|
1278
|
-
try {
|
|
1279
|
-
window.removeEventListener("dragover", dragover);
|
|
1280
|
-
if (mark)
|
|
1281
|
-
container == null ? void 0 : container.parentElement.removeChild(mark);
|
|
1282
|
-
if (last && this.draggedElement) {
|
|
1283
|
-
let [dragPath, dragNode] = this.toPath(this.draggedElement);
|
|
1284
|
-
let [targetPath] = this.toPath(last.el);
|
|
1285
|
-
let toPath = last.direction === "top" ? targetPath : Path.next(targetPath);
|
|
1286
|
-
if (!Path.equals(targetPath, dragPath)) {
|
|
1287
|
-
const parent = Node.parent(this._editor.current, dragPath);
|
|
1288
|
-
if (Path.equals(Path.parent(targetPath), Path.parent(dragPath)) && Path.compare(dragPath, targetPath) === -1) {
|
|
1289
|
-
toPath = Path.previous(toPath);
|
|
1290
|
-
}
|
|
1291
|
-
let delPath = Path.parent(dragPath);
|
|
1292
|
-
const targetNode = Node.get(this._editor.current, targetPath);
|
|
1293
|
-
if (dragNode.type === "list-item") {
|
|
1294
|
-
if (targetNode.type !== "list-item") {
|
|
1295
|
-
Transforms.delete(this._editor.current, { at: dragPath });
|
|
1296
|
-
Transforms.insertNodes(
|
|
1297
|
-
this._editor.current,
|
|
1298
|
-
__spreadProps(__spreadValues({}, parent), {
|
|
1299
|
-
children: [EditorUtils.copy(dragNode)]
|
|
1300
|
-
}),
|
|
1301
|
-
{ at: toPath, select: true }
|
|
1302
|
-
);
|
|
1303
|
-
if (((_a2 = parent.children) == null ? void 0 : _a2.length) === 1) {
|
|
1304
|
-
if (EditorUtils.isNextPath(Path.parent(dragPath), targetPath)) {
|
|
1305
|
-
delPath = Path.next(Path.parent(dragPath));
|
|
1306
|
-
} else {
|
|
1307
|
-
delPath = Path.parent(dragPath);
|
|
1580
|
+
*/ key: "dragStart",
|
|
1581
|
+
value: function dragStart(e, container) {
|
|
1582
|
+
var _this = this;
|
|
1583
|
+
var _this_draggedElement_dataset, _this_draggedElement;
|
|
1584
|
+
e.stopPropagation();
|
|
1585
|
+
var img = document.createElement('img');
|
|
1586
|
+
img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
|
1587
|
+
e.dataTransfer.setDragImage(img, 1, 1);
|
|
1588
|
+
var ableToEnter = ((_this_draggedElement = this.draggedElement) === null || _this_draggedElement === void 0 ? void 0 : (_this_draggedElement_dataset = _this_draggedElement.dataset) === null || _this_draggedElement_dataset === void 0 ? void 0 : _this_draggedElement_dataset.be) === 'list-item' ? new Set([
|
|
1589
|
+
'paragraph',
|
|
1590
|
+
'head',
|
|
1591
|
+
'blockquote',
|
|
1592
|
+
'code',
|
|
1593
|
+
'table',
|
|
1594
|
+
'list',
|
|
1595
|
+
'list-item',
|
|
1596
|
+
'media',
|
|
1597
|
+
'attach'
|
|
1598
|
+
]) : this.ableToEnter;
|
|
1599
|
+
var mark = null;
|
|
1600
|
+
var els = document.querySelectorAll('[data-be]');
|
|
1601
|
+
var points = [];
|
|
1602
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1603
|
+
try {
|
|
1604
|
+
// @ts-ignore
|
|
1605
|
+
for(var _iterator = els[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1606
|
+
var el = _step.value;
|
|
1607
|
+
var _this_draggedElement1;
|
|
1608
|
+
if (!ableToEnter.has(el.dataset.be)) continue;
|
|
1609
|
+
if (el.classList.contains('frontmatter')) continue;
|
|
1610
|
+
var pre = el.previousSibling;
|
|
1611
|
+
if (el.dataset.be === 'paragraph' && ((_this_draggedElement1 = this.draggedElement) === null || _this_draggedElement1 === void 0 ? void 0 : _this_draggedElement1.dataset.be) === 'list-item' && (!pre || pre.classList.contains('check-item'))) {
|
|
1612
|
+
continue;
|
|
1613
|
+
}
|
|
1614
|
+
if (el === this.draggedElement) continue;
|
|
1615
|
+
var top = getOffsetTop(el, container);
|
|
1616
|
+
var left = getOffsetLeft(el, container);
|
|
1617
|
+
points.push({
|
|
1618
|
+
el: el,
|
|
1619
|
+
direction: 'top',
|
|
1620
|
+
left: left,
|
|
1621
|
+
top: top
|
|
1622
|
+
});
|
|
1623
|
+
points.push({
|
|
1624
|
+
el: el,
|
|
1625
|
+
left: left,
|
|
1626
|
+
direction: 'bottom',
|
|
1627
|
+
top: top + el.clientHeight + 2
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
} catch (err) {
|
|
1631
|
+
_didIteratorError = true;
|
|
1632
|
+
_iteratorError = err;
|
|
1633
|
+
} finally{
|
|
1634
|
+
try {
|
|
1635
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1636
|
+
_iterator.return();
|
|
1637
|
+
}
|
|
1638
|
+
} finally{
|
|
1639
|
+
if (_didIteratorError) {
|
|
1640
|
+
throw _iteratorError;
|
|
1641
|
+
}
|
|
1308
1642
|
}
|
|
1309
|
-
}
|
|
1310
|
-
} else {
|
|
1311
|
-
Transforms.moveNodes(this._editor.current, {
|
|
1312
|
-
at: dragPath,
|
|
1313
|
-
to: toPath
|
|
1314
|
-
});
|
|
1315
1643
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1644
|
+
var last = null;
|
|
1645
|
+
var dragover = function(e) {
|
|
1646
|
+
e.preventDefault();
|
|
1647
|
+
var top = e.clientY - 40 + container.scrollTop;
|
|
1648
|
+
var distance = 1000000;
|
|
1649
|
+
var cur = null;
|
|
1650
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1651
|
+
try {
|
|
1652
|
+
for(var _iterator = points[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1653
|
+
var p = _step.value;
|
|
1654
|
+
var curDistance = Math.abs(p.top - top);
|
|
1655
|
+
if (curDistance < distance) {
|
|
1656
|
+
cur = p;
|
|
1657
|
+
distance = curDistance;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
} catch (err) {
|
|
1661
|
+
_didIteratorError = true;
|
|
1662
|
+
_iteratorError = err;
|
|
1663
|
+
} finally{
|
|
1664
|
+
try {
|
|
1665
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1666
|
+
_iterator.return();
|
|
1667
|
+
}
|
|
1668
|
+
} finally{
|
|
1669
|
+
if (_didIteratorError) {
|
|
1670
|
+
throw _iteratorError;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
if (cur) {
|
|
1675
|
+
var rect = container.getBoundingClientRect();
|
|
1676
|
+
var scrollTop = container.scrollTop;
|
|
1677
|
+
var scrollLeft = container.scrollLeft;
|
|
1678
|
+
last = cur;
|
|
1679
|
+
var width = last.el.dataset.be === 'list-item' ? last.el.clientWidth + 20 + 'px' : last.el.clientWidth + 'px';
|
|
1680
|
+
if (!mark) {
|
|
1681
|
+
mark = document.createElement('div');
|
|
1682
|
+
mark.classList.add('move-mark');
|
|
1683
|
+
mark.style.width = width;
|
|
1684
|
+
mark.style.height = '2px';
|
|
1685
|
+
mark.style.transform = "translate(".concat(last.left - rect.left - scrollLeft, "px, ").concat(last.top - rect.top - scrollTop, "px)");
|
|
1686
|
+
container === null || container === void 0 ? void 0 : container.parentElement.append(mark);
|
|
1687
|
+
} else {
|
|
1688
|
+
mark.style.width = width;
|
|
1689
|
+
mark.style.transform = "translate(".concat(last.left - rect.left - scrollLeft, "px, ").concat(last.top - rect.top - scrollTop, "px)");
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
window.addEventListener('dragover', dragover);
|
|
1694
|
+
window.addEventListener('dragend', function() {
|
|
1695
|
+
try {
|
|
1696
|
+
window.removeEventListener('dragover', dragover);
|
|
1697
|
+
if (mark) container === null || container === void 0 ? void 0 : container.parentElement.removeChild(mark);
|
|
1698
|
+
if (last && _this.draggedElement) {
|
|
1699
|
+
var _this_toPath = _sliced_to_array(_this.toPath(_this.draggedElement), 2), dragPath = _this_toPath[0], dragNode = _this_toPath[1];
|
|
1700
|
+
var _this_toPath1 = _sliced_to_array(_this.toPath(last.el), 1), targetPath = _this_toPath1[0];
|
|
1701
|
+
var toPath = last.direction === 'top' ? targetPath : Path.next(targetPath);
|
|
1702
|
+
if (!Path.equals(targetPath, dragPath)) {
|
|
1703
|
+
var _parent_children;
|
|
1704
|
+
var parent = Node.parent(_this._editor.current, dragPath);
|
|
1705
|
+
if (Path.equals(Path.parent(targetPath), Path.parent(dragPath)) && Path.compare(dragPath, targetPath) === -1) {
|
|
1706
|
+
toPath = Path.previous(toPath);
|
|
1707
|
+
}
|
|
1708
|
+
var delPath = Path.parent(dragPath);
|
|
1709
|
+
var targetNode = Node.get(_this._editor.current, targetPath);
|
|
1710
|
+
if (dragNode.type === 'list-item') {
|
|
1711
|
+
if (targetNode.type !== 'list-item') {
|
|
1712
|
+
var _parent_children1;
|
|
1713
|
+
Transforms.delete(_this._editor.current, {
|
|
1714
|
+
at: dragPath
|
|
1715
|
+
});
|
|
1716
|
+
Transforms.insertNodes(_this._editor.current, _object_spread_props(_object_spread({}, parent), {
|
|
1717
|
+
children: [
|
|
1718
|
+
EditorUtils.copy(dragNode)
|
|
1719
|
+
]
|
|
1720
|
+
}), {
|
|
1721
|
+
at: toPath,
|
|
1722
|
+
select: true
|
|
1723
|
+
});
|
|
1724
|
+
if (((_parent_children1 = parent.children) === null || _parent_children1 === void 0 ? void 0 : _parent_children1.length) === 1) {
|
|
1725
|
+
if (EditorUtils.isNextPath(Path.parent(dragPath), targetPath)) {
|
|
1726
|
+
delPath = Path.next(Path.parent(dragPath));
|
|
1727
|
+
} else {
|
|
1728
|
+
delPath = Path.parent(dragPath);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
} else {
|
|
1732
|
+
Transforms.moveNodes(_this._editor.current, {
|
|
1733
|
+
at: dragPath,
|
|
1734
|
+
to: toPath
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
} else {
|
|
1738
|
+
Transforms.moveNodes(_this._editor.current, {
|
|
1739
|
+
at: dragPath,
|
|
1740
|
+
to: toPath
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
if (((_parent_children = parent.children) === null || _parent_children === void 0 ? void 0 : _parent_children.length) === 1) {
|
|
1744
|
+
if (Path.equals(Path.parent(toPath), Path.parent(delPath)) && Path.compare(toPath, delPath) !== 1) {
|
|
1745
|
+
delPath = Path.next(delPath);
|
|
1746
|
+
}
|
|
1747
|
+
Transforms.delete(_this._editor.current, {
|
|
1748
|
+
at: delPath
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
if ((dragNode === null || dragNode === void 0 ? void 0 : dragNode.type) !== 'media') _this.draggedElement.draggable = false;
|
|
1753
|
+
}
|
|
1754
|
+
_this.draggedElement = null;
|
|
1755
|
+
} catch (error) {
|
|
1756
|
+
console.error(error);
|
|
1757
|
+
}
|
|
1758
|
+
}, {
|
|
1759
|
+
once: true
|
|
1320
1760
|
});
|
|
1321
|
-
}
|
|
1322
|
-
if (((_b2 = parent.children) == null ? void 0 : _b2.length) === 1) {
|
|
1323
|
-
if (Path.equals(Path.parent(toPath), Path.parent(delPath)) && Path.compare(toPath, delPath) !== 1) {
|
|
1324
|
-
delPath = Path.next(delPath);
|
|
1325
|
-
}
|
|
1326
|
-
Transforms.delete(this._editor.current, { at: delPath });
|
|
1327
|
-
}
|
|
1328
1761
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
this.draggedElement = null;
|
|
1333
|
-
} catch (error) {
|
|
1334
|
-
console.error(error);
|
|
1335
|
-
}
|
|
1336
|
-
},
|
|
1337
|
-
{ once: true }
|
|
1338
|
-
);
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1762
|
+
},
|
|
1763
|
+
{
|
|
1764
|
+
/**
|
|
1341
1765
|
* 替换编辑器中的文本内容
|
|
1342
1766
|
*
|
|
1343
1767
|
* @param searchText - 要查找和替换的原始文本
|
|
@@ -1360,136 +1784,130 @@ var EditorStore = class {
|
|
|
1360
1784
|
* replaceAll: false
|
|
1361
1785
|
* });
|
|
1362
1786
|
* ```
|
|
1363
|
-
*/
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1787
|
+
*/ key: "replaceText",
|
|
1788
|
+
value: function replaceText(searchText, replaceText) {
|
|
1789
|
+
var _this = this;
|
|
1790
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1791
|
+
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_replaceAll = options.replaceAll, replaceAll = _options_replaceAll === void 0 ? true : _options_replaceAll;
|
|
1792
|
+
if (!searchText) return 0;
|
|
1793
|
+
var editor = this._editor.current;
|
|
1794
|
+
var replaceCount = 0;
|
|
1795
|
+
// 遍历所有文本节点进行替换
|
|
1796
|
+
var textNodes = Array.from(Editor.nodes(editor, {
|
|
1797
|
+
at: [],
|
|
1798
|
+
match: function(n) {
|
|
1799
|
+
return Text.isText(n) && typeof n.text === 'string';
|
|
1800
|
+
}
|
|
1801
|
+
}));
|
|
1802
|
+
Editor.withoutNormalizing(editor, function() {
|
|
1803
|
+
if (replaceAll) {
|
|
1804
|
+
var _loop = function(i) {
|
|
1805
|
+
var _textNodes_i = _sliced_to_array(textNodes[i], 2), node = _textNodes_i[0], path = _textNodes_i[1];
|
|
1806
|
+
var originalText = node.text;
|
|
1807
|
+
var newText = originalText;
|
|
1808
|
+
var nodeReplaceCount = 0;
|
|
1809
|
+
if (caseSensitive) {
|
|
1810
|
+
if (wholeWord) {
|
|
1811
|
+
// 匹配完整单词
|
|
1812
|
+
var regex = new RegExp("\\b".concat(_this.escapeRegExp(searchText), "\\b"), 'g');
|
|
1813
|
+
newText = originalText.replace(regex, function() {
|
|
1814
|
+
nodeReplaceCount++;
|
|
1815
|
+
return replaceText;
|
|
1816
|
+
});
|
|
1817
|
+
} else {
|
|
1818
|
+
// 普通字符串替换
|
|
1819
|
+
newText = originalText.replace(new RegExp(_this.escapeRegExp(searchText), 'g'), function() {
|
|
1820
|
+
nodeReplaceCount++;
|
|
1821
|
+
return replaceText;
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
} else {
|
|
1825
|
+
if (wholeWord) {
|
|
1826
|
+
// 匹配完整单词,不区分大小写
|
|
1827
|
+
var regex1 = new RegExp("\\b".concat(_this.escapeRegExp(searchText), "\\b"), 'gi');
|
|
1828
|
+
newText = originalText.replace(regex1, function() {
|
|
1829
|
+
nodeReplaceCount++;
|
|
1830
|
+
return replaceText;
|
|
1831
|
+
});
|
|
1832
|
+
} else {
|
|
1833
|
+
// 普通字符串替换,不区分大小写
|
|
1834
|
+
newText = originalText.replace(new RegExp(_this.escapeRegExp(searchText), 'gi'), function() {
|
|
1835
|
+
nodeReplaceCount++;
|
|
1836
|
+
return replaceText;
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
// 如果文本发生了变化,更新节点
|
|
1841
|
+
if (newText !== originalText) {
|
|
1842
|
+
Transforms.insertText(editor, newText, {
|
|
1843
|
+
at: path,
|
|
1844
|
+
voids: true
|
|
1845
|
+
});
|
|
1846
|
+
replaceCount += nodeReplaceCount;
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
// 替换所有:从后往前处理,避免路径变化影响前面的操作
|
|
1850
|
+
for(var i = textNodes.length - 1; i >= 0; i--)_loop(i);
|
|
1851
|
+
} else {
|
|
1852
|
+
var _loop1 = function(i1) {
|
|
1853
|
+
var _textNodes_i = _sliced_to_array(textNodes[i1], 2), node = _textNodes_i[0], path = _textNodes_i[1];
|
|
1854
|
+
var originalText = node.text;
|
|
1855
|
+
var newText = originalText;
|
|
1856
|
+
var nodeReplaceCount = 0;
|
|
1857
|
+
if (caseSensitive) {
|
|
1858
|
+
if (wholeWord) {
|
|
1859
|
+
// 匹配完整单词
|
|
1860
|
+
var regex = new RegExp("\\b".concat(_this.escapeRegExp(searchText), "\\b"), '');
|
|
1861
|
+
newText = originalText.replace(regex, function() {
|
|
1862
|
+
nodeReplaceCount++;
|
|
1863
|
+
return replaceText;
|
|
1864
|
+
});
|
|
1865
|
+
} else {
|
|
1866
|
+
// 普通字符串替换
|
|
1867
|
+
newText = originalText.replace(new RegExp(_this.escapeRegExp(searchText), ''), function() {
|
|
1868
|
+
nodeReplaceCount++;
|
|
1869
|
+
return replaceText;
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
} else {
|
|
1873
|
+
if (wholeWord) {
|
|
1874
|
+
// 匹配完整单词,不区分大小写
|
|
1875
|
+
var regex1 = new RegExp("\\b".concat(_this.escapeRegExp(searchText), "\\b"), 'i');
|
|
1876
|
+
newText = originalText.replace(regex1, function() {
|
|
1877
|
+
nodeReplaceCount++;
|
|
1878
|
+
return replaceText;
|
|
1879
|
+
});
|
|
1880
|
+
} else {
|
|
1881
|
+
// 普通字符串替换,不区分大小写
|
|
1882
|
+
newText = originalText.replace(new RegExp(_this.escapeRegExp(searchText), 'i'), function() {
|
|
1883
|
+
nodeReplaceCount++;
|
|
1884
|
+
return replaceText;
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
// 如果文本发生了变化,更新节点并停止
|
|
1889
|
+
if (newText !== originalText) {
|
|
1890
|
+
Transforms.insertText(editor, newText, {
|
|
1891
|
+
at: path,
|
|
1892
|
+
voids: true
|
|
1893
|
+
});
|
|
1894
|
+
replaceCount += nodeReplaceCount;
|
|
1895
|
+
return "break" // 只替换第一个匹配项
|
|
1896
|
+
;
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
// 只替换第一个:从前往后处理,找到第一个匹配就停止
|
|
1900
|
+
for(var i1 = 0; i1 < textNodes.length; i1++){
|
|
1901
|
+
var _ret = _loop1(i1);
|
|
1902
|
+
if (_ret === "break") break;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
return replaceCount;
|
|
1477
1907
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
at: path,
|
|
1482
|
-
voids: true
|
|
1483
|
-
});
|
|
1484
|
-
replaceCount += nodeReplaceCount;
|
|
1485
|
-
break;
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
});
|
|
1490
|
-
return replaceCount;
|
|
1491
|
-
}
|
|
1492
|
-
/**
|
|
1908
|
+
},
|
|
1909
|
+
{
|
|
1910
|
+
/**
|
|
1493
1911
|
* 在选中的区域内替换文本
|
|
1494
1912
|
*
|
|
1495
1913
|
* @param searchText - 要查找和替换的原始文本
|
|
@@ -1506,87 +1924,80 @@ var EditorStore = class {
|
|
|
1506
1924
|
* // 在选中区域内替换文本
|
|
1507
1925
|
* const count = store.replaceTextInSelection("old", "new");
|
|
1508
1926
|
* ```
|
|
1509
|
-
*/
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
});
|
|
1587
|
-
return replaceCount;
|
|
1588
|
-
}
|
|
1589
|
-
/**
|
|
1927
|
+
*/ key: "replaceTextInSelection",
|
|
1928
|
+
value: function replaceTextInSelection(searchText, replaceText) {
|
|
1929
|
+
var _this = this;
|
|
1930
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1931
|
+
var editor = this._editor.current;
|
|
1932
|
+
var selection = editor.selection;
|
|
1933
|
+
if (!selection || Range.isCollapsed(selection)) {
|
|
1934
|
+
return 0;
|
|
1935
|
+
}
|
|
1936
|
+
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_replaceAll = options.replaceAll, replaceAll = _options_replaceAll === void 0 ? true : _options_replaceAll;
|
|
1937
|
+
if (!searchText) return 0;
|
|
1938
|
+
var replaceCount = 0;
|
|
1939
|
+
// 获取选中区域的文本节点
|
|
1940
|
+
var textNodes = Array.from(Editor.nodes(editor, {
|
|
1941
|
+
at: selection,
|
|
1942
|
+
match: function(n) {
|
|
1943
|
+
return Text.isText(n) && typeof n.text === 'string';
|
|
1944
|
+
}
|
|
1945
|
+
}));
|
|
1946
|
+
Editor.withoutNormalizing(editor, function() {
|
|
1947
|
+
var _loop = function(i) {
|
|
1948
|
+
var _textNodes_i = _sliced_to_array(textNodes[i], 2), node = _textNodes_i[0], path = _textNodes_i[1];
|
|
1949
|
+
var originalText = node.text;
|
|
1950
|
+
var newText = originalText;
|
|
1951
|
+
var nodeReplaceCount = 0;
|
|
1952
|
+
if (caseSensitive) {
|
|
1953
|
+
if (wholeWord) {
|
|
1954
|
+
var regex = new RegExp("\\b".concat(_this.escapeRegExp(searchText), "\\b"), 'g');
|
|
1955
|
+
newText = originalText.replace(regex, function() {
|
|
1956
|
+
nodeReplaceCount++;
|
|
1957
|
+
return replaceText;
|
|
1958
|
+
});
|
|
1959
|
+
} else {
|
|
1960
|
+
newText = originalText.replace(new RegExp(_this.escapeRegExp(searchText), 'g'), function() {
|
|
1961
|
+
nodeReplaceCount++;
|
|
1962
|
+
return replaceText;
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
} else {
|
|
1966
|
+
if (wholeWord) {
|
|
1967
|
+
var regex1 = new RegExp("\\b".concat(_this.escapeRegExp(searchText), "\\b"), 'gi');
|
|
1968
|
+
newText = originalText.replace(regex1, function() {
|
|
1969
|
+
nodeReplaceCount++;
|
|
1970
|
+
return replaceText;
|
|
1971
|
+
});
|
|
1972
|
+
} else {
|
|
1973
|
+
newText = originalText.replace(new RegExp(_this.escapeRegExp(searchText), 'gi'), function() {
|
|
1974
|
+
nodeReplaceCount++;
|
|
1975
|
+
return replaceText;
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
if (newText !== originalText) {
|
|
1980
|
+
Transforms.insertText(editor, newText, {
|
|
1981
|
+
at: path,
|
|
1982
|
+
voids: true
|
|
1983
|
+
});
|
|
1984
|
+
replaceCount += nodeReplaceCount;
|
|
1985
|
+
if (!replaceAll && nodeReplaceCount > 0) {
|
|
1986
|
+
return "break";
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
};
|
|
1990
|
+
// 从后往前处理,避免路径变化影响前面的操作
|
|
1991
|
+
for(var i = textNodes.length - 1; i >= 0; i--){
|
|
1992
|
+
var _ret = _loop(i);
|
|
1993
|
+
if (_ret === "break") break;
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
return replaceCount;
|
|
1997
|
+
}
|
|
1998
|
+
},
|
|
1999
|
+
{
|
|
2000
|
+
/**
|
|
1590
2001
|
* 替换所有匹配的文本(replaceText 的简化版本)
|
|
1591
2002
|
*
|
|
1592
2003
|
* @param searchText - 要查找和替换的原始文本
|
|
@@ -1603,24 +2014,29 @@ var EditorStore = class {
|
|
|
1603
2014
|
* // 区分大小写替换
|
|
1604
2015
|
* const count = store.replaceAll("Old", "New", true);
|
|
1605
2016
|
* ```
|
|
1606
|
-
*/
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
2017
|
+
*/ key: "replaceAll",
|
|
2018
|
+
value: function replaceAll(searchText, replaceText) {
|
|
2019
|
+
var caseSensitive = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
2020
|
+
return this.replaceText(searchText, replaceText, {
|
|
2021
|
+
caseSensitive: caseSensitive,
|
|
2022
|
+
replaceAll: true
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
},
|
|
2026
|
+
{
|
|
2027
|
+
key: "escapeRegExp",
|
|
2028
|
+
value: /**
|
|
1614
2029
|
* 转义正则表达式特殊字符
|
|
1615
2030
|
*
|
|
1616
2031
|
* @param string - 需要转义的字符串
|
|
1617
2032
|
* @returns 转义后的字符串
|
|
1618
2033
|
* @private
|
|
1619
|
-
*/
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
2034
|
+
*/ function escapeRegExp(string) {
|
|
2035
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2036
|
+
}
|
|
2037
|
+
},
|
|
2038
|
+
{
|
|
2039
|
+
/**
|
|
1624
2040
|
* 在编辑器中根据路径描述和文本内容查找并选择匹配位置
|
|
1625
2041
|
*
|
|
1626
2042
|
* @param pathDescription - 路径描述,用于限制搜索范围。可以是:
|
|
@@ -1635,23 +2051,21 @@ var EditorStore = class {
|
|
|
1635
2051
|
* ```ts
|
|
1636
2052
|
* // 查找所有包含 "focus" 的位置
|
|
1637
2053
|
* const results = store.findByPathAndText("", "focus");
|
|
1638
|
-
*/
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1654
|
-
/**
|
|
2054
|
+
*/ key: "findByPathAndText",
|
|
2055
|
+
value: function findByPathAndText1(pathDescription, searchText) {
|
|
2056
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2057
|
+
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 ? 50 : _options_maxResults;
|
|
2058
|
+
if (!searchText.trim()) return [];
|
|
2059
|
+
var editor = this._editor.current;
|
|
2060
|
+
return findByPathAndText(editor, pathDescription, searchText, {
|
|
2061
|
+
caseSensitive: caseSensitive,
|
|
2062
|
+
wholeWord: wholeWord,
|
|
2063
|
+
maxResults: maxResults
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
},
|
|
2067
|
+
{
|
|
2068
|
+
/**
|
|
1655
2069
|
* 更新编辑器的状态数据
|
|
1656
2070
|
*
|
|
1657
2071
|
* @param value - 状态更新器,可以是函数或对象
|
|
@@ -1674,19 +2088,35 @@ var EditorStore = class {
|
|
|
1674
2088
|
* manual: false
|
|
1675
2089
|
* });
|
|
1676
2090
|
* ```
|
|
1677
|
-
*/
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
}
|
|
2091
|
+
*/ key: "setState",
|
|
2092
|
+
value: function setState(value) {
|
|
2093
|
+
if (value instanceof Function) {
|
|
2094
|
+
value(this);
|
|
2095
|
+
} else {
|
|
2096
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2097
|
+
try {
|
|
2098
|
+
for(var _iterator = Object.keys(value)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2099
|
+
var key = _step.value;
|
|
2100
|
+
// @ts-ignore
|
|
2101
|
+
this[key] = value[key];
|
|
2102
|
+
}
|
|
2103
|
+
} catch (err) {
|
|
2104
|
+
_didIteratorError = true;
|
|
2105
|
+
_iteratorError = err;
|
|
2106
|
+
} finally{
|
|
2107
|
+
try {
|
|
2108
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2109
|
+
_iterator.return();
|
|
2110
|
+
}
|
|
2111
|
+
} finally{
|
|
2112
|
+
if (_didIteratorError) {
|
|
2113
|
+
throw _iteratorError;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
]);
|
|
2121
|
+
return EditorStore;
|
|
2122
|
+
}();
|