New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

digirati-annotation-bridge

Package Overview
Dependencies
Maintainers
1
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

digirati-annotation-bridge - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

82

es/annotations.js

@@ -0,1 +1,3 @@

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';

@@ -6,2 +8,4 @@

export function parseTarget(source) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var match = W3C_SELECTOR.exec(source);

@@ -11,6 +15,7 @@ if (match) {

unit: match[1] === 'percent:' ? 'percent' : 'pixel',
x: parseInt(match[2], 10),
y: parseInt(match[3], 10),
width: parseInt(match[4], 10),
height: parseInt(match[5], 10)
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
};

@@ -22,3 +27,5 @@ }

export function mapTarget(target) {
var boxSelector = parseTarget(target);
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var boxSelector = parseTarget(target, scale);
if (typeof boxSelector === 'string') {

@@ -67,12 +74,69 @@ return { type: WHOLE_CANVAS_SELECTOR };

export function createDraftListFromAnnotations(annotations, resourceTemplate, scale) {
return annotations.map(function (anno) {
return createDraftFromAnnotation(resourceTemplate, anno, scale);
});
}
export function immutableRegionsFromDraftList(drafts) {
return Object.keys(drafts).filter(function (k) {
return drafts[k] && drafts[k].selector;
}).map(function (k) {
return drafts[k];
}).filter(function (anno) {
return anno && anno.selector;
}).map(function (anno) {
var r = anno.selector;
return {
id: anno.id,
onClick: function onClick() {},
left: r.x, // should be r.left
top: r.y, // should be r.top
height: r.height,
width: r.width,
scale: r.scale,
selected: false,
editing: false,
immutable: true
};
});
}
export function immutableRegionsFromAnnotations(annotations, resourceTemplate, scale) {
return immutableRegionsFromDraftList(createDraftListFromAnnotations(annotations, resourceTemplate, scale));
}
export function editableRegionsFromDraftList(drafts) {
var currentDraftKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var onClickRegion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
return null;
};
var currentSelectorExists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
return Object.keys(drafts).filter(function (k) {
return drafts[k] && drafts[k].selector;
}).map(function (k) {
var r = drafts[k].selector;
return _extends({
id: drafts[k].id,
onClick: function onClick() {
return onClickRegion(k);
},
selected: '' + k === '' + currentDraftKey,
editing: '' + k === '' + currentDraftKey && currentSelectorExists,
immutable: false
}, r);
});
}
export function createDraftFromAnnotation(resourceTemplate, annotation) {
var scale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
if (!(resourceTemplate && resourceTemplate.captureModels && resourceTemplate.captureModels['madoc:form'] && resourceTemplate.captureModels['madoc:form'].interactiveResources)) {
return null;
}
var input = mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, JSON.parse(annotation.body.value));
var selector = mapTarget(annotation.target);
return {
id: annotation.id,
input: input,
selector: selector,
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, JSON.parse(annotation.body.value)),
selector: mapTarget(annotation.target, scale),
isPublishing: true,

@@ -79,0 +143,0 @@ isPreviewing: true,

@@ -15,2 +15,13 @@ import { ID, OMEKA_LABEL } from './vocab';

};
}
export function iteratorGenerator(generator) {
var instance = generator();
return function () {
for (var _len = arguments.length, props = Array(_len), _key = 0; _key < _len; _key++) {
props[_key] = arguments[_key];
}
return instance.next(props).value;
};
}

37

es/index.js

@@ -6,12 +6,7 @@ import { addCaptureModel, addInteractiveResource, addResourceTemplate } from 'digirati-annotation-redux/es/actions/resourceTemplate';

