@uibit/diff-viewer 0.1.1 → 0.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/dist/frameworks/angular/index.ts +25 -25
- package/dist/frameworks/astro/index.d.ts +6 -1
- package/dist/frameworks/preact/index.d.ts +1 -0
- package/dist/frameworks/react/index.ts +72 -0
- package/dist/frameworks/stencil/index.d.ts +1 -0
- package/dist/frameworks/svelte/index.svelte +46 -17
- package/dist/frameworks/vue/index.ts +74 -20
- package/package.json +3 -3
- package/dist/frameworks/react/index.d.ts +0 -19
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { Component, ChangeDetectionStrategy, ElementRef, input, effect, booleanAttribute } from '@angular/core';
|
|
2
2
|
import '@uibit/diff-viewer';
|
|
3
3
|
import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
|
|
4
|
-
|
|
5
4
|
@Component({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
selector: 'uibit-diff-viewer',
|
|
6
|
+
template: '<ng-content></ng-content>',
|
|
7
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
8
|
+
standalone: true
|
|
10
9
|
})
|
|
11
10
|
export class NgxDiffViewer {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
constructor(private el: ElementRef<HTMLElementClass>){
|
|
12
|
+
effect(()=>{
|
|
13
|
+
if (this.el.nativeElement) {
|
|
14
|
+
this.el.nativeElement.mode = this.mode();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
effect(()=>{
|
|
18
|
+
if (this.el.nativeElement) {
|
|
19
|
+
this.el.nativeElement.showLineNumbers = this.showLineNumbers();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
effect(()=>{
|
|
23
|
+
if (this.el.nativeElement) {
|
|
24
|
+
this.el.nativeElement.locale = this.locale();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
readonly mode = input<'split' | 'inline'>('split');
|
|
29
|
+
readonly showLineNumbers = input<boolean, any>(true, {
|
|
30
|
+
transform: booleanAttribute
|
|
17
31
|
});
|
|
18
|
-
|
|
19
|
-
if (this.el.nativeElement) {
|
|
20
|
-
this.el.nativeElement.showLineNumbers = this.showLineNumbers();
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
effect(() => {
|
|
24
|
-
if (this.el.nativeElement) {
|
|
25
|
-
this.el.nativeElement.locale = this.locale();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
readonly mode = input<'split' | 'inline', any>('split');
|
|
31
|
-
readonly showLineNumbers = input<boolean, any>(true, { transform: booleanAttribute });
|
|
32
|
-
readonly locale = input<string, any>('');
|
|
32
|
+
readonly locale = input<string>('');
|
|
33
33
|
}
|
|
@@ -4,7 +4,12 @@ import '@uibit/diff-viewer';
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace astroHTML.JSX {
|
|
6
6
|
interface IntrinsicElements {
|
|
7
|
-
'uibit-diff-viewer': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes
|
|
7
|
+
'uibit-diff-viewer': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes & {
|
|
8
|
+
mode?: 'split' | 'inline';
|
|
9
|
+
showLineNumbers?: boolean;
|
|
10
|
+
locale?: string;
|
|
11
|
+
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
|
|
3
|
+
import '@uibit/diff-viewer';
|
|
4
|
+
const useTypeOfLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
5
|
+
export interface DiffViewerProps extends Omit<React.HTMLAttributes<HTMLElementClass>, 'mode' | 'showLineNumbers' | 'locale'> {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
mode?: 'split' | 'inline';
|
|
8
|
+
showLineNumbers?: boolean;
|
|
9
|
+
locale?: string;
|
|
10
|
+
}
|
|
11
|
+
export const DiffViewer = ({ ref, children, ...props }: DiffViewerProps & {
|
|
12
|
+
ref?: React.Ref<HTMLElementClass>;
|
|
13
|
+
})=>{
|
|
14
|
+
const innerRef = useRef<HTMLElementClass>(null);
|
|
15
|
+
const propsRef = useRef(props);
|
|
16
|
+
propsRef.current = props;
|
|
17
|
+
useImperativeHandle(ref, ()=>innerRef.current!);
|
|
18
|
+
useTypeOfLayoutEffect(()=>{
|
|
19
|
+
const element = innerRef.current;
|
|
20
|
+
if (element && props.mode !== undefined) {
|
|
21
|
+
(element as any).mode = props.mode;
|
|
22
|
+
}
|
|
23
|
+
}, [
|
|
24
|
+
props.mode
|
|
25
|
+
]);
|
|
26
|
+
useTypeOfLayoutEffect(()=>{
|
|
27
|
+
const element = innerRef.current;
|
|
28
|
+
if (element && props.showLineNumbers !== undefined) {
|
|
29
|
+
(element as any).showLineNumbers = props.showLineNumbers;
|
|
30
|
+
}
|
|
31
|
+
}, [
|
|
32
|
+
props.showLineNumbers
|
|
33
|
+
]);
|
|
34
|
+
useTypeOfLayoutEffect(()=>{
|
|
35
|
+
const element = innerRef.current;
|
|
36
|
+
if (element && props.locale !== undefined) {
|
|
37
|
+
(element as any).locale = props.locale;
|
|
38
|
+
}
|
|
39
|
+
}, [
|
|
40
|
+
props.locale
|
|
41
|
+
]);
|
|
42
|
+
const domProps = {
|
|
43
|
+
...props
|
|
44
|
+
};
|
|
45
|
+
const customPropNames = [
|
|
46
|
+
'mode',
|
|
47
|
+
'showLineNumbers',
|
|
48
|
+
'locale'
|
|
49
|
+
];
|
|
50
|
+
for (const key of customPropNames){
|
|
51
|
+
delete (domProps as any)[key];
|
|
52
|
+
}
|
|
53
|
+
return React.createElement('uibit-diff-viewer', {
|
|
54
|
+
ref: innerRef,
|
|
55
|
+
...domProps
|
|
56
|
+
}, children);
|
|
57
|
+
};
|
|
58
|
+
declare global {
|
|
59
|
+
namespace React {
|
|
60
|
+
namespace JSX {
|
|
61
|
+
interface IntrinsicElements {
|
|
62
|
+
'uibit-diff-viewer': React.ClassAttributes<HTMLElementClass> & React.HTMLAttributes<HTMLElementClass> & {
|
|
63
|
+
children?: React.ReactNode;
|
|
64
|
+
class?: string;
|
|
65
|
+
mode?: 'split' | 'inline';
|
|
66
|
+
showLineNumbers?: boolean;
|
|
67
|
+
locale?: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -1,37 +1,66 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import '@uibit/diff-viewer';
|
|
3
3
|
import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
mode =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
mode = $bindable(),
|
|
7
|
+
showLineNumbers = $bindable(),
|
|
8
|
+
locale = $bindable(),
|
|
9
|
+
children,
|
|
10
|
+
...restProps
|
|
10
11
|
} = $props<{
|
|
11
|
-
children?:
|
|
12
|
+
children?: import('svelte').Snippet;
|
|
12
13
|
mode?: 'split' | 'inline';
|
|
13
14
|
showLineNumbers?: boolean;
|
|
14
15
|
locale?: string;
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
[key: string]: any;
|
|
16
18
|
}>();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (elementRef && mode !== undefined) {
|
|
19
|
+
|
|
20
|
+
let elementRef: HTMLElementClass | null = $state(null);
|
|
21
|
+
|
|
22
|
+
$effect(() => {
|
|
23
|
+
if (elementRef && mode !== undefined && elementRef.mode !== mode) {
|
|
22
24
|
elementRef.mode = mode;
|
|
23
25
|
}
|
|
24
|
-
if (elementRef && showLineNumbers !== undefined) {
|
|
26
|
+
if (elementRef && showLineNumbers !== undefined && elementRef.showLineNumbers !== showLineNumbers) {
|
|
25
27
|
elementRef.showLineNumbers = showLineNumbers;
|
|
26
28
|
}
|
|
27
|
-
if (elementRef && locale !== undefined) {
|
|
29
|
+
if (elementRef && locale !== undefined && elementRef.locale !== locale) {
|
|
28
30
|
elementRef.locale = locale;
|
|
29
31
|
}
|
|
30
32
|
});
|
|
31
|
-
|
|
33
|
+
|
|
34
|
+
$effect(() => {
|
|
35
|
+
const element = elementRef;
|
|
36
|
+
if (!element) return;
|
|
37
|
+
|
|
38
|
+
const handleEvent = () => {
|
|
39
|
+
if (mode !== element.mode) {
|
|
40
|
+
mode = element.mode as any;
|
|
41
|
+
}
|
|
42
|
+
if (showLineNumbers !== element.showLineNumbers) {
|
|
43
|
+
showLineNumbers = element.showLineNumbers as any;
|
|
44
|
+
}
|
|
45
|
+
if (locale !== element.locale) {
|
|
46
|
+
locale = element.locale as any;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const events = ['change', 'input'];
|
|
51
|
+
for (const event of events) {
|
|
52
|
+
element.addEventListener(event, handleEvent);
|
|
53
|
+
}
|
|
54
|
+
return () => {
|
|
55
|
+
for (const event of events) {
|
|
56
|
+
element.removeEventListener(event, handleEvent);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
32
61
|
</script>
|
|
33
62
|
|
|
34
|
-
<uibit-diff-viewer bind:this={elementRef} {
|
|
63
|
+
<uibit-diff-viewer bind:this={elementRef} {...restProps}>
|
|
35
64
|
|
|
36
65
|
{#if children}
|
|
37
66
|
{@render children()}
|
|
@@ -1,24 +1,78 @@
|
|
|
1
|
-
import { defineComponent, h } from 'vue';
|
|
1
|
+
import { defineComponent, h, ref, watch } from 'vue';
|
|
2
2
|
import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
|
|
3
3
|
import '@uibit/diff-viewer';
|
|
4
|
-
|
|
5
4
|
export const DiffViewer = defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
name: 'DiffViewer',
|
|
6
|
+
props: {
|
|
7
|
+
mode: {
|
|
8
|
+
type: [
|
|
9
|
+
String,
|
|
10
|
+
Number,
|
|
11
|
+
Boolean,
|
|
12
|
+
Array,
|
|
13
|
+
Object
|
|
14
|
+
] as any
|
|
15
|
+
},
|
|
16
|
+
showLineNumbers: {
|
|
17
|
+
type: [
|
|
18
|
+
String,
|
|
19
|
+
Number,
|
|
20
|
+
Boolean,
|
|
21
|
+
Array,
|
|
22
|
+
Object
|
|
23
|
+
] as any
|
|
24
|
+
},
|
|
25
|
+
locale: {
|
|
26
|
+
type: [
|
|
27
|
+
String,
|
|
28
|
+
Number,
|
|
29
|
+
Boolean,
|
|
30
|
+
Array,
|
|
31
|
+
Object
|
|
32
|
+
] as any
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
emits: [],
|
|
36
|
+
setup (props, { slots, emit }) {
|
|
37
|
+
const elementRef = ref<HTMLElementClass | null>(null);
|
|
38
|
+
if (false) {
|
|
39
|
+
watch(()=>props.modelValue, (newVal)=>{
|
|
40
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
41
|
+
elementRef.value.value = newVal;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
watch(()=>props.value, (newVal)=>{
|
|
45
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
46
|
+
elementRef.value.value = newVal;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
watch(()=>props.mode, (newVal)=>{
|
|
51
|
+
if (elementRef.value && newVal !== undefined) {
|
|
52
|
+
(elementRef.value as any).mode = newVal;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
watch(()=>props.showLineNumbers, (newVal)=>{
|
|
56
|
+
if (elementRef.value && newVal !== undefined) {
|
|
57
|
+
(elementRef.value as any).showLineNumbers = newVal;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
watch(()=>props.locale, (newVal)=>{
|
|
61
|
+
if (elementRef.value && newVal !== undefined) {
|
|
62
|
+
(elementRef.value as any).locale = newVal;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return ()=>{
|
|
66
|
+
const eventListeners: Record<string, any> = {};
|
|
67
|
+
const mergedProps = {
|
|
68
|
+
...props,
|
|
69
|
+
...eventListeners,
|
|
70
|
+
ref: elementRef
|
|
71
|
+
};
|
|
72
|
+
if (false && props.modelValue !== undefined) {
|
|
73
|
+
(mergedProps as any).value = props.modelValue;
|
|
74
|
+
}
|
|
75
|
+
return h('uibit-diff-viewer', mergedProps, slots.default?.());
|
|
76
|
+
};
|
|
77
|
+
}
|
|
24
78
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uibit/diff-viewer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Encapsulated side-by-side or inline comparison block for two text or code snippets. Computes a line-level diff internally using LCS and renders color-coded deleted/inserted/unchanged lines with optional line numbers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./custom-elements.json": "./custom-elements.json",
|
|
14
|
-
"./react": "./dist/frameworks/react/index.
|
|
14
|
+
"./react": "./dist/frameworks/react/index.ts",
|
|
15
15
|
"./vue": "./dist/frameworks/vue/index.ts",
|
|
16
16
|
"./svelte": "./dist/frameworks/svelte/index.svelte",
|
|
17
17
|
"./angular": "./dist/frameworks/angular/index.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@types/node": "^20.19.43",
|
|
50
50
|
"lit": "^3.3.3",
|
|
51
51
|
"typescript": "7.0.2",
|
|
52
|
-
"@uibit/codegen": "0.
|
|
52
|
+
"@uibit/codegen": "0.2.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"lit": "^3.0.0",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { HTMLAttributes, ClassAttributes } from 'react';
|
|
2
|
-
import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
|
|
3
|
-
import '@uibit/diff-viewer';
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
namespace React {
|
|
7
|
-
namespace JSX {
|
|
8
|
-
interface IntrinsicElements {
|
|
9
|
-
'uibit-diff-viewer': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
|
|
10
|
-
children?: React.ReactNode;
|
|
11
|
-
class?: string;
|
|
12
|
-
mode?: 'split' | 'inline';
|
|
13
|
-
showLineNumbers?: boolean;
|
|
14
|
-
locale?: string;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|