@annotation-studio/redux
Advanced tools
Comparing version 1.0.0-pr.13d9d144 to 1.0.0-pr.16a66bcc
@@ -11,2 +11,3 @@ import _extends from 'babel-runtime/helpers/extends'; | ||
import { isSelecting, getCurrentSelector } from '../query/selectorQuery'; | ||
import { reset, moveForward } from './resources'; | ||
@@ -375,6 +376,37 @@ export var DRAFT_CREATE = 'DRAFT_CREATE'; | ||
markDraftAs(id, DRAFT_LIFECYCLE_NEW, DRAFT_LIFECYCLE_READ)(dispatch, getState); | ||
var state = getState(); | ||
var draft = getDraftById(state, id); | ||
// Select draft. | ||
dispatch({ type: DRAFT_SELECT, payload: { id: id, scope: scope } }); | ||
// Update selector. | ||
if (draft.isPreviewing === false && draft.selector && draft.selector.type && draft.selector.type.toLowerCase() !== 'wholecanvasselector') { | ||
dispatch(editCurrentDraftSelector(scope)); | ||
} | ||
}; | ||
} | ||
export function selectDraftAndNavigate(id) { | ||
return function (dispatch, getState) { | ||
var state = getState(); | ||
var draft = getDraftById(state, id); | ||
// Error. | ||
if (!draft) { | ||
return null; | ||
} | ||
// Go to path. | ||
if (draft.fingerprint.path.length) { | ||
dispatch(reset(draft.fingerprint.scope)); | ||
draft.fingerprint.path.forEach(function (forward) { | ||
return dispatch(moveForward(draft.fingerprint.scope, forward)); | ||
}); | ||
} | ||
// select draft. | ||
dispatch(selectDraft(draft.fingerprint.scope, id)); | ||
}; | ||
} | ||
export function previewDraft(id) { | ||
@@ -381,0 +413,0 @@ return function (dispatch, getState) { |
@@ -39,2 +39,3 @@ import md5 from 'blueimp-md5'; | ||
var elucidateServer = getServer(state()); | ||
return createElucidateCollection(elucidateServer, label, md5(resourceId)).then(function (collection) { | ||
@@ -82,4 +83,4 @@ dispatch(setCollection(resourceId, collection)); | ||
dispatch(addElucidateAnnotation(annotation)); | ||
return annotation; | ||
dispatch(addElucidateAnnotation(postedAnnotation)); | ||
return postedAnnotation; | ||
}); | ||
@@ -86,0 +87,0 @@ }; |
@@ -115,2 +115,3 @@ import _extends from 'babel-runtime/helpers/extends'; | ||
if (selector.type === 'WholeCanvasSelector') { | ||
console.warn('WARNING: `editCurrentDraftSelector` should never be called when whole canvas selector is chosen'); | ||
return dispatch(discardCurrentDraft(scope)); | ||
@@ -117,0 +118,0 @@ } |
@@ -14,3 +14,3 @@ import _extends from 'babel-runtime/helpers/extends'; | ||
import { richAnnotationList } from './query/elucidateQuery'; | ||
import { currentManifest } from './query/manifestQuery'; | ||
import { currentManifest, currentCanvas } from './query/manifestQuery'; | ||
import { setViewer, withViewer } from './actions/viewer'; | ||
@@ -69,2 +69,4 @@ import { currentSelectorIsSecondary, isSelecting } from './query/selectorQuery'; | ||
currentSelector: currentSelector, | ||
elucidateServer: props.elucidateServer ? props.elucidateServer : state.elucidate ? state.elucidate.server : null, | ||
currentCanvas: currentCanvas(state), | ||
currentDraft: currentDraft, | ||
@@ -71,0 +73,0 @@ currentDrafts: state.drafts.currentDrafts, |
@@ -156,4 +156,4 @@ import _extends from 'babel-runtime/helpers/extends'; | ||
}).reduce(function (state, field) { | ||
if (field && field.omekaMetaData && field.omekaMetaData && field.omekaMetaData.bodyType.id && field.omekaMetaData.bodyType.id === 'oa:TextualBody' && field.inputType === 'madoc:textarea') { | ||
var body = new AnnotationBody(null, draft.input[field.id], 'text/plain', 'TextualBody'); | ||
if (field && field.omekaMetaData && field.omekaMetaData && field.omekaMetaData.bodyType.id && field.omekaMetaData.bodyType.id === 'oa:TextualBody' && (field.inputType === 'madoc:textarea' || field.inputType === 'madoc:htmlfield')) { | ||
var body = new AnnotationBody(null, draft.input[field.id], field.inputType === 'madoc:textarea' ? 'text/plain' : 'text/html', 'TextualBody'); | ||
body.purpose = field.omekaMetaData.purpose ? field.omekaMetaData.purpose.label : null; | ||
@@ -160,0 +160,0 @@ state.push(body); |
@@ -110,3 +110,3 @@ import _asyncIterator from 'babel-runtime/helpers/asyncIterator'; | ||
body: JSON.stringify(body), | ||
credentials: withoutCredentials ? null : process.env.NODE_ENV === 'production' ? 'include' : null, | ||
credentials: withoutCredentials ? 'omit' : process.env.NODE_ENV === 'production' ? 'include' : 'omit', | ||
cache: process.env.NODE_ENV === 'production' ? 'default' : 'force-cache', | ||
@@ -138,6 +138,8 @@ redirect: 'follow' | ||
try { | ||
return makeRequest('POST', uri, body); | ||
return makeRequest('POST', uri, body, headers); | ||
} catch (e) { | ||
console.warn('Request failed, trying again without credentials', e); | ||
return makeRequest('POST', uri, body, { withoutCredentials: true }); | ||
return makeRequest('POST', uri, body, headers, { | ||
withoutCredentials: true | ||
}); | ||
} | ||
@@ -150,6 +152,6 @@ } | ||
try { | ||
return makeRequest('PUT', uri, body); | ||
return makeRequest('PUT', uri, body, headers); | ||
} catch (e) { | ||
console.warn('Request failed, trying again without credentials', e); | ||
return makeRequest('PUT', uri, body, { withoutCredentials: true }); | ||
return makeRequest('PUT', uri, body, headers, { withoutCredentials: true }); | ||
} | ||
@@ -156,0 +158,0 @@ } |
import _extends from 'babel-runtime/helpers/extends'; | ||
import { AnnotationSelector } from '../lib/elucidate/index'; | ||
import { isV3Manifest } from '../utility'; | ||
export function getServer(state) { | ||
@@ -16,6 +17,18 @@ return state.elucidate.server; | ||
export function getCanvasFromManifest(manifest, canvasId) { | ||
if (!(manifest || manifest.sequences || manifest.sequences[0] || manifest.sequences[0].canvases)) { | ||
if (!manifest) { | ||
return null; | ||
} | ||
var canvases = manifest.sequences[0].canvases; | ||
var canvases = null; | ||
var idProperty = null; | ||
try { | ||
if (isV3Manifest(manifest)) { | ||
canvases = manifest.items; | ||
idProperty = 'id'; | ||
} else { | ||
canvases = manifest.sequences[0].canvases; | ||
idProperty = '@id'; | ||
} | ||
} catch (ex) { | ||
return null; | ||
} | ||
for (var _iterator = canvases, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -35,3 +48,3 @@ var _ref; | ||
if (canvas['@id'] === canvasId) { | ||
if (canvas[idProperty] === canvasId) { | ||
return canvas; | ||
@@ -38,0 +51,0 @@ } |
@@ -0,1 +1,3 @@ | ||
import { isV3Manifest } from '../utility'; | ||
export function currentManifest(state) { | ||
@@ -6,13 +8,18 @@ return manifestById(state, state.manifest.current); | ||
export function getImageServiceFromCanvas(canvas) { | ||
if (canvas.images && canvas.images[0] && canvas.images[0].resource && canvas.images[0].resource.service && canvas.images[0].resource.service['@id']) { | ||
return canvas.images[0].resource.service['@id'] + '/info.json'; | ||
} | ||
if (canvas.hasOwnProperty('type') && canvas.type === 'Canvas') { | ||
if (canvas.items && canvas.items[0] && canvas.items[0].items && canvas.items[0].items[0] && canvas.items[0].items[0].body && canvas.items[0].items[0].body.service && canvas.items[0].items[0].body.service[0] && canvas.items[0].items[0].body.service[0].id) { | ||
return canvas.items[0].items[0].body.service[0].id + '/info.json'; | ||
} | ||
} else { | ||
if (canvas.images && canvas.images[0] && canvas.images[0].resource && canvas.images[0].resource.service && canvas.images[0].resource.service['@id']) { | ||
return canvas.images[0].resource.service['@id'] + '/info.json'; | ||
} | ||
if (canvas.thumbnail && canvas.thumbnail.service && canvas.thumbnail.service['@id']) { | ||
return canvas.thumbnail.service['@id'] + '/info.json'; | ||
if (canvas.thumbnail && canvas.thumbnail.service && canvas.thumbnail.service['@id']) { | ||
return canvas.thumbnail.service['@id'] + '/info.json'; | ||
} | ||
if (canvas.thumbnail && canvas.thumbnail['@id']) { | ||
return canvas.thumbnail['@id']; | ||
} | ||
} | ||
if (canvas.thumbnail && canvas.thumbnail['@id']) { | ||
return canvas.thumbnail['@id']; | ||
} | ||
return null; | ||
@@ -33,6 +40,18 @@ } | ||
var canvasId = state.manifest.currentCanvas; | ||
if (!(manifest && canvasId && manifest.sequences && manifest.sequences[0] && manifest.sequences[0].canvases)) { | ||
return null; | ||
var canvases = null; | ||
var idProperty = null; | ||
if (isV3Manifest(manifest)) { | ||
if (!manifest.hasOwnProperty('items')) { | ||
return null; | ||
} | ||
canvases = manifest.items; | ||
idProperty = 'id'; | ||
} else { | ||
if (!(manifest && canvasId && manifest.sequences && manifest.sequences[0] && manifest.sequences[0].canvases)) { | ||
return null; | ||
} | ||
canvases = manifest.sequences[0].canvases; | ||
idProperty = '@id'; | ||
} | ||
var canvases = manifest.sequences[0].canvases; | ||
for (var _iterator = canvases, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -52,3 +71,3 @@ var _ref; | ||
if (canvas['@id'] === canvasId) { | ||
if (canvas[idProperty] === canvasId) { | ||
return canvas; | ||
@@ -55,0 +74,0 @@ } |
@@ -52,2 +52,22 @@ var SHOW_LOGS = false; | ||
return item; | ||
} | ||
var CONTEXT_V3 = 'http://iiif.io/api/presentation/3/context.json'; | ||
export function isV3Manifest(manifest) { | ||
if (!manifest) { | ||
return false; | ||
} | ||
var context = manifest['@context']; | ||
if (!context) { | ||
return false; | ||
} | ||
switch (context.constructor) { | ||
case Array: | ||
return context.includes(CONTEXT_V3); | ||
case String: | ||
return context === CONTEXT_V3; | ||
default: | ||
return false; | ||
} | ||
} |
@@ -41,2 +41,3 @@ 'use strict'; | ||
exports.selectDraft = selectDraft; | ||
exports.selectDraftAndNavigate = selectDraftAndNavigate; | ||
exports.previewDraft = previewDraft; | ||
@@ -65,2 +66,4 @@ exports.unpreviewDraft = unpreviewDraft; | ||
var _resources = require('./resources'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -430,6 +433,37 @@ | ||
markDraftAs(id, DRAFT_LIFECYCLE_NEW, DRAFT_LIFECYCLE_READ)(dispatch, getState); | ||
var state = getState(); | ||
var draft = (0, _draftQuery.getDraftById)(state, id); | ||
// Select draft. | ||
dispatch({ type: DRAFT_SELECT, payload: { id: id, scope: scope } }); | ||
// Update selector. | ||
if (draft.isPreviewing === false && draft.selector && draft.selector.type && draft.selector.type.toLowerCase() !== 'wholecanvasselector') { | ||
dispatch((0, _selectors2.editCurrentDraftSelector)(scope)); | ||
} | ||
}; | ||
} | ||
function selectDraftAndNavigate(id) { | ||
return function (dispatch, getState) { | ||
var state = getState(); | ||
var draft = (0, _draftQuery.getDraftById)(state, id); | ||
// Error. | ||
if (!draft) { | ||
return null; | ||
} | ||
// Go to path. | ||
if (draft.fingerprint.path.length) { | ||
dispatch((0, _resources.reset)(draft.fingerprint.scope)); | ||
draft.fingerprint.path.forEach(function (forward) { | ||
return dispatch((0, _resources.moveForward)(draft.fingerprint.scope, forward)); | ||
}); | ||
} | ||
// select draft. | ||
dispatch(selectDraft(draft.fingerprint.scope, id)); | ||
}; | ||
} | ||
function previewDraft(id) { | ||
@@ -436,0 +470,0 @@ return function (dispatch, getState) { |
@@ -65,2 +65,3 @@ 'use strict'; | ||
var elucidateServer = (0, _elucidateQuery.getServer)(state()); | ||
return (0, _elucidate.createElucidateCollection)(elucidateServer, label, (0, _blueimpMd2.default)(resourceId)).then(function (collection) { | ||
@@ -108,4 +109,4 @@ dispatch(setCollection(resourceId, collection)); | ||
dispatch(addElucidateAnnotation(annotation)); | ||
return annotation; | ||
dispatch(addElucidateAnnotation(postedAnnotation)); | ||
return postedAnnotation; | ||
}); | ||
@@ -112,0 +113,0 @@ }; |
@@ -139,2 +139,3 @@ 'use strict'; | ||
if (selector.type === 'WholeCanvasSelector') { | ||
console.warn('WARNING: `editCurrentDraftSelector` should never be called when whole canvas selector is chosen'); | ||
return dispatch((0, _drafts.discardCurrentDraft)(scope)); | ||
@@ -141,0 +142,0 @@ } |
@@ -93,2 +93,4 @@ 'use strict'; | ||
currentSelector: currentSelector, | ||
elucidateServer: props.elucidateServer ? props.elucidateServer : state.elucidate ? state.elucidate.server : null, | ||
currentCanvas: (0, _manifestQuery.currentCanvas)(state), | ||
currentDraft: currentDraft, | ||
@@ -95,0 +97,0 @@ currentDrafts: state.drafts.currentDrafts, |
@@ -194,4 +194,4 @@ 'use strict'; | ||
}).reduce(function (state, field) { | ||
if (field && field.omekaMetaData && field.omekaMetaData && field.omekaMetaData.bodyType.id && field.omekaMetaData.bodyType.id === 'oa:TextualBody' && field.inputType === 'madoc:textarea') { | ||
var body = new _AnnotationBody2.default(null, draft.input[field.id], 'text/plain', 'TextualBody'); | ||
if (field && field.omekaMetaData && field.omekaMetaData && field.omekaMetaData.bodyType.id && field.omekaMetaData.bodyType.id === 'oa:TextualBody' && (field.inputType === 'madoc:textarea' || field.inputType === 'madoc:htmlfield')) { | ||
var body = new _AnnotationBody2.default(null, draft.input[field.id], field.inputType === 'madoc:textarea' ? 'text/plain' : 'text/html', 'TextualBody'); | ||
body.purpose = field.omekaMetaData.purpose ? field.omekaMetaData.purpose.label : null; | ||
@@ -198,0 +198,0 @@ state.push(body); |
@@ -251,3 +251,3 @@ 'use strict'; | ||
body: JSON.stringify(body), | ||
credentials: withoutCredentials ? null : process.env.NODE_ENV === 'production' ? 'include' : null, | ||
credentials: withoutCredentials ? 'omit' : process.env.NODE_ENV === 'production' ? 'include' : 'omit', | ||
cache: process.env.NODE_ENV === 'production' ? 'default' : 'force-cache', | ||
@@ -279,6 +279,8 @@ redirect: 'follow' | ||
try { | ||
return makeRequest('POST', uri, body); | ||
return makeRequest('POST', uri, body, headers); | ||
} catch (e) { | ||
console.warn('Request failed, trying again without credentials', e); | ||
return makeRequest('POST', uri, body, { withoutCredentials: true }); | ||
return makeRequest('POST', uri, body, headers, { | ||
withoutCredentials: true | ||
}); | ||
} | ||
@@ -291,6 +293,6 @@ } | ||
try { | ||
return makeRequest('PUT', uri, body); | ||
return makeRequest('PUT', uri, body, headers); | ||
} catch (e) { | ||
console.warn('Request failed, trying again without credentials', e); | ||
return makeRequest('PUT', uri, body, { withoutCredentials: true }); | ||
return makeRequest('PUT', uri, body, headers, { withoutCredentials: true }); | ||
} | ||
@@ -297,0 +299,0 @@ } |
@@ -19,2 +19,4 @@ 'use strict'; | ||
var _utility = require('../utility'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -35,6 +37,18 @@ | ||
function getCanvasFromManifest(manifest, canvasId) { | ||
if (!(manifest || manifest.sequences || manifest.sequences[0] || manifest.sequences[0].canvases)) { | ||
if (!manifest) { | ||
return null; | ||
} | ||
var canvases = manifest.sequences[0].canvases; | ||
var canvases = null; | ||
var idProperty = null; | ||
try { | ||
if ((0, _utility.isV3Manifest)(manifest)) { | ||
canvases = manifest.items; | ||
idProperty = 'id'; | ||
} else { | ||
canvases = manifest.sequences[0].canvases; | ||
idProperty = '@id'; | ||
} | ||
} catch (ex) { | ||
return null; | ||
} | ||
for (var _iterator = canvases, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -54,3 +68,3 @@ var _ref; | ||
if (canvas['@id'] === canvasId) { | ||
if (canvas[idProperty] === canvasId) { | ||
return canvas; | ||
@@ -57,0 +71,0 @@ } |
@@ -10,2 +10,5 @@ 'use strict'; | ||
exports.allManifests = allManifests; | ||
var _utility = require('../utility'); | ||
function currentManifest(state) { | ||
@@ -16,13 +19,18 @@ return manifestById(state, state.manifest.current); | ||
function getImageServiceFromCanvas(canvas) { | ||
if (canvas.images && canvas.images[0] && canvas.images[0].resource && canvas.images[0].resource.service && canvas.images[0].resource.service['@id']) { | ||
return canvas.images[0].resource.service['@id'] + '/info.json'; | ||
} | ||
if (canvas.hasOwnProperty('type') && canvas.type === 'Canvas') { | ||
if (canvas.items && canvas.items[0] && canvas.items[0].items && canvas.items[0].items[0] && canvas.items[0].items[0].body && canvas.items[0].items[0].body.service && canvas.items[0].items[0].body.service[0] && canvas.items[0].items[0].body.service[0].id) { | ||
return canvas.items[0].items[0].body.service[0].id + '/info.json'; | ||
} | ||
} else { | ||
if (canvas.images && canvas.images[0] && canvas.images[0].resource && canvas.images[0].resource.service && canvas.images[0].resource.service['@id']) { | ||
return canvas.images[0].resource.service['@id'] + '/info.json'; | ||
} | ||
if (canvas.thumbnail && canvas.thumbnail.service && canvas.thumbnail.service['@id']) { | ||
return canvas.thumbnail.service['@id'] + '/info.json'; | ||
if (canvas.thumbnail && canvas.thumbnail.service && canvas.thumbnail.service['@id']) { | ||
return canvas.thumbnail.service['@id'] + '/info.json'; | ||
} | ||
if (canvas.thumbnail && canvas.thumbnail['@id']) { | ||
return canvas.thumbnail['@id']; | ||
} | ||
} | ||
if (canvas.thumbnail && canvas.thumbnail['@id']) { | ||
return canvas.thumbnail['@id']; | ||
} | ||
return null; | ||
@@ -43,6 +51,18 @@ } | ||
var canvasId = state.manifest.currentCanvas; | ||
if (!(manifest && canvasId && manifest.sequences && manifest.sequences[0] && manifest.sequences[0].canvases)) { | ||
return null; | ||
var canvases = null; | ||
var idProperty = null; | ||
if ((0, _utility.isV3Manifest)(manifest)) { | ||
if (!manifest.hasOwnProperty('items')) { | ||
return null; | ||
} | ||
canvases = manifest.items; | ||
idProperty = 'id'; | ||
} else { | ||
if (!(manifest && canvasId && manifest.sequences && manifest.sequences[0] && manifest.sequences[0].canvases)) { | ||
return null; | ||
} | ||
canvases = manifest.sequences[0].canvases; | ||
idProperty = '@id'; | ||
} | ||
var canvases = manifest.sequences[0].canvases; | ||
for (var _iterator = canvases, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -62,3 +82,3 @@ var _ref; | ||
if (canvas['@id'] === canvasId) { | ||
if (canvas[idProperty] === canvasId) { | ||
return canvas; | ||
@@ -65,0 +85,0 @@ } |
@@ -5,2 +5,3 @@ 'use strict'; | ||
exports.selectorCompat = selectorCompat; | ||
exports.isV3Manifest = isV3Manifest; | ||
var SHOW_LOGS = false; | ||
@@ -57,2 +58,22 @@ var SHOW_WARNINGS = false; | ||
return item; | ||
} | ||
var CONTEXT_V3 = 'http://iiif.io/api/presentation/3/context.json'; | ||
function isV3Manifest(manifest) { | ||
if (!manifest) { | ||
return false; | ||
} | ||
var context = manifest['@context']; | ||
if (!context) { | ||
return false; | ||
} | ||
switch (context.constructor) { | ||
case Array: | ||
return context.includes(CONTEXT_V3); | ||
case String: | ||
return context === CONTEXT_V3; | ||
default: | ||
return false; | ||
} | ||
} |
{ | ||
"name": "@annotation-studio/redux", | ||
"version": "1.0.0-pr.13d9d144", | ||
"version": "1.0.0-pr.16a66bcc", | ||
"description": "Describe annotation-redux here", | ||
@@ -38,3 +38,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@fesk/test-environment": "^1.0.0-pr.13d9d144", | ||
"@fesk/test-environment": "1.0.0-pr.16a66bcc", | ||
"babel-jest": "^20.0.3", | ||
@@ -46,7 +46,9 @@ "babel-plugin-transform-async-to-generator": "^6.24.1", | ||
"cross-spawn": "^6.0.5", | ||
"fetch-mock": "^6.5.1", | ||
"jest": "^20.0.0", | ||
"nwb": "^0.21.5", | ||
"nwb-watch": "^1.0.0-pr.13d9d144", | ||
"nwb-watch": "1.0.0-pr.16a66bcc", | ||
"react-intl": "^2.2.2", | ||
"react-intl-redux": "^0.7.0", | ||
"redux-mock-store": "^1.5.3", | ||
"webpack-cli": "^2.0.11" | ||
@@ -53,0 +55,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
345114
9178
15