@manifest-editor/creator-api 2.2.2-next.0.a82700e → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@iiif/helpers/vault"),t=require("@iiif/helpers/vault/actions"),n=require("react-iiif-vault"),r=require("@iiif/parser"),i=require("@manifest-editor/editor-api");function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=class{constructor(e,t){c(this,`vault`,void 0),c(this,`original`,void 0),c(this,`reference`,void 0),c(this,`resource`,void 0),this.vault=t,this.original=e,this.reference=(0,r.isSpecificResource)(e)?e.source:e,this.resource=(0,r.isSpecificResource)(e)?e:{type:`SpecificResource`,source:this.reference}}ref(){return this.reference}specificResource(){return this.resource}optionalSpecificResource(){return(0,r.isSpecificResource)(this.original)?{...this.original,source:{id:this.original.source?.id,type:this.original.source?.type}}:this.original}get(){return this.vault.get(this.resource)}};function u(e){return e.configKey??e.id}function d(e){switch(e){case`Image`:case`Video`:case`Sound`:case`Dataset`:case`Text`:case`TextualBody`:case`Composite`:case`List`:case`Choice`:case`Independents`:case`Audience`:return`ContentResource`;case`ImageService1`:case`ImageService2`:case`ImageService3`:return`Service`}return e}const f={Annotation:r.emptyAnnotation,AnnotationPage:r.emptyAnnotationPage,Canvas:r.emptyCanvas,Collection:r.emptyCollection,Manifest:r.emptyManifest,Range:r.emptyRange,ResourceProvider:r.emptyAgent,Service:r.emptyService};function p(e){let t=d(e);return f[t]||{}}function m(){return`${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`}function h(e,t,n){let i=[];if(t.length===0)return[];let a=(0,r.toRef)(e.parent),o=e.property,s=e.filter;for(let r of t)if(!(s&&(!r.tags||!r.tags.includes(s)))&&a&&o){if(r.supports.parentTypes&&!r.supports.parentTypes.includes(a.type)||r.supports.parentFields&&!r.supports.parentFields.includes(o))continue;if(r.supports.parentFieldMap){let e=r.supports.parentFieldMap[a.type];if(!e||!e.includes(o))continue}if(r.supports.disallowPainting&&e.isPainting||r.supports.onlyPainting&&!e.isPainting||r.supports.custom&&!r.supports.custom({property:o,resource:a,atIndex:e.index},n.vault))continue;let t=Object.keys(e.initialData||{}).filter(e=>e!==`skipEditingOnCreate`);if(!r.supports.initialData&&t.length!==0||r.resourceType!==e.type&&!(r.additionalTypes||[]).includes(e.type))continue;i.push(r)}return i}function g(e,t,n,r){return(i,a={})=>(typeof t!=`string`&&(a.parent={property:n,resource:t,atIndex:a?.parent?.atIndex}),e.create(r,i,a))}var _=class e{constructor(t,n){c(this,`resource`,void 0),c(this,`warnings`,[]),c(this,`errors`,[]),c(this,`partOf`,void 0),c(this,`references`,[]),c(this,`embedded`,[]),c(this,`vault`,void 0),c(this,`specificResource`,void 0),this.vault=n;let a={...t};if(a.type===`SpecificResource`){let e=a.source;this.specificResource={...a,source:{id:e.id,type:d(e.type)}},a=e}let o=Object.keys(a),s=p(a.type);for(let t of o)if(!(i.references.inlineProperties.includes(t)||!i.references.all.includes(t))){if(a.type===`Range`&&t===`items`){let e=[];for(let r of a[t]){if(r instanceof l){this.references.push(r),e.push(r);continue}let i=new l(r,n);e.push(i),a[t]=i}a[t]=e;continue}if(a.type===`Manifest`&&t===`start`){let e=a[t];if(e instanceof l){this.references.push(e);continue}let r=new l(e,n);a[t]=r;continue}if(a.type===`Annotation`&&t===`target`){let e=a[t];if(e instanceof l){this.references.push(e);continue}typeof e==`string`&&(e={id:e,type:`Canvas`});let r=new l(e,n);a[t]=r;continue}if(!i.references.single.includes(t)&&(i.references.externalProperties.includes(t)||i.references.internalProperties.includes(t))){let i=a[t]||[],o=Array.isArray(i)?i:[i],s=[];for(let t of o){if(t instanceof l){this.references.push(t),s.push(t);continue}if(t instanceof e){this.embedded.push(t),s.push(t);continue}if((0,r.isSpecificResource)(t)){let r=new e(t,n);this.embedded.push(r),s.push(r);continue}if(this.vault.get(t,{skipSelfReturn:!0})){let e=d(t.type),r=new l({id:t.id,type:e},n);this.references.push(r),s.push(r)}else{let r=new e(t,n);this.embedded.push(r),s.push(r)}}a[t]=s}}this.resource={...s,...a}}get(){return this.resource}getSpecificResource(){let e=this.ref();return(0,r.isSpecificResource)(e)?e:{type:`SpecificResource`,source:e}}ref(){return this.specificResource?this.specificResource:{id:this.resource.id,type:d(this.resource.type)}}getAllReferencedResources(){return this.references}getAllEmbeddedResources(){let e=[];for(let t of this.embedded)e.push(...t.getAllEmbeddedResources());return e.push(...this.embedded),e}getVaultResource(){let t=this.resource,n=Object.keys(t),a={};for(let r of n){if(i.references.inlineProperties.includes(r)||!i.references.all.includes(r)){a[r]=t[r];continue}if(i.references.single.includes(r)){let e=t[r];a[r]=e instanceof l?t.type===`Manifest`&&r===`start`||t.type===`Annotation`&&r===`target`?e.specificResource():e.optionalSpecificResource():t[r];continue}if(t[r]){a[r]=[];for(let n of t[r]||[]){if(t.type===`Range`&&r===`items`){n instanceof l&&(n.ref().type===`Canvas`?a[r].push(n.specificResource()):a[r].push(n.ref())),n instanceof e&&(n.ref().type===`Canvas`?a[r].push(n.getSpecificResource()):a[r].push(n.ref()));continue}n instanceof l&&a[r].push(n.optionalSpecificResource()),n instanceof e&&a[r].push(n.ref())}}}return this.partOf&&(a[r.HAS_PART]=a[r.HAS_PART]||[],a[r.HAS_PART].push(this.partOf)),a}setPartOf(e){let t=this.ref();this.partOf={id:t.id,type:d(t.type),[r.PART_OF]:e}}},v=class{constructor(e,t,r,i,a,o={}){c(this,`vault`,void 0),c(this,`previewVault`,void 0),c(this,`configs`,void 0),c(this,`options`,void 0),c(this,`config`,void 0),c(this,`creatorConfig`,void 0),c(this,`target`,void 0),c(this,`selector`,void 0),c(this,`serialisedSelector`,null),this.vault=e,this.previewVault=i,this.options=t,this.configs=r,this.creatorConfig=o,this.config=o[a]||{},this.target=this.options.target||this.options.parent?.resource;let s=this.options.initialData?.selector;this.selector=s?(0,n.annotationResponseToSelector)(s):null,this.options.initialData?.getSerialisedSelector&&(this.serialisedSelector=this.options.initialData.getSerialisedSelector())}getPreviewVault(){return this.previewVault}setSelector(e){this.selector=e}getSerialisedSelector(){if(this.serialisedSelector)return this.serialisedSelector;let e=this.selector;if(e){let t=(0,n.seraliseSupportedSelector)(e,this.options.initialData?.on);if(t)return t}return null}getTarget(){let e=this.target,t=this.getSerialisedSelector();return t?{type:`SpecificResource`,source:e,selector:t}:e}getParent(){return this.options.parent?.resource}getParentResource(){let e=this.getParent();if(e)return{type:`SpecificResource`,source:e}}generateId(e,t){return t&&t instanceof l&&(t=t.ref()),this.options.rootId&&(t={id:this.options.rootId,type:`none`}),`${(t||this.options.parent?.resource)?.id}/${e}/${m()}`}ref(e){let t=``,n=``;return typeof e==`string`?t=e:(t=e.id,n=e.type),n=this.vault.getState().iiif.mapping[t]||n||`unknown`,new l({id:t,type:n},this.vault)}embed(e){return new _(e,this.vault)}async create(e,t,n){let r=this.configs.find(t=>t.id===e);if(!r)throw Error(`Creator config ${e} not found`);return await new y(this.vault,r,t,this.configs,this.previewVault,n,this.creatorConfig).run()}},y=class{constructor(e,t,n,r,i,a,o){c(this,`resource`,null),c(this,`payload`,void 0),c(this,`vault`,void 0),c(this,`previewVault`,void 0),c(this,`definition`,void 0),c(this,`options`,void 0),c(this,`configs`,void 0),c(this,`creatorConfig`,void 0),this.vault=e,this.previewVault=i,this.definition=t,this.payload=n,this.configs=this.filterCreateConfigs(r),this.creatorConfig=o||{},this.options={targetType:a?.targetType||t.resourceType,...a||{}}}filterCreateConfigs(e){let t={};for(let n of e)t[n.id]=n;return Object.values(t)}async run(){let e=new v(this.vault,this.options,this.configs,this.previewVault,u(this.definition),this.creatorConfig),t=await this.definition.create(this.payload,e);if(Array.isArray(t)){let e=[];for(let n of t)n instanceof _?e.push(n):e.push(new _(n,this.vault));return this.resource=e,this.resource}return this.resource=t instanceof _?t:new _(t,this.vault),this.resource}getActions(){if(!this.resource)return[];let e=Array.isArray(this.resource)?this.resource:[this.resource],n=[],r={},i={};for(let a of e){this.options.parent&&a.setPartOf(this.options.parent.resource.id);let e=[...a.getAllEmbeddedResources(),a];for(let t of e){let e=t.getVaultResource();if(!e.type||!e.id)continue;let n=d(e.type);r[n]=r[n]?r[n]:{},r[n][e.id]=e,i[e.id]=n}n.push((0,t.importEntities)({entities:r})),n.push((0,t.addMappings)({mapping:i}))}return n}commit(e=[]){if(!this.resource)throw Error(`Creator has not been run`);let n=this.getActions();return this.vault.dispatch((0,t.batchActions)({actions:[...n,...e]})),Array.isArray(this.resource)?this.resource.map(e=>e.ref()):this.resource.ref()}},b=class{constructor(t,n,r,i){c(this,`configs`,void 0),c(this,`vault`,void 0),c(this,`previewVault`,void 0),c(this,`creatorConfig`,void 0),this.configs=n||[],this.vault=t,this.previewVault=r||new e.Vault,this.creatorConfig=i||{}}matchBasedOnResource(e){return h(e,this.configs||[],{vault:this.vault})}async create(e,n,r){let i=this.configs.find(t=>t.id===e);if(!i)throw Error(`Creator config ${e} not found`);if(r?.parent){if(i.supports.parentTypes&&!i.supports.parentTypes.includes(r.parent.resource.type))throw Error(`Definition ${e} does not support parent type ${r.parent.resource.type}`);if(i.supports.parentFields&&!i.supports.parentFields.includes(r.parent.property))throw Error(`Definition ${e} does not support parent field ${r.parent.property}`);if(i.supports.parentFieldMap){let t=i.supports.parentFieldMap[r.parent.resource.type];if(!t||!t.includes(r.parent.property))throw Error(`Definition ${e} does not support parent ${r.parent.property} / ${r.parent.property}`)}if(i.supports.custom&&!i.supports.custom(r.parent,this.vault))throw Error(`Definition does not support resource`)}let a=new y(this.vault,i,n,this.configs,this.previewVault,r,this.creatorConfig),o=await a.run(),s=Array.isArray(o)?o:[o],c=[];for(let e of s)r?.parent&&(r.parent.property===`start`||r.parent.property===`target`?c.push(t.entityActions.modifyEntityField({id:r.parent.resource.id,type:r.parent.resource.type,value:e.ref(),key:r.parent.property})):c.push(t.entityActions.addReference({id:r.parent.resource.id,type:r.parent.resource.type,reference:e.ref(),key:r.parent.property,index:r.parent.atIndex})));let l=a.commit(c);if(r?.parent&&i.sideEffects){for(let e of i.sideEffects)if(e.run){let t=Array.isArray(l)?l:[l];for(let n of t)await e.run(n,{vault:this.vault,options:r})}}return l}};function x(e){return e}function S(e,t,n={}){let r=e.render?r=>{let i={...r,options:{...r.options||{},initialData:{...t||{},...r.options?.initialData||{},...n||{}}}};return e.render?.(i)}:void 0;return{...e,render:r}}function C(e,t){let n=n=>t(n,e.render);return{...e,render:n}}exports.Creator=b,exports.CreatorResource=_,exports.creatorHelper=g,exports.defineCreator=x,exports.getCreatorConfigKey=u,exports.getEmptyType=p,exports.matchBasedOnResource=h,exports.randomId=m,exports.resolveType=d,exports.withCustomRender=C,exports.withInitialData=S;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@iiif/helpers/vault"),t=require("@iiif/helpers/vault/actions"),n=require("@manifest-editor/editor-api"),r=require("react-iiif-vault"),i=require("@iiif/parser");function a(e,t,r){let i=r.placeholderPosition;if(!i)return;let a=(Array.isArray(t)?t:[t]).flatMap(t=>t.type===`Annotation`?[e.get(t)]:r.parent?.resource.type===`Annotation`&&r.parent.property===`body`?[e.get(r.parent.resource)]:[]),o=e.get({id:i.canvasId,type:`Canvas`}),s=(0,n.getCanvasLayout)(e,o.id);if(s?.customised===!1&&i.placeholderId){let t=s.slots.find(e=>e.id===i.placeholderId),r=[t,...(0,n.getEmptyCanvasPlaceholders)(e,o).filter(e=>e.id!==t.id)];if(!t||a.length>r.length||t.annotationIds?.length&&t.annotationIds[0]!==i.replaceAnnotationId)throw Error(`This position is no longer available. Choose an empty position.`);{let t=s.slots.map(e=>({...e}));if(a.forEach((a,s)=>{let c=r[s],l=(0,n.getImageSize)(e,a)||i.bounds;new n.EditorInstance({vault:e,reference:a}).annotation.target.setPosition((0,n.fitWithinBounds)(l,(0,n.layoutSlotToPixels)(c.bounds,o))),t.find(e=>e.id===c.id).annotationIds=[a.id]}),i.replaceAnnotationId)for(let t of o.items)e.modifyEntityField(t,`items`,e.get(t).items.filter(e=>e.id!==i.replaceAnnotationId));(0,n.setCanvasLayout)(e,o.id,{...s,slots:t}),(0,n.syncCanvasPaintOrder)(e,o)}return}let c=[],l=Math.ceil(Math.sqrt(a.length)),u=Math.ceil(a.length/l);e.batch(()=>{a.forEach((t,r)=>{let a=t.body?.[0]&&e.get(t.body[0]),o=(0,n.getImageSize)(e,t)||(a&&(0,n.validSize)(a)?a:i.bounds),s={x:i.bounds.x+r%l*i.bounds.width/l,y:i.bounds.y+Math.floor(r/l)*i.bounds.height/u,width:i.bounds.width/l,height:i.bounds.height/u},d=new n.EditorInstance({vault:e,reference:{id:t.id,type:`Annotation`}}),f=(0,n.fitWithinBounds)(o,s);d.annotation.target.set({type:`SpecificResource`,source:{id:i.canvasId,type:`Canvas`},selector:{type:`FragmentSelector`,value:`xywh=${f.x},${f.y},${f.width},${f.height}`}}),c.push(t.id)});let t=(0,n.getCanvasLayout)(e,i.canvasId);if(i.replaceAnnotationId)for(let t of o.items)e.modifyEntityField(t,`items`,e.get(t).items.filter(e=>e.id!==i.replaceAnnotationId));t&&i.placeholderId&&c.length&&(0,n.setCanvasLayout)(e,i.canvasId,{...t,slots:t.slots.map(e=>e.id===i.placeholderId?{...e,annotationIds:[...(e.annotationIds||[]).filter(e=>e!==i.replaceAnnotationId),...c]}:e)})})}function o(e){"@babel/helpers - typeof";return o=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var u=class{constructor(e,t){l(this,`vault`,void 0),l(this,`original`,void 0),l(this,`reference`,void 0),l(this,`resource`,void 0),this.vault=t,this.original=e,this.reference=(0,i.isSpecificResource)(e)?e.source:e,this.resource=(0,i.isSpecificResource)(e)?e:{type:`SpecificResource`,source:this.reference}}ref(){return this.reference}specificResource(){return this.resource}optionalSpecificResource(){return(0,i.isSpecificResource)(this.original)?{...this.original,source:{id:this.original.source?.id,type:this.original.source?.type}}:this.original}get(){return this.vault.get(this.resource)}};function d(e){return e.configKey??e.id}function f(e){switch(e){case`Image`:case`Video`:case`Sound`:case`Dataset`:case`Text`:case`TextualBody`:case`Composite`:case`List`:case`Choice`:case`Independents`:case`Audience`:return`ContentResource`;case`ImageService1`:case`ImageService2`:case`ImageService3`:return`Service`}return e}const p={Annotation:i.emptyAnnotation,AnnotationPage:i.emptyAnnotationPage,Canvas:i.emptyCanvas,Collection:i.emptyCollection,Manifest:i.emptyManifest,Range:i.emptyRange,ResourceProvider:i.emptyAgent,Service:i.emptyService};function m(e){let t=f(e);return p[t]||{}}function h(){return`${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`}function g(e,t,n){let r=[];if(t.length===0)return[];let a=(0,i.toRef)(e.parent),o=e.property,s=e.filter;for(let i of t)if(!(s&&(!i.tags||!i.tags.includes(s)))&&a&&o){if(i.supports.parentTypes&&!i.supports.parentTypes.includes(a.type)||i.supports.parentFields&&!i.supports.parentFields.includes(o))continue;if(i.supports.parentFieldMap){let e=i.supports.parentFieldMap[a.type];if(!e||!e.includes(o))continue}if(i.supports.disallowPainting&&e.isPainting||i.supports.onlyPainting&&!e.isPainting||i.supports.custom&&!i.supports.custom({property:o,resource:a,atIndex:e.index},n.vault))continue;let t=Object.keys(e.initialData||{}).filter(e=>e!==`skipEditingOnCreate`);if(!i.supports.initialData&&t.length!==0||i.resourceType!==e.type&&!(i.additionalTypes||[]).includes(e.type))continue;r.push(i)}return r}function _(e,t,n,r){return(i,a={})=>(typeof t!=`string`&&(a.parent={property:n,resource:t,atIndex:a?.parent?.atIndex}),e.create(r,i,a))}var v=class e{constructor(t,r){l(this,`resource`,void 0),l(this,`meta`,{}),l(this,`warnings`,[]),l(this,`errors`,[]),l(this,`partOf`,void 0),l(this,`references`,[]),l(this,`embedded`,[]),l(this,`vault`,void 0),l(this,`specificResource`,void 0),this.vault=r;let a={...t};if(a.type===`SpecificResource`){let e=a.source;this.specificResource={...a,source:{id:e.id,type:f(e.type)}},a=e}let o=Object.keys(a),s=m(a.type);for(let t of o)if(!(n.references.inlineProperties.includes(t)||!n.references.all.includes(t))){if(a.type===`Range`&&t===`items`){let e=[];for(let n of a[t]){if(n instanceof u){this.references.push(n),e.push(n);continue}let i=new u(n,r);e.push(i),a[t]=i}a[t]=e;continue}if(a.type===`Manifest`&&t===`start`){let e=a[t];if(e instanceof u){this.references.push(e);continue}let n=new u(e,r);a[t]=n;continue}if(a.type===`Annotation`&&t===`target`){let e=a[t];if(e instanceof u){this.references.push(e);continue}typeof e==`string`&&(e={id:e,type:`Canvas`});let n=new u(e,r);a[t]=n;continue}if(!n.references.single.includes(t)&&(n.references.externalProperties.includes(t)||n.references.internalProperties.includes(t))){let n=a[t]||[],o=Array.isArray(n)?n:[n],s=[];for(let t of o){if(t instanceof u){this.references.push(t),s.push(t);continue}if(t instanceof e){this.embedded.push(t),s.push(t);continue}if((0,i.isSpecificResource)(t)){let n=new e(t,r);this.embedded.push(n),s.push(n);continue}if(this.vault.get(t,{skipSelfReturn:!0})){let e=f(t.type),n=new u({id:t.id,type:e},r);this.references.push(n),s.push(n)}else{let n=new e(t,r);this.embedded.push(n),s.push(n)}}a[t]=s}}this.resource={...s,...a}}get(){return this.resource}getSpecificResource(){let e=this.ref();return(0,i.isSpecificResource)(e)?e:{type:`SpecificResource`,source:e}}ref(){return this.specificResource?this.specificResource:{id:this.resource.id,type:f(this.resource.type)}}getAllReferencedResources(){return this.references}getAllEmbeddedResources(){let e=[];for(let t of this.embedded)e.push(...t.getAllEmbeddedResources());return e.push(...this.embedded),e}getVaultResource(){let t=this.resource,r=Object.keys(t),a={};for(let i of r){if(n.references.inlineProperties.includes(i)||!n.references.all.includes(i)){a[i]=t[i];continue}if(n.references.single.includes(i)){let e=t[i];a[i]=e instanceof u?t.type===`Manifest`&&i===`start`||t.type===`Annotation`&&i===`target`?e.specificResource():e.optionalSpecificResource():t[i];continue}if(t[i]){a[i]=[];for(let n of t[i]||[]){if(t.type===`Range`&&i===`items`){n instanceof u&&(n.ref().type===`Canvas`?a[i].push(n.specificResource()):a[i].push(n.ref())),n instanceof e&&(n.ref().type===`Canvas`?a[i].push(n.getSpecificResource()):a[i].push(n.ref()));continue}n instanceof u&&a[i].push(n.optionalSpecificResource()),n instanceof e&&a[i].push(n.ref())}}}return this.partOf&&(a[i.HAS_PART]=a[i.HAS_PART]||[],a[i.HAS_PART].push(this.partOf)),a}setPartOf(e){let t=this.ref();this.partOf={id:t.id,type:f(t.type),[i.PART_OF]:e}}},y=class{constructor(e,t,n,i,a,o={}){l(this,`vault`,void 0),l(this,`previewVault`,void 0),l(this,`configs`,void 0),l(this,`options`,void 0),l(this,`config`,void 0),l(this,`creatorConfig`,void 0),l(this,`target`,void 0),l(this,`selector`,void 0),l(this,`serialisedSelector`,null),this.vault=e,this.previewVault=i,this.options=t,this.configs=n,this.creatorConfig=o,this.config=o[a]||{},this.target=this.options.target||this.options.parent?.resource;let s=this.options.initialData?.selector;this.selector=s?(0,r.annotationResponseToSelector)(s):null,this.options.initialData?.getSerialisedSelector&&(this.serialisedSelector=this.options.initialData.getSerialisedSelector())}getPreviewVault(){return this.previewVault}setSelector(e){this.selector=e}getSerialisedSelector(){if(this.serialisedSelector)return this.serialisedSelector;let e=this.selector;if(e){let t=(0,r.seraliseSupportedSelector)(e,this.options.initialData?.on);if(t)return t}return null}getTarget(){let e=this.target,t=this.getSerialisedSelector();return t?{type:`SpecificResource`,source:e,selector:t}:e}getParent(){return this.options.parent?.resource}getParentResource(){let e=this.getParent();if(e)return{type:`SpecificResource`,source:e}}generateId(e,t){return t&&t instanceof u&&(t=t.ref()),this.options.rootId&&(t={id:this.options.rootId,type:`none`}),`${(t||this.options.parent?.resource)?.id}/${e}/${h()}`}ref(e){let t=``,n=``;return typeof e==`string`?t=e:(t=e.id,n=e.type),n=this.vault.getState().iiif.mapping[t]||n||`unknown`,new u({id:t,type:n},this.vault)}embed(e){return new v(e,this.vault)}async create(e,t,n){let r=this.configs.find(t=>t.id===e);if(!r)throw Error(`Creator config ${e} not found`);return await new b(this.vault,r,t,this.configs,this.previewVault,n,this.creatorConfig).run()}},b=class{constructor(e,t,n,r,i,a,o){l(this,`resource`,null),l(this,`payload`,void 0),l(this,`vault`,void 0),l(this,`previewVault`,void 0),l(this,`definition`,void 0),l(this,`options`,void 0),l(this,`configs`,void 0),l(this,`creatorConfig`,void 0),this.vault=e,this.previewVault=i,this.definition=t,this.payload=n,this.configs=this.filterCreateConfigs(r),this.creatorConfig=o||{},this.options={targetType:a?.targetType||t.resourceType,...a||{}}}filterCreateConfigs(e){let t={};for(let n of e)t[n.id]=n;return Object.values(t)}async run(){let e=new y(this.vault,this.options,this.configs,this.previewVault,d(this.definition),this.creatorConfig),t=await this.definition.create(this.payload,e);if(Array.isArray(t)){let e=[];for(let n of t)n instanceof v?e.push(n):e.push(new v(n,this.vault));return this.resource=e,this.resource}return this.resource=t instanceof v?t:new v(t,this.vault),this.resource}getActions(){if(!this.resource)return[];let e=Array.isArray(this.resource)?this.resource:[this.resource],n=[],r={},i={};for(let a of e){this.options.parent&&a.setPartOf(this.options.parent.resource.id);let e=[...a.getAllEmbeddedResources(),a];for(let a of e){let e=a.getVaultResource();for(let[r,i]of Object.entries(a.meta))for(let[a,o]of Object.entries(i))n.push(t.metaActions.setMetaValue({id:e.id,meta:r,key:a,value:o}));if(!e.type||!e.id)continue;let o=f(e.type);r[o]=r[o]?r[o]:{},r[o][e.id]=e,i[e.id]=o}n.push((0,t.importEntities)({entities:r})),n.push((0,t.addMappings)({mapping:i}))}return n}commit(e=[]){if(!this.resource)throw Error(`Creator has not been run`);let n=this.getActions();return this.vault.dispatch((0,t.batchActions)({actions:[...n,...e]})),Array.isArray(this.resource)?this.resource.map(e=>e.ref()):this.resource.ref()}},x=class{constructor(t,n,r,i){l(this,`configs`,void 0),l(this,`vault`,void 0),l(this,`previewVault`,void 0),l(this,`creatorConfig`,void 0),this.configs=n||[],this.vault=t,this.previewVault=r||new e.Vault,this.creatorConfig=i||{}}matchBasedOnResource(e){return g(e,this.configs||[],{vault:this.vault})}async create(e,r,i){let o=this.configs.find(t=>t.id===e);if(!o)throw Error(`Creator config ${e} not found`);if(i?.parent){if(o.supports.parentTypes&&!o.supports.parentTypes.includes(i.parent.resource.type))throw Error(`Definition ${e} does not support parent type ${i.parent.resource.type}`);if(o.supports.parentFields&&!o.supports.parentFields.includes(i.parent.property))throw Error(`Definition ${e} does not support parent field ${i.parent.property}`);if(o.supports.parentFieldMap){let t=o.supports.parentFieldMap[i.parent.resource.type];if(!t||!t.includes(i.parent.property))throw Error(`Definition ${e} does not support parent ${i.parent.property} / ${i.parent.property}`)}if(o.supports.custom&&!o.supports.custom(i.parent,this.vault))throw Error(`Definition does not support resource`)}let s=new b(this.vault,o,r,this.configs,this.previewVault,i,this.creatorConfig);if(i?.placeholderPosition&&!(0,n.validRectangle)(i.placeholderPosition.bounds))throw Error(`Invalid placeholder position`);let c=await s.run(),l=Array.isArray(c)?c:[c],u=[];for(let e of l)i?.parent&&(i.parent.property===`start`||i.parent.property===`target`?u.push(t.entityActions.modifyEntityField({id:i.parent.resource.id,type:i.parent.resource.type,value:e.ref(),key:i.parent.property})):u.push(t.entityActions.addReference({id:i.parent.resource.id,type:i.parent.resource.type,reference:e.ref(),key:i.parent.property,index:i.placeholderPosition?.replaceAnnotationId?this.vault.get(i.parent.resource)[i.parent.property]?.findIndex(e=>e.id===i.placeholderPosition.replaceAnnotationId):i.parent.atIndex})));let d=i?.placeholderPosition;if(d){if(d.replaceAnnotationId&&l.length!==1)throw Error(`Choose one image to replace this image. Nothing has been changed.`);let e=this.vault.get({id:d.canvasId,type:`Canvas`}),t=(0,n.getCanvasLayout)(this.vault,e.id);if(t?.customised===!1){let r=t.slots.find(e=>e.id===d.placeholderId),i=(0,n.getEmptyCanvasPlaceholders)(this.vault,e);if(!r||(d.replaceAnnotationId?r.annotationIds?.length!==1||r.annotationIds[0]!==d.replaceAnnotationId||l.length!==1:!i.some(e=>e.id===r.id)||l.length>i.length))throw Error(`Not enough empty positions. Reduce the selection or choose a larger layout. Nothing has been added.`)}(0,n.beginCanvasComposition)(this.vault,e)}let f=s.commit(u);if(i?.parent&&o.sideEffects){for(let e of o.sideEffects)if(e.run&&!(i.placeholderPosition&&e.spatial&&e.canvasInteraction)){let t=Array.isArray(f)?f:[f];for(let n of t)await e.run(n,{vault:this.vault,options:i})}}return i?.placeholderPosition&&a(this.vault,f,s.options),f}};function S(e){return e}function C(e,t,n={}){let r=e.render?r=>{let i={...r,options:{...r.options||{},initialData:{...t||{},...r.options?.initialData||{},...n||{}}}};return e.render?.(i)}:void 0;return{...e,render:r}}function w(e,t){let n=n=>t(n,e.render);return{...e,render:n}}exports.Creator=x,exports.CreatorResource=v,exports.creatorHelper=_,exports.defineCreator=S,exports.getCreatorConfigKey=d,exports.getEmptyType=m,exports.matchBasedOnResource=g,exports.randomId=h,exports.resolveType=f,exports.withCustomRender=w,exports.withInitialData=C;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["isSpecificResource","emptyAnnotation","emptyAnnotationPage","emptyCanvas","emptyCollection","emptyManifest","emptyRange","emptyAgent","emptyService","toRef","references","isSpecificResource","HAS_PART","PART_OF","annotationResponseToSelector","seraliseSupportedSelector","importEntities","addMappings","batchActions","Vault","entityActions"],"sources":["../src/ReferencedResource.ts","../src/utils.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/CreatorRuntime.ts","../src/Creator.ts","../src/creator-register.ts"],"sourcesContent":["import type { Vault } from \"@iiif/helpers/vault\";\nimport { isSpecificResource } from \"@iiif/parser\";\nimport type { Reference, SpecificResource } from \"@iiif/presentation-3\";\n\nexport class ReferencedResource {\n vault: Vault;\n original: Reference | SpecificResource;\n reference: Reference;\n resource: SpecificResource;\n constructor(reference: Reference | SpecificResource, vault: Vault) {\n this.vault = vault;\n this.original = reference;\n this.reference = isSpecificResource(reference)\n ? reference.source\n : reference;\n this.resource = isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: this.reference };\n }\n\n // @todo editable specific resource.\n\n ref() {\n return this.reference;\n }\n\n specificResource() {\n return this.resource;\n }\n\n optionalSpecificResource() {\n if (isSpecificResource(this.original)) {\n return {\n ...this.original,\n source: {\n id: this.original.source?.id,\n type: this.original.source?.type,\n },\n };\n }\n\n // @todo check if there are targets here that would make this a specific resource.\n return this.original;\n }\n\n get() {\n return this.vault.get(this.resource);\n }\n}\n","import type { Entities, Vault } from \"@iiif/helpers/vault\";\nimport {\n emptyAgent,\n emptyAnnotation,\n emptyAnnotationPage,\n emptyCanvas,\n emptyCollection,\n emptyManifest,\n emptyRange,\n emptyService,\n toRef,\n} from \"@iiif/parser\";\nimport type {\n CreatorDefinitionFilterByParent,\n IIIFManifestEditor,\n} from \"./creator-register\";\nimport type {\n AllAvailableParentTypes,\n CreatableResource,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n GetCreatorPayload,\n GetSupportedResourceFields,\n ResolvedCreatorReturn,\n} from \"./types\";\n\nexport function getCreatorConfigKey(definition: CreatorDefinition): string {\n return definition.configKey ?? definition.id;\n}\n\nexport function resolveType(type: string): keyof Entities {\n switch (type) {\n case \"Image\":\n case \"Video\":\n case \"Sound\":\n case \"Dataset\":\n case \"Text\":\n case \"TextualBody\":\n case \"Composite\":\n case \"List\":\n case \"Choice\":\n case \"Independents\":\n case \"Audience\":\n return \"ContentResource\";\n case \"ImageService1\":\n case \"ImageService2\":\n case \"ImageService3\":\n return \"Service\";\n }\n\n return type as any;\n}\n\nconst emptyTypes = {\n Annotation: emptyAnnotation,\n AnnotationPage: emptyAnnotationPage,\n Canvas: emptyCanvas,\n Collection: emptyCollection,\n Manifest: emptyManifest,\n Range: emptyRange,\n ResourceProvider: emptyAgent,\n Service: emptyService,\n};\n\nexport function getEmptyType(type: string): any {\n const key = resolveType(type);\n return emptyTypes[key as \"Manifest\"] || {};\n}\n\nexport function randomId() {\n return `${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`;\n}\n\nexport function matchBasedOnResource(\n resource: CreatableResource,\n list: CreatorDefinition[],\n options: { vault: Vault },\n): CreatorDefinition[] {\n const supported = [];\n if (list.length === 0) {\n return [];\n }\n const parent = toRef(resource.parent);\n const property = resource.property;\n const filter = resource.filter;\n\n for (const def of list) {\n if (filter) {\n if (!def.tags) continue;\n if (!def.tags.includes(filter)) {\n continue;\n }\n }\n\n if (parent && property) {\n if (def.supports.parentTypes) {\n if (!def.supports.parentTypes.includes(parent.type)) {\n continue;\n }\n }\n if (def.supports.parentFields) {\n if (!def.supports.parentFields.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.parentFieldMap) {\n const type = def.supports.parentFieldMap[parent.type];\n if (!type || !type.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.disallowPainting && resource.isPainting) {\n continue;\n }\n if (def.supports.onlyPainting && !resource.isPainting) {\n continue;\n }\n\n if (def.supports.custom) {\n const isValid = def.supports.custom(\n { property, resource: parent, atIndex: resource.index },\n options.vault,\n );\n if (!isValid) {\n continue;\n }\n }\n\n const initialDataKeys = Object.keys(resource.initialData || {}).filter(\n (key) => key !== \"skipEditingOnCreate\",\n );\n\n if (!def.supports.initialData && initialDataKeys.length !== 0) {\n continue;\n }\n\n if (def.resourceType !== resource.type) {\n if (!(def.additionalTypes || []).includes(resource.type)) {\n continue;\n }\n }\n supported.push(def);\n }\n }\n\n return supported;\n}\n\nexport function creatorHelper<\n const ResourceType extends AllAvailableParentTypes,\n const Parent extends { id: string; type: ResourceType },\n const ResourceField extends GetSupportedResourceFields<ResourceType>,\n const CID extends CreatorDefinitionFilterByParent<\n ResourceType,\n ResourceField\n >[\"id\"],\n Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>,\n Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>,\n>(\n ctx: CreatorFunctionContext,\n parent: Parent | ResourceType,\n property: ResourceField,\n definition: CID,\n): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return> {\n return (payload: Payload, options = {}) => {\n if (typeof parent !== \"string\") {\n options.parent = {\n property,\n resource: parent,\n atIndex: options?.parent?.atIndex,\n };\n }\n return ctx.create(definition, payload, options) as any;\n };\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport { HAS_PART, isSpecificResource, PART_OF } from \"@iiif/parser\";\nimport type { SpecificResource } from \"@iiif/presentation-3\";\nimport { references } from \"@manifest-editor/editor-api\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport { getEmptyType, resolveType } from \"./utils\";\n\nexport class CreatorResource {\n resource: any;\n warnings: string[] = [];\n errors: string[] = [];\n partOf: any;\n references: ReferencedResource[] = [];\n embedded: CreatorResource[] = [];\n vault: Vault;\n specificResource?: SpecificResource;\n\n constructor(inputData: any, vault: Vault) {\n this.vault = vault;\n let data = { ...inputData };\n\n if (data.type === \"SpecificResource\") {\n const source = data.source;\n this.specificResource = {\n ...data,\n source: { id: source.id, type: resolveType(source.type) },\n };\n data = source;\n }\n\n const properties = Object.keys(data);\n const defaultType = getEmptyType(data.type);\n\n for (const key of properties) {\n // These properties are NOT references and can be just included normally.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n continue;\n }\n\n if (data.type === \"Range\" && key === \"items\") {\n const newRange: any = [];\n for (const range of data[key]) {\n if (range instanceof ReferencedResource) {\n this.references.push(range);\n newRange.push(range);\n continue;\n }\n\n const rangeRef = new ReferencedResource(range, vault);\n newRange.push(rangeRef);\n data[key] = rangeRef;\n }\n\n data[key] = newRange;\n continue;\n }\n\n if (data.type === \"Manifest\" && key === \"start\") {\n const start = data[key];\n\n if (start instanceof ReferencedResource) {\n this.references.push(start);\n continue;\n }\n\n const startRef = new ReferencedResource(start, vault);\n data[key] = startRef;\n continue;\n }\n\n if (data.type === \"Annotation\" && key === \"target\") {\n let target = data[key];\n\n if (target instanceof ReferencedResource) {\n this.references.push(target);\n continue;\n }\n\n if (typeof target === \"string\") {\n target = { id: target, type: \"Canvas\" };\n }\n\n const targetRef = new ReferencedResource(target, vault);\n data[key] = targetRef;\n continue;\n }\n\n // @todo Handle single item cases. (not caught by the above 2 cases)\n if (references.single.includes(key as any)) {\n continue;\n }\n\n // This property SHOULD already be in the Vault OR an instance of creator resource.\n if (\n references.externalProperties.includes(key as any) ||\n references.internalProperties.includes(key as any)\n ) {\n const _items = (data[key] || []) as any[];\n const items = Array.isArray(_items) ? _items : [_items];\n const newItems: any[] = [];\n for (const item of items) {\n if (item instanceof ReferencedResource) {\n this.references.push(item);\n newItems.push(item);\n continue;\n }\n if (item instanceof CreatorResource) {\n this.embedded.push(item);\n newItems.push(item);\n continue;\n }\n\n // A SpecificResource carries its selector and source inline. Vault.get()\n // resolves it to its source, so an existing source must not turn the\n // wrapper into a plain reference.\n if (isSpecificResource(item)) {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n continue;\n }\n\n const exists = this.vault.get(item, { skipSelfReturn: true });\n if (exists) {\n const type = resolveType(item.type);\n const newItem = new ReferencedResource(\n { id: item.id, type },\n vault,\n );\n this.references.push(newItem);\n newItems.push(newItem);\n } else {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n }\n }\n data[key] = newItems;\n }\n }\n this.resource = { ...defaultType, ...data };\n }\n\n // This is what is returned from the creator instance\n get() {\n return this.resource;\n }\n\n getSpecificResource() {\n const reference = this.ref();\n return isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: reference };\n }\n\n ref() {\n if (this.specificResource) {\n return this.specificResource;\n }\n\n return {\n id: this.resource.id,\n type: resolveType(this.resource.type as string) as any,\n };\n }\n\n getAllReferencedResources() {\n return this.references;\n }\n\n getAllEmbeddedResources(): CreatorResource[] {\n const allEmbedded = [];\n for (const resource of this.embedded) {\n allEmbedded.push(...resource.getAllEmbeddedResources());\n }\n allEmbedded.push(...this.embedded);\n return allEmbedded;\n }\n\n getVaultResource() {\n const resource = this.resource;\n const properties = Object.keys(resource);\n const newResource: any = {};\n\n for (const key of properties) {\n // Skip these, they are just normal inline values.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n newResource[key] = resource[key];\n continue;\n }\n\n if (references.single.includes(key as any)) {\n const ref = resource[key];\n if (ref instanceof ReferencedResource) {\n // These MUST be specific resources.\n if (\n (resource.type === \"Manifest\" && key === \"start\") ||\n (resource.type === \"Annotation\" && key === \"target\")\n ) {\n newResource[key] = ref.specificResource();\n } else {\n newResource[key] = ref.optionalSpecificResource();\n }\n } else {\n newResource[key] = resource[key];\n }\n continue;\n }\n\n if (resource[key]) {\n newResource[key] = [];\n for (const item of resource[key] || []) {\n if (resource.type === \"Range\" && key === \"items\") {\n if (item instanceof ReferencedResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.specificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n if (item instanceof CreatorResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.getSpecificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n continue;\n }\n\n if (item instanceof ReferencedResource) {\n newResource[key].push(item.optionalSpecificResource());\n }\n if (item instanceof CreatorResource) {\n newResource[key].push(item.ref());\n }\n }\n }\n }\n\n if (this.partOf) {\n newResource[HAS_PART] = newResource[HAS_PART] || [];\n newResource[HAS_PART].push(this.partOf);\n }\n\n return newResource;\n }\n\n setPartOf(id: string) {\n const ref = this.ref();\n this.partOf = {\n id: ref.id,\n type: resolveType(ref.type),\n [PART_OF]: id,\n };\n }\n}\n","import type { SupportedSelector } from \"@iiif/helpers\";\nimport type { Vault } from \"@iiif/helpers/vault\";\nimport type {\n Reference,\n Selector,\n SpecificResource,\n} from \"@iiif/presentation-3\";\nimport {\n type AnnotationResponse,\n annotationResponseToSelector,\n seraliseSupportedSelector,\n} from \"react-iiif-vault\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport type {\n CreatorConfig,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n} from \"./types\";\nimport { randomId } from \"./utils\";\n\nexport class CreatorInstance implements CreatorFunctionContext {\n vault: Vault;\n previewVault: Vault;\n configs: CreatorDefinition[];\n options: CreatorOptions;\n config: Record<string, unknown>;\n creatorConfig: CreatorConfig;\n\n target: CreatorOptions[\"target\"];\n selector: SupportedSelector | undefined | null;\n serialisedSelector: { type: string; value: string } | null = null;\n\n constructor(\n vault: Vault,\n options: CreatorOptions,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n configKey: string,\n creatorConfig: CreatorConfig = {},\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.options = options;\n this.configs = createConfigs;\n this.creatorConfig = creatorConfig;\n this.config = creatorConfig[configKey] || {};\n this.target = this.options.target || this.options.parent?.resource;\n const response: AnnotationResponse = this.options.initialData?.selector;\n this.selector = response ? annotationResponseToSelector(response) : null;\n if (this.options.initialData?.getSerialisedSelector) {\n this.serialisedSelector =\n this.options.initialData.getSerialisedSelector();\n }\n }\n\n getPreviewVault() {\n return this.previewVault;\n }\n\n setSelector(selector: SupportedSelector) {\n this.selector = selector;\n }\n\n getSerialisedSelector() {\n if (this.serialisedSelector) {\n return this.serialisedSelector;\n }\n const selector = this.selector;\n if (selector) {\n const serialisedSelector = seraliseSupportedSelector(\n selector,\n this.options.initialData?.on,\n );\n if (serialisedSelector) {\n return serialisedSelector;\n }\n }\n return null;\n }\n\n getTarget(): SpecificResource | Reference | undefined {\n const target = this.target;\n const serialisedSelector = this.getSerialisedSelector();\n\n if (serialisedSelector) {\n return {\n type: \"SpecificResource\",\n source: target,\n selector: serialisedSelector as Selector,\n };\n }\n\n return target;\n }\n\n getParent(): Reference | undefined {\n return this.options.parent?.resource;\n }\n getParentResource(): SpecificResource | undefined {\n const parent = this.getParent();\n if (parent) {\n return {\n type: \"SpecificResource\",\n source: parent,\n };\n }\n }\n\n generateId(type: string, parent?: Reference | ReferencedResource) {\n if (parent && parent instanceof ReferencedResource) {\n parent = parent.ref();\n }\n if (this.options.rootId) {\n parent = { id: this.options.rootId, type: \"none\" };\n }\n\n return `${(parent || this.options.parent?.resource)?.id}/${type}/${randomId()}`;\n }\n\n ref(idOrRef: string | Reference) {\n let id = \"\";\n let type = \"\";\n\n if (typeof idOrRef === \"string\") {\n id = idOrRef;\n } else {\n id = idOrRef.id;\n type = idOrRef.type;\n }\n\n const state = this.vault.getState();\n const realType = state.iiif.mapping[id];\n\n if (!realType) {\n type = type || \"unknown\";\n } else {\n type = realType;\n }\n\n return new ReferencedResource({ id, type }, this.vault);\n }\n\n embed(data: any) {\n return new CreatorResource(data, this.vault);\n }\n\n async create(\n definition: string,\n payload: any,\n options?: Partial<CreatorOptions>,\n ) {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig,\n );\n\n return (await runtime.run()) as any;\n }\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport {\n addMappings,\n batchActions,\n importEntities,\n} from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { CreatorInstance } from \"./CreatorInstance\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport type { CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { getCreatorConfigKey, resolveType } from \"./utils\";\n\nexport class CreatorRuntime {\n // This will hold state for the creation process\n resource: CreatorResource | Array<CreatorResource> | null = null;\n payload: any;\n vault: Vault;\n previewVault: Vault;\n definition: CreatorDefinition;\n options: CreatorOptions;\n configs: CreatorDefinition[];\n creatorConfig: CreatorConfig;\n\n constructor(\n vault: Vault,\n definition: CreatorDefinition,\n payload: any,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n options?: Partial<CreatorOptions>,\n creatorConfig?: CreatorConfig,\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.definition = definition;\n this.payload = payload;\n this.configs = this.filterCreateConfigs(createConfigs);\n this.creatorConfig = creatorConfig || {};\n this.options = {\n targetType: options?.targetType || definition.resourceType,\n ...(options || {}),\n };\n }\n\n filterCreateConfigs(configs: CreatorDefinition[]) {\n const indexedByIdLastWins: Record<string, CreatorDefinition> = {};\n for (const config of configs) {\n indexedByIdLastWins[config.id] = config;\n }\n return Object.values(indexedByIdLastWins);\n }\n\n async run(): Promise<CreatorResource | CreatorResource[]> {\n const instance = new CreatorInstance(\n this.vault,\n this.options,\n this.configs,\n this.previewVault,\n getCreatorConfigKey(this.definition),\n this.creatorConfig,\n );\n const result = await this.definition.create(this.payload, instance);\n\n // Could be an array.\n if (Array.isArray(result)) {\n const results: CreatorResource[] = [];\n for (const item of result) {\n if (item instanceof CreatorResource) {\n results.push(item);\n } else {\n results.push(new CreatorResource(item, this.vault));\n }\n }\n this.resource = results;\n\n return this.resource;\n }\n\n if (result instanceof CreatorResource) {\n this.resource = result;\n } else {\n this.resource = new CreatorResource(result, this.vault);\n }\n\n return this.resource;\n }\n\n getActions() {\n if (!this.resource) {\n return [];\n }\n\n const allResources = Array.isArray(this.resource)\n ? this.resource\n : [this.resource];\n\n const actions = [];\n\n const resources: any = {};\n const mapping: any = {};\n\n for (const resource of allResources) {\n if (this.options.parent) {\n resource.setPartOf(this.options.parent.resource.id);\n }\n\n const embedded = resource.getAllEmbeddedResources();\n\n const allItems = [...embedded, resource];\n\n for (const item of allItems) {\n const resource = item.getVaultResource();\n if (!resource.type || !resource.id) {\n continue;\n }\n const type = resolveType(resource.type);\n resources[type] = resources[type] ? resources[type] : {};\n resources[type][resource.id] = resource;\n mapping[resource.id] = type;\n }\n\n actions.push(importEntities({ entities: resources }));\n actions.push(addMappings({ mapping }));\n }\n\n return actions as any[];\n }\n\n commit(afterActions: any[] = []): Reference | Reference[] {\n if (!this.resource) {\n throw new Error(\"Creator has not been run\");\n }\n\n const actions = this.getActions();\n this.vault.dispatch(\n batchActions({ actions: [...actions, ...afterActions] }),\n );\n\n if (Array.isArray(this.resource)) {\n return this.resource.map((resource) => resource.ref() as Reference);\n }\n\n return this.resource.ref() as Reference;\n }\n}\n","import { Vault } from \"@iiif/helpers/vault\";\nimport { entityActions } from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport type { CreatableResource, CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { matchBasedOnResource } from \"./utils\";\n\nexport class Creator {\n configs: CreatorDefinition[];\n vault: Vault;\n previewVault: Vault;\n creatorConfig: CreatorConfig;\n\n constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault, creatorConfig?: CreatorConfig) {\n this.configs = configs || [];\n this.vault = vault;\n this.previewVault = previewVault || new Vault();\n this.creatorConfig = creatorConfig || {};\n }\n\n matchBasedOnResource(resource: CreatableResource) {\n return matchBasedOnResource(resource, this.configs || [], { vault: this.vault });\n }\n\n async create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference | Reference[]> {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n if (options?.parent) {\n if (foundDefinition.supports.parentTypes) {\n if (!foundDefinition.supports.parentTypes.includes(options.parent.resource.type)) {\n throw new Error(`Definition ${definition} does not support parent type ${options.parent.resource.type}`);\n }\n }\n if (foundDefinition.supports.parentFields) {\n if (!foundDefinition.supports.parentFields.includes(options.parent.property)) {\n throw new Error(`Definition ${definition} does not support parent field ${options.parent.property}`);\n }\n }\n\n if (foundDefinition.supports.parentFieldMap) {\n const type = foundDefinition.supports.parentFieldMap[options.parent.resource.type];\n if (!type || !type.includes(options.parent.property)) {\n throw new Error(\n `Definition ${definition} does not support parent ${options.parent.property} / ${options.parent.property}`,\n );\n }\n }\n if (foundDefinition.supports.custom) {\n const isValid = foundDefinition.supports.custom(options.parent, this.vault);\n if (!isValid) {\n throw new Error(`Definition does not support resource`);\n }\n }\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig,\n );\n\n const run = await runtime.run();\n const allResources = Array.isArray(run) ? run : [run];\n const afterActions: any[] = [];\n\n for (const resource of allResources) {\n if (options?.parent) {\n if (options.parent.property === \"start\" || options.parent.property === \"target\") {\n afterActions.push(\n entityActions.modifyEntityField({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n value: resource.ref(),\n key: options.parent.property,\n }),\n );\n } else {\n afterActions.push(\n entityActions.addReference({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n reference: resource.ref(),\n key: options.parent.property,\n index: options.parent.atIndex,\n }),\n );\n }\n }\n }\n\n const result = runtime.commit(afterActions);\n\n // Only run side effects if there is a parent\n if (options?.parent) {\n if (foundDefinition.sideEffects) {\n for (const sideEffect of foundDefinition.sideEffects) {\n if (sideEffect.run) {\n const allResults = Array.isArray(result) ? result : [result];\n for (const item of allResults) {\n // @todo we need more in the ctx (like parent/target where this is to be added.)\n await sideEffect.run(item, { vault: this.vault, options: options as any });\n }\n }\n }\n }\n }\n\n return result;\n }\n}\n","import type {\n AllAvailableParentTypes,\n AllParentTypes,\n AllProperties,\n CreatorContext,\n CreatorDefinition,\n SpecificCreatorDefinition,\n} from \"./types\";\n\n// Want to enable the following APIs.\n//\n// const createImage = useCreator(\n// resource,\n// \"thumbnail\",\n// \"@manifest-editor/image-url-creator\"\n// );\n//\n// createImage({ url: 'https://example.org/image.jpg' });\n//\n// These should be constructed from an array of creators.\n// UseCreator<Resource, ResourceField, CreatorId> -> CreatorPayload\n//\n// But then also:\n// await manifestEditor.descriptive.thumbnail.create(\"@manifest-editor/image-url-creator\", {\n// url: \"https://example.org/image.jpg\",\n// });\n//\n// So essentially, I think we want to create a type that is roughly structured like this:\n// {\n// Manifest: {\n// thumbnail: {\n// \"@manifest-editor/image-url-creator\": {\n// url: string;\n// }\n// }\n// }\n// }\n// Although it would include _all_ available creators.\n// Then the helpers would be fairly easy to implement.\n//\n// Here the creator definition (might need to change) for this:\n\nexport function defineCreator<\n const Payload = any,\n const ID = Readonly<string>,\n const ResourceType extends AllAvailableParentTypes = never,\n const AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [],\n const AllResourceTypes = [ResourceType, ...AdditionalResourceTypes],\n const SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes,\n const SupportsParentFields extends Array<AllProperties> = [],\n const CreateReturnType = any,\n>(\n options: SpecificCreatorDefinition<\n Payload,\n ID,\n ResourceType,\n AdditionalResourceTypes,\n AllResourceTypes,\n SupportsParentTypes,\n SupportsParentFields,\n CreateReturnType\n >\n) {\n return options;\n}\n\nexport function withInitialData<T extends CreatorDefinition>(\n creator: T,\n data: Record<string, any>,\n overrides: Record<string, any> = {}\n): T {\n const render = creator.render\n ? (ctx: CreatorContext<any>) => {\n const newContext: CreatorContext = {\n ...ctx,\n options: {\n ...(ctx.options || {}),\n initialData: {\n ...(data || {}),\n ...(ctx.options?.initialData || {}),\n ...(overrides || {}),\n },\n },\n };\n return creator.render?.(newContext);\n }\n : undefined;\n\n return { ...creator, render } as T;\n}\n\nexport function withCustomRender<T extends CreatorDefinition>(\n creator: T,\n render: (ctx: CreatorContext<any>, originalRender: (ctx: CreatorContext<any>) => React.ReactNode) => React.ReactNode\n): T {\n const newRender = (ctx: CreatorContext<any>) => {\n return render(ctx, creator.render as any);\n };\n\n return { ...creator, render: newRender } as T;\n}\n\nexport declare namespace IIIFManifestEditor {\n interface CreatorDefinitions {}\n}\n\nexport type ExtractCreatorGenerics<T extends CreatorDefinition> =\n T extends SpecificCreatorDefinition<\n infer Payload,\n infer ID,\n infer ResourceType,\n infer AdditionalResourceTypes,\n infer AllResourceTypes,\n infer SupportsParentTypes,\n infer SupportsParentFields,\n infer CreateReturnType\n >\n ? {\n Payload: Payload;\n ID: ID;\n ResourceType: ResourceType;\n AdditionalResourceTypes: AdditionalResourceTypes;\n AllResourceTypes: AllResourceTypes;\n SupportsParentTypes: SupportsParentTypes;\n SupportsParentFields: SupportsParentFields;\n CreateReturnType: CreateReturnType;\n }\n : never;\n\ntype CreatorSupportsParentTypes<T, Type extends AllAvailableParentTypes> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentTypes\"] extends never\n ? false\n : HelperInArray<Type, ExtractCreatorGenerics<T>[\"SupportsParentTypes\"]>\n : false;\n\ntype CreatorSupportsParentFields<T, Field extends AllProperties> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentFields\"] extends never\n ? false\n : HelperInArray<Field, ExtractCreatorGenerics<T>[\"SupportsParentFields\"]>\n : false;\n\ntype CreatorSupportsParent<\n T,\n Type extends AllAvailableParentTypes,\n Field extends AllProperties,\n> = T extends CreatorDefinition\n ? CreatorSupportsParentTypes<T, Type> extends true\n ? CreatorSupportsParentFields<T, Field> extends true\n ? true\n : false\n : false\n : false;\n\ntype HelperInArray<ToFind, Array extends readonly any[]> = Array extends readonly [infer Head, ...infer Tail]\n ? Head extends ToFind\n ? true\n : HelperInArray<ToFind, Tail>\n : false;\n\nexport type CreatorDefinitionFilterByParent<\n Type extends AllAvailableParentTypes,\n Field extends AllProperties = AllProperties,\n CD extends IIIFManifestEditor.CreatorDefinitions = IIIFManifestEditor.CreatorDefinitions,\n> = {\n [K in keyof CD]: CreatorSupportsParent<CD[K], Type, Field> extends true ? CD[K] : never;\n}[keyof CD];\n"],"mappings":"s6BAIA,IAAa,EAAb,KAAgC,CAK9B,YAAY,EAAyC,EAAc,CAJnE,EAAA,KAAA,QAAA,IAAA,EAAA,EACA,EAAA,KAAA,WAAA,IAAA,EAAA,EACA,EAAA,KAAA,YAAA,IAAA,EAAA,EACA,EAAA,KAAA,WAAA,IAAA,EAAA,EAEE,KAAK,MAAQ,EACb,KAAK,SAAW,EAChB,KAAK,WAAA,EAAYA,EAAAA,mBAAAA,CAAmB,CAAS,EACzC,EAAU,OACV,EACJ,KAAK,UAAA,EAAWA,EAAAA,mBAAAA,CAAmB,CAAS,EACxC,EACA,CAAE,KAAM,mBAAoB,OAAQ,KAAK,SAAU,CACzD,CAIA,KAAM,CACJ,OAAO,KAAK,SACd,CAEA,kBAAmB,CACjB,OAAO,KAAK,QACd,CAEA,0BAA2B,CAYzB,OAXA,EAAIA,EAAAA,mBAAAA,CAAmB,KAAK,QAAQ,EAC3B,CACL,GAAG,KAAK,SACR,OAAQ,CACN,GAAI,KAAK,SAAS,QAAQ,GAC1B,KAAM,KAAK,SAAS,QAAQ,IAC9B,CACF,EAIK,KAAK,QACd,CAEA,KAAM,CACJ,OAAO,KAAK,MAAM,IAAI,KAAK,QAAQ,CACrC,CACF,ECrBA,SAAgB,EAAoB,EAAuC,CACzE,OAAO,EAAW,WAAa,EAAW,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AS,CAAU,CACpC,EACA,IAAA,GAEJ,MAAO,CAAE,GAAG,EAAS,QAAO,CAC9B,CAEA,SAAgB,EACd,EACA,EACG,CACH,IAAM,EAAa,GACV,EAAO,EAAK,EAAQ,MAAa,EAG1C,MAAO,CAAE,GAAG,EAAS,OAAQ,CAAU,CACzC"}
1
+ {"version":3,"file":"index.cjs","names":["getCanvasLayout","getEmptyCanvasPlaceholders","getImageSize","EditorInstance","fitWithinBounds","layoutSlotToPixels","validSize","isSpecificResource","emptyAnnotation","emptyAnnotationPage","emptyCanvas","emptyCollection","emptyManifest","emptyRange","emptyAgent","emptyService","toRef","references","isSpecificResource","HAS_PART","PART_OF","annotationResponseToSelector","seraliseSupportedSelector","metaActions","importEntities","addMappings","batchActions","Vault","validRectangle","entityActions","getCanvasLayout","getEmptyCanvasPlaceholders"],"sources":["../src/placeholder-position.ts","../src/ReferencedResource.ts","../src/utils.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/CreatorRuntime.ts","../src/Creator.ts","../src/creator-register.ts"],"sourcesContent":["import type { Vault } from \"@iiif/helpers/vault\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport {\n EditorInstance,\n fitWithinBounds,\n getCanvasLayout,\n getImageSize,\n setCanvasLayout,\n validSize,\n getEmptyCanvasPlaceholders,\n layoutSlotToPixels,\n syncCanvasPaintOrder,\n} from \"@manifest-editor/editor-api\";\nimport type { CreatorOptions } from \"./types\";\n\n/** A placement hint fits a resource inside a box; an explicit selector remains an exact target. */\nexport function placeCreatedResources(vault: Vault, result: Reference | Reference[], options: CreatorOptions) {\n const placement = options.placeholderPosition;\n if (!placement) return;\n const refs = Array.isArray(result) ? result : [result];\n const annotations = refs.flatMap((ref) => {\n if (ref.type === \"Annotation\") return [vault.get(ref)];\n if (options.parent?.resource.type === \"Annotation\" && options.parent.property === \"body\")\n return [vault.get(options.parent.resource)];\n return [];\n });\n const canvas = vault.get<any>({ id: placement.canvasId, type: \"Canvas\" });\n const state = getCanvasLayout(vault, canvas.id);\n if (state?.customised === false && placement.placeholderId) {\n const first = state.slots.find((slot) => slot.id === placement.placeholderId)!;\n const empty = getEmptyCanvasPlaceholders(vault, canvas).filter((slot) => slot.id !== first.id);\n const positions = [first, ...empty];\n if (\n !first ||\n annotations.length > positions.length ||\n (first.annotationIds?.length && first.annotationIds[0] !== placement.replaceAnnotationId)\n )\n throw new Error(\"This position is no longer available. Choose an empty position.\");\n {\n const slots = state.slots.map((slot) => ({ ...slot }));\n annotations.forEach((annotation, index) => {\n const slot = positions[index]!;\n const size = getImageSize(vault, annotation) || placement.bounds;\n new EditorInstance({ vault, reference: annotation }).annotation.target.setPosition(\n fitWithinBounds(size, layoutSlotToPixels(slot.bounds, canvas))\n );\n slots.find((item) => item.id === slot.id)!.annotationIds = [annotation.id];\n });\n if (placement.replaceAnnotationId)\n for (const page of canvas.items)\n vault.modifyEntityField(\n page,\n \"items\",\n vault.get(page).items.filter((ref: any) => ref.id !== placement.replaceAnnotationId)\n );\n setCanvasLayout(vault, canvas.id, { ...state, slots });\n syncCanvasPaintOrder(vault, canvas);\n }\n return;\n }\n const placed: string[] = [];\n const columns = Math.ceil(Math.sqrt(annotations.length));\n const rows = Math.ceil(annotations.length / columns);\n vault.batch(() => {\n annotations.forEach((annotation, i) => {\n const body = annotation.body?.[0] && vault.get<any>(annotation.body[0]);\n const size = getImageSize(vault, annotation) || (body && validSize(body) ? body : placement.bounds);\n const bounds = {\n x: placement.bounds.x + ((i % columns) * placement.bounds.width) / columns,\n y: placement.bounds.y + (Math.floor(i / columns) * placement.bounds.height) / rows,\n width: placement.bounds.width / columns,\n height: placement.bounds.height / rows,\n };\n const editor = new EditorInstance({ vault, reference: { id: annotation.id, type: \"Annotation\" } });\n const position = fitWithinBounds(size, bounds);\n editor.annotation.target.set({\n type: \"SpecificResource\",\n source: { id: placement.canvasId, type: \"Canvas\" },\n selector: {\n type: \"FragmentSelector\",\n value: `xywh=${position.x},${position.y},${position.width},${position.height}`,\n },\n });\n placed.push(annotation.id);\n });\n const state = getCanvasLayout(vault, placement.canvasId);\n if (placement.replaceAnnotationId)\n for (const page of canvas.items)\n vault.modifyEntityField(\n page,\n \"items\",\n vault.get(page).items.filter((ref: any) => ref.id !== placement.replaceAnnotationId)\n );\n if (state && placement.placeholderId && placed.length)\n setCanvasLayout(vault, placement.canvasId, {\n ...state,\n slots: state.slots.map((slot) =>\n slot.id === placement.placeholderId\n ? {\n ...slot,\n annotationIds: [\n ...(slot.annotationIds || []).filter((id) => id !== placement.replaceAnnotationId),\n ...placed,\n ],\n }\n : slot\n ),\n });\n });\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport { isSpecificResource } from \"@iiif/parser\";\nimport type { Reference, SpecificResource } from \"@iiif/presentation-3\";\n\nexport class ReferencedResource {\n vault: Vault;\n original: Reference | SpecificResource;\n reference: Reference;\n resource: SpecificResource;\n constructor(reference: Reference | SpecificResource, vault: Vault) {\n this.vault = vault;\n this.original = reference;\n this.reference = isSpecificResource(reference)\n ? reference.source\n : reference;\n this.resource = isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: this.reference };\n }\n\n // @todo editable specific resource.\n\n ref() {\n return this.reference;\n }\n\n specificResource() {\n return this.resource;\n }\n\n optionalSpecificResource() {\n if (isSpecificResource(this.original)) {\n return {\n ...this.original,\n source: {\n id: this.original.source?.id,\n type: this.original.source?.type,\n },\n };\n }\n\n // @todo check if there are targets here that would make this a specific resource.\n return this.original;\n }\n\n get() {\n return this.vault.get(this.resource);\n }\n}\n","import type { Entities, Vault } from \"@iiif/helpers/vault\";\nimport {\n emptyAgent,\n emptyAnnotation,\n emptyAnnotationPage,\n emptyCanvas,\n emptyCollection,\n emptyManifest,\n emptyRange,\n emptyService,\n toRef,\n} from \"@iiif/parser\";\nimport type {\n CreatorDefinitionFilterByParent,\n IIIFManifestEditor,\n} from \"./creator-register\";\nimport type {\n AllAvailableParentTypes,\n CreatableResource,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n GetCreatorPayload,\n GetSupportedResourceFields,\n ResolvedCreatorReturn,\n} from \"./types\";\n\nexport function getCreatorConfigKey(definition: CreatorDefinition): string {\n return definition.configKey ?? definition.id;\n}\n\nexport function resolveType(type: string): keyof Entities {\n switch (type) {\n case \"Image\":\n case \"Video\":\n case \"Sound\":\n case \"Dataset\":\n case \"Text\":\n case \"TextualBody\":\n case \"Composite\":\n case \"List\":\n case \"Choice\":\n case \"Independents\":\n case \"Audience\":\n return \"ContentResource\";\n case \"ImageService1\":\n case \"ImageService2\":\n case \"ImageService3\":\n return \"Service\";\n }\n\n return type as any;\n}\n\nconst emptyTypes = {\n Annotation: emptyAnnotation,\n AnnotationPage: emptyAnnotationPage,\n Canvas: emptyCanvas,\n Collection: emptyCollection,\n Manifest: emptyManifest,\n Range: emptyRange,\n ResourceProvider: emptyAgent,\n Service: emptyService,\n};\n\nexport function getEmptyType(type: string): any {\n const key = resolveType(type);\n return emptyTypes[key as \"Manifest\"] || {};\n}\n\nexport function randomId() {\n return `${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`;\n}\n\nexport function matchBasedOnResource(\n resource: CreatableResource,\n list: CreatorDefinition[],\n options: { vault: Vault },\n): CreatorDefinition[] {\n const supported = [];\n if (list.length === 0) {\n return [];\n }\n const parent = toRef(resource.parent);\n const property = resource.property;\n const filter = resource.filter;\n\n for (const def of list) {\n if (filter) {\n if (!def.tags) continue;\n if (!def.tags.includes(filter)) {\n continue;\n }\n }\n\n if (parent && property) {\n if (def.supports.parentTypes) {\n if (!def.supports.parentTypes.includes(parent.type)) {\n continue;\n }\n }\n if (def.supports.parentFields) {\n if (!def.supports.parentFields.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.parentFieldMap) {\n const type = def.supports.parentFieldMap[parent.type];\n if (!type || !type.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.disallowPainting && resource.isPainting) {\n continue;\n }\n if (def.supports.onlyPainting && !resource.isPainting) {\n continue;\n }\n\n if (def.supports.custom) {\n const isValid = def.supports.custom(\n { property, resource: parent, atIndex: resource.index },\n options.vault,\n );\n if (!isValid) {\n continue;\n }\n }\n\n const initialDataKeys = Object.keys(resource.initialData || {}).filter(\n (key) => key !== \"skipEditingOnCreate\",\n );\n\n if (!def.supports.initialData && initialDataKeys.length !== 0) {\n continue;\n }\n\n if (def.resourceType !== resource.type) {\n if (!(def.additionalTypes || []).includes(resource.type)) {\n continue;\n }\n }\n supported.push(def);\n }\n }\n\n return supported;\n}\n\nexport function creatorHelper<\n const ResourceType extends AllAvailableParentTypes,\n const Parent extends { id: string; type: ResourceType },\n const ResourceField extends GetSupportedResourceFields<ResourceType>,\n const CID extends CreatorDefinitionFilterByParent<\n ResourceType,\n ResourceField\n >[\"id\"],\n Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>,\n Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>,\n>(\n ctx: CreatorFunctionContext,\n parent: Parent | ResourceType,\n property: ResourceField,\n definition: CID,\n): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return> {\n return (payload: Payload, options = {}) => {\n if (typeof parent !== \"string\") {\n options.parent = {\n property,\n resource: parent,\n atIndex: options?.parent?.atIndex,\n };\n }\n return ctx.create(definition, payload, options) as any;\n };\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport { HAS_PART, isSpecificResource, PART_OF } from \"@iiif/parser\";\nimport type { SpecificResource } from \"@iiif/presentation-3\";\nimport { references } from \"@manifest-editor/editor-api\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport { getEmptyType, resolveType } from \"./utils\";\n\nexport class CreatorResource {\n resource: any;\n meta: Record<string, Record<string, unknown>> = {};\n warnings: string[] = [];\n errors: string[] = [];\n partOf: any;\n references: ReferencedResource[] = [];\n embedded: CreatorResource[] = [];\n vault: Vault;\n specificResource?: SpecificResource;\n\n constructor(inputData: any, vault: Vault) {\n this.vault = vault;\n let data = { ...inputData };\n\n if (data.type === \"SpecificResource\") {\n const source = data.source;\n this.specificResource = {\n ...data,\n source: { id: source.id, type: resolveType(source.type) },\n };\n data = source;\n }\n\n const properties = Object.keys(data);\n const defaultType = getEmptyType(data.type);\n\n for (const key of properties) {\n // These properties are NOT references and can be just included normally.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n continue;\n }\n\n if (data.type === \"Range\" && key === \"items\") {\n const newRange: any = [];\n for (const range of data[key]) {\n if (range instanceof ReferencedResource) {\n this.references.push(range);\n newRange.push(range);\n continue;\n }\n\n const rangeRef = new ReferencedResource(range, vault);\n newRange.push(rangeRef);\n data[key] = rangeRef;\n }\n\n data[key] = newRange;\n continue;\n }\n\n if (data.type === \"Manifest\" && key === \"start\") {\n const start = data[key];\n\n if (start instanceof ReferencedResource) {\n this.references.push(start);\n continue;\n }\n\n const startRef = new ReferencedResource(start, vault);\n data[key] = startRef;\n continue;\n }\n\n if (data.type === \"Annotation\" && key === \"target\") {\n let target = data[key];\n\n if (target instanceof ReferencedResource) {\n this.references.push(target);\n continue;\n }\n\n if (typeof target === \"string\") {\n target = { id: target, type: \"Canvas\" };\n }\n\n const targetRef = new ReferencedResource(target, vault);\n data[key] = targetRef;\n continue;\n }\n\n // @todo Handle single item cases. (not caught by the above 2 cases)\n if (references.single.includes(key as any)) {\n continue;\n }\n\n // This property SHOULD already be in the Vault OR an instance of creator resource.\n if (\n references.externalProperties.includes(key as any) ||\n references.internalProperties.includes(key as any)\n ) {\n const _items = (data[key] || []) as any[];\n const items = Array.isArray(_items) ? _items : [_items];\n const newItems: any[] = [];\n for (const item of items) {\n if (item instanceof ReferencedResource) {\n this.references.push(item);\n newItems.push(item);\n continue;\n }\n if (item instanceof CreatorResource) {\n this.embedded.push(item);\n newItems.push(item);\n continue;\n }\n\n // A SpecificResource carries its selector and source inline. Vault.get()\n // resolves it to its source, so an existing source must not turn the\n // wrapper into a plain reference.\n if (isSpecificResource(item)) {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n continue;\n }\n\n const exists = this.vault.get(item, { skipSelfReturn: true });\n if (exists) {\n const type = resolveType(item.type);\n const newItem = new ReferencedResource(\n { id: item.id, type },\n vault,\n );\n this.references.push(newItem);\n newItems.push(newItem);\n } else {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n }\n }\n data[key] = newItems;\n }\n }\n this.resource = { ...defaultType, ...data };\n }\n\n // This is what is returned from the creator instance\n get() {\n return this.resource;\n }\n\n getSpecificResource() {\n const reference = this.ref();\n return isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: reference };\n }\n\n ref() {\n if (this.specificResource) {\n return this.specificResource;\n }\n\n return {\n id: this.resource.id,\n type: resolveType(this.resource.type as string) as any,\n };\n }\n\n getAllReferencedResources() {\n return this.references;\n }\n\n getAllEmbeddedResources(): CreatorResource[] {\n const allEmbedded = [];\n for (const resource of this.embedded) {\n allEmbedded.push(...resource.getAllEmbeddedResources());\n }\n allEmbedded.push(...this.embedded);\n return allEmbedded;\n }\n\n getVaultResource() {\n const resource = this.resource;\n const properties = Object.keys(resource);\n const newResource: any = {};\n\n for (const key of properties) {\n // Skip these, they are just normal inline values.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n newResource[key] = resource[key];\n continue;\n }\n\n if (references.single.includes(key as any)) {\n const ref = resource[key];\n if (ref instanceof ReferencedResource) {\n // These MUST be specific resources.\n if (\n (resource.type === \"Manifest\" && key === \"start\") ||\n (resource.type === \"Annotation\" && key === \"target\")\n ) {\n newResource[key] = ref.specificResource();\n } else {\n newResource[key] = ref.optionalSpecificResource();\n }\n } else {\n newResource[key] = resource[key];\n }\n continue;\n }\n\n if (resource[key]) {\n newResource[key] = [];\n for (const item of resource[key] || []) {\n if (resource.type === \"Range\" && key === \"items\") {\n if (item instanceof ReferencedResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.specificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n if (item instanceof CreatorResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.getSpecificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n continue;\n }\n\n if (item instanceof ReferencedResource) {\n newResource[key].push(item.optionalSpecificResource());\n }\n if (item instanceof CreatorResource) {\n newResource[key].push(item.ref());\n }\n }\n }\n }\n\n if (this.partOf) {\n newResource[HAS_PART] = newResource[HAS_PART] || [];\n newResource[HAS_PART].push(this.partOf);\n }\n\n return newResource;\n }\n\n setPartOf(id: string) {\n const ref = this.ref();\n this.partOf = {\n id: ref.id,\n type: resolveType(ref.type),\n [PART_OF]: id,\n };\n }\n}\n","import type { SupportedSelector } from \"@iiif/helpers\";\nimport type { Vault } from \"@iiif/helpers/vault\";\nimport type {\n Reference,\n Selector,\n SpecificResource,\n} from \"@iiif/presentation-3\";\nimport {\n type AnnotationResponse,\n annotationResponseToSelector,\n seraliseSupportedSelector,\n} from \"react-iiif-vault\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport type {\n CreatorConfig,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n} from \"./types\";\nimport { randomId } from \"./utils\";\n\nexport class CreatorInstance implements CreatorFunctionContext {\n vault: Vault;\n previewVault: Vault;\n configs: CreatorDefinition[];\n options: CreatorOptions;\n config: Record<string, unknown>;\n creatorConfig: CreatorConfig;\n\n target: CreatorOptions[\"target\"];\n selector: SupportedSelector | undefined | null;\n serialisedSelector: { type: string; value: string } | null = null;\n\n constructor(\n vault: Vault,\n options: CreatorOptions,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n configKey: string,\n creatorConfig: CreatorConfig = {},\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.options = options;\n this.configs = createConfigs;\n this.creatorConfig = creatorConfig;\n this.config = creatorConfig[configKey] || {};\n this.target = this.options.target || this.options.parent?.resource;\n const response: AnnotationResponse = this.options.initialData?.selector;\n this.selector = response ? annotationResponseToSelector(response) : null;\n if (this.options.initialData?.getSerialisedSelector) {\n this.serialisedSelector =\n this.options.initialData.getSerialisedSelector();\n }\n }\n\n getPreviewVault() {\n return this.previewVault;\n }\n\n setSelector(selector: SupportedSelector) {\n this.selector = selector;\n }\n\n getSerialisedSelector() {\n if (this.serialisedSelector) {\n return this.serialisedSelector;\n }\n const selector = this.selector;\n if (selector) {\n const serialisedSelector = seraliseSupportedSelector(\n selector,\n this.options.initialData?.on,\n );\n if (serialisedSelector) {\n return serialisedSelector;\n }\n }\n return null;\n }\n\n getTarget(): SpecificResource | Reference | undefined {\n const target = this.target;\n const serialisedSelector = this.getSerialisedSelector();\n\n if (serialisedSelector) {\n return {\n type: \"SpecificResource\",\n source: target,\n selector: serialisedSelector as Selector,\n };\n }\n\n return target;\n }\n\n getParent(): Reference | undefined {\n return this.options.parent?.resource;\n }\n getParentResource(): SpecificResource | undefined {\n const parent = this.getParent();\n if (parent) {\n return {\n type: \"SpecificResource\",\n source: parent,\n };\n }\n }\n\n generateId(type: string, parent?: Reference | ReferencedResource) {\n if (parent && parent instanceof ReferencedResource) {\n parent = parent.ref();\n }\n if (this.options.rootId) {\n parent = { id: this.options.rootId, type: \"none\" };\n }\n\n return `${(parent || this.options.parent?.resource)?.id}/${type}/${randomId()}`;\n }\n\n ref(idOrRef: string | Reference) {\n let id = \"\";\n let type = \"\";\n\n if (typeof idOrRef === \"string\") {\n id = idOrRef;\n } else {\n id = idOrRef.id;\n type = idOrRef.type;\n }\n\n const state = this.vault.getState();\n const realType = state.iiif.mapping[id];\n\n if (!realType) {\n type = type || \"unknown\";\n } else {\n type = realType;\n }\n\n return new ReferencedResource({ id, type }, this.vault);\n }\n\n embed(data: any) {\n return new CreatorResource(data, this.vault);\n }\n\n async create(\n definition: string,\n payload: any,\n options?: Partial<CreatorOptions>,\n ) {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig,\n );\n\n return (await runtime.run()) as any;\n }\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport {\n addMappings,\n metaActions,\n batchActions,\n importEntities,\n} from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { CreatorInstance } from \"./CreatorInstance\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport type { CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { getCreatorConfigKey, resolveType } from \"./utils\";\n\nexport class CreatorRuntime {\n // This will hold state for the creation process\n resource: CreatorResource | Array<CreatorResource> | null = null;\n payload: any;\n vault: Vault;\n previewVault: Vault;\n definition: CreatorDefinition;\n options: CreatorOptions;\n configs: CreatorDefinition[];\n creatorConfig: CreatorConfig;\n\n constructor(\n vault: Vault,\n definition: CreatorDefinition,\n payload: any,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n options?: Partial<CreatorOptions>,\n creatorConfig?: CreatorConfig,\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.definition = definition;\n this.payload = payload;\n this.configs = this.filterCreateConfigs(createConfigs);\n this.creatorConfig = creatorConfig || {};\n this.options = {\n targetType: options?.targetType || definition.resourceType,\n ...(options || {}),\n };\n }\n\n filterCreateConfigs(configs: CreatorDefinition[]) {\n const indexedByIdLastWins: Record<string, CreatorDefinition> = {};\n for (const config of configs) {\n indexedByIdLastWins[config.id] = config;\n }\n return Object.values(indexedByIdLastWins);\n }\n\n async run(): Promise<CreatorResource | CreatorResource[]> {\n const instance = new CreatorInstance(\n this.vault,\n this.options,\n this.configs,\n this.previewVault,\n getCreatorConfigKey(this.definition),\n this.creatorConfig,\n );\n const result = await this.definition.create(this.payload, instance);\n\n // Could be an array.\n if (Array.isArray(result)) {\n const results: CreatorResource[] = [];\n for (const item of result) {\n if (item instanceof CreatorResource) {\n results.push(item);\n } else {\n results.push(new CreatorResource(item, this.vault));\n }\n }\n this.resource = results;\n\n return this.resource;\n }\n\n if (result instanceof CreatorResource) {\n this.resource = result;\n } else {\n this.resource = new CreatorResource(result, this.vault);\n }\n\n return this.resource;\n }\n\n getActions() {\n if (!this.resource) {\n return [];\n }\n\n const allResources = Array.isArray(this.resource)\n ? this.resource\n : [this.resource];\n\n const actions = [];\n\n const resources: any = {};\n const mapping: any = {};\n\n for (const resource of allResources) {\n if (this.options.parent) {\n resource.setPartOf(this.options.parent.resource.id);\n }\n\n const embedded = resource.getAllEmbeddedResources();\n\n const allItems = [...embedded, resource];\n\n for (const item of allItems) {\n const resource = item.getVaultResource();\n for (const [meta, values] of Object.entries(item.meta)) {\n for (const [key, value] of Object.entries(values)) {\n actions.push(metaActions.setMetaValue({ id: resource.id, meta, key, value }));\n }\n }\n if (!resource.type || !resource.id) {\n continue;\n }\n const type = resolveType(resource.type);\n resources[type] = resources[type] ? resources[type] : {};\n resources[type][resource.id] = resource;\n mapping[resource.id] = type;\n }\n\n actions.push(importEntities({ entities: resources }));\n actions.push(addMappings({ mapping }));\n }\n\n return actions as any[];\n }\n\n commit(afterActions: any[] = []): Reference | Reference[] {\n if (!this.resource) {\n throw new Error(\"Creator has not been run\");\n }\n\n const actions = this.getActions();\n this.vault.dispatch(\n batchActions({ actions: [...actions, ...afterActions] }),\n );\n\n if (Array.isArray(this.resource)) {\n return this.resource.map((resource) => resource.ref() as Reference);\n }\n\n return this.resource.ref() as Reference;\n }\n}\n","import { Vault } from \"@iiif/helpers/vault\";\nimport { entityActions } from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { placeCreatedResources } from \"./placeholder-position\";\nimport {\n beginCanvasComposition,\n getCanvasLayout,\n getEmptyCanvasPlaceholders,\n validRectangle,\n} from \"@manifest-editor/editor-api\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport type { CreatableResource, CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { matchBasedOnResource } from \"./utils\";\n\nexport class Creator {\n configs: CreatorDefinition[];\n vault: Vault;\n previewVault: Vault;\n creatorConfig: CreatorConfig;\n\n constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault, creatorConfig?: CreatorConfig) {\n this.configs = configs || [];\n this.vault = vault;\n this.previewVault = previewVault || new Vault();\n this.creatorConfig = creatorConfig || {};\n }\n\n matchBasedOnResource(resource: CreatableResource) {\n return matchBasedOnResource(resource, this.configs || [], { vault: this.vault });\n }\n\n async create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference | Reference[]> {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n if (options?.parent) {\n if (foundDefinition.supports.parentTypes) {\n if (!foundDefinition.supports.parentTypes.includes(options.parent.resource.type)) {\n throw new Error(`Definition ${definition} does not support parent type ${options.parent.resource.type}`);\n }\n }\n if (foundDefinition.supports.parentFields) {\n if (!foundDefinition.supports.parentFields.includes(options.parent.property)) {\n throw new Error(`Definition ${definition} does not support parent field ${options.parent.property}`);\n }\n }\n\n if (foundDefinition.supports.parentFieldMap) {\n const type = foundDefinition.supports.parentFieldMap[options.parent.resource.type];\n if (!type || !type.includes(options.parent.property)) {\n throw new Error(\n `Definition ${definition} does not support parent ${options.parent.property} / ${options.parent.property}`\n );\n }\n }\n if (foundDefinition.supports.custom) {\n const isValid = foundDefinition.supports.custom(options.parent, this.vault);\n if (!isValid) {\n throw new Error(`Definition does not support resource`);\n }\n }\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig\n );\n\n if (options?.placeholderPosition && !validRectangle(options.placeholderPosition.bounds)) {\n throw new Error(\"Invalid placeholder position\");\n }\n const run = await runtime.run();\n const allResources = Array.isArray(run) ? run : [run];\n const afterActions: any[] = [];\n\n for (const resource of allResources) {\n if (options?.parent) {\n if (options.parent.property === \"start\" || options.parent.property === \"target\") {\n afterActions.push(\n entityActions.modifyEntityField({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n value: resource.ref(),\n key: options.parent.property,\n })\n );\n } else {\n afterActions.push(\n entityActions.addReference({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n reference: resource.ref(),\n key: options.parent.property,\n index: options.placeholderPosition?.replaceAnnotationId\n ? this.vault\n .get<any>(options.parent.resource)\n [options.parent.property]?.findIndex(\n (ref: Reference) => ref.id === options.placeholderPosition!.replaceAnnotationId\n )\n : options.parent.atIndex,\n })\n );\n }\n }\n }\n\n // Validate against live occupancy before any parent references are committed.\n const placement = options?.placeholderPosition;\n if (placement) {\n if (placement.replaceAnnotationId && allResources.length !== 1)\n throw new Error(\"Choose one image to replace this image. Nothing has been changed.\");\n const canvas = this.vault.get<any>({ id: placement.canvasId, type: \"Canvas\" });\n const state = getCanvasLayout(this.vault, canvas.id);\n if (state?.customised === false) {\n const slot = state.slots.find((slot) => slot.id === placement.placeholderId);\n const empty = getEmptyCanvasPlaceholders(this.vault, canvas);\n if (\n !slot ||\n (placement.replaceAnnotationId\n ? slot.annotationIds?.length !== 1 ||\n slot.annotationIds[0] !== placement.replaceAnnotationId ||\n allResources.length !== 1\n : !empty.some((item) => item.id === slot.id) || allResources.length > empty.length)\n )\n throw new Error(\n \"Not enough empty positions. Reduce the selection or choose a larger layout. Nothing has been added.\"\n );\n }\n beginCanvasComposition(this.vault, canvas);\n }\n const result = runtime.commit(afterActions);\n\n // Only run side effects if there is a parent\n if (options?.parent) {\n if (foundDefinition.sideEffects) {\n for (const sideEffect of foundDefinition.sideEffects) {\n if (sideEffect.run && !(options.placeholderPosition && sideEffect.spatial && sideEffect.canvasInteraction)) {\n const allResults = Array.isArray(result) ? result : [result];\n for (const item of allResults) {\n // @todo we need more in the ctx (like parent/target where this is to be added.)\n await sideEffect.run(item, { vault: this.vault, options: options as any });\n }\n }\n }\n }\n }\n\n if (options?.placeholderPosition) placeCreatedResources(this.vault, result, runtime.options);\n\n return result;\n }\n}\n","import type {\n AllAvailableParentTypes,\n AllParentTypes,\n AllProperties,\n CreatorContext,\n CreatorDefinition,\n SpecificCreatorDefinition,\n} from \"./types\";\n\n// Want to enable the following APIs.\n//\n// const createImage = useCreator(\n// resource,\n// \"thumbnail\",\n// \"@manifest-editor/image-url-creator\"\n// );\n//\n// createImage({ url: 'https://example.org/image.jpg' });\n//\n// These should be constructed from an array of creators.\n// UseCreator<Resource, ResourceField, CreatorId> -> CreatorPayload\n//\n// But then also:\n// await manifestEditor.descriptive.thumbnail.create(\"@manifest-editor/image-url-creator\", {\n// url: \"https://example.org/image.jpg\",\n// });\n//\n// So essentially, I think we want to create a type that is roughly structured like this:\n// {\n// Manifest: {\n// thumbnail: {\n// \"@manifest-editor/image-url-creator\": {\n// url: string;\n// }\n// }\n// }\n// }\n// Although it would include _all_ available creators.\n// Then the helpers would be fairly easy to implement.\n//\n// Here the creator definition (might need to change) for this:\n\nexport function defineCreator<\n const Payload = any,\n const ID = Readonly<string>,\n const ResourceType extends AllAvailableParentTypes = never,\n const AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [],\n const AllResourceTypes = [ResourceType, ...AdditionalResourceTypes],\n const SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes,\n const SupportsParentFields extends Array<AllProperties> = [],\n const CreateReturnType = any,\n>(\n options: SpecificCreatorDefinition<\n Payload,\n ID,\n ResourceType,\n AdditionalResourceTypes,\n AllResourceTypes,\n SupportsParentTypes,\n SupportsParentFields,\n CreateReturnType\n >\n) {\n return options;\n}\n\nexport function withInitialData<T extends CreatorDefinition>(\n creator: T,\n data: Record<string, any>,\n overrides: Record<string, any> = {}\n): T {\n const render = creator.render\n ? (ctx: CreatorContext<any>) => {\n const newContext: CreatorContext = {\n ...ctx,\n options: {\n ...(ctx.options || {}),\n initialData: {\n ...(data || {}),\n ...(ctx.options?.initialData || {}),\n ...(overrides || {}),\n },\n },\n };\n return creator.render?.(newContext);\n }\n : undefined;\n\n return { ...creator, render } as T;\n}\n\nexport function withCustomRender<T extends CreatorDefinition>(\n creator: T,\n render: (ctx: CreatorContext<any>, originalRender: (ctx: CreatorContext<any>) => React.ReactNode) => React.ReactNode\n): T {\n const newRender = (ctx: CreatorContext<any>) => {\n return render(ctx, creator.render as any);\n };\n\n return { ...creator, render: newRender } as T;\n}\n\nexport declare namespace IIIFManifestEditor {\n interface CreatorDefinitions {}\n}\n\nexport type ExtractCreatorGenerics<T extends CreatorDefinition> =\n T extends SpecificCreatorDefinition<\n infer Payload,\n infer ID,\n infer ResourceType,\n infer AdditionalResourceTypes,\n infer AllResourceTypes,\n infer SupportsParentTypes,\n infer SupportsParentFields,\n infer CreateReturnType\n >\n ? {\n Payload: Payload;\n ID: ID;\n ResourceType: ResourceType;\n AdditionalResourceTypes: AdditionalResourceTypes;\n AllResourceTypes: AllResourceTypes;\n SupportsParentTypes: SupportsParentTypes;\n SupportsParentFields: SupportsParentFields;\n CreateReturnType: CreateReturnType;\n }\n : never;\n\ntype CreatorSupportsParentTypes<T, Type extends AllAvailableParentTypes> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentTypes\"] extends never\n ? false\n : HelperInArray<Type, ExtractCreatorGenerics<T>[\"SupportsParentTypes\"]>\n : false;\n\ntype CreatorSupportsParentFields<T, Field extends AllProperties> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentFields\"] extends never\n ? false\n : HelperInArray<Field, ExtractCreatorGenerics<T>[\"SupportsParentFields\"]>\n : false;\n\ntype CreatorSupportsParent<\n T,\n Type extends AllAvailableParentTypes,\n Field extends AllProperties,\n> = T extends CreatorDefinition\n ? CreatorSupportsParentTypes<T, Type> extends true\n ? CreatorSupportsParentFields<T, Field> extends true\n ? true\n : false\n : false\n : false;\n\ntype HelperInArray<ToFind, Array extends readonly any[]> = Array extends readonly [infer Head, ...infer Tail]\n ? Head extends ToFind\n ? true\n : HelperInArray<ToFind, Tail>\n : false;\n\nexport type CreatorDefinitionFilterByParent<\n Type extends AllAvailableParentTypes,\n Field extends AllProperties = AllProperties,\n CD extends IIIFManifestEditor.CreatorDefinitions = IIIFManifestEditor.CreatorDefinitions,\n> = {\n [K in keyof CD]: CreatorSupportsParent<CD[K], Type, Field> extends true ? CD[K] : never;\n}[keyof CD];\n"],"mappings":"kPAgBA,SAAgB,EAAsB,EAAc,EAAiC,EAAyB,CAC5G,IAAM,EAAY,EAAQ,oBAC1B,GAAI,CAAC,EAAW,OAEhB,IAAM,GADO,MAAM,QAAQ,CAAM,EAAI,EAAS,CAAC,CAAM,EAAA,CAC5B,QAAS,GAC5B,EAAI,OAAS,aAAqB,CAAC,EAAM,IAAI,CAAG,CAAC,EACjD,EAAQ,QAAQ,SAAS,OAAS,cAAgB,EAAQ,OAAO,WAAa,OACzE,CAAC,EAAM,IAAI,EAAQ,OAAO,QAAQ,CAAC,EACrC,CAAC,CACT,EACK,EAAS,EAAM,IAAS,CAAE,GAAI,EAAU,SAAU,KAAM,QAAS,CAAC,EAClE,GAAA,EAAQA,EAAAA,gBAAAA,CAAgB,EAAO,EAAO,EAAE,EAC9C,GAAI,GAAO,aAAe,IAAS,EAAU,cAAe,CAC1D,IAAM,EAAQ,EAAM,MAAM,KAAM,GAAS,EAAK,KAAO,EAAU,aAAa,EAEtE,EAAY,CAAC,EAAO,IAAA,EADZC,EAAAA,2BAAAA,CAA2B,EAAO,CAAM,CAAC,CAAC,OAAQ,GAAS,EAAK,KAAO,EAAM,EAC1D,CAAC,EAClC,GACE,CAAC,GACD,EAAY,OAAS,EAAU,QAC9B,EAAM,eAAe,QAAU,EAAM,cAAc,KAAO,EAAU,oBAErE,MAAU,MAAM,iEAAiE,EACnF,CACE,IAAM,EAAQ,EAAM,MAAM,IAAK,IAAU,CAAE,GAAG,CAAK,EAAE,EASrD,GARA,EAAY,SAAS,EAAY,IAAU,CACzC,IAAM,EAAO,EAAU,GACjB,GAAA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Aa,MAAM,QAAQ,CAAM,EAAI,EAAS,CAAC,CAAM,EAC3D,IAAK,IAAM,KAAQ,EAEjB,MAAM,EAAW,IAAI,EAAM,CAAE,MAAO,KAAK,MAAgB,SAAe,CAAC,CAE7E,EAON,OAFI,GAAS,qBAAqB,EAAsB,KAAK,MAAO,EAAQ,EAAQ,OAAO,EAEpF,CACT,CACF,ECpHA,SAAgB,EAUd,EAUA,CACA,OAAO,CACT,CAEA,SAAgB,EACd,EACA,EACA,EAAiC,CAAC,EAC/B,CACH,IAAM,EAAS,EAAQ,OAClB,GAA6B,CAC5B,IAAM,EAA6B,CACjC,GAAG,EACH,QAAS,CACP,GAAI,EAAI,SAAW,CAAC,EACpB,YAAa,CACX,GAAI,GAAQ,CAAC,EACb,GAAI,EAAI,SAAS,aAAe,CAAC,EACjC,GAAI,GAAa,CAAC,CACpB,CACF,CACF,EACA,OAAO,EAAQ,SAAS,CAAU,CACpC,EACA,IAAA,GAEJ,MAAO,CAAE,GAAG,EAAS,QAAO,CAC9B,CAEA,SAAgB,EACd,EACA,EACG,CACH,IAAM,EAAa,GACV,EAAO,EAAK,EAAQ,MAAa,EAG1C,MAAO,CAAE,GAAG,EAAS,OAAQ,CAAU,CACzC"}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Entities, Vault } from "@iiif/helpers/vault";
2
2
  import { Annotation, DescriptiveProperties, LinkingProperties, NavPlaceExtension, Reference, SpecificResource, StructuralProperties, TechnicalProperties } from "@iiif/presentation-3";
3
3
  import { resources } from "@manifest-editor/editor-api";
4
+ import { EditorI18n, MessageReference } from "@manifest-editor/i18n";
4
5
  import { ReactNode } from "react";
5
6
  import { SupportedSelector } from "@iiif/helpers";
6
7
  //#region src/ReferencedResource.d.ts
@@ -72,6 +73,7 @@ declare class ReferencedResource {
72
73
  //#region src/CreatorResource.d.ts
73
74
  declare class CreatorResource {
74
75
  resource: any;
76
+ meta: Record<string, Record<string, unknown>>;
75
77
  warnings: string[];
76
78
  errors: string[];
77
79
  partOf: any;
@@ -200,6 +202,10 @@ type CreatorDefinitionFilterByParent<Type extends AllAvailableParentTypes, Field
200
202
  //#endregion
201
203
  //#region src/types.d.ts
202
204
  interface CreatorContext<T = any> {
205
+ /** Optional editor-instance formatter for form feedback; never use for authored IIIF values.
206
+ * Hosts supply this at render time. Do not persist or send it through a worker.
207
+ */
208
+ i18n?: Pick<EditorI18n, "resolveMessage">;
203
209
  vault: Vault;
204
210
  options: CreatorOptions;
205
211
  config?: Record<string, unknown>;
@@ -227,7 +233,15 @@ interface CreatorParent {
227
233
  property: string;
228
234
  atIndex?: number;
229
235
  }
236
+ /** A fitting hint, independent of an annotation's exact selector. */
237
+ interface PlaceholderPosition {
238
+ canvasId: string;
239
+ bounds: import("@manifest-editor/editor-api").Rectangle;
240
+ placeholderId?: string;
241
+ replaceAnnotationId?: string;
242
+ }
230
243
  interface CreatorOptions {
244
+ placeholderPosition?: PlaceholderPosition;
231
245
  targetType: string;
232
246
  target?: Reference;
233
247
  parent?: CreatorParent;
@@ -235,7 +249,30 @@ interface CreatorOptions {
235
249
  rootId?: string;
236
250
  }
237
251
  type CreatorConfig = Record<string, Record<string, unknown>>;
238
- type CreatorConfigField = {
252
+ /** Deferred UI text only. Plain references are safe in module-level definitions.
253
+ * Resolve at display time with the corresponding legacy string as fallback.
254
+ * Help and placeholders are optional metadata for custom forms, not payload defaults.
255
+ */
256
+ interface CreatorDisplayMessages {
257
+ labelMessage?: MessageReference;
258
+ summaryMessage?: MessageReference;
259
+ helpMessage?: MessageReference;
260
+ placeholderMessage?: MessageReference;
261
+ }
262
+ /** Serialisable feedback, separate from Error instances and IIIF resource data. */
263
+ interface CreatorValidationMessage {
264
+ /** Stable machine-readable code; never translated. */
265
+ readonly code?: string;
266
+ /** Optional payload/config field ID; never translated. */
267
+ readonly field?: string;
268
+ readonly message: MessageReference;
269
+ }
270
+ /** Input to the opt-in error mapper; this context itself is not worker transport. */
271
+ interface CreatorValidationContext<Payload = any> {
272
+ readonly payload: Payload;
273
+ readonly vault: Vault;
274
+ }
275
+ type CreatorConfigField = CreatorDisplayMessages & {
239
276
  id: string;
240
277
  type: "checkbox";
241
278
  label: string;
@@ -259,10 +296,12 @@ type AllAvailableParentTypes = keyof typeof resources.supported;
259
296
  type GetSupportedResourceFields<Resource extends AllAvailableParentTypes> = {} & (typeof resources.supported)[Resource]["allowed"][number];
260
297
  type AllProperties = ({} & keyof LinkingProperties) | ({} & keyof StructuralProperties<any>) | ({} & keyof TechnicalProperties) | ({} & keyof DescriptiveProperties) | ({} & keyof Annotation) | ({} & keyof NavPlaceExtension);
261
298
  type AllParentTypes = ["Collection", "Manifest", "Canvas", "Annotation", "AnnotationPage", "Range", "AnnotationCollection", "ContentResource", "Agent"];
262
- interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, ResourceType extends AllAvailableParentTypes = never, AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [], AllResourceTypes = [ResourceType, ...AdditionalResourceTypes], SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes, SupportsParentFields extends Array<AllProperties> = [], CreateReturnType = any | Promise<any> | any[] | Promise<any[]>> {
299
+ interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, ResourceType extends AllAvailableParentTypes = never, AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [], AllResourceTypes = [ResourceType, ...AdditionalResourceTypes], SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes, SupportsParentFields extends Array<AllProperties> = [], CreateReturnType = any | Promise<any> | any[] | Promise<any[]>> extends CreatorDisplayMessages {
263
300
  readonly id: ID;
264
301
  label: string;
265
302
  summary?: string;
303
+ /** Hide the form help icon when the creator supplies its own browsing interface. */
304
+ hideSummary?: boolean;
266
305
  icon?: any;
267
306
  dependencies?: string[];
268
307
  tags?: string[];
@@ -270,6 +309,11 @@ interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, Resour
270
309
  readonly configKey?: string;
271
310
  create: (payload: Payload, ctx: CreatorInstance) => CreateReturnType;
272
311
  validate?: (payload: Payload, vault: Vault) => void | Promise<void>;
312
+ /** Map a known validation/creation failure for display without replacing the error.
313
+ * Consumers opt in at their existing catch boundary; undefined uses their normal
314
+ * fallback. The creator runtime does not call this or change validation semantics.
315
+ */
316
+ validationErrorMessage?: (error: unknown, context: CreatorValidationContext<Payload>) => CreatorValidationMessage | undefined;
273
317
  supportsResource?: (value: string, helpers: CreatorResourceProbeHelpers, ctx: {
274
318
  vault: Vault;
275
319
  resource: CreatableResource;
@@ -280,6 +324,9 @@ interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, Resour
280
324
  resourceType: ResourceType;
281
325
  additionalTypes?: AdditionalResourceTypes;
282
326
  actionButton?: string;
327
+ actionButtonMessage?: MessageReference;
328
+ /** Editor tab to open after creating this resource. */
329
+ initialEditor?: string;
283
330
  resourceFields: string[];
284
331
  embeddedResources?: string[];
285
332
  staticFields?: Record<string, any>;
@@ -308,6 +355,7 @@ interface CreatorSideEffect {
308
355
  canvasInteraction?: boolean;
309
356
  }
310
357
  interface CreatableResource {
358
+ placeholderPosition?: PlaceholderPosition;
311
359
  type: string;
312
360
  parent?: Reference;
313
361
  property?: string;
@@ -344,5 +392,5 @@ declare function creatorHelper<const ResourceType extends AllAvailableParentType
344
392
  type: ResourceType;
345
393
  }, const ResourceField extends GetSupportedResourceFields<ResourceType>, const CID extends CreatorDefinitionFilterByParent<ResourceType, ResourceField>["id"], Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>, Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>>(ctx: CreatorFunctionContext, parent: Parent | ResourceType, property: ResourceField, definition: CID): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return>;
346
394
  //#endregion
347
- export { AllAvailableParentTypes, AllParentTypes, AllProperties, CreatableResource, Creator, CreatorConfig, CreatorConfigField, CreatorConfiguration, CreatorContext, CreatorDefinition, CreatorDefinitionFilterByParent, CreatorFunctionContext, CreatorOptions, CreatorResource, CreatorResourceProbeHelpers, CreatorResourceProbeResult, CreatorSideEffect, ExtractCreatorGenerics, GetCreatorPayload, GetSupportedResourceFields, IIIFManifestEditor, ResolvedCreatorReturn, SpecificCreatorDefinition, creatorHelper, defineCreator, getCreatorConfigKey, getEmptyType, matchBasedOnResource, randomId, resolveType, withCustomRender, withInitialData };
395
+ export { AllAvailableParentTypes, AllParentTypes, AllProperties, CreatableResource, Creator, CreatorConfig, CreatorConfigField, CreatorConfiguration, CreatorContext, CreatorDefinition, CreatorDefinitionFilterByParent, CreatorDisplayMessages, CreatorFunctionContext, CreatorOptions, CreatorResource, CreatorResourceProbeHelpers, CreatorResourceProbeResult, CreatorSideEffect, CreatorValidationContext, CreatorValidationMessage, ExtractCreatorGenerics, GetCreatorPayload, GetSupportedResourceFields, IIIFManifestEditor, PlaceholderPosition, ResolvedCreatorReturn, SpecificCreatorDefinition, creatorHelper, defineCreator, getCreatorConfigKey, getEmptyType, matchBasedOnResource, randomId, resolveType, withCustomRender, withInitialData };
348
396
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/ReferencedResource.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/creator-register.ts","../src/types.ts","../src/Creator.ts","../src/utils.ts"],"mappings":";;;;;;cAIa;EACX,OAAO;EACP,UAAU,YAAY;EACtB,WAAW;EACX,UAAU;EACV,YAAY,WAAW,YAAY,kBAAkB,OAAO;EAa5D;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;MAKQ;MACA;;;EASR;;;;cCtCW;EACX;EACA;EACA;EACA;EACA,YAAY;EACZ,UAAU;EACV,OAAO;EACP,mBAAmB;EAEnB,YAAY,gBAAgB,OAAO;EAkInC;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;MAcuD;;;EAPvD;;;;;;;;;;;;;;;;;;;;;;;;IAOuD;;E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;EAAY,MAAM;SACnC,sBAAsB,2BAA2B,qBACjD,YAAY,gCAChB,cACA,sBAEF,UAAU,kBAAkB,mBAAmB,mBAAmB,OAClE,SAAS,sBAAsB,mBAAmB,mBAAmB,OAErE,KAAK,wBACL,QAAQ,SAAS,cACjB,UAAU,eACV,YAAY,OACV,SAAS,SAAS,UAAU,QAAQ,oBAAoB,QAAQ"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/ReferencedResource.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/creator-register.ts","../src/types.ts","../src/Creator.ts","../src/utils.ts"],"mappings":";;;;;;;cAIa;EACX,OAAO;EACP,UAAU,YAAY;EACtB,WAAW;EACX,UAAU;EACV,YAAY,WAAW,YAAY,kBAAkB,OAAO;EAa5D;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;MAKQ;MACA;;;EASR;;;;cCtCW;EACX;EACA,MAAM,eAAe;EACrB;EACA;EACA;EACA,YAAY;EACZ,UAAU;EACV,OAAO;EACP,mBAAmB;EAEnB,YAAY,gBAAgB,OAAO;EAkInC;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;MAcuD;;;EAPvD;;;;;;;;;;;;;;;;;;;;;;;;IAOuD;;EAIvD,6BAAyB;EAIzB,2BAA2B;EAS3B;EAwEA,UAAU;;;;cCxOC,2BAA2B;EACtC,OAAO;EACP,cAAc;EACd,SAAS;EACT,SAAS;EACT,QAAQ;EACR,eAAe;EAEf,QAAQ;EACR,UAAU;EACV;IAAsB;IAAc;;EAEpC,YACE,OAAO,OACP,SAAS,gBACT,eAAe,qBACf,cAAc,OACd,mBACA,gBAAe;EAiBjB,mBAAe,8BAAA;EAIf,YAAY,UAAU;EAItB;;;;IAjC4B;IAAe;;EAkD3C,aAAa,mBAAmB;EAehC,aAAa;EAGb,qBAAqB;EAUrB,WAAW,cAAc,SAAS,YAAY;EAW9C,IAAI,kBAAkB,YAAS;EAuB/B,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S,sBAAsB,mBAAmB,mBAAmB,OAErE,KAAK,wBACL,QAAQ,SAAS,cACjB,UAAU,eACV,YAAY,OACV,SAAS,SAAS,UAAU,QAAQ,oBAAoB,QAAQ"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Entities, Vault } from "@iiif/helpers/vault";
2
2
  import { resources } from "@manifest-editor/editor-api";
3
3
  import { Annotation, DescriptiveProperties, LinkingProperties, NavPlaceExtension, Reference, SpecificResource, StructuralProperties, TechnicalProperties } from "@iiif/presentation-3";
4
+ import { EditorI18n, MessageReference } from "@manifest-editor/i18n";
4
5
  import { ReactNode } from "react";
5
6
  import { SupportedSelector } from "@iiif/helpers";
6
7
  //#region src/ReferencedResource.d.ts
@@ -72,6 +73,7 @@ declare class ReferencedResource {
72
73
  //#region src/CreatorResource.d.ts
73
74
  declare class CreatorResource {
74
75
  resource: any;
76
+ meta: Record<string, Record<string, unknown>>;
75
77
  warnings: string[];
76
78
  errors: string[];
77
79
  partOf: any;
@@ -200,6 +202,10 @@ type CreatorDefinitionFilterByParent<Type extends AllAvailableParentTypes, Field
200
202
  //#endregion
201
203
  //#region src/types.d.ts
202
204
  interface CreatorContext<T = any> {
205
+ /** Optional editor-instance formatter for form feedback; never use for authored IIIF values.
206
+ * Hosts supply this at render time. Do not persist or send it through a worker.
207
+ */
208
+ i18n?: Pick<EditorI18n, "resolveMessage">;
203
209
  vault: Vault;
204
210
  options: CreatorOptions;
205
211
  config?: Record<string, unknown>;
@@ -227,7 +233,15 @@ interface CreatorParent {
227
233
  property: string;
228
234
  atIndex?: number;
229
235
  }
236
+ /** A fitting hint, independent of an annotation's exact selector. */
237
+ interface PlaceholderPosition {
238
+ canvasId: string;
239
+ bounds: import("@manifest-editor/editor-api").Rectangle;
240
+ placeholderId?: string;
241
+ replaceAnnotationId?: string;
242
+ }
230
243
  interface CreatorOptions {
244
+ placeholderPosition?: PlaceholderPosition;
231
245
  targetType: string;
232
246
  target?: Reference;
233
247
  parent?: CreatorParent;
@@ -235,7 +249,30 @@ interface CreatorOptions {
235
249
  rootId?: string;
236
250
  }
237
251
  type CreatorConfig = Record<string, Record<string, unknown>>;
238
- type CreatorConfigField = {
252
+ /** Deferred UI text only. Plain references are safe in module-level definitions.
253
+ * Resolve at display time with the corresponding legacy string as fallback.
254
+ * Help and placeholders are optional metadata for custom forms, not payload defaults.
255
+ */
256
+ interface CreatorDisplayMessages {
257
+ labelMessage?: MessageReference;
258
+ summaryMessage?: MessageReference;
259
+ helpMessage?: MessageReference;
260
+ placeholderMessage?: MessageReference;
261
+ }
262
+ /** Serialisable feedback, separate from Error instances and IIIF resource data. */
263
+ interface CreatorValidationMessage {
264
+ /** Stable machine-readable code; never translated. */
265
+ readonly code?: string;
266
+ /** Optional payload/config field ID; never translated. */
267
+ readonly field?: string;
268
+ readonly message: MessageReference;
269
+ }
270
+ /** Input to the opt-in error mapper; this context itself is not worker transport. */
271
+ interface CreatorValidationContext<Payload = any> {
272
+ readonly payload: Payload;
273
+ readonly vault: Vault;
274
+ }
275
+ type CreatorConfigField = CreatorDisplayMessages & {
239
276
  id: string;
240
277
  type: "checkbox";
241
278
  label: string;
@@ -259,10 +296,12 @@ type AllAvailableParentTypes = keyof typeof resources.supported;
259
296
  type GetSupportedResourceFields<Resource extends AllAvailableParentTypes> = {} & (typeof resources.supported)[Resource]["allowed"][number];
260
297
  type AllProperties = ({} & keyof LinkingProperties) | ({} & keyof StructuralProperties<any>) | ({} & keyof TechnicalProperties) | ({} & keyof DescriptiveProperties) | ({} & keyof Annotation) | ({} & keyof NavPlaceExtension);
261
298
  type AllParentTypes = ["Collection", "Manifest", "Canvas", "Annotation", "AnnotationPage", "Range", "AnnotationCollection", "ContentResource", "Agent"];
262
- interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, ResourceType extends AllAvailableParentTypes = never, AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [], AllResourceTypes = [ResourceType, ...AdditionalResourceTypes], SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes, SupportsParentFields extends Array<AllProperties> = [], CreateReturnType = any | Promise<any> | any[] | Promise<any[]>> {
299
+ interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, ResourceType extends AllAvailableParentTypes = never, AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [], AllResourceTypes = [ResourceType, ...AdditionalResourceTypes], SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes, SupportsParentFields extends Array<AllProperties> = [], CreateReturnType = any | Promise<any> | any[] | Promise<any[]>> extends CreatorDisplayMessages {
263
300
  readonly id: ID;
264
301
  label: string;
265
302
  summary?: string;
303
+ /** Hide the form help icon when the creator supplies its own browsing interface. */
304
+ hideSummary?: boolean;
266
305
  icon?: any;
267
306
  dependencies?: string[];
268
307
  tags?: string[];
@@ -270,6 +309,11 @@ interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, Resour
270
309
  readonly configKey?: string;
271
310
  create: (payload: Payload, ctx: CreatorInstance) => CreateReturnType;
272
311
  validate?: (payload: Payload, vault: Vault) => void | Promise<void>;
312
+ /** Map a known validation/creation failure for display without replacing the error.
313
+ * Consumers opt in at their existing catch boundary; undefined uses their normal
314
+ * fallback. The creator runtime does not call this or change validation semantics.
315
+ */
316
+ validationErrorMessage?: (error: unknown, context: CreatorValidationContext<Payload>) => CreatorValidationMessage | undefined;
273
317
  supportsResource?: (value: string, helpers: CreatorResourceProbeHelpers, ctx: {
274
318
  vault: Vault;
275
319
  resource: CreatableResource;
@@ -280,6 +324,9 @@ interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, Resour
280
324
  resourceType: ResourceType;
281
325
  additionalTypes?: AdditionalResourceTypes;
282
326
  actionButton?: string;
327
+ actionButtonMessage?: MessageReference;
328
+ /** Editor tab to open after creating this resource. */
329
+ initialEditor?: string;
283
330
  resourceFields: string[];
284
331
  embeddedResources?: string[];
285
332
  staticFields?: Record<string, any>;
@@ -308,6 +355,7 @@ interface CreatorSideEffect {
308
355
  canvasInteraction?: boolean;
309
356
  }
310
357
  interface CreatableResource {
358
+ placeholderPosition?: PlaceholderPosition;
311
359
  type: string;
312
360
  parent?: Reference;
313
361
  property?: string;
@@ -344,5 +392,5 @@ declare function creatorHelper<const ResourceType extends AllAvailableParentType
344
392
  type: ResourceType;
345
393
  }, const ResourceField extends GetSupportedResourceFields<ResourceType>, const CID extends CreatorDefinitionFilterByParent<ResourceType, ResourceField>["id"], Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>, Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>>(ctx: CreatorFunctionContext, parent: Parent | ResourceType, property: ResourceField, definition: CID): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return>;
346
394
  //#endregion
347
- export { AllAvailableParentTypes, AllParentTypes, AllProperties, CreatableResource, Creator, CreatorConfig, CreatorConfigField, CreatorConfiguration, CreatorContext, CreatorDefinition, CreatorDefinitionFilterByParent, CreatorFunctionContext, CreatorOptions, CreatorResource, CreatorResourceProbeHelpers, CreatorResourceProbeResult, CreatorSideEffect, ExtractCreatorGenerics, GetCreatorPayload, GetSupportedResourceFields, IIIFManifestEditor, ResolvedCreatorReturn, SpecificCreatorDefinition, creatorHelper, defineCreator, getCreatorConfigKey, getEmptyType, matchBasedOnResource, randomId, resolveType, withCustomRender, withInitialData };
395
+ export { AllAvailableParentTypes, AllParentTypes, AllProperties, CreatableResource, Creator, CreatorConfig, CreatorConfigField, CreatorConfiguration, CreatorContext, CreatorDefinition, CreatorDefinitionFilterByParent, CreatorDisplayMessages, CreatorFunctionContext, CreatorOptions, CreatorResource, CreatorResourceProbeHelpers, CreatorResourceProbeResult, CreatorSideEffect, CreatorValidationContext, CreatorValidationMessage, ExtractCreatorGenerics, GetCreatorPayload, GetSupportedResourceFields, IIIFManifestEditor, PlaceholderPosition, ResolvedCreatorReturn, SpecificCreatorDefinition, creatorHelper, defineCreator, getCreatorConfigKey, getEmptyType, matchBasedOnResource, randomId, resolveType, withCustomRender, withInitialData };
348
396
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ReferencedResource.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/creator-register.ts","../src/types.ts","../src/Creator.ts","../src/utils.ts"],"mappings":";;;;;;cAIa;EACX,OAAO;EACP,UAAU,YAAY;EACtB,WAAW;EACX,UAAU;EACV,YAAY,WAAW,YAAY,kBAAkB,OAAO;EAa5D;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;MAKQ;MACA;;;EASR;;;;cCtCW;EACX;EACA;EACA;EACA;EACA,YAAY;EACZ,UAAU;EACV,OAAO;EACP,mBAAmB;EAEnB,YAAY,gBAAgB,OAAO;EAkInC;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;MAcuD;;;EAPvD;;;;;;;;;;;;;;;;;;;;;;;;IAOuD;;EAIvD,6BAAyB;EAIzB,2BAA2B;EAS3B;EAwEA,UAAU;;;;cCvOC,2BAA2B;EACtC,OAAO;EACP,cAAc;EACd,SAAS;EACT,SAAS;EACT,QAAQ;EACR,eAAe;EAEf,QAAQ;EACR,UAAU;EACV;IAAsB;IAAc;;EAEpC,YACE,OAAO,OACP,SAAS,gBACT,eAAe,qBACf,cAAc,OACd,mBACA,gBAAe;EAiBjB,mBAAe,8BAAA;EAIf,YAAY,UAAU;EAItB;;;;IAjC4B;IAAe;;EAkD3C,aAAa,mBAAmB;EAehC,aAAa;EAGb,qBAAqB;EAUrB,WAAW,cAAc,SAAS,YAAY;EAW9C,IAAI,kBAAkB,YAAS;EAuB/B,MAAM,YAAS;EAIT,OACJ,oBACA,cACA,UAAU,QAAQ,kBAAe;;;;iBC9GrB,oBACR,qBACA,KAAK,wBACL,qBAAqB,uCACrB,gCAAgC,MAAM,qCACtC,oBAAoB,iBAAiB,gCACrC,4BAA4B,MAAM,2BAA2B,sBAC7D,6BAA6B,MA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ACjB,UAAU,QAAQ,eAAe,OAAO;IAExC;IACA;;EAGF,cAAc,MAAM;;KAIV,kBAAkB,iBAAiB,0BAC7C;UASe;EACf,OACE,aACA;IAAO,SAAS;IAAgB,OAAO;eAC7B;EACZ;EACA;EACA;EACA;;UAIe;EACf;EACA,SAAS;EACT;EACA;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;;;;cC5NW;EACX,SAAS;EACT,OAAO;EACP,cAAc;EACd,eAAe;EAEf,YAAY,OAAO,OAAO,SAAS,qBAAqB,eAAe,OAAO,gBAAgB;EAO9F,qBAAqB,UAAU,oBAAiB;EAI1C,OAAO,oBAAoB,cAAc,UAAU,QAAQ,kBAAkB,QAAQ,YAAY;;;;iBCGzF,oBAAoB,YAAY;iBAIhC,YAAY,qBAAqB;iBAkCjC,aAAa;iBAKb;iBAIA,qBACd,UAAU,mBACV,MAAM,qBACN;EAAW,OAAO;IACjB;iBAyEa,oBACR,qBAAqB,+BACrB;EAAiB;EAAY,MAAM;SACnC,sBAAsB,2BAA2B,qBACjD,YAAY,gCAChB,cACA,sBAEF,UAAU,kBAAkB,mBAAmB,mBAAmB,OAClE,SAAS,sBAAsB,mBAAmB,mBAAmB,OAErE,KAAK,wBACL,QAAQ,SAAS,cACjB,UAAU,eACV,YAAY,OACV,SAAS,SAAS,UAAU,QAAQ,oBAAoB,QAAQ"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ReferencedResource.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/creator-register.ts","../src/types.ts","../src/Creator.ts","../src/utils.ts"],"mappings":";;;;;;;cAIa;EACX,OAAO;EACP,UAAU,YAAY;EACtB,WAAW;EACX,UAAU;EACV,YAAY,WAAW,YAAY,kBAAkB,OAAO;EAa5D;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;MAKQ;MACA;;;EASR;;;;cCtCW;EACX;EACA,MAAM,eAAe;EACrB;EACA;EACA;EACA,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AAgB,OAAO;eAAmB;EAC9E;EACA;EACA;EACA;;UAIe;EACf,sBAAsB;EACtB;EACA,SAAS;EACT;EACA;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;;;;cCtPW;EACX,SAAS;EACT,OAAO;EACP,cAAc;EACd,eAAe;EAEf,YAAY,OAAO,OAAO,SAAS,qBAAqB,eAAe,OAAO,gBAAgB;EAO9F,qBAAqB,UAAU,oBAAiB;EAI1C,OAAO,oBAAoB,cAAc,UAAU,QAAQ,kBAAkB,QAAQ,YAAY;;;;iBCJzF,oBAAoB,YAAY;iBAIhC,YAAY,qBAAqB;iBAkCjC,aAAa;iBAKb;iBAIA,qBACd,UAAU,mBACV,MAAM,qBACN;EAAW,OAAO;IACjB;iBAyEa,oBACR,qBAAqB,+BACrB;EAAiB;EAAY,MAAM;SACnC,sBAAsB,2BAA2B,qBACjD,YAAY,gCAChB,cACA,sBAEF,UAAU,kBAAkB,mBAAmB,mBAAmB,OAClE,SAAS,sBAAsB,mBAAmB,mBAAmB,OAErE,KAAK,wBACL,QAAQ,SAAS,cACjB,UAAU,eACV,YAAY,OACV,SAAS,SAAS,UAAU,QAAQ,oBAAoB,QAAQ"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Vault as e}from"@iiif/helpers/vault";import{addMappings as t,batchActions as n,entityActions as r,importEntities as i}from"@iiif/helpers/vault/actions";import{annotationResponseToSelector as a,seraliseSupportedSelector as o}from"react-iiif-vault";import{HAS_PART as s,PART_OF as c,emptyAgent as l,emptyAnnotation as u,emptyAnnotationPage as d,emptyCanvas as f,emptyCollection as p,emptyManifest as m,emptyRange as h,emptyService as g,isSpecificResource as _,toRef as v}from"@iiif/parser";import{references as y}from"@manifest-editor/editor-api";function b(e){"@babel/helpers - typeof";return b=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},b(e)}function x(e,t){if(b(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(b(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function S(e){var t=x(e,`string`);return b(t)==`symbol`?t:t+``}function C(e,t,n){return(t=S(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var w=class{constructor(e,t){C(this,`vault`,void 0),C(this,`original`,void 0),C(this,`reference`,void 0),C(this,`resource`,void 0),this.vault=t,this.original=e,this.reference=_(e)?e.source:e,this.resource=_(e)?e:{type:`SpecificResource`,source:this.reference}}ref(){return this.reference}specificResource(){return this.resource}optionalSpecificResource(){return _(this.original)?{...this.original,source:{id:this.original.source?.id,type:this.original.source?.type}}:this.original}get(){return this.vault.get(this.resource)}};function T(e){return e.configKey??e.id}function E(e){switch(e){case`Image`:case`Video`:case`Sound`:case`Dataset`:case`Text`:case`TextualBody`:case`Composite`:case`List`:case`Choice`:case`Independents`:case`Audience`:return`ContentResource`;case`ImageService1`:case`ImageService2`:case`ImageService3`:return`Service`}return e}const D={Annotation:u,AnnotationPage:d,Canvas:f,Collection:p,Manifest:m,Range:h,ResourceProvider:l,Service:g};function O(e){let t=E(e);return D[t]||{}}function k(){return`${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`}function A(e,t,n){let r=[];if(t.length===0)return[];let i=v(e.parent),a=e.property,o=e.filter;for(let s of t)if(!(o&&(!s.tags||!s.tags.includes(o)))&&i&&a){if(s.supports.parentTypes&&!s.supports.parentTypes.includes(i.type)||s.supports.parentFields&&!s.supports.parentFields.includes(a))continue;if(s.supports.parentFieldMap){let e=s.supports.parentFieldMap[i.type];if(!e||!e.includes(a))continue}if(s.supports.disallowPainting&&e.isPainting||s.supports.onlyPainting&&!e.isPainting||s.supports.custom&&!s.supports.custom({property:a,resource:i,atIndex:e.index},n.vault))continue;let t=Object.keys(e.initialData||{}).filter(e=>e!==`skipEditingOnCreate`);if(!s.supports.initialData&&t.length!==0||s.resourceType!==e.type&&!(s.additionalTypes||[]).includes(e.type))continue;r.push(s)}return r}function j(e,t,n,r){return(i,a={})=>(typeof t!=`string`&&(a.parent={property:n,resource:t,atIndex:a?.parent?.atIndex}),e.create(r,i,a))}var M=class e{constructor(t,n){C(this,`resource`,void 0),C(this,`warnings`,[]),C(this,`errors`,[]),C(this,`partOf`,void 0),C(this,`references`,[]),C(this,`embedded`,[]),C(this,`vault`,void 0),C(this,`specificResource`,void 0),this.vault=n;let r={...t};if(r.type===`SpecificResource`){let e=r.source;this.specificResource={...r,source:{id:e.id,type:E(e.type)}},r=e}let i=Object.keys(r),a=O(r.type);for(let t of i)if(!(y.inlineProperties.includes(t)||!y.all.includes(t))){if(r.type===`Range`&&t===`items`){let e=[];for(let i of r[t]){if(i instanceof w){this.references.push(i),e.push(i);continue}let a=new w(i,n);e.push(a),r[t]=a}r[t]=e;continue}if(r.type===`Manifest`&&t===`start`){let e=r[t];if(e instanceof w){this.references.push(e);continue}let i=new w(e,n);r[t]=i;continue}if(r.type===`Annotation`&&t===`target`){let e=r[t];if(e instanceof w){this.references.push(e);continue}typeof e==`string`&&(e={id:e,type:`Canvas`});let i=new w(e,n);r[t]=i;continue}if(!y.single.includes(t)&&(y.externalProperties.includes(t)||y.internalProperties.includes(t))){let i=r[t]||[],a=Array.isArray(i)?i:[i],o=[];for(let t of a){if(t instanceof w){this.references.push(t),o.push(t);continue}if(t instanceof e){this.embedded.push(t),o.push(t);continue}if(_(t)){let r=new e(t,n);this.embedded.push(r),o.push(r);continue}if(this.vault.get(t,{skipSelfReturn:!0})){let e=E(t.type),r=new w({id:t.id,type:e},n);this.references.push(r),o.push(r)}else{let r=new e(t,n);this.embedded.push(r),o.push(r)}}r[t]=o}}this.resource={...a,...r}}get(){return this.resource}getSpecificResource(){let e=this.ref();return _(e)?e:{type:`SpecificResource`,source:e}}ref(){return this.specificResource?this.specificResource:{id:this.resource.id,type:E(this.resource.type)}}getAllReferencedResources(){return this.references}getAllEmbeddedResources(){let e=[];for(let t of this.embedded)e.push(...t.getAllEmbeddedResources());return e.push(...this.embedded),e}getVaultResource(){let t=this.resource,n=Object.keys(t),r={};for(let i of n){if(y.inlineProperties.includes(i)||!y.all.includes(i)){r[i]=t[i];continue}if(y.single.includes(i)){let e=t[i];r[i]=e instanceof w?t.type===`Manifest`&&i===`start`||t.type===`Annotation`&&i===`target`?e.specificResource():e.optionalSpecificResource():t[i];continue}if(t[i]){r[i]=[];for(let n of t[i]||[]){if(t.type===`Range`&&i===`items`){n instanceof w&&(n.ref().type===`Canvas`?r[i].push(n.specificResource()):r[i].push(n.ref())),n instanceof e&&(n.ref().type===`Canvas`?r[i].push(n.getSpecificResource()):r[i].push(n.ref()));continue}n instanceof w&&r[i].push(n.optionalSpecificResource()),n instanceof e&&r[i].push(n.ref())}}}return this.partOf&&(r[s]=r[s]||[],r[s].push(this.partOf)),r}setPartOf(e){let t=this.ref();this.partOf={id:t.id,type:E(t.type),[c]:e}}},N=class{constructor(e,t,n,r,i,o={}){C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`configs`,void 0),C(this,`options`,void 0),C(this,`config`,void 0),C(this,`creatorConfig`,void 0),C(this,`target`,void 0),C(this,`selector`,void 0),C(this,`serialisedSelector`,null),this.vault=e,this.previewVault=r,this.options=t,this.configs=n,this.creatorConfig=o,this.config=o[i]||{},this.target=this.options.target||this.options.parent?.resource;let s=this.options.initialData?.selector;this.selector=s?a(s):null,this.options.initialData?.getSerialisedSelector&&(this.serialisedSelector=this.options.initialData.getSerialisedSelector())}getPreviewVault(){return this.previewVault}setSelector(e){this.selector=e}getSerialisedSelector(){if(this.serialisedSelector)return this.serialisedSelector;let e=this.selector;if(e){let t=o(e,this.options.initialData?.on);if(t)return t}return null}getTarget(){let e=this.target,t=this.getSerialisedSelector();return t?{type:`SpecificResource`,source:e,selector:t}:e}getParent(){return this.options.parent?.resource}getParentResource(){let e=this.getParent();if(e)return{type:`SpecificResource`,source:e}}generateId(e,t){return t&&t instanceof w&&(t=t.ref()),this.options.rootId&&(t={id:this.options.rootId,type:`none`}),`${(t||this.options.parent?.resource)?.id}/${e}/${k()}`}ref(e){let t=``,n=``;return typeof e==`string`?t=e:(t=e.id,n=e.type),n=this.vault.getState().iiif.mapping[t]||n||`unknown`,new w({id:t,type:n},this.vault)}embed(e){return new M(e,this.vault)}async create(e,t,n){let r=this.configs.find(t=>t.id===e);if(!r)throw Error(`Creator config ${e} not found`);return await new P(this.vault,r,t,this.configs,this.previewVault,n,this.creatorConfig).run()}},P=class{constructor(e,t,n,r,i,a,o){C(this,`resource`,null),C(this,`payload`,void 0),C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`definition`,void 0),C(this,`options`,void 0),C(this,`configs`,void 0),C(this,`creatorConfig`,void 0),this.vault=e,this.previewVault=i,this.definition=t,this.payload=n,this.configs=this.filterCreateConfigs(r),this.creatorConfig=o||{},this.options={targetType:a?.targetType||t.resourceType,...a||{}}}filterCreateConfigs(e){let t={};for(let n of e)t[n.id]=n;return Object.values(t)}async run(){let e=new N(this.vault,this.options,this.configs,this.previewVault,T(this.definition),this.creatorConfig),t=await this.definition.create(this.payload,e);if(Array.isArray(t)){let e=[];for(let n of t)n instanceof M?e.push(n):e.push(new M(n,this.vault));return this.resource=e,this.resource}return this.resource=t instanceof M?t:new M(t,this.vault),this.resource}getActions(){if(!this.resource)return[];let e=Array.isArray(this.resource)?this.resource:[this.resource],n=[],r={},a={};for(let o of e){this.options.parent&&o.setPartOf(this.options.parent.resource.id);let e=[...o.getAllEmbeddedResources(),o];for(let t of e){let e=t.getVaultResource();if(!e.type||!e.id)continue;let n=E(e.type);r[n]=r[n]?r[n]:{},r[n][e.id]=e,a[e.id]=n}n.push(i({entities:r})),n.push(t({mapping:a}))}return n}commit(e=[]){if(!this.resource)throw Error(`Creator has not been run`);let t=this.getActions();return this.vault.dispatch(n({actions:[...t,...e]})),Array.isArray(this.resource)?this.resource.map(e=>e.ref()):this.resource.ref()}},F=class{constructor(t,n,r,i){C(this,`configs`,void 0),C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`creatorConfig`,void 0),this.configs=n||[],this.vault=t,this.previewVault=r||new e,this.creatorConfig=i||{}}matchBasedOnResource(e){return A(e,this.configs||[],{vault:this.vault})}async create(e,t,n){let i=this.configs.find(t=>t.id===e);if(!i)throw Error(`Creator config ${e} not found`);if(n?.parent){if(i.supports.parentTypes&&!i.supports.parentTypes.includes(n.parent.resource.type))throw Error(`Definition ${e} does not support parent type ${n.parent.resource.type}`);if(i.supports.parentFields&&!i.supports.parentFields.includes(n.parent.property))throw Error(`Definition ${e} does not support parent field ${n.parent.property}`);if(i.supports.parentFieldMap){let t=i.supports.parentFieldMap[n.parent.resource.type];if(!t||!t.includes(n.parent.property))throw Error(`Definition ${e} does not support parent ${n.parent.property} / ${n.parent.property}`)}if(i.supports.custom&&!i.supports.custom(n.parent,this.vault))throw Error(`Definition does not support resource`)}let a=new P(this.vault,i,t,this.configs,this.previewVault,n,this.creatorConfig),o=await a.run(),s=Array.isArray(o)?o:[o],c=[];for(let e of s)n?.parent&&(n.parent.property===`start`||n.parent.property===`target`?c.push(r.modifyEntityField({id:n.parent.resource.id,type:n.parent.resource.type,value:e.ref(),key:n.parent.property})):c.push(r.addReference({id:n.parent.resource.id,type:n.parent.resource.type,reference:e.ref(),key:n.parent.property,index:n.parent.atIndex})));let l=a.commit(c);if(n?.parent&&i.sideEffects){for(let e of i.sideEffects)if(e.run){let t=Array.isArray(l)?l:[l];for(let r of t)await e.run(r,{vault:this.vault,options:n})}}return l}};function I(e){return e}function L(e,t,n={}){let r=e.render?r=>{let i={...r,options:{...r.options||{},initialData:{...t||{},...r.options?.initialData||{},...n||{}}}};return e.render?.(i)}:void 0;return{...e,render:r}}function R(e,t){let n=n=>t(n,e.render);return{...e,render:n}}export{F as Creator,M as CreatorResource,j as creatorHelper,I as defineCreator,T as getCreatorConfigKey,O as getEmptyType,A as matchBasedOnResource,k as randomId,E as resolveType,R as withCustomRender,L as withInitialData};
1
+ import{Vault as e}from"@iiif/helpers/vault";import{addMappings as t,batchActions as n,entityActions as r,importEntities as i,metaActions as a}from"@iiif/helpers/vault/actions";import{EditorInstance as o,beginCanvasComposition as s,fitWithinBounds as c,getCanvasLayout as l,getEmptyCanvasPlaceholders as u,getImageSize as d,layoutSlotToPixels as f,references as p,setCanvasLayout as m,syncCanvasPaintOrder as h,validRectangle as g,validSize as _}from"@manifest-editor/editor-api";import{annotationResponseToSelector as v,seraliseSupportedSelector as y}from"react-iiif-vault";import{HAS_PART as b,PART_OF as x,emptyAgent as S,emptyAnnotation as C,emptyAnnotationPage as w,emptyCanvas as T,emptyCollection as E,emptyManifest as D,emptyRange as O,emptyService as k,isSpecificResource as A,toRef as j}from"@iiif/parser";function M(e,t,n){let r=n.placeholderPosition;if(!r)return;let i=(Array.isArray(t)?t:[t]).flatMap(t=>t.type===`Annotation`?[e.get(t)]:n.parent?.resource.type===`Annotation`&&n.parent.property===`body`?[e.get(n.parent.resource)]:[]),a=e.get({id:r.canvasId,type:`Canvas`}),s=l(e,a.id);if(s?.customised===!1&&r.placeholderId){let t=s.slots.find(e=>e.id===r.placeholderId),n=[t,...u(e,a).filter(e=>e.id!==t.id)];if(!t||i.length>n.length||t.annotationIds?.length&&t.annotationIds[0]!==r.replaceAnnotationId)throw Error(`This position is no longer available. Choose an empty position.`);{let t=s.slots.map(e=>({...e}));if(i.forEach((i,s)=>{let l=n[s],u=d(e,i)||r.bounds;new o({vault:e,reference:i}).annotation.target.setPosition(c(u,f(l.bounds,a))),t.find(e=>e.id===l.id).annotationIds=[i.id]}),r.replaceAnnotationId)for(let t of a.items)e.modifyEntityField(t,`items`,e.get(t).items.filter(e=>e.id!==r.replaceAnnotationId));m(e,a.id,{...s,slots:t}),h(e,a)}return}let p=[],g=Math.ceil(Math.sqrt(i.length)),v=Math.ceil(i.length/g);e.batch(()=>{i.forEach((t,n)=>{let i=t.body?.[0]&&e.get(t.body[0]),a=d(e,t)||(i&&_(i)?i:r.bounds),s={x:r.bounds.x+n%g*r.bounds.width/g,y:r.bounds.y+Math.floor(n/g)*r.bounds.height/v,width:r.bounds.width/g,height:r.bounds.height/v},l=new o({vault:e,reference:{id:t.id,type:`Annotation`}}),u=c(a,s);l.annotation.target.set({type:`SpecificResource`,source:{id:r.canvasId,type:`Canvas`},selector:{type:`FragmentSelector`,value:`xywh=${u.x},${u.y},${u.width},${u.height}`}}),p.push(t.id)});let t=l(e,r.canvasId);if(r.replaceAnnotationId)for(let t of a.items)e.modifyEntityField(t,`items`,e.get(t).items.filter(e=>e.id!==r.replaceAnnotationId));t&&r.placeholderId&&p.length&&m(e,r.canvasId,{...t,slots:t.slots.map(e=>e.id===r.placeholderId?{...e,annotationIds:[...(e.annotationIds||[]).filter(e=>e!==r.replaceAnnotationId),...p]}:e)})})}function N(e){"@babel/helpers - typeof";return N=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},N(e)}function P(e,t){if(N(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(N(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function F(e){var t=P(e,`string`);return N(t)==`symbol`?t:t+``}function I(e,t,n){return(t=F(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var L=class{constructor(e,t){I(this,`vault`,void 0),I(this,`original`,void 0),I(this,`reference`,void 0),I(this,`resource`,void 0),this.vault=t,this.original=e,this.reference=A(e)?e.source:e,this.resource=A(e)?e:{type:`SpecificResource`,source:this.reference}}ref(){return this.reference}specificResource(){return this.resource}optionalSpecificResource(){return A(this.original)?{...this.original,source:{id:this.original.source?.id,type:this.original.source?.type}}:this.original}get(){return this.vault.get(this.resource)}};function R(e){return e.configKey??e.id}function z(e){switch(e){case`Image`:case`Video`:case`Sound`:case`Dataset`:case`Text`:case`TextualBody`:case`Composite`:case`List`:case`Choice`:case`Independents`:case`Audience`:return`ContentResource`;case`ImageService1`:case`ImageService2`:case`ImageService3`:return`Service`}return e}const B={Annotation:C,AnnotationPage:w,Canvas:T,Collection:E,Manifest:D,Range:O,ResourceProvider:S,Service:k};function V(e){let t=z(e);return B[t]||{}}function H(){return`${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`}function U(e,t,n){let r=[];if(t.length===0)return[];let i=j(e.parent),a=e.property,o=e.filter;for(let s of t)if(!(o&&(!s.tags||!s.tags.includes(o)))&&i&&a){if(s.supports.parentTypes&&!s.supports.parentTypes.includes(i.type)||s.supports.parentFields&&!s.supports.parentFields.includes(a))continue;if(s.supports.parentFieldMap){let e=s.supports.parentFieldMap[i.type];if(!e||!e.includes(a))continue}if(s.supports.disallowPainting&&e.isPainting||s.supports.onlyPainting&&!e.isPainting||s.supports.custom&&!s.supports.custom({property:a,resource:i,atIndex:e.index},n.vault))continue;let t=Object.keys(e.initialData||{}).filter(e=>e!==`skipEditingOnCreate`);if(!s.supports.initialData&&t.length!==0||s.resourceType!==e.type&&!(s.additionalTypes||[]).includes(e.type))continue;r.push(s)}return r}function W(e,t,n,r){return(i,a={})=>(typeof t!=`string`&&(a.parent={property:n,resource:t,atIndex:a?.parent?.atIndex}),e.create(r,i,a))}var G=class e{constructor(t,n){I(this,`resource`,void 0),I(this,`meta`,{}),I(this,`warnings`,[]),I(this,`errors`,[]),I(this,`partOf`,void 0),I(this,`references`,[]),I(this,`embedded`,[]),I(this,`vault`,void 0),I(this,`specificResource`,void 0),this.vault=n;let r={...t};if(r.type===`SpecificResource`){let e=r.source;this.specificResource={...r,source:{id:e.id,type:z(e.type)}},r=e}let i=Object.keys(r),a=V(r.type);for(let t of i)if(!(p.inlineProperties.includes(t)||!p.all.includes(t))){if(r.type===`Range`&&t===`items`){let e=[];for(let i of r[t]){if(i instanceof L){this.references.push(i),e.push(i);continue}let a=new L(i,n);e.push(a),r[t]=a}r[t]=e;continue}if(r.type===`Manifest`&&t===`start`){let e=r[t];if(e instanceof L){this.references.push(e);continue}let i=new L(e,n);r[t]=i;continue}if(r.type===`Annotation`&&t===`target`){let e=r[t];if(e instanceof L){this.references.push(e);continue}typeof e==`string`&&(e={id:e,type:`Canvas`});let i=new L(e,n);r[t]=i;continue}if(!p.single.includes(t)&&(p.externalProperties.includes(t)||p.internalProperties.includes(t))){let i=r[t]||[],a=Array.isArray(i)?i:[i],o=[];for(let t of a){if(t instanceof L){this.references.push(t),o.push(t);continue}if(t instanceof e){this.embedded.push(t),o.push(t);continue}if(A(t)){let r=new e(t,n);this.embedded.push(r),o.push(r);continue}if(this.vault.get(t,{skipSelfReturn:!0})){let e=z(t.type),r=new L({id:t.id,type:e},n);this.references.push(r),o.push(r)}else{let r=new e(t,n);this.embedded.push(r),o.push(r)}}r[t]=o}}this.resource={...a,...r}}get(){return this.resource}getSpecificResource(){let e=this.ref();return A(e)?e:{type:`SpecificResource`,source:e}}ref(){return this.specificResource?this.specificResource:{id:this.resource.id,type:z(this.resource.type)}}getAllReferencedResources(){return this.references}getAllEmbeddedResources(){let e=[];for(let t of this.embedded)e.push(...t.getAllEmbeddedResources());return e.push(...this.embedded),e}getVaultResource(){let t=this.resource,n=Object.keys(t),r={};for(let i of n){if(p.inlineProperties.includes(i)||!p.all.includes(i)){r[i]=t[i];continue}if(p.single.includes(i)){let e=t[i];r[i]=e instanceof L?t.type===`Manifest`&&i===`start`||t.type===`Annotation`&&i===`target`?e.specificResource():e.optionalSpecificResource():t[i];continue}if(t[i]){r[i]=[];for(let n of t[i]||[]){if(t.type===`Range`&&i===`items`){n instanceof L&&(n.ref().type===`Canvas`?r[i].push(n.specificResource()):r[i].push(n.ref())),n instanceof e&&(n.ref().type===`Canvas`?r[i].push(n.getSpecificResource()):r[i].push(n.ref()));continue}n instanceof L&&r[i].push(n.optionalSpecificResource()),n instanceof e&&r[i].push(n.ref())}}}return this.partOf&&(r[b]=r[b]||[],r[b].push(this.partOf)),r}setPartOf(e){let t=this.ref();this.partOf={id:t.id,type:z(t.type),[x]:e}}},K=class{constructor(e,t,n,r,i,a={}){I(this,`vault`,void 0),I(this,`previewVault`,void 0),I(this,`configs`,void 0),I(this,`options`,void 0),I(this,`config`,void 0),I(this,`creatorConfig`,void 0),I(this,`target`,void 0),I(this,`selector`,void 0),I(this,`serialisedSelector`,null),this.vault=e,this.previewVault=r,this.options=t,this.configs=n,this.creatorConfig=a,this.config=a[i]||{},this.target=this.options.target||this.options.parent?.resource;let o=this.options.initialData?.selector;this.selector=o?v(o):null,this.options.initialData?.getSerialisedSelector&&(this.serialisedSelector=this.options.initialData.getSerialisedSelector())}getPreviewVault(){return this.previewVault}setSelector(e){this.selector=e}getSerialisedSelector(){if(this.serialisedSelector)return this.serialisedSelector;let e=this.selector;if(e){let t=y(e,this.options.initialData?.on);if(t)return t}return null}getTarget(){let e=this.target,t=this.getSerialisedSelector();return t?{type:`SpecificResource`,source:e,selector:t}:e}getParent(){return this.options.parent?.resource}getParentResource(){let e=this.getParent();if(e)return{type:`SpecificResource`,source:e}}generateId(e,t){return t&&t instanceof L&&(t=t.ref()),this.options.rootId&&(t={id:this.options.rootId,type:`none`}),`${(t||this.options.parent?.resource)?.id}/${e}/${H()}`}ref(e){let t=``,n=``;return typeof e==`string`?t=e:(t=e.id,n=e.type),n=this.vault.getState().iiif.mapping[t]||n||`unknown`,new L({id:t,type:n},this.vault)}embed(e){return new G(e,this.vault)}async create(e,t,n){let r=this.configs.find(t=>t.id===e);if(!r)throw Error(`Creator config ${e} not found`);return await new q(this.vault,r,t,this.configs,this.previewVault,n,this.creatorConfig).run()}},q=class{constructor(e,t,n,r,i,a,o){I(this,`resource`,null),I(this,`payload`,void 0),I(this,`vault`,void 0),I(this,`previewVault`,void 0),I(this,`definition`,void 0),I(this,`options`,void 0),I(this,`configs`,void 0),I(this,`creatorConfig`,void 0),this.vault=e,this.previewVault=i,this.definition=t,this.payload=n,this.configs=this.filterCreateConfigs(r),this.creatorConfig=o||{},this.options={targetType:a?.targetType||t.resourceType,...a||{}}}filterCreateConfigs(e){let t={};for(let n of e)t[n.id]=n;return Object.values(t)}async run(){let e=new K(this.vault,this.options,this.configs,this.previewVault,R(this.definition),this.creatorConfig),t=await this.definition.create(this.payload,e);if(Array.isArray(t)){let e=[];for(let n of t)n instanceof G?e.push(n):e.push(new G(n,this.vault));return this.resource=e,this.resource}return this.resource=t instanceof G?t:new G(t,this.vault),this.resource}getActions(){if(!this.resource)return[];let e=Array.isArray(this.resource)?this.resource:[this.resource],n=[],r={},o={};for(let s of e){this.options.parent&&s.setPartOf(this.options.parent.resource.id);let e=[...s.getAllEmbeddedResources(),s];for(let t of e){let e=t.getVaultResource();for(let[r,i]of Object.entries(t.meta))for(let[t,o]of Object.entries(i))n.push(a.setMetaValue({id:e.id,meta:r,key:t,value:o}));if(!e.type||!e.id)continue;let i=z(e.type);r[i]=r[i]?r[i]:{},r[i][e.id]=e,o[e.id]=i}n.push(i({entities:r})),n.push(t({mapping:o}))}return n}commit(e=[]){if(!this.resource)throw Error(`Creator has not been run`);let t=this.getActions();return this.vault.dispatch(n({actions:[...t,...e]})),Array.isArray(this.resource)?this.resource.map(e=>e.ref()):this.resource.ref()}},J=class{constructor(t,n,r,i){I(this,`configs`,void 0),I(this,`vault`,void 0),I(this,`previewVault`,void 0),I(this,`creatorConfig`,void 0),this.configs=n||[],this.vault=t,this.previewVault=r||new e,this.creatorConfig=i||{}}matchBasedOnResource(e){return U(e,this.configs||[],{vault:this.vault})}async create(e,t,n){let i=this.configs.find(t=>t.id===e);if(!i)throw Error(`Creator config ${e} not found`);if(n?.parent){if(i.supports.parentTypes&&!i.supports.parentTypes.includes(n.parent.resource.type))throw Error(`Definition ${e} does not support parent type ${n.parent.resource.type}`);if(i.supports.parentFields&&!i.supports.parentFields.includes(n.parent.property))throw Error(`Definition ${e} does not support parent field ${n.parent.property}`);if(i.supports.parentFieldMap){let t=i.supports.parentFieldMap[n.parent.resource.type];if(!t||!t.includes(n.parent.property))throw Error(`Definition ${e} does not support parent ${n.parent.property} / ${n.parent.property}`)}if(i.supports.custom&&!i.supports.custom(n.parent,this.vault))throw Error(`Definition does not support resource`)}let a=new q(this.vault,i,t,this.configs,this.previewVault,n,this.creatorConfig);if(n?.placeholderPosition&&!g(n.placeholderPosition.bounds))throw Error(`Invalid placeholder position`);let o=await a.run(),c=Array.isArray(o)?o:[o],d=[];for(let e of c)n?.parent&&(n.parent.property===`start`||n.parent.property===`target`?d.push(r.modifyEntityField({id:n.parent.resource.id,type:n.parent.resource.type,value:e.ref(),key:n.parent.property})):d.push(r.addReference({id:n.parent.resource.id,type:n.parent.resource.type,reference:e.ref(),key:n.parent.property,index:n.placeholderPosition?.replaceAnnotationId?this.vault.get(n.parent.resource)[n.parent.property]?.findIndex(e=>e.id===n.placeholderPosition.replaceAnnotationId):n.parent.atIndex})));let f=n?.placeholderPosition;if(f){if(f.replaceAnnotationId&&c.length!==1)throw Error(`Choose one image to replace this image. Nothing has been changed.`);let e=this.vault.get({id:f.canvasId,type:`Canvas`}),t=l(this.vault,e.id);if(t?.customised===!1){let n=t.slots.find(e=>e.id===f.placeholderId),r=u(this.vault,e);if(!n||(f.replaceAnnotationId?n.annotationIds?.length!==1||n.annotationIds[0]!==f.replaceAnnotationId||c.length!==1:!r.some(e=>e.id===n.id)||c.length>r.length))throw Error(`Not enough empty positions. Reduce the selection or choose a larger layout. Nothing has been added.`)}s(this.vault,e)}let p=a.commit(d);if(n?.parent&&i.sideEffects){for(let e of i.sideEffects)if(e.run&&!(n.placeholderPosition&&e.spatial&&e.canvasInteraction)){let t=Array.isArray(p)?p:[p];for(let r of t)await e.run(r,{vault:this.vault,options:n})}}return n?.placeholderPosition&&M(this.vault,p,a.options),p}};function Y(e){return e}function X(e,t,n={}){let r=e.render?r=>{let i={...r,options:{...r.options||{},initialData:{...t||{},...r.options?.initialData||{},...n||{}}}};return e.render?.(i)}:void 0;return{...e,render:r}}function Z(e,t){let n=n=>t(n,e.render);return{...e,render:n}}export{J as Creator,G as CreatorResource,W as creatorHelper,Y as defineCreator,R as getCreatorConfigKey,V as getEmptyType,U as matchBasedOnResource,H as randomId,z as resolveType,Z as withCustomRender,X as withInitialData};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/ReferencedResource.ts","../src/utils.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/CreatorRuntime.ts","../src/Creator.ts","../src/creator-register.ts"],"sourcesContent":["import type { Vault } from \"@iiif/helpers/vault\";\nimport { isSpecificResource } from \"@iiif/parser\";\nimport type { Reference, SpecificResource } from \"@iiif/presentation-3\";\n\nexport class ReferencedResource {\n vault: Vault;\n original: Reference | SpecificResource;\n reference: Reference;\n resource: SpecificResource;\n constructor(reference: Reference | SpecificResource, vault: Vault) {\n this.vault = vault;\n this.original = reference;\n this.reference = isSpecificResource(reference)\n ? reference.source\n : reference;\n this.resource = isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: this.reference };\n }\n\n // @todo editable specific resource.\n\n ref() {\n return this.reference;\n }\n\n specificResource() {\n return this.resource;\n }\n\n optionalSpecificResource() {\n if (isSpecificResource(this.original)) {\n return {\n ...this.original,\n source: {\n id: this.original.source?.id,\n type: this.original.source?.type,\n },\n };\n }\n\n // @todo check if there are targets here that would make this a specific resource.\n return this.original;\n }\n\n get() {\n return this.vault.get(this.resource);\n }\n}\n","import type { Entities, Vault } from \"@iiif/helpers/vault\";\nimport {\n emptyAgent,\n emptyAnnotation,\n emptyAnnotationPage,\n emptyCanvas,\n emptyCollection,\n emptyManifest,\n emptyRange,\n emptyService,\n toRef,\n} from \"@iiif/parser\";\nimport type {\n CreatorDefinitionFilterByParent,\n IIIFManifestEditor,\n} from \"./creator-register\";\nimport type {\n AllAvailableParentTypes,\n CreatableResource,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n GetCreatorPayload,\n GetSupportedResourceFields,\n ResolvedCreatorReturn,\n} from \"./types\";\n\nexport function getCreatorConfigKey(definition: CreatorDefinition): string {\n return definition.configKey ?? definition.id;\n}\n\nexport function resolveType(type: string): keyof Entities {\n switch (type) {\n case \"Image\":\n case \"Video\":\n case \"Sound\":\n case \"Dataset\":\n case \"Text\":\n case \"TextualBody\":\n case \"Composite\":\n case \"List\":\n case \"Choice\":\n case \"Independents\":\n case \"Audience\":\n return \"ContentResource\";\n case \"ImageService1\":\n case \"ImageService2\":\n case \"ImageService3\":\n return \"Service\";\n }\n\n return type as any;\n}\n\nconst emptyTypes = {\n Annotation: emptyAnnotation,\n AnnotationPage: emptyAnnotationPage,\n Canvas: emptyCanvas,\n Collection: emptyCollection,\n Manifest: emptyManifest,\n Range: emptyRange,\n ResourceProvider: emptyAgent,\n Service: emptyService,\n};\n\nexport function getEmptyType(type: string): any {\n const key = resolveType(type);\n return emptyTypes[key as \"Manifest\"] || {};\n}\n\nexport function randomId() {\n return `${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`;\n}\n\nexport function matchBasedOnResource(\n resource: CreatableResource,\n list: CreatorDefinition[],\n options: { vault: Vault },\n): CreatorDefinition[] {\n const supported = [];\n if (list.length === 0) {\n return [];\n }\n const parent = toRef(resource.parent);\n const property = resource.property;\n const filter = resource.filter;\n\n for (const def of list) {\n if (filter) {\n if (!def.tags) continue;\n if (!def.tags.includes(filter)) {\n continue;\n }\n }\n\n if (parent && property) {\n if (def.supports.parentTypes) {\n if (!def.supports.parentTypes.includes(parent.type)) {\n continue;\n }\n }\n if (def.supports.parentFields) {\n if (!def.supports.parentFields.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.parentFieldMap) {\n const type = def.supports.parentFieldMap[parent.type];\n if (!type || !type.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.disallowPainting && resource.isPainting) {\n continue;\n }\n if (def.supports.onlyPainting && !resource.isPainting) {\n continue;\n }\n\n if (def.supports.custom) {\n const isValid = def.supports.custom(\n { property, resource: parent, atIndex: resource.index },\n options.vault,\n );\n if (!isValid) {\n continue;\n }\n }\n\n const initialDataKeys = Object.keys(resource.initialData || {}).filter(\n (key) => key !== \"skipEditingOnCreate\",\n );\n\n if (!def.supports.initialData && initialDataKeys.length !== 0) {\n continue;\n }\n\n if (def.resourceType !== resource.type) {\n if (!(def.additionalTypes || []).includes(resource.type)) {\n continue;\n }\n }\n supported.push(def);\n }\n }\n\n return supported;\n}\n\nexport function creatorHelper<\n const ResourceType extends AllAvailableParentTypes,\n const Parent extends { id: string; type: ResourceType },\n const ResourceField extends GetSupportedResourceFields<ResourceType>,\n const CID extends CreatorDefinitionFilterByParent<\n ResourceType,\n ResourceField\n >[\"id\"],\n Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>,\n Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>,\n>(\n ctx: CreatorFunctionContext,\n parent: Parent | ResourceType,\n property: ResourceField,\n definition: CID,\n): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return> {\n return (payload: Payload, options = {}) => {\n if (typeof parent !== \"string\") {\n options.parent = {\n property,\n resource: parent,\n atIndex: options?.parent?.atIndex,\n };\n }\n return ctx.create(definition, payload, options) as any;\n };\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport { HAS_PART, isSpecificResource, PART_OF } from \"@iiif/parser\";\nimport type { SpecificResource } from \"@iiif/presentation-3\";\nimport { references } from \"@manifest-editor/editor-api\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport { getEmptyType, resolveType } from \"./utils\";\n\nexport class CreatorResource {\n resource: any;\n warnings: string[] = [];\n errors: string[] = [];\n partOf: any;\n references: ReferencedResource[] = [];\n embedded: CreatorResource[] = [];\n vault: Vault;\n specificResource?: SpecificResource;\n\n constructor(inputData: any, vault: Vault) {\n this.vault = vault;\n let data = { ...inputData };\n\n if (data.type === \"SpecificResource\") {\n const source = data.source;\n this.specificResource = {\n ...data,\n source: { id: source.id, type: resolveType(source.type) },\n };\n data = source;\n }\n\n const properties = Object.keys(data);\n const defaultType = getEmptyType(data.type);\n\n for (const key of properties) {\n // These properties are NOT references and can be just included normally.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n continue;\n }\n\n if (data.type === \"Range\" && key === \"items\") {\n const newRange: any = [];\n for (const range of data[key]) {\n if (range instanceof ReferencedResource) {\n this.references.push(range);\n newRange.push(range);\n continue;\n }\n\n const rangeRef = new ReferencedResource(range, vault);\n newRange.push(rangeRef);\n data[key] = rangeRef;\n }\n\n data[key] = newRange;\n continue;\n }\n\n if (data.type === \"Manifest\" && key === \"start\") {\n const start = data[key];\n\n if (start instanceof ReferencedResource) {\n this.references.push(start);\n continue;\n }\n\n const startRef = new ReferencedResource(start, vault);\n data[key] = startRef;\n continue;\n }\n\n if (data.type === \"Annotation\" && key === \"target\") {\n let target = data[key];\n\n if (target instanceof ReferencedResource) {\n this.references.push(target);\n continue;\n }\n\n if (typeof target === \"string\") {\n target = { id: target, type: \"Canvas\" };\n }\n\n const targetRef = new ReferencedResource(target, vault);\n data[key] = targetRef;\n continue;\n }\n\n // @todo Handle single item cases. (not caught by the above 2 cases)\n if (references.single.includes(key as any)) {\n continue;\n }\n\n // This property SHOULD already be in the Vault OR an instance of creator resource.\n if (\n references.externalProperties.includes(key as any) ||\n references.internalProperties.includes(key as any)\n ) {\n const _items = (data[key] || []) as any[];\n const items = Array.isArray(_items) ? _items : [_items];\n const newItems: any[] = [];\n for (const item of items) {\n if (item instanceof ReferencedResource) {\n this.references.push(item);\n newItems.push(item);\n continue;\n }\n if (item instanceof CreatorResource) {\n this.embedded.push(item);\n newItems.push(item);\n continue;\n }\n\n // A SpecificResource carries its selector and source inline. Vault.get()\n // resolves it to its source, so an existing source must not turn the\n // wrapper into a plain reference.\n if (isSpecificResource(item)) {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n continue;\n }\n\n const exists = this.vault.get(item, { skipSelfReturn: true });\n if (exists) {\n const type = resolveType(item.type);\n const newItem = new ReferencedResource(\n { id: item.id, type },\n vault,\n );\n this.references.push(newItem);\n newItems.push(newItem);\n } else {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n }\n }\n data[key] = newItems;\n }\n }\n this.resource = { ...defaultType, ...data };\n }\n\n // This is what is returned from the creator instance\n get() {\n return this.resource;\n }\n\n getSpecificResource() {\n const reference = this.ref();\n return isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: reference };\n }\n\n ref() {\n if (this.specificResource) {\n return this.specificResource;\n }\n\n return {\n id: this.resource.id,\n type: resolveType(this.resource.type as string) as any,\n };\n }\n\n getAllReferencedResources() {\n return this.references;\n }\n\n getAllEmbeddedResources(): CreatorResource[] {\n const allEmbedded = [];\n for (const resource of this.embedded) {\n allEmbedded.push(...resource.getAllEmbeddedResources());\n }\n allEmbedded.push(...this.embedded);\n return allEmbedded;\n }\n\n getVaultResource() {\n const resource = this.resource;\n const properties = Object.keys(resource);\n const newResource: any = {};\n\n for (const key of properties) {\n // Skip these, they are just normal inline values.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n newResource[key] = resource[key];\n continue;\n }\n\n if (references.single.includes(key as any)) {\n const ref = resource[key];\n if (ref instanceof ReferencedResource) {\n // These MUST be specific resources.\n if (\n (resource.type === \"Manifest\" && key === \"start\") ||\n (resource.type === \"Annotation\" && key === \"target\")\n ) {\n newResource[key] = ref.specificResource();\n } else {\n newResource[key] = ref.optionalSpecificResource();\n }\n } else {\n newResource[key] = resource[key];\n }\n continue;\n }\n\n if (resource[key]) {\n newResource[key] = [];\n for (const item of resource[key] || []) {\n if (resource.type === \"Range\" && key === \"items\") {\n if (item instanceof ReferencedResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.specificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n if (item instanceof CreatorResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.getSpecificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n continue;\n }\n\n if (item instanceof ReferencedResource) {\n newResource[key].push(item.optionalSpecificResource());\n }\n if (item instanceof CreatorResource) {\n newResource[key].push(item.ref());\n }\n }\n }\n }\n\n if (this.partOf) {\n newResource[HAS_PART] = newResource[HAS_PART] || [];\n newResource[HAS_PART].push(this.partOf);\n }\n\n return newResource;\n }\n\n setPartOf(id: string) {\n const ref = this.ref();\n this.partOf = {\n id: ref.id,\n type: resolveType(ref.type),\n [PART_OF]: id,\n };\n }\n}\n","import type { SupportedSelector } from \"@iiif/helpers\";\nimport type { Vault } from \"@iiif/helpers/vault\";\nimport type {\n Reference,\n Selector,\n SpecificResource,\n} from \"@iiif/presentation-3\";\nimport {\n type AnnotationResponse,\n annotationResponseToSelector,\n seraliseSupportedSelector,\n} from \"react-iiif-vault\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport type {\n CreatorConfig,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n} from \"./types\";\nimport { randomId } from \"./utils\";\n\nexport class CreatorInstance implements CreatorFunctionContext {\n vault: Vault;\n previewVault: Vault;\n configs: CreatorDefinition[];\n options: CreatorOptions;\n config: Record<string, unknown>;\n creatorConfig: CreatorConfig;\n\n target: CreatorOptions[\"target\"];\n selector: SupportedSelector | undefined | null;\n serialisedSelector: { type: string; value: string } | null = null;\n\n constructor(\n vault: Vault,\n options: CreatorOptions,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n configKey: string,\n creatorConfig: CreatorConfig = {},\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.options = options;\n this.configs = createConfigs;\n this.creatorConfig = creatorConfig;\n this.config = creatorConfig[configKey] || {};\n this.target = this.options.target || this.options.parent?.resource;\n const response: AnnotationResponse = this.options.initialData?.selector;\n this.selector = response ? annotationResponseToSelector(response) : null;\n if (this.options.initialData?.getSerialisedSelector) {\n this.serialisedSelector =\n this.options.initialData.getSerialisedSelector();\n }\n }\n\n getPreviewVault() {\n return this.previewVault;\n }\n\n setSelector(selector: SupportedSelector) {\n this.selector = selector;\n }\n\n getSerialisedSelector() {\n if (this.serialisedSelector) {\n return this.serialisedSelector;\n }\n const selector = this.selector;\n if (selector) {\n const serialisedSelector = seraliseSupportedSelector(\n selector,\n this.options.initialData?.on,\n );\n if (serialisedSelector) {\n return serialisedSelector;\n }\n }\n return null;\n }\n\n getTarget(): SpecificResource | Reference | undefined {\n const target = this.target;\n const serialisedSelector = this.getSerialisedSelector();\n\n if (serialisedSelector) {\n return {\n type: \"SpecificResource\",\n source: target,\n selector: serialisedSelector as Selector,\n };\n }\n\n return target;\n }\n\n getParent(): Reference | undefined {\n return this.options.parent?.resource;\n }\n getParentResource(): SpecificResource | undefined {\n const parent = this.getParent();\n if (parent) {\n return {\n type: \"SpecificResource\",\n source: parent,\n };\n }\n }\n\n generateId(type: string, parent?: Reference | ReferencedResource) {\n if (parent && parent instanceof ReferencedResource) {\n parent = parent.ref();\n }\n if (this.options.rootId) {\n parent = { id: this.options.rootId, type: \"none\" };\n }\n\n return `${(parent || this.options.parent?.resource)?.id}/${type}/${randomId()}`;\n }\n\n ref(idOrRef: string | Reference) {\n let id = \"\";\n let type = \"\";\n\n if (typeof idOrRef === \"string\") {\n id = idOrRef;\n } else {\n id = idOrRef.id;\n type = idOrRef.type;\n }\n\n const state = this.vault.getState();\n const realType = state.iiif.mapping[id];\n\n if (!realType) {\n type = type || \"unknown\";\n } else {\n type = realType;\n }\n\n return new ReferencedResource({ id, type }, this.vault);\n }\n\n embed(data: any) {\n return new CreatorResource(data, this.vault);\n }\n\n async create(\n definition: string,\n payload: any,\n options?: Partial<CreatorOptions>,\n ) {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig,\n );\n\n return (await runtime.run()) as any;\n }\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport {\n addMappings,\n batchActions,\n importEntities,\n} from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { CreatorInstance } from \"./CreatorInstance\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport type { CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { getCreatorConfigKey, resolveType } from \"./utils\";\n\nexport class CreatorRuntime {\n // This will hold state for the creation process\n resource: CreatorResource | Array<CreatorResource> | null = null;\n payload: any;\n vault: Vault;\n previewVault: Vault;\n definition: CreatorDefinition;\n options: CreatorOptions;\n configs: CreatorDefinition[];\n creatorConfig: CreatorConfig;\n\n constructor(\n vault: Vault,\n definition: CreatorDefinition,\n payload: any,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n options?: Partial<CreatorOptions>,\n creatorConfig?: CreatorConfig,\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.definition = definition;\n this.payload = payload;\n this.configs = this.filterCreateConfigs(createConfigs);\n this.creatorConfig = creatorConfig || {};\n this.options = {\n targetType: options?.targetType || definition.resourceType,\n ...(options || {}),\n };\n }\n\n filterCreateConfigs(configs: CreatorDefinition[]) {\n const indexedByIdLastWins: Record<string, CreatorDefinition> = {};\n for (const config of configs) {\n indexedByIdLastWins[config.id] = config;\n }\n return Object.values(indexedByIdLastWins);\n }\n\n async run(): Promise<CreatorResource | CreatorResource[]> {\n const instance = new CreatorInstance(\n this.vault,\n this.options,\n this.configs,\n this.previewVault,\n getCreatorConfigKey(this.definition),\n this.creatorConfig,\n );\n const result = await this.definition.create(this.payload, instance);\n\n // Could be an array.\n if (Array.isArray(result)) {\n const results: CreatorResource[] = [];\n for (const item of result) {\n if (item instanceof CreatorResource) {\n results.push(item);\n } else {\n results.push(new CreatorResource(item, this.vault));\n }\n }\n this.resource = results;\n\n return this.resource;\n }\n\n if (result instanceof CreatorResource) {\n this.resource = result;\n } else {\n this.resource = new CreatorResource(result, this.vault);\n }\n\n return this.resource;\n }\n\n getActions() {\n if (!this.resource) {\n return [];\n }\n\n const allResources = Array.isArray(this.resource)\n ? this.resource\n : [this.resource];\n\n const actions = [];\n\n const resources: any = {};\n const mapping: any = {};\n\n for (const resource of allResources) {\n if (this.options.parent) {\n resource.setPartOf(this.options.parent.resource.id);\n }\n\n const embedded = resource.getAllEmbeddedResources();\n\n const allItems = [...embedded, resource];\n\n for (const item of allItems) {\n const resource = item.getVaultResource();\n if (!resource.type || !resource.id) {\n continue;\n }\n const type = resolveType(resource.type);\n resources[type] = resources[type] ? resources[type] : {};\n resources[type][resource.id] = resource;\n mapping[resource.id] = type;\n }\n\n actions.push(importEntities({ entities: resources }));\n actions.push(addMappings({ mapping }));\n }\n\n return actions as any[];\n }\n\n commit(afterActions: any[] = []): Reference | Reference[] {\n if (!this.resource) {\n throw new Error(\"Creator has not been run\");\n }\n\n const actions = this.getActions();\n this.vault.dispatch(\n batchActions({ actions: [...actions, ...afterActions] }),\n );\n\n if (Array.isArray(this.resource)) {\n return this.resource.map((resource) => resource.ref() as Reference);\n }\n\n return this.resource.ref() as Reference;\n }\n}\n","import { Vault } from \"@iiif/helpers/vault\";\nimport { entityActions } from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport type { CreatableResource, CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { matchBasedOnResource } from \"./utils\";\n\nexport class Creator {\n configs: CreatorDefinition[];\n vault: Vault;\n previewVault: Vault;\n creatorConfig: CreatorConfig;\n\n constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault, creatorConfig?: CreatorConfig) {\n this.configs = configs || [];\n this.vault = vault;\n this.previewVault = previewVault || new Vault();\n this.creatorConfig = creatorConfig || {};\n }\n\n matchBasedOnResource(resource: CreatableResource) {\n return matchBasedOnResource(resource, this.configs || [], { vault: this.vault });\n }\n\n async create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference | Reference[]> {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n if (options?.parent) {\n if (foundDefinition.supports.parentTypes) {\n if (!foundDefinition.supports.parentTypes.includes(options.parent.resource.type)) {\n throw new Error(`Definition ${definition} does not support parent type ${options.parent.resource.type}`);\n }\n }\n if (foundDefinition.supports.parentFields) {\n if (!foundDefinition.supports.parentFields.includes(options.parent.property)) {\n throw new Error(`Definition ${definition} does not support parent field ${options.parent.property}`);\n }\n }\n\n if (foundDefinition.supports.parentFieldMap) {\n const type = foundDefinition.supports.parentFieldMap[options.parent.resource.type];\n if (!type || !type.includes(options.parent.property)) {\n throw new Error(\n `Definition ${definition} does not support parent ${options.parent.property} / ${options.parent.property}`,\n );\n }\n }\n if (foundDefinition.supports.custom) {\n const isValid = foundDefinition.supports.custom(options.parent, this.vault);\n if (!isValid) {\n throw new Error(`Definition does not support resource`);\n }\n }\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig,\n );\n\n const run = await runtime.run();\n const allResources = Array.isArray(run) ? run : [run];\n const afterActions: any[] = [];\n\n for (const resource of allResources) {\n if (options?.parent) {\n if (options.parent.property === \"start\" || options.parent.property === \"target\") {\n afterActions.push(\n entityActions.modifyEntityField({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n value: resource.ref(),\n key: options.parent.property,\n }),\n );\n } else {\n afterActions.push(\n entityActions.addReference({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n reference: resource.ref(),\n key: options.parent.property,\n index: options.parent.atIndex,\n }),\n );\n }\n }\n }\n\n const result = runtime.commit(afterActions);\n\n // Only run side effects if there is a parent\n if (options?.parent) {\n if (foundDefinition.sideEffects) {\n for (const sideEffect of foundDefinition.sideEffects) {\n if (sideEffect.run) {\n const allResults = Array.isArray(result) ? result : [result];\n for (const item of allResults) {\n // @todo we need more in the ctx (like parent/target where this is to be added.)\n await sideEffect.run(item, { vault: this.vault, options: options as any });\n }\n }\n }\n }\n }\n\n return result;\n }\n}\n","import type {\n AllAvailableParentTypes,\n AllParentTypes,\n AllProperties,\n CreatorContext,\n CreatorDefinition,\n SpecificCreatorDefinition,\n} from \"./types\";\n\n// Want to enable the following APIs.\n//\n// const createImage = useCreator(\n// resource,\n// \"thumbnail\",\n// \"@manifest-editor/image-url-creator\"\n// );\n//\n// createImage({ url: 'https://example.org/image.jpg' });\n//\n// These should be constructed from an array of creators.\n// UseCreator<Resource, ResourceField, CreatorId> -> CreatorPayload\n//\n// But then also:\n// await manifestEditor.descriptive.thumbnail.create(\"@manifest-editor/image-url-creator\", {\n// url: \"https://example.org/image.jpg\",\n// });\n//\n// So essentially, I think we want to create a type that is roughly structured like this:\n// {\n// Manifest: {\n// thumbnail: {\n// \"@manifest-editor/image-url-creator\": {\n// url: string;\n// }\n// }\n// }\n// }\n// Although it would include _all_ available creators.\n// Then the helpers would be fairly easy to implement.\n//\n// Here the creator definition (might need to change) for this:\n\nexport function defineCreator<\n const Payload = any,\n const ID = Readonly<string>,\n const ResourceType extends AllAvailableParentTypes = never,\n const AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [],\n const AllResourceTypes = [ResourceType, ...AdditionalResourceTypes],\n const SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes,\n const SupportsParentFields extends Array<AllProperties> = [],\n const CreateReturnType = any,\n>(\n options: SpecificCreatorDefinition<\n Payload,\n ID,\n ResourceType,\n AdditionalResourceTypes,\n AllResourceTypes,\n SupportsParentTypes,\n SupportsParentFields,\n CreateReturnType\n >\n) {\n return options;\n}\n\nexport function withInitialData<T extends CreatorDefinition>(\n creator: T,\n data: Record<string, any>,\n overrides: Record<string, any> = {}\n): T {\n const render = creator.render\n ? (ctx: CreatorContext<any>) => {\n const newContext: CreatorContext = {\n ...ctx,\n options: {\n ...(ctx.options || {}),\n initialData: {\n ...(data || {}),\n ...(ctx.options?.initialData || {}),\n ...(overrides || {}),\n },\n },\n };\n return creator.render?.(newContext);\n }\n : undefined;\n\n return { ...creator, render } as T;\n}\n\nexport function withCustomRender<T extends CreatorDefinition>(\n creator: T,\n render: (ctx: CreatorContext<any>, originalRender: (ctx: CreatorContext<any>) => React.ReactNode) => React.ReactNode\n): T {\n const newRender = (ctx: CreatorContext<any>) => {\n return render(ctx, creator.render as any);\n };\n\n return { ...creator, render: newRender } as T;\n}\n\nexport declare namespace IIIFManifestEditor {\n interface CreatorDefinitions {}\n}\n\nexport type ExtractCreatorGenerics<T extends CreatorDefinition> =\n T extends SpecificCreatorDefinition<\n infer Payload,\n infer ID,\n infer ResourceType,\n infer AdditionalResourceTypes,\n infer AllResourceTypes,\n infer SupportsParentTypes,\n infer SupportsParentFields,\n infer CreateReturnType\n >\n ? {\n Payload: Payload;\n ID: ID;\n ResourceType: ResourceType;\n AdditionalResourceTypes: AdditionalResourceTypes;\n AllResourceTypes: AllResourceTypes;\n SupportsParentTypes: SupportsParentTypes;\n SupportsParentFields: SupportsParentFields;\n CreateReturnType: CreateReturnType;\n }\n : never;\n\ntype CreatorSupportsParentTypes<T, Type extends AllAvailableParentTypes> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentTypes\"] extends never\n ? false\n : HelperInArray<Type, ExtractCreatorGenerics<T>[\"SupportsParentTypes\"]>\n : false;\n\ntype CreatorSupportsParentFields<T, Field extends AllProperties> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentFields\"] extends never\n ? false\n : HelperInArray<Field, ExtractCreatorGenerics<T>[\"SupportsParentFields\"]>\n : false;\n\ntype CreatorSupportsParent<\n T,\n Type extends AllAvailableParentTypes,\n Field extends AllProperties,\n> = T extends CreatorDefinition\n ? CreatorSupportsParentTypes<T, Type> extends true\n ? CreatorSupportsParentFields<T, Field> extends true\n ? true\n : false\n : false\n : false;\n\ntype HelperInArray<ToFind, Array extends readonly any[]> = Array extends readonly [infer Head, ...infer Tail]\n ? Head extends ToFind\n ? true\n : HelperInArray<ToFind, Tail>\n : false;\n\nexport type CreatorDefinitionFilterByParent<\n Type extends AllAvailableParentTypes,\n Field extends AllProperties = AllProperties,\n CD extends IIIFManifestEditor.CreatorDefinitions = IIIFManifestEditor.CreatorDefinitions,\n> = {\n [K in keyof CD]: CreatorSupportsParent<CD[K], Type, Field> extends true ? CD[K] : never;\n}[keyof CD];\n"],"mappings":"4tCAIA,IAAa,EAAb,KAAgC,CAK9B,YAAY,EAAyC,EAAc,CAJnE,EAAA,KAAA,QAAA,IAAA,EAAA,EACA,EAAA,KAAA,WAAA,IAAA,EAAA,EACA,EAAA,KAAA,YAAA,IAAA,EAAA,EACA,EAAA,KAAA,WAAA,IAAA,EAAA,EAEE,KAAK,MAAQ,EACb,KAAK,SAAW,EAChB,KAAK,UAAY,EAAmB,CAAS,EACzC,EAAU,OACV,EACJ,KAAK,SAAW,EAAmB,CAAS,EACxC,EACA,CAAE,KAAM,mBAAoB,OAAQ,KAAK,SAAU,CACzD,CAIA,KAAM,CACJ,OAAO,KAAK,SACd,CAEA,kBAAmB,CACjB,OAAO,KAAK,QACd,CAEA,0BAA2B,CAYzB,OAXI,EAAmB,KAAK,QAAQ,EAC3B,CACL,GAAG,KAAK,SACR,OAAQ,CACN,GAAI,KAAK,SAAS,QAAQ,GAC1B,KAAM,KAAK,SAAS,QAAQ,IAC9B,CACF,EAIK,KAAK,QACd,CAEA,KAAM,CACJ,OAAO,KAAK,MAAM,IAAI,KAAK,QAAQ,CACrC,CACF,ECrBA,SAAgB,EAAoB,EAAuC,CACzE,OAAO,EAAW,WAAa,EAAW,EAC5C,CAEA,SAAgB,EAAY,EAA8B,CACxD,OAAQ,EAAR,CACE,I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Ac,aAAa,CACzB,GAAI,EAAQ,OAAO,SAAS,GAC5B,KAAM,EAAQ,OAAO,SAAS,KAC9B,UAAW,EAAS,IAAI,EACxB,IAAK,EAAQ,OAAO,SACpB,MAAO,EAAQ,OAAO,OACxB,CAAC,CACH,GAKN,IAAM,EAAS,EAAQ,OAAO,CAAY,EAG1C,GAAI,GAAS,QACP,EAAgB,YACb,KAAA,IAAM,KAAc,EAAgB,YACvC,GAAI,EAAW,IAAK,CAClB,IAAM,EAAa,MAAM,QAAQ,CAAM,EAAI,EAAS,CAAC,CAAM,EAC3D,IAAK,IAAM,KAAQ,EAEjB,MAAM,EAAW,IAAI,EAAM,CAAE,MAAO,KAAK,MAAgB,SAAe,CAAC,CAE7E,EAKN,OAAO,CACT,CACF,EC1EA,SAAgB,EAUd,EAUA,CACA,OAAO,CACT,CAEA,SAAgB,EACd,EACA,EACA,EAAiC,CAAC,EAC/B,CACH,IAAM,EAAS,EAAQ,OAClB,GAA6B,CAC5B,IAAM,EAA6B,CACjC,GAAG,EACH,QAAS,CACP,GAAI,EAAI,SAAW,CAAC,EACpB,YAAa,CACX,GAAI,GAAQ,CAAC,EACb,GAAI,EAAI,SAAS,aAAe,CAAC,EACjC,GAAI,GAAa,CAAC,CACpB,CACF,CACF,EACA,OAAO,EAAQ,SAAS,CAAU,CACpC,EACA,IAAA,GAEJ,MAAO,CAAE,GAAG,EAAS,QAAO,CAC9B,CAEA,SAAgB,EACd,EACA,EACG,CACH,IAAM,EAAa,GACV,EAAO,EAAK,EAAQ,MAAa,EAG1C,MAAO,CAAE,GAAG,EAAS,OAAQ,CAAU,CACzC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/placeholder-position.ts","../src/ReferencedResource.ts","../src/utils.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/CreatorRuntime.ts","../src/Creator.ts","../src/creator-register.ts"],"sourcesContent":["import type { Vault } from \"@iiif/helpers/vault\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport {\n EditorInstance,\n fitWithinBounds,\n getCanvasLayout,\n getImageSize,\n setCanvasLayout,\n validSize,\n getEmptyCanvasPlaceholders,\n layoutSlotToPixels,\n syncCanvasPaintOrder,\n} from \"@manifest-editor/editor-api\";\nimport type { CreatorOptions } from \"./types\";\n\n/** A placement hint fits a resource inside a box; an explicit selector remains an exact target. */\nexport function placeCreatedResources(vault: Vault, result: Reference | Reference[], options: CreatorOptions) {\n const placement = options.placeholderPosition;\n if (!placement) return;\n const refs = Array.isArray(result) ? result : [result];\n const annotations = refs.flatMap((ref) => {\n if (ref.type === \"Annotation\") return [vault.get(ref)];\n if (options.parent?.resource.type === \"Annotation\" && options.parent.property === \"body\")\n return [vault.get(options.parent.resource)];\n return [];\n });\n const canvas = vault.get<any>({ id: placement.canvasId, type: \"Canvas\" });\n const state = getCanvasLayout(vault, canvas.id);\n if (state?.customised === false && placement.placeholderId) {\n const first = state.slots.find((slot) => slot.id === placement.placeholderId)!;\n const empty = getEmptyCanvasPlaceholders(vault, canvas).filter((slot) => slot.id !== first.id);\n const positions = [first, ...empty];\n if (\n !first ||\n annotations.length > positions.length ||\n (first.annotationIds?.length && first.annotationIds[0] !== placement.replaceAnnotationId)\n )\n throw new Error(\"This position is no longer available. Choose an empty position.\");\n {\n const slots = state.slots.map((slot) => ({ ...slot }));\n annotations.forEach((annotation, index) => {\n const slot = positions[index]!;\n const size = getImageSize(vault, annotation) || placement.bounds;\n new EditorInstance({ vault, reference: annotation }).annotation.target.setPosition(\n fitWithinBounds(size, layoutSlotToPixels(slot.bounds, canvas))\n );\n slots.find((item) => item.id === slot.id)!.annotationIds = [annotation.id];\n });\n if (placement.replaceAnnotationId)\n for (const page of canvas.items)\n vault.modifyEntityField(\n page,\n \"items\",\n vault.get(page).items.filter((ref: any) => ref.id !== placement.replaceAnnotationId)\n );\n setCanvasLayout(vault, canvas.id, { ...state, slots });\n syncCanvasPaintOrder(vault, canvas);\n }\n return;\n }\n const placed: string[] = [];\n const columns = Math.ceil(Math.sqrt(annotations.length));\n const rows = Math.ceil(annotations.length / columns);\n vault.batch(() => {\n annotations.forEach((annotation, i) => {\n const body = annotation.body?.[0] && vault.get<any>(annotation.body[0]);\n const size = getImageSize(vault, annotation) || (body && validSize(body) ? body : placement.bounds);\n const bounds = {\n x: placement.bounds.x + ((i % columns) * placement.bounds.width) / columns,\n y: placement.bounds.y + (Math.floor(i / columns) * placement.bounds.height) / rows,\n width: placement.bounds.width / columns,\n height: placement.bounds.height / rows,\n };\n const editor = new EditorInstance({ vault, reference: { id: annotation.id, type: \"Annotation\" } });\n const position = fitWithinBounds(size, bounds);\n editor.annotation.target.set({\n type: \"SpecificResource\",\n source: { id: placement.canvasId, type: \"Canvas\" },\n selector: {\n type: \"FragmentSelector\",\n value: `xywh=${position.x},${position.y},${position.width},${position.height}`,\n },\n });\n placed.push(annotation.id);\n });\n const state = getCanvasLayout(vault, placement.canvasId);\n if (placement.replaceAnnotationId)\n for (const page of canvas.items)\n vault.modifyEntityField(\n page,\n \"items\",\n vault.get(page).items.filter((ref: any) => ref.id !== placement.replaceAnnotationId)\n );\n if (state && placement.placeholderId && placed.length)\n setCanvasLayout(vault, placement.canvasId, {\n ...state,\n slots: state.slots.map((slot) =>\n slot.id === placement.placeholderId\n ? {\n ...slot,\n annotationIds: [\n ...(slot.annotationIds || []).filter((id) => id !== placement.replaceAnnotationId),\n ...placed,\n ],\n }\n : slot\n ),\n });\n });\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport { isSpecificResource } from \"@iiif/parser\";\nimport type { Reference, SpecificResource } from \"@iiif/presentation-3\";\n\nexport class ReferencedResource {\n vault: Vault;\n original: Reference | SpecificResource;\n reference: Reference;\n resource: SpecificResource;\n constructor(reference: Reference | SpecificResource, vault: Vault) {\n this.vault = vault;\n this.original = reference;\n this.reference = isSpecificResource(reference)\n ? reference.source\n : reference;\n this.resource = isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: this.reference };\n }\n\n // @todo editable specific resource.\n\n ref() {\n return this.reference;\n }\n\n specificResource() {\n return this.resource;\n }\n\n optionalSpecificResource() {\n if (isSpecificResource(this.original)) {\n return {\n ...this.original,\n source: {\n id: this.original.source?.id,\n type: this.original.source?.type,\n },\n };\n }\n\n // @todo check if there are targets here that would make this a specific resource.\n return this.original;\n }\n\n get() {\n return this.vault.get(this.resource);\n }\n}\n","import type { Entities, Vault } from \"@iiif/helpers/vault\";\nimport {\n emptyAgent,\n emptyAnnotation,\n emptyAnnotationPage,\n emptyCanvas,\n emptyCollection,\n emptyManifest,\n emptyRange,\n emptyService,\n toRef,\n} from \"@iiif/parser\";\nimport type {\n CreatorDefinitionFilterByParent,\n IIIFManifestEditor,\n} from \"./creator-register\";\nimport type {\n AllAvailableParentTypes,\n CreatableResource,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n GetCreatorPayload,\n GetSupportedResourceFields,\n ResolvedCreatorReturn,\n} from \"./types\";\n\nexport function getCreatorConfigKey(definition: CreatorDefinition): string {\n return definition.configKey ?? definition.id;\n}\n\nexport function resolveType(type: string): keyof Entities {\n switch (type) {\n case \"Image\":\n case \"Video\":\n case \"Sound\":\n case \"Dataset\":\n case \"Text\":\n case \"TextualBody\":\n case \"Composite\":\n case \"List\":\n case \"Choice\":\n case \"Independents\":\n case \"Audience\":\n return \"ContentResource\";\n case \"ImageService1\":\n case \"ImageService2\":\n case \"ImageService3\":\n return \"Service\";\n }\n\n return type as any;\n}\n\nconst emptyTypes = {\n Annotation: emptyAnnotation,\n AnnotationPage: emptyAnnotationPage,\n Canvas: emptyCanvas,\n Collection: emptyCollection,\n Manifest: emptyManifest,\n Range: emptyRange,\n ResourceProvider: emptyAgent,\n Service: emptyService,\n};\n\nexport function getEmptyType(type: string): any {\n const key = resolveType(type);\n return emptyTypes[key as \"Manifest\"] || {};\n}\n\nexport function randomId() {\n return `${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`;\n}\n\nexport function matchBasedOnResource(\n resource: CreatableResource,\n list: CreatorDefinition[],\n options: { vault: Vault },\n): CreatorDefinition[] {\n const supported = [];\n if (list.length === 0) {\n return [];\n }\n const parent = toRef(resource.parent);\n const property = resource.property;\n const filter = resource.filter;\n\n for (const def of list) {\n if (filter) {\n if (!def.tags) continue;\n if (!def.tags.includes(filter)) {\n continue;\n }\n }\n\n if (parent && property) {\n if (def.supports.parentTypes) {\n if (!def.supports.parentTypes.includes(parent.type)) {\n continue;\n }\n }\n if (def.supports.parentFields) {\n if (!def.supports.parentFields.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.parentFieldMap) {\n const type = def.supports.parentFieldMap[parent.type];\n if (!type || !type.includes(property)) {\n continue;\n }\n }\n\n if (def.supports.disallowPainting && resource.isPainting) {\n continue;\n }\n if (def.supports.onlyPainting && !resource.isPainting) {\n continue;\n }\n\n if (def.supports.custom) {\n const isValid = def.supports.custom(\n { property, resource: parent, atIndex: resource.index },\n options.vault,\n );\n if (!isValid) {\n continue;\n }\n }\n\n const initialDataKeys = Object.keys(resource.initialData || {}).filter(\n (key) => key !== \"skipEditingOnCreate\",\n );\n\n if (!def.supports.initialData && initialDataKeys.length !== 0) {\n continue;\n }\n\n if (def.resourceType !== resource.type) {\n if (!(def.additionalTypes || []).includes(resource.type)) {\n continue;\n }\n }\n supported.push(def);\n }\n }\n\n return supported;\n}\n\nexport function creatorHelper<\n const ResourceType extends AllAvailableParentTypes,\n const Parent extends { id: string; type: ResourceType },\n const ResourceField extends GetSupportedResourceFields<ResourceType>,\n const CID extends CreatorDefinitionFilterByParent<\n ResourceType,\n ResourceField\n >[\"id\"],\n Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>,\n Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>,\n>(\n ctx: CreatorFunctionContext,\n parent: Parent | ResourceType,\n property: ResourceField,\n definition: CID,\n): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return> {\n return (payload: Payload, options = {}) => {\n if (typeof parent !== \"string\") {\n options.parent = {\n property,\n resource: parent,\n atIndex: options?.parent?.atIndex,\n };\n }\n return ctx.create(definition, payload, options) as any;\n };\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport { HAS_PART, isSpecificResource, PART_OF } from \"@iiif/parser\";\nimport type { SpecificResource } from \"@iiif/presentation-3\";\nimport { references } from \"@manifest-editor/editor-api\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport { getEmptyType, resolveType } from \"./utils\";\n\nexport class CreatorResource {\n resource: any;\n meta: Record<string, Record<string, unknown>> = {};\n warnings: string[] = [];\n errors: string[] = [];\n partOf: any;\n references: ReferencedResource[] = [];\n embedded: CreatorResource[] = [];\n vault: Vault;\n specificResource?: SpecificResource;\n\n constructor(inputData: any, vault: Vault) {\n this.vault = vault;\n let data = { ...inputData };\n\n if (data.type === \"SpecificResource\") {\n const source = data.source;\n this.specificResource = {\n ...data,\n source: { id: source.id, type: resolveType(source.type) },\n };\n data = source;\n }\n\n const properties = Object.keys(data);\n const defaultType = getEmptyType(data.type);\n\n for (const key of properties) {\n // These properties are NOT references and can be just included normally.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n continue;\n }\n\n if (data.type === \"Range\" && key === \"items\") {\n const newRange: any = [];\n for (const range of data[key]) {\n if (range instanceof ReferencedResource) {\n this.references.push(range);\n newRange.push(range);\n continue;\n }\n\n const rangeRef = new ReferencedResource(range, vault);\n newRange.push(rangeRef);\n data[key] = rangeRef;\n }\n\n data[key] = newRange;\n continue;\n }\n\n if (data.type === \"Manifest\" && key === \"start\") {\n const start = data[key];\n\n if (start instanceof ReferencedResource) {\n this.references.push(start);\n continue;\n }\n\n const startRef = new ReferencedResource(start, vault);\n data[key] = startRef;\n continue;\n }\n\n if (data.type === \"Annotation\" && key === \"target\") {\n let target = data[key];\n\n if (target instanceof ReferencedResource) {\n this.references.push(target);\n continue;\n }\n\n if (typeof target === \"string\") {\n target = { id: target, type: \"Canvas\" };\n }\n\n const targetRef = new ReferencedResource(target, vault);\n data[key] = targetRef;\n continue;\n }\n\n // @todo Handle single item cases. (not caught by the above 2 cases)\n if (references.single.includes(key as any)) {\n continue;\n }\n\n // This property SHOULD already be in the Vault OR an instance of creator resource.\n if (\n references.externalProperties.includes(key as any) ||\n references.internalProperties.includes(key as any)\n ) {\n const _items = (data[key] || []) as any[];\n const items = Array.isArray(_items) ? _items : [_items];\n const newItems: any[] = [];\n for (const item of items) {\n if (item instanceof ReferencedResource) {\n this.references.push(item);\n newItems.push(item);\n continue;\n }\n if (item instanceof CreatorResource) {\n this.embedded.push(item);\n newItems.push(item);\n continue;\n }\n\n // A SpecificResource carries its selector and source inline. Vault.get()\n // resolves it to its source, so an existing source must not turn the\n // wrapper into a plain reference.\n if (isSpecificResource(item)) {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n continue;\n }\n\n const exists = this.vault.get(item, { skipSelfReturn: true });\n if (exists) {\n const type = resolveType(item.type);\n const newItem = new ReferencedResource(\n { id: item.id, type },\n vault,\n );\n this.references.push(newItem);\n newItems.push(newItem);\n } else {\n const newItem = new CreatorResource(item, vault);\n this.embedded.push(newItem);\n newItems.push(newItem);\n }\n }\n data[key] = newItems;\n }\n }\n this.resource = { ...defaultType, ...data };\n }\n\n // This is what is returned from the creator instance\n get() {\n return this.resource;\n }\n\n getSpecificResource() {\n const reference = this.ref();\n return isSpecificResource(reference)\n ? reference\n : { type: \"SpecificResource\", source: reference };\n }\n\n ref() {\n if (this.specificResource) {\n return this.specificResource;\n }\n\n return {\n id: this.resource.id,\n type: resolveType(this.resource.type as string) as any,\n };\n }\n\n getAllReferencedResources() {\n return this.references;\n }\n\n getAllEmbeddedResources(): CreatorResource[] {\n const allEmbedded = [];\n for (const resource of this.embedded) {\n allEmbedded.push(...resource.getAllEmbeddedResources());\n }\n allEmbedded.push(...this.embedded);\n return allEmbedded;\n }\n\n getVaultResource() {\n const resource = this.resource;\n const properties = Object.keys(resource);\n const newResource: any = {};\n\n for (const key of properties) {\n // Skip these, they are just normal inline values.\n if (\n references.inlineProperties.includes(key as any) ||\n !references.all.includes(key as any)\n ) {\n newResource[key] = resource[key];\n continue;\n }\n\n if (references.single.includes(key as any)) {\n const ref = resource[key];\n if (ref instanceof ReferencedResource) {\n // These MUST be specific resources.\n if (\n (resource.type === \"Manifest\" && key === \"start\") ||\n (resource.type === \"Annotation\" && key === \"target\")\n ) {\n newResource[key] = ref.specificResource();\n } else {\n newResource[key] = ref.optionalSpecificResource();\n }\n } else {\n newResource[key] = resource[key];\n }\n continue;\n }\n\n if (resource[key]) {\n newResource[key] = [];\n for (const item of resource[key] || []) {\n if (resource.type === \"Range\" && key === \"items\") {\n if (item instanceof ReferencedResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.specificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n if (item instanceof CreatorResource) {\n if (item.ref().type === \"Canvas\") {\n newResource[key].push(item.getSpecificResource());\n } else {\n newResource[key].push(item.ref());\n }\n }\n continue;\n }\n\n if (item instanceof ReferencedResource) {\n newResource[key].push(item.optionalSpecificResource());\n }\n if (item instanceof CreatorResource) {\n newResource[key].push(item.ref());\n }\n }\n }\n }\n\n if (this.partOf) {\n newResource[HAS_PART] = newResource[HAS_PART] || [];\n newResource[HAS_PART].push(this.partOf);\n }\n\n return newResource;\n }\n\n setPartOf(id: string) {\n const ref = this.ref();\n this.partOf = {\n id: ref.id,\n type: resolveType(ref.type),\n [PART_OF]: id,\n };\n }\n}\n","import type { SupportedSelector } from \"@iiif/helpers\";\nimport type { Vault } from \"@iiif/helpers/vault\";\nimport type {\n Reference,\n Selector,\n SpecificResource,\n} from \"@iiif/presentation-3\";\nimport {\n type AnnotationResponse,\n annotationResponseToSelector,\n seraliseSupportedSelector,\n} from \"react-iiif-vault\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport { ReferencedResource } from \"./ReferencedResource\";\nimport type {\n CreatorConfig,\n CreatorDefinition,\n CreatorFunctionContext,\n CreatorOptions,\n} from \"./types\";\nimport { randomId } from \"./utils\";\n\nexport class CreatorInstance implements CreatorFunctionContext {\n vault: Vault;\n previewVault: Vault;\n configs: CreatorDefinition[];\n options: CreatorOptions;\n config: Record<string, unknown>;\n creatorConfig: CreatorConfig;\n\n target: CreatorOptions[\"target\"];\n selector: SupportedSelector | undefined | null;\n serialisedSelector: { type: string; value: string } | null = null;\n\n constructor(\n vault: Vault,\n options: CreatorOptions,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n configKey: string,\n creatorConfig: CreatorConfig = {},\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.options = options;\n this.configs = createConfigs;\n this.creatorConfig = creatorConfig;\n this.config = creatorConfig[configKey] || {};\n this.target = this.options.target || this.options.parent?.resource;\n const response: AnnotationResponse = this.options.initialData?.selector;\n this.selector = response ? annotationResponseToSelector(response) : null;\n if (this.options.initialData?.getSerialisedSelector) {\n this.serialisedSelector =\n this.options.initialData.getSerialisedSelector();\n }\n }\n\n getPreviewVault() {\n return this.previewVault;\n }\n\n setSelector(selector: SupportedSelector) {\n this.selector = selector;\n }\n\n getSerialisedSelector() {\n if (this.serialisedSelector) {\n return this.serialisedSelector;\n }\n const selector = this.selector;\n if (selector) {\n const serialisedSelector = seraliseSupportedSelector(\n selector,\n this.options.initialData?.on,\n );\n if (serialisedSelector) {\n return serialisedSelector;\n }\n }\n return null;\n }\n\n getTarget(): SpecificResource | Reference | undefined {\n const target = this.target;\n const serialisedSelector = this.getSerialisedSelector();\n\n if (serialisedSelector) {\n return {\n type: \"SpecificResource\",\n source: target,\n selector: serialisedSelector as Selector,\n };\n }\n\n return target;\n }\n\n getParent(): Reference | undefined {\n return this.options.parent?.resource;\n }\n getParentResource(): SpecificResource | undefined {\n const parent = this.getParent();\n if (parent) {\n return {\n type: \"SpecificResource\",\n source: parent,\n };\n }\n }\n\n generateId(type: string, parent?: Reference | ReferencedResource) {\n if (parent && parent instanceof ReferencedResource) {\n parent = parent.ref();\n }\n if (this.options.rootId) {\n parent = { id: this.options.rootId, type: \"none\" };\n }\n\n return `${(parent || this.options.parent?.resource)?.id}/${type}/${randomId()}`;\n }\n\n ref(idOrRef: string | Reference) {\n let id = \"\";\n let type = \"\";\n\n if (typeof idOrRef === \"string\") {\n id = idOrRef;\n } else {\n id = idOrRef.id;\n type = idOrRef.type;\n }\n\n const state = this.vault.getState();\n const realType = state.iiif.mapping[id];\n\n if (!realType) {\n type = type || \"unknown\";\n } else {\n type = realType;\n }\n\n return new ReferencedResource({ id, type }, this.vault);\n }\n\n embed(data: any) {\n return new CreatorResource(data, this.vault);\n }\n\n async create(\n definition: string,\n payload: any,\n options?: Partial<CreatorOptions>,\n ) {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig,\n );\n\n return (await runtime.run()) as any;\n }\n}\n","import type { Vault } from \"@iiif/helpers/vault\";\nimport {\n addMappings,\n metaActions,\n batchActions,\n importEntities,\n} from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { CreatorInstance } from \"./CreatorInstance\";\nimport { CreatorResource } from \"./CreatorResource\";\nimport type { CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { getCreatorConfigKey, resolveType } from \"./utils\";\n\nexport class CreatorRuntime {\n // This will hold state for the creation process\n resource: CreatorResource | Array<CreatorResource> | null = null;\n payload: any;\n vault: Vault;\n previewVault: Vault;\n definition: CreatorDefinition;\n options: CreatorOptions;\n configs: CreatorDefinition[];\n creatorConfig: CreatorConfig;\n\n constructor(\n vault: Vault,\n definition: CreatorDefinition,\n payload: any,\n createConfigs: CreatorDefinition[],\n previewVault: Vault,\n options?: Partial<CreatorOptions>,\n creatorConfig?: CreatorConfig,\n ) {\n this.vault = vault;\n this.previewVault = previewVault;\n this.definition = definition;\n this.payload = payload;\n this.configs = this.filterCreateConfigs(createConfigs);\n this.creatorConfig = creatorConfig || {};\n this.options = {\n targetType: options?.targetType || definition.resourceType,\n ...(options || {}),\n };\n }\n\n filterCreateConfigs(configs: CreatorDefinition[]) {\n const indexedByIdLastWins: Record<string, CreatorDefinition> = {};\n for (const config of configs) {\n indexedByIdLastWins[config.id] = config;\n }\n return Object.values(indexedByIdLastWins);\n }\n\n async run(): Promise<CreatorResource | CreatorResource[]> {\n const instance = new CreatorInstance(\n this.vault,\n this.options,\n this.configs,\n this.previewVault,\n getCreatorConfigKey(this.definition),\n this.creatorConfig,\n );\n const result = await this.definition.create(this.payload, instance);\n\n // Could be an array.\n if (Array.isArray(result)) {\n const results: CreatorResource[] = [];\n for (const item of result) {\n if (item instanceof CreatorResource) {\n results.push(item);\n } else {\n results.push(new CreatorResource(item, this.vault));\n }\n }\n this.resource = results;\n\n return this.resource;\n }\n\n if (result instanceof CreatorResource) {\n this.resource = result;\n } else {\n this.resource = new CreatorResource(result, this.vault);\n }\n\n return this.resource;\n }\n\n getActions() {\n if (!this.resource) {\n return [];\n }\n\n const allResources = Array.isArray(this.resource)\n ? this.resource\n : [this.resource];\n\n const actions = [];\n\n const resources: any = {};\n const mapping: any = {};\n\n for (const resource of allResources) {\n if (this.options.parent) {\n resource.setPartOf(this.options.parent.resource.id);\n }\n\n const embedded = resource.getAllEmbeddedResources();\n\n const allItems = [...embedded, resource];\n\n for (const item of allItems) {\n const resource = item.getVaultResource();\n for (const [meta, values] of Object.entries(item.meta)) {\n for (const [key, value] of Object.entries(values)) {\n actions.push(metaActions.setMetaValue({ id: resource.id, meta, key, value }));\n }\n }\n if (!resource.type || !resource.id) {\n continue;\n }\n const type = resolveType(resource.type);\n resources[type] = resources[type] ? resources[type] : {};\n resources[type][resource.id] = resource;\n mapping[resource.id] = type;\n }\n\n actions.push(importEntities({ entities: resources }));\n actions.push(addMappings({ mapping }));\n }\n\n return actions as any[];\n }\n\n commit(afterActions: any[] = []): Reference | Reference[] {\n if (!this.resource) {\n throw new Error(\"Creator has not been run\");\n }\n\n const actions = this.getActions();\n this.vault.dispatch(\n batchActions({ actions: [...actions, ...afterActions] }),\n );\n\n if (Array.isArray(this.resource)) {\n return this.resource.map((resource) => resource.ref() as Reference);\n }\n\n return this.resource.ref() as Reference;\n }\n}\n","import { Vault } from \"@iiif/helpers/vault\";\nimport { entityActions } from \"@iiif/helpers/vault/actions\";\nimport type { Reference } from \"@iiif/presentation-3\";\nimport { placeCreatedResources } from \"./placeholder-position\";\nimport {\n beginCanvasComposition,\n getCanvasLayout,\n getEmptyCanvasPlaceholders,\n validRectangle,\n} from \"@manifest-editor/editor-api\";\nimport { CreatorRuntime } from \"./CreatorRuntime\";\nimport type { CreatableResource, CreatorConfig, CreatorDefinition, CreatorOptions } from \"./types\";\nimport { matchBasedOnResource } from \"./utils\";\n\nexport class Creator {\n configs: CreatorDefinition[];\n vault: Vault;\n previewVault: Vault;\n creatorConfig: CreatorConfig;\n\n constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault, creatorConfig?: CreatorConfig) {\n this.configs = configs || [];\n this.vault = vault;\n this.previewVault = previewVault || new Vault();\n this.creatorConfig = creatorConfig || {};\n }\n\n matchBasedOnResource(resource: CreatableResource) {\n return matchBasedOnResource(resource, this.configs || [], { vault: this.vault });\n }\n\n async create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference | Reference[]> {\n const foundDefinition = this.configs.find((t) => t.id === definition);\n if (!foundDefinition) {\n throw new Error(`Creator config ${definition} not found`);\n }\n\n if (options?.parent) {\n if (foundDefinition.supports.parentTypes) {\n if (!foundDefinition.supports.parentTypes.includes(options.parent.resource.type)) {\n throw new Error(`Definition ${definition} does not support parent type ${options.parent.resource.type}`);\n }\n }\n if (foundDefinition.supports.parentFields) {\n if (!foundDefinition.supports.parentFields.includes(options.parent.property)) {\n throw new Error(`Definition ${definition} does not support parent field ${options.parent.property}`);\n }\n }\n\n if (foundDefinition.supports.parentFieldMap) {\n const type = foundDefinition.supports.parentFieldMap[options.parent.resource.type];\n if (!type || !type.includes(options.parent.property)) {\n throw new Error(\n `Definition ${definition} does not support parent ${options.parent.property} / ${options.parent.property}`\n );\n }\n }\n if (foundDefinition.supports.custom) {\n const isValid = foundDefinition.supports.custom(options.parent, this.vault);\n if (!isValid) {\n throw new Error(`Definition does not support resource`);\n }\n }\n }\n\n const runtime = new CreatorRuntime(\n this.vault,\n foundDefinition,\n payload,\n this.configs,\n this.previewVault,\n options,\n this.creatorConfig\n );\n\n if (options?.placeholderPosition && !validRectangle(options.placeholderPosition.bounds)) {\n throw new Error(\"Invalid placeholder position\");\n }\n const run = await runtime.run();\n const allResources = Array.isArray(run) ? run : [run];\n const afterActions: any[] = [];\n\n for (const resource of allResources) {\n if (options?.parent) {\n if (options.parent.property === \"start\" || options.parent.property === \"target\") {\n afterActions.push(\n entityActions.modifyEntityField({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n value: resource.ref(),\n key: options.parent.property,\n })\n );\n } else {\n afterActions.push(\n entityActions.addReference({\n id: options.parent.resource.id,\n type: options.parent.resource.type as any,\n reference: resource.ref(),\n key: options.parent.property,\n index: options.placeholderPosition?.replaceAnnotationId\n ? this.vault\n .get<any>(options.parent.resource)\n [options.parent.property]?.findIndex(\n (ref: Reference) => ref.id === options.placeholderPosition!.replaceAnnotationId\n )\n : options.parent.atIndex,\n })\n );\n }\n }\n }\n\n // Validate against live occupancy before any parent references are committed.\n const placement = options?.placeholderPosition;\n if (placement) {\n if (placement.replaceAnnotationId && allResources.length !== 1)\n throw new Error(\"Choose one image to replace this image. Nothing has been changed.\");\n const canvas = this.vault.get<any>({ id: placement.canvasId, type: \"Canvas\" });\n const state = getCanvasLayout(this.vault, canvas.id);\n if (state?.customised === false) {\n const slot = state.slots.find((slot) => slot.id === placement.placeholderId);\n const empty = getEmptyCanvasPlaceholders(this.vault, canvas);\n if (\n !slot ||\n (placement.replaceAnnotationId\n ? slot.annotationIds?.length !== 1 ||\n slot.annotationIds[0] !== placement.replaceAnnotationId ||\n allResources.length !== 1\n : !empty.some((item) => item.id === slot.id) || allResources.length > empty.length)\n )\n throw new Error(\n \"Not enough empty positions. Reduce the selection or choose a larger layout. Nothing has been added.\"\n );\n }\n beginCanvasComposition(this.vault, canvas);\n }\n const result = runtime.commit(afterActions);\n\n // Only run side effects if there is a parent\n if (options?.parent) {\n if (foundDefinition.sideEffects) {\n for (const sideEffect of foundDefinition.sideEffects) {\n if (sideEffect.run && !(options.placeholderPosition && sideEffect.spatial && sideEffect.canvasInteraction)) {\n const allResults = Array.isArray(result) ? result : [result];\n for (const item of allResults) {\n // @todo we need more in the ctx (like parent/target where this is to be added.)\n await sideEffect.run(item, { vault: this.vault, options: options as any });\n }\n }\n }\n }\n }\n\n if (options?.placeholderPosition) placeCreatedResources(this.vault, result, runtime.options);\n\n return result;\n }\n}\n","import type {\n AllAvailableParentTypes,\n AllParentTypes,\n AllProperties,\n CreatorContext,\n CreatorDefinition,\n SpecificCreatorDefinition,\n} from \"./types\";\n\n// Want to enable the following APIs.\n//\n// const createImage = useCreator(\n// resource,\n// \"thumbnail\",\n// \"@manifest-editor/image-url-creator\"\n// );\n//\n// createImage({ url: 'https://example.org/image.jpg' });\n//\n// These should be constructed from an array of creators.\n// UseCreator<Resource, ResourceField, CreatorId> -> CreatorPayload\n//\n// But then also:\n// await manifestEditor.descriptive.thumbnail.create(\"@manifest-editor/image-url-creator\", {\n// url: \"https://example.org/image.jpg\",\n// });\n//\n// So essentially, I think we want to create a type that is roughly structured like this:\n// {\n// Manifest: {\n// thumbnail: {\n// \"@manifest-editor/image-url-creator\": {\n// url: string;\n// }\n// }\n// }\n// }\n// Although it would include _all_ available creators.\n// Then the helpers would be fairly easy to implement.\n//\n// Here the creator definition (might need to change) for this:\n\nexport function defineCreator<\n const Payload = any,\n const ID = Readonly<string>,\n const ResourceType extends AllAvailableParentTypes = never,\n const AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [],\n const AllResourceTypes = [ResourceType, ...AdditionalResourceTypes],\n const SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes,\n const SupportsParentFields extends Array<AllProperties> = [],\n const CreateReturnType = any,\n>(\n options: SpecificCreatorDefinition<\n Payload,\n ID,\n ResourceType,\n AdditionalResourceTypes,\n AllResourceTypes,\n SupportsParentTypes,\n SupportsParentFields,\n CreateReturnType\n >\n) {\n return options;\n}\n\nexport function withInitialData<T extends CreatorDefinition>(\n creator: T,\n data: Record<string, any>,\n overrides: Record<string, any> = {}\n): T {\n const render = creator.render\n ? (ctx: CreatorContext<any>) => {\n const newContext: CreatorContext = {\n ...ctx,\n options: {\n ...(ctx.options || {}),\n initialData: {\n ...(data || {}),\n ...(ctx.options?.initialData || {}),\n ...(overrides || {}),\n },\n },\n };\n return creator.render?.(newContext);\n }\n : undefined;\n\n return { ...creator, render } as T;\n}\n\nexport function withCustomRender<T extends CreatorDefinition>(\n creator: T,\n render: (ctx: CreatorContext<any>, originalRender: (ctx: CreatorContext<any>) => React.ReactNode) => React.ReactNode\n): T {\n const newRender = (ctx: CreatorContext<any>) => {\n return render(ctx, creator.render as any);\n };\n\n return { ...creator, render: newRender } as T;\n}\n\nexport declare namespace IIIFManifestEditor {\n interface CreatorDefinitions {}\n}\n\nexport type ExtractCreatorGenerics<T extends CreatorDefinition> =\n T extends SpecificCreatorDefinition<\n infer Payload,\n infer ID,\n infer ResourceType,\n infer AdditionalResourceTypes,\n infer AllResourceTypes,\n infer SupportsParentTypes,\n infer SupportsParentFields,\n infer CreateReturnType\n >\n ? {\n Payload: Payload;\n ID: ID;\n ResourceType: ResourceType;\n AdditionalResourceTypes: AdditionalResourceTypes;\n AllResourceTypes: AllResourceTypes;\n SupportsParentTypes: SupportsParentTypes;\n SupportsParentFields: SupportsParentFields;\n CreateReturnType: CreateReturnType;\n }\n : never;\n\ntype CreatorSupportsParentTypes<T, Type extends AllAvailableParentTypes> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentTypes\"] extends never\n ? false\n : HelperInArray<Type, ExtractCreatorGenerics<T>[\"SupportsParentTypes\"]>\n : false;\n\ntype CreatorSupportsParentFields<T, Field extends AllProperties> = T extends CreatorDefinition\n ? ExtractCreatorGenerics<T>[\"SupportsParentFields\"] extends never\n ? false\n : HelperInArray<Field, ExtractCreatorGenerics<T>[\"SupportsParentFields\"]>\n : false;\n\ntype CreatorSupportsParent<\n T,\n Type extends AllAvailableParentTypes,\n Field extends AllProperties,\n> = T extends CreatorDefinition\n ? CreatorSupportsParentTypes<T, Type> extends true\n ? CreatorSupportsParentFields<T, Field> extends true\n ? true\n : false\n : false\n : false;\n\ntype HelperInArray<ToFind, Array extends readonly any[]> = Array extends readonly [infer Head, ...infer Tail]\n ? Head extends ToFind\n ? true\n : HelperInArray<ToFind, Tail>\n : false;\n\nexport type CreatorDefinitionFilterByParent<\n Type extends AllAvailableParentTypes,\n Field extends AllProperties = AllProperties,\n CD extends IIIFManifestEditor.CreatorDefinitions = IIIFManifestEditor.CreatorDefinitions,\n> = {\n [K in keyof CD]: CreatorSupportsParent<CD[K], Type, Field> extends true ? CD[K] : never;\n}[keyof CD];\n"],"mappings":"+yBAgBA,SAAgB,EAAsB,EAAc,EAAiC,EAAyB,CAC5G,IAAM,EAAY,EAAQ,oBAC1B,GAAI,CAAC,EAAW,OAEhB,IAAM,GADO,MAAM,QAAQ,CAAM,EAAI,EAAS,CAAC,CAAM,EAAA,CAC5B,QAAS,GAC5B,EAAI,OAAS,aAAqB,CAAC,EAAM,IAAI,CAAG,CAAC,EACjD,EAAQ,QAAQ,SAAS,OAAS,cAAgB,EAAQ,OAAO,WAAa,OACzE,CAAC,EAAM,IAAI,EAAQ,OAAO,QAAQ,CAAC,EACrC,CAAC,CACT,EACK,EAAS,EAAM,IAAS,CAAE,GAAI,EAAU,SAAU,KAAM,QAAS,CAAC,EAClE,EAAQ,EAAgB,EAAO,EAAO,EAAE,EAC9C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EACd,EACA,EACA,EAAiC,CAAC,EAC/B,CACH,IAAM,EAAS,EAAQ,OAClB,GAA6B,CAC5B,IAAM,EAA6B,CACjC,GAAG,EACH,QAAS,CACP,GAAI,EAAI,SAAW,CAAC,EACpB,YAAa,CACX,GAAI,GAAQ,CAAC,EACb,GAAI,EAAI,SAAS,aAAe,CAAC,EACjC,GAAI,GAAa,CAAC,CACpB,CACF,CACF,EACA,OAAO,EAAQ,SAAS,CAAU,CACpC,EACA,IAAA,GAEJ,MAAO,CAAE,GAAG,EAAS,QAAO,CAC9B,CAEA,SAAgB,EACd,EACA,EACG,CACH,IAAM,EAAa,GACV,EAAO,EAAK,EAAQ,MAAa,EAG1C,MAAO,CAAE,GAAG,EAAS,OAAQ,CAAU,CACzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifest-editor/creator-api",
3
- "version": "2.2.2-next.0.a82700e",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "bugs": "https://github.com/digirati-co-uk/iiif-manifest-editor/issues",
6
6
  "repository": {
@@ -34,25 +34,28 @@
34
34
  "dev": "tsdown src/index.ts --watch",
35
35
  "typecheck": "tsc --noEmit",
36
36
  "lint": "publint",
37
- "prepack": "tsdown src/index.ts"
37
+ "prepack": "tsdown src/index.ts",
38
+ "test": "vitest run --config vitest.config.ts"
38
39
  },
39
40
  "dependencies": {
40
- "@atlas-viewer/atlas": "3.3.0",
41
- "@iiif/helpers": "4.0.0",
42
- "@iiif/parser": "4.0.1",
41
+ "@atlas-viewer/atlas": "3.3.6",
42
+ "@iiif/helpers": "4.0.5",
43
+ "@iiif/parser": "4.0.7",
43
44
  "@iiif/presentation-3": "^2.2.3",
44
45
  "@iiif/presentation-3-normalized": "^0.9.7",
45
- "@manifest-editor/editor-api": "2.2.2-next.0.a82700e",
46
- "polygon-editor": "0.0.23",
47
- "react-iiif-vault": "4.0.0"
46
+ "@manifest-editor/editor-api": "2.3.0",
47
+ "@manifest-editor/i18n": "2.3.0",
48
+ "polygon-editor": "1.0.0",
49
+ "react-iiif-vault": "4.1.0"
48
50
  },
49
51
  "devDependencies": {
50
52
  "@types/react": "19.2.18",
51
53
  "tiny-invariant": "^1.3.3",
52
- "tsdown": "0.22.14"
54
+ "tsdown": "0.22.14",
55
+ "vitest": "4.1.10"
53
56
  },
54
57
  "publishConfig": {
55
58
  "access": "public"
56
59
  },
57
- "gitHead": "a82700eb6b66d398882f7d40ad7603771edcabcf"
60
+ "gitHead": "34c06c440b1788a470f3da536169560ab1c0d3a3"
58
61
  }