@bendyline/squisq-editor-react 2.0.1 → 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/README.md +10 -2
- package/dist/index.d.ts +683 -60
- package/dist/index.js +9648 -3750
- package/dist/monaco.js +0 -1
- package/dist/styles/index.css +1160 -241
- package/package.json +10 -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 -1247
- package/src/EditorShell.tsx +0 -1334
- 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 -1250
- package/src/PreviewPanel.tsx +0 -422
- package/src/RawEditor.tsx +0 -731
- package/src/RecorderEntry.tsx +0 -159
- 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 -2587
- 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 -792
- 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 -48
- 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 -485
- 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__/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__/mediaAttachmentFlow.test.ts +0 -110
- package/src/__tests__/mediaBinDrop.test.tsx +0 -90
- package/src/__tests__/mediaReferences.test.ts +0 -82
- 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 -540
- 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 -566
- 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 -164
- 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__/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 -145
- 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 -405
- 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/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 -259
- 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/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 -470
- 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/mediaDragMime.ts +0 -32
- package/src/mediaEntries.ts +0 -12
- package/src/mediaReferences.ts +0 -299
- 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 -616
- package/src/scene/SceneBlockExtension.ts +0 -205
- package/src/scene/SceneBlockToolbar.tsx +0 -201
- 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/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__/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 -103
- 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/hooks/useSceneHitTest.ts +0 -105
- package/src/scene/hooks/useScenePanZoom.ts +0 -147
- 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 -792
- 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/diagram.css +0 -183
- package/src/styles/editor.css +0 -6811
- package/src/styles/folder-view.css +0 -210
- package/src/styles/image-edit-affordance.css +0 -201
- package/src/styles/index.css +0 -18
- 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/wysiwygImageUpload.ts +0 -113
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vitest-environment jsdom
|
|
3
|
-
*
|
|
4
|
-
* High-level smoke test for the `<ImageEditor>` shell — verifies it
|
|
5
|
-
* mounts against a sidecar container, finishes its initial seed, and
|
|
6
|
-
* renders the toolbar / canvas / panels.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
9
|
-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
10
|
-
import { MemoryContentContainer, scopeContainer } from '@bendyline/squisq/storage';
|
|
11
|
-
import { writeImageEditDoc, createEmptyImageEditDoc } from '@bendyline/squisq/imageEdit';
|
|
12
|
-
import { DARK_SURFACE } from '@bendyline/squisq/schemas';
|
|
13
|
-
import { ImageEditor } from '../ImageEditor.js';
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
if (typeof URL.createObjectURL !== 'function') {
|
|
17
|
-
Object.defineProperty(URL, 'createObjectURL', {
|
|
18
|
-
configurable: true,
|
|
19
|
-
value: vi.fn(() => 'blob:stub'),
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
if (typeof URL.revokeObjectURL !== 'function') {
|
|
23
|
-
Object.defineProperty(URL, 'revokeObjectURL', {
|
|
24
|
-
configurable: true,
|
|
25
|
-
value: vi.fn(),
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('<ImageEditor>', () => {
|
|
31
|
-
it('mounts an existing state.json and shows toolbar / layers / properties', async () => {
|
|
32
|
-
const parent = new MemoryContentContainer();
|
|
33
|
-
const sidecar = scopeContainer(parent, 'pic_files');
|
|
34
|
-
await writeImageEditDoc(sidecar, createEmptyImageEditDoc(64, 48));
|
|
35
|
-
|
|
36
|
-
render(<ImageEditor filesContainer={sidecar} />);
|
|
37
|
-
|
|
38
|
-
await waitFor(() => {
|
|
39
|
-
expect(screen.getByTestId('image-editor')).toBeTruthy();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
expect(screen.getByTestId('image-editor-toolbar')).toBeTruthy();
|
|
43
|
-
expect(screen.getByTestId('image-editor-layers')).toBeTruthy();
|
|
44
|
-
expect(screen.getByTestId('image-editor-properties')).toBeTruthy();
|
|
45
|
-
|
|
46
|
-
// SVG canvas viewBox reflects the doc dimensions.
|
|
47
|
-
const svg = document.querySelector('svg.squisq-image-editor-canvas');
|
|
48
|
-
expect(svg).not.toBeNull();
|
|
49
|
-
expect(svg!.getAttribute('viewBox')).toBe('0 0 64 48');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('shows the loading state before the seed completes', () => {
|
|
53
|
-
const parent = new MemoryContentContainer();
|
|
54
|
-
const sidecar = scopeContainer(parent, 'pic_files');
|
|
55
|
-
render(<ImageEditor filesContainer={sidecar} />);
|
|
56
|
-
expect(screen.getByText(/loading image editor/i)).toBeTruthy();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('adds a centered shape layer from the Layers panel menu', async () => {
|
|
60
|
-
const parent = new MemoryContentContainer();
|
|
61
|
-
const sidecar = scopeContainer(parent, 'pic_files');
|
|
62
|
-
await writeImageEditDoc(sidecar, createEmptyImageEditDoc(640, 480));
|
|
63
|
-
|
|
64
|
-
render(<ImageEditor filesContainer={sidecar} />);
|
|
65
|
-
await waitFor(() => expect(screen.getByTestId('image-editor')).toBeTruthy());
|
|
66
|
-
|
|
67
|
-
fireEvent.click(screen.getByRole('button', { name: 'Add layer' }));
|
|
68
|
-
fireEvent.click(screen.getByRole('menuitem', { name: 'Shape layer' }));
|
|
69
|
-
|
|
70
|
-
await waitFor(() => expect(screen.getByTitle('Rectangle')).toBeTruthy());
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('applies an explicit dark surface to the editor chrome', async () => {
|
|
74
|
-
const parent = new MemoryContentContainer();
|
|
75
|
-
const sidecar = scopeContainer(parent, 'pic_files');
|
|
76
|
-
await writeImageEditDoc(sidecar, createEmptyImageEditDoc(64, 48));
|
|
77
|
-
|
|
78
|
-
render(<ImageEditor filesContainer={sidecar} surface={DARK_SURFACE} />);
|
|
79
|
-
|
|
80
|
-
await waitFor(() => {
|
|
81
|
-
expect(screen.getByTestId('image-editor')).toBeTruthy();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const editor = screen.getByTestId('image-editor');
|
|
85
|
-
expect(editor.style.getPropertyValue('--squisq-image-editor-bg')).toBe(DARK_SURFACE.background);
|
|
86
|
-
expect(editor.style.getPropertyValue('--squisq-image-editor-text')).toBe(DARK_SURFACE.text);
|
|
87
|
-
expect(editor.style.getPropertyValue('--squisq-image-editor-panel-bg')).toBe(
|
|
88
|
-
`color-mix(in srgb, ${DARK_SURFACE.background} 92%, ${DARK_SURFACE.text} 8%)`,
|
|
89
|
-
);
|
|
90
|
-
expect(editor.style.getPropertyValue('--squisq-image-editor-control-bg')).toBe(
|
|
91
|
-
`color-mix(in srgb, ${DARK_SURFACE.background} 86%, ${DARK_SURFACE.text} 14%)`,
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import type { ImageEditDoc, ImageEditLayer } from '@bendyline/squisq/schemas';
|
|
3
|
-
import { createEmptyImageEditDoc } from '@bendyline/squisq/imageEdit';
|
|
4
|
-
import {
|
|
5
|
-
imageEditorReducer,
|
|
6
|
-
initialImageEditorState,
|
|
7
|
-
type ImageEditorState,
|
|
8
|
-
type ImageEditorAction,
|
|
9
|
-
} from '../imageEditor/state.js';
|
|
10
|
-
|
|
11
|
-
function bootstrap(): ImageEditorState {
|
|
12
|
-
const doc = createEmptyImageEditDoc(400, 300);
|
|
13
|
-
// touch sets updatedAt — clear it for stable comparisons
|
|
14
|
-
return initialImageEditorState(doc);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function dispatchAll(state: ImageEditorState, actions: ImageEditorAction[]): ImageEditorState {
|
|
18
|
-
return actions.reduce((s, a) => imageEditorReducer(s, a), state);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('imageEditorReducer', () => {
|
|
22
|
-
it('initial state is clean and selects no layer', () => {
|
|
23
|
-
const s = bootstrap();
|
|
24
|
-
expect(s.dirty).toBe(false);
|
|
25
|
-
expect(s.selectedLayerId).toBe(null);
|
|
26
|
-
expect(s.tool).toBe('select');
|
|
27
|
-
expect(s.doc.canvas.width).toBe(400);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('add-layer assigns an id, marks dirty, and selects by default', () => {
|
|
31
|
-
const s0 = bootstrap();
|
|
32
|
-
const s1 = imageEditorReducer(s0, {
|
|
33
|
-
type: 'add-layer',
|
|
34
|
-
layer: {
|
|
35
|
-
type: 'shape',
|
|
36
|
-
position: { x: 0, y: 0, width: 50, height: 50 },
|
|
37
|
-
content: { shape: 'rect', fill: '#fff' },
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
expect(s1.dirty).toBe(true);
|
|
41
|
-
expect(s1.doc.layers).toHaveLength(1);
|
|
42
|
-
const added = s1.doc.layers[0]!;
|
|
43
|
-
expect(added.id).toMatch(/^layer-/);
|
|
44
|
-
expect(s1.selectedLayerId).toBe(added.id);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('add-layer with select:false leaves selection untouched', () => {
|
|
48
|
-
const s = imageEditorReducer(bootstrap(), {
|
|
49
|
-
type: 'add-layer',
|
|
50
|
-
select: false,
|
|
51
|
-
layer: {
|
|
52
|
-
type: 'shape',
|
|
53
|
-
position: { x: 0, y: 0, width: 1, height: 1 },
|
|
54
|
-
content: { shape: 'rect' },
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
expect(s.selectedLayerId).toBe(null);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('remove-layer drops the layer and clears selection if it was selected', () => {
|
|
61
|
-
const s1 = imageEditorReducer(bootstrap(), {
|
|
62
|
-
type: 'add-layer',
|
|
63
|
-
layer: {
|
|
64
|
-
type: 'shape',
|
|
65
|
-
position: { x: 0, y: 0, width: 1, height: 1 },
|
|
66
|
-
content: { shape: 'rect' },
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const id = s1.doc.layers[0]!.id;
|
|
70
|
-
const s2 = imageEditorReducer(s1, { type: 'remove-layer', layerId: id });
|
|
71
|
-
expect(s2.doc.layers).toHaveLength(0);
|
|
72
|
-
expect(s2.selectedLayerId).toBe(null);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('update-layer applies a shallow patch', () => {
|
|
76
|
-
const s1 = imageEditorReducer(bootstrap(), {
|
|
77
|
-
type: 'add-layer',
|
|
78
|
-
layer: {
|
|
79
|
-
type: 'shape',
|
|
80
|
-
position: { x: 10, y: 10, width: 20, height: 20 },
|
|
81
|
-
content: { shape: 'rect' },
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
const id = s1.doc.layers[0]!.id;
|
|
85
|
-
const s2 = imageEditorReducer(s1, {
|
|
86
|
-
type: 'update-layer',
|
|
87
|
-
layerId: id,
|
|
88
|
-
patch: { name: 'Box', opacity: 0.5 },
|
|
89
|
-
});
|
|
90
|
-
const layer = s2.doc.layers[0]!;
|
|
91
|
-
expect(layer.name).toBe('Box');
|
|
92
|
-
expect(layer.opacity).toBe(0.5);
|
|
93
|
-
// Untouched fields are preserved.
|
|
94
|
-
expect(layer.position).toEqual({ x: 10, y: 10, width: 20, height: 20 });
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('reorder-layer moves a layer to the requested index', () => {
|
|
98
|
-
let s = bootstrap();
|
|
99
|
-
s = dispatchAll(s, [
|
|
100
|
-
{ type: 'add-layer', layer: shape('a') },
|
|
101
|
-
{ type: 'add-layer', layer: shape('b') },
|
|
102
|
-
{ type: 'add-layer', layer: shape('c') },
|
|
103
|
-
]);
|
|
104
|
-
const ids = s.doc.layers.map((l) => l.id);
|
|
105
|
-
// Move the first layer to the top of the stack.
|
|
106
|
-
const s2 = imageEditorReducer(s, { type: 'reorder-layer', layerId: ids[0]!, toIndex: 2 });
|
|
107
|
-
expect(s2.doc.layers.map((l) => l.id)).toEqual([ids[1], ids[2], ids[0]]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('crop translates layer positions into the new origin and resizes the canvas', () => {
|
|
111
|
-
let s = bootstrap();
|
|
112
|
-
s = imageEditorReducer(s, {
|
|
113
|
-
type: 'add-layer',
|
|
114
|
-
layer: {
|
|
115
|
-
type: 'shape',
|
|
116
|
-
position: { x: 100, y: 80, width: 50, height: 50 },
|
|
117
|
-
content: { shape: 'rect' },
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
const s2 = imageEditorReducer(s, {
|
|
121
|
-
type: 'crop',
|
|
122
|
-
rect: { x: 50, y: 50, width: 200, height: 150 },
|
|
123
|
-
});
|
|
124
|
-
expect(s2.doc.canvas.width).toBe(200);
|
|
125
|
-
expect(s2.doc.canvas.height).toBe(150);
|
|
126
|
-
const layer = s2.doc.layers[0]!;
|
|
127
|
-
expect(layer.position.x).toBe(50);
|
|
128
|
-
expect(layer.position.y).toBe(30);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('mark-clean clears the dirty flag without touching the doc', () => {
|
|
132
|
-
let s = bootstrap();
|
|
133
|
-
s = imageEditorReducer(s, { type: 'set-canvas', canvas: { width: 1, height: 1 } });
|
|
134
|
-
expect(s.dirty).toBe(true);
|
|
135
|
-
const docRef = s.doc;
|
|
136
|
-
s = imageEditorReducer(s, { type: 'mark-clean' });
|
|
137
|
-
expect(s.dirty).toBe(false);
|
|
138
|
-
expect(s.doc).toBe(docRef);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('select / set-tool do not mark the doc dirty', () => {
|
|
142
|
-
const s0 = imageEditorReducer(bootstrap(), {
|
|
143
|
-
type: 'add-layer',
|
|
144
|
-
layer: shape('x'),
|
|
145
|
-
});
|
|
146
|
-
const s1 = imageEditorReducer(
|
|
147
|
-
{ ...s0, dirty: false },
|
|
148
|
-
{
|
|
149
|
-
type: 'select',
|
|
150
|
-
layerId: s0.doc.layers[0]!.id,
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
expect(s1.dirty).toBe(false);
|
|
154
|
-
const s2 = imageEditorReducer(s1, { type: 'set-tool', tool: 'crop' });
|
|
155
|
-
expect(s2.dirty).toBe(false);
|
|
156
|
-
expect(s2.tool).toBe('crop');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
function shape(name: string): ImageEditLayer {
|
|
161
|
-
return {
|
|
162
|
-
id: '', // assigned by reducer
|
|
163
|
-
type: 'shape',
|
|
164
|
-
name,
|
|
165
|
-
position: { x: 0, y: 0, width: 10, height: 10 },
|
|
166
|
-
content: { shape: 'rect' },
|
|
167
|
-
} as ImageEditLayer;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Make the test module type-check without unused import warnings.
|
|
171
|
-
export type _Unused = ImageEditDoc;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { EditorProvider } from '../EditorContext';
|
|
4
|
-
import { InlinePreviewGutter } from '../InlinePreviewGutter';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The gutter pulls its data from the EditorContext's parsed Doc. We mount
|
|
8
|
-
* it against a real provider seeded with markdown that contains both an
|
|
9
|
-
* annotated heading (`{[title]}`) and a plain heading. The first
|
|
10
|
-
* should produce a card; the second should be ignored.
|
|
11
|
-
*
|
|
12
|
-
* We deliberately don't snapshot the SVG — the BlockRenderer covers that
|
|
13
|
-
* elsewhere. Here we just assert (a) the gutter mounts, (b) it renders
|
|
14
|
-
* one card per annotated block, and (c) the empty state shows when there
|
|
15
|
-
* are no annotated blocks.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
function renderGutter(markdown: string) {
|
|
19
|
-
return render(
|
|
20
|
-
<EditorProvider initialMarkdown={markdown} initialView="wysiwyg" articleId="test">
|
|
21
|
-
<InlinePreviewGutter />
|
|
22
|
-
</EditorProvider>,
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('InlinePreviewGutter', () => {
|
|
27
|
-
it('renders the empty state when no blocks are template-annotated', async () => {
|
|
28
|
-
renderGutter('# Plain heading\n\nSome body text.\n');
|
|
29
|
-
expect(await screen.findByText(/tag a heading with a template/i)).toBeTruthy();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('renders one card per template-annotated block', async () => {
|
|
33
|
-
const md = [
|
|
34
|
-
'# Welcome {[title]}',
|
|
35
|
-
'',
|
|
36
|
-
'Subtitle goes here.',
|
|
37
|
-
'',
|
|
38
|
-
'## Plain heading',
|
|
39
|
-
'',
|
|
40
|
-
'No template tag — should not produce a card.',
|
|
41
|
-
'',
|
|
42
|
-
'## Big number {[statHighlight]}',
|
|
43
|
-
'',
|
|
44
|
-
'42',
|
|
45
|
-
].join('\n');
|
|
46
|
-
|
|
47
|
-
const { container } = renderGutter(md);
|
|
48
|
-
|
|
49
|
-
// Two annotated headings → two cards.
|
|
50
|
-
await screen.findByTestId('inline-preview-gutter');
|
|
51
|
-
const cards = container.querySelectorAll('.squisq-inline-preview-card');
|
|
52
|
-
expect(cards.length).toBe(2);
|
|
53
|
-
|
|
54
|
-
// Template labels are rendered alongside each card.
|
|
55
|
-
const labels = Array.from(
|
|
56
|
-
container.querySelectorAll('.squisq-inline-preview-card-template'),
|
|
57
|
-
).map((el) => el.textContent);
|
|
58
|
-
// Templates render their human-readable label (via `templateLabel`).
|
|
59
|
-
expect(labels).toContain('Title');
|
|
60
|
-
expect(labels).toContain('Stat Highlight');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeAll } from 'vitest';
|
|
2
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import { EditorProvider } from '../EditorContext';
|
|
4
|
-
import { InlinePreviewGutter } from '../InlinePreviewGutter';
|
|
5
|
-
|
|
6
|
-
// jsdom lacks ResizeObserver — the gutter's heading-layout hook wires one
|
|
7
|
-
// up to recompute on editor resizes. Stub a no-op for these tests.
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
if (typeof globalThis.ResizeObserver === 'undefined') {
|
|
10
|
-
globalThis.ResizeObserver = class {
|
|
11
|
-
observe() {}
|
|
12
|
-
unobserve() {}
|
|
13
|
-
disconnect() {}
|
|
14
|
-
} as unknown as typeof ResizeObserver;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The gutter pulls heading data from the parsed Doc (via `useHeadingLayout`)
|
|
20
|
-
* and pairs it to DOM headings inside the `.squisq-wysiwyg-container`.
|
|
21
|
-
* To exercise the all-blocks bracket logic we provide both: real markdown
|
|
22
|
-
* (so the parser populates `doc.blocks`) AND a sibling stub container with
|
|
23
|
-
* matching `<h*>` elements (so the DOM-pairing path finds something to
|
|
24
|
-
* measure).
|
|
25
|
-
*/
|
|
26
|
-
function renderWithMatchingDom(markdown: string, headingHtml: string) {
|
|
27
|
-
return render(
|
|
28
|
-
<EditorProvider initialMarkdown={markdown} initialView="wysiwyg" articleId="test">
|
|
29
|
-
<div className="squisq-editor-with-gutter" style={{ position: 'relative', height: 600 }}>
|
|
30
|
-
<div
|
|
31
|
-
className="squisq-wysiwyg-container"
|
|
32
|
-
style={{ position: 'relative', width: 800, height: 600 }}
|
|
33
|
-
>
|
|
34
|
-
<div
|
|
35
|
-
className="squisq-wysiwyg-editor"
|
|
36
|
-
dangerouslySetInnerHTML={{ __html: headingHtml }}
|
|
37
|
-
/>
|
|
38
|
-
</div>
|
|
39
|
-
<InlinePreviewGutter />
|
|
40
|
-
</div>
|
|
41
|
-
</EditorProvider>,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('InlinePreviewGutter — all-block bracket lines', () => {
|
|
46
|
-
it('renders a vertical-extent bar per heading even when none are annotated', async () => {
|
|
47
|
-
const md = '# Hello World\n\nBody\n\n## Getting Started\n\nBody\n\n## Tips\n\nBody\n';
|
|
48
|
-
const { container } = renderWithMatchingDom(
|
|
49
|
-
md,
|
|
50
|
-
'<h1>Hello World</h1>' +
|
|
51
|
-
'<p>Body</p>' +
|
|
52
|
-
'<h2>Getting Started</h2>' +
|
|
53
|
-
'<p>Body</p>' +
|
|
54
|
-
'<h2>Tips</h2>' +
|
|
55
|
-
'<p>Body</p>',
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
await waitFor(
|
|
59
|
-
() => {
|
|
60
|
-
const bars = container.querySelectorAll('.squisq-inline-preview-extent');
|
|
61
|
-
expect(bars.length).toBe(3);
|
|
62
|
-
},
|
|
63
|
-
{ timeout: 1000 },
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// All three should be the untagged variant (no `data-template` on any).
|
|
67
|
-
const bars = container.querySelectorAll('.squisq-inline-preview-extent');
|
|
68
|
-
bars.forEach((bar) =>
|
|
69
|
-
expect(bar.classList.contains('squisq-inline-preview-extent--untagged')).toBe(true),
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('renders a strong tagged bar for annotated headings + lighter bars for the rest', async () => {
|
|
74
|
-
const md = '# Welcome\n\n## Getting Started {[sectionHeader]}\n\n## Tips\n';
|
|
75
|
-
const { container } = renderWithMatchingDom(
|
|
76
|
-
md,
|
|
77
|
-
'<h1>Welcome</h1>' +
|
|
78
|
-
'<h2 data-template="sectionHeader">Getting Started</h2>' +
|
|
79
|
-
'<h2>Tips</h2>',
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
await waitFor(
|
|
83
|
-
() => {
|
|
84
|
-
const bars = container.querySelectorAll('.squisq-inline-preview-extent');
|
|
85
|
-
expect(bars.length).toBe(3);
|
|
86
|
-
},
|
|
87
|
-
{ timeout: 1000 },
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const bars = Array.from(container.querySelectorAll('.squisq-inline-preview-extent'));
|
|
91
|
-
const tagged = bars.filter(
|
|
92
|
-
(b) => !b.classList.contains('squisq-inline-preview-extent--untagged'),
|
|
93
|
-
);
|
|
94
|
-
const untagged = bars.filter((b) =>
|
|
95
|
-
b.classList.contains('squisq-inline-preview-extent--untagged'),
|
|
96
|
-
);
|
|
97
|
-
expect(tagged.length).toBe(1);
|
|
98
|
-
expect(untagged.length).toBe(2);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// `screen` import unused but kept to mirror the sibling test file's style.
|
|
103
|
-
void screen;
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
4
|
-
import type { SquisqAnnotatedSchema } from '@bendyline/squisq/jsonForm';
|
|
5
|
-
import { JsonEditor } from '../jsonEditor';
|
|
6
|
-
|
|
7
|
-
function Controlled<T>({
|
|
8
|
-
schema,
|
|
9
|
-
initial,
|
|
10
|
-
onValueChange,
|
|
11
|
-
}: {
|
|
12
|
-
schema: SquisqAnnotatedSchema;
|
|
13
|
-
initial: T;
|
|
14
|
-
onValueChange?: (next: T) => void;
|
|
15
|
-
}) {
|
|
16
|
-
const [value, setValue] = useState<T>(initial);
|
|
17
|
-
return (
|
|
18
|
-
<JsonEditor
|
|
19
|
-
schema={schema}
|
|
20
|
-
value={value}
|
|
21
|
-
onChange={(v) => {
|
|
22
|
-
setValue(v as T);
|
|
23
|
-
onValueChange?.(v as T);
|
|
24
|
-
}}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe('JsonEditor', () => {
|
|
30
|
-
it('renders text input and propagates edits through onChange', () => {
|
|
31
|
-
const schema: SquisqAnnotatedSchema = {
|
|
32
|
-
type: 'object',
|
|
33
|
-
properties: { title: { type: 'string', title: 'Title' } },
|
|
34
|
-
};
|
|
35
|
-
const onChange = vi.fn();
|
|
36
|
-
render(<Controlled schema={schema} initial={{ title: 'Hi' }} onValueChange={onChange} />);
|
|
37
|
-
const input = screen.getByDisplayValue('Hi') as HTMLInputElement;
|
|
38
|
-
fireEvent.change(input, { target: { value: 'Hello' } });
|
|
39
|
-
expect(onChange).toHaveBeenLastCalledWith({ title: 'Hello' });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('toggles a boolean via the toggle control', () => {
|
|
43
|
-
const schema: SquisqAnnotatedSchema = {
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: { active: { type: 'boolean', title: 'Active' } },
|
|
46
|
-
};
|
|
47
|
-
const onChange = vi.fn();
|
|
48
|
-
render(<Controlled schema={schema} initial={{ active: false }} onValueChange={onChange} />);
|
|
49
|
-
const button = screen.getByRole('button', { pressed: false });
|
|
50
|
-
fireEvent.click(button);
|
|
51
|
-
expect(onChange).toHaveBeenLastCalledWith({ active: true });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('hides fields whose hidden rule matches', () => {
|
|
55
|
-
const schema: SquisqAnnotatedSchema = {
|
|
56
|
-
type: 'object',
|
|
57
|
-
properties: {
|
|
58
|
-
showAuthor: { type: 'boolean', title: 'Show author' },
|
|
59
|
-
authorName: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
title: 'Author name',
|
|
62
|
-
squisq: { hidden: { field: 'showAuthor', truthy: false } },
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
const { container } = render(
|
|
67
|
-
<Controlled schema={schema} initial={{ showAuthor: false, authorName: 'Alex' }} />,
|
|
68
|
-
);
|
|
69
|
-
expect(container.textContent).not.toContain('Author name');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('selecting a different segmented option commits the new enum value', () => {
|
|
73
|
-
const schema: SquisqAnnotatedSchema = {
|
|
74
|
-
type: 'object',
|
|
75
|
-
properties: {
|
|
76
|
-
size: { type: 'string', title: 'Size', enum: ['s', 'm', 'l'] },
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
const onChange = vi.fn();
|
|
80
|
-
render(<Controlled schema={schema} initial={{ size: 's' }} onValueChange={onChange} />);
|
|
81
|
-
fireEvent.click(screen.getByRole('button', { name: 'l' }));
|
|
82
|
-
expect(onChange).toHaveBeenLastCalledWith({ size: 'l' });
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('card-stack: + Add appends, × Remove removes, ↑↓ reorder', () => {
|
|
86
|
-
const schema: SquisqAnnotatedSchema = {
|
|
87
|
-
type: 'object',
|
|
88
|
-
properties: {
|
|
89
|
-
sections: {
|
|
90
|
-
type: 'array',
|
|
91
|
-
title: 'Sections',
|
|
92
|
-
items: {
|
|
93
|
-
type: 'object',
|
|
94
|
-
properties: { heading: { type: 'string' } },
|
|
95
|
-
squisq: { itemLabel: { fromField: 'heading' } },
|
|
96
|
-
},
|
|
97
|
-
squisq: { control: 'card-stack', addLabel: '+ Add section' },
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
const onChange = vi.fn();
|
|
102
|
-
render(
|
|
103
|
-
<Controlled
|
|
104
|
-
schema={schema}
|
|
105
|
-
initial={{ sections: [{ heading: 'A' }, { heading: 'B' }] }}
|
|
106
|
-
onValueChange={onChange}
|
|
107
|
-
/>,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// + Add appends a new empty item.
|
|
111
|
-
fireEvent.click(screen.getByText('+ Add section'));
|
|
112
|
-
expect(onChange).toHaveBeenLastCalledWith({
|
|
113
|
-
sections: [{ heading: 'A' }, { heading: 'B' }, { heading: '' }],
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// × on the first card removes it.
|
|
117
|
-
const removeButtons = screen.getAllByLabelText('Remove');
|
|
118
|
-
fireEvent.click(removeButtons[0]);
|
|
119
|
-
expect(onChange).toHaveBeenLastCalledWith({
|
|
120
|
-
sections: [{ heading: 'B' }, { heading: '' }],
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// ↓ on the first card reorders.
|
|
124
|
-
const downs = screen.getAllByLabelText('Move down');
|
|
125
|
-
fireEvent.click(downs[0]);
|
|
126
|
-
expect(onChange).toHaveBeenLastCalledWith({
|
|
127
|
-
sections: [{ heading: '' }, { heading: 'B' }],
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('chip-bin: typing + Enter appends, × removes', () => {
|
|
132
|
-
const schema: SquisqAnnotatedSchema = {
|
|
133
|
-
type: 'object',
|
|
134
|
-
properties: {
|
|
135
|
-
tags: {
|
|
136
|
-
type: 'array',
|
|
137
|
-
items: { type: 'string' },
|
|
138
|
-
squisq: { control: 'chip-bin', addLabel: '+ Add tag' },
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
const onChange = vi.fn();
|
|
143
|
-
render(<Controlled schema={schema} initial={{ tags: ['one'] }} onValueChange={onChange} />);
|
|
144
|
-
|
|
145
|
-
const addInput = screen.getByPlaceholderText('+ Add tag');
|
|
146
|
-
fireEvent.change(addInput, { target: { value: 'two' } });
|
|
147
|
-
fireEvent.keyDown(addInput, { key: 'Enter' });
|
|
148
|
-
expect(onChange).toHaveBeenLastCalledWith({ tags: ['one', 'two'] });
|
|
149
|
-
|
|
150
|
-
fireEvent.click(screen.getByLabelText('Remove one'));
|
|
151
|
-
expect(onChange).toHaveBeenLastCalledWith({ tags: ['two'] });
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('omitting onChange disables every editor', () => {
|
|
155
|
-
const schema: SquisqAnnotatedSchema = {
|
|
156
|
-
type: 'object',
|
|
157
|
-
properties: { title: { type: 'string', title: 'Title' } },
|
|
158
|
-
};
|
|
159
|
-
const onChange = vi.fn();
|
|
160
|
-
// Use a sniffer onChange we can verify is never called by simulating an
|
|
161
|
-
// attempted change. We render WITHOUT passing onChange to JsonEditor.
|
|
162
|
-
render(<JsonEditor schema={schema} value={{ title: 'Hi' }} />);
|
|
163
|
-
const input = screen.getByDisplayValue('Hi') as HTMLInputElement;
|
|
164
|
-
expect(input.disabled).toBe(true);
|
|
165
|
-
fireEvent.change(input, { target: { value: 'changed' } });
|
|
166
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('escapes object property names as RFC 6901 pointer segments', () => {
|
|
170
|
-
const schema: SquisqAnnotatedSchema = {
|
|
171
|
-
type: 'object',
|
|
172
|
-
properties: { 'a/b~c': { type: 'string', title: 'Odd key' } },
|
|
173
|
-
};
|
|
174
|
-
const onChange = vi.fn();
|
|
175
|
-
render(<Controlled schema={schema} initial={{ 'a/b~c': 'before' }} onValueChange={onChange} />);
|
|
176
|
-
fireEvent.change(screen.getByLabelText('Odd key'), { target: { value: 'after' } });
|
|
177
|
-
expect(onChange).toHaveBeenLastCalledWith({ 'a/b~c': 'after' });
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('associates labels/help/errors and reports validation after render', async () => {
|
|
181
|
-
const schema: SquisqAnnotatedSchema = {
|
|
182
|
-
type: 'object',
|
|
183
|
-
properties: {
|
|
184
|
-
title: { type: 'string', title: 'Title', description: 'A useful title' },
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
const onValidate = vi.fn();
|
|
188
|
-
render(
|
|
189
|
-
<JsonEditor
|
|
190
|
-
schema={schema}
|
|
191
|
-
value={{ title: '' }}
|
|
192
|
-
onChange={() => {}}
|
|
193
|
-
validate={() => [{ path: '/title', message: 'Required' }]}
|
|
194
|
-
onValidate={onValidate}
|
|
195
|
-
/>,
|
|
196
|
-
);
|
|
197
|
-
const input = screen.getByLabelText('Title');
|
|
198
|
-
expect(input.getAttribute('aria-invalid')).toBe('true');
|
|
199
|
-
const described = input.getAttribute('aria-describedby') ?? '';
|
|
200
|
-
expect(described).toContain('-help');
|
|
201
|
-
expect(described).toContain('-error');
|
|
202
|
-
expect(screen.getByRole('alert').textContent).toBe('Required');
|
|
203
|
-
await waitFor(() =>
|
|
204
|
-
expect(onValidate).toHaveBeenCalledWith([{ path: '/title', message: 'Required' }]),
|
|
205
|
-
);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('adds ARIA state and keyboard navigation to segmented/tabs controls', () => {
|
|
209
|
-
const schema: SquisqAnnotatedSchema = {
|
|
210
|
-
oneOf: [
|
|
211
|
-
{ type: 'string', title: 'Text option' },
|
|
212
|
-
{ type: 'number', title: 'Number option' },
|
|
213
|
-
],
|
|
214
|
-
squisq: { control: 'tabs', label: 'Value type' },
|
|
215
|
-
};
|
|
216
|
-
render(<JsonEditor schema={schema} value="hello" onChange={() => {}} />);
|
|
217
|
-
const tabs = screen.getAllByRole('tab');
|
|
218
|
-
expect(tabs[0].getAttribute('aria-selected')).toBe('true');
|
|
219
|
-
fireEvent.keyDown(tabs[0], { key: 'ArrowRight' });
|
|
220
|
-
expect(tabs[1].getAttribute('aria-selected')).toBe('true');
|
|
221
|
-
expect(screen.getByRole('tabpanel')).toBeTruthy();
|
|
222
|
-
});
|
|
223
|
-
});
|