()
| 10 | const Modified = CodeMirrorMerge.Modified; |
| 11 | |
| 12 | export const MergeExample = () => { |
| 13 | const [orientation, setOrientation] = useState<CodeMirrorMergeProps['orientation']>('a-b'); |
| 14 | const [revertControls, setRevertControls] = useState<CodeMirrorMergeProps['revertControls']>(); |
| 15 | const [highlightChanges, setHighlightChanges] = useState<CodeMirrorMergeProps['highlightChanges']>(true); |
| 16 | const [gutter, setGutter] = useState<CodeMirrorMergeProps['gutter']>(true); |
| 17 | const [collapseUnchanged, setCollapseUnchanged] = useState<CodeMirrorMergeProps['collapseUnchanged']>({}); |
| 18 | const { theme } = useTheme(); |
| 19 | const handleOrientation = (evn: React.ChangeEvent<HTMLSelectElement>) => { |
| 20 | setOrientation(evn.target.value as CodeMirrorMergeProps['orientation']); |
| 21 | }; |
| 22 | const [originalValue, setOriginalValue] = useState(originalCode); |
| 23 | const random = useRef<number>(); |
| 24 | const click = () => { |
| 25 | random.current = Math.floor(Math.random() * 101); |
| 26 | const code = '// hello world' + random.current + '\n' + originalCode; |
| 27 | setOriginalValue(code); |
| 28 | }; |
| 29 | return ( |
| 30 | <Fragment> |
| 31 | <button onClick={click}>Change Original Value {random.current}</button> |
| 32 | <CodeMirrorMerge |
| 33 | orientation={orientation} |
| 34 | revertControls={revertControls} |
| 35 | collapseUnchanged={collapseUnchanged} |
| 36 | highlightChanges={highlightChanges} |
| 37 | gutter={gutter} |
| 38 | style={{ height: 300, overflow: 'auto' }} |
| 39 | theme={theme} |
| 40 | > |
| 41 | <Original |
| 42 | value={originalValue} |
| 43 | extensions={[langs.js()]} |
| 44 | onChange={(val) => { |
| 45 | // console.log('::::::::::', val) |
| 46 | }} |
| 47 | /> |
| 48 | <Modified |
| 49 | value={modifiedCode} |
| 50 | extensions={[langs.js(), EditorView.editable.of(false), EditorState.readOnly.of(true)]} |
| 51 | /> |
| 52 | </CodeMirrorMerge> |
| 53 | <label> |
| 54 | Orientation |
| 55 | <select onChange={handleOrientation} defaultValue={orientation}> |
| 56 | <option value="">please orientation choose</option> |
| 57 | <option value="a-b">a-b</option> |
| 58 | <option value="b-a">b-a</option> |
| 59 | </select> |
| 60 | </label> |
| 61 | <br /> |
| 62 | <label> |
| 63 | Revert buttons |
| 64 | <select |
| 65 | defaultValue={revertControls} |
| 66 | onChange={(evn) => setRevertControls(evn.target.value as CodeMirrorMergeProps['revertControls'])} |
| 67 | > |
| 68 | <option value="">please revertControls choose</option> |
| 69 | <option value="a-to-b">a-to-b</option> |
nothing calls this directly
no test coverage detected
searching dependent graphs…