feat: save conflict resolution
This commit is contained in:
parent
bacbe4f543
commit
4b0e3d1c43
@ -105,7 +105,7 @@
|
||||
v-icon(left) mdi-code-tags
|
||||
span Source
|
||||
v-divider.mx-2(vertical)
|
||||
v-btn(color='primary', text, :href='`/h/` + page.locale + `/` + page.path', disabled)
|
||||
v-btn(color='primary', text, :href='`/h/` + page.locale + `/` + page.path')
|
||||
v-icon(left) mdi-history
|
||||
span History
|
||||
v-spacer
|
||||
|
@ -147,7 +147,7 @@
|
||||
v-tooltip(bottom)
|
||||
template(v-slot:activator='{ on }')
|
||||
v-btn(icon, tile, height='64', v-on='on', @click='pageNew')
|
||||
v-icon(color='grey') mdi-file-document-box-plus-outline
|
||||
v-icon(color='grey') mdi-text-box-plus-outline
|
||||
span {{$t('common:header.newPage')}}
|
||||
v-divider(vertical)
|
||||
|
||||
@ -172,18 +172,18 @@
|
||||
v-list-item-content
|
||||
v-list-item-title {{name}}
|
||||
v-list-item-subtitle {{email}}
|
||||
v-list-item(href='/w', disabled)
|
||||
v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
|
||||
v-list-item-content
|
||||
v-list-item-title {{$t('common:header.myWiki')}}
|
||||
v-list-item-subtitle.overline Coming soon
|
||||
v-list-item(href='/p', disabled)
|
||||
v-list-item-action: v-icon(color='blue') mdi-face-profile
|
||||
v-list-item-content
|
||||
v-list-item-title {{$t('common:header.profile')}}
|
||||
v-list-item-subtitle.overline Coming soon
|
||||
//- v-list-item(href='/w', disabled)
|
||||
//- v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
|
||||
//- v-list-item-content
|
||||
//- v-list-item-title {{$t('common:header.myWiki')}}
|
||||
//- v-list-item-subtitle.overline Coming soon
|
||||
//- v-list-item(href='/p', disabled)
|
||||
//- v-list-item-action: v-icon(color='blue') mdi-face-profile
|
||||
//- v-list-item-content
|
||||
//- v-list-item-title {{$t('common:header.profile')}}
|
||||
//- v-list-item-subtitle.overline Coming soon
|
||||
v-list-item(href='/a', v-if='isAuthenticated && isAdmin')
|
||||
v-list-item-action.btn-animate-rotate: v-icon(:color='$vuetify.theme.dark ? `blue-grey lighten-3` : `blue-grey`') mdi-settings
|
||||
v-list-item-action.btn-animate-rotate: v-icon(:color='$vuetify.theme.dark ? `blue-grey lighten-3` : `blue-grey`') mdi-cog
|
||||
v-list-item-title(:class='$vuetify.theme.dark ? `blue-grey--text text--lighten-3` : `blue-grey--text`') {{$t('common:header.admin')}}
|
||||
v-list-item(@click='logout')
|
||||
v-list-item-action: v-icon(color='red') mdi-logout
|
||||
|
@ -13,7 +13,7 @@
|
||||
full-width
|
||||
)
|
||||
template(slot='actions')
|
||||
v-btn.mr-3.animated.fadeIn(color='amber', outlined, small, v-if='isConflict')
|
||||
v-btn.mr-3.animated.fadeIn(color='amber', outlined, small, v-if='isConflict', @click='openConflict')
|
||||
.overline.amber--text.mr-3 Conflict
|
||||
status-indicator(intermediary, pulse)
|
||||
v-btn.animated.fadeInDown(
|
||||
@ -22,10 +22,9 @@
|
||||
@click='save'
|
||||
@click.ctrl.exact='saveAndClose'
|
||||
:class='{ "is-icon": $vuetify.breakpoint.mdAndDown }'
|
||||
:disabled='!isDirty'
|
||||
)
|
||||
v-icon(color='green', :left='$vuetify.breakpoint.lgAndUp') mdi-check
|
||||
span(v-if='$vuetify.breakpoint.lgAndUp && mode !== `create` && !isDirty') {{ $t('editor:save.saved') }}
|
||||
span.grey--text(v-if='$vuetify.breakpoint.lgAndUp && mode !== `create` && !isDirty') {{ $t('editor:save.saved') }}
|
||||
span.white--text(v-else-if='$vuetify.breakpoint.lgAndUp') {{ mode === 'create' ? $t('common:actions.create') : $t('common:actions.save') }}
|
||||
v-btn.animated.fadeInDown.wait-p1s(
|
||||
text
|
||||
@ -86,7 +85,8 @@ export default {
|
||||
editorModalProperties: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-properties.vue'),
|
||||
editorModalUnsaved: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-unsaved.vue'),
|
||||
editorModalMedia: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-media.vue'),
|
||||
editorModalBlocks: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-blocks.vue')
|
||||
editorModalBlocks: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-blocks.vue'),
|
||||
editorModalConflict: () => import(/* webpackChunkName: "editor-conflict", webpackMode: "lazy" */ './editor/editor-modal-conflict.vue')
|
||||
},
|
||||
props: {
|
||||
locale: {
|
||||
@ -136,6 +136,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isSaving: false,
|
||||
isConflict: false,
|
||||
dialogProps: false,
|
||||
dialogProgress: false,
|
||||
@ -152,6 +153,7 @@ export default {
|
||||
mode: get('editor/mode'),
|
||||
welcomeMode() { return this.mode === `create` && this.path === `home` },
|
||||
currentPageTitle: sync('page/title'),
|
||||
checkoutDateActive: sync('editor/checkoutDateActive'),
|
||||
isDirty () {
|
||||
return _.some([
|
||||
this.initContentParsed !== this.$store.get('editor/content'),
|
||||
@ -183,6 +185,8 @@ export default {
|
||||
this.$store.commit('page/SET_TITLE', this.title)
|
||||
|
||||
this.$store.commit('page/SET_MODE', 'edit')
|
||||
|
||||
this.checkoutDateActive = this.checkoutDate
|
||||
},
|
||||
mounted() {
|
||||
this.$store.set('editor/mode', this.initMode || 'create')
|
||||
@ -205,6 +209,10 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
this.$root.$on('resetEditorConflict', () => {
|
||||
this.isConflict = false
|
||||
})
|
||||
|
||||
// this.$store.set('editor/mode', 'edit')
|
||||
// this.currentEditor = `editorApi`
|
||||
},
|
||||
@ -218,8 +226,12 @@ export default {
|
||||
hideProgressDialog() {
|
||||
this.dialogProgress = false
|
||||
},
|
||||
async save() {
|
||||
openConflict() {
|
||||
this.$root.$emit('saveConflict')
|
||||
},
|
||||
async save({ rethrow = false, overwrite = false } = {}) {
|
||||
this.showProgressDialog('saving')
|
||||
this.isSaving = true
|
||||
try {
|
||||
if (this.$store.get('editor/mode') === 'create') {
|
||||
// --------------------------------------------
|
||||
@ -244,6 +256,8 @@ export default {
|
||||
})
|
||||
resp = _.get(resp, 'data.pages.create', {})
|
||||
if (_.get(resp, 'responseResult.succeeded')) {
|
||||
this.checkoutDateActive = _.get(resp, 'page.updatedAt', this.checkoutDateActive)
|
||||
this.isConflict = false
|
||||
this.$store.commit('showNotification', {
|
||||
message: this.$t('editor:save.createSuccess'),
|
||||
style: 'success',
|
||||
@ -261,6 +275,25 @@ export default {
|
||||
// -> UPDATE EXISTING PAGE
|
||||
// --------------------------------------------
|
||||
|
||||
const conflictResp = await this.$apollo.query({
|
||||
query: gql`
|
||||
query ($id: Int!, $checkoutDate: Date!) {
|
||||
pages {
|
||||
checkConflicts(id: $id, checkoutDate: $checkoutDate)
|
||||
}
|
||||
}
|
||||
`,
|
||||
fetchPolicy: 'network-only',
|
||||
variables: {
|
||||
id: this.pageId,
|
||||
checkoutDate: this.checkoutDateActive
|
||||
}
|
||||
})
|
||||
if (_.get(conflictResp, 'data.pages.checkConflicts', false)) {
|
||||
this.$root.$emit('saveConflict')
|
||||
throw new Error('Save conflict! Another user has already modified this page.')
|
||||
}
|
||||
|
||||
let resp = await this.$apollo.mutate({
|
||||
mutation: updatePageMutation,
|
||||
variables: {
|
||||
@ -280,6 +313,8 @@ export default {
|
||||
})
|
||||
resp = _.get(resp, 'data.pages.update', {})
|
||||
if (_.get(resp, 'responseResult.succeeded')) {
|
||||
this.checkoutDateActive = _.get(resp, 'page.updatedAt', this.checkoutDateActive)
|
||||
this.isConflict = false
|
||||
this.$store.commit('showNotification', {
|
||||
message: this.$t('editor:save.updateSuccess'),
|
||||
style: 'success',
|
||||
@ -302,13 +337,16 @@ export default {
|
||||
style: 'error',
|
||||
icon: 'warning'
|
||||
})
|
||||
if (rethrow === true) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
this.isSaving = false
|
||||
this.hideProgressDialog()
|
||||
},
|
||||
async saveAndClose() {
|
||||
try {
|
||||
await this.save()
|
||||
await this.save({ rethrow: true })
|
||||
await this.exit()
|
||||
} catch (err) {
|
||||
// Error is already handled
|
||||
@ -348,12 +386,12 @@ export default {
|
||||
variables () {
|
||||
return {
|
||||
id: this.pageId,
|
||||
checkoutDate: this.checkoutDate
|
||||
checkoutDate: this.checkoutDateActive
|
||||
}
|
||||
},
|
||||
update: (data) => _.cloneDeep(data.pages.checkConflicts),
|
||||
skip () {
|
||||
return this.mode === 'create' || !this.isDirty
|
||||
return this.mode === 'create' || this.isSaving || !this.isDirty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -633,6 +633,14 @@ export default {
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
// Handle save conflict
|
||||
this.$root.$on('saveConflict', () => {
|
||||
this.toggleModal(`editorModalConflict`)
|
||||
})
|
||||
this.$root.$on('overwriteEditorContent', () => {
|
||||
this.cm.setValue(this.$store.get('editor/content'))
|
||||
})
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.$root.$off('editorInsert')
|
||||
|
216
client/components/editor/editor-modal-conflict.vue
Normal file
216
client/components/editor/editor-modal-conflict.vue
Normal file
@ -0,0 +1,216 @@
|
||||
<template lang='pug'>
|
||||
v-card.editor-modal-conflict.animated.fadeIn(flat, tile)
|
||||
.pa-4
|
||||
v-toolbar.radius-7(flat, color='indigo', style='border-bottom-left-radius: 0; border-bottom-right-radius: 0;', dark)
|
||||
v-icon.mr-3 mdi-merge
|
||||
.subtitle-1 Resolve Save Conflict
|
||||
v-spacer
|
||||
v-btn(outlined, color='white', @click='useLocal', title='Use content in the left panel')
|
||||
v-icon(left) mdi-alpha-l-box
|
||||
span Use Local
|
||||
v-dialog(
|
||||
v-model='isRemoteConfirmDiagShown'
|
||||
width='500'
|
||||
)
|
||||
template(v-slot:activator='{ on }')
|
||||
v-btn.ml-3(outlined, color='white', v-on='on', title='Discard local changes and use latest version')
|
||||
v-icon(left) mdi-alpha-r-box
|
||||
span Use Remote
|
||||
v-card
|
||||
.dialog-header.is-short.is-indigo
|
||||
v-icon.mr-3(color='white') mdi-alpha-r-box
|
||||
span Overwrite with Remote Version?
|
||||
v-card-text.pa-4
|
||||
.body-2 Are you sure you want to replace your current version with the latest remote content? #[strong Your current edits will be lost.]
|
||||
v-card-chin
|
||||
v-spacer
|
||||
v-btn(outlined, color='indigo', @click='isRemoteConfirmDiagShown = false')
|
||||
v-icon(left) mdi-close
|
||||
span Cancel
|
||||
v-btn(@click='useRemote', color='indigo', dark)
|
||||
v-icon(left) mdi-check
|
||||
span Confirm
|
||||
v-divider.mx-3(vertical)
|
||||
v-btn(outlined, color='indigo lighten-4', @click='close')
|
||||
v-icon(left) mdi-close
|
||||
span Cancel
|
||||
v-row.indigo.darken-1.body-2(no-gutters)
|
||||
v-col.pa-4
|
||||
v-icon.mr-3(color='white') mdi-alpha-l-box
|
||||
span.white--text Local Version #[em.indigo--text.text--lighten-4 (editable)]
|
||||
v-divider(vertical)
|
||||
v-col.pa-4
|
||||
v-icon.mr-3(color='white') mdi-alpha-r-box
|
||||
span.white--text Remote Version #[em.indigo--text.text--lighten-4 (read-only)]
|
||||
v-row.grey.lighten-2.body-2(no-gutters)
|
||||
v-col.px-4.py-2
|
||||
em.grey--text.text--darken-2 Your current edit, based on page version from #[span(:title='$options.filters.moment(checkoutDateActive, `LLL`)') {{ checkoutDateActive | moment('from') }}]
|
||||
v-divider(vertical)
|
||||
v-col.px-4.py-2
|
||||
em.grey--text.text--darken-2 Last edited by #[strong {{latest.authorName}}], #[span(:title='$options.filters.moment(latest.updatedAt, `LLL`)') {{ latest.updatedAt | moment('from') }}]
|
||||
v-row.grey.lighten-3.grey--text.text--darken-3(no-gutters)
|
||||
v-col.pa-4
|
||||
.body-2
|
||||
strong.indigo--text Title:
|
||||
strong.pl-2 {{title}}
|
||||
.caption
|
||||
strong.indigo--text Description:
|
||||
span.pl-2 {{description}}
|
||||
v-divider(vertical, light)
|
||||
v-col.pa-4
|
||||
.body-2
|
||||
strong.indigo--text Title:
|
||||
strong.pl-2 {{latest.title}}
|
||||
.caption
|
||||
strong.indigo--text Description:
|
||||
span.pl-2 {{latest.description}}
|
||||
v-card.radius-7(:light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark')
|
||||
div(ref='cm')
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import _ from 'lodash'
|
||||
import gql from 'graphql-tag'
|
||||
import { sync, get } from 'vuex-pathify'
|
||||
|
||||
/* global siteConfig */
|
||||
|
||||
// ========================================
|
||||
// IMPORTS
|
||||
// ========================================
|
||||
|
||||
import '../../libs/codemirror-merge/diff-match-patch.js'
|
||||
|
||||
// Code Mirror
|
||||
import CodeMirror from 'codemirror'
|
||||
import 'codemirror/lib/codemirror.css'
|
||||
|
||||
// Language
|
||||
import 'codemirror/mode/markdown/markdown.js'
|
||||
import 'codemirror/mode/htmlmixed/htmlmixed.js'
|
||||
|
||||
// Addons
|
||||
import 'codemirror/addon/selection/active-line.js'
|
||||
import 'codemirror/addon/merge/merge.js'
|
||||
import 'codemirror/addon/merge/merge.css'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
cm: null,
|
||||
latest: {
|
||||
title: '',
|
||||
description: '',
|
||||
updatedAt: '',
|
||||
authorName: ''
|
||||
},
|
||||
isRemoteConfirmDiagShown: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
editorKey: get('editor/editorKey'),
|
||||
activeModal: sync('editor/activeModal'),
|
||||
pageId: get('page/id'),
|
||||
title: get('page/title'),
|
||||
description: get('page/description'),
|
||||
updatedAt: get('page/updatedAt'),
|
||||
checkoutDateActive: sync('editor/checkoutDateActive')
|
||||
},
|
||||
methods: {
|
||||
close () {
|
||||
this.isRemoteConfirmDiagShown = false
|
||||
this.activeModal = ''
|
||||
},
|
||||
overwriteAndClose() {
|
||||
this.checkoutDateActive = this.latest.updatedAt
|
||||
this.$root.$emit('overwriteEditorContent')
|
||||
this.$root.$emit('resetEditorConflict')
|
||||
this.close()
|
||||
},
|
||||
useLocal () {
|
||||
this.$store.set('editor/content', this.cm.edit.getValue())
|
||||
this.overwriteAndClose()
|
||||
},
|
||||
useRemote () {
|
||||
this.$store.set('editor/content', this.latest.content)
|
||||
this.overwriteAndClose()
|
||||
}
|
||||
},
|
||||
async mounted () {
|
||||
let textMode = 'text/html'
|
||||
|
||||
switch (this.editorKey) {
|
||||
case 'markdown':
|
||||
textMode = 'text/markdown'
|
||||
break
|
||||
}
|
||||
|
||||
let resp = await this.$apollo.query({
|
||||
query: gql`
|
||||
query ($id: Int!) {
|
||||
pages {
|
||||
conflictLatest(id: $id) {
|
||||
id
|
||||
authorId
|
||||
authorName
|
||||
content
|
||||
createdAt
|
||||
description
|
||||
isPublished
|
||||
locale
|
||||
path
|
||||
tags
|
||||
title
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
fetchPolicy: 'network-only',
|
||||
variables: {
|
||||
id: this.$store.get('page/id')
|
||||
}
|
||||
})
|
||||
resp = _.get(resp, 'data.pages.conflictLatest', false)
|
||||
|
||||
if (!resp) {
|
||||
return this.$store.commit('showNotification', {
|
||||
message: 'Failed to fetch latest version.',
|
||||
style: 'warning',
|
||||
icon: 'warning'
|
||||
})
|
||||
}
|
||||
this.latest = resp
|
||||
|
||||
this.cm = CodeMirror.MergeView(this.$refs.cm, {
|
||||
value: this.$store.get('editor/content'),
|
||||
orig: resp.content,
|
||||
tabSize: 2,
|
||||
mode: textMode,
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
connect: null,
|
||||
highlightDifferences: true,
|
||||
styleActiveLine: true,
|
||||
collapseIdentical: true,
|
||||
direction: siteConfig.rtl ? 'rtl' : 'ltr'
|
||||
})
|
||||
this.cm.rightOriginal().setSize(null, 'calc(100vh - 265px)')
|
||||
this.cm.editor().setSize(null, 'calc(100vh - 265px)')
|
||||
this.cm.wrap.style.height = 'calc(100vh - 265px)'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang='scss'>
|
||||
.editor-modal-conflict {
|
||||
position: fixed !important;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 10;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
background-color: rgba(0, 0, 0, .9) !important;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
@ -9,6 +9,7 @@ mutation ($content: String!, $description: String!, $editor: String!, $isPrivate
|
||||
}
|
||||
page {
|
||||
id
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ mutation ($id: Int!, $content: String, $description: String, $editor: String, $i
|
||||
slug
|
||||
message
|
||||
}
|
||||
page {
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
60
client/libs/codemirror-merge/diff-match-patch.js
Normal file
60
client/libs/codemirror-merge/diff-match-patch.js
Normal file
@ -0,0 +1,60 @@
|
||||
var diff_match_patch=function(){this.Diff_Timeout=1;this.Diff_EditCost=4;this.Match_Threshold=.5;this.Match_Distance=1E3;this.Patch_DeleteThreshold=.5;this.Patch_Margin=4;this.Match_MaxBits=32},DIFF_DELETE=-1,DIFF_INSERT=1,DIFF_EQUAL=0;diff_match_patch.Diff=function(a,b){this[0]=a;this[1]=b};diff_match_patch.Diff.prototype.length=2;diff_match_patch.Diff.prototype.toString=function(){return this[0]+","+this[1]};
|
||||
diff_match_patch.prototype.diff_main=function(a,b,c,d){"undefined"==typeof d&&(d=0>=this.Diff_Timeout?Number.MAX_VALUE:(new Date).getTime()+1E3*this.Diff_Timeout);if(null==a||null==b)throw Error("Null input. (diff_main)");if(a==b)return a?[new diff_match_patch.Diff(DIFF_EQUAL,a)]:[];"undefined"==typeof c&&(c=!0);var e=c,f=this.diff_commonPrefix(a,b);c=a.substring(0,f);a=a.substring(f);b=b.substring(f);f=this.diff_commonSuffix(a,b);var g=a.substring(a.length-f);a=a.substring(0,a.length-f);b=b.substring(0,
|
||||
b.length-f);a=this.diff_compute_(a,b,e,d);c&&a.unshift(new diff_match_patch.Diff(DIFF_EQUAL,c));g&&a.push(new diff_match_patch.Diff(DIFF_EQUAL,g));this.diff_cleanupMerge(a);return a};
|
||||
diff_match_patch.prototype.diff_compute_=function(a,b,c,d){if(!a)return[new diff_match_patch.Diff(DIFF_INSERT,b)];if(!b)return[new diff_match_patch.Diff(DIFF_DELETE,a)];var e=a.length>b.length?a:b,f=a.length>b.length?b:a,g=e.indexOf(f);return-1!=g?(c=[new diff_match_patch.Diff(DIFF_INSERT,e.substring(0,g)),new diff_match_patch.Diff(DIFF_EQUAL,f),new diff_match_patch.Diff(DIFF_INSERT,e.substring(g+f.length))],a.length>b.length&&(c[0][0]=c[2][0]=DIFF_DELETE),c):1==f.length?[new diff_match_patch.Diff(DIFF_DELETE,
|
||||
a),new diff_match_patch.Diff(DIFF_INSERT,b)]:(e=this.diff_halfMatch_(a,b))?(b=e[1],f=e[3],a=e[4],e=this.diff_main(e[0],e[2],c,d),c=this.diff_main(b,f,c,d),e.concat([new diff_match_patch.Diff(DIFF_EQUAL,a)],c)):c&&100<a.length&&100<b.length?this.diff_lineMode_(a,b,d):this.diff_bisect_(a,b,d)};
|
||||
diff_match_patch.prototype.diff_lineMode_=function(a,b,c){var d=this.diff_linesToChars_(a,b);a=d.chars1;b=d.chars2;d=d.lineArray;a=this.diff_main(a,b,!1,c);this.diff_charsToLines_(a,d);this.diff_cleanupSemantic(a);a.push(new diff_match_patch.Diff(DIFF_EQUAL,""));for(var e=d=b=0,f="",g="";b<a.length;){switch(a[b][0]){case DIFF_INSERT:e++;g+=a[b][1];break;case DIFF_DELETE:d++;f+=a[b][1];break;case DIFF_EQUAL:if(1<=d&&1<=e){a.splice(b-d-e,d+e);b=b-d-e;d=this.diff_main(f,g,!1,c);for(e=d.length-1;0<=e;e--)a.splice(b,
|
||||
0,d[e]);b+=d.length}d=e=0;g=f=""}b++}a.pop();return a};
|
||||
diff_match_patch.prototype.diff_bisect_=function(a,b,c){for(var d=a.length,e=b.length,f=Math.ceil((d+e)/2),g=2*f,h=Array(g),l=Array(g),k=0;k<g;k++)h[k]=-1,l[k]=-1;h[f+1]=0;l[f+1]=0;k=d-e;for(var m=0!=k%2,p=0,x=0,w=0,q=0,t=0;t<f&&!((new Date).getTime()>c);t++){for(var v=-t+p;v<=t-x;v+=2){var n=f+v;var r=v==-t||v!=t&&h[n-1]<h[n+1]?h[n+1]:h[n-1]+1;for(var y=r-v;r<d&&y<e&&a.charAt(r)==b.charAt(y);)r++,y++;h[n]=r;if(r>d)x+=2;else if(y>e)p+=2;else if(m&&(n=f+k-v,0<=n&&n<g&&-1!=l[n])){var u=d-l[n];if(r>=
|
||||
u)return this.diff_bisectSplit_(a,b,r,y,c)}}for(v=-t+w;v<=t-q;v+=2){n=f+v;u=v==-t||v!=t&&l[n-1]<l[n+1]?l[n+1]:l[n-1]+1;for(r=u-v;u<d&&r<e&&a.charAt(d-u-1)==b.charAt(e-r-1);)u++,r++;l[n]=u;if(u>d)q+=2;else if(r>e)w+=2;else if(!m&&(n=f+k-v,0<=n&&n<g&&-1!=h[n]&&(r=h[n],y=f+r-n,u=d-u,r>=u)))return this.diff_bisectSplit_(a,b,r,y,c)}}return[new diff_match_patch.Diff(DIFF_DELETE,a),new diff_match_patch.Diff(DIFF_INSERT,b)]};
|
||||
diff_match_patch.prototype.diff_bisectSplit_=function(a,b,c,d,e){var f=a.substring(0,c),g=b.substring(0,d);a=a.substring(c);b=b.substring(d);f=this.diff_main(f,g,!1,e);e=this.diff_main(a,b,!1,e);return f.concat(e)};
|
||||
diff_match_patch.prototype.diff_linesToChars_=function(a,b){function c(a){for(var b="",c=0,g=-1,h=d.length;g<a.length-1;){g=a.indexOf("\n",c);-1==g&&(g=a.length-1);var l=a.substring(c,g+1);(e.hasOwnProperty?e.hasOwnProperty(l):void 0!==e[l])?b+=String.fromCharCode(e[l]):(h==f&&(l=a.substring(c),g=a.length),b+=String.fromCharCode(h),e[l]=h,d[h++]=l);c=g+1}return b}var d=[],e={};d[0]="";var f=4E4,g=c(a);f=65535;var h=c(b);return{chars1:g,chars2:h,lineArray:d}};
|
||||
diff_match_patch.prototype.diff_charsToLines_=function(a,b){for(var c=0;c<a.length;c++){for(var d=a[c][1],e=[],f=0;f<d.length;f++)e[f]=b[d.charCodeAt(f)];a[c][1]=e.join("")}};diff_match_patch.prototype.diff_commonPrefix=function(a,b){if(!a||!b||a.charAt(0)!=b.charAt(0))return 0;for(var c=0,d=Math.min(a.length,b.length),e=d,f=0;c<e;)a.substring(f,e)==b.substring(f,e)?f=c=e:d=e,e=Math.floor((d-c)/2+c);return e};
|
||||
diff_match_patch.prototype.diff_commonSuffix=function(a,b){if(!a||!b||a.charAt(a.length-1)!=b.charAt(b.length-1))return 0;for(var c=0,d=Math.min(a.length,b.length),e=d,f=0;c<e;)a.substring(a.length-e,a.length-f)==b.substring(b.length-e,b.length-f)?f=c=e:d=e,e=Math.floor((d-c)/2+c);return e};
|
||||
diff_match_patch.prototype.diff_commonOverlap_=function(a,b){var c=a.length,d=b.length;if(0==c||0==d)return 0;c>d?a=a.substring(c-d):c<d&&(b=b.substring(0,c));c=Math.min(c,d);if(a==b)return c;d=0;for(var e=1;;){var f=a.substring(c-e);f=b.indexOf(f);if(-1==f)return d;e+=f;if(0==f||a.substring(c-e)==b.substring(0,e))d=e,e++}};
|
||||
diff_match_patch.prototype.diff_halfMatch_=function(a,b){function c(a,b,c){for(var d=a.substring(c,c+Math.floor(a.length/4)),e=-1,g="",h,k,l,m;-1!=(e=b.indexOf(d,e+1));){var p=f.diff_commonPrefix(a.substring(c),b.substring(e)),u=f.diff_commonSuffix(a.substring(0,c),b.substring(0,e));g.length<u+p&&(g=b.substring(e-u,e)+b.substring(e,e+p),h=a.substring(0,c-u),k=a.substring(c+p),l=b.substring(0,e-u),m=b.substring(e+p))}return 2*g.length>=a.length?[h,k,l,m,g]:null}if(0>=this.Diff_Timeout)return null;
|
||||
var d=a.length>b.length?a:b,e=a.length>b.length?b:a;if(4>d.length||2*e.length<d.length)return null;var f=this,g=c(d,e,Math.ceil(d.length/4));d=c(d,e,Math.ceil(d.length/2));if(g||d)g=d?g?g[4].length>d[4].length?g:d:d:g;else return null;if(a.length>b.length){d=g[0];e=g[1];var h=g[2];var l=g[3]}else h=g[0],l=g[1],d=g[2],e=g[3];return[d,e,h,l,g[4]]};
|
||||
diff_match_patch.prototype.diff_cleanupSemantic=function(a){for(var b=!1,c=[],d=0,e=null,f=0,g=0,h=0,l=0,k=0;f<a.length;)a[f][0]==DIFF_EQUAL?(c[d++]=f,g=l,h=k,k=l=0,e=a[f][1]):(a[f][0]==DIFF_INSERT?l+=a[f][1].length:k+=a[f][1].length,e&&e.length<=Math.max(g,h)&&e.length<=Math.max(l,k)&&(a.splice(c[d-1],0,new diff_match_patch.Diff(DIFF_DELETE,e)),a[c[d-1]+1][0]=DIFF_INSERT,d--,d--,f=0<d?c[d-1]:-1,k=l=h=g=0,e=null,b=!0)),f++;b&&this.diff_cleanupMerge(a);this.diff_cleanupSemanticLossless(a);for(f=1;f<
|
||||
a.length;){if(a[f-1][0]==DIFF_DELETE&&a[f][0]==DIFF_INSERT){b=a[f-1][1];c=a[f][1];d=this.diff_commonOverlap_(b,c);e=this.diff_commonOverlap_(c,b);if(d>=e){if(d>=b.length/2||d>=c.length/2)a.splice(f,0,new diff_match_patch.Diff(DIFF_EQUAL,c.substring(0,d))),a[f-1][1]=b.substring(0,b.length-d),a[f+1][1]=c.substring(d),f++}else if(e>=b.length/2||e>=c.length/2)a.splice(f,0,new diff_match_patch.Diff(DIFF_EQUAL,b.substring(0,e))),a[f-1][0]=DIFF_INSERT,a[f-1][1]=c.substring(0,c.length-e),a[f+1][0]=DIFF_DELETE,
|
||||
a[f+1][1]=b.substring(e),f++;f++}f++}};
|
||||
diff_match_patch.prototype.diff_cleanupSemanticLossless=function(a){function b(a,b){if(!a||!b)return 6;var c=a.charAt(a.length-1),d=b.charAt(0),e=c.match(diff_match_patch.nonAlphaNumericRegex_),f=d.match(diff_match_patch.nonAlphaNumericRegex_),g=e&&c.match(diff_match_patch.whitespaceRegex_),h=f&&d.match(diff_match_patch.whitespaceRegex_);c=g&&c.match(diff_match_patch.linebreakRegex_);d=h&&d.match(diff_match_patch.linebreakRegex_);var k=c&&a.match(diff_match_patch.blanklineEndRegex_),l=d&&b.match(diff_match_patch.blanklineStartRegex_);
|
||||
return k||l?5:c||d?4:e&&!g&&h?3:g||h?2:e||f?1:0}for(var c=1;c<a.length-1;){if(a[c-1][0]==DIFF_EQUAL&&a[c+1][0]==DIFF_EQUAL){var d=a[c-1][1],e=a[c][1],f=a[c+1][1],g=this.diff_commonSuffix(d,e);if(g){var h=e.substring(e.length-g);d=d.substring(0,d.length-g);e=h+e.substring(0,e.length-g);f=h+f}g=d;h=e;for(var l=f,k=b(d,e)+b(e,f);e.charAt(0)===f.charAt(0);){d+=e.charAt(0);e=e.substring(1)+f.charAt(0);f=f.substring(1);var m=b(d,e)+b(e,f);m>=k&&(k=m,g=d,h=e,l=f)}a[c-1][1]!=g&&(g?a[c-1][1]=g:(a.splice(c-
|
||||
1,1),c--),a[c][1]=h,l?a[c+1][1]=l:(a.splice(c+1,1),c--))}c++}};diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;diff_match_patch.whitespaceRegex_=/\s/;diff_match_patch.linebreakRegex_=/[\r\n]/;diff_match_patch.blanklineEndRegex_=/\n\r?\n$/;diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/;
|
||||
diff_match_patch.prototype.diff_cleanupEfficiency=function(a){for(var b=!1,c=[],d=0,e=null,f=0,g=!1,h=!1,l=!1,k=!1;f<a.length;)a[f][0]==DIFF_EQUAL?(a[f][1].length<this.Diff_EditCost&&(l||k)?(c[d++]=f,g=l,h=k,e=a[f][1]):(d=0,e=null),l=k=!1):(a[f][0]==DIFF_DELETE?k=!0:l=!0,e&&(g&&h&&l&&k||e.length<this.Diff_EditCost/2&&3==g+h+l+k)&&(a.splice(c[d-1],0,new diff_match_patch.Diff(DIFF_DELETE,e)),a[c[d-1]+1][0]=DIFF_INSERT,d--,e=null,g&&h?(l=k=!0,d=0):(d--,f=0<d?c[d-1]:-1,l=k=!1),b=!0)),f++;b&&this.diff_cleanupMerge(a)};
|
||||
diff_match_patch.prototype.diff_cleanupMerge=function(a){a.push(new diff_match_patch.Diff(DIFF_EQUAL,""));for(var b=0,c=0,d=0,e="",f="",g;b<a.length;)switch(a[b][0]){case DIFF_INSERT:d++;f+=a[b][1];b++;break;case DIFF_DELETE:c++;e+=a[b][1];b++;break;case DIFF_EQUAL:1<c+d?(0!==c&&0!==d&&(g=this.diff_commonPrefix(f,e),0!==g&&(0<b-c-d&&a[b-c-d-1][0]==DIFF_EQUAL?a[b-c-d-1][1]+=f.substring(0,g):(a.splice(0,0,new diff_match_patch.Diff(DIFF_EQUAL,f.substring(0,g))),b++),f=f.substring(g),e=e.substring(g)),
|
||||
g=this.diff_commonSuffix(f,e),0!==g&&(a[b][1]=f.substring(f.length-g)+a[b][1],f=f.substring(0,f.length-g),e=e.substring(0,e.length-g))),b-=c+d,a.splice(b,c+d),e.length&&(a.splice(b,0,new diff_match_patch.Diff(DIFF_DELETE,e)),b++),f.length&&(a.splice(b,0,new diff_match_patch.Diff(DIFF_INSERT,f)),b++),b++):0!==b&&a[b-1][0]==DIFF_EQUAL?(a[b-1][1]+=a[b][1],a.splice(b,1)):b++,c=d=0,f=e=""}""===a[a.length-1][1]&&a.pop();c=!1;for(b=1;b<a.length-1;)a[b-1][0]==DIFF_EQUAL&&a[b+1][0]==DIFF_EQUAL&&(a[b][1].substring(a[b][1].length-
|
||||
a[b-1][1].length)==a[b-1][1]?(a[b][1]=a[b-1][1]+a[b][1].substring(0,a[b][1].length-a[b-1][1].length),a[b+1][1]=a[b-1][1]+a[b+1][1],a.splice(b-1,1),c=!0):a[b][1].substring(0,a[b+1][1].length)==a[b+1][1]&&(a[b-1][1]+=a[b+1][1],a[b][1]=a[b][1].substring(a[b+1][1].length)+a[b+1][1],a.splice(b+1,1),c=!0)),b++;c&&this.diff_cleanupMerge(a)};
|
||||
diff_match_patch.prototype.diff_xIndex=function(a,b){var c=0,d=0,e=0,f=0,g;for(g=0;g<a.length;g++){a[g][0]!==DIFF_INSERT&&(c+=a[g][1].length);a[g][0]!==DIFF_DELETE&&(d+=a[g][1].length);if(c>b)break;e=c;f=d}return a.length!=g&&a[g][0]===DIFF_DELETE?f:f+(b-e)};
|
||||
diff_match_patch.prototype.diff_prettyHtml=function(a){for(var b=[],c=/&/g,d=/</g,e=/>/g,f=/\n/g,g=0;g<a.length;g++){var h=a[g][0],l=a[g][1].replace(c,"&").replace(d,"<").replace(e,">").replace(f,"¶<br>");switch(h){case DIFF_INSERT:b[g]='<ins style="background:#e6ffe6;">'+l+"</ins>";break;case DIFF_DELETE:b[g]='<del style="background:#ffe6e6;">'+l+"</del>";break;case DIFF_EQUAL:b[g]="<span>"+l+"</span>"}}return b.join("")};
|
||||
diff_match_patch.prototype.diff_text1=function(a){for(var b=[],c=0;c<a.length;c++)a[c][0]!==DIFF_INSERT&&(b[c]=a[c][1]);return b.join("")};diff_match_patch.prototype.diff_text2=function(a){for(var b=[],c=0;c<a.length;c++)a[c][0]!==DIFF_DELETE&&(b[c]=a[c][1]);return b.join("")};
|
||||
diff_match_patch.prototype.diff_levenshtein=function(a){for(var b=0,c=0,d=0,e=0;e<a.length;e++){var f=a[e][1];switch(a[e][0]){case DIFF_INSERT:c+=f.length;break;case DIFF_DELETE:d+=f.length;break;case DIFF_EQUAL:b+=Math.max(c,d),d=c=0}}return b+=Math.max(c,d)};
|
||||
diff_match_patch.prototype.diff_toDelta=function(a){for(var b=[],c=0;c<a.length;c++)switch(a[c][0]){case DIFF_INSERT:b[c]="+"+encodeURI(a[c][1]);break;case DIFF_DELETE:b[c]="-"+a[c][1].length;break;case DIFF_EQUAL:b[c]="="+a[c][1].length}return b.join("\t").replace(/%20/g," ")};
|
||||
diff_match_patch.prototype.diff_fromDelta=function(a,b){for(var c=[],d=0,e=0,f=b.split(/\t/g),g=0;g<f.length;g++){var h=f[g].substring(1);switch(f[g].charAt(0)){case "+":try{c[d++]=new diff_match_patch.Diff(DIFF_INSERT,decodeURI(h))}catch(k){throw Error("Illegal escape in diff_fromDelta: "+h);}break;case "-":case "=":var l=parseInt(h,10);if(isNaN(l)||0>l)throw Error("Invalid number in diff_fromDelta: "+h);h=a.substring(e,e+=l);"="==f[g].charAt(0)?c[d++]=new diff_match_patch.Diff(DIFF_EQUAL,h):c[d++]=
|
||||
new diff_match_patch.Diff(DIFF_DELETE,h);break;default:if(f[g])throw Error("Invalid diff operation in diff_fromDelta: "+f[g]);}}if(e!=a.length)throw Error("Delta length ("+e+") does not equal source text length ("+a.length+").");return c};diff_match_patch.prototype.match_main=function(a,b,c){if(null==a||null==b||null==c)throw Error("Null input. (match_main)");c=Math.max(0,Math.min(c,a.length));return a==b?0:a.length?a.substring(c,c+b.length)==b?c:this.match_bitap_(a,b,c):-1};
|
||||
diff_match_patch.prototype.match_bitap_=function(a,b,c){function d(a,d){var e=a/b.length,g=Math.abs(c-d);return f.Match_Distance?e+g/f.Match_Distance:g?1:e}if(b.length>this.Match_MaxBits)throw Error("Pattern too long for this browser.");var e=this.match_alphabet_(b),f=this,g=this.Match_Threshold,h=a.indexOf(b,c);-1!=h&&(g=Math.min(d(0,h),g),h=a.lastIndexOf(b,c+b.length),-1!=h&&(g=Math.min(d(0,h),g)));var l=1<<b.length-1;h=-1;for(var k,m,p=b.length+a.length,x,w=0;w<b.length;w++){k=0;for(m=p;k<m;)d(w,
|
||||
c+m)<=g?k=m:p=m,m=Math.floor((p-k)/2+k);p=m;k=Math.max(1,c-m+1);var q=Math.min(c+m,a.length)+b.length;m=Array(q+2);for(m[q+1]=(1<<w)-1;q>=k;q--){var t=e[a.charAt(q-1)];m[q]=0===w?(m[q+1]<<1|1)&t:(m[q+1]<<1|1)&t|(x[q+1]|x[q])<<1|1|x[q+1];if(m[q]&l&&(t=d(w,q-1),t<=g))if(g=t,h=q-1,h>c)k=Math.max(1,2*c-h);else break}if(d(w+1,c)>g)break;x=m}return h};
|
||||
diff_match_patch.prototype.match_alphabet_=function(a){for(var b={},c=0;c<a.length;c++)b[a.charAt(c)]=0;for(c=0;c<a.length;c++)b[a.charAt(c)]|=1<<a.length-c-1;return b};
|
||||
diff_match_patch.prototype.patch_addContext_=function(a,b){if(0!=b.length){if(null===a.start2)throw Error("patch not initialized");for(var c=b.substring(a.start2,a.start2+a.length1),d=0;b.indexOf(c)!=b.lastIndexOf(c)&&c.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)d+=this.Patch_Margin,c=b.substring(a.start2-d,a.start2+a.length1+d);d+=this.Patch_Margin;(c=b.substring(a.start2-d,a.start2))&&a.diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL,c));(d=b.substring(a.start2+a.length1,
|
||||
a.start2+a.length1+d))&&a.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,d));a.start1-=c.length;a.start2-=c.length;a.length1+=c.length+d.length;a.length2+=c.length+d.length}};
|
||||
diff_match_patch.prototype.patch_make=function(a,b,c){if("string"==typeof a&&"string"==typeof b&&"undefined"==typeof c){var d=a;b=this.diff_main(d,b,!0);2<b.length&&(this.diff_cleanupSemantic(b),this.diff_cleanupEfficiency(b))}else if(a&&"object"==typeof a&&"undefined"==typeof b&&"undefined"==typeof c)b=a,d=this.diff_text1(b);else if("string"==typeof a&&b&&"object"==typeof b&&"undefined"==typeof c)d=a;else if("string"==typeof a&&"string"==typeof b&&c&&"object"==typeof c)d=a,b=c;else throw Error("Unknown call format to patch_make.");
|
||||
if(0===b.length)return[];c=[];a=new diff_match_patch.patch_obj;for(var e=0,f=0,g=0,h=d,l=0;l<b.length;l++){var k=b[l][0],m=b[l][1];e||k===DIFF_EQUAL||(a.start1=f,a.start2=g);switch(k){case DIFF_INSERT:a.diffs[e++]=b[l];a.length2+=m.length;d=d.substring(0,g)+m+d.substring(g);break;case DIFF_DELETE:a.length1+=m.length;a.diffs[e++]=b[l];d=d.substring(0,g)+d.substring(g+m.length);break;case DIFF_EQUAL:m.length<=2*this.Patch_Margin&&e&&b.length!=l+1?(a.diffs[e++]=b[l],a.length1+=m.length,a.length2+=m.length):
|
||||
m.length>=2*this.Patch_Margin&&e&&(this.patch_addContext_(a,h),c.push(a),a=new diff_match_patch.patch_obj,e=0,h=d,f=g)}k!==DIFF_INSERT&&(f+=m.length);k!==DIFF_DELETE&&(g+=m.length)}e&&(this.patch_addContext_(a,h),c.push(a));return c};
|
||||
diff_match_patch.prototype.patch_deepCopy=function(a){for(var b=[],c=0;c<a.length;c++){var d=a[c],e=new diff_match_patch.patch_obj;e.diffs=[];for(var f=0;f<d.diffs.length;f++)e.diffs[f]=new diff_match_patch.Diff(d.diffs[f][0],d.diffs[f][1]);e.start1=d.start1;e.start2=d.start2;e.length1=d.length1;e.length2=d.length2;b[c]=e}return b};
|
||||
diff_match_patch.prototype.patch_apply=function(a,b){if(0==a.length)return[b,[]];a=this.patch_deepCopy(a);var c=this.patch_addPadding(a);b=c+b+c;this.patch_splitMax(a);for(var d=0,e=[],f=0;f<a.length;f++){var g=a[f].start2+d,h=this.diff_text1(a[f].diffs),l=-1;if(h.length>this.Match_MaxBits){var k=this.match_main(b,h.substring(0,this.Match_MaxBits),g);-1!=k&&(l=this.match_main(b,h.substring(h.length-this.Match_MaxBits),g+h.length-this.Match_MaxBits),-1==l||k>=l)&&(k=-1)}else k=this.match_main(b,h,
|
||||
g);if(-1==k)e[f]=!1,d-=a[f].length2-a[f].length1;else if(e[f]=!0,d=k-g,g=-1==l?b.substring(k,k+h.length):b.substring(k,l+this.Match_MaxBits),h==g)b=b.substring(0,k)+this.diff_text2(a[f].diffs)+b.substring(k+h.length);else if(g=this.diff_main(h,g,!1),h.length>this.Match_MaxBits&&this.diff_levenshtein(g)/h.length>this.Patch_DeleteThreshold)e[f]=!1;else{this.diff_cleanupSemanticLossless(g);h=0;var m;for(l=0;l<a[f].diffs.length;l++){var p=a[f].diffs[l];p[0]!==DIFF_EQUAL&&(m=this.diff_xIndex(g,h));p[0]===
|
||||
DIFF_INSERT?b=b.substring(0,k+m)+p[1]+b.substring(k+m):p[0]===DIFF_DELETE&&(b=b.substring(0,k+m)+b.substring(k+this.diff_xIndex(g,h+p[1].length)));p[0]!==DIFF_DELETE&&(h+=p[1].length)}}}b=b.substring(c.length,b.length-c.length);return[b,e]};
|
||||
diff_match_patch.prototype.patch_addPadding=function(a){for(var b=this.Patch_Margin,c="",d=1;d<=b;d++)c+=String.fromCharCode(d);for(d=0;d<a.length;d++)a[d].start1+=b,a[d].start2+=b;d=a[0];var e=d.diffs;if(0==e.length||e[0][0]!=DIFF_EQUAL)e.unshift(new diff_match_patch.Diff(DIFF_EQUAL,c)),d.start1-=b,d.start2-=b,d.length1+=b,d.length2+=b;else if(b>e[0][1].length){var f=b-e[0][1].length;e[0][1]=c.substring(e[0][1].length)+e[0][1];d.start1-=f;d.start2-=f;d.length1+=f;d.length2+=f}d=a[a.length-1];e=d.diffs;
|
||||
0==e.length||e[e.length-1][0]!=DIFF_EQUAL?(e.push(new diff_match_patch.Diff(DIFF_EQUAL,c)),d.length1+=b,d.length2+=b):b>e[e.length-1][1].length&&(f=b-e[e.length-1][1].length,e[e.length-1][1]+=c.substring(0,f),d.length1+=f,d.length2+=f);return c};
|
||||
diff_match_patch.prototype.patch_splitMax=function(a){for(var b=this.Match_MaxBits,c=0;c<a.length;c++)if(!(a[c].length1<=b)){var d=a[c];a.splice(c--,1);for(var e=d.start1,f=d.start2,g="";0!==d.diffs.length;){var h=new diff_match_patch.patch_obj,l=!0;h.start1=e-g.length;h.start2=f-g.length;""!==g&&(h.length1=h.length2=g.length,h.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,g)));for(;0!==d.diffs.length&&h.length1<b-this.Patch_Margin;){g=d.diffs[0][0];var k=d.diffs[0][1];g===DIFF_INSERT?(h.length2+=
|
||||
k.length,f+=k.length,h.diffs.push(d.diffs.shift()),l=!1):g===DIFF_DELETE&&1==h.diffs.length&&h.diffs[0][0]==DIFF_EQUAL&&k.length>2*b?(h.length1+=k.length,e+=k.length,l=!1,h.diffs.push(new diff_match_patch.Diff(g,k)),d.diffs.shift()):(k=k.substring(0,b-h.length1-this.Patch_Margin),h.length1+=k.length,e+=k.length,g===DIFF_EQUAL?(h.length2+=k.length,f+=k.length):l=!1,h.diffs.push(new diff_match_patch.Diff(g,k)),k==d.diffs[0][1]?d.diffs.shift():d.diffs[0][1]=d.diffs[0][1].substring(k.length))}g=this.diff_text2(h.diffs);
|
||||
g=g.substring(g.length-this.Patch_Margin);k=this.diff_text1(d.diffs).substring(0,this.Patch_Margin);""!==k&&(h.length1+=k.length,h.length2+=k.length,0!==h.diffs.length&&h.diffs[h.diffs.length-1][0]===DIFF_EQUAL?h.diffs[h.diffs.length-1][1]+=k:h.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,k)));l||a.splice(++c,0,h)}}};diff_match_patch.prototype.patch_toText=function(a){for(var b=[],c=0;c<a.length;c++)b[c]=a[c];return b.join("")};
|
||||
diff_match_patch.prototype.patch_fromText=function(a){var b=[];if(!a)return b;a=a.split("\n");for(var c=0,d=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;c<a.length;){var e=a[c].match(d);if(!e)throw Error("Invalid patch string: "+a[c]);var f=new diff_match_patch.patch_obj;b.push(f);f.start1=parseInt(e[1],10);""===e[2]?(f.start1--,f.length1=1):"0"==e[2]?f.length1=0:(f.start1--,f.length1=parseInt(e[2],10));f.start2=parseInt(e[3],10);""===e[4]?(f.start2--,f.length2=1):"0"==e[4]?f.length2=0:(f.start2--,f.length2=
|
||||
parseInt(e[4],10));for(c++;c<a.length;){e=a[c].charAt(0);try{var g=decodeURI(a[c].substring(1))}catch(h){throw Error("Illegal escape in patch_fromText: "+g);}if("-"==e)f.diffs.push(new diff_match_patch.Diff(DIFF_DELETE,g));else if("+"==e)f.diffs.push(new diff_match_patch.Diff(DIFF_INSERT,g));else if(" "==e)f.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,g));else if("@"==e)break;else if(""!==e)throw Error('Invalid patch mode "'+e+'" in: '+g);c++}}return b};
|
||||
diff_match_patch.patch_obj=function(){this.diffs=[];this.start2=this.start1=null;this.length2=this.length1=0};
|
||||
diff_match_patch.patch_obj.prototype.toString=function(){for(var a=["@@ -"+(0===this.length1?this.start1+",0":1==this.length1?this.start1+1:this.start1+1+","+this.length1)+" +"+(0===this.length2?this.start2+",0":1==this.length2?this.start2+1:this.start2+1+","+this.length2)+" @@\n"],b,c=0;c<this.diffs.length;c++){switch(this.diffs[c][0]){case DIFF_INSERT:b="+";break;case DIFF_DELETE:b="-";break;case DIFF_EQUAL:b=" "}a[c+1]=b+encodeURI(this.diffs[c][1])+"\n"}return a.join("").replace(/%20/g," ")};
|
||||
this.diff_match_patch=diff_match_patch;this.DIFF_DELETE=DIFF_DELETE;this.DIFF_INSERT=DIFF_INSERT;this.DIFF_EQUAL=DIFF_EQUAL;
|
||||
|
||||
window.diff_match_patch = diff_match_patch
|
||||
window.DIFF_INSERT = DIFF_INSERT
|
||||
window.DIFF_DELETE = DIFF_DELETE
|
||||
window.DIFF_EQUAL = DIFF_EQUAL
|
@ -10,7 +10,8 @@ const state = {
|
||||
folderTree: [],
|
||||
currentFolderId: 0,
|
||||
currentFileId: null
|
||||
}
|
||||
},
|
||||
checkoutDateActive: ''
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -139,7 +139,7 @@ module.exports = {
|
||||
async single (obj, args, context, info) {
|
||||
let page = await WIKI.models.pages.getPageFromDb(args.id)
|
||||
if (page) {
|
||||
if (WIKI.auth.checkAccess(context.req.user, ['read:history'], {
|
||||
if (WIKI.auth.checkAccess(context.req.user, ['manage:pages', 'delete:pages'], {
|
||||
path: page.path,
|
||||
locale: page.localeCode
|
||||
})) {
|
||||
@ -263,13 +263,35 @@ module.exports = {
|
||||
path: page.path,
|
||||
locale: page.localeCode
|
||||
})) {
|
||||
return page.updatedAt !== args.checkoutDate
|
||||
return page.updatedAt > args.checkoutDate
|
||||
} else {
|
||||
throw new WIKI.Error.PageUpdateForbidden()
|
||||
}
|
||||
} else {
|
||||
throw new WIKI.Error.PageNotFound()
|
||||
}
|
||||
},
|
||||
/**
|
||||
* FETCH LATEST VERSION FOR CONFLICT COMPARISON
|
||||
*/
|
||||
async conflictLatest (obj, args, context, info) {
|
||||
let page = await WIKI.models.pages.getPageFromDb(args.id)
|
||||
if (page) {
|
||||
if (WIKI.auth.checkAccess(context.req.user, ['write:pages', 'manage:pages'], {
|
||||
path: page.path,
|
||||
locale: page.localeCode
|
||||
})) {
|
||||
return {
|
||||
...page,
|
||||
tags: page.tags.map(t => t.tag),
|
||||
locale: page.localeCode
|
||||
}
|
||||
} else {
|
||||
throw new WIKI.Error.PageViewForbidden()
|
||||
}
|
||||
} else {
|
||||
throw new WIKI.Error.PageNotFound()
|
||||
}
|
||||
}
|
||||
},
|
||||
PageMutation: {
|
||||
|
@ -66,6 +66,10 @@ type PageQuery {
|
||||
id: Int!
|
||||
checkoutDate: Date!
|
||||
): Boolean! @auth(requires: ["write:pages", "manage:pages", "manage:system"])
|
||||
|
||||
conflictLatest(
|
||||
id: Int!
|
||||
): PageConflictLatest! @auth(requires: ["write:pages", "manage:pages", "manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@ -277,6 +281,21 @@ type PageLinkItem {
|
||||
links: [String]!
|
||||
}
|
||||
|
||||
type PageConflictLatest {
|
||||
id: Int!
|
||||
authorId: String!
|
||||
authorName: String!
|
||||
content: String!
|
||||
createdAt: Date!
|
||||
description: String!
|
||||
isPublished: Boolean!
|
||||
locale: String!
|
||||
path: String!
|
||||
tags: [String]
|
||||
title: String!
|
||||
updatedAt: Date!
|
||||
}
|
||||
|
||||
enum PageOrderBy {
|
||||
CREATED
|
||||
ID
|
||||
|
@ -293,6 +293,9 @@ module.exports = class Page extends Model {
|
||||
mode: 'create'
|
||||
})
|
||||
|
||||
// -> Get latest updatedAt
|
||||
page.updatedAt = await WIKI.models.pages.query().findById(page.id).select('updatedAt').then(r => r.updatedAt)
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
@ -340,12 +343,7 @@ module.exports = class Page extends Model {
|
||||
publishStartDate: opts.publishStartDate || '',
|
||||
title: opts.title
|
||||
}).where('id', ogPage.id)
|
||||
let page = await WIKI.models.pages.getPageFromDb({
|
||||
path: ogPage.path,
|
||||
locale: ogPage.localeCode,
|
||||
userId: ogPage.authorId,
|
||||
isPrivate: ogPage.isPrivate
|
||||
})
|
||||
let page = await WIKI.models.pages.getPageFromDb(ogPage.id)
|
||||
|
||||
// -> Save Tags
|
||||
await WIKI.models.tags.associateTags({ tags: opts.tags, page })
|
||||
@ -381,6 +379,9 @@ module.exports = class Page extends Model {
|
||||
}).update('title', page.title)
|
||||
}
|
||||
|
||||
// -> Get latest updatedAt
|
||||
page.updatedAt = await WIKI.models.pages.query().findById(page.id).select('updatedAt').then(r => r.updatedAt)
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user