@bendyline/squisq-editor-react 2.1.0 → 2.2.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/LICENSE +21 -0
- package/NOTICE.md +40 -0
- package/dist/index.d.ts +188 -55
- package/dist/index.js +5094 -2948
- package/dist/monaco.js +0 -1
- package/dist/styles/index.css +234 -145
- package/package.json +9 -6
- package/dist/index.js.map +0 -1
- package/dist/monaco.js.map +0 -1
- package/src/BlockCardView.tsx +0 -121
- package/src/BlockPreviewPanel.tsx +0 -69
- package/src/BlockPropertiesPopover.tsx +0 -222
- package/src/DocumentSettingsDialog.tsx +0 -272
- package/src/DropZoneOverlay.tsx +0 -137
- package/src/EditorContext.tsx +0 -1274
- package/src/EditorShell.tsx +0 -1358
- package/src/EmojiPicker.tsx +0 -332
- package/src/FolderView.tsx +0 -131
- package/src/Icon.tsx +0 -26
- package/src/ImageEditor.tsx +0 -395
- package/src/ImageNodeView.tsx +0 -284
- package/src/ImageViewer.tsx +0 -221
- package/src/InlineIcon.ts +0 -84
- package/src/InlinePreviewGutter.tsx +0 -590
- package/src/LinkDialog.tsx +0 -276
- package/src/MediaBin.tsx +0 -500
- package/src/MentionExtension.tsx +0 -261
- package/src/OutlinePanel.tsx +0 -547
- package/src/PlainHtmlPreview.tsx +0 -277
- package/src/PreviewControls.tsx +0 -1265
- package/src/PreviewPanel.tsx +0 -426
- package/src/RawEditor.tsx +0 -743
- package/src/RecorderEntry.tsx +0 -162
- package/src/StatusBar.tsx +0 -51
- package/src/TemplateAnnotation.ts +0 -167
- package/src/TemplateContentPreview.tsx +0 -56
- package/src/TemplatePicker.tsx +0 -1314
- package/src/ThemeCustomizerPanel.tsx +0 -304
- package/src/ThemePicker.tsx +0 -433
- package/src/TimelineBlockPreview.tsx +0 -37
- package/src/TimelineTrack.tsx +0 -671
- package/src/Toolbar.tsx +0 -2885
- package/src/Tooltip.tsx +0 -142
- package/src/TransitionPicker.tsx +0 -390
- package/src/VersionHistoryPanel.tsx +0 -359
- package/src/ViewMenuPanel.tsx +0 -189
- package/src/ViewSwitcher.tsx +0 -56
- package/src/WysiwygEditor.tsx +0 -806
- package/src/__tests__/blockProperties.test.ts +0 -92
- package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
- package/src/__tests__/blockRange.test.ts +0 -105
- package/src/__tests__/blockTagActivity.test.ts +0 -183
- package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
- package/src/__tests__/buildPreviewDocContent.test.ts +0 -65
- package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
- package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
- package/src/__tests__/codeContextSectionView.test.tsx +0 -97
- package/src/__tests__/codeContextZoneManager.test.ts +0 -127
- package/src/__tests__/createShapeLayer.test.ts +0 -46
- package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
- package/src/__tests__/detectMarkdown.test.ts +0 -73
- package/src/__tests__/diffContextSections.test.ts +0 -39
- package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
- package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
- package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
- package/src/__tests__/editorScrollSync.test.ts +0 -65
- package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
- package/src/__tests__/editorShellProps.test.tsx +0 -550
- package/src/__tests__/embeddedMedia.test.ts +0 -48
- package/src/__tests__/emojiPicker.test.tsx +0 -93
- package/src/__tests__/fileKind.test.ts +0 -112
- package/src/__tests__/findMode.test.tsx +0 -104
- package/src/__tests__/findModel.test.ts +0 -55
- package/src/__tests__/headingTransition.test.ts +0 -176
- package/src/__tests__/imageEditAffordance.test.tsx +0 -272
- package/src/__tests__/imageEditModalContract.test.tsx +0 -119
- package/src/__tests__/imageEditorShell.test.tsx +0 -94
- package/src/__tests__/imageEditorState.test.ts +0 -171
- package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
- package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
- package/src/__tests__/jsonEditor.test.tsx +0 -223
- package/src/__tests__/layersPanel.test.tsx +0 -167
- package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
- package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
- package/src/__tests__/majorApiTypes.test.ts +0 -26
- package/src/__tests__/markdownCodeFence.test.ts +0 -45
- package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
- package/src/__tests__/mediaBinDrop.test.tsx +0 -90
- package/src/__tests__/mediaReferences.test.ts +0 -97
- package/src/__tests__/narrationSave.test.ts +0 -148
- package/src/__tests__/outlinePanel.test.tsx +0 -169
- package/src/__tests__/outlineSource.test.ts +0 -217
- package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
- package/src/__tests__/presentationMode.test.tsx +0 -290
- package/src/__tests__/previewControls.test.tsx +0 -571
- package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
- package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
- package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
- package/src/__tests__/propertiesPanel.test.tsx +0 -69
- package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
- package/src/__tests__/recorderFormats.test.ts +0 -146
- package/src/__tests__/recorderMediaInsert.test.ts +0 -86
- package/src/__tests__/recorderTheme.test.tsx +0 -42
- package/src/__tests__/recorderTimingJson.test.ts +0 -41
- package/src/__tests__/resolveBlockVisual.test.ts +0 -43
- package/src/__tests__/selectionConversions.test.ts +0 -80
- package/src/__tests__/statusBar.test.tsx +0 -27
- package/src/__tests__/teleprompter.test.tsx +0 -190
- package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
- package/src/__tests__/templateContentPreview.test.ts +0 -101
- package/src/__tests__/templatePickerMetadata.test.ts +0 -32
- package/src/__tests__/templatePickerPortal.test.tsx +0 -62
- package/src/__tests__/timelineSource.test.ts +0 -134
- package/src/__tests__/tiptapBridge.test.ts +0 -575
- package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
- package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
- package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
- package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -190
- package/src/__tests__/tooltip.test.tsx +0 -72
- package/src/__tests__/transformStyleId.test.ts +0 -13
- package/src/__tests__/transitionCatalog.test.ts +0 -64
- package/src/__tests__/useBlockNavigator.test.tsx +0 -67
- package/src/__tests__/useImageEditor.test.tsx +0 -226
- package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
- package/src/__tests__/useMediaRecorder.test.ts +0 -302
- package/src/__tests__/useTimelineClock.test.ts +0 -21
- package/src/__tests__/versionHistory.test.tsx +0 -197
- package/src/__tests__/viewMenuPanel.test.tsx +0 -130
- package/src/__tests__/writeCanvasSettings.test.ts +0 -15
- package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
- package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
- package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
- package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
- package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
- package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -164
- package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
- package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
- package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
- package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
- package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
- package/src/asciiDiagram/asciiDiagramData.ts +0 -149
- package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
- package/src/asciiDiagram/asciiPaste.ts +0 -19
- package/src/blockProperties.ts +0 -88
- package/src/blockRange.ts +0 -132
- package/src/blockSlice.ts +0 -75
- package/src/blockTagActivity.ts +0 -233
- package/src/buildDocumentPreviewMarkdown.ts +0 -168
- package/src/buildPreviewDoc.ts +0 -407
- package/src/codeContext/CodeContextSectionView.tsx +0 -124
- package/src/codeContext/CodeContextZoneManager.ts +0 -149
- package/src/codeContext/CodeContextZones.tsx +0 -121
- package/src/codeContext/diffContextSections.ts +0 -38
- package/src/codeContext/types.ts +0 -75
- package/src/codeSnippet/CodeSnippetExtension.ts +0 -205
- package/src/codeSnippet/CodeSnippetWidget.tsx +0 -109
- package/src/codeSnippet/__tests__/CodeSnippetExtension.test.ts +0 -95
- package/src/codeSnippet/__tests__/codeSnippetLanguages.test.ts +0 -50
- package/src/codeSnippet/codeSnippetCommands.ts +0 -21
- package/src/codeSnippet/codeSnippetData.ts +0 -43
- package/src/codeSnippet/codeSnippetLanguages.ts +0 -216
- package/src/customTemplates/AddBin.tsx +0 -126
- package/src/customTemplates/CustomLayoutManager.tsx +0 -234
- package/src/customTemplates/CustomTemplateContext.tsx +0 -188
- package/src/customTemplates/LayerToolbar.tsx +0 -580
- package/src/customTemplates/ShapeGlyph.tsx +0 -47
- package/src/customTemplates/TemplateDesigner.tsx +0 -433
- package/src/customTemplates/__tests__/library.test.ts +0 -96
- package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
- package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
- package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
- package/src/customTemplates/designer.css +0 -732
- package/src/customTemplates/index.ts +0 -31
- package/src/customTemplates/library.ts +0 -110
- package/src/customTemplates/normalizePositions.ts +0 -75
- package/src/customTemplates/shapeDefs.ts +0 -131
- package/src/customTemplates/thumbnail.tsx +0 -63
- package/src/customTemplates/tokenDefs.ts +0 -60
- package/src/customTemplates/useDocCustomTemplates.ts +0 -52
- package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
- package/src/customThemes/CustomThemeContext.tsx +0 -185
- package/src/customThemes/CustomThemeDialog.tsx +0 -316
- package/src/customThemes/ImportThemeSection.tsx +0 -178
- package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
- package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
- package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
- package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
- package/src/customThemes/customThemeLibrary.ts +0 -100
- package/src/customThemes/index.ts +0 -37
- package/src/customThemes/themeControls.tsx +0 -229
- package/src/customThemes/themeDraft.ts +0 -288
- package/src/customThemes/useDocCustomThemes.ts +0 -49
- package/src/detectMarkdown.ts +0 -62
- package/src/diagram/DiagramCanvas.tsx +0 -260
- package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
- package/src/diagram/diagramCommands.ts +0 -604
- package/src/diagram/diagramConstants.ts +0 -17
- package/src/diagram/types.ts +0 -35
- package/src/editorScrollSync.ts +0 -73
- package/src/embeddedMedia.ts +0 -78
- package/src/emojiData.ts +0 -1317
- package/src/fileKind.ts +0 -158
- package/src/find/FindHighlightExtension.ts +0 -81
- package/src/find/FindToolbar.tsx +0 -314
- package/src/find/findModel.ts +0 -77
- package/src/frontmatter.ts +0 -29
- package/src/frontmatterSettings.ts +0 -23
- package/src/headingTransition.ts +0 -291
- package/src/hooks/useFileDrop.ts +0 -266
- package/src/imageEditor/CanvasSurface.tsx +0 -703
- package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
- package/src/imageEditor/LayersPanel.tsx +0 -218
- package/src/imageEditor/PropertiesPanel.tsx +0 -474
- package/src/imageEditor/Toolbar.tsx +0 -459
- package/src/imageEditor/createShapeLayer.ts +0 -280
- package/src/imageEditor/icons.tsx +0 -68
- package/src/imageEditor/image-editor.css +0 -574
- package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
- package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
- package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
- package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
- package/src/imageEditor/state.ts +0 -173
- package/src/imageEditor/useImageEditor.ts +0 -385
- package/src/imageEditor/useImageEditorTokens.ts +0 -70
- package/src/index.ts +0 -559
- package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
- package/src/jsonEditor/JsonEditor.tsx +0 -81
- package/src/jsonEditor/JsonEditorContext.tsx +0 -81
- package/src/jsonEditor/RenderNode.tsx +0 -87
- package/src/jsonEditor/editors.tsx +0 -745
- package/src/jsonEditor/index.ts +0 -2
- package/src/jsonEditor/json-editor.css +0 -463
- package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
- package/src/markdownCodeFence.ts +0 -72
- package/src/mediaDragMime.ts +0 -32
- package/src/mediaEntries.ts +0 -12
- package/src/mediaReferences.ts +0 -301
- package/src/mermaid/MermaidDiagramCanvas.tsx +0 -693
- package/src/mermaid/MermaidDiagramExtension.ts +0 -243
- package/src/mermaid/MermaidDiagramTypeThumbnail.tsx +0 -184
- package/src/mermaid/MermaidDiagramWidget.tsx +0 -653
- package/src/mermaid/MermaidShapePalette.tsx +0 -245
- package/src/mermaid/__tests__/MermaidDiagramExtension.test.ts +0 -361
- package/src/mermaid/__tests__/mermaidDiagramTypes.test.ts +0 -35
- package/src/mermaid/__tests__/mermaidRenderer.test.ts +0 -49
- package/src/mermaid/__tests__/mermaidSourceOps.test.ts +0 -213
- package/src/mermaid/__tests__/mermaidSyntax.test.ts +0 -71
- package/src/mermaid/mermaidCommands.ts +0 -34
- package/src/mermaid/mermaidData.ts +0 -31
- package/src/mermaid/mermaidDiagramTypes.ts +0 -325
- package/src/mermaid/mermaidModel.ts +0 -31
- package/src/mermaid/mermaidRenderer.ts +0 -181
- package/src/mermaid/mermaidShapes.ts +0 -113
- package/src/mermaid/mermaidSourceOps.ts +0 -454
- package/src/monaco.ts +0 -35
- package/src/monacoWorkers.ts +0 -89
- package/src/outlineSource.ts +0 -171
- package/src/presentation/PresentationMode.tsx +0 -596
- package/src/rawEditorIsolation.ts +0 -18
- package/src/recorder/RecorderButton.tsx +0 -80
- package/src/recorder/RecorderModal.tsx +0 -706
- package/src/recorder/RecorderPanel.tsx +0 -77
- package/src/recorder/formats.ts +0 -159
- package/src/recorder/hooks/useMediaRecorder.ts +0 -436
- package/src/recorder/hooks/useStreamPreview.ts +0 -47
- package/src/recorder/insertMediaBlock.ts +0 -30
- package/src/recorder/sources/cameraStream.ts +0 -32
- package/src/recorder/sources/micStream.ts +0 -25
- package/src/recorder/sources/screenStream.ts +0 -162
- package/src/recorder/timingJson.ts +0 -66
- package/src/resolveBlockVisual.ts +0 -39
- package/src/scene/Scene.tsx +0 -647
- package/src/scene/SceneBlockExtension.ts +0 -205
- package/src/scene/SceneBlockToolbar.tsx +0 -216
- package/src/scene/SceneBlockWidget.tsx +0 -441
- package/src/scene/ScenePropsBar.tsx +0 -85
- package/src/scene/SceneSelection.tsx +0 -111
- package/src/scene/SceneSideToolbar.tsx +0 -89
- package/src/scene/SceneViewControls.tsx +0 -43
- package/src/scene/SceneViewport.tsx +0 -106
- package/src/scene/ShapePalette.tsx +0 -196
- package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
- package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
- package/src/scene/__tests__/bezierEdit.test.ts +0 -85
- package/src/scene/__tests__/blockLayers.test.ts +0 -57
- package/src/scene/__tests__/fitScale.test.ts +0 -19
- package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
- package/src/scene/__tests__/shapeLayers.test.ts +0 -106
- package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
- package/src/scene/__tests__/useScenePanZoom.test.ts +0 -130
- package/src/scene/adapters/DiagramAdapter.ts +0 -79
- package/src/scene/adapters/DrawingAdapter.ts +0 -420
- package/src/scene/adapters/LayoutAdapter.ts +0 -313
- package/src/scene/adapters/blockLayers.ts +0 -159
- package/src/scene/commands/SceneCommand.ts +0 -84
- package/src/scene/commands/drawingCommands.ts +0 -318
- package/src/scene/commands/layoutCommands.ts +0 -301
- package/src/scene/fitScale.ts +0 -17
- package/src/scene/hooks/useSceneHitTest.ts +0 -105
- package/src/scene/hooks/useScenePanZoom.ts +0 -154
- package/src/scene/hooks/useSceneSelection.ts +0 -62
- package/src/scene/index.ts +0 -90
- package/src/scene/layers/DiagramEdges.tsx +0 -142
- package/src/scene/layers/edgeGeometry.ts +0 -104
- package/src/scene/layers/nodeCard.tsx +0 -164
- package/src/scene/layers/renderLayer.tsx +0 -70
- package/src/scene/layers/shapeLayers.ts +0 -201
- package/src/scene/paths/bezierEdit.ts +0 -208
- package/src/scene/scene.css +0 -874
- package/src/scene/text/SceneTextOverlay.tsx +0 -161
- package/src/scene/text/sceneTextChannel.ts +0 -46
- package/src/scene/text/sceneTextConfig.ts +0 -31
- package/src/scene/text/sceneTiptap.ts +0 -36
- package/src/scene/text/useSceneTextEditing.ts +0 -39
- package/src/scene/tools/ConnectTool.ts +0 -209
- package/src/scene/tools/DrawingConnectTool.ts +0 -231
- package/src/scene/tools/PathTool.ts +0 -158
- package/src/scene/tools/PlaceTool.ts +0 -47
- package/src/scene/tools/SceneTool.ts +0 -85
- package/src/scene/tools/SelectTool.ts +0 -300
- package/src/scene/tools/ShapeTool.ts +0 -143
- package/src/scene/tools/TextTool.ts +0 -72
- package/src/scene/tools/TokenTool.ts +0 -95
- package/src/scene/tools/createDrawShapeTool.ts +0 -82
- package/src/selectionConversions.ts +0 -155
- package/src/styles/ascii-diagram.css +0 -79
- package/src/styles/ascii-timeline.css +0 -596
- package/src/styles/code-context.css +0 -155
- package/src/styles/code-snippet.css +0 -76
- package/src/styles/diagram.css +0 -183
- package/src/styles/editor.css +0 -7131
- package/src/styles/folder-view.css +0 -210
- package/src/styles/image-edit-affordance.css +0 -201
- package/src/styles/index.css +0 -20
- package/src/styles/mermaid-diagram.css +0 -487
- package/src/styles/tree-view.css +0 -189
- package/src/teleprompter/TeleprompterControls.tsx +0 -218
- package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
- package/src/teleprompter/TeleprompterSurface.tsx +0 -267
- package/src/teleprompter/TeleprompterView.tsx +0 -338
- package/src/teleprompter/canvasRenderer.ts +0 -161
- package/src/teleprompter/floatingWindow.ts +0 -352
- package/src/teleprompter/index.ts +0 -61
- package/src/teleprompter/pcmWorklet.ts +0 -62
- package/src/teleprompter/recording/insertPreamble.ts +0 -80
- package/src/teleprompter/recording/narrationSave.ts +0 -134
- package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
- package/src/teleprompter/scrollModel.ts +0 -85
- package/src/teleprompter/teleprompterTheme.ts +0 -303
- package/src/teleprompter/types.ts +0 -38
- package/src/teleprompter/useFloatingWindow.ts +0 -74
- package/src/teleprompter/useMicAnalysis.ts +0 -211
- package/src/teleprompter/useTeleprompter.ts +0 -421
- package/src/templateContentPreviewResolver.ts +0 -360
- package/src/timeline/TimelineEditorWidget.tsx +0 -861
- package/src/timeline/TimelineViewExtension.ts +0 -252
- package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
- package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
- package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
- package/src/timeline/__tests__/timelineOps.test.ts +0 -277
- package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
- package/src/timeline/timelineCommands.ts +0 -421
- package/src/timeline/timelineData.ts +0 -54
- package/src/timeline/timelineOps.ts +0 -381
- package/src/timeline/timelinePaste.ts +0 -8
- package/src/timelineSource.ts +0 -244
- package/src/tiptap/TiptapAudio.tsx +0 -86
- package/src/tiptap/TiptapVideo.tsx +0 -119
- package/src/tiptap/useResolvedMediaSrc.ts +0 -47
- package/src/tiptapBridge.ts +0 -986
- package/src/tooltipPlacement.ts +0 -13
- package/src/transformStyleId.ts +0 -17
- package/src/transitionCatalog.ts +0 -159
- package/src/treeview/TreeOutlineWidget.tsx +0 -390
- package/src/treeview/TreeViewExtension.ts +0 -250
- package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
- package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
- package/src/treeview/__tests__/treeOps.test.ts +0 -177
- package/src/treeview/__tests__/treePaste.test.ts +0 -40
- package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
- package/src/treeview/treeOps.ts +0 -231
- package/src/treeview/treePaste.ts +0 -13
- package/src/treeview/treeViewCommands.ts +0 -99
- package/src/treeview/treeViewData.ts +0 -41
- package/src/types/monaco-shims.d.ts +0 -10
- package/src/useBlockNavigator.ts +0 -153
- package/src/useHeadingLayout.ts +0 -294
- package/src/useMonacoLoader.ts +0 -82
- package/src/useTimelineClock.ts +0 -76
- package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
- package/src/utils/dropUtils.ts +0 -136
- package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
- package/src/writeCanvasSettings.ts +0 -30
- package/src/wysiwygImageUpload.ts +0 -113
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { parseTree, renderTree, type Tree, type TreeNode } from '@bendyline/squisq/doc';
|
|
3
|
-
import {
|
|
4
|
-
addItemOp,
|
|
5
|
-
indentItemOp,
|
|
6
|
-
moveItemOp,
|
|
7
|
-
moveItemDownOp,
|
|
8
|
-
moveItemUpOp,
|
|
9
|
-
outdentItemOp,
|
|
10
|
-
removeItemOp,
|
|
11
|
-
renameItemOp,
|
|
12
|
-
sanitizeTreeLabel,
|
|
13
|
-
toggleDirOp,
|
|
14
|
-
} from '../treeOps';
|
|
15
|
-
|
|
16
|
-
function tree(art: string): Tree {
|
|
17
|
-
return parseTree(art);
|
|
18
|
-
}
|
|
19
|
-
function flat(t: Tree): string[] {
|
|
20
|
-
const out: string[] = [];
|
|
21
|
-
const walk = (ns: TreeNode[], d: number) => {
|
|
22
|
-
for (const n of ns) {
|
|
23
|
-
out.push(`${d}:${n.label}`);
|
|
24
|
-
walk(n.children, d + 1);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
walk(t.roots, 0);
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const BASE = ['root/', '├── a', '├── b/', '│ └── b1', '└── c'].join('\n');
|
|
32
|
-
|
|
33
|
-
describe('sanitizeTreeLabel', () => {
|
|
34
|
-
it('strips connector glyphs and newlines', () => {
|
|
35
|
-
expect(sanitizeTreeLabel('a ├── b │ c\nd')).toBe('a b c d');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('treeOps', () => {
|
|
40
|
-
it('renameItemOp renames without mutating the input', () => {
|
|
41
|
-
const t = tree(BASE);
|
|
42
|
-
const next = renameItemOp(t, 'a', 'alpha');
|
|
43
|
-
expect(flat(next)).toContain('1:alpha');
|
|
44
|
-
expect(flat(t)).toContain('1:a'); // original untouched
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('addItemOp adds a child and a sibling', () => {
|
|
48
|
-
const child = addItemOp(tree(BASE), 'a', 'child', 'a1');
|
|
49
|
-
const aNode = child.roots[0].children.find((n) => n.label === 'a');
|
|
50
|
-
expect(aNode?.children.map((c) => c.label)).toEqual(['a1']);
|
|
51
|
-
|
|
52
|
-
const sib = addItemOp(tree(BASE), 'a', 'siblingAfter', 'a2');
|
|
53
|
-
expect(sib.roots[0].children.map((c) => c.label)).toEqual(['a', 'a2', 'b/', 'c']);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('addItemOp with isDir adds a trailing-slash folder with a folder default name', () => {
|
|
57
|
-
// Explicit label gets a slash.
|
|
58
|
-
const named = addItemOp(tree(BASE), 'a', 'siblingAfter', 'assets', true);
|
|
59
|
-
const assets = named.roots[0].children.find((n) => n.label === 'assets/');
|
|
60
|
-
expect(assets?.isDir).toBe(true);
|
|
61
|
-
|
|
62
|
-
// Default name is a fresh `folderN/`.
|
|
63
|
-
const auto = addItemOp(tree(BASE), 'a', 'siblingAfter', undefined, true);
|
|
64
|
-
const folder = auto.roots[0].children.find((n) => n.label.startsWith('folder'));
|
|
65
|
-
expect(folder?.label).toBe('folder1/');
|
|
66
|
-
expect(folder?.isDir).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('removeItemOp drops a node and its subtree', () => {
|
|
70
|
-
const next = removeItemOp(tree(BASE), 'b');
|
|
71
|
-
expect(flat(next)).toEqual(['0:root/', '1:a', '1:c']);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('indentItemOp re-parents under the preceding sibling', () => {
|
|
75
|
-
const next = indentItemOp(tree(BASE), 'c'); // c indents under b/
|
|
76
|
-
expect(flat(next)).toEqual(['0:root/', '1:a', '1:b/', '2:b1', '2:c']);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('indentItemOp is a no-op for the first sibling', () => {
|
|
80
|
-
const t = tree(BASE);
|
|
81
|
-
expect(indentItemOp(t, 'a')).toBe(t);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('outdentItemOp promotes a node to a sibling of its parent (subtree carried)', () => {
|
|
85
|
-
const next = outdentItemOp(tree(BASE), 'b1'); // b1 outdents next to b/
|
|
86
|
-
expect(flat(next)).toEqual(['0:root/', '1:a', '1:b/', '1:b1', '1:c']);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('outdentItemOp is a no-op for a root', () => {
|
|
90
|
-
const t = tree(BASE);
|
|
91
|
-
expect(outdentItemOp(t, 'root')).toBe(t);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('moveItemOp reorders siblings before or after a target', () => {
|
|
95
|
-
expect(flat(moveItemOp(tree(BASE), 'c', 'a', 'before'))).toEqual([
|
|
96
|
-
'0:root/',
|
|
97
|
-
'1:c',
|
|
98
|
-
'1:a',
|
|
99
|
-
'1:b/',
|
|
100
|
-
'2:b1',
|
|
101
|
-
]);
|
|
102
|
-
expect(flat(moveItemOp(tree(BASE), 'b', 'c', 'after'))).toEqual([
|
|
103
|
-
'0:root/',
|
|
104
|
-
'1:a',
|
|
105
|
-
'1:c',
|
|
106
|
-
'1:b/',
|
|
107
|
-
'2:b1',
|
|
108
|
-
]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('moveItemOp reparents nodes and carries their subtrees', () => {
|
|
112
|
-
expect(flat(moveItemOp(tree(BASE), 'c', 'a', 'child'))).toEqual([
|
|
113
|
-
'0:root/',
|
|
114
|
-
'1:a',
|
|
115
|
-
'2:c',
|
|
116
|
-
'1:b/',
|
|
117
|
-
'2:b1',
|
|
118
|
-
]);
|
|
119
|
-
expect(flat(moveItemOp(tree(BASE), 'b', 'a', 'child'))).toEqual([
|
|
120
|
-
'0:root/',
|
|
121
|
-
'1:a',
|
|
122
|
-
'2:b/',
|
|
123
|
-
'3:b1',
|
|
124
|
-
'1:c',
|
|
125
|
-
]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('moveItemOp can outdent relative to a shallower target', () => {
|
|
129
|
-
expect(flat(moveItemOp(tree(BASE), 'b1', 'b', 'before'))).toEqual([
|
|
130
|
-
'0:root/',
|
|
131
|
-
'1:a',
|
|
132
|
-
'1:b1',
|
|
133
|
-
'1:b/',
|
|
134
|
-
'1:c',
|
|
135
|
-
]);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('moveItemOp rejects self-drops and drops into the source subtree', () => {
|
|
139
|
-
const t = tree(BASE);
|
|
140
|
-
expect(moveItemOp(t, 'b', 'b', 'child')).toBe(t);
|
|
141
|
-
expect(moveItemOp(t, 'b', 'b1', 'child')).toBe(t);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('moveItemUp / moveItemDown reorder siblings within bounds', () => {
|
|
145
|
-
expect(flat(moveItemDownOp(tree(BASE), 'a'))).toEqual([
|
|
146
|
-
'0:root/',
|
|
147
|
-
'1:b/',
|
|
148
|
-
'2:b1',
|
|
149
|
-
'1:a',
|
|
150
|
-
'1:c',
|
|
151
|
-
]);
|
|
152
|
-
const t = tree(BASE);
|
|
153
|
-
expect(moveItemUpOp(t, 'a')).toBe(t); // already first
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('toggleDirOp toggles the trailing slash', () => {
|
|
157
|
-
const on = toggleDirOp(tree(BASE), 'a'); // a → a/
|
|
158
|
-
expect(on.roots[0].children[0].label).toBe('a/');
|
|
159
|
-
const off = toggleDirOp(on, 'a'); // a/ → a
|
|
160
|
-
expect(off.roots[0].children.find((n) => n.label === 'a')).toBeDefined();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('every op keeps the tree renderable + byte-stable', () => {
|
|
164
|
-
for (const op of [
|
|
165
|
-
(t: Tree) => renameItemOp(t, 'a', 'alpha'),
|
|
166
|
-
(t: Tree) => addItemOp(t, 'b', 'child', 'b2'),
|
|
167
|
-
(t: Tree) => indentItemOp(t, 'c'),
|
|
168
|
-
(t: Tree) => outdentItemOp(t, 'b1'),
|
|
169
|
-
(t: Tree) => moveItemOp(t, 'c', 'a', 'child'),
|
|
170
|
-
(t: Tree) => moveItemDownOp(t, 'a'),
|
|
171
|
-
]) {
|
|
172
|
-
const next = op(tree(BASE));
|
|
173
|
-
const r1 = renderTree(next);
|
|
174
|
-
expect(renderTree(parseTree(r1))).toBe(r1);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { shouldPasteAsTreeFence } from '../treePaste';
|
|
3
|
-
|
|
4
|
-
const FILE_TREE = ['src/', '├── index.ts', '├── utils/', '│ └── math.ts', '└── config.ts'].join(
|
|
5
|
-
'\n',
|
|
6
|
-
);
|
|
7
|
-
const ASCII_TREE = ['root', '|-- a', '|-- b', '`-- c'].join('\n');
|
|
8
|
-
const BOX_DIAGRAM = [
|
|
9
|
-
'┌────────┐',
|
|
10
|
-
'│ Alpha │',
|
|
11
|
-
'└───┬────┘',
|
|
12
|
-
' ▼',
|
|
13
|
-
'┌────────┐',
|
|
14
|
-
'│ Beta │',
|
|
15
|
-
'└────────┘',
|
|
16
|
-
].join('\n');
|
|
17
|
-
|
|
18
|
-
describe('shouldPasteAsTreeFence', () => {
|
|
19
|
-
it('accepts bare Unicode file-tree art', () => {
|
|
20
|
-
expect(shouldPasteAsTreeFence(FILE_TREE)).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('accepts bare ASCII tree art', () => {
|
|
24
|
-
expect(shouldPasteAsTreeFence(ASCII_TREE)).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('rejects a box diagram (belongs to the diagram gate)', () => {
|
|
28
|
-
expect(shouldPasteAsTreeFence(BOX_DIAGRAM)).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('rejects a GFM table', () => {
|
|
32
|
-
expect(shouldPasteAsTreeFence(['| a | b |', '|---|---|', '| 1 | 2 |'].join('\n'))).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('rejects text already containing a fence, and prose', () => {
|
|
36
|
-
expect(shouldPasteAsTreeFence('```\n' + FILE_TREE + '\n```')).toBe(false);
|
|
37
|
-
expect(shouldPasteAsTreeFence('just a normal paragraph of text')).toBe(false);
|
|
38
|
-
expect(shouldPasteAsTreeFence('')).toBe(false);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Command pipeline through a REAL tiptap editor: fence text in →
|
|
3
|
-
* applyTreeCommand → fence text out, verified by re-parsing.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Editor } from '@tiptap/core';
|
|
7
|
-
import StarterKit from '@tiptap/starter-kit';
|
|
8
|
-
import { afterEach, beforeAll, describe, expect, it } from 'vitest';
|
|
9
|
-
import { parseTree } from '@bendyline/squisq/doc';
|
|
10
|
-
import { markdownToTiptap } from '../../tiptapBridge';
|
|
11
|
-
import { HeadingWithTemplate } from '../../TemplateAnnotation';
|
|
12
|
-
import { TreeViewExtension, TREEVIEW_KEY } from '../TreeViewExtension';
|
|
13
|
-
import { applyTreeCommand } from '../treeViewCommands';
|
|
14
|
-
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
if (typeof globalThis.ResizeObserver === 'undefined') {
|
|
17
|
-
class RO {
|
|
18
|
-
observe(): void {}
|
|
19
|
-
unobserve(): void {}
|
|
20
|
-
disconnect(): void {}
|
|
21
|
-
}
|
|
22
|
-
globalThis.ResizeObserver = RO as unknown as typeof ResizeObserver;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const ART = ['src/', '├── index.ts', '├── utils/', '│ └── math.ts', '└── config.ts'].join('\n');
|
|
27
|
-
|
|
28
|
-
let editors: Editor[] = [];
|
|
29
|
-
function makeEditor(md: string): Editor {
|
|
30
|
-
const editor = new Editor({
|
|
31
|
-
extensions: [
|
|
32
|
-
StarterKit.configure({
|
|
33
|
-
heading: false,
|
|
34
|
-
codeBlock: { HTMLAttributes: { class: 'squisq-code-block' } },
|
|
35
|
-
}),
|
|
36
|
-
HeadingWithTemplate.configure({ levels: [1, 2, 3, 4, 5, 6] }),
|
|
37
|
-
TreeViewExtension,
|
|
38
|
-
],
|
|
39
|
-
content: markdownToTiptap(md),
|
|
40
|
-
});
|
|
41
|
-
editors.push(editor);
|
|
42
|
-
return editor;
|
|
43
|
-
}
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
for (const e of editors) e.destroy();
|
|
46
|
-
editors = [];
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
function firstId(editor: Editor): string {
|
|
50
|
-
const s = TREEVIEW_KEY.getState(editor.state);
|
|
51
|
-
expect(s?.entries.length).toBeGreaterThan(0);
|
|
52
|
-
return s?.entries[0].id as string;
|
|
53
|
-
}
|
|
54
|
-
function fenceOf(editor: Editor): { text: string; language: string | null } {
|
|
55
|
-
let text = '';
|
|
56
|
-
let language: string | null = null;
|
|
57
|
-
editor.state.doc.descendants((node) => {
|
|
58
|
-
if (node.type.name === 'codeBlock' && text === '') {
|
|
59
|
-
text = node.textContent;
|
|
60
|
-
language = (node.attrs as { language?: string | null }).language ?? null;
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
});
|
|
65
|
-
return { text, language };
|
|
66
|
-
}
|
|
67
|
-
function labels(editor: Editor): string[] {
|
|
68
|
-
const out: string[] = [];
|
|
69
|
-
const walk = (ns: ReturnType<typeof parseTree>['roots']) =>
|
|
70
|
-
ns.forEach((n) => (out.push(n.label), walk(n.children)));
|
|
71
|
-
walk(parseTree(fenceOf(editor).text).roots);
|
|
72
|
-
return out;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
describe('applyTreeCommand', () => {
|
|
76
|
-
it('renameItem rewrites the fence', () => {
|
|
77
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
78
|
-
const id = firstId(editor);
|
|
79
|
-
expect(
|
|
80
|
-
applyTreeCommand(editor, id, { kind: 'renameItem', id: 'index-ts', label: 'main.ts' }),
|
|
81
|
-
).toBe(true);
|
|
82
|
-
expect(labels(editor)).toContain('main.ts');
|
|
83
|
-
expect(labels(editor)).not.toContain('index.ts');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('addItem (child) grows the tree', () => {
|
|
87
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
88
|
-
const id = firstId(editor);
|
|
89
|
-
expect(
|
|
90
|
-
applyTreeCommand(editor, id, {
|
|
91
|
-
kind: 'addItem',
|
|
92
|
-
targetId: 'utils',
|
|
93
|
-
position: 'child',
|
|
94
|
-
label: 'io.ts',
|
|
95
|
-
}),
|
|
96
|
-
).toBe(true);
|
|
97
|
-
const utils = parseTree(fenceOf(editor).text).roots[0].children.find(
|
|
98
|
-
(n) => n.label === 'utils/',
|
|
99
|
-
);
|
|
100
|
-
expect(utils?.children.map((c) => c.label)).toContain('io.ts');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('indentItem / outdentItem restructure', () => {
|
|
104
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
105
|
-
const id = firstId(editor);
|
|
106
|
-
// config.ts indents under utils/
|
|
107
|
-
expect(applyTreeCommand(editor, id, { kind: 'indentItem', id: 'config-ts' })).toBe(true);
|
|
108
|
-
const utils = parseTree(fenceOf(editor).text).roots[0].children.find(
|
|
109
|
-
(n) => n.label === 'utils/',
|
|
110
|
-
);
|
|
111
|
-
expect(utils?.children.map((c) => c.label)).toContain('config.ts');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('moveItem reorders and reparents through one fence rewrite', () => {
|
|
115
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
116
|
-
const id = firstId(editor);
|
|
117
|
-
expect(
|
|
118
|
-
applyTreeCommand(editor, id, {
|
|
119
|
-
kind: 'moveItem',
|
|
120
|
-
id: 'config-ts',
|
|
121
|
-
targetId: 'utils',
|
|
122
|
-
position: 'child',
|
|
123
|
-
}),
|
|
124
|
-
).toBe(true);
|
|
125
|
-
const tree = parseTree(fenceOf(editor).text);
|
|
126
|
-
const utils = tree.roots[0].children.find((n) => n.label === 'utils/');
|
|
127
|
-
expect(utils?.children.map((child) => child.label)).toEqual(['math.ts', 'config.ts']);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('removeItem drops a node', () => {
|
|
131
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
132
|
-
const id = firstId(editor);
|
|
133
|
-
expect(applyTreeCommand(editor, id, { kind: 'removeItem', id: 'config-ts' })).toBe(true);
|
|
134
|
-
expect(labels(editor)).not.toContain('config.ts');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('promotes the fence language to the explicit `tree` tag on edit', () => {
|
|
138
|
-
// A once-edited tree should carry `language: 'tree'` so its identity
|
|
139
|
-
// survives a later flatten → markdown → re-import round-trip.
|
|
140
|
-
const editor = makeEditor('```text\n' + ART + '\n```\n');
|
|
141
|
-
const id = firstId(editor);
|
|
142
|
-
expect(fenceOf(editor).language).toBe('text');
|
|
143
|
-
applyTreeCommand(editor, id, { kind: 'renameItem', id: 'index-ts', label: 'app.ts' });
|
|
144
|
-
expect(fenceOf(editor).language).toBe('tree');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('keeps the block id stable across the language-promotion rewrite', () => {
|
|
148
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
149
|
-
const id = firstId(editor);
|
|
150
|
-
applyTreeCommand(editor, id, { kind: 'renameItem', id: 'index-ts', label: 'app.ts' });
|
|
151
|
-
expect(firstId(editor)).toBe(id);
|
|
152
|
-
expect(fenceOf(editor).language).toBe('tree');
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('one undo restores the original fence bytes', () => {
|
|
156
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
157
|
-
const id = firstId(editor);
|
|
158
|
-
const before = fenceOf(editor).text;
|
|
159
|
-
applyTreeCommand(editor, id, { kind: 'renameItem', id: 'index-ts', label: 'app.ts' });
|
|
160
|
-
expect(fenceOf(editor).text).not.toBe(before);
|
|
161
|
-
editor.commands.undo();
|
|
162
|
-
expect(fenceOf(editor).text).toBe(before);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('no-op commands leave the document untouched', () => {
|
|
166
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
167
|
-
const id = firstId(editor);
|
|
168
|
-
const json = JSON.stringify(editor.state.doc.toJSON());
|
|
169
|
-
expect(applyTreeCommand(editor, id, { kind: 'indentItem', id: 'src' })).toBe(false); // root
|
|
170
|
-
expect(JSON.stringify(editor.state.doc.toJSON())).toBe(json);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('returns false for an unknown block id', () => {
|
|
174
|
-
const editor = makeEditor('```\n' + ART + '\n```\n');
|
|
175
|
-
expect(applyTreeCommand(editor, 'tree-999', { kind: 'removeItem', id: 'index-ts' })).toBe(
|
|
176
|
-
false,
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
});
|
package/src/treeview/treeOps.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure outline operations over the tree model — the write-direction half of
|
|
3
|
-
* the fence-is-source-of-truth loop:
|
|
4
|
-
*
|
|
5
|
-
* fence text → parseTree → op → renderTree → fence text
|
|
6
|
-
*
|
|
7
|
-
* Every op returns a NEW Tree (inputs untouched). These are the genuinely
|
|
8
|
-
* new operations with no diagram analog: indent / outdent (re-parent a node
|
|
9
|
-
* carrying its subtree), move-up / move-down (reorder siblings), plus
|
|
10
|
-
* add / rename / remove / toggle-directory. Connector rails re-derive in
|
|
11
|
-
* render, so ops only touch structure + labels.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import type { Tree, TreeNode } from '@bendyline/squisq/doc';
|
|
15
|
-
|
|
16
|
-
/** Make an arbitrary rename safe as a tree label: no connector glyphs / newlines. */
|
|
17
|
-
export function sanitizeTreeLabel(label: string): string {
|
|
18
|
-
return label
|
|
19
|
-
.replace(/[├└│─┃┏┓┗┛┣┫┳┻╋╰╭╮╯|`]/gu, ' ')
|
|
20
|
-
.replace(/\s+/g, ' ')
|
|
21
|
-
.trim();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function cloneNode(n: TreeNode): TreeNode {
|
|
25
|
-
return {
|
|
26
|
-
id: n.id,
|
|
27
|
-
label: n.label,
|
|
28
|
-
children: n.children.map(cloneNode),
|
|
29
|
-
...(n.isDir ? { isDir: true } : {}),
|
|
30
|
-
...(n.comment ? { comment: n.comment } : {}),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function cloneTree(t: Tree): Tree {
|
|
34
|
-
return { roots: t.roots.map(cloneNode), style: t.style, warnings: [...t.warnings] };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface Loc {
|
|
38
|
-
siblings: TreeNode[];
|
|
39
|
-
index: number;
|
|
40
|
-
node: TreeNode;
|
|
41
|
-
parent: TreeNode | null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type TreeDropPosition = 'before' | 'child' | 'after';
|
|
45
|
-
|
|
46
|
-
/** Locate a node by id in a (cloned) tree, returning its sibling array + index + parent. */
|
|
47
|
-
function locate(roots: TreeNode[], id: string, parent: TreeNode | null = null): Loc | null {
|
|
48
|
-
for (let i = 0; i < roots.length; i++) {
|
|
49
|
-
if (roots[i].id === id) return { siblings: roots, index: i, node: roots[i], parent };
|
|
50
|
-
const inner = locate(roots[i].children, id, roots[i]);
|
|
51
|
-
if (inner) return inner;
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function markDir(n: TreeNode): void {
|
|
57
|
-
n.isDir = n.label.endsWith('/') || n.children.length > 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function containsNode(node: TreeNode, id: string): boolean {
|
|
61
|
-
return node.id === id || node.children.some((child) => containsNode(child, id));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function renameItemOp(tree: Tree, id: string, label: string): Tree {
|
|
65
|
-
const clean = sanitizeTreeLabel(label);
|
|
66
|
-
const next = cloneTree(tree);
|
|
67
|
-
const loc = locate(next.roots, id);
|
|
68
|
-
if (!loc || clean.length === 0 || clean === loc.node.label) return tree;
|
|
69
|
-
loc.node.label = clean;
|
|
70
|
-
markDir(loc.node);
|
|
71
|
-
return next;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function addItemOp(
|
|
75
|
-
tree: Tree,
|
|
76
|
-
targetId: string,
|
|
77
|
-
position: 'child' | 'siblingAfter',
|
|
78
|
-
label?: string,
|
|
79
|
-
isDir?: boolean,
|
|
80
|
-
): Tree {
|
|
81
|
-
const next = cloneTree(tree);
|
|
82
|
-
const loc = locate(next.roots, targetId);
|
|
83
|
-
if (!loc) return tree;
|
|
84
|
-
let name = sanitizeTreeLabel(label ?? '') || freshLabel(next, isDir);
|
|
85
|
-
// A folder carries a trailing slash so it re-parses as a directory.
|
|
86
|
-
if (isDir && !name.endsWith('/')) name += '/';
|
|
87
|
-
const node: TreeNode = {
|
|
88
|
-
id: `__new-${name}`,
|
|
89
|
-
label: name,
|
|
90
|
-
children: [],
|
|
91
|
-
...(isDir ? { isDir: true } : {}),
|
|
92
|
-
};
|
|
93
|
-
if (position === 'child') {
|
|
94
|
-
loc.node.children.push(node);
|
|
95
|
-
markDir(loc.node);
|
|
96
|
-
} else {
|
|
97
|
-
loc.siblings.splice(loc.index + 1, 0, node);
|
|
98
|
-
}
|
|
99
|
-
return next;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function removeItemOp(tree: Tree, id: string): Tree {
|
|
103
|
-
const next = cloneTree(tree);
|
|
104
|
-
const loc = locate(next.roots, id);
|
|
105
|
-
if (!loc) return tree;
|
|
106
|
-
loc.siblings.splice(loc.index, 1);
|
|
107
|
-
if (loc.parent) markDir(loc.parent);
|
|
108
|
-
return next;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Node becomes the last child of its immediate preceding sibling. */
|
|
112
|
-
export function indentItemOp(tree: Tree, id: string): Tree {
|
|
113
|
-
const next = cloneTree(tree);
|
|
114
|
-
const loc = locate(next.roots, id);
|
|
115
|
-
if (!loc || loc.index === 0) return tree; // nothing to indent under
|
|
116
|
-
const [moved] = loc.siblings.splice(loc.index, 1);
|
|
117
|
-
const newParent = loc.siblings[loc.index - 1];
|
|
118
|
-
newParent.children.push(moved);
|
|
119
|
-
markDir(newParent);
|
|
120
|
-
return next;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Node becomes a sibling of its parent, inserted directly after it (subtree carried). */
|
|
124
|
-
export function outdentItemOp(tree: Tree, id: string): Tree {
|
|
125
|
-
const next = cloneTree(tree);
|
|
126
|
-
const loc = locate(next.roots, id);
|
|
127
|
-
if (!loc || !loc.parent) return tree; // roots can't outdent
|
|
128
|
-
const grand = locate(next.roots, loc.parent.id);
|
|
129
|
-
if (!grand) return tree;
|
|
130
|
-
const [moved] = loc.siblings.splice(loc.index, 1);
|
|
131
|
-
grand.siblings.splice(grand.index + 1, 0, moved);
|
|
132
|
-
markDir(loc.parent);
|
|
133
|
-
return next;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Move a node and its complete subtree relative to any other node. Dropping
|
|
138
|
-
* before/after adopts the target's parent; dropping as a child appends to the
|
|
139
|
-
* target. A node can never be moved into its own subtree.
|
|
140
|
-
*/
|
|
141
|
-
export function moveItemOp(
|
|
142
|
-
tree: Tree,
|
|
143
|
-
id: string,
|
|
144
|
-
targetId: string,
|
|
145
|
-
position: TreeDropPosition,
|
|
146
|
-
): Tree {
|
|
147
|
-
const currentSource = locate(tree.roots, id);
|
|
148
|
-
const currentTarget = locate(tree.roots, targetId);
|
|
149
|
-
if (
|
|
150
|
-
!currentSource ||
|
|
151
|
-
!currentTarget ||
|
|
152
|
-
id === targetId ||
|
|
153
|
-
containsNode(currentSource.node, targetId)
|
|
154
|
-
) {
|
|
155
|
-
return tree;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Avoid a fence rewrite when the drop describes the node's current slot.
|
|
159
|
-
if (currentSource.siblings === currentTarget.siblings) {
|
|
160
|
-
if (position === 'before' && currentSource.index === currentTarget.index - 1) return tree;
|
|
161
|
-
if (position === 'after' && currentSource.index === currentTarget.index + 1) return tree;
|
|
162
|
-
}
|
|
163
|
-
if (
|
|
164
|
-
position === 'child' &&
|
|
165
|
-
currentSource.parent?.id === currentTarget.node.id &&
|
|
166
|
-
currentSource.index === currentSource.siblings.length - 1
|
|
167
|
-
) {
|
|
168
|
-
return tree;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const next = cloneTree(tree);
|
|
172
|
-
const source = locate(next.roots, id);
|
|
173
|
-
if (!source) return tree;
|
|
174
|
-
const [moved] = source.siblings.splice(source.index, 1);
|
|
175
|
-
if (source.parent) markDir(source.parent);
|
|
176
|
-
|
|
177
|
-
// Locate again after removal so same-sibling indices are current.
|
|
178
|
-
const target = locate(next.roots, targetId);
|
|
179
|
-
if (!target) return tree;
|
|
180
|
-
if (position === 'child') {
|
|
181
|
-
target.node.children.push(moved);
|
|
182
|
-
markDir(target.node);
|
|
183
|
-
} else {
|
|
184
|
-
target.siblings.splice(target.index + (position === 'after' ? 1 : 0), 0, moved);
|
|
185
|
-
}
|
|
186
|
-
return next;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function moveItemUpOp(tree: Tree, id: string): Tree {
|
|
190
|
-
const next = cloneTree(tree);
|
|
191
|
-
const loc = locate(next.roots, id);
|
|
192
|
-
if (!loc || loc.index === 0) return tree;
|
|
193
|
-
[loc.siblings[loc.index - 1], loc.siblings[loc.index]] = [
|
|
194
|
-
loc.siblings[loc.index],
|
|
195
|
-
loc.siblings[loc.index - 1],
|
|
196
|
-
];
|
|
197
|
-
return next;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function moveItemDownOp(tree: Tree, id: string): Tree {
|
|
201
|
-
const next = cloneTree(tree);
|
|
202
|
-
const loc = locate(next.roots, id);
|
|
203
|
-
if (!loc || loc.index >= loc.siblings.length - 1) return tree;
|
|
204
|
-
[loc.siblings[loc.index], loc.siblings[loc.index + 1]] = [
|
|
205
|
-
loc.siblings[loc.index + 1],
|
|
206
|
-
loc.siblings[loc.index],
|
|
207
|
-
];
|
|
208
|
-
return next;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/** Toggle the trailing-slash directory marker on a node's label. */
|
|
212
|
-
export function toggleDirOp(tree: Tree, id: string): Tree {
|
|
213
|
-
const next = cloneTree(tree);
|
|
214
|
-
const loc = locate(next.roots, id);
|
|
215
|
-
if (!loc) return tree;
|
|
216
|
-
loc.node.label = loc.node.label.endsWith('/')
|
|
217
|
-
? loc.node.label.slice(0, -1)
|
|
218
|
-
: `${loc.node.label}/`;
|
|
219
|
-
markDir(loc.node);
|
|
220
|
-
return next;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function freshLabel(tree: Tree, isDir?: boolean): string {
|
|
224
|
-
const labels = new Set<string>();
|
|
225
|
-
const walk = (ns: TreeNode[]): void => ns.forEach((n) => (labels.add(n.label), walk(n.children)));
|
|
226
|
-
walk(tree.roots);
|
|
227
|
-
const base = isDir ? 'folder' : 'item';
|
|
228
|
-
let i = 1;
|
|
229
|
-
while (labels.has(`${base}${i}`) || labels.has(`${base}${i}/`)) i++;
|
|
230
|
-
return `${base}${i}`;
|
|
231
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paste gate for bare (unfenced) ASCII tree art. `├──`/`└──` file-tree lines
|
|
3
|
-
* would otherwise route through the markdown converter and mangle; when this
|
|
4
|
-
* matches, the paste handler drops the text verbatim into a fresh code block
|
|
5
|
-
* that the TreeViewExtension picks up as an interactive outline.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { detectTree } from '@bendyline/squisq/doc';
|
|
9
|
-
|
|
10
|
-
export function shouldPasteAsTreeFence(text: string): boolean {
|
|
11
|
-
if (!text || text.includes('```')) return false;
|
|
12
|
-
return detectTree(text).isTree;
|
|
13
|
-
}
|