import { BODY_TYPE, COMBINE, CONFORMS_TO, DESCRIPTION, EXTERNALISE, FORM_FIELDS, HUMAN_READABLE, ID, INPUT_TYPE, MOTIVATED_BY, MULTIPLE, PURPOSE, RDFS_LABEL, SERIALIZE, TITLE, TYPE, UI_GROUP, SELECTOR } from './vocab';
import { BODY_TYPE, COMBINE, CONFORMS_TO, DESCRIPTION, EXTERNALISE, FORM_FIELDS, HUMAN_READABLE, ID, INPUT_TYPE, MOTIVATED_BY, MULTIPLE, PURPOSE, RDFS_LABEL, SERIALIZE, TITLE, TYPE, UI_GROUP, UI_CHOICE, SELECTOR, HAS_PART } from './vocab';
import { castBool, labelId } from './helpers';
export function getW3CAnnotationBody(state) {
var currentDraft = getCurrentDraft(state);
var resourceTemplate = getCurrentResourceTemplate(state);
var captureModels = getForm(resourceTemplate).fields;
var values = currentDraft.input;
export function mapDraftToDataSet(captureModels, values) {
var contexts = {};

@@ -26,5 +21,8 @@ var body = {};

});
body['@context'] = contexts;
return body;
}
export function dataSetToAnnotation(body) {
return {

@@ -37,3 +35,26 @@ "type": ["TextualBody", "Dataset"],

export function getW3CAnnotationBody(state) {
var currentDraft = getCurrentDraft(state);
var resourceTemplate = getCurrentResourceTemplate(state);
var captureModels = getForm(resourceTemplate).fields;
return dataSetToAnnotation(mapDraftToDataSet(captureModels, currentDraft.input));
}
export function getDraftTemplateFromCaptureModel(template) {
var resources = template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].interactiveResources;
return Object.keys(resources).reduce(function (obj, key) {
obj[resources[key].id] = null;
return obj;
}, {});
}
export function omekaImportResourceTemplate(dispatch, resourceTemplate) {
// Recurse all the things.
if (resourceTemplate[UI_CHOICE] === 'True' && Array.isArray(resourceTemplate[HAS_PART])) {
return resourceTemplate[HAS_PART].map(function (template) {
return omekaImportResourceTemplate(dispatch, template);
});
}
// Set the resource template

@@ -40,0 +61,0 @@ dispatch(addResourceTemplate(resourceTemplate[ID], resourceTemplate[DESCRIPTION], resourceTemplate[TITLE], {

@@ -9,2 +9,3 @@ // DUBLIN CORE CONSTANTS

export var FORM_FIELDS = 'dcterms:hasPart';
export var HAS_PART = 'dcterms:hasPart';
export var RDFS_LABEL = 'rdfs:label';

@@ -23,2 +24,3 @@

export var MULTIPLE = 'crowds:uiMultiple';
export var UI_CHOICE = 'crowds:uiChoice';
export var SELECTOR = 'crowds:uiSelectorType';

@@ -25,0 +27,0 @@

'use strict';
exports.__esModule = true;
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; };
exports.parseTarget = parseTarget;

@@ -8,2 +11,6 @@ exports.mapTarget = mapTarget;

exports.mapAnnotationBody = mapAnnotationBody;
exports.createDraftListFromAnnotations = createDraftListFromAnnotations;
exports.immutableRegionsFromDraftList = immutableRegionsFromDraftList;
exports.immutableRegionsFromAnnotations = immutableRegionsFromAnnotations;
exports.editableRegionsFromDraftList = editableRegionsFromDraftList;
exports.createDraftFromAnnotation = createDraftFromAnnotation;

@@ -16,2 +23,4 @@

function parseTarget(source) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var match = W3C_SELECTOR.exec(source);

@@ -21,6 +30,7 @@ if (match) {

unit: match[1] === 'percent:' ? 'percent' : 'pixel',
x: parseInt(match[2], 10),
y: parseInt(match[3], 10),
width: parseInt(match[4], 10),
height: parseInt(match[5], 10)
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
};

@@ -32,3 +42,5 @@ }

function mapTarget(target) {
var boxSelector = parseTarget(target);
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var boxSelector = parseTarget(target, scale);
if (typeof boxSelector === 'string') {

@@ -77,12 +89,69 @@ return { type: _vocab.WHOLE_CANVAS_SELECTOR };

function createDraftListFromAnnotations(annotations, resourceTemplate, scale) {
return annotations.map(function (anno) {
return createDraftFromAnnotation(resourceTemplate, anno, scale);
});
}
function immutableRegionsFromDraftList(drafts) {
return Object.keys(drafts).filter(function (k) {
return drafts[k] && drafts[k].selector;
}).map(function (k) {
return drafts[k];
}).filter(function (anno) {
return anno && anno.selector;
}).map(function (anno) {
var r = anno.selector;
return {
id: anno.id,
onClick: function onClick() {},
left: r.x, // should be r.left
top: r.y, // should be r.top
height: r.height,
width: r.width,
scale: r.scale,
selected: false,
editing: false,
immutable: true
};
});
}
function immutableRegionsFromAnnotations(annotations, resourceTemplate, scale) {
return immutableRegionsFromDraftList(createDraftListFromAnnotations(annotations, resourceTemplate, scale));
}
function editableRegionsFromDraftList(drafts) {
var currentDraftKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var onClickRegion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
return null;
};
var currentSelectorExists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
return Object.keys(drafts).filter(function (k) {
return drafts[k] && drafts[k].selector;
}).map(function (k) {
var r = drafts[k].selector;
return _extends({
id: drafts[k].id,
onClick: function onClick() {
return onClickRegion(k);
},
selected: '' + k === '' + currentDraftKey,
editing: '' + k === '' + currentDraftKey && currentSelectorExists,
immutable: false
}, r);
});
}
function createDraftFromAnnotation(resourceTemplate, annotation) {
var scale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
if (!(resourceTemplate && resourceTemplate.captureModels && resourceTemplate.captureModels['madoc:form'] && resourceTemplate.captureModels['madoc:form'].interactiveResources)) {
return null;
}
var input = mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, JSON.parse(annotation.body.value));
var selector = mapTarget(annotation.target);
return {
id: annotation.id,
input: input,
selector: selector,
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, JSON.parse(annotation.body.value)),
selector: mapTarget(annotation.target, scale),
isPublishing: true,

@@ -89,0 +158,0 @@ isPreviewing: true,

@@ -6,2 +6,3 @@ 'use strict';

exports.labelId = labelId;
exports.iteratorGenerator = iteratorGenerator;

@@ -22,2 +23,13 @@ var _vocab = require('./vocab');

};
}
function iteratorGenerator(generator) {
var instance = generator();
return function () {
for (var _len = arguments.length, props = Array(_len), _key = 0; _key < _len; _key++) {
props[_key] = arguments[_key];
}
return instance.next(props).value;
};
}

@@ -5,3 +5,6 @@ 'use strict';

exports.resourceTemplateReverseTypeLookup = exports.parseTarget = exports.mapTarget = exports.mapAnnotationBody = exports.createDraftFromAnnotation = undefined;
exports.mapDraftToDataSet = mapDraftToDataSet;
exports.dataSetToAnnotation = dataSetToAnnotation;
exports.getW3CAnnotationBody = getW3CAnnotationBody;
exports.getDraftTemplateFromCaptureModel = getDraftTemplateFromCaptureModel;
exports.omekaImportResourceTemplate = omekaImportResourceTemplate;

@@ -22,8 +25,3 @@ exports.default = omekaCreateStore;

function getW3CAnnotationBody(state) {
var currentDraft = (0, _draftQuery.getCurrentDraft)(state);
var resourceTemplate = (0, _resourceTemplateQuery.getCurrentResourceTemplate)(state);
var captureModels = (0, _resourceTemplateQuery.getForm)(resourceTemplate).fields;
var values = currentDraft.input;
function mapDraftToDataSet(captureModels, values) {
var contexts = {};

@@ -38,5 +36,8 @@ var body = {};

});
body['@context'] = contexts;
return body;
}
function dataSetToAnnotation(body) {
return {

@@ -49,3 +50,26 @@ "type": ["TextualBody", "Dataset"],

function getW3CAnnotationBody(state) {
var currentDraft = (0, _draftQuery.getCurrentDraft)(state);
var resourceTemplate = (0, _resourceTemplateQuery.getCurrentResourceTemplate)(state);
var captureModels = (0, _resourceTemplateQuery.getForm)(resourceTemplate).fields;
return dataSetToAnnotation(mapDraftToDataSet(captureModels, currentDraft.input));
}
function getDraftTemplateFromCaptureModel(template) {
var resources = template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].interactiveResources;
return Object.keys(resources).reduce(function (obj, key) {
obj[resources[key].id] = null;
return obj;
}, {});
}
function omekaImportResourceTemplate(dispatch, resourceTemplate) {
// Recurse all the things.
if (resourceTemplate[_vocab.UI_CHOICE] === 'True' && Array.isArray(resourceTemplate[_vocab.HAS_PART])) {
return resourceTemplate[_vocab.HAS_PART].map(function (template) {
return omekaImportResourceTemplate(dispatch, template);
});
}
// Set the resource template

@@ -52,0 +76,0 @@ dispatch((0, _resourceTemplate.addResourceTemplate)(resourceTemplate[_vocab.ID], resourceTemplate[_vocab.DESCRIPTION], resourceTemplate[_vocab.TITLE], {

@@ -12,2 +12,3 @@ 'use strict';

var FORM_FIELDS = exports.FORM_FIELDS = 'dcterms:hasPart';
var HAS_PART = exports.HAS_PART = 'dcterms:hasPart';
var RDFS_LABEL = exports.RDFS_LABEL = 'rdfs:label';

@@ -26,2 +27,3 @@

var MULTIPLE = exports.MULTIPLE = 'crowds:uiMultiple';
var UI_CHOICE = exports.UI_CHOICE = 'crowds:uiChoice';
var SELECTOR = exports.SELECTOR = 'crowds:uiSelectorType';

@@ -28,0 +30,0 @@

{
"name": "digirati-annotation-bridge",
"version": "0.2.0",
"version": "0.2.1",
"description": "Describe annotation-bridge here",

@@ -20,3 +20,3 @@ "main": "lib/index.js",

"dependencies": {
"digirati-annotation-redux": "^0.2.0"
"digirati-annotation-redux": "^0.2.1"
},

@@ -23,0 +23,0 @@ "devDependencies": {

# Annotation Bridge
[![Travis][build-badge]][build]
[![npm package][npm-badge]][npm]
[![Coveralls][coveralls-badge]][coveralls]
Annotation bridge is tracked under NLW-123 and NLW-23 and is responsible for communicating with Omeka-S in both directions.
This package depends on `redux` and `lib-json-ld`
[build-badge]: https://img.shields.io/travis/user/repo/master.png?style=flat-square
[build]: https://travis-ci.org/user/repo
[npm-badge]: https://img.shields.io/npm/v/npm-package.png?style=flat-square
[npm]: https://www.npmjs.org/package/npm-package
[coveralls-badge]: https://img.shields.io/coveralls/user/repo/master.png?style=flat-square
[coveralls]: https://coveralls.io/github/user/repo
This package depends on `redux`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc