digirati-annotation-bridge
Advanced tools
Comparing version 0.2.15-alpha.8b4c1dcd to 0.2.15-alpha.8c6580fd
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import { BOX_SELECTOR, WHOLE_CANVAS_SELECTOR } from './vocab'; | ||
import AnnotationBody from './annotationBody'; | ||
import { AnnotationSelector } from 'digirati-annotation-redux/es/lib/elucidate/index'; | ||
var W3C_SELECTOR = /[#&\?]xywh\=(pixel\:|percent\:)?(\d+),(\d+),(\d+),(\d+)/; | ||
export function parseTarget(source) { | ||
/** | ||
* @deprecated | ||
*/ | ||
export function parseTarget(target) { | ||
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var match = W3C_SELECTOR.exec(source); | ||
if (match) { | ||
return { | ||
unit: match[1] === 'percent:' ? 'percent' : 'pixel', | ||
scale: scale, | ||
x: parseInt(match[2], 10) * scale, | ||
y: parseInt(match[3], 10) * scale, | ||
width: parseInt(match[4], 10) * scale, | ||
height: parseInt(match[5], 10) * scale | ||
}; | ||
} | ||
return source; | ||
return AnnotationSelector.parse(target, scale); | ||
} | ||
@@ -61,4 +53,2 @@ | ||
console.info('RT => ', resourceTemplate, bodyFields); | ||
fields.forEach(function (field) { | ||
@@ -88,3 +78,3 @@ var template = resourceTemplateReverseTypeLookup(resourceTemplate, field); | ||
}).map(function (anno) { | ||
var r = anno.selector; | ||
var r = anno.selector.target; | ||
return { | ||
@@ -132,2 +122,24 @@ id: anno.id, | ||
export function detectTypeOfAnnotation(annotation) { | ||
if (annotation.body && annotation.body.value && typeof annotation.body.value === 'string') { | ||
// @todo temporary type. | ||
return 'ANNOTATION_STUDIO'; | ||
} | ||
if (Object.prototype.toString.call(annotation.body) === '[object Array]') { | ||
return 'ANNOTATION_ARRAY'; | ||
} | ||
return 'UNKNOWN'; | ||
} | ||
export function getAnnotationBody(annotation) { | ||
var type = detectTypeOfAnnotation(annotation); | ||
switch (type) { | ||
case 'ANNOTATION_STUDIO': | ||
return JSON.parse(annotation.body.value); | ||
default: | ||
return AnnotationBody.fromBody(annotation.body); | ||
} | ||
} | ||
export function createDraftFromAnnotation(resourceTemplate, annotation) { | ||
@@ -141,3 +153,3 @@ var scale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
id: annotation.id, | ||
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, typeof annotation.body.value === 'string' ? JSON.parse(annotation.body.value) : annotation.body.value), | ||
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, getAnnotationBody(annotation)), | ||
selector: mapTarget(annotation.target, scale), | ||
@@ -144,0 +156,0 @@ isPublishing: true, |
@@ -15,2 +15,4 @@ 'use strict'; | ||
exports.editableRegionsFromDraftList = editableRegionsFromDraftList; | ||
exports.detectTypeOfAnnotation = detectTypeOfAnnotation; | ||
exports.getAnnotationBody = getAnnotationBody; | ||
exports.createDraftFromAnnotation = createDraftFromAnnotation; | ||
@@ -20,19 +22,17 @@ | ||
var W3C_SELECTOR = /[#&\?]xywh\=(pixel\:|percent\:)?(\d+),(\d+),(\d+),(\d+)/; | ||
var _annotationBody = require('./annotationBody'); | ||
function parseTarget(source) { | ||
var _annotationBody2 = _interopRequireDefault(_annotationBody); | ||
var _index = require('digirati-annotation-redux/es/lib/elucidate/index'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @deprecated | ||
*/ | ||
function parseTarget(target) { | ||
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var match = W3C_SELECTOR.exec(source); | ||
if (match) { | ||
return { | ||
unit: match[1] === 'percent:' ? 'percent' : 'pixel', | ||
scale: scale, | ||
x: parseInt(match[2], 10) * scale, | ||
y: parseInt(match[3], 10) * scale, | ||
width: parseInt(match[4], 10) * scale, | ||
height: parseInt(match[5], 10) * scale | ||
}; | ||
} | ||
return source; | ||
return _index.AnnotationSelector.parse(target, scale); | ||
} | ||
@@ -77,4 +77,2 @@ | ||
console.info('RT => ', resourceTemplate, bodyFields); | ||
fields.forEach(function (field) { | ||
@@ -104,3 +102,3 @@ var template = resourceTemplateReverseTypeLookup(resourceTemplate, field); | ||
}).map(function (anno) { | ||
var r = anno.selector; | ||
var r = anno.selector.target; | ||
return { | ||
@@ -148,2 +146,24 @@ id: anno.id, | ||
function detectTypeOfAnnotation(annotation) { | ||
if (annotation.body && annotation.body.value && typeof annotation.body.value === 'string') { | ||
// @todo temporary type. | ||
return 'ANNOTATION_STUDIO'; | ||
} | ||
if (Object.prototype.toString.call(annotation.body) === '[object Array]') { | ||
return 'ANNOTATION_ARRAY'; | ||
} | ||
return 'UNKNOWN'; | ||
} | ||
function getAnnotationBody(annotation) { | ||
var type = detectTypeOfAnnotation(annotation); | ||
switch (type) { | ||
case 'ANNOTATION_STUDIO': | ||
return JSON.parse(annotation.body.value); | ||
default: | ||
return _annotationBody2.default.fromBody(annotation.body); | ||
} | ||
} | ||
function createDraftFromAnnotation(resourceTemplate, annotation) { | ||
@@ -157,3 +177,3 @@ var scale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
id: annotation.id, | ||
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, typeof annotation.body.value === 'string' ? JSON.parse(annotation.body.value) : annotation.body.value), | ||
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, getAnnotationBody(annotation)), | ||
selector: mapTarget(annotation.target, scale), | ||
@@ -160,0 +180,0 @@ isPublishing: true, |
{ | ||
"name": "digirati-annotation-bridge", | ||
"version": "0.2.15-alpha.8b4c1dcd", | ||
"version": "0.2.15-alpha.8c6580fd", | ||
"description": "Describe annotation-bridge here", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"digirati-annotation-redux": "^0.2.15-alpha.8b4c1dcd" | ||
"digirati-annotation-redux": "^0.2.15-alpha.8c6580fd" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
31215
12
726