@annotation-studio/plugin-core
Advanced tools
Comparing version 1.0.0-pr.73cfbc15 to 1.0.0-pr.7943fd1a
@@ -11,3 +11,3 @@ var _class, _temp2; | ||
import { connector } from '@annotation-studio/redux'; | ||
import { changeFingerprintSource, changeFingerprintIdentity, changeFingerPrintCreator } from '@annotation-studio/redux/es/actions/drafts'; | ||
import { isSavedDraft, changeFingerprintSource, changeFingerprintIdentity, changeFingerPrintCreator } from '@annotation-studio/redux/es/actions/drafts'; | ||
import { getAllAnnotationsFromCollection } from '@annotation-studio/redux/es/lib/elucidate/index'; | ||
@@ -39,3 +39,5 @@ import { asyncForEach } from './core.utils'; | ||
}, _this.warnUser = function (event) { | ||
var drafts = _this.props.drafts; | ||
var _this$props = _this.props, | ||
drafts = _this$props.drafts, | ||
disableCloseWarning = _this$props.disableCloseWarning; | ||
@@ -45,4 +47,12 @@ var changes = drafts ? Object.values(drafts).filter(function (draft) { | ||
}) : []; | ||
if (changes.length) { | ||
var message = 'You have ' + changes + ' unsaved annotation' + (changes.length > 1 ? 's' : null) + ', if you leave the page they will be lost.';; | ||
var changedValues = Object.values(drafts).map(function (draft) { | ||
return Object.values(draft.input).filter(function (e) { | ||
return e; | ||
}); | ||
}).filter(function (e) { | ||
return e.length; | ||
}); | ||
if (changes.length && changedValues.length && disableCloseWarning === false) { | ||
var message = 'You have ' + changes + ' unsaved annotation' + (changes.length > 1 ? 's' : null) + ', if you leave the page they will be lost.'; | ||
event.preventDefault(); | ||
@@ -61,2 +71,3 @@ event.returnValue = message; | ||
manifest = _props.manifest, | ||
manifestJson = _props.manifestJson, | ||
createCollection = _props.createCollection, | ||
@@ -75,20 +86,21 @@ addElucidateAnnotation = _props.addElucidateAnnotation, | ||
if (!elucidateServer) { | ||
return; | ||
} | ||
if (canvasId) { | ||
fetch(manifest, { | ||
var manifestPromise = manifestJson ? Promise.resolve(manifestJson) : fetch(manifest, { | ||
cache: process.env.NODE_ENV === 'production' ? 'default' : 'force-cache' | ||
}).then(function (response) { | ||
return response.json(); | ||
}).then(function (response) { | ||
}); | ||
manifestPromise.then(function (response) { | ||
return addManifest(manifest, response); | ||
}).then(function (response) { | ||
}).then(function () { | ||
return selectManifest(manifest); | ||
}).then(function (response) { | ||
}).then(function () { | ||
return canvasId ? selectCanvas(canvasId) : null; | ||
}); | ||
} | ||
// Set the server. | ||
setServer(elucidateServer, subject); | ||
if (elucidateServer) { | ||
// Set the server. | ||
setServer(elucidateServer, subject); | ||
} | ||
// Set the resource. | ||
@@ -103,3 +115,5 @@ if (subject) { | ||
this.setState({ onlineStatus: navigator.onLine ? Core.ONLINE : Core.OFFLINE }); | ||
this.setState({ | ||
onlineStatus: navigator.onLine ? Core.ONLINE : Core.OFFLINE | ||
}); | ||
@@ -115,28 +129,24 @@ // Import local storage saved items | ||
var isSavedDraft = function isSavedDraft(annotation) { | ||
if (annotation.motivation !== 'http://www.digirati.com/ns/crowds#drafting') { | ||
return false; | ||
} | ||
if (Array.isArray(annotation.body)) { | ||
return false; | ||
} | ||
return annotation.body.purpose === 'editing'; | ||
}; | ||
// Set collection. | ||
createCollection(subject, subject).then(function (c) { | ||
return getAllAnnotationsFromCollection(c); | ||
}).then(function (iterable) { | ||
return asyncForEach(iterable, function (i) { | ||
if (isSavedDraft(i)) { | ||
var draft = JSON.parse(i.body.value); | ||
var identity = i.id.substr(i.id.length - 1) === '/' ? i.id.substr(0, i.id.length - 1).split('/').pop() : i.id.split('/').pop(); | ||
if (draft) { | ||
importDraft(draft.id, changeFingerPrintCreator(changeFingerprintIdentity(draft, identity), i.creator && i.creator.name ? i.creator.name : 'unknown')); | ||
if (elucidateServer) { | ||
// Set collection. | ||
createCollection(subject, subject).then(function (c) { | ||
return getAllAnnotationsFromCollection(c); | ||
}).then(function (iterable) { | ||
return asyncForEach(iterable, function (i) { | ||
if (isSavedDraft(i)) { | ||
var draft = JSON.parse(i.body.value); | ||
var identity = i.id.substr(i.id.length - 1) === '/' ? i.id.substr(0, i.id.length - 1).split('/').pop() : i.id.split('/').pop(); | ||
if (draft) { | ||
importDraft(draft.id, changeFingerPrintCreator(changeFingerprintIdentity(draft, identity), i.creator && i.creator.name ? i.creator.name : 'unknown')); | ||
} | ||
} else { | ||
addElucidateAnnotation(i); | ||
} | ||
} else { | ||
addElucidateAnnotation(i); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
if (this.props.onReady) { | ||
this.props.onReady(); | ||
} | ||
}; | ||
@@ -158,3 +168,4 @@ | ||
null, | ||
'If you leave this page you may lose your progress on ', | ||
'If you leave this page you may lose your progress on', | ||
' ', | ||
changes.length, | ||
@@ -176,2 +187,3 @@ ' annotation', | ||
Core.prototype.render = function render() { | ||
var innerContent = this.props.innerContent; | ||
var onlineStatus = this.state.onlineStatus; | ||
@@ -190,3 +202,4 @@ | ||
React.version | ||
) | ||
), | ||
innerContent ? innerContent : null | ||
); | ||
@@ -193,0 +206,0 @@ }; |
@@ -5,10 +5,5 @@ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
import { render } from 'react-dom'; | ||
import { createStore, reducers } from '@annotation-studio/redux'; | ||
import { unknownPropertyWarning } from './core.utils'; | ||
import CoreProvider from './core.provider'; | ||
import localstorage from 'store'; | ||
import moment from 'moment'; | ||
var DEFAULT_LOCALE = 'en'; | ||
export default function CorePlugin($el, _ref) { | ||
@@ -18,22 +13,23 @@ var manifest = _ref.manifest, | ||
elucidateServer = _ref.elucidateServer, | ||
disableCloseWarning = _ref.disableCloseWarning, | ||
locale = _ref.locale, | ||
unknownProps = _objectWithoutProperties(_ref, ['manifest', 'canvas', 'elucidateServer', 'locale']); | ||
unknownProps = _objectWithoutProperties(_ref, ['manifest', 'canvas', 'elucidateServer', 'disableCloseWarning', 'locale']); | ||
unknownPropertyWarning(unknownProps); | ||
locale = locale || DEFAULT_LOCALE; | ||
moment.locale(locale); | ||
var disableCloseWarningBoolean = disableCloseWarning ? disableCloseWarning === 'true' : false; | ||
var url = window.location.href; | ||
var savedDraftList = localstorage.get('annotation-studio/' + url) || {}; | ||
var store = createStore(reducers, [], locale); | ||
render(React.createElement(CoreProvider, { | ||
store: store, | ||
manifest: manifest, | ||
savedDraftList: savedDraftList, | ||
elucidateServer: elucidateServer, | ||
canvas: canvas | ||
}), $el); | ||
return Promise.resolve(store); | ||
return new Promise(function (resolve, err) { | ||
try { | ||
render(React.createElement(CoreProvider, { | ||
locale: locale, | ||
manifest: manifest, | ||
disableCloseWarning: disableCloseWarningBoolean, | ||
elucidateServer: elucidateServer, | ||
canvas: canvas, | ||
onLoadStore: resolve | ||
}), $el); | ||
} catch (e) { | ||
err(e); | ||
} | ||
}); | ||
} |
@@ -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; }; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
@@ -10,5 +12,11 @@ | ||
import React, { PureComponent } from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { pluginKit } from '@annotation-studio/components'; | ||
import { createStore, reducers } from '@annotation-studio/redux'; | ||
import merge from 'lodash.merge'; | ||
import localstorage from 'store'; | ||
import Core from './core'; | ||
import moment from 'moment/moment'; | ||
export var DEFAULT_LOCALE = 'en'; | ||
var CoreProvider = function (_PureComponent) { | ||
@@ -18,16 +26,89 @@ _inherits(CoreProvider, _PureComponent); | ||
function CoreProvider() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, CoreProvider); | ||
return _possibleConstructorReturn(this, _PureComponent.apply(this, arguments)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _PureComponent.call.apply(_PureComponent, [this].concat(args))), _this), _this.state = { | ||
savedDraftList: {}, | ||
storeReady: false | ||
}, _this.store = null, _this.onReady = function () { | ||
var onLoadStore = _this.props.onLoadStore; | ||
if (onLoadStore) { | ||
_this.setState(function () { | ||
onLoadStore(_this.store); | ||
return { storeReady: true }; | ||
}); | ||
} | ||
}, _this.getStore = function () { | ||
return _this.store; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
CoreProvider.prototype.render = function render() { | ||
CoreProvider.prototype.componentWillMount = function componentWillMount() { | ||
var _props = this.props, | ||
store = _props.store, | ||
props = _objectWithoutProperties(_props, ['store']); | ||
locale = _props.locale, | ||
_props$loadSavedDraft = _props.loadSavedDrafts, | ||
loadSavedDrafts = _props$loadSavedDraft === undefined ? true : _props$loadSavedDraft, | ||
savedDraftsId = _props.savedDraftsId, | ||
savedDraftList = _props.savedDraftList, | ||
customCreateStore = _props.customCreateStore, | ||
onLoadStore = _props.onLoadStore; | ||
var selectedLocale = locale || DEFAULT_LOCALE; | ||
moment.locale(selectedLocale); | ||
this.setState({ locale: selectedLocale }); | ||
if (loadSavedDrafts) { | ||
var url = savedDraftsId || window.location.href; | ||
var savedDraftListFromLS = localstorage.get('annotation-studio/' + url) || {}; | ||
this.setState({ | ||
savedDraftList: merge(savedDraftList || {}, savedDraftListFromLS) | ||
}); | ||
} else if (savedDraftList) { | ||
this.setState({ savedDraftList: savedDraftList }); | ||
} | ||
this.store = customCreateStore ? customCreateStore({ createStore: createStore, reducers: reducers, locale: this.state.locale }) : createStore(reducers, [], selectedLocale); | ||
}; | ||
CoreProvider.prototype.render = function render() { | ||
var _state = this.state, | ||
storeReady = _state.storeReady, | ||
savedDraftList = _state.savedDraftList, | ||
locale = _state.locale; | ||
var _props2 = this.props, | ||
plugins = _props2.plugins, | ||
behaviours = _props2.behaviours, | ||
children = _props2.children, | ||
props = _objectWithoutProperties(_props2, ['plugins', 'behaviours', 'children']); | ||
return React.createElement( | ||
Provider, | ||
{ store: store }, | ||
React.createElement(Core, props) | ||
pluginKit.Provider, | ||
{ | ||
store: this.store, | ||
plugins: plugins, | ||
behaviours: behaviours | ||
}, | ||
React.createElement(Core, _extends({}, props, { | ||
onReady: this.onReady, | ||
savedDraftList: savedDraftList, | ||
innerContent: storeReady && children ? children(_extends({}, props, { | ||
store: this.store, | ||
savedDraftList: savedDraftList, | ||
plugins: plugins, | ||
behaviours: behaviours, | ||
locale: locale | ||
})) : null, | ||
locale: locale | ||
})) | ||
); | ||
@@ -34,0 +115,0 @@ }; |
import _regeneratorRuntime from 'babel-runtime/regenerator'; | ||
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; }; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
@@ -9,3 +11,64 @@ | ||
import moment from 'moment'; | ||
import { generateDraftId } from '@annotation-studio/redux/es/actions/drafts'; | ||
export function draftCreationHelper(_ref) { | ||
var _captureModel, _ref2; | ||
var realId = _ref.id, | ||
input = _ref.input, | ||
selector = _ref.selector, | ||
captureModel = _ref.captureModel, | ||
tree = _ref.tree, | ||
path = _ref.path, | ||
motivation = _ref.motivation, | ||
_ref$isPreviewing = _ref.isPreviewing, | ||
isPreviewing = _ref$isPreviewing === undefined ? false : _ref$isPreviewing, | ||
created = _ref.created; | ||
var id = realId || generateDraftId(); | ||
return _ref2 = {}, _ref2[captureModel] = (_captureModel = {}, _captureModel[id] = { | ||
id: id, | ||
input: input, | ||
selectors: Object.keys(input).reduce(function (acc, key) { | ||
acc[key] = {}; | ||
return acc; | ||
}, {}), | ||
template: captureModel, | ||
motivation: motivation ? motivation : { | ||
id: 'http://www.w3.org/ns/oa#tagging', | ||
label: 'oa:tagging', | ||
instance: 'tagging' | ||
}, | ||
isPublishing: false, | ||
isPreviewing: isPreviewing, | ||
selector: selector ? _extends({ | ||
type: 'madoc:boxdraw', | ||
source: { | ||
name: null, | ||
template: captureModel, | ||
scope: tree ? tree : captureModel, | ||
draft: id | ||
} | ||
}, selector) : { | ||
type: 'wholecanvasselector', | ||
source: { | ||
name: null, | ||
template: captureModel, | ||
scope: tree ? tree : captureModel, | ||
draft: id | ||
}, | ||
name: null | ||
}, | ||
fingerprint: { | ||
scope: tree ? tree : captureModel, | ||
path: path ? path : tree && tree !== captureModel ? [captureModel] : [], | ||
created: created ? created : new Date(), | ||
lifecycle: 'DRAFT_LIFECYCLE_NEW', | ||
source: 'localStorage', | ||
creator: 'you', | ||
partOf: null | ||
} | ||
}, _captureModel), _ref2; | ||
} | ||
export function getAttributes($el) { | ||
@@ -23,3 +86,3 @@ var attributes = {}; | ||
export var fetchResourceTemplate = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resource) { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resource) { | ||
var headers, locale; | ||
@@ -35,3 +98,3 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
if (locale && process.env.NODE_ENV === 'production') { | ||
headers.set("X-Annotation-Studio-Locale", locale); | ||
headers.set('X-Annotation-Studio-Locale', locale); | ||
} | ||
@@ -54,3 +117,3 @@ | ||
console.warn('Can\'t send credentials, not same origin. Falling back.', _context.t0); | ||
console.warn("Can't send credentials, not same origin. Falling back."); | ||
_context.prev = 12; | ||
@@ -70,6 +133,5 @@ _context.next = 15; | ||
console.warn('Unable to send locale, likely CORS not available. falling back.', _context.t1); | ||
console.warn('Unable to send locale, likely CORS not available. falling back.'); | ||
_context.next = 23; | ||
return fetch('' + resource, { | ||
cache: process.env.NODE_ENV === 'production' ? 'default' : 'force-cache' | ||
@@ -90,3 +152,3 @@ }); | ||
return function fetchResourceTemplate(_x) { | ||
return _ref.apply(this, arguments); | ||
return _ref3.apply(this, arguments); | ||
}; | ||
@@ -104,5 +166,5 @@ }(); | ||
export function unknownPropertyWarning(unknownProps) { | ||
delete unknownProps['class']; | ||
delete unknownProps['behaviour']; | ||
delete unknownProps['style']; | ||
delete unknownProps.class; | ||
delete unknownProps.behaviour; | ||
delete unknownProps.style; | ||
if (Object.keys(unknownProps).length) { | ||
@@ -109,0 +171,0 @@ console.warn('Found unknown properties passed to component', unknownProps); |
@@ -51,3 +51,5 @@ 'use strict'; | ||
}, _this.warnUser = function (event) { | ||
var drafts = _this.props.drafts; | ||
var _this$props = _this.props, | ||
drafts = _this$props.drafts, | ||
disableCloseWarning = _this$props.disableCloseWarning; | ||
@@ -57,4 +59,12 @@ var changes = drafts ? Object.values(drafts).filter(function (draft) { | ||
}) : []; | ||
if (changes.length) { | ||
var message = 'You have ' + changes + ' unsaved annotation' + (changes.length > 1 ? 's' : null) + ', if you leave the page they will be lost.';; | ||
var changedValues = Object.values(drafts).map(function (draft) { | ||
return Object.values(draft.input).filter(function (e) { | ||
return e; | ||
}); | ||
}).filter(function (e) { | ||
return e.length; | ||
}); | ||
if (changes.length && changedValues.length && disableCloseWarning === false) { | ||
var message = 'You have ' + changes + ' unsaved annotation' + (changes.length > 1 ? 's' : null) + ', if you leave the page they will be lost.'; | ||
event.preventDefault(); | ||
@@ -73,2 +83,3 @@ event.returnValue = message; | ||
manifest = _props.manifest, | ||
manifestJson = _props.manifestJson, | ||
createCollection = _props.createCollection, | ||
@@ -87,20 +98,21 @@ addElucidateAnnotation = _props.addElucidateAnnotation, | ||
if (!elucidateServer) { | ||
return; | ||
} | ||
if (canvasId) { | ||
fetch(manifest, { | ||
var manifestPromise = manifestJson ? Promise.resolve(manifestJson) : fetch(manifest, { | ||
cache: process.env.NODE_ENV === 'production' ? 'default' : 'force-cache' | ||
}).then(function (response) { | ||
return response.json(); | ||
}).then(function (response) { | ||
}); | ||
manifestPromise.then(function (response) { | ||
return addManifest(manifest, response); | ||
}).then(function (response) { | ||
}).then(function () { | ||
return selectManifest(manifest); | ||
}).then(function (response) { | ||
}).then(function () { | ||
return canvasId ? selectCanvas(canvasId) : null; | ||
}); | ||
} | ||
// Set the server. | ||
setServer(elucidateServer, subject); | ||
if (elucidateServer) { | ||
// Set the server. | ||
setServer(elucidateServer, subject); | ||
} | ||
// Set the resource. | ||
@@ -115,3 +127,5 @@ if (subject) { | ||
this.setState({ onlineStatus: navigator.onLine ? Core.ONLINE : Core.OFFLINE }); | ||
this.setState({ | ||
onlineStatus: navigator.onLine ? Core.ONLINE : Core.OFFLINE | ||
}); | ||
@@ -127,28 +141,24 @@ // Import local storage saved items | ||
var isSavedDraft = function isSavedDraft(annotation) { | ||
if (annotation.motivation !== 'http://www.digirati.com/ns/crowds#drafting') { | ||
return false; | ||
} | ||
if (Array.isArray(annotation.body)) { | ||
return false; | ||
} | ||
return annotation.body.purpose === 'editing'; | ||
}; | ||
// Set collection. | ||
createCollection(subject, subject).then(function (c) { | ||
return (0, _index.getAllAnnotationsFromCollection)(c); | ||
}).then(function (iterable) { | ||
return (0, _core.asyncForEach)(iterable, function (i) { | ||
if (isSavedDraft(i)) { | ||
var draft = JSON.parse(i.body.value); | ||
var identity = i.id.substr(i.id.length - 1) === '/' ? i.id.substr(0, i.id.length - 1).split('/').pop() : i.id.split('/').pop(); | ||
if (draft) { | ||
importDraft(draft.id, (0, _drafts.changeFingerPrintCreator)((0, _drafts.changeFingerprintIdentity)(draft, identity), i.creator && i.creator.name ? i.creator.name : 'unknown')); | ||
if (elucidateServer) { | ||
// Set collection. | ||
createCollection(subject, subject).then(function (c) { | ||
return (0, _index.getAllAnnotationsFromCollection)(c); | ||
}).then(function (iterable) { | ||
return (0, _core.asyncForEach)(iterable, function (i) { | ||
if ((0, _drafts.isSavedDraft)(i)) { | ||
var draft = JSON.parse(i.body.value); | ||
var identity = i.id.substr(i.id.length - 1) === '/' ? i.id.substr(0, i.id.length - 1).split('/').pop() : i.id.split('/').pop(); | ||
if (draft) { | ||
importDraft(draft.id, (0, _drafts.changeFingerPrintCreator)((0, _drafts.changeFingerprintIdentity)(draft, identity), i.creator && i.creator.name ? i.creator.name : 'unknown')); | ||
} | ||
} else { | ||
addElucidateAnnotation(i); | ||
} | ||
} else { | ||
addElucidateAnnotation(i); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
if (this.props.onReady) { | ||
this.props.onReady(); | ||
} | ||
}; | ||
@@ -170,3 +180,4 @@ | ||
null, | ||
'If you leave this page you may lose your progress on ', | ||
'If you leave this page you may lose your progress on', | ||
' ', | ||
changes.length, | ||
@@ -188,2 +199,3 @@ ' annotation', | ||
Core.prototype.render = function render() { | ||
var innerContent = this.props.innerContent; | ||
var onlineStatus = this.state.onlineStatus; | ||
@@ -202,3 +214,4 @@ | ||
_react2.default.version | ||
) | ||
), | ||
innerContent ? innerContent : null | ||
); | ||
@@ -205,0 +218,0 @@ }; |
@@ -12,4 +12,2 @@ 'use strict'; | ||
var _redux = require('@annotation-studio/redux'); | ||
var _core = require('./core.utils'); | ||
@@ -21,10 +19,2 @@ | ||
var _store = require('store'); | ||
var _store2 = _interopRequireDefault(_store); | ||
var _moment = require('moment'); | ||
var _moment2 = _interopRequireDefault(_moment); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -34,4 +24,2 @@ | ||
var DEFAULT_LOCALE = 'en'; | ||
function CorePlugin($el, _ref) { | ||
@@ -41,23 +29,24 @@ var manifest = _ref.manifest, | ||
elucidateServer = _ref.elucidateServer, | ||
disableCloseWarning = _ref.disableCloseWarning, | ||
locale = _ref.locale, | ||
unknownProps = _objectWithoutProperties(_ref, ['manifest', 'canvas', 'elucidateServer', 'locale']); | ||
unknownProps = _objectWithoutProperties(_ref, ['manifest', 'canvas', 'elucidateServer', 'disableCloseWarning', 'locale']); | ||
(0, _core.unknownPropertyWarning)(unknownProps); | ||
locale = locale || DEFAULT_LOCALE; | ||
_moment2.default.locale(locale); | ||
var disableCloseWarningBoolean = disableCloseWarning ? disableCloseWarning === 'true' : false; | ||
var url = window.location.href; | ||
var savedDraftList = _store2.default.get('annotation-studio/' + url) || {}; | ||
var store = (0, _redux.createStore)(_redux.reducers, [], locale); | ||
(0, _reactDom.render)(_react2.default.createElement(_core3.default, { | ||
store: store, | ||
manifest: manifest, | ||
savedDraftList: savedDraftList, | ||
elucidateServer: elucidateServer, | ||
canvas: canvas | ||
}), $el); | ||
return Promise.resolve(store); | ||
return new Promise(function (resolve, err) { | ||
try { | ||
(0, _reactDom.render)(_react2.default.createElement(_core3.default, { | ||
locale: locale, | ||
manifest: manifest, | ||
disableCloseWarning: disableCloseWarningBoolean, | ||
elucidateServer: elucidateServer, | ||
canvas: canvas, | ||
onLoadStore: resolve | ||
}), $el); | ||
} catch (e) { | ||
err(e); | ||
} | ||
}); | ||
} | ||
module.exports = exports['default']; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.DEFAULT_LOCALE = undefined; | ||
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; }; | ||
var _react = require('react'); | ||
@@ -9,4 +12,14 @@ | ||
var _reactRedux = require('react-redux'); | ||
var _components = require('@annotation-studio/components'); | ||
var _redux = require('@annotation-studio/redux'); | ||
var _lodash = require('lodash.merge'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _store = require('store'); | ||
var _store2 = _interopRequireDefault(_store); | ||
var _core = require('./core'); | ||
@@ -16,2 +29,6 @@ | ||
var _moment = require('moment/moment'); | ||
var _moment2 = _interopRequireDefault(_moment); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -27,2 +44,4 @@ | ||
var DEFAULT_LOCALE = exports.DEFAULT_LOCALE = 'en'; | ||
var CoreProvider = function (_PureComponent) { | ||
@@ -32,16 +51,89 @@ _inherits(CoreProvider, _PureComponent); | ||
function CoreProvider() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, CoreProvider); | ||
return _possibleConstructorReturn(this, _PureComponent.apply(this, arguments)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _PureComponent.call.apply(_PureComponent, [this].concat(args))), _this), _this.state = { | ||
savedDraftList: {}, | ||
storeReady: false | ||
}, _this.store = null, _this.onReady = function () { | ||
var onLoadStore = _this.props.onLoadStore; | ||
if (onLoadStore) { | ||
_this.setState(function () { | ||
onLoadStore(_this.store); | ||
return { storeReady: true }; | ||
}); | ||
} | ||
}, _this.getStore = function () { | ||
return _this.store; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
CoreProvider.prototype.render = function render() { | ||
CoreProvider.prototype.componentWillMount = function componentWillMount() { | ||
var _props = this.props, | ||
store = _props.store, | ||
props = _objectWithoutProperties(_props, ['store']); | ||
locale = _props.locale, | ||
_props$loadSavedDraft = _props.loadSavedDrafts, | ||
loadSavedDrafts = _props$loadSavedDraft === undefined ? true : _props$loadSavedDraft, | ||
savedDraftsId = _props.savedDraftsId, | ||
savedDraftList = _props.savedDraftList, | ||
customCreateStore = _props.customCreateStore, | ||
onLoadStore = _props.onLoadStore; | ||
var selectedLocale = locale || DEFAULT_LOCALE; | ||
_moment2.default.locale(selectedLocale); | ||
this.setState({ locale: selectedLocale }); | ||
if (loadSavedDrafts) { | ||
var url = savedDraftsId || window.location.href; | ||
var savedDraftListFromLS = _store2.default.get('annotation-studio/' + url) || {}; | ||
this.setState({ | ||
savedDraftList: (0, _lodash2.default)(savedDraftList || {}, savedDraftListFromLS) | ||
}); | ||
} else if (savedDraftList) { | ||
this.setState({ savedDraftList: savedDraftList }); | ||
} | ||
this.store = customCreateStore ? customCreateStore({ createStore: _redux.createStore, reducers: _redux.reducers, locale: this.state.locale }) : (0, _redux.createStore)(_redux.reducers, [], selectedLocale); | ||
}; | ||
CoreProvider.prototype.render = function render() { | ||
var _state = this.state, | ||
storeReady = _state.storeReady, | ||
savedDraftList = _state.savedDraftList, | ||
locale = _state.locale; | ||
var _props2 = this.props, | ||
plugins = _props2.plugins, | ||
behaviours = _props2.behaviours, | ||
children = _props2.children, | ||
props = _objectWithoutProperties(_props2, ['plugins', 'behaviours', 'children']); | ||
return _react2.default.createElement( | ||
_reactRedux.Provider, | ||
{ store: store }, | ||
_react2.default.createElement(_core2.default, props) | ||
_components.pluginKit.Provider, | ||
{ | ||
store: this.store, | ||
plugins: plugins, | ||
behaviours: behaviours | ||
}, | ||
_react2.default.createElement(_core2.default, _extends({}, props, { | ||
onReady: this.onReady, | ||
savedDraftList: savedDraftList, | ||
innerContent: storeReady && children ? children(_extends({}, props, { | ||
store: this.store, | ||
savedDraftList: savedDraftList, | ||
plugins: plugins, | ||
behaviours: behaviours, | ||
locale: locale | ||
})) : null, | ||
locale: locale | ||
})) | ||
); | ||
@@ -53,3 +145,2 @@ }; | ||
exports.default = CoreProvider; | ||
module.exports = exports['default']; | ||
exports.default = CoreProvider; |
@@ -10,4 +10,6 @@ 'use strict'; | ||
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; }; | ||
var fetchResourceTemplate = exports.fetchResourceTemplate = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(resource) { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(resource) { | ||
var headers, locale; | ||
@@ -23,3 +25,3 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
if (locale && process.env.NODE_ENV === 'production') { | ||
headers.set("X-Annotation-Studio-Locale", locale); | ||
headers.set('X-Annotation-Studio-Locale', locale); | ||
} | ||
@@ -42,3 +44,3 @@ | ||
console.warn('Can\'t send credentials, not same origin. Falling back.', _context.t0); | ||
console.warn("Can't send credentials, not same origin. Falling back."); | ||
_context.prev = 12; | ||
@@ -58,6 +60,5 @@ _context.next = 15; | ||
console.warn('Unable to send locale, likely CORS not available. falling back.', _context.t1); | ||
console.warn('Unable to send locale, likely CORS not available. falling back.'); | ||
_context.next = 23; | ||
return fetch('' + resource, { | ||
cache: process.env.NODE_ENV === 'production' ? 'default' : 'force-cache' | ||
@@ -78,6 +79,7 @@ }); | ||
return function fetchResourceTemplate(_x) { | ||
return _ref.apply(this, arguments); | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); | ||
exports.draftCreationHelper = draftCreationHelper; | ||
exports.getAttributes = getAttributes; | ||
@@ -103,2 +105,4 @@ exports.deferred = deferred; | ||
var _drafts = require('@annotation-studio/redux/es/actions/drafts'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -108,2 +112,62 @@ | ||
function draftCreationHelper(_ref) { | ||
var _captureModel, _ref2; | ||
var realId = _ref.id, | ||
input = _ref.input, | ||
selector = _ref.selector, | ||
captureModel = _ref.captureModel, | ||
tree = _ref.tree, | ||
path = _ref.path, | ||
motivation = _ref.motivation, | ||
_ref$isPreviewing = _ref.isPreviewing, | ||
isPreviewing = _ref$isPreviewing === undefined ? false : _ref$isPreviewing, | ||
created = _ref.created; | ||
var id = realId || (0, _drafts.generateDraftId)(); | ||
return _ref2 = {}, _ref2[captureModel] = (_captureModel = {}, _captureModel[id] = { | ||
id: id, | ||
input: input, | ||
selectors: Object.keys(input).reduce(function (acc, key) { | ||
acc[key] = {}; | ||
return acc; | ||
}, {}), | ||
template: captureModel, | ||
motivation: motivation ? motivation : { | ||
id: 'http://www.w3.org/ns/oa#tagging', | ||
label: 'oa:tagging', | ||
instance: 'tagging' | ||
}, | ||
isPublishing: false, | ||
isPreviewing: isPreviewing, | ||
selector: selector ? _extends({ | ||
type: 'madoc:boxdraw', | ||
source: { | ||
name: null, | ||
template: captureModel, | ||
scope: tree ? tree : captureModel, | ||
draft: id | ||
} | ||
}, selector) : { | ||
type: 'wholecanvasselector', | ||
source: { | ||
name: null, | ||
template: captureModel, | ||
scope: tree ? tree : captureModel, | ||
draft: id | ||
}, | ||
name: null | ||
}, | ||
fingerprint: { | ||
scope: tree ? tree : captureModel, | ||
path: path ? path : tree && tree !== captureModel ? [captureModel] : [], | ||
created: created ? created : new Date(), | ||
lifecycle: 'DRAFT_LIFECYCLE_NEW', | ||
source: 'localStorage', | ||
creator: 'you', | ||
partOf: null | ||
} | ||
}, _captureModel), _ref2; | ||
} | ||
function getAttributes($el) { | ||
@@ -129,5 +193,5 @@ var attributes = {}; | ||
function unknownPropertyWarning(unknownProps) { | ||
delete unknownProps['class']; | ||
delete unknownProps['behaviour']; | ||
delete unknownProps['style']; | ||
delete unknownProps.class; | ||
delete unknownProps.behaviour; | ||
delete unknownProps.style; | ||
if (Object.keys(unknownProps).length) { | ||
@@ -134,0 +198,0 @@ console.warn('Found unknown properties passed to component', unknownProps); |
{ | ||
"name": "@annotation-studio/plugin-core", | ||
"version": "1.0.0-pr.73cfbc15", | ||
"version": "1.0.0-pr.7943fd1a", | ||
"description": "Annotation studio core plugin", | ||
@@ -13,3 +13,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"watch": "./bin/watch", | ||
"watch": "nwb-watch-module", | ||
"build": "nwb build-web-module --copy-files", | ||
@@ -20,15 +20,16 @@ "clean": "nwb clean-module", | ||
"test:watch": "echo \"No tests in this package\"", | ||
"prepublish": "npm run build" | ||
"prepublish": "NODE_ENV=production npm run build" | ||
}, | ||
"dependencies": { | ||
"@annotation-studio/bridge": "^1.0.0-pr.73cfbc15", | ||
"@annotation-studio/redux": "^1.0.0-pr.73cfbc15" | ||
}, | ||
"peerDependencies": { | ||
"moment": "*", | ||
"react": "*", | ||
"react-dom": "*", | ||
"@annotation-studio/bridge": "1.0.0-rc.20", | ||
"@annotation-studio/components": "1.0.0-rc.20", | ||
"@annotation-studio/redux": "1.0.0-rc.20", | ||
"moment": "^2.20.1", | ||
"react": "^16.5.0", | ||
"react-dom": "^16.5.0", | ||
"react-redux": "*" | ||
}, | ||
"devDependencies": { | ||
"@annotation-studio/bridge": "1.0.0-pr.7943fd1a", | ||
"@annotation-studio/redux": "1.0.0-pr.7943fd1a", | ||
"babel-cli": "^6.24.1", | ||
@@ -40,6 +41,8 @@ "babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"extract-text-webpack-plugin": "^2.1.0", | ||
"lodash.merge": "4.6.1", | ||
"moment": "^2.20.1", | ||
"nwb": "^0.21.5", | ||
"react": "*", | ||
"react-dom": "*", | ||
"nwb-watch": "1.0.0-pr.7943fd1a", | ||
"react": "^16.5.0", | ||
"react-dom": "^16.5.0", | ||
"react-redux": "*" | ||
@@ -53,3 +56,6 @@ }, | ||
"license": "MIT", | ||
"repository": "" | ||
"repository": "", | ||
"dependencies": { | ||
"create-react-context": "^0.2.2" | ||
} | ||
} |
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
46029
25
1004
8
15
+ Addedcreate-react-context@^0.2.2
+ Added@annotation-studio/bridge@1.0.0-rc.20(transitive)
+ Added@annotation-studio/components@1.0.0-rc.20(transitive)
+ Added@annotation-studio/redux@1.0.0-rc.20(transitive)
+ Added@bokuweb/react-draggable-custom@1.4.2(transitive)
+ Added@fesk/bem-js@1.0.1(transitive)
+ Added@types/quill@1.3.10(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasap@2.0.6(transitive)
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-helper-bindify-decorators@6.24.1(transitive)
+ Addedbabel-helper-builder-binary-assignment-operator-visitor@6.24.1(transitive)
+ Addedbabel-helper-explode-assignable-expression@6.24.1(transitive)
+ Addedbabel-helper-explode-class@6.24.1(transitive)
+ Addedbabel-helper-function-name@6.24.1(transitive)
+ Addedbabel-helper-get-function-arity@6.24.1(transitive)
+ Addedbabel-helper-remap-async-to-generator@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-plugin-syntax-async-functions@6.13.0(transitive)
+ Addedbabel-plugin-syntax-async-generators@6.13.0(transitive)
+ Addedbabel-plugin-syntax-class-constructor-call@6.18.0(transitive)
+ Addedbabel-plugin-syntax-class-properties@6.13.0(transitive)
+ Addedbabel-plugin-syntax-decorators@6.13.0(transitive)
+ Addedbabel-plugin-syntax-do-expressions@6.13.0(transitive)
+ Addedbabel-plugin-syntax-dynamic-import@6.18.0(transitive)
+ Addedbabel-plugin-syntax-exponentiation-operator@6.13.0(transitive)
+ Addedbabel-plugin-syntax-export-extensions@6.13.0(transitive)
+ Addedbabel-plugin-syntax-function-bind@6.13.0(transitive)
+ Addedbabel-plugin-syntax-object-rest-spread@6.13.0(transitive)
+ Addedbabel-plugin-syntax-trailing-function-commas@6.22.0(transitive)
+ Addedbabel-plugin-transform-async-generator-functions@6.24.1(transitive)
+ Addedbabel-plugin-transform-async-to-generator@6.24.1(transitive)
+ Addedbabel-plugin-transform-class-constructor-call@6.24.1(transitive)
+ Addedbabel-plugin-transform-class-properties@6.24.1(transitive)
+ Addedbabel-plugin-transform-decorators@6.24.1(transitive)
+ Addedbabel-plugin-transform-do-expressions@6.22.0(transitive)
+ Addedbabel-plugin-transform-exponentiation-operator@6.24.1(transitive)
+ Addedbabel-plugin-transform-export-extensions@6.22.0(transitive)
+ Addedbabel-plugin-transform-function-bind@6.22.0(transitive)
+ Addedbabel-plugin-transform-object-rest-spread@6.26.0(transitive)
+ Addedbabel-preset-stage-0@6.24.1(transitive)
+ Addedbabel-preset-stage-1@6.24.1(transitive)
+ Addedbabel-preset-stage-2@6.24.1(transitive)
+ Addedbabel-preset-stage-3@6.24.1(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcan-use-dom@0.1.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedchange-emitter@0.1.6(transitive)
+ Addedclassnames@2.5.1(transitive)
+ Addedclone@2.1.2(transitive)
+ Addedcore-js@1.2.72.6.12(transitive)
+ Addedcreate-react-class@15.7.0(transitive)
+ Addedcreate-react-context@0.2.3(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddeep-equal@1.1.2(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedeventemitter3@2.0.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedfast-diff@1.1.2(transitive)
+ Addedfbjs@0.8.18(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedgoogle-maps-infobox@1.1.15(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedgud@1.0.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhoist-non-react-statics@1.2.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-date-object@1.1.0(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedlodash.debounce@4.0.8(transitive)
+ Addedlodash.isequal@4.5.0(transitive)
+ Addedlodash.isfunction@3.0.9(transitive)
+ Addedmarker-clusterer-plus@2.1.4(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedobject-is@1.1.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedopenseadragon@2.4.2(transitive)
+ Addedparchment@1.1.4(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedquill@1.3.7(transitive)
+ Addedquill-delta@3.6.3(transitive)
+ Addedreact@15.7.0(transitive)
+ Addedreact-datepicker@0.41.1(transitive)
+ Addedreact-display-name@0.2.5(transitive)
+ Addedreact-dom@15.7.016.14.0(transitive)
+ Addedreact-dom-factories@1.0.2(transitive)
+ Addedreact-draggable-custom@1.4.7(transitive)
+ Addedreact-geosuggest@2.14.1(transitive)
+ Addedreact-google-maps@6.3.0(transitive)
+ Addedreact-google-static-map@0.1.0(transitive)
+ Addedreact-onclickoutside@5.11.1(transitive)
+ Addedreact-portal@3.2.0(transitive)
+ Addedreact-prop-types-element-of-type@2.2.0(transitive)
+ Addedreact-quill@1.3.5(transitive)
+ Addedreact-resizable-box@1.8.4(transitive)
+ Addedreact-rnd@4.2.2(transitive)
+ Addedrecompose@0.23.5(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedscheduler@0.19.1(transitive)
+ Addedscriptjs@2.5.9(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtether@1.4.7(transitive)
+ Addedto-fast-properties@1.0.3(transitive)
+ Addedua-parser-js@0.7.40(transitive)
+ Addedwarning@3.0.0(transitive)
- Removed@annotation-studio/bridge@1.0.0-rc.33(transitive)
- Removed@annotation-studio/redux@1.0.0-rc.33(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedreact-dom@19.0.0(transitive)
- Removedscheduler@0.25.0(transitive)