jQuery-Merge-for-php-diff icon indicating copy to clipboard operation
jQuery-Merge-for-php-diff copied to clipboard

V2

Open Xiphe opened this issue 5 years ago • 1 comments

Here's what I'm thinking a V2 of this project should look like

  • no jQuery instead vanilla JS (maybe optional wrapper)
  • typescript
  • support new features of https://github.com/JBlond/php-diff
  • change API to not require full files but instead resolve in a unified diff applyable by https://www.php.net/manual/en/function.xdiff-string-patch.php
  • test coverage https://github.com/Xiphe/jQuery-Merge-for-php-diff/issues/5
  • support multiple diff instances on same page https://github.com/Xiphe/jQuery-Merge-for-php-diff/issues/8
  • maybe even support custom editing

Here's how I think it should work:

const merge = new PhPDiffMerge({
  diff: document.getElementById('diff1'),
});

console.log(merge.allSolved);
/* false */
console.log(merge.differences);
/* 
[{
  left: { startLine: 1, endLine: 4 },
  right: { startLine: 1, endLine: 7 },
  resolved: false
}] 
*/

merge.onChange((difference) => {
  console.log(merge.allSolved);
  /* true */
  console.log(difference);
  /* 
  {
    left: { startLine: 1, endLine: 4 },
    right: { startLine: 1, endLine: 7 },
    resolved: true
  }
  */
});

function onResolveClick() {
  if (!merge.allSolved) {
    throw new Error('please resolve all differences first');
  }

  myPhpBackend.POST('/resolved', { patch: merge.getPatch() }).then(() => console.log('YAY'));
}

Xiphe avatar Oct 13 '20 12:10 Xiphe

I'm not sure about xdiff. It is a PECL extension and not always available.

JBlond avatar Feb 28 '22 11:02 JBlond