2016-11-23 22:58:48 +01:00
|
|
|
//per http://redux.js.org/docs/recipes/ComputingDerivedData.html
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect'
|
|
|
|
|
2016-11-28 18:47:47 +01:00
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
|
|
|
|
import {Format, Show} from './reducers'
|
|
|
|
|
2016-11-30 20:57:35 +01:00
|
|
|
import * as Dubdiff from './util/dubdiff'
|
|
|
|
|
2016-11-28 18:47:47 +01:00
|
|
|
|
2016-11-23 22:58:48 +01:00
|
|
|
const input = (state) => state.input
|
2016-11-28 18:47:47 +01:00
|
|
|
const format = (state) => state.format
|
|
|
|
const show = (state) => state.show
|
2016-11-23 22:58:48 +01:00
|
|
|
|
|
|
|
export const safeInput = createSelector(
|
|
|
|
[input],
|
|
|
|
(input) => {
|
|
|
|
//!!! sanitize the input here and return
|
|
|
|
return input
|
|
|
|
}
|
2016-11-28 18:47:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
export const isMarkdownFormat = createSelector(
|
|
|
|
[format],
|
|
|
|
(format) => {
|
|
|
|
console.log(format, Format.MARKDOWN)
|
|
|
|
return format == Format.MARKDOWN
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const isShow = (type) => createSelector(
|
|
|
|
[show],
|
|
|
|
(show) => {
|
|
|
|
return show == type
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const isShowOriginal = isShow(Show.ORIGINAL)
|
|
|
|
export const isShowFinal = isShow(Show.FINAL)
|
|
|
|
export const isShowDifference= isShow(Show.DIFFERENCE)
|
|
|
|
|
|
|
|
|
|
|
|
export const diff = createSelector(
|
|
|
|
[format, input],
|
|
|
|
(format, input) => {
|
2016-11-30 20:57:35 +01:00
|
|
|
return Dubdiff.plaintextDiff(input.original, input.final)
|
2016-11-28 18:47:47 +01:00
|
|
|
/*
|
|
|
|
let diff = JsDiff.diffWords (input.original.replace(/ /g, ' '), input.final.replace(/ /g, ' '))
|
|
|
|
return diff.map(({added, removed, value})=>({added, removed, value:value.replace(/ /g, ' ')})).map(part => (
|
|
|
|
part.added ? <ins>{part.value}</ins> :
|
|
|
|
part.removed ? <del>{part.value}</del> :
|
|
|
|
<span>{part.value}</span>
|
|
|
|
))
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-11-30 20:57:35 +01:00
|
|
|
|
|
|
|
|
2016-11-28 18:47:47 +01:00
|
|
|
/*
|
|
|
|
html diff
|
|
|
|
---
|
|
|
|
|
|
|
|
diffHtml(parentOriginal, parentFinal) {
|
|
|
|
create stringOriginal, stringFinal consisting of
|
|
|
|
}
|
|
|
|
*/
|