-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
748 additions
and
984 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,29 @@ | ||
import { Extension } from '@codemirror/state' | ||
import { realmPlugin, system } from '../../gurx' | ||
import { coreSystem } from '../core' | ||
import { ViewMode, addEditorWrapper$, viewMode$ } from '../core' | ||
import { DiffSourceWrapper } from './DiffSourceWrapper' | ||
import { Cell } from '@mdxeditor/gurx' | ||
import { realmPlugin } from '@/RealmWithPlugins' | ||
|
||
/** @internal */ | ||
export type ViewMode = 'rich-text' | 'source' | 'diff' | ||
|
||
/** @internal */ | ||
export const diffSourceSystem = system( | ||
(r, [{ markdown, setMarkdown, markdownSignal }]) => { | ||
const diffMarkdown = r.node('') | ||
const markdownSourceEditorValue = r.node('') | ||
const cmExtensions = r.node<Extension[]>([]) | ||
|
||
r.link(markdown, markdownSourceEditorValue) | ||
r.link(markdownSourceEditorValue, markdownSignal) | ||
const viewMode = r.node<ViewMode>('rich-text') | ||
|
||
r.sub( | ||
r.pipe( | ||
viewMode, | ||
r.o.scan( | ||
(prev, next) => { | ||
return { | ||
current: prev.next, | ||
next | ||
} | ||
}, | ||
{ current: 'rich-text' as ViewMode, next: 'rich-text' as ViewMode } | ||
), | ||
r.o.withLatestFrom(markdownSourceEditorValue) | ||
), | ||
([{ current }, markdownSourceFromEditor]) => { | ||
if (current === 'source' || current === 'diff') { | ||
r.pub(setMarkdown, markdownSourceFromEditor) | ||
} | ||
} | ||
) | ||
return { viewMode, diffMarkdown, markdownSourceEditorValue, cmExtensions } | ||
}, | ||
[coreSystem] | ||
) | ||
export const diffMarkdown$ = Cell('') | ||
export const cmExtensions$ = Cell<Extension[]>([]) | ||
|
||
export interface DiffSourcePluginParams { | ||
viewMode?: ViewMode | ||
diffMarkdown?: string | ||
codeMirrorExtensions?: Extension[] | ||
} | ||
|
||
export const [ | ||
/** @internal */ | ||
diffSourcePlugin, | ||
/** @internal */ | ||
diffSourcePluginHooks | ||
] = realmPlugin({ | ||
id: 'diff-source', | ||
systemSpec: diffSourceSystem, | ||
applyParamsToSystem: (r, params?: DiffSourcePluginParams) => { | ||
r.pubKey('diffMarkdown', params?.diffMarkdown || '') | ||
export const diffSourcePlugin = realmPlugin({ | ||
update: (r, params?: DiffSourcePluginParams) => { | ||
r.pub(diffMarkdown$, params?.diffMarkdown || '') | ||
}, | ||
|
||
init(r, params?: DiffSourcePluginParams) { | ||
r.pubKey('diffMarkdown', params?.diffMarkdown || '') | ||
r.pubKey('cmExtensions', params?.codeMirrorExtensions || []) | ||
r.pubKey('addEditorWrapper', DiffSourceWrapper) | ||
r.pubKey('viewMode', params?.viewMode || 'rich-text') | ||
r.pubIn({ | ||
[diffMarkdown$]: params?.diffMarkdown || '', | ||
[cmExtensions$]: params?.codeMirrorExtensions || [], | ||
[addEditorWrapper$]: DiffSourceWrapper, | ||
[viewMode$]: params?.viewMode || 'rich-text' | ||
}) | ||
} | ||
}) |
Oops, something went wrong.