-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(app): canvas export image content is not rendered if it's higher than viewport * fix(app): fix custom editor initial value * fix(dom-export): reduce dom-export timeout * Create early-snails-leave.md
- Loading branch information
1 parent
a8a9ee5
commit 15312cd
Showing
15 changed files
with
702 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@codeimage/app": patch | ||
"@codeimage/dom-export": patch | ||
--- | ||
|
||
fix(app): canvas export image content is not rendered if it's higher than viewport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
apps/codeimage/src/components/CustomEditor/CanvasEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import {getRootEditorStore} from '@codeimage/store/editor'; | ||
import {getActiveEditorStore} from '@codeimage/store/editor/activeEditor'; | ||
import {EditorView} from '@codemirror/view'; | ||
import { | ||
createCompartmentExtension, | ||
createEditorControlledValue, | ||
createEditorFocus, | ||
} from 'solid-codemirror'; | ||
import {Accessor, createEffect, createSignal, on} from 'solid-js'; | ||
import CustomEditor from './CustomEditor'; | ||
|
||
interface CanvasEditorProps { | ||
readOnly: boolean; | ||
} | ||
|
||
export default function CanvasEditor(props: CanvasEditorProps) { | ||
const [editorView, setEditorView] = createSignal<EditorView>(); | ||
const activeEditorStore = getActiveEditorStore(); | ||
const { | ||
state: editorState, | ||
actions: {setFocused}, | ||
} = getRootEditorStore(); | ||
|
||
const {setFocused: editorSetFocused} = createEditorFocus( | ||
editorView as Accessor<EditorView>, | ||
focusing => setFocused(focusing), | ||
); | ||
|
||
createEffect( | ||
on( | ||
editorView, | ||
view => { | ||
if (!view) return; | ||
createEffect( | ||
on( | ||
() => editorState.options.focused, | ||
isFocused => { | ||
if (view && !view.hasFocus && isFocused) { | ||
editorSetFocused(true); | ||
} | ||
}, | ||
), | ||
); | ||
}, | ||
{defer: true}, | ||
), | ||
); | ||
|
||
createCompartmentExtension( | ||
() => | ||
EditorView.domEventHandlers({ | ||
paste(event, view) { | ||
setTimeout(() => { | ||
const localValue = view.state.doc.toString(); | ||
activeEditorStore.format(localValue); | ||
}); | ||
}, | ||
}), | ||
editorView, | ||
); | ||
|
||
createEditorControlledValue( | ||
editorView as Accessor<EditorView>, | ||
() => activeEditorStore.editor()?.code ?? '', | ||
); | ||
|
||
return ( | ||
<CustomEditor | ||
onEditorViewChange={setEditorView} | ||
readOnly={props.readOnly} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/codeimage/src/components/CustomEditor/PreviewExportEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {getRootEditorStore} from '@codeimage/store/editor'; | ||
import {Annotation, Transaction} from '@codemirror/state'; | ||
import {EditorView} from '@codemirror/view'; | ||
import {createEffect, createSignal, lazy, on} from 'solid-js'; | ||
|
||
const syncAnnotation = Annotation.define<boolean>(); | ||
|
||
function syncDispatch(tr: Transaction, other: EditorView) { | ||
if (!tr.changes.empty && !tr.annotation(syncAnnotation)) { | ||
const annotations: Annotation<unknown>[] = [syncAnnotation.of(true)]; | ||
const userEvent = tr.annotation(Transaction.userEvent); | ||
if (userEvent) annotations.push(Transaction.userEvent.of(userEvent)); | ||
other.dispatch({changes: tr.changes, annotations}); | ||
} | ||
} | ||
|
||
const CustomEditor = lazy(() => import('./CustomEditor')); | ||
|
||
export default function PreviewExportEditor() { | ||
const [editorView, setEditorView] = createSignal<EditorView>(); | ||
|
||
createEffect( | ||
on(editorView, editorView => { | ||
if (!editorView) return; | ||
getRootEditorStore().canvasEditorEvents.listen(tr => { | ||
setTimeout(() => syncDispatch(tr, editorView), 250); | ||
}); | ||
}), | ||
); | ||
|
||
return <CustomEditor onEditorViewChange={setEditorView} readOnly={true} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.