v-code-diff 0.3.11 → 0.3.12
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/README.md +36 -22
- package/dist/v-code-diff/util.d.ts +1 -4
- package/dist/v-code-diff/v-code-diff.d.ts +55 -19
- package/dist/v-code-diff.cjs.js +1 -1
- package/dist/v-code-diff.esm.js +1 -1
- package/dist/v-code-diff.umd.js +1 -1
- package/package.json +7 -7
- package/src/lib/index.ts +1 -6
- package/src/lib/v-code-diff/util.ts +12 -30
- package/src/lib/v-code-diff/v-code-diff.ts +8 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# VCodeDiff
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/v-code-diff)
|
|
3
|
+
[](https://www.npmjs.com/package/v-code-diff)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://www.npmjs.com/package/v-code-diff)
|
|
6
6
|
|
|
@@ -117,29 +117,31 @@ export default {
|
|
|
117
117
|
|
|
118
118
|
# Events
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
|
123
|
-
|
|
|
120
|
+
|
|
121
|
+
| Event Name | Description | Callback Params |
|
|
122
|
+
| ------------- | --------------------- | --------------- |
|
|
123
|
+
| before-render | hook before rendering | - |
|
|
124
|
+
| after-render | hook after rendering | - |
|
|
124
125
|
|
|
125
126
|
# Props
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
135
|
-
|
|
|
136
|
-
|
|
|
137
|
-
|
|
|
138
|
-
|
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
|
|
|
142
|
-
|
|
|
128
|
+
|
|
129
|
+
| Prop | Description | Type | Optional | Default |
|
|
130
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------------------------- | ------------ |
|
|
131
|
+
| highlight | control whether to highlight the code | boolean | - | true |
|
|
132
|
+
| language | code language,such as`typescript`. If you don't input, it will be judged automatically. [view all supported languages](https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md) | string | - | - |
|
|
133
|
+
| old-string | old string | string | - | - |
|
|
134
|
+
| new-string | new string | string | - | - |
|
|
135
|
+
| context | number of show context lines | number | - | - |
|
|
136
|
+
| outputFormat | show method | string | line-by-line,side-by-side | line-by-line |
|
|
137
|
+
| drawFileList | show files list | boolean | - | false |
|
|
138
|
+
| renderNothingWhenEmpty | render nothing when empty | boolean | - | false |
|
|
139
|
+
| diffStyle | difference style | string | word, char | word |
|
|
140
|
+
| fileName | file name | string | - | |
|
|
141
|
+
| isShowNoChange | show raw when no change | boolean | - | false |
|
|
142
|
+
| trim | Remove blank characters before and after the string | boolean | - | false |
|
|
143
|
+
| language | code language | boolean | - | false |
|
|
144
|
+
| noDiffLineFeed | Do not diff windows line feed (CRLF) and linux line feed (LF) | boolean | - | false |
|
|
143
145
|
|
|
144
146
|
# Difference from [vue-code-diff](https://github.com/ddchef/vue-code-diff)
|
|
145
147
|
|
|
@@ -149,6 +151,18 @@ export default {
|
|
|
149
151
|
|
|
150
152
|
# ChangeLog
|
|
151
153
|
|
|
154
|
+
### 0.3.12
|
|
155
|
+
|
|
156
|
+
1. Remove prop `syncScroll` due to bug. Synchronized scrolling is now enabled by default
|
|
157
|
+
|
|
158
|
+
### 0.3.11
|
|
159
|
+
|
|
160
|
+
1. Add prop `syncScroll` to control whether the horizontal scroll bar needs to be scrolled synchronously
|
|
161
|
+
|
|
162
|
+
### 0.3.10
|
|
163
|
+
|
|
164
|
+
1. Fixed type error when exporting
|
|
165
|
+
|
|
152
166
|
### 0.3.9
|
|
153
167
|
|
|
154
168
|
1. Make the imported highlight.js style take effect only in `.d2h-wrapper` div
|
|
@@ -161,7 +175,7 @@ export default {
|
|
|
161
175
|
### 0.3.7
|
|
162
176
|
|
|
163
177
|
1. Fix the problem of displaying "File Without Change..." when isShowNoChange is true and the old and new codes are different,
|
|
164
|
-
then show all the source code
|
|
178
|
+
then show all the source code
|
|
165
179
|
|
|
166
180
|
### 0.3.6
|
|
167
181
|
|
|
@@ -17,8 +17,5 @@ declare type Props = Readonly<{
|
|
|
17
17
|
export declare function useDebounceFn(fn: any, delay: any): () => void;
|
|
18
18
|
export declare const createHtml: (props: Props) => string;
|
|
19
19
|
export declare function highlightElements(element: Element, props: any, ctx: SetupContext<any>): Promise<void>;
|
|
20
|
-
export declare function
|
|
21
|
-
addSyncScroll: () => void;
|
|
22
|
-
removeSyncScroll: () => void;
|
|
23
|
-
};
|
|
20
|
+
export declare function syncScroll(selector: any): void;
|
|
24
21
|
export {};
|
|
@@ -53,28 +53,66 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
53
53
|
type: BooleanConstructor;
|
|
54
54
|
default: boolean;
|
|
55
55
|
};
|
|
56
|
-
|
|
56
|
+
}, {
|
|
57
|
+
html: import("vue-demi").Ref<string>;
|
|
58
|
+
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, ("before-render" | "after-render")[], "before-render" | "after-render", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
59
|
+
highlight: {
|
|
57
60
|
type: BooleanConstructor;
|
|
58
61
|
default: boolean;
|
|
59
62
|
};
|
|
63
|
+
oldString: {
|
|
64
|
+
type: StringConstructor;
|
|
65
|
+
default: string;
|
|
66
|
+
};
|
|
67
|
+
newString: {
|
|
68
|
+
type: StringConstructor;
|
|
69
|
+
default: string;
|
|
70
|
+
};
|
|
71
|
+
context: {
|
|
72
|
+
type: NumberConstructor;
|
|
73
|
+
default: number;
|
|
74
|
+
};
|
|
75
|
+
outputFormat: {
|
|
76
|
+
type: PropType<"line-by-line" | "side-by-side">;
|
|
77
|
+
default: string;
|
|
78
|
+
};
|
|
79
|
+
drawFileList: {
|
|
80
|
+
type: BooleanConstructor;
|
|
81
|
+
default: boolean;
|
|
82
|
+
};
|
|
83
|
+
renderNothingWhenEmpty: {
|
|
84
|
+
type: BooleanConstructor;
|
|
85
|
+
default: boolean;
|
|
86
|
+
};
|
|
87
|
+
diffStyle: {
|
|
88
|
+
type: PropType<"word" | "char">;
|
|
89
|
+
default: string;
|
|
90
|
+
};
|
|
91
|
+
fileName: {
|
|
92
|
+
type: StringConstructor;
|
|
93
|
+
default: string;
|
|
94
|
+
};
|
|
95
|
+
isShowNoChange: {
|
|
96
|
+
type: BooleanConstructor;
|
|
97
|
+
default: boolean;
|
|
98
|
+
};
|
|
99
|
+
trim: {
|
|
100
|
+
type: BooleanConstructor;
|
|
101
|
+
default: boolean;
|
|
102
|
+
};
|
|
103
|
+
language: {
|
|
104
|
+
type: StringConstructor;
|
|
105
|
+
default: string;
|
|
106
|
+
};
|
|
107
|
+
noDiffLineFeed: {
|
|
108
|
+
type: BooleanConstructor;
|
|
109
|
+
default: boolean;
|
|
110
|
+
};
|
|
111
|
+
}>> & {
|
|
112
|
+
"onBefore-render"?: ((...args: any[]) => any) | undefined;
|
|
113
|
+
"onAfter-render"?: ((...args: any[]) => any) | undefined;
|
|
60
114
|
}, {
|
|
61
|
-
html: import("vue-demi").Ref<string>;
|
|
62
|
-
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, ("before-render" | "after-render")[], "before-render" | "after-render", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<{
|
|
63
|
-
highlight: boolean;
|
|
64
|
-
oldString: string;
|
|
65
|
-
newString: string;
|
|
66
|
-
context: number;
|
|
67
|
-
outputFormat: "line-by-line" | "side-by-side";
|
|
68
|
-
drawFileList: boolean;
|
|
69
|
-
renderNothingWhenEmpty: boolean;
|
|
70
|
-
diffStyle: "word" | "char";
|
|
71
|
-
fileName: string;
|
|
72
|
-
isShowNoChange: boolean;
|
|
73
115
|
trim: boolean;
|
|
74
|
-
language: string;
|
|
75
|
-
noDiffLineFeed: boolean;
|
|
76
|
-
syncScroll: boolean;
|
|
77
|
-
} & {}>, {
|
|
78
116
|
highlight: boolean;
|
|
79
117
|
oldString: string;
|
|
80
118
|
newString: string;
|
|
@@ -85,9 +123,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
85
123
|
diffStyle: "word" | "char";
|
|
86
124
|
fileName: string;
|
|
87
125
|
isShowNoChange: boolean;
|
|
88
|
-
trim: boolean;
|
|
89
126
|
language: string;
|
|
90
127
|
noDiffLineFeed: boolean;
|
|
91
|
-
syncScroll: boolean;
|
|
92
128
|
}>;
|
|
93
129
|
export default _default;
|
package/dist/v-code-diff.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue-demi"),n=require("diff"),t=require("diff2html"),r=require("highlight.js");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue-demi"),n=require("diff"),t=require("diff2html"),r=require("highlight.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}require("diff2html/bundles/css/diff2html.min.css");var a=l(t),d=i(r);const o=e=>{let t=e.trim?e.oldString.trim():e.oldString,r=e.trim?e.newString.trim():e.newString;t=e.noDiffLineFeed?t.replace(/(\r\n)/g,"\n"):t,r=e.noDiffLineFeed?r.replace(/(\r\n)/g,"\n"):r;let i=e.context;e.isShowNoChange&&t===r&&(t="File Without Change\tOldString: ======================== \n"+t,r="File Without Change\tNewString: ======================== \n"+r,i=99999);const l=n.createPatch(e.fileName,t,r,"","",{context:i});return a.html(l,{outputFormat:e.outputFormat,drawFileList:e.drawFileList,matching:"lines",diffStyle:e.diffStyle,renderNothingWhenEmpty:e.renderNothingWhenEmpty})};async function p(e,n,t){t.emit("before-render");const r=await async function(e){return new Promise((n=>{setTimeout((()=>{const t=e.querySelectorAll(".d2h-wrapper .d2h-code-line-ctn");n(Array.from(t))}),0)}))}(e),i=Array.from(r).map((e=>async function(e,n){return new Promise((t=>{setTimeout((()=>{if(n){const t=e.innerText;e.innerHTML=d.default.highlight(t,{language:n}).value}else d.default.highlightElement(e);t(!0)}),0)}))}(e,n.language)));await Promise.all(i),t.emit("after-render")}function h(e){let n=document.createElement("div");document.querySelectorAll(e).forEach((function(t){t.addEventListener("mouseenter",(function(e){n=e.target})),t.addEventListener("scroll",(function(t){t.target===n&&document.querySelectorAll(e).forEach((function(e){n!==e&&(e.scrollTop=n.scrollTop,e.scrollLeft=n.scrollLeft)}))}))}))}var s=[],u=[];function c(e,n){if(e&&"undefined"!=typeof document){var t,r=!0===n.prepend?"prepend":"append",i=!0===n.singleTag,l="string"==typeof n.container?document.querySelector(n.container):document.getElementsByTagName("head")[0];if(i){var a=s.indexOf(l);-1===a&&(a=s.push(l)-1,u[a]={}),t=u[a]&&u[a][r]?u[a][r]:u[a][r]=d()}else t=d();65279===e.charCodeAt(0)&&(e=e.substring(1)),t.styleSheet?t.styleSheet.cssText+=e:t.appendChild(document.createTextNode(e))}function d(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),n.attributes)for(var t=Object.keys(n.attributes),i=0;i<t.length;i++)e.setAttribute(t[i],n.attributes[t[i]]);var a="prepend"===r?"afterbegin":"beforeend";return l.insertAdjacentElement(a,e),e}}c(".d2h-wrapper .hljs {\n display: inline-block;\n padding: 0;\n background: transparent;\n vertical-align: middle;\n}\n.d2h-wrapper .hljs-comment,\n.d2h-wrapper .hljs-quote {\n color: #800;\n}\n.d2h-wrapper .hljs-keyword,\n.d2h-wrapper .hljs-selector-tag,\n.d2h-wrapper .hljs-section,\n.d2h-wrapper .hljs-title,\n.d2h-wrapper .hljs-name {\n color: #008;\n}\n.d2h-wrapper .hljs-variable,\n.d2h-wrapper .hljs-template-variable {\n color: #660;\n}\n.d2h-wrapper .hljs-string,\n.d2h-wrapper .hljs-selector-attr,\n.d2h-wrapper .hljs-selector-pseudo,\n.d2h-wrapper .hljs-regexp {\n color: #080;\n}\n.d2h-wrapper .hljs-literal,\n.d2h-wrapper .hljs-symbol,\n.d2h-wrapper .hljs-bullet,\n.d2h-wrapper .hljs-meta,\n.d2h-wrapper .hljs-number,\n.d2h-wrapper .hljs-link {\n color: #066;\n}\n.d2h-wrapper .hljs-title,\n.d2h-wrapper .hljs-doctag,\n.d2h-wrapper .hljs-type,\n.d2h-wrapper .hljs-attr,\n.d2h-wrapper .hljs-built_in,\n.d2h-wrapper .hljs-builtin-name,\n.d2h-wrapper .hljs-params {\n color: #606;\n}\n.d2h-wrapper .hljs-attribute,\n.d2h-wrapper .hljs-subst {\n color: #000;\n}\n.d2h-wrapper .hljs-formula {\n background-color: #eee;\n font-style: italic;\n}\n.d2h-wrapper .hljs-selector-id,\n.d2h-wrapper .hljs-selector-class {\n color: #9B703F;\n}\n.d2h-wrapper .hljs-addition {\n background-color: #baeeba;\n}\n.d2h-wrapper .hljs-deletion {\n background-color: #ffc8bd;\n}\n.d2h-wrapper .hljs-doctag,\n.d2h-wrapper .hljs-strong {\n font-weight: bold;\n}\n.d2h-wrapper .hljs-emphasis {\n font-style: italic;\n}",{});c(".d2h-wrapper {\n position: relative;\n line-height: normal;\n}\n.d2h-wrapper .d2h-file-header {\n display: none;\n}\n.d2h-wrapper .d2h-files-diff {\n display: flex;\n}\n.d2h-wrapper .d2h-file-side-diff {\n margin-bottom: -5px;\n}\n.d2h-wrapper .d2h-code-side-emptyplaceholder {\n max-height: 19px;\n}\n.d2h-wrapper .d2h-code-side-line,\n.d2h-wrapper .d2h-code-line {\n width: auto;\n}\n.d2h-wrapper .d2h-code-side-line .d2h-info {\n height: 18px;\n}\n.d2h-wrapper .d2h-cntx,\n.d2h-wrapper .d2h-del,\n.d2h-wrapper .d2h-ins {\n height: 18px;\n}\n.d2h-wrapper .d2h-code-linenumber,\n.d2h-wrapper .d2h-code-side-linenumber {\n line-height: 20px;\n height: 20px;\n}\n.d2h-wrapper tr {\n height: 20px;\n}",{});var f=e.defineComponent({name:"CodeDiff",props:{highlight:{type:Boolean,default:!0},oldString:{type:String,default:""},newString:{type:String,default:""},context:{type:Number,default:10},outputFormat:{type:String,default:"line-by-line"},drawFileList:{type:Boolean,default:!1},renderNothingWhenEmpty:{type:Boolean,default:!1},diffStyle:{type:String,default:"word"},fileName:{type:String,default:""},isShowNoChange:{type:Boolean,default:!1},trim:{type:Boolean,default:!1},language:{type:String,default:""},noDiffLineFeed:{type:Boolean,default:!1}},emits:["before-render","after-render"],setup(n,t){const r=e.ref(o(n)),i=function(e,n){let t;return function(){const r=this,i=arguments;clearTimeout(t),t=setTimeout((function(){e.apply(r,i)}),n)}}((async()=>{if(r.value=o(n),n.highlight){const e=document.createElement("div");e.innerHTML=r.value,await p(e,n,t),r.value=e.innerHTML}}),200);return e.watch(n,i,{deep:!0,immediate:!0}),e.onMounted((()=>{"side-by-side"===n.outputFormat&&h(".d2h-file-side-diff")})),e.onUpdated((()=>{"side-by-side"===n.outputFormat&&h(".d2h-file-side-diff")})),{html:r}},render(){return e.isVue3?e.h("div",{innerHTML:this.html}):e.h("div",{domProps:{innerHTML:this.html}})}});const m=e=>{e.component(f.name,f)};var g={install:m};exports.CodeDiff=f,exports.default=g,exports.install=m;
|
package/dist/v-code-diff.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as e,ref as n,watch as
|
|
1
|
+
import{defineComponent as e,ref as n,watch as t,onMounted as r,onUpdated as i,isVue3 as l,h as a}from"vue-demi";import{createPatch as d}from"diff";import*as o from"diff2html";import p from"highlight.js";import"diff2html/bundles/css/diff2html.min.css";const h=e=>{let n=e.trim?e.oldString.trim():e.oldString,t=e.trim?e.newString.trim():e.newString;n=e.noDiffLineFeed?n.replace(/(\r\n)/g,"\n"):n,t=e.noDiffLineFeed?t.replace(/(\r\n)/g,"\n"):t;let r=e.context;e.isShowNoChange&&n===t&&(n="File Without Change\tOldString: ======================== \n"+n,t="File Without Change\tNewString: ======================== \n"+t,r=99999);const i=d(e.fileName,n,t,"","",{context:r});return o.html(i,{outputFormat:e.outputFormat,drawFileList:e.drawFileList,matching:"lines",diffStyle:e.diffStyle,renderNothingWhenEmpty:e.renderNothingWhenEmpty})};async function s(e,n,t){t.emit("before-render");const r=await async function(e){return new Promise((n=>{setTimeout((()=>{const t=e.querySelectorAll(".d2h-wrapper .d2h-code-line-ctn");n(Array.from(t))}),0)}))}(e),i=Array.from(r).map((e=>async function(e,n){return new Promise((t=>{setTimeout((()=>{if(n){const t=e.innerText;e.innerHTML=p.highlight(t,{language:n}).value}else p.highlightElement(e);t(!0)}),0)}))}(e,n.language)));await Promise.all(i),t.emit("after-render")}function c(e){let n=document.createElement("div");document.querySelectorAll(e).forEach((function(t){t.addEventListener("mouseenter",(function(e){n=e.target})),t.addEventListener("scroll",(function(t){t.target===n&&document.querySelectorAll(e).forEach((function(e){n!==e&&(e.scrollTop=n.scrollTop,e.scrollLeft=n.scrollLeft)}))}))}))}var u=[],f=[];function m(e,n){if(e&&"undefined"!=typeof document){var t,r=!0===n.prepend?"prepend":"append",i=!0===n.singleTag,l="string"==typeof n.container?document.querySelector(n.container):document.getElementsByTagName("head")[0];if(i){var a=u.indexOf(l);-1===a&&(a=u.push(l)-1,f[a]={}),t=f[a]&&f[a][r]?f[a][r]:f[a][r]=d()}else t=d();65279===e.charCodeAt(0)&&(e=e.substring(1)),t.styleSheet?t.styleSheet.cssText+=e:t.appendChild(document.createTextNode(e))}function d(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),n.attributes)for(var t=Object.keys(n.attributes),i=0;i<t.length;i++)e.setAttribute(t[i],n.attributes[t[i]]);var a="prepend"===r?"afterbegin":"beforeend";return l.insertAdjacentElement(a,e),e}}m(".d2h-wrapper .hljs {\n display: inline-block;\n padding: 0;\n background: transparent;\n vertical-align: middle;\n}\n.d2h-wrapper .hljs-comment,\n.d2h-wrapper .hljs-quote {\n color: #800;\n}\n.d2h-wrapper .hljs-keyword,\n.d2h-wrapper .hljs-selector-tag,\n.d2h-wrapper .hljs-section,\n.d2h-wrapper .hljs-title,\n.d2h-wrapper .hljs-name {\n color: #008;\n}\n.d2h-wrapper .hljs-variable,\n.d2h-wrapper .hljs-template-variable {\n color: #660;\n}\n.d2h-wrapper .hljs-string,\n.d2h-wrapper .hljs-selector-attr,\n.d2h-wrapper .hljs-selector-pseudo,\n.d2h-wrapper .hljs-regexp {\n color: #080;\n}\n.d2h-wrapper .hljs-literal,\n.d2h-wrapper .hljs-symbol,\n.d2h-wrapper .hljs-bullet,\n.d2h-wrapper .hljs-meta,\n.d2h-wrapper .hljs-number,\n.d2h-wrapper .hljs-link {\n color: #066;\n}\n.d2h-wrapper .hljs-title,\n.d2h-wrapper .hljs-doctag,\n.d2h-wrapper .hljs-type,\n.d2h-wrapper .hljs-attr,\n.d2h-wrapper .hljs-built_in,\n.d2h-wrapper .hljs-builtin-name,\n.d2h-wrapper .hljs-params {\n color: #606;\n}\n.d2h-wrapper .hljs-attribute,\n.d2h-wrapper .hljs-subst {\n color: #000;\n}\n.d2h-wrapper .hljs-formula {\n background-color: #eee;\n font-style: italic;\n}\n.d2h-wrapper .hljs-selector-id,\n.d2h-wrapper .hljs-selector-class {\n color: #9B703F;\n}\n.d2h-wrapper .hljs-addition {\n background-color: #baeeba;\n}\n.d2h-wrapper .hljs-deletion {\n background-color: #ffc8bd;\n}\n.d2h-wrapper .hljs-doctag,\n.d2h-wrapper .hljs-strong {\n font-weight: bold;\n}\n.d2h-wrapper .hljs-emphasis {\n font-style: italic;\n}",{});m(".d2h-wrapper {\n position: relative;\n line-height: normal;\n}\n.d2h-wrapper .d2h-file-header {\n display: none;\n}\n.d2h-wrapper .d2h-files-diff {\n display: flex;\n}\n.d2h-wrapper .d2h-file-side-diff {\n margin-bottom: -5px;\n}\n.d2h-wrapper .d2h-code-side-emptyplaceholder {\n max-height: 19px;\n}\n.d2h-wrapper .d2h-code-side-line,\n.d2h-wrapper .d2h-code-line {\n width: auto;\n}\n.d2h-wrapper .d2h-code-side-line .d2h-info {\n height: 18px;\n}\n.d2h-wrapper .d2h-cntx,\n.d2h-wrapper .d2h-del,\n.d2h-wrapper .d2h-ins {\n height: 18px;\n}\n.d2h-wrapper .d2h-code-linenumber,\n.d2h-wrapper .d2h-code-side-linenumber {\n line-height: 20px;\n height: 20px;\n}\n.d2h-wrapper tr {\n height: 20px;\n}",{});var g=e({name:"CodeDiff",props:{highlight:{type:Boolean,default:!0},oldString:{type:String,default:""},newString:{type:String,default:""},context:{type:Number,default:10},outputFormat:{type:String,default:"line-by-line"},drawFileList:{type:Boolean,default:!1},renderNothingWhenEmpty:{type:Boolean,default:!1},diffStyle:{type:String,default:"word"},fileName:{type:String,default:""},isShowNoChange:{type:Boolean,default:!1},trim:{type:Boolean,default:!1},language:{type:String,default:""},noDiffLineFeed:{type:Boolean,default:!1}},emits:["before-render","after-render"],setup(e,l){const a=n(h(e)),d=function(e,n){let t;return function(){const r=this,i=arguments;clearTimeout(t),t=setTimeout((function(){e.apply(r,i)}),n)}}((async()=>{if(a.value=h(e),e.highlight){const n=document.createElement("div");n.innerHTML=a.value,await s(n,e,l),a.value=n.innerHTML}}),200);return t(e,d,{deep:!0,immediate:!0}),r((()=>{"side-by-side"===e.outputFormat&&c(".d2h-file-side-diff")})),i((()=>{"side-by-side"===e.outputFormat&&c(".d2h-file-side-diff")})),{html:a}},render(){return a("div",l?{innerHTML:this.html}:{domProps:{innerHTML:this.html}})}});const w=e=>{e.component(g.name,g)};var y={install:w};export{g as CodeDiff,y as default,w as install};
|
package/dist/v-code-diff.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vue-demi"),require("diff"),require("diff2html"),require("highlight.js"),require("diff2html/bundles/css/diff2html.min.css")):"function"==typeof define&&define.amd?define(["exports","vue-demi","diff","diff2html","highlight.js","diff2html/bundles/css/diff2html.min.css"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["v-code-diff"]={},e.VueDemi,e.diff,e.d2h,e.hljs)}(this,(function(e,n,t,r,
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vue-demi"),require("diff"),require("diff2html"),require("highlight.js"),require("diff2html/bundles/css/diff2html.min.css")):"function"==typeof define&&define.amd?define(["exports","vue-demi","diff","diff2html","highlight.js","diff2html/bundles/css/diff2html.min.css"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["v-code-diff"]={},e.VueDemi,e.diff,e.d2h,e.hljs)}(this,(function(e,n,t,r,i){"use strict";function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function d(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}var a=d(r),o=l(i);const h=e=>{let n=e.trim?e.oldString.trim():e.oldString,r=e.trim?e.newString.trim():e.newString;n=e.noDiffLineFeed?n.replace(/(\r\n)/g,"\n"):n,r=e.noDiffLineFeed?r.replace(/(\r\n)/g,"\n"):r;let i=e.context;e.isShowNoChange&&n===r&&(n="File Without Change\tOldString: ======================== \n"+n,r="File Without Change\tNewString: ======================== \n"+r,i=99999);const l=t.createPatch(e.fileName,n,r,"","",{context:i});return a.html(l,{outputFormat:e.outputFormat,drawFileList:e.drawFileList,matching:"lines",diffStyle:e.diffStyle,renderNothingWhenEmpty:e.renderNothingWhenEmpty})};async function p(e,n,t){t.emit("before-render");const r=await async function(e){return new Promise((n=>{setTimeout((()=>{const t=e.querySelectorAll(".d2h-wrapper .d2h-code-line-ctn");n(Array.from(t))}),0)}))}(e),i=Array.from(r).map((e=>async function(e,n){return new Promise((t=>{setTimeout((()=>{if(n){const t=e.innerText;e.innerHTML=o.default.highlight(t,{language:n}).value}else o.default.highlightElement(e);t(!0)}),0)}))}(e,n.language)));await Promise.all(i),t.emit("after-render")}function s(e){let n=document.createElement("div");document.querySelectorAll(e).forEach((function(t){t.addEventListener("mouseenter",(function(e){n=e.target})),t.addEventListener("scroll",(function(t){t.target===n&&document.querySelectorAll(e).forEach((function(e){n!==e&&(e.scrollTop=n.scrollTop,e.scrollLeft=n.scrollLeft)}))}))}))}var f=[],u=[];function c(e,n){if(e&&"undefined"!=typeof document){var t,r=!0===n.prepend?"prepend":"append",i=!0===n.singleTag,l="string"==typeof n.container?document.querySelector(n.container):document.getElementsByTagName("head")[0];if(i){var d=f.indexOf(l);-1===d&&(d=f.push(l)-1,u[d]={}),t=u[d]&&u[d][r]?u[d][r]:u[d][r]=a()}else t=a();65279===e.charCodeAt(0)&&(e=e.substring(1)),t.styleSheet?t.styleSheet.cssText+=e:t.appendChild(document.createTextNode(e))}function a(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),n.attributes)for(var t=Object.keys(n.attributes),i=0;i<t.length;i++)e.setAttribute(t[i],n.attributes[t[i]]);var d="prepend"===r?"afterbegin":"beforeend";return l.insertAdjacentElement(d,e),e}}c(".d2h-wrapper .hljs {\n display: inline-block;\n padding: 0;\n background: transparent;\n vertical-align: middle;\n}\n.d2h-wrapper .hljs-comment,\n.d2h-wrapper .hljs-quote {\n color: #800;\n}\n.d2h-wrapper .hljs-keyword,\n.d2h-wrapper .hljs-selector-tag,\n.d2h-wrapper .hljs-section,\n.d2h-wrapper .hljs-title,\n.d2h-wrapper .hljs-name {\n color: #008;\n}\n.d2h-wrapper .hljs-variable,\n.d2h-wrapper .hljs-template-variable {\n color: #660;\n}\n.d2h-wrapper .hljs-string,\n.d2h-wrapper .hljs-selector-attr,\n.d2h-wrapper .hljs-selector-pseudo,\n.d2h-wrapper .hljs-regexp {\n color: #080;\n}\n.d2h-wrapper .hljs-literal,\n.d2h-wrapper .hljs-symbol,\n.d2h-wrapper .hljs-bullet,\n.d2h-wrapper .hljs-meta,\n.d2h-wrapper .hljs-number,\n.d2h-wrapper .hljs-link {\n color: #066;\n}\n.d2h-wrapper .hljs-title,\n.d2h-wrapper .hljs-doctag,\n.d2h-wrapper .hljs-type,\n.d2h-wrapper .hljs-attr,\n.d2h-wrapper .hljs-built_in,\n.d2h-wrapper .hljs-builtin-name,\n.d2h-wrapper .hljs-params {\n color: #606;\n}\n.d2h-wrapper .hljs-attribute,\n.d2h-wrapper .hljs-subst {\n color: #000;\n}\n.d2h-wrapper .hljs-formula {\n background-color: #eee;\n font-style: italic;\n}\n.d2h-wrapper .hljs-selector-id,\n.d2h-wrapper .hljs-selector-class {\n color: #9B703F;\n}\n.d2h-wrapper .hljs-addition {\n background-color: #baeeba;\n}\n.d2h-wrapper .hljs-deletion {\n background-color: #ffc8bd;\n}\n.d2h-wrapper .hljs-doctag,\n.d2h-wrapper .hljs-strong {\n font-weight: bold;\n}\n.d2h-wrapper .hljs-emphasis {\n font-style: italic;\n}",{});c(".d2h-wrapper {\n position: relative;\n line-height: normal;\n}\n.d2h-wrapper .d2h-file-header {\n display: none;\n}\n.d2h-wrapper .d2h-files-diff {\n display: flex;\n}\n.d2h-wrapper .d2h-file-side-diff {\n margin-bottom: -5px;\n}\n.d2h-wrapper .d2h-code-side-emptyplaceholder {\n max-height: 19px;\n}\n.d2h-wrapper .d2h-code-side-line,\n.d2h-wrapper .d2h-code-line {\n width: auto;\n}\n.d2h-wrapper .d2h-code-side-line .d2h-info {\n height: 18px;\n}\n.d2h-wrapper .d2h-cntx,\n.d2h-wrapper .d2h-del,\n.d2h-wrapper .d2h-ins {\n height: 18px;\n}\n.d2h-wrapper .d2h-code-linenumber,\n.d2h-wrapper .d2h-code-side-linenumber {\n line-height: 20px;\n height: 20px;\n}\n.d2h-wrapper tr {\n height: 20px;\n}",{});var m=n.defineComponent({name:"CodeDiff",props:{highlight:{type:Boolean,default:!0},oldString:{type:String,default:""},newString:{type:String,default:""},context:{type:Number,default:10},outputFormat:{type:String,default:"line-by-line"},drawFileList:{type:Boolean,default:!1},renderNothingWhenEmpty:{type:Boolean,default:!1},diffStyle:{type:String,default:"word"},fileName:{type:String,default:""},isShowNoChange:{type:Boolean,default:!1},trim:{type:Boolean,default:!1},language:{type:String,default:""},noDiffLineFeed:{type:Boolean,default:!1}},emits:["before-render","after-render"],setup(e,t){const r=n.ref(h(e)),i=function(e,n){let t;return function(){const r=this,i=arguments;clearTimeout(t),t=setTimeout((function(){e.apply(r,i)}),n)}}((async()=>{if(r.value=h(e),e.highlight){const n=document.createElement("div");n.innerHTML=r.value,await p(n,e,t),r.value=n.innerHTML}}),200);return n.watch(e,i,{deep:!0,immediate:!0}),n.onMounted((()=>{"side-by-side"===e.outputFormat&&s(".d2h-file-side-diff")})),n.onUpdated((()=>{"side-by-side"===e.outputFormat&&s(".d2h-file-side-diff")})),{html:r}},render(){return n.isVue3?n.h("div",{innerHTML:this.html}):n.h("div",{domProps:{innerHTML:this.html}})}});const g=e=>{e.component(m.name,m)};var w={install:g};e.CodeDiff=m,e.default=w,e.install=g,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "v-code-diff",
|
|
3
3
|
"description": "A diff plugin of vue, support vue2 and vue3",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.12",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "vite",
|
|
6
|
+
"dev": "pnpm switch:3 && vite",
|
|
7
|
+
"dev:2": "pnpm switch:2 && cd ./dev/vue2.7 && pnpm dev",
|
|
7
8
|
"build": "npx rimraf dist && rollup --config rollup.config.js",
|
|
9
|
+
"switch:3": "vue-demi-switch 3",
|
|
10
|
+
"switch:2": "vue-demi-switch 2.7 vue2",
|
|
8
11
|
"serve": "vite preview",
|
|
9
12
|
"commit": "git-cz",
|
|
10
13
|
"gh-pages": "vite build --base=/v-code-diff/ && gh-pages -d ./pages"
|
|
@@ -45,7 +48,7 @@
|
|
|
45
48
|
"diff": "^5.0.0",
|
|
46
49
|
"diff2html": "^3.4.5",
|
|
47
50
|
"highlight.js": "^10.5.0",
|
|
48
|
-
"vue-demi": "
|
|
51
|
+
"vue-demi": "^0.13.6"
|
|
49
52
|
},
|
|
50
53
|
"devDependencies": {
|
|
51
54
|
"@ant-design-vue/use": "^0.0.1-alpha.10",
|
|
@@ -59,7 +62,6 @@
|
|
|
59
62
|
"@vitejs/plugin-legacy": "^1.5.3",
|
|
60
63
|
"@vitejs/plugin-vue": "^1.6.2",
|
|
61
64
|
"@vitejs/plugin-vue-jsx": "^1.1.8",
|
|
62
|
-
"@vue/compiler-sfc": "^3.2.11",
|
|
63
65
|
"@vue/eslint-config-standard": "^4.0.0",
|
|
64
66
|
"@vue/eslint-config-typescript": "^4.0.0",
|
|
65
67
|
"@vueuse/core": "^4.11.2",
|
|
@@ -70,13 +72,10 @@
|
|
|
70
72
|
"cross-env": "^7.0.3",
|
|
71
73
|
"dotenv": "^8.2.0",
|
|
72
74
|
"eslint": "^7.22.0",
|
|
73
|
-
"eslint-config-prettier": "^8.1.0",
|
|
74
75
|
"eslint-plugin-import": "^2.22.1",
|
|
75
|
-
"eslint-plugin-prettier": "^3.4.0",
|
|
76
76
|
"eslint-plugin-vue": "^7.17.0",
|
|
77
77
|
"gh-pages": "^3.2.1",
|
|
78
78
|
"lint-staged": "^10.5.4",
|
|
79
|
-
"prettier": "^2.2.1",
|
|
80
79
|
"rollup": "^2.38.5",
|
|
81
80
|
"rollup-plugin-styles": "^3.14.1",
|
|
82
81
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -92,6 +91,7 @@
|
|
|
92
91
|
"vue": "^3.2.11",
|
|
93
92
|
"vue-eslint-parser": "^7.11.0",
|
|
94
93
|
"vue-tsc": "^0.3.0",
|
|
94
|
+
"vue2": "npm:vue@2",
|
|
95
95
|
"yorkie": "^2.0.0"
|
|
96
96
|
},
|
|
97
97
|
"gitHooks": {
|
package/src/lib/index.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'vue-demi'
|
|
2
2
|
import CodeDiff from './v-code-diff'
|
|
3
3
|
|
|
4
|
-
const components = [
|
|
5
|
-
CodeDiff
|
|
6
|
-
]
|
|
7
4
|
const install = (app) => {
|
|
8
|
-
|
|
9
|
-
app.component(component.name, component)
|
|
10
|
-
})
|
|
5
|
+
app.component(CodeDiff.name, CodeDiff)
|
|
11
6
|
}
|
|
12
7
|
|
|
13
8
|
export {
|
|
@@ -83,40 +83,22 @@ export async function highlightElements (element: Element, props, ctx: SetupCont
|
|
|
83
83
|
ctx.emit('after-render')
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
export function
|
|
86
|
+
export function syncScroll (selector) {
|
|
87
87
|
let active: HTMLElement = document.createElement('div')
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
document.querySelectorAll(selector).forEach(function (target) {
|
|
93
|
-
if (active === target) return
|
|
94
|
-
|
|
95
|
-
target.scrollTop = active.scrollTop
|
|
96
|
-
target.scrollLeft = active.scrollLeft
|
|
88
|
+
document.querySelectorAll(selector).forEach(function (element) {
|
|
89
|
+
element.addEventListener('mouseenter', function (e) {
|
|
90
|
+
active = e.target
|
|
97
91
|
})
|
|
98
|
-
}
|
|
99
92
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
93
|
+
element.addEventListener('scroll', function (e) {
|
|
94
|
+
if (e.target !== active) return
|
|
103
95
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
element.addEventListener('mouseenter', onMouseenter)
|
|
107
|
-
element.addEventListener('scroll', onScroll)
|
|
108
|
-
})
|
|
109
|
-
}
|
|
96
|
+
document.querySelectorAll(selector).forEach(function (target) {
|
|
97
|
+
if (active === target) return
|
|
110
98
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
element.removeEventListener('scroll', onScroll)
|
|
99
|
+
target.scrollTop = active.scrollTop
|
|
100
|
+
target.scrollLeft = active.scrollLeft
|
|
101
|
+
})
|
|
115
102
|
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
addSyncScroll,
|
|
120
|
-
removeSyncScroll
|
|
121
|
-
}
|
|
103
|
+
})
|
|
122
104
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent, isVue3, PropType, h, ref, watch, onUpdated, onMounted } from 'vue-demi'
|
|
2
|
-
import { createHtml, highlightElements,
|
|
2
|
+
import { createHtml, highlightElements, syncScroll, useDebounceFn } from './util'
|
|
3
3
|
import './styles'
|
|
4
4
|
|
|
5
5
|
export default defineComponent({
|
|
@@ -56,10 +56,6 @@ export default defineComponent({
|
|
|
56
56
|
noDiffLineFeed: {
|
|
57
57
|
type: Boolean,
|
|
58
58
|
default: false
|
|
59
|
-
},
|
|
60
|
-
syncScroll: {
|
|
61
|
-
type: Boolean,
|
|
62
|
-
default: true
|
|
63
59
|
}
|
|
64
60
|
},
|
|
65
61
|
emits: ['before-render', 'after-render'],
|
|
@@ -76,16 +72,16 @@ export default defineComponent({
|
|
|
76
72
|
}, 200)
|
|
77
73
|
watch(props, cb, { deep: true, immediate: true })
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (newVal) {
|
|
83
|
-
addSyncScroll()
|
|
75
|
+
onMounted(() => {
|
|
76
|
+
if (props.outputFormat === 'side-by-side') {
|
|
77
|
+
syncScroll('.d2h-file-side-diff')
|
|
84
78
|
}
|
|
85
79
|
})
|
|
86
80
|
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
onUpdated(() => {
|
|
82
|
+
if (props.outputFormat === 'side-by-side') {
|
|
83
|
+
syncScroll('.d2h-file-side-diff')
|
|
84
|
+
}
|
|
89
85
|
})
|
|
90
86
|
|
|
91
87
|
return {
|