Skip to content

Commit 1cec683

Browse files
authored
Add support for Vue, React and web components (#22)
2 parents 7f38d27 + 981faa3 commit 1cec683

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4556
-251
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ package
1212
pnpm-lock.yaml
1313
package-lock.json
1414
yarn.lock
15+
16+
# Vanilla build files
17+
vanilla.js

.github/workflows/code-quality.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
- uses: actions/setup-node@v3
1111
with:
1212
node-version: 21
13+
cache: 'npm'
1314

1415
- name: Install dependendencies
1516
run: npm i

.github/workflows/deploy-demo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
- uses: actions/setup-node@v3
1414
with:
1515
node-version: 21
16+
cache: 'npm'
1617

1718
- name: Install dependendencies
1819
run: npm i

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- uses: actions/setup-node@v3
1717
with:
1818
node-version: 21
19+
cache: 'npm'
1920

2021
- name: Install dependendencies
2122
run: npm i
@@ -47,6 +48,7 @@ jobs:
4748
- uses: actions/setup-node@v3
4849
with:
4950
node-version: 21
51+
cache: 'npm'
5052

5153
- name: Install dependendencies
5254
run: npm i

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ dist
1212
pnpm-lock.yaml
1313
package-lock.json
1414
yarn.lock
15+
16+
# Vanilla build files
17+
vanilla.js

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"codicon",
44
"cyrb",
55
"devicon",
6+
"fileoverview",
67
"fontisto",
78
"heroicons",
89
"iconify",
@@ -18,5 +19,13 @@
1819
],
1920
"[svelte]": {
2021
"editor.defaultFormatter": "svelte.svelte-vscode"
22+
},
23+
"[vue]": {
24+
"editor.formatOnSave": true,
25+
"editor.defaultFormatter": "esbenp.prettier-vscode"
26+
},
27+
"[javascriptreact]": {
28+
"editor.formatOnSave": true,
29+
"editor.defaultFormatter": "esbenp.prettier-vscode"
2130
}
2231
}

README.md

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010

1111
## A web-based merge editor
1212

13-
Mismerge is a modern two-way and one-way merge editor for the web, built with Svelte. You can [visit the demo](https://beartocode.github.io/mismerge/) and start merging now, or use it as a component for your project.
13+
Mismerge is a modern two-way and one-way merge editor for the web, built with **Svelte**. You can [visit the demo](https://beartocode.github.io/mismerge/) and start merging now, or use it as a component for your project. It is also available in **React** and **Vue**.
1414

1515
## Features
1616

17-
- Two way merge editor
18-
- One way merge editor
19-
- Support lines wrapping
20-
- Support syntax highlighting
21-
- Can ignore whitespace
22-
- Can ignore case
23-
- Custom input history
24-
- Blocks, words and chars counter
25-
- Works in SvelteKit & TypeScript
17+
- ▶️ One way merge editor
18+
- 🔀 Two way merge editor
19+
- 📑 Support lines wrapping
20+
- 🌈 Support syntax highlighting
21+
- ➖ Can ignore whitespace
22+
- 📜 Custom input history
23+
- 🔠 Can ignore case
24+
- 🔢 Blocks, words and chars counter
25+
- ✅ Works in SvelteKit & TypeScript
26+
- 🌎 Available in React & Vue
2627

2728
## Installation
2829

@@ -32,6 +33,8 @@ npm i @mismerge/core
3233

3334
## Usage
3435

36+
### Svelte
37+
3538
```svelte
3639
<script>
3740
import { MisMerge3 } from '@mismerge/core';
@@ -60,6 +63,74 @@ npm i @mismerge/core
6063
</style>
6164
```
6265

66+
### React
67+
68+
Install the **additional** adapter package:
69+
70+
```
71+
npm i @mismerge/react
72+
```
73+
74+
```jsx
75+
import { DefaultDarkColors, MisMerge3 } from './lib';
76+
import { useEffect, useState } from 'react';
77+
import '@mismerge/core/styles.css';
78+
import '@mismerge/core/dark.css';
79+
80+
function App() {
81+
const [ctr, setCtr] = useState('Hello world!');
82+
83+
useEffect(() => {
84+
console.log(ctr);
85+
}, [ctr]);
86+
87+
return (
88+
<>
89+
<MisMerge3
90+
lhs="Hello world!"
91+
ctr={ctr}
92+
rhs="Hello world!"
93+
onCtrChange={setCtr}
94+
colors={DefaultDarkColors}
95+
wrapLines={true}
96+
/>
97+
</>
98+
);
99+
}
100+
```
101+
102+
### Vue
103+
104+
Install the **additional** adapter package:
105+
106+
```
107+
npm i @mismerge/vue
108+
```
109+
110+
> [!NOTE]
111+
> Due to some differences in how Vue treats boolean attributes, some default properties may not correspond to the ones described in the API section.
112+
113+
```vue
114+
<script setup lang="ts">
115+
import { MisMerge3, DefaultDarkColors } from './lib';
116+
import '@mismerge/core/styles.css';
117+
import '@mismerge/core/dark.css';
118+
</script>
119+
120+
<template>
121+
<MisMerge3
122+
lhs="Hello"
123+
ctr="World"
124+
rhs="!"
125+
ctr-editable
126+
:colors="DefaultDarkColors"
127+
:on-ctr-change="console.log"
128+
/>
129+
</template>
130+
```
131+
132+
## Customization
133+
63134
### Adding syntax highlighting
64135

65136
You need to provide your own syntax highlighter. Example and demo using [Shiki-JS](https://github.com/shikijs/shiki). The highlighter can be either sync or async.
@@ -167,7 +238,7 @@ A list of properties for `<MisMerge2>`(2), `<MisMerge3>`(3), or both.
167238
| `ignoreCase` | `boolean` | `false` | Ignore case in diff | Both |
168239
| `conflictsResolved` | `boolean` | - | Binding for when all conflicts have been resolved | 3 |
169240

170-
Events:
241+
Events (available for Svelte):
171242

172243
| Name | Description |
173244
| ------------- | ------------------------------------------------------------- |

0 commit comments

Comments
 (0)