@ht-rnd/merge-conflict-viewer 1.0.0 → 1.0.2
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 +2 -2
- package/dist/lib/main.cjs +2 -2
- package/dist/lib/main.es.js +321 -316
- package/dist/types/index.d.ts +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -221,7 +221,7 @@ The variables are optional. If your CSS does not define one (you copied the file
|
|
|
221
221
|
|
|
222
222
|
### Tailwind v3.4 and v4
|
|
223
223
|
|
|
224
|
-
The same file works with both. It only uses utilities that exist in both (typed arbitrary values such as `bg-[color:var(--
|
|
224
|
+
The same file works with both. It only uses utilities that exist in both (typed arbitrary values such as `bg-[color:var(--mcv-modified)]`, `size-*`, no v4-only syntax) and computes the colour classes per cell in JavaScript, so there are no variant-order surprises. The registry test installs the component into a fresh Tailwind v3.4 project and a fresh v4 project, type-checks them and builds the CSS.
|
|
225
225
|
|
|
226
226
|
Tailwind v3 projects keep their theme in `tailwind.config.js`; the `--merge-*` variables are plain CSS variables referenced through arbitrary values, so nothing needs to be added to the config.
|
|
227
227
|
|
|
@@ -463,7 +463,7 @@ Takes the [options](#options) above. Returns everything `useMergeConflicts` retu
|
|
|
463
463
|
|---|---|
|
|
464
464
|
| `items` | Everything shown, in order: rows (`current`, `result` and `incoming` lines) and folds of unchanged lines |
|
|
465
465
|
| `labels`, `stacked`, `statusState`, `statusText` | Resolved texts, whether the panes are stacked, and the banner state (`"empty" \| "pending" \| "resolved"`) |
|
|
466
|
-
| `collapsed`, `toggleCollapsed` | Whether unchanged runs are folded |
|
|
466
|
+
| `collapsed`, `toggleCollapsed` | Whether unchanged runs are folded. `collapsed` turns `false` when the user opens a run by hand, and `toggleCollapsed` then folds them all again before it switches folding off |
|
|
467
467
|
| `activeId`, `goToChange(dir)`, `goToNextUnresolved()` | Navigation between changes |
|
|
468
468
|
| `editable`, `editingId`, `startEdit(id)`, `cancelEdit()`, `editorText(id)`, `commitEdit(id, text)` | Editing; `commitEdit` returns the parser's message when the text is not valid JSON |
|
|
469
469
|
| `getRootProps()`, `getScrollProps()`, `getGridProps()`, `getHeaderProps(pane)`, `getCellProps(row, pane, column)`, `getFoldProps(fold, pane)` | Prop getters to spread on your elements |
|
package/dist/lib/main.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`),c=o.length-1,i=e===null?"":`${JSON.stringify(e)}: `;return o.map((h,u)=>{const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const nt=require("react/jsx-runtime"),y=require("react"),ot=3;function ie(e,t,s){const r=[],n=(c,i)=>{for(let h=c;h<i;h++)r.push({type:"row",row:e[h]})};let o=0;for(;o<e.length;){if(e[o].blockId!==null){r.push({type:"row",row:e[o]}),o++;continue}let c=o;for(;c<e.length&&e[c].blockId===null;)c++;const i=o===0?1:t,h=c===e.length?1:t,u=c-o-i-h,f=`${e[o-1]?.blockId??"start"}>${e[c]?.blockId??"end"}`;u<ot||s.has(f)?n(o,c):(n(o,o+i),r.push({type:"fold",key:f,hidden:u}),n(c-h,c)),o=c}return r}function Ce(e,t){if(t===null)return[e,"",""];const s=e.endsWith(",")?",":"",r=s?e.slice(0,-1):e,n=t.endsWith(",")?t.slice(0,-1):t;let o=0;const c=Math.min(r.length,n.length);for(;o<c&&r[o]===n[o];)o++;let i=r.length,h=n.length;for(;i>o&&h>o&&r[i-1]===n[h-1];)i--,h--;return[r.slice(0,o),r.slice(o,i),r.slice(i)+s]}function Ae(e,t){if(t==null)return[{text:e,changed:!1}];const[s,r,n]=Ce(e,t);if(!r)return[{text:e,changed:!1}];const o=[];return s&&o.push({text:s,changed:!1}),o.push({text:r,changed:!0}),n&&o.push({text:n,changed:!1}),o}function B(e,t,s){return e===1?t:s}const Ie={current:"Current",result:"Result",incoming:"Incoming",applyAllCurrent:"Apply all from current",applyAllIncoming:"Apply all from incoming",previousChange:"Previous change",nextChange:"Next change",hideUnchanged:"Hide unchanged lines",undo:"Undo",redo:"Redo",summary:({total:e})=>e===0?"No differences":`${e} ${B(e,"change","changes")}`,noChanges:"No differences. Nothing to merge.",unresolved:({unresolved:e,total:t})=>`${e} of ${t} ${B(t,"change","changes")} still ${B(e,"needs","need")} a decision.`,allResolved:({total:e})=>`All ${e} ${B(e,"change","changes")} resolved. Safe to merge.`,nextUnresolved:"Next unresolved",unchangedLines:e=>`${e} unchanged ${B(e,"line","lines")}`,showUnchanged:e=>`Show ${e} unchanged ${B(e,"line","lines")}`,acceptCurrent:e=>`Accept current ${e}`,acceptIncoming:e=>`Accept incoming ${e}`,removeChange:e=>`Remove ${e} from result`,editChange:e=>`Edit ${e} in result`,revertEdit:e=>`Revert edit of ${e}`,editorTitle:e=>`Edit ${e} (JSON value)`,editorInput:e=>`JSON value of ${e}`,apply:"Apply",cancel:"Cancel"};function Le(e){const t={...Ie};for(const[s,r]of Object.entries(e??{}))r!==void 0&&(t[s]=r);return t}const Ee=" ",st=["id","@id","key","name","code","uuid","slug"];function de(e){return typeof e=="object"&&e!==null&&"custom"in e}function U(e,t){return Object.hasOwn(e,t)}function z(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function P(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((s,r)=>P(s,t[r]));if(z(e)&&z(t)){const s=Object.keys(e),r=Object.keys(t);return s.length===r.length&&s.every(n=>U(t,n)&&P(e[n],t[n]))}return!1}function ue(e){return Array.isArray(e)?`[${e.map(ue).join(",")}]`:z(e)?`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${ue(e[t])}`).join(",")}}`:JSON.stringify(e)??"null"}function ae(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}const rt=/^[A-Za-z_$][\w$]*$/;function lt(e,t){return rt.test(t)?e?`${e}.${t}`:t:`${e}[${JSON.stringify(t)}]`}function ct(e,t){const s=[...t],r=new Set(t);let n=-1;for(const o of e){if(r.has(o)){n=s.indexOf(o);continue}n+=1,s.splice(n,0,o),r.add(o)}return s}function we(e,t){const s=e.length,r=t.length,n=r+1,o=new Uint32Array((s+1)*n);for(let u=s-1;u>=0;u--)for(let f=r-1;f>=0;f--)o[u*n+f]=e[u]===t[f]?o[(u+1)*n+f+1]+1:Math.max(o[(u+1)*n+f],o[u*n+f+1]);const c=[];let i=0,h=0;for(;i<s&&h<r;)e[i]===t[h]?(c.push([i,h]),i++,h++):o[(i+1)*n+h]>=o[i*n+h+1]?i++:h++;return c}function it(e,t){return st.find(s=>[e,t].every(r=>{const n=new Set;return r.every(o=>{if(!z(o)||!U(o,s))return!1;const c=o[s];return typeof c!="string"&&typeof c!="number"||n.has(c)?!1:(n.add(c),!0)})}))}function te(e,t,s,r,n,o){const c={type:"conflict",id:JSON.stringify(s),key:t,label:r,path:s,kind:e==="left"?"left-only":"right-only",hasLeft:e==="left",hasRight:e==="right",left:e==="left"?n:void 0,right:e==="right"?n:void 0};return o.push(c),c}function xe(e,t,s,r,n,o){if(P(r,n))return{type:"equal",key:e,value:r};if(z(r)&&z(n))return{type:"container",key:e,container:"object",children:Me(r,n,t,s,o)};if(Array.isArray(r)&&Array.isArray(n))return{type:"container",key:e,container:"array",children:ut(r,n,t,s,o)};const c={type:"conflict",id:JSON.stringify(t),key:e,label:s,path:t,kind:"modified",hasLeft:!0,hasRight:!0,left:r,right:n};return o.push(c),c}function Me(e,t,s,r,n){const o=[];for(const c of ct(Object.keys(e),Object.keys(t))){const i=U(e,c),h=U(t,c),u=[...s,c],f=lt(r,c);i&&h?o.push(xe(c,u,f,e[c],t[c],n)):i?o.push(te("left",c,u,f,e[c],n)):o.push(te("right",c,u,f,t[c],n))}return o}function ut(e,t,s,r,n){const o=it(e,t),c=(S,a)=>S.map(w=>a?`${typeof w[a]}:${w[a]}`:ue(w));let i=we(c(e,o),c(t,o)),h=o!==void 0;h&&i.length===0&&(h=!1,i=we(c(e,void 0),c(t,void 0)));const u=[];let f=0,$=0;const k=S=>`${r}[${S}]`,M=()=>[...s,u.length],R=(S,a)=>{u.push(xe(null,M(),k(a),e[S],t[a],n))},N=(S,a)=>{const w=h?0:Math.min(S-f,a-$);for(let v=0;v<w;v++)R(f+v,$+v);for(let v=f+w;v<S;v++)u.push(te("left",null,M(),k(v),e[v],n));for(let v=$+w;v<a;v++)u.push(te("right",null,M(),k(v),t[v],n));f=S,$=a};for(const[S,a]of i)N(S,a),R(S,a),f=S+1,$=a+1;return N(e.length,t.length),u}function Te(e,t){const s=[];return{children:Me(e,t,[],"",s),conflicts:s}}function Z(e,t){const s=t??"right";return de(s)?{present:!0,value:s.custom,side:null,custom:!0}:s==="left"&&e.hasLeft?{present:!0,value:e.left,side:"left"}:s==="right"&&e.hasRight?{present:!0,value:e.right,side:"right"}:{present:!1,side:null}}function at(e,t){const s=Z(e,t);return s.custom?"custom":s.side??"deleted"}function Y(e,t){const s={};for(const r of e.conflicts)s[r.id]=t;return s}function je(e,t,s){const r={},n=[];for(const o of e){let c;if(o.type==="equal")c=ae(o.value);else if(o.type==="container")c=je(o.children,t,o.container);else{const i=Z(o,t[o.id]);if(!i.present)continue;c=ae(i.value)}s==="array"?n.push(c):o.key!==null&&(r[o.key]=c)}return s==="array"?n:r}function fe(e,t){return je(e.children,t,"object")}const $e=Symbol("unknown");function Ne(e){return e.hasLeft&&e.hasRight?"deleted":e.hasLeft?"right":"left"}function Pe(e,t,s,r){for(const n of e){if(n.type==="equal")continue;if(n.type==="container"){const i=s==="object"&&n.key!==null&&z(t)&&U(t,n.key)?t[n.key]:$e;Pe(n.children,i,n.container,r);continue}if(t===$e){r[n.id]="right";continue}let o=!1,c=!1;if(s==="object"){if(n.key===null||!z(t)||!U(t,n.key)){r[n.id]=Ne(n);continue}const i=t[n.key];if(o=n.hasLeft&&P(i,n.left),c=n.hasRight&&P(i,n.right),!o&&!c){r[n.id]={custom:ae(i)};continue}}else{const i=Array.isArray(t)?t:[];if(o=n.hasLeft&&i.some(h=>P(h,n.left)),c=n.hasRight&&i.some(h=>P(h,n.right)),!o&&!c){r[n.id]=Ne(n);continue}}r[n.id]=o&&!c?"left":"right"}}function Ke(e,t){let s=0,r=0;for(const o of e.conflicts)U(t,o.id)&&(s++,de(t[o.id])&&r++);const n=e.conflicts.length;return{total:n,resolved:s,unresolved:n-s,edited:r,allResolved:s===n}}function De(e,t){if(!t)return Y(e,"right");for(const r of["left","right"]){const n=Y(e,r);if(P(t,fe(e,n)))return n}const s=Y(e,"right");return Pe(e.children,t,"object",s),s}function H(e,t,s,r){const n=Ee.repeat(s),o=(JSON.stringify(t,null,2)??"null").split(`
|
|
2
|
+
`),c=o.length-1,i=e===null?"":`${JSON.stringify(e)}: `;return o.map((h,u)=>{const f=u===0?`${i}${h}`:h;return`${n}${f}${u===c&&r?",":""}`})}function _e(e,t){const s=[],r=[],n=(u,f,$,k=null)=>{s.push({index:s.length,blockId:k,blockRow:0,blockSize:1,left:u,right:f,result:$,leftNo:null,rightNo:null,resultNo:null})},o=(u,f)=>{const $=u.map(a=>a.type!=="conflict"||a.hasLeft),k=u.map(a=>a.type!=="conflict"||a.hasRight),M=u.map(a=>a.type!=="conflict"||Z(a,t[a.id]).present),R=$.lastIndexOf(!0),N=k.lastIndexOf(!0),S=M.lastIndexOf(!0);u.forEach((a,w)=>{const v=w!==R,C=w!==N,A=w!==S;if(a.type==="equal"){const g=H(a.key,a.value,f,v),b=H(a.key,a.value,f,C),j=H(a.key,a.value,f,A);g.forEach((_,D)=>{n(_,b[D],j[D])});return}if(a.type==="container"){const g=Ee.repeat(f),b=a.key===null?"":`${JSON.stringify(a.key)}: `,[j,_]=a.container==="array"?["[","]"]:["{","}"],D=`${g}${b}${j}`;n(D,D,D),o(a.children,f+1),n(`${g}${_}${v?",":""}`,`${g}${_}${C?",":""}`,`${g}${_}${A?",":""}`);return}const F=a.hasLeft?H(a.key,a.left,f,v):[],T=a.hasRight?H(a.key,a.right,f,C):[],I=Z(a,t[a.id]),E=I.present?H(a.key,I.value,f,A):[],K=Math.max(F.length,T.length,E.length),W=s.length;for(let g=0;g<K;g++)n(F[g]??null,T[g]??null,E[g]??null,a.id);r.push({id:a.id,entry:a,kind:a.kind,start:W,size:K,selection:at(a,t[a.id])})})};n("{","{","{"),o(e.children,1),n("}","}","}");for(const u of r)for(let f=0;f<u.size;f++)s[u.start+f].blockRow=f,s[u.start+f].blockSize=u.size;let c=0,i=0,h=0;for(const u of s)u.leftNo=u.left===null?null:++c,u.rightNo=u.right===null?null:++i,u.resultNo=u.result===null?null:++h;return{rows:s,blocks:r}}const ze=y.createContext(null);function dt({viewer:e,children:t}){return nt.jsx(ze.Provider,{value:e,children:t})}function ft(){const e=y.useContext(ze);if(!e)throw new Error("useMergeViewerContext must be used inside a MergeViewerProvider");return e}const ht="minmax(0, 1fr) 3.5rem 3.5ch 3.5ch minmax(0, 1fr) 3.5ch 3.5rem minmax(0, 1fr)",gt="3.5ch 3.5rem minmax(0, 1fr)",pt={current:{code:"1",actions:"2",number:"3",header:"1 / 4",fold:"1 / 4"},result:{number:"4",code:"5",header:"4 / 6",fold:"4 / 6"},incoming:{number:"6",actions:"7",code:"8",header:"6 / 9",fold:"6 / 9"}},yt={current:{number:"1",actions:"2",code:"3",header:"1 / -1",fold:"1 / -1"},incoming:{number:"1",actions:"2",code:"3",header:"1 / -1",fold:"1 / -1"},result:{number:"1",code:"2 / 4",header:"1 / -1",fold:"1 / -1"}},mt={current:0,incoming:1,result:2};function ee(e,t,s,r,n){const c=(e==="stacked"?yt:pt)[t][s]??"auto";if(e==="horizontal")return{gridRow:s==="header"?1:r+2,gridColumn:c};const i=mt[t]*(n+1);return{gridRow:s==="header"?i+1:i+r+2,gridColumn:c}}function Fe(e){return e==="stacked"?gt:ht}const vt=100;function Je({currentJson:e,incomingJson:t,initialMergedJson:s,startUnresolved:r,decisions:n,onDecisionsChange:o}){const c=y.useMemo(()=>JSON.stringify(e),[e]),i=y.useMemo(()=>JSON.stringify(t),[t]),h=y.useMemo(()=>s===void 0?void 0:JSON.stringify(s),[s]),u=y.useMemo(()=>Te(e,t),[c,i]),f=y.useMemo(()=>De(u,s),[u,h]),$=r??s===void 0,k=()=>$?{}:f,[M,R]=y.useState(k),N=y.useRef({past:[],future:[]}),[,S]=y.useState(0),[a,w]=y.useState(u);a!==u&&(w(u),R(k()),N.current={past:[],future:[]});const v=n!==void 0,C=v?n:M,A=y.useRef(C);A.current=C;const F=y.useRef(o);F.current=o;const T=g=>{A.current=g,v||R(g),F.current?.(g),S(b=>b+1)},I=g=>{if(P(g,A.current))return;const b=N.current;b.past.push(A.current),b.past.length>vt&&b.past.shift(),b.future=[],T(g)},E=y.useMemo(()=>({...f,...C}),[f,C]),K=y.useMemo(()=>fe(u,E),[u,E]),W=y.useMemo(()=>Ke(u,C),[u,C]);return{tree:u,decisions:C,selection:E,merged:K,status:W,isResolved:g=>Object.hasOwn(C,g),choose:(g,b)=>I({...A.current,[g]:b}),revert:g=>{const b={...A.current},j=k();Object.hasOwn(j,g)?b[g]=j[g]:delete b[g],I(b)},applyAll:g=>I(Y(u,g)),reset:()=>I(k()),undo:()=>{const g=N.current,b=g.past.pop();b&&(g.future.push(A.current),T(b))},redo:()=>{const g=N.current,b=g.future.pop();b&&(g.past.push(A.current),T(b))},canUndo:N.current.past.length>0,canRedo:N.current.future.length>0}}const bt=900,kt=3,St=typeof window>"u"?y.useEffect:y.useLayoutEffect,ce=e=>e?"":void 0;function Ot({onMergeChange:e,editable:t=!1,labels:s,layout:r="responsive",stackBelow:n=bt,collapseUnchanged:o=!1,...c}){const i=y.useMemo(()=>Le(s),[s]),h=Je(c),{tree:u,selection:f,merged:$,status:k,isResolved:M}=h,R=y.useMemo(()=>_e(u,f),[u,f]),N=y.useMemo(()=>{const l=new Map;for(const d of R.blocks)l.set(d.id,d);return l},[R]),S=y.useRef(e);S.current=e,y.useEffect(()=>{S.current?.($,k)},[$,k]);const[a,w]=y.useState(null),[v,C]=y.useState(null),[A,F]=y.useState(!1);St(()=>{if(r!=="responsive"||!v||typeof ResizeObserver>"u")return;const l=new ResizeObserver(([d])=>{F(d.contentRect.width<n)});return l.observe(v),()=>l.disconnect()},[r,v,n]);const T=r==="vertical"||r==="responsive"&&A,I=T?"stacked":"horizontal",E=typeof o=="number"?o:kt,[K,W]=y.useState(o!==!1),[g,b]=y.useState(()=>new Set),j=y.useMemo(()=>K?ie(R.rows,E,g):R.rows.map(l=>({type:"row",row:l})),[K,R,E,g]),_=l=>l.filter(d=>d.type==="fold").length,D=y.useMemo(()=>K&&_(j)===_(ie(R.rows,E,new Set)),[K,j,R,E]),Ue=()=>{b(new Set),W(!D)},Ve=l=>{b(d=>new Set(d).add(l))},[G,ne]=y.useState(null),[he,oe]=y.useState(null),V=y.useMemo(()=>u.conflicts.map(l=>l.id),[u]),qe=l=>{const d=Array.from(a?.querySelectorAll("[data-merge-block]")??[]).filter(L=>L.dataset.mergeBlock===l),p=d.find(L=>getComputedStyle(L).display!=="none")??d[0],O=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;p?.scrollIntoView?.({block:"center",behavior:O?"auto":"smooth"})},ge=l=>{ne(l),qe(l)},pe=(l,d)=>{if(l.length===0)return null;const p=G===null?-1:V.indexOf(G);if(d==="next")return l.find(L=>V.indexOf(L)>p)??l[0];const O=p===-1?V.length:p;return[...l].reverse().find(L=>V.indexOf(L)<O)??l[l.length-1]},Be=()=>{const l=pe(V.filter(d=>!M(d)),"next");return l===null?!1:(ge(l),!0)},He=l=>{const d=pe(V,l);d!==null&&ge(d)},X=(l,d)=>{h.choose(l,d),ne(l)},ye=l=>{const d=N.get(l);if(!d)return"null";const p=Z(d.entry,f[l]),O=p.present?p.value:d.entry.hasRight?d.entry.right:d.entry.left;return JSON.stringify(O,null,2)??"null"},me=l=>{ne(l),oe(l)},We=()=>oe(null),Ye=(l,d)=>{let p;try{p=JSON.parse(d)}catch(O){return O instanceof Error?O.message:"Invalid JSON"}return X(l,{custom:p}),oe(null),null},se=(l,d,p,O,L)=>{const m=d.blockId?N.get(d.blockId):void 0,le=!!m&&d.blockRow===0,Xe=!!m&&d.blockRow===d.blockSize-1,Q=m?M(m.id):!0,x=m?.entry,Qe=l==="current"?m?.selection==="left":l==="incoming"?m?.selection==="right":!0;let q="unchanged";m&&(p===null?q="filler":l==="result"&&!Q?q="pending":l==="result"&&m.selection==="custom"?q="edited":Q&&!Qe?q="rejected":q="changed");const J={};if(m&&x&&le){const Se=()=>({label:i.removeChange(x.label),pressed:Q&&m.selection==="deleted",run:()=>X(m.id,"deleted")}),Oe=(Re,tt)=>({label:tt,pressed:Q&&m.selection===Re,run:()=>X(m.id,Re)});l==="current"&&x.hasLeft?(J.remove=Se(),J.accept=Oe("left",i.acceptCurrent(x.label))):l==="incoming"&&x.hasRight?(J.accept=Oe("right",i.acceptIncoming(x.label)),J.remove=Se()):l==="result"&&t&&(m.selection==="custom"&&(J.revert={label:i.revertEdit(x.label),pressed:!1,run:()=>h.revert(m.id)}),J.edit={label:i.editChange(x.label),pressed:!1,run:()=>me(m.id)})}const et=l==="result"&&t&&le&&m!==void 0&&he===m.id;return{pane:l,text:p,segments:p===null?[]:Ae(p,l!=="result"&&m?.kind==="modified"?L:void 0),lineNo:O,state:q,kind:m?.kind??null,blockId:m?.id??null,blockStart:le,blockEnd:Xe,active:!!m&&G===m?.id,actions:J,editor:et&&m&&x?{title:i.editorTitle(x.label),inputLabel:i.editorInput(x.label),initialText:ye(m.id)}:void 0}},ve=j.map((l,d)=>{if(l.type==="fold")return{type:"fold",key:`fold-${l.key}`,index:d,hidden:l.hidden,label:i.unchangedLines(l.hidden),showLabel:i.showUnchanged(l.hidden),expand:()=>Ve(l.key)};const{row:p}=l;return{type:"row",key:`row-${p.index}`,index:d,row:p,current:se("current",p,p.left,p.leftNo,p.right),result:se("result",p,p.result,p.resultNo,null),incoming:se("incoming",p,p.right,p.rightNo,p.left)}}),be=k.total,ke=be===0?"empty":k.allResolved?"resolved":"pending",Ze=be===0?i.noChanges:k.allResolved?i.allResolved(k):i.unresolved(k),Ge=l=>{const d=l.target;if(!(l.ctrlKey||l.metaKey)||d.closest("textarea, input"))return;const p=l.key.toLowerCase();p==="z"&&!l.shiftKey?(l.preventDefault(),h.undo()):(p==="z"&&l.shiftKey||p==="y")&&(l.preventDefault(),h.redo())},re=ve.length;return{...h,choose:X,items:ve,labels:i,stacked:T,statusState:ke,statusText:Ze,collapsed:D,toggleCollapsed:Ue,activeId:G,goToChange:He,goToNextUnresolved:Be,editable:t,editingId:he,startEdit:me,cancelEdit:We,editorText:ye,commitEdit:Ye,getRootProps:()=>({ref:w,onKeyDown:Ge,"data-merge-status":ke}),getScrollProps:()=>({ref:C}),getGridProps:()=>({style:{display:"grid",gridTemplateColumns:Fe(I)},"data-layout":I}),getHeaderProps:l=>({style:{...ee(I,l,"header",0,re)},"data-pane":l,"data-column":"header"}),getCellProps:(l,d,p)=>{const O=l[d],L={...ee(I,d,p,l.index,re)};return T&&O.state==="filler"&&(L.display="none"),{style:L,"data-pane":d,"data-column":p,"data-state":O.state,"data-kind":O.kind??void 0,"data-block-start":ce(O.blockStart),"data-block-end":ce(O.blockEnd),"data-active":ce(O.active),"data-merge-block":p==="code"&&O.blockStart?O.blockId??void 0:void 0}},getFoldProps:(l,d)=>({type:"button",style:{...ee(I,d,"fold",l.index,re)},tabIndex:d==="current"?0:-1,"aria-hidden":d==="current"?void 0:!0,"aria-label":l.showLabel,"data-pane":d,"data-column":"fold",onClick:l.expand})}}exports.MergeViewerProvider=dt;exports.buildMergeLayout=_e;exports.buildMergeTree=Te;exports.buildMergedJson=fe;exports.deepEqual=P;exports.defaultLabels=Ie;exports.foldRows=ie;exports.getMergeStatus=Ke;exports.gridTemplateColumns=Fe;exports.initialSelection=De;exports.inlineSegments=Ae;exports.isCustomChoice=de;exports.placeCell=ee;exports.resolveLabels=Le;exports.selectAll=Y;exports.splitInlineEdit=Ce;exports.useMergeConflicts=Je;exports.useMergeViewer=Ot;exports.useMergeViewerContext=ft;
|
package/dist/lib/main.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useContext as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
1
|
+
import { jsx as Ye } from "react/jsx-runtime";
|
|
2
|
+
import { useContext as Ze, createContext as Ge, useMemo as I, useState as K, useRef as ee, useEffect as Ae, useLayoutEffect as Xe } from "react";
|
|
3
|
+
const Qe = 3;
|
|
4
|
+
function $e(e, t, r) {
|
|
5
5
|
const s = [], n = (c, i) => {
|
|
6
6
|
for (let h = c; h < i; h++)
|
|
7
7
|
s.push({ type: "row", row: e[h] });
|
|
@@ -15,12 +15,12 @@ function Ze(e, t, r) {
|
|
|
15
15
|
let c = o;
|
|
16
16
|
for (; c < e.length && e[c].blockId === null; )
|
|
17
17
|
c++;
|
|
18
|
-
const i = o === 0 ? 1 : t, h = c === e.length ? 1 : t, u = c - o - i - h,
|
|
19
|
-
u <
|
|
18
|
+
const i = o === 0 ? 1 : t, h = c === e.length ? 1 : t, u = c - o - i - h, f = `${e[o - 1]?.blockId ?? "start"}>${e[c]?.blockId ?? "end"}`;
|
|
19
|
+
u < Qe || r.has(f) ? n(o, c) : (n(o, o + i), s.push({ type: "fold", key: f, hidden: u }), n(c - h, c)), o = c;
|
|
20
20
|
}
|
|
21
21
|
return s;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function et(e, t) {
|
|
24
24
|
if (t === null)
|
|
25
25
|
return [e, "", ""];
|
|
26
26
|
const r = e.endsWith(",") ? "," : "", s = r ? e.slice(0, -1) : e, n = t.endsWith(",") ? t.slice(0, -1) : t;
|
|
@@ -33,10 +33,10 @@ function Ge(e, t) {
|
|
|
33
33
|
i--, h--;
|
|
34
34
|
return [s.slice(0, o), s.slice(o, i), s.slice(i) + r];
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function tt(e, t) {
|
|
37
37
|
if (t == null)
|
|
38
38
|
return [{ text: e, changed: !1 }];
|
|
39
|
-
const [r, s, n] =
|
|
39
|
+
const [r, s, n] = et(e, t);
|
|
40
40
|
if (!s)
|
|
41
41
|
return [{ text: e, changed: !1 }];
|
|
42
42
|
const o = [];
|
|
@@ -45,7 +45,7 @@ function Xe(e, t) {
|
|
|
45
45
|
function H(e, t, r) {
|
|
46
46
|
return e === 1 ? t : r;
|
|
47
47
|
}
|
|
48
|
-
const
|
|
48
|
+
const nt = {
|
|
49
49
|
current: "Current",
|
|
50
50
|
result: "Result",
|
|
51
51
|
incoming: "Incoming",
|
|
@@ -77,44 +77,44 @@ const Qe = {
|
|
|
77
77
|
apply: "Apply",
|
|
78
78
|
cancel: "Cancel"
|
|
79
79
|
};
|
|
80
|
-
function
|
|
81
|
-
const t = { ...
|
|
80
|
+
function ot(e) {
|
|
81
|
+
const t = { ...nt };
|
|
82
82
|
for (const [r, s] of Object.entries(e ?? {}))
|
|
83
83
|
s !== void 0 && (t[r] = s);
|
|
84
84
|
return t;
|
|
85
85
|
}
|
|
86
|
-
const
|
|
87
|
-
function
|
|
86
|
+
const Ie = " ", rt = ["id", "@id", "key", "name", "code", "uuid", "slug"];
|
|
87
|
+
function Le(e) {
|
|
88
88
|
return typeof e == "object" && e !== null && "custom" in e;
|
|
89
89
|
}
|
|
90
90
|
function B(e, t) {
|
|
91
91
|
return Object.hasOwn(e, t);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function F(e) {
|
|
94
94
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function _(e, t) {
|
|
97
97
|
if (e === t)
|
|
98
98
|
return !0;
|
|
99
99
|
if (Array.isArray(e) || Array.isArray(t))
|
|
100
|
-
return Array.isArray(e) && Array.isArray(t) && e.length === t.length && e.every((r, s) =>
|
|
101
|
-
if (
|
|
100
|
+
return Array.isArray(e) && Array.isArray(t) && e.length === t.length && e.every((r, s) => _(r, t[s]));
|
|
101
|
+
if (F(e) && F(t)) {
|
|
102
102
|
const r = Object.keys(e), s = Object.keys(t);
|
|
103
|
-
return r.length === s.length && r.every((n) => B(t, n) &&
|
|
103
|
+
return r.length === s.length && r.every((n) => B(t, n) && _(e[n], t[n]));
|
|
104
104
|
}
|
|
105
105
|
return !1;
|
|
106
106
|
}
|
|
107
|
-
function ue(e) {
|
|
108
|
-
return Array.isArray(e) ? `[${e.map(ue).join(",")}]` : z(e) ? `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${ue(e[t])}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
109
|
-
}
|
|
110
107
|
function ae(e) {
|
|
108
|
+
return Array.isArray(e) ? `[${e.map(ae).join(",")}]` : F(e) ? `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${ae(e[t])}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
109
|
+
}
|
|
110
|
+
function de(e) {
|
|
111
111
|
return e === void 0 ? e : JSON.parse(JSON.stringify(e));
|
|
112
112
|
}
|
|
113
|
-
const
|
|
114
|
-
function
|
|
115
|
-
return
|
|
113
|
+
const st = /^[A-Za-z_$][\w$]*$/;
|
|
114
|
+
function lt(e, t) {
|
|
115
|
+
return st.test(t) ? e ? `${e}.${t}` : t : `${e}[${JSON.stringify(t)}]`;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function ct(e, t) {
|
|
118
118
|
const r = [...t], s = new Set(t);
|
|
119
119
|
let n = -1;
|
|
120
120
|
for (const o of e) {
|
|
@@ -126,23 +126,23 @@ function rt(e, t) {
|
|
|
126
126
|
}
|
|
127
127
|
return r;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function Re(e, t) {
|
|
130
130
|
const r = e.length, s = t.length, n = s + 1, o = new Uint32Array((r + 1) * n);
|
|
131
131
|
for (let u = r - 1; u >= 0; u--)
|
|
132
|
-
for (let
|
|
133
|
-
o[u * n +
|
|
132
|
+
for (let f = s - 1; f >= 0; f--)
|
|
133
|
+
o[u * n + f] = e[u] === t[f] ? o[(u + 1) * n + f + 1] + 1 : Math.max(o[(u + 1) * n + f], o[u * n + f + 1]);
|
|
134
134
|
const c = [];
|
|
135
135
|
let i = 0, h = 0;
|
|
136
136
|
for (; i < r && h < s; )
|
|
137
137
|
e[i] === t[h] ? (c.push([i, h]), i++, h++) : o[(i + 1) * n + h] >= o[i * n + h + 1] ? i++ : h++;
|
|
138
138
|
return c;
|
|
139
139
|
}
|
|
140
|
-
function
|
|
141
|
-
return
|
|
140
|
+
function it(e, t) {
|
|
141
|
+
return rt.find(
|
|
142
142
|
(r) => [e, t].every((s) => {
|
|
143
143
|
const n = /* @__PURE__ */ new Set();
|
|
144
144
|
return s.every((o) => {
|
|
145
|
-
if (!
|
|
145
|
+
if (!F(o) || !B(o, r))
|
|
146
146
|
return !1;
|
|
147
147
|
const c = o[r];
|
|
148
148
|
return typeof c != "string" && typeof c != "number" || n.has(c) ? !1 : (n.add(c), !0);
|
|
@@ -150,7 +150,7 @@ function st(e, t) {
|
|
|
150
150
|
})
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function ne(e, t, r, s, n, o) {
|
|
154
154
|
const c = {
|
|
155
155
|
type: "conflict",
|
|
156
156
|
id: JSON.stringify(r),
|
|
@@ -165,22 +165,22 @@ function te(e, t, r, s, n, o) {
|
|
|
165
165
|
};
|
|
166
166
|
return o.push(c), c;
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
if (
|
|
168
|
+
function Ce(e, t, r, s, n, o) {
|
|
169
|
+
if (_(s, n))
|
|
170
170
|
return { type: "equal", key: e, value: s };
|
|
171
|
-
if (
|
|
171
|
+
if (F(s) && F(n))
|
|
172
172
|
return {
|
|
173
173
|
type: "container",
|
|
174
174
|
key: e,
|
|
175
175
|
container: "object",
|
|
176
|
-
children:
|
|
176
|
+
children: Ee(s, n, t, r, o)
|
|
177
177
|
};
|
|
178
178
|
if (Array.isArray(s) && Array.isArray(n))
|
|
179
179
|
return {
|
|
180
180
|
type: "container",
|
|
181
181
|
key: e,
|
|
182
182
|
container: "array",
|
|
183
|
-
children:
|
|
183
|
+
children: ut(s, n, t, r, o)
|
|
184
184
|
};
|
|
185
185
|
const c = {
|
|
186
186
|
type: "conflict",
|
|
@@ -196,27 +196,27 @@ function Ie(e, t, r, s, n, o) {
|
|
|
196
196
|
};
|
|
197
197
|
return o.push(c), c;
|
|
198
198
|
}
|
|
199
|
-
function
|
|
199
|
+
function Ee(e, t, r, s, n) {
|
|
200
200
|
const o = [];
|
|
201
|
-
for (const c of
|
|
202
|
-
const i = B(e, c), h = B(t, c), u = [...r, c],
|
|
201
|
+
for (const c of ct(Object.keys(e), Object.keys(t))) {
|
|
202
|
+
const i = B(e, c), h = B(t, c), u = [...r, c], f = lt(s, c);
|
|
203
203
|
i && h ? o.push(
|
|
204
|
-
|
|
204
|
+
Ce(
|
|
205
205
|
c,
|
|
206
206
|
u,
|
|
207
|
-
|
|
207
|
+
f,
|
|
208
208
|
e[c],
|
|
209
209
|
t[c],
|
|
210
210
|
n
|
|
211
211
|
)
|
|
212
212
|
) : i ? o.push(
|
|
213
|
-
|
|
213
|
+
ne("left", c, u, f, e[c], n)
|
|
214
214
|
) : o.push(
|
|
215
|
-
|
|
215
|
+
ne(
|
|
216
216
|
"right",
|
|
217
217
|
c,
|
|
218
218
|
u,
|
|
219
|
-
|
|
219
|
+
f,
|
|
220
220
|
t[c],
|
|
221
221
|
n
|
|
222
222
|
)
|
|
@@ -224,28 +224,28 @@ function Le(e, t, r, s, n) {
|
|
|
224
224
|
}
|
|
225
225
|
return o;
|
|
226
226
|
}
|
|
227
|
-
function
|
|
228
|
-
const o =
|
|
229
|
-
(
|
|
227
|
+
function ut(e, t, r, s, n) {
|
|
228
|
+
const o = it(e, t), c = (k, a) => k.map(
|
|
229
|
+
($) => a ? `${typeof $[a]}:${$[a]}` : ae($)
|
|
230
230
|
);
|
|
231
|
-
let i =
|
|
231
|
+
let i = Re(
|
|
232
232
|
c(e, o),
|
|
233
233
|
c(t, o)
|
|
234
234
|
), h = o !== void 0;
|
|
235
|
-
h && i.length === 0 && (h = !1, i =
|
|
235
|
+
h && i.length === 0 && (h = !1, i = Re(c(e, void 0), c(t, void 0)));
|
|
236
236
|
const u = [];
|
|
237
|
-
let
|
|
238
|
-
const b = (k) => `${s}[${k}]`, T = () => [...r, u.length],
|
|
237
|
+
let f = 0, R = 0;
|
|
238
|
+
const b = (k) => `${s}[${k}]`, T = () => [...r, u.length], S = (k, a) => {
|
|
239
239
|
u.push(
|
|
240
|
-
|
|
240
|
+
Ce(null, T(), b(a), e[k], t[a], n)
|
|
241
241
|
);
|
|
242
|
-
},
|
|
243
|
-
const
|
|
244
|
-
for (let m = 0; m <
|
|
245
|
-
|
|
246
|
-
for (let m =
|
|
242
|
+
}, w = (k, a) => {
|
|
243
|
+
const $ = h ? 0 : Math.min(k - f, a - R);
|
|
244
|
+
for (let m = 0; m < $; m++)
|
|
245
|
+
S(f + m, R + m);
|
|
246
|
+
for (let m = f + $; m < k; m++)
|
|
247
247
|
u.push(
|
|
248
|
-
|
|
248
|
+
ne(
|
|
249
249
|
"left",
|
|
250
250
|
null,
|
|
251
251
|
T(),
|
|
@@ -254,9 +254,9 @@ function lt(e, t, r, s, n) {
|
|
|
254
254
|
n
|
|
255
255
|
)
|
|
256
256
|
);
|
|
257
|
-
for (let m =
|
|
257
|
+
for (let m = R + $; m < a; m++)
|
|
258
258
|
u.push(
|
|
259
|
-
|
|
259
|
+
ne(
|
|
260
260
|
"right",
|
|
261
261
|
null,
|
|
262
262
|
T(),
|
|
@@ -265,93 +265,93 @@ function lt(e, t, r, s, n) {
|
|
|
265
265
|
n
|
|
266
266
|
)
|
|
267
267
|
);
|
|
268
|
-
|
|
268
|
+
f = k, R = a;
|
|
269
269
|
};
|
|
270
270
|
for (const [k, a] of i)
|
|
271
|
-
|
|
272
|
-
return
|
|
271
|
+
w(k, a), S(k, a), f = k + 1, R = a + 1;
|
|
272
|
+
return w(e.length, t.length), u;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function at(e, t) {
|
|
275
275
|
const r = [];
|
|
276
|
-
return { children:
|
|
276
|
+
return { children: Ee(e, t, [], "", r), conflicts: r };
|
|
277
277
|
}
|
|
278
278
|
function Z(e, t) {
|
|
279
279
|
const r = t ?? "right";
|
|
280
|
-
return
|
|
280
|
+
return Le(r) ? { present: !0, value: r.custom, side: null, custom: !0 } : r === "left" && e.hasLeft ? { present: !0, value: e.left, side: "left" } : r === "right" && e.hasRight ? { present: !0, value: e.right, side: "right" } : { present: !1, side: null };
|
|
281
281
|
}
|
|
282
|
-
function
|
|
282
|
+
function dt(e, t) {
|
|
283
283
|
const r = Z(e, t);
|
|
284
284
|
return r.custom ? "custom" : r.side ?? "deleted";
|
|
285
285
|
}
|
|
286
|
-
function
|
|
286
|
+
function te(e, t) {
|
|
287
287
|
const r = {};
|
|
288
288
|
for (const s of e.conflicts)
|
|
289
289
|
r[s.id] = t;
|
|
290
290
|
return r;
|
|
291
291
|
}
|
|
292
|
-
function
|
|
292
|
+
function xe(e, t, r) {
|
|
293
293
|
const s = {}, n = [];
|
|
294
294
|
for (const o of e) {
|
|
295
295
|
let c;
|
|
296
296
|
if (o.type === "equal")
|
|
297
|
-
c =
|
|
297
|
+
c = de(o.value);
|
|
298
298
|
else if (o.type === "container")
|
|
299
|
-
c =
|
|
299
|
+
c = xe(o.children, t, o.container);
|
|
300
300
|
else {
|
|
301
301
|
const i = Z(o, t[o.id]);
|
|
302
302
|
if (!i.present)
|
|
303
303
|
continue;
|
|
304
|
-
c =
|
|
304
|
+
c = de(i.value);
|
|
305
305
|
}
|
|
306
306
|
r === "array" ? n.push(c) : o.key !== null && (s[o.key] = c);
|
|
307
307
|
}
|
|
308
308
|
return r === "array" ? n : s;
|
|
309
309
|
}
|
|
310
|
-
function
|
|
311
|
-
return
|
|
310
|
+
function Te(e, t) {
|
|
311
|
+
return xe(e.children, t, "object");
|
|
312
312
|
}
|
|
313
|
-
const
|
|
314
|
-
function
|
|
313
|
+
const we = /* @__PURE__ */ Symbol("unknown");
|
|
314
|
+
function Ne(e) {
|
|
315
315
|
return e.hasLeft && e.hasRight ? "deleted" : e.hasLeft ? "right" : "left";
|
|
316
316
|
}
|
|
317
|
-
function
|
|
317
|
+
function je(e, t, r, s) {
|
|
318
318
|
for (const n of e) {
|
|
319
319
|
if (n.type === "equal")
|
|
320
320
|
continue;
|
|
321
321
|
if (n.type === "container") {
|
|
322
|
-
const i = r === "object" && n.key !== null &&
|
|
323
|
-
|
|
322
|
+
const i = r === "object" && n.key !== null && F(t) && B(t, n.key) ? t[n.key] : we;
|
|
323
|
+
je(n.children, i, n.container, s);
|
|
324
324
|
continue;
|
|
325
325
|
}
|
|
326
|
-
if (t ===
|
|
326
|
+
if (t === we) {
|
|
327
327
|
s[n.id] = "right";
|
|
328
328
|
continue;
|
|
329
329
|
}
|
|
330
330
|
let o = !1, c = !1;
|
|
331
331
|
if (r === "object") {
|
|
332
|
-
if (n.key === null || !
|
|
333
|
-
s[n.id] =
|
|
332
|
+
if (n.key === null || !F(t) || !B(t, n.key)) {
|
|
333
|
+
s[n.id] = Ne(n);
|
|
334
334
|
continue;
|
|
335
335
|
}
|
|
336
336
|
const i = t[n.key];
|
|
337
|
-
if (o = n.hasLeft &&
|
|
338
|
-
s[n.id] = { custom:
|
|
337
|
+
if (o = n.hasLeft && _(i, n.left), c = n.hasRight && _(i, n.right), !o && !c) {
|
|
338
|
+
s[n.id] = { custom: de(i) };
|
|
339
339
|
continue;
|
|
340
340
|
}
|
|
341
341
|
} else {
|
|
342
342
|
const i = Array.isArray(t) ? t : [];
|
|
343
|
-
if (o = n.hasLeft && i.some((h) =>
|
|
344
|
-
s[n.id] =
|
|
343
|
+
if (o = n.hasLeft && i.some((h) => _(h, n.left)), c = n.hasRight && i.some((h) => _(h, n.right)), !o && !c) {
|
|
344
|
+
s[n.id] = Ne(n);
|
|
345
345
|
continue;
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
s[n.id] = o && !c ? "left" : "right";
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function ft(e, t) {
|
|
352
352
|
let r = 0, s = 0;
|
|
353
353
|
for (const o of e.conflicts)
|
|
354
|
-
B(t, o.id) && (r++,
|
|
354
|
+
B(t, o.id) && (r++, Le(t[o.id]) && s++);
|
|
355
355
|
const n = e.conflicts.length;
|
|
356
356
|
return {
|
|
357
357
|
total: n,
|
|
@@ -361,99 +361,99 @@ function ut(e, t) {
|
|
|
361
361
|
allResolved: r === n
|
|
362
362
|
};
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function ht(e, t) {
|
|
365
365
|
if (!t)
|
|
366
|
-
return
|
|
366
|
+
return te(e, "right");
|
|
367
367
|
for (const s of ["left", "right"]) {
|
|
368
|
-
const n =
|
|
369
|
-
if (
|
|
368
|
+
const n = te(e, s);
|
|
369
|
+
if (_(t, Te(e, n)))
|
|
370
370
|
return n;
|
|
371
371
|
}
|
|
372
|
-
const r =
|
|
373
|
-
return
|
|
372
|
+
const r = te(e, "right");
|
|
373
|
+
return je(e.children, t, "object", r), r;
|
|
374
374
|
}
|
|
375
375
|
function W(e, t, r, s) {
|
|
376
|
-
const n =
|
|
376
|
+
const n = Ie.repeat(r), o = (JSON.stringify(t, null, 2) ?? "null").split(`
|
|
377
377
|
`), c = o.length - 1, i = e === null ? "" : `${JSON.stringify(e)}: `;
|
|
378
378
|
return o.map((h, u) => {
|
|
379
|
-
const
|
|
380
|
-
return `${n}${
|
|
379
|
+
const f = u === 0 ? `${i}${h}` : h;
|
|
380
|
+
return `${n}${f}${u === c && s ? "," : ""}`;
|
|
381
381
|
});
|
|
382
382
|
}
|
|
383
|
-
function
|
|
384
|
-
const r = [], s = [], n = (u,
|
|
383
|
+
function gt(e, t) {
|
|
384
|
+
const r = [], s = [], n = (u, f, R, b = null) => {
|
|
385
385
|
r.push({
|
|
386
386
|
index: r.length,
|
|
387
387
|
blockId: b,
|
|
388
388
|
blockRow: 0,
|
|
389
389
|
blockSize: 1,
|
|
390
390
|
left: u,
|
|
391
|
-
right:
|
|
392
|
-
result:
|
|
391
|
+
right: f,
|
|
392
|
+
result: R,
|
|
393
393
|
leftNo: null,
|
|
394
394
|
rightNo: null,
|
|
395
395
|
resultNo: null
|
|
396
396
|
});
|
|
397
|
-
}, o = (u,
|
|
398
|
-
const
|
|
397
|
+
}, o = (u, f) => {
|
|
398
|
+
const R = u.map((a) => a.type !== "conflict" || a.hasLeft), b = u.map((a) => a.type !== "conflict" || a.hasRight), T = u.map(
|
|
399
399
|
(a) => a.type !== "conflict" || Z(a, t[a.id]).present
|
|
400
|
-
),
|
|
401
|
-
u.forEach((a,
|
|
402
|
-
const m =
|
|
400
|
+
), S = R.lastIndexOf(!0), w = b.lastIndexOf(!0), k = T.lastIndexOf(!0);
|
|
401
|
+
u.forEach((a, $) => {
|
|
402
|
+
const m = $ !== S, N = $ !== w, A = $ !== k;
|
|
403
403
|
if (a.type === "equal") {
|
|
404
|
-
const g = W(a.key, a.value,
|
|
405
|
-
g.forEach((
|
|
406
|
-
n(
|
|
404
|
+
const g = W(a.key, a.value, f, m), v = W(a.key, a.value, f, N), M = W(a.key, a.value, f, A);
|
|
405
|
+
g.forEach((z, P) => {
|
|
406
|
+
n(z, v[P], M[P]);
|
|
407
407
|
});
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
410
410
|
if (a.type === "container") {
|
|
411
|
-
const g =
|
|
412
|
-
n(
|
|
413
|
-
`${g}${
|
|
414
|
-
`${g}${
|
|
415
|
-
`${g}${
|
|
411
|
+
const g = Ie.repeat(f), v = a.key === null ? "" : `${JSON.stringify(a.key)}: `, [M, z] = a.container === "array" ? ["[", "]"] : ["{", "}"], P = `${g}${v}${M}`;
|
|
412
|
+
n(P, P, P), o(a.children, f + 1), n(
|
|
413
|
+
`${g}${z}${m ? "," : ""}`,
|
|
414
|
+
`${g}${z}${N ? "," : ""}`,
|
|
415
|
+
`${g}${z}${A ? "," : ""}`
|
|
416
416
|
);
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
|
-
const U = a.hasLeft ? W(a.key, a.left,
|
|
420
|
-
for (let g = 0; g <
|
|
421
|
-
n(U[g] ?? null, j[g] ?? null,
|
|
419
|
+
const U = a.hasLeft ? W(a.key, a.left, f, m) : [], j = a.hasRight ? W(a.key, a.right, f, N) : [], L = Z(a, t[a.id]), E = L.present ? W(a.key, L.value, f, A) : [], D = Math.max(U.length, j.length, E.length), Y = r.length;
|
|
420
|
+
for (let g = 0; g < D; g++)
|
|
421
|
+
n(U[g] ?? null, j[g] ?? null, E[g] ?? null, a.id);
|
|
422
422
|
s.push({
|
|
423
423
|
id: a.id,
|
|
424
424
|
entry: a,
|
|
425
425
|
kind: a.kind,
|
|
426
426
|
start: Y,
|
|
427
|
-
size:
|
|
428
|
-
selection:
|
|
427
|
+
size: D,
|
|
428
|
+
selection: dt(a, t[a.id])
|
|
429
429
|
});
|
|
430
430
|
});
|
|
431
431
|
};
|
|
432
432
|
n("{", "{", "{"), o(e.children, 1), n("}", "}", "}");
|
|
433
433
|
for (const u of s)
|
|
434
|
-
for (let
|
|
435
|
-
r[u.start +
|
|
434
|
+
for (let f = 0; f < u.size; f++)
|
|
435
|
+
r[u.start + f].blockRow = f, r[u.start + f].blockSize = u.size;
|
|
436
436
|
let c = 0, i = 0, h = 0;
|
|
437
437
|
for (const u of r)
|
|
438
438
|
u.leftNo = u.left === null ? null : ++c, u.rightNo = u.right === null ? null : ++i, u.resultNo = u.result === null ? null : ++h;
|
|
439
439
|
return { rows: r, blocks: s };
|
|
440
440
|
}
|
|
441
|
-
const
|
|
442
|
-
function
|
|
441
|
+
const Me = Ge(null);
|
|
442
|
+
function It({
|
|
443
443
|
viewer: e,
|
|
444
444
|
children: t
|
|
445
445
|
}) {
|
|
446
|
-
return /* @__PURE__ */
|
|
446
|
+
return /* @__PURE__ */ Ye(Me.Provider, { value: e, children: t });
|
|
447
447
|
}
|
|
448
|
-
function
|
|
449
|
-
const e =
|
|
448
|
+
function Lt() {
|
|
449
|
+
const e = Ze(Me);
|
|
450
450
|
if (!e)
|
|
451
451
|
throw new Error(
|
|
452
452
|
"useMergeViewerContext must be used inside a MergeViewerProvider"
|
|
453
453
|
);
|
|
454
454
|
return e;
|
|
455
455
|
}
|
|
456
|
-
const
|
|
456
|
+
const pt = "minmax(0, 1fr) 3.5rem 3.5ch 3.5ch minmax(0, 1fr) 3.5ch 3.5rem minmax(0, 1fr)", yt = "3.5ch 3.5rem minmax(0, 1fr)", mt = {
|
|
457
457
|
current: {
|
|
458
458
|
code: "1",
|
|
459
459
|
actions: "2",
|
|
@@ -474,7 +474,7 @@ const ft = "minmax(0, 1fr) 3.5rem 3.5ch 3.5ch minmax(0, 1fr) 3.5ch 3.5rem minmax
|
|
|
474
474
|
header: "6 / 9",
|
|
475
475
|
fold: "6 / 9"
|
|
476
476
|
}
|
|
477
|
-
},
|
|
477
|
+
}, vt = {
|
|
478
478
|
current: {
|
|
479
479
|
number: "1",
|
|
480
480
|
actions: "2",
|
|
@@ -496,26 +496,26 @@ const ft = "minmax(0, 1fr) 3.5rem 3.5ch 3.5ch minmax(0, 1fr) 3.5ch 3.5rem minmax
|
|
|
496
496
|
header: "1 / -1",
|
|
497
497
|
fold: "1 / -1"
|
|
498
498
|
}
|
|
499
|
-
},
|
|
499
|
+
}, bt = {
|
|
500
500
|
current: 0,
|
|
501
501
|
incoming: 1,
|
|
502
502
|
result: 2
|
|
503
503
|
};
|
|
504
|
-
function
|
|
505
|
-
const c = (e === "stacked" ?
|
|
504
|
+
function ie(e, t, r, s, n) {
|
|
505
|
+
const c = (e === "stacked" ? vt : mt)[t][r] ?? "auto";
|
|
506
506
|
if (e === "horizontal")
|
|
507
507
|
return { gridRow: r === "header" ? 1 : s + 2, gridColumn: c };
|
|
508
|
-
const i =
|
|
508
|
+
const i = bt[t] * (n + 1);
|
|
509
509
|
return {
|
|
510
510
|
gridRow: r === "header" ? i + 1 : i + s + 2,
|
|
511
511
|
gridColumn: c
|
|
512
512
|
};
|
|
513
513
|
}
|
|
514
|
-
function
|
|
515
|
-
return e === "stacked" ?
|
|
514
|
+
function kt(e) {
|
|
515
|
+
return e === "stacked" ? yt : pt;
|
|
516
516
|
}
|
|
517
|
-
const
|
|
518
|
-
function
|
|
517
|
+
const Ot = 100;
|
|
518
|
+
function St({
|
|
519
519
|
currentJson: e,
|
|
520
520
|
incomingJson: t,
|
|
521
521
|
initialMergedJson: r,
|
|
@@ -523,309 +523,314 @@ function bt({
|
|
|
523
523
|
decisions: n,
|
|
524
524
|
onDecisionsChange: o
|
|
525
525
|
}) {
|
|
526
|
-
const c =
|
|
526
|
+
const c = I(() => JSON.stringify(e), [e]), i = I(
|
|
527
527
|
() => JSON.stringify(t),
|
|
528
528
|
[t]
|
|
529
|
-
), h =
|
|
529
|
+
), h = I(
|
|
530
530
|
() => r === void 0 ? void 0 : JSON.stringify(r),
|
|
531
531
|
[r]
|
|
532
|
-
), u =
|
|
533
|
-
() =>
|
|
532
|
+
), u = I(
|
|
533
|
+
() => at(e, t),
|
|
534
534
|
[c, i]
|
|
535
|
-
),
|
|
536
|
-
() =>
|
|
535
|
+
), f = I(
|
|
536
|
+
() => ht(u, r),
|
|
537
537
|
[u, h]
|
|
538
|
-
),
|
|
539
|
-
a !== u && (
|
|
540
|
-
const m = n !== void 0, N = m ? n : T,
|
|
541
|
-
|
|
542
|
-
const U =
|
|
538
|
+
), R = s ?? r === void 0, b = () => R ? {} : f, [T, S] = K(b), w = ee({ past: [], future: [] }), [, k] = K(0), [a, $] = K(u);
|
|
539
|
+
a !== u && ($(u), S(b()), w.current = { past: [], future: [] });
|
|
540
|
+
const m = n !== void 0, N = m ? n : T, A = ee(N);
|
|
541
|
+
A.current = N;
|
|
542
|
+
const U = ee(o);
|
|
543
543
|
U.current = o;
|
|
544
544
|
const j = (g) => {
|
|
545
|
-
|
|
546
|
-
},
|
|
547
|
-
if (
|
|
545
|
+
A.current = g, m || S(g), U.current?.(g), k((v) => v + 1);
|
|
546
|
+
}, L = (g) => {
|
|
547
|
+
if (_(g, A.current))
|
|
548
548
|
return;
|
|
549
|
-
const v =
|
|
550
|
-
v.past.push(
|
|
551
|
-
},
|
|
552
|
-
() => ({ ...
|
|
553
|
-
[
|
|
554
|
-
),
|
|
555
|
-
() =>
|
|
556
|
-
[u,
|
|
557
|
-
), Y =
|
|
558
|
-
() =>
|
|
549
|
+
const v = w.current;
|
|
550
|
+
v.past.push(A.current), v.past.length > Ot && v.past.shift(), v.future = [], j(g);
|
|
551
|
+
}, E = I(
|
|
552
|
+
() => ({ ...f, ...N }),
|
|
553
|
+
[f, N]
|
|
554
|
+
), D = I(
|
|
555
|
+
() => Te(u, E),
|
|
556
|
+
[u, E]
|
|
557
|
+
), Y = I(
|
|
558
|
+
() => ft(u, N),
|
|
559
559
|
[u, N]
|
|
560
560
|
);
|
|
561
561
|
return {
|
|
562
562
|
tree: u,
|
|
563
563
|
decisions: N,
|
|
564
|
-
selection:
|
|
565
|
-
merged:
|
|
564
|
+
selection: E,
|
|
565
|
+
merged: D,
|
|
566
566
|
status: Y,
|
|
567
567
|
isResolved: (g) => Object.hasOwn(N, g),
|
|
568
|
-
choose: (g, v) =>
|
|
568
|
+
choose: (g, v) => L({ ...A.current, [g]: v }),
|
|
569
569
|
revert: (g) => {
|
|
570
|
-
const v = { ...
|
|
571
|
-
Object.hasOwn(
|
|
570
|
+
const v = { ...A.current }, M = b();
|
|
571
|
+
Object.hasOwn(M, g) ? v[g] = M[g] : delete v[g], L(v);
|
|
572
572
|
},
|
|
573
|
-
applyAll: (g) =>
|
|
574
|
-
reset: () =>
|
|
573
|
+
applyAll: (g) => L(te(u, g)),
|
|
574
|
+
reset: () => L(b()),
|
|
575
575
|
undo: () => {
|
|
576
|
-
const g =
|
|
577
|
-
v && (g.future.push(
|
|
576
|
+
const g = w.current, v = g.past.pop();
|
|
577
|
+
v && (g.future.push(A.current), j(v));
|
|
578
578
|
},
|
|
579
579
|
redo: () => {
|
|
580
|
-
const g =
|
|
581
|
-
v && (g.past.push(
|
|
580
|
+
const g = w.current, v = g.future.pop();
|
|
581
|
+
v && (g.past.push(A.current), j(v));
|
|
582
582
|
},
|
|
583
|
-
canUndo:
|
|
584
|
-
canRedo:
|
|
583
|
+
canUndo: w.current.past.length > 0,
|
|
584
|
+
canRedo: w.current.future.length > 0
|
|
585
585
|
};
|
|
586
586
|
}
|
|
587
|
-
const
|
|
588
|
-
function
|
|
587
|
+
const $t = 900, Rt = 3, wt = typeof window > "u" ? Ae : Xe, ue = (e) => e ? "" : void 0;
|
|
588
|
+
function Ct({
|
|
589
589
|
onMergeChange: e,
|
|
590
590
|
editable: t = !1,
|
|
591
591
|
labels: r,
|
|
592
592
|
layout: s = "responsive",
|
|
593
|
-
stackBelow: n =
|
|
593
|
+
stackBelow: n = $t,
|
|
594
594
|
collapseUnchanged: o = !1,
|
|
595
595
|
...c
|
|
596
596
|
}) {
|
|
597
|
-
const i =
|
|
598
|
-
() =>
|
|
599
|
-
[u,
|
|
600
|
-
),
|
|
597
|
+
const i = I(() => ot(r), [r]), h = St(c), { tree: u, selection: f, merged: R, status: b, isResolved: T } = h, S = I(
|
|
598
|
+
() => gt(u, f),
|
|
599
|
+
[u, f]
|
|
600
|
+
), w = I(() => {
|
|
601
601
|
const l = /* @__PURE__ */ new Map();
|
|
602
|
-
for (const
|
|
603
|
-
l.set(
|
|
602
|
+
for (const d of S.blocks)
|
|
603
|
+
l.set(d.id, d);
|
|
604
604
|
return l;
|
|
605
|
-
}, [
|
|
606
|
-
k.current = e,
|
|
607
|
-
k.current?.(
|
|
608
|
-
}, [
|
|
609
|
-
const [a,
|
|
610
|
-
|
|
605
|
+
}, [S]), k = ee(e);
|
|
606
|
+
k.current = e, Ae(() => {
|
|
607
|
+
k.current?.(R, b);
|
|
608
|
+
}, [R, b]);
|
|
609
|
+
const [a, $] = K(null), [m, N] = K(null), [A, U] = K(!1);
|
|
610
|
+
wt(() => {
|
|
611
611
|
if (s !== "responsive" || !m || typeof ResizeObserver > "u")
|
|
612
612
|
return;
|
|
613
|
-
const l = new ResizeObserver(([
|
|
614
|
-
U(
|
|
613
|
+
const l = new ResizeObserver(([d]) => {
|
|
614
|
+
U(d.contentRect.width < n);
|
|
615
615
|
});
|
|
616
616
|
return l.observe(m), () => l.disconnect();
|
|
617
617
|
}, [s, m, n]);
|
|
618
|
-
const j = s === "vertical" || s === "responsive" &&
|
|
618
|
+
const j = s === "vertical" || s === "responsive" && A, L = j ? "stacked" : "horizontal", E = typeof o == "number" ? o : Rt, [D, Y] = K(o !== !1), [g, v] = K(
|
|
619
619
|
() => /* @__PURE__ */ new Set()
|
|
620
|
-
),
|
|
621
|
-
() =>
|
|
622
|
-
[
|
|
623
|
-
),
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
620
|
+
), M = I(
|
|
621
|
+
() => D ? $e(S.rows, E, g) : S.rows.map((l) => ({ type: "row", row: l })),
|
|
622
|
+
[D, S, E, g]
|
|
623
|
+
), z = (l) => l.filter((d) => d.type === "fold").length, P = I(
|
|
624
|
+
() => D && z(M) === z($e(S.rows, E, /* @__PURE__ */ new Set())),
|
|
625
|
+
[D, M, S, E]
|
|
626
|
+
), Ke = () => {
|
|
627
|
+
v(/* @__PURE__ */ new Set()), Y(!P);
|
|
628
|
+
}, De = (l) => {
|
|
629
|
+
v((d) => new Set(d).add(l));
|
|
630
|
+
}, [G, oe] = K(null), [fe, re] = K(null), V = I(() => u.conflicts.map((l) => l.id), [u]), Pe = (l) => {
|
|
631
|
+
const d = Array.from(
|
|
627
632
|
a?.querySelectorAll("[data-merge-block]") ?? []
|
|
628
|
-
).filter((C) => C.dataset.mergeBlock === l), p =
|
|
633
|
+
).filter((C) => C.dataset.mergeBlock === l), p = d.find((C) => getComputedStyle(C).display !== "none") ?? d[0], O = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? !1;
|
|
629
634
|
p?.scrollIntoView?.({
|
|
630
635
|
block: "center",
|
|
631
|
-
behavior:
|
|
636
|
+
behavior: O ? "auto" : "smooth"
|
|
632
637
|
});
|
|
633
|
-
},
|
|
634
|
-
|
|
635
|
-
},
|
|
638
|
+
}, he = (l) => {
|
|
639
|
+
oe(l), Pe(l);
|
|
640
|
+
}, ge = (l, d) => {
|
|
636
641
|
if (l.length === 0)
|
|
637
642
|
return null;
|
|
638
|
-
const p =
|
|
639
|
-
if (
|
|
643
|
+
const p = G === null ? -1 : V.indexOf(G);
|
|
644
|
+
if (d === "next")
|
|
640
645
|
return l.find((C) => V.indexOf(C) > p) ?? l[0];
|
|
641
|
-
const
|
|
642
|
-
return [...l].reverse().find((C) => V.indexOf(C) <
|
|
643
|
-
},
|
|
644
|
-
const l =
|
|
645
|
-
V.filter((
|
|
646
|
+
const O = p === -1 ? V.length : p;
|
|
647
|
+
return [...l].reverse().find((C) => V.indexOf(C) < O) ?? l[l.length - 1];
|
|
648
|
+
}, _e = () => {
|
|
649
|
+
const l = ge(
|
|
650
|
+
V.filter((d) => !T(d)),
|
|
646
651
|
"next"
|
|
647
652
|
);
|
|
648
|
-
return l === null ? !1 : (
|
|
649
|
-
},
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
},
|
|
653
|
-
h.choose(l,
|
|
654
|
-
}, ge = (l) => {
|
|
655
|
-
const f = R.get(l);
|
|
656
|
-
if (!f)
|
|
657
|
-
return "null";
|
|
658
|
-
const p = Z(f.entry, d[l]), $ = p.present ? p.value : f.entry.hasRight ? f.entry.right : f.entry.left;
|
|
659
|
-
return JSON.stringify($, null, 2) ?? "null";
|
|
653
|
+
return l === null ? !1 : (he(l), !0);
|
|
654
|
+
}, ze = (l) => {
|
|
655
|
+
const d = ge(V, l);
|
|
656
|
+
d !== null && he(d);
|
|
657
|
+
}, X = (l, d) => {
|
|
658
|
+
h.choose(l, d), oe(l);
|
|
660
659
|
}, pe = (l) => {
|
|
661
|
-
|
|
662
|
-
|
|
660
|
+
const d = w.get(l);
|
|
661
|
+
if (!d)
|
|
662
|
+
return "null";
|
|
663
|
+
const p = Z(d.entry, f[l]), O = p.present ? p.value : d.entry.hasRight ? d.entry.right : d.entry.left;
|
|
664
|
+
return JSON.stringify(O, null, 2) ?? "null";
|
|
665
|
+
}, ye = (l) => {
|
|
666
|
+
oe(l), re(l);
|
|
667
|
+
}, Fe = () => re(null), Ue = (l, d) => {
|
|
663
668
|
let p;
|
|
664
669
|
try {
|
|
665
|
-
p = JSON.parse(
|
|
666
|
-
} catch (
|
|
667
|
-
return
|
|
670
|
+
p = JSON.parse(d);
|
|
671
|
+
} catch (O) {
|
|
672
|
+
return O instanceof Error ? O.message : "Invalid JSON";
|
|
668
673
|
}
|
|
669
|
-
return
|
|
670
|
-
},
|
|
671
|
-
const y =
|
|
674
|
+
return X(l, { custom: p }), re(null), null;
|
|
675
|
+
}, se = (l, d, p, O, C) => {
|
|
676
|
+
const y = d.blockId ? w.get(d.blockId) : void 0, ce = !!y && d.blockRow === 0, Ve = !!y && d.blockRow === d.blockSize - 1, Q = y ? T(y.id) : !0, x = y?.entry, qe = l === "current" ? y?.selection === "left" : l === "incoming" ? y?.selection === "right" : !0;
|
|
672
677
|
let q = "unchanged";
|
|
673
|
-
y && (p === null ? q = "filler" : l === "result" && !
|
|
678
|
+
y && (p === null ? q = "filler" : l === "result" && !Q ? q = "pending" : l === "result" && y.selection === "custom" ? q = "edited" : Q && !qe ? q = "rejected" : q = "changed");
|
|
674
679
|
const J = {};
|
|
675
|
-
if (y && x &&
|
|
676
|
-
const
|
|
680
|
+
if (y && x && ce) {
|
|
681
|
+
const ke = () => ({
|
|
677
682
|
label: i.removeChange(x.label),
|
|
678
|
-
pressed:
|
|
679
|
-
run: () =>
|
|
680
|
-
}),
|
|
681
|
-
label:
|
|
682
|
-
pressed:
|
|
683
|
-
run: () =>
|
|
683
|
+
pressed: Q && y.selection === "deleted",
|
|
684
|
+
run: () => X(y.id, "deleted")
|
|
685
|
+
}), Oe = (Se, We) => ({
|
|
686
|
+
label: We,
|
|
687
|
+
pressed: Q && y.selection === Se,
|
|
688
|
+
run: () => X(y.id, Se)
|
|
684
689
|
});
|
|
685
|
-
l === "current" && x.hasLeft ? (J.remove =
|
|
690
|
+
l === "current" && x.hasLeft ? (J.remove = ke(), J.accept = Oe("left", i.acceptCurrent(x.label))) : l === "incoming" && x.hasRight ? (J.accept = Oe("right", i.acceptIncoming(x.label)), J.remove = ke()) : l === "result" && t && (y.selection === "custom" && (J.revert = {
|
|
686
691
|
label: i.revertEdit(x.label),
|
|
687
692
|
pressed: !1,
|
|
688
693
|
run: () => h.revert(y.id)
|
|
689
694
|
}), J.edit = {
|
|
690
695
|
label: i.editChange(x.label),
|
|
691
696
|
pressed: !1,
|
|
692
|
-
run: () =>
|
|
697
|
+
run: () => ye(y.id)
|
|
693
698
|
});
|
|
694
699
|
}
|
|
695
|
-
const
|
|
700
|
+
const He = l === "result" && t && ce && y !== void 0 && fe === y.id;
|
|
696
701
|
return {
|
|
697
702
|
pane: l,
|
|
698
703
|
text: p,
|
|
699
|
-
segments: p === null ? [] :
|
|
704
|
+
segments: p === null ? [] : tt(
|
|
700
705
|
p,
|
|
701
706
|
l !== "result" && y?.kind === "modified" ? C : void 0
|
|
702
707
|
),
|
|
703
|
-
lineNo:
|
|
708
|
+
lineNo: O,
|
|
704
709
|
state: q,
|
|
705
710
|
kind: y?.kind ?? null,
|
|
706
711
|
blockId: y?.id ?? null,
|
|
707
|
-
blockStart:
|
|
708
|
-
blockEnd:
|
|
709
|
-
active: !!y &&
|
|
712
|
+
blockStart: ce,
|
|
713
|
+
blockEnd: Ve,
|
|
714
|
+
active: !!y && G === y?.id,
|
|
710
715
|
actions: J,
|
|
711
|
-
editor:
|
|
716
|
+
editor: He && y && x ? {
|
|
712
717
|
title: i.editorTitle(x.label),
|
|
713
718
|
inputLabel: i.editorInput(x.label),
|
|
714
|
-
initialText:
|
|
719
|
+
initialText: pe(y.id)
|
|
715
720
|
} : void 0
|
|
716
721
|
};
|
|
717
|
-
},
|
|
722
|
+
}, me = M.map((l, d) => {
|
|
718
723
|
if (l.type === "fold")
|
|
719
724
|
return {
|
|
720
725
|
type: "fold",
|
|
721
726
|
key: `fold-${l.key}`,
|
|
722
|
-
index:
|
|
727
|
+
index: d,
|
|
723
728
|
hidden: l.hidden,
|
|
724
729
|
label: i.unchangedLines(l.hidden),
|
|
725
730
|
showLabel: i.showUnchanged(l.hidden),
|
|
726
|
-
expand: () =>
|
|
731
|
+
expand: () => De(l.key)
|
|
727
732
|
};
|
|
728
733
|
const { row: p } = l;
|
|
729
734
|
return {
|
|
730
735
|
type: "row",
|
|
731
736
|
key: `row-${p.index}`,
|
|
732
|
-
index:
|
|
737
|
+
index: d,
|
|
733
738
|
row: p,
|
|
734
|
-
current:
|
|
735
|
-
result:
|
|
736
|
-
incoming:
|
|
739
|
+
current: se("current", p, p.left, p.leftNo, p.right),
|
|
740
|
+
result: se("result", p, p.result, p.resultNo, null),
|
|
741
|
+
incoming: se("incoming", p, p.right, p.rightNo, p.left)
|
|
737
742
|
};
|
|
738
|
-
}),
|
|
739
|
-
const
|
|
740
|
-
if (!(l.ctrlKey || l.metaKey) ||
|
|
743
|
+
}), ve = b.total, be = ve === 0 ? "empty" : b.allResolved ? "resolved" : "pending", Je = ve === 0 ? i.noChanges : b.allResolved ? i.allResolved(b) : i.unresolved(b), Be = (l) => {
|
|
744
|
+
const d = l.target;
|
|
745
|
+
if (!(l.ctrlKey || l.metaKey) || d.closest("textarea, input"))
|
|
741
746
|
return;
|
|
742
747
|
const p = l.key.toLowerCase();
|
|
743
748
|
p === "z" && !l.shiftKey ? (l.preventDefault(), h.undo()) : (p === "z" && l.shiftKey || p === "y") && (l.preventDefault(), h.redo());
|
|
744
|
-
},
|
|
749
|
+
}, le = me.length;
|
|
745
750
|
return {
|
|
746
751
|
...h,
|
|
747
|
-
choose:
|
|
748
|
-
items:
|
|
752
|
+
choose: X,
|
|
753
|
+
items: me,
|
|
749
754
|
labels: i,
|
|
750
755
|
stacked: j,
|
|
751
|
-
statusState:
|
|
752
|
-
statusText:
|
|
756
|
+
statusState: be,
|
|
757
|
+
statusText: Je,
|
|
753
758
|
collapsed: P,
|
|
754
|
-
toggleCollapsed:
|
|
755
|
-
activeId:
|
|
756
|
-
goToChange:
|
|
757
|
-
goToNextUnresolved:
|
|
759
|
+
toggleCollapsed: Ke,
|
|
760
|
+
activeId: G,
|
|
761
|
+
goToChange: ze,
|
|
762
|
+
goToNextUnresolved: _e,
|
|
758
763
|
editable: t,
|
|
759
|
-
editingId:
|
|
760
|
-
startEdit:
|
|
761
|
-
cancelEdit:
|
|
762
|
-
editorText:
|
|
763
|
-
commitEdit:
|
|
764
|
+
editingId: fe,
|
|
765
|
+
startEdit: ye,
|
|
766
|
+
cancelEdit: Fe,
|
|
767
|
+
editorText: pe,
|
|
768
|
+
commitEdit: Ue,
|
|
764
769
|
getRootProps: () => ({
|
|
765
|
-
ref:
|
|
766
|
-
onKeyDown:
|
|
767
|
-
"data-merge-status":
|
|
770
|
+
ref: $,
|
|
771
|
+
onKeyDown: Be,
|
|
772
|
+
"data-merge-status": be
|
|
768
773
|
}),
|
|
769
774
|
getScrollProps: () => ({ ref: N }),
|
|
770
775
|
getGridProps: () => ({
|
|
771
776
|
style: {
|
|
772
777
|
display: "grid",
|
|
773
|
-
gridTemplateColumns:
|
|
778
|
+
gridTemplateColumns: kt(L)
|
|
774
779
|
},
|
|
775
|
-
"data-layout":
|
|
780
|
+
"data-layout": L
|
|
776
781
|
}),
|
|
777
782
|
getHeaderProps: (l) => ({
|
|
778
|
-
style: { ...
|
|
783
|
+
style: { ...ie(L, l, "header", 0, le) },
|
|
779
784
|
"data-pane": l,
|
|
780
785
|
"data-column": "header"
|
|
781
786
|
}),
|
|
782
|
-
getCellProps: (l,
|
|
783
|
-
const
|
|
784
|
-
...
|
|
787
|
+
getCellProps: (l, d, p) => {
|
|
788
|
+
const O = l[d], C = {
|
|
789
|
+
...ie(L, d, p, l.index, le)
|
|
785
790
|
};
|
|
786
|
-
return j &&
|
|
791
|
+
return j && O.state === "filler" && (C.display = "none"), {
|
|
787
792
|
style: C,
|
|
788
|
-
"data-pane":
|
|
793
|
+
"data-pane": d,
|
|
789
794
|
"data-column": p,
|
|
790
|
-
"data-state":
|
|
791
|
-
"data-kind":
|
|
792
|
-
"data-block-start":
|
|
793
|
-
"data-block-end":
|
|
794
|
-
"data-active":
|
|
795
|
-
"data-merge-block": p === "code" &&
|
|
795
|
+
"data-state": O.state,
|
|
796
|
+
"data-kind": O.kind ?? void 0,
|
|
797
|
+
"data-block-start": ue(O.blockStart),
|
|
798
|
+
"data-block-end": ue(O.blockEnd),
|
|
799
|
+
"data-active": ue(O.active),
|
|
800
|
+
"data-merge-block": p === "code" && O.blockStart ? O.blockId ?? void 0 : void 0
|
|
796
801
|
};
|
|
797
802
|
},
|
|
798
|
-
getFoldProps: (l,
|
|
803
|
+
getFoldProps: (l, d) => ({
|
|
799
804
|
type: "button",
|
|
800
|
-
style: { ...
|
|
805
|
+
style: { ...ie(L, d, "fold", l.index, le) },
|
|
801
806
|
// Only one of the three panes needs to be reachable and announced.
|
|
802
|
-
tabIndex:
|
|
803
|
-
"aria-hidden":
|
|
807
|
+
tabIndex: d === "current" ? 0 : -1,
|
|
808
|
+
"aria-hidden": d === "current" ? void 0 : !0,
|
|
804
809
|
"aria-label": l.showLabel,
|
|
805
|
-
"data-pane":
|
|
810
|
+
"data-pane": d,
|
|
806
811
|
"data-column": "fold",
|
|
807
812
|
onClick: l.expand
|
|
808
813
|
})
|
|
809
814
|
};
|
|
810
815
|
}
|
|
811
816
|
export {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
817
|
+
It as MergeViewerProvider,
|
|
818
|
+
gt as buildMergeLayout,
|
|
819
|
+
at as buildMergeTree,
|
|
820
|
+
Te as buildMergedJson,
|
|
821
|
+
_ as deepEqual,
|
|
822
|
+
nt as defaultLabels,
|
|
823
|
+
$e as foldRows,
|
|
824
|
+
ft as getMergeStatus,
|
|
825
|
+
kt as gridTemplateColumns,
|
|
826
|
+
ht as initialSelection,
|
|
827
|
+
tt as inlineSegments,
|
|
828
|
+
Le as isCustomChoice,
|
|
829
|
+
ie as placeCell,
|
|
830
|
+
ot as resolveLabels,
|
|
831
|
+
te as selectAll,
|
|
832
|
+
et as splitInlineEdit,
|
|
833
|
+
St as useMergeConflicts,
|
|
834
|
+
Ct as useMergeViewer,
|
|
835
|
+
Lt as useMergeViewerContext
|
|
831
836
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -243,8 +243,15 @@ export declare interface MergeViewer extends MergeConflictsState {
|
|
|
243
243
|
statusState: MergeViewerStatusState;
|
|
244
244
|
/** The banner text matching `statusState`. */
|
|
245
245
|
statusText: string;
|
|
246
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* Whether long runs of unchanged lines are folded. `false` as soon as one
|
|
248
|
+
* of them was opened by hand, so a "hide" button reads as not pressed.
|
|
249
|
+
*/
|
|
247
250
|
collapsed: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Hides every unchanged run when some are showing (including ones opened by
|
|
253
|
+
* hand), otherwise switches folding off again.
|
|
254
|
+
*/
|
|
248
255
|
toggleCollapsed: () => void;
|
|
249
256
|
activeId: string | null;
|
|
250
257
|
/** Scrolls to the next or previous change and marks it active. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ht-rnd/merge-conflict-viewer",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Headless merge conflict viewer for JSON (React hooks and merge model), with a shadcn/ui registry component",
|
|
7
7
|
"author": "ht-rnd",
